From aa122bf246a1f8778d5205a5a1f24c705b0e6f74 Mon Sep 17 00:00:00 2001 From: Dubslow Date: Wed, 4 Feb 2015 16:11:21 -0600 Subject: [PATCH] Implement hack to make closing the history dialog not disable history Also word wrap the extra long text --- src/coreencryption.cpp | 2 +- src/widget/widget.cpp | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/coreencryption.cpp b/src/coreencryption.cpp index e5c401552..00e4d1a52 100644 --- a/src/coreencryption.cpp +++ b/src/coreencryption.cpp @@ -225,7 +225,7 @@ void Core::checkEncryptedHistory() QString a(tr("Please enter the password for the chat history for the %1 profile.", "used in load() when no hist pw set").arg(Settings::getInstance().getCurrentProfile())); QString b(tr("The previous password is incorrect; please try again:", "used on retries in load()")); - QString c(tr("Disabling chat history now will leave the encrypted history intact (but not usable); if you later remember the password, you may re-enable encryption from the Privacy tab with the correct password to use the history.", "part of history password dialog")); + QString c(tr("\nDisabling chat history now will leave the encrypted history intact (but not usable); if you later remember the password, you may re-enable encryption from the Privacy tab with the correct password to use the history.", "part of history password dialog")); QString dialogtxt; if (pwsaltedkeys[ptHistory]) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 71e4a042b..9fa5affc1 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -1294,18 +1295,48 @@ QString Widget::passwordDialog(const QString& cancel, const QString& body) } else { + // we use a hack. It is considered that closing the dialog without explicitly clicking + // disable history is confusing. But we can't distinguish between clicking the cancel + // button and closing the dialog. So instead, we reverse the Ok and Cancel roles, + // so that nothing but explicitly clicking disable history closes the dialog QString ret; QInputDialog dialog; dialog.setWindowTitle(tr("Enter your password")); - dialog.setOkButtonText(tr("Decrypt")); - dialog.setCancelButtonText(cancel); + dialog.setOkButtonText(cancel); + dialog.setCancelButtonText(tr("Decrypt")); dialog.setInputMode(QInputDialog::TextInput); dialog.setTextEchoMode(QLineEdit::Password); dialog.setLabelText(body); + + // problem with previous hack: the default button is disable history, not decrypt. + // use another hack to reverse the default buttons. + // http://www.qtcentre.org/threads/49924-Change-property-of-QInputDialog-button + QList l = dialog.findChildren(); + if (!l.isEmpty()) + { + QPushButton* ok = l.first()->button(QDialogButtonBox::Ok); + QPushButton* cancel = l.first()->button(QDialogButtonBox::Cancel); + if (ok && cancel) + { + ok->setAutoDefault(false); + ok->setDefault(false); + cancel->setAutoDefault(true); + cancel->setDefault(true); + } + else + qWarning() << "PasswordDialog: Missing button!"; + } + else + qWarning() << "PasswordDialog: No QDialogButtonBox!"; + + // using similar code, set QLabels to wrap + for (auto* label : dialog.findChildren()) + label->setWordWrap(true); + while (true) { int val = dialog.exec(); - if (val != QDialog::Accepted) + if (val == QDialog::Accepted) return QString(); else { @@ -1314,7 +1345,7 @@ QString Widget::passwordDialog(const QString& cancel, const QString& body) return ret; } dialog.setTextValue(""); - dialog.setLabelText(body + "\n" + tr("You must enter a non-empty password.")); + dialog.setLabelText(body + "\n\n" + tr("You must enter a non-empty password:")); } } }