MauiMan

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

KDE's Doxygen guidelines are available online.