From e591add0254dcb9cda3ac8d04fec8329d188b4f0 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 4 Jul 2017 15:05:54 +0300 Subject: [PATCH] move autostart functionality to universalSettings --- app/universalsettings.cpp | 46 +++++++++++++++++++ app/universalsettings.h | 11 ++--- .../contents/configuration/TweaksConfig.qml | 4 +- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/app/universalsettings.cpp b/app/universalsettings.cpp index 6b7a9f7b4..0c2333009 100644 --- a/app/universalsettings.cpp +++ b/app/universalsettings.cpp @@ -40,6 +40,14 @@ UniversalSettings::~UniversalSettings() void UniversalSettings::load() { + //! check if user has set the autostart option + bool autostartUserSet = m_universalGroup.readEntry("userConfiguredAutostart", false); + + if (!autostartUserSet && !autostart()) { + setAutostart(true); + } + + //! load configuration loadConfig(); } @@ -90,6 +98,44 @@ void UniversalSettings::setCurrentLayoutName(QString layoutName) emit currentLayoutNameChanged(); } +bool UniversalSettings::autostart() const +{ + QFile autostartFile(QDir::homePath() + "/.config/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"); + + if (oldAutostartFile.exists()) { + oldAutostartFile.remove(); + } + + //! end of removal of old autostart file + + QFile autostartFile(QDir::homePath() + "/.config/autostart/org.kde.latte-dock.desktop"); + QFile metaFile("/usr/share/applications/org.kde.latte-dock.desktop"); + + if (!state && autostartFile.exists()) { + //! the first time that the user disables the autostart, this is recorded + //! and from now own it will not be recreated it in the beginning + if (!m_universalGroup.readEntry("userConfiguredAutostart", false)) { + m_universalGroup.writeEntry("userConfiguredAutostart", true); + } + + autostartFile.remove(); + emit autostartChanged(); + } else if (state && metaFile.exists()) { + metaFile.copy(autostartFile.fileName()); + //! I havent added the flag "OnlyShowIn=KDE;" into the autostart file + //! because I fall onto a Plasma 5.8 case that this flag + //! didnt let the plasma desktop to start + emit autostartChanged(); + } +} + void UniversalSettings::loadConfig() { m_version = m_universalGroup.readEntry("version", 1); diff --git a/app/universalsettings.h b/app/universalsettings.h index 1b0706ac9..545373dd2 100644 --- a/app/universalsettings.h +++ b/app/universalsettings.h @@ -34,22 +34,20 @@ namespace Latte { //! independent of layouts class UniversalSettings : public QObject { Q_OBJECT - //Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged) + Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged) Q_PROPERTY(bool exposeLayoutsMenu READ exposeLayoutsMenu WRITE setExposeLayoutsMenu NOTIFY exposeLayoutsMenuChanged) Q_PROPERTY(QString currentLayoutName READ currentLayoutName WRITE setCurrentLayoutName NOTIFY currentLayoutNameChanged) - //Q_PROPERTY(Latte::Dock::SessionType currentSession READ currentSession WRITE setCurrentSession NOTIFY currentSessionChanged) - - //Q_PROPERTY(QAction *altSessionAction READ altSessionAction NOTIFY altSessionActionChanged) - //Q_PROPERTY(QAction *addWidgetsAction READ addWidgetsAction NOTIFY addWidgetsActionChanged) - public: UniversalSettings(KSharedConfig::Ptr config, QObject *parent = nullptr); ~UniversalSettings() override; void load(); + bool autostart() const; + void setAutostart(bool state); + bool exposeLayoutsMenu() const; void setExposeLayoutsMenu(bool state); @@ -60,6 +58,7 @@ public: void setCurrentLayoutName(QString layoutName); signals: + void autostartChanged(); void currentLayoutNameChanged(); void exposeLayoutsMenuChanged(); void versionChanged(); diff --git a/shell/package/contents/configuration/TweaksConfig.qml b/shell/package/contents/configuration/TweaksConfig.qml index b29e7c5bb..16d576f0a 100644 --- a/shell/package/contents/configuration/TweaksConfig.qml +++ b/shell/package/contents/configuration/TweaksConfig.qml @@ -113,10 +113,10 @@ PlasmaComponents.Page { PlasmaComponents.CheckBox { Layout.leftMargin: units.smallSpacing * 2 text: i18n("Enable autostart during startup") - checked: globalSettings.autostart + checked: universalSettings.autostart onClicked: { - globalSettings.autostart = checked + universalSettings.autostart = checked; } }