2014-09-15 18:45:59 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "privacyform.h"
|
2014-10-08 22:32:19 +08:00
|
|
|
#include "ui_privacysettings.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/widget/form/settingswidget.h"
|
2014-10-12 18:24:05 +08:00
|
|
|
#include "src/misc/settings.h"
|
|
|
|
#include "src/historykeeper.h"
|
2014-10-19 01:38:47 +08:00
|
|
|
#include "src/core.h"
|
|
|
|
#include "src/widget/widget.h"
|
|
|
|
#include "src/widget/form/setpassworddialog.h"
|
2014-10-19 17:02:15 +08:00
|
|
|
#include <QMessageBox>
|
2014-11-04 00:44:01 +08:00
|
|
|
#include <QFile>
|
2014-12-04 23:22:17 +08:00
|
|
|
#include <QDebug>
|
2014-09-15 18:45:59 +08:00
|
|
|
|
2014-10-06 00:17:01 +08:00
|
|
|
PrivacyForm::PrivacyForm() :
|
2014-10-17 23:24:23 +08:00
|
|
|
GenericForm(tr("Privacy"), QPixmap(":/img/settings/privacy.png"))
|
2014-09-15 18:45:59 +08:00
|
|
|
{
|
2014-10-08 22:32:19 +08:00
|
|
|
bodyUI = new Ui::PrivacySettings;
|
|
|
|
bodyUI->setupUi(this);
|
2014-10-09 22:36:24 +08:00
|
|
|
|
2014-11-28 00:58:33 +08:00
|
|
|
bodyUI->encryptToxHLayout->addStretch();
|
|
|
|
bodyUI->encryptLogsHLayout->addStretch();
|
|
|
|
|
2014-10-09 22:36:24 +08:00
|
|
|
connect(bodyUI->cbTypingNotification, SIGNAL(stateChanged(int)), this, SLOT(onTypingNotificationEnabledUpdated()));
|
|
|
|
connect(bodyUI->cbKeepHistory, SIGNAL(stateChanged(int)), this, SLOT(onEnableLoggingUpdated()));
|
2014-10-19 16:48:10 +08:00
|
|
|
connect(bodyUI->cbEncryptHistory, SIGNAL(clicked()), this, SLOT(onEncryptLogsUpdated()));
|
2014-11-28 00:58:33 +08:00
|
|
|
connect(bodyUI->changeLogsPwButton, &QPushButton::clicked, this, &PrivacyForm::setChatLogsPassword);
|
2014-10-19 16:48:10 +08:00
|
|
|
connect(bodyUI->cbEncryptTox, SIGNAL(clicked()), this, SLOT(onEncryptToxUpdated()));
|
2014-11-28 00:58:33 +08:00
|
|
|
connect(bodyUI->changeToxPwButton, &QPushButton::clicked, this, &PrivacyForm::setToxPassword);
|
2014-11-16 00:10:04 +08:00
|
|
|
connect(bodyUI->nospamLineEdit, SIGNAL(editingFinished()), this, SLOT(setNospam()));
|
|
|
|
connect(bodyUI->randomNosapamButton, SIGNAL(clicked()), this, SLOT(generateRandomNospam()));
|
2014-11-16 01:16:56 +08:00
|
|
|
connect(bodyUI->nospamLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onNospamEdit()));
|
2014-09-15 18:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PrivacyForm::~PrivacyForm()
|
|
|
|
{
|
2014-10-08 22:32:19 +08:00
|
|
|
delete bodyUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrivacyForm::onEnableLoggingUpdated()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setEnableLogging(bodyUI->cbKeepHistory->isChecked());
|
|
|
|
bodyUI->cbEncryptHistory->setEnabled(bodyUI->cbKeepHistory->isChecked());
|
2014-10-09 22:36:24 +08:00
|
|
|
HistoryKeeper::getInstance()->resetInstance();
|
2014-11-10 21:06:35 +08:00
|
|
|
Widget::getInstance()->clearAllReceipts();
|
2014-10-08 22:32:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrivacyForm::onTypingNotificationEnabledUpdated()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setTypingNotification(bodyUI->cbTypingNotification->isChecked());
|
|
|
|
}
|
|
|
|
|
2014-11-28 00:22:14 +08:00
|
|
|
bool PrivacyForm::setChatLogsPassword()
|
|
|
|
{
|
2014-11-28 00:58:33 +08:00
|
|
|
Core* core = Core::getInstance();
|
2014-11-28 00:22:14 +08:00
|
|
|
SetPasswordDialog* dialog;
|
2014-11-28 00:58:33 +08:00
|
|
|
QString body = tr("Please set your new chat log password.");
|
2014-11-28 00:22:14 +08:00
|
|
|
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())
|
|
|
|
{
|
2014-12-05 00:55:14 +08:00
|
|
|
QList<HistoryKeeper::HistMessage> oldMessages = HistoryKeeper::exportMessagesDeleteFile();
|
|
|
|
|
2014-11-28 00:22:14 +08:00
|
|
|
QString newpw = dialog->getPassword();
|
|
|
|
delete dialog;
|
|
|
|
|
|
|
|
if (r == 2)
|
|
|
|
core->useOtherPassword(Core::ptHistory);
|
|
|
|
else
|
|
|
|
core->setPassword(newpw, Core::ptHistory);
|
2014-12-05 00:55:14 +08:00
|
|
|
|
|
|
|
//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?
|
|
|
|
|
2014-12-05 01:44:45 +08:00
|
|
|
Settings::getInstance().setEncryptLogs(true);
|
2014-12-05 00:55:14 +08:00
|
|
|
HistoryKeeper::getInstance()->importMessages(oldMessages);
|
|
|
|
|
2014-11-28 00:22:14 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete dialog;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-08 22:32:19 +08:00
|
|
|
void PrivacyForm::onEncryptLogsUpdated()
|
|
|
|
{
|
2014-11-27 23:38:23 +08:00
|
|
|
Core* core = Core::getInstance();
|
2014-10-08 22:32:19 +08:00
|
|
|
|
2014-11-27 23:38:23 +08:00
|
|
|
if (bodyUI->cbEncryptHistory->isChecked())
|
2014-10-19 01:38:47 +08:00
|
|
|
{
|
2014-11-27 23:38:23 +08:00
|
|
|
if (!core->isPasswordSet(Core::ptHistory))
|
|
|
|
{
|
2014-11-28 00:22:14 +08:00
|
|
|
if (setChatLogsPassword())
|
2014-11-27 23:38:23 +08:00
|
|
|
{
|
|
|
|
bodyUI->cbEncryptHistory->setChecked(true);
|
2014-11-28 00:58:33 +08:00
|
|
|
bodyUI->changeLogsPwButton->setEnabled(true);
|
|
|
|
return;
|
2014-11-27 23:38:23 +08:00
|
|
|
}
|
|
|
|
}
|
2014-10-19 01:38:47 +08:00
|
|
|
}
|
2014-11-22 16:46:22 +08:00
|
|
|
else
|
2014-10-19 17:02:15 +08:00
|
|
|
{
|
2015-01-20 11:16:28 +08:00
|
|
|
QMessageBox::StandardButton button = QMessageBox::warning(
|
|
|
|
Widget::getInstance(),
|
|
|
|
tr("Old encrypted chat logs", "title"),
|
2015-01-23 21:05:46 +08:00
|
|
|
tr("Would you like to decrypt your chat logs?\nOtherwise they will be deleted."),
|
2015-01-20 11:16:28 +08:00
|
|
|
QMessageBox::Ok | QMessageBox::No | QMessageBox::Cancel,
|
2015-01-20 12:23:13 +08:00
|
|
|
QMessageBox::Cancel
|
2015-01-20 11:16:28 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
if (button == QMessageBox::Ok)
|
2014-11-27 23:38:23 +08:00
|
|
|
{
|
2014-12-05 00:55:14 +08:00
|
|
|
QList<HistoryKeeper::HistMessage> oldMessages = HistoryKeeper::exportMessagesDeleteFile(true);
|
|
|
|
core->clearPassword(Core::ptHistory);
|
2014-12-04 23:22:17 +08:00
|
|
|
Settings::getInstance().setEncryptLogs(false);
|
|
|
|
HistoryKeeper::getInstance()->importMessages(oldMessages);
|
2014-11-27 23:38:23 +08:00
|
|
|
}
|
2015-01-20 11:16:28 +08:00
|
|
|
else if (button == QMessageBox::No)
|
|
|
|
{
|
|
|
|
if (QMessageBox::critical(
|
|
|
|
Widget::getInstance(),
|
|
|
|
tr("Old encrypted chat logs", "title"),
|
|
|
|
tr("Are you sure you want to lose your entire chat history?"),
|
2015-01-27 09:12:36 +08:00
|
|
|
QMessageBox::Yes | QMessageBox::Cancel,
|
2015-01-20 11:16:28 +08:00
|
|
|
QMessageBox::Cancel
|
|
|
|
)
|
2015-01-27 09:12:36 +08:00
|
|
|
== QMessageBox::Yes)
|
2015-01-20 11:16:28 +08:00
|
|
|
{
|
|
|
|
HistoryKeeper::removeHistory(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bodyUI->cbEncryptHistory->setChecked(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-11-27 23:38:23 +08:00
|
|
|
else
|
2014-12-04 23:22:17 +08:00
|
|
|
{
|
2015-01-20 11:16:28 +08:00
|
|
|
bodyUI->cbEncryptHistory->setChecked(true);
|
|
|
|
return;
|
2014-12-04 23:22:17 +08:00
|
|
|
}
|
2014-10-19 17:02:15 +08:00
|
|
|
}
|
2014-11-27 23:38:23 +08:00
|
|
|
|
2014-11-28 00:22:14 +08:00
|
|
|
core->clearPassword(Core::ptHistory);
|
|
|
|
Settings::getInstance().setEncryptLogs(false);
|
|
|
|
bodyUI->cbEncryptHistory->setChecked(false);
|
2014-11-28 00:58:33 +08:00
|
|
|
bodyUI->changeLogsPwButton->setEnabled(false);
|
2014-10-08 22:32:19 +08:00
|
|
|
}
|
|
|
|
|
2014-11-28 00:22:14 +08:00
|
|
|
bool PrivacyForm::setToxPassword()
|
2014-10-08 22:32:19 +08:00
|
|
|
{
|
2014-11-28 00:58:33 +08:00
|
|
|
Core* core = Core::getInstance();
|
2014-11-28 00:22:14 +08:00
|
|
|
SetPasswordDialog* dialog;
|
2014-11-28 00:58:33 +08:00
|
|
|
QString body = tr("Please set your new data file password.");
|
2014-11-28 00:22:14 +08:00
|
|
|
if (core->isPasswordSet(Core::ptHistory))
|
|
|
|
dialog = new SetPasswordDialog(body, tr("Use chat log password", "pushbutton text"), this);
|
|
|
|
else
|
|
|
|
dialog = new SetPasswordDialog(body, QString(), this);
|
2014-10-19 16:48:10 +08:00
|
|
|
|
2014-11-28 00:22:14 +08:00
|
|
|
if (int r = dialog->exec())
|
2014-10-19 16:48:10 +08:00
|
|
|
{
|
2014-11-28 00:22:14 +08:00
|
|
|
QString newpw = dialog->getPassword();
|
|
|
|
delete dialog;
|
|
|
|
|
|
|
|
if (r == 2)
|
|
|
|
core->useOtherPassword(Core::ptMain);
|
|
|
|
else
|
|
|
|
core->setPassword(newpw, Core::ptMain);
|
2014-12-05 03:31:43 +08:00
|
|
|
|
|
|
|
Settings::getInstance().setEncryptTox(true);
|
|
|
|
core->saveConfiguration();
|
2014-11-28 00:22:14 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete dialog;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrivacyForm::onEncryptToxUpdated()
|
|
|
|
{
|
|
|
|
Core* core = Core::getInstance();
|
|
|
|
|
|
|
|
if (bodyUI->cbEncryptTox->isChecked())
|
2015-01-23 21:05:46 +08:00
|
|
|
{
|
2014-11-28 00:58:33 +08:00
|
|
|
if (!core->isPasswordSet(Core::ptMain))
|
2015-01-23 21:05:46 +08:00
|
|
|
{
|
2014-11-28 00:22:14 +08:00
|
|
|
if (setToxPassword())
|
2014-10-19 16:48:10 +08:00
|
|
|
{
|
2014-11-28 00:22:14 +08:00
|
|
|
bodyUI->cbEncryptTox->setChecked(true);
|
2014-11-28 00:58:33 +08:00
|
|
|
bodyUI->changeToxPwButton->setEnabled(true);
|
2014-11-28 00:22:14 +08:00
|
|
|
return;
|
2014-10-19 16:48:10 +08:00
|
|
|
}
|
2015-01-23 21:05:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!Widget::getInstance()->askQuestion(tr("Decrypt your data file", "title"), tr("Would you like to decrypt your data file?")))
|
|
|
|
{
|
|
|
|
bodyUI->cbEncryptTox->setChecked(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// affirmative answer falls through to the catch all below
|
|
|
|
}
|
2014-10-19 16:48:10 +08:00
|
|
|
|
2014-11-28 00:22:14 +08:00
|
|
|
bodyUI->cbEncryptTox->setChecked(false);
|
|
|
|
Settings::getInstance().setEncryptTox(false);
|
2014-11-28 00:58:33 +08:00
|
|
|
bodyUI->changeToxPwButton->setEnabled(false);
|
2014-11-28 00:22:14 +08:00
|
|
|
core->clearPassword(Core::ptMain);
|
2014-09-15 18:45:59 +08:00
|
|
|
}
|
2014-11-16 00:10:04 +08:00
|
|
|
|
|
|
|
void PrivacyForm::setNospam()
|
|
|
|
{
|
|
|
|
QString newNospam = bodyUI->nospamLineEdit->text();
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
uint32_t nospam = newNospam.toLongLong(&ok, 16);
|
|
|
|
if (ok)
|
|
|
|
Core::getInstance()->setNospam(nospam);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrivacyForm::present()
|
|
|
|
{
|
|
|
|
bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().noSpam);
|
|
|
|
bodyUI->cbTypingNotification->setChecked(Settings::getInstance().isTypingNotificationEnabled());
|
|
|
|
bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging());
|
|
|
|
bodyUI->cbEncryptHistory->setChecked(Settings::getInstance().getEncryptLogs());
|
2014-11-28 00:58:33 +08:00
|
|
|
bodyUI->changeLogsPwButton->setEnabled(Settings::getInstance().getEncryptLogs());
|
2014-11-16 00:10:04 +08:00
|
|
|
bodyUI->cbEncryptHistory->setEnabled(Settings::getInstance().getEnableLogging());
|
|
|
|
bodyUI->cbEncryptTox->setChecked(Settings::getInstance().getEncryptTox());
|
2014-11-28 00:58:33 +08:00
|
|
|
bodyUI->changeToxPwButton->setEnabled(Settings::getInstance().getEncryptTox());
|
2014-11-16 00:10:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrivacyForm::generateRandomNospam()
|
|
|
|
{
|
|
|
|
QTime time = QTime::currentTime();
|
|
|
|
qsrand((uint)time.msec());
|
|
|
|
|
2014-11-18 09:12:19 +08:00
|
|
|
uint32_t newNospam{0};
|
2014-11-16 00:10:04 +08:00
|
|
|
for (int i = 0; i < 4; i++)
|
2014-11-16 06:26:30 +08:00
|
|
|
newNospam = (newNospam<<8) + (qrand() % 256); // Generate byte by byte. For some reason.
|
2014-11-16 00:10:04 +08:00
|
|
|
|
2014-11-16 06:26:30 +08:00
|
|
|
Core::getInstance()->setNospam(newNospam);
|
2014-11-16 00:10:04 +08:00
|
|
|
bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().noSpam);
|
|
|
|
}
|
2014-11-16 01:16:56 +08:00
|
|
|
|
|
|
|
void PrivacyForm::onNospamEdit()
|
|
|
|
{
|
|
|
|
QString str = bodyUI->nospamLineEdit->text();
|
|
|
|
int curs = bodyUI->nospamLineEdit->cursorPosition();
|
|
|
|
if (str.length() != 8)
|
|
|
|
{
|
|
|
|
str = QString("00000000").replace(0, str.length(), str);
|
|
|
|
bodyUI->nospamLineEdit->setText(str);
|
|
|
|
bodyUI->nospamLineEdit->setCursorPosition(curs);
|
|
|
|
};
|
|
|
|
}
|