File indexing completed on 2024-12-01 04:36:35
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "libruqolawidgets_private_export.h" 0010 #include "settings/updateadminsettingsjob.h" 0011 #include <QScrollArea> 0012 #include <QVariant> 0013 class RocketChatAccount; 0014 class QCheckBox; 0015 class QSpinBox; 0016 class QFormLayout; 0017 class QLineEdit; 0018 class QComboBox; 0019 class QLabel; 0020 class KPasswordLineEdit; 0021 class QPlainTextEdit; 0022 class LIBRUQOLAWIDGETS_TESTS_EXPORT SettingsWidgetBase : public QScrollArea 0023 { 0024 Q_OBJECT 0025 public: 0026 explicit SettingsWidgetBase(RocketChatAccount *account, QWidget *parent = nullptr); 0027 ~SettingsWidgetBase() override; 0028 0029 virtual void initialize(const QMap<QString, QVariant> &mapSettings) = 0; 0030 0031 Q_SIGNALS: 0032 void changedDone(const QString &buttonObjectName); 0033 0034 protected: 0035 void connectCheckBox(QCheckBox *checkBox, const QString &variable); 0036 void addSpinbox(const QString &labelStr, QSpinBox *spinBox, const QString &variable); 0037 void addLineEdit(const QString &labelStr, QLineEdit *lineEdit, const QString &variable, bool readOnly = false); 0038 0039 void addComboBox(const QString &labelStr, const QMap<QString, QString> &items, QComboBox *comboBox, const QString &variable); 0040 void fillComboBox(QComboBox *comboBox, const QMap<QString, QString> &items); 0041 0042 void addPasswordEdit(const QString &labelStr, KPasswordLineEdit *lineEdit, const QString &variable); 0043 void addLabel(const QString &labelStr, QLabel *labelElement, const QString &variable); 0044 void addPlainTextEdit(const QString &labelStr, QPlainTextEdit *lineEdit, const QString &variable); 0045 0046 QWidget *const mCurrentWidget; 0047 QFormLayout *mMainLayout = nullptr; 0048 0049 void initializeWidget(QPlainTextEdit *lineEdit, const QMap<QString, QVariant> &mapSettings, const QString &defaultValue = QString()); 0050 void initializeWidget(KPasswordLineEdit *lineEdit, const QMap<QString, QVariant> &mapSettings); 0051 void initializeWidget(QLineEdit *lineEdit, const QMap<QString, QVariant> &mapSettings, const QString &defaultValue = QString()); 0052 void initializeWidget(QCheckBox *checkbox, const QMap<QString, QVariant> &mapSettings, bool defaultValue = false); 0053 void initializeWidget(QSpinBox *spinbox, const QMap<QString, QVariant> &mapSettings, int defaultValue = -1); 0054 void initializeWidget(QComboBox *comboBox, const QMap<QString, QVariant> &mapSettings, const QString &defaultValue = QString()); 0055 void initializeWidget(QLabel *label, const QMap<QString, QVariant> &mapSettings, const QString &defaultValue); 0056 0057 [[nodiscard]] QLabel *createBoldLabel(const QString &text); 0058 [[nodiscard]] QString urlFromRelativePath(const QString &relativePath); 0059 0060 RocketChatAccount *const mAccount; 0061 0062 private: 0063 LIBRUQOLAWIDGETS_NO_EXPORT bool updateSettings(const QString &settingName, 0064 const QVariant &value, 0065 RocketChatRestApi::UpdateAdminSettingsJob::UpdateAdminSettingsInfo::ValueType typeValue, 0066 const QString &buttonObjectName = {}); 0067 LIBRUQOLAWIDGETS_NO_EXPORT void slotAdminSettingsDone(const QJsonObject &obj, const QString &buttonObjectName); 0068 LIBRUQOLAWIDGETS_NO_EXPORT void disableTooButton(const QString &variableName); 0069 };