2022-06-18 10:46:14 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Authors: zhangzihao <zhangzihao@kylinos.cn>
|
|
|
|
|
* Modified by: zhangpengfei <zhangpengfei@kylinos.cn>
|
|
|
|
|
*
|
|
|
|
|
*/
|
2023-05-31 17:59:20 +08:00
|
|
|
|
|
2022-06-18 10:46:14 +08:00
|
|
|
|
#include "global-settings.h"
|
2023-05-31 17:59:20 +08:00
|
|
|
|
#include "global-settings-private.h"
|
|
|
|
|
#include <QPalette>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDBusReply>
|
|
|
|
|
#include <QDebug>
|
2022-06-18 10:46:14 +08:00
|
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
|
#define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise"
|
|
|
|
|
#define THEME_GSETTINGS_ID "org.ukui.style"
|
2022-06-18 10:46:14 +08:00
|
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
|
using namespace UkuiSearch;
|
2022-06-18 10:46:14 +08:00
|
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
|
GlobalSettingsPrivate::GlobalSettingsPrivate(QObject *parent) : QObject(parent)
|
2022-11-28 18:11:55 +08:00
|
|
|
|
{
|
|
|
|
|
//全局页面透明度
|
|
|
|
|
//the default number of transparency for mainwindow is 0.7
|
|
|
|
|
setValue(TRANSPARENCY_KEY, 0.7);
|
2022-06-18 10:46:14 +08:00
|
|
|
|
if(QGSettings::isSchemaInstalled(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID)) {
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_transGsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this);
|
|
|
|
|
connect(m_transGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
2022-06-18 10:46:14 +08:00
|
|
|
|
if(key == TRANSPARENCY_KEY) {
|
2023-05-31 17:59:20 +08:00
|
|
|
|
double transparency = m_transGsettings->get(TRANSPARENCY_KEY).toDouble();
|
|
|
|
|
setValue(TRANSPARENCY_KEY, transparency);
|
2022-06-18 10:46:14 +08:00
|
|
|
|
qApp->paletteChanged(qApp->palette());
|
2023-05-31 17:59:20 +08:00
|
|
|
|
Q_EMIT this->valueChanged(TRANSPARENCY_KEY, transparency);
|
2022-06-18 10:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2022-11-28 18:11:55 +08:00
|
|
|
|
if(m_transGsettings->keys().contains(TRANSPARENCY_KEY)) {
|
|
|
|
|
setValue(TRANSPARENCY_KEY, m_transGsettings->get(TRANSPARENCY_KEY).toDouble());
|
|
|
|
|
}
|
2022-06-18 10:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 18:11:55 +08:00
|
|
|
|
//主题,字体大小
|
|
|
|
|
setValue(STYLE_NAME_KEY, "ukui-light");
|
|
|
|
|
setValue(FONT_SIZE_KEY, 11);
|
2022-06-18 10:46:14 +08:00
|
|
|
|
if(QGSettings::isSchemaInstalled(THEME_GSETTINGS_ID)) {
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_themeGsettings = new QGSettings(THEME_GSETTINGS_ID, QByteArray(), this);
|
|
|
|
|
connect(m_themeGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
2022-06-18 10:46:14 +08:00
|
|
|
|
if(key == STYLE_NAME_KEY) {
|
|
|
|
|
//当前主题改变时也发出paletteChanged信号,通知主界面刷新
|
2022-11-28 18:11:55 +08:00
|
|
|
|
setValue(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
|
2022-06-18 10:46:14 +08:00
|
|
|
|
qApp->paletteChanged(qApp->palette());
|
2023-05-31 17:59:20 +08:00
|
|
|
|
Q_EMIT this->valueChanged(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
|
2022-06-18 10:46:14 +08:00
|
|
|
|
} else if(key == FONT_SIZE_KEY) {
|
2022-11-28 18:11:55 +08:00
|
|
|
|
setValue(FONT_SIZE_KEY, m_themeGsettings->get(FONT_SIZE_KEY).toDouble());
|
2022-06-18 10:46:14 +08:00
|
|
|
|
qApp->paletteChanged(qApp->palette());
|
|
|
|
|
} else if (key == ICON_THEME_KEY) {
|
|
|
|
|
qApp->paletteChanged(qApp->palette());
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-11-28 18:11:55 +08:00
|
|
|
|
if(m_themeGsettings->keys().contains(STYLE_NAME_KEY)) {
|
|
|
|
|
setValue(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
|
|
|
|
|
}
|
|
|
|
|
if(m_themeGsettings->keys().contains(FONT_SIZE_KEY)) {
|
|
|
|
|
setValue(FONT_SIZE_KEY, m_themeGsettings->get(FONT_SIZE_KEY).toDouble());
|
|
|
|
|
}
|
2022-06-18 10:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
|
const QVariant GlobalSettingsPrivate::getValue(const QString &key) {
|
2022-06-18 10:46:14 +08:00
|
|
|
|
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_mutex.lock();
|
|
|
|
|
QVariant value = m_cache.value(key);
|
|
|
|
|
m_mutex.unlock();
|
|
|
|
|
return value;
|
2022-06-18 10:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//this method is designed for main process settings only!!
|
2023-05-31 17:59:20 +08:00
|
|
|
|
void GlobalSettingsPrivate::setValue(const QString &key, const QVariant &value) {
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_mutex.lock();
|
2022-06-18 10:46:14 +08:00
|
|
|
|
m_cache.insert(key, value);
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_mutex.unlock();
|
2022-06-18 10:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 17:59:20 +08:00
|
|
|
|
GlobalSettings &GlobalSettings::getInstance() {
|
|
|
|
|
static GlobalSettings instance;
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QVariant GlobalSettings::getValue(const QString& key)
|
|
|
|
|
{
|
|
|
|
|
return d->getValue(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent), d(new GlobalSettingsPrivate(this))
|
|
|
|
|
{
|
|
|
|
|
connect(d, &GlobalSettingsPrivate::valueChanged, this, &GlobalSettings::valueChanged);
|
2022-06-18 10:46:14 +08:00
|
|
|
|
}
|