| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2009 Simon Esneault <[email protected]> * |
| 3 |
* Copyright (c) 2010 Daniel Faust <[email protected]> * |
| 4 |
* * |
| 5 |
* This program is free software; you can redistribute it and/or modify it under * |
| 6 |
* the terms of the GNU General Public License as published by the Free Software * |
| 7 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 8 |
* version. * |
| 9 |
* * |
| 10 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 11 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 12 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 13 |
* * |
| 14 |
* You should have received a copy of the GNU General Public License along with * |
| 15 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 16 |
****************************************************************************************/ |
| 17 |
|
| 18 |
#ifndef AMAROK_LABELS_ENGINE |
| 19 |
#define AMAROK_LABELS_ENGINE |
| 20 |
|
| 21 |
#include "ContextObserver.h" |
| 22 |
#include "context/DataEngine.h" |
| 23 |
#include "core/meta/forward_declarations.h" |
| 24 |
#include "network/NetworkAccessManagerProxy.h" |
| 25 |
|
| 26 |
#include <QMap> |
| 27 |
#include <QTimer> |
| 28 |
#include <QPointer> |
| 29 |
|
| 30 |
using namespace Context; |
| 31 |
|
| 32 |
/** |
| 33 |
* This class provide labels from last.fm |
| 34 |
* |
| 35 |
*/ |
| 36 |
class LabelsEngine : public DataEngine, public ContextObserver |
| 37 |
{ |
| 38 |
Q_OBJECT |
| 39 |
public: |
| 40 |
LabelsEngine( QObject *parent, const QList<QVariant> &args ); |
| 41 |
virtual ~LabelsEngine(); |
| 42 |
|
| 43 |
QStringList sources() const; |
| 44 |
|
| 45 |
protected: |
| 46 |
// reimplemented from Plasma::DataEngine |
| 47 |
bool sourceRequestEvent( const QString &name ); |
| 48 |
|
| 49 |
private Q_SLOTS: |
| 50 |
|
| 51 |
void update( bool reload = false ); |
| 52 |
|
| 53 |
/** |
| 54 |
* This slots will handle last.fm result for this query: |
| 55 |
* API key is : 402d3ca8e9bc9d3cf9b85e1202944ca5 |
| 56 |
* http://ws.audioscrobbler.com/2.0/?method=track.gettoptags&artist=radiohead&track=paranoid+android&api_key=b25b959554ed76058ac220b7b2e0a026 |
| 57 |
* see here for details: http://www.lastfm.com/api/ |
| 58 |
*/ |
| 59 |
void resultLastFm( const QUrl &url, QByteArray data, NetworkAccessManagerProxy::Error e ); |
| 60 |
|
| 61 |
void resultReady( const Meta::LabelList &labels ); |
| 62 |
void dataQueryDone(); |
| 63 |
|
| 64 |
void timeout(); |
| 65 |
|
| 66 |
private: |
| 67 |
/** |
| 68 |
* Engine was updated, so we check if the songs is different, and if it is, we delete every and start |
| 69 |
* all the query/ fetching stuff |
| 70 |
*/ |
| 71 |
void fetchLastFm(); |
| 72 |
void updateLocal(); |
| 73 |
|
| 74 |
QTimer m_timeoutTimer; |
| 75 |
|
| 76 |
/// The URL for the network request |
| 77 |
QUrl m_lastFmUrl; |
| 78 |
|
| 79 |
QStringList m_sources; |
| 80 |
|
| 81 |
// Cache the artist and title of the current track so we can check against metadata |
| 82 |
// updates. We only want to update the labels if the artist change |
| 83 |
QString m_artist; |
| 84 |
QString m_title; |
| 85 |
// Send the album name to the applet, used to filter labels that match the album |
| 86 |
QString m_album; |
| 87 |
|
| 88 |
int m_try; |
| 89 |
|
| 90 |
QStringList m_allLabels; // all labels known to amarok |
| 91 |
QStringList m_userLabels; // user labels |
| 92 |
QMap < QString, QVariant > m_webLabels; // downloaded labels |
| 93 |
|
| 94 |
}; |
| 95 |
|
| 96 |
AMAROK_EXPORT_DATAENGINE( labels, LabelsEngine ) |
| 97 |
#endif |
| 98 |
|