Add tasks for indexing Google Drive songs.

This commit is contained in:
John Maguire 2012-08-06 14:00:54 +02:00
parent a3f9947444
commit c5b74c832e
3 changed files with 35 additions and 4 deletions

View File

@ -36,6 +36,24 @@ public:
bool blocks_library_scans; bool blocks_library_scans;
}; };
class ScopedTask {
public:
ScopedTask(const int task_id, TaskManager* task_manager)
: task_id_(task_id),
task_manager_(task_manager) {
}
~ScopedTask() {
task_manager_->SetTaskFinished(task_id_);
}
private:
const int task_id_;
TaskManager* task_manager_;
Q_DISABLE_COPY(ScopedTask);
};
// Everything here is thread safe // Everything here is thread safe
QList<Task> GetTasks(); QList<Task> GetTasks();
@ -56,6 +74,8 @@ private:
QMutex mutex_; QMutex mutex_;
QMap<int, Task> tasks_; QMap<int, Task> tasks_;
int next_task_id_; int next_task_id_;
Q_DISABLE_COPY(TaskManager);
}; };
#endif // TASKMANAGER_H #endif // TASKMANAGER_H

View File

@ -9,6 +9,7 @@
#include "core/database.h" #include "core/database.h"
#include "core/mergedproxymodel.h" #include "core/mergedproxymodel.h"
#include "core/player.h" #include "core/player.h"
#include "core/taskmanager.h"
#include "core/timeconstants.h" #include "core/timeconstants.h"
#include "globalsearch/globalsearch.h" #include "globalsearch/globalsearch.h"
#include "globalsearch/librarysearchprovider.h" #include "globalsearch/librarysearchprovider.h"
@ -33,6 +34,7 @@ GoogleDriveService::GoogleDriveService(Application* app, InternetModel* parent)
: InternetService(kServiceName, app, parent, parent), : InternetService(kServiceName, app, parent, parent),
root_(NULL), root_(NULL),
client_(new google_drive::Client(this)), client_(new google_drive::Client(this)),
task_manager_(app->task_manager()),
library_sort_model_(new QSortFilterProxyModel(this)) { library_sort_model_(new QSortFilterProxyModel(this)) {
library_backend_ = new LibraryBackend; library_backend_ = new LibraryBackend;
library_backend_->moveToThread(app_->database()->thread()); library_backend_->moveToThread(app_->database()->thread());
@ -127,6 +129,9 @@ void GoogleDriveService::MaybeAddFileToDatabase(const google_drive::File& file)
return; return;
} }
const int task_id = task_manager_->StartTask(
tr("Indexing %1").arg(file.title()));
// Song not in index; tag and add. // Song not in index; tag and add.
TagReaderClient::ReplyType* reply = app_->tag_reader_client()->ReadGoogleDrive( TagReaderClient::ReplyType* reply = app_->tag_reader_client()->ReadGoogleDrive(
file.download_url(), file.download_url(),
@ -136,15 +141,18 @@ void GoogleDriveService::MaybeAddFileToDatabase(const google_drive::File& file)
client_->access_token()); client_->access_token());
NewClosure(reply, SIGNAL(Finished(bool)), NewClosure(reply, SIGNAL(Finished(bool)),
this, SLOT(ReadTagsFinished(TagReaderClient::ReplyType*,google_drive::File,QString)), this, SLOT(ReadTagsFinished(TagReaderClient::ReplyType*,google_drive::File,QString,int)),
reply, file, url); reply, file, url, task_id);
} }
void GoogleDriveService::ReadTagsFinished(TagReaderClient::ReplyType* reply, void GoogleDriveService::ReadTagsFinished(TagReaderClient::ReplyType* reply,
const google_drive::File& metadata, const google_drive::File& metadata,
const QString& url) { const QString& url,
const int task_id) {
reply->deleteLater(); reply->deleteLater();
TaskManager::ScopedTask(task_id, task_manager_);
const pb::tagreader::ReadGoogleDriveResponse& msg = const pb::tagreader::ReadGoogleDriveResponse& msg =
reply->message().read_google_drive_response(); reply->message().read_google_drive_response();
if (!msg.has_metadata() || !msg.metadata().filesize()) { if (!msg.has_metadata() || !msg.metadata().filesize()) {

View File

@ -10,6 +10,7 @@ class QStandardItem;
class LibraryBackend; class LibraryBackend;
class LibraryModel; class LibraryModel;
class TaskManager;
class QSortFilterProxyModel; class QSortFilterProxyModel;
namespace google_drive { namespace google_drive {
@ -40,7 +41,8 @@ class GoogleDriveService : public InternetService {
void ListFilesFinished(google_drive::ListFilesResponse* response); void ListFilesFinished(google_drive::ListFilesResponse* response);
void ReadTagsFinished(TagReaderClient::ReplyType* reply, void ReadTagsFinished(TagReaderClient::ReplyType* reply,
const google_drive::File& metadata, const google_drive::File& metadata,
const QString& url); const QString& url,
const int task_id);
private: private:
void Connect(); void Connect();
@ -53,6 +55,7 @@ class GoogleDriveService : public InternetService {
google_drive::Client* client_; google_drive::Client* client_;
NetworkAccessManager network_; NetworkAccessManager network_;
TaskManager* task_manager_;
LibraryBackend* library_backend_; LibraryBackend* library_backend_;
LibraryModel* library_model_; LibraryModel* library_model_;