mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-14 09:18:06 +03:00
118 lines
3.0 KiB
C++
118 lines
3.0 KiB
C++
/*
|
|
* Copyright 2017 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/>.
|
|
*/
|
|
|
|
#include "universalsettings.h"
|
|
|
|
namespace Latte {
|
|
|
|
UniversalSettings::UniversalSettings(KSharedConfig::Ptr config, QObject *parent)
|
|
: QObject(parent),
|
|
m_config(config),
|
|
m_universalGroup(KConfigGroup(config, QStringLiteral("UniversalSettings")))
|
|
{
|
|
connect(this, &UniversalSettings::currentLayoutNameChanged, this, &UniversalSettings::saveConfig);
|
|
connect(this, &UniversalSettings::versionChanged, this, &UniversalSettings::saveConfig);
|
|
connect(this, &UniversalSettings::exposeLayoutsMenuChanged, this, &UniversalSettings::saveConfig);
|
|
}
|
|
|
|
UniversalSettings::~UniversalSettings()
|
|
{
|
|
saveConfig();
|
|
cleanupSettings();
|
|
}
|
|
|
|
void UniversalSettings::load()
|
|
{
|
|
loadConfig();
|
|
}
|
|
|
|
bool UniversalSettings::exposeLayoutsMenu() const
|
|
{
|
|
return m_exposeLayoutsMenu;
|
|
}
|
|
|
|
void UniversalSettings::setExposeLayoutsMenu(bool state)
|
|
{
|
|
if (m_exposeLayoutsMenu == state) {
|
|
return;
|
|
}
|
|
|
|
m_exposeLayoutsMenu = state;
|
|
emit exposeLayoutsMenuChanged();
|
|
}
|
|
|
|
|
|
int UniversalSettings::version() const
|
|
{
|
|
return m_version;
|
|
}
|
|
|
|
void UniversalSettings::setVersion(int ver)
|
|
{
|
|
if (m_version == ver) {
|
|
return;
|
|
}
|
|
|
|
m_version = ver;
|
|
|
|
emit versionChanged();
|
|
}
|
|
|
|
QString UniversalSettings::currentLayoutName() const
|
|
{
|
|
return m_currentLayoutName;
|
|
}
|
|
|
|
void UniversalSettings::setCurrentLayoutName(QString layoutName)
|
|
{
|
|
if (m_currentLayoutName == layoutName) {
|
|
return;
|
|
}
|
|
|
|
m_currentLayoutName = layoutName;
|
|
emit currentLayoutNameChanged();
|
|
}
|
|
|
|
void UniversalSettings::loadConfig()
|
|
{
|
|
m_version = m_universalGroup.readEntry("version", 1);
|
|
m_exposeLayoutsMenu = m_universalGroup.readEntry("exposeLayoutsMenu", false);
|
|
m_currentLayoutName = m_universalGroup.readEntry("currentLayout", QString());
|
|
}
|
|
|
|
void UniversalSettings::saveConfig()
|
|
{
|
|
m_universalGroup.writeEntry("version", m_version);
|
|
m_universalGroup.writeEntry("exposeLayoutsMenu", m_exposeLayoutsMenu);
|
|
m_universalGroup.writeEntry("currentLayout", m_currentLayoutName);
|
|
|
|
m_universalGroup.sync();
|
|
}
|
|
|
|
void UniversalSettings::cleanupSettings()
|
|
{
|
|
KConfigGroup containments = KConfigGroup(m_config, QStringLiteral("Containments"));
|
|
containments.deleteGroup();
|
|
|
|
containments.sync();
|
|
}
|
|
|
|
}
|