add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / lastfm.h
blobcbf3811e20244a19b3f13e530f0860ed6fccccd5
1 /***************************************************************************
2 * copyright : (C) 2006 Chris Muehlhaeuser <chris@chris.de> *
3 * : (C) 2006 Seb Ruiz <ruiz@kde.org> *
4 * : (C) 2006 Ian Monroe <ian@monroe.nu> *
5 * : (C) 2006 Mark Kretschmann <markey@web.de> *
6 **************************************************************************/
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
17 #ifndef AMAROK_LASTFM_H
18 #define AMAROK_LASTFM_H
20 #include "metabundle.h"
22 #include <q3http.h>
23 #include <QObject>
24 #include <q3serversocket.h>
25 #include <q3url.h>
26 #include <q3valuelist.h>
27 //Added by qt3to4:
28 #include <Q3PtrList>
30 #include <kconfigdialog.h>
31 #include <KJob>
33 class KLineEdit;
34 class KAction;
35 class K3ProcIO;
36 class KUrl;
38 namespace KIO { class Job; }
40 /* AmarokHttp is a hack written so that lastfm code could easily use something proxy aware.
41 DO NOT use this class for anything else, use KIO directly instead. */
42 class AmarokHttp : public QObject
44 Q_OBJECT
46 public:
47 explicit AmarokHttp ( const QString & hostname, quint16 port = 80, QObject* parent = 0 );
48 int get ( const QString & path );
49 Q3Http::State state() const;
50 QByteArray readAll ();
51 Q3Http::Error error();
53 signals:
54 void requestFinished ( int id, bool error );
56 protected slots:
57 void slotData(KIO::Job*, const QByteArray& );
58 void slotResult(KJob*);
60 protected:
61 QString m_hostname;
62 quint16 m_port;
63 QString m_path;
64 Q3Http::State m_state;
65 Q3Http::Error m_error;
66 bool m_done;
67 QByteArray m_result;
71 namespace LastFm
73 class WebService;
75 class Controller : public QObject
77 Q_OBJECT
79 public:
80 static Controller* instance();
82 KUrl getNewProxy( QString genreUrl );
84 bool isPlaying() const { return m_service != 0; }
85 WebService* getService() const { return m_service; }
86 QString getGenreUrl() const { return m_genreUrl; }
88 static bool checkCredentials();
89 static QString createCustomStation();
90 static QString stationDescription( QString url = QString() ); // necessary for translation
92 public slots:
93 void playbackStopped();
94 void ban();
95 void love();
96 void skip();
98 private:
99 Controller();
100 void setActionsEnabled( bool enable );
102 static Controller *s_instance;
103 Q3PtrList<KAction> m_actionList;
105 QString m_genreUrl;
106 WebService* m_service;
109 class WebService : public QObject
111 Q_OBJECT
113 public:
114 enum DataType { Artist, Album, Track };
116 WebService( QObject* parent );
117 ~WebService();
119 bool handshake( const QString& username, const QString& password );
121 bool changeStation( QString url );
122 QString currentUsername() const { return m_username; }
123 QString currentPassword() const { return m_password; }
124 QString currentStation() const { return m_station; }
125 QString session() const { return m_session; }
126 Q3Url streamUrl() const { return m_streamUrl; }
128 void friends( QString username );
129 void neighbours( QString username );
131 void recentTracks( QString username );
132 void userTags( QString username );
134 void recommend( int type, QString username, QString artist, QString token = QString() );
136 void recommendArtist( QString username, QString artist )
137 { recommend( WebService::Artist, username, artist ); }
139 void recommendAlbum( QString username, QString artist, QString album )
140 { recommend( WebService::Album, username, artist, album ); }
142 void recommendTrack( QString username, QString artist, QString track )
143 { recommend( WebService::Track, username, artist, track ); }
146 Verify with server that a supplied user/pass combo is valid. Password
147 should be MD5 hashed.
149 void verifyUser( const QString& user, const QString& pass );
151 K3ProcIO* getServer() { return m_server; }
152 QString proxyUrl() { return m_proxyUrl; }
154 void showError( int code, QString message = QString() );
155 QString parameter( const QString keyName, const QString data ) const;
157 void addObserver( QObject * observer ) { m_metaDataObservers.append( observer ); }
159 public slots:
160 void requestMetaData();
161 void enableScrobbling( bool enabled );
163 void love();
164 void skip();
165 void ban();
167 signals:
168 void actionStarted();
169 void actionFinished();
171 void stationChanged( QString url, QString name );
172 void songQueued();
174 void metaDataResult( const MetaBundle &bundle );
175 void enableScrobblingDone();
177 void loveDone();
178 void skipDone();
179 void banDone();
181 void friendsResult( const QString& username, const QStringList& friends );
182 void neighboursResult( const QString& username, const QStringList& friends );
184 void recentTracksResult( const QString& username, Q3ValueList< QPair<QString, QString> > songs );
185 void userTagsResult( const QString& username, const QStringList& tags );
187 private:
188 enum errorCode { E_NOCONTENT = 1, E_NOMEMBERS = 2, E_NOFANS = 3, E_NOAVAIL = 4, E_NOSUBSCRIBER = 5,
189 E_NONEIGHBOURS = 6, E_NOSTOPPED = 7, E_OTHER = 0 };
193 QStringList parameterArray( const QString keyName, const QString data ) const;
194 QStringList parameterKeys( const QString keyName, const QString data ) const;
196 QString m_username; // login username
197 QString m_password; // login password
198 QString m_station; // the url of the station
199 QString m_session; // session id that last.fm provides
200 QString m_baseHost; // who are we connecting to?
201 QString m_basePath; // where are we connecting to!
202 Q3Url m_streamUrl; // last.fm webserver for direct connection (proxy connects to this)
203 bool m_subscriber; // self explanatory
205 QString m_proxyUrl;
206 K3ProcIO *m_server;
207 MetaBundle m_metaBundle;
209 QList<QObject*> m_metaDataObservers; //temporary hack
211 private slots:
212 void readProxy();
213 void metaDataFinished( int id, bool error );
214 void fetchImageFinished( KIO::Job* );
215 void enableScrobblingFinished( int id, bool error );
217 void loveFinished( int id, bool error );
218 void skipFinished( int id, bool error );
219 void banFinished( int id, bool error );
221 void friendsFinished( int id, bool error );
222 void neighboursFinished( int id, bool error );
224 void recentTracksFinished( int id, bool error );
225 void userTagsFinished( int id, bool error );
227 void recommendFinished( int id, bool error );
230 class Bundle
232 public:
233 Bundle() {}
234 Bundle( const Bundle& bundle);
235 QString imageUrl() const { return m_imageUrl; }
236 void setImageUrl( const QString& imageUrl ) { m_imageUrl = imageUrl; }
238 QString artistUrl() const { return m_artistUrl; }
239 void setArtistUrl( const QString& theValue ) { m_artistUrl = theValue; }
241 QString albumUrl() const { return m_albumUrl; }
242 void setAlbumUrl( const QString& theValue ) { m_albumUrl = theValue; }
244 QString titleUrl() const { return m_titleUrl; }
245 void setTitleUrl( const QString& theValue ) { m_titleUrl = theValue; }
247 private:
248 QString m_imageUrl;
249 QString m_albumUrl;
250 QString m_artistUrl;
251 QString m_titleUrl;
254 // We must implement this because QServerSocket has one pure virtual method.
255 // It's just used for finding a free port.
256 class MyServerSocket : public Q3ServerSocket
258 public:
259 MyServerSocket() : Q3ServerSocket( quint16( 0 ) ) {}
261 private:
262 void newConnection( int ) {}
266 class LoginDialog : public KDialog
268 Q_OBJECT
270 public:
271 LoginDialog( QWidget *parent );
273 protected slots:
274 void slotButtonClicked( ButtonCode button );
276 private:
277 KLineEdit *m_userLineEdit;
278 KLineEdit *m_passLineEdit;
282 class CustomStationDialog : public KDialog
284 Q_OBJECT
286 public:
287 CustomStationDialog( QWidget *parent );
289 QString text() const;
291 private:
292 KLineEdit *m_edit;
296 #endif /*AMAROK_LASTFM_H*/