File indexing completed on 2024-12-01 04:36:52
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "myaccountconfigurewidget.h" 0008 #include "myaccount2e2configurewidget.h" 0009 #include "myaccount2faconfigurewidget.h" 0010 #include "myaccountmanagedeviceconfigurewidget.h" 0011 #include "myaccountpersonalaccesstokenconfigurewidget.h" 0012 #include "myaccountpreferenceconfigurewidget.h" 0013 #include "myaccountprofileconfigurewidget.h" 0014 #include "rocketchataccount.h" 0015 #include <KLocalizedString> 0016 #include <QTabWidget> 0017 #include <QVBoxLayout> 0018 0019 MyAccountConfigureWidget::MyAccountConfigureWidget(RocketChatAccount *account, QWidget *parent) 0020 : QWidget(parent) 0021 , mMyAccount2FaConfigureWidget(new MyAccount2FaConfigureWidget(account, this)) 0022 , mMyAccount2ProfileConfigureWidget(new MyAccountProfileConfigureWidget(account, this)) 0023 , mMyAccountPreferenceConfigureWidget(new MyAccountPreferenceConfigureWidget(account, this)) 0024 , mMyAccount2e2ConfigureWidget(new MyAccount2e2ConfigureWidget(account, this)) 0025 , mMyAccountPersonalAccessTokenConfigureWidget(new MyAccountPersonalAccessTokenConfigureWidget(account, this)) 0026 , mRocketChatAccount(account) 0027 { 0028 auto mainLayout = new QVBoxLayout(this); 0029 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0030 mainLayout->setContentsMargins({}); 0031 0032 auto tabWidget = new QTabWidget(this); 0033 tabWidget->setObjectName(QStringLiteral("tabWidget")); 0034 mainLayout->addWidget(tabWidget); 0035 0036 mMyAccount2ProfileConfigureWidget->setObjectName(QStringLiteral("mMyAccount2ProfileConfigureWidget")); 0037 const int profileIndexPage = tabWidget->addTab(mMyAccount2ProfileConfigureWidget, i18n("Profile")); 0038 if (account && !account->allowProfileChange()) { 0039 tabWidget->setTabVisible(profileIndexPage, false); 0040 } 0041 0042 mMyAccountPreferenceConfigureWidget->setObjectName(QStringLiteral("mMyAccountPreferenceConfigureWidget")); 0043 tabWidget->addTab(mMyAccountPreferenceConfigureWidget, i18n("Preference")); 0044 0045 mMyAccount2FaConfigureWidget->setObjectName(QStringLiteral("mMyAccount2FaConfigureWidget")); 0046 const int index2faPage = tabWidget->addTab(mMyAccount2FaConfigureWidget, i18n("Two Authentication Factor")); 0047 if (account && !account->twoFactorAuthenticationEnabled()) { 0048 tabWidget->setTabVisible(index2faPage, false); 0049 } 0050 0051 mMyAccount2e2ConfigureWidget->setObjectName(QStringLiteral("mMyAccount2e2ConfigureWidget")); 0052 const int index2e2Page = tabWidget->addTab(mMyAccount2e2ConfigureWidget, i18n("E2E Encryption")); 0053 if (account && !account->encryptionEnabled()) { 0054 tabWidget->setTabVisible(index2e2Page, false); 0055 } 0056 if (account && account->hasLicense(QStringLiteral("device-management"))) { 0057 auto manageDeviceWidget = new MyAccountManageDeviceConfigureWidget(mRocketChatAccount, this); 0058 tabWidget->addTab(manageDeviceWidget, i18n("Manage Device")); 0059 manageDeviceWidget->initialize(); 0060 } 0061 mMyAccountPersonalAccessTokenConfigureWidget->setObjectName(QStringLiteral("mMyAccountPersonalAccessTokenConfigureWidget")); 0062 const int pageIndex = tabWidget->addTab(mMyAccountPersonalAccessTokenConfigureWidget, i18n("Personal Access Token")); 0063 if (account && !account->hasPermission(QStringLiteral("create-personal-access-tokens"))) { 0064 tabWidget->setTabVisible(pageIndex, false); 0065 } 0066 } 0067 0068 MyAccountConfigureWidget::~MyAccountConfigureWidget() = default; 0069 0070 void MyAccountConfigureWidget::save() 0071 { 0072 mMyAccountPreferenceConfigureWidget->save(); 0073 if (mRocketChatAccount) { 0074 if (mRocketChatAccount->allowProfileChange()) { 0075 mMyAccount2ProfileConfigureWidget->save(); 0076 } 0077 if (mRocketChatAccount->twoFactorAuthenticationEnabled()) { 0078 mMyAccount2FaConfigureWidget->save(); 0079 } 0080 if (mRocketChatAccount->encryptionEnabled()) { 0081 mMyAccount2e2ConfigureWidget->save(); 0082 } 0083 } 0084 } 0085 0086 void MyAccountConfigureWidget::load() 0087 { 0088 mMyAccountPreferenceConfigureWidget->load(); 0089 if (mRocketChatAccount) { 0090 if (mRocketChatAccount->allowProfileChange()) { 0091 mMyAccount2ProfileConfigureWidget->load(); 0092 } 0093 if (mRocketChatAccount->twoFactorAuthenticationEnabled()) { 0094 mMyAccount2FaConfigureWidget->load(); 0095 } 0096 if (mRocketChatAccount->encryptionEnabled()) { 0097 mMyAccount2e2ConfigureWidget->load(); 0098 } 0099 } 0100 } 0101 0102 void MyAccountConfigureWidget::initialize() 0103 { 0104 mMyAccount2ProfileConfigureWidget->initialize(); 0105 mMyAccount2FaConfigureWidget->initialize(); 0106 if (mRocketChatAccount && mRocketChatAccount->hasPermission(QStringLiteral("create-personal-access-tokens"))) { 0107 mMyAccountPersonalAccessTokenConfigureWidget->initialize(); 0108 } 0109 } 0110 0111 #include "moc_myaccountconfigurewidget.cpp"