MauiMan

thememanager.cpp
1#include "thememanager.h"
2
3#include "settingsstore.h"
4#include "mauimanutils.h"
5
6#include <QDebug>
7
8using namespace MauiMan;
9
10
11ThemeManager::ThemeManager(QObject *parent) : QObject(parent)
12 ,m_settings(new MauiMan::SettingsStore(this))
13{
14 qDebug( " INIT THEME MANAGER");
15
16#if !defined Q_OS_ANDROID
17 auto server = new MauiManUtils(this);
18 if(server->serverRunning())
19 {
20 this->setConnections();
21 }
22
23 connect(server, &MauiManUtils::serverRunningChanged, [this](bool state)
24 {
25 qDebug() << "THEMEMANAGER MauiMan server running? " << state;
26
27 if(state)
28 {
29 this->setConnections();
30 qDebug() <<"THEMEMANAGER MauiMan server running? " << state << m_interface->isValid();
31
32 }
33 });
34#endif
35
36 loadSettings();
37
38}
39
40
41void ThemeManager::sync(const QString &key, const QVariant &value)
42{
43#if !defined Q_OS_ANDROID
44 if (m_interface && m_interface->isValid())
45 {
46 m_interface->call(key, value);
47 }
48#else
49 Q_UNUSED(key)
50 Q_UNUSED(value)
51#endif
52}
53
54void ThemeManager::setConnections()
55{
56#if !defined Q_OS_ANDROID
57 if(m_interface)
58 {
59 m_interface->disconnect();
60 m_interface->deleteLater();
61 m_interface = nullptr;
62 }
63
64 m_interface = new QDBusInterface (QStringLiteral("org.mauiman.Manager"),
65 QStringLiteral("/Theme"),
66 QStringLiteral("org.mauiman.Theme"),
68
69 if (m_interface->isValid())
70 {
71 connect(m_interface, SIGNAL(accentColorChanged(QString)), this, SLOT(onAccentColorChanged(QString)));
72 connect(m_interface, SIGNAL(iconThemeChanged(QString)), this, SLOT(onIconThemeChanged(QString)));
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)));
82 connect(m_interface, SIGNAL(defaultFontChanged(QString)), this, SLOT(onDefaultFontChanged(QString)));
83 connect(m_interface, SIGNAL(smallFontChanged(QString)), this, SLOT(onSmallFontChanged(QString)));
84 connect(m_interface, SIGNAL(monospacedFontChanged(QString)), this, SLOT(onMonospacedFontChanged(QString)));
85 connect(m_interface, SIGNAL(customColorSchemeChanged(QString)), this, SLOT(onCustomColorSchemeChanged(QString)));
86 }
87#endif
88}
89
90void ThemeManager::loadSettings()
91{
92 m_settings->beginModule(QStringLiteral("Theme"));
93
94#if !defined Q_OS_ANDROID
95 if(m_interface && m_interface->isValid())
96 {
97 m_accentColor = m_interface->property("accentColor").toString();
98 m_styleType = m_interface->property("styleType").toInt();
99 m_iconTheme = m_interface->property("iconTheme").toString();
100 m_windowControlsTheme = m_interface->property("windowControlsTheme").toString();
101 m_enableCSD = m_interface->property("enableCSD").toBool();
102 m_borderRadius = m_interface->property("borderRadius").toUInt();
103 m_iconSize = m_interface->property("iconSize").toUInt();
104 m_paddingSize = m_interface->property("paddingSize").toUInt();
105 m_marginSize = m_interface->property("marginSize").toUInt();
106 m_spacingSize = m_interface->property("spacingSize").toUInt();
107 m_enableEffects = m_interface->property("enableEffects").toBool();
108 m_defaultFont = m_interface->property("defaultFont").toString();
109 m_smallFont = m_interface->property("smallFont").toString();
110 m_monospacedFont = m_interface->property("monospacedFont").toString();
111 m_customColorScheme = m_interface->property("customColorScheme").toString();
112
113 return;
114 }
115#endif
116
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();
132}
133
134int ThemeManager::styleType() const
135{
136 return m_styleType;
137}
138
139void ThemeManager::setStyleType(int newStyleType)
140{
141 if (m_styleType == newStyleType)
142 return;
143
144 m_styleType = newStyleType;
145 m_settings->save(QStringLiteral("StyleType"), m_styleType);
146 sync(QStringLiteral("setStyleType"), newStyleType);
147 Q_EMIT styleTypeChanged(m_styleType);
148}
149
151{
152 return m_accentColor;
153}
154
155void ThemeManager::setAccentColor(const QString &newAccentColor)
156{
157 if (m_accentColor == newAccentColor)
158 return;
159
160 qDebug() << "Setting accent color" << m_accentColor;
161
162 m_accentColor = newAccentColor;
163 m_settings->save(QStringLiteral("AccentColor"), m_accentColor);
164 sync(QStringLiteral("setAccentColor"), m_accentColor);
165 Q_EMIT accentColorChanged(m_accentColor);
166}
167
168void ThemeManager::resetAccentColor()
169{
170 this->setAccentColor(ThemeManager::DefaultValues::accentColor);
171}
172
173const QString &ThemeManager::iconTheme() const
174{
175 return m_iconTheme;
176}
177
178void ThemeManager::setIconTheme(const QString &newIconTheme)
179{
180 if (m_iconTheme == newIconTheme)
181 return;
182
183 m_iconTheme = newIconTheme;
184 m_settings->save(QStringLiteral("IconTheme"), m_iconTheme);
185 sync(QStringLiteral("setIconTheme"), m_iconTheme);
186 Q_EMIT iconThemeChanged(m_iconTheme);
187}
188
190{
191 return m_windowControlsTheme;
192}
193
194void ThemeManager::setWindowControlsTheme(const QString &newWindowControlsTheme)
195{
196 if (m_windowControlsTheme == newWindowControlsTheme)
197 return;
198
199 m_windowControlsTheme = newWindowControlsTheme;
200 m_settings->save(QStringLiteral("WindowControlsTheme"), m_windowControlsTheme);
201 sync(QStringLiteral("setWindowControlsTheme"), m_windowControlsTheme);
202 Q_EMIT windowControlsThemeChanged(m_windowControlsTheme);
203}
204
205bool ThemeManager::enableCSD() const
206{
207 return m_enableCSD;
208}
209
210void ThemeManager::setEnableCSD(bool enableCSD)
211{
212 if (m_enableCSD == enableCSD)
213 return;
214
215 m_enableCSD = enableCSD;
216 m_settings->save(QStringLiteral("EnableCSD"), m_enableCSD);
217 sync(QStringLiteral("setEnableCSD"), m_enableCSD);
218 Q_EMIT enableCSDChanged(m_enableCSD);
219}
220
221void ThemeManager::onStyleTypeChanged(const int &newStyleType)
222{
223 if (m_styleType == newStyleType)
224 return;
225
226 m_styleType = newStyleType;
227 Q_EMIT styleTypeChanged(m_styleType);
228}
229
230void ThemeManager::onAccentColorChanged(const QString &newAccentColor)
231{
232 if (m_accentColor == newAccentColor)
233 return;
234
235 m_accentColor = newAccentColor;
236 Q_EMIT accentColorChanged(m_accentColor);
237}
238
239void ThemeManager::onWindowControlsThemeChanged(const QString &newWindowControlsTheme)
240{
241 if (m_windowControlsTheme == newWindowControlsTheme)
242 return;
243
244 m_windowControlsTheme = newWindowControlsTheme;
245 Q_EMIT windowControlsThemeChanged(m_windowControlsTheme);
246}
247
248void ThemeManager::onIconThemeChanged(const QString &newIconTheme)
249{
250 if (m_iconTheme == newIconTheme)
251 return;
252
253 m_iconTheme = newIconTheme;
254 Q_EMIT iconThemeChanged(m_iconTheme);
255}
256
257void ThemeManager::onEnableCSDChanged(const bool &enableCSD)
258{
259 if (m_enableCSD == enableCSD)
260 return;
261
262 m_enableCSD = enableCSD;
263 Q_EMIT enableCSDChanged(m_enableCSD);
264}
265
266void ThemeManager::onBorderRadiusChanged(const uint &radius)
267{
268 if (m_borderRadius == radius)
269 return;
270 m_borderRadius = radius;
271 Q_EMIT borderRadiusChanged(m_borderRadius);
272}
273
274void ThemeManager::onIconSizeChanged(const uint &size)
275{
276 if (m_iconSize == size)
277 return;
278 m_iconSize = size;
279 Q_EMIT iconSizeChanged(m_iconSize);
280}
281
282void ThemeManager::onPaddingSizeChanged(const uint &paddingSize)
283{
284 if (m_paddingSize == paddingSize)
285 return;
286
287 m_paddingSize = paddingSize;
288 Q_EMIT paddingSizeChanged(m_paddingSize);
289}
290
291void ThemeManager::onMarginSizeChanged(const uint &marginSize)
292{
293 if (m_marginSize == marginSize)
294 return;
295
296 m_marginSize = marginSize;
297 Q_EMIT marginSizeChanged(m_marginSize);
298}
299
300void ThemeManager::onSpacingSizeChanged(const uint &spacingSize)
301{
302 if (m_spacingSize == spacingSize)
303 return;
304
305 m_spacingSize = spacingSize;
306 Q_EMIT spacingSizeChanged(m_spacingSize);
307}
308
309void ThemeManager::onEnableEffectsChanged(bool enableEffects)
310{
311 qDebug() << "ENABLE EFEFCTS MODIFIED" << enableEffects;
312 if (m_enableEffects == enableEffects)
313 return;
314
315 m_enableEffects = enableEffects;
316 Q_EMIT enableEffectsChanged(m_enableEffects);
317}
318
319void ThemeManager::onDefaultFontChanged(const QString &font)
320{
321 if (m_defaultFont == font)
322 return;
323
324 m_defaultFont = font;
325 Q_EMIT defaultFontChanged(m_defaultFont);
326}
327
328void ThemeManager::onSmallFontChanged(const QString &font)
329{
330 if (m_smallFont == font)
331 return;
332
333 m_smallFont = font;
334 Q_EMIT smallFontChanged(m_smallFont);
335}
336
337void ThemeManager::onMonospacedFontChanged(const QString &font)
338{
339 if (m_monospacedFont == font)
340 return;
341
342 m_monospacedFont = font;
343 Q_EMIT monospacedFontChanged(m_monospacedFont);
344}
345
346void ThemeManager::onCustomColorSchemeChanged(const QString &scheme)
347{
348 if (m_customColorScheme == scheme)
349 return;
350
351 m_customColorScheme = scheme;
352 Q_EMIT customColorSchemeChanged(m_customColorScheme);
353}
354
356{
357 return m_borderRadius;
358}
359
360void ThemeManager::setBorderRadius(uint newBorderRadius)
361{
362 if (m_borderRadius == newBorderRadius)
363 return;
364 m_borderRadius = newBorderRadius;
365 m_settings->save(QStringLiteral("BorderRadius"), m_borderRadius);
366 sync(QStringLiteral("setBorderRadius"), m_borderRadius);
367 Q_EMIT borderRadiusChanged(m_borderRadius);
368}
369
370void ThemeManager::resetBorderRadius()
371{
372 this->setBorderRadius(ThemeManager::DefaultValues::borderRadius);
373}
374
375uint ThemeManager::iconSize() const
376{
377 return m_iconSize;
378}
379
380void ThemeManager::setIconSize(uint newIconSize)
381{
382 if (m_iconSize == newIconSize)
383 return;
384 m_iconSize = newIconSize;
385 m_settings->save(QStringLiteral("IconSize"), m_iconSize);
386 sync(QStringLiteral("setIconSize"), m_iconSize);
387 Q_EMIT iconSizeChanged(m_iconSize);
388}
389
391{
392 return m_enableEffects;
393}
394
395void ThemeManager::setEnableEffects(bool enableEffects)
396{
397 if (m_enableEffects == enableEffects)
398 return;
399
400 m_enableEffects = enableEffects;
401 m_settings->save(QStringLiteral("EnableEffects"), m_enableEffects);
402 sync(QStringLiteral("setEnableEffects"), m_enableEffects);
403 Q_EMIT enableEffectsChanged(m_enableEffects);
404}
405
406uint ThemeManager::paddingSize() const
407{
408 return m_paddingSize;
409}
410
411uint ThemeManager::marginSize() const
412{
413 return m_marginSize;
414}
415
416void ThemeManager::setPaddingSize(uint paddingSize)
417{
418 if (m_paddingSize == paddingSize)
419 return;
420
421 m_paddingSize = paddingSize;
422 m_settings->save(QStringLiteral("PaddingSize"), m_paddingSize);
423 sync(QStringLiteral("setPaddingSize"), m_paddingSize);
424 Q_EMIT paddingSizeChanged(m_paddingSize);
425}
426
427void ThemeManager::resetPaddingSize()
428{
429 this->setPaddingSize(ThemeManager::DefaultValues::paddingSize);
430}
431
432void ThemeManager::setMarginSize(uint marginSize)
433{
434 if (m_marginSize == marginSize)
435 return;
436
437 m_marginSize = marginSize;
438 m_settings->save(QStringLiteral("MarginSize"), m_marginSize);
439 sync(QStringLiteral("setMarginSize"), m_marginSize);
440 Q_EMIT marginSizeChanged(m_marginSize);
441}
442
443void ThemeManager::resetMarginSize()
444{
445 this->setMarginSize(ThemeManager::DefaultValues::marginSize);
446}
447
448uint ThemeManager::spacingSize() const
449{
450 return m_spacingSize;
451}
452
453void ThemeManager::setSpacingSize(uint spacingSize)
454{
455 if (m_spacingSize == spacingSize)
456 return;
457
458 m_spacingSize = spacingSize;
459 m_settings->save(QStringLiteral("SpacingSize"), m_spacingSize);
460 sync(QStringLiteral("setSpacingSize"), m_spacingSize);
461 Q_EMIT spacingSizeChanged(m_spacingSize);
462}
463
464void ThemeManager::resetSPacingSize()
465{
466 this->setSpacingSize(ThemeManager::DefaultValues::spacingSize);
467}
468
470{
471 return m_defaultFont;
472}
473
475{
476 return m_smallFont;
477}
478
480{
481 return m_monospacedFont;
482}
483
484void ThemeManager::setDefaultFont(const QString &defaultFont)
485{
486 if (m_defaultFont == defaultFont)
487 return;
488
489 m_defaultFont = defaultFont;
490 m_settings->save(QStringLiteral("DefaultFont"), m_defaultFont);
491 sync(QStringLiteral("setDefaultFont"), m_defaultFont);
492 Q_EMIT defaultFontChanged(m_defaultFont);
493}
494
495void ThemeManager::resetDefaultFont()
496{
497 setDefaultFont(ThemeManager::DefaultValues::defaultFont);
498}
499
500void ThemeManager::setSmallFont(const QString &smallFont)
501{
502 if (m_smallFont == smallFont)
503 return;
504
505 m_smallFont = smallFont;
506 m_settings->save(QStringLiteral("SmallFont"), m_smallFont);
507 sync(QStringLiteral("setSmallFont"), m_smallFont);
508 Q_EMIT smallFontChanged(m_smallFont);
509}
510
511void ThemeManager::resetSmallFont()
512{
513 setSmallFont(ThemeManager::DefaultValues::smallFont);
514}
515
516void ThemeManager::setMonospacedFont(const QString &monospacedFont)
517{
518 if (m_monospacedFont == monospacedFont)
519 return;
520
521 m_monospacedFont = monospacedFont;
522 m_settings->save(QStringLiteral("MonospacedFont"), m_monospacedFont);
523 sync(QStringLiteral("setMonospacedFont"), m_monospacedFont);
524 Q_EMIT monospacedFontChanged(m_monospacedFont);
525}
526
527void ThemeManager::resetMonospacedFont()
528{
529 setMonospacedFont(ThemeManager::DefaultValues::monospacedFont);
530}
531
533{
534 return m_customColorScheme;
535}
536
537void ThemeManager::setCustomColorScheme(const QString &customColorScheme)
538{
539 if (m_customColorScheme == customColorScheme)
540 return;
541
542 m_customColorScheme = customColorScheme;
543 m_settings->save(QStringLiteral("CustomColorScheme"), m_customColorScheme);
544 sync(QStringLiteral("setCustomColorScheme"), m_customColorScheme);
545 Q_EMIT customColorSchemeChanged(m_customColorScheme);
546}
547
548void MauiMan::ThemeManager::resetIconSize()
549{
550 this->setIconSize(ThemeManager::DefaultValues::iconSize);
551}
The MauiManUtils class.
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()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:51:22 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.