From 78804b12c6667afa86d73041fd313bee019b86cd Mon Sep 17 00:00:00 2001 From: Arnaud Bienner Date: Tue, 7 Oct 2014 00:23:28 +0200 Subject: [PATCH] Use a save dialog option instead of quick change menu. This is less confusing IMO. The dialog will shown up only if users decided to in the preferences, so that will not bother users who don't need this. This reuses lot of things from Alan contribution from #4484 --- src/playlist/playlist.h | 2 + src/playlist/playlistmanager.cpp | 29 +++++++++++--- src/playlist/playlistmanager.h | 7 ++-- src/playlist/playlistsaveoptionsdialog.cpp | 44 ++++++---------------- src/playlist/playlistsaveoptionsdialog.h | 6 +-- src/playlist/playlistsaveoptionsdialog.ui | 29 ++++++++------ src/playlistparsers/asxiniparser.cpp | 5 ++- src/playlistparsers/asxiniparser.h | 3 +- src/playlistparsers/asxparser.cpp | 2 +- src/playlistparsers/asxparser.h | 3 +- src/playlistparsers/cueparser.cpp | 3 +- src/playlistparsers/cueparser.h | 3 +- src/playlistparsers/m3uparser.cpp | 5 ++- src/playlistparsers/m3uparser.h | 3 +- src/playlistparsers/parserbase.cpp | 15 +++----- src/playlistparsers/parserbase.h | 12 ++++-- src/playlistparsers/playlistparser.cpp | 5 ++- src/playlistparsers/playlistparser.h | 3 +- src/playlistparsers/plsparser.cpp | 4 +- src/playlistparsers/plsparser.h | 3 +- src/playlistparsers/wplparser.cpp | 4 +- src/playlistparsers/wplparser.h | 3 +- src/playlistparsers/xspfparser.cpp | 6 +-- src/playlistparsers/xspfparser.h | 3 +- src/ui/behavioursettingspage.cpp | 4 ++ src/ui/behavioursettingspage.ui | 7 ++++ 26 files changed, 121 insertions(+), 92 deletions(-) diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index 2c1236bab..a3a80cbb7 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -138,6 +138,8 @@ class Playlist : public QAbstractListModel { Path_Automatic = 0, // Automatically select path type Path_Absolute, // Always use absolute paths Path_Relative, // Always use relative paths + Path_Ask_User, // Only used in preferences: to ask user which of the + // previous values he wants to use. }; static const char* kCddaMimeType; diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index 9ff41da8e..334d26c29 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -18,6 +18,7 @@ #include "playlistbackend.h" #include "playlistcontainer.h" #include "playlistmanager.h" +#include "playlistsaveoptionsdialog.h" #include "playlistview.h" #include "core/application.h" #include "core/logging.h" @@ -172,9 +173,10 @@ void PlaylistManager::Load(const QString& filename) { playlist->InsertUrls(urls << QUrl::fromLocalFile(filename)); } -void PlaylistManager::Save(int id, const QString& filename) { +void PlaylistManager::Save(int id, const QString& filename, + Playlist::Path path_type) { if (playlists_.contains(id)) { - parser_->Save(playlist(id)->GetAllSongs(), filename); + parser_->Save(playlist(id)->GetAllSongs(), filename, path_type); } else { // Playlist is not in the playlist manager: probably save action was // triggered @@ -184,16 +186,18 @@ void PlaylistManager::Save(int id, const QString& filename) { watcher->setFuture(future); NewClosure(watcher, SIGNAL(finished()), this, - SLOT(ItemsLoadedForSavePlaylist(QFutureWatcher*, QString)), + SLOT(ItemsLoadedForSavePlaylist(QFutureWatcher*, QString, + Playlist::Path)), watcher, filename); } } void PlaylistManager::ItemsLoadedForSavePlaylist(QFutureWatcher* watcher, - const QString& filename) { + const QString& filename, + Playlist::Path path_type) { SongList song_list = watcher->future().results(); - parser_->Save(song_list, filename); + parser_->Save(song_list, filename, path_type); } void PlaylistManager::SaveWithUI(int id, const QString& suggested_filename) { @@ -230,10 +234,23 @@ void PlaylistManager::SaveWithUI(int id, const QString& suggested_filename) { return; } + QSettings s; + s.beginGroup(Playlist::kSettingsGroup); + int p = s.value(Playlist::kPathType, Playlist::Path_Automatic).toInt(); + Playlist::Path path = static_cast(p); + if (path == Playlist::Path_Ask_User) { + PlaylistSaveOptionsDialog optionsDialog(nullptr); + optionsDialog.setModal(true); + if (optionsDialog.exec() != QDialog::Accepted) { + return; + } + path = optionsDialog.path_type(); + } + settings.setValue("last_save_playlist", filename); settings.endGroup(); - Save(id == -1 ? current_id() : id, filename); + Save(id == -1 ? current_id() : id, filename, path); } void PlaylistManager::Rename(int id, const QString& new_name) { diff --git a/src/playlist/playlistmanager.h b/src/playlist/playlistmanager.h index f516c3dc8..6f33bbb6f 100644 --- a/src/playlist/playlistmanager.h +++ b/src/playlist/playlistmanager.h @@ -76,7 +76,7 @@ class PlaylistManagerInterface : public QObject { virtual void New(const QString& name, const SongList& songs = SongList(), const QString& special_type = QString()) = 0; virtual void Load(const QString& filename) = 0; - virtual void Save(int id, const QString& filename) = 0; + virtual void Save(int id, const QString& filename, Playlist::Path path_type) = 0; virtual void Rename(int id, const QString& new_name) = 0; virtual void Delete(int id) = 0; virtual bool Close(int id) = 0; @@ -181,7 +181,7 @@ class PlaylistManager : public PlaylistManagerInterface { void New(const QString& name, const SongList& songs = SongList(), const QString& special_type = QString()); void Load(const QString& filename); - void Save(int id, const QString& filename); + void Save(int id, const QString& filename, Playlist::Path path_type); // Display a file dialog to let user choose a file before saving the file void SaveWithUI(int id, const QString& suggested_filename); void Rename(int id, const QString& new_name); @@ -232,7 +232,8 @@ class PlaylistManager : public PlaylistManagerInterface { void UpdateSummaryText(); void SongsDiscovered(const SongList& songs); void ItemsLoadedForSavePlaylist(QFutureWatcher* watcher, - const QString& filename); + const QString& filename, + Playlist::Path path_type); private: Playlist* AddPlaylist(int id, const QString& name, diff --git a/src/playlist/playlistsaveoptionsdialog.cpp b/src/playlist/playlistsaveoptionsdialog.cpp index 44d0f9538..48bda0859 100644 --- a/src/playlist/playlistsaveoptionsdialog.cpp +++ b/src/playlist/playlistsaveoptionsdialog.cpp @@ -1,5 +1,5 @@ /* This file is part of Clementine. - Copyright 2010, David Sansome + Copyright 2014, David Sansome Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,44 +29,24 @@ PlaylistSaveOptionsDialog::PlaylistSaveOptionsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::PlaylistSaveOptionsDialog) { ui->setupUi(this); - ui->filePaths->addItem(tr("Automatic"), PlaylistSaveOptions::Paths_Automatic); - ui->filePaths->addItem(tr("Relative"), PlaylistSaveOptions::Paths_Relative); - ui->filePaths->addItem(tr("Absolute"), PlaylistSaveOptions::Paths_Absolute); - - ui->pathSeparators->addItem(tr("Automatic"), - PlaylistSaveOptions::Separators_Automatic); - ui->pathSeparators->addItem(tr("Windows-style") + " (\\)", - PlaylistSaveOptions::Separators_Windows); - ui->pathSeparators->addItem(tr("Unix-style") + " (/)", - PlaylistSaveOptions::Separators_Unix); - - QSettings s; - s.beginGroup(kSettingsGroup); - ui->filePaths->setCurrentIndex(ui->filePaths->findData( - s.value("file_paths", PlaylistSaveOptions::Paths_Automatic))); - ui->pathSeparators->setCurrentIndex(ui->pathSeparators->findData( - s.value("path_separators", PlaylistSaveOptions::Separators_Automatic))); + ui->filePaths->addItem(tr("Automatic"), Playlist::Path_Automatic); + ui->filePaths->addItem(tr("Relative"), Playlist::Path_Relative); + ui->filePaths->addItem(tr("Absolute"), Playlist::Path_Absolute); } PlaylistSaveOptionsDialog::~PlaylistSaveOptionsDialog() { delete ui; } void PlaylistSaveOptionsDialog::accept() { - QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("file_paths", - ui->filePaths->itemData(ui->filePaths->currentIndex()).toInt()); - s.setValue( - "path_separators", - ui->pathSeparators->itemData(ui->pathSeparators->currentIndex()).toInt()); + if (ui->remember_user_choice->isChecked()) { + QSettings s; + s.beginGroup(Playlist::kSettingsGroup); + s.setValue(Playlist::kPathType, + ui->filePaths->itemData(ui->filePaths->currentIndex()).toInt()); + } QDialog::accept(); } -PlaylistSaveOptions PlaylistSaveOptionsDialog::options() const { - PlaylistSaveOptions o; - o.filePathStyle = static_cast( - ui->filePaths->itemData(ui->filePaths->currentIndex()).toInt()); - o.pathSeparatorStyle = static_cast( - ui->pathSeparators->itemData(ui->pathSeparators->currentIndex()).toInt()); - return o; +Playlist::Path PlaylistSaveOptionsDialog::path_type() const { + return static_cast(ui->filePaths->itemData(ui->filePaths->currentIndex()).toInt()); } diff --git a/src/playlist/playlistsaveoptionsdialog.h b/src/playlist/playlistsaveoptionsdialog.h index 4e54d64c8..6c9db8caf 100644 --- a/src/playlist/playlistsaveoptionsdialog.h +++ b/src/playlist/playlistsaveoptionsdialog.h @@ -1,5 +1,5 @@ /* This file is part of Clementine. - Copyright 2010, David Sansome + Copyright 2014, David Sansome Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,7 +20,7 @@ #include -struct PlaylistSaveOptions; +#include "playlist.h" namespace Ui { class PlaylistSaveOptionsDialog; @@ -34,7 +34,7 @@ class PlaylistSaveOptionsDialog : public QDialog { ~PlaylistSaveOptionsDialog(); void accept(); - PlaylistSaveOptions options() const; + Playlist::Path path_type() const; private: static const char* kSettingsGroup; diff --git a/src/playlist/playlistsaveoptionsdialog.ui b/src/playlist/playlistsaveoptionsdialog.ui index f95837253..c2e004b41 100644 --- a/src/playlist/playlistsaveoptionsdialog.ui +++ b/src/playlist/playlistsaveoptionsdialog.ui @@ -7,7 +7,7 @@ 0 0 348 - 114 + 116 @@ -15,7 +15,7 @@ - + @@ -23,18 +23,25 @@ - - - - Path separators - - - - - + + + + + + 0 + + + + + This can be changed later through the preferences + + + Remember my choice + + diff --git a/src/playlistparsers/asxiniparser.cpp b/src/playlistparsers/asxiniparser.cpp index 343ae1310..79b5b4a4c 100644 --- a/src/playlistparsers/asxiniparser.cpp +++ b/src/playlistparsers/asxiniparser.cpp @@ -50,13 +50,14 @@ SongList AsxIniParser::Load(QIODevice* device, const QString& playlist_path, } void AsxIniParser::Save(const SongList& songs, QIODevice* device, - const QDir& dir) const { + const QDir& dir, + Playlist::Path path_type) const { QTextStream s(device); s << "[Reference]" << endl; int n = 1; for (const Song& song : songs) { - s << "Ref" << n << "=" << URLOrRelativeFilename(song.url(), dir) << endl; + s << "Ref" << n << "=" << URLOrFilename(song.url(), dir, path_type) << endl; ++n; } } diff --git a/src/playlistparsers/asxiniparser.h b/src/playlistparsers/asxiniparser.h index cb15e52ef..d8736ac1e 100644 --- a/src/playlistparsers/asxiniparser.h +++ b/src/playlistparsers/asxiniparser.h @@ -34,7 +34,8 @@ class AsxIniParser : public ParserBase { SongList Load(QIODevice* device, const QString& playlist_path = "", const QDir& dir = QDir()) const; void Save(const SongList& songs, QIODevice* device, - const QDir& dir = QDir()) const; + const QDir& dir = QDir(), + Playlist::Path path_type = Playlist::Path_Automatic) const; }; #endif // ASXINIPARSER_H diff --git a/src/playlistparsers/asxparser.cpp b/src/playlistparsers/asxparser.cpp index eb99e2082..4223c06df 100644 --- a/src/playlistparsers/asxparser.cpp +++ b/src/playlistparsers/asxparser.cpp @@ -118,7 +118,7 @@ return_song: } void ASXParser::Save(const SongList& songs, QIODevice* device, - const QDir&) const { + const QDir&, Playlist::Path path_type) const { QXmlStreamWriter writer(device); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(2); diff --git a/src/playlistparsers/asxparser.h b/src/playlistparsers/asxparser.h index 681eab17a..c46a27c4a 100644 --- a/src/playlistparsers/asxparser.h +++ b/src/playlistparsers/asxparser.h @@ -34,7 +34,8 @@ class ASXParser : public XMLParser { SongList Load(QIODevice* device, const QString& playlist_path = "", const QDir& dir = QDir()) const; void Save(const SongList& songs, QIODevice* device, - const QDir& dir = QDir()) const; + const QDir& dir = QDir(), + Playlist::Path path_type = Playlist::Path_Automatic) const; private: Song ParseTrack(QXmlStreamReader* reader, const QDir& dir) const; diff --git a/src/playlistparsers/cueparser.cpp b/src/playlistparsers/cueparser.cpp index da861a381..00d1401e3 100644 --- a/src/playlistparsers/cueparser.cpp +++ b/src/playlistparsers/cueparser.cpp @@ -352,7 +352,8 @@ qint64 CueParser::IndexToMarker(const QString& index) const { } void CueParser::Save(const SongList& songs, QIODevice* device, - const QDir& dir) const { + const QDir& dir, + Playlist::Path path_type) const { // TODO } diff --git a/src/playlistparsers/cueparser.h b/src/playlistparsers/cueparser.h index 0f07b0b11..13ca9d067 100644 --- a/src/playlistparsers/cueparser.h +++ b/src/playlistparsers/cueparser.h @@ -54,7 +54,8 @@ class CueParser : public ParserBase { SongList Load(QIODevice* device, const QString& playlist_path = "", const QDir& dir = QDir()) const; void Save(const SongList& songs, QIODevice* device, - const QDir& dir = QDir()) const; + const QDir& dir = QDir(), + Playlist::Path path_type = Playlist::Path_Automatic) const; private: // A single TRACK entry in .cue file. diff --git a/src/playlistparsers/m3uparser.cpp b/src/playlistparsers/m3uparser.cpp index 1b7087119..6f6874982 100644 --- a/src/playlistparsers/m3uparser.cpp +++ b/src/playlistparsers/m3uparser.cpp @@ -105,7 +105,8 @@ bool M3UParser::ParseMetadata(const QString& line, } void M3UParser::Save(const SongList& songs, QIODevice* device, - const QDir& dir) const { + const QDir& dir, + Playlist::Path path_type) const { device->write("#EXTM3U\n"); QSettings s; @@ -124,7 +125,7 @@ void M3UParser::Save(const SongList& songs, QIODevice* device, .arg(song.title()); device->write(meta.toUtf8()); } - device->write(URLOrRelativeFilename(song.url(), dir).toUtf8()); + device->write(URLOrFilename(song.url(), dir, path_type).toUtf8()); device->write("\n"); } } diff --git a/src/playlistparsers/m3uparser.h b/src/playlistparsers/m3uparser.h index 431e5728b..c8695e5bd 100644 --- a/src/playlistparsers/m3uparser.h +++ b/src/playlistparsers/m3uparser.h @@ -42,7 +42,8 @@ class M3UParser : public ParserBase { SongList Load(QIODevice* device, const QString& playlist_path = "", const QDir& dir = QDir()) const; void Save(const SongList& songs, QIODevice* device, - const QDir& dir = QDir()) const; + const QDir& dir = QDir(), + Playlist::Path path_type = Playlist::Path_Automatic) const; private: enum M3UType { diff --git a/src/playlistparsers/parserbase.cpp b/src/playlistparsers/parserbase.cpp index d095ea2d5..2a3b7dab2 100644 --- a/src/playlistparsers/parserbase.cpp +++ b/src/playlistparsers/parserbase.cpp @@ -86,22 +86,17 @@ Song ParserBase::LoadSong(const QString& filename_or_url, qint64 beginning, return song; } -QString ParserBase::URLOrRelativeFilename(const QUrl& url, - const QDir& dir) const { +QString ParserBase::URLOrFilename(const QUrl& url, + const QDir& dir, + Playlist::Path path_type) const { if (url.scheme() != "file") return url.toString(); - QSettings s; - s.beginGroup(Playlist::kSettingsGroup); - int p = s.value(Playlist::kPathType, Playlist::Path_Automatic).toInt(); - const Playlist::Path path = static_cast(p); - s.endGroup(); - const QString filename = url.toLocalFile(); - if (path != Playlist::Path_Absolute && QDir::isAbsolutePath(filename)) { + if (path_type != Playlist::Path_Absolute && QDir::isAbsolutePath(filename)) { const QString relative = dir.relativeFilePath(filename); - if (!relative.startsWith("../") || path == Playlist::Path_Relative) + if (!relative.startsWith("../") || path_type == Playlist::Path_Relative) return relative; } return filename; diff --git a/src/playlistparsers/parserbase.h b/src/playlistparsers/parserbase.h index 9b01dd546..d12feece4 100644 --- a/src/playlistparsers/parserbase.h +++ b/src/playlistparsers/parserbase.h @@ -22,6 +22,7 @@ #include #include "core/song.h" +#include "playlist/playlist.h" class LibraryBackendInterface; @@ -51,7 +52,8 @@ class ParserBase : public QObject { virtual SongList Load(QIODevice* device, const QString& playlist_path = "", const QDir& dir = QDir()) const = 0; virtual void Save(const SongList& songs, QIODevice* device, - const QDir& dir = QDir()) const = 0; + const QDir& dir = QDir(), + Playlist::Path path_type = Playlist::Path_Automatic) const = 0; protected: // Loads a song. If filename_or_url is a URL (with a scheme other than @@ -65,10 +67,12 @@ class ParserBase : public QObject { void LoadSong(const QString& filename_or_url, qint64 beginning, const QDir& dir, Song* song) const; - // If the URL is a file:// URL then returns its path relative to the - // directory. Otherwise returns the URL as is. + // If the URL is a file:// URL then returns its path, absolute or relative to + // the directory depending on the path_type option. + // Otherwise returns the URL as is. // This function should always be used when saving a playlist. - QString URLOrRelativeFilename(const QUrl& url, const QDir& dir) const; + QString URLOrFilename(const QUrl& url, const QDir& dir, + Playlist::Path path_type) const; private: LibraryBackendInterface* library_; diff --git a/src/playlistparsers/playlistparser.cpp b/src/playlistparsers/playlistparser.cpp index 77d4573f7..9079eace8 100644 --- a/src/playlistparsers/playlistparser.cpp +++ b/src/playlistparsers/playlistparser.cpp @@ -131,7 +131,8 @@ SongList PlaylistParser::LoadFromDevice(QIODevice* device, } void PlaylistParser::Save(const SongList& songs, - const QString& filename) const { + const QString& filename, + Playlist::Path path_type) const { QFileInfo info(filename); // Find a parser that supports this file extension @@ -145,5 +146,5 @@ void PlaylistParser::Save(const SongList& songs, QFile file(filename); file.open(QIODevice::WriteOnly); - return parser->Save(songs, &file, info.absolutePath()); + return parser->Save(songs, &file, info.absolutePath(), path_type); } diff --git a/src/playlistparsers/playlistparser.h b/src/playlistparsers/playlistparser.h index 455afb087..d25eb7e59 100644 --- a/src/playlistparsers/playlistparser.h +++ b/src/playlistparsers/playlistparser.h @@ -22,6 +22,7 @@ #include #include "core/song.h" +#include "playlist/playlist.h" class ParserBase; class LibraryBackendInterface; @@ -48,7 +49,7 @@ class PlaylistParser : public QObject { SongList LoadFromDevice(QIODevice* device, const QString& path_hint = QString(), const QDir& dir_hint = QDir()) const; - void Save(const SongList& songs, const QString& filename) const; + void Save(const SongList& songs, const QString& filename, Playlist::Path) const; private: QString FilterForParser(const ParserBase* parser, diff --git a/src/playlistparsers/plsparser.cpp b/src/playlistparsers/plsparser.cpp index f5eb2ce4c..9edce3061 100644 --- a/src/playlistparsers/plsparser.cpp +++ b/src/playlistparsers/plsparser.cpp @@ -62,7 +62,7 @@ SongList PLSParser::Load(QIODevice* device, const QString& playlist_path, } void PLSParser::Save(const SongList& songs, QIODevice* device, - const QDir& dir) const { + const QDir& dir, Playlist::Path path_type) const { QTextStream s(device); s << "[playlist]" << endl; s << "Version=2" << endl; @@ -70,7 +70,7 @@ void PLSParser::Save(const SongList& songs, QIODevice* device, int n = 1; for (const Song& song : songs) { - s << "File" << n << "=" << URLOrRelativeFilename(song.url(), dir) << endl; + s << "File" << n << "=" << URLOrFilename(song.url(), dir, path_type) << endl; s << "Title" << n << "=" << song.title() << endl; s << "Length" << n << "=" << song.length_nanosec() / kNsecPerSec << endl; ++n; diff --git a/src/playlistparsers/plsparser.h b/src/playlistparsers/plsparser.h index 4fc10b6aa..3bc57a9e8 100644 --- a/src/playlistparsers/plsparser.h +++ b/src/playlistparsers/plsparser.h @@ -34,7 +34,8 @@ class PLSParser : public ParserBase { SongList Load(QIODevice* device, const QString& playlist_path = "", const QDir& dir = QDir()) const; void Save(const SongList& songs, QIODevice* device, - const QDir& dir = QDir()) const; + const QDir& dir = QDir(), + Playlist::Path path_type = Playlist::Path_Automatic) const; }; #endif // PLSPARSER_H diff --git a/src/playlistparsers/wplparser.cpp b/src/playlistparsers/wplparser.cpp index d4b9ea351..0dc022f35 100644 --- a/src/playlistparsers/wplparser.cpp +++ b/src/playlistparsers/wplparser.cpp @@ -77,7 +77,7 @@ void WplParser::ParseSeq(const QDir& dir, QXmlStreamReader* reader, } void WplParser::Save(const SongList& songs, QIODevice* device, - const QDir& dir) const { + const QDir& dir, Playlist::Path path_type) const { QXmlStreamWriter writer(device); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(2); @@ -98,7 +98,7 @@ void WplParser::Save(const SongList& songs, QIODevice* device, StreamElement seq("seq", &writer); for (const Song& song : songs) { writer.writeStartElement("media"); - writer.writeAttribute("src", URLOrRelativeFilename(song.url(), dir)); + writer.writeAttribute("src", URLOrFilename(song.url(), dir, path_type)); writer.writeEndElement(); } } diff --git a/src/playlistparsers/wplparser.h b/src/playlistparsers/wplparser.h index 2b0bd3ec1..cf295f277 100644 --- a/src/playlistparsers/wplparser.h +++ b/src/playlistparsers/wplparser.h @@ -32,7 +32,8 @@ class WplParser : public XMLParser { SongList Load(QIODevice* device, const QString& playlist_path, const QDir& dir) const; - void Save(const SongList& songs, QIODevice* device, const QDir& dir) const; + void Save(const SongList& songs, QIODevice* device, const QDir& dir, + Playlist::Path path_type = Playlist::Path_Automatic) const; private: void ParseSeq(const QDir& dir, QXmlStreamReader* reader, diff --git a/src/playlistparsers/xspfparser.cpp b/src/playlistparsers/xspfparser.cpp index 7713aacf4..7f452684c 100644 --- a/src/playlistparsers/xspfparser.cpp +++ b/src/playlistparsers/xspfparser.cpp @@ -103,7 +103,7 @@ return_song: } void XSPFParser::Save(const SongList& songs, QIODevice* device, - const QDir& dir) const { + const QDir& dir, Playlist::Path path_type) const { QFileInfo file; QXmlStreamWriter writer(device); writer.setAutoFormatting(true); @@ -120,7 +120,7 @@ void XSPFParser::Save(const SongList& songs, QIODevice* device, StreamElement tracklist("trackList", &writer); for (const Song& song : songs) { - QString filename_or_url = URLOrRelativeFilename(song.url(), dir).toUtf8(); + QString filename_or_url = URLOrFilename(song.url(), dir, path_type).toUtf8(); StreamElement track("track", &writer); writer.writeTextElement("location", filename_or_url); @@ -154,7 +154,7 @@ void XSPFParser::Save(const SongList& songs, QIODevice* device, // playlist. QUrl url = QUrl(art_filename); url.setScheme("file"); // Need to explicitly set this. - art_filename = URLOrRelativeFilename(url, dir).toUtf8(); + art_filename = URLOrFilename(url, dir, path_type).toUtf8(); } else { // Just use whatever URL was in the Song. art_filename = art; diff --git a/src/playlistparsers/xspfparser.h b/src/playlistparsers/xspfparser.h index 0102c1288..fc7d1fb70 100644 --- a/src/playlistparsers/xspfparser.h +++ b/src/playlistparsers/xspfparser.h @@ -39,7 +39,8 @@ class XSPFParser : public XMLParser { SongList Load(QIODevice* device, const QString& playlist_path = "", const QDir& dir = QDir()) const; void Save(const SongList& songs, QIODevice* device, - const QDir& dir = QDir()) const; + const QDir& dir = QDir(), + Playlist::Path path_type = Playlist::Path_Automatic) const; private: Song ParseTrack(QXmlStreamReader* reader, const QDir& dir) const; diff --git a/src/ui/behavioursettingspage.cpp b/src/ui/behavioursettingspage.cpp index 48b49ac02..857d63c66 100644 --- a/src/ui/behavioursettingspage.cpp +++ b/src/ui/behavioursettingspage.cpp @@ -146,6 +146,8 @@ void BehaviourSettingsPage::Load() { case Playlist::Path_Relative: ui_->b_relative_path->setChecked(true); break; + case Playlist::Path_Ask_User: + ui_->b_ask_path->setChecked(true); } ui_->b_write_metadata->setChecked( s.value(Playlist::kWriteMetadata, true).toBool()); @@ -185,6 +187,8 @@ void BehaviourSettingsPage::Save() { path = Playlist::Path_Absolute; } else if (ui_->b_relative_path->isChecked()) { path = Playlist::Path_Relative; + } else if (ui_->b_ask_path->isChecked()) { + path = Playlist::Path_Ask_User; } s.beginGroup(MainWindow::kSettingsGroup); diff --git a/src/ui/behavioursettingspage.ui b/src/ui/behavioursettingspage.ui index a875bcfdd..ed4596058 100644 --- a/src/ui/behavioursettingspage.ui +++ b/src/ui/behavioursettingspage.ui @@ -265,6 +265,13 @@ + + + + Ask when saving + + +