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 configviewpull/1/head
parent
7b060c22a5
commit
e57d525824
@ -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
|
Loading…
Reference in New Issue