2011-01-24 01:09:57 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ALBUMCOVERCHOICECONTROLLER_H
|
|
|
|
#define ALBUMCOVERCHOICECONTROLLER_H
|
|
|
|
|
2011-01-24 19:32:09 +01:00
|
|
|
#include <QAction>
|
|
|
|
#include <QList>
|
2011-01-26 00:33:27 +01:00
|
|
|
#include <QMenu>
|
2011-01-24 01:09:57 +01:00
|
|
|
#include <QWidget>
|
|
|
|
|
2011-04-02 16:43:50 +02:00
|
|
|
class AlbumCoverFetcher;
|
2011-04-27 21:10:37 +02:00
|
|
|
class AlbumCoverSearcher;
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2011-01-24 01:09:57 +01:00
|
|
|
class CoverFromURLDialog;
|
2011-02-02 17:22:04 +01:00
|
|
|
class QFileDialog;
|
2011-01-24 01:09:57 +01:00
|
|
|
class Song;
|
|
|
|
|
2014-01-08 12:05:48 +01:00
|
|
|
struct CoverSearchStatistics;
|
|
|
|
|
2011-01-24 19:32:09 +01:00
|
|
|
// Controller for the common album cover related menu options.
|
2011-01-24 01:09:57 +01:00
|
|
|
class AlbumCoverChoiceController : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2012-02-18 19:57:36 +01:00
|
|
|
static const char* kLoadImageFileFilter;
|
|
|
|
static const char* kSaveImageFileFilter;
|
|
|
|
static const char* kAllFilesFilter;
|
|
|
|
|
2011-01-26 00:33:27 +01:00
|
|
|
AlbumCoverChoiceController(QWidget* parent = 0);
|
2011-01-24 01:09:57 +01:00
|
|
|
~AlbumCoverChoiceController();
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
void SetApplication(Application* app);
|
2011-07-23 20:34:41 +02:00
|
|
|
|
2011-01-26 00:33:27 +01:00
|
|
|
// Getters for all QActions implemented by this controller.
|
|
|
|
|
|
|
|
QAction* cover_from_file_action() const { return cover_from_file_; }
|
2011-02-02 17:22:04 +01:00
|
|
|
QAction* cover_to_file_action() const { return cover_to_file_; }
|
2011-01-26 00:33:27 +01:00
|
|
|
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_; }
|
|
|
|
QAction* show_cover_action() const { return show_cover_; }
|
2013-12-30 23:50:57 +01:00
|
|
|
QAction* search_cover_auto_action() const { return search_cover_auto_; }
|
2011-01-24 01:09:57 +01:00
|
|
|
|
2011-01-24 19:32:09 +01:00
|
|
|
// 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
|
2011-01-26 00:33:27 +01:00
|
|
|
QList<QAction*> GetAllActions();
|
|
|
|
|
2011-01-24 18:53:31 +01:00
|
|
|
// All of the methods below require a currently selected song as an
|
|
|
|
// input parameter. Also - LoadCoverFromFile, LoadCoverFromURL,
|
2014-02-07 16:34:20 +01:00
|
|
|
// SearchForCover, UnsetCover and SaveCover all update manual path
|
2011-01-24 18:53:31 +01:00
|
|
|
// of the given song in library to the new cover.
|
2011-01-24 01:09:57 +01:00
|
|
|
|
2014-02-07 16:34:20 +01: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
|
2011-01-24 01:09:57 +01:00
|
|
|
// path to the chosen cover will be returned.
|
2011-01-24 18:53:31 +01:00
|
|
|
QString LoadCoverFromFile(Song* song);
|
2011-01-24 01:09:57 +01:00
|
|
|
|
2011-02-02 17:22:04 +01: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.
|
|
|
|
void SaveCoverToFile(const Song& song, const QImage& image);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Downloads the cover from an URL given by user. This returns the downloaded
|
|
|
|
// image
|
2011-01-24 01:09:57 +01:00
|
|
|
// or null image if something went wrong for example when user cancelled the
|
|
|
|
// dialog.
|
2011-01-24 18:53:31 +01:00
|
|
|
QString LoadCoverFromURL(Song* song);
|
2011-01-24 01:09:57 +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.
|
2011-01-24 18:53:31 +01:00
|
|
|
QString SearchForCover(Song* song);
|
2011-01-24 01:09:57 +01:00
|
|
|
|
|
|
|
// Returns a path which indicates that the cover has been unset manually.
|
2011-01-24 18:53:31 +01:00
|
|
|
QString UnsetCover(Song* song);
|
2011-01-24 01:09:57 +01:00
|
|
|
|
|
|
|
// Shows the cover of given song in it's original size.
|
|
|
|
void ShowCover(const Song& song);
|
|
|
|
|
2013-12-30 23:50:57 +01:00
|
|
|
// Search for covers automatically
|
|
|
|
void SearchCoverAutomatically(const Song& song);
|
|
|
|
|
2011-01-24 18:53:31 +01:00
|
|
|
// Saves the chosen cover as manual cover path of this song in library.
|
|
|
|
void SaveCover(Song* song, const QString& cover);
|
|
|
|
|
2011-03-14 21:01:27 +01:00
|
|
|
// Saves the cover that the user picked through a drag and drop operation.
|
|
|
|
QString SaveCover(Song* song, const QDropEvent* e);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Saves the given image in cache as a cover for 'artist' - 'album'.
|
2011-01-24 18:53:31 +01:00
|
|
|
// The method returns path of the cached image.
|
2014-02-07 16:34:20 +01:00
|
|
|
QString SaveCoverInCache(const QString& artist, const QString& album,
|
|
|
|
const QImage& image);
|
2011-01-24 18:53:31 +01:00
|
|
|
|
2011-03-14 21:01:27 +01:00
|
|
|
static bool CanAcceptDrag(const QDragEnterEvent* e);
|
|
|
|
|
2013-12-30 23:50:57 +01:00
|
|
|
signals:
|
|
|
|
void AutomaticCoverSearchDone();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2013-12-30 23:50:57 +01:00
|
|
|
void AlbumCoverFetched(quint64 id, const QImage& image,
|
|
|
|
const CoverSearchStatistics& statistics);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-02-08 00:53:32 +01:00
|
|
|
QString GetInitialPathForFileDialog(const Song& song,
|
|
|
|
const QString& filename);
|
|
|
|
|
2011-03-14 21:01:27 +01:00
|
|
|
static bool IsKnownImageExtension(const QString& suffix);
|
|
|
|
static QSet<QString>* sImageExtensions;
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2011-01-24 01:09:57 +01:00
|
|
|
AlbumCoverSearcher* cover_searcher_;
|
2011-04-02 16:43:50 +02:00
|
|
|
AlbumCoverFetcher* cover_fetcher_;
|
2011-01-24 01:09:57 +01:00
|
|
|
|
2011-02-02 17:22:04 +01:00
|
|
|
QFileDialog* save_file_dialog_;
|
2011-01-24 01:09:57 +01:00
|
|
|
CoverFromURLDialog* cover_from_url_dialog_;
|
2011-01-24 18:53:31 +01:00
|
|
|
|
2011-01-26 00:33:27 +01:00
|
|
|
QAction* cover_from_file_;
|
2011-02-02 17:22:04 +01:00
|
|
|
QAction* cover_to_file_;
|
|
|
|
QAction* separator_;
|
2011-01-26 00:33:27 +01:00
|
|
|
QAction* cover_from_url_;
|
|
|
|
QAction* search_for_cover_;
|
|
|
|
QAction* unset_cover_;
|
|
|
|
QAction* show_cover_;
|
2013-12-30 23:50:57 +01:00
|
|
|
QAction* search_cover_auto_;
|
|
|
|
|
|
|
|
QMap<quint64, Song> cover_fetching_tasks_;
|
2011-01-24 01:09:57 +01:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // ALBUMCOVERCHOICECONTROLLER_H
|