Add error handling for mtp and gpod device

This commit is contained in:
Jonas Kvinge
2019-01-21 18:58:54 +01:00
parent ad5e366aad
commit 41e2a75675
12 changed files with 93 additions and 45 deletions

View File

@@ -64,36 +64,39 @@ MtpDevice::~MtpDevice() {}
bool MtpDevice::Init() {
InitBackendDirectory("/", first_time_, false);
model_->Init();
loader_ = new MtpLoader(url_, app_->task_manager(), backend_, shared_from_this());
if (!loader_->Init()) {
delete loader_;
loader_ = nullptr;
return false;
}
model_->Init();
loader_->moveToThread(loader_thread_);
connect(loader_, SIGNAL(Error(QString)), SIGNAL(Error(QString)));
connect(loader_, SIGNAL(Error(QString)), SLOT(LoaderError(QString)));
connect(loader_, SIGNAL(TaskStarted(int)), SIGNAL(TaskStarted(int)));
connect(loader_, SIGNAL(LoadFinished()), SLOT(LoadFinished()));
connect(loader_, SIGNAL(LoadFinished(bool)), SLOT(LoadFinished(bool)));
connect(loader_thread_, SIGNAL(started()), loader_, SLOT(LoadDatabase()));
db_busy_.lock();
loader_thread_->start();
return true;
}
void MtpDevice::LoadFinished() {
void MtpDevice::ConnectAsync() {
db_busy_.lock();
loader_thread_->start();
}
void MtpDevice::LoadFinished(bool success) {
loader_->deleteLater();
loader_ = nullptr;
db_busy_.unlock();
emit ConnectFinished(unique_id_, success);
}
void MtpDevice::LoaderError(const QString& message) { app_->AddError(message); }
bool MtpDevice::StartCopy(QList<Song::FileType> *supported_types) {
// Ensure only one "organise files" can be active at any one time