USe native dir separators for display

This commit is contained in:
craig.p.drummond
2013-10-14 18:17:34 +00:00
parent 63d6f37195
commit 9d2bcbcb98
7 changed files with 35 additions and 17 deletions

View File

@@ -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
-----

View File

@@ -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) ) ) {

View File

@@ -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); }

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);