Skip to content

Commit

Permalink
Create Display Mnemonic dialog always on top.
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 74881be commit ea3d469
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
30 changes: 0 additions & 30 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,35 +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.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 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

0 comments on commit ea3d469

Please sign in to comment.