From f27f938042180d05993691ea0825c4485a5f5b9b Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 2 Feb 2021 22:29:27 +0200 Subject: [PATCH] support XDG_CONFIG_PATH for app code BUG:428210 --- app/layouts/importer.cpp | 17 +++++++++-------- app/layouts/manager.cpp | 3 ++- app/plasma/extended/screenpool.cpp | 5 ++++- app/plasma/extended/theme.cpp | 2 +- app/settings/universalsettings.cpp | 15 ++++++++------- app/shortcuts/shortcutstracker.cpp | 3 ++- app/tools/commontools.cpp | 13 +++++++++++++ app/tools/commontools.h | 2 ++ app/wm/schemecolors.cpp | 3 ++- app/wm/tracker/schemes.cpp | 3 ++- 10 files changed, 45 insertions(+), 21 deletions(-) diff --git a/app/layouts/importer.cpp b/app/layouts/importer.cpp index de512c97b..0dd48a03a 100644 --- a/app/layouts/importer.cpp +++ b/app/layouts/importer.cpp @@ -27,6 +27,7 @@ #include "../screenpool.h" #include "../layout/abstractlayout.h" #include "../settings/universalsettings.h" +#include "../tools/commontools.h" // Qt #include @@ -63,17 +64,17 @@ Importer::~Importer() bool Importer::updateOldConfiguration() { - QFile oldAppletsFile(QDir::homePath() + "/.config/lattedock-appletsrc"); + QFile oldAppletsFile(Latte::configPath() + "/lattedock-appletsrc"); if (!oldAppletsFile.exists()) { return false; } //! import standard old configuration and create the relevant layouts - importOldLayout(QDir::homePath() + "/.config/lattedock-appletsrc", i18n("My Layout")); - importOldLayout(QDir::homePath() + "/.config/lattedock-appletsrc", i18n("Alternative"), true); + importOldLayout(Latte::configPath() + "/lattedock-appletsrc", i18n("My Layout")); + importOldLayout(Latte::configPath() + "/lattedock-appletsrc", i18n("Alternative"), true); - QFile extFile(QDir::homePath() + "/.config/lattedockextrc"); + QFile extFile(Latte::configPath() + "/lattedockextrc"); //! import also the old user layouts into the new architecture if (extFile.exists()) { @@ -268,7 +269,7 @@ QString Importer::layoutCanBeImported(QString oldAppletsPath, QString newName, Q QDir layoutDir(exportDirectory.isNull() ? layoutUserDir() : exportDirectory); if (!layoutDir.exists() && exportDirectory.isNull()) { - QDir(QDir::homePath() + "/.config").mkdir("latte"); + QDir(Latte::configPath()).mkdir("latte"); } //! set up the new layout name @@ -397,7 +398,7 @@ bool Importer::exportFullConfiguration(QString file) return false; } - archive.addLocalFile(QString(QDir::homePath() + "/.config/lattedockrc"), QStringLiteral("lattedockrc")); + archive.addLocalFile(QString(Latte::configPath() + "/lattedockrc"), QStringLiteral("lattedockrc")); for(const auto &layoutName : availableLayouts()) { archive.addLocalFile(layoutUserFilePath(layoutName), QString("latte/" + layoutName + ".layout.latte")); @@ -515,7 +516,7 @@ bool Importer::importHelper(QString fileName) latteDir.removeRecursively(); } - archive.directory()->copyTo(QString(QDir::homePath() + "/.config")); + archive.directory()->copyTo(Latte::configPath()); return true; } @@ -591,7 +592,7 @@ bool Importer::layoutExists(QString layoutName) QString Importer::layoutUserDir() { - return QString(QDir::homePath() + "/.config/latte"); + return QString(Latte::configPath() + "/latte"); } QString Importer::layoutUserFilePath(QString layoutName) diff --git a/app/layouts/manager.cpp b/app/layouts/manager.cpp index f606d38d3..505ab8e84 100644 --- a/app/layouts/manager.cpp +++ b/app/layouts/manager.cpp @@ -33,6 +33,7 @@ #include "../settings/dialogs/settingsdialog.h" #include "../settings/universalsettings.h" #include "../templates/templatesmanager.h" +#include "../tools/commontools.h" // Qt #include @@ -87,7 +88,7 @@ void Manager::init() //startup create what is necessary.... if (!layoutsDir.exists()) { - QDir(QDir::homePath() + "/.config").mkdir("latte"); + QDir(Latte::configPath()).mkdir("latte"); } QString defpath = m_corona->templatesManager()->newLayout(i18n("My Layout"), i18n(Templates::DEFAULTLAYOUTTEMPLATENAME)); diff --git a/app/plasma/extended/screenpool.cpp b/app/plasma/extended/screenpool.cpp index 84d4fca7c..8ae4b82a8 100644 --- a/app/plasma/extended/screenpool.cpp +++ b/app/plasma/extended/screenpool.cpp @@ -19,6 +19,9 @@ #include "screenpool.h" +// local +#include "../../tools/commontools.h" + // Qt #include #include @@ -43,7 +46,7 @@ ScreenPool::ScreenPool(QObject *parent) load(); - QString plasmaSettingsFile = QDir::homePath() + "/.config/" + PLASMARC; + QString plasmaSettingsFile = Latte::configPath() + "/" + PLASMARC; KDirWatch::self()->addFile(plasmaSettingsFile); diff --git a/app/plasma/extended/theme.cpp b/app/plasma/extended/theme.cpp index 233db00a0..84b626782 100644 --- a/app/plasma/extended/theme.cpp +++ b/app/plasma/extended/theme.cpp @@ -377,7 +377,7 @@ void Theme::loadThemePaths() } else { //! when plasma theme uses the kde colors //! we track when kde color scheme is changing - QString kdeSettingsFile = QDir::homePath() + "/.config/kdeglobals"; + QString kdeSettingsFile = Latte::configPath() + "/kdeglobals"; KDirWatch::self()->addFile(kdeSettingsFile); diff --git a/app/settings/universalsettings.cpp b/app/settings/universalsettings.cpp index 97de7c949..83a6b01be 100644 --- a/app/settings/universalsettings.cpp +++ b/app/settings/universalsettings.cpp @@ -25,6 +25,7 @@ #include "../layout/centrallayout.h" #include "../layouts/importer.h" #include "../layouts/manager.h" +#include "../tools/commontools.h" // Qt #include @@ -40,7 +41,7 @@ #define KWINMETAFORWARDTOPLASMASTRING "org.kde.plasmashell,/PlasmaShell,org.kde.PlasmaShell,activateLauncherMenu" #define KWINCOLORSSCRIPT "kwin/scripts/lattewindowcolors" -#define KWINRC "/.config/kwinrc" +#define KWINRC "kwinrc" #define KWINRCTRACKERINTERVAL 2500 @@ -101,7 +102,7 @@ void UniversalSettings::load() } //! Track KWin rc options - const QString kwinrcFilePath = QDir::homePath() + KWINRC; + const QString kwinrcFilePath = Latte::configPath() + "/" + KWINRC; KDirWatch::self()->addFile(kwinrcFilePath); recoverKWinOptions(); @@ -212,14 +213,14 @@ void UniversalSettings::setLaunchers(QStringList launcherList) bool UniversalSettings::autostart() const { - QFile autostartFile(QDir::homePath() + "/.config/autostart/org.kde.latte-dock.desktop"); + QFile autostartFile(Latte::configPath() + "/autostart/org.kde.latte-dock.desktop"); return autostartFile.exists(); } void UniversalSettings::setAutostart(bool state) { //! remove old autostart file - QFile oldAutostartFile(QDir::homePath() + "/.config/autostart/latte-dock.desktop"); + QFile oldAutostartFile(Latte::configPath() + "/autostart/latte-dock.desktop"); if (oldAutostartFile.exists()) { oldAutostartFile.remove(); @@ -227,7 +228,7 @@ void UniversalSettings::setAutostart(bool state) //! end of removal of old autostart file - QFile autostartFile(QDir::homePath() + "/.config/autostart/org.kde.latte-dock.desktop"); + QFile autostartFile(Latte::configPath() + "/autostart/org.kde.latte-dock.desktop"); QFile metaFile(Layouts::Importer::standardPath("applications/org.kde.latte-dock.desktop", false)); if (!state && autostartFile.exists()) { @@ -241,9 +242,9 @@ void UniversalSettings::setAutostart(bool state) emit autostartChanged(); } else if (state && metaFile.exists()) { //! check if autostart folder exists and create otherwise - QDir autostartDir(QDir::homePath() + "/.config/autostart"); + QDir autostartDir(Latte::configPath() + "/autostart"); if (!autostartDir.exists()) { - QDir configDir(QDir::homePath() + "/.config"); + QDir configDir(Latte::configPath()); configDir.mkdir("autostart"); } diff --git a/app/shortcuts/shortcutstracker.cpp b/app/shortcuts/shortcutstracker.cpp index 86e082874..ab944f9af 100644 --- a/app/shortcuts/shortcutstracker.cpp +++ b/app/shortcuts/shortcutstracker.cpp @@ -19,6 +19,7 @@ // local #include "shortcutstracker.h" +#include "../tools/commontools.h" // Qt #include @@ -56,7 +57,7 @@ void ShortcutsTracker::initGlobalShortcutsWatcher() m_badgesForActivate << QString(); } - const QString globalShortcutsFilePath = QDir::homePath() + "/.config/" + GLOBALSHORTCUTSCONFIG; + const QString globalShortcutsFilePath = Latte::configPath() + "/" + GLOBALSHORTCUTSCONFIG; m_shortcutsConfigPtr = KSharedConfig::openConfig(globalShortcutsFilePath); KDirWatch::self()->addFile(globalShortcutsFilePath); diff --git a/app/tools/commontools.cpp b/app/tools/commontools.cpp index a963c1aa9..8919246d5 100644 --- a/app/tools/commontools.cpp +++ b/app/tools/commontools.cpp @@ -21,6 +21,7 @@ #include "commontools.h" // Qt +#include #include #include #include @@ -101,4 +102,16 @@ QString standardPath(QString subPath, bool localfirst) return ""; } +QString configPath() +{ + QStringList configPaths = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation); + + if (configPaths.count() == 0) { + return QDir::homePath() + "/.config"; + } + + return configPaths[0]; +} + + } diff --git a/app/tools/commontools.h b/app/tools/commontools.h index 1da1cb3f3..351263bae 100644 --- a/app/tools/commontools.h +++ b/app/tools/commontools.h @@ -37,6 +37,8 @@ float colorLumina(float r, float g, float b); //! returns the standard path found that contains the subPath //! local paths have higher priority by default QString standardPath(QString subPath, bool localFirst = true); + +QString configPath(); } #endif diff --git a/app/wm/schemecolors.cpp b/app/wm/schemecolors.cpp index 9642137f1..1a49bf8db 100644 --- a/app/wm/schemecolors.cpp +++ b/app/wm/schemecolors.cpp @@ -22,6 +22,7 @@ // local #include "../layouts/importer.h" +#include "../tools/commontools.h" // Qt #include @@ -158,7 +159,7 @@ QString SchemeColors::possibleSchemeFile(QString scheme) QString tempScheme = scheme; if (scheme == "kdeglobals") { - QString settingsFile = QDir::homePath() + "/.config/kdeglobals"; + QString settingsFile = Latte::configPath() + "/kdeglobals"; if (QFileInfo(settingsFile).exists()) { KSharedConfigPtr filePtr = KSharedConfig::openConfig(settingsFile); diff --git a/app/wm/tracker/schemes.cpp b/app/wm/tracker/schemes.cpp index a566b79af..f15ea366a 100644 --- a/app/wm/tracker/schemes.cpp +++ b/app/wm/tracker/schemes.cpp @@ -22,6 +22,7 @@ // local #include "../abstractwindowinterface.h" #include "../../lattecorona.h" +#include "../../tools/commontools.h" // Qt #include @@ -65,7 +66,7 @@ void Schemes::init() }); //! track for changing default scheme - QString kdeSettingsFile = QDir::homePath() + "/.config/kdeglobals"; + QString kdeSettingsFile = Latte::configPath() + "/kdeglobals"; KDirWatch::self()->addFile(kdeSettingsFile);