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

Added change pw buttons; encryption is very nearly done.

@apprb there is one question and one TODO that you should look over in privacyform.cpp, as well as a TODO in historykeeper.cpp
Also both the encryption settings box and the pw dialog lineedits should probably be in a QGridLayout... but I don't really want to do that by hand :P
This commit is contained in:
dubslow 2014-11-27 11:58:33 -05:00 committed by Dubslow
parent 4eb3036414
commit fc30d342bc
6 changed files with 79 additions and 30 deletions

View File

@ -72,6 +72,9 @@ void Core::clearPassword(PasswordType passtype)
delete[] pwsaltedkeys[passtype];
pwsaltedkeys[passtype] = nullptr;
}
if (passtype == ptMain)
saveConfiguration();
}
QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype)

View File

@ -137,7 +137,7 @@ HistoryKeeper::~HistoryKeeper()
void HistoryKeeper::reencrypt(QString newpw)
{
// this needs to appropriately set the core password as well
// TODO: this needs to appropriately set the core password as well
// if newpw.isEmpty(), then use the other core password
}

View File

@ -27,7 +27,8 @@ SetPasswordDialog::SetPasswordDialog(QString body, QString extraButton, QWidget*
connect(ui->passwordlineEdit, SIGNAL(textChanged(QString)), this, SLOT(onPasswordEdit()));
connect(ui->repasswordlineEdit, SIGNAL(textChanged(QString)), this, SLOT(onPasswordEdit()));
ui->body->setText(body);
ui->body->setText(body + tr("\nTo encourage good habits, qTox requires at least 8 characters."));
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
if (!extraButton.isEmpty())
{
@ -44,7 +45,7 @@ SetPasswordDialog::~SetPasswordDialog()
void SetPasswordDialog::onPasswordEdit()
{
if ( !ui->passwordlineEdit->text().isEmpty()
if ( ui->passwordlineEdit->text().length() >= 8
&& ui->passwordlineEdit->text() == ui->repasswordlineEdit->text())
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
else

View File

@ -20,6 +20,19 @@
<item>
<widget class="QLabel" name="body" />
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>12</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="hLayout1">
<item>
@ -64,7 +77,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<height>12</height>
</size>
</property>
</spacer>

View File

@ -32,10 +32,15 @@ PrivacyForm::PrivacyForm() :
bodyUI = new Ui::PrivacySettings;
bodyUI->setupUi(this);
bodyUI->encryptToxHLayout->addStretch();
bodyUI->encryptLogsHLayout->addStretch();
connect(bodyUI->cbTypingNotification, SIGNAL(stateChanged(int)), this, SLOT(onTypingNotificationEnabledUpdated()));
connect(bodyUI->cbKeepHistory, SIGNAL(stateChanged(int)), this, SLOT(onEnableLoggingUpdated()));
connect(bodyUI->cbEncryptHistory, SIGNAL(clicked()), this, SLOT(onEncryptLogsUpdated()));
connect(bodyUI->changeLogsPwButton, &QPushButton::clicked, this, &PrivacyForm::setChatLogsPassword);
connect(bodyUI->cbEncryptTox, SIGNAL(clicked()), this, SLOT(onEncryptToxUpdated()));
connect(bodyUI->changeToxPwButton, &QPushButton::clicked, this, &PrivacyForm::setToxPassword);
connect(bodyUI->nospamLineEdit, SIGNAL(editingFinished()), this, SLOT(setNospam()));
connect(bodyUI->randomNosapamButton, SIGNAL(clicked()), this, SLOT(generateRandomNospam()));
connect(bodyUI->nospamLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onNospamEdit()));
@ -61,8 +66,9 @@ void PrivacyForm::onTypingNotificationEnabledUpdated()
bool PrivacyForm::setChatLogsPassword()
{
Core* core = Core::getInstance();
SetPasswordDialog* dialog;
QString body = tr("Please set your new chat log password:");
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
@ -110,7 +116,8 @@ void PrivacyForm::onEncryptLogsUpdated()
Settings::getInstance().setEncryptLogs(true);
bodyUI->cbEncryptHistory->setChecked(true);
// not logically necessary, but more consistent (esp. if the logic changes)
// enable change pw button
bodyUI->changeLogsPwButton->setEnabled(true);
return;
}
}
}
@ -127,13 +134,14 @@ void PrivacyForm::onEncryptLogsUpdated()
core->clearPassword(Core::ptHistory);
Settings::getInstance().setEncryptLogs(false);
bodyUI->cbEncryptHistory->setChecked(false);
// disable change pw button
bodyUI->changeLogsPwButton->setEnabled(false);
}
bool PrivacyForm::setToxPassword()
{
Core* core = Core::getInstance();
SetPasswordDialog* dialog;
QString body = tr("Please set your new data file password:");
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
@ -162,18 +170,18 @@ void PrivacyForm::onEncryptToxUpdated()
Core* core = Core::getInstance();
if (bodyUI->cbEncryptTox->isChecked())
if (!Core::getInstance()->isPasswordSet(Core::ptMain))
if (!core->isPasswordSet(Core::ptMain))
if (setToxPassword())
{
bodyUI->cbEncryptTox->setChecked(true);
Settings::getInstance().setEncryptTox(true);
// enable change pw button
bodyUI->changeToxPwButton->setEnabled(true);
return;
}
bodyUI->cbEncryptTox->setChecked(false);
Settings::getInstance().setEncryptTox(false);
// disable change pw button
bodyUI->changeToxPwButton->setEnabled(false);
core->clearPassword(Core::ptMain);
}
@ -193,8 +201,10 @@ void PrivacyForm::present()
bodyUI->cbTypingNotification->setChecked(Settings::getInstance().isTypingNotificationEnabled());
bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging());
bodyUI->cbEncryptHistory->setChecked(Settings::getInstance().getEncryptLogs());
bodyUI->changeLogsPwButton->setEnabled(Settings::getInstance().getEncryptLogs());
bodyUI->cbEncryptHistory->setEnabled(Settings::getInstance().getEnableLogging());
bodyUI->cbEncryptTox->setChecked(Settings::getInstance().getEncryptTox());
bodyUI->changeToxPwButton->setEnabled(Settings::getInstance().getEncryptTox());
}
void PrivacyForm::generateRandomNospam()

View File

@ -71,27 +71,49 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="cbEncryptTox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Encrypt Tox data file</string>
</property>
</widget>
<layout class="QHBoxLayout" name="encryptToxHLayout">
<item>
<widget class="QCheckBox" name="cbEncryptTox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Encrypt Tox data file</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="changeToxPwButton">
<property name="text">
<string>Change password</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cbEncryptHistory">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Encrypt chat logs</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="encryptLogsHLayout">
<item>
<widget class="QCheckBox" name="cbEncryptHistory">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Encrypt chat logs</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="changeLogsPwButton">
<property name="text">
<string>Change password</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>