This commit is contained in:
Simon Stürz 2016-02-20 15:17:17 +01:00 committed by Michael Zanetti
parent 0eadc5af47
commit 7ee67da613
3 changed files with 23 additions and 0 deletions

View File

@ -169,6 +169,22 @@ QString GuhSettings::logPath()
return logPath;
}
QString GuhSettings::settingsPath()
{
QString path;
QString organisationName = QCoreApplication::instance()->organizationName();
if (organisationName == "guh-test") {
path = "/tmp/" + organisationName;
} else if (GuhSettings::isRoot()) {
path = "/etc/guh/";
} else {
path = QDir::homePath() + "/.config/" + organisationName;
}
return path;
}
/*! Returns the path where the log file (console log) will be stored. */
QString GuhSettings::consoleLogPath()
{

View File

@ -47,6 +47,7 @@ public:
static bool isRoot();
static QString logPath();
static QString settingsPath();
static QString consoleLogPath();
// forwarded QSettings methods

View File

@ -186,6 +186,12 @@ int main(int argc, char *argv[])
// inform about userid
int userId = getuid();
if (userId != 0) {
// check if config directory for logfile exists
if (!QDir().mkpath(GuhSettings::settingsPath())) {
fprintf(stdout, "Could not create guh settings directory %s", qPrintable(GuhSettings::settingsPath()));
exit(EXIT_FAILURE);
}
qCDebug(dcApplication) << "=====================================";
qCDebug(dcApplication) << "guhd" << GUH_VERSION_STRING << "started with user ID" << userId;
qCDebug(dcApplication) << "=====================================";