/thirdparty/liblastfm2/src/types/Tag.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 77 lines · 46 code · 8 blank · 23 comment · 0 complexity · 5bd14ade2b49a8eadd8b9fea7b64ed0c MD5 · raw file

  1. /*
  2. Copyright 2009 Last.fm Ltd.
  3. - Primarily authored by Max Howell, Jono Cole and Doug Mansell
  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. #include "Tag.h"
  17. #include "User.h"
  18. #include "../core/UrlBuilder.h"
  19. #include "../core/XmlQuery.h"
  20. #include "../ws/ws.h"
  21. using lastfm::Tag;
  22. using lastfm::User;
  23. QUrl
  24. Tag::www() const
  25. {
  26. return UrlBuilder( "tag" ).slash( m_name ).url();
  27. }
  28. QUrl
  29. Tag::www( const User& user ) const
  30. {
  31. return UrlBuilder( "user" ).slash( user.name() ).slash( "tags" ).slash( Tag::name() ).url();
  32. }
  33. QNetworkReply*
  34. Tag::search() const
  35. {
  36. QMap<QString, QString> map;
  37. map["method"] = "tag.search";
  38. map["tag"] = m_name;
  39. return ws::get(map);
  40. }
  41. //static
  42. QNetworkReply*
  43. Tag::getTopTags()
  44. {
  45. QMap<QString, QString> map;
  46. map["method"] = "tag.getTopTags";
  47. return ws::get(map);
  48. }
  49. QMap<int, QString> //static
  50. Tag::list( QNetworkReply* r )
  51. {
  52. QMap<int, QString> tags;
  53. try {
  54. foreach (XmlQuery xq, XmlQuery( r->readAll() ).children("tag"))
  55. // we toLower always as otherwise it is ugly mixed case, as first
  56. // ever tag decides case, and Last.fm is case insensitive about it
  57. // anyway
  58. tags.insertMulti( xq["count"].text().toInt(), xq["name"].text().toLower() );
  59. }
  60. catch (ws::ParseError& e)
  61. {
  62. qWarning() << e.what();
  63. }
  64. return tags;
  65. }