1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 11:19:18 +01:00

Add Load context menu item to all radio services. Fixes issue #1013

This commit is contained in:
David Sansome 2010-12-04 15:49:43 +00:00
parent f94f2cd03c
commit 5bb287c223
18 changed files with 102 additions and 23 deletions

View File

@ -271,8 +271,11 @@ void IcecastService::ShowContextMenu(RadioItem* item, const QModelIndex& index,
else
context_item_ = QModelIndex();
add_to_playlist_->setEnabled(context_item_.isValid() &&
model_->GetSong(context_item_).is_valid());
const bool can_play = context_item_.isValid() &&
model_->GetSong(context_item_).is_valid();
add_to_playlist_->setEnabled(can_play);
load_to_playlist_->setEnabled(can_play);
context_menu_->popup(global_pos);
}
@ -284,6 +287,8 @@ void IcecastService::EnsureMenuCreated() {
add_to_playlist_ = context_menu_->addAction(
IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
load_to_playlist_ = context_menu_->addAction(
IconLoader::Load("media-playback-start"), tr("Load"), this, SLOT(LoadToPlaylist()));
context_menu_->addSeparator();
context_menu_->addAction(IconLoader::Load("download"), tr("Open dir.xiph.org in browser"), this, SLOT(Homepage()));
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh station list"), this, SLOT(LoadDirectory()));
@ -294,10 +299,19 @@ void IcecastService::Homepage() {
}
void IcecastService::AddToPlaylist() {
AddSelectedToPlaylist(false);
}
void IcecastService::LoadToPlaylist() {
AddSelectedToPlaylist(true);
}
void IcecastService::AddSelectedToPlaylist(bool clear_first) {
Song song(model_->GetSong(context_item_));
if (!song.is_valid())
return;
emit AddItemsToPlaylist(PlaylistItemList() <<
PlaylistItemPtr(new SongPlaylistItem(song)));
PlaylistItemPtr(new SongPlaylistItem(song)),
clear_first);
}

View File

@ -57,17 +57,21 @@ class IcecastService : public RadioService {
void LoadDirectory();
void Homepage();
void AddToPlaylist();
void LoadToPlaylist();
private:
void EnsureMenuCreated();
IcecastBackend::StationList ParseDirectory(QIODevice* device) const;
IcecastBackend::Station ReadStation(QXmlStreamReader* reader) const;
void AddSelectedToPlaylist(bool clear_first);
RadioItem* root_;
NetworkAccessManager* network_;
QMenu* context_menu_;
QModelIndex context_item_;
QAction* add_to_playlist_;
QAction* load_to_playlist_;
IcecastBackend* backend_;
IcecastModel* model_;

View File

@ -384,6 +384,8 @@ void JamendoService::EnsureMenuCreated() {
context_menu_ = new QMenu;
add_to_playlist_ = context_menu_->addAction(IconLoader::Load("media-playback-start"),
tr("Add to playlist"), this, SLOT(AddToPlaylist()));
load_to_playlist_ = context_menu_->addAction(IconLoader::Load("media-playback-start"),
tr("Load"), this, SLOT(LoadToPlaylist()));
album_info_ = context_menu_->addAction(IconLoader::Load("view-media-lyrics"),
tr("Album info on jamendo.com..."), this, SLOT(AlbumInfo()));
download_album_ = context_menu_->addAction(IconLoader::Load("download"),
@ -410,6 +412,7 @@ void JamendoService::ShowContextMenu(RadioItem*, const QModelIndex& index,
}
add_to_playlist_->setEnabled(context_item_.isValid());
load_to_playlist_->setEnabled(context_item_.isValid());
album_info_->setEnabled(context_item_.isValid());
download_album_->setEnabled(context_item_.isValid());
context_menu_->popup(global_pos);
@ -421,6 +424,14 @@ QWidget* JamendoService::HeaderWidget() const {
}
void JamendoService::AddToPlaylist() {
AddSelectedToPlaylist(false);
}
void JamendoService::LoadToPlaylist() {
AddSelectedToPlaylist(true);
}
void JamendoService::AddSelectedToPlaylist(bool clear_first) {
SongList songs(library_model_->GetChildSongs(
library_sort_model_->mapToSource(context_item_)));
@ -430,7 +441,7 @@ void JamendoService::AddToPlaylist() {
items << PlaylistItemPtr(new JamendoPlaylistItem(song));
}
emit AddItemsToPlaylist(items);
emit AddItemsToPlaylist(items, clear_first);
}
void JamendoService::AlbumInfo() {

View File

@ -85,6 +85,8 @@ class JamendoService : public RadioService {
void EnsureMenuCreated();
void AddSelectedToPlaylist(bool clear_first);
private slots:
void DownloadDirectory();
void DownloadDirectoryProgress(qint64 received, qint64 total);
@ -93,6 +95,7 @@ class JamendoService : public RadioService {
void UpdateTotalSongCount(int count);
void AddToPlaylist();
void LoadToPlaylist();
void AlbumInfo();
void DownloadAlbum();
void Homepage();
@ -105,6 +108,7 @@ class JamendoService : public RadioService {
QModelIndex context_item_;
QAction* add_to_playlist_;
QAction* load_to_playlist_;
QAction* album_info_;
QAction* download_album_;

View File

@ -69,6 +69,8 @@ LastFMService::LastFMService(RadioModel* parent)
play_action_ = context_menu_->addAction(
IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
load_action_ = context_menu_->addAction(
IconLoader::Load("media-playback-start"), tr("Load"), this, SLOT(LoadToPlaylist()));
remove_action_ = context_menu_->addAction(
IconLoader::Load("list-remove"), tr("Remove"), this, SLOT(Remove()));
context_menu_->addSeparator();
@ -479,6 +481,7 @@ void LastFMService::ShowContextMenu(RadioItem* item, const QModelIndex&,
}
play_action_->setEnabled(item->playable);
load_action_->setEnabled(item->playable);
context_menu_->popup(global_pos);
}
@ -557,7 +560,11 @@ void LastFMService::RefreshNeighboursFinished() {
}
void LastFMService::AddToPlaylist() {
emit AddItemToPlaylist(context_item_);
emit AddItemToPlaylist(context_item_, false);
}
void LastFMService::LoadToPlaylist() {
emit AddItemToPlaylist(context_item_, true);
}
void LastFMService::AddArtistRadio() {
@ -587,7 +594,7 @@ void LastFMService::AddArtistOrTag(const QString& name,
item->playable = true;
item->lazy_loaded = true;
item->InsertNotify(list);
emit AddItemToPlaylist(item);
emit AddItemToPlaylist(item, false);
SaveList(name, list);
}

View File

@ -129,6 +129,7 @@ class LastFMService : public RadioService {
void TunerError(lastfm::ws::Error error);
void AddToPlaylist();
void LoadToPlaylist();
void AddArtistRadio();
void AddTagRadio();
void AddCustomRadio();
@ -157,6 +158,8 @@ class LastFMService : public RadioService {
void Tune(const lastfm::RadioStation& station);
void AddSelectedToPlaylist(bool clear_first);
private:
lastfm::Audioscrobbler* scrobbler_;
lastfm::Track last_track_;
@ -167,6 +170,7 @@ class LastFMService : public RadioService {
boost::scoped_ptr<QMenu> context_menu_;
QAction* play_action_;
QAction* load_action_;
QAction* remove_action_;
QAction* add_artist_action_;
QAction* add_tag_action_;

View File

@ -253,6 +253,8 @@ void MagnatuneService::EnsureMenuCreated() {
add_to_playlist_ = context_menu_->addAction(
IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
load_to_playlist_ = context_menu_->addAction(
IconLoader::Load("media-playback-start"), tr("Load"), this, SLOT(LoadToPlaylist()));
download_ = context_menu_->addAction(
IconLoader::Load("download"), tr("Download this album"), this, SLOT(Download()));
context_menu_->addSeparator();
@ -278,11 +280,20 @@ void MagnatuneService::ShowContextMenu(RadioItem*, const QModelIndex& index,
context_item_ = QModelIndex();
add_to_playlist_->setEnabled(context_item_.isValid());
load_to_playlist_->setEnabled(context_item_.isValid());
download_->setEnabled(context_item_.isValid() && membership_ == Membership_Download);
context_menu_->popup(global_pos);
}
void MagnatuneService::AddToPlaylist() {
AddSelectedToPlaylist(false);
}
void MagnatuneService::LoadToPlaylist() {
AddSelectedToPlaylist(true);
}
void MagnatuneService::AddSelectedToPlaylist(bool clear_first) {
SongList songs(library_model_->GetChildSongs(
library_sort_model_->mapToSource(context_item_)));
@ -292,7 +303,7 @@ void MagnatuneService::AddToPlaylist() {
items << shared_ptr<PlaylistItem>(new MagnatunePlaylistItem(song));
}
emit AddItemsToPlaylist(items);
emit AddItemsToPlaylist(items, clear_first);
}
void MagnatuneService::Homepage() {

View File

@ -95,12 +95,14 @@ class MagnatuneService : public RadioService {
void ReloadDatabaseFinished();
void AddToPlaylist();
void LoadToPlaylist();
void Download();
void Homepage();
void ShowConfig();
private:
void EnsureMenuCreated();
void AddSelectedToPlaylist(bool clear_first);
Song ReadTrack(QXmlStreamReader& reader);
@ -110,6 +112,7 @@ class MagnatuneService : public RadioService {
QModelIndex context_item_;
QAction* add_to_playlist_;
QAction* load_to_playlist_;
QAction* download_;
LibraryBackend* library_backend_;

View File

@ -59,8 +59,8 @@ void RadioModel::AddService(RadioService *service) {
connect(service, SIGNAL(StreamError(QString)), SIGNAL(StreamError(QString)));
connect(service, SIGNAL(StreamMetadataFound(QUrl,Song)), SIGNAL(StreamMetadataFound(QUrl,Song)));
connect(service, SIGNAL(OpenSettingsAtPage(SettingsDialog::Page)), SIGNAL(OpenSettingsAtPage(SettingsDialog::Page)));
connect(service, SIGNAL(AddItemToPlaylist(RadioItem*)), SIGNAL(AddItemToPlaylist(RadioItem*)));
connect(service, SIGNAL(AddItemsToPlaylist(PlaylistItemList)), SIGNAL(AddItemsToPlaylist(PlaylistItemList)));
connect(service, SIGNAL(AddItemToPlaylist(RadioItem*,bool)), SIGNAL(AddItemToPlaylist(RadioItem*,bool)));
connect(service, SIGNAL(AddItemsToPlaylist(PlaylistItemList,bool)), SIGNAL(AddItemsToPlaylist(PlaylistItemList,bool)));
}
RadioService* RadioModel::ServiceByName(const QString& name) {

View File

@ -80,8 +80,8 @@ class RadioModel : public SimpleTreeModel<RadioItem> {
void StreamMetadataFound(const QUrl& original_url, const Song& song);
void OpenSettingsAtPage(SettingsDialog::Page);
void AddItemToPlaylist(RadioItem* item);
void AddItemsToPlaylist(const PlaylistItemList& items);
void AddItemToPlaylist(RadioItem* item, bool clear_first);
void AddItemsToPlaylist(const PlaylistItemList& items, bool clear_first);
protected:
void LazyPopulate(RadioItem* parent);

View File

@ -69,8 +69,8 @@ class RadioService : public QObject {
void StreamMetadataFound(const QUrl& original_url, const Song& song);
void OpenSettingsAtPage(SettingsDialog::Page page);
void AddItemToPlaylist(RadioItem* item);
void AddItemsToPlaylist(const PlaylistItemList& items);
void AddItemToPlaylist(RadioItem* item, bool clear_first);
void AddItemsToPlaylist(const PlaylistItemList& items, bool clear_first);
private:
RadioModel* model_;

View File

@ -90,6 +90,7 @@ void SavedRadio::ShowContextMenu(RadioItem* item, const QModelIndex&,
if (!context_menu_) {
context_menu_ = new QMenu;
add_action_ = context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
load_action_ = context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Load"), this, SLOT(LoadToPlaylist()));
remove_action_ = context_menu_->addAction(IconLoader::Load("list-remove"), tr("Remove"), this, SLOT(Remove()));
edit_action_ = context_menu_->addAction(IconLoader::Load("edit-rename"), tr("Edit..."), this, SLOT(Edit()));
context_menu_->addSeparator();
@ -99,6 +100,7 @@ void SavedRadio::ShowContextMenu(RadioItem* item, const QModelIndex&,
context_item_ = item;
add_action_->setEnabled(item != root_);
load_action_->setEnabled(item != root_);
remove_action_->setEnabled(item != root_);
edit_action_->setEnabled(item != root_);
@ -135,7 +137,11 @@ void SavedRadio::Edit() {
}
void SavedRadio::AddToPlaylist() {
emit AddItemToPlaylist(context_item_);
emit AddItemToPlaylist(context_item_, false);
}
void SavedRadio::LoadToPlaylist() {
emit AddItemToPlaylist(context_item_, true);
}
RadioItem* SavedRadio::ItemForStream(const Stream& stream, RadioItem* parent) {

View File

@ -53,6 +53,7 @@ class SavedRadio : public RadioService {
private slots:
void AddToPlaylist();
void LoadToPlaylist();
void Remove();
void Edit();
@ -78,6 +79,7 @@ class SavedRadio : public RadioService {
RadioItem* context_item_;
QAction* add_action_;
QAction* load_action_;
QAction* remove_action_;
QAction* edit_action_;

View File

@ -73,6 +73,7 @@ void SomaFMService::ShowContextMenu(RadioItem* item, const QModelIndex&,
if (!context_menu_) {
context_menu_ = new QMenu;
context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Load"), this, SLOT(LoadToPlaylist()));
context_menu_->addSeparator();
context_menu_->addAction(IconLoader::Load("download"), tr("Open somafm.com in browser"), this, SLOT(Homepage()));
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh channels"), this, SLOT(RefreshChannels()));
@ -225,7 +226,11 @@ void SomaFMService::Homepage() {
}
void SomaFMService::AddToPlaylist() {
emit AddItemToPlaylist(context_item_);
emit AddItemToPlaylist(context_item_, false);
}
void SomaFMService::LoadToPlaylist() {
emit AddItemToPlaylist(context_item_, true);
}
PlaylistItem::Options SomaFMService::playlistitem_options() const {

View File

@ -56,6 +56,7 @@ class SomaFMService : public RadioService {
void LoadPlaylistFinished();
void AddToPlaylist();
void LoadToPlaylist();
void Homepage();
private:

View File

@ -47,7 +47,7 @@ public slots:
signals:
void ShowSettingsDialog();
void AddPlaylistItems(const PlaylistItemList& items);
void AddPlaylistItems(const PlaylistItemList& items, bool clear_first = false);
protected:
void showEvent(QShowEvent* e);

View File

@ -449,8 +449,8 @@ MainWindow::MainWindow(Engine::Type engine, QWidget *parent)
connect(radio_model_, SIGNAL(AsyncLoadFinished(PlaylistItem::SpecialLoadResult)), player_, SLOT(HandleSpecialLoad(PlaylistItem::SpecialLoadResult)));
connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), playlists_, SLOT(SetActiveStreamMetadata(QUrl,Song)));
connect(radio_model_, SIGNAL(OpenSettingsAtPage(SettingsDialog::Page)), SLOT(OpenSettingsDialogAtPage(SettingsDialog::Page)));
connect(radio_model_, SIGNAL(AddItemToPlaylist(RadioItem*)), SLOT(InsertRadioItem(RadioItem*)));
connect(radio_model_, SIGNAL(AddItemsToPlaylist(PlaylistItemList)), SLOT(InsertRadioItems(PlaylistItemList)));
connect(radio_model_, SIGNAL(AddItemToPlaylist(RadioItem*,bool)), SLOT(InsertRadioItem(RadioItem*,bool)));
connect(radio_model_, SIGNAL(AddItemsToPlaylist(PlaylistItemList,bool)), SLOT(InsertRadioItems(PlaylistItemList,bool)));
connect(radio_model_->GetLastFMService(), SIGNAL(ScrobblingEnabledChanged(bool)), SLOT(ScrobblingEnabledChanged(bool)));
connect(radio_model_->GetLastFMService(), SIGNAL(ButtonVisibilityChanged(bool)), SLOT(LastFMButtonVisibilityChanged(bool)));
connect(radio_view_->tree(), SIGNAL(doubleClicked(QModelIndex)), SLOT(RadioDoubleClick(QModelIndex)));
@ -1006,7 +1006,10 @@ void MainWindow::RadioDoubleClick(const QModelIndex& index) {
}
}
void MainWindow::InsertRadioItem(RadioItem* item) {
void MainWindow::InsertRadioItem(RadioItem* item, bool clear_first) {
if (clear_first)
playlists_->ClearCurrent();
QModelIndex first_song = playlists_->current()->InsertRadioStations(
QList<RadioItem*>() << item);
@ -1021,7 +1024,10 @@ void MainWindow::InsertRadioItem(RadioItem* item) {
}
}
void MainWindow::InsertRadioItems(const PlaylistItemList& items) {
void MainWindow::InsertRadioItems(const PlaylistItemList& items, bool clear_first) {
if (clear_first)
playlists_->ClearCurrent();
QModelIndex first_song = playlists_->current()->InsertItems(items);
if (!playlists_->current()->proxy()->mapFromSource(first_song).isValid()) {
@ -1666,7 +1672,8 @@ void MainWindow::ConnectInfoView(SongInfoBase* view) {
connect(player_, SIGNAL(Stopped()), view, SLOT(SongFinished()));
connect(view, SIGNAL(ShowSettingsDialog()), SLOT(ShowSongInfoConfig()));
connect(view, SIGNAL(AddPlaylistItems(PlaylistItemList)), SLOT(InsertRadioItems(PlaylistItemList)));
connect(view, SIGNAL(AddPlaylistItems(PlaylistItemList,bool)),
SLOT(InsertRadioItems(PlaylistItemList,bool)));
}
void MainWindow::ShowSongInfoConfig() {

View File

@ -162,8 +162,8 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void UpdateTrackPosition();
void RadioDoubleClick(const QModelIndex& index);
void InsertRadioItem(RadioItem*);
void InsertRadioItems(const PlaylistItemList& items);
void InsertRadioItem(RadioItem*, bool clear_first);
void InsertRadioItems(const PlaylistItemList& items, bool clear_first);
void ScrobblingEnabledChanged(bool value);
void LastFMButtonVisibilityChanged(bool value);
void Love();