PageRenderTime 94ms CodeModel.GetById 31ms app.highlight 16ms RepoModel.GetById 34ms app.codeStats 0ms

/thirdparty/liblastfm2/src/types/User.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 184 lines | 111 code | 40 blank | 33 comment | 7 complexity | 1b77ebc4bb993cee465d528d59d575cb MD5 | raw file
  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 <QString>
 24#include <QStringList>
 25#include <QUrl>
 26
 27#include <lastfm/AbstractType>
 28#include <lastfm/ws.h>
 29
 30namespace lastfm
 31{
 32    class UserList;
 33
 34    class LASTFM_DLLEXPORT User : public AbstractType
 35    {
 36    public:
 37        User() : AbstractType(), m_name( lastfm::ws::Username ), m_match( -1.0f )
 38        {}
 39
 40        User( const QString& name ) : AbstractType(), m_name( name ), m_match( -1.0f )
 41        {}
 42
 43        User( const class XmlQuery& xml );
 44
 45        lastfm::User& operator=( const lastfm::User& that ) { m_name = that.name(); m_images = that.m_images; m_realName = that.m_realName; m_match = that.m_match; return *this; }
 46        bool operator==(const lastfm::User& that) const { return m_name == that.m_name; }
 47        bool operator<(const lastfm::User& that) const { return m_name < that.m_name; }
 48
 49        operator QString() const { return m_name; }
 50        QString name() const { return m_name; }
 51        void setName( const QString& name ){ m_name = name; }
 52    
 53        /** use Tag::list() on the response to get a WeightedStringList */
 54        QNetworkReply* getTopTags() const;
 55
 56        /** use User::list() on the response to get a QList<User> */
 57        QNetworkReply* getFriends(  bool recentTracks = false, int limit = 50, int page = 1 ) const;
 58        QNetworkReply* getFriendsListeningNow( int limit = 50, int page = 1 ) const;
 59        QNetworkReply* getNeighbours( int limit = 50, int page = 1 ) const;
 60    
 61        QNetworkReply* getPlaylists() const;
 62        QNetworkReply* getTopArtists( QString period = "overall", int limit = 50, int page = 1 ) const;
 63        QNetworkReply* getRecentTracks( int limit = 50, int page = 1 ) const;
 64        QNetworkReply* getRecentArtists() const;
 65        QNetworkReply* getRecentStations(  int limit = 10, int page = 1  ) const;
 66        QNetworkReply* getRecommendedArtists( int limit = 50, int page = 1 ) const;
 67    
 68        static UserList list( QNetworkReply* );
 69
 70        QString toString() const { return name(); }
 71        QDomElement toDomElement( QDomDocument& ) const { return QDomElement(); }
 72    
 73    //////
 74        QUrl imageUrl( ImageSize size = Large, bool square = false ) const;
 75        
 76        QString realName() const { return m_realName; }
 77    
 78        /** the user's profile page at www.last.fm */
 79        QUrl www() const;
 80    
 81        /** Returns the match between the logged in user and the user which this
 82          * object represents (if < 0.0f then not set) */
 83        float match() const { return m_match; }
 84    
 85    protected:
 86        QString m_name;
 87
 88        QList<QUrl> m_images;
 89    
 90        float m_match;
 91    
 92        QString m_realName;
 93        
 94        QMap<QString, QString> params( const QString& method ) const;
 95    };
 96
 97    class LASTFM_DLLEXPORT Gender
 98    {
 99        QString s;
100
101    public:
102        Gender() :s(/*confused!*/){}
103
104        Gender( const QString& ss ) :s( ss.toLower() )
105        {}
106
107        bool known() const { return male() || female(); }
108        bool male() const { return s == "m"; }
109        bool female() const { return s == "f"; }
110
111        QString toString() const
112        {
113            QString result;
114
115            if (male())
116                result = QObject::tr( "m" );
117            else if (female())
118                result = QObject::tr( "f" );
119            else
120                result = QObject::tr( "n" ); // as in neuter
121
122            return result;
123        }
124    };
125
126
127    /** The Extended User contains extra information about a user's account */
128    class LASTFM_DLLEXPORT UserDetails : public User
129    {
130    public:
131        UserDetails();
132        /** User details */
133        UserDetails( QNetworkReply* );
134    
135        /** you can only get information about the any user */
136        static QNetworkReply* getInfo( const QString& username = lastfm::ws::Username );
137
138        /** a verbose string, eg. "A man with 36,153 scrobbles" */
139        QString getInfoString() const;
140
141        bool isSubscriber() const{ return m_isSubscriber; }
142        bool canBootstrap() const{ return m_canBootstrap; }
143        quint32 scrobbleCount() const{ return m_scrobbles; }
144        QDateTime dateRegistered() const { return m_registered; }
145        Gender gender() const { return m_gender; }
146        QString country() const { return m_country; }
147
148        void setScrobbleCount( quint32 scrobblesCount );
149        void setDateRegistered( const QDateTime& date );
150        void setImages( const QList<QUrl>& images );
151        void setRealName( const QString& realName );
152        void setAge( unsigned short age );
153        void setIsSubscriber( bool subscriber );
154        void setCanBootstrap( bool canBootstrap );
155        void setGender( const QString& s );
156        void setCountry( const QString& country );
157
158    
159        // pass the result to Artist::list(), if you want the other data 
160        // you have to parse the lfm() yourself members
161        // http://www.last.fm/api/show?service=388
162        // static QNetworkReply* getRecommendedArtists();
163
164    protected:
165        Gender m_gender;
166        unsigned short m_age;
167        unsigned int m_scrobbles;
168        QDateTime m_registered;
169        QString m_country;
170        bool m_isSubscriber;
171        bool m_canBootstrap;
172    };
173
174    class LASTFM_DLLEXPORT UserList : public QList<User>
175    {
176    public:
177        int total;
178        int page;
179        int perPage;
180        int totalPages;
181    };
182}
183
184#endif