/thirdparty/liblastfm2/src/types/Tag.cpp
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 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#include "Tag.h" 21#include "User.h" 22#include "../core/UrlBuilder.h" 23#include "../core/XmlQuery.h" 24#include "../ws/ws.h" 25using lastfm::Tag; 26using lastfm::User; 27 28 29QUrl 30Tag::www() const 31{ 32 return UrlBuilder( "tag" ).slash( m_name ).url(); 33} 34 35 36QUrl 37Tag::www( const User& user ) const 38{ 39 return UrlBuilder( "user" ).slash( user.name() ).slash( "tags" ).slash( Tag::name() ).url(); 40} 41 42 43QNetworkReply* 44Tag::search() const 45{ 46 QMap<QString, QString> map; 47 map["method"] = "tag.search"; 48 map["tag"] = m_name; 49 return ws::get(map); 50} 51 52//static 53QNetworkReply* 54Tag::getTopTags() 55{ 56 QMap<QString, QString> map; 57 map["method"] = "tag.getTopTags"; 58 return ws::get(map); 59} 60 61QMap<int, QString> //static 62Tag::list( QNetworkReply* r ) 63{ 64 QMap<int, QString> tags; 65 try { 66 foreach (XmlQuery xq, XmlQuery( r->readAll() ).children("tag")) 67 // we toLower always as otherwise it is ugly mixed case, as first 68 // ever tag decides case, and Last.fm is case insensitive about it 69 // anyway 70 tags.insertMulti( xq["count"].text().toInt(), xq["name"].text().toLower() ); 71 } 72 catch (ws::ParseError& e) 73 { 74 qWarning() << e.what(); 75 } 76 return tags; 77}