| 1 |
/*************************************************************************************** |
| 2 |
* Copyright (c) 2009 Nathan Sala <[email protected]> * |
| 3 |
* Copyright (c) 2009 Oleksandr Khayrullin <[email protected]> * |
| 4 |
* Copyright (c) 2009-2010 Joffrey Clavel <[email protected]> * |
| 5 |
* Copyright (c) 2024 Tuomas Nurmi <[email protected]> * |
| 6 |
* * |
| 7 |
* This program is free software; you can redistribute it and/or modify it under * |
| 8 |
* the terms of the GNU General Public License as published by the Free Software * |
| 9 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 10 |
* version. * |
| 11 |
* * |
| 12 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 13 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 14 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU General Public License along with * |
| 17 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 18 |
****************************************************************************************/ |
| 19 |
|
| 20 |
#ifndef SIMILARARTISTSENGINE_H |
| 21 |
#define SIMILARARTISTSENGINE_H |
| 22 |
|
| 23 |
#include "SimilarArtistModel.h" |
| 24 |
|
| 25 |
#include "core/meta/Meta.h" |
| 26 |
#include "network/NetworkAccessManagerProxy.h" |
| 27 |
|
| 28 |
namespace Collections |
| 29 |
{ |
| 30 |
class QueryMaker; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* This class provide SimilarArtists data for use in the SimilarArtists context applet. |
| 35 |
* It gets its information from the API lastfm. |
| 36 |
*/ |
| 37 |
class SimilarArtistsEngine : public QObject |
| 38 |
{ |
| 39 |
Q_OBJECT |
| 40 |
Q_PROPERTY( int maximumArtists READ maximumArtists WRITE setMaximumArtists NOTIFY maxArtistsChanged ) |
| 41 |
Q_PROPERTY( SimilarArtistModel* model READ model CONSTANT ) |
| 42 |
Q_PROPERTY( QString currentTarget READ currentTarget NOTIFY targetChanged ) |
| 43 |
|
| 44 |
public: |
| 45 |
|
| 46 |
/** |
| 47 |
* Construct the engine |
| 48 |
* @param parent The object parent to this engine |
| 49 |
* @param args The list of arguments |
| 50 |
*/ |
| 51 |
explicit SimilarArtistsEngine( QObject* parent = nullptr ); |
| 52 |
|
| 53 |
/** |
| 54 |
* Destroy the dataEngine |
| 55 |
*/ |
| 56 |
~SimilarArtistsEngine() override; |
| 57 |
|
| 58 |
SimilarArtistModel *model() const { return m_model; } |
| 59 |
|
| 60 |
/** |
| 61 |
* Fetches the similar artists for an artist thanks to the LastFM WebService |
| 62 |
* Store this in the similar artist list of this class |
| 63 |
* @param artistName the name of the artist |
| 64 |
*/ |
| 65 |
void similarArtistsRequest( const QString &artistName ); |
| 66 |
|
| 67 |
void artistInfoRequest( const QString &artistName ); |
| 68 |
|
| 69 |
void searchLocalCollection( const QString &artistName ); |
| 70 |
|
| 71 |
Q_INVOKABLE void navigateToArtist( const QString &artist ); |
| 72 |
|
| 73 |
/** |
| 74 |
* The maximum number of similar artists |
| 75 |
* @return number of similar artists |
| 76 |
*/ |
| 77 |
int maximumArtists() const; |
| 78 |
|
| 79 |
/** |
| 80 |
* Set the maximum number of similar artists |
| 81 |
* @param number The maximum number of similar artists |
| 82 |
*/ |
| 83 |
void setMaximumArtists( int number ); |
| 84 |
|
| 85 |
QString currentTarget() const; |
| 86 |
|
| 87 |
Q_SIGNALS: |
| 88 |
void maxArtistsChanged(); |
| 89 |
void targetChanged(); |
| 90 |
|
| 91 |
private: |
| 92 |
/** |
| 93 |
* The max number of similar artists to get |
| 94 |
*/ |
| 95 |
int m_maxArtists; |
| 96 |
|
| 97 |
SimilarArtistModel *m_model; |
| 98 |
|
| 99 |
Collections::QueryMaker *m_lastQueryMaker; |
| 100 |
QString m_queriedArtist; |
| 101 |
|
| 102 |
bool m_artistInfoQueryInProcess; |
| 103 |
|
| 104 |
private Q_SLOTS: |
| 105 |
/** |
| 106 |
* Update similar artists for the current playing track. |
| 107 |
* Launch when the track played on amarok has changed. |
| 108 |
* @param force force update to take place. |
| 109 |
*/ |
| 110 |
bool update( bool force = false ); |
| 111 |
|
| 112 |
void resultReady( const Meta::AlbumList &albums ); |
| 113 |
|
| 114 |
/** |
| 115 |
* Parse the xml fetched on the lastFM API. |
| 116 |
* Launched when the download of the data are finished. |
| 117 |
*/ |
| 118 |
void parseSimilarArtists( const QUrl &url, const QByteArray &data, NetworkAccessManagerProxy::Error e ); |
| 119 |
|
| 120 |
void parseArtistInfo( const QUrl &url, const QByteArray &data, NetworkAccessManagerProxy::Error e ); |
| 121 |
}; |
| 122 |
|
| 123 |
#endif // SIMILARARTISTSENGINE_H |