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#endif
90}
91
92void AccessibilityManager::setConnections()
93{
94#if !defined Q_OS_ANDROID
95 if(m_interface)
96 {
97 m_interface->disconnect();
98 m_interface->deleteLater();
99 m_interface = nullptr;
100 }
101
102 m_interface = new QDBusInterface(QStringLiteral("org.mauiman.Manager"),
103 QStringLiteral("/Accessibility"),
104 QStringLiteral("org.mauiman.Accessibility"),
106
107 if (m_interface->isValid())
108 {
109 connect(m_interface, SIGNAL(singleClickChanged(bool)), this, SLOT(onSingleClickChanged(bool)));
110 connect(m_interface, SIGNAL(playSoundsChanged(bool)), this, SLOT(onPlaySoundsChanged(bool)));
111 connect(m_interface, SIGNAL(scrollBarPolicyChanged(uint)), this, SLOT(onScrollBarPolicyChanged(uint)));
112 }
113#endif
114}
115
116void AccessibilityManager::loadSettings()
117{
118 m_settings->beginModule(QStringLiteral("Accessibility"));
119
120#if !defined Q_OS_ANDROID
121 if(m_interface && m_interface->isValid())
122 {
123 m_singleClick = m_interface->property("singleClick").toBool();
124 m_scrollBarPolicy = m_interface->property("scrollBarPolicy").toUInt();
125 m_playSounds = m_interface->property("playSounds").toBool();
126 return;
127 }
128#endif
129
130 m_singleClick = m_settings->load(QStringLiteral("SingleClick"), m_singleClick).toBool();
131 m_scrollBarPolicy = m_settings->load(QStringLiteral("ScrollBarPolicy"), m_scrollBarPolicy).toUInt();
132 m_playSounds = m_settings->load(QStringLiteral("PlaySounds"), m_playSounds).toBool();
133}
134
136{
137 return m_scrollBarPolicy;
138}
139
140void AccessibilityManager::setScrollBarPolicy(uint newScrollBarPolicy)
141{
142 if (m_scrollBarPolicy == newScrollBarPolicy)
143 return;
144
145 m_scrollBarPolicy = newScrollBarPolicy;
146
147 sync(QStringLiteral("setScrollBarPolicy"), m_scrollBarPolicy);
148 m_settings->save(QStringLiteral("ScrollBarPolicy"), m_scrollBarPolicy);
149
150 Q_EMIT scrollBarPolicyChanged(m_scrollBarPolicy);
151}
152
154{
155 return m_playSounds;
156}
157
158void AccessibilityManager::setPlaySounds(bool newPlaySounds)
159{
160 if (m_playSounds == newPlaySounds)
161 return;
162
163 m_playSounds = newPlaySounds;
164
165 sync(QStringLiteral("setPlaySounds"), m_playSounds);
166 m_settings->save(QStringLiteral("PlaySounds"), m_playSounds);
167
168 Q_EMIT playSoundsChanged(m_playSounds);
169}
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 Fri Jul 26 2024 11:51:22 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.