1 /*
2    Copyright 2009-2010 Last.fm Ltd.
3       - Primarily authored by Max Howell, Jono Cole, Doug Mansell and Michael Coffey
4 
5    This file is part of liblastfm.
6 
7    liblastfm is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11 
12    liblastfm is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with liblastfm.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifndef LASTFM_USER_H
21 #define LASTFM_USER_H
22 
23 #include <QStringList>
24 
25 #include "AbstractType.h"
26 #include "ws.h"
27 
28 namespace lastfm
29 {
30     class UserList;
31     class XmlQuery;
32     class Artist;
33 
34     class LASTFM_DLLEXPORT Gender
35     {
36 
37     public:
38         Gender();
39         Gender( const Gender& gender );
40         Gender( const QString& ss );
41         ~Gender();
42 
43         bool known() const;
44         bool male() const;
45         bool female() const;
46 
47         QString toString() const;
48         lastfm::Gender& operator=( const lastfm::Gender& that );
49 
50     private:
51         class GenderPrivate;
52         GenderPrivate * const d;
53     };
54 
55     class LASTFM_DLLEXPORT User : public AbstractType
56     {
57     public:
58         enum Type
59         {
60             TypeUser,
61             TypeSubscriber,
62             TypeModerator,
63             TypeStaff,
64             TypeAlumni
65         };
66 
67     public:
68         User();
69         User( const QString& name );
70         User( const XmlQuery& xml );
71         User( const User& user );
72         ~User();
73 
74         lastfm::User& operator=( const lastfm::User& that );
75         bool operator==(const lastfm::User& that) const;
76         bool operator<(const lastfm::User& that) const;
77 
78         operator QString() const;
79 
80         QString name() const;
81         void setName( const QString& name );
82 
83         Type type() const;
84         void setType( Type type );
85 
86         bool isSubscriber() const;
87         void setIsSubscriber( bool subscriber );
88 
89         bool canBootstrap() const;
90         void setCanBootstrap( bool canBootstrap );
91 
92         quint32 scrobbleCount() const;
93         void setScrobbleCount( quint32 scrobblesCount );
94 
95         QDateTime dateRegistered() const;
96         void setDateRegistered( const QDateTime& date );
97 
98         Gender gender() const;
99         QString country() const;
100 
101         QString realName() const;
102         void setRealName( const QString& realName );
103 
104         QUrl imageUrl( ImageSize size = LargeImage, bool square = false ) const;
105         void setImages( const QList<QUrl>& images );
106 
107         unsigned short age() const;
108         void setAge( unsigned short age );
109 
110         void setGender( const QString& s );
111         void setCountry( const QString& country );
112 
113         /** use Tag::list() on the response to get a WeightedStringList */
114         QNetworkReply* getTopTags() const;
115 
116         /** use User::list() on the response to get a UserList */
117         QNetworkReply* getFriends(  bool recentTracks = false, int limit = 50, int page = 1 ) const;
118         QNetworkReply* getFriendsListeningNow( int limit = 50, int page = 1 ) const;
119         QNetworkReply* getFriendsThatListenTo( const lastfm::Artist& artist, int limit = 50, int page = 1 ) const;
120         QNetworkReply* getNeighbours( int limit = 50, int page = 1 ) const;
121 
122         QNetworkReply* getLovedTracks( int limit = 50, int page = 1 ) const;
123         QNetworkReply* getPlaylists() const;
124         QNetworkReply* getTopArtists( QString period = "overall", int limit = 50, int page = 1 ) const;
125         QNetworkReply* getRecentTracks( int limit = 50, int page = 1 ) const;
126         QNetworkReply* getRecentArtists() const;
127         QNetworkReply* getRecentStations(  int limit = 10, int page = 1  ) const;
128         QNetworkReply* getRecommendedArtists( int limit = 50, int page = 1 ) const;
129 
130         /** you can only get information about the any user */
131         static QNetworkReply* getInfo( const QString& username = lastfm::ws::Username );
132 
133         /** a verbose string, eg. "A man with 36,153 scrobbles" */
134         QString getInfoString() const;
135 
136         static UserList list( QNetworkReply* );
137 
138         QString toString() const;
139         QDomElement toDomElement( QDomDocument& ) const;
140 
141         /** the user's profile page at www.last.fm */
142         QUrl www() const;
143 
144         /** Returns the match between the logged in user and the user which this
145           * object represents (if < 0.0f then not set) */
146         float match() const;
147 
148     protected:
149         QMap<QString, QString> params( const QString& method ) const;
150 
151     protected:
152         class UserPrivate;
153         UserPrivate * const d;
154     };
155 
156     class LASTFM_DLLEXPORT UserList
157     {
158     public:
159         UserList();
160         UserList( const XmlQuery& query );
161         UserList( const UserList& other );
162         ~UserList();
163         UserList& operator=( const UserList& other );
164 
165         int totalUsers();
166         int totalPages();
167         int currentPage();
168         int usersPerPage();
169         QList<User> users();
170 
171     private:
172         class UserListPrivate * const d;
173     };
174 }
175 
176 #endif
177