diff --git a/src/coreencryption.cpp b/src/coreencryption.cpp
index b2d9e2c0d..0ee3906e9 100644
--- a/src/coreencryption.cpp
+++ b/src/coreencryption.cpp
@@ -48,6 +48,9 @@ void Core::setPassword(QString& password, PasswordType passtype, uint8_t* salt)
tox_derive_key_from_pass(str.data(), str.size(), pwsaltedkeys[passtype]);
password.clear();
+
+ if (passtype == ptMain)
+ saveConfiguration();
}
void Core::useOtherPassword(PasswordType type)
@@ -56,7 +59,10 @@ void Core::useOtherPassword(PasswordType type)
if (type == ptHistory)
pwsaltedkeys[ptHistory] = pwsaltedkeys[ptMain];
else if (type == ptMain)
+ {
pwsaltedkeys[ptMain] = pwsaltedkeys[ptHistory];
+ saveConfiguration();
+ }
}
void Core::clearPassword(PasswordType passtype)
diff --git a/src/widget/form/setpassworddialog.cpp b/src/widget/form/setpassworddialog.cpp
index f8624dc84..2e401b79f 100644
--- a/src/widget/form/setpassworddialog.cpp
+++ b/src/widget/form/setpassworddialog.cpp
@@ -44,7 +44,8 @@ SetPasswordDialog::~SetPasswordDialog()
void SetPasswordDialog::onPasswordEdit()
{
- if (ui->passwordlineEdit->text() == ui->repasswordlineEdit->text())
+ if ( !ui->passwordlineEdit->text().isEmpty()
+ && ui->passwordlineEdit->text() == ui->repasswordlineEdit->text())
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
else
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp
index 961a700cf..158f03683 100644
--- a/src/widget/form/settings/privacyform.cpp
+++ b/src/widget/form/settings/privacyform.cpp
@@ -59,6 +59,44 @@ void PrivacyForm::onTypingNotificationEnabledUpdated()
Settings::getInstance().setTypingNotification(bodyUI->cbTypingNotification->isChecked());
}
+bool PrivacyForm::setChatLogsPassword()
+{
+ SetPasswordDialog* dialog;
+ QString body = tr("Please set your new chat log password:");
+ if (core->isPasswordSet(Core::ptMain))
+ dialog = new SetPasswordDialog(body, tr("Use data file password", "pushbutton text"), this);
+ else
+ dialog = new SetPasswordDialog(body, QString(), this);
+
+ if (int r = dialog->exec())
+ {
+ QString newpw = dialog->getPassword();
+ delete dialog;
+
+ if (!HistoryKeeper::checkPassword())
+ 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")))
+ {
+ HistoryKeeper::getInstance()->reencrypt(r == 2 ? QString() : newpw);
+ // will set core and reset itself
+ return true;
+ }
+ // @apprb you resetInstance() in the old code but wouldn't that wipe out the current unencrypted history?
+ // current history should of course just become encrypted
+ if (r == 2)
+ core->useOtherPassword(Core::ptHistory);
+ else
+ core->setPassword(newpw, Core::ptHistory);
+ // HistoryKeeper::encryptPlain();
+ return true;
+ }
+ else
+ {
+ delete dialog;
+ return false;
+ }
+}
+
void PrivacyForm::onEncryptLogsUpdated()
{
Core* core = Core::getInstance();
@@ -67,43 +105,13 @@ void PrivacyForm::onEncryptLogsUpdated()
{
if (!core->isPasswordSet(Core::ptHistory))
{
- SetPasswordDialog* dialog;
- QString body = tr("Please set your new chat log password:");
- if (core->isPasswordSet(Core::ptMain))
- dialog = new SetPasswordDialog(body, tr("Use datafile password", "pushbutton text"));
- else
- dialog = new SetPasswordDialog(body, QString());
-
- if (int r = dialog->exec())
+ if (setChatLogsPassword())
{
- QString newpw;
- if (r != 2)
- newpw = dialog->getPassword();
- delete dialog;
- if (r != 2 && newpw.isEmpty())
- goto fail;
-
Settings::getInstance().setEncryptLogs(true);
bodyUI->cbEncryptHistory->setChecked(true);
// not logically necessary, but more consistent (esp. if the logic changes)
- if (!HistoryKeeper::checkPassword())
- 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")))
- {
- HistoryKeeper::getInstance()->reencrypt(newpw);
- // will set core and reset itself
- return;
- }
- // @apprb you resetInstance() in the old code but wouldn't that wipe out the current unencrypted history?
- // that should of course just become encrypted
- if (newpw.isEmpty())
- core->useOtherPassword(Core::ptHistory);
- else
- core->setPassword(newpw, Core::ptHistory);
- return;
+ // enable change pw button
}
- else
- delete dialog;
}
}
else
@@ -116,40 +124,57 @@ void PrivacyForm::onEncryptLogsUpdated()
HistoryKeeper::resetInstance();
}
- fail:
- core->clearPassword(Core::ptHistory);
- Settings::getInstance().setEncryptLogs(false);
- bodyUI->cbEncryptHistory->setChecked(false);
+ core->clearPassword(Core::ptHistory);
+ Settings::getInstance().setEncryptLogs(false);
+ bodyUI->cbEncryptHistory->setChecked(false);
+ // disable change pw button
+}
+
+bool PrivacyForm::setToxPassword()
+{
+ SetPasswordDialog* dialog;
+ QString body = tr("Please set your new data file password:");
+ if (core->isPasswordSet(Core::ptHistory))
+ dialog = new SetPasswordDialog(body, tr("Use chat log password", "pushbutton text"), this);
+ else
+ dialog = new SetPasswordDialog(body, QString(), this);
+
+ if (int r = dialog->exec())
+ {
+ QString newpw = dialog->getPassword();
+ delete dialog;
+
+ if (r == 2)
+ core->useOtherPassword(Core::ptMain);
+ else
+ core->setPassword(newpw, Core::ptMain);
+ return true;
+ }
+ else
+ {
+ delete dialog;
+ return false;
+ }
}
void PrivacyForm::onEncryptToxUpdated()
{
- bool encryptionState = bodyUI->cbEncryptTox->isChecked();
+ Core* core = Core::getInstance();
- if (encryptionState)
- {
+ if (bodyUI->cbEncryptTox->isChecked())
if (!Core::getInstance()->isPasswordSet(Core::ptMain))
- {
- SetPasswordDialog dialog;
- if (dialog.exec())
+ if (setToxPassword())
{
- QString pswd = dialog.getPassword();
- if (pswd.size() == 0)
- encryptionState = false;
-
- Core::getInstance()->setPassword(pswd, Core::ptMain);
- } else {
- encryptionState = false;
- Core::getInstance()->clearPassword(Core::ptMain);
+ bodyUI->cbEncryptTox->setChecked(true);
+ Settings::getInstance().setEncryptTox(true);
+ // enable change pw button
+ return;
}
- }
- }
- bodyUI->cbEncryptTox->setChecked(encryptionState);
- Settings::getInstance().setEncryptTox(encryptionState);
-
- if (!Settings::getInstance().getEncryptTox())
- Core::getInstance()->clearPassword(Core::ptMain);
+ bodyUI->cbEncryptTox->setChecked(false);
+ Settings::getInstance().setEncryptTox(false);
+ // disable change pw button
+ core->clearPassword(Core::ptMain);
}
void PrivacyForm::setNospam()
diff --git a/src/widget/form/settings/privacyform.h b/src/widget/form/settings/privacyform.h
index fc0e4eb0d..e0b7c70fc 100644
--- a/src/widget/form/settings/privacyform.h
+++ b/src/widget/form/settings/privacyform.h
@@ -39,7 +39,9 @@ private slots:
void generateRandomNospam();
void onNospamEdit();
void onEncryptLogsUpdated();
+ bool setChatLogsPassword();
void onEncryptToxUpdated();
+ bool setToxPassword();
private:
Ui::PrivacySettings* bodyUI;
diff --git a/src/widget/form/settings/privacysettings.ui b/src/widget/form/settings/privacysettings.ui
index 87b76d171..0491dab15 100644
--- a/src/widget/form/settings/privacysettings.ui
+++ b/src/widget/form/settings/privacysettings.ui
@@ -57,7 +57,7 @@
- Keep History (unstable)
+ Keep chat logs (mostly stable)
@@ -76,7 +76,7 @@
true
- Encrypt Tox datafile
+ Encrypt Tox data file
@@ -86,7 +86,7 @@
true
- Encrypt History
+ Encrypt chat logs
true