From bfc81e4d5c0d3e09904f394cc6d1a80153ecdfb3 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Wed, 30 Dec 2009 01:41:37 +0000 Subject: [PATCH] Play in last.fm context menu --- src/lastfmservice.cpp | 12 +++++++++++- src/lastfmservice.h | 6 ++++++ src/mainwindow.cpp | 7 ++++++- src/mainwindow.h | 2 ++ src/radiomodel.cpp | 1 + src/radiomodel.h | 2 ++ src/radioservice.h | 2 ++ 7 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lastfmservice.cpp b/src/lastfmservice.cpp index 6ec2a64b4..9993cb01c 100644 --- a/src/lastfmservice.cpp +++ b/src/lastfmservice.cpp @@ -42,8 +42,11 @@ LastFMService::LastFMService(QObject* parent) config_->ui_.username->setText(lastfm::ws::Username); config_->ui_.scrobble->setEnabled(scrobbling_enabled_); + play_action_ = context_menu_->addAction(QIcon(":media-playback-start.png"), "Add to playlist", this, SLOT(AddToPlaylist())); + context_menu_->addSeparator(); context_menu_->addAction(QIcon(":configure.png"), "Configure Last.fm...", config_, SLOT(show())); + } LastFMService::~LastFMService() { @@ -365,7 +368,10 @@ void LastFMService::Ban() { LoadNext(last_url_); } -void LastFMService::ShowContextMenu(RadioItem *, const QPoint &global_pos) { +void LastFMService::ShowContextMenu(RadioItem* item, const QPoint &global_pos) { + context_item_ = item; + + play_action_->setEnabled(item->playable); context_menu_->popup(global_pos); } @@ -434,3 +440,7 @@ void LastFMService::RefreshNeighboursFinished() { item->InsertNotify(neighbours_list_); } } + +void LastFMService::AddToPlaylist() { + emit AddItemToPlaylist(context_item_); +} diff --git a/src/lastfmservice.h b/src/lastfmservice.h index f9f617b27..d72bc3a17 100644 --- a/src/lastfmservice.h +++ b/src/lastfmservice.h @@ -7,6 +7,7 @@ #include class QMenu; +class QAction; class LastFMConfig; @@ -78,6 +79,8 @@ class LastFMService : public RadioService { void TunerTrackAvailable(); void TunerError(lastfm::ws::Error error); + void AddToPlaylist(); + private: RadioItem* CreateStationItem(ItemType type, const QString& name, const QString& icon, RadioItem* parent); @@ -93,7 +96,10 @@ class LastFMService : public RadioService { lastfm::Track last_track_; LastFMConfig* config_; + QMenu* context_menu_; + QAction* play_action_; + RadioItem* context_item_; QUrl last_url_; bool initial_tune_; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f2aabe2bd..83b75c3aa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -156,6 +156,7 @@ MainWindow::MainWindow(QWidget *parent) connect(radio_model_, SIGNAL(StreamFinished()), player_, SLOT(Next())); connect(radio_model_, SIGNAL(StreamReady(QUrl,QUrl)), player_, SLOT(StreamReady(QUrl,QUrl))); connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), playlist_, SLOT(SetStreamMetadata(QUrl,Song))); + connect(radio_model_, SIGNAL(AddItemToPlaylist(RadioItem*)), SLOT(InsertRadioItem(RadioItem*))); connect(radio_model_->GetLastFMService(), SIGNAL(ScrobblingEnabledChanged(bool)), SLOT(ScrobblingEnabledChanged(bool))); connect(ui_.radio_view, SIGNAL(doubleClicked(QModelIndex)), SLOT(RadioDoubleClick(QModelIndex))); @@ -363,8 +364,12 @@ void MainWindow::Love() { } void MainWindow::RadioDoubleClick(const QModelIndex& index) { + InsertRadioItem(radio_model_->IndexToItem(index)); +} + +void MainWindow::InsertRadioItem(RadioItem* item) { QModelIndex first_song = playlist_->InsertRadioStations( - QList() << radio_model_->IndexToItem(index)); + QList() << item); if (first_song.isValid() && player_->GetState() != Engine::Playing) player_->PlayAt(first_song.row()); diff --git a/src/mainwindow.h b/src/mainwindow.h index 76af1102e..b680727cf 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -12,6 +12,7 @@ class Library; class LibraryConfig; class RadioModel; class Song; +class RadioItem; class QSortFilterProxyModel; class SystemTrayIcon; @@ -50,6 +51,7 @@ class MainWindow : public QMainWindow { void UpdateTrackPosition(); void RadioDoubleClick(const QModelIndex& index); + void InsertRadioItem(RadioItem*); void ScrobblingEnabledChanged(bool value); void Love(); diff --git a/src/radiomodel.cpp b/src/radiomodel.cpp index 9fc898592..0ba81ff2d 100644 --- a/src/radiomodel.cpp +++ b/src/radiomodel.cpp @@ -28,6 +28,7 @@ void RadioModel::AddService(RadioService *service) { connect(service, SIGNAL(StreamFinished()), SIGNAL(StreamFinished())); connect(service, SIGNAL(StreamError(QString)), SIGNAL(StreamError(QString))); connect(service, SIGNAL(StreamMetadataFound(QUrl,Song)), SIGNAL(StreamMetadataFound(QUrl,Song))); + connect(service, SIGNAL(AddItemToPlaylist(RadioItem*)), SIGNAL(AddItemToPlaylist(RadioItem*))); } RadioService* RadioModel::ServiceByName(const QString& name) { diff --git a/src/radiomodel.h b/src/radiomodel.h index aebf69be3..cbd4fd9a0 100644 --- a/src/radiomodel.h +++ b/src/radiomodel.h @@ -42,6 +42,8 @@ class RadioModel : public SimpleTreeModel { void StreamError(const QString& message); void StreamMetadataFound(const QUrl& original_url, const Song& song); + void AddItemToPlaylist(RadioItem* item); + protected: void LazyPopulate(RadioItem* parent); diff --git a/src/radioservice.h b/src/radioservice.h index 130bb963c..864228dbb 100644 --- a/src/radioservice.h +++ b/src/radioservice.h @@ -41,6 +41,8 @@ class RadioService : public QObject { void StreamError(const QString& message); void StreamMetadataFound(const QUrl& original_url, const Song& song); + void AddItemToPlaylist(RadioItem* item); + private: QString name_; };