From 9d2bcbcb986becf01d9ec4ed1bfc4e3a9205ea2a Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Mon, 14 Oct 2013 18:17:34 +0000 Subject: [PATCH] USe native dir separators for display --- ChangeLog | 7 +++---- devices/devicepropertieswidget.cpp | 8 ++++---- devices/devicepropertieswidget.h | 3 ++- gui/serversettings.cpp | 8 ++++---- online/podcastsettingsdialog.cpp | 4 ++-- support/utils.cpp | 18 ++++++++++++++++-- support/utils.h | 4 ++++ 7 files changed, 35 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74863538a..f7b93648a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -73,10 +73,9 @@ 39. Also read Jamendo genre's from album tag. 40. Modify message-widget so that it uses a squeezed-text label. Because of this, always use Cantata's copy of KMessageWidget for all KDE builds. -41. No longer compile Windows versions against TagLib. Seems like the tag - editor, track organiser, and HTTP server are not really working for windows - builds - and I have neither the time nor enthusiasm to determine why. -42. Cantata requires libMTP 1.1.0 or newer. +41. Cantata requires libMTP 1.1.0 or newer. +42. When diplaying paths, convert to native separators, and remove trailing + separator. When reading back entry, revert this process. 1.1.3 ----- diff --git a/devices/devicepropertieswidget.cpp b/devices/devicepropertieswidget.cpp index 71e1f6b85..f638dea4a 100644 --- a/devices/devicepropertieswidget.cpp +++ b/devices/devicepropertieswidget.cpp @@ -133,7 +133,7 @@ void DevicePropertiesWidget::update(const QString &path, const DeviceOptions &op origOpts=opts; if (props&Prop_Folder) { - musicFolder->setText(path); + musicFolder->setText(Utils::convertDirForDisplay(path)); connect(musicFolder, SIGNAL(textChanged(const QString &)), this, SLOT(checkSaveable())); } else { REMOVE(musicFolder); @@ -269,7 +269,7 @@ void DevicePropertiesWidget::update(const QString &path, const DeviceOptions &op connect(defaultVolume,SIGNAL(currentIndexChanged(int)), this, SLOT(checkSaveable())); } - origMusicFolder=path; + origMusicFolder=Utils::fixPath(path); connect(configFilename, SIGNAL(clicked()), SLOT(configureFilenameScheme())); connect(filenameScheme, SIGNAL(textChanged(const QString &)), this, SLOT(checkSaveable())); connect(vfatSafe, SIGNAL(stateChanged(int)), this, SLOT(checkSaveable())); @@ -326,9 +326,9 @@ void DevicePropertiesWidget::checkSaveable() modified=opts!=origOpts; if (!modified && checkFolder) { - modified=musicFolder->text().trimmed()!=origMusicFolder; + modified=music()!=origMusicFolder; } - saveable=!opts.scheme.isEmpty() && (!checkFolder || !musicFolder->text().trimmed().isEmpty()) && !opts.coverName.isEmpty(); + saveable=!opts.scheme.isEmpty() && (!checkFolder || !music().isEmpty()) && !opts.coverName.isEmpty(); if (saveable && ( (-1!=opts.coverName.indexOf(noCoverText) && opts.coverName!=noCoverText) || (-1!=opts.coverName.indexOf(embedCoverText) && opts.coverName!=embedCoverText) ) ) { diff --git a/devices/devicepropertieswidget.h b/devices/devicepropertieswidget.h index ee5dde2fa..5cd9e9702 100644 --- a/devices/devicepropertieswidget.h +++ b/devices/devicepropertieswidget.h @@ -26,6 +26,7 @@ #include "ui_devicepropertieswidget.h" #include "device.h" +#include "utils.h" class FilenameSchemeDialog; class DevicePropertiesWidget : public QWidget, Ui::DevicePropertiesWidget @@ -54,7 +55,7 @@ public: DeviceOptions settings(); bool isModified() const { return modified; } bool isSaveable() const { return saveable; } - QString music() const { return musicFolder ? musicFolder->text().trimmed() : origMusicFolder; } + QString music() const { return musicFolder ? Utils::convertDirFromDisplay(musicFolder->text()) : origMusicFolder; } QString cover() const; void showRemoteConnectionNote(bool v) { remoteDeviceNote->setVisible(v); } diff --git a/gui/serversettings.cpp b/gui/serversettings.cpp index ec7d4a9a8..94e3e5de6 100644 --- a/gui/serversettings.cpp +++ b/gui/serversettings.cpp @@ -345,7 +345,7 @@ QString ServerSettings::generateName(int ignore) const void ServerSettings::setDetails(const MPDConnectionDetails &details) { if (details.name==MPDUser::constName) { - basicDir->setText(QDir::toNativeSeparators(details.dir)); + basicDir->setText(Utils::convertDirForDisplay(details.dir)); basicCoverName->setText(details.coverName); stackedWidget->setCurrentIndex(1); } else { @@ -353,7 +353,7 @@ void ServerSettings::setDetails(const MPDConnectionDetails &details) host->setText(details.hostname); port->setValue(details.port); password->setText(details.password); - dir->setText(QDir::toNativeSeparators(details.dir)); + dir->setText(Utils::convertDirForDisplay(details.dir)); dynamizerPort->setValue(details.dynamizerPort); coverName->setText(details.coverName); #ifdef ENABLE_HTTP_STREAM_PLAYBACK @@ -374,7 +374,7 @@ MPDConnectionDetails ServerSettings::getDetails() const details.hostname=host->text().trimmed(); details.port=port->value(); details.password=password->text(); - details.dir=Utils::fixPath(QDir::fromNativeSeparators(dir->text().trimmed())); + details.dir=Utils::convertDirFromDisplay(dir->text()); details.dynamizerPort=dynamizerPort->value(); details.coverName=coverName->text().trimmed(); #ifdef ENABLE_HTTP_STREAM_PLAYBACK @@ -382,7 +382,7 @@ MPDConnectionDetails ServerSettings::getDetails() const #endif } else { details=MPDUser::self()->details(true); - details.dir=Utils::fixPath(QDir::fromNativeSeparators(basicDir->text().trimmed())); + details.dir=Utils::convertDirFromDisplay(basicDir->text()); details.coverName=basicCoverName->text().trimmed(); MPDUser::self()->setMusicFolder(details.dir); } diff --git a/online/podcastsettingsdialog.cpp b/online/podcastsettingsdialog.cpp index a87740cb7..c8728ba9b 100644 --- a/online/podcastsettingsdialog.cpp +++ b/online/podcastsettingsdialog.cpp @@ -100,7 +100,7 @@ PodcastSettingsDialog::PodcastSettingsDialog(QWidget *p) setIndex(updateCombo, origRssUpdate); connect(updateCombo, SIGNAL(currentIndexChanged(int)), SLOT(checkSaveable())); #ifdef TAGLIB_FOUND - origPodcastDownloadPath=QDir::toNativeSeparators(Settings::self()->podcastDownloadPath()); + origPodcastDownloadPath=Utils::convertDirForDisplay(Settings::self()->podcastDownloadPath()); origPodcastAutoDownload=Settings::self()->podcastAutoDownload(); downloadPath->setText(origPodcastDownloadPath); autoDownload->setChecked(origPodcastAutoDownload); @@ -133,7 +133,7 @@ void PodcastSettingsDialog::slotButtonClicked(int button) #ifdef TAGLIB_FOUND if (downloadPath->text().trimmed()!=origPodcastDownloadPath) { changed|=DownloadPath; - Settings::self()->savePodcastDownloadPath(Utils::fixPath(QDir::fromNativeSeparators(downloadPath->text().trimmed()))); + Settings::self()->savePodcastDownloadPath(Utils::convertDirFromDisplay(downloadPath->text().trimmed())); } if (origPodcastAutoDownload!=autoDownload->isChecked()) { changed|=AutoDownload; diff --git a/support/utils.cpp b/support/utils.cpp index 67c33d2fc..3f0a08250 100644 --- a/support/utils.cpp +++ b/support/utils.cpp @@ -100,11 +100,25 @@ QString Utils::fixPath(const QString &dir) } d.replace(QLatin1String("/./"), constDirSepStr); if (!d.isEmpty() && !d.endsWith(constDirSep)) { - d+="/"; + d+=constDirSep; } return d; } +QString Utils::convertDirForDisplay(const QString &dir) +{ + QString d(dir); + if (d.endsWith(constDirSep)) { + d=d.left(d.length()-1); + } + return QDir::toNativeSeparators(d); +} + +QString Utils::convertDirFromDisplay(const QString &dir) +{ + return fixPath(QDir::fromNativeSeparators(dir.trimmed())); +} + QString Utils::getDir(const QString &file) { QString d(file); @@ -241,7 +255,7 @@ bool Utils::createDir(const QString &dir, const QString &base, const char *group QString d(base); foreach (const QString &p, parts) { - d+='/'+p; + d+=constDirSep+p; int rv=::chown(QFile::encodeName(d).constData(), geteuid(), gid); Q_UNUSED(rv); } diff --git a/support/utils.h b/support/utils.h index 01dc7276f..1ead42a44 100644 --- a/support/utils.h +++ b/support/utils.h @@ -53,6 +53,10 @@ namespace Utils extern QString strippedText(QString s); extern QString stripAcceleratorMarkers(QString label); extern QString fixPath(const QString &d); + // Convert directory to a format suitable fo rUI - e.g. use native separators, and remove any traling separator + extern QString convertDirForDisplay(const QString &dir); + // Convert directory from a UI field - convert to / separators, and add a trailing separator + extern QString convertDirFromDisplay(const QString &dir); extern QString getDir(const QString &file); extern QString getFile(const QString &file); extern QString changeExtension(const QString &file, const QString &extension);