mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
moving the responsibility for naming playlists into mimeData() methods (into models)
this means that pretty names for new playlists now also work when double clicking (in certain mode) or dragging and dropping fixes issue #1477
This commit is contained in:
parent
383138737c
commit
7de912d3a1
@ -25,11 +25,12 @@ class MimeData : public QMimeData {
|
||||
|
||||
public:
|
||||
MimeData(bool clear = false, bool play_now = false,
|
||||
bool enqueue = false, const QString& name_for_new_playlist_ = QString())
|
||||
bool enqueue = false, bool open_in_new_playlist = false)
|
||||
: clear_first_(clear),
|
||||
play_now_(play_now),
|
||||
enqueue_now_(enqueue),
|
||||
name_for_new_playlist_(name_for_new_playlist_),
|
||||
open_in_new_playlist_(open_in_new_playlist),
|
||||
name_for_new_playlist_(QString()),
|
||||
from_doubleclick_(false) {}
|
||||
|
||||
// If this is set then the playlist will be cleared before these songs
|
||||
@ -44,14 +45,24 @@ public:
|
||||
// If this is set then the items are added to the queue after being inserted.
|
||||
bool enqueue_now_;
|
||||
|
||||
// If this is not empty then the items are inserted into a newly created playlist
|
||||
// with this name.
|
||||
// If this is set then the items are inserted into a newly created playlist.
|
||||
bool open_in_new_playlist_;
|
||||
|
||||
// This serves as a name for the new playlist in 'open_in_new_playlist_' mode.
|
||||
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
|
||||
// flags to the defaults set by the user.
|
||||
// manually in a double-click). The MainWindow will set the above flags to
|
||||
// the defaults set by the user.
|
||||
bool from_doubleclick_;
|
||||
|
||||
// Returns a pretty name for a playlist containing songs described by this MimeData
|
||||
// object. By pretty name we mean the value of 'name_for_new_playlist_' or generic
|
||||
// "Playlist" string if the 'name_for_new_playlist_' attribute is empty.
|
||||
QString get_name_for_new_playlist() {
|
||||
return name_for_new_playlist_.isEmpty() ? tr("Playlist") : name_for_new_playlist_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // MIMEDATA_H
|
||||
|
@ -371,7 +371,7 @@ void DeviceView::AddToPlaylist() {
|
||||
void DeviceView::OpenInNewPlaylist() {
|
||||
QMimeData* data = model()->mimeData(selectedIndexes());
|
||||
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
|
||||
mime_data->name_for_new_playlist_ = LibraryView::GetNameForNewPlaylist(GetSelectedSongs());
|
||||
mime_data->open_in_new_playlist_ = true;
|
||||
}
|
||||
emit AddToPlaylistSignal(data);
|
||||
}
|
||||
|
@ -911,6 +911,7 @@ QMimeData* LibraryModel::mimeData(const QModelIndexList& indexes) const {
|
||||
|
||||
GeneratorMimeData* data = new GeneratorMimeData(generator);
|
||||
data->setData(kSmartPlaylistsMimeType, QByteArray());
|
||||
data->name_for_new_playlist_ = this->data(indexes.first()).toString();
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -924,11 +925,8 @@ QMimeData* LibraryModel::mimeData(const QModelIndexList& indexes) const {
|
||||
GetChildSongs(IndexToItem(index), &urls, &data->songs, &song_ids);
|
||||
}
|
||||
|
||||
if(!indexes.isEmpty()) {
|
||||
data->name_for_new_playlist_ = LibraryView::GetNameForNewPlaylist(data->songs);
|
||||
}
|
||||
|
||||
data->setUrls(urls);
|
||||
data->name_for_new_playlist_ = LibraryView::GetNameForNewPlaylist(data->songs);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -374,28 +374,9 @@ void LibraryView::AddToPlaylistEnqueue() {
|
||||
|
||||
void LibraryView::OpenInNewPlaylist() {
|
||||
QMimeData* data = model()->mimeData(selectedIndexes());
|
||||
|
||||
// we look for the first smart playlist among selection because this
|
||||
// is the one which will get into the new playlist eventually
|
||||
QString first_smart_playlist_name;
|
||||
foreach(const QModelIndex& index, selectedIndexes()) {
|
||||
const int type = model()->data(index, LibraryModel::Role_Type).toInt();
|
||||
|
||||
if(type == LibraryItem::Type_SmartPlaylist) {
|
||||
first_smart_playlist_name = model()->data(index).toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
|
||||
if(first_smart_playlist_name.isEmpty()) {
|
||||
mime_data->name_for_new_playlist_
|
||||
= LibraryView::GetNameForNewPlaylist(GetSelectedSongs());
|
||||
} else {
|
||||
mime_data->name_for_new_playlist_ = first_smart_playlist_name;
|
||||
}
|
||||
mime_data->open_in_new_playlist_ = true;
|
||||
}
|
||||
|
||||
emit AddToPlaylistSignal(data);
|
||||
}
|
||||
|
||||
|
@ -219,6 +219,8 @@ QMimeData* IcecastModel::mimeData(const QModelIndexList& indexes) const {
|
||||
}
|
||||
|
||||
data->setUrls(urls);
|
||||
data->name_for_new_playlist_ = "Icecast";
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -171,10 +171,12 @@ QStringList RadioModel::mimeTypes() const {
|
||||
QMimeData* RadioModel::mimeData(const QModelIndexList& indexes) const {
|
||||
QList<QUrl> urls;
|
||||
|
||||
QModelIndex last_valid_index;
|
||||
foreach (const QModelIndex& index, indexes) {
|
||||
if (!IsPlayable(index))
|
||||
continue;
|
||||
|
||||
last_valid_index = index;
|
||||
urls << index.data(Role_Url).toUrl();
|
||||
}
|
||||
|
||||
@ -184,6 +186,7 @@ QMimeData* RadioModel::mimeData(const QModelIndexList& indexes) const {
|
||||
RadioMimeData* data = new RadioMimeData(this);
|
||||
data->setUrls(urls);
|
||||
data->indexes = indexes;
|
||||
data->name_for_new_playlist_ = RadioModel::ServiceForIndex(last_valid_index)->name();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -94,9 +94,7 @@ 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;
|
||||
if(add_mode == AddMode_OpenInNew) {
|
||||
mime_data->name_for_new_playlist_ = name();
|
||||
}
|
||||
mime_data->open_in_new_playlist_ = add_mode == AddMode_OpenInNew;
|
||||
}
|
||||
emit AddToPlaylistSignal(data);
|
||||
}
|
||||
|
@ -985,7 +985,7 @@ void MainWindow::ApplyAddBehaviour(MainWindow::AddBehaviour b, MimeData* data) c
|
||||
break;
|
||||
|
||||
case AddBehaviour_OpenInNew:
|
||||
data->name_for_new_playlist_ = tr("Playlist");
|
||||
data->open_in_new_playlist_ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1020,8 +1020,8 @@ void MainWindow::AddToPlaylist(QMimeData* data) {
|
||||
}
|
||||
|
||||
// Should we create a new playlist for the songs?
|
||||
if(!mime_data->name_for_new_playlist_.isEmpty()) {
|
||||
playlists_->New(mime_data->name_for_new_playlist_);
|
||||
if(mime_data->open_in_new_playlist_) {
|
||||
playlists_->New(mime_data->get_name_for_new_playlist());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,9 +132,13 @@ void FileView::ItemDoubleClick(const QModelIndex& index) {
|
||||
if (model_->isDir(index))
|
||||
return;
|
||||
|
||||
QString file_path = model_->filePath(index);
|
||||
|
||||
MimeData* data = new MimeData;
|
||||
data->from_doubleclick_ = true;
|
||||
data->setUrls(QList<QUrl>() << QUrl::fromLocalFile(model_->filePath(index)));
|
||||
data->setUrls(QList<QUrl>() << QUrl::fromLocalFile(file_path));
|
||||
data->name_for_new_playlist_ = file_path;
|
||||
|
||||
emit AddToPlaylist(data);
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,16 @@ QList<QUrl> FileViewList::UrlListFromSelection() const {
|
||||
MimeData* FileViewList::MimeDataFromSelection() const {
|
||||
MimeData* data = new MimeData;
|
||||
data->setUrls(UrlListFromSelection());
|
||||
|
||||
QList<QString> filenames = FilenamesFromSelection();
|
||||
// if just one file / folder selected - use it's path as the new playlist's name
|
||||
if(filenames.size() == 1) {
|
||||
data->name_for_new_playlist_ = filenames[0];
|
||||
// otherwise, use the current root path
|
||||
} else {
|
||||
data->name_for_new_playlist_ = static_cast<QFileSystemModel*>(model())->rootPath();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -90,16 +100,7 @@ void FileViewList::AddToPlaylistSlot() {
|
||||
|
||||
void FileViewList::OpenInNewPlaylistSlot() {
|
||||
MimeData* data = MimeDataFromSelection();
|
||||
|
||||
QList<QString> filenames = FilenamesFromSelection();
|
||||
// if just one file / folder selected - use it's path as the new playlist's name
|
||||
if(filenames.size() == 1) {
|
||||
data->name_for_new_playlist_ = filenames[0];
|
||||
// otherwise, use the current root path
|
||||
} else {
|
||||
data->name_for_new_playlist_ = static_cast<QFileSystemModel*>(model())->rootPath();
|
||||
}
|
||||
|
||||
data->open_in_new_playlist_ = true;
|
||||
emit AddToPlaylist(data);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user