File indexing completed on 2024-10-27 04:24:10
0001 #include "thememanager.h" 0002 0003 #include "settingsstore.h" 0004 #include "mauimanutils.h" 0005 0006 #include <QDebug> 0007 0008 using namespace MauiMan; 0009 0010 0011 ThemeManager::ThemeManager(QObject *parent) : QObject(parent) 0012 ,m_settings(new MauiMan::SettingsStore(this)) 0013 { 0014 qDebug( " INIT THEME MANAGER"); 0015 0016 #if !defined Q_OS_ANDROID 0017 auto server = new MauiManUtils(this); 0018 if(server->serverRunning()) 0019 { 0020 this->setConnections(); 0021 } 0022 0023 connect(server, &MauiManUtils::serverRunningChanged, [this](bool state) 0024 { 0025 qDebug() << "THEMEMANAGER MauiMan server running? " << state; 0026 0027 if(state) 0028 { 0029 this->setConnections(); 0030 qDebug() <<"THEMEMANAGER MauiMan server running? " << state << m_interface->isValid(); 0031 0032 } 0033 }); 0034 #endif 0035 0036 loadSettings(); 0037 0038 } 0039 0040 0041 void ThemeManager::sync(const QString &key, const QVariant &value) 0042 { 0043 #if !defined Q_OS_ANDROID 0044 if (m_interface && m_interface->isValid()) 0045 { 0046 m_interface->call(key, value); 0047 } 0048 #else 0049 Q_UNUSED(key) 0050 Q_UNUSED(value) 0051 #endif 0052 } 0053 0054 void ThemeManager::setConnections() 0055 { 0056 #if !defined Q_OS_ANDROID 0057 if(m_interface) 0058 { 0059 m_interface->disconnect(); 0060 m_interface->deleteLater(); 0061 m_interface = nullptr; 0062 } 0063 0064 m_interface = new QDBusInterface (QStringLiteral("org.mauiman.Manager"), 0065 QStringLiteral("/Theme"), 0066 QStringLiteral("org.mauiman.Theme"), 0067 QDBusConnection::sessionBus(), this); 0068 0069 if (m_interface->isValid()) 0070 { 0071 connect(m_interface, SIGNAL(accentColorChanged(QString)), this, SLOT(onAccentColorChanged(QString))); 0072 connect(m_interface, SIGNAL(iconThemeChanged(QString)), this, SLOT(onIconThemeChanged(QString))); 0073 connect(m_interface, SIGNAL(windowControlsThemeChanged(QString)), this, SLOT(onWindowControlsThemeChanged(QString))); 0074 connect(m_interface, SIGNAL(styleTypeChanged(int)), this, SLOT(onStyleTypeChanged(int))); 0075 connect(m_interface, SIGNAL(enableCSDChanged(bool)), this, SLOT(onEnableCSDChanged(bool))); 0076 connect(m_interface, SIGNAL(borderRadiusChanged(uint)), this, SLOT(onBorderRadiusChanged(uint))); 0077 connect(m_interface, SIGNAL(iconSizeChanged(uint)), this, SLOT(onIconSizeChanged(uint))); 0078 connect(m_interface, SIGNAL(paddingSizeChanged(uint)), this, SLOT(onPaddingSizeChanged(uint))); 0079 connect(m_interface, SIGNAL(marginSizeChanged(uint)), this, SLOT(onMarginSizeChanged(uint))); 0080 connect(m_interface, SIGNAL(spacingSizeChanged(uint)), this, SLOT(onSpacingSizeChanged(uint))); 0081 connect(m_interface, SIGNAL(enableEffectsChanged(bool)), this, SLOT(onEnableEffectsChanged(bool))); 0082 connect(m_interface, SIGNAL(defaultFontChanged(QString)), this, SLOT(onDefaultFontChanged(QString))); 0083 connect(m_interface, SIGNAL(smallFontChanged(QString)), this, SLOT(onSmallFontChanged(QString))); 0084 connect(m_interface, SIGNAL(monospacedFontChanged(QString)), this, SLOT(onMonospacedFontChanged(QString))); 0085 connect(m_interface, SIGNAL(customColorSchemeChanged(QString)), this, SLOT(onCustomColorSchemeChanged(QString))); 0086 } 0087 #endif 0088 } 0089 0090 void ThemeManager::loadSettings() 0091 { 0092 m_settings->beginModule(QStringLiteral("Theme")); 0093 0094 #if !defined Q_OS_ANDROID 0095 if(m_interface && m_interface->isValid()) 0096 { 0097 m_accentColor = m_interface->property("accentColor").toString(); 0098 m_styleType = m_interface->property("styleType").toInt(); 0099 m_iconTheme = m_interface->property("iconTheme").toString(); 0100 m_windowControlsTheme = m_interface->property("windowControlsTheme").toString(); 0101 m_enableCSD = m_interface->property("enableCSD").toBool(); 0102 m_borderRadius = m_interface->property("borderRadius").toUInt(); 0103 m_iconSize = m_interface->property("iconSize").toUInt(); 0104 m_paddingSize = m_interface->property("paddingSize").toUInt(); 0105 m_marginSize = m_interface->property("marginSize").toUInt(); 0106 m_spacingSize = m_interface->property("spacingSize").toUInt(); 0107 m_enableEffects = m_interface->property("enableEffects").toBool(); 0108 m_defaultFont = m_interface->property("defaultFont").toString(); 0109 m_smallFont = m_interface->property("smallFont").toString(); 0110 m_monospacedFont = m_interface->property("monospacedFont").toString(); 0111 m_customColorScheme = m_interface->property("customColorScheme").toString(); 0112 0113 return; 0114 } 0115 #endif 0116 0117 m_accentColor = m_settings->load(QStringLiteral("AccentColor"), m_accentColor).toString(); 0118 m_styleType = m_settings->load(QStringLiteral("StyleType"), m_styleType).toInt(); 0119 m_iconTheme = m_settings->load(QStringLiteral("IconTheme"), m_iconTheme).toString(); 0120 m_windowControlsTheme = m_settings->load(QStringLiteral("WindowControlsTheme"), m_windowControlsTheme).toString(); 0121 m_enableCSD = m_settings->load(QStringLiteral("EnableCSD"), m_enableCSD).toBool(); 0122 m_borderRadius = m_settings->load(QStringLiteral("BorderRadius"), m_borderRadius).toUInt(); 0123 m_iconSize = m_settings->load(QStringLiteral("IconSize"), m_iconSize).toUInt(); 0124 m_paddingSize = m_settings->load(QStringLiteral("PaddingSize"), m_paddingSize).toUInt(); 0125 m_marginSize = m_settings->load(QStringLiteral("MarginSize"), m_marginSize).toUInt(); 0126 m_spacingSize = m_settings->load(QStringLiteral("SpacingSize"), m_spacingSize).toUInt(); 0127 m_enableEffects = m_settings->load(QStringLiteral("EnableEffects"), m_enableEffects).toBool(); 0128 m_defaultFont = m_settings->load(QStringLiteral("DefaultFont"), m_defaultFont).toString(); 0129 m_smallFont = m_settings->load(QStringLiteral("SmallFont"), m_smallFont).toString(); 0130 m_monospacedFont = m_settings->load(QStringLiteral("MonospacedFont"), m_monospacedFont).toString(); 0131 m_customColorScheme = m_settings->load(QStringLiteral("CustomColorScheme"), m_customColorScheme).toString(); 0132 } 0133 0134 int ThemeManager::styleType() const 0135 { 0136 return m_styleType; 0137 } 0138 0139 void ThemeManager::setStyleType(int newStyleType) 0140 { 0141 if (m_styleType == newStyleType) 0142 return; 0143 0144 m_styleType = newStyleType; 0145 m_settings->save(QStringLiteral("StyleType"), m_styleType); 0146 sync(QStringLiteral("setStyleType"), newStyleType); 0147 Q_EMIT styleTypeChanged(m_styleType); 0148 } 0149 0150 const QString &ThemeManager::accentColor() const 0151 { 0152 return m_accentColor; 0153 } 0154 0155 void ThemeManager::setAccentColor(const QString &newAccentColor) 0156 { 0157 if (m_accentColor == newAccentColor) 0158 return; 0159 0160 qDebug() << "Setting accent color" << m_accentColor; 0161 0162 m_accentColor = newAccentColor; 0163 m_settings->save(QStringLiteral("AccentColor"), m_accentColor); 0164 sync(QStringLiteral("setAccentColor"), m_accentColor); 0165 Q_EMIT accentColorChanged(m_accentColor); 0166 } 0167 0168 void ThemeManager::resetAccentColor() 0169 { 0170 this->setAccentColor(ThemeManager::DefaultValues::accentColor); 0171 } 0172 0173 const QString &ThemeManager::iconTheme() const 0174 { 0175 return m_iconTheme; 0176 } 0177 0178 void ThemeManager::setIconTheme(const QString &newIconTheme) 0179 { 0180 if (m_iconTheme == newIconTheme) 0181 return; 0182 0183 m_iconTheme = newIconTheme; 0184 m_settings->save(QStringLiteral("IconTheme"), m_iconTheme); 0185 sync(QStringLiteral("setIconTheme"), m_iconTheme); 0186 Q_EMIT iconThemeChanged(m_iconTheme); 0187 } 0188 0189 const QString &ThemeManager::windowControlsTheme() const 0190 { 0191 return m_windowControlsTheme; 0192 } 0193 0194 void ThemeManager::setWindowControlsTheme(const QString &newWindowControlsTheme) 0195 { 0196 if (m_windowControlsTheme == newWindowControlsTheme) 0197 return; 0198 0199 m_windowControlsTheme = newWindowControlsTheme; 0200 m_settings->save(QStringLiteral("WindowControlsTheme"), m_windowControlsTheme); 0201 sync(QStringLiteral("setWindowControlsTheme"), m_windowControlsTheme); 0202 Q_EMIT windowControlsThemeChanged(m_windowControlsTheme); 0203 } 0204 0205 bool ThemeManager::enableCSD() const 0206 { 0207 return m_enableCSD; 0208 } 0209 0210 void ThemeManager::setEnableCSD(bool enableCSD) 0211 { 0212 if (m_enableCSD == enableCSD) 0213 return; 0214 0215 m_enableCSD = enableCSD; 0216 m_settings->save(QStringLiteral("EnableCSD"), m_enableCSD); 0217 sync(QStringLiteral("setEnableCSD"), m_enableCSD); 0218 Q_EMIT enableCSDChanged(m_enableCSD); 0219 } 0220 0221 void ThemeManager::onStyleTypeChanged(const int &newStyleType) 0222 { 0223 if (m_styleType == newStyleType) 0224 return; 0225 0226 m_styleType = newStyleType; 0227 Q_EMIT styleTypeChanged(m_styleType); 0228 } 0229 0230 void ThemeManager::onAccentColorChanged(const QString &newAccentColor) 0231 { 0232 if (m_accentColor == newAccentColor) 0233 return; 0234 0235 m_accentColor = newAccentColor; 0236 Q_EMIT accentColorChanged(m_accentColor); 0237 } 0238 0239 void ThemeManager::onWindowControlsThemeChanged(const QString &newWindowControlsTheme) 0240 { 0241 if (m_windowControlsTheme == newWindowControlsTheme) 0242 return; 0243 0244 m_windowControlsTheme = newWindowControlsTheme; 0245 Q_EMIT windowControlsThemeChanged(m_windowControlsTheme); 0246 } 0247 0248 void ThemeManager::onIconThemeChanged(const QString &newIconTheme) 0249 { 0250 if (m_iconTheme == newIconTheme) 0251 return; 0252 0253 m_iconTheme = newIconTheme; 0254 Q_EMIT iconThemeChanged(m_iconTheme); 0255 } 0256 0257 void ThemeManager::onEnableCSDChanged(const bool &enableCSD) 0258 { 0259 if (m_enableCSD == enableCSD) 0260 return; 0261 0262 m_enableCSD = enableCSD; 0263 Q_EMIT enableCSDChanged(m_enableCSD); 0264 } 0265 0266 void ThemeManager::onBorderRadiusChanged(const uint &radius) 0267 { 0268 if (m_borderRadius == radius) 0269 return; 0270 m_borderRadius = radius; 0271 Q_EMIT borderRadiusChanged(m_borderRadius); 0272 } 0273 0274 void ThemeManager::onIconSizeChanged(const uint &size) 0275 { 0276 if (m_iconSize == size) 0277 return; 0278 m_iconSize = size; 0279 Q_EMIT iconSizeChanged(m_iconSize); 0280 } 0281 0282 void ThemeManager::onPaddingSizeChanged(const uint &paddingSize) 0283 { 0284 if (m_paddingSize == paddingSize) 0285 return; 0286 0287 m_paddingSize = paddingSize; 0288 Q_EMIT paddingSizeChanged(m_paddingSize); 0289 } 0290 0291 void ThemeManager::onMarginSizeChanged(const uint &marginSize) 0292 { 0293 if (m_marginSize == marginSize) 0294 return; 0295 0296 m_marginSize = marginSize; 0297 Q_EMIT marginSizeChanged(m_marginSize); 0298 } 0299 0300 void ThemeManager::onSpacingSizeChanged(const uint &spacingSize) 0301 { 0302 if (m_spacingSize == spacingSize) 0303 return; 0304 0305 m_spacingSize = spacingSize; 0306 Q_EMIT spacingSizeChanged(m_spacingSize); 0307 } 0308 0309 void ThemeManager::onEnableEffectsChanged(bool enableEffects) 0310 { 0311 qDebug() << "ENABLE EFEFCTS MODIFIED" << enableEffects; 0312 if (m_enableEffects == enableEffects) 0313 return; 0314 0315 m_enableEffects = enableEffects; 0316 Q_EMIT enableEffectsChanged(m_enableEffects); 0317 } 0318 0319 void ThemeManager::onDefaultFontChanged(const QString &font) 0320 { 0321 if (m_defaultFont == font) 0322 return; 0323 0324 m_defaultFont = font; 0325 Q_EMIT defaultFontChanged(m_defaultFont); 0326 } 0327 0328 void ThemeManager::onSmallFontChanged(const QString &font) 0329 { 0330 if (m_smallFont == font) 0331 return; 0332 0333 m_smallFont = font; 0334 Q_EMIT smallFontChanged(m_smallFont); 0335 } 0336 0337 void ThemeManager::onMonospacedFontChanged(const QString &font) 0338 { 0339 if (m_monospacedFont == font) 0340 return; 0341 0342 m_monospacedFont = font; 0343 Q_EMIT monospacedFontChanged(m_monospacedFont); 0344 } 0345 0346 void ThemeManager::onCustomColorSchemeChanged(const QString &scheme) 0347 { 0348 if (m_customColorScheme == scheme) 0349 return; 0350 0351 m_customColorScheme = scheme; 0352 Q_EMIT customColorSchemeChanged(m_customColorScheme); 0353 } 0354 0355 uint ThemeManager::borderRadius() const 0356 { 0357 return m_borderRadius; 0358 } 0359 0360 void ThemeManager::setBorderRadius(uint newBorderRadius) 0361 { 0362 if (m_borderRadius == newBorderRadius) 0363 return; 0364 m_borderRadius = newBorderRadius; 0365 m_settings->save(QStringLiteral("BorderRadius"), m_borderRadius); 0366 sync(QStringLiteral("setBorderRadius"), m_borderRadius); 0367 Q_EMIT borderRadiusChanged(m_borderRadius); 0368 } 0369 0370 void ThemeManager::resetBorderRadius() 0371 { 0372 this->setBorderRadius(ThemeManager::DefaultValues::borderRadius); 0373 } 0374 0375 uint ThemeManager::iconSize() const 0376 { 0377 return m_iconSize; 0378 } 0379 0380 void ThemeManager::setIconSize(uint newIconSize) 0381 { 0382 if (m_iconSize == newIconSize) 0383 return; 0384 m_iconSize = newIconSize; 0385 m_settings->save(QStringLiteral("IconSize"), m_iconSize); 0386 sync(QStringLiteral("setIconSize"), m_iconSize); 0387 Q_EMIT iconSizeChanged(m_iconSize); 0388 } 0389 0390 bool ThemeManager::enableEffects() const 0391 { 0392 return m_enableEffects; 0393 } 0394 0395 void ThemeManager::setEnableEffects(bool enableEffects) 0396 { 0397 if (m_enableEffects == enableEffects) 0398 return; 0399 0400 m_enableEffects = enableEffects; 0401 m_settings->save(QStringLiteral("EnableEffects"), m_enableEffects); 0402 sync(QStringLiteral("setEnableEffects"), m_enableEffects); 0403 Q_EMIT enableEffectsChanged(m_enableEffects); 0404 } 0405 0406 uint ThemeManager::paddingSize() const 0407 { 0408 return m_paddingSize; 0409 } 0410 0411 uint ThemeManager::marginSize() const 0412 { 0413 return m_marginSize; 0414 } 0415 0416 void ThemeManager::setPaddingSize(uint paddingSize) 0417 { 0418 if (m_paddingSize == paddingSize) 0419 return; 0420 0421 m_paddingSize = paddingSize; 0422 m_settings->save(QStringLiteral("PaddingSize"), m_paddingSize); 0423 sync(QStringLiteral("setPaddingSize"), m_paddingSize); 0424 Q_EMIT paddingSizeChanged(m_paddingSize); 0425 } 0426 0427 void ThemeManager::resetPaddingSize() 0428 { 0429 this->setPaddingSize(ThemeManager::DefaultValues::paddingSize); 0430 } 0431 0432 void ThemeManager::setMarginSize(uint marginSize) 0433 { 0434 if (m_marginSize == marginSize) 0435 return; 0436 0437 m_marginSize = marginSize; 0438 m_settings->save(QStringLiteral("MarginSize"), m_marginSize); 0439 sync(QStringLiteral("setMarginSize"), m_marginSize); 0440 Q_EMIT marginSizeChanged(m_marginSize); 0441 } 0442 0443 void ThemeManager::resetMarginSize() 0444 { 0445 this->setMarginSize(ThemeManager::DefaultValues::marginSize); 0446 } 0447 0448 uint ThemeManager::spacingSize() const 0449 { 0450 return m_spacingSize; 0451 } 0452 0453 void ThemeManager::setSpacingSize(uint spacingSize) 0454 { 0455 if (m_spacingSize == spacingSize) 0456 return; 0457 0458 m_spacingSize = spacingSize; 0459 m_settings->save(QStringLiteral("SpacingSize"), m_spacingSize); 0460 sync(QStringLiteral("setSpacingSize"), m_spacingSize); 0461 Q_EMIT spacingSizeChanged(m_spacingSize); 0462 } 0463 0464 void ThemeManager::resetSPacingSize() 0465 { 0466 this->setSpacingSize(ThemeManager::DefaultValues::spacingSize); 0467 } 0468 0469 QString ThemeManager::defaultFont() const 0470 { 0471 return m_defaultFont; 0472 } 0473 0474 QString ThemeManager::smallFont() const 0475 { 0476 return m_smallFont; 0477 } 0478 0479 QString ThemeManager::monospacedFont() const 0480 { 0481 return m_monospacedFont; 0482 } 0483 0484 void ThemeManager::setDefaultFont(const QString &defaultFont) 0485 { 0486 if (m_defaultFont == defaultFont) 0487 return; 0488 0489 m_defaultFont = defaultFont; 0490 m_settings->save(QStringLiteral("DefaultFont"), m_defaultFont); 0491 sync(QStringLiteral("setDefaultFont"), m_defaultFont); 0492 Q_EMIT defaultFontChanged(m_defaultFont); 0493 } 0494 0495 void ThemeManager::resetDefaultFont() 0496 { 0497 setDefaultFont(ThemeManager::DefaultValues::defaultFont); 0498 } 0499 0500 void ThemeManager::setSmallFont(const QString &smallFont) 0501 { 0502 if (m_smallFont == smallFont) 0503 return; 0504 0505 m_smallFont = smallFont; 0506 m_settings->save(QStringLiteral("SmallFont"), m_smallFont); 0507 sync(QStringLiteral("setSmallFont"), m_smallFont); 0508 Q_EMIT smallFontChanged(m_smallFont); 0509 } 0510 0511 void ThemeManager::resetSmallFont() 0512 { 0513 setSmallFont(ThemeManager::DefaultValues::smallFont); 0514 } 0515 0516 void ThemeManager::setMonospacedFont(const QString &monospacedFont) 0517 { 0518 if (m_monospacedFont == monospacedFont) 0519 return; 0520 0521 m_monospacedFont = monospacedFont; 0522 m_settings->save(QStringLiteral("MonospacedFont"), m_monospacedFont); 0523 sync(QStringLiteral("setMonospacedFont"), m_monospacedFont); 0524 Q_EMIT monospacedFontChanged(m_monospacedFont); 0525 } 0526 0527 void ThemeManager::resetMonospacedFont() 0528 { 0529 setMonospacedFont(ThemeManager::DefaultValues::monospacedFont); 0530 } 0531 0532 QString ThemeManager::customColorScheme() const 0533 { 0534 return m_customColorScheme; 0535 } 0536 0537 void ThemeManager::setCustomColorScheme(const QString &customColorScheme) 0538 { 0539 if (m_customColorScheme == customColorScheme) 0540 return; 0541 0542 m_customColorScheme = customColorScheme; 0543 m_settings->save(QStringLiteral("CustomColorScheme"), m_customColorScheme); 0544 sync(QStringLiteral("setCustomColorScheme"), m_customColorScheme); 0545 Q_EMIT customColorSchemeChanged(m_customColorScheme); 0546 } 0547 0548 void MauiMan::ThemeManager::resetIconSize() 0549 { 0550 this->setIconSize(ThemeManager::DefaultValues::iconSize); 0551 }