From 1a04ff968dc40e366eaae2ce7f3c6b05e89b316d Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 7 Mar 2017 19:22:15 +0200 Subject: [PATCH] fix #233,support autostart through tweaks page --- app/dockconfigview.cpp | 26 ++++++++++++++++++- app/dockconfigview.h | 5 ++++ app/dockcorona.cpp | 26 +++++++++++++++++++ app/dockcorona.h | 4 +++ shell/contents/configuration/TweaksConfig.qml | 4 +-- 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/app/dockconfigview.cpp b/app/dockconfigview.cpp index de202637a..c8332f2fe 100644 --- a/app/dockconfigview.cpp +++ b/app/dockconfigview.cpp @@ -66,7 +66,11 @@ DockConfigView::DockConfigView(Plasma::Containment *containment, DockView *dockV }); auto *dockCorona = qobject_cast(m_dockView->corona()); - connections << connect(this, &DockConfigView::aboutApplication, dockCorona, &DockCorona::aboutApplication); + + if (dockCorona) { + connections << connect(this, &DockConfigView::aboutApplication, dockCorona, &DockCorona::aboutApplication); + connections << connect(dockCorona, SIGNAL(autostartChanged()), this, SIGNAL(autostartChanged())); + } } DockConfigView::~DockConfigView() @@ -252,5 +256,25 @@ void DockConfigView::setSticker(bool blockFocusLost) m_blockFocusLost = blockFocusLost; } +bool DockConfigView::autostart() const +{ + auto *dockCorona = qobject_cast(m_dockView->corona()); + + if (dockCorona) { + return dockCorona->autostart(); + } + + return false; +} + +void DockConfigView::setAutostart(bool state) +{ + auto *dockCorona = qobject_cast(m_dockView->corona()); + + if (dockCorona) { + dockCorona->setAutostart(state); + } +} + } // kate: indent-mode cstyle; indent-width 4; replace-tabs on; diff --git a/app/dockconfigview.h b/app/dockconfigview.h index acbcb6c1f..838e60379 100644 --- a/app/dockconfigview.h +++ b/app/dockconfigview.h @@ -43,6 +43,7 @@ class DockView; class DockConfigView : public PlasmaQuick::ConfigView { Q_OBJECT + Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged) public: DockConfigView(Plasma::Containment *containment, DockView *dockView, QWindow *parent = nullptr); @@ -51,11 +52,15 @@ public: void init() override; Qt::WindowFlags wFlags() const; + void setAutostart(bool state); + bool autostart() const; + public slots: Q_INVOKABLE void setSticker(bool blockFocusLost); Q_INVOKABLE void syncGeometry(); signals: + void autostartChanged(); void showSignal(); protected: diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 122c4518b..0322956d3 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -576,6 +578,30 @@ void DockCorona::aboutApplication() aboutDialog->show(); } +void DockCorona::setAutostart(bool state) +{ + QFile autostartFile(QDir::homePath() + "/.config/autostart/latte-dock.desktop"); + QFile metaFile("/usr/share/applications/latte-dock.desktop"); + + if (!state && autostartFile.exists()) { + 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(); + } +} + +bool DockCorona::autostart() const +{ + QFile autostartFile(QDir::homePath() + "/.config/autostart/latte-dock.desktop"); + return autostartFile.exists(); +} + + QList DockCorona::freeEdges(QScreen *screen) const { using Plasma::Types; diff --git a/app/dockcorona.h b/app/dockcorona.h index b9499044e..801de71fe 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -65,6 +65,9 @@ public: void addDock(Plasma::Containment *containment); void recreateDock(Plasma::Containment *containment); + void setAutostart(bool state); + bool autostart() const; + void aboutApplication(); void closeApplication(); @@ -75,6 +78,7 @@ public slots: void dockContainmentDestroyed(QObject *cont); signals: + void autostartChanged(); void configurationShown(PlasmaQuick::ConfigView *configView); void docksCountChanged(); void dockLocationChanged(); diff --git a/shell/contents/configuration/TweaksConfig.qml b/shell/contents/configuration/TweaksConfig.qml index 292398818..79e3da8ad 100644 --- a/shell/contents/configuration/TweaksConfig.qml +++ b/shell/contents/configuration/TweaksConfig.qml @@ -49,16 +49,16 @@ PlasmaComponents.Page { } PlasmaComponents.CheckBox { - id: showGlow Layout.leftMargin: units.smallSpacing * 2 text: i18n("Enable autostart during startup") + checked: dockConfig.autostart onClicked: { + dockConfig.autostart = checked; } } PlasmaComponents.CheckBox { - id: threeColorsWindows Layout.leftMargin: units.smallSpacing * 2 text: i18n("Show dock on desktop or actitivy change")