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

@@ -40,34 +40,35 @@ MtpLoader::MtpLoader(const QUrl &url, TaskManager *task_manager, CollectionBacke
original_thread_ = thread();
}
MtpLoader::~MtpLoader() {
delete connection_;
}
MtpLoader::~MtpLoader() {}
bool MtpLoader::Init() {
connection_ = new MtpConnection(url_);
return connection_->is_valid();
}
bool MtpLoader::Init() { return true; }
void MtpLoader::LoadDatabase() {
int task_id = task_manager_->StartTask(tr("Loading MTP device"));
emit TaskStarted(task_id);
TryLoad();
bool success = TryLoad();
moveToThread(original_thread_);
task_manager_->SetTaskFinished(task_id);
emit LoadFinished();
emit LoadFinished(success);
}
bool MtpLoader::TryLoad() {
MtpConnection dev(url_);
if (!dev.is_valid()) {
emit Error(tr("Error connecting MTP device"));
return false;
}
// Load the list of songs on the device
SongList songs;
LIBMTP_track_t* tracks = LIBMTP_Get_Tracklisting_With_Callback(connection_->device(), nullptr, nullptr);
LIBMTP_track_t* tracks = LIBMTP_Get_Tracklisting_With_Callback(dev.device(), nullptr, nullptr);
while (tracks) {
LIBMTP_track_t *track = tracks;