further refactoring of duplicated playlist-insertion related code in RadioServices
This commit is contained in:
parent
79159700fc
commit
c8aed5fd30
@ -64,15 +64,9 @@ class DigitallyImportedServiceBase(clementine.RadioService):
|
|||||||
def ShowContextMenu(self, index, global_pos):
|
def ShowContextMenu(self, index, global_pos):
|
||||||
if not self.menu:
|
if not self.menu:
|
||||||
self.menu = QMenu()
|
self.menu = QMenu()
|
||||||
self.menu.addAction(clementine.IconLoader.Load("media-playback-start"),
|
|
||||||
self.tr("Append to current playlist"), self.AddToPlaylist)
|
|
||||||
self.menu.addAction(clementine.IconLoader.Load("media-playback-start"),
|
|
||||||
self.tr("Replace current playlist"), self.LoadToPlaylist)
|
|
||||||
self.menu.addAction(clementine.IconLoader.Load("document-new"),
|
|
||||||
self.tr("Open in new playlist"), self.OpenInNewPlaylist)
|
|
||||||
|
|
||||||
self.menu.addSeparator()
|
|
||||||
|
|
||||||
|
for action in self.GetPlaylistActions():
|
||||||
|
self.menu.addAction(action)
|
||||||
self.menu.addAction(clementine.IconLoader.Load("download"),
|
self.menu.addAction(clementine.IconLoader.Load("download"),
|
||||||
self.tr("Open " + self.HOMEPAGE_NAME + " in browser"), self.Homepage)
|
self.tr("Open " + self.HOMEPAGE_NAME + " in browser"), self.Homepage)
|
||||||
self.menu.addAction(clementine.IconLoader.Load("view-refresh"),
|
self.menu.addAction(clementine.IconLoader.Load("view-refresh"),
|
||||||
@ -86,14 +80,8 @@ class DigitallyImportedServiceBase(clementine.RadioService):
|
|||||||
self.context_index = index
|
self.context_index = index
|
||||||
self.menu.popup(global_pos)
|
self.menu.popup(global_pos)
|
||||||
|
|
||||||
def AddToPlaylist(self):
|
def GetCurrentIndex(self):
|
||||||
self.AddItemToPlaylist(self.context_index, self.AddMode_Append)
|
return self.context_index
|
||||||
|
|
||||||
def LoadToPlaylist(self):
|
|
||||||
self.AddItemToPlaylist(self.context_index, self.AddMode_Replace)
|
|
||||||
|
|
||||||
def OpenInNewPlaylist(self):
|
|
||||||
self.AddItemToPlaylist(self.context_index, self.AddMode_OpenInNew)
|
|
||||||
|
|
||||||
def Homepage(self):
|
def Homepage(self):
|
||||||
QDesktopServices.openUrl(self.HOMEPAGE_URL)
|
QDesktopServices.openUrl(self.HOMEPAGE_URL)
|
||||||
|
@ -271,9 +271,9 @@ void IcecastService::ShowContextMenu(const QModelIndex& index,
|
|||||||
const bool can_play = context_item_.isValid() &&
|
const bool can_play = context_item_.isValid() &&
|
||||||
model_->GetSong(context_item_).is_valid();
|
model_->GetSong(context_item_).is_valid();
|
||||||
|
|
||||||
add_to_playlist_->setEnabled(can_play);
|
GetAppendToPlaylistAction()->setEnabled(can_play);
|
||||||
load_to_playlist_->setEnabled(can_play);
|
GetReplacePlaylistAction()->setEnabled(can_play);
|
||||||
open_in_new_playlist_->setEnabled(can_play);
|
GetOpenInNewPlaylistAction()->setEnabled(can_play);
|
||||||
context_menu_->popup(global_pos);
|
context_menu_->popup(global_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,13 +283,7 @@ void IcecastService::EnsureMenuCreated() {
|
|||||||
|
|
||||||
context_menu_ = new QMenu;
|
context_menu_ = new QMenu;
|
||||||
|
|
||||||
add_to_playlist_ = context_menu_->addAction(
|
context_menu_->addActions(GetPlaylistActions());
|
||||||
IconLoader::Load("media-playback-start"), tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
|
||||||
load_to_playlist_ = context_menu_->addAction(
|
|
||||||
IconLoader::Load("media-playback-start"), tr("Replace current playlist"), this, SLOT(LoadToPlaylist()));
|
|
||||||
open_in_new_playlist_ = context_menu_->addAction(
|
|
||||||
IconLoader::Load("document-new"), tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
|
|
||||||
context_menu_->addSeparator();
|
|
||||||
context_menu_->addAction(IconLoader::Load("download"), tr("Open dir.xiph.org in browser"), this, SLOT(Homepage()));
|
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()));
|
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh station list"), this, SLOT(LoadDirectory()));
|
||||||
}
|
}
|
||||||
@ -298,14 +292,6 @@ void IcecastService::Homepage() {
|
|||||||
QDesktopServices::openUrl(QUrl(kHomepage));
|
QDesktopServices::openUrl(QUrl(kHomepage));
|
||||||
}
|
}
|
||||||
|
|
||||||
void IcecastService::AddToPlaylist() {
|
QModelIndex IcecastService::GetCurrentIndex() {
|
||||||
AddItemToPlaylist(context_item_, AddMode_Append);
|
return context_item_;
|
||||||
}
|
|
||||||
|
|
||||||
void IcecastService::LoadToPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_, AddMode_Replace);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IcecastService::OpenInNewPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_, AddMode_OpenInNew);
|
|
||||||
}
|
}
|
||||||
|
@ -52,12 +52,12 @@ class IcecastService : public RadioService {
|
|||||||
|
|
||||||
QWidget* HeaderWidget() const;
|
QWidget* HeaderWidget() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QModelIndex GetCurrentIndex();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void LoadDirectory();
|
void LoadDirectory();
|
||||||
void Homepage();
|
void Homepage();
|
||||||
void AddToPlaylist();
|
|
||||||
void LoadToPlaylist();
|
|
||||||
void OpenInNewPlaylist();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void EnsureMenuCreated();
|
void EnsureMenuCreated();
|
||||||
@ -68,9 +68,6 @@ class IcecastService : public RadioService {
|
|||||||
NetworkAccessManager* network_;
|
NetworkAccessManager* network_;
|
||||||
QMenu* context_menu_;
|
QMenu* context_menu_;
|
||||||
QModelIndex context_item_;
|
QModelIndex context_item_;
|
||||||
QAction* add_to_playlist_;
|
|
||||||
QAction* load_to_playlist_;
|
|
||||||
QAction* open_in_new_playlist_;
|
|
||||||
|
|
||||||
IcecastBackend* backend_;
|
IcecastBackend* backend_;
|
||||||
IcecastModel* model_;
|
IcecastModel* model_;
|
||||||
|
@ -378,13 +378,7 @@ void JamendoService::EnsureMenuCreated() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
context_menu_ = new QMenu;
|
context_menu_ = new QMenu;
|
||||||
add_to_playlist_ = context_menu_->addAction(IconLoader::Load("media-playback-start"),
|
context_menu_->addActions(GetPlaylistActions());
|
||||||
tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
|
||||||
load_to_playlist_ = context_menu_->addAction(IconLoader::Load("media-playback-start"),
|
|
||||||
tr("Replace current playlist"), this, SLOT(LoadToPlaylist()));
|
|
||||||
open_in_new_playlist_ = context_menu_->addAction(IconLoader::Load("document-new"),
|
|
||||||
tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
|
|
||||||
context_menu_->addSeparator();
|
|
||||||
album_info_ = context_menu_->addAction(IconLoader::Load("view-media-lyrics"),
|
album_info_ = context_menu_->addAction(IconLoader::Load("view-media-lyrics"),
|
||||||
tr("Album info on jamendo.com..."), this, SLOT(AlbumInfo()));
|
tr("Album info on jamendo.com..."), this, SLOT(AlbumInfo()));
|
||||||
download_album_ = context_menu_->addAction(IconLoader::Load("download"),
|
download_album_ = context_menu_->addAction(IconLoader::Load("download"),
|
||||||
@ -409,9 +403,9 @@ void JamendoService::ShowContextMenu(const QModelIndex& index, const QPoint& glo
|
|||||||
context_item_ = QModelIndex();
|
context_item_ = QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
add_to_playlist_->setEnabled(context_item_.isValid());
|
GetAppendToPlaylistAction()->setEnabled(context_item_.isValid());
|
||||||
load_to_playlist_->setEnabled(context_item_.isValid());
|
GetReplacePlaylistAction()->setEnabled(context_item_.isValid());
|
||||||
open_in_new_playlist_->setEnabled(context_item_.isValid());
|
GetOpenInNewPlaylistAction()->setEnabled(context_item_.isValid());
|
||||||
album_info_->setEnabled(context_item_.isValid());
|
album_info_->setEnabled(context_item_.isValid());
|
||||||
download_album_->setEnabled(context_item_.isValid());
|
download_album_->setEnabled(context_item_.isValid());
|
||||||
context_menu_->popup(global_pos);
|
context_menu_->popup(global_pos);
|
||||||
@ -422,16 +416,8 @@ QWidget* JamendoService::HeaderWidget() const {
|
|||||||
return library_filter_;
|
return library_filter_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JamendoService::AddToPlaylist() {
|
QModelIndex JamendoService::GetCurrentIndex() {
|
||||||
AddItemToPlaylist(context_item_, AddMode_Append);
|
return context_item_;
|
||||||
}
|
|
||||||
|
|
||||||
void JamendoService::LoadToPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_, AddMode_Replace);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JamendoService::OpenInNewPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_, AddMode_OpenInNew);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JamendoService::AlbumInfo() {
|
void JamendoService::AlbumInfo() {
|
||||||
|
@ -66,6 +66,9 @@ class JamendoService : public RadioService {
|
|||||||
static const int kBatchSize;
|
static const int kBatchSize;
|
||||||
static const int kApproxDatabaseSize;
|
static const int kApproxDatabaseSize;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QModelIndex GetCurrentIndex();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ParseDirectory(QIODevice* device) const;
|
void ParseDirectory(QIODevice* device) const;
|
||||||
|
|
||||||
@ -91,9 +94,6 @@ class JamendoService : public RadioService {
|
|||||||
void ParseDirectoryFinished();
|
void ParseDirectoryFinished();
|
||||||
void UpdateTotalSongCount(int count);
|
void UpdateTotalSongCount(int count);
|
||||||
|
|
||||||
void AddToPlaylist();
|
|
||||||
void LoadToPlaylist();
|
|
||||||
void OpenInNewPlaylist();
|
|
||||||
void AlbumInfo();
|
void AlbumInfo();
|
||||||
void DownloadAlbum();
|
void DownloadAlbum();
|
||||||
void Homepage();
|
void Homepage();
|
||||||
@ -104,9 +104,6 @@ class JamendoService : public RadioService {
|
|||||||
QMenu* context_menu_;
|
QMenu* context_menu_;
|
||||||
QModelIndex context_item_;
|
QModelIndex context_item_;
|
||||||
|
|
||||||
QAction* add_to_playlist_;
|
|
||||||
QAction* load_to_playlist_;
|
|
||||||
QAction* open_in_new_playlist_;
|
|
||||||
QAction* album_info_;
|
QAction* album_info_;
|
||||||
QAction* download_album_;
|
QAction* download_album_;
|
||||||
|
|
||||||
|
@ -74,13 +74,7 @@ LastFMService::LastFMService(RadioModel* parent)
|
|||||||
{
|
{
|
||||||
ReloadSettings();
|
ReloadSettings();
|
||||||
|
|
||||||
play_action_ = context_menu_->addAction(
|
context_menu_->addActions(GetPlaylistActions());
|
||||||
IconLoader::Load("media-playback-start"), tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
|
||||||
load_action_ = context_menu_->addAction(
|
|
||||||
IconLoader::Load("media-playback-start"), tr("Replace current playlist"), this, SLOT(LoadToPlaylist()));
|
|
||||||
open_in_new_playlist_ = context_menu_->addAction(IconLoader::Load("document-new"),
|
|
||||||
tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
|
|
||||||
context_menu_->addSeparator();
|
|
||||||
remove_action_ = context_menu_->addAction(
|
remove_action_ = context_menu_->addAction(
|
||||||
IconLoader::Load("list-remove"), tr("Remove"), this, SLOT(Remove()));
|
IconLoader::Load("list-remove"), tr("Remove"), this, SLOT(Remove()));
|
||||||
context_menu_->addSeparator();
|
context_menu_->addSeparator();
|
||||||
@ -470,9 +464,9 @@ void LastFMService::ShowContextMenu(const QModelIndex& index, const QPoint &glob
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool playable = model()->IsPlayable(index);
|
const bool playable = model()->IsPlayable(index);
|
||||||
play_action_->setEnabled(playable);
|
GetAppendToPlaylistAction()->setEnabled(playable);
|
||||||
load_action_->setEnabled(playable);
|
GetReplacePlaylistAction()->setEnabled(playable);
|
||||||
open_in_new_playlist_->setEnabled(playable);
|
GetOpenInNewPlaylistAction()->setEnabled(playable);
|
||||||
context_menu_->popup(global_pos);
|
context_menu_->popup(global_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,16 +552,8 @@ void LastFMService::RefreshNeighboursFinished() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LastFMService::AddToPlaylist() {
|
QModelIndex LastFMService::GetCurrentIndex() {
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_Append);
|
return context_item_->index();
|
||||||
}
|
|
||||||
|
|
||||||
void LastFMService::LoadToPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_Replace);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LastFMService::OpenInNewPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LastFMService::AddArtistRadio() {
|
void LastFMService::AddArtistRadio() {
|
||||||
|
@ -116,6 +116,9 @@ class LastFMService : public RadioService {
|
|||||||
void ScrobblingEnabledChanged(bool value);
|
void ScrobblingEnabledChanged(bool value);
|
||||||
void ButtonVisibilityChanged(bool value);
|
void ButtonVisibilityChanged(bool value);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QModelIndex GetCurrentIndex();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void AuthenticateReplyFinished();
|
void AuthenticateReplyFinished();
|
||||||
void RefreshFriendsFinished();
|
void RefreshFriendsFinished();
|
||||||
@ -124,9 +127,6 @@ class LastFMService : public RadioService {
|
|||||||
void TunerTrackAvailable();
|
void TunerTrackAvailable();
|
||||||
void TunerError(lastfm::ws::Error error);
|
void TunerError(lastfm::ws::Error error);
|
||||||
|
|
||||||
void AddToPlaylist();
|
|
||||||
void LoadToPlaylist();
|
|
||||||
void OpenInNewPlaylist();
|
|
||||||
void AddArtistRadio();
|
void AddArtistRadio();
|
||||||
void AddTagRadio();
|
void AddTagRadio();
|
||||||
void AddCustomRadio();
|
void AddCustomRadio();
|
||||||
@ -172,9 +172,6 @@ class LastFMService : public RadioService {
|
|||||||
boost::scoped_ptr<LastFMStationDialog> station_dialog_;
|
boost::scoped_ptr<LastFMStationDialog> station_dialog_;
|
||||||
|
|
||||||
boost::scoped_ptr<QMenu> context_menu_;
|
boost::scoped_ptr<QMenu> context_menu_;
|
||||||
QAction* play_action_;
|
|
||||||
QAction* load_action_;
|
|
||||||
QAction* open_in_new_playlist_;
|
|
||||||
QAction* remove_action_;
|
QAction* remove_action_;
|
||||||
QAction* add_artist_action_;
|
QAction* add_artist_action_;
|
||||||
QAction* add_tag_action_;
|
QAction* add_tag_action_;
|
||||||
|
@ -248,13 +248,7 @@ void MagnatuneService::EnsureMenuCreated() {
|
|||||||
|
|
||||||
context_menu_ = new QMenu;
|
context_menu_ = new QMenu;
|
||||||
|
|
||||||
add_to_playlist_ = context_menu_->addAction(
|
context_menu_->addActions(GetPlaylistActions());
|
||||||
IconLoader::Load("media-playback-start"), tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
|
||||||
load_to_playlist_ = context_menu_->addAction(
|
|
||||||
IconLoader::Load("media-playback-start"), tr("Replace current playlist"), this, SLOT(LoadToPlaylist()));
|
|
||||||
open_in_new_playlist_ = context_menu_->addAction(IconLoader::Load("document-new"),
|
|
||||||
tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
|
|
||||||
context_menu_->addSeparator();
|
|
||||||
download_ = context_menu_->addAction(
|
download_ = context_menu_->addAction(
|
||||||
IconLoader::Load("download"), tr("Download this album"), this, SLOT(Download()));
|
IconLoader::Load("download"), tr("Download this album"), this, SLOT(Download()));
|
||||||
context_menu_->addSeparator();
|
context_menu_->addSeparator();
|
||||||
@ -278,23 +272,15 @@ void MagnatuneService::ShowContextMenu(const QModelIndex& index, const QPoint& g
|
|||||||
else
|
else
|
||||||
context_item_ = QModelIndex();
|
context_item_ = QModelIndex();
|
||||||
|
|
||||||
add_to_playlist_->setEnabled(context_item_.isValid());
|
GetAppendToPlaylistAction()->setEnabled(context_item_.isValid());
|
||||||
load_to_playlist_->setEnabled(context_item_.isValid());
|
GetReplacePlaylistAction()->setEnabled(context_item_.isValid());
|
||||||
open_in_new_playlist_->setEnabled(context_item_.isValid());
|
GetOpenInNewPlaylistAction()->setEnabled(context_item_.isValid());
|
||||||
download_->setEnabled(context_item_.isValid() && membership_ == Membership_Download);
|
download_->setEnabled(context_item_.isValid() && membership_ == Membership_Download);
|
||||||
context_menu_->popup(global_pos);
|
context_menu_->popup(global_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MagnatuneService::AddToPlaylist() {
|
QModelIndex MagnatuneService::GetCurrentIndex() {
|
||||||
AddItemToPlaylist(context_item_, AddMode_Append);
|
return context_item_;
|
||||||
}
|
|
||||||
|
|
||||||
void MagnatuneService::LoadToPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_, AddMode_Replace);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MagnatuneService::OpenInNewPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_, AddMode_OpenInNew);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MagnatuneService::Homepage() {
|
void MagnatuneService::Homepage() {
|
||||||
|
@ -88,14 +88,14 @@ class MagnatuneService : public RadioService {
|
|||||||
signals:
|
signals:
|
||||||
void DownloadFinished(const QStringList& albums);
|
void DownloadFinished(const QStringList& albums);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QModelIndex GetCurrentIndex();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void UpdateTotalSongCount(int count);
|
void UpdateTotalSongCount(int count);
|
||||||
void ReloadDatabase();
|
void ReloadDatabase();
|
||||||
void ReloadDatabaseFinished();
|
void ReloadDatabaseFinished();
|
||||||
|
|
||||||
void AddToPlaylist();
|
|
||||||
void LoadToPlaylist();
|
|
||||||
void OpenInNewPlaylist();
|
|
||||||
void Download();
|
void Download();
|
||||||
void Homepage();
|
void Homepage();
|
||||||
void ShowConfig();
|
void ShowConfig();
|
||||||
@ -110,9 +110,6 @@ class MagnatuneService : public RadioService {
|
|||||||
QModelIndex context_item_;
|
QModelIndex context_item_;
|
||||||
QStandardItem* root_;
|
QStandardItem* root_;
|
||||||
|
|
||||||
QAction* add_to_playlist_;
|
|
||||||
QAction* load_to_playlist_;
|
|
||||||
QAction* open_in_new_playlist_;
|
|
||||||
QAction* download_;
|
QAction* download_;
|
||||||
|
|
||||||
LibraryBackend* library_backend_;
|
LibraryBackend* library_backend_;
|
||||||
|
@ -19,14 +19,63 @@
|
|||||||
#include "radiomodel.h"
|
#include "radiomodel.h"
|
||||||
#include "core/mergedproxymodel.h"
|
#include "core/mergedproxymodel.h"
|
||||||
#include "core/mimedata.h"
|
#include "core/mimedata.h"
|
||||||
|
#include "ui/iconloader.h"
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
RadioService::RadioService(const QString& name, RadioModel* model)
|
RadioService::RadioService(const QString& name, RadioModel* model)
|
||||||
: QObject(model),
|
: QObject(model),
|
||||||
model_(model),
|
model_(model),
|
||||||
name_(name)
|
name_(name),
|
||||||
|
append_to_playlist_(NULL),
|
||||||
|
replace_playlist_(NULL),
|
||||||
|
open_in_new_playlist_(NULL),
|
||||||
|
separator_(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QAction*> RadioService::GetPlaylistActions() {
|
||||||
|
if(!separator_) {
|
||||||
|
separator_ = new QAction(this);
|
||||||
|
separator_->setSeparator(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QList<QAction*>() << GetAppendToPlaylistAction()
|
||||||
|
<< GetReplacePlaylistAction()
|
||||||
|
<< GetOpenInNewPlaylistAction()
|
||||||
|
<< separator_;
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction* RadioService::GetAppendToPlaylistAction() {
|
||||||
|
if(!append_to_playlist_) {
|
||||||
|
append_to_playlist_ = new QAction(IconLoader::Load("media-playback-start"),
|
||||||
|
tr("Append to current playlist"), this);
|
||||||
|
connect(append_to_playlist_, SIGNAL(triggered()), this, SLOT(AppendToPlaylist()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return append_to_playlist_;
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction* RadioService::GetReplacePlaylistAction() {
|
||||||
|
if(!replace_playlist_) {
|
||||||
|
replace_playlist_ = new QAction(IconLoader::Load("media-playback-start"),
|
||||||
|
tr("Replace current playlist"), this);
|
||||||
|
connect(replace_playlist_, SIGNAL(triggered()), this, SLOT(ReplacePlaylist()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return replace_playlist_;
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction* RadioService::GetOpenInNewPlaylistAction() {
|
||||||
|
if(!open_in_new_playlist_) {
|
||||||
|
open_in_new_playlist_ = new QAction(IconLoader::Load("document-new"),
|
||||||
|
tr("Open in new playlist"), this);
|
||||||
|
connect(open_in_new_playlist_, SIGNAL(triggered()), this, SLOT(OpenInNewPlaylist()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return open_in_new_playlist_;
|
||||||
|
}
|
||||||
|
|
||||||
PlaylistItem::SpecialLoadResult RadioService::StartLoading(const QUrl &url) {
|
PlaylistItem::SpecialLoadResult RadioService::StartLoading(const QUrl &url) {
|
||||||
return PlaylistItem::SpecialLoadResult(
|
return PlaylistItem::SpecialLoadResult(
|
||||||
PlaylistItem::SpecialLoadResult::TrackAvailable, url, url);
|
PlaylistItem::SpecialLoadResult::TrackAvailable, url, url);
|
||||||
@ -49,3 +98,15 @@ void RadioService::AddItemsToPlaylist(const QModelIndexList& indexes, AddMode ad
|
|||||||
}
|
}
|
||||||
emit AddToPlaylistSignal(data);
|
emit AddToPlaylistSignal(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RadioService::AppendToPlaylist() {
|
||||||
|
AddItemToPlaylist(GetCurrentIndex(), AddMode_Append);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RadioService::ReplacePlaylist() {
|
||||||
|
AddItemToPlaylist(GetCurrentIndex(), AddMode_Replace);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RadioService::OpenInNewPlaylist() {
|
||||||
|
AddItemToPlaylist(GetCurrentIndex(), AddMode_OpenInNew);
|
||||||
|
}
|
||||||
|
@ -65,7 +65,26 @@ signals:
|
|||||||
|
|
||||||
void AddToPlaylistSignal(QMimeData* data);
|
void AddToPlaylistSignal(QMimeData* data);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void AppendToPlaylist();
|
||||||
|
void ReplacePlaylist();
|
||||||
|
void OpenInNewPlaylist();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// Subclass provides the currently selected QModelIndex on RadioService's
|
||||||
|
// request.
|
||||||
|
virtual QModelIndex GetCurrentIndex() = 0;
|
||||||
|
|
||||||
|
// Returns all the playlist insertion related QActions (see below).
|
||||||
|
QList<QAction*> GetPlaylistActions();
|
||||||
|
|
||||||
|
// Returns the 'append to playlist' QAction.
|
||||||
|
QAction* GetAppendToPlaylistAction();
|
||||||
|
// Returns the 'replace playlist' QAction.
|
||||||
|
QAction* GetReplacePlaylistAction();
|
||||||
|
// Returns the 'open in new playlist' QAction.
|
||||||
|
QAction* GetOpenInNewPlaylistAction();
|
||||||
|
|
||||||
// Describes how songs should be added to playlist.
|
// Describes how songs should be added to playlist.
|
||||||
enum AddMode {
|
enum AddMode {
|
||||||
// appends songs to the current playlist
|
// appends songs to the current playlist
|
||||||
@ -84,6 +103,11 @@ protected:
|
|||||||
private:
|
private:
|
||||||
RadioModel* model_;
|
RadioModel* model_;
|
||||||
QString name_;
|
QString name_;
|
||||||
|
|
||||||
|
QAction* append_to_playlist_;
|
||||||
|
QAction* replace_playlist_;
|
||||||
|
QAction* open_in_new_playlist_;
|
||||||
|
QAction* separator_;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(RadioService*);
|
Q_DECLARE_METATYPE(RadioService*);
|
||||||
|
@ -90,10 +90,7 @@ void SavedRadio::ShowContextMenu(const QModelIndex& index,
|
|||||||
const QPoint& global_pos) {
|
const QPoint& global_pos) {
|
||||||
if (!context_menu_) {
|
if (!context_menu_) {
|
||||||
context_menu_ = new QMenu;
|
context_menu_ = new QMenu;
|
||||||
add_action_ = context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
context_menu_->addActions(GetPlaylistActions());
|
||||||
load_action_ = context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Replace current playlist"), this, SLOT(LoadToPlaylist()));
|
|
||||||
open_in_new_playlist_ = context_menu_->addAction(IconLoader::Load("document-new"), tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
|
|
||||||
context_menu_->addSeparator();
|
|
||||||
remove_action_ = context_menu_->addAction(IconLoader::Load("list-remove"), tr("Remove"), this, SLOT(Remove()));
|
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()));
|
edit_action_ = context_menu_->addAction(IconLoader::Load("edit-rename"), tr("Edit..."), this, SLOT(Edit()));
|
||||||
context_menu_->addSeparator();
|
context_menu_->addSeparator();
|
||||||
@ -103,9 +100,9 @@ void SavedRadio::ShowContextMenu(const QModelIndex& index,
|
|||||||
context_item_ = model()->itemFromIndex(index);
|
context_item_ = model()->itemFromIndex(index);
|
||||||
const bool is_root = index.data(RadioModel::Role_Type).toInt() == RadioModel::Type_Service;
|
const bool is_root = index.data(RadioModel::Role_Type).toInt() == RadioModel::Type_Service;
|
||||||
|
|
||||||
add_action_->setEnabled(!is_root);
|
GetAppendToPlaylistAction()->setEnabled(!is_root);
|
||||||
load_action_->setEnabled(!is_root);
|
GetReplacePlaylistAction()->setEnabled(!is_root);
|
||||||
open_in_new_playlist_->setEnabled(!is_root);
|
GetOpenInNewPlaylistAction()->setEnabled(!is_root);
|
||||||
remove_action_->setEnabled(!is_root);
|
remove_action_->setEnabled(!is_root);
|
||||||
edit_action_->setEnabled(!is_root);
|
edit_action_->setEnabled(!is_root);
|
||||||
|
|
||||||
@ -140,16 +137,8 @@ void SavedRadio::Edit() {
|
|||||||
SaveStreams();
|
SaveStreams();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SavedRadio::AddToPlaylist() {
|
QModelIndex SavedRadio::GetCurrentIndex() {
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_Append);
|
return context_item_->index();
|
||||||
}
|
|
||||||
|
|
||||||
void SavedRadio::LoadToPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_Replace);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SavedRadio::OpenInNewPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SavedRadio::AddStreamToList(const Stream& stream, QStandardItem* parent) {
|
void SavedRadio::AddStreamToList(const Stream& stream, QStandardItem* parent) {
|
||||||
|
@ -50,10 +50,10 @@ class SavedRadio : public RadioService {
|
|||||||
signals:
|
signals:
|
||||||
void ShowAddStreamDialog();
|
void ShowAddStreamDialog();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QModelIndex GetCurrentIndex();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void AddToPlaylist();
|
|
||||||
void LoadToPlaylist();
|
|
||||||
void OpenInNewPlaylist();
|
|
||||||
void Remove();
|
void Remove();
|
||||||
void Edit();
|
void Edit();
|
||||||
|
|
||||||
@ -78,9 +78,6 @@ class SavedRadio : public RadioService {
|
|||||||
QStandardItem* context_item_;
|
QStandardItem* context_item_;
|
||||||
QStandardItem* root_;
|
QStandardItem* root_;
|
||||||
|
|
||||||
QAction* add_action_;
|
|
||||||
QAction* load_action_;
|
|
||||||
QAction* open_in_new_playlist_;
|
|
||||||
QAction* remove_action_;
|
QAction* remove_action_;
|
||||||
QAction* edit_action_;
|
QAction* edit_action_;
|
||||||
|
|
||||||
|
@ -69,10 +69,7 @@ void SomaFMService::LazyPopulate(QStandardItem* item) {
|
|||||||
void SomaFMService::ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {
|
void SomaFMService::ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {
|
||||||
if (!context_menu_) {
|
if (!context_menu_) {
|
||||||
context_menu_ = new QMenu;
|
context_menu_ = new QMenu;
|
||||||
context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
|
context_menu_->addActions(GetPlaylistActions());
|
||||||
context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Replace current playlist"), this, SLOT(LoadToPlaylist()));
|
|
||||||
context_menu_->addAction(IconLoader::Load("document-new"), tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
|
|
||||||
context_menu_->addSeparator();
|
|
||||||
context_menu_->addAction(IconLoader::Load("download"), tr("Open somafm.com in browser"), this, SLOT(Homepage()));
|
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()));
|
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh channels"), this, SLOT(RefreshChannels()));
|
||||||
}
|
}
|
||||||
@ -213,16 +210,8 @@ void SomaFMService::Homepage() {
|
|||||||
QDesktopServices::openUrl(QUrl(kHomepage));
|
QDesktopServices::openUrl(QUrl(kHomepage));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SomaFMService::AddToPlaylist() {
|
QModelIndex SomaFMService::GetCurrentIndex() {
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_Append);
|
return context_item_->index();
|
||||||
}
|
|
||||||
|
|
||||||
void SomaFMService::LoadToPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_Replace);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SomaFMService::OpenInNewPlaylist() {
|
|
||||||
AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaylistItem::Options SomaFMService::playlistitem_options() const {
|
PlaylistItem::Options SomaFMService::playlistitem_options() const {
|
||||||
|
@ -48,14 +48,14 @@ class SomaFMService : public RadioService {
|
|||||||
PlaylistItem::Options playlistitem_options() const;
|
PlaylistItem::Options playlistitem_options() const;
|
||||||
PlaylistItem::SpecialLoadResult StartLoading(const QUrl& url);
|
PlaylistItem::SpecialLoadResult StartLoading(const QUrl& url);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QModelIndex GetCurrentIndex();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void RefreshChannels();
|
void RefreshChannels();
|
||||||
void RefreshChannelsFinished();
|
void RefreshChannelsFinished();
|
||||||
void LoadPlaylistFinished();
|
void LoadPlaylistFinished();
|
||||||
|
|
||||||
void AddToPlaylist();
|
|
||||||
void LoadToPlaylist();
|
|
||||||
void OpenInNewPlaylist();
|
|
||||||
void Homepage();
|
void Homepage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -35,6 +35,14 @@ signals:
|
|||||||
void AddToPlaylistSignal(QMimeData* data);
|
void AddToPlaylistSignal(QMimeData* data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual QModelIndex GetCurrentIndex() = 0;
|
||||||
|
|
||||||
|
QList<QAction*> GetPlaylistActions();
|
||||||
|
|
||||||
|
QAction* GetAppendToPlaylistAction();
|
||||||
|
QAction* GetReplacePlaylistAction();
|
||||||
|
QAction* GetOpenInNewPlaylistAction();
|
||||||
|
|
||||||
enum AddMode {
|
enum AddMode {
|
||||||
AddMode_Append,
|
AddMode_Append,
|
||||||
AddMode_Replace,
|
AddMode_Replace,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user