1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/src/widget/form/settings/privacyform.cpp

118 lines
3.9 KiB
C++
Raw Normal View History

/*
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"
#include "src/misc/settings.h"
#include "src/historykeeper.h"
#include "src/core.h"
#include "src/widget/widget.h"
#include "src/widget/form/setpassworddialog.h"
2014-10-06 00:17:01 +08:00
PrivacyForm::PrivacyForm() :
GenericForm(tr("Privacy settings"), QPixmap(":/img/settings/privacy.png"))
{
2014-10-08 22:32:19 +08:00
bodyUI = new Ui::PrivacySettings;
bodyUI->setupUi(this);
2014-10-09 22:36:24 +08:00
bodyUI->cbTypingNotification->setChecked(Settings::getInstance().isTypingNotificationEnabled());
bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging());
bodyUI->cbEncryptHistory->setChecked(Settings::getInstance().getEncryptLogs());
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()));
connect(bodyUI->cbEncryptTox, SIGNAL(clicked()), this, SLOT(onEncryptToxUpdated()));
}
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-10-08 22:32:19 +08:00
}
void PrivacyForm::onTypingNotificationEnabledUpdated()
{
Settings::getInstance().setTypingNotification(bodyUI->cbTypingNotification->isChecked());
}
void PrivacyForm::onEncryptLogsUpdated()
{
2014-10-19 16:48:10 +08:00
bool encrytionState = bodyUI->cbEncryptHistory->isChecked();
2014-10-08 22:32:19 +08:00
2014-10-19 16:48:10 +08:00
if (encrytionState)
{
if (!Core::getInstance()->isPasswordSet())
{
SetPasswordDialog dialog;
if (dialog.exec())
{
QString pswd = dialog.getPassword();
2014-10-19 16:48:10 +08:00
if (pswd.size() == 0)
encrytionState = false;
2014-10-19 16:48:10 +08:00
Core::getInstance()->setPassword(pswd);
} else {
encrytionState = false;
Core::getInstance()->clearPassword();
}
}
}
2014-10-19 16:48:10 +08:00
bodyUI->cbEncryptHistory->setChecked(encrytionState);
Settings::getInstance().setEncryptLogs(encrytionState);
if (!Settings::getInstance().getEncryptLogs() && !Settings::getInstance().getEncryptTox())
Core::getInstance()->clearPassword();
2014-10-08 22:32:19 +08:00
}
void PrivacyForm::onEncryptToxUpdated()
2014-10-08 22:32:19 +08:00
{
2014-10-19 16:48:10 +08:00
bool encrytionState = bodyUI->cbEncryptTox->isChecked();
if (encrytionState)
{
if (!Core::getInstance()->isPasswordSet())
{
SetPasswordDialog dialog;
if (dialog.exec())
{
QString pswd = dialog.getPassword();
if (pswd.size() == 0)
encrytionState = false;
Core::getInstance()->setPassword(pswd);
} else {
encrytionState = false;
Core::getInstance()->clearPassword();
}
}
}
// bodyUI->cbEncryptTox->setChecked(encrytionState);
// Settings::getInstance().setEncryptTox(encrytionState);
if (!Settings::getInstance().getEncryptLogs() && !Settings::getInstance().getEncryptTox())
Core::getInstance()->clearPassword();
}