File indexing completed on 2024-10-27 04:24:09
0001 #include "accessibilitymanager.h" 0002 #include "settingsstore.h" 0003 #include "mauimanutils.h" 0004 0005 #include <QDebug> 0006 0007 #if !defined Q_OS_ANDROID 0008 #include <QDBusInterface> 0009 #endif 0010 0011 using namespace MauiMan; 0012 0013 AccessibilityManager::AccessibilityManager(QObject *parent) : QObject(parent) 0014 ,m_settings(new MauiMan::SettingsStore(this)) 0015 { 0016 qDebug( " INIT ACCESSIBILITY MANAGER"); 0017 0018 #if !defined Q_OS_ANDROID 0019 auto server = new MauiManUtils(this); 0020 if(server->serverRunning()) 0021 { 0022 this->setConnections(); 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 bool AccessibilityManager::singleClick() const 0038 { 0039 return m_singleClick; 0040 } 0041 0042 void AccessibilityManager::setSingleClick(bool singleClick) 0043 { 0044 if (m_singleClick == singleClick) 0045 return; 0046 0047 m_singleClick = singleClick; 0048 0049 sync(QStringLiteral("setSingleClick"), m_singleClick); 0050 m_settings->save(QStringLiteral("SingleClick"), m_singleClick); 0051 0052 Q_EMIT singleClickChanged(m_singleClick); 0053 } 0054 0055 void AccessibilityManager::onSingleClickChanged(bool singleClick) 0056 { 0057 if (m_singleClick == singleClick) 0058 return; 0059 0060 m_singleClick = singleClick; 0061 Q_EMIT singleClickChanged(m_singleClick); 0062 } 0063 0064 void AccessibilityManager::onScrollBarPolicyChanged(uint scrollBarPolicy) 0065 { 0066 if (m_scrollBarPolicy == scrollBarPolicy) 0067 return; 0068 0069 m_scrollBarPolicy = scrollBarPolicy; 0070 Q_EMIT scrollBarPolicyChanged(m_scrollBarPolicy); 0071 } 0072 0073 void AccessibilityManager::onPlaySoundsChanged(bool playSounds) 0074 { 0075 if (m_playSounds == playSounds) 0076 return; 0077 0078 m_playSounds = playSounds; 0079 Q_EMIT playSoundsChanged(m_playSounds); 0080 } 0081 0082 void AccessibilityManager::sync(const QString &key, const QVariant &value) 0083 { 0084 #if !defined Q_OS_ANDROID 0085 if (m_interface && m_interface->isValid()) 0086 { 0087 m_interface->call(key, value); 0088 } 0089 #endif 0090 } 0091 0092 void AccessibilityManager::setConnections() 0093 { 0094 #if !defined Q_OS_ANDROID 0095 if(m_interface) 0096 { 0097 m_interface->disconnect(); 0098 m_interface->deleteLater(); 0099 m_interface = nullptr; 0100 } 0101 0102 m_interface = new QDBusInterface(QStringLiteral("org.mauiman.Manager"), 0103 QStringLiteral("/Accessibility"), 0104 QStringLiteral("org.mauiman.Accessibility"), 0105 QDBusConnection::sessionBus(), this); 0106 0107 if (m_interface->isValid()) 0108 { 0109 connect(m_interface, SIGNAL(singleClickChanged(bool)), this, SLOT(onSingleClickChanged(bool))); 0110 connect(m_interface, SIGNAL(playSoundsChanged(bool)), this, SLOT(onPlaySoundsChanged(bool))); 0111 connect(m_interface, SIGNAL(scrollBarPolicyChanged(uint)), this, SLOT(onScrollBarPolicyChanged(uint))); 0112 } 0113 #endif 0114 } 0115 0116 void AccessibilityManager::loadSettings() 0117 { 0118 m_settings->beginModule(QStringLiteral("Accessibility")); 0119 0120 #if !defined Q_OS_ANDROID 0121 if(m_interface && m_interface->isValid()) 0122 { 0123 m_singleClick = m_interface->property("singleClick").toBool(); 0124 m_scrollBarPolicy = m_interface->property("scrollBarPolicy").toUInt(); 0125 m_playSounds = m_interface->property("playSounds").toBool(); 0126 return; 0127 } 0128 #endif 0129 0130 m_singleClick = m_settings->load(QStringLiteral("SingleClick"), m_singleClick).toBool(); 0131 m_scrollBarPolicy = m_settings->load(QStringLiteral("ScrollBarPolicy"), m_scrollBarPolicy).toUInt(); 0132 m_playSounds = m_settings->load(QStringLiteral("PlaySounds"), m_playSounds).toBool(); 0133 } 0134 0135 uint AccessibilityManager::scrollBarPolicy() const 0136 { 0137 return m_scrollBarPolicy; 0138 } 0139 0140 void AccessibilityManager::setScrollBarPolicy(uint newScrollBarPolicy) 0141 { 0142 if (m_scrollBarPolicy == newScrollBarPolicy) 0143 return; 0144 0145 m_scrollBarPolicy = newScrollBarPolicy; 0146 0147 sync(QStringLiteral("setScrollBarPolicy"), m_scrollBarPolicy); 0148 m_settings->save(QStringLiteral("ScrollBarPolicy"), m_scrollBarPolicy); 0149 0150 Q_EMIT scrollBarPolicyChanged(m_scrollBarPolicy); 0151 } 0152 0153 bool AccessibilityManager::playSounds() const 0154 { 0155 return m_playSounds; 0156 } 0157 0158 void AccessibilityManager::setPlaySounds(bool newPlaySounds) 0159 { 0160 if (m_playSounds == newPlaySounds) 0161 return; 0162 0163 m_playSounds = newPlaySounds; 0164 0165 sync(QStringLiteral("setPlaySounds"), m_playSounds); 0166 m_settings->save(QStringLiteral("PlaySounds"), m_playSounds); 0167 0168 Q_EMIT playSoundsChanged(m_playSounds); 0169 }