~ubuntu-branches/ubuntu/natty/clementine/natty

« back to all changes in this revision

Viewing changes to src/songinfo/echonesttags.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2010-12-12 11:32:03 UTC
  • Revision ID: james.westby@ubuntu.com-20101212113203-oi0lbt5d9alzfjq7
Tags: upstream-0.6
ImportĀ upstreamĀ versionĀ 0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2010, David Sansome <me@davidsansome.com>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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/>.
 
16
*/
 
17
 
 
18
#include "echonesttags.h"
 
19
#include "tagwidget.h"
 
20
 
 
21
#include <echonest/Artist.h>
 
22
 
 
23
#include <boost/scoped_ptr.hpp>
 
24
 
 
25
struct EchoNestTags::Request {
 
26
  Request(int id) : id_(id), artist_(new Echonest::Artist) {}
 
27
 
 
28
  int id_;
 
29
  boost::scoped_ptr<Echonest::Artist> artist_;
 
30
};
 
31
 
 
32
void EchoNestTags::FetchInfo(int id, const Song& metadata) {
 
33
  boost::shared_ptr<Request> request(new Request(id));
 
34
  request->artist_->setName(metadata.artist());
 
35
 
 
36
  QNetworkReply* reply = request->artist_->fetchTerms();
 
37
  connect(reply, SIGNAL(finished()), SLOT(RequestFinished()));
 
38
  requests_[reply] = request;
 
39
}
 
40
 
 
41
void EchoNestTags::RequestFinished() {
 
42
  QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
 
43
  if (!reply || !requests_.contains(reply))
 
44
    return;
 
45
  reply->deleteLater();
 
46
 
 
47
  RequestPtr request = requests_.take(reply);
 
48
 
 
49
  try {
 
50
    request->artist_->parseProfile(reply);
 
51
  } catch (Echonest::ParseError e) {
 
52
    qWarning() << "Error parsing echonest reply:" << e.errorType() << e.what();
 
53
  }
 
54
 
 
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");
 
61
 
 
62
    TagWidget* widget = new TagWidget(TagWidget::Type_Tags);
 
63
    data.contents_ = widget;
 
64
 
 
65
    widget->SetIcon(data.icon_);
 
66
 
 
67
    foreach (const Echonest::Term& term, request->artist_->terms()) {
 
68
      widget->AddTag(term.name());
 
69
      if (widget->count() >= 10)
 
70
        break;
 
71
    }
 
72
 
 
73
    emit InfoReady(request->id_, data);
 
74
  }
 
75
 
 
76
  emit Finished(request->id_);
 
77
}
 
78