File indexing completed on 2024-06-02 04:51:22
0001 /*************************************************************************************** 0002 * Copyright (c) 2009 Nathan Sala <sala.nathan@gmail.com> * 0003 * Copyright (c) 2009 Oleksandr Khayrullin <saniokh@gmail.com> * 0004 * Copyright (c) 2009-2010 Joffrey Clavel <jclavel@clabert.info> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) any later * 0009 * version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #ifndef SIMILARARTISTSENGINE_H 0020 #define SIMILARARTISTSENGINE_H 0021 0022 #include "NetworkAccessManagerProxy.h" 0023 #include "context/DataEngine.h" 0024 #include "context/applets/similarartists/SimilarArtist.h" 0025 #include "core/meta/forward_declarations.h" 0026 0027 using namespace Context; 0028 0029 /** 0030 * This class provide SimilarArtists data for use in the SimilarArtists context applet. 0031 * It gets its information from the API lastfm. 0032 */ 0033 class SimilarArtistsEngine : public DataEngine 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY( int maximumArtists READ maximumArtists WRITE setMaximumArtists ) 0037 Q_PROPERTY( QString artist READ artist WRITE setArtist ) 0038 0039 public: 0040 0041 /** 0042 * Construct the engine 0043 * @param parent The object parent to this engine 0044 * @param args The list of arguments 0045 */ 0046 SimilarArtistsEngine( QObject *parent, const QList<QVariant> &args ); 0047 0048 virtual void init(); 0049 0050 /** 0051 * Destroy the dataEngine 0052 */ 0053 virtual ~SimilarArtistsEngine(); 0054 0055 /** 0056 * Fetches the similar artists for an artist thanks to the LastFM WebService 0057 * Store this in the similar artist list of this class 0058 * @param artistName the name of the artist 0059 */ 0060 void similarArtistsRequest( const QString &artistName ); 0061 0062 /** 0063 * The maximum number of similar artists 0064 * @return number of similar artists 0065 */ 0066 int maximumArtists() const; 0067 0068 /** 0069 * Set the maximum number of similar artists 0070 * @param number The maximum number of similar artists 0071 */ 0072 void setMaximumArtists( int number ); 0073 0074 QString artist() const; 0075 void setArtist( const QString &name ); 0076 0077 protected: 0078 bool sourceRequestEvent( const QString &name ); 0079 0080 private: 0081 /** 0082 * The max number of similar artists to get 0083 */ 0084 int m_maxArtists; 0085 0086 /** 0087 * The artist, whose research is similar artists. 0088 */ 0089 QString m_artist; 0090 0091 private Q_SLOTS: 0092 /** 0093 * Update similar artists for the current playing track. 0094 * Launch when the track played on amarok has changed. 0095 * @param force force update to take place. 0096 */ 0097 bool update( bool force = false ); 0098 0099 bool update( const QString &name ); 0100 0101 /** 0102 * Parse the xml fetched on the lastFM API. 0103 * Launched when the download of the data are finished. 0104 */ 0105 void parseSimilarArtists( const QUrl &url, const QByteArray &data, NetworkAccessManagerProxy::Error e ); 0106 }; 0107 0108 #endif // SIMILARARTISTSENGINE_H