1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Implement hack to make closing the history dialog not disable history

Also word wrap the extra long text
This commit is contained in:
Dubslow 2015-02-04 16:11:21 -06:00
parent 864d1297e7
commit aa122bf246
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
2 changed files with 36 additions and 5 deletions

View File

@ -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])

View File

@ -47,6 +47,7 @@
#include <QThread>
#include <QFileDialog>
#include <QInputDialog>
#include <QDialogButtonBox>
#include <QTimer>
#include <QStyleFactory>
#include <QTranslator>
@ -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<QDialogButtonBox*> l = dialog.findChildren<QDialogButtonBox*>();
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<QLabel*>())
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:"));
}
}
}