1#include "thememanager.h"
3#include "settingsstore.h"
4#include "mauimanutils.h"
14 qDebug(
" INIT THEME MANAGER");
16#if !defined Q_OS_ANDROID
18 if(server->serverRunning())
20 this->setConnections();
23 connect(server, &MauiManUtils::serverRunningChanged, [
this](
bool state)
25 qDebug() <<
"THEMEMANAGER MauiMan server running? " << state;
29 this->setConnections();
30 qDebug() <<
"THEMEMANAGER MauiMan server running? " << state << m_interface->isValid();
43#if !defined Q_OS_ANDROID
44 if (m_interface && m_interface->
isValid())
46 m_interface->
call(key, value);
54void ThemeManager::setConnections()
56#if !defined Q_OS_ANDROID
61 m_interface =
nullptr;
64 m_interface =
new QDBusInterface (QStringLiteral(
"org.mauiman.Manager"),
65 QStringLiteral(
"/Theme"),
66 QStringLiteral(
"org.mauiman.Theme"),
73 connect(m_interface, SIGNAL(windowControlsThemeChanged(
QString)),
this, SLOT(onWindowControlsThemeChanged(
QString)));
74 connect(m_interface, SIGNAL(styleTypeChanged(
int)),
this, SLOT(onStyleTypeChanged(
int)));
75 connect(m_interface, SIGNAL(enableCSDChanged(
bool)),
this, SLOT(onEnableCSDChanged(
bool)));
76 connect(m_interface, SIGNAL(borderRadiusChanged(uint)),
this, SLOT(onBorderRadiusChanged(uint)));
77 connect(m_interface, SIGNAL(iconSizeChanged(uint)),
this, SLOT(onIconSizeChanged(uint)));
78 connect(m_interface, SIGNAL(paddingSizeChanged(uint)),
this, SLOT(onPaddingSizeChanged(uint)));
79 connect(m_interface, SIGNAL(marginSizeChanged(uint)),
this, SLOT(onMarginSizeChanged(uint)));
80 connect(m_interface, SIGNAL(spacingSizeChanged(uint)),
this, SLOT(onSpacingSizeChanged(uint)));
81 connect(m_interface, SIGNAL(enableEffectsChanged(
bool)),
this, SLOT(onEnableEffectsChanged(
bool)));
84 connect(m_interface, SIGNAL(monospacedFontChanged(
QString)),
this, SLOT(onMonospacedFontChanged(
QString)));
85 connect(m_interface, SIGNAL(customColorSchemeChanged(
QString)),
this, SLOT(onCustomColorSchemeChanged(
QString)));
90void ThemeManager::loadSettings()
94#if !defined Q_OS_ANDROID
95 if(m_interface && m_interface->
isValid())
100 m_windowControlsTheme = m_interface->
property(
"windowControlsTheme").
toString();
107 m_enableEffects = m_interface->
property(
"enableEffects").
toBool();
111 m_customColorScheme = m_interface->
property(
"customColorScheme").
toString();
117 m_accentColor = m_settings->
load(QStringLiteral(
"AccentColor"), m_accentColor).
toString();
118 m_styleType = m_settings->
load(QStringLiteral(
"StyleType"), m_styleType).
toInt();
119 m_iconTheme = m_settings->
load(QStringLiteral(
"IconTheme"), m_iconTheme).
toString();
120 m_windowControlsTheme = m_settings->
load(QStringLiteral(
"WindowControlsTheme"), m_windowControlsTheme).
toString();
121 m_enableCSD = m_settings->
load(QStringLiteral(
"EnableCSD"), m_enableCSD).
toBool();
122 m_borderRadius = m_settings->
load(QStringLiteral(
"BorderRadius"), m_borderRadius).
toUInt();
123 m_iconSize = m_settings->
load(QStringLiteral(
"IconSize"), m_iconSize).
toUInt();
124 m_paddingSize = m_settings->
load(QStringLiteral(
"PaddingSize"), m_paddingSize).
toUInt();
125 m_marginSize = m_settings->
load(QStringLiteral(
"MarginSize"), m_marginSize).
toUInt();
126 m_spacingSize = m_settings->
load(QStringLiteral(
"SpacingSize"), m_spacingSize).
toUInt();
127 m_enableEffects = m_settings->
load(QStringLiteral(
"EnableEffects"), m_enableEffects).
toBool();
128 m_defaultFont = m_settings->
load(QStringLiteral(
"DefaultFont"), m_defaultFont).
toString();
129 m_smallFont = m_settings->
load(QStringLiteral(
"SmallFont"), m_smallFont).
toString();
130 m_monospacedFont = m_settings->
load(QStringLiteral(
"MonospacedFont"), m_monospacedFont).
toString();
131 m_customColorScheme = m_settings->
load(QStringLiteral(
"CustomColorScheme"), m_customColorScheme).
toString();
139void ThemeManager::setStyleType(
int newStyleType)
141 if (m_styleType == newStyleType)
144 m_styleType = newStyleType;
145 m_settings->
save(QStringLiteral(
"StyleType"), m_styleType);
146 sync(QStringLiteral(
"setStyleType"), newStyleType);
147 Q_EMIT styleTypeChanged(m_styleType);
152 return m_accentColor;
155void ThemeManager::setAccentColor(
const QString &newAccentColor)
157 if (m_accentColor == newAccentColor)
160 qDebug() <<
"Setting accent color" << m_accentColor;
162 m_accentColor = newAccentColor;
163 m_settings->
save(QStringLiteral(
"AccentColor"), m_accentColor);
164 sync(QStringLiteral(
"setAccentColor"), m_accentColor);
165 Q_EMIT accentColorChanged(m_accentColor);
168void ThemeManager::resetAccentColor()
170 this->setAccentColor(ThemeManager::DefaultValues::accentColor);
178void ThemeManager::setIconTheme(
const QString &newIconTheme)
180 if (m_iconTheme == newIconTheme)
183 m_iconTheme = newIconTheme;
184 m_settings->
save(QStringLiteral(
"IconTheme"), m_iconTheme);
185 sync(QStringLiteral(
"setIconTheme"), m_iconTheme);
186 Q_EMIT iconThemeChanged(m_iconTheme);
191 return m_windowControlsTheme;
194void ThemeManager::setWindowControlsTheme(
const QString &newWindowControlsTheme)
196 if (m_windowControlsTheme == newWindowControlsTheme)
199 m_windowControlsTheme = newWindowControlsTheme;
200 m_settings->
save(QStringLiteral(
"WindowControlsTheme"), m_windowControlsTheme);
201 sync(QStringLiteral(
"setWindowControlsTheme"), m_windowControlsTheme);
202 Q_EMIT windowControlsThemeChanged(m_windowControlsTheme);
210void ThemeManager::setEnableCSD(
bool enableCSD)
216 m_settings->
save(QStringLiteral(
"EnableCSD"), m_enableCSD);
217 sync(QStringLiteral(
"setEnableCSD"), m_enableCSD);
218 Q_EMIT enableCSDChanged(m_enableCSD);
221void ThemeManager::onStyleTypeChanged(
const int &newStyleType)
223 if (m_styleType == newStyleType)
226 m_styleType = newStyleType;
227 Q_EMIT styleTypeChanged(m_styleType);
230void ThemeManager::onAccentColorChanged(
const QString &newAccentColor)
232 if (m_accentColor == newAccentColor)
235 m_accentColor = newAccentColor;
236 Q_EMIT accentColorChanged(m_accentColor);
239void ThemeManager::onWindowControlsThemeChanged(
const QString &newWindowControlsTheme)
241 if (m_windowControlsTheme == newWindowControlsTheme)
244 m_windowControlsTheme = newWindowControlsTheme;
245 Q_EMIT windowControlsThemeChanged(m_windowControlsTheme);
248void ThemeManager::onIconThemeChanged(
const QString &newIconTheme)
250 if (m_iconTheme == newIconTheme)
253 m_iconTheme = newIconTheme;
254 Q_EMIT iconThemeChanged(m_iconTheme);
257void ThemeManager::onEnableCSDChanged(
const bool &enableCSD)
263 Q_EMIT enableCSDChanged(m_enableCSD);
266void ThemeManager::onBorderRadiusChanged(
const uint &radius)
268 if (m_borderRadius == radius)
270 m_borderRadius = radius;
271 Q_EMIT borderRadiusChanged(m_borderRadius);
274void ThemeManager::onIconSizeChanged(
const uint &size)
276 if (m_iconSize == size)
279 Q_EMIT iconSizeChanged(m_iconSize);
282void ThemeManager::onPaddingSizeChanged(
const uint &paddingSize)
288 Q_EMIT paddingSizeChanged(m_paddingSize);
291void ThemeManager::onMarginSizeChanged(
const uint &marginSize)
297 Q_EMIT marginSizeChanged(m_marginSize);
300void ThemeManager::onSpacingSizeChanged(
const uint &spacingSize)
306 Q_EMIT spacingSizeChanged(m_spacingSize);
309void ThemeManager::onEnableEffectsChanged(
bool enableEffects)
316 Q_EMIT enableEffectsChanged(m_enableEffects);
319void ThemeManager::onDefaultFontChanged(
const QString &font)
321 if (m_defaultFont == font)
324 m_defaultFont = font;
325 Q_EMIT defaultFontChanged(m_defaultFont);
328void ThemeManager::onSmallFontChanged(
const QString &font)
330 if (m_smallFont == font)
334 Q_EMIT smallFontChanged(m_smallFont);
337void ThemeManager::onMonospacedFontChanged(
const QString &font)
339 if (m_monospacedFont == font)
342 m_monospacedFont = font;
343 Q_EMIT monospacedFontChanged(m_monospacedFont);
346void ThemeManager::onCustomColorSchemeChanged(
const QString &scheme)
348 if (m_customColorScheme == scheme)
351 m_customColorScheme = scheme;
352 Q_EMIT customColorSchemeChanged(m_customColorScheme);
357 return m_borderRadius;
360void ThemeManager::setBorderRadius(uint newBorderRadius)
362 if (m_borderRadius == newBorderRadius)
364 m_borderRadius = newBorderRadius;
365 m_settings->
save(QStringLiteral(
"BorderRadius"), m_borderRadius);
366 sync(QStringLiteral(
"setBorderRadius"), m_borderRadius);
367 Q_EMIT borderRadiusChanged(m_borderRadius);
370void ThemeManager::resetBorderRadius()
372 this->setBorderRadius(ThemeManager::DefaultValues::borderRadius);
380void ThemeManager::setIconSize(uint newIconSize)
382 if (m_iconSize == newIconSize)
384 m_iconSize = newIconSize;
385 m_settings->
save(QStringLiteral(
"IconSize"), m_iconSize);
386 sync(QStringLiteral(
"setIconSize"), m_iconSize);
387 Q_EMIT iconSizeChanged(m_iconSize);
392 return m_enableEffects;
395void ThemeManager::setEnableEffects(
bool enableEffects)
401 m_settings->
save(QStringLiteral(
"EnableEffects"), m_enableEffects);
402 sync(QStringLiteral(
"setEnableEffects"), m_enableEffects);
403 Q_EMIT enableEffectsChanged(m_enableEffects);
408 return m_paddingSize;
416void ThemeManager::setPaddingSize(uint paddingSize)
422 m_settings->
save(QStringLiteral(
"PaddingSize"), m_paddingSize);
423 sync(QStringLiteral(
"setPaddingSize"), m_paddingSize);
424 Q_EMIT paddingSizeChanged(m_paddingSize);
427void ThemeManager::resetPaddingSize()
429 this->setPaddingSize(ThemeManager::DefaultValues::paddingSize);
432void ThemeManager::setMarginSize(uint marginSize)
438 m_settings->
save(QStringLiteral(
"MarginSize"), m_marginSize);
439 sync(QStringLiteral(
"setMarginSize"), m_marginSize);
440 Q_EMIT marginSizeChanged(m_marginSize);
443void ThemeManager::resetMarginSize()
445 this->setMarginSize(ThemeManager::DefaultValues::marginSize);
450 return m_spacingSize;
453void ThemeManager::setSpacingSize(uint spacingSize)
459 m_settings->
save(QStringLiteral(
"SpacingSize"), m_spacingSize);
460 sync(QStringLiteral(
"setSpacingSize"), m_spacingSize);
461 Q_EMIT spacingSizeChanged(m_spacingSize);
464void ThemeManager::resetSPacingSize()
466 this->setSpacingSize(ThemeManager::DefaultValues::spacingSize);
471 return m_defaultFont;
481 return m_monospacedFont;
484void ThemeManager::setDefaultFont(
const QString &defaultFont)
490 m_settings->
save(QStringLiteral(
"DefaultFont"), m_defaultFont);
491 sync(QStringLiteral(
"setDefaultFont"), m_defaultFont);
492 Q_EMIT defaultFontChanged(m_defaultFont);
495void ThemeManager::resetDefaultFont()
497 setDefaultFont(ThemeManager::DefaultValues::defaultFont);
500void ThemeManager::setSmallFont(
const QString &smallFont)
506 m_settings->
save(QStringLiteral(
"SmallFont"), m_smallFont);
507 sync(QStringLiteral(
"setSmallFont"), m_smallFont);
508 Q_EMIT smallFontChanged(m_smallFont);
511void ThemeManager::resetSmallFont()
513 setSmallFont(ThemeManager::DefaultValues::smallFont);
516void ThemeManager::setMonospacedFont(
const QString &monospacedFont)
522 m_settings->
save(QStringLiteral(
"MonospacedFont"), m_monospacedFont);
523 sync(QStringLiteral(
"setMonospacedFont"), m_monospacedFont);
524 Q_EMIT monospacedFontChanged(m_monospacedFont);
527void ThemeManager::resetMonospacedFont()
529 setMonospacedFont(ThemeManager::DefaultValues::monospacedFont);
534 return m_customColorScheme;
537void ThemeManager::setCustomColorScheme(
const QString &customColorScheme)
543 m_settings->
save(QStringLiteral(
"CustomColorScheme"), m_customColorScheme);
544 sync(QStringLiteral(
"setCustomColorScheme"), m_customColorScheme);
545 Q_EMIT customColorSchemeChanged(m_customColorScheme);
548void MauiMan::ThemeManager::resetIconSize()
550 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