1#include "thememanager.h"
3#include "settingsstore.h"
4#include "mauimanutils.h"
8#if !defined Q_OS_ANDROID
9#include <QDBusInterface>
17 qDebug(
" INIT THEME MANAGER");
19#if !defined Q_OS_ANDROID
21 if(server->serverRunning())
23 this->setConnections();
26 connect(server, &MauiManUtils::serverRunningChanged, [
this](
bool state)
28 qDebug() <<
"THEMEMANAGER MauiMan server running? " << state;
32 this->setConnections();
33 qDebug() <<
"THEMEMANAGER MauiMan server running? " << state << m_interface->isValid();
46#if !defined Q_OS_ANDROID
47 if (m_interface && m_interface->
isValid())
49 m_interface->
call(key, value);
57void ThemeManager::setConnections()
59#if !defined Q_OS_ANDROID
64 m_interface =
nullptr;
67 m_interface =
new QDBusInterface (QStringLiteral(
"org.mauiman.Manager"),
68 QStringLiteral(
"/Theme"),
69 QStringLiteral(
"org.mauiman.Theme"),
76 connect(m_interface, SIGNAL(windowControlsThemeChanged(
QString)),
this, SLOT(onWindowControlsThemeChanged(
QString)));
77 connect(m_interface, SIGNAL(styleTypeChanged(
int)),
this, SLOT(onStyleTypeChanged(
int)));
78 connect(m_interface, SIGNAL(enableCSDChanged(
bool)),
this, SLOT(onEnableCSDChanged(
bool)));
79 connect(m_interface, SIGNAL(borderRadiusChanged(uint)),
this, SLOT(onBorderRadiusChanged(uint)));
80 connect(m_interface, SIGNAL(iconSizeChanged(uint)),
this, SLOT(onIconSizeChanged(uint)));
81 connect(m_interface, SIGNAL(paddingSizeChanged(uint)),
this, SLOT(onPaddingSizeChanged(uint)));
82 connect(m_interface, SIGNAL(marginSizeChanged(uint)),
this, SLOT(onMarginSizeChanged(uint)));
83 connect(m_interface, SIGNAL(spacingSizeChanged(uint)),
this, SLOT(onSpacingSizeChanged(uint)));
84 connect(m_interface, SIGNAL(enableEffectsChanged(
bool)),
this, SLOT(onEnableEffectsChanged(
bool)));
87 connect(m_interface, SIGNAL(monospacedFontChanged(
QString)),
this, SLOT(onMonospacedFontChanged(
QString)));
88 connect(m_interface, SIGNAL(customColorSchemeChanged(
QString)),
this, SLOT(onCustomColorSchemeChanged(
QString)));
93void ThemeManager::loadSettings()
97#if !defined Q_OS_ANDROID
98 if(m_interface && m_interface->
isValid())
103 m_windowControlsTheme = m_interface->
property(
"windowControlsTheme").
toString();
110 m_enableEffects = m_interface->
property(
"enableEffects").
toBool();
114 m_customColorScheme = m_interface->
property(
"customColorScheme").
toString();
120 m_accentColor = m_settings->
load(QStringLiteral(
"AccentColor"), m_accentColor).
toString();
121 m_styleType = m_settings->
load(QStringLiteral(
"StyleType"), m_styleType).
toInt();
122 m_iconTheme = m_settings->
load(QStringLiteral(
"IconTheme"), m_iconTheme).
toString();
123 m_windowControlsTheme = m_settings->
load(QStringLiteral(
"WindowControlsTheme"), m_windowControlsTheme).
toString();
124 m_enableCSD = m_settings->
load(QStringLiteral(
"EnableCSD"), m_enableCSD).
toBool();
125 m_borderRadius = m_settings->
load(QStringLiteral(
"BorderRadius"), m_borderRadius).
toUInt();
126 m_iconSize = m_settings->
load(QStringLiteral(
"IconSize"), m_iconSize).
toUInt();
127 m_paddingSize = m_settings->
load(QStringLiteral(
"PaddingSize"), m_paddingSize).
toUInt();
128 m_marginSize = m_settings->
load(QStringLiteral(
"MarginSize"), m_marginSize).
toUInt();
129 m_spacingSize = m_settings->
load(QStringLiteral(
"SpacingSize"), m_spacingSize).
toUInt();
130 m_enableEffects = m_settings->
load(QStringLiteral(
"EnableEffects"), m_enableEffects).
toBool();
131 m_defaultFont = m_settings->
load(QStringLiteral(
"DefaultFont"), m_defaultFont).
toString();
132 m_smallFont = m_settings->
load(QStringLiteral(
"SmallFont"), m_smallFont).
toString();
133 m_monospacedFont = m_settings->
load(QStringLiteral(
"MonospacedFont"), m_monospacedFont).
toString();
134 m_customColorScheme = m_settings->
load(QStringLiteral(
"CustomColorScheme"), m_customColorScheme).
toString();
142void ThemeManager::setStyleType(
int newStyleType)
144 if (m_styleType == newStyleType)
147 m_styleType = newStyleType;
148 m_settings->
save(QStringLiteral(
"StyleType"), m_styleType);
149 sync(QStringLiteral(
"setStyleType"), newStyleType);
150 Q_EMIT styleTypeChanged(m_styleType);
155 return m_accentColor;
158void ThemeManager::setAccentColor(
const QString &newAccentColor)
160 if (m_accentColor == newAccentColor)
163 qDebug() <<
"Setting accent color" << m_accentColor;
165 m_accentColor = newAccentColor;
166 m_settings->
save(QStringLiteral(
"AccentColor"), m_accentColor);
167 sync(QStringLiteral(
"setAccentColor"), m_accentColor);
168 Q_EMIT accentColorChanged(m_accentColor);
171void ThemeManager::resetAccentColor()
173 this->setAccentColor(ThemeManager::DefaultValues::accentColor);
181void ThemeManager::setIconTheme(
const QString &newIconTheme)
183 if (m_iconTheme == newIconTheme)
186 m_iconTheme = newIconTheme;
187 m_settings->
save(QStringLiteral(
"IconTheme"), m_iconTheme);
188 sync(QStringLiteral(
"setIconTheme"), m_iconTheme);
189 Q_EMIT iconThemeChanged(m_iconTheme);
194 return m_windowControlsTheme;
197void ThemeManager::setWindowControlsTheme(
const QString &newWindowControlsTheme)
199 if (m_windowControlsTheme == newWindowControlsTheme)
202 m_windowControlsTheme = newWindowControlsTheme;
203 m_settings->
save(QStringLiteral(
"WindowControlsTheme"), m_windowControlsTheme);
204 sync(QStringLiteral(
"setWindowControlsTheme"), m_windowControlsTheme);
205 Q_EMIT windowControlsThemeChanged(m_windowControlsTheme);
213void ThemeManager::setEnableCSD(
bool enableCSD)
219 m_settings->
save(QStringLiteral(
"EnableCSD"), m_enableCSD);
220 sync(QStringLiteral(
"setEnableCSD"), m_enableCSD);
221 Q_EMIT enableCSDChanged(m_enableCSD);
224void ThemeManager::onStyleTypeChanged(
const int &newStyleType)
226 if (m_styleType == newStyleType)
229 m_styleType = newStyleType;
230 Q_EMIT styleTypeChanged(m_styleType);
233void ThemeManager::onAccentColorChanged(
const QString &newAccentColor)
235 if (m_accentColor == newAccentColor)
238 m_accentColor = newAccentColor;
239 Q_EMIT accentColorChanged(m_accentColor);
242void ThemeManager::onWindowControlsThemeChanged(
const QString &newWindowControlsTheme)
244 if (m_windowControlsTheme == newWindowControlsTheme)
247 m_windowControlsTheme = newWindowControlsTheme;
248 Q_EMIT windowControlsThemeChanged(m_windowControlsTheme);
251void ThemeManager::onIconThemeChanged(
const QString &newIconTheme)
253 if (m_iconTheme == newIconTheme)
256 m_iconTheme = newIconTheme;
257 Q_EMIT iconThemeChanged(m_iconTheme);
260void ThemeManager::onEnableCSDChanged(
const bool &enableCSD)
266 Q_EMIT enableCSDChanged(m_enableCSD);
269void ThemeManager::onBorderRadiusChanged(
const uint &radius)
271 if (m_borderRadius == radius)
273 m_borderRadius = radius;
274 Q_EMIT borderRadiusChanged(m_borderRadius);
277void ThemeManager::onIconSizeChanged(
const uint &size)
279 if (m_iconSize == size)
282 Q_EMIT iconSizeChanged(m_iconSize);
285void ThemeManager::onPaddingSizeChanged(
const uint &paddingSize)
291 Q_EMIT paddingSizeChanged(m_paddingSize);
294void ThemeManager::onMarginSizeChanged(
const uint &marginSize)
300 Q_EMIT marginSizeChanged(m_marginSize);
303void ThemeManager::onSpacingSizeChanged(
const uint &spacingSize)
309 Q_EMIT spacingSizeChanged(m_spacingSize);
312void ThemeManager::onEnableEffectsChanged(
bool enableEffects)
319 Q_EMIT enableEffectsChanged(m_enableEffects);
322void ThemeManager::onDefaultFontChanged(
const QString &font)
324 if (m_defaultFont == font)
327 m_defaultFont = font;
328 Q_EMIT defaultFontChanged(m_defaultFont);
331void ThemeManager::onSmallFontChanged(
const QString &font)
333 if (m_smallFont == font)
337 Q_EMIT smallFontChanged(m_smallFont);
340void ThemeManager::onMonospacedFontChanged(
const QString &font)
342 if (m_monospacedFont == font)
345 m_monospacedFont = font;
346 Q_EMIT monospacedFontChanged(m_monospacedFont);
349void ThemeManager::onCustomColorSchemeChanged(
const QString &scheme)
351 if (m_customColorScheme == scheme)
354 m_customColorScheme = scheme;
355 Q_EMIT customColorSchemeChanged(m_customColorScheme);
360 return m_borderRadius;
363void ThemeManager::setBorderRadius(uint newBorderRadius)
365 if (m_borderRadius == newBorderRadius)
367 m_borderRadius = newBorderRadius;
368 m_settings->
save(QStringLiteral(
"BorderRadius"), m_borderRadius);
369 sync(QStringLiteral(
"setBorderRadius"), m_borderRadius);
370 Q_EMIT borderRadiusChanged(m_borderRadius);
373void ThemeManager::resetBorderRadius()
375 this->setBorderRadius(ThemeManager::DefaultValues::borderRadius);
383void ThemeManager::setIconSize(uint newIconSize)
385 if (m_iconSize == newIconSize)
387 m_iconSize = newIconSize;
388 m_settings->
save(QStringLiteral(
"IconSize"), m_iconSize);
389 sync(QStringLiteral(
"setIconSize"), m_iconSize);
390 Q_EMIT iconSizeChanged(m_iconSize);
395 return m_enableEffects;
398void ThemeManager::setEnableEffects(
bool enableEffects)
404 m_settings->
save(QStringLiteral(
"EnableEffects"), m_enableEffects);
405 sync(QStringLiteral(
"setEnableEffects"), m_enableEffects);
406 Q_EMIT enableEffectsChanged(m_enableEffects);
411 return m_paddingSize;
419void ThemeManager::setPaddingSize(uint paddingSize)
425 m_settings->
save(QStringLiteral(
"PaddingSize"), m_paddingSize);
426 sync(QStringLiteral(
"setPaddingSize"), m_paddingSize);
427 Q_EMIT paddingSizeChanged(m_paddingSize);
430void ThemeManager::resetPaddingSize()
432 this->setPaddingSize(ThemeManager::DefaultValues::paddingSize);
435void ThemeManager::setMarginSize(uint marginSize)
441 m_settings->
save(QStringLiteral(
"MarginSize"), m_marginSize);
442 sync(QStringLiteral(
"setMarginSize"), m_marginSize);
443 Q_EMIT marginSizeChanged(m_marginSize);
446void ThemeManager::resetMarginSize()
448 this->setMarginSize(ThemeManager::DefaultValues::marginSize);
453 return m_spacingSize;
456void ThemeManager::setSpacingSize(uint spacingSize)
462 m_settings->
save(QStringLiteral(
"SpacingSize"), m_spacingSize);
463 sync(QStringLiteral(
"setSpacingSize"), m_spacingSize);
464 Q_EMIT spacingSizeChanged(m_spacingSize);
467void ThemeManager::resetSPacingSize()
469 this->setSpacingSize(ThemeManager::DefaultValues::spacingSize);
474 return m_defaultFont;
484 return m_monospacedFont;
487void ThemeManager::setDefaultFont(
const QString &defaultFont)
493 m_settings->
save(QStringLiteral(
"DefaultFont"), m_defaultFont);
494 sync(QStringLiteral(
"setDefaultFont"), m_defaultFont);
495 Q_EMIT defaultFontChanged(m_defaultFont);
498void ThemeManager::resetDefaultFont()
500 setDefaultFont(ThemeManager::DefaultValues::defaultFont);
503void ThemeManager::setSmallFont(
const QString &smallFont)
509 m_settings->
save(QStringLiteral(
"SmallFont"), m_smallFont);
510 sync(QStringLiteral(
"setSmallFont"), m_smallFont);
511 Q_EMIT smallFontChanged(m_smallFont);
514void ThemeManager::resetSmallFont()
516 setSmallFont(ThemeManager::DefaultValues::smallFont);
519void ThemeManager::setMonospacedFont(
const QString &monospacedFont)
525 m_settings->
save(QStringLiteral(
"MonospacedFont"), m_monospacedFont);
526 sync(QStringLiteral(
"setMonospacedFont"), m_monospacedFont);
527 Q_EMIT monospacedFontChanged(m_monospacedFont);
530void ThemeManager::resetMonospacedFont()
532 setMonospacedFont(ThemeManager::DefaultValues::monospacedFont);
537 return m_customColorScheme;
540void ThemeManager::setCustomColorScheme(
const QString &customColorScheme)
546 m_settings->
save(QStringLiteral(
"CustomColorScheme"), m_customColorScheme);
547 sync(QStringLiteral(
"setCustomColorScheme"), m_customColorScheme);
548 Q_EMIT customColorSchemeChanged(m_customColorScheme);
551void MauiMan::ThemeManager::resetIconSize()
553 this->setIconSize(ThemeManager::DefaultValues::iconSize);
The SettingsStore class Allows to store and read settings for MauiMan from the local conf file.
void save(const QString &key, const QVariant &value)
Save a conf value entry to the local file.
void beginModule(const QString &module)
Set up the module section to write to.
QVariant load(const QString &key, const QVariant &defaultValue)
Load the value of a conf entry, with a possible default value.
QString monospacedFont
The preferred mono spaced font, for example the one used in console terminals, or in text editors.
QString iconTheme
The preferred icon theme.
uint borderRadius
The corner border radius of the UI elements, also affects the radius of the CSD window corners.
QString smallFont
The preferred small font, for details.
bool enableEffects
Whether the user prefers for the system to have visual effects, such as animations,...
QString accentColor
The preferred accent color used for the highlighted and checked states.
QString defaultFont
The preferred default font, for most part of the UI.
uint paddingSize
The preferred padding size for the UI elements, such as buttons, tool bars, menu entries,...
uint marginSize
The preferred margin size around views.
int styleType
The style type for the color scheme.
QString windowControlsTheme
The preferred theme for the CSD window control buttons.
QString customColorScheme
The preferred color scheme to be used when the styleType is set to Custom.
bool enableCSD
Whether to use client side decorations (CSD) for the applications.
uint spacingSize
The preferred spacing size between elements in a row or column, such as lists or browsing elements.
uint iconSize
The preferred size of the icons in the buttons, menu entries and other elements.
The MauiMan name-space contains all of the available modules for configuring the Maui Applications an...
QDBusMessage call(QDBus::CallMode mode, const QString &method, Args &&... args)
bool isValid() const const
QDBusConnection sessionBus()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QVariant property(const char *name) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool toBool() const const
int toInt(bool *ok) const const
QString toString() const const
uint toUInt(bool *ok) const const