2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
#ifndef ALBUMCOVERMANAGER_H
|
|
|
|
#define ALBUMCOVERMANAGER_H
|
|
|
|
|
2010-06-12 00:35:41 +02:00
|
|
|
#include <QMainWindow>
|
2010-02-28 19:04:50 +01:00
|
|
|
#include <QIcon>
|
2010-06-12 17:18:16 +02:00
|
|
|
#include <QModelIndex>
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2010-03-26 13:22:19 +01:00
|
|
|
#include "gtest/gtest_prod.h"
|
|
|
|
|
2010-06-12 17:18:16 +02:00
|
|
|
#include "core/song.h"
|
2012-02-13 21:44:04 +01:00
|
|
|
#include "covers/albumcoverloaderoptions.h"
|
2011-06-26 17:07:48 +02:00
|
|
|
#include "covers/coversearchstatistics.h"
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2011-01-24 01:09:57 +01:00
|
|
|
class AlbumCoverChoiceController;
|
2013-05-06 21:22:05 +02:00
|
|
|
class AlbumCoverExport;
|
|
|
|
class AlbumCoverExporter;
|
2010-02-28 20:25:52 +01:00
|
|
|
class AlbumCoverFetcher;
|
2010-06-12 19:13:01 +02:00
|
|
|
class AlbumCoverSearcher;
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2010-12-14 16:00:46 +01:00
|
|
|
class LibraryBackend;
|
2011-01-10 23:26:13 +01:00
|
|
|
class SongMimeData;
|
2010-05-10 23:50:31 +02:00
|
|
|
class Ui_CoverManager;
|
|
|
|
|
|
|
|
class QListWidgetItem;
|
|
|
|
class QMenu;
|
2010-10-16 20:21:28 +02:00
|
|
|
class QNetworkAccessManager;
|
2013-05-06 21:22:05 +02:00
|
|
|
class QPushButton;
|
2010-06-12 01:07:53 +02:00
|
|
|
class QProgressBar;
|
2010-03-03 21:35:19 +01:00
|
|
|
|
2010-06-12 00:35:41 +02:00
|
|
|
class AlbumCoverManager : public QMainWindow {
|
2010-02-28 19:04:50 +01:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-07 16:34:20 +01:00
|
|
|
AlbumCoverManager(Application* app, LibraryBackend* library_backend,
|
2017-03-04 00:16:27 +01:00
|
|
|
QWidget* parent = nullptr,
|
|
|
|
QNetworkAccessManager* network = 0);
|
2010-02-28 20:25:52 +01:00
|
|
|
~AlbumCoverManager();
|
2010-02-28 19:04:50 +01:00
|
|
|
|
|
|
|
static const char* kSettingsGroup;
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
LibraryBackend* backend() const;
|
2010-06-12 19:13:01 +02:00
|
|
|
QIcon no_cover_icon() const { return no_cover_icon_; }
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2010-06-12 17:18:16 +02:00
|
|
|
void Reset();
|
2010-03-26 13:22:19 +01:00
|
|
|
void Init();
|
|
|
|
|
2013-05-06 21:22:05 +02:00
|
|
|
void EnableCoversButtons();
|
|
|
|
void DisableCoversButtons();
|
2011-04-27 21:36:42 +02:00
|
|
|
|
2010-06-12 17:18:16 +02:00
|
|
|
SongList GetSongsInAlbum(const QModelIndex& index) const;
|
|
|
|
SongList GetSongsInAlbums(const QModelIndexList& indexes) const;
|
2011-01-10 23:26:13 +01:00
|
|
|
SongMimeData* GetMimeDataForAlbums(const QModelIndexList& indexes) const;
|
2010-06-12 17:18:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
signals:
|
2011-01-10 23:26:13 +01:00
|
|
|
void AddToPlaylist(QMimeData* data);
|
2010-06-12 17:18:16 +02:00
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
protected:
|
2014-02-07 16:34:20 +01:00
|
|
|
void showEvent(QShowEvent*);
|
|
|
|
void closeEvent(QCloseEvent*);
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2010-03-03 15:29:53 +01:00
|
|
|
// For the album view context menu events
|
2014-02-07 16:34:20 +01:00
|
|
|
bool eventFilter(QObject* obj, QEvent* event);
|
2010-03-03 15:29:53 +01:00
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
private slots:
|
|
|
|
void ArtistChanged(QListWidgetItem* current);
|
|
|
|
void CoverImageLoaded(quint64 id, const QImage& image);
|
|
|
|
void UpdateFilter();
|
2010-02-28 20:25:52 +01:00
|
|
|
void FetchAlbumCovers();
|
2013-05-06 21:22:05 +02:00
|
|
|
void ExportCovers();
|
2011-06-26 17:07:48 +02:00
|
|
|
void AlbumCoverFetched(quint64 id, const QImage& image,
|
|
|
|
const CoverSearchStatistics& statistics);
|
2013-05-06 21:22:05 +02:00
|
|
|
void CancelRequests();
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2010-03-03 15:29:53 +01:00
|
|
|
// On the context menu
|
|
|
|
void FetchSingleCover();
|
2011-01-24 01:09:57 +01:00
|
|
|
|
|
|
|
void LoadCoverFromFile();
|
2011-02-02 17:22:04 +01:00
|
|
|
void SaveCoverToFile();
|
2011-01-24 01:09:57 +01:00
|
|
|
void LoadCoverFromURL();
|
|
|
|
void SearchForCover();
|
2010-03-03 15:29:53 +01:00
|
|
|
void UnsetCover();
|
2011-01-24 01:09:57 +01:00
|
|
|
void ShowCover();
|
2010-03-03 15:29:53 +01:00
|
|
|
|
2010-06-12 17:18:16 +02:00
|
|
|
// For adding albums to the playlist
|
|
|
|
void AlbumDoubleClicked(const QModelIndex& index);
|
|
|
|
void AddSelectedToPlaylist();
|
|
|
|
void LoadSelectedToPlaylist();
|
|
|
|
|
2011-01-24 18:53:31 +01:00
|
|
|
void UpdateCoverInList(QListWidgetItem* item, const QString& cover);
|
2013-05-06 21:22:05 +02:00
|
|
|
void UpdateExportStatus(int exported, int bad, int count);
|
2011-01-24 18:53:31 +01:00
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
private:
|
2017-03-04 00:16:27 +01:00
|
|
|
enum ArtistItemType {
|
|
|
|
All_Artists,
|
|
|
|
Various_Artists,
|
|
|
|
Specific_Artist,
|
|
|
|
};
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2010-02-28 20:25:52 +01:00
|
|
|
enum Role {
|
|
|
|
Role_ArtistName = Qt::UserRole + 1,
|
2017-03-04 00:16:27 +01:00
|
|
|
Role_AlbumArtistName,
|
2010-02-28 20:25:52 +01:00
|
|
|
Role_AlbumName,
|
2010-03-03 15:29:53 +01:00
|
|
|
Role_PathAutomatic,
|
|
|
|
Role_PathManual,
|
2011-04-28 14:27:53 +02:00
|
|
|
Role_FirstUrl,
|
2010-02-28 20:25:52 +01:00
|
|
|
};
|
|
|
|
|
2017-03-04 00:16:27 +01:00
|
|
|
enum HideCovers {
|
|
|
|
Hide_None,
|
|
|
|
Hide_WithCovers,
|
|
|
|
Hide_WithoutCovers,
|
|
|
|
};
|
2010-03-26 13:22:19 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QString InitialPathForOpenCoverDialog(const QString& path_automatic,
|
|
|
|
const QString& first_file_name) const;
|
2010-12-15 21:15:46 +01:00
|
|
|
|
2017-03-06 19:41:29 +01:00
|
|
|
QString EffectiveAlbumArtistName(const QListWidgetItem& item) const;
|
2017-03-04 00:16:27 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Returns the selected element in form of a Song ready to be used
|
2011-01-24 01:09:57 +01:00
|
|
|
// by AlbumCoverChoiceController or invalid song if there's nothing
|
|
|
|
// or multiple elements selected.
|
|
|
|
Song GetSingleSelectionAsSong();
|
|
|
|
// Returns the first of the selected elements in form of a Song ready
|
|
|
|
// to be used by AlbumCoverChoiceController or invalid song if there's nothing
|
|
|
|
// selected.
|
|
|
|
Song GetFirstSelectedAsSong();
|
|
|
|
|
|
|
|
Song ItemAsSong(QListWidgetItem* item);
|
|
|
|
|
2010-06-12 01:07:53 +02:00
|
|
|
void UpdateStatusText();
|
2014-02-07 16:34:20 +01:00
|
|
|
bool ShouldHide(const QListWidgetItem& item, const QString& filter,
|
|
|
|
HideCovers hide) const;
|
2010-06-12 19:13:01 +02:00
|
|
|
void SaveAndSetCover(QListWidgetItem* item, const QImage& image);
|
2010-03-26 13:22:19 +01:00
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
private:
|
2010-05-10 23:50:31 +02:00
|
|
|
Ui_CoverManager* ui_;
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2011-01-24 01:09:57 +01:00
|
|
|
|
|
|
|
AlbumCoverChoiceController* album_cover_choice_controller_;
|
2010-02-28 19:04:50 +01:00
|
|
|
|
|
|
|
QAction* filter_all_;
|
|
|
|
QAction* filter_with_covers_;
|
|
|
|
QAction* filter_without_covers_;
|
|
|
|
|
2012-02-13 21:44:04 +01:00
|
|
|
AlbumCoverLoaderOptions cover_loader_options_;
|
2010-02-28 19:04:50 +01:00
|
|
|
QMap<quint64, QListWidgetItem*> cover_loading_tasks_;
|
|
|
|
|
2010-02-28 20:25:52 +01:00
|
|
|
AlbumCoverFetcher* cover_fetcher_;
|
|
|
|
QMap<quint64, QListWidgetItem*> cover_fetching_tasks_;
|
2011-06-26 17:07:48 +02:00
|
|
|
CoverSearchStatistics fetch_statistics_;
|
2010-02-28 20:25:52 +01:00
|
|
|
|
2010-06-12 19:13:01 +02:00
|
|
|
AlbumCoverSearcher* cover_searcher_;
|
2013-05-06 21:22:05 +02:00
|
|
|
AlbumCoverExport* cover_export_;
|
|
|
|
AlbumCoverExporter* cover_exporter_;
|
2010-06-12 19:13:01 +02:00
|
|
|
|
2017-03-04 04:16:55 +01:00
|
|
|
QImage GenerateNoCoverImage(const QIcon& no_cover_icon) const;
|
2017-03-06 19:09:01 +01:00
|
|
|
bool ItemHasCover(const QListWidgetItem& item) const;
|
2017-03-04 04:16:55 +01:00
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
QIcon artist_icon_;
|
|
|
|
QIcon all_artists_icon_;
|
2017-03-04 04:16:55 +01:00
|
|
|
const QIcon no_cover_icon_;
|
|
|
|
const QImage no_cover_image_;
|
|
|
|
const QIcon no_cover_item_icon_;
|
2010-03-03 15:29:53 +01:00
|
|
|
|
|
|
|
QMenu* context_menu_;
|
|
|
|
QList<QListWidgetItem*> context_menu_items_;
|
2010-03-26 13:22:19 +01:00
|
|
|
|
2010-06-12 01:07:53 +02:00
|
|
|
QProgressBar* progress_bar_;
|
2013-05-06 21:22:05 +02:00
|
|
|
QPushButton* abort_progress_;
|
2010-06-12 01:07:53 +02:00
|
|
|
int jobs_;
|
|
|
|
|
2012-10-01 16:39:58 +02:00
|
|
|
LibraryBackend* library_backend_;
|
|
|
|
|
2010-03-26 13:22:19 +01:00
|
|
|
FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithCover);
|
|
|
|
FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithoutCover);
|
|
|
|
FRIEND_TEST(AlbumCoverManagerTest, HidesItemsWithFilter);
|
2010-02-28 19:04:50 +01:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // ALBUMCOVERMANAGER_H
|