From 9ce8cf59d6d17e30ecaeb0f45cebb1bf58e5f81c Mon Sep 17 00:00:00 2001 From: John Maguire Date: Fri, 10 Aug 2012 11:46:26 -0700 Subject: [PATCH] Make sure Google Drive is connected when converting URLs. --- src/internet/googledriveservice.cpp | 16 +++++++++++++++- src/internet/googledriveservice.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/internet/googledriveservice.cpp b/src/internet/googledriveservice.cpp index a6111988c..4c4086b60 100644 --- a/src/internet/googledriveservice.cpp +++ b/src/internet/googledriveservice.cpp @@ -65,7 +65,9 @@ QStandardItem* GoogleDriveService::CreateRootItem() { void GoogleDriveService::LazyPopulate(QStandardItem* item) { switch (item->data(InternetModel::Role_Type).toInt()) { case InternetModel::Type_Service: - Connect(); + if (!client_->is_authenticated()) { + Connect(); + } library_model_->Init(); model()->merged_model()->AddSubModel(item->index(), library_sort_model_); break; @@ -110,6 +112,17 @@ void GoogleDriveService::ConnectFinished(google_drive::ConnectResponse* response ListFilesForMimeType("application/x-flac"); // FLAC } +void GoogleDriveService::EnsureConnected() { + if (client_->is_authenticated()) { + return; + } + + QEventLoop loop; + connect(client_, SIGNAL(Authenticated()), &loop, SLOT(quit())); + Connect(); + loop.exec(); +} + void GoogleDriveService::FilesFound(const QList& files) { foreach (const google_drive::File& file, files) { MaybeAddFileToDatabase(file); @@ -183,6 +196,7 @@ void GoogleDriveService::ReadTagsFinished(TagReaderClient::ReplyType* reply, } QUrl GoogleDriveService::GetStreamingUrlFromSongId(const QString& id) { + EnsureConnected(); QScopedPointer response(client_->GetFile(id)); QEventLoop loop; diff --git a/src/internet/googledriveservice.h b/src/internet/googledriveservice.h index a253e3fd8..22fa562b0 100644 --- a/src/internet/googledriveservice.h +++ b/src/internet/googledriveservice.h @@ -46,6 +46,7 @@ class GoogleDriveService : public InternetService { private: void Connect(); + void EnsureConnected(); void RefreshAuthorisation(const QString& refresh_token); void MaybeAddFileToDatabase(const google_drive::File& file); void ListFilesForMimeType(const QString& mime_type);