ManaPlus
pincodemanager.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2018 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "pincodemanager.h"
22 
23 #include "client.h"
24 
25 #include "gui/windows/okdialog.h"
27 
29 
34 
35 #include "net/charserverhandler.h"
36 
37 #include "utils/gettext.h"
38 
39 #include "debug.h"
40 
42 
44  mOldPincode(),
45  mNewPincode(),
46  mSeed(0U),
47  mAccountId(BeingId_zero),
49  mState(PincodeState::None)
50 {
51 }
52 
54 {
55 }
56 
58 {
59  mSeed = 0;
62  mNewPincode.clear();
63 }
64 
66 {
67  if (mDialog == PincodeDialog)
68  mDialog = nullptr;
69 }
70 
72 {
73  switch (mState)
74  {
75  case PincodeState::Ask:
77  // TRANSLATORS: dialog caption
78  _("Pincode"),
79  // TRANSLATORS: dialog label
80  _("Enter pincode"),
81  mSeed,
82  nullptr);
86  break;
88  mNewPincode.clear();
90  // TRANSLATORS: dialog caption
91  _("New pincode"),
92  // TRANSLATORS: dialog label
93  _("Enter new pincode"),
94  mSeed,
95  nullptr);
99  break;
101  mOldPincode.clear();
102  mNewPincode.clear();
104  // TRANSLATORS: dialog caption
105  _("Change pincode"),
106  // TRANSLATORS: dialog label
107  _("Enter old pincode"),
108  mSeed,
109  nullptr);
111  mDialog->setActionEventId("ok");
113  break;
114  case PincodeState::None:
115  default:
116  break;
117  }
118 }
119 
120 void PincodeManager::setNewPincode(const std::string &pincode)
121 {
122  if (mNewPincode.empty())
123  { // first pincode
124  mNewPincode = pincode;
126  // TRANSLATORS: dialog caption
127  _("New pincode"),
128  // TRANSLATORS: dialog label
129  _("Confirm new pincode"),
130  mSeed,
131  nullptr);
133  mDialog->setActionEventId("ok");
135  }
136  else
137  { // pincode confirmation
138  if (mNewPincode != pincode)
139  {
140  mNewPincode.clear();
142  // TRANSLATORS: error header
143  _("Pincode"),
144  // TRANSLATORS: error message
145  _("Wrong pincode confirmation!"),
146  // TRANSLATORS: ok dialog button
147  _("OK"),
149  Modal_true,
151  nullptr,
152  260);
154  }
155  else
156  {
158  mNewPincode);
159  mNewPincode.clear();
160  }
161  }
162 }
163 
164 void PincodeManager::changePincode(const std::string &pincode)
165 {
166  if (mOldPincode.empty())
167  { // set old pincode
168  mOldPincode = pincode;
170  // TRANSLATORS: dialog caption
171  _("Change pincode"),
172  // TRANSLATORS: dialog label
173  _("Enter new pincode"),
174  mSeed,
175  nullptr);
177  mDialog->setActionEventId("ok");
179  }
180  else if (mNewPincode.empty())
181  { // set first new pincode
182  mNewPincode = pincode;
184  // TRANSLATORS: dialog caption
185  _("Change pincode"),
186  // TRANSLATORS: dialog label
187  _("Confirm new pincode"),
188  mSeed,
189  nullptr);
191  mDialog->setActionEventId("ok");
193  }
194  else
195  { // new pincode confirmation
196  if (mNewPincode != pincode)
197  {
198  mOldPincode.clear();
199  mNewPincode.clear();
201  // TRANSLATORS: error header
202  _("Pincode"),
203  // TRANSLATORS: error message
204  _("Wrong pincode confirmation!"),
205  // TRANSLATORS: ok dialog button
206  _("OK"),
208  Modal_true,
210  nullptr,
211  260);
213  }
214  else
215  {
217  mOldPincode,
218  mNewPincode);
219  mOldPincode.clear();
220  mNewPincode.clear();
221  }
222  }
223 }
224 
225 void PincodeManager::sendPincode(const std::string &pincode)
226 {
228  pincode);
229 }
230 
232 {
234  if (client)
235  client->focusWindow();
236 }
237 
239 {
241  updateState();
242 }
243 
245 {
246  if (mDialog)
247  {
249  mDialog = nullptr;
250  }
251 }
252 
254 {
255  return mState != PincodeState::None;
256 }
#define _(s)
Definition: gettext.h:34
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
virtual void changePincode(const BeingId accountId, const std::string &oldPin, const std::string &newPin) const =0
NpcDialog * mDialog
Definition: npcrecv.cpp:41
void setNewPincode(const std::string &pincode)
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
Client * client
Definition: client.cpp:117
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:24
virtual void sendCheckPincode(const BeingId accountId, const std::string &pin) const =0
BeingId mAccountId
Window * mDialog
virtual void requestFocus()
Definition: widget.cpp:203
virtual void setNewPincode(const BeingId accountId, const std::string &pin) const =0
void changePincode(const std::string &pincode)
#define nullptr
Definition: localconsts.h:44
const bool ShowCenter_true
Definition: showcenter.h:29
void sendPincode(const std::string &pincode)
NewPincodeListener newPincodeListener
virtual void scheduleDelete()
Definition: window.cpp:826
void focusWindow()
Definition: client.cpp:807
NewPincodeRetryListener newPincodeRetryListener
PincodeManager pincodeManager
PincodeListener pincodeListener
void clearDialog(const PincodeDialog *const PincodeDialog)
std::string mOldPincode
std::string mNewPincode
PincodeStateT mState
const BeingId BeingId_zero
Definition: beingid.h:29
ChangePincodeListener changePincodeListener
Net::CharServerHandler * charServerHandler
Definition: net.cpp:81