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]; delete[] pwsaltedkeys[passtype];
pwsaltedkeys[passtype] = nullptr; pwsaltedkeys[passtype] = nullptr;
} }
if (passtype == ptMain)
saveConfiguration();
} }
QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype) QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype)

View File

@ -137,7 +137,7 @@ HistoryKeeper::~HistoryKeeper()
void HistoryKeeper::reencrypt(QString newpw) 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 // 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->passwordlineEdit, SIGNAL(textChanged(QString)), this, SLOT(onPasswordEdit()));
connect(ui->repasswordlineEdit, 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()) if (!extraButton.isEmpty())
{ {
@ -44,7 +45,7 @@ SetPasswordDialog::~SetPasswordDialog()
void SetPasswordDialog::onPasswordEdit() void SetPasswordDialog::onPasswordEdit()
{ {
if ( !ui->passwordlineEdit->text().isEmpty() if ( ui->passwordlineEdit->text().length() >= 8
&& ui->passwordlineEdit->text() == ui->repasswordlineEdit->text()) && ui->passwordlineEdit->text() == ui->repasswordlineEdit->text())
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
else else

View File

@ -20,6 +20,19 @@
<item> <item>
<widget class="QLabel" name="body" /> <widget class="QLabel" name="body" />
</item> </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> <item>
<layout class="QHBoxLayout" name="hLayout1"> <layout class="QHBoxLayout" name="hLayout1">
<item> <item>
@ -64,7 +77,7 @@
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>40</height> <height>12</height>
</size> </size>
</property> </property>
</spacer> </spacer>

View File

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

View File

@ -70,6 +70,8 @@
<string>Encryption</string> <string>Encryption</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="encryptToxHLayout">
<item> <item>
<widget class="QCheckBox" name="cbEncryptTox"> <widget class="QCheckBox" name="cbEncryptTox">
<property name="enabled"> <property name="enabled">
@ -80,6 +82,17 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="changeToxPwButton">
<property name="text">
<string>Change password</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="encryptLogsHLayout">
<item> <item>
<widget class="QCheckBox" name="cbEncryptHistory"> <widget class="QCheckBox" name="cbEncryptHistory">
<property name="enabled"> <property name="enabled">
@ -93,6 +106,15 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="changeLogsPwButton">
<property name="text">
<string>Change password</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>