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
pull/1/head
Michail Vourlakos 8 years ago
parent 7b060c22a5
commit e57d525824

@ -12,6 +12,7 @@ set(lattedock-app_SRCS
panelshadows.cpp panelshadows.cpp
alternativeshelper.cpp alternativeshelper.cpp
screenpool.cpp screenpool.cpp
globalsettings.cpp
main.cpp main.cpp
) )

@ -89,6 +89,12 @@ void DockConfigView::init()
PanelShadows::self()->addWindow(this); PanelShadows::self()->addWindow(this);
rootContext()->setContextProperty(QStringLiteral("dock"), m_dockView); rootContext()->setContextProperty(QStringLiteral("dock"), m_dockView);
rootContext()->setContextProperty(QStringLiteral("dockConfig"), this); rootContext()->setContextProperty(QStringLiteral("dockConfig"), this);
auto *dockCorona = qobject_cast<DockCorona *>(m_dockView->corona());
if (dockCorona) {
rootContext()->setContextProperty(QStringLiteral("globalSettings"), dockCorona->globalSettings());
}
KDeclarative::KDeclarative kdeclarative; KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine()); kdeclarative.setDeclarativeEngine(engine());
kdeclarative.setTranslationDomain(QStringLiteral("latte-dock")); kdeclarative.setTranslationDomain(QStringLiteral("latte-dock"));

