File indexing completed on 2024-07-14 09:00:24

0001 /*
0002     SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "settingwidget.h"
0008 #include "bssidcombobox.h"
0009 #include "hwaddrcombobox.h"
0010 #include "passwordfield.h"
0011 #include "ssidcombobox.h"
0012 
0013 #include <QCheckBox>
0014 #include <QComboBox>
0015 #include <QGroupBox>
0016 #include <QLineEdit>
0017 #include <QPushButton>
0018 #include <QSpinBox>
0019 #include <QTableView>
0020 
0021 #include <KUrlRequester>
0022 
0023 SettingWidget::SettingWidget(const NetworkManager::Setting::Ptr &setting, QWidget *parent, Qt::WindowFlags f)
0024     : QWidget(parent, f)
0025     , m_type(setting->name())
0026 {
0027 }
0028 
0029 SettingWidget::SettingWidget(const NetworkManager::Setting::Ptr &setting, const QStringList &hints, QWidget *parent, Qt::WindowFlags f)
0030     : QWidget(parent, f)
0031     , m_hints(hints)
0032     , m_type(setting->name())
0033 {
0034 }
0035 
0036 SettingWidget::~SettingWidget() = default;
0037 
0038 void SettingWidget::loadConfig(const NetworkManager::Setting::Ptr &setting)
0039 {
0040     Q_UNUSED(setting);
0041 }
0042 
0043 void SettingWidget::loadSecrets(const NetworkManager::Setting::Ptr &setting)
0044 {
0045     Q_UNUSED(setting);
0046 }
0047 
0048 void SettingWidget::watchChangedSetting()
0049 {
0050     // Attempt to connect to all widgets representing various configurations
0051     // to notify about setting change
0052 
0053     /************ Qt Widgets ************/
0054 
0055     // Connect all QLineEdit widgets
0056     const QList<QLineEdit *> lineEdits = findChildren<QLineEdit *>();
0057     for (QLineEdit *lineedit : lineEdits) {
0058         connect(lineedit, &QLineEdit::textChanged, this, &SettingWidget::settingChanged);
0059     }
0060 
0061     // Connect all QComboBox widgets
0062     const QList<QComboBox *> comboboxes = findChildren<QComboBox *>();
0063     for (QComboBox *combobox : comboboxes) {
0064         connect(combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingWidget::settingChanged);
0065         connect(combobox, &QComboBox::currentTextChanged, this, &SettingWidget::settingChanged);
0066     }
0067 
0068     // Connect all QCheckBox widgets
0069     const QList<QCheckBox *> checkboxes = findChildren<QCheckBox *>();
0070     for (QCheckBox *checkbox : checkboxes) {
0071         connect(checkbox, &QCheckBox::stateChanged, this, &SettingWidget::settingChanged);
0072     }
0073 
0074     // Connect all QPushButton widgets
0075     const QList<QPushButton *> pushbuttons = findChildren<QPushButton *>();
0076     for (QPushButton *pushbutton : pushbuttons) {
0077         connect(pushbutton, &QPushButton::clicked, this, &SettingWidget::settingChanged);
0078     }
0079 
0080     // Connect all QSpinBox widgets
0081     const QList<QSpinBox *> spinboxes = findChildren<QSpinBox *>();
0082     for (QSpinBox *spinbox : spinboxes) {
0083         connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingWidget::settingChanged);
0084     }
0085 
0086     // Connect all KUrlRequester widgets
0087     const QList<KUrlRequester *> urlrequesters = findChildren<KUrlRequester *>();
0088     for (KUrlRequester *urlrequester : urlrequesters) {
0089         connect(urlrequester, &KUrlRequester::textChanged, this, &SettingWidget::settingChanged);
0090         connect(urlrequester, &KUrlRequester::urlSelected, this, &SettingWidget::settingChanged);
0091     }
0092 
0093     // Connect all QTableView widgets
0094     const QList<QTableView *> tableviews = findChildren<QTableView *>();
0095     for (QTableView *tableview : tableviews) {
0096         connect(tableview, &QTableView::clicked, this, &SettingWidget::settingChanged);
0097     }
0098 
0099     // Connect all QGroupBox widgets
0100     const QList<QGroupBox *> groupBoxes = findChildren<QGroupBox *>();
0101     for (QGroupBox *box : groupBoxes) {
0102         connect(box, &QGroupBox::toggled, this, &SettingWidget::settingChanged);
0103     }
0104 
0105     /********** OUR CUSTOM WIDGETS **********/
0106     // Connect all PasswordField widgets
0107     const QList<PasswordField *> passwordfields = findChildren<PasswordField *>();
0108     for (PasswordField *passwordfield : passwordfields) {
0109         connect(passwordfield, &PasswordField::textChanged, this, &SettingWidget::settingChanged);
0110         connect(passwordfield, &PasswordField::passwordOptionChanged, this, &SettingWidget::settingChanged);
0111     }
0112 
0113     // Connect all HwAddrComboBox widgets
0114     const QList<HwAddrComboBox *> hwAddrcomboboxes = findChildren<HwAddrComboBox *>();
0115     for (HwAddrComboBox *combobox : hwAddrcomboboxes) {
0116         connect(combobox, &HwAddrComboBox::hwAddressChanged, this, &SettingWidget::settingChanged);
0117     }
0118 
0119     // Connect all SssidComboBox widgets
0120     const QList<SsidComboBox *> ssidcomboboxes = findChildren<SsidComboBox *>();
0121     for (SsidComboBox *combobox : ssidcomboboxes) {
0122         connect(combobox, &SsidComboBox::ssidChanged, this, &SettingWidget::settingChanged);
0123     }
0124 
0125     // Connect all BssidComboBox widgets
0126     const QList<BssidComboBox *> bssidcomboboxes = findChildren<BssidComboBox *>();
0127     for (BssidComboBox *combobox : bssidcomboboxes) {
0128         connect(combobox, &BssidComboBox::bssidChanged, this, &SettingWidget::settingChanged);
0129     }
0130 }
0131 
0132 QString SettingWidget::type() const
0133 {
0134     return m_type;
0135 }
0136 
0137 void SettingWidget::slotWidgetChanged()
0138 {
0139     Q_EMIT validChanged(isValid());
0140 }
0141 
0142 #include "moc_settingwidget.cpp"