~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/songinfo/tagwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
*/
17
17
 
18
18
#include "tagwidget.h"
 
19
#include "internet/lastfmservice.h"
 
20
#include "internet/internetmimedata.h"
 
21
#include "internet/internetmodel.h"
19
22
#include "playlist/playlistitemmimedata.h"
20
 
#include "radio/lastfmservice.h"
21
 
#include "radio/radiomimedata.h"
22
 
#include "radio/radiomodel.h"
23
23
#include "smartplaylists/generator.h"
24
24
#include "smartplaylists/generatormimedata.h"
25
25
#include "smartplaylists/querygenerator.h"
113
113
 
114
114
TagWidget::TagWidget(Type type, QWidget* parent)
115
115
  : QWidget(parent),
116
 
    type_(type),
117
 
    menu_(NULL)
 
116
    type_(type)
118
117
{
119
118
  setLayout(new FlowLayout(4, 6, 4));
120
119
}
130
129
  tags_ << widget;
131
130
}
132
131
 
133
 
void TagWidget::EnsureMenuCreated() {
134
 
  if (menu_)
135
 
    return;
136
 
 
137
 
  menu_ = new QMenu(this);
138
 
  switch (type_) {
139
 
    case Type_Tags:
140
 
      menu_->addAction(QIcon(":/last.fm/as.png"), tr("Play last.fm tag radio"),
141
 
                       this, SLOT(PlayLastFmTagRadio()));
142
 
      break;
143
 
 
144
 
    case Type_Artists:
145
 
      menu_->addAction(QIcon(":/last.fm/as.png"), tr("Play last.fm artist radio"),
146
 
                       this, SLOT(PlayLastFmArtistRadio()));
147
 
      menu_->addAction(IconLoader::Load("folder-sound"), tr("Play from my Library"),
148
 
                       this, SLOT(PlayFromLibrary()));
149
 
      break;
150
 
  }
151
 
}
152
 
 
153
132
void TagWidget::TagClicked() {
154
133
  TagWidgetTag* tag = qobject_cast<TagWidgetTag*>(sender());
155
134
  if (!tag)
156
135
    return;
157
136
 
158
 
  EnsureMenuCreated();
159
 
 
160
 
  context_item_ = tag->text();
161
 
  menu_->popup(tag->mapToGlobal(tag->rect().bottomLeft()));
162
 
}
163
 
 
164
 
void TagWidget::PlayLastFmArtistRadio() {
165
 
  PlayLastFm("lastfm://artist/%1/similarartists");
166
 
}
167
 
 
168
 
void TagWidget::PlayLastFmTagRadio() {
169
 
  PlayLastFm("lastfm://globaltags/%1");
170
 
}
171
 
 
172
 
void TagWidget::PlayFromLibrary() {
173
 
  using smart_playlists::GeneratorMimeData;
174
 
  using smart_playlists::GeneratorPtr;
175
 
  using smart_playlists::QueryGenerator;
176
 
  using smart_playlists::Search;
177
 
  using smart_playlists::SearchTerm;
178
 
 
179
 
  GeneratorPtr gen(new QueryGenerator(QString(), Search(
180
 
      Search::Type_And, Search::TermList() <<
181
 
        SearchTerm(SearchTerm::Field_Artist, SearchTerm::Op_Contains, context_item_),
182
 
      Search::Sort_FieldAsc, SearchTerm::Field_Album, 100)));
183
 
  emit AddToPlaylist(new GeneratorMimeData(gen));
184
 
}
185
 
 
186
 
void TagWidget::PlayLastFm(const QString& url_pattern) {
187
 
  LastFMService* last_fm = RadioModel::Service<LastFMService>();
188
 
  if (!last_fm->IsAuthenticated()) {
189
 
    last_fm->ShowConfig();
190
 
    return;
191
 
  }
192
 
 
193
 
  QUrl url(url_pattern.arg(context_item_));
194
 
  PlaylistItemPtr item(last_fm->PlaylistItemForUrl(url));
195
 
  if (!item)
196
 
    return;
197
 
 
198
 
  emit AddToPlaylist(new PlaylistItemMimeData(item));
 
137
  emit DoGlobalSearch(tag->text());
199
138
}