user-friendly name for 'Open in new playlist' playlists (fixes issue #1445)

This commit is contained in:
Paweł Bara 2011-02-14 17:00:13 +00:00
parent e67f39cedb
commit 0182829223
10 changed files with 58 additions and 14 deletions

View File

@ -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

View File

@ -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]+)\'')

View File

@ -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

View File

@ -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<MimeData*>(data)) {
mime_data->new_playlist_ = true;
mime_data->name_for_new_playlist_ = LibraryView::GetNameForNewPlaylist(GetSelectedSongs());
}
emit AddToPlaylistSignal(data);
}

View File

@ -37,8 +37,9 @@
#include <QHelpEvent>
#include <QMenu>
#include <QMessageBox>
#include <QSortFilterProxyModel>
#include <QSet>
#include <QSettings>
#include <QSortFilterProxyModel>
#include <QToolTip>
#include <QWhatsThis>
@ -374,7 +375,7 @@ void LibraryView::AddToPlaylistEnqueue() {
void LibraryView::OpenInNewPlaylist() {
QMimeData* data = model()->mimeData(selectedIndexes());
if (MimeData* mime_data = qobject_cast<MimeData*>(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<Wizard*>(sender());
library_->UpdateGenerator(context_menu_index_, wizard->CreateGenerator());
}
QString LibraryView::GetNameForNewPlaylist(const SongList& songs) {
QSet<QString> artists;
QSet<QString> 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;
}

View File

@ -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();

View File

@ -94,7 +94,9 @@ void RadioService::AddItemsToPlaylist(const QModelIndexList& indexes, AddMode ad
model()->merged_model()->mapFromSource(indexes));
if (MimeData* mime_data = qobject_cast<MimeData*>(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);
}

View File

@ -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() {}

View File

@ -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_);
}
}

View File

@ -90,7 +90,7 @@ void FileViewList::AddToPlaylistSlot() {
void FileViewList::OpenInNewPlaylistSlot() {
MimeData* data = MimeDataFromSelection();
data->new_playlist_ = true;
data->name_for_new_playlist_ = static_cast<QFileSystemModel*>(model())->rootPath();
emit AddToPlaylist(data);
}