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 2019 - 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 ALBUMCOVERCHOICECONTROLLER_H
# define ALBUMCOVERCHOICECONTROLLER_H
# include "config.h"
2018-05-01 00:41:33 +02:00
# include <QtGlobal>
# include <QObject>
2018-02-27 18:06:05 +01:00
# include <QWidget>
2021-02-26 21:03:51 +01:00
# include <QPair>
2020-02-09 02:29:35 +01:00
# include <QSet>
2018-05-01 00:41:33 +02:00
# include <QList>
# include <QMap>
2021-02-26 21:03:51 +01:00
# include <QByteArray>
2018-05-01 00:41:33 +02:00
# include <QString>
2020-02-09 02:29:35 +01:00
# include <QUrl>
2018-05-01 00:41:33 +02:00
# include <QImage>
2021-02-26 21:03:51 +01:00
# include <QMutex>
2018-02-27 18:06:05 +01:00
2020-02-09 02:29:35 +01:00
# include "core/song.h"
2019-03-11 23:07:11 +01:00
# include "settings/collectionsettingspage.h"
2021-02-26 21:03:51 +01:00
# include "albumcoverimageresult.h"
2019-03-11 23:07:11 +01:00
2020-02-09 02:29:35 +01:00
class QFileDialog ;
class QAction ;
2021-02-26 21:03:51 +01:00
class QActionGroup ;
class QMenu ;
2020-02-09 02:29:35 +01:00
class QDragEnterEvent ;
class QDropEvent ;
2018-05-01 00:41:33 +02:00
class Application ;
2018-02-27 18:06:05 +01:00
class AlbumCoverFetcher ;
class AlbumCoverSearcher ;
class CoverFromURLDialog ;
struct CoverSearchStatistics ;
// Controller for the common album cover related menu options.
class AlbumCoverChoiceController : public QWidget {
Q_OBJECT
public :
static const char * kLoadImageFileFilter ;
static const char * kSaveImageFileFilter ;
static const char * kAllFilesFilter ;
2020-04-07 16:49:15 +02:00
explicit AlbumCoverChoiceController ( QWidget * parent = nullptr ) ;
2020-06-15 21:55:05 +02:00
~ AlbumCoverChoiceController ( ) override ;
2018-02-27 18:06:05 +01:00
2019-07-07 21:14:24 +02:00
void Init ( Application * app ) ;
2019-03-11 23:07:11 +01:00
void ReloadSettings ( ) ;
2018-02-27 18:06:05 +01:00
2021-02-26 21:03:51 +01:00
CollectionSettingsPage : : SaveCoverType get_save_album_cover_type ( ) const { return ( save_embedded_cover_override_ ? CollectionSettingsPage : : SaveCoverType_Embedded : save_cover_type_ ) ; }
2021-02-27 01:32:45 +01:00
CollectionSettingsPage : : SaveCoverType get_collection_save_album_cover_type ( ) const { return save_cover_type_ ; }
2021-02-26 21:03:51 +01:00
2018-02-27 18:06:05 +01:00
// Getters for all QActions implemented by this controller.
QAction * cover_from_file_action ( ) const { return cover_from_file_ ; }
QAction * cover_to_file_action ( ) const { return cover_to_file_ ; }
QAction * cover_from_url_action ( ) const { return cover_from_url_ ; }
QAction * search_for_cover_action ( ) const { return search_for_cover_ ; }
QAction * unset_cover_action ( ) const { return unset_cover_ ; }
2021-02-26 21:03:51 +01:00
QAction * delete_cover_action ( ) const { return delete_cover_ ; }
QAction * clear_cover_action ( ) const { return clear_cover_ ; }
2018-02-27 18:06:05 +01:00
QAction * show_cover_action ( ) const { return show_cover_ ; }
QAction * search_cover_auto_action ( ) const { return search_cover_auto_ ; }
// Returns QAction* for every operation implemented by this controller.
// The list contains QAction* for:
// 1. loading cover from file
// 2. loading cover from URL
// 3. searching for cover using last.fm
// 4. unsetting the cover manually
// 5. showing the cover in original size
QList < QAction * > GetAllActions ( ) ;
2018-05-01 00:41:33 +02:00
// All of the methods below require a currently selected song as an input parameter.
// Also - LoadCoverFromFile, LoadCoverFromURL, SearchForCover, UnsetCover and SaveCover all update manual path of the given song in collection to the new cover.
2018-02-27 18:06:05 +01:00
2018-05-01 00:41:33 +02:00
// Lets the user choose a cover from disk. If no cover will be chosen or the chosen cover will not be a proper image, this returns an empty string.
// Otherwise, the path to the chosen cover will be returned.
2021-02-26 21:03:51 +01:00
AlbumCoverImageResult LoadImageFromFile ( Song * song ) ;
2019-07-07 21:14:24 +02:00
QUrl LoadCoverFromFile ( Song * song ) ;
2018-02-27 18:06:05 +01:00
2018-05-01 00:41:33 +02:00
// Shows a dialog that allows user to save the given image on disk.
// The image is supposed to be the cover of the given song's album.
2021-02-26 21:03:51 +01:00
void SaveCoverToFileManual ( const Song & song , const AlbumCoverImageResult & result ) ;
2018-02-27 18:06:05 +01:00
2018-05-01 00:41:33 +02:00
// Downloads the cover from an URL given by user.
// This returns the downloaded image or null image if something went wrong for example when user cancelled the dialog.
2019-07-07 21:14:24 +02:00
QUrl LoadCoverFromURL ( Song * song ) ;
2021-02-26 21:03:51 +01:00
AlbumCoverImageResult LoadImageFromURL ( ) ;
2018-02-27 18:06:05 +01:00
// Lets the user choose a cover among all that have been found on last.fm.
// Returns the chosen cover or null cover if user didn't choose anything.
2019-07-07 21:14:24 +02:00
QUrl SearchForCover ( Song * song ) ;
2021-02-26 21:03:51 +01:00
AlbumCoverImageResult SearchForImage ( Song * song ) ;
2018-02-27 18:06:05 +01:00
// Returns a path which indicates that the cover has been unset manually.
2021-03-07 05:43:56 +01:00
QUrl UnsetCover ( Song * song , const bool clear_art_automatic = false ) ;
2018-02-27 18:06:05 +01:00
2021-02-26 21:03:51 +01:00
// Clears any album cover art associated with the song.
2021-03-07 03:43:49 +01:00
void ClearCover ( Song * song , const bool clear_art_automatic = false ) ;
2021-02-26 21:03:51 +01:00
// Physically deletes associated album covers from disk.
2021-03-07 03:43:49 +01:00
bool DeleteCover ( Song * song , const bool manually_unset = false ) ;
2021-02-26 21:03:51 +01:00
2018-02-27 18:06:05 +01:00
// Shows the cover of given song in it's original size.
2021-02-26 21:03:51 +01:00
void ShowCover ( const Song & song , const QImage & image = QImage ( ) ) ;
2018-09-10 21:58:57 +02:00
void ShowCover ( const Song & song , const QPixmap & pixmap ) ;
2018-02-27 18:06:05 +01:00
// Search for covers automatically
2021-09-12 21:24:22 +02:00
quint64 SearchCoverAutomatically ( const Song & song ) ;
2018-02-27 18:06:05 +01:00
// Saves the chosen cover as manual cover path of this song in collection.
2021-02-26 21:03:51 +01:00
void SaveArtAutomaticToSong ( Song * song , const QUrl & art_automatic ) ;
void SaveArtManualToSong ( Song * song , const QUrl & art_manual , const bool clear_art_automatic = false ) ;
2018-02-27 18:06:05 +01:00
// Saves the cover that the user picked through a drag and drop operation.
2019-07-07 21:14:24 +02:00
QUrl SaveCover ( Song * song , const QDropEvent * e ) ;
2018-02-27 18:06:05 +01:00
2019-03-11 23:07:11 +01:00
// Saves the given image in album directory or cache as a cover for 'album artist' - 'album'. The method returns path of the image.
2021-02-26 21:03:51 +01:00
QUrl SaveCoverAutomatic ( Song * song , const AlbumCoverImageResult & result ) ;
QUrl SaveCoverToFileAutomatic ( const Song * song , const AlbumCoverImageResult & result , const bool force_overwrite = false ) ;
QUrl SaveCoverToFileAutomatic ( const Song : : Source source , const QString & artist , const QString & album , const QString & album_id , const QString & album_dir , const AlbumCoverImageResult & result , const bool force_overwrite = false ) ;
void SaveCoverEmbeddedAutomatic ( const Song & song , const AlbumCoverImageResult & result ) ;
void SaveCoverEmbeddedAutomatic ( const Song & song , const QUrl & cover_url ) ;
void SaveCoverEmbeddedAutomatic ( const Song & song , const QString & cover_filename ) ;
2021-06-20 19:04:08 +02:00
void SaveCoverEmbeddedAutomatic ( const QList < QUrl > & urls , const QImage & image ) ;
2018-02-27 18:06:05 +01:00
static bool CanAcceptDrag ( const QDragEnterEvent * e ) ;
2021-02-27 01:32:45 +01:00
public slots :
void set_save_embedded_cover_override ( const bool value ) { save_embedded_cover_override_ = value ; }
2018-02-27 18:06:05 +01:00
private slots :
2021-02-26 21:03:51 +01:00
void AlbumCoverFetched ( const quint64 id , const AlbumCoverImageResult & result , const CoverSearchStatistics & statistics ) ;
2021-03-07 05:43:56 +01:00
void SaveEmbeddedCoverAsyncFinished ( quint64 id , const bool success , const bool cleared ) ;
2018-02-27 18:06:05 +01:00
2021-02-27 01:32:45 +01:00
signals :
void AutomaticCoverSearchDone ( ) ;
2021-02-26 21:03:51 +01:00
2021-02-27 01:32:45 +01:00
private :
2021-06-22 13:41:38 +02:00
static QString GetInitialPathForFileDialog ( const Song & song , const QString & filename ) ;
2018-02-27 18:06:05 +01:00
static bool IsKnownImageExtension ( const QString & suffix ) ;
static QSet < QString > * sImageExtensions ;
Application * app_ ;
AlbumCoverSearcher * cover_searcher_ ;
AlbumCoverFetcher * cover_fetcher_ ;
QFileDialog * save_file_dialog_ ;
CoverFromURLDialog * cover_from_url_dialog_ ;
QAction * cover_from_file_ ;
QAction * cover_to_file_ ;
QAction * cover_from_url_ ;
QAction * search_for_cover_ ;
2021-02-26 21:03:51 +01:00
QAction * separator1_ ;
2018-02-27 18:06:05 +01:00
QAction * unset_cover_ ;
2021-02-26 21:03:51 +01:00
QAction * delete_cover_ ;
QAction * clear_cover_ ;
QAction * separator2_ ;
2018-02-27 18:06:05 +01:00
QAction * show_cover_ ;
QAction * search_cover_auto_ ;
QMap < quint64 , Song > cover_fetching_tasks_ ;
2021-09-12 21:24:22 +02:00
QMap < quint64 , Song > cover_save_tasks_ ;
2021-02-26 21:03:51 +01:00
QMutex mutex_cover_save_tasks_ ;
2019-03-11 23:07:11 +01:00
2021-02-26 21:03:51 +01:00
CollectionSettingsPage : : SaveCoverType save_cover_type_ ;
CollectionSettingsPage : : SaveCoverFilename save_cover_filename_ ;
2019-03-11 23:07:11 +01:00
QString cover_pattern_ ;
bool cover_overwrite_ ;
bool cover_lowercase_ ;
bool cover_replace_spaces_ ;
2021-02-26 21:03:51 +01:00
bool save_embedded_cover_override_ ;
2019-03-11 23:07:11 +01:00
2018-02-27 18:06:05 +01:00
} ;
# endif // ALBUMCOVERCHOICECONTROLLER_H