2014-09-15 18:45:59 +08:00
|
|
|
/*
|
|
|
|
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"
|
2015-04-24 08:32:09 +08:00
|
|
|
#include "src/core/core.h"
|
2014-10-19 01:38:47 +08:00
|
|
|
#include "src/widget/widget.h"
|
2015-02-07 04:01:30 +08:00
|
|
|
#include "src/widget/gui.h"
|
2014-10-19 01:38:47 +08:00
|
|
|
#include "src/widget/form/setpassworddialog.h"
|
2015-06-06 03:37:01 +08:00
|
|
|
#include "src/translator.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() :
|
2015-06-06 03:37:01 +08:00
|
|
|
GenericForm(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
|
|
|
|
|
|
|
connect(bodyUI->cbTypingNotification, SIGNAL(stateChanged(int)), this, SLOT(onTypingNotificationEnabledUpdated()));
|
|
|
|
connect(bodyUI->cbKeepHistory, SIGNAL(stateChanged(int)), this, SLOT(onEnableLoggingUpdated()));
|
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()));
|
2015-06-06 03:37:01 +08:00
|
|
|
|
|
|
|
Translator::registerHandler(std::bind(&PrivacyForm::retranslateUi, this), this);
|
2014-09-15 18:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PrivacyForm::~PrivacyForm()
|
|
|
|
{
|
2015-06-06 03:37:01 +08:00
|
|
|
Translator::unregister(this);
|
2014-10-08 22:32:19 +08:00
|
|
|
delete bodyUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrivacyForm::onEnableLoggingUpdated()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setEnableLogging(bodyUI->cbKeepHistory->isChecked());
|
2015-01-28 07:25:41 +08:00
|
|
|
HistoryKeeper::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-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);
|
|
|
|
}
|
|
|
|
|
2015-06-05 21:39:01 +08:00
|
|
|
void PrivacyForm::showEvent(QShowEvent*)
|
2014-11-16 00:10:04 +08:00
|
|
|
{
|
|
|
|
bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().noSpam);
|
|
|
|
bodyUI->cbTypingNotification->setChecked(Settings::getInstance().isTypingNotificationEnabled());
|
|
|
|
bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging());
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
}
|
2015-06-06 03:37:01 +08:00
|
|
|
|
|
|
|
void PrivacyForm::retranslateUi()
|
|
|
|
{
|
|
|
|
bodyUI->retranslateUi(this);
|
|
|
|
}
|