2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine .
* Copyright 2010 , David Sansome < me @ davidsansome . com >
2021-03-20 21:14:47 +01:00
* Copyright 2018 - 2021 , Jonas Kvinge < jonas @ jkvinge . net >
2018-02-27 18:06:05 +01:00
*
* Strawberry 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 .
*
* Strawberry 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 Strawberry . If not , see < http : //www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
# ifndef ALBUMCOVERMANAGER_H
# define ALBUMCOVERMANAGER_H
# include "config.h"
2018-05-01 00:41:33 +02:00
# include <QtGlobal>
2018-02-27 18:06:05 +01:00
# include <QMainWindow>
2020-02-08 15:03:11 +01:00
# include <QObject>
2018-05-01 00:41:33 +02:00
# include <QAbstractItemModel>
# include <QList>
# include <QListWidgetItem>
# include <QMap>
2021-02-26 21:03:51 +01:00
# include <QMultiMap>
2018-05-01 00:41:33 +02:00
# include <QString>
# include <QImage>
2018-02-27 18:06:05 +01:00
# include <QIcon>
# include "core/song.h"
2018-05-01 00:41:33 +02:00
# include "albumcoverloaderoptions.h"
2020-04-20 18:03:18 +02:00
# include "albumcoverloaderresult.h"
2021-02-26 21:03:51 +01:00
# include "albumcoverchoicecontroller.h"
2018-05-01 00:41:33 +02:00
# include "coversearchstatistics.h"
2021-02-26 21:03:51 +01:00
# include "settings/collectionsettingspage.h"
2018-02-27 18:06:05 +01:00
2020-02-08 15:03:11 +01:00
class QWidget ;
class QMimeData ;
class QMenu ;
class QAction ;
class QProgressBar ;
class QPushButton ;
class QEvent ;
class QCloseEvent ;
class QShowEvent ;
2018-05-01 00:41:33 +02:00
class Application ;
class CollectionBackend ;
class SongMimeData ;
2018-02-27 18:06:05 +01:00
class AlbumCoverExport ;
class AlbumCoverExporter ;
class AlbumCoverFetcher ;
class AlbumCoverSearcher ;
2018-05-01 00:41:33 +02:00
class Ui_CoverManager ;
2018-02-27 18:06:05 +01:00
2021-02-26 21:03:51 +01:00
class AlbumItem : public QListWidgetItem {
public :
AlbumItem ( const QIcon & icon , const QString & text , QListWidget * parent = nullptr , int type = Type ) : QListWidgetItem ( icon , text , parent , type ) { } ;
QList < QUrl > urls ;
2021-06-20 19:04:08 +02:00
private :
Q_DISABLE_COPY ( AlbumItem )
2021-02-26 21:03:51 +01:00
} ;
2018-02-27 18:06:05 +01:00
class AlbumCoverManager : public QMainWindow {
Q_OBJECT
2021-02-26 21:03:51 +01:00
2018-02-27 18:06:05 +01:00
public :
2020-04-06 22:30:03 +02:00
explicit AlbumCoverManager ( Application * app , CollectionBackend * collection_backend , QMainWindow * mainwindow , QWidget * parent = nullptr ) ;
2020-06-15 21:55:05 +02:00
~ AlbumCoverManager ( ) override ;
2018-02-27 18:06:05 +01:00
static const char * kSettingsGroup ;
void Reset ( ) ;
void Init ( ) ;
void EnableCoversButtons ( ) ;
void DisableCoversButtons ( ) ;
2021-01-26 16:48:04 +01:00
SongList GetSongsInAlbum ( const QModelIndex & idx ) const ;
2021-02-26 21:03:51 +01:00
CollectionBackend * backend ( ) const { return collection_backend_ ; }
2018-02-27 18:06:05 +01:00
protected :
2021-02-26 21:03:51 +01:00
void showEvent ( QShowEvent * e ) override ;
void closeEvent ( QCloseEvent * e ) override ;
2018-02-27 18:06:05 +01:00
// For the album view context menu events
2021-02-26 21:03:51 +01:00
bool eventFilter ( QObject * obj , QEvent * e ) override ;
2018-02-27 18:06:05 +01:00
private :
enum ArtistItemType {
All_Artists ,
Various_Artists ,
Specific_Artist
} ;
enum Role {
2021-02-26 21:03:51 +01:00
Role_AlbumArtist = Qt : : UserRole + 1 ,
Role_Album ,
2018-02-27 18:06:05 +01:00
Role_PathAutomatic ,
Role_PathManual ,
2021-02-26 21:03:51 +01:00
Role_Filetype ,
Role_CuePath ,
Role_ImageData ,
Role_Image
2018-02-27 18:06:05 +01:00
} ;
enum HideCovers {
Hide_None ,
Hide_WithCovers ,
Hide_WithoutCovers
} ;
2020-04-06 22:30:03 +02:00
void LoadGeometry ( ) ;
2021-02-26 21:03:51 +01:00
void SaveSettings ( ) ;
2020-04-06 22:30:03 +02:00
2018-02-27 18:06:05 +01:00
QString InitialPathForOpenCoverDialog ( const QString & path_automatic , const QString & first_file_name ) const ;
2018-05-01 00:41:33 +02:00
// Returns the selected element in form of a Song ready to be used by AlbumCoverChoiceController or invalid song if there's nothing or multiple elements selected.
2018-02-27 18:06:05 +01:00
Song GetSingleSelectionAsSong ( ) ;
2018-05-01 00:41:33 +02:00
// 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.
2018-02-27 18:06:05 +01:00
Song GetFirstSelectedAsSong ( ) ;
2021-02-26 21:03:51 +01:00
Song ItemAsSong ( QListWidgetItem * item ) { return ItemAsSong ( static_cast < AlbumItem * > ( item ) ) ; }
2021-06-22 13:41:38 +02:00
static Song ItemAsSong ( AlbumItem * item ) ;
2018-02-27 18:06:05 +01:00
void UpdateStatusText ( ) ;
2021-02-26 21:03:51 +01:00
bool ShouldHide ( const AlbumItem & item , const QString & filter , HideCovers hide ) const ;
void SaveAndSetCover ( AlbumItem * item , const AlbumCoverImageResult & result ) ;
void SaveImageToAlbums ( Song * song , const AlbumCoverImageResult & result ) ;
SongList GetSongsInAlbums ( const QModelIndexList & indexes ) const ;
SongMimeData * GetMimeDataForAlbums ( const QModelIndexList & indexes ) const ;
bool ItemHasCover ( const AlbumItem & item ) const ;
2018-02-27 18:06:05 +01:00
2020-04-06 22:30:03 +02:00
signals :
void AddToPlaylist ( QMimeData * data ) ;
private slots :
void ArtistChanged ( QListWidgetItem * current ) ;
2020-04-20 18:03:18 +02:00
void AlbumCoverLoaded ( const quint64 id , const AlbumCoverLoaderResult & result ) ;
2020-04-06 22:30:03 +02:00
void UpdateFilter ( ) ;
void FetchAlbumCovers ( ) ;
void ExportCovers ( ) ;
2021-02-26 21:03:51 +01:00
void AlbumCoverFetched ( const quint64 id , const AlbumCoverImageResult & result , const CoverSearchStatistics & statistics ) ;
2020-04-06 22:30:03 +02:00
void CancelRequests ( ) ;
// On the context menu
void FetchSingleCover ( ) ;
void LoadCoverFromFile ( ) ;
void SaveCoverToFile ( ) ;
void LoadCoverFromURL ( ) ;
void SearchForCover ( ) ;
void UnsetCover ( ) ;
2021-02-26 21:03:51 +01:00
void ClearCover ( ) ;
void DeleteCover ( ) ;
2020-04-06 22:30:03 +02:00
void ShowCover ( ) ;
// For adding albums to the playlist
2020-12-07 17:23:08 +01:00
void AlbumDoubleClicked ( const QModelIndex & idx ) ;
2020-04-06 22:30:03 +02:00
void AddSelectedToPlaylist ( ) ;
void LoadSelectedToPlaylist ( ) ;
2021-02-26 21:03:51 +01:00
void UpdateCoverInList ( AlbumItem * item , const QUrl & cover ) ;
2020-06-14 18:58:24 +02:00
void UpdateExportStatus ( const int exported , const int skipped , const int max ) ;
2020-04-06 22:30:03 +02:00
2021-02-26 21:03:51 +01:00
void SaveEmbeddedCoverAsyncFinished ( quint64 id , const bool success ) ;
2018-02-27 18:06:05 +01:00
private :
Ui_CoverManager * ui_ ;
2020-04-06 22:30:03 +02:00
QMainWindow * mainwindow_ ;
2018-02-27 18:06:05 +01:00
Application * app_ ;
2021-02-26 21:03:51 +01:00
CollectionBackend * collection_backend_ ;
2018-02-27 18:06:05 +01:00
AlbumCoverChoiceController * album_cover_choice_controller_ ;
QAction * filter_all_ ;
QAction * filter_with_covers_ ;
QAction * filter_without_covers_ ;
AlbumCoverLoaderOptions cover_loader_options_ ;
2021-02-26 21:03:51 +01:00
QMap < quint64 , AlbumItem * > cover_loading_tasks_ ;
2018-02-27 18:06:05 +01:00
AlbumCoverFetcher * cover_fetcher_ ;
2021-02-26 21:03:51 +01:00
QMap < quint64 , AlbumItem * > cover_fetching_tasks_ ;
2018-02-27 18:06:05 +01:00
CoverSearchStatistics fetch_statistics_ ;
AlbumCoverSearcher * cover_searcher_ ;
AlbumCoverExport * cover_export_ ;
AlbumCoverExporter * cover_exporter_ ;
QIcon artist_icon_ ;
QIcon all_artists_icon_ ;
2021-02-26 21:03:51 +01:00
const QImage image_nocover_thumbnail_ ;
const QIcon icon_nocover_item_ ;
2018-02-27 18:06:05 +01:00
QMenu * context_menu_ ;
QList < QListWidgetItem * > context_menu_items_ ;
QProgressBar * progress_bar_ ;
QPushButton * abort_progress_ ;
int jobs_ ;
2021-02-26 21:03:51 +01:00
QMultiMap < qint64 , AlbumItem * > cover_save_tasks_ ;
QList < AlbumItem * > cover_save_tasks2_ ;
QListWidgetItem * all_artists_ ;
2018-02-27 18:06:05 +01:00
} ;
# endif // ALBUMCOVERMANAGER_H