diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-03-07 23:32:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-03-07 23:32:25 +0300 |
commit | 0d9e625499c18a4eaf79d38dfb1ef6abf0c553bd (patch) | |
tree | 1e4c29a0de3697946060410e41910f88bcc5b979 /src/pincodemanager.cpp | |
parent | b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75 (diff) | |
download | manaverse-0d9e625499c18a4eaf79d38dfb1ef6abf0c553bd.tar.gz manaverse-0d9e625499c18a4eaf79d38dfb1ef6abf0c553bd.tar.bz2 manaverse-0d9e625499c18a4eaf79d38dfb1ef6abf0c553bd.tar.xz manaverse-0d9e625499c18a4eaf79d38dfb1ef6abf0c553bd.zip |
Add support for set new pincode.
Add pincode dialog and widget.
Diffstat (limited to 'src/pincodemanager.cpp')
-rw-r--r-- | src/pincodemanager.cpp | 88 |
1 files changed, 83 insertions, 5 deletions
diff --git a/src/pincodemanager.cpp b/src/pincodemanager.cpp index e13671293..4ee8abd3a 100644 --- a/src/pincodemanager.cpp +++ b/src/pincodemanager.cpp @@ -20,13 +20,28 @@ #include "pincodemanager.h" +#include "gui/windows/okdialog.h" +#include "gui/windows/pincodedialog.h" + +#include "gui/widgets/createwidget.h" + +#include "listeners/newpincodelistener.h" +#include "listeners/newpincoderetrylistener.h" + +#include "net/charserverhandler.h" + +#include "utils/gettext.h" + #include "debug.h" PincodeManager pincodeManager; PincodeManager::PincodeManager() : + mNewPincode(), mSeed(0U), - mAccountId(BeingId_zero) + mAccountId(BeingId_zero), + mDialog(nullptr), + mState(PincodeState::None) { } @@ -38,21 +53,84 @@ void PincodeManager::init() { mSeed = 0; mAccountId = BeingId_zero; + mState = PincodeState::None; } -void PincodeManager::pinOk() +void PincodeManager::clearDialog(const PincodeDialog *const PincodeDialog) { + if (mDialog == PincodeDialog) + mDialog = nullptr; } -void PincodeManager::askPin() +void PincodeManager::updateState() { + switch (mState) + { + case PincodeState::None: + case PincodeState::Ask: + case PincodeState::Change: + default: + break; + case PincodeState::Create: + CREATEWIDGETV(mDialog, PincodeDialog, + // TRANSLATORS: dialog caption + _("New pincode"), + // TRANSLATORS: dialog label + _("Set new pincode"), + mSeed, + nullptr); + mDialog->requestFocus(); + mDialog->setActionEventId("ok"); + mDialog->addActionListener(&newPincodeListener); + break; + } } -void PincodeManager::createNewPin() +void PincodeManager::setNewPincode(const std::string &pincode) { + if (mNewPincode.empty()) + { // first pincode + mNewPincode = pincode; + CREATEWIDGETV(mDialog, PincodeDialog, + // TRANSLATORS: dialog caption + _("New pincode"), + // TRANSLATORS: dialog label + _("Confirm new pincode"), + mSeed, + nullptr); + mDialog->requestFocus(); + mDialog->setActionEventId("ok"); + mDialog->addActionListener(&newPincodeListener); + } + else + { // pincode confirmation + if (mNewPincode != pincode) + { + mNewPincode.clear(); + OkDialog *const dialog = CREATEWIDGETR(OkDialog, + // TRANSLATORS: error header + _("Pincode"), + // TRANSLATORS: error message + _("Wrong pincode confirmation!"), + // TRANSLATORS: ok dialog button + _("OK"), + DialogType::ERROR, + Modal_true, + ShowCenter_true, + nullptr, + 260); + dialog->addActionListener(&newPincodeRetryListener); + } + else + { + charServerHandler->setNewPincode(mAccountId, + mNewPincode); + mNewPincode.clear(); + } + } } -void PincodeManager::changePin() +void PincodeManager::pinOk() { } |