1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-30 19:15:08 +01:00

Refactor GoogleDriveService into a CloudFileService.

This commit is contained in:
John Maguire 2012-11-28 16:21:14 +01:00
parent 334cd1052b
commit db7679abe6
3 changed files with 14 additions and 107 deletions

View File

@ -29,64 +29,24 @@ const char* GoogleDriveService::kSettingsGroup = "GoogleDrive";
namespace {
static const char* kSongsTable = "google_drive_songs";
static const char* kFtsTable = "google_drive_songs_fts";
static const char* kDriveEditFileUrl = "https://docs.google.com/file/d/%1/edit";
static const char* kServiceId = "google_drive";
}
GoogleDriveService::GoogleDriveService(Application* app, InternetModel* parent)
: InternetService(kServiceName, app, parent, parent),
root_(NULL),
client_(new google_drive::Client(this)),
task_manager_(app->task_manager()),
library_sort_model_(new QSortFilterProxyModel(this)),
playlist_manager_(app->playlist_manager()) {
library_backend_ = new LibraryBackend;
library_backend_->moveToThread(app_->database()->thread());
library_backend_->Init(app_->database(), kSongsTable,
QString::null, QString::null, kFtsTable);
library_model_ = new LibraryModel(library_backend_, app_, this);
library_sort_model_->setSourceModel(library_model_);
library_sort_model_->setSortRole(LibraryModel::Role_SortText);
library_sort_model_->setDynamicSortFilter(true);
library_sort_model_->sort(0);
: CloudFileService(
app, parent,
kServiceName, kServiceId,
QIcon(":/providers/googledrive.png"),
SettingsDialog::Page_GoogleDrive),
client_(new google_drive::Client(this)) {
app->player()->RegisterUrlHandler(new GoogleDriveUrlHandler(this, this));
app->global_search()->AddProvider(new LibrarySearchProvider(
library_backend_,
tr("Google Drive"),
"google_drive",
QIcon(":/providers/googledrive.png"),
true, app_, this));
}
GoogleDriveService::~GoogleDriveService() {
}
QStandardItem* GoogleDriveService::CreateRootItem() {
root_ = new QStandardItem(QIcon(":providers/googledrive.png"), "Google Drive");
root_->setData(true, InternetModel::Role_CanLazyLoad);
return root_;
}
void GoogleDriveService::LazyPopulate(QStandardItem* item) {
switch (item->data(InternetModel::Role_Type).toInt()) {
case InternetModel::Type_Service:
if (refresh_token().isEmpty()) {
ShowSettingsDialog();
} else if (!client_->is_authenticated()) {
Connect();
}
library_model_->Init();
model()->merged_model()->AddSubModel(item->index(), library_sort_model_);
break;
default:
break;
}
bool GoogleDriveService::has_credentials() const {
return !refresh_token().isEmpty();
}
QString GoogleDriveService::refresh_token() const {
@ -290,22 +250,3 @@ void GoogleDriveService::OpenWithDrive() {
QUrl(QString(kDriveEditFileUrl).arg(song.url().path())));
}
}
void GoogleDriveService::ShowSettingsDialog() {
app_->OpenSettingsDialogAtPage(SettingsDialog::Page_GoogleDrive);
}
void GoogleDriveService::ShowCoverManager() {
if (!cover_manager_) {
cover_manager_.reset(new AlbumCoverManager(app_, library_backend_));
cover_manager_->Init();
connect(cover_manager_.get(), SIGNAL(AddToPlaylist(QMimeData*)), SLOT(AddToPlaylist(QMimeData*)));
}
cover_manager_->show();
}
void GoogleDriveService::AddToPlaylist(QMimeData* mime) {
playlist_manager_->current()->dropMimeData(
mime, Qt::CopyAction, -1, 0, QModelIndex());
}

View File

@ -1,20 +1,10 @@
#ifndef GOOGLEDRIVESERVICE_H
#define GOOGLEDRIVESERVICE_H
#include "internetservice.h"
#include "cloudfileservice.h"
#include "core/network.h"
#include "core/tagreaderclient.h"
class QStandardItem;
class AlbumCoverManager;
class LibraryBackend;
class LibraryModel;
class PlaylistManager;
class TaskManager;
class QSortFilterProxyModel;
namespace google_drive {
class Client;
class ConnectResponse;
@ -22,22 +12,20 @@ namespace google_drive {
class ListFilesResponse;
}
class GoogleDriveService : public InternetService {
class GoogleDriveService : public CloudFileService {
Q_OBJECT
public:
GoogleDriveService(Application* app, InternetModel* parent);
~GoogleDriveService();
static const char* kServiceName;
static const char* kSettingsGroup;
virtual bool has_credentials() const;
virtual void ShowContextMenu(const QPoint& global_pos);
google_drive::Client* client() const { return client_; }
QString refresh_token() const;
QStandardItem* CreateRootItem();
void LazyPopulate(QStandardItem* item);
void ShowContextMenu(const QPoint& global_pos);
QUrl GetStreamingUrlFromSongId(const QString& file_id);
public slots:
@ -57,9 +45,6 @@ class GoogleDriveService : public InternetService {
const int task_id);
void OpenWithDrive();
void ShowSettingsDialog();
void ShowCoverManager();
void AddToPlaylist(QMimeData* mime);
private:
void EnsureConnected();
@ -67,24 +52,13 @@ class GoogleDriveService : public InternetService {
void MaybeAddFileToDatabase(const google_drive::File& file);
void ListFilesForMimeType(const QString& mime_type);
QStandardItem* root_;
google_drive::Client* client_;
NetworkAccessManager network_;
TaskManager* task_manager_;
LibraryBackend* library_backend_;
LibraryModel* library_model_;
QSortFilterProxyModel* library_sort_model_;
PlaylistManager* playlist_manager_;
int indexing_task_id_;
boost::scoped_ptr<QMenu> context_menu_;
QAction* open_in_drive_action_;
boost::scoped_ptr<AlbumCoverManager> cover_manager_;
};
#endif

View File

@ -3,17 +3,9 @@
#include "internet/cloudfileservice.h"
#include <QMenu>
#include "core/tagreaderclient.h"
#include "ui/albumcovermanager.h"
class LibraryBackend;
class LibraryModel;
class NetworkAccessManager;
class PlaylistManager;
class QNetworkReply;
class QSortFilterProxyModel;
class UbuntuOneAuthenticator;
class UbuntuOneService : public CloudFileService {