~ / QDir::homePath()
BUG: 538
This commit is contained in:
committed by
craig.p.drummond
parent
64a864380f
commit
9b2ea337fd
@@ -40,6 +40,8 @@
|
||||
overlay scrollbars have been disabled.
|
||||
25. Add note about 'AlbumArtist' tag to initial settings wizard.
|
||||
26. Use QDesktopWidget::logicalDpiX()/96.0 to set DPI scale factor.
|
||||
27. Expand ~/ QDir::homePath() when read from UI.
|
||||
28. Save QDir::homePath()/ as ~ in config file, and convert when read.
|
||||
|
||||
1.4.2
|
||||
-----
|
||||
|
||||
@@ -176,11 +176,7 @@ MPDConnectionDetails Settings::connectionDetails(const QString &name)
|
||||
cfg.beginGroup(n);
|
||||
details.hostname=cfg.get("host", name.isEmpty() ? mpdDefaults.host : QString());
|
||||
details.port=cfg.get("port", name.isEmpty() ? mpdDefaults.port : 6600);
|
||||
#ifdef Q_OS_WIN
|
||||
details.dir=Utils::fixPath(QDir::fromNativeSeparators(cfg.get("dir", name.isEmpty() ? mpdDefaults.dir : "/var/lib/mpd/music")));
|
||||
#else
|
||||
details.dir=Utils::fixPath(cfg.get("dir", name.isEmpty() ? mpdDefaults.dir : "/var/lib/mpd/music"));
|
||||
#endif
|
||||
details.dir=cfg.getPath("dir", name.isEmpty() ? mpdDefaults.dir : "/var/lib/mpd/music");
|
||||
#if defined ENABLE_KDE_SUPPORT && defined ENABLE_KWALLET
|
||||
if (KWallet::Wallet::isEnabled()) {
|
||||
if (cfg.get("passwd", false)) {
|
||||
@@ -448,7 +444,7 @@ int Settings::contextBackdropBlur()
|
||||
|
||||
QString Settings::contextBackdropFile()
|
||||
{
|
||||
return cfg.get("contextBackdropFile", QString());
|
||||
return cfg.getPath("contextBackdropFile", QString());
|
||||
}
|
||||
|
||||
bool Settings::contextDarkBackground()
|
||||
@@ -620,7 +616,7 @@ int Settings::playQueueBackgroundBlur()
|
||||
|
||||
QString Settings::playQueueBackgroundFile()
|
||||
{
|
||||
return cfg.get("playQueueBackgroundFile", QString());
|
||||
return cfg.getPath("playQueueBackgroundFile", QString());
|
||||
}
|
||||
|
||||
bool Settings::playQueueConfirmClear()
|
||||
@@ -874,7 +870,7 @@ void Settings::saveConnectionDetails(const MPDConnectionDetails &v)
|
||||
cfg.beginGroup(n);
|
||||
cfg.set("host", v.hostname);
|
||||
cfg.set("port", (int)v.port);
|
||||
cfg.set("dir", v.dir);
|
||||
cfg.setPath("dir", v.dir);
|
||||
#if defined ENABLE_KDE_SUPPORT && defined ENABLE_KWALLET
|
||||
if (KWallet::Wallet::isEnabled()) {
|
||||
cfg.set("passwd", !v.password.isEmpty());
|
||||
@@ -1070,7 +1066,7 @@ void Settings::saveContextBackdropBlur(int v)
|
||||
|
||||
void Settings::saveContextBackdropFile(const QString &v)
|
||||
{
|
||||
cfg.set("contextBackdropFile", v);
|
||||
cfg.setPath("contextBackdropFile", v);
|
||||
}
|
||||
|
||||
void Settings::saveContextDarkBackground(bool v)
|
||||
@@ -1211,7 +1207,7 @@ void Settings::savePlayQueueBackgroundBlur(int v)
|
||||
|
||||
void Settings::savePlayQueueBackgroundFile(const QString &v)
|
||||
{
|
||||
cfg.set("playQueueBackgroundFile", v);
|
||||
cfg.setPath("playQueueBackgroundFile", v);
|
||||
}
|
||||
|
||||
void Settings::savePlayQueueConfirmClear(bool v)
|
||||
|
||||
@@ -52,6 +52,15 @@ int Configuration::get(const QString &key, int def, int min, int max)
|
||||
return v<min ? min : (v>max ? max : v);
|
||||
}
|
||||
|
||||
QString Configuration::getPath(const QString &key, const QString &def)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return Utils::fixPath(QDir::fromNativeSeparators(get(key, def)));
|
||||
#else
|
||||
return Utils::tildaToHome(Utils::fixPath(get(key, def)));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
void Configuration::beginGroup(const QString &group)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#else
|
||||
#include <QSettings>
|
||||
#endif
|
||||
#include "utils.h"
|
||||
|
||||
class Configuration
|
||||
#ifndef ENABLE_KDE_SUPPORT
|
||||
@@ -97,6 +98,8 @@ public:
|
||||
void removeEntry(const QString &key) { remove(key); }
|
||||
#endif
|
||||
int get(const QString &key, int def, int min, int max);
|
||||
QString getPath(const QString &key, const QString &def);
|
||||
void setPath(const QString &key, const QString &val) { return set(key, Utils::homeToTilda(val)); }
|
||||
|
||||
private:
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
|
||||
@@ -122,6 +122,29 @@ QString Utils::fixPath(const QString &dir)
|
||||
return d;
|
||||
}
|
||||
|
||||
#ifndef Q_OS_WIN
|
||||
static const QLatin1String constTilda("~");
|
||||
QString Utils::homeToTilda(const QString &s)
|
||||
{
|
||||
QString hp=QDir::homePath();
|
||||
if (s==hp) {
|
||||
return constTilda;
|
||||
}
|
||||
if (s.startsWith(hp+constDirSepStr)) {
|
||||
return constTilda+fixPath(s.mid(hp.length()));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
QString Utils::tildaToHome(const QString &s)
|
||||
{
|
||||
if (s==constTilda) {
|
||||
return fixPath(QDir::homePath());
|
||||
}
|
||||
return s.startsWith(constTilda+constDirSep) ? fixPath(QDir::homePath()+constDirSepStr+s.mid(1)) : s;
|
||||
}
|
||||
#endif
|
||||
|
||||
QString Utils::convertDirForDisplay(const QString &dir)
|
||||
{
|
||||
if (dir.isEmpty() || dir.startsWith(constHttp)) {
|
||||
@@ -132,7 +155,8 @@ QString Utils::convertDirForDisplay(const QString &dir)
|
||||
if (d.endsWith(constDirSep)) {
|
||||
d=d.left(d.length()-1);
|
||||
}
|
||||
return QDir::toNativeSeparators(d);
|
||||
d=homeToTilda(QDir::toNativeSeparators(d));
|
||||
return d.endsWith(constDirSep) ? d.left(d.length()-1) : d;
|
||||
}
|
||||
|
||||
QString Utils::convertDirFromDisplay(const QString &dir)
|
||||
@@ -145,7 +169,7 @@ QString Utils::convertDirFromDisplay(const QString &dir)
|
||||
if (d.startsWith(constHttp)) {
|
||||
return fixPath(d);
|
||||
}
|
||||
return fixPath(QDir::fromNativeSeparators(d));
|
||||
return tildaToHome(fixPath(QDir::fromNativeSeparators(d)));
|
||||
}
|
||||
|
||||
QString Utils::getDir(const QString &file)
|
||||
|
||||
@@ -64,6 +64,14 @@ namespace Utils
|
||||
extern QString strippedText(QString s);
|
||||
extern QString stripAcceleratorMarkers(QString label);
|
||||
extern QString fixPath(const QString &d);
|
||||
#ifdef Q_OS_WIN
|
||||
inline QString homeToTilda(const QString &s) { return s; }
|
||||
inline QString tildaToHome(const QString &s) { return s; }
|
||||
#else
|
||||
extern QString homeToTilda(const QString &s);
|
||||
extern QString tildaToHome(const QString &s);
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user