From ca5e9c324deb8bb2c8c570c78d9b6f862620a022 Mon Sep 17 00:00:00 2001 From: Dubslow Date: Mon, 2 Feb 2015 17:19:43 -0600 Subject: [PATCH] When enabling history encryption, check for and use previously-ignored encrypted history Should close dubslow/qTox#5 and close dubslow/qTox#6 Note that the GUI isn't updated with the ignored history, that's a TODO --- src/widget/form/settings/privacyform.cpp | 45 +++++++++++++++--------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp index 3582cf82d..f38deed2c 100644 --- a/src/widget/form/settings/privacyform.cpp +++ b/src/widget/form/settings/privacyform.cpp @@ -74,33 +74,44 @@ bool PrivacyForm::setChatLogsPassword() else dialog = new SetPasswordDialog(body, QString(), this); - if (int r = dialog->exec()) - { + // check if an encrypted history exists because it was disabled earlier, and use it if possible + QString path = HistoryKeeper::getHistoryPath(QString(), 1); + QByteArray salt = core->getSaltFromFile(path); + bool haveEncHist = salt.size() > 0; + + do { + int r = dialog->exec(); + if (r == QDialog::Rejected) + break; + QList oldMessages = HistoryKeeper::exportMessagesDeleteFile(); QString newpw = dialog->getPassword(); - delete dialog; if (r == 2) core->useOtherPassword(Core::ptHistory); + else if (haveEncHist) + core->setPassword(newpw, Core::ptHistory, reinterpret_cast(salt.data())); else core->setPassword(newpw, Core::ptHistory); - //if (!HistoryKeeper::checkPassword(true)) - // if (checkContinue(tr("Old encrypted chat logs", "title"), - // tr("Would you like to re-encrypt your old chat logs?\nOtherwise they will be deleted.", "body"))) - // for now, don't bother asking. Why wouldn't you want to reencrypt? + if (!haveEncHist || HistoryKeeper::checkPassword(1)) + { + Settings::getInstance().setEncryptLogs(true); + HistoryKeeper::getInstance()->importMessages(oldMessages); + // TODO: The old encrypted history is loaded, but doesn't appear in the GUI. @apprb ? + delete dialog; + return true; + } + else + { + if (!Widget::getInstance()->askQuestion(tr("Old encrypted chat log", "popup title"), tr("There is currently an unused encrypted chat log, but the password you just entered doesn't match.\nWould you like to try again?"))) + haveEncHist = false; // logically this is really just a `break`, but conceptually this is more accurate + } + } while (haveEncHist); - Settings::getInstance().setEncryptLogs(true); - HistoryKeeper::getInstance()->importMessages(oldMessages); - - return true; - } - else - { - delete dialog; - return false; - } + delete dialog; + return false; } void PrivacyForm::onEncryptLogsUpdated()