mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
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
This commit is contained in:
parent
31ac5dbe46
commit
ca5e9c324d
|
@ -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<HistoryKeeper::HistMessage> 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<uint8_t*>(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);
|
||||
|
||||
delete dialog;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void PrivacyForm::onEncryptLogsUpdated()
|
||||
|
|
Loading…
Reference in New Issue
Block a user