Skip to content

Commit

Permalink
ConfigFile: use QStandardPaths::AppConfigLocation for the config file
Browse files Browse the repository at this point in the history
Also use appName instead of appNameGui in order to compute the path

Issue: #2245

The reason is to respect the XDG spec on Unix (#1601) and might help
on windows roaming profiles (#684)
  • Loading branch information
ogoffart committed Dec 6, 2017
1 parent a46dcef commit 9699b19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
19 changes: 18 additions & 1 deletion src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,27 @@ Application::Application(int &argc, char **argv)
// TODO: Can't set this without breaking current config paths
// setOrganizationName(QLatin1String(APPLICATION_VENDOR));
setOrganizationDomain(QLatin1String(APPLICATION_REV_DOMAIN));
setApplicationName(_theme->appNameGUI());
setApplicationName(_theme->appName());
setWindowIcon(_theme->applicationIcon());
setAttribute(Qt::AA_UseHighDpiPixmaps, true);

auto confDir = ConfigFile().configPath();
if (!QFileInfo(confDir).exists()) {
// Migrate from version <= 2.5
setApplicationName(_theme->appNameGUI());
QString oldDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
setApplicationName(_theme->appName());
if (QFileInfo(oldDir).isDir()) {
qCInfo(lcApplication) << "Migrating old config from" << oldDir << "to" << confDir;
if (!QFile::rename(oldDir, confDir)) {
qCWarning(lcApplication) << "Failed to move the old config file to its new location (" << oldDir << "to" << confDir << ")";
} else {
// Create a symbolic link so a downgrade of the client would still find the config.
QFile::link(confDir, oldDir);
}
}
}

parseOptions(arguments());
//no need to waste time;
if (_helpOnly || _versionOnly)
Expand Down
14 changes: 2 additions & 12 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#ifndef TOKEN_AUTH_ONLY
#include <QWidget>
#include <QHeaderView>
#include <QDesktopServices>
#endif

#include <QCoreApplication>
Expand All @@ -34,6 +33,7 @@
#include <QLoggingCategory>
#include <QSettings>
#include <QNetworkProxy>
#include <QStandardPaths>

#define DEFAULT_REMOTE_POLL_INTERVAL 30000 // default remote poll time in milliseconds
#define DEFAULT_FULL_LOCAL_DISCOVERY_INTERVAL (60 * 60 * 1000) // 1 hour
Expand Down Expand Up @@ -250,26 +250,16 @@ QVariant ConfigFile::getPolicySetting(const QString &setting, const QVariant &de

QString ConfigFile::configPath() const
{
#ifndef TOKEN_AUTH_ONLY
if (_confDir.isEmpty()) {
// Qt 5's QStandardPaths::writableLocation gives us wrong results (without /data/),
// so we'll have to use the deprecated version for now
_confDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
_confDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
}
#endif
QString dir = _confDir;

if (!dir.endsWith(QLatin1Char('/')))
dir.append(QLatin1Char('/'));
return dir;
}

QString ConfigFile::configPathWithAppName() const
{
//HACK
return QFileInfo(configFile()).dir().absolutePath().append("/");
}

static const QLatin1String exclFile("sync-exclude.lst");

QString ConfigFile::excludeFile(Scope scope) const
Expand Down
1 change: 0 additions & 1 deletion src/libsync/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
SystemScope };

QString configPath() const;
QString configPathWithAppName() const;
QString configFile() const;
QString excludeFile(Scope scope) const;
static QString excludeFileFromSystem(); // doesn't access config dir
Expand Down

0 comments on commit 9699b19

Please sign in to comment.