Add a cover manager for the Google Drive library.

This commit is contained in:
John Maguire 2012-10-01 16:39:58 +02:00
parent a7ca176d31
commit 07abe82ef3
5 changed files with 46 additions and 11 deletions

View File

@ -13,10 +13,12 @@
#include "core/player.h" #include "core/player.h"
#include "core/taskmanager.h" #include "core/taskmanager.h"
#include "core/timeconstants.h" #include "core/timeconstants.h"
#include "ui/albumcovermanager.h"
#include "globalsearch/globalsearch.h" #include "globalsearch/globalsearch.h"
#include "globalsearch/librarysearchprovider.h" #include "globalsearch/librarysearchprovider.h"
#include "library/librarybackend.h" #include "library/librarybackend.h"
#include "library/librarymodel.h" #include "library/librarymodel.h"
#include "playlist/playlist.h"
#include "ui/iconloader.h" #include "ui/iconloader.h"
#include "googledriveclient.h" #include "googledriveclient.h"
#include "googledriveurlhandler.h" #include "googledriveurlhandler.h"
@ -39,7 +41,8 @@ GoogleDriveService::GoogleDriveService(Application* app, InternetModel* parent)
root_(NULL), root_(NULL),
client_(new google_drive::Client(this)), client_(new google_drive::Client(this)),
task_manager_(app->task_manager()), task_manager_(app->task_manager()),
library_sort_model_(new QSortFilterProxyModel(this)) { library_sort_model_(new QSortFilterProxyModel(this)),
playlist_manager_(app->playlist_manager()) {
library_backend_ = new LibraryBackend; library_backend_ = new LibraryBackend;
library_backend_->moveToThread(app_->database()->thread()); library_backend_->moveToThread(app_->database()->thread());
library_backend_->Init(app_->database(), kSongsTable, library_backend_->Init(app_->database(), kSongsTable,
@ -245,6 +248,11 @@ void GoogleDriveService::ShowContextMenu(const QPoint& global_pos) {
QIcon(":/providers/googledrive.png"), tr("Open in Google Drive"), QIcon(":/providers/googledrive.png"), tr("Open in Google Drive"),
this, SLOT(OpenWithDrive())); this, SLOT(OpenWithDrive()));
context_menu_->addSeparator(); context_menu_->addSeparator();
context_menu_->addAction(
IconLoader::Load("download"),
tr("Cover Manager"),
this,
SLOT(ShowCoverManager()));
context_menu_->addAction(IconLoader::Load("configure"), context_menu_->addAction(IconLoader::Load("configure"),
tr("Configure..."), tr("Configure..."),
this, SLOT(ShowSettingsDialog())); this, SLOT(ShowSettingsDialog()));
@ -285,3 +293,18 @@ void GoogleDriveService::OpenWithDrive() {
void GoogleDriveService::ShowSettingsDialog() { void GoogleDriveService::ShowSettingsDialog() {
app_->OpenSettingsDialogAtPage(SettingsDialog::Page_GoogleDrive); 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

@ -8,8 +8,10 @@
class QStandardItem; class QStandardItem;
class AlbumCoverManager;
class LibraryBackend; class LibraryBackend;
class LibraryModel; class LibraryModel;
class PlaylistManager;
class TaskManager; class TaskManager;
class QSortFilterProxyModel; class QSortFilterProxyModel;
@ -56,6 +58,8 @@ class GoogleDriveService : public InternetService {
void OpenWithDrive(); void OpenWithDrive();
void ShowSettingsDialog(); void ShowSettingsDialog();
void ShowCoverManager();
void AddToPlaylist(QMimeData* mime);
private: private:
void EnsureConnected(); void EnsureConnected();
@ -73,11 +77,14 @@ class GoogleDriveService : public InternetService {
LibraryBackend* library_backend_; LibraryBackend* library_backend_;
LibraryModel* library_model_; LibraryModel* library_model_;
QSortFilterProxyModel* library_sort_model_; QSortFilterProxyModel* library_sort_model_;
PlaylistManager* playlist_manager_;
int indexing_task_id_; int indexing_task_id_;
boost::scoped_ptr<QMenu> context_menu_; boost::scoped_ptr<QMenu> context_menu_;
QAction* open_in_drive_action_; QAction* open_in_drive_action_;
boost::scoped_ptr<AlbumCoverManager> cover_manager_;
}; };
#endif #endif

View File

@ -51,6 +51,7 @@
const char* AlbumCoverManager::kSettingsGroup = "CoverManager"; const char* AlbumCoverManager::kSettingsGroup = "CoverManager";
AlbumCoverManager::AlbumCoverManager(Application* app, AlbumCoverManager::AlbumCoverManager(Application* app,
LibraryBackend* library_backend,
QWidget* parent, QWidget* parent,
QNetworkAccessManager* network) QNetworkAccessManager* network)
: QMainWindow(parent), : QMainWindow(parent),
@ -63,7 +64,8 @@ AlbumCoverManager::AlbumCoverManager(Application* app,
all_artists_icon_(IconLoader::Load("x-clementine-album")), all_artists_icon_(IconLoader::Load("x-clementine-album")),
context_menu_(new QMenu(this)), context_menu_(new QMenu(this)),
progress_bar_(new QProgressBar(this)), progress_bar_(new QProgressBar(this)),
jobs_(0) jobs_(0),
library_backend_(library_backend)
{ {
ui_->setupUi(this); ui_->setupUi(this);
ui_->albums->set_cover_manager(this); ui_->albums->set_cover_manager(this);
@ -110,7 +112,7 @@ AlbumCoverManager::~AlbumCoverManager() {
} }
LibraryBackend* AlbumCoverManager::backend() const { LibraryBackend* AlbumCoverManager::backend() const {
return app_->library_backend(); return library_backend_;
} }
void AlbumCoverManager::Init() { void AlbumCoverManager::Init() {
@ -244,7 +246,7 @@ void AlbumCoverManager::Reset() {
new QListWidgetItem(all_artists_icon_, tr("All artists"), ui_->artists, All_Artists); new QListWidgetItem(all_artists_icon_, tr("All artists"), ui_->artists, All_Artists);
new QListWidgetItem(artist_icon_, tr("Various artists"), ui_->artists, Various_Artists); new QListWidgetItem(artist_icon_, tr("Various artists"), ui_->artists, Various_Artists);
QStringList artists(app_->library_backend()->GetAllArtistsWithAlbums()); QStringList artists(library_backend_->GetAllArtistsWithAlbums());
qStableSort(artists.begin(), artists.end(), CompareNocase); qStableSort(artists.begin(), artists.end(), CompareNocase);
foreach (const QString& artist, artists) { foreach (const QString& artist, artists) {
@ -275,10 +277,10 @@ void AlbumCoverManager::ArtistChanged(QListWidgetItem* current) {
// selected in the artist list. // selected in the artist list.
LibraryBackend::AlbumList albums; LibraryBackend::AlbumList albums;
switch (current->type()) { switch (current->type()) {
case Various_Artists: albums = app_->library_backend()->GetCompilationAlbums(); break; case Various_Artists: albums = library_backend_->GetCompilationAlbums(); break;
case Specific_Artist: albums = app_->library_backend()->GetAlbumsByArtist(current->text()); break; case Specific_Artist: albums = library_backend_->GetAlbumsByArtist(current->text()); break;
case All_Artists: case All_Artists:
default: albums = app_->library_backend()->GetAllAlbums(); break; default: albums = library_backend_->GetAllAlbums(); break;
} }
// Sort by album name. The list is already sorted by sqlite but it was done // Sort by album name. The list is already sorted by sqlite but it was done
@ -634,7 +636,7 @@ SongList AlbumCoverManager::GetSongsInAlbum(const QModelIndex& index) const {
if (!artist.isEmpty()) if (!artist.isEmpty())
q.AddWhere("artist", artist); q.AddWhere("artist", artist);
if (!app_->library_backend()->ExecQuery(&q)) if (!library_backend_->ExecQuery(&q))
return ret; return ret;
while (q.Next()) { while (q.Next()) {
@ -659,7 +661,7 @@ SongMimeData* AlbumCoverManager::GetMimeDataForAlbums(const QModelIndexList& ind
return NULL; return NULL;
SongMimeData* data = new SongMimeData; SongMimeData* data = new SongMimeData;
data->backend = app_->library_backend(); data->backend = library_backend_;
data->songs = songs; data->songs = songs;
return data; return data;
} }
@ -691,7 +693,7 @@ void AlbumCoverManager::SaveAndSetCover(QListWidgetItem *item, const QImage &ima
QString path = album_cover_choice_controller_->SaveCoverInCache(artist, album, image); QString path = album_cover_choice_controller_->SaveCoverInCache(artist, album, image);
// Save the image in the database // Save the image in the database
app_->library_backend()->UpdateManualAlbumArtAsync(artist, album, path); library_backend_->UpdateManualAlbumArtAsync(artist, album, path);
// Update the icon in our list // Update the icon in our list
quint64 id = app_->album_cover_loader()->LoadImageAsync( quint64 id = app_->album_cover_loader()->LoadImageAsync(

View File

@ -45,6 +45,7 @@ class AlbumCoverManager : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
AlbumCoverManager(Application* app, AlbumCoverManager(Application* app,
LibraryBackend* library_backend,
QWidget* parent = 0, QWidget* parent = 0,
QNetworkAccessManager* network = 0); QNetworkAccessManager* network = 0);
~AlbumCoverManager(); ~AlbumCoverManager();
@ -168,6 +169,8 @@ class AlbumCoverManager : public QMainWindow {
QProgressBar* progress_bar_; QProgressBar* progress_bar_;
int jobs_; int jobs_;
LibraryBackend* library_backend_;
FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithCover); FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithCover);
FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithoutCover); FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithoutCover);
FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithFilter); FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithFilter);

View File

@ -1902,7 +1902,7 @@ void MainWindow::ChangeLibraryQueryMode(QAction* action) {
void MainWindow::ShowCoverManager() { void MainWindow::ShowCoverManager() {
if (!cover_manager_) { if (!cover_manager_) {
cover_manager_.reset(new AlbumCoverManager(app_)); cover_manager_.reset(new AlbumCoverManager(app_, app_->library_backend()));
cover_manager_->Init(); cover_manager_->Init();
// Cover manager connections // Cover manager connections