From aaf9b95d9787c1634a175bf811da4018a1d5737e Mon Sep 17 00:00:00 2001 From: Matthieu Baerts Date: Sat, 17 Oct 2015 15:53:22 +0200 Subject: [PATCH] Autorun:xdg: create autostart dir if needed After a fresh installation of Ubuntu, 'autostart' dir is not available. Simply create it with QDir::mkpath() (= mkdir -p). --- src/platform/autorun_xdg.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/platform/autorun_xdg.cpp b/src/platform/autorun_xdg.cpp index fd0140a40..b1825c776 100644 --- a/src/platform/autorun_xdg.cpp +++ b/src/platform/autorun_xdg.cpp @@ -26,14 +26,19 @@ namespace Platform { - QString getAutostartFilePath() + QString getAutostartDirPath() { QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QString config = env.value("XDG_CONFIG_HOME"); if (config.isEmpty()) config = QDir::homePath() + "/" + ".config"; - return config + "/" + "autostart/qTox - " + - Settings::getInstance().getCurrentProfile() + ".desktop"; + return config + "/autostart"; + } + + QString getAutostartFilePath(QString dir) + { + return dir + "/qTox - " + Settings::getInstance().getCurrentProfile() + + ".desktop"; } inline QString currentCommandLine() @@ -45,11 +50,12 @@ namespace Platform bool Platform::setAutorun(bool on) { - - QFile desktop(getAutostartFilePath()); + QString dirPath = getAutostartDirPath(); + QFile desktop(getAutostartFilePath(dirPath)); if (on) { - if (!desktop.open(QFile::WriteOnly | QFile::Truncate)) + if (!QDir().mkpath(dirPath) || + !desktop.open(QFile::WriteOnly | QFile::Truncate)) return false; desktop.write("[Desktop Entry]\n"); desktop.write("Type=Application\n"); @@ -66,7 +72,7 @@ bool Platform::setAutorun(bool on) bool Platform::getAutorun() { - return QFile(getAutostartFilePath()).exists(); + return QFile(getAutostartFilePath(getAutostartDirPath())).exists(); } #endif // defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)