diff --git a/scripts/digitallyimported-radio/diservice.py b/scripts/digitallyimported-radio/diservice.py index 88ceb612d..6d8fb33af 100644 --- a/scripts/digitallyimported-radio/diservice.py +++ b/scripts/digitallyimported-radio/diservice.py @@ -10,7 +10,7 @@ class DigitallyImportedService(DigitallyImportedServiceBase): HOMEPAGE_NAME = "di.fm" STREAM_LIST_URL = QUrl("http://listen.di.fm/") ICON_FILENAME = "icon-small.png" - SERVICE_NAME = "digitally_imported" + SERVICE_NAME = "DigitallyImported" SERVICE_DESCRIPTION = "Digitally Imported" # These have to be in the same order as in the settings dialog diff --git a/scripts/digitallyimported-radio/skyservice.py b/scripts/digitallyimported-radio/skyservice.py index 705d83497..5991e3386 100644 --- a/scripts/digitallyimported-radio/skyservice.py +++ b/scripts/digitallyimported-radio/skyservice.py @@ -12,7 +12,7 @@ class SkyFmService(DigitallyImportedServiceBase): HOMEPAGE_NAME = "sky.fm" STREAM_LIST_URL = QUrl("http://listen.sky.fm/") ICON_FILENAME = "icon-sky.png" - SERVICE_NAME = "sky_fm" + SERVICE_NAME = "SKY.fm" SERVICE_DESCRIPTION = "SKY.fm" HASHKEY_RE = re.compile(r'hashKey\s*=\s*\'([0-9a-f]+)\'') diff --git a/src/core/mimedata.h b/src/core/mimedata.h index d7c630217..bdfcf3106 100644 --- a/src/core/mimedata.h +++ b/src/core/mimedata.h @@ -25,11 +25,11 @@ class MimeData : public QMimeData { public: MimeData(bool clear = false, bool play_now = false, - bool enqueue = false, bool new_playlist = false) + bool enqueue = false, const QString& name_for_new_playlist_ = QString()) : clear_first_(clear), play_now_(play_now), enqueue_now_(enqueue), - new_playlist_(new_playlist), + name_for_new_playlist_(name_for_new_playlist_), from_doubleclick_(false) {} // If this is set then the playlist will be cleared before these songs @@ -44,8 +44,9 @@ public: // If this is set then the items are added to the queue after being inserted. bool enqueue_now_; - // If this is set then the items are inserted into a newly created playlist. - bool new_playlist_; + // If this is not empty then the items are inserted into a newly created playlist + // with this name. + QString name_for_new_playlist_; // This can be set if this MimeData goes via MainWindow (ie. it is created // manually in a double-click). The MainWindow will set the above three diff --git a/src/devices/deviceview.cpp b/src/devices/deviceview.cpp index 09e6242db..f9d19c0d1 100644 --- a/src/devices/deviceview.cpp +++ b/src/devices/deviceview.cpp @@ -24,6 +24,7 @@ #include "core/mimedata.h" #include "library/librarydirectorymodel.h" #include "library/librarymodel.h" +#include "library/libraryview.h" #include "ui/iconloader.h" #include "ui/organisedialog.h" #include "ui/organiseerrordialog.h" @@ -370,7 +371,7 @@ void DeviceView::AddToPlaylist() { void DeviceView::OpenInNewPlaylist() { QMimeData* data = model()->mimeData(selectedIndexes()); if (MimeData* mime_data = qobject_cast(data)) { - mime_data->new_playlist_ = true; + mime_data->name_for_new_playlist_ = LibraryView::GetNameForNewPlaylist(GetSelectedSongs()); } emit AddToPlaylistSignal(data); } diff --git a/src/library/libraryview.cpp b/src/library/libraryview.cpp index 2949d86d9..a5a98c319 100644 --- a/src/library/libraryview.cpp +++ b/src/library/libraryview.cpp @@ -37,8 +37,9 @@ #include #include #include -#include +#include #include +#include #include #include @@ -374,7 +375,7 @@ void LibraryView::AddToPlaylistEnqueue() { void LibraryView::OpenInNewPlaylist() { QMimeData* data = model()->mimeData(selectedIndexes()); if (MimeData* mime_data = qobject_cast(data)) { - mime_data->new_playlist_ = true; + mime_data->name_for_new_playlist_ = LibraryView::GetNameForNewPlaylist(GetSelectedSongs()); } emit AddToPlaylistSignal(data); } @@ -529,3 +530,36 @@ void LibraryView::EditSmartPlaylistFinished() { const Wizard* wizard = qobject_cast(sender()); library_->UpdateGenerator(context_menu_index_, wizard->CreateGenerator()); } + +QString LibraryView::GetNameForNewPlaylist(const SongList& songs) { + QSet artists; + QSet albums; + + foreach(const Song& song, songs) { + artists << (song.artist().isEmpty() + ? tr("Unknown") + : song.artist()); + albums << (song.album().isEmpty() + ? tr("Unknown") + : song.album()); + + if(artists.size() > 1) { + break; + } + } + + bool various_artists = artists.size() > 1; + + QString result; + if(various_artists) { + result = tr("Various artists"); + } else { + result = artists.values().at(0); + } + + if(!various_artists && albums.size() == 1) { + result += " - " + albums.toList()[0]; + } + + return result; +} diff --git a/src/library/libraryview.h b/src/library/libraryview.h index ea8c64de8..fae5b24b9 100644 --- a/src/library/libraryview.h +++ b/src/library/libraryview.h @@ -70,6 +70,10 @@ class LibraryView : public AutoExpandingTreeView { void keyboardSearch(const QString &search); void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible); + // Returns a pretty automatic name for playlist created from the given list of + // songs. + static QString GetNameForNewPlaylist(const SongList& songs); + public slots: void TotalSongCountUpdated(int count); void ReloadSettings(); diff --git a/src/radio/radioservice.cpp b/src/radio/radioservice.cpp index 57f2655fe..9b1f17f4f 100644 --- a/src/radio/radioservice.cpp +++ b/src/radio/radioservice.cpp @@ -94,7 +94,9 @@ void RadioService::AddItemsToPlaylist(const QModelIndexList& indexes, AddMode ad model()->merged_model()->mapFromSource(indexes)); if (MimeData* mime_data = qobject_cast(data)) { mime_data->clear_first_ = add_mode == AddMode_Replace; - mime_data->new_playlist_ = add_mode == AddMode_OpenInNew; + if(add_mode == AddMode_OpenInNew) { + mime_data->name_for_new_playlist_ = name(); + } } emit AddToPlaylistSignal(data); } diff --git a/src/radio/radioservice.h b/src/radio/radioservice.h index 8787a27b0..0facb67b4 100644 --- a/src/radio/radioservice.h +++ b/src/radio/radioservice.h @@ -34,6 +34,8 @@ class RadioService : public QObject { Q_OBJECT public: + // Constructs a new radio service with the given name and model. The name + // should be user-friendly (like 'DigitallyImported' or 'Last.fm'). RadioService(const QString& name, RadioModel* model); virtual ~RadioService() {} diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 29b6ebc1c..9f6d56c87 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -985,7 +985,7 @@ void MainWindow::ApplyAddBehaviour(MainWindow::AddBehaviour b, MimeData* data) c break; case AddBehaviour_OpenInNew: - data->new_playlist_ = true; + data->name_for_new_playlist_ = tr("Playlist"); break; } } @@ -1020,8 +1020,8 @@ void MainWindow::AddToPlaylist(QMimeData* data) { } // Should we create a new playlist for the songs? - if(mime_data->new_playlist_) { - playlists_->New(tr("Playlist")); + if(!mime_data->name_for_new_playlist_.isEmpty()) { + playlists_->New(mime_data->name_for_new_playlist_); } } diff --git a/src/widgets/fileviewlist.cpp b/src/widgets/fileviewlist.cpp index f09e119c8..79e041c6c 100644 --- a/src/widgets/fileviewlist.cpp +++ b/src/widgets/fileviewlist.cpp @@ -90,7 +90,7 @@ void FileViewList::AddToPlaylistSlot() { void FileViewList::OpenInNewPlaylistSlot() { MimeData* data = MimeDataFromSelection(); - data->new_playlist_ = true; + data->name_for_new_playlist_ = static_cast(model())->rootPath(); emit AddToPlaylist(data); }