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

Ah, much cleaner

This commit is contained in:
dubslow 2014-11-27 11:22:14 -05:00 committed by Dubslow
parent bafca96554
commit 4eb3036414
5 changed files with 95 additions and 61 deletions

View File

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

View File

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

View File

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

View File

@ -39,7 +39,9 @@ private slots:
void generateRandomNospam();
void onNospamEdit();
void onEncryptLogsUpdated();
bool setChatLogsPassword();
void onEncryptToxUpdated();
bool setToxPassword();
private:
Ui::PrivacySettings* bodyUI;

View File

@ -57,7 +57,7 @@
<string extracomment="History keeping still under developing. Log format changin is possible."/>
</property>
<property name="text">
<string>Keep History (unstable)</string>
<string>Keep chat logs (mostly stable)</string>
</property>
</widget>
</item>
@ -76,7 +76,7 @@
<bool>true</bool>
</property>
<property name="text">
<string>Encrypt Tox datafile</string>
<string>Encrypt Tox data file</string>
</property>
</widget>
</item>
@ -86,7 +86,7 @@
<bool>true</bool>
</property>
<property name="text">
<string>Encrypt History</string>
<string>Encrypt chat logs</string>
</property>
<property name="checkable">
<bool>true</bool>