simplifying AddItems API of RadioService

This commit is contained in:
Paweł Bara 2011-02-09 18:23:14 +00:00
parent 60ac6768b8
commit 38172c39b4
10 changed files with 49 additions and 32 deletions

View File

@ -87,13 +87,13 @@ class DigitallyImportedServiceBase(clementine.RadioService):
self.menu.popup(global_pos) self.menu.popup(global_pos)
def AddToPlaylist(self): def AddToPlaylist(self):
self.AddItemToPlaylist(self.context_index, False) self.AddItemToPlaylist(self.context_index, self.AddMode_Append)
def LoadToPlaylist(self): def LoadToPlaylist(self):
self.AddItemToPlaylist(self.context_index, True) self.AddItemToPlaylist(self.context_index, self.AddMode_Replace)
def OpenInNewPlaylist(self): def OpenInNewPlaylist(self):
self.AddItemToPlaylist(self.context_index, False, False, True) self.AddItemToPlaylist(self.context_index, self.AddMode_OpenInNew)
def Homepage(self): def Homepage(self):
QDesktopServices.openUrl(self.HOMEPAGE_URL) QDesktopServices.openUrl(self.HOMEPAGE_URL)

View File

@ -299,13 +299,13 @@ void IcecastService::Homepage() {
} }
void IcecastService::AddToPlaylist() { void IcecastService::AddToPlaylist() {
AddItemToPlaylist(context_item_, false); AddItemToPlaylist(context_item_, AddMode_Append);
} }
void IcecastService::LoadToPlaylist() { void IcecastService::LoadToPlaylist() {
AddItemToPlaylist(context_item_, true); AddItemToPlaylist(context_item_, AddMode_Replace);
} }
void IcecastService::OpenInNewPlaylist() { void IcecastService::OpenInNewPlaylist() {
AddItemToPlaylist(context_item_, false, false, true); AddItemToPlaylist(context_item_, AddMode_OpenInNew);
} }

View File

@ -423,15 +423,15 @@ QWidget* JamendoService::HeaderWidget() const {
} }
void JamendoService::AddToPlaylist() { void JamendoService::AddToPlaylist() {
AddItemToPlaylist(context_item_, false); AddItemToPlaylist(context_item_, AddMode_Append);
} }
void JamendoService::LoadToPlaylist() { void JamendoService::LoadToPlaylist() {
AddItemToPlaylist(context_item_, true); AddItemToPlaylist(context_item_, AddMode_Replace);
} }
void JamendoService::OpenInNewPlaylist() { void JamendoService::OpenInNewPlaylist() {
AddItemToPlaylist(context_item_, false, false, true); AddItemToPlaylist(context_item_, AddMode_OpenInNew);
} }
void JamendoService::AlbumInfo() { void JamendoService::AlbumInfo() {

View File

@ -559,15 +559,15 @@ void LastFMService::RefreshNeighboursFinished() {
} }
void LastFMService::AddToPlaylist() { void LastFMService::AddToPlaylist() {
AddItemToPlaylist(context_item_->index(), false); AddItemToPlaylist(context_item_->index(), AddMode_Append);
} }
void LastFMService::LoadToPlaylist() { void LastFMService::LoadToPlaylist() {
AddItemToPlaylist(context_item_->index(), true); AddItemToPlaylist(context_item_->index(), AddMode_Replace);
} }
void LastFMService::OpenInNewPlaylist() { void LastFMService::OpenInNewPlaylist() {
AddItemToPlaylist(context_item_->index(), false, false, true); AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
} }
void LastFMService::AddArtistRadio() { void LastFMService::AddArtistRadio() {
@ -612,7 +612,7 @@ void LastFMService::AddArtistOrTag(const QString& name,
item->setData(title_pattern.arg(content), RadioModel::Role_Title); item->setData(title_pattern.arg(content), RadioModel::Role_Title);
item->setData(RadioModel::PlayBehaviour_SingleItem, RadioModel::Role_PlayBehaviour); item->setData(RadioModel::PlayBehaviour_SingleItem, RadioModel::Role_PlayBehaviour);
list->appendRow(item); list->appendRow(item);
emit AddItemToPlaylist(item->index(), false); emit AddItemToPlaylist(item->index(), AddMode_Append);
SaveList(name, list); SaveList(name, list);
} }

View File

@ -286,15 +286,15 @@ void MagnatuneService::ShowContextMenu(const QModelIndex& index, const QPoint& g
} }
void MagnatuneService::AddToPlaylist() { void MagnatuneService::AddToPlaylist() {
AddItemToPlaylist(context_item_, false); AddItemToPlaylist(context_item_, AddMode_Append);
} }
void MagnatuneService::LoadToPlaylist() { void MagnatuneService::LoadToPlaylist() {
AddItemToPlaylist(context_item_, true); AddItemToPlaylist(context_item_, AddMode_Replace);
} }
void MagnatuneService::OpenInNewPlaylist() { void MagnatuneService::OpenInNewPlaylist() {
AddItemToPlaylist(context_item_, false, false, true); AddItemToPlaylist(context_item_, AddMode_OpenInNew);
} }
void MagnatuneService::Homepage() { void MagnatuneService::Homepage() {

View File

@ -36,17 +36,16 @@ PlaylistItem::SpecialLoadResult RadioService::LoadNext(const QUrl&) {
return PlaylistItem::SpecialLoadResult(); return PlaylistItem::SpecialLoadResult();
} }
void RadioService::AddItemToPlaylist(const QModelIndex& index, bool clear, bool enqueue, bool start_new) { void RadioService::AddItemToPlaylist(const QModelIndex& index, AddMode add_mode) {
AddItemsToPlaylist(QModelIndexList() << index, clear, enqueue, start_new); 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( QMimeData* data = model()->merged_model()->mimeData(
model()->merged_model()->mapFromSource(indexes)); model()->merged_model()->mapFromSource(indexes));
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) { if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
mime_data->clear_first_ = clear; mime_data->clear_first_ = add_mode == AddMode_Replace;
mime_data->enqueue_now_ = enqueue; mime_data->new_playlist_ = add_mode == AddMode_OpenInNew;
mime_data->new_playlist_ = start_new;
} }
emit AddToPlaylistSignal(data); emit AddToPlaylistSignal(data);
} }

