Servatrice: group all the use of QSettings in a single file

and add a method to guess the path of servatrice.ini
This commit is contained in:
Fabio Bas 2014-10-02 22:37:50 +02:00
parent 277aba79dc
commit a1b6600fe1
7 changed files with 113 additions and 53 deletions

View file

@ -0,0 +1,37 @@
#include "settingscache.h"
#include <QCoreApplication>
#include <QFile>
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
QString SettingsCache::guessConfigurationPath(QString & specificPath)
{
const QString fileName="servatrice.ini";
QString guessFileName;
// specific path
if(!specificPath.isEmpty() && QFile::exists(specificPath))
return specificPath;
// application directory path
guessFileName = QCoreApplication::applicationDirPath() + "/" + fileName;
if(QFile::exists(guessFileName))
return guessFileName;
#ifdef Q_OS_UNIX
// /etc
guessFileName = "/etc/" + fileName;
if(QFile::exists(guessFileName))
return guessFileName;
#endif
#if QT_VERSION >= 0x050000
guessFileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + fileName;
#else
guessFileName = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + fileName;
#endif
return guessFileName;
}