File indexing completed on 2024-12-01 04:36:34

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "administratorsettingswidget.h"
0008 #include "accounts/accountsettingswidget.h"
0009 #include "analytics/analyticswidget.h"
0010 #include "cas/cassettingswidget.h"
0011 #include "conferencecall/conferencecallsettingswidget.h"
0012 #include "email/emailsettingswidget.h"
0013 #include "encryption/encryptionsettingswidget.h"
0014 #include "enterprise/enterprisesettingswidget.h"
0015 #include "fileupload/fileuploadsettingswidget.h"
0016 #include "general/generalsettingswidget.h"
0017 #include "irc/ircwidget.h"
0018 #include "ircfederation/ircfederationwidget.h"
0019 #include "layout/layoutsettingswidget.h"
0020 #include "ldap/ldapsettingswidget.h"
0021 #include "logs/logssettingswidget.h"
0022 #include "message/messagesettingswidget.h"
0023 #include "mobile/mobilesettingswidget.h"
0024 #include "oauth/oauthsettingswidget.h"
0025 #include "password/passwordsettingswidget.h"
0026 #include "ratelimiter/ratelimiterwidget.h"
0027 #include "retentionpolicy/retentionpolicysettingswidget.h"
0028 #include "rocketchataccount.h"
0029 #include "rocketchatbackend.h"
0030 #include "slackbridge/slackbridgewidget.h"
0031 #include "troubleshoot/troubleshootsettingswidget.h"
0032 #include "userdatadownload/userdatadownloadwidget.h"
0033 #include "videoconference/videoconferencewidget.h"
0034 #include "webdav/webdavsettingswidget.h"
0035 #include "webrtc/webrtcsettingswidget.h"
0036 
0037 #include <KLocalizedString>
0038 #include <QTabWidget>
0039 #include <QVBoxLayout>
0040 
0041 AdministratorSettingsWidget::AdministratorSettingsWidget(RocketChatAccount *account, QWidget *parent)
0042     : QWidget{parent}
0043     , mTabWidget(new QTabWidget(this))
0044     , mAccountSettingsWidget(new AccountSettingsWidget(account, this))
0045     , mEncryptionSettingsWidget(new EncryptionSettingsWidget(account, this))
0046     , mMessageSettingsWidget(new MessageSettingsWidget(account, this))
0047     , mUploadFileSettingsWidget(new FileUploadSettingsWidget(account, this))
0048     , mRetentionPolicySettingsWidget(new RetentionPolicySettingsWidget(account, this))
0049     , mGeneralSettingsWidget(new GeneralSettingsWidget(account, this))
0050     , mRateLimiterWidget(new RateLimiterWidget(account, this))
0051     , mPasswordSettingsWidget(new PasswordSettingsWidget(account, this))
0052     , mVideoConferenceWidget(new VideoConferenceWidget(account, this))
0053     , mIrcFederationWidget(new IrcFederationWidget(account, this))
0054     , mWebDavSettingsWidget(new WebDavSettingsWidget(account, this))
0055     , mLDapSettingsWidget(new LDapSettingsWidget(account, this))
0056     , mLayoutSettingsWidget(new LayoutSettingsWidget(account, this))
0057     , mEnterpriseSettingsWidget(new EnterpriseSettingsWidget(account, this))
0058     , mUserDataDownloadWidget(new UserDataDownloadWidget(account, this))
0059     , mSlackBridgeWidget(new SlackBridgeWidget(account, this))
0060     , mLogsSettingsWidget(new LogsSettingsWidget(account, this))
0061     , mEmailSettingsWidget(new EmailSettingsWidget(account, this))
0062     , mMobileSettingsWidget(new MobileSettingsWidget(account, this))
0063     , mTroubleshootSettingsWidget(new TroubleshootSettingsWidget(account, this))
0064     , mConferenceCallSettingsWidget(new ConferenceCallSettingsWidget(account, this))
0065     , mWebRtcSettingsWidget(new WebRtcSettingsWidget(account, this))
0066     , mCasSettingsWidget(new CasSettingsWidget(account, this))
0067     , mOauthSettingsWidget(new OauthSettingsWidget(account, this))
0068     , mAnalyticsWidget(new AnalyticsWidget(account, this))
0069     , mIrcWidget(new IrcWidget(account, this))
0070     , mRocketChatAccount(account)
0071 {
0072     auto mainLayout = new QVBoxLayout(this);
0073     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0074     mainLayout->setContentsMargins({});
0075 
0076     mTabWidget->setObjectName(QStringLiteral("mTabWidget"));
0077     mainLayout->addWidget(mTabWidget);
0078 
0079     mAccountSettingsWidget->setObjectName(QStringLiteral("mAccountSettingsWidget"));
0080     mEncryptionSettingsWidget->setObjectName(QStringLiteral("mEncryptionSettingsWidget"));
0081     mMessageSettingsWidget->setObjectName(QStringLiteral("mMessageSettingsWidget"));
0082     mUploadFileSettingsWidget->setObjectName(QStringLiteral("mUploadFileSettingsWidget"));
0083     mRetentionPolicySettingsWidget->setObjectName(QStringLiteral("mRetentionPolicySettingsWidget"));
0084     mGeneralSettingsWidget->setObjectName(QStringLiteral("mGeneralSettingsWidget"));
0085     mRateLimiterWidget->setObjectName(QStringLiteral("mRateLimiterWidget"));
0086     mPasswordSettingsWidget->setObjectName(QStringLiteral("mPasswordSettingsWidget"));
0087     mVideoConferenceWidget->setObjectName(QStringLiteral("mVideoConferenceWidget"));
0088     mIrcFederationWidget->setObjectName(QStringLiteral("mIrcFederationWidget"));
0089     mWebDavSettingsWidget->setObjectName(QStringLiteral("mWebDavSettingsWidget"));
0090     mLDapSettingsWidget->setObjectName(QStringLiteral("mLDapSettingsWidget"));
0091     mLayoutSettingsWidget->setObjectName(QStringLiteral("mLayoutSettingsWidget"));
0092     mEnterpriseSettingsWidget->setObjectName(QStringLiteral("mEnterpriseSettingsWidget"));
0093     mUserDataDownloadWidget->setObjectName(QStringLiteral("mUserDataDownloadWidget"));
0094     mSlackBridgeWidget->setObjectName(QStringLiteral("mSlackBridgeWidget"));
0095     mLogsSettingsWidget->setObjectName(QStringLiteral("mLogsSettingsWidget"));
0096     mEmailSettingsWidget->setObjectName(QStringLiteral("mEmailSettingsWidget"));
0097     mMobileSettingsWidget->setObjectName(QStringLiteral("mMobileSettingsWidget"));
0098     mTroubleshootSettingsWidget->setObjectName(QStringLiteral("mTroubleshootSettingsWidget"));
0099     mConferenceCallSettingsWidget->setObjectName(QStringLiteral("mConferenceCallSettingsWidget"));
0100     mWebRtcSettingsWidget->setObjectName(QStringLiteral("mWebRtcSettingsWidget"));
0101     mCasSettingsWidget->setObjectName(QStringLiteral("mCasSettingsWidget"));
0102     mOauthSettingsWidget->setObjectName(QStringLiteral("mOauthSettingsWidget"));
0103     mAnalyticsWidget->setObjectName(QStringLiteral("mAnalyticsWidget"));
0104     mIrcWidget->setObjectName(QStringLiteral("mIrcWidget"));
0105     mTabWidget->addTab(mAccountSettingsWidget, i18n("Accounts"));
0106     mTabWidget->addTab(mEncryptionSettingsWidget, i18n("Encryption"));
0107     mTabWidget->addTab(mMessageSettingsWidget, i18n("Message"));
0108     mTabWidget->addTab(mUploadFileSettingsWidget, i18n("File Upload"));
0109     mTabWidget->addTab(mRetentionPolicySettingsWidget, i18n("Retention Policy"));
0110     mTabWidget->addTab(mGeneralSettingsWidget, i18n("General"));
0111     mTabWidget->addTab(mRateLimiterWidget, i18n("Rate Limiter"));
0112     mTabWidget->addTab(mPasswordSettingsWidget, i18n("Password"));
0113     mTabWidget->addTab(mVideoConferenceWidget, i18n("Video Conference"));
0114     mTabWidget->addTab(mIrcFederationWidget, i18n("IRC Federation"));
0115     mTabWidget->addTab(mIrcWidget, i18n("IRC"));
0116     mTabWidget->addTab(mWebDavSettingsWidget, i18n("Webdav"));
0117     mTabWidget->addTab(mLDapSettingsWidget, i18n("LDAP"));
0118     mTabWidget->addTab(mLayoutSettingsWidget, i18n("Layout"));
0119     mTabWidget->addTab(mEnterpriseSettingsWidget, i18n("Enterprise"));
0120     mTabWidget->addTab(mUserDataDownloadWidget, i18n("User Data Download"));
0121     mTabWidget->addTab(mSlackBridgeWidget, i18n("Slack Bridge"));
0122     mTabWidget->addTab(mLogsSettingsWidget, i18n("Logs"));
0123     mTabWidget->addTab(mEmailSettingsWidget, i18n("Email"));
0124     mTabWidget->addTab(mMobileSettingsWidget, i18n("Mobile"));
0125     mTabWidget->addTab(mTroubleshootSettingsWidget, i18n("Troubleshoot"));
0126     mTabWidget->addTab(mConferenceCallSettingsWidget, i18n("Conference Call"));
0127     mTabWidget->addTab(mWebRtcSettingsWidget, i18n("WebRTC"));
0128     mTabWidget->addTab(mCasSettingsWidget, i18n("CAS"));
0129     mTabWidget->addTab(mOauthSettingsWidget, i18n("Oauth"));
0130     mTabWidget->addTab(mAnalyticsWidget, i18n("Analytics"));
0131     if (mRocketChatAccount) {
0132         connect(mRocketChatAccount, &RocketChatAccount::publicSettingLoaded, this, &AdministratorSettingsWidget::initialize);
0133     }
0134     updateState(false);
0135 }
0136 
0137 AdministratorSettingsWidget::~AdministratorSettingsWidget() = default;
0138 
0139 void AdministratorSettingsWidget::loadSettings()
0140 {
0141     // Load from database ?
0142     mRocketChatAccount->rocketChatBackend()->loadPublicSettingsAdministrator();
0143 }
0144 
0145 void AdministratorSettingsWidget::initialize(const QJsonObject &obj)
0146 {
0147     QJsonArray configs = obj.value(QLatin1String("result")).toArray();
0148     // qDebug() << " obj " << obj;
0149     QMap<QString, QVariant> mapSettings;
0150     for (QJsonValueRef currentConfig : configs) {
0151         const QJsonObject currentConfObject = currentConfig.toObject();
0152         const QString id = currentConfObject[QLatin1String("_id")].toString();
0153         const QVariant value = currentConfObject[QLatin1String("value")].toVariant();
0154         // qDebug() << "id  " << id << " value " << value;
0155         mapSettings.insert(id, value);
0156     }
0157 
0158     initializeValues(mAccountSettingsWidget, mapSettings);
0159     initializeValues(mEncryptionSettingsWidget, mapSettings);
0160     initializeValues(mMessageSettingsWidget, mapSettings);
0161     initializeValues(mUploadFileSettingsWidget, mapSettings);
0162     initializeValues(mRetentionPolicySettingsWidget, mapSettings);
0163     initializeValues(mGeneralSettingsWidget, mapSettings);
0164     initializeValues(mRateLimiterWidget, mapSettings);
0165     initializeValues(mPasswordSettingsWidget, mapSettings);
0166     initializeValues(mVideoConferenceWidget, mapSettings);
0167     initializeValues(mIrcFederationWidget, mapSettings);
0168     initializeValues(mWebDavSettingsWidget, mapSettings);
0169     initializeValues(mLDapSettingsWidget, mapSettings);
0170     initializeValues(mLayoutSettingsWidget, mapSettings);
0171     initializeValues(mEnterpriseSettingsWidget, mapSettings);
0172     initializeValues(mUserDataDownloadWidget, mapSettings);
0173     initializeValues(mSlackBridgeWidget, mapSettings);
0174     initializeValues(mLogsSettingsWidget, mapSettings);
0175     initializeValues(mEmailSettingsWidget, mapSettings);
0176     initializeValues(mMobileSettingsWidget, mapSettings);
0177     initializeValues(mTroubleshootSettingsWidget, mapSettings);
0178     initializeValues(mConferenceCallSettingsWidget, mapSettings);
0179     initializeValues(mWebRtcSettingsWidget, mapSettings);
0180     initializeValues(mCasSettingsWidget, mapSettings);
0181     initializeValues(mOauthSettingsWidget, mapSettings);
0182     initializeValues(mAnalyticsWidget, mapSettings);
0183     initializeValues(mIrcWidget, mapSettings);
0184     updateState(true);
0185 }
0186 
0187 void AdministratorSettingsWidget::initializeValues(SettingsWidgetBase *widget, const QMap<QString, QVariant> &mapSettings)
0188 {
0189     widget->initialize(mapSettings);
0190 }
0191 
0192 void AdministratorSettingsWidget::updateState(bool state)
0193 {
0194     mAccountSettingsWidget->setEnabled(state);
0195     mEncryptionSettingsWidget->setEnabled(state);
0196     mMessageSettingsWidget->setEnabled(state);
0197     mUploadFileSettingsWidget->setEnabled(state);
0198     mRetentionPolicySettingsWidget->setEnabled(state);
0199     mRateLimiterWidget->setEnabled(state);
0200     mPasswordSettingsWidget->setEnabled(state);
0201     mVideoConferenceWidget->setEnabled(state);
0202     mIrcFederationWidget->setEnabled(state);
0203     mWebDavSettingsWidget->setEnabled(state);
0204     mLDapSettingsWidget->setEnabled(state);
0205     mLayoutSettingsWidget->setEnabled(state);
0206     mEnterpriseSettingsWidget->setEnabled(state);
0207     mUserDataDownloadWidget->setEnabled(state);
0208     mSlackBridgeWidget->setEnabled(state);
0209     mLogsSettingsWidget->setEnabled(state);
0210     mEmailSettingsWidget->setEnabled(state);
0211     mMobileSettingsWidget->setEnabled(state);
0212     mTroubleshootSettingsWidget->setEnabled(state);
0213     mConferenceCallSettingsWidget->setEnabled(state);
0214     mWebRtcSettingsWidget->setEnabled(state);
0215     mCasSettingsWidget->setEnabled(state);
0216     mOauthSettingsWidget->setEnabled(state);
0217     mAnalyticsWidget->setEnabled(state);
0218     mIrcWidget->setEnabled(state);
0219 }
0220 
0221 #include "moc_administratorsettingswidget.cpp"