View File

@ -66,8 +66,20 @@ signals:
void AddToPlaylistSignal(QMimeData* data); void AddToPlaylistSignal(QMimeData* data);
protected: protected:
void AddItemToPlaylist(const QModelIndex& index, bool clear = false, bool enqueue = false, bool start_new = false); // Describes how songs should be added to playlist.
void AddItemsToPlaylist(const QModelIndexList& indexes, bool clear = false, bool enqueue = false, bool start_new = false); 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: private:
RadioModel* model_; RadioModel* model_;

View File

@ -141,15 +141,15 @@ void SavedRadio::Edit() {
} }
void SavedRadio::AddToPlaylist() { void SavedRadio::AddToPlaylist() {
AddItemToPlaylist(context_item_->index(), false); AddItemToPlaylist(context_item_->index(), AddMode_Append);
} }
void SavedRadio::LoadToPlaylist() { void SavedRadio::LoadToPlaylist() {
AddItemToPlaylist(context_item_->index(), true); AddItemToPlaylist(context_item_->index(), AddMode_Replace);
} }
void SavedRadio::OpenInNewPlaylist() { void SavedRadio::OpenInNewPlaylist() {
AddItemToPlaylist(context_item_->index(), false, false, true); AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
} }
void SavedRadio::AddStreamToList(const Stream& stream, QStandardItem* parent) { void SavedRadio::AddStreamToList(const Stream& stream, QStandardItem* parent) {

View File

@ -214,15 +214,15 @@ void SomaFMService::Homepage() {
} }
void SomaFMService::AddToPlaylist() { void SomaFMService::AddToPlaylist() {
AddItemToPlaylist(context_item_->index(), false); AddItemToPlaylist(context_item_->index(), AddMode_Append);
} }
void SomaFMService::LoadToPlaylist() { void SomaFMService::LoadToPlaylist() {
AddItemToPlaylist(context_item_->index(), true); AddItemToPlaylist(context_item_->index(), AddMode_Replace);
} }
void SomaFMService::OpenInNewPlaylist() { void SomaFMService::OpenInNewPlaylist() {
AddItemToPlaylist(context_item_->index(), false, false, true); AddItemToPlaylist(context_item_->index(), AddMode_OpenInNew);
} }
PlaylistItem::Options SomaFMService::playlistitem_options() const { PlaylistItem::Options SomaFMService::playlistitem_options() const {

View File

@ -35,6 +35,12 @@ signals:
void AddToPlaylistSignal(QMimeData* data); void AddToPlaylistSignal(QMimeData* data);
protected: protected:
void AddItemToPlaylist(const QModelIndex& index, bool clear = false, bool enqueue = false, bool start_new = false); enum AddMode {
void AddItemsToPlaylist(const QModelIndexList& indexes, bool clear = false, bool enqueue = false, bool start_new = false); AddMode_Append,
AddMode_Replace,
AddMode_OpenInNew
};
void AddItemToPlaylist(const QModelIndex& index, AddMode add_mode);
void AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode);
}; };