File indexing completed on 2024-10-27 04:24:10
0001 #include "backgroundmanager.h" 0002 0003 #include "settingsstore.h" 0004 #include "mauimanutils.h" 0005 0006 #include <QDebug> 0007 0008 #if !defined Q_OS_ANDROID 0009 #include <QDBusInterface> 0010 #endif 0011 0012 using namespace MauiMan; 0013 BackgroundManager::BackgroundManager(QObject *parent) : QObject(parent) 0014 ,m_settings(new MauiMan::SettingsStore(this)) 0015 { 0016 qDebug( " INIT BACKGORUND MANAGER"); 0017 #if !defined Q_OS_ANDROID 0018 auto server = new MauiManUtils(this); 0019 if(server->serverRunning()) 0020 { 0021 this->setConnections(); 0022 0023 } 0024 0025 connect(server, &MauiManUtils::serverRunningChanged, [this](bool state) 0026 { 0027 if(state) 0028 { 0029 this->setConnections(); 0030 } 0031 }); 0032 #endif 0033 0034 loadSettings(); 0035 0036 } 0037 0038 QString BackgroundManager::wallpaperSource() const 0039 { 0040 return m_wallpaperSource; 0041 } 0042 0043 bool BackgroundManager::dimWallpaper() const 0044 { 0045 return m_dimWallpaper; 0046 } 0047 0048 bool BackgroundManager::fitWallpaper() const 0049 { 0050 return m_fitWallpaper; 0051 } 0052 0053 QString BackgroundManager::solidColor() const 0054 { 0055 return m_solidColor; 0056 } 0057 0058 bool BackgroundManager::showWallpaper() const 0059 { 0060 return m_showWallpaper; 0061 } 0062 0063 void BackgroundManager::setWallpaperSource(QString wallpaperSource) 0064 { 0065 if (m_wallpaperSource == wallpaperSource) 0066 return; 0067 0068 m_wallpaperSource = wallpaperSource; 0069 m_settings->save(QStringLiteral("Wallpaper"), m_wallpaperSource); 0070 sync(QStringLiteral("setWallpaperSource"), m_wallpaperSource); 0071 Q_EMIT wallpaperSourceChanged(m_wallpaperSource); 0072 } 0073 0074 void BackgroundManager::setDimWallpaper(bool dimWallpaper) 0075 { 0076 if (m_dimWallpaper == dimWallpaper) 0077 return; 0078 0079 m_dimWallpaper = dimWallpaper; 0080 m_settings->save(QStringLiteral("DimWallpaper"), m_dimWallpaper); 0081 sync(QStringLiteral("setDimWallpaper"), m_dimWallpaper); 0082 Q_EMIT dimWallpaperChanged(m_dimWallpaper); 0083 } 0084 0085 void BackgroundManager::setFitWallpaper(bool fitWallpaper) 0086 { 0087 if (m_fitWallpaper == fitWallpaper) 0088 return; 0089 0090 m_fitWallpaper = fitWallpaper; 0091 m_settings->save(QStringLiteral("FitWallpaper"), m_fitWallpaper); 0092 sync(QStringLiteral("setFitWallpaper"), m_fitWallpaper); 0093 Q_EMIT fitWallpaperChanged(m_fitWallpaper); 0094 } 0095 0096 void BackgroundManager::setSolidColor(QString solidColor) 0097 { 0098 if (m_solidColor == solidColor) 0099 return; 0100 0101 m_solidColor = solidColor; 0102 m_settings->save(QStringLiteral("SolidColor"), m_solidColor); 0103 sync(QStringLiteral("setSolidColor"), m_solidColor); 0104 Q_EMIT solidColorChanged(m_solidColor); 0105 } 0106 0107 void BackgroundManager::setShowWallpaper(bool showWallpaper) 0108 { 0109 if (m_showWallpaper == showWallpaper) 0110 return; 0111 0112 m_showWallpaper = showWallpaper; 0113 sync(QStringLiteral("setShowWallpaper"), m_showWallpaper); 0114 m_settings->save(QStringLiteral("ShowWallpaper"), m_showWallpaper); 0115 Q_EMIT showWallpaperChanged(m_showWallpaper); 0116 } 0117 0118 QString BackgroundManager::wallpaperSourceDir() const 0119 { 0120 return m_wallpaperSourceDir; 0121 } 0122 0123 void BackgroundManager::setWallpaperSourceDir(QString wallpaperSourceDir) 0124 { 0125 if (m_wallpaperSourceDir == wallpaperSourceDir) 0126 return; 0127 0128 m_wallpaperSourceDir = wallpaperSourceDir; 0129 Q_EMIT wallpaperSourceDirChanged(m_wallpaperSourceDir); 0130 } 0131 0132 void BackgroundManager::onWallpaperChanged(const QString &wallpaperSource) 0133 { 0134 if (m_wallpaperSource == wallpaperSource) 0135 return; 0136 0137 m_wallpaperSource = wallpaperSource; 0138 Q_EMIT wallpaperSourceChanged(m_wallpaperSource); 0139 } 0140 0141 void BackgroundManager::onSolidColorChanged(const QString &solidColor) 0142 { 0143 if (m_solidColor == solidColor) 0144 return; 0145 0146 m_solidColor = solidColor; 0147 Q_EMIT solidColorChanged(m_solidColor); 0148 } 0149 0150 void BackgroundManager::onFitWallpaperChanged(const bool &fitWallpaper) 0151 { 0152 if (m_fitWallpaper == fitWallpaper) 0153 return; 0154 0155 m_fitWallpaper = fitWallpaper; 0156 Q_EMIT fitWallpaperChanged(m_fitWallpaper); 0157 } 0158 0159 void BackgroundManager::onDimWallpaperChanged(const bool &dimWallpaper) 0160 { 0161 if (m_dimWallpaper == dimWallpaper) 0162 return; 0163 0164 m_dimWallpaper = dimWallpaper; 0165 Q_EMIT dimWallpaperChanged(m_dimWallpaper); 0166 } 0167 0168 void BackgroundManager::onShowWallpaperChanged(const bool &showWallpaper) 0169 { 0170 if (m_showWallpaper == showWallpaper) 0171 return; 0172 0173 m_showWallpaper = showWallpaper; 0174 Q_EMIT showWallpaperChanged(m_showWallpaper); 0175 } 0176 0177 void BackgroundManager::sync(const QString &key, const QVariant &value) 0178 { 0179 #if !defined Q_OS_ANDROID 0180 if (m_interface && m_interface->isValid()) 0181 { 0182 m_interface->call(key, value); 0183 } 0184 #else 0185 Q_UNUSED(key) 0186 Q_UNUSED(value) 0187 #endif 0188 } 0189 0190 void BackgroundManager::setConnections() 0191 { 0192 #if !defined Q_OS_ANDROID 0193 0194 if(m_interface) 0195 { 0196 m_interface->disconnect(); 0197 m_interface->deleteLater(); 0198 m_interface = nullptr; 0199 } 0200 0201 m_interface = new QDBusInterface (QStringLiteral("org.mauiman.Manager"), 0202 QStringLiteral("/Background"), 0203 QStringLiteral("org.mauiman.Background"), 0204 QDBusConnection::sessionBus(), this); 0205 if (m_interface->isValid()) 0206 { 0207 connect(m_interface, SIGNAL(wallpaperSourceChanged(QString)), this, SLOT(onWallpaperChanged(QString))); 0208 connect(m_interface, SIGNAL(solidColorChanged(QString)), this, SLOT(onSolidColorChanged(QString))); 0209 connect(m_interface, SIGNAL(fitWallpaperChanged(bool)), this, SLOT(onFitWallpaperChanged(bool))); 0210 connect(m_interface, SIGNAL(showWallpaperChanged(bool)), this, SLOT(onShowWallpaperChanged(bool))); 0211 connect(m_interface, SIGNAL(dimWallpaperChanged(bool)), this, SLOT(onDimWallpaperChanged(bool))); 0212 0213 } 0214 #endif 0215 } 0216 0217 void BackgroundManager::loadSettings() 0218 { 0219 m_settings->beginModule(QStringLiteral("Background")); 0220 0221 #if !defined Q_OS_ANDROID 0222 0223 if(m_interface && m_interface->isValid()) 0224 { 0225 m_wallpaperSource = m_interface->property("wallpaperSource").toString(); 0226 m_dimWallpaper = m_interface->property("dimWallpaper").toBool(); 0227 m_showWallpaper = m_interface->property("showWallpaper").toBool(); 0228 m_fitWallpaper = m_interface->property("fitWallpaper").toBool(); 0229 m_solidColor = m_interface->property("solidColor").toString(); 0230 return; 0231 } 0232 #endif 0233 0234 m_wallpaperSource = m_settings->load(QStringLiteral("Wallpaper"), m_wallpaperSource).toString(); 0235 m_dimWallpaper = m_settings->load(QStringLiteral("DimWallpaper"), m_dimWallpaper).toBool(); 0236 m_showWallpaper = m_settings->load(QStringLiteral("ShowWallpaper"), m_showWallpaper).toBool(); 0237 m_fitWallpaper = m_settings->load(QStringLiteral("FitWallpaper"), m_fitWallpaper).toBool(); 0238 m_solidColor = m_settings->load(QStringLiteral("SolidColor"), m_solidColor).toString(); 0239 }