slight improvement to the context view layout imo.
[amarok.git] / src / CoverFetcher.h
blob8e4fc837809d75d838adc4925d58982729a7382a
1 // (c) 2004 Mark Kretschmann <markey@web.de>
2 // (c) 2004 Stefan Bogner <bochi@online.ms>
3 // See COPYING file for licensing information.
5 #ifndef AMAROK_COVERFETCHER_H
6 #define AMAROK_COVERFETCHER_H
8 #include "meta/Meta.h"
10 #include <QImage> //stack allocated
11 #include <QLabel> //baseclass
12 #include <QMutex>
13 #include <QObject> //baseclass
14 #include <QStringList> //stack allocated
16 class KJob;
18 class CoverLabel : public QLabel {
19 public:
20 explicit CoverLabel ( QWidget * parent, Qt::WindowFlags f = 0 );
22 void setInformation( const QString artist, const QString album ) {
23 m_artist = artist;
24 m_album = album;
27 protected:
28 virtual void mouseReleaseEvent(QMouseEvent *pEvent);
30 private:
31 QString m_artist;
32 QString m_album;
35 class CoverFetcherSingleton;
37 namespace KIO { class Job; }
39 class CoverFetcher : public QObject
41 friend class EditSearchDialog;
42 Q_OBJECT
44 static const uint MAX_COVERS_CHOICE = 10;
46 public:
48 AMAROK_EXPORT static CoverFetcher* instance();
50 ~CoverFetcher();
52 /// allow the user to edit the query?
53 void setUserCanEditQuery( bool b ) { m_userCanEditQuery = b; }
55 /// Main Fetch loop
57 void manualFetch( Meta::AlbumPtr album );
59 QString amazonURL() const { return m_amazonURL; }
60 QString asin() const { return m_asin; }
61 QImage image() const { return m_image; }
63 AMAROK_EXPORT void queueAlbum( Meta::AlbumPtr album );
64 AMAROK_EXPORT void queueAlbums( Meta::AlbumList albums );
66 bool wasError() const { return !m_success; }
67 QStringList errors() const { return m_errors; }
69 enum Locale { International=0, France, Germany, Japan, UK, Canada };
70 static QString localeIDToString( int id );
71 static int localeStringToID( const QString &locale );
73 private slots:
74 void finishedXmlFetch( KJob * job );
75 void finishedImageFetch( KJob * job );
76 void changeLocale( int id );
78 private:
79 friend class CoverFetcherSingleton;
80 CoverFetcher();
81 void startFetchLoop();
82 Meta::AlbumList m_albums;
83 Meta::AlbumPtr m_albumPtr;
84 QMutex m_albumsMutex;
85 QMutex m_fetchMutex;
87 bool m_userCanEditQuery;
88 QString m_userQuery; /// the query from the query edit dialog
89 QString m_xml;
90 QImage m_image;
91 QString m_amazonURL;
92 QString m_asin;
93 int m_size;
95 QStringList m_queries;
96 QStringList m_userQueries;
97 QStringList m_coverAsins;
98 QStringList m_coverAmazonUrls;
99 QStringList m_coverUrls;
100 QStringList m_coverNames;
101 QString m_currentCoverName;
102 QStringList m_errors;
104 bool m_success;
105 bool m_isFetching;
107 private:
108 void buildQueries( Meta::AlbumPtr album );
110 /// Fetch a cover
111 void startFetch( Meta::AlbumPtr album );
113 /// The fetch was successful!
114 void finish();
116 /// The fetch failed, finish up and log an error message
117 void finishWithError( const QString &message, KJob *job = 0 );
119 /// Prompt the user for a query
120 void getUserQuery( QString explanation = QString() );
122 /// Will try all available queries, and then prompt the user, if allowed
123 void attemptAnotherFetch();
125 /// Show the cover that has been found
126 void showCover();
129 namespace The
131 inline CoverFetcher *coverFetcher() { return CoverFetcher::instance(); }
134 #endif /* AMAROK_COVERFETCHER_H */