From c541291aac30346c64072216197d64d1287a4f55 Mon Sep 17 00:00:00 2001 From: apprb Date: Sun, 16 Nov 2014 01:10:04 +0900 Subject: [PATCH] Nospam id part edit --- src/core.cpp | 7 ++++ src/core.h | 2 + src/widget/form/settings/privacyform.cpp | 41 ++++++++++++++++++--- src/widget/form/settings/privacyform.h | 4 ++ src/widget/form/settings/privacysettings.ui | 40 ++++++++++++++++++++ 5 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index 1456b997b..e08bd464d 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1866,3 +1866,10 @@ bool Core::isReady() { return ready; } + +void Core::setNospam(uint32_t nospam) +{ + uint8_t *nspm = reinterpret_cast(&nospam); + std::reverse(nspm, nspm + 4); + tox_set_nospam(tox, nospam); +} diff --git a/src/core.h b/src/core.h index 904a8212c..301a463dd 100644 --- a/src/core.h +++ b/src/core.h @@ -118,6 +118,8 @@ public slots: void micMuteToggle(int callId); void volMuteToggle(int callId); + void setNospam(uint32_t nospam); + static void joinGroupCall(int groupId); ///< Starts a call in an existing AV groupchat. Call from the GUI thread. static void leaveGroupCall(int groupId); ///< Will not leave the group, just stop the call. Call from the GUI thread. static void disableGroupCallMic(int groupId); diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp index 8345f0299..6dc38804b 100644 --- a/src/widget/form/settings/privacyform.cpp +++ b/src/widget/form/settings/privacyform.cpp @@ -30,16 +30,12 @@ PrivacyForm::PrivacyForm() : bodyUI = new Ui::PrivacySettings; bodyUI->setupUi(this); - bodyUI->cbTypingNotification->setChecked(Settings::getInstance().isTypingNotificationEnabled()); - bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging()); - bodyUI->cbEncryptHistory->setChecked(Settings::getInstance().getEncryptLogs()); - bodyUI->cbEncryptHistory->setEnabled(Settings::getInstance().getEnableLogging()); - bodyUI->cbEncryptTox->setChecked(Settings::getInstance().getEncryptTox()); - connect(bodyUI->cbTypingNotification, SIGNAL(stateChanged(int)), this, SLOT(onTypingNotificationEnabledUpdated())); connect(bodyUI->cbKeepHistory, SIGNAL(stateChanged(int)), this, SLOT(onEnableLoggingUpdated())); connect(bodyUI->cbEncryptHistory, SIGNAL(clicked()), this, SLOT(onEncryptLogsUpdated())); connect(bodyUI->cbEncryptTox, SIGNAL(clicked()), this, SLOT(onEncryptToxUpdated())); + connect(bodyUI->nospamLineEdit, SIGNAL(editingFinished()), this, SLOT(setNospam())); + connect(bodyUI->randomNosapamButton, SIGNAL(clicked()), this, SLOT(generateRandomNospam())); } PrivacyForm::~PrivacyForm() @@ -134,3 +130,36 @@ void PrivacyForm::onEncryptToxUpdated() if (!Settings::getInstance().getEncryptTox()) Core::getInstance()->clearPassword(Core::ptMain); } + +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()); + bodyUI->cbEncryptHistory->setEnabled(Settings::getInstance().getEnableLogging()); + bodyUI->cbEncryptTox->setChecked(Settings::getInstance().getEncryptTox()); +} + +void PrivacyForm::generateRandomNospam() +{ + QTime time = QTime::currentTime(); + qsrand((uint)time.msec()); + + uint8_t *newNospam = new uint8_t[4]; + for (int i = 0; i < 4; i++) + newNospam[i] = qrand() % 256; + + Core::getInstance()->setNospam(*reinterpret_cast(newNospam)); + bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().noSpam); +} diff --git a/src/widget/form/settings/privacyform.h b/src/widget/form/settings/privacyform.h index 2a0d79a53..e7a844b92 100644 --- a/src/widget/form/settings/privacyform.h +++ b/src/widget/form/settings/privacyform.h @@ -30,9 +30,13 @@ public: PrivacyForm(); ~PrivacyForm(); + virtual void present(); + private slots: void onEnableLoggingUpdated(); void onTypingNotificationEnabledUpdated(); + void setNospam(); + void generateRandomNospam(); void onEncryptLogsUpdated(); void onEncryptToxUpdated(); diff --git a/src/widget/form/settings/privacysettings.ui b/src/widget/form/settings/privacysettings.ui index 899df3cb4..84b4aecda 100644 --- a/src/widget/form/settings/privacysettings.ui +++ b/src/widget/form/settings/privacysettings.ui @@ -96,6 +96,46 @@ + + + + Nospam + + + + + + + + HHHHHHHH + + + + + + + Generate random nospam + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + +