1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine 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.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "echonesttags.h"
19
#include "tagwidget.h"
21
#include <echonest/Artist.h>
23
#include <boost/scoped_ptr.hpp>
25
struct EchoNestTags::Request {
26
Request(int id) : id_(id), artist_(new Echonest::Artist) {}
29
boost::scoped_ptr<Echonest::Artist> artist_;
32
void EchoNestTags::FetchInfo(int id, const Song& metadata) {
33
boost::shared_ptr<Request> request(new Request(id));
34
request->artist_->setName(metadata.artist());
36
QNetworkReply* reply = request->artist_->fetchTerms();
37
connect(reply, SIGNAL(finished()), SLOT(RequestFinished()));
38
requests_[reply] = request;
41
void EchoNestTags::RequestFinished() {
42
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
43
if (!reply || !requests_.contains(reply))
47
RequestPtr request = requests_.take(reply);
50
request->artist_->parseProfile(reply);
51
} catch (Echonest::ParseError e) {
52
qWarning() << "Error parsing echonest reply:" << e.errorType() << e.what();
55
if (!request->artist_->terms().isEmpty()) {
56
CollapsibleInfoPane::Data data;
57
data.id_ = "echonest/artisttags";
58
data.title_ = tr("Artist tags");
59
data.type_ = CollapsibleInfoPane::Data::Type_Tags;
60
data.icon_ = QIcon(":/last.fm/icon_tag.png");
62
TagWidget* widget = new TagWidget(TagWidget::Type_Tags);
63
data.contents_ = widget;
65
widget->SetIcon(data.icon_);
67
foreach (const Echonest::Term& term, request->artist_->terms()) {
68
widget->AddTag(term.name());
69
if (widget->count() >= 10)
73
emit InfoReady(request->id_, data);
76
emit Finished(request->id_);