Commit 220c110b authored by Yerrey Dev's avatar Yerrey Dev Committed by Nate Graham
Browse files

Support saving playlist with relative paths

Adds the support for saving playlists with relative paths in cases where
the music files are located in the same folder as the playlist to be saved.
This setting is "Prefer relative paths" by default as that seems to be
common with most music players.

A new persistent config `alwaysUseAbsolutePlaylistPaths` is created, which
is then checked in `MediaPlayListProxyModel::savePlaylist`. With a false
value, music files in the same folder as the playlist are pathed with just
the filename, otherwise with absolute paths. With a true value an absolute
path is always used.

BUG: 449262
FIXED-IN: 22.12
parent 0fcddb0d
Pipeline #222910 passed with stage
in 4 minutes and 32 seconds
......@@ -42,6 +42,13 @@
</default>
</entry>
</group>
<group name="Playlist">
<entry key="AlwaysUseAbsolutePlaylistPaths" type="Bool" >
<default>
false
</default>
</entry>
</group>
<group name="Views">
<entry key="EmbeddedView" type="Enum">
<choices>
......
......@@ -76,6 +76,7 @@ void ElisaConfigurationDialog::save()
Elisa::ElisaConfiguration::setShowProgressOnTaskBar(mShowProgressInTaskBar);
Elisa::ElisaConfiguration::setShowSystemTrayIcon(mShowSystemTrayIcon);
Elisa::ElisaConfiguration::setForceUsageOfFastFileSearch(!mForceUsageOfSlowFileSystemIndexing);
Elisa::ElisaConfiguration::setAlwaysUseAbsolutePlaylistPaths(mAlwaysUseAbsolutePlaylistPaths);
Elisa::ElisaConfiguration::setPlayAtStartup(mPlayAtStartup);
Elisa::ElisaConfiguration::setScanAtStartup(mScanAtStartup);
Elisa::ElisaConfiguration::setColorScheme(mColorScheme);
......@@ -171,6 +172,18 @@ void ElisaConfigurationDialog::setForceUsageOfSlowFileSystemIndexing(bool forceU
setDirty();
}
void ElisaConfigurationDialog::setAlwaysUseAbsolutePlaylistPaths(bool alwaysUseAbsolutePlaylistPaths)
{
if (mAlwaysUseAbsolutePlaylistPaths == alwaysUseAbsolutePlaylistPaths) {
return;
}
mAlwaysUseAbsolutePlaylistPaths = alwaysUseAbsolutePlaylistPaths;
Q_EMIT alwaysUseAbsolutePlaylistPathsChanged();
setDirty();
}
void ElisaConfigurationDialog::setEmbeddedView(ElisaUtils::PlayListEntryType embeddedView)
{
if (mEmbeddedView == embeddedView) {
......@@ -274,6 +287,9 @@ void ElisaConfigurationDialog::configChanged()
mForceUsageOfSlowFileSystemIndexing = !Elisa::ElisaConfiguration::forceUsageOfFastFileSearch();
Q_EMIT forceUsageOfSlowFileSystemIndexingChanged();
mAlwaysUseAbsolutePlaylistPaths = Elisa::ElisaConfiguration::alwaysUseAbsolutePlaylistPaths();
Q_EMIT alwaysUseAbsolutePlaylistPathsChanged();
switch (Elisa::ElisaConfiguration::embeddedView())
{
case Elisa::ElisaConfiguration::EnumEmbeddedView::NoView:
......
......@@ -29,6 +29,11 @@ class ELISALIB_EXPORT ElisaConfigurationDialog : public QObject
WRITE setForceUsageOfSlowFileSystemIndexing
NOTIFY forceUsageOfSlowFileSystemIndexingChanged)
Q_PROPERTY(bool alwaysUseAbsolutePlaylistPaths
READ alwaysUseAbsolutePlaylistPaths
WRITE setAlwaysUseAbsolutePlaylistPaths
NOTIFY alwaysUseAbsolutePlaylistPathsChanged)
Q_PROPERTY(bool showNowPlayingBackground
READ showNowPlayingBackground
WRITE setShowNowPlayingBackground
......@@ -112,6 +117,11 @@ public:
return mForceUsageOfSlowFileSystemIndexing;
}
[[nodiscard]] bool alwaysUseAbsolutePlaylistPaths() const
{
return mAlwaysUseAbsolutePlaylistPaths;
}
[[nodiscard]] ElisaUtils::PlayListEntryType embeddedView() const
{
return mEmbeddedView;
......@@ -159,6 +169,8 @@ Q_SIGNALS:
void forceUsageOfSlowFileSystemIndexingChanged();
void alwaysUseAbsolutePlaylistPathsChanged();
void embeddedViewChanged();
void initialViewIndexChanged();
......@@ -187,6 +199,8 @@ public Q_SLOTS:
void setForceUsageOfSlowFileSystemIndexing(bool forceUsageOfSlowFileSystemIndexing);
void setAlwaysUseAbsolutePlaylistPaths(bool alwaysUseAbsolutePlaylistPaths);
void setEmbeddedView(ElisaUtils::PlayListEntryType embeddedView);
void setInitialViewIndex(int initialViewIndex);
......@@ -221,6 +235,8 @@ private:
bool mForceUsageOfSlowFileSystemIndexing = true;
bool mAlwaysUseAbsolutePlaylistPaths = false;
bool mPlayAtStartup = false;
bool mScanAtStartup = true;
......
......@@ -9,6 +9,7 @@
#include "mediaplaylistproxymodel.h"
#include "mediaplaylist.h"
#include "playListLogging.h"
#include "elisa_settings.h"
#include <QItemSelection>
#include <QList>
#include <QMediaPlaylist>
......@@ -715,10 +716,27 @@ bool MediaPlayListProxyModel::savePlayList(const QUrl &fileName)
{
QMediaPlaylist savePlaylist;
for (int i = 0; i < rowCount(); ++i) {
if (data(index(i,0), MediaPlayList::IsValidRole).toBool()) {
data(index(i,0), MediaPlayList::ResourceRole).toUrl();
savePlaylist.addMedia(data(index(i,0), MediaPlayList::ResourceRole).toUrl());
if (Elisa::ElisaConfiguration::self()->alwaysUseAbsolutePlaylistPaths()) {
for (int i = 0; i < rowCount(); ++i) {
if (data(index(i,0), MediaPlayList::IsValidRole).toBool()) {
data(index(i,0), MediaPlayList::ResourceRole).toUrl();
savePlaylist.addMedia(QUrl(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile()));
}
}
} else {
QFileInfo playlistFile(fileName.toLocalFile());
QDir dir(playlistFile.absolutePath());
for (int i = 0; i < rowCount(); ++i) {
if (data(index(i,0), MediaPlayList::IsValidRole).toBool()) {
QFileInfo musicFile(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile());
if (musicFile.dir().path() == dir.absolutePath()) {
savePlaylist.addMedia(QUrl(musicFile.fileName()));
} else {
savePlaylist.addMedia(QUrl(data(index(i,0), MediaPlayList::ResourceRole).toUrl().toLocalFile()));
}
}
}
}
......
......@@ -13,6 +13,7 @@ import QtQuick.Controls 2.4 as QQC2
import QtQuick.Dialogs 1.3 as Dialogs
import org.kde.kirigami 2.14 as Kirigami
import org.kde.kcm 1.6 as KCM
import org.kde.elisa 1.0
......@@ -277,6 +278,32 @@ ColumnLayout {
ElisaConfigurationDialog.forceUsageOfSlowFileSystemIndexing = currentIndex === 0 ? false : true
}
}
Item {
Kirigami.FormData.isSection: true
}
// Playlist save settings
// ======================
RowLayout {
Kirigami.FormData.label: i18n("When saving playlist files:")
spacing: Kirigami.Units.smallSpacing
QQC2.ComboBox {
model: [i18nc("@item:inlistbox Configure dialog, playlist save type", "Prefer relative paths"),
i18nc("@item:inlistbox Configure dialog, playlist save type", "Always use absolute paths")]
currentIndex: ElisaConfigurationDialog.alwaysUseAbsolutePlaylistPaths ? 1 : 0
onActivated: {
ElisaConfigurationDialog.alwaysUseAbsolutePlaylistPaths = currentIndex === 0 ? false : true
}
}
KCM.ContextualHelpButton {
toolTipText: xi18nc("@info:tooltip Playlist Relative Paths", "When <interface>Prefer relative paths</interface> is selected, files in the same folder as the playlist will be referred with only the filename. Absolute paths are used in other cases.")
}
}
}
Kirigami.InlineMessage {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment