2021-01-29 11:43:07 +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>
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-01-26 14:31:56 +08:00
|
|
|
|
|
2021-01-04 14:21:45 +08:00
|
|
|
|
#include "global-settings.h"
|
2024-01-26 14:31:56 +08:00
|
|
|
|
#include "global-settings-private.h"
|
|
|
|
|
#include <QPalette>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDBusReply>
|
|
|
|
|
#include <QDebug>
|
2020-12-28 20:29:13 +08:00
|
|
|
|
|
2024-01-26 14:31:56 +08:00
|
|
|
|
#define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise"
|
|
|
|
|
#define THEME_GSETTINGS_ID "org.ukui.style"
|
2021-01-03 16:58:26 +08:00
|
|
|
|
|
2024-01-26 14:31:56 +08:00
|
|
|
|
using namespace UkuiSearch;
|
2021-01-03 16:58:26 +08:00
|
|
|
|
|
2024-01-26 14:31:56 +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);
|
2021-04-26 15:06:47 +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) {
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(key == TRANSPARENCY_KEY) {
|
2024-01-26 14:31:56 +08:00
|
|
|
|
double transparency = m_transGsettings->get(TRANSPARENCY_KEY).toDouble();
|
|
|
|
|
setValue(TRANSPARENCY_KEY, transparency);
|
2021-01-04 14:21:45 +08:00
|
|
|
|
qApp->paletteChanged(qApp->palette());
|
2024-01-26 14:31:56 +08:00
|
|
|
|
Q_EMIT this->valueChanged(TRANSPARENCY_KEY, transparency);
|
2021-01-04 14:21:45 +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());
|
|
|
|
|
}
|
2021-04-13 15:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 18:11:55 +08:00
|
|
|
|
//主题,字体大小
|
|
|
|
|
setValue(STYLE_NAME_KEY, "ukui-light");
|
|
|
|
|
setValue(FONT_SIZE_KEY, 11);
|
2021-04-26 15:06:47 +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) {
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(key == STYLE_NAME_KEY) {
|
2021-04-13 15:40:19 +08:00
|
|
|
|
//当前主题改变时也发出paletteChanged信号,通知主界面刷新
|
2022-11-28 18:11:55 +08:00
|
|
|
|
setValue(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
|
2021-04-20 16:24:07 +08:00
|
|
|
|
qApp->paletteChanged(qApp->palette());
|
2024-01-26 14:31:56 +08:00
|
|
|
|
Q_EMIT this->valueChanged(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
|
2021-06-11 11:45:07 +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());
|
2021-06-11 11:45:07 +08:00
|
|
|
|
qApp->paletteChanged(qApp->palette());
|
2021-05-12 15:58:38 +08:00
|
|
|
|
} else if (key == ICON_THEME_KEY) {
|
|
|
|
|
qApp->paletteChanged(qApp->palette());
|
2021-04-13 15:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
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());
|
|
|
|
|
}
|
2021-01-04 14:21:45 +08:00
|
|
|
|
}
|
2021-01-03 16:58:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 14:31:56 +08:00
|
|
|
|
const QVariant GlobalSettingsPrivate::getValue(const QString &key) {
|
2021-01-03 16:58:26 +08:00
|
|
|
|
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_mutex.lock();
|
|
|
|
|
QVariant value = m_cache.value(key);
|
|
|
|
|
m_mutex.unlock();
|
|
|
|
|
return value;
|
2021-01-03 16:58:26 +08:00
|
|
|
|
}
|
2020-12-28 20:29:13 +08:00
|
|
|
|
|
2021-05-13 11:17:07 +08:00
|
|
|
|
//this method is designed for main process settings only!!
|
2024-01-26 14:31:56 +08:00
|
|
|
|
void GlobalSettingsPrivate::setValue(const QString &key, const QVariant &value) {
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_mutex.lock();
|
2021-01-03 16:58:26 +08:00
|
|
|
|
m_cache.insert(key, value);
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_mutex.unlock();
|
2020-12-28 20:29:13 +08:00
|
|
|
|
}
|
2021-03-30 09:23:57 +08:00
|
|
|
|
|
2024-01-26 14:31:56 +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);
|
2021-03-30 09:23:57 +08:00
|
|
|
|
}
|