simplifying AddItems API of RadioService
This commit is contained in:
parent
60ac6768b8
commit
38172c39b4
@ -87,13 +87,13 @@ class DigitallyImportedServiceBase(clementine.RadioService):
|
||||
self.menu.popup(global_pos)
|
||||
|
||||
def AddToPlaylist(self):
|
||||
self.AddItemToPlaylist(self.context_index, False)
|
||||
self.AddItemToPlaylist(self.context_index, self.AddMode_Append)
|
||||
|
||||
def LoadToPlaylist(self):
|
||||
self.AddItemToPlaylist(self.context_index, True)
|
||||
self.AddItemToPlaylist(self.context_index, self.AddMode_Replace)
|
||||
|
||||
def OpenInNewPlaylist(self):
|
||||
self.AddItemToPlaylist(self.context_index, False, False, True)
|
||||
self.AddItemToPlaylist(self.context_index, self.AddMode_OpenInNew)
|
||||
|
||||
def Homepage(self):
|
||||
QDesktopServices.openUrl(self.HOMEPAGE_URL)
|
||||
|
@ -299,13 +299,13 @@ void IcecastService::Homepage() {
|
||||
}
|
||||
|
||||
void IcecastService::AddToPlaylist() {
|
||||
AddItemToPlaylist(context_item_, false);
|
||||
AddItemToPlaylist(context_item_, AddMode_Append);
|
||||
}
|
||||
|
||||
void IcecastService::LoadToPlaylist() {
|
||||
AddItemToPlaylist(context_item_, true);
|
||||
AddItemToPlaylist(context_item_, AddMode_Replace);
|
||||
}
|
||||
|
||||
void IcecastService::OpenInNewPlaylist() {
|
||||
AddItemToPlaylist(context_item_, false, false, true);
|
||||
AddItemToPlaylist(context_item_, AddMode_OpenInNew);
|
||||
}
|
||||
|
@ -423,15 +423,15 @@ QWidget* JamendoService::HeaderWidget() const {
|
||||
}
|
||||
|
||||
void JamendoService::AddToPlaylist() {
|
||||
AddItemToPlaylist(context_item_, false);
|
||||
AddItemToPlaylist(context_item_, AddMode_Append);
|
||||
}
|
||||
|
||||
void JamendoService::LoadToPlaylist() {
|
||||
AddItemToPlaylist(context_item_, true);
|
||||
AddItemToPlaylist(context_item_, AddMode_Replace);
|
||||
}
|
||||
|
||||
void JamendoService::OpenInNewPlaylist() {
|
||||
AddItemToPlaylist(context_item_, false, false, true);
|
||||
AddItemToPlaylist(context_item_, AddMode_OpenInNew);
|
||||
}
|
||||
|
||||
void JamendoService::AlbumInfo() {
|
||||
|
@ -559,15 +559,15 @@ void LastFMService::RefreshNeighboursFinished() {
|
||||
}
|
||||
|
||||
void LastFMService::AddToPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), false);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_Append);
|
||||
}
|
||||
|
||||
void LastFMService::LoadToPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), true);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_Replace);
|
||||
}
|
||||
|
||||
void LastFMService::OpenInNewPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), false, false, true);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
|
||||
}
|
||||
|
||||
void LastFMService::AddArtistRadio() {
|
||||
@ -612,7 +612,7 @@ void LastFMService::AddArtistOrTag(const QString& name,
|
||||
item->setData(title_pattern.arg(content), RadioModel::Role_Title);
|
||||
item->setData(RadioModel::PlayBehaviour_SingleItem, RadioModel::Role_PlayBehaviour);
|
||||
list->appendRow(item);
|
||||
emit AddItemToPlaylist(item->index(), false);
|
||||
emit AddItemToPlaylist(item->index(), AddMode_Append);
|
||||
|
||||
SaveList(name, list);
|
||||
}
|
||||
|
@ -286,15 +286,15 @@ void MagnatuneService::ShowContextMenu(const QModelIndex& index, const QPoint& g
|
||||
}
|
||||
|
||||
void MagnatuneService::AddToPlaylist() {
|
||||
AddItemToPlaylist(context_item_, false);
|
||||
AddItemToPlaylist(context_item_, AddMode_Append);
|
||||
}
|
||||
|
||||
void MagnatuneService::LoadToPlaylist() {
|
||||
AddItemToPlaylist(context_item_, true);
|
||||
AddItemToPlaylist(context_item_, AddMode_Replace);
|
||||
}
|
||||
|
||||
void MagnatuneService::OpenInNewPlaylist() {
|
||||
AddItemToPlaylist(context_item_, false, false, true);
|
||||
AddItemToPlaylist(context_item_, AddMode_OpenInNew);
|
||||
}
|
||||
|
||||
void MagnatuneService::Homepage() {
|
||||
|
@ -36,17 +36,16 @@ PlaylistItem::SpecialLoadResult RadioService::LoadNext(const QUrl&) {
|
||||
return PlaylistItem::SpecialLoadResult();
|
||||
}
|
||||
|
||||
void RadioService::AddItemToPlaylist(const QModelIndex& index, bool clear, bool enqueue, bool start_new) {
|
||||
AddItemsToPlaylist(QModelIndexList() << index, clear, enqueue, start_new);
|
||||
void RadioService::AddItemToPlaylist(const QModelIndex& index, AddMode add_mode) {
|
||||
AddItemsToPlaylist(QModelIndexList() << index, add_mode);
|
||||
}
|
||||
|
||||
void RadioService::AddItemsToPlaylist(const QModelIndexList& indexes, bool clear, bool enqueue, bool start_new) {
|
||||
void RadioService::AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode) {
|
||||
QMimeData* data = model()->merged_model()->mimeData(
|
||||
model()->merged_model()->mapFromSource(indexes));
|
||||
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
|
||||
mime_data->clear_first_ = clear;
|
||||
mime_data->enqueue_now_ = enqueue;
|
||||
mime_data->new_playlist_ = start_new;
|
||||
mime_data->clear_first_ = add_mode == AddMode_Replace;
|
||||
mime_data->new_playlist_ = add_mode == AddMode_OpenInNew;
|
||||
}
|
||||
emit AddToPlaylistSignal(data);
|
||||
}
|
||||
|
@ -66,8 +66,20 @@ signals:
|
||||
void AddToPlaylistSignal(QMimeData* data);
|
||||
|
||||
protected:
|
||||
void AddItemToPlaylist(const QModelIndex& index, bool clear = false, bool enqueue = false, bool start_new = false);
|
||||
void AddItemsToPlaylist(const QModelIndexList& indexes, bool clear = false, bool enqueue = false, bool start_new = false);
|
||||
// Describes how songs should be added to playlist.
|
||||
enum AddMode {
|
||||
// appends songs to the current playlist
|
||||
AddMode_Append,
|
||||
// clears the current playlist and then appends all songs to it
|
||||
AddMode_Replace,
|
||||
// creates a new, empty playlist and then adds all songs to it
|
||||
AddMode_OpenInNew
|
||||
};
|
||||
|
||||
// Adds the 'index' element to playlist using the 'add_mode' mode.
|
||||
void AddItemToPlaylist(const QModelIndex& index, AddMode add_mode);
|
||||
// Adds the 'indexes' elements to playlist using the 'add_mode' mode.
|
||||
void AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode);
|
||||
|
||||
private:
|
||||
RadioModel* model_;
|
||||
|
@ -141,15 +141,15 @@ void SavedRadio::Edit() {
|
||||
}
|
||||
|
||||
void SavedRadio::AddToPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), false);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_Append);
|
||||
}
|
||||
|
||||
void SavedRadio::LoadToPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), true);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_Replace);
|
||||
}
|
||||
|
||||
void SavedRadio::OpenInNewPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), false, false, true);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
|
||||
}
|
||||
|
||||
void SavedRadio::AddStreamToList(const Stream& stream, QStandardItem* parent) {
|
||||
|
@ -214,15 +214,15 @@ void SomaFMService::Homepage() {
|
||||
}
|
||||
|
||||
void SomaFMService::AddToPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), false);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_Append);
|
||||
}
|
||||
|
||||
void SomaFMService::LoadToPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), true);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_Replace);
|
||||
}
|
||||
|
||||
void SomaFMService::OpenInNewPlaylist() {
|
||||
AddItemToPlaylist(context_item_->index(), false, false, true);
|
||||
AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
|
||||
}
|
||||
|
||||
PlaylistItem::Options SomaFMService::playlistitem_options() const {
|
||||
|
@ -35,6 +35,12 @@ signals:
|
||||
void AddToPlaylistSignal(QMimeData* data);
|
||||
|
||||
protected:
|
||||
void AddItemToPlaylist(const QModelIndex& index, bool clear = false, bool enqueue = false, bool start_new = false);
|
||||
void AddItemsToPlaylist(const QModelIndexList& indexes, bool clear = false, bool enqueue = false, bool start_new = false);
|
||||
enum AddMode {
|
||||
AddMode_Append,
|
||||
AddMode_Replace,
|
||||
AddMode_OpenInNew
|
||||
};
|
||||
|
||||
void AddItemToPlaylist(const QModelIndex& index, AddMode add_mode);
|
||||
void AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user