qTox
Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
src
widget
form
settings
privacyform.cpp
Go to the documentation of this file.
1
/*
2
Copyright © 2014-2019 by The qTox Project Contributors
3
4
This file is part of qTox, a Qt-based graphical interface for Tox.
5
6
qTox is libre software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
qTox is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with qTox. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#include "
privacyform.h
"
21
#include "ui_privacysettings.h"
22
23
#include <QDebug>
24
#include <QFile>
25
#include <QMessageBox>
26
27
#include "
src/core/core.h
"
28
#include "
src/nexus.h
"
29
#include "
src/persistence/history.h
"
30
#include "
src/persistence/profile.h
"
31
#include "
src/persistence/settings.h
"
32
#include "
src/widget/form/setpassworddialog.h
"
33
#include "
src/widget/form/settingswidget.h
"
34
#include "
src/widget/gui.h
"
35
#include "
src/widget/tool/recursivesignalblocker.h
"
36
#include "
src/widget/translator.h
"
37
#include "
src/widget/widget.h
"
38
39
#include <chrono>
40
#include <random>
41
42
PrivacyForm::PrivacyForm
(
Core
* _core)
43
:
GenericForm
(QPixmap(
":/img/settings/privacy.png"
))
44
, bodyUI(new
Ui
::PrivacySettings)
45
, core{_core}
46
{
47
bodyUI->setupUi(
this
);
48
49
// block all child signals during initialization
50
const
RecursiveSignalBlocker
signalBlocker(
this
);
51
52
eventsInit();
53
Translator::registerHandler
(std::bind(&
PrivacyForm::retranslateUi
,
this
),
this
);
54
}
55
56
PrivacyForm::~PrivacyForm
()
57
{
58
Translator::unregister
(
this
);
59
delete
bodyUI
;
60
}
61
62
void
PrivacyForm::on_cbKeepHistory_stateChanged
()
63
{
64
Settings::getInstance
().
setEnableLogging
(
bodyUI
->cbKeepHistory->isChecked());
65
if
(!
bodyUI
->cbKeepHistory->isChecked()) {
66
emit
clearAllReceipts
();
67
QMessageBox::StandardButton dialogDelHistory;
68
dialogDelHistory =
69
QMessageBox::question(
nullptr
, tr(
"Confirmation"
),
70
tr(
"Do you want to permanently delete all chat history?"
),
71
QMessageBox::Yes | QMessageBox::No);
72
if
(dialogDelHistory == QMessageBox::Yes) {
73
Nexus::getProfile
()->
getHistory
()->
eraseHistory
();
74
}
75
}
76
}
77
78
void
PrivacyForm::on_cbTypingNotification_stateChanged
()
79
{
80
Settings::getInstance
().
setTypingNotification
(
bodyUI
->cbTypingNotification->isChecked());
81
}
82
83
void
PrivacyForm::on_nospamLineEdit_editingFinished
()
84
{
85
QString newNospam =
bodyUI
->nospamLineEdit->text();
86
87
bool
ok;
88
uint32_t nospam = newNospam.toLongLong(&ok, 16);
89
if
(ok) {
90
core
->
setNospam
(nospam);
91
}
92
}
93
94
void
PrivacyForm::showEvent
(QShowEvent*)
95
{
96
const
Settings
& s =
Settings::getInstance
();
97
bodyUI
->nospamLineEdit->setText(
core
->
getSelfId
().
getNoSpamString
());
98
bodyUI
->cbTypingNotification->setChecked(s.
getTypingNotification
());
99
bodyUI
->cbKeepHistory->setChecked(
Settings::getInstance
().getEnableLogging());
100
bodyUI
->blackListTextEdit->setText(s.
getBlackList
().join(
'\n'
));
101
}
102
103
void
PrivacyForm::on_randomNosapamButton_clicked
()
104
{
105
uint32_t newNospam{0};
106
107
static
std::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
108
newNospam = rng();
109
110
core
->
setNospam
(newNospam);
111
bodyUI
->nospamLineEdit->setText(
core
->
getSelfId
().
getNoSpamString
());
112
}
113
114
void
PrivacyForm::on_nospamLineEdit_textChanged
()
115
{
116
QString str =
bodyUI
->nospamLineEdit->text();
117
int
curs =
bodyUI
->nospamLineEdit->cursorPosition();
118
if
(str.length() != 8) {
119
str = QString(
"00000000"
).replace(0, str.length(), str);
120
bodyUI
->nospamLineEdit->setText(str);
121
bodyUI
->nospamLineEdit->setCursorPosition(curs);
122
}
123
}
124
125
void
PrivacyForm::on_blackListTextEdit_textChanged
()
126
{
127
const
QStringList strlist =
bodyUI
->blackListTextEdit->toPlainText().split(
'\n'
);
128
Settings::getInstance
().
setBlackList
(strlist);
129
}
130
131
void
PrivacyForm::retranslateUi
()
132
{
133
bodyUI
->retranslateUi(
this
);
134
}
PrivacyForm::bodyUI
Ui::PrivacySettings * bodyUI
Definition:
privacyform.h:57
Core::setNospam
void setNospam(uint32_t nospam)
Sets the NoSpam value to prevent friend request spam.
Definition:
core.cpp:1804
profile.h
Settings
Definition:
settings.h:51
history.h
recursivesignalblocker.h
PrivacyForm::core
Core * core
Definition:
privacyform.h:58
PrivacyForm::on_randomNosapamButton_clicked
void on_randomNosapamButton_clicked()
Definition:
privacyform.cpp:103
settings.h
ToxId::getNoSpamString
QString getNoSpamString() const
Returns the NoSpam value converted to QString.
Definition:
toxid.cpp:204
History::eraseHistory
void eraseHistory()
Erases all the chat history from the database.
Definition:
history.cpp:771
Settings::setBlackList
void setBlackList(const QStringList &blist) override
Definition:
settings.cpp:1682
setpassworddialog.h
Translator::unregister
static void unregister(void *owner)
Unregisters all handlers of an owner.
Definition:
translator.cpp:103
Settings::setTypingNotification
void setTypingNotification(bool enabled)
Definition:
settings.cpp:1669
PrivacyForm::~PrivacyForm
~PrivacyForm()
Definition:
privacyform.cpp:56
Nexus::getProfile
static Profile * getProfile()
Get current user profile.
Definition:
nexus.cpp:290
Settings::setEnableLogging
void setEnableLogging(bool newValue)
Definition:
settings.cpp:1247
Core::getSelfId
ToxId getSelfId() const override
Returns our Tox ID.
Definition:
core.cpp:1258
Ui
Definition:
filetransferwidget.h:30
PrivacyForm::on_blackListTextEdit_textChanged
void on_blackListTextEdit_textChanged()
Definition:
privacyform.cpp:125
widget.h
Translator::registerHandler
static void registerHandler(const std::function< void()> &, void *owner)
Register a function to be called when the UI needs to be retranslated.
Definition:
translator.cpp:93
PrivacyForm::clearAllReceipts
void clearAllReceipts()
Settings::getInstance
static Settings & getInstance()
Returns the singleton instance.
Definition:
settings.cpp:88
PrivacyForm::on_nospamLineEdit_textChanged
void on_nospamLineEdit_textChanged()
Definition:
privacyform.cpp:114
Profile::getHistory
History * getHistory()
Get chat history.
Definition:
profile.cpp:785
PrivacyForm::on_cbKeepHistory_stateChanged
void on_cbKeepHistory_stateChanged()
Definition:
privacyform.cpp:62
PrivacyForm::showEvent
void showEvent(QShowEvent *) final
Definition:
privacyform.cpp:94
settingswidget.h
Settings::getTypingNotification
bool getTypingNotification() const
Definition:
settings.cpp:1663
core.h
Settings::getBlackList
QStringList getBlackList() const override
Definition:
settings.cpp:1676
privacyform.h
gui.h
PrivacyForm::on_nospamLineEdit_editingFinished
void on_nospamLineEdit_editingFinished()
Definition:
privacyform.cpp:83
PrivacyForm::retranslateUi
void retranslateUi()
Definition:
privacyform.cpp:131
PrivacyForm::on_cbTypingNotification_stateChanged
void on_cbTypingNotification_stateChanged()
Definition:
privacyform.cpp:78
translator.h
RecursiveSignalBlocker
Recursively blocks all signals from an object and its children.
Definition:
recursivesignalblocker.h:27
GenericForm
Definition:
genericsettings.h:24
nexus.h
PrivacyForm::PrivacyForm
PrivacyForm(Core *_core)
Definition:
privacyform.cpp:42
Core
Definition:
core.h:59
Generated by
1.8.17