File indexing completed on 2024-09-15 10:32:54
0001 /* 0002 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "global_settings_widget.h" 0008 0009 #include "hotkeys_model.h" 0010 #include "settings.h" 0011 0012 #include <KConfigGroup> 0013 #include <KDesktopFile> 0014 #include <KGlobal> 0015 #include <QDebug> 0016 0017 #include <QStandardPaths> 0018 0019 GlobalSettingsWidget::GlobalSettingsWidget(QWidget *parent) 0020 : HotkeysWidgetIFace(parent) 0021 , _model(nullptr) 0022 { 0023 ui.setupUi(this); 0024 0025 QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kde5/services/kded/khotkeys.desktop"); 0026 if (KDesktopFile::isDesktopFile(path)) { 0027 _config = KSharedConfig::openConfig(path, KConfig::NoGlobals, QStandardPaths::GenericDataLocation); 0028 } 0029 0030 connect(ui.enabled, SIGNAL(stateChanged(int)), _changedSignals, SLOT(map())); 0031 _changedSignals->setMapping(ui.enabled, "enabled"); 0032 0033 connect(ui.gestures_group, SIGNAL(clicked(bool)), _changedSignals, SLOT(map())); 0034 _changedSignals->setMapping(ui.gestures_group, "gestures_enabled"); 0035 0036 connect(ui.gestures_timeout, SIGNAL(valueChanged(int)), _changedSignals, SLOT(map())); 0037 _changedSignals->setMapping(ui.gestures_timeout, "gestures_timeout"); 0038 0039 connect(ui.gestures_button, SIGNAL(currentIndexChanged(int)), _changedSignals, SLOT(map())); 0040 _changedSignals->setMapping(ui.gestures_button, "gestures_button"); 0041 } 0042 0043 GlobalSettingsWidget::~GlobalSettingsWidget() 0044 { 0045 } 0046 0047 void GlobalSettingsWidget::doCopyFromObject() 0048 { 0049 if (_config) { 0050 KConfigGroup file(_config, "Desktop Entry"); 0051 ui.enabled->setChecked(file.readEntry("X-KDE-Kded-autoload", false)); 0052 } 0053 0054 ui.gestures_group->setVisible(_model); 0055 if (_model) { 0056 KHotKeys::Settings *settings = _model->settings(); 0057 Q_ASSERT(settings); 0058 ui.gestures_group->setChecked(!settings->areGesturesDisabled()); 0059 ui.gestures_button->setCurrentIndex(settings->gestureMouseButton() - 2); 0060 ui.gestures_timeout->setValue(settings->gestureTimeOut()); 0061 } 0062 } 0063 0064 void GlobalSettingsWidget::doCopyToObject() 0065 { 0066 if (_config) { 0067 KConfigGroup file(_config, "Desktop Entry"); 0068 file.writeEntry("X-KDE-Kded-autoload", ui.enabled->checkState() == Qt::Checked); 0069 _config->sync(); 0070 } 0071 0072 if (_model) { 0073 KHotKeys::Settings *settings = _model->settings(); 0074 Q_ASSERT(settings); 0075 ui.gestures_group->isChecked() ? settings->enableGestures() : settings->disableGestures(); 0076 settings->setGestureMouseButton(ui.gestures_button->currentIndex() + 2); 0077 settings->setGestureTimeOut(ui.gestures_timeout->value()); 0078 } 0079 } 0080 0081 bool GlobalSettingsWidget::isChanged() const 0082 { 0083 if (_config) { 0084 KConfigGroup file(_config, "Desktop Entry"); 0085 bool enabled = file.readEntry("X-KDE-Kded-autoload", false); 0086 0087 if (enabled != ui.enabled->isChecked()) { 0088 return true; 0089 } 0090 } 0091 0092 if (_model) { 0093 KHotKeys::Settings *settings = _model->settings(); 0094 Q_ASSERT(settings); 0095 if ((!settings->areGesturesDisabled()) != ui.gestures_group->isChecked() // 0096 || settings->gestureMouseButton() - 2 != ui.gestures_button->currentIndex() // 0097 || settings->gestureTimeOut() != ui.gestures_timeout->value()) { 0098 return true; 0099 } 0100 } 0101 0102 return false; 0103 } 0104 0105 void GlobalSettingsWidget::setModel(KHotkeysModel *model) 0106 { 0107 _model = model; 0108 doCopyFromObject(); 0109 } 0110 0111 #include "moc_global_settings_widget.cpp"