mirror of https://github.com/cutefishos/settings
refactor(settings): move appearance and wallpaper to the framework
parent
4d91953904
commit
384a6723bd
@ -1,215 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: revenmartin <revenmartin@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "appearance.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Appearance::Appearance(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_interface("com.cutefish.Services",
|
||||
"/com/cutefish/Services/Appearance",
|
||||
"com.cutefish.Services.Appearance",
|
||||
QDBusConnection::sessionBus())
|
||||
, m_dockSettings(new QSettings(QSettings::UserScope, "cutefishos", "dock"))
|
||||
, m_dockIconSize(0)
|
||||
, m_dockDirection(0)
|
||||
, m_dockVisibility(0)
|
||||
, m_fontPointSize(11)
|
||||
{
|
||||
m_dockIconSize = m_dockSettings->value("IconSize").toInt();
|
||||
m_dockDirection = m_dockSettings->value("Direction").toInt();
|
||||
m_dockVisibility = m_dockSettings->value("Visibility").toInt();
|
||||
m_dockRoundedWindow = m_dockSettings->value("RoundedWindow").toBool();
|
||||
// Dock only supports the centered style. Migrate old Full style settings.
|
||||
m_dockSettings->setValue("Style", 0);
|
||||
|
||||
// Init
|
||||
if (m_interface.isValid()) {
|
||||
m_fontPointSize = m_interface.property("systemFontPointSize").toInt();
|
||||
|
||||
connect(&m_interface, SIGNAL(darkModeDimsWallpaerChanged()), this, SIGNAL(dimsWallpaperChanged()));
|
||||
connect(&m_interface, SIGNAL(blurEnabledChanged()), this, SIGNAL(blurEnabledChanged()));
|
||||
}
|
||||
}
|
||||
|
||||
void Appearance::switchDarkMode(bool darkMode)
|
||||
{
|
||||
if (m_interface.isValid()) {
|
||||
m_interface.call("setDarkMode", darkMode);
|
||||
}
|
||||
}
|
||||
|
||||
bool Appearance::dimsWallpaper() const
|
||||
{
|
||||
return m_interface.property("darkModeDimsWallpaer").toBool();
|
||||
}
|
||||
|
||||
void Appearance::setDimsWallpaper(bool value)
|
||||
{
|
||||
m_interface.call("setDarkModeDimsWallpaer", value);
|
||||
}
|
||||
|
||||
bool Appearance::blurEnabled() const
|
||||
{
|
||||
return m_interface.property("blurEnabled").toBool();
|
||||
}
|
||||
|
||||
void Appearance::setBlurEnabled(bool value)
|
||||
{
|
||||
m_interface.call("setBlurEnabled", value);
|
||||
}
|
||||
|
||||
int Appearance::dockIconSize() const
|
||||
{
|
||||
return m_dockIconSize;
|
||||
}
|
||||
|
||||
void Appearance::setDockIconSize(int dockIconSize)
|
||||
{
|
||||
if (m_dockIconSize != dockIconSize) {
|
||||
QDBusInterface iface("com.cutefish.Dock",
|
||||
"/Dock",
|
||||
"com.cutefish.Dock",
|
||||
QDBusConnection::sessionBus());
|
||||
if (iface.isValid()) {
|
||||
iface.call("setIconSize", dockIconSize);
|
||||
}
|
||||
|
||||
m_dockIconSize = dockIconSize;
|
||||
emit dockIconSizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int Appearance::dockDirection() const
|
||||
{
|
||||
return m_dockDirection;
|
||||
}
|
||||
|
||||
void Appearance::setDockDirection(int dockDirection)
|
||||
{
|
||||
if (m_dockDirection != dockDirection) {
|
||||
QDBusInterface iface("com.cutefish.Dock",
|
||||
"/Dock",
|
||||
"com.cutefish.Dock",
|
||||
QDBusConnection::sessionBus());
|
||||
if (iface.isValid()) {
|
||||
iface.call("setDirection", dockDirection);
|
||||
}
|
||||
|
||||
m_dockDirection = dockDirection;
|
||||
emit dockDirectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int Appearance::dockVisibility() const
|
||||
{
|
||||
return m_dockVisibility;
|
||||
}
|
||||
|
||||
void Appearance::setDockVisibility(int visibility)
|
||||
{
|
||||
if (m_dockVisibility != visibility) {
|
||||
m_dockVisibility = visibility;
|
||||
|
||||
QDBusInterface iface("com.cutefish.Dock",
|
||||
"/Dock",
|
||||
"com.cutefish.Dock",
|
||||
QDBusConnection::sessionBus());
|
||||
if (iface.isValid()) {
|
||||
iface.call("setVisibility", visibility);
|
||||
}
|
||||
|
||||
emit dockVisibilityChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int Appearance::dockRoundedWindow() const
|
||||
{
|
||||
return m_dockRoundedWindow;
|
||||
}
|
||||
|
||||
void Appearance::setDockRoundedWindow(bool enable)
|
||||
{
|
||||
if (m_dockRoundedWindow == enable)
|
||||
return;
|
||||
|
||||
m_dockRoundedWindow = enable;
|
||||
m_dockSettings->setValue("RoundedWindow", m_dockRoundedWindow);
|
||||
}
|
||||
|
||||
void Appearance::setGenericFontFamily(const QString &name)
|
||||
{
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
QDBusInterface iface("com.cutefish.Services",
|
||||
"/com/cutefish/Services/Appearance",
|
||||
"com.cutefish.Services.Appearance",
|
||||
QDBusConnection::sessionBus(), this);
|
||||
if (iface.isValid()) {
|
||||
iface.call("setSystemFont", name);
|
||||
}
|
||||
}
|
||||
|
||||
void Appearance::setFixedFontFamily(const QString &name)
|
||||
{
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
QDBusInterface iface("com.cutefish.Services",
|
||||
"/com/cutefish/Services/Appearance",
|
||||
"com.cutefish.Services.Appearance",
|
||||
QDBusConnection::sessionBus(), this);
|
||||
if (iface.isValid()) {
|
||||
iface.call("setSystemFixedFont", name);
|
||||
}
|
||||
}
|
||||
|
||||
int Appearance::fontPointSize() const
|
||||
{
|
||||
return m_fontPointSize;
|
||||
}
|
||||
|
||||
void Appearance::setFontPointSize(int fontPointSize)
|
||||
{
|
||||
m_fontPointSize = fontPointSize;
|
||||
|
||||
QDBusInterface iface("com.cutefish.Services",
|
||||
"/com/cutefish/Services/Appearance",
|
||||
"com.cutefish.Services.Appearance",
|
||||
QDBusConnection::sessionBus(), this);
|
||||
if (iface.isValid()) {
|
||||
iface.call("setSystemFontPointSize", m_fontPointSize * 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
void Appearance::setAccentColor(int accentColor)
|
||||
{
|
||||
QDBusInterface iface("com.cutefish.Services",
|
||||
"/com/cutefish/Services/Appearance",
|
||||
"com.cutefish.Services.Appearance",
|
||||
QDBusConnection::sessionBus(), this);
|
||||
if (iface.isValid()) {
|
||||
iface.call("setAccentColor", accentColor);
|
||||
}
|
||||
}
|
||||
@ -1,81 +0,0 @@
|
||||
#include "background.h"
|
||||
#include <QtConcurrent>
|
||||
|
||||
static QVariantList getBackgroundPaths()
|
||||
{
|
||||
QVariantList list;
|
||||
QDirIterator it("/usr/share/backgrounds/cutefishos", QStringList() << "*.jpg" << "*.png", QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString bg = it.next();
|
||||
list.append(QVariant(bg));
|
||||
}
|
||||
std::sort(list.begin(), list.end(), [](const QVariant &left, const QVariant &right) {
|
||||
return left.toString() < right.toString();
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
Background::Background(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_interface("com.cutefish.Services",
|
||||
"/com/cutefish/Services/Appearance",
|
||||
"com.cutefish.Services.Appearance",
|
||||
QDBusConnection::sessionBus(), this)
|
||||
{
|
||||
if (m_interface.isValid()) {
|
||||
m_currentPath = m_interface.property("wallpaper").toString();
|
||||
|
||||
QDBusConnection::sessionBus().connect(m_interface.service(),
|
||||
m_interface.path(),
|
||||
m_interface.interface(),
|
||||
"backgroundTypeChanged", this, SIGNAL(backgroundTypeChanged()));
|
||||
QDBusConnection::sessionBus().connect(m_interface.service(),
|
||||
m_interface.path(),
|
||||
m_interface.interface(),
|
||||
"backgroundColorChanged", this, SIGNAL(backgroundColorChanged()));
|
||||
}
|
||||
}
|
||||
|
||||
QVariantList Background::backgrounds()
|
||||
{
|
||||
QFuture<QVariantList> future = QtConcurrent::run(&getBackgroundPaths);
|
||||
QVariantList list = future.result();
|
||||
return list;
|
||||
}
|
||||
|
||||
QString Background::currentBackgroundPath()
|
||||
{
|
||||
return m_currentPath;
|
||||
}
|
||||
|
||||
void Background::setBackground(QString path)
|
||||
{
|
||||
if (m_currentPath != path && !path.isEmpty()) {
|
||||
m_currentPath = path;
|
||||
|
||||
if (m_interface.isValid()) {
|
||||
m_interface.call("setWallpaper", path);
|
||||
emit backgroundChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Background::backgroundType()
|
||||
{
|
||||
return m_interface.property("backgroundType").toInt();
|
||||
}
|
||||
|
||||
void Background::setBackgroundType(int type)
|
||||
{
|
||||
m_interface.call("setBackgroundType", QVariant::fromValue(type));
|
||||
}
|
||||
|
||||
QString Background::backgroundColor()
|
||||
{
|
||||
return m_interface.property("backgroundColor").toString();
|
||||
}
|
||||
|
||||
void Background::setBackgroundColor(const QString &color)
|
||||
{
|
||||
m_interface.call("setBackgroundColor", QVariant::fromValue(color));
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
#ifndef BACKGROUND_H
|
||||
#define BACKGROUND_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusConnection>
|
||||
#include <QDirIterator>
|
||||
#include <QDir>
|
||||
|
||||
class Background : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString currentBackgroundPath READ currentBackgroundPath WRITE setBackground NOTIFY backgroundChanged)
|
||||
Q_PROPERTY(QVariantList backgrounds READ backgrounds NOTIFY stub)
|
||||
|
||||
Q_PROPERTY(int backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged)
|
||||
Q_PROPERTY(QString backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
|
||||
|
||||
public:
|
||||
explicit Background(QObject *parent = nullptr);
|
||||
|
||||
QVariantList backgrounds();
|
||||
QString currentBackgroundPath();
|
||||
Q_INVOKABLE void setBackground(QString newBackgroundPath);
|
||||
|
||||
int backgroundType();
|
||||
void setBackgroundType(int type);
|
||||
|
||||
QString backgroundColor();
|
||||
void setBackgroundColor(const QString &color);
|
||||
|
||||
signals:
|
||||
void backgroundChanged();
|
||||
void backgroundColorChanged();
|
||||
void backgroundTypeChanged();
|
||||
void stub();
|
||||
|
||||
private:
|
||||
QDBusInterface m_interface;
|
||||
QString m_currentPath;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: revenmartin <revenmartin@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "docksettings.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
|
||||
DockSettings::DockSettings(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_dockSettings(new QSettings(QSettings::UserScope, "cutefishos", "dock"))
|
||||
, m_dockIconSize(0)
|
||||
, m_dockDirection(0)
|
||||
, m_dockVisibility(0)
|
||||
{
|
||||
m_dockIconSize = m_dockSettings->value("IconSize").toInt();
|
||||
m_dockDirection = m_dockSettings->value("Direction").toInt();
|
||||
m_dockVisibility = m_dockSettings->value("Visibility").toInt();
|
||||
m_dockRoundedWindow = m_dockSettings->value("RoundedWindow").toBool();
|
||||
// Dock only supports the centered style. Migrate old Full style settings.
|
||||
m_dockSettings->setValue("Style", 0);
|
||||
}
|
||||
|
||||
int DockSettings::dockIconSize() const
|
||||
{
|
||||
return m_dockIconSize;
|
||||
}
|
||||
|
||||
void DockSettings::setDockIconSize(int dockIconSize)
|
||||
{
|
||||
if (m_dockIconSize != dockIconSize) {
|
||||
QDBusInterface iface("com.cutefish.Dock",
|
||||
"/Dock",
|
||||
"com.cutefish.Dock",
|
||||
QDBusConnection::sessionBus());
|
||||
if (iface.isValid()) {
|
||||
iface.call("setIconSize", dockIconSize);
|
||||
}
|
||||
|
||||
m_dockIconSize = dockIconSize;
|
||||
emit dockIconSizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int DockSettings::dockDirection() const
|
||||
{
|
||||
return m_dockDirection;
|
||||
}
|
||||
|
||||
void DockSettings::setDockDirection(int dockDirection)
|
||||
{
|
||||
if (m_dockDirection != dockDirection) {
|
||||
QDBusInterface iface("com.cutefish.Dock",
|
||||
"/Dock",
|
||||
"com.cutefish.Dock",
|
||||
QDBusConnection::sessionBus());
|
||||
if (iface.isValid()) {
|
||||
iface.call("setDirection", dockDirection);
|
||||
}
|
||||
|
||||
m_dockDirection = dockDirection;
|
||||
emit dockDirectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int DockSettings::dockVisibility() const
|
||||
{
|
||||
return m_dockVisibility;
|
||||
}
|
||||
|
||||
void DockSettings::setDockVisibility(int visibility)
|
||||
{
|
||||
if (m_dockVisibility != visibility) {
|
||||
m_dockVisibility = visibility;
|
||||
|
||||
QDBusInterface iface("com.cutefish.Dock",
|
||||
"/Dock",
|
||||
"com.cutefish.Dock",
|
||||
QDBusConnection::sessionBus());
|
||||
if (iface.isValid()) {
|
||||
iface.call("setVisibility", visibility);
|
||||
}
|
||||
|
||||
emit dockVisibilityChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int DockSettings::dockRoundedWindow() const
|
||||
{
|
||||
return m_dockRoundedWindow;
|
||||
}
|
||||
|
||||
void DockSettings::setDockRoundedWindow(bool enable)
|
||||
{
|
||||
if (m_dockRoundedWindow == enable)
|
||||
return;
|
||||
|
||||
m_dockRoundedWindow = enable;
|
||||
m_dockSettings->setValue("RoundedWindow", m_dockRoundedWindow);
|
||||
}
|
||||
Loading…
Reference in New Issue