Skip to content
Snippets Groups Projects
Commit 4c40b3a8 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Accept full filename for configuration files

parent d964298c
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,12 @@ namespace gepetto { ...@@ -43,6 +43,12 @@ namespace gepetto {
/// and GEPETTO_GUI_SETTINGS_DIR are read. /// and GEPETTO_GUI_SETTINGS_DIR are read.
void setupPaths () const; void setupPaths () const;
/// Return the directory into which configuration file are.
QDir getConfigPath () const;
/// Get the filename of a configuration file.
QString getQSettingsFileName (const std::string& settingsName) const;
/// Update values accordingly with command arguments /// Update values accordingly with command arguments
int fromArgv (int argc, char* argv[]); int fromArgv (int argc, char* argv[]);
......
...@@ -208,11 +208,27 @@ namespace gepetto { ...@@ -208,11 +208,27 @@ namespace gepetto {
; ;
} }
QDir Settings::getConfigPath () const
{
QDir d (installDirectory);
d.cd ("etc");
d.cd (QCoreApplication::organizationName());
return d;
}
QString Settings::getQSettingsFileName (const std::string& settingsName) const
{
QString name (QString::fromStdString (settingsName));
QString ext (".conf");
QDir dir (getConfigPath());
if (dir.exists(name + ext) || !dir.exists(name))
return dir.absoluteFilePath(name + ext);
return dir.absoluteFilePath(name);
}
void Settings::readRobotFile () void Settings::readRobotFile ()
{ {
QSettings robot (QSettings::SystemScope, QSettings robot (getQSettingsFileName (predifinedRobotConf));
QCoreApplication::organizationName(),
QString::fromStdString(predifinedRobotConf));
if (robot.status() != QSettings::NoError) { if (robot.status() != QSettings::NoError) {
logError(QString ("Enable to open configuration file ") logError(QString ("Enable to open configuration file ")
+ robot.fileName()); + robot.fileName());
...@@ -238,9 +254,7 @@ namespace gepetto { ...@@ -238,9 +254,7 @@ namespace gepetto {
void Settings::readEnvFile () void Settings::readEnvFile ()
{ {
QSettings env (QSettings::SystemScope, QSettings env (getQSettingsFileName (predifinedEnvConf));
QCoreApplication::organizationName(),
QString::fromStdString(predifinedEnvConf));
if (env.status() != QSettings::NoError) { if (env.status() != QSettings::NoError) {
logError(QString ("Enable to open configuration file ") + env.fileName()); logError(QString ("Enable to open configuration file ") + env.fileName());
} else { } else {
...@@ -263,9 +277,7 @@ namespace gepetto { ...@@ -263,9 +277,7 @@ namespace gepetto {
void Settings::readSettingFile () void Settings::readSettingFile ()
{ {
QSettings env (QSettings::SystemScope, QSettings env (getQSettingsFileName (configurationFile));
QCoreApplication::organizationName(),
QString::fromStdString(configurationFile));
if (env.status() != QSettings::NoError) { if (env.status() != QSettings::NoError) {
logError(QString ("Enable to open configuration file ") + env.fileName()); logError(QString ("Enable to open configuration file ") + env.fileName());
} else { } else {
...@@ -285,9 +297,7 @@ namespace gepetto { ...@@ -285,9 +297,7 @@ namespace gepetto {
void Settings::writeRobotFile () void Settings::writeRobotFile ()
{ {
QSettings robot (QSettings::SystemScope, QSettings robot (getQSettingsFileName (predifinedRobotConf));
QCoreApplication::organizationName(),
QString::fromStdString(predifinedRobotConf));
if (!robot.isWritable()) { if (!robot.isWritable()) {
log (QString("Configuration file ") + robot.fileName() + QString(" is not writable.")); log (QString("Configuration file ") + robot.fileName() + QString(" is not writable."));
return; return;
...@@ -308,9 +318,7 @@ namespace gepetto { ...@@ -308,9 +318,7 @@ namespace gepetto {
void Settings::writeEnvFile () void Settings::writeEnvFile ()
{ {
QSettings env (QSettings::SystemScope, QSettings env (getQSettingsFileName (predifinedEnvConf));
QCoreApplication::organizationName(),
QString::fromStdString(predifinedEnvConf));
if (!env.isWritable()) { if (!env.isWritable()) {
logError (QString ("Configuration file") + env.fileName() + QString("is not writable.")); logError (QString ("Configuration file") + env.fileName() + QString("is not writable."));
return; return;
...@@ -328,9 +336,7 @@ namespace gepetto { ...@@ -328,9 +336,7 @@ namespace gepetto {
void Settings::writeSettingFile () void Settings::writeSettingFile ()
{ {
QSettings env (QSettings::SystemScope, QSettings env (getQSettingsFileName (configurationFile));
QCoreApplication::organizationName(),
QString::fromStdString(configurationFile));
if (!env.isWritable()) { if (!env.isWritable()) {
logError (QString ("Configuration file") + env.fileName() + QString("is not writable.")); logError (QString ("Configuration file") + env.fileName() + QString("is not writable."));
return; return;
...@@ -351,9 +357,7 @@ namespace gepetto { ...@@ -351,9 +357,7 @@ namespace gepetto {
QVariant Settings::getSetting (const QString & key, QVariant Settings::getSetting (const QString & key,
const QVariant & defaultValue) const QVariant & defaultValue)
{ {
QSettings env (QSettings::SystemScope, QSettings env (getQSettingsFileName (configurationFile));
QCoreApplication::organizationName(),
QString::fromStdString(configurationFile));
if (env.status() == QSettings::NoError) { if (env.status() == QSettings::NoError) {
return env.value (key, defaultValue); return env.value (key, defaultValue);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment