File indexing completed on 2024-12-01 04:36:52
0001 /* 0002 SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "myaccount2e2configurewidget.h" 0008 #include "connection.h" 0009 #include "e2e/resetowne2ekeyjob.h" 0010 #include "misc/passwordconfirmwidget.h" 0011 #include "rocketchataccount.h" 0012 #include "ruqolawidgets_debug.h" 0013 #include <KLocalizedString> 0014 #include <QLabel> 0015 #include <QPushButton> 0016 #include <QVBoxLayout> 0017 0018 MyAccount2e2ConfigureWidget::MyAccount2e2ConfigureWidget(RocketChatAccount *account, QWidget *parent) 0019 : QWidget{parent} 0020 , mResetE2eKey(new QPushButton(i18n("Reset E2E Key"), this)) 0021 , mRocketChatAccount(account) 0022 , mPasswordConfirmWidget(new PasswordConfirmWidget(this)) 0023 { 0024 auto mainLayout = new QVBoxLayout(this); 0025 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0026 0027 auto changePasswordLabel = 0028 new QLabel(i18n("You can now create encrypted private groups and direct messages. You may also change existing private groups or DMs to encrypted. " 0029 "This is end to end encryption so the key to encode/decode your messages will not be saved on the server. For that reason you need to " 0030 "store your password somewhere safe. You will be required to enter it on other devices you wish to use e2e encryption on."), 0031 this); 0032 changePasswordLabel->setWordWrap(true); 0033 changePasswordLabel->setObjectName(QStringLiteral("changePasswordLabel")); 0034 mainLayout->addWidget(changePasswordLabel); 0035 0036 // TODO add change password 0037 mPasswordConfirmWidget->setObjectName(QStringLiteral("mPasswordConfirmWidget")); 0038 mainLayout->addWidget(mPasswordConfirmWidget); 0039 0040 auto removePasswordlabel = new QLabel( 0041 i18n("This option will remove your current E2E key and log you out. " 0042 "When you login again, Rocket.Chat will generate you a new key and restore your access to any encrypted room that has one or more members online." 0043 " Due to the nature of the E2E encryption, Rocket.Chat will not be able to restore access to any encrypted room that has no member online."), 0044 this); 0045 removePasswordlabel->setObjectName(QStringLiteral("removePasswordlabel")); 0046 removePasswordlabel->setWordWrap(true); 0047 mainLayout->addWidget(removePasswordlabel); 0048 0049 mResetE2eKey->setObjectName(QStringLiteral("mResetE2eKey")); 0050 mainLayout->addWidget(mResetE2eKey); 0051 connect(mResetE2eKey, &QPushButton::clicked, this, &MyAccount2e2ConfigureWidget::slotResetE2EKey); 0052 mainLayout->addStretch(1); 0053 } 0054 0055 void MyAccount2e2ConfigureWidget::save() 0056 { 0057 // TODO 0058 } 0059 0060 void MyAccount2e2ConfigureWidget::load() 0061 { 0062 // TODO 0063 } 0064 0065 MyAccount2e2ConfigureWidget::~MyAccount2e2ConfigureWidget() = default; 0066 0067 void MyAccount2e2ConfigureWidget::slotResetE2EKey() 0068 { 0069 // TODO it uses "/api/v1/method.call/e2e.resetOwnE2EKey" 0070 // => use restapi for calling ddp method 0071 auto job = new RocketChatRestApi::ResetOwnE2eKeyJob(this); 0072 mRocketChatAccount->restApi()->initializeRestApiJob(job); 0073 connect(job, &RocketChatRestApi::ResetOwnE2eKeyJob::resetE2eKeyDone, this, &MyAccount2e2ConfigureWidget::slotReset2E2KeyDone); 0074 if (!job->start()) { 0075 qCWarning(RUQOLAWIDGETS_LOG) << "Impossible to start ResetOwnE2eKeyJob job"; 0076 } 0077 } 0078 0079 void MyAccount2e2ConfigureWidget::slotReset2E2KeyDone(const QJsonObject &replyObject) 0080 { 0081 qDebug() << " replyObject " << replyObject; 0082 } 0083 0084 #include "moc_myaccount2e2configurewidget.cpp"