Fix list index out of bounds crash on loading of .pls playlists, thanks to Tim Beaule...
[amarok.git] / src / CoverFetcher.h
blobb6e18f964696c9084c399c701483e53714dd8a92
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 Meta::AlbumList m_albums;
82 Meta::AlbumPtr m_albumPtr;
83 QMutex m_albumsMutex;
84 QMutex m_fetchMutex;
86 bool m_userCanEditQuery;
87 QString m_userQuery; /// the query from the query edit dialog
88 QString m_xml;
89 QImage m_image;
90 QString m_amazonURL;
91 QString m_asin;
92 int m_size;
94 QStringList m_queries;
95 QStringList m_userQueries;
96 QStringList m_coverAsins;
97 QStringList m_coverAmazonUrls;
98 QStringList m_coverUrls;
99 QStringList m_coverNames;
100 QString m_currentCoverName;
101 QStringList m_errors;
103 bool m_success;
104 bool m_isFetching;
106 private:
107 void buildQueries( Meta::AlbumPtr album );
109 /// Fetch a cover
110 void startFetch( Meta::AlbumPtr album );
112 /// The fetch was successful!
113 void finish();
115 /// The fetch failed, finish up and log an error message
116 void finishWithError( const QString &message, KJob *job = 0 );
118 /// Prompt the user for a query
119 void getUserQuery( QString explanation = QString() );
121 /// Will try all available queries, and then prompt the user, if allowed
122 void attemptAnotherFetch();
124 /// Show the cover that has been found
125 void showCover();
128 namespace The
130 inline CoverFetcher *coverFetcher() { return CoverFetcher::instance(); }
133 #endif /* AMAROK_COVERFETCHER_H */