@ -53,11 +53,12 @@ namespace Latte {
DockCorona::DockCorona(QObject *parent) DockCorona::DockCorona(QObject *parent)
: Plasma::Corona(parent), : Plasma::Corona(parent),
m_screenPool(new ScreenPool(KSharedConfig::openConfig(), this)), m_screenPool(new ScreenPool(KSharedConfig::openConfig(), this)),
m_globalSettings(new GlobalSettings(this)),
m_activityConsumer(new KActivities::Consumer(this)) m_activityConsumer(new KActivities::Consumer(this))
{ {
restoreConfig();
KPackage::Package package(new DockPackage(this)); KPackage::Package package(new DockPackage(this));
m_screenPool->load(); m_screenPool->load();
m_globalSettings->load();
if (!package.isValid()) { if (!package.isValid()) {
qWarning() << staticMetaObject.className() qWarning() << staticMetaObject.className()
@ -98,7 +99,7 @@ DockCorona::~DockCorona()
delete containments().first(); delete containments().first();
} }
m_altSessionAction->deleteLater(); m_globalSettings->deleteLater();
qDeleteAll(m_dockViews); qDeleteAll(m_dockViews);
qDeleteAll(m_waitingDockViews); qDeleteAll(m_waitingDockViews);
m_dockViews.clear(); m_dockViews.clear();
@ -123,13 +124,6 @@ void DockCorona::load()
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &DockCorona::screenCountChanged); connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &DockCorona::screenCountChanged);
connect(m_screenPool, &ScreenPool::primaryPoolChanged, 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(); loadLayout();
} }
} }
@ -205,6 +199,11 @@ ScreenPool *DockCorona::screenPool() const
return m_screenPool; return m_screenPool;
} }
GlobalSettings *DockCorona::globalSettings() const
{
return m_globalSettings;
}
int DockCorona::numScreens() const int DockCorona::numScreens() const
{ {
return qGuiApp->screens().count(); return qGuiApp->screens().count();
@ -625,35 +624,6 @@ bool DockCorona::autostart() const
return autostartFile.exists(); 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() Dock::SessionType DockCorona::currentSession()
{ {
return m_session; return m_session;
@ -667,11 +637,9 @@ void DockCorona::setCurrentSession(Dock::SessionType session)
m_session = session; m_session = session;
if (m_session == Dock::DefaultSession) emit currentSessionChanged(m_session);;
m_altSessionAction->setChecked(false);
else
m_altSessionAction->setChecked(true);
} }
void DockCorona::switchToSession(Dock::SessionType session) void DockCorona::switchToSession(Dock::SessionType session)
{ {
if (currentSession() == 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 inline void DockCorona::qmlRegisterTypes() const
{ {
qmlRegisterType<QScreen>(); qmlRegisterType<QScreen>();

@ -22,6 +22,7 @@
#define DOCKCORONA_H #define DOCKCORONA_H
#include "dockview.h" #include "dockview.h"
#include "globalsettings.h"
#include "../liblattedock/dock.h" #include "../liblattedock/dock.h"
#include <QObject> #include <QObject>
@ -36,6 +37,7 @@ class Types;
} }
class ScreenPool; class ScreenPool;
class GlobalSettings;
namespace KActivities { namespace KActivities {
class Consumer; class Consumer;
@ -70,11 +72,6 @@ public:
bool autostart() const; bool autostart() const;
void setAutostart(bool state); void setAutostart(bool state);
bool exposeAltSession() const;
void setExposeAltSession(bool state);
QAction *altSessionAction();
Dock::SessionType currentSession(); Dock::SessionType currentSession();
void setCurrentSession(Dock::SessionType session); void setCurrentSession(Dock::SessionType session);
void switchToSession(Dock::SessionType session); void switchToSession(Dock::SessionType session);
@ -83,6 +80,7 @@ public:
void closeApplication(); void closeApplication();
ScreenPool *screenPool() const; ScreenPool *screenPool() const;
GlobalSettings *globalSettings() const;
public slots: public slots:
void activateLauncherMenu(); void activateLauncherMenu();
@ -92,9 +90,9 @@ public slots:
signals: signals:
void autostartChanged(); void autostartChanged();
void configurationShown(PlasmaQuick::ConfigView *configView); void configurationShown(PlasmaQuick::ConfigView *configView);
void currentSessionChanged(Dock::SessionType type);
void docksCountChanged(); void docksCountChanged();
void dockLocationChanged(); void dockLocationChanged();
void exposeAltSessionChanged();
void raiseDocksTemporaryChanged(); void raiseDocksTemporaryChanged();
private slots: private slots:
@ -104,7 +102,6 @@ private slots:
void load(); void load();
void addOutput(QScreen *screen); void addOutput(QScreen *screen);
void enableAltSession(bool flag);
void primaryOutputChanged(); void primaryOutputChanged();
void screenRemoved(QScreen *screen); void screenRemoved(QScreen *screen);
void screenCountChanged(); void screenCountChanged();
@ -112,8 +109,6 @@ private slots:
private: private:
void cleanConfig(); void cleanConfig();
void restoreConfig();
void saveConfig();
void qmlRegisterTypes() const; void qmlRegisterTypes() const;
bool appletExists(uint containmentId, uint appletId) const; bool appletExists(uint containmentId, uint appletId) const;
bool containmentContainsTasks(Plasma::Containment *cont); bool containmentContainsTasks(Plasma::Containment *cont);
@ -134,12 +129,8 @@ private:
//! with tasks" will be loaded otherwise. Currently the older one dock wins //! with tasks" will be loaded otherwise. Currently the older one dock wins
int m_firstContainmentWithTasks{ -1}; int m_firstContainmentWithTasks{ -1};
bool m_exposeAltSession{false};
Dock::SessionType m_session{Dock::DefaultSession}; Dock::SessionType m_session{Dock::DefaultSession};
QAction *m_altSessionAction{nullptr};
QHash<const Plasma::Containment *, DockView *> m_dockViews; QHash<const Plasma::Containment *, DockView *> m_dockViews;
QHash<const Plasma::Containment *, DockView *> m_waitingDockViews; QHash<const Plasma::Containment *, DockView *> m_waitingDockViews;
QList<KDeclarative::QmlObject *> m_alternativesObjects; QList<KDeclarative::QmlObject *> m_alternativesObjects;
@ -150,6 +141,7 @@ private:
QPointer<KAboutApplicationDialog> aboutDialog; QPointer<KAboutApplicationDialog> aboutDialog;
ScreenPool *m_screenPool; ScreenPool *m_screenPool;
GlobalSettings *m_globalSettings;
}; };
} }

@ -21,8 +21,9 @@
#include "dockview.h" #include "dockview.h"
#include "dockconfigview.h" #include "dockconfigview.h"
#include "dockcorona.h" #include "dockcorona.h"
#include "visibilitymanager.h" #include "globalsettings.h"
#include "panelshadows_p.h" #include "panelshadows_p.h"
#include "visibilitymanager.h"
#include "../liblattedock/extras.h" #include "../liblattedock/extras.h"
#include <QAction> #include <QAction>
@ -112,8 +113,6 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool alwaysVis
m_screenSyncTimer.start(); m_screenSyncTimer.start();
} }
}); });
connect(dockCorona, SIGNAL(exposeAltSessionChanged()), this, SIGNAL(exposeAltSessionChanged()));
connect(dockCorona, SIGNAL(exposeAltSessionChanged()), this, SIGNAL(altSessionActionChanged()));
} }
m_screenSyncTimer.setSingleShot(true); m_screenSyncTimer.setSingleShot(true);
@ -174,6 +173,13 @@ void DockView::init()
connect(this, SIGNAL(normalThicknessChanged()), corona(), SIGNAL(availableScreenRectChanged())); connect(this, SIGNAL(normalThicknessChanged()), corona(), SIGNAL(availableScreenRectChanged()));
connect(this, SIGNAL(shadowChanged()), corona(), SIGNAL(availableScreenRectChanged())); connect(this, SIGNAL(shadowChanged()), corona(), SIGNAL(availableScreenRectChanged()));
rootContext()->setContextProperty(QStringLiteral("dock"), this); rootContext()->setContextProperty(QStringLiteral("dock"), this);
auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (dockCorona) {
rootContext()->setContextProperty(QStringLiteral("globalSettings"), dockCorona->globalSettings());
}
setSource(corona()->kPackage().filePath("lattedockui")); setSource(corona()->kPackage().filePath("lattedockui"));
setVisible(true); setVisible(true);
syncGeometry(); syncGeometry();
@ -697,16 +703,6 @@ int DockView::docksWithTasks()
return dockCorona->noDocksWithTasks(); return dockCorona->noDocksWithTasks();
} }
QAction *DockView::altSessionAction() const
{
auto dockCorona = qobject_cast<DockCorona *>(corona());
if (!dockCorona)
return 0;
return dockCorona->altSessionAction();
}
void DockView::updateFormFactor() void DockView::updateFormFactor()
{ {
if (!this->containment()) if (!this->containment())
@ -819,26 +815,6 @@ void DockView::setRunningSession(Dock::SessionType session)
} }
} }
bool DockView::exposeAltSession() const
{
auto *dockCorona = qobject_cast<DockCorona *>(corona());
if (dockCorona) {
return dockCorona->exposeAltSession();
}
return false;
}
void DockView::setExposeAltSession(bool state)
{
auto *dockCorona = qobject_cast<DockCorona *>(corona());
if (dockCorona && dockCorona->exposeAltSession() != state) {
dockCorona->setExposeAltSession(state);
}
}
float DockView::maxLength() const float DockView::maxLength() const
{ {
return m_maxLength; return m_maxLength;
@ -1424,9 +1400,9 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
} else { } else {
auto *dockCorona = qobject_cast<DockCorona *>(this->corona()); auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (dockCorona && exposeAltSession()) { if (dockCorona && dockCorona->globalSettings()->exposeAltSession()) {
desktopMenu->addSeparator(); desktopMenu->addSeparator();
desktopMenu->addAction(dockCorona->altSessionAction()); desktopMenu->addAction(dockCorona->globalSettings()->altSessionAction());
} }
desktopMenu->addActions(actions); desktopMenu->addActions(actions);

@ -47,7 +47,6 @@ class DockView : public PlasmaQuick::ContainmentView {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool drawShadows READ drawShadows WRITE setDrawShadows NOTIFY drawShadowsChanged) Q_PROPERTY(bool drawShadows READ drawShadows WRITE setDrawShadows NOTIFY drawShadowsChanged)
Q_PROPERTY(bool drawEffects READ drawEffects WRITE setDrawEffects NOTIFY drawEffectsChanged) 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(bool onPrimary READ onPrimary WRITE setOnPrimary NOTIFY onPrimaryChanged)
Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) 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(VisibilityManager *visibility READ visibility NOTIFY visibilityChanged)
Q_PROPERTY(QQmlListProperty<QScreen> screens READ screens) Q_PROPERTY(QQmlListProperty<QScreen> screens READ screens)
Q_PROPERTY(QAction *altSessionAction READ altSessionAction NOTIFY altSessionActionChanged)
Q_PROPERTY(QRect effectsArea READ effectsArea WRITE setEffectsArea NOTIFY effectsAreaChanged) Q_PROPERTY(QRect effectsArea READ effectsArea WRITE setEffectsArea NOTIFY effectsAreaChanged)
Q_PROPERTY(QRect localGeometry READ localGeometry WRITE setLocalGeometry NOTIFY localGeometryChanged) Q_PROPERTY(QRect localGeometry READ localGeometry WRITE setLocalGeometry NOTIFY localGeometryChanged)
Q_PROPERTY(QRect maskArea READ maskArea WRITE setMaskArea NOTIFY maskAreaChanged) Q_PROPERTY(QRect maskArea READ maskArea WRITE setMaskArea NOTIFY maskAreaChanged)
@ -103,9 +100,6 @@ public:
bool drawEffects() const; bool drawEffects() const;
void setDrawEffects(bool draw); void setDrawEffects(bool draw);
bool exposeAltSession() const;
void setExposeAltSession(bool state);
float maxLength() const; float maxLength() const;
void setMaxLength(float length); void setMaxLength(float length);
@ -130,7 +124,6 @@ public:
QRect absGeometry() const; QRect absGeometry() const;
QRect screenGeometry() const; QRect screenGeometry() const;
QAction *altSessionAction() const;
Latte::Dock::SessionType runningSession() const; Latte::Dock::SessionType runningSession() const;
void setRunningSession(Latte::Dock::SessionType session); void setRunningSession(Latte::Dock::SessionType session);
@ -181,7 +174,6 @@ signals:
void eventTriggered(QEvent *ev); void eventTriggered(QEvent *ev);
void alignmentChanged(); void alignmentChanged();
void altSessionActionChanged();
void currentScreenChanged(); void currentScreenChanged();
void dockLocationChanged(); void dockLocationChanged();
void docksCountChanged(); void docksCountChanged();
@ -189,7 +181,6 @@ signals:
void drawEffectsChanged(); void drawEffectsChanged();
void effectsAreaChanged(); void effectsAreaChanged();
void enabledBordersChanged(); void enabledBordersChanged();
void exposeAltSessionChanged();
void widthChanged(); void widthChanged();
void heightChanged(); void heightChanged();
void localGeometryChanged(); void localGeometryChanged();

@ -0,0 +1,89 @@
#include "globalsettings.h"
#include <QIcon>
#include <QDebug>
#include <KLocalizedString>
namespace Latte {
GlobalSettings::GlobalSettings(QObject *parent)
: QObject(parent)
{
m_corona = qobject_cast<DockCorona *>(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"

@ -0,0 +1,71 @@
/*
* Copyright 2016 Smith AR <audoban@openmailbox.org>
* Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef GLOBALSETTINGS_H
#define GLOBALSETTINGS_H
#include "dockcorona.h"
#include "../liblattedock/dock.h"
#include <KConfigGroup>
#include <KSharedConfig>
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

@ -55,7 +55,8 @@ DragDrop.DropArea {
&& (plasmoid.configuration.panelPosition === Latte.Dock.Justify) && !root.solidPanel && (plasmoid.configuration.panelPosition === Latte.Dock.Justify) && !root.solidPanel
property bool editMode: plasmoid.userConfiguring 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 immutable: plasmoid.immutable
property bool inStartup: true property bool inStartup: true
property bool isHorizontal: plasmoid.formFactor === PlasmaCore.Types.Horizontal property bool isHorizontal: plasmoid.formFactor === PlasmaCore.Types.Horizontal
@ -161,8 +162,9 @@ DragDrop.DropArea {
property Item latteAppletContainer property Item latteAppletContainer
property Item latteApplet property Item latteApplet
property QtObject dock 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; // TO BE DELETED, if not needed: property int counter:0;

@ -92,10 +92,10 @@ PlasmaComponents.Page {
PlasmaComponents.CheckBox { PlasmaComponents.CheckBox {
Layout.leftMargin: units.smallSpacing * 2 Layout.leftMargin: units.smallSpacing * 2
text: i18n("Expose Alternative Session in the context menu") text: i18n("Expose Alternative Session in the context menu")
checked: dock.exposeAltSession checked: globalSettings.exposeAltSession
onClicked: { onClicked: {
dock.exposeAltSession = checked; globalSettings.exposeAltSession = checked;
} }
} }

@ -86,6 +86,7 @@ PlasmaCore.FrameSvgItem {
if (containment.children[i].objectName === "dockLayoutView") { if (containment.children[i].objectName === "dockLayoutView") {
dockLayout = containment.children[i]; dockLayout = containment.children[i];
dockLayout.dock = dock; dockLayout.dock = dock;
dockLayout.globalSettings = globalSettings;
} }
} }
} }

Loading…
Cancel
Save