Skip to content

Commit

Permalink
Fix Jan's review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Oct 20, 2022
1 parent 38e722a commit 06c350c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
22 changes: 0 additions & 22 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QNetworkAccessManager>
#include <QMessageBox>
#include "clientsideencryption.h"
#include "ui_mnemonicdialog.h"

namespace {
static const char urlC[] = "url";
Expand Down Expand Up @@ -398,27 +397,6 @@ AccountPtr AccountManager::createAccount()
return acc;
}

void AccountManager::displayMnemonic(const QString& mnemonic)
{
auto *widget = new QDialog;
Ui_Dialog ui;
ui.setupUi(widget);
widget->setWindowTitle(tr("End-to-End encryption mnemonic"));
ui.label->setText(tr("To protect your Cryptographic Identity, we encrypt it with a mnemonic of 12 dictionary words. "
"Please note these down and keep them safe. "
"They will be needed to add other devices to your account (like your mobile phone or laptop)."));
QFont monoFont(QStringLiteral("Monospace"));
monoFont.setStyleHint(QFont::TypeWriter);
ui.textEdit->setFont(monoFont);
ui.textEdit->setText(mnemonic);
ui.textEdit->setReadOnly(true);
ui.textEdit->focusWidget();
ui.textEdit->selectAll();
ui.textEdit->setAlignment(Qt::AlignCenter);
widget->exec();
widget->resize(widget->sizeHint());
}

void AccountManager::shutdown()
{
const auto accountsCopy = _accounts;
Expand Down
3 changes: 0 additions & 3 deletions src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ public slots:
/// Saves account state data, not including the account
void saveAccountState(AccountState *a);

/// Display a Box with the mnemonic so the user can copy it to a safe place.
static void displayMnemonic(const QString& mnemonic);


Q_SIGNALS:
void accountAdded(AccountState *account);
Expand Down
34 changes: 32 additions & 2 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "syncresult.h"
#include "ignorelisttablewidget.h"
#include "wizard/owncloudwizard.h"
#include "ui_mnemonicdialog.h"

#include <cmath>

Expand Down Expand Up @@ -243,7 +244,7 @@ void AccountSettings::slotE2eEncryptionMnemonicReady()
{
auto *const actionDisplayMnemonic = addActionToEncryptionMessage(tr("Display mnemonic"), e2EeUiActionDisplayMnemonicId);
connect(actionDisplayMnemonic, &QAction::triggered, this, [this]() {
AccountManager::instance()->displayMnemonic(_accountState->account()->e2e()->_mnemonic);
displayMnemonic(_accountState->account()->e2e()->_mnemonic);
});
_ui->encryptionMessage->setText(tr("This account supports End-to-End encryption"));
_ui->encryptionMessage->show();
Expand All @@ -264,7 +265,7 @@ void AccountSettings::slotE2eEncryptionInitializationFinished(bool isNewMnemonic
removeActionFromEncryptionMessage(e2EeUiActionEnableEncryptionId);
slotE2eEncryptionMnemonicReady();
if (isNewMnemonicGenerated) {
AccountManager::instance()->displayMnemonic(_accountState->account()->e2e()->_mnemonic);
displayMnemonic(_accountState->account()->e2e()->_mnemonic);
}
}
}
Expand Down Expand Up @@ -951,6 +952,35 @@ void AccountSettings::slotSetSubFolderAvailability(Folder *folder, const QString
folder->scheduleThisFolderSoon();
}

void AccountSettings::displayMnemonic(const QString &mnemonic)
{
auto widget = QDialog(this);
Ui_Dialog ui;
ui.setupUi(&widget);
widget.setWindowTitle(tr("End-to-End encryption mnemonic"));
ui.label->setText(
tr("To protect your Cryptographic Identity, we encrypt it with a mnemonic of 12 dictionary words. "
"Please note these down and keep them safe. "
"They will be needed to add other devices to your account (like your mobile phone or laptop)."));
QFont monoFont(QStringLiteral("Monospace"));
monoFont.setStyleHint(QFont::TypeWriter);
ui.lineEdit->setFont(monoFont);
ui.lineEdit->setText(mnemonic);
ui.lineEdit->setReadOnly(true);

ui.lineEdit->setStyleSheet(QStringLiteral("QLineEdit{ color: black; background: lightgrey; border-style: inset;}"));

ui.lineEdit->focusWidget();
ui.lineEdit->selectAll();
ui.lineEdit->setAlignment(Qt::AlignCenter);

const QFont font(QStringLiteral(""), 0);
QFontMetrics fm(font);
ui.lineEdit->setFixedWidth(fm.width(mnemonic));
widget.resize(widget.sizeHint());
widget.exec();
}

void AccountSettings::showConnectionLabel(const QString &message, QStringList errors)
{
const QString errStyle = QLatin1String("color:#ffffff; background-color:#bb4d4d;padding:5px;"
Expand Down
1 change: 1 addition & 0 deletions src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected slots:
const QVector<int> &roles);

private:
void displayMnemonic(const QString &mnemonic);
void showConnectionLabel(const QString &message,
QStringList errors = QStringList());
bool event(QEvent *) override;
Expand Down
18 changes: 7 additions & 11 deletions src/gui/mnemonicdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>588</width>
<height>214</height>
<height>131</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -31,6 +31,9 @@
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>7</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
Expand All @@ -39,7 +42,7 @@
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>50</verstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -73,20 +76,13 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>80</height>
</size>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
Expand Down

0 comments on commit 06c350c

Please sign in to comment.