MauiMan

accessibilitymanager.cpp
1#include "accessibilitymanager.h"
2#include "settingsstore.h"
3#include "mauimanutils.h"
4
5#include <QDebug>
6
7#if !defined Q_OS_ANDROID
8#include <QDBusInterface>
9#endif
10
11using namespace MauiMan;
12
13AccessibilityManager::AccessibilityManager(QObject *parent) : QObject(parent)
14 ,m_settings(new MauiMan::SettingsStore(this))
15{
16 qDebug( " INIT ACCESSIBILITY MANAGER");
17
18#if !defined Q_OS_ANDROID
19 auto server = new MauiManUtils(this);
20 if(server->serverRunning())
21 {
22 this->setConnections();
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
38{
39 return m_singleClick;
40}
41
42void AccessibilityManager::setSingleClick(bool singleClick)
43{
44 if (m_singleClick == singleClick)
45 return;
46
47 m_singleClick = singleClick;
48
49 sync(QStringLiteral("setSingleClick"), m_singleClick);
50 m_settings->save(QStringLiteral("SingleClick"), m_singleClick);
51
52 Q_EMIT singleClickChanged(m_singleClick);
53}
54
55void AccessibilityManager::onSingleClickChanged(bool singleClick)
56{
57 if (m_singleClick == singleClick)
58 return;
59
60 m_singleClick = singleClick;
61 Q_EMIT singleClickChanged(m_singleClick);
62}
63
64void AccessibilityManager::onScrollBarPolicyChanged(uint scrollBarPolicy)
65{
66 if (m_scrollBarPolicy == scrollBarPolicy)
67 return;
68
69 m_scrollBarPolicy = scrollBarPolicy;
70 Q_EMIT scrollBarPolicyChanged(m_scrollBarPolicy);
71}
72
73void AccessibilityManager::onPlaySoundsChanged(bool playSounds)
74{
75 if (m_playSounds == playSounds)
76 return;
77
78 m_playSounds = playSounds;
79 Q_EMIT playSoundsChanged(m_playSounds);
80}
81
82void AccessibilityManager::sync(const QString &key, const QVariant &value)
83{
84#if !defined Q_OS_ANDROID
85 if (m_interface && m_interface->isValid())
86 {
87 m_interface->call(key, value);
88 }
89#else
90 Q_UNUSED(key)
91 Q_UNUSED(value)
92#endif
93}
94
95void AccessibilityManager::setConnections()
96{
97#if !defined Q_OS_ANDROID
98 if(m_interface)
99 {
100 m_interface->disconnect();
101 m_interface->deleteLater();
102 m_interface = nullptr;
103 }
104
105 m_interface = new QDBusInterface(QStringLiteral("org.mauiman.Manager"),
106 QStringLiteral("/Accessibility"),
107 QStringLiteral("org.mauiman.Accessibility"),
109
110 if (m_interface->isValid())
111 {
112 connect(m_interface, SIGNAL(singleClickChanged(bool)), this, SLOT(onSingleClickChanged(bool)));
113 connect(m_interface, SIGNAL(playSoundsChanged(bool)), this, SLOT(onPlaySoundsChanged(bool)));
114 connect(m_interface, SIGNAL(scrollBarPolicyChanged(uint)), this, SLOT(onScrollBarPolicyChanged(uint)));
115 }
116#endif
117}
118
119void AccessibilityManager::loadSettings()
120{
121 m_settings->beginModule(QStringLiteral("Accessibility"));
122
123#if !defined Q_OS_ANDROID
124 if(m_interface && m_interface->isValid())
125 {
126 m_singleClick = m_interface->property("singleClick").toBool();
127 m_scrollBarPolicy = m_interface->property("scrollBarPolicy").toUInt();
128 m_playSounds = m_interface->property("playSounds").toBool();
129 return;
130 }
131#endif
132
133 m_singleClick = m_settings->load(QStringLiteral("SingleClick"), m_singleClick).toBool();
134 m_scrollBarPolicy = m_settings->load(QStringLiteral("ScrollBarPolicy"), m_scrollBarPolicy).toUInt();
135 m_playSounds = m_settings->load(QStringLiteral("PlaySounds"), m_playSounds).toBool();
136}
137
139{
140 return m_scrollBarPolicy;
141}
142
143void AccessibilityManager::setScrollBarPolicy(uint newScrollBarPolicy)
144{
145 if (m_scrollBarPolicy == newScrollBarPolicy)
146 return;
147
148 m_scrollBarPolicy = newScrollBarPolicy;
149
150 sync(QStringLiteral("setScrollBarPolicy"), m_scrollBarPolicy);
151 m_settings->save(QStringLiteral("ScrollBarPolicy"), m_scrollBarPolicy);
152
153 Q_EMIT scrollBarPolicyChanged(m_scrollBarPolicy);
154}
155
157{
158 return m_playSounds;
159}
160
161void AccessibilityManager::setPlaySounds(bool newPlaySounds)
162{
163 if (m_playSounds == newPlaySounds)
164 return;
165
166 m_playSounds = newPlaySounds;
167
168 sync(QStringLiteral("setPlaySounds"), m_playSounds);
169 m_settings->save(QStringLiteral("PlaySounds"), m_playSounds);
170
171 Q_EMIT playSoundsChanged(m_playSounds);
172}
The MauiManUtils class.
bool singleClick
Whether to open items with a single click.
uint scrollBarPolicy
The policy for showing the scroll bars.
bool playSounds
Whether the user prefers the application to emit notification or alarm sounds.
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
uint toUInt(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:39 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.