From 11f500411209f6fa52f7f818845052fbffd9b115 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 15 Mar 2020 01:56:48 +0100 Subject: [PATCH] Use a shorter playlist name when songs are added from file view Fixes #363 --- src/widgets/fileviewlist.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/widgets/fileviewlist.cpp b/src/widgets/fileviewlist.cpp index 5501c50bf..8c5b29b3b 100644 --- a/src/widgets/fileviewlist.cpp +++ b/src/widgets/fileviewlist.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -83,11 +84,28 @@ MimeData *FileViewList::MimeDataFromSelection() const { QList filenames = FilenamesFromSelection(); // if just one folder selected - use it's path as the new playlist's name if (filenames.size() == 1 && QFileInfo(filenames.first()).isDir()) { - data->name_for_new_playlist_ = filenames.first(); - // otherwise, use the current root path + if (filenames.first().length() > 20) { + data->name_for_new_playlist_ = QDir(filenames.first()).dirName(); + } + else { + data->name_for_new_playlist_ = filenames.first(); + } } + // otherwise, use the current root path else { - data->name_for_new_playlist_ = static_cast(model())->rootPath(); + QString path = static_cast(model())->rootPath(); + if (path.length() > 20) { + QFileInfo info(path); + if (info.isDir()) { + data->name_for_new_playlist_ = QDir(info.filePath()).dirName(); + } + else { + data->name_for_new_playlist_ = info.baseName(); + } + } + else { + data->name_for_new_playlist_ = path; + } } return data; @@ -130,7 +148,6 @@ void FileViewList::MoveToCollectionSlot() { } void FileViewList::CopyToDeviceSlot() { - //qLog(Debug) << __PRETTY_FUNCTION__; emit CopyToDevice(UrlListFromSelection()); }