| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2009-2010 Joffrey Clavel <[email protected]> * |
| 3 |
* Copyright (c) 2024 Tuomas Nurmi <[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 SIMILAR_ARTIST_H |
| 19 |
#define SIMILAR_ARTIST_H |
| 20 |
|
| 21 |
#include <QStandardItemModel> |
| 22 |
#include <QUrl> |
| 23 |
#include <QXmlStreamReader> |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Represents a similar artist to another |
| 28 |
* @author Joffrey Clavel |
| 29 |
* @version 0.1 |
| 30 |
*/ |
| 31 |
class SimilarArtistModel : public QStandardItemModel |
| 32 |
{ |
| 33 |
public: |
| 34 |
explicit SimilarArtistModel( QObject *parent = nullptr ); |
| 35 |
|
| 36 |
QVariant data( const QModelIndex &index, int role ) const override; |
| 37 |
void clearAll(); |
| 38 |
void fillFromXml( QXmlStreamReader &xml ); |
| 39 |
void fillArtistInfoFromXml( QXmlStreamReader &xml ); |
| 40 |
QString currentTarget() const { return m_similarTo; } |
| 41 |
void setCurrentTarget( const QString &target ); |
| 42 |
void setCover( const QString &target, const QUrl &cover ); |
| 43 |
|
| 44 |
enum ArtistDataRoles { |
| 45 |
NameRole = Qt::UserRole + 1, |
| 46 |
MatchRole, |
| 47 |
LinkRole, |
| 48 |
ImageRole, |
| 49 |
BioRole, |
| 50 |
ListenerCountRole, |
| 51 |
PlayCountRole, |
| 52 |
OwnPlayCountRole, |
| 53 |
AlbumCoverRole |
| 54 |
}; |
| 55 |
protected: |
| 56 |
QHash<int, QByteArray> roleNames() const override; |
| 57 |
private: |
| 58 |
/** |
| 59 |
* Currently active target artist |
| 60 |
*/ |
| 61 |
QString m_similarTo; |
| 62 |
|
| 63 |
|
| 64 |
class SimilarArtistItem : public QStandardItem |
| 65 |
{ |
| 66 |
/** |
| 67 |
* @return The name of this artist |
| 68 |
*/ |
| 69 |
QString name() const; |
| 70 |
|
| 71 |
/** |
| 72 |
* @return the percent of match of this artist, between 0 and 100 |
| 73 |
*/ |
| 74 |
int match() const; |
| 75 |
|
| 76 |
/** |
| 77 |
* @return a url on the web for this artist, for example on last.fm |
| 78 |
*/ |
| 79 |
QUrl url() const; |
| 80 |
|
| 81 |
/** |
| 82 |
* @return a url on the web for an image oh this artist, for example on last.fm |
| 83 |
*/ |
| 84 |
QUrl urlImage() const; |
| 85 |
|
| 86 |
|
| 87 |
QString bioText() const; |
| 88 |
|
| 89 |
QString listenerCount() const; |
| 90 |
QString playCount() const; |
| 91 |
QString ownPlayCount() const; |
| 92 |
QUrl albumCover() const; |
| 93 |
|
| 94 |
private: |
| 95 |
/** |
| 96 |
* The name of this artist |
| 97 |
*/ |
| 98 |
QString m_name; |
| 99 |
|
| 100 |
/** |
| 101 |
* The match of this artist to the artist similarTo, between 0 and 100 |
| 102 |
*/ |
| 103 |
int m_match; |
| 104 |
|
| 105 |
/** |
| 106 |
* A url of this artist on the web |
| 107 |
*/ |
| 108 |
QUrl m_url; |
| 109 |
|
| 110 |
/** |
| 111 |
* A image url of this artist on the web |
| 112 |
*/ |
| 113 |
QUrl m_urlImage; |
| 114 |
|
| 115 |
QString m_bioText; |
| 116 |
QString m_listenerCount; |
| 117 |
QString m_playCount; |
| 118 |
QString m_ownPlayCount; |
| 119 |
QUrl m_albumCover; |
| 120 |
|
| 121 |
friend class SimilarArtistModel; |
| 122 |
}; |
| 123 |
}; |
| 124 |
|
| 125 |
Q_DECLARE_METATYPE( SimilarArtistModel* ) |
| 126 |
|
| 127 |
#endif // SIMILAR_ARTIST_H |