/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. This file is part of liblastfm.
  5. liblastfm is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. liblastfm is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef LASTFM_USER_H
  17. #define LASTFM_USER_H
  18. #include <QString>
  19. #include <QStringList>
  20. #include <QUrl>
  21. #include <lastfm/AbstractType>
  22. #include <lastfm/ws.h>
  23. namespace lastfm
  24. {
  25. class UserList;
  26. class LASTFM_DLLEXPORT User : public AbstractType
  27. {
  28. public:
  29. User() : AbstractType(), m_name( lastfm::ws::Username ), m_match( -1.0f )
  30. {}
  31. User( const QString& name ) : AbstractType(), m_name( name ), m_match( -1.0f )
  32. {}
  33. User( const class XmlQuery& xml );
  34. 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; }
  35. bool operator==(const lastfm::User& that) const { return m_name == that.m_name; }
  36. bool operator<(const lastfm::User& that) const { return m_name < that.m_name; }
  37. operator QString() const { return m_name; }
  38. QString name() const { return m_name; }
  39. void setName( const QString& name ){ m_name = name; }
  40. /** use Tag::list() on the response to get a WeightedStringList */
  41. QNetworkReply* getTopTags() const;
  42. /** use User::list() on the response to get a QList<User> */
  43. QNetworkReply* getFriends( bool recentTracks = false, int limit = 50, int page = 1 ) const;
  44. QNetworkReply* getFriendsListeningNow( int limit = 50, int page = 1 ) const;
  45. QNetworkReply* getNeighbours( int limit = 50, int page = 1 ) const;
  46. QNetworkReply* getPlaylists() const;
  47. QNetworkReply* getTopArtists( QString period = "overall", int limit = 50, int page = 1 ) const;
  48. QNetworkReply* getRecentTracks( int limit = 50, int page = 1 ) const;
  49. QNetworkReply* getRecentArtists() const;
  50. QNetworkReply* getRecentStations( int limit = 10, int page = 1 ) const;
  51. QNetworkReply* getRecommendedArtists( int limit = 50, int page = 1 ) const;
  52. static UserList list( QNetworkReply* );
  53. QString toString() const { return name(); }
  54. QDomElement toDomElement( QDomDocument& ) const { return QDomElement(); }
  55. //////
  56. QUrl imageUrl( ImageSize size = Large, bool square = false ) const;
  57. QString realName() const { return m_realName; }
  58. /** the user's profile page at www.last.fm */
  59. QUrl www() const;
  60. /** Returns the match between the logged in user and the user which this
  61. * object represents (if < 0.0f then not set) */
  62. float match() const { return m_match; }
  63. protected:
  64. QString m_name;
  65. QList<QUrl> m_images;
  66. float m_match;
  67. QString m_realName;
  68. QMap<QString, QString> params( const QString& method ) const;
  69. };
  70. class LASTFM_DLLEXPORT Gender
  71. {
  72. QString s;
  73. public:
  74. Gender() :s(/*confused!*/){}
  75. Gender( const QString& ss ) :s( ss.toLower() )
  76. {}
  77. bool known() const { return male() || female(); }
  78. bool male() const { return s == "m"; }
  79. bool female() const { return s == "f"; }
  80. QString toString() const
  81. {
  82. QString result;
  83. if (male())
  84. result = QObject::tr( "m" );
  85. else if (female())
  86. result = QObject::tr( "f" );
  87. else
  88. result = QObject::tr( "n" ); // as in neuter
  89. return result;
  90. }
  91. };
  92. /** The Extended User contains extra information about a user's account */
  93. class LASTFM_DLLEXPORT UserDetails : public User
  94. {
  95. public:
  96. UserDetails();
  97. /** User details */
  98. UserDetails( QNetworkReply* );
  99. /** you can only get information about the any user */
  100. static QNetworkReply* getInfo( const QString& username = lastfm::ws::Username );
  101. /** a verbose string, eg. "A man with 36,153 scrobbles" */
  102. QString getInfoString() const;
  103. bool isSubscriber() const{ return m_isSubscriber; }
  104. bool canBootstrap() const{ return m_canBootstrap; }
  105. quint32 scrobbleCount() const{ return m_scrobbles; }
  106. QDateTime dateRegistered() const { return m_registered; }
  107. Gender gender() const { return m_gender; }
  108. QString country() const { return m_country; }
  109. void setScrobbleCount( quint32 scrobblesCount );
  110. void setDateRegistered( const QDateTime& date );
  111. void setImages( const QList<QUrl>& images );
  112. void setRealName( const QString& realName );
  113. void setAge( unsigned short age );
  114. void setIsSubscriber( bool subscriber );
  115. void setCanBootstrap( bool canBootstrap );
  116. void setGender( const QString& s );
  117. void setCountry( const QString& country );
  118. // pass the result to Artist::list(), if you want the other data
  119. // you have to parse the lfm() yourself members
  120. // http://www.last.fm/api/show?service=388
  121. // static QNetworkReply* getRecommendedArtists();
  122. protected:
  123. Gender m_gender;
  124. unsigned short m_age;
  125. unsigned int m_scrobbles;
  126. QDateTime m_registered;
  127. QString m_country;
  128. bool m_isSubscriber;
  129. bool m_canBootstrap;
  130. };
  131. class LASTFM_DLLEXPORT UserList : public QList<User>
  132. {
  133. public:
  134. int total;
  135. int page;
  136. int perPage;
  137. int totalPages;
  138. };
  139. }
  140. #endif