MauiMan

backgroundmanager.cpp
1#include "backgroundmanager.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;
13BackgroundManager::BackgroundManager(QObject *parent) : QObject(parent)
14 ,m_settings(new MauiMan::SettingsStore(this))
15{
16 qDebug( " INIT BACKGORUND MANAGER");
17#if !defined Q_OS_ANDROID
18 auto server = new MauiManUtils(this);
19 if(server->serverRunning())
20 {
21 this->setConnections();
22
23 }
24
25 connect(server, &MauiManUtils::serverRunningChanged, [this](bool state)
26 {
27 if(state)
28 {
29 this->setConnections();
30 }
31 });
32#endif
33
34 loadSettings();
35
36}
37
39{
40 return m_wallpaperSource;
41}
42
44{
45 return m_dimWallpaper;
46}
47
49{
50 return m_fitWallpaper;
51}
52
54{
55 return m_solidColor;
56}
57
59{
60 return m_showWallpaper;
61}
62
63void BackgroundManager::setWallpaperSource(QString wallpaperSource)
64{
65 if (m_wallpaperSource == wallpaperSource)
66 return;
67
68 m_wallpaperSource = wallpaperSource;
69 m_settings->save(QStringLiteral("Wallpaper"), m_wallpaperSource);
70 sync(QStringLiteral("setWallpaperSource"), m_wallpaperSource);
71 Q_EMIT wallpaperSourceChanged(m_wallpaperSource);
72}
73
74void BackgroundManager::setDimWallpaper(bool dimWallpaper)
75{
76 if (m_dimWallpaper == dimWallpaper)
77 return;
78
79 m_dimWallpaper = dimWallpaper;
80 m_settings->save(QStringLiteral("DimWallpaper"), m_dimWallpaper);
81 sync(QStringLiteral("setDimWallpaper"), m_dimWallpaper);
82 Q_EMIT dimWallpaperChanged(m_dimWallpaper);
83}
84
85void BackgroundManager::setFitWallpaper(bool fitWallpaper)
86{
87 if (m_fitWallpaper == fitWallpaper)
88 return;
89
90 m_fitWallpaper = fitWallpaper;
91 m_settings->save(QStringLiteral("FitWallpaper"), m_fitWallpaper);
92 sync(QStringLiteral("setFitWallpaper"), m_fitWallpaper);
93 Q_EMIT fitWallpaperChanged(m_fitWallpaper);
94}
95
96void BackgroundManager::setSolidColor(QString solidColor)
97{
98 if (m_solidColor == solidColor)
99 return;
100
101 m_solidColor = solidColor;
102 m_settings->save(QStringLiteral("SolidColor"), m_solidColor);
103 sync(QStringLiteral("setSolidColor"), m_solidColor);
104 Q_EMIT solidColorChanged(m_solidColor);
105}
106
107void BackgroundManager::setShowWallpaper(bool showWallpaper)
108{
109 if (m_showWallpaper == showWallpaper)
110 return;
111
112 m_showWallpaper = showWallpaper;
113 sync(QStringLiteral("setShowWallpaper"), m_showWallpaper);
114 m_settings->save(QStringLiteral("ShowWallpaper"), m_showWallpaper);
115 Q_EMIT showWallpaperChanged(m_showWallpaper);
116}
117
119{
120 return m_wallpaperSourceDir;
121}
122
123void BackgroundManager::setWallpaperSourceDir(QString wallpaperSourceDir)
124{
125 if (m_wallpaperSourceDir == wallpaperSourceDir)
126 return;
127
128 m_wallpaperSourceDir = wallpaperSourceDir;
129 Q_EMIT wallpaperSourceDirChanged(m_wallpaperSourceDir);
130}
131
132void BackgroundManager::onWallpaperChanged(const QString &wallpaperSource)
133{
134 if (m_wallpaperSource == wallpaperSource)
135 return;
136
137 m_wallpaperSource = wallpaperSource;
138 Q_EMIT wallpaperSourceChanged(m_wallpaperSource);
139}
140
141void BackgroundManager::onSolidColorChanged(const QString &solidColor)
142{
143 if (m_solidColor == solidColor)
144 return;
145
146 m_solidColor = solidColor;
147 Q_EMIT solidColorChanged(m_solidColor);
148}
149
150void BackgroundManager::onFitWallpaperChanged(const bool &fitWallpaper)
151{
152 if (m_fitWallpaper == fitWallpaper)
153 return;
154
155 m_fitWallpaper = fitWallpaper;
156 Q_EMIT fitWallpaperChanged(m_fitWallpaper);
157}
158
159void BackgroundManager::onDimWallpaperChanged(const bool &dimWallpaper)
160{
161 if (m_dimWallpaper == dimWallpaper)
162 return;
163
164 m_dimWallpaper = dimWallpaper;
165 Q_EMIT dimWallpaperChanged(m_dimWallpaper);
166}
167
168void BackgroundManager::onShowWallpaperChanged(const bool &showWallpaper)
169{
170 if (m_showWallpaper == showWallpaper)
171 return;
172
173 m_showWallpaper = showWallpaper;
174 Q_EMIT showWallpaperChanged(m_showWallpaper);
175}
176
177void BackgroundManager::sync(const QString &key, const QVariant &value)
178{
179#if !defined Q_OS_ANDROID
180 if (m_interface && m_interface->isValid())
181 {
182 m_interface->call(key, value);
183 }
184#else
185 Q_UNUSED(key)
186 Q_UNUSED(value)
187#endif
188}
189
190void BackgroundManager::setConnections()
191{
192#if !defined Q_OS_ANDROID
193
194 if(m_interface)
195 {
196 m_interface->disconnect();
197 m_interface->deleteLater();
198 m_interface = nullptr;
199 }
200
201 m_interface = new QDBusInterface (QStringLiteral("org.mauiman.Manager"),
202 QStringLiteral("/Background"),
203 QStringLiteral("org.mauiman.Background"),
205 if (m_interface->isValid())
206 {
207 connect(m_interface, SIGNAL(wallpaperSourceChanged(QString)), this, SLOT(onWallpaperChanged(QString)));
208 connect(m_interface, SIGNAL(solidColorChanged(QString)), this, SLOT(onSolidColorChanged(QString)));
209 connect(m_interface, SIGNAL(fitWallpaperChanged(bool)), this, SLOT(onFitWallpaperChanged(bool)));
210 connect(m_interface, SIGNAL(showWallpaperChanged(bool)), this, SLOT(onShowWallpaperChanged(bool)));
211 connect(m_interface, SIGNAL(dimWallpaperChanged(bool)), this, SLOT(onDimWallpaperChanged(bool)));
212
213 }
214#endif
215}
216
217void BackgroundManager::loadSettings()
218{
219 m_settings->beginModule(QStringLiteral("Background"));
220
221#if !defined Q_OS_ANDROID
222
223 if(m_interface && m_interface->isValid())
224 {
225 m_wallpaperSource = m_interface->property("wallpaperSource").toString();
226 m_dimWallpaper = m_interface->property("dimWallpaper").toBool();
227 m_showWallpaper = m_interface->property("showWallpaper").toBool();
228 m_fitWallpaper = m_interface->property("fitWallpaper").toBool();
229 m_solidColor = m_interface->property("solidColor").toString();
230 return;
231 }
232#endif
233
234 m_wallpaperSource = m_settings->load(QStringLiteral("Wallpaper"), m_wallpaperSource).toString();
235 m_dimWallpaper = m_settings->load(QStringLiteral("DimWallpaper"), m_dimWallpaper).toBool();
236 m_showWallpaper = m_settings->load(QStringLiteral("ShowWallpaper"), m_showWallpaper).toBool();
237 m_fitWallpaper = m_settings->load(QStringLiteral("FitWallpaper"), m_fitWallpaper).toBool();
238 m_solidColor = m_settings->load(QStringLiteral("SolidColor"), m_solidColor).toString();
239}
The MauiManUtils class.
bool showWallpaper
Whether to display the wallpaper image.
QString wallpaperSource
The image file path to be used as the wallpaper background.
bool fitWallpaper
Whether the wallpaper image should fit the screen area, preserving its aspect ratio,...
bool dimWallpaper
Whether the wallpaper background should have a dimmed effect.
QString solidColor
A color to be used in the background.
QString wallpaperSourceDir
The preferred file path to the directory containing the wallpaper images.
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.
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
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.