From d9a84289712520c958cd5bf6fc26c6cfffa4e6f9 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sat, 18 Mar 2017 13:21:17 +0200 Subject: [PATCH] create globalsettings for corona --first all the code concerning exposeAltSession is moved in it and in the future also the autostart and currentSession can follow. This will improve both dockview and configview --- app/CMakeLists.txt | 1 + app/dockconfigview.cpp | 6 ++ app/dockcorona.cpp | 67 +++----------- app/dockcorona.h | 18 ++-- app/dockview.cpp | 46 +++------- app/dockview.h | 9 -- app/globalsettings.cpp | 89 +++++++++++++++++++ app/globalsettings.h | 71 +++++++++++++++ containment/contents/ui/main.qml | 6 +- shell/contents/configuration/TweaksConfig.qml | 4 +- shell/contents/views/Panel.qml | 1 + 11 files changed, 200 insertions(+), 118 deletions(-) create mode 100644 app/globalsettings.cpp create mode 100644 app/globalsettings.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index c1c783f07..f36c887f7 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -12,6 +12,7 @@ set(lattedock-app_SRCS panelshadows.cpp alternativeshelper.cpp screenpool.cpp + globalsettings.cpp main.cpp ) diff --git a/app/dockconfigview.cpp b/app/dockconfigview.cpp index b271a0a43..ce311a45a 100644 --- a/app/dockconfigview.cpp +++ b/app/dockconfigview.cpp @@ -89,6 +89,12 @@ void DockConfigView::init() PanelShadows::self()->addWindow(this); rootContext()->setContextProperty(QStringLiteral("dock"), m_dockView); rootContext()->setContextProperty(QStringLiteral("dockConfig"), this); + auto *dockCorona = qobject_cast(m_dockView->corona()); + + if (dockCorona) { + rootContext()->setContextProperty(QStringLiteral("globalSettings"), dockCorona->globalSettings()); + } + KDeclarative::KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); kdeclarative.setTranslationDomain(QStringLiteral("latte-dock")); diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 225d2b060..265b066d3 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -53,11 +53,12 @@ namespace Latte { DockCorona::DockCorona(QObject *parent) : Plasma::Corona(parent), m_screenPool(new ScreenPool(KSharedConfig::openConfig(), this)), + m_globalSettings(new GlobalSettings(this)), m_activityConsumer(new KActivities::Consumer(this)) { - restoreConfig(); KPackage::Package package(new DockPackage(this)); m_screenPool->load(); + m_globalSettings->load(); if (!package.isValid()) { qWarning() << staticMetaObject.className() @@ -98,7 +99,7 @@ DockCorona::~DockCorona() delete containments().first(); } - m_altSessionAction->deleteLater(); + m_globalSettings->deleteLater(); qDeleteAll(m_dockViews); qDeleteAll(m_waitingDockViews); m_dockViews.clear(); @@ -123,13 +124,6 @@ void DockCorona::load() connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &DockCorona::screenCountChanged); connect(m_screenPool, &ScreenPool::primaryPoolChanged, this, &DockCorona::screenCountChanged); - //! create the alternative session action - const QIcon altIcon = QIcon::fromTheme("user-identity"); - m_altSessionAction = new QAction(altIcon, i18n("Alternative Session"), this); - m_altSessionAction->setStatusTip(tr("Enable/Disable Alternative Session")); - m_altSessionAction->setCheckable(true); - connect(m_altSessionAction, &QAction::triggered, this, &DockCorona::enableAltSession); - loadLayout(); } } @@ -205,6 +199,11 @@ ScreenPool *DockCorona::screenPool() const return m_screenPool; } +GlobalSettings *DockCorona::globalSettings() const +{ + return m_globalSettings; +} + int DockCorona::numScreens() const { return qGuiApp->screens().count(); @@ -625,35 +624,6 @@ bool DockCorona::autostart() const return autostartFile.exists(); } -QAction *DockCorona::altSessionAction() -{ - return m_altSessionAction; -} - -void DockCorona::enableAltSession(bool flag) -{ - if (flag) { - switchToSession(Dock::AlternativeSession); - } else { - switchToSession(Dock::DefaultSession); - } -} - -bool DockCorona::exposeAltSession() const -{ - return m_exposeAltSession; -} -void DockCorona::setExposeAltSession(bool state) -{ - if (m_exposeAltSession == state) { - return; - } - - m_exposeAltSession = state; - saveConfig(); - emit exposeAltSessionChanged(); -} - Dock::SessionType DockCorona::currentSession() { return m_session; @@ -667,11 +637,9 @@ void DockCorona::setCurrentSession(Dock::SessionType session) m_session = session; - if (m_session == Dock::DefaultSession) - m_altSessionAction->setChecked(false); - else - m_altSessionAction->setChecked(true); + emit currentSessionChanged(m_session);; } + void DockCorona::switchToSession(Dock::SessionType session) { if (currentSession() == session) { @@ -1125,21 +1093,6 @@ void DockCorona::activateLauncherMenu() } } -//!BEGIN configuration functions -void DockCorona::saveConfig() -{ - auto conf = config()->group("General"); - conf.writeEntry("exposeAltSession", m_exposeAltSession); - conf.sync(); -} - -void DockCorona::restoreConfig() -{ - auto conf = config()->group("General");; - setExposeAltSession(conf.readEntry("exposeAltSession", false)); -} -//!END configuration functions - inline void DockCorona::qmlRegisterTypes() const { qmlRegisterType(); diff --git a/app/dockcorona.h b/app/dockcorona.h index e8a7e9c28..7adc080bd 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -22,6 +22,7 @@ #define DOCKCORONA_H #include "dockview.h" +#include "globalsettings.h" #include "../liblattedock/dock.h" #include @@ -36,6 +37,7 @@ class Types; } class ScreenPool; +class GlobalSettings; namespace KActivities { class Consumer; @@ -70,11 +72,6 @@ public: bool autostart() const; void setAutostart(bool state); - bool exposeAltSession() const; - void setExposeAltSession(bool state); - - QAction *altSessionAction(); - Dock::SessionType currentSession(); void setCurrentSession(Dock::SessionType session); void switchToSession(Dock::SessionType session); @@ -83,6 +80,7 @@ public: void closeApplication(); ScreenPool *screenPool() const; + GlobalSettings *globalSettings() const; public slots: void activateLauncherMenu(); @@ -92,9 +90,9 @@ public slots: signals: void autostartChanged(); void configurationShown(PlasmaQuick::ConfigView *configView); + void currentSessionChanged(Dock::SessionType type); void docksCountChanged(); void dockLocationChanged(); - void exposeAltSessionChanged(); void raiseDocksTemporaryChanged(); private slots: @@ -104,7 +102,6 @@ private slots: void load(); void addOutput(QScreen *screen); - void enableAltSession(bool flag); void primaryOutputChanged(); void screenRemoved(QScreen *screen); void screenCountChanged(); @@ -112,8 +109,6 @@ private slots: private: void cleanConfig(); - void restoreConfig(); - void saveConfig(); void qmlRegisterTypes() const; bool appletExists(uint containmentId, uint appletId) const; bool containmentContainsTasks(Plasma::Containment *cont); @@ -134,12 +129,8 @@ private: //! with tasks" will be loaded otherwise. Currently the older one dock wins int m_firstContainmentWithTasks{ -1}; - bool m_exposeAltSession{false}; - Dock::SessionType m_session{Dock::DefaultSession}; - QAction *m_altSessionAction{nullptr}; - QHash m_dockViews; QHash m_waitingDockViews; QList m_alternativesObjects; @@ -150,6 +141,7 @@ private: QPointer aboutDialog; ScreenPool *m_screenPool; + GlobalSettings *m_globalSettings; }; } diff --git a/app/dockview.cpp b/app/dockview.cpp index 0f01954f6..ac77a6f7b 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -21,8 +21,9 @@ #include "dockview.h" #include "dockconfigview.h" #include "dockcorona.h" -#include "visibilitymanager.h" +#include "globalsettings.h" #include "panelshadows_p.h" +#include "visibilitymanager.h" #include "../liblattedock/extras.h" #include @@ -112,8 +113,6 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool alwaysVis m_screenSyncTimer.start(); } }); - connect(dockCorona, SIGNAL(exposeAltSessionChanged()), this, SIGNAL(exposeAltSessionChanged())); - connect(dockCorona, SIGNAL(exposeAltSessionChanged()), this, SIGNAL(altSessionActionChanged())); } m_screenSyncTimer.setSingleShot(true); @@ -174,6 +173,13 @@ void DockView::init() connect(this, SIGNAL(normalThicknessChanged()), corona(), SIGNAL(availableScreenRectChanged())); connect(this, SIGNAL(shadowChanged()), corona(), SIGNAL(availableScreenRectChanged())); rootContext()->setContextProperty(QStringLiteral("dock"), this); + + auto *dockCorona = qobject_cast(this->corona()); + + if (dockCorona) { + rootContext()->setContextProperty(QStringLiteral("globalSettings"), dockCorona->globalSettings()); + } + setSource(corona()->kPackage().filePath("lattedockui")); setVisible(true); syncGeometry(); @@ -697,16 +703,6 @@ int DockView::docksWithTasks() return dockCorona->noDocksWithTasks(); } -QAction *DockView::altSessionAction() const -{ - auto dockCorona = qobject_cast(corona()); - - if (!dockCorona) - return 0; - - return dockCorona->altSessionAction(); -} - void DockView::updateFormFactor() { if (!this->containment()) @@ -819,26 +815,6 @@ void DockView::setRunningSession(Dock::SessionType session) } } -bool DockView::exposeAltSession() const -{ - auto *dockCorona = qobject_cast(corona()); - - if (dockCorona) { - return dockCorona->exposeAltSession(); - } - - return false; -} - -void DockView::setExposeAltSession(bool state) -{ - auto *dockCorona = qobject_cast(corona()); - - if (dockCorona && dockCorona->exposeAltSession() != state) { - dockCorona->setExposeAltSession(state); - } -} - float DockView::maxLength() const { return m_maxLength; @@ -1424,9 +1400,9 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event) } else { auto *dockCorona = qobject_cast(this->corona()); - if (dockCorona && exposeAltSession()) { + if (dockCorona && dockCorona->globalSettings()->exposeAltSession()) { desktopMenu->addSeparator(); - desktopMenu->addAction(dockCorona->altSessionAction()); + desktopMenu->addAction(dockCorona->globalSettings()->altSessionAction()); } desktopMenu->addActions(actions); diff --git a/app/dockview.h b/app/dockview.h index 3bbc6c76d..3e58ce469 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -47,7 +47,6 @@ class DockView : public PlasmaQuick::ContainmentView { Q_OBJECT Q_PROPERTY(bool drawShadows READ drawShadows WRITE setDrawShadows NOTIFY drawShadowsChanged) Q_PROPERTY(bool drawEffects READ drawEffects WRITE setDrawEffects NOTIFY drawEffectsChanged) - Q_PROPERTY(bool exposeAltSession READ exposeAltSession WRITE setExposeAltSession NOTIFY exposeAltSessionChanged) Q_PROPERTY(bool onPrimary READ onPrimary WRITE setOnPrimary NOTIFY onPrimaryChanged) Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) @@ -69,8 +68,6 @@ class DockView : public PlasmaQuick::ContainmentView { Q_PROPERTY(VisibilityManager *visibility READ visibility NOTIFY visibilityChanged) Q_PROPERTY(QQmlListProperty screens READ screens) - Q_PROPERTY(QAction *altSessionAction READ altSessionAction NOTIFY altSessionActionChanged) - Q_PROPERTY(QRect effectsArea READ effectsArea WRITE setEffectsArea NOTIFY effectsAreaChanged) Q_PROPERTY(QRect localGeometry READ localGeometry WRITE setLocalGeometry NOTIFY localGeometryChanged) Q_PROPERTY(QRect maskArea READ maskArea WRITE setMaskArea NOTIFY maskAreaChanged) @@ -103,9 +100,6 @@ public: bool drawEffects() const; void setDrawEffects(bool draw); - bool exposeAltSession() const; - void setExposeAltSession(bool state); - float maxLength() const; void setMaxLength(float length); @@ -130,7 +124,6 @@ public: QRect absGeometry() const; QRect screenGeometry() const; - QAction *altSessionAction() const; Latte::Dock::SessionType runningSession() const; void setRunningSession(Latte::Dock::SessionType session); @@ -181,7 +174,6 @@ signals: void eventTriggered(QEvent *ev); void alignmentChanged(); - void altSessionActionChanged(); void currentScreenChanged(); void dockLocationChanged(); void docksCountChanged(); @@ -189,7 +181,6 @@ signals: void drawEffectsChanged(); void effectsAreaChanged(); void enabledBordersChanged(); - void exposeAltSessionChanged(); void widthChanged(); void heightChanged(); void localGeometryChanged(); diff --git a/app/globalsettings.cpp b/app/globalsettings.cpp new file mode 100644 index 000000000..510362032 --- /dev/null +++ b/app/globalsettings.cpp @@ -0,0 +1,89 @@ +#include "globalsettings.h" + +#include +#include + +#include + +namespace Latte { + +GlobalSettings::GlobalSettings(QObject *parent) + : QObject(parent) +{ + m_corona = qobject_cast(parent); + + if (m_corona) { + m_configGroup = m_corona->config()->group("General"); + + //! create the alternative session action + const QIcon altIcon = QIcon::fromTheme("user-identity"); + m_altSessionAction = new QAction(altIcon, i18n("Alternative Session"), this); + m_altSessionAction->setStatusTip(tr("Enable/Disable Alternative Session")); + m_altSessionAction->setCheckable(true); + connect(m_altSessionAction, &QAction::triggered, this, &GlobalSettings::enableAltSession); + + connect(m_corona, &DockCorona::currentSessionChanged, this, &GlobalSettings::currentSessionChanged); + } +} + +GlobalSettings::~GlobalSettings() +{ + m_altSessionAction->deleteLater(); + m_configGroup.sync(); +} + +void GlobalSettings::enableAltSession(bool enabled) +{ + if (enabled) { + m_corona->switchToSession(Dock::AlternativeSession); + } else { + m_corona->switchToSession(Dock::DefaultSession); + } +} + +bool GlobalSettings::exposeAltSession() const +{ + return m_exposeAltSession; +} + +void GlobalSettings::setExposeAltSession(bool state) +{ + if (m_exposeAltSession == state) { + return; + } + + m_exposeAltSession = state; + save(); + emit exposeAltSessionChanged(); +} + +void GlobalSettings::currentSessionChanged(Dock::SessionType type) +{ + if (m_corona->currentSession() == Dock::DefaultSession) + m_altSessionAction->setChecked(false); + else + m_altSessionAction->setChecked(true); + +} + +QAction *GlobalSettings::altSessionAction() const +{ + return m_altSessionAction; +} + +//!BEGIN configuration functions +void GlobalSettings::load() +{ + setExposeAltSession(m_configGroup.readEntry("exposeAltSession", false)); +} + +void GlobalSettings::save() +{ + m_configGroup.writeEntry("exposeAltSession", m_exposeAltSession); + m_configGroup.sync(); +} +//!END configuration functions + +} + +#include "moc_globalsettings.cpp" diff --git a/app/globalsettings.h b/app/globalsettings.h new file mode 100644 index 000000000..1c26991fb --- /dev/null +++ b/app/globalsettings.h @@ -0,0 +1,71 @@ +/* +* Copyright 2016 Smith AR +* Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* Latte-Dock is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef GLOBALSETTINGS_H +#define GLOBALSETTINGS_H + +#include "dockcorona.h" +#include "../liblattedock/dock.h" + +#include +#include + +class DockCorona; + +namespace Latte { + +class GlobalSettings : public QObject { + Q_OBJECT + Q_PROPERTY(bool exposeAltSession READ exposeAltSession WRITE setExposeAltSession NOTIFY exposeAltSessionChanged) + + Q_PROPERTY(QAction *altSessionAction READ altSessionAction NOTIFY altSessionActionChanged) + +public: + GlobalSettings(QObject *parent = nullptr); + ~GlobalSettings() override; + + void load(); + + bool exposeAltSession() const; + void setExposeAltSession(bool state); + + QAction *altSessionAction() const; + +signals: + void altSessionActionChanged(); + void exposeAltSessionChanged(); + +private slots: + void currentSessionChanged(Dock::SessionType type); + void enableAltSession(bool enabled); + +private: + void save(); + + bool m_exposeAltSession{false}; + QAction *m_altSessionAction{nullptr}; + DockCorona *m_corona{nullptr}; + + KConfigGroup m_configGroup; +}; + +} + +#endif // GLOBALSETTINGS_H diff --git a/containment/contents/ui/main.qml b/containment/contents/ui/main.qml index dfbed5229..39dcabf71 100644 --- a/containment/contents/ui/main.qml +++ b/containment/contents/ui/main.qml @@ -55,7 +55,8 @@ DragDrop.DropArea { && (plasmoid.configuration.panelPosition === Latte.Dock.Justify) && !root.solidPanel property bool editMode: plasmoid.userConfiguring - property bool exposeAltSession: dock ? dock.exposeAltSession : false + property bool exposeAltSession: globalSettings ? globalSettings.exposeAltSession : false + property bool immutable: plasmoid.immutable property bool inStartup: true property bool isHorizontal: plasmoid.formFactor === PlasmaCore.Types.Horizontal @@ -161,8 +162,9 @@ DragDrop.DropArea { property Item latteAppletContainer property Item latteApplet property QtObject dock + property QtObject globalSettings - property QtObject altSessionAction: dock ? dock.altSessionAction : 0 + property QtObject altSessionAction: globalSettings ? globalSettings.altSessionAction : 0 // TO BE DELETED, if not needed: property int counter:0; diff --git a/shell/contents/configuration/TweaksConfig.qml b/shell/contents/configuration/TweaksConfig.qml index 93128a546..9ef83c410 100644 --- a/shell/contents/configuration/TweaksConfig.qml +++ b/shell/contents/configuration/TweaksConfig.qml @@ -92,10 +92,10 @@ PlasmaComponents.Page { PlasmaComponents.CheckBox { Layout.leftMargin: units.smallSpacing * 2 text: i18n("Expose Alternative Session in the context menu") - checked: dock.exposeAltSession + checked: globalSettings.exposeAltSession onClicked: { - dock.exposeAltSession = checked; + globalSettings.exposeAltSession = checked; } } diff --git a/shell/contents/views/Panel.qml b/shell/contents/views/Panel.qml index 376aa03b1..5b9bfbf54 100644 --- a/shell/contents/views/Panel.qml +++ b/shell/contents/views/Panel.qml @@ -86,6 +86,7 @@ PlasmaCore.FrameSvgItem { if (containment.children[i].objectName === "dockLayoutView") { dockLayout = containment.children[i]; dockLayout.dock = dock; + dockLayout.globalSettings = globalSettings; } } }