File indexing completed on 2024-11-24 04:19:36

0001 #include "theme.h"
0002 #include "themeadaptor.h"
0003 #include <QDBusInterface>
0004 
0005 #include "settingsstore.h"
0006 
0007 #include <QDebug>
0008 
0009 Theme::Theme(QObject *parent) : QObject(parent)
0010 {
0011     qDebug("INIT THEME SERVER");
0012     new ThemeAdaptor(this);
0013     if(!QDBusConnection::sessionBus().registerObject(QStringLiteral("/Theme"), this))
0014     {
0015         qDebug() << "FAILED TO REGISTER THEME DBUS OBJECT";
0016         return;
0017     }
0018 
0019     bool ok = false;
0020 
0021     MauiMan::SettingsStore settings;
0022 
0023     settings.beginModule(QStringLiteral("Theme"));
0024 
0025     m_accentColor = settings.load(QStringLiteral("AccentColor"), m_accentColor).toString();
0026     m_iconTheme = settings.load(QStringLiteral("IconTheme"), m_iconTheme).toString();
0027     m_windowControlsTheme = settings.load(QStringLiteral("WindowControlsTheme"), m_windowControlsTheme).toString();
0028     m_styleType = settings.load(QStringLiteral("StyleType"), m_styleType).toInt(&ok);
0029     m_enableCSD = settings.load(QStringLiteral("EnableCSD"), m_enableCSD).toBool();
0030     m_borderRadius = settings.load(QStringLiteral("BorderRadius"), m_borderRadius).toUInt();
0031     m_iconSize = settings.load(QStringLiteral("IconSize"), m_iconSize).toUInt(&ok);
0032     m_paddingSize = settings.load(QStringLiteral("PaddingSize"), m_paddingSize).toUInt(&ok);
0033     m_marginSize = settings.load(QStringLiteral("MarginSize"), m_marginSize).toUInt(&ok);
0034     m_spacingSize = settings.load(QStringLiteral("SpacingSize"), m_spacingSize).toUInt(&ok);
0035     m_enableEffects = settings.load(QStringLiteral("EnableEffects"), m_enableEffects).toBool();
0036     m_defaultFont = settings.load(QStringLiteral("DefaultFont"), m_defaultFont).toString();
0037     m_smallFont = settings.load(QStringLiteral("SmallFont"), m_smallFont).toString();
0038     m_monospacedFont = settings.load(QStringLiteral("MonospacedFont"), m_monospacedFont).toString();
0039     m_customColorScheme = settings.load(QStringLiteral("CustomColorScheme"), m_customColorScheme).toString();
0040 
0041     settings.endModule();
0042 }
0043 
0044 int Theme::styleType() const
0045 {
0046     return m_styleType;
0047 }
0048 
0049 void Theme::setStyleType(int newStyleType)
0050 {
0051     if (m_styleType == newStyleType)
0052         return;
0053     m_styleType = newStyleType;
0054     Q_EMIT styleTypeChanged(m_styleType);
0055 }
0056 
0057 const QString &Theme::accentColor() const
0058 {
0059     return m_accentColor;
0060 }
0061 
0062 void Theme::setAccentColor(const QString &newAccentColor)
0063 {
0064     if (m_accentColor == newAccentColor)
0065         return;
0066     m_accentColor = newAccentColor;
0067     Q_EMIT accentColorChanged(m_accentColor);
0068 }
0069 
0070 const QString &Theme::iconTheme() const
0071 {
0072     return m_iconTheme;
0073 }
0074 
0075 void Theme::setIconTheme(const QString &newIconTheme)
0076 {
0077     if (m_iconTheme == newIconTheme)
0078         return;
0079     m_iconTheme = newIconTheme;
0080     Q_EMIT iconThemeChanged(m_iconTheme);
0081 }
0082 
0083 const QString &Theme::windowControlsTheme() const
0084 {
0085     return m_windowControlsTheme;
0086 }
0087 
0088 void Theme::setWindowControlsTheme(const QString &newWindowControlsTheme)
0089 {
0090     if (m_windowControlsTheme == newWindowControlsTheme)
0091         return;
0092     m_windowControlsTheme = newWindowControlsTheme;
0093     Q_EMIT windowControlsThemeChanged(m_windowControlsTheme);
0094 }
0095 
0096 bool Theme::enableCSD() const
0097 {
0098     return m_enableCSD;
0099 }
0100 
0101 void Theme::setEnableCSD(bool enableCSD)
0102 {
0103     if (m_enableCSD == enableCSD)
0104         return;
0105 
0106     m_enableCSD = enableCSD;
0107     Q_EMIT enableCSDChanged(m_enableCSD);
0108 }
0109 
0110 uint Theme::borderRadius() const
0111 {
0112     return m_borderRadius;
0113 }
0114 
0115 void Theme::setBorderRadius(uint newBorderRadius)
0116 {
0117     if (m_borderRadius == newBorderRadius)
0118         return;
0119     m_borderRadius = newBorderRadius;
0120     Q_EMIT borderRadiusChanged(m_borderRadius);
0121 }
0122 
0123 uint Theme::iconSize() const
0124 {
0125     return m_iconSize;
0126 }
0127 
0128 void Theme::setIconSize(uint newIconSize)
0129 {
0130     if (m_iconSize == newIconSize)
0131         return;
0132     m_iconSize = newIconSize;
0133     Q_EMIT iconSizeChanged(m_iconSize);
0134 }
0135 
0136 bool Theme::enableEffects() const
0137 {
0138     return m_enableEffects;
0139 }
0140 
0141 void Theme::setEnableEffects(bool enableEffects)
0142 {
0143     if (m_enableEffects == enableEffects)
0144         return;
0145 
0146     m_enableEffects = enableEffects;
0147     Q_EMIT enableEffectsChanged(m_enableEffects);
0148 }
0149 
0150 uint Theme::paddingSize() const
0151 {
0152     return m_paddingSize;
0153 }
0154 
0155 uint Theme::marginSize() const
0156 {
0157     return m_marginSize;
0158 }
0159 
0160 uint Theme::spacingSize() const
0161 {
0162     return m_spacingSize;
0163 }
0164 
0165 void Theme::setSpacingSize(uint spacingSize)
0166 {
0167     if (m_spacingSize == spacingSize)
0168         return;
0169 
0170     m_spacingSize = spacingSize;
0171     Q_EMIT spacingSizeChanged(m_spacingSize);
0172 }
0173 
0174 QString Theme::defaultFont() const
0175 {
0176     return m_defaultFont;
0177 }
0178 
0179 QString Theme::smallFont() const
0180 {
0181     return m_smallFont;
0182 }
0183 
0184 QString Theme::monospacedFont() const
0185 {
0186     return m_monospacedFont;
0187 }
0188 
0189 void Theme::setDefaultFont(const QString &defaultFont)
0190 {
0191     if (m_defaultFont == defaultFont)
0192         return;
0193 
0194     m_defaultFont = defaultFont;
0195     Q_EMIT defaultFontChanged(m_defaultFont);
0196 }
0197 
0198 void Theme::setSmallFont(const QString &smallFont)
0199 {
0200     if (m_smallFont == smallFont)
0201         return;
0202 
0203     m_smallFont = smallFont;
0204     Q_EMIT smallFontChanged(m_smallFont);
0205 }
0206 
0207 void Theme::setMonospacedFont(const QString &monospacedFont)
0208 {
0209     if (m_monospacedFont == monospacedFont)
0210         return;
0211 
0212     m_monospacedFont = monospacedFont;
0213     Q_EMIT monospacedFontChanged(m_monospacedFont);
0214 }
0215 
0216 QString Theme::customColorScheme() const
0217 {
0218     return m_customColorScheme;
0219 }
0220 
0221 void Theme::setCustomColorScheme(const QString &customColorScheme)
0222 {
0223     if (m_customColorScheme == customColorScheme)
0224         return;
0225 
0226     m_customColorScheme = customColorScheme;
0227     Q_EMIT customColorSchemeChanged(m_customColorScheme);
0228 }
0229 
0230 void Theme::setPaddingSize(uint paddingSize)
0231 {
0232     if (m_paddingSize == paddingSize)
0233         return;
0234 
0235     m_paddingSize = paddingSize;
0236     Q_EMIT paddingSizeChanged(m_paddingSize);
0237 }
0238 
0239 void Theme::setMarginSize(uint marginSize)
0240 {
0241     if (m_marginSize == marginSize)
0242         return;
0243 
0244     m_marginSize = marginSize;
0245     Q_EMIT marginSizeChanged(m_marginSize);
0246 }