~ari-tczew/ubuntu/natty/clementine/lp-747113

« back to all changes in this revision

Viewing changes to src/radio/lastfmservice.cpp

  • Committer: Artur Rona
  • Date: 2011-04-04 20:05:33 UTC
  • Revision ID: ari-tczew@ubuntu.com-20110404200533-6aclzasj5pp8t1hq
* New upstream release. (LP: #747113)
* Drop all patches, have been applied upstream.
* Update debian/copyright.
* Refresh description in debian/control in order to avoid lintian error.
* Bump debhelper to 8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
*/
17
17
 
18
18
#include "lastfmservice.h"
19
 
#include "radioitem.h"
20
19
#include "lastfmstationdialog.h"
21
20
#include "radiomodel.h"
22
21
#include "radioplaylistitem.h"
51
50
const char* LastFMService::kApiKey = "75d20fb472be99275392aefa2760ea09";
52
51
const char* LastFMService::kSecret = "d3072b60ae626be12be69448f5c46e70";
53
52
 
 
53
const char* LastFMService::kUrlArtist   = "lastfm://artist/%1/similarartists";
 
54
const char* LastFMService::kUrlTag      = "lastfm://globaltags/%1";
 
55
const char* LastFMService::kUrlCustom   = "lastfm://rql/%1";
 
56
 
 
57
const char* LastFMService::kTitleArtist = QT_TR_NOOP("Last.fm Similar Artists to %1");
 
58
const char* LastFMService::kTitleTag    = QT_TR_NOOP("Last.fm Tag Radio: %1");
 
59
const char* LastFMService::kTitleCustom = QT_TR_NOOP("Last.fm Custom Radio: %1");
 
60
 
54
61
LastFMService::LastFMService(RadioModel* parent)
55
62
  : RadioService(kServiceName, parent),
56
63
    scrobbler_(NULL),
67
74
{
68
75
  ReloadSettings();
69
76
 
70
 
  play_action_ = context_menu_->addAction(
71
 
      IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
72
 
  load_action_ = context_menu_->addAction(
73
 
      IconLoader::Load("media-playback-start"), tr("Load"), this, SLOT(LoadToPlaylist()));
 
77
  context_menu_->addActions(GetPlaylistActions());
74
78
  remove_action_ = context_menu_->addAction(
75
79
      IconLoader::Load("list-remove"), tr("Remove"), this, SLOT(Remove()));
76
80
  context_menu_->addSeparator();
112
116
  return !lastfm::ws::SessionKey.isEmpty();
113
117
}
114
118
 
115
 
RadioItem* LastFMService::CreateRootItem(RadioItem* parent) {
116
 
  RadioItem* item = new RadioItem(this, RadioItem::Type_Service, kServiceName, parent);
117
 
  item->icon = QIcon(":last.fm/as.png");
 
119
QStandardItem* LastFMService::CreateRootItem() {
 
120
  QStandardItem* item = new QStandardItem(QIcon(":last.fm/as.png"), kServiceName);
 
121
  item->setData(true, RadioModel::Role_CanLazyLoad);
118
122
  return item;
119
123
}
120
124
 
121
 
void LastFMService::LazyPopulate(RadioItem *item) {
122
 
  switch (item->type) {
123
 
    case RadioItem::Type_Service:
 
125
void LastFMService::LazyPopulate(QStandardItem* parent) {
 
126
  switch (parent->data(RadioModel::Role_Type).toInt()) {
 
127
    case RadioModel::Type_Service:
124
128
      // Normal radio types
125
 
      CreateStationItem(Type_MyRecommendations, tr("My Recommendations"), ":last.fm/recommended_radio.png", item);
126
 
      CreateStationItem(Type_MyRadio, tr("My Radio Station"), ":last.fm/personal_radio.png", item);
127
 
      CreateStationItem(Type_MyMix, tr("My Mix Radio"), ":last.fm/loved_radio.png", item);
128
 
      CreateStationItem(Type_MyNeighbourhood, tr("My Neighborhood"), ":last.fm/neighbour_radio.png", item);
 
129
      CreateStationItem(parent,
 
130
          tr("My Recommendations"),
 
131
          ":last.fm/recommended_radio.png",
 
132
          "lastfm://user/USERNAME/recommended",
 
133
          tr("My Last.fm Recommended Radio"));
 
134
      CreateStationItem(parent,
 
135
          tr("My Radio Station"),
 
136
          ":last.fm/personal_radio.png",
 
137
          "lastfm://user/USERNAME/library",
 
138
          tr("My Last.fm Library"));
 
139
      CreateStationItem(parent,
 
140
          tr("My Mix Radio"),
 
141
          ":last.fm/loved_radio.png",
 
142
          "lastfm://user/USERNAME/mix",
 
143
          tr("My Last.fm Mix Radio"));
 
144
      CreateStationItem(parent,
 
145
          tr("My Neighborhood"),
 
146
          ":last.fm/neighbour_radio.png",
 
147
          "lastfm://user/USERNAME/neighbours",
 
148
          tr("My Last.fm Neighborhood"));
129
149
 
130
150
      // Types that have children
131
 
      artist_list_ = new RadioItem(this, Type_ArtistRadio, tr("Artist radio"), item);
132
 
      artist_list_->icon = QIcon(":last.fm/icon_radio.png");
133
 
      artist_list_->lazy_loaded = true;
134
 
 
135
 
      tag_list_ = new RadioItem(this, Type_TagRadio, tr("Tag radio"), item);
136
 
      tag_list_->icon = QIcon(":last.fm/icon_tag.png");
137
 
      tag_list_->lazy_loaded = true;
138
 
 
139
 
      custom_list_ = new RadioItem(this, Type_CustomRadio, tr("Custom radio"), item);
140
 
      custom_list_->icon = QIcon(":last.fm/icon_radio.png");
141
 
      custom_list_->lazy_loaded = true;
142
 
 
143
 
      RestoreList("artists", Type_Artist, QIcon(":last.fm/icon_radio.png"), artist_list_);
144
 
      RestoreList("tags", Type_Tag, QIcon(":last.fm/icon_tag.png"), tag_list_);
145
 
      RestoreList("custom", Type_Custom, QIcon(":last.fm/icon_radio.png"), custom_list_);
146
 
 
147
 
      friends_list_ = new RadioItem(this, Type_MyFriends, tr("Friends"), item);
148
 
      friends_list_->icon = QIcon(":last.fm/my_friends.png");
149
 
 
150
 
      neighbours_list_ = new RadioItem(this, Type_MyNeighbours, tr("Neighbors"), item);
151
 
      neighbours_list_->icon = QIcon(":last.fm/my_neighbours.png");
 
151
      artist_list_ = new QStandardItem(QIcon(":last.fm/icon_radio.png"), tr("Artist radio"));
 
152
      artist_list_->setData(Type_Artists, RadioModel::Role_Type);
 
153
      parent->appendRow(artist_list_);
 
154
 
 
155
      tag_list_ = new QStandardItem(QIcon(":last.fm/icon_tag.png"), tr("Tag radio"));
 
156
      tag_list_->setData(Type_Tags, RadioModel::Role_Type);
 
157
      parent->appendRow(tag_list_);
 
158
 
 
159
      custom_list_ = new QStandardItem(QIcon(":last.fm/icon_radio.png"), tr("Custom radio"));
 
160
      custom_list_->setData(Type_Custom, RadioModel::Role_Type);
 
161
      parent->appendRow(custom_list_);
 
162
 
 
163
      RestoreList("artists", kUrlArtist, tr(kTitleArtist), QIcon(":last.fm/icon_radio.png"), artist_list_);
 
164
      RestoreList("tags", kUrlTag, tr(kTitleTag), QIcon(":last.fm/icon_tag.png"), tag_list_);
 
165
      RestoreList("custom", kUrlCustom, tr(kTitleCustom), QIcon(":last.fm/icon_radio.png"), custom_list_);
 
166
 
 
167
      friends_list_ = new QStandardItem(QIcon(":last.fm/my_friends.png"), tr("Friends"));
 
168
      friends_list_->setData(Type_Friends, RadioModel::Role_Type);
 
169
      friends_list_->setData(true, RadioModel::Role_CanLazyLoad);
 
170
      parent->appendRow(friends_list_);
 
171
 
 
172
      neighbours_list_ = new QStandardItem(QIcon(":last.fm/my_neighbours.png"), tr("Neighbors"));
 
173
      neighbours_list_->setData(Type_Neighbours, RadioModel::Role_Type);
 
174
      neighbours_list_->setData(true, RadioModel::Role_CanLazyLoad);
 
175
      parent->appendRow(neighbours_list_);
152
176
 
153
177
      if (!IsAuthenticated())
154
178
        ShowConfig();
158
182
      add_custom_action_->setEnabled(true);
159
183
      break;
160
184
 
161
 
    case Type_MyFriends:
 
185
    case Type_Friends:
162
186
      RefreshFriends();
163
187
      break;
164
188
 
165
 
    case Type_MyNeighbours:
 
189
    case Type_Neighbours:
166
190
      RefreshNeighbours();
167
191
      break;
168
192
 
169
193
    case Type_OtherUser:
170
 
      CreateStationItem(Type_OtherUserRadio, item->key, ":last.fm/recommended_radio.png", item)
171
 
          ->display_text = tr("Last.fm Radio Station - %1").arg(item->key);
172
 
      CreateStationItem(Type_OtherUserMix, item->key, ":last.fm/loved_radio.png", item)
173
 
          ->display_text = tr("Last.fm Mix Radio - %1").arg(item->key);
174
 
      CreateStationItem(Type_OtherUserNeighbourhood, item->key, ":last.fm/neighbour_radio.png", item)
175
 
          ->display_text = tr("Last.fm Neighbor Radio - %1").arg(item->key);
 
194
      CreateStationItem(parent,
 
195
          tr("Last.fm Radio Station - %1").arg(parent->text()),
 
196
          ":last.fm/personal_radio.png",
 
197
          "lastfm://user/" + parent->text() + "/library",
 
198
          tr("Last.fm Library - %1").arg(parent->text()));
 
199
      CreateStationItem(parent,
 
200
          tr("Last.fm Mix Radio - %1").arg(parent->text()),
 
201
          ":last.fm/loved_radio.png",
 
202
          "lastfm://user/" + parent->text() + "/mix",
 
203
          tr("Last.fm Mix Radio - %1").arg(parent->text()));
 
204
      CreateStationItem(parent,
 
205
          tr("Last.fm Neighbor Radio - %1").arg(parent->text()),
 
206
          ":last.fm/neighbour_radio.png",
 
207
          "lastfm://user/" + parent->text() + "/neighbours",
 
208
          tr("Last.fm Neighbor Radio - %1").arg(parent->text()));
176
209
      break;
177
210
 
178
211
    default:
179
212
      break;
180
213
  }
181
 
 
182
 
  item->lazy_loaded = true;
183
214
}
184
215
 
185
 
RadioItem* LastFMService::CreateStationItem(ItemType type, const QString& name,
186
 
                                            const QString& icon, RadioItem* parent) {
187
 
  RadioItem* ret = new RadioItem(this, type, name, parent);
188
 
  ret->lazy_loaded = true;
189
 
  ret->icon = QIcon(icon);
190
 
  ret->playable = true;
191
 
 
 
216
QStandardItem* LastFMService::CreateStationItem(
 
217
    QStandardItem* parent, const QString& name, const QString& icon,
 
218
    const QString& url, const QString& title) {
 
219
  QStandardItem* ret = new QStandardItem(QIcon(icon), name);
 
220
  ret->setData(url, RadioModel::Role_Url);
 
221
  ret->setData(title, RadioModel::Role_Title);
 
222
  ret->setData(RadioModel::PlayBehaviour_SingleItem, RadioModel::Role_PlayBehaviour);
 
223
  parent->appendRow(ret);
192
224
  return ret;
193
225
}
194
226
 
248
280
  emit AuthenticationComplete(true);
249
281
}
250
282
 
251
 
QUrl LastFMService::UrlForItem(const RadioItem* item) const {
252
 
  switch (item->type) {
253
 
    case Type_MyRecommendations:
254
 
      return "lastfm://user/" + lastfm::ws::Username + "/recommended";
255
 
 
256
 
    case Type_MyMix:
257
 
      return QString("lastfm://rql/") + QString("adv:" + lastfm::ws::Username).toUtf8().toBase64();
258
 
 
259
 
    case Type_MyNeighbourhood:
260
 
      return "lastfm://user/" + lastfm::ws::Username + "/neighbours";
261
 
 
262
 
    case Type_MyRadio:
263
 
      return "lastfm://user/" + lastfm::ws::Username + "/library";
264
 
 
265
 
    case Type_OtherUser:
266
 
    case Type_OtherUserRadio:
267
 
      return "lastfm://user/" + item->key + "/library";
268
 
 
269
 
    case Type_OtherUserMix:
270
 
      return QString("lastfm://rql/") + QString("adv:" + item->key).toUtf8().toBase64();
271
 
 
272
 
    case Type_OtherUserNeighbourhood:
273
 
      return "lastfm://user/" + item->key + "/neighbours";
274
 
 
275
 
    case Type_Artist:
276
 
      return "lastfm://artist/" + item->key + "/similarartists";
277
 
 
278
 
    case Type_Tag:
279
 
      return "lastfm://globaltags/" + item->key;
280
 
 
281
 
    case Type_Custom:
282
 
      return QString("lastfm://rql/" + item->key.toUtf8().toBase64());
283
 
  }
284
 
  return QUrl();
285
 
}
286
 
 
287
 
QString LastFMService::TitleForItem(const RadioItem* item) const {
288
 
  const QString me(lastfm::ws::Username);
289
 
 
290
 
  switch (item->type) {
291
 
    case Type_MyRecommendations: return tr("Last.fm Recommended Radio - %1").arg(me);
292
 
    case Type_MyMix:             return tr("Last.fm Mix Radio - %1").arg(me);
293
 
    case Type_MyNeighbourhood:   return tr("Last.fm Neighbor Radio - %1").arg(me);
294
 
    case Type_MyRadio:           return tr("Last.fm Library - %1").arg(me);
295
 
    case Type_OtherUser:
296
 
    case Type_OtherUserRadio:    return tr("Last.fm Library - %1").arg(item->key);
297
 
    case Type_OtherUserMix:      return tr("Last.fm Mix Radio - %1").arg(item->key);
298
 
    case Type_OtherUserNeighbourhood: return tr("Last.fm Neighbor Radio - %1").arg(item->key);
299
 
    case Type_Artist:            return tr("Last.fm Similar Artists to %1").arg(item->key);
300
 
    case Type_Tag:               return tr("Last.fm Tag Radio: %1").arg(item->key);
301
 
    case Type_Custom:            return tr("Last.fm Custom Radio: %1").arg(item->key);
302
 
  }
303
 
  return QString();
 
283
QUrl LastFMService::FixupUrl(const QUrl& url) {
 
284
  QUrl ret;
 
285
  ret.setEncodedUrl(url.toEncoded().replace(
 
286
      "USERNAME", QUrl::toPercentEncoding(lastfm::ws::Username)));
 
287
  return ret;
304
288
}
305
289
 
306
290
PlaylistItem::SpecialLoadResult LastFMService::StartLoading(const QUrl& url) {
314
298
 
315
299
  last_url_ = url;
316
300
  initial_tune_ = true;
317
 
  Tune(lastfm::RadioStation(url));
 
301
  Tune(lastfm::RadioStation(FixupUrl(url)));
318
302
 
319
303
  return PlaylistItem::SpecialLoadResult(
320
304
      PlaylistItem::SpecialLoadResult::WillLoadAsynchronously, url);
321
305
}
322
306
 
323
 
PlaylistItem::SpecialLoadResult LastFMService::LoadNext(const QUrl &) {
 
307
PlaylistItem::SpecialLoadResult LastFMService::LoadNext(const QUrl&) {
324
308
  if (playlist_.empty()) {
325
309
    return PlaylistItem::SpecialLoadResult();
326
310
  }
464
448
  emit AsyncLoadFinished(LoadNext(last_url_));
465
449
}
466
450
 
467
 
void LastFMService::ShowContextMenu(RadioItem* item, const QModelIndex&,
468
 
                                    const QPoint &global_pos) {
469
 
  context_item_ = item;
 
451
void LastFMService::ShowContextMenu(const QModelIndex& index, const QPoint &global_pos) {
 
452
  context_item_ = model()->itemFromIndex(index);
470
453
 
471
 
  switch (item->type) {
472
 
    case Type_Artist:
473
 
    case Type_Tag:
 
454
  switch (index.parent().data(RadioModel::Role_Type).toInt()) {
 
455
    case Type_Artists:
 
456
    case Type_Tags:
474
457
    case Type_Custom:
475
458
      remove_action_->setEnabled(true);
476
459
      break;
480
463
      break;
481
464
  }
482
465
 
483
 
  play_action_->setEnabled(item->playable);
484
 
  load_action_->setEnabled(item->playable);
 
466
  const bool playable = model()->IsPlayable(index);
 
467
  GetAppendToPlaylistAction()->setEnabled(playable);
 
468
  GetReplacePlaylistAction()->setEnabled(playable);
 
469
  GetOpenInNewPlaylistAction()->setEnabled(playable);
485
470
  context_menu_->popup(global_pos);
486
471
}
487
472
 
489
474
  if (!friends_list_ || !IsAuthenticated())
490
475
    return;
491
476
 
492
 
  friends_list_->ClearNotify();
 
477
  if (friends_list_->hasChildren())
 
478
    friends_list_->removeRows(0, friends_list_->rowCount());
493
479
 
494
480
  lastfm::AuthenticatedUser user;
495
481
  QNetworkReply* reply = user.getFriends();
497
483
}
498
484
 
499
485
void LastFMService::RefreshNeighbours() {
500
 
  if (!friends_list_ || !IsAuthenticated())
 
486
  if (!neighbours_list_ || !IsAuthenticated())
501
487
    return;
502
488
 
503
 
  neighbours_list_->ClearNotify();
 
489
  if (neighbours_list_->hasChildren())
 
490
    neighbours_list_->removeRows(0, neighbours_list_->rowCount());
504
491
 
505
492
  lastfm::AuthenticatedUser user;
506
493
  QNetworkReply* reply = user.getNeighbours();
526
513
  }
527
514
 
528
515
  foreach (const lastfm::User& f, friends) {
529
 
    RadioItem* item = new RadioItem(this, Type_OtherUser, f);
530
 
    item->icon = QIcon(":last.fm/icon_user.png");
531
 
    item->playable = true;
532
 
    item->InsertNotify(friends_list_);
 
516
    QStandardItem* item = new QStandardItem(QIcon(":last.fm/icon_user.png"), f.name());
 
517
    item->setData(QUrl("lastfm://user/" + f.name() + "/library"), RadioModel::Role_Url);
 
518
    item->setData(tr("Last.fm Library - %1").arg(f.name()), RadioModel::Role_Title);
 
519
    item->setData(true, RadioModel::Role_CanLazyLoad);
 
520
    item->setData(Type_OtherUser, RadioModel::Role_Type);
 
521
    item->setData(RadioModel::PlayBehaviour_SingleItem, RadioModel::Role_PlayBehaviour);
 
522
    friends_list_->appendRow(item);
533
523
  }
534
524
}
535
525
 
552
542
  }
553
543
 
554
544
  foreach (const lastfm::User& n, neighbours) {
555
 
    RadioItem* item = new RadioItem(this, Type_OtherUser, n);
556
 
    item->icon = QIcon(":last.fm/user_purple.png");
557
 
    item->playable = true;
558
 
    item->InsertNotify(neighbours_list_);
 
545
    QStandardItem* item = new QStandardItem(QIcon(":last.fm/user_purple.png"), n.name());
 
546
    item->setData(QUrl("lastfm://user/" + n.name() + "/library"), RadioModel::Role_Url);
 
547
    item->setData(tr("Last.fm Library - %1").arg(n.name()), RadioModel::Role_Title);
 
548
    item->setData(true, RadioModel::Role_CanLazyLoad);
 
549
    item->setData(Type_OtherUser, RadioModel::Role_Type);
 
550
    item->setData(RadioModel::PlayBehaviour_SingleItem, RadioModel::Role_PlayBehaviour);
 
551
    neighbours_list_->appendRow(item);
559
552
  }
560
553
}
561
554
 
562
 
void LastFMService::AddToPlaylist() {
563
 
  emit AddItemToPlaylist(context_item_, false);
564
 
}
565
 
 
566
 
void LastFMService::LoadToPlaylist() {
567
 
  emit AddItemToPlaylist(context_item_, true);
 
555
QModelIndex LastFMService::GetCurrentIndex() {
 
556
  return context_item_->index();
568
557
}
569
558
 
570
559
void LastFMService::AddArtistRadio() {
571
 
  AddArtistOrTag("artists", LastFMStationDialog::Artist, Type_Artist, QIcon(":last.fm/icon_radio.png"), artist_list_);
 
560
  AddArtistOrTag("artists", LastFMStationDialog::Artist,
 
561
                 kUrlArtist, tr(kTitleArtist),
 
562
                 ":last.fm/icon_radio.png", artist_list_);
572
563
}
573
564
 
574
565
void LastFMService::AddTagRadio() {
575
 
  AddArtistOrTag("tags", LastFMStationDialog::Tag, Type_Tag, QIcon(":last.fm/icon_tag.png"), tag_list_);
 
566
  AddArtistOrTag("tags", LastFMStationDialog::Tag,
 
567
                 kUrlTag, tr(kTitleTag),
 
568
                 ":last.fm/icon_tag.png", tag_list_);
576
569
}
577
570
 
578
571
void LastFMService::AddCustomRadio() {
579
 
  AddArtistOrTag("custom", LastFMStationDialog::Custom, Type_Custom, QIcon(":last.fm/icon_radio.png"), custom_list_);
 
572
  AddArtistOrTag("custom", LastFMStationDialog::Custom,
 
573
                 kUrlCustom, tr(kTitleCustom),
 
574
                 ":last.fm/icon_radio.png", custom_list_);
580
575
}
581
576
 
582
577
void LastFMService::AddArtistOrTag(const QString& name,
583
 
                                   LastFMStationDialog::Type dialog_type, ItemType item_type,
584
 
                                   const QIcon& icon, RadioItem* list) {
 
578
                                   LastFMStationDialog::Type dialog_type,
 
579
                                   const QString& url_pattern,
 
580
                                   const QString& title_pattern,
 
581
                                   const QString& icon, QStandardItem* list) {
585
582
  station_dialog_->SetType(dialog_type);
586
583
  if (station_dialog_->exec() == QDialog::Rejected)
587
584
    return;
589
586
  if (station_dialog_->content().isEmpty())
590
587
    return;
591
588
 
592
 
  RadioItem* item = new RadioItem(this, item_type, station_dialog_->content());
593
 
  item->icon = icon;
594
 
  item->playable = true;
595
 
  item->lazy_loaded = true;
596
 
  item->InsertNotify(list);
597
 
  emit AddItemToPlaylist(item, false);
 
589
  QString content = station_dialog_->content();
 
590
  QString url_content;
 
591
  if (name == "custom")
 
592
    url_content = content.toUtf8().toBase64();
 
593
  else
 
594
    url_content = content;
 
595
 
 
596
  QStandardItem* item = new QStandardItem(QIcon(icon), content);
 
597
  item->setData(url_pattern.arg(url_content), RadioModel::Role_Url);
 
598
  item->setData(title_pattern.arg(content), RadioModel::Role_Title);
 
599
  item->setData(RadioModel::PlayBehaviour_SingleItem, RadioModel::Role_PlayBehaviour);
 
600
  list->appendRow(item);
 
601
  emit AddItemToPlaylist(item->index(), AddMode_Append);
598
602
 
599
603
  SaveList(name, list);
600
604
}
601
605
 
602
 
void LastFMService::SaveList(const QString& name, RadioItem* list) const {
 
606
void LastFMService::SaveList(const QString& name, QStandardItem* list) const {
603
607
  QSettings settings;
604
608
  settings.beginGroup(kSettingsGroup);
605
609
 
606
 
  settings.beginWriteArray(name, list->children.count());
607
 
  for (int i=0 ; i<list->children.count() ; ++i) {
 
610
  settings.beginWriteArray(name, list->rowCount());
 
611
  for (int i=0 ; i<list->rowCount() ; ++i) {
608
612
    settings.setArrayIndex(i);
609
 
    settings.setValue("key", list->children[i]->key);
 
613
    settings.setValue("key", list->child(i)->text());
610
614
  }
611
615
  settings.endArray();
612
616
}
613
617
 
614
 
void LastFMService::RestoreList(const QString &name, ItemType item_type,
615
 
                                const QIcon& icon, RadioItem *list) {
 
618
void LastFMService::RestoreList(const QString& name,
 
619
                                const QString& url_pattern,
 
620
                                const QString& title_pattern,
 
621
                                const QIcon& icon, QStandardItem* parent) {
616
622
  QSettings settings;
617
623
  settings.beginGroup(kSettingsGroup);
618
624
 
619
 
  list->ClearNotify();
 
625
  if (parent->hasChildren())
 
626
    parent->removeRows(0, parent->rowCount());
620
627
 
621
628
  int count = settings.beginReadArray(name);
622
629
  for (int i=0 ; i<count ; ++i) {
623
630
    settings.setArrayIndex(i);
624
 
    RadioItem* item = new RadioItem(this, item_type,
625
 
                                    settings.value("key").toString(), list);
626
 
    item->icon = icon;
627
 
    item->playable = true;
628
 
    item->lazy_loaded = true;
 
631
    QString content = settings.value("key").toString();
 
632
    QString url_content;
 
633
    if (name == "custom")
 
634
      url_content = content.toUtf8().toBase64();
 
635
    else
 
636
      url_content = content;
 
637
 
 
638
    QStandardItem* item = new QStandardItem(icon, content);
 
639
    item->setData(url_pattern.arg(url_content), RadioModel::Role_Url);
 
640
    item->setData(title_pattern.arg(content), RadioModel::Role_Title);
 
641
    item->setData(RadioModel::PlayBehaviour_SingleItem, RadioModel::Role_PlayBehaviour);
 
642
    parent->appendRow(item);
629
643
  }
630
644
  settings.endArray();
631
645
}
632
646
 
633
647
void LastFMService::Remove() {
634
 
  int type = context_item_->type;
635
 
 
636
 
  context_item_->parent->DeleteNotify(context_item_->row);
637
 
 
638
 
  if (type == Type_Artist)
 
648
  int type = context_item_->parent()->data(RadioModel::Role_Type).toInt();
 
649
 
 
650
  context_item_->parent()->removeRow(context_item_->row());
 
651
 
 
652
  if (type == Type_Artists)
639
653
    SaveList("artists", artist_list_);
640
 
  else if (type == Type_Tag)
 
654
  else if (type == Type_Tags)
641
655
    SaveList("tags", tag_list_);
642
656
  else if (type == Type_Custom)
643
657
    SaveList("custom", custom_list_);
747
761
 
748
762
  if (sections.count() == 2 && url.host() == "artist" && sections[1] == "similarartists") {
749
763
    ret.reset(new RadioPlaylistItem(this, url,
750
 
        tr("Last.fm Similar Artists to %1").arg(sections[0]), QString()));
 
764
        tr(kTitleArtist).arg(sections[0]), QString()));
751
765
  } else if (sections.count() == 1 && url.host() == "globaltags") {
752
766
    ret.reset(new RadioPlaylistItem(this, url,
753
 
        tr("Last.fm Tag Radio: %1").arg(sections[0]), QString()));
 
767
        tr(kTitleTag).arg(sections[0]), QString()));
754
768
  }
755
769
 
756
770
  return ret;