File indexing completed on 2024-10-27 04:24:10
0001 #include "inputdevicesmanager.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 InputDevicesManager::InputDevicesManager(QObject *parent) : QObject(parent) 0013 ,m_settings(new MauiMan::SettingsStore(this)) 0014 { 0015 qDebug( " INIT ACCESSIBILITY MANAGER"); 0016 0017 #if !defined Q_OS_ANDROID 0018 auto server = new MauiManUtils(this); 0019 if(server->serverRunning()) 0020 { 0021 this->setConnections(); 0022 } 0023 0024 connect(server, &MauiManUtils::serverRunningChanged, [this](bool state) 0025 { 0026 if(state) 0027 { 0028 this->setConnections(); 0029 } 0030 }); 0031 #endif 0032 0033 loadSettings(); 0034 0035 } 0036 0037 QString MauiMan::InputDevicesManager::keyboardLayout() const 0038 { 0039 return m_keyboardLayout; 0040 } 0041 0042 QString MauiMan::InputDevicesManager::keyboardModel() const 0043 { 0044 return m_keyboardModel; 0045 } 0046 0047 QString MauiMan::InputDevicesManager::keyboardVariant() const 0048 { 0049 return m_keyboardVariant; 0050 } 0051 0052 QString MauiMan::InputDevicesManager::keyboardOptions() const 0053 { 0054 return m_keyboardOptions; 0055 } 0056 0057 QString MauiMan::InputDevicesManager::keyboardRules() const 0058 { 0059 return m_keyboardRules; 0060 } 0061 0062 void MauiMan::InputDevicesManager::setKeyboardLayout(QString keyboardLayout) 0063 { 0064 if (m_keyboardLayout == keyboardLayout) 0065 return; 0066 0067 m_keyboardLayout = keyboardLayout; 0068 sync(QStringLiteral("setKeyboardLayout"), m_keyboardLayout); 0069 m_settings->save(QStringLiteral("KeyboardLayout"), m_keyboardLayout); 0070 Q_EMIT keyboardLayoutChanged(m_keyboardLayout); 0071 } 0072 0073 void MauiMan::InputDevicesManager::setKeyboardModel(QString keyboardModel) 0074 { 0075 if (m_keyboardModel == keyboardModel) 0076 return; 0077 0078 m_keyboardModel = keyboardModel; 0079 sync(QStringLiteral("setKeyboardModel"), m_keyboardModel); 0080 m_settings->save(QStringLiteral("KeyboardModel"), m_keyboardModel); 0081 Q_EMIT keyboardModelChanged(m_keyboardModel); 0082 } 0083 0084 void MauiMan::InputDevicesManager::setKeyboardVariant(QString keyboardVariant) 0085 { 0086 if (m_keyboardVariant == keyboardVariant) 0087 return; 0088 0089 m_keyboardVariant = keyboardVariant; 0090 sync(QStringLiteral("setKeyboardVariant"), m_keyboardVariant); 0091 m_settings->save(QStringLiteral("KeyboardVariant"), m_keyboardVariant); 0092 Q_EMIT keyboardVariantChanged(m_keyboardVariant); 0093 } 0094 0095 void MauiMan::InputDevicesManager::setKeyboardOptions(QString keyboardOptions) 0096 { 0097 if (m_keyboardOptions == keyboardOptions) 0098 return; 0099 0100 m_keyboardOptions = keyboardOptions; 0101 sync(QStringLiteral("setKeyboardOptions"), m_keyboardOptions); 0102 m_settings->save(QStringLiteral("KeyboardOptions"), m_keyboardOptions); 0103 Q_EMIT keyboardOptionsChanged(m_keyboardOptions); 0104 } 0105 0106 void MauiMan::InputDevicesManager::setKeyboardRules(QString keyboardRules) 0107 { 0108 if (m_keyboardRules == keyboardRules) 0109 return; 0110 0111 m_keyboardRules = keyboardRules; 0112 sync(QStringLiteral("setKeyboardRules"), m_keyboardRules); 0113 m_settings->save(QStringLiteral("KeyboardRules"), m_keyboardRules); 0114 Q_EMIT keyboardRulesChanged(m_keyboardRules); 0115 } 0116 0117 void MauiMan::InputDevicesManager::onKeyboardLayoutChanged(const QString &keyboardLayout) 0118 { 0119 if (m_keyboardLayout == keyboardLayout) 0120 return; 0121 0122 m_keyboardLayout = keyboardLayout; 0123 Q_EMIT keyboardLayoutChanged(m_keyboardLayout); 0124 } 0125 0126 void MauiMan::InputDevicesManager::onKeyboardModelChanged(const QString &keyboardModel) 0127 { 0128 if (m_keyboardModel == keyboardModel) 0129 return; 0130 0131 m_keyboardModel = keyboardModel; 0132 Q_EMIT keyboardModelChanged(m_keyboardModel); 0133 } 0134 0135 void MauiMan::InputDevicesManager::onKeyboardOptionsChanged(const QString &keyboardOptions) 0136 { 0137 if (m_keyboardOptions == keyboardOptions) 0138 return; 0139 0140 m_keyboardOptions = keyboardOptions; 0141 Q_EMIT keyboardOptionsChanged(m_keyboardOptions); 0142 } 0143 0144 void MauiMan::InputDevicesManager::onKeyboardRulesChanged(const QString &keyboardRules) 0145 { 0146 if (m_keyboardRules == keyboardRules) 0147 return; 0148 0149 m_keyboardRules = keyboardRules; 0150 Q_EMIT keyboardRulesChanged(m_keyboardRules); 0151 } 0152 0153 void MauiMan::InputDevicesManager::onKeyboardVariantChanged(const QString &keyboardVariant) 0154 { 0155 if (m_keyboardVariant == keyboardVariant) 0156 return; 0157 0158 m_keyboardVariant = keyboardVariant; 0159 Q_EMIT keyboardVariantChanged(m_keyboardVariant); 0160 } 0161 0162 void MauiMan::InputDevicesManager::sync(const QString &key, const QVariant &value) 0163 { 0164 #if !defined Q_OS_ANDROID 0165 if (m_interface && m_interface->isValid()) 0166 { 0167 m_interface->call(key, value); 0168 } 0169 #else 0170 Q_UNUSED(key) 0171 Q_UNUSED(value) 0172 #endif 0173 } 0174 0175 void MauiMan::InputDevicesManager::setConnections() 0176 { 0177 #if !defined Q_OS_ANDROID 0178 if(m_interface) 0179 { 0180 m_interface->disconnect(); 0181 m_interface->deleteLater(); 0182 m_interface = nullptr; 0183 } 0184 0185 m_interface = new QDBusInterface (QStringLiteral("org.mauiman.Manager"), 0186 QStringLiteral("/InputDevices"), 0187 QStringLiteral("org.mauiman.InputDevices"), 0188 QDBusConnection::sessionBus(), this); 0189 if (m_interface->isValid()) 0190 { 0191 connect(m_interface, SIGNAL(keyboardLayoutChanged(double)), this, SLOT(onKeyboardLayoutChanged(QString))); 0192 connect(m_interface, SIGNAL(keyboardModelChanged(double)), this, SLOT(onKeyboardModelChanged(QString))); 0193 connect(m_interface, SIGNAL(keyboardRulesChanged(double)), this, SLOT(onKeyboardRulesChanged(QString))); 0194 connect(m_interface, SIGNAL(keyboardOptionsChanged(double)), this, SLOT(onKeyboardOptionsChanged(QString))); 0195 connect(m_interface, SIGNAL(keyboardVariantChanged(double)), this, SLOT(onKeyboardVariantChanged(QString))); 0196 0197 } 0198 #endif 0199 } 0200 0201 void MauiMan::InputDevicesManager::loadSettings() 0202 { 0203 m_settings->beginModule(QStringLiteral("InputDevices")); 0204 0205 #if !defined Q_OS_ANDROID 0206 0207 if(m_interface && m_interface->isValid()) 0208 { 0209 m_keyboardLayout = m_interface->property("keyboardLayout").toString(); 0210 m_keyboardModel = m_interface->property("keyboardModel").toString(); 0211 m_keyboardOptions = m_interface->property("keyboardOptions").toString(); 0212 m_keyboardRules = m_interface->property("keyboardRules").toString(); 0213 m_keyboardVariant = m_interface->property("keyboardVariant").toString(); 0214 return; 0215 } 0216 #endif 0217 0218 m_keyboardLayout = m_settings->load(QStringLiteral("KeyboardLayout"), m_keyboardLayout).toString(); 0219 m_keyboardModel = m_settings->load(QStringLiteral("KeyboardModel"), m_keyboardModel).toString(); 0220 m_keyboardOptions = m_settings->load(QStringLiteral("KeyboardOptions"), m_keyboardOptions).toString(); 0221 m_keyboardRules = m_settings->load(QStringLiteral("KeyboardRules"), m_keyboardRules).toString(); 0222 m_keyboardVariant = m_settings->load(QStringLiteral("KeyboardVariant"), m_keyboardVariant).toString(); 0223 }