Browse Source

refactor(settings): replace filesystem code with Paths

reviewable/pr6649/r3
sudden6 7 years ago
parent
commit
377dd10a0e
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 59
      src/persistence/settings.cpp

59
src/persistence/settings.cpp

@ -58,7 +58,6 @@ @@ -58,7 +58,6 @@
* @brief Toxme info like name@server
*/
const QString Settings::globalSettingsFile = "qtox.ini";
Settings* Settings::settings{nullptr};
QMutex Settings::bigLock{QMutex::Recursive};
QThread* Settings::settingsThread{nullptr};
@ -113,25 +112,12 @@ void Settings::loadGlobal() @@ -113,25 +112,12 @@ void Settings::loadGlobal()
createSettingsDir();
QString localSettingsPath = qApp->applicationDirPath() + QDir::separator() + globalSettingsFile;
if (QFile(localSettingsPath).exists()) {
QSettings ps(localSettingsPath, QSettings::IniFormat);
ps.setIniCodec("UTF-8");
ps.beginGroup("Advanced");
makeToxPortable = ps.value("makeToxPortable", false).toBool();
ps.endGroup();
} else {
makeToxPortable = false;
}
QDir dir(getSettingsDirPath());
QString filePath = dir.filePath(globalSettingsFile);
QString filePath = paths.getGlobalSettingsPath();
// If no settings file exist -- use the default one
if (!QFile(filePath).exists()) {
qDebug() << "No settings file found, using defaults";
filePath = ":/conf/" + globalSettingsFile;
filePath = ":/conf/qtox.ini";
}
qDebug() << "Loading settings from " + filePath;
@ -334,13 +320,7 @@ void Settings::loadPersonal(Profile* profile) @@ -334,13 +320,7 @@ void Settings::loadPersonal(Profile* profile)
{
QMutexLocker locker{&bigLock};
QDir dir(getSettingsDirPath());
QString filePath = dir.filePath(globalSettingsFile);
// load from a profile specific friend data list if possible
QString tmp = dir.filePath(profile->getName() + ".ini");
if (QFile(tmp).exists()) // otherwise, filePath remains the global file
filePath = tmp;
const QString filePath{paths.getProfilesDir()};
qDebug() << "Loading personal settings from" << filePath;
@ -466,7 +446,7 @@ void Settings::saveGlobal() @@ -466,7 +446,7 @@ void Settings::saveGlobal()
if (!loaded)
return;
QString path = getSettingsDirPath() + globalSettingsFile;
QString path = paths.getGlobalSettingsPath();
qDebug() << "Saving global settings at " + path;
QSettings s(path, QSettings::IniFormat);
@ -739,25 +719,8 @@ uint32_t Settings::makeProfileId(const QString& profile) @@ -739,25 +719,8 @@ uint32_t Settings::makeProfileId(const QString& profile)
QString Settings::getSettingsDirPath() const
{
QMutexLocker locker{&bigLock};
if (makeToxPortable)
return qApp->applicationDirPath() + QDir::separator();
// workaround for https://bugreports.qt-project.org/browse/QTBUG-38845
#ifdef Q_OS_WIN
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
+ QDir::separator() + "AppData" + QDir::separator() + "Roaming"
+ QDir::separator() + "tox")
+ QDir::separator();
#elif defined(Q_OS_OSX)
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
+ QDir::separator() + "Library" + QDir::separator()
+ "Application Support" + QDir::separator() + "Tox")
+ QDir::separator();
#else
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
+ QDir::separator() + "tox")
+ QDir::separator();
#endif
QString settingsFile {paths.getGlobalSettingsPath()};
return QFileInfo{settingsFile}.dir().absolutePath();
}
/**
@ -874,15 +837,7 @@ bool Settings::getMakeToxPortable() const @@ -874,15 +837,7 @@ bool Settings::getMakeToxPortable() const
void Settings::setMakeToxPortable(bool newValue)
{
QMutexLocker locker{&bigLock};
if (newValue != makeToxPortable) {
QFile(getSettingsDirPath() + globalSettingsFile).remove();
makeToxPortable = newValue;
saveGlobal();
emit makeToxPortableChanged(makeToxPortable);
}
// TODO(sudden6): to be removed
}
bool Settings::getAutorun() const

Loading…
Cancel
Save