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
alternativeshelper.cpp
screenpool.cpp
globalsettings.cpp
main.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<DockCorona *>(m_dockView->corona());
if (dockCorona) {
rootContext()->setContextProperty(QStringLiteral("globalSettings"), dockCorona->globalSettings());
}
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
kdeclarative.setTranslationDomain(QStringLiteral("latte-dock"));

@ -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<QScreen>();

@ -22,6 +22,7 @@
#define DOCKCORONA_H
#include "dockview.h"
#include "globalsettings.h"
#include "../liblattedock/dock.h"
#include <QObject>
@ -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<const Plasma::Containment *, DockView *> m_dockViews;
QHash<const Plasma::Containment *, DockView *> m_waitingDockViews;
QList<KDeclarative::QmlObject *> m_alternativesObjects;
@ -150,6 +141,7 @@ private:
QPointer<KAboutApplicationDialog> aboutDialog;
ScreenPool *m_screenPool;
GlobalSettings *m_globalSettings;
};
}

@ -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 <QAction>
@ -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<DockCorona *>(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<DockCorona *>(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<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
{
return m_maxLength;
@ -1424,9 +1400,9 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
} else {
auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (dockCorona && exposeAltSession()) {
if (dockCorona && dockCorona->globalSettings()->exposeAltSession()) {
desktopMenu->addSeparator();
desktopMenu->addAction(dockCorona->altSessionAction());
desktopMenu->addAction(dockCorona->globalSettings()->altSessionAction());
}
desktopMenu->addActions(actions);

@ -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<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 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();

@ -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
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;

@ -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;
}
}

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

Loading…
Cancel
Save