ManaPlus
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes

#include <logindialog.h>

Inheritance diagram for LoginDialog:
Window ActionListener KeyListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 LoginDialog (LoginData &data, ServerInfo *const server, std::string *const updateHost)
 
 ~LoginDialog ()
 
void postInit ()
 
void action (const ActionEvent &event)
 
void keyPressed (KeyEvent &event)
 
void close ()
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX, int offsetY)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
virtual void setVisible (Visible visible)
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
void setModal (const Modal modal)
 
Rect getWindowArea () const
 
bool isResizeAllowed (const MouseEvent &event) const
 
void setCaptionFont (Font *font)
 
void enableVisibleSound (bool b)
 
bool isWindowVisible () const
 
void setPadding (int padding)
 
int getPadding () const
 
void setTitleBarHeight (unsigned int height)
 
unsigned int getTitleBarHeight () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void setMovable (Move movable)
 
bool isMovable () const
 
Rect getChildrenArea ()
 
virtual void resizeToContent ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 

Static Public Attributes

static std::string savedPasswordKey
 
static std::string savedPassword
 

Private Member Functions

bool canSubmit () const
 
void prepareUpdate ()
 
void mergeUpdateHosts ()
 

Private Attributes

LoginDatamLoginData
 
ServerInfomServer
 
TextFieldmUserField
 
TextFieldmPassField
 
CheckBoxmKeepCheck
 
LabelmUpdateTypeLabel
 
UpdateTypeModelmUpdateTypeModel
 
DropDownmUpdateTypeDropDown
 
ButtonmServerButton
 
ButtonmLoginButton
 
ButtonmRegisterButton
 
CheckBoxmCustomUpdateHost
 
TextFieldmUpdateHostText
 
UpdateListModelmUpdateListModel
 
DropDownmUpdateHostDropDown
 
std::string * mUpdateHost
 
std::string mServerName
 

Additional Inherited Members

- Static Public Member Functions inherited from Window
static void setWindowContainer (WindowContainer *const windowContainer)
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

The login dialog.

Definition at line 47 of file logindialog.h.

Constructor & Destructor Documentation

◆ LoginDialog()

LoginDialog::LoginDialog ( LoginData data,
ServerInfo *const  server,
std::string *const  updateHost 
)

Constructor

See also
Window::Window

Definition at line 66 of file logindialog.cpp.

68  :
69  // TRANSLATORS: login dialog name
70  Window(_("Login"), Modal_false, nullptr, "login.xml"),
72  KeyListener(),
73  mLoginData(&data),
74  mServer(server),
76  LoseFocusOnTab_true, nullptr, std::string(), false)),
78 #ifdef SAVE_PASSWORD
79  // TRANSLATORS: login dialog label
80  mKeepCheck(new CheckBox(this, _("Remember user and password"),
81 #else
82  // TRANSLATORS: login dialog label
83  mKeepCheck(new CheckBox(this, _("Remember username"),
84 #endif
85  mLoginData->remember, nullptr, std::string())),
86  // TRANSLATORS: login dialog label
87  mUpdateTypeLabel(new Label(this, _("Update:"))),
90  false, Modal_false, nullptr, std::string())),
91  // TRANSLATORS: login dialog button
92  mServerButton(new Button(this, _("Change Server"), "server",
93  BUTTON_SKIN, this)),
94  // TRANSLATORS: login dialog button
95  mLoginButton(new Button(this, _("Login"), "login",
96  BUTTON_SKIN, this)),
97  // TRANSLATORS: login dialog button
98  mRegisterButton(new Button(this, _("Register"), "register",
99  BUTTON_SKIN, this)),
100  // TRANSLATORS: login dialog checkbox
101  mCustomUpdateHost(new CheckBox(this, _("Custom update host"),
103  this, "customhost")),
105  "customUpdateHost", ""),
106  LoseFocusOnTab_true, nullptr, std::string(), false)),
107  mUpdateListModel(nullptr),
108  mUpdateHostDropDown(nullptr),
109  mUpdateHost(updateHost),
110  mServerName(server->hostname)
111 {
112  setCloseButton(true);
113  setWindowName("Login");
114 
115  if (charServerHandler != nullptr)
116  charServerHandler->clear();
117 
118  mergeUpdateHosts();
119 
120  // TRANSLATORS: login dialog label
121  Label *const serverLabel1 = new Label(this, _("Server:"));
122  Label *const serverLabel2 = new Label(this, mServerName);
123  serverLabel2->adjustSize();
124  // TRANSLATORS: login dialog label
125  Label *const userLabel = new Label(this, _("Name:"));
126  // TRANSLATORS: login dialog label
127  Label *const passLabel = new Label(this, _("Password:"));
128  if (mServer->updateHosts.size() > 1)
129  {
130  mUpdateListModel = new UpdateListModel(mServer);
131  mUpdateHostDropDown = new DropDown(this, mUpdateListModel,
132  false, Modal_false, this, "updateselect");
133  const std::string str = serverConfig.getValue("updateHost2", "");
134  if (!str.empty())
135  mUpdateHostDropDown->setSelectedString(str);
136  }
137  else
138  {
139  mUpdateListModel = nullptr;
140  mUpdateHostDropDown = nullptr;
141  }
143 
144  if (mPassField->getText().empty() &&
146  {
147  mPassField->setText(LoginDialog::savedPassword);
148  }
149 
150  mUpdateTypeDropDown->setActionEventId("updatetype");
153 
156 
157  mUserField->setActionEventId("login");
158  mPassField->setActionEventId("login");
159 
160  mUserField->addKeyListener(this);
161  mPassField->addKeyListener(this);
164 
165  place(0, 0, serverLabel1, 1, 1);
166  place(1, 0, serverLabel2, 8, 1);
167  place(0, 1, userLabel, 1, 1);
168  place(1, 1, mUserField, 8, 1);
169  place(0, 2, passLabel, 1, 1);
170  place(1, 2, mPassField, 8, 1);
171  place(0, 6, mUpdateTypeLabel, 1, 1);
172  place(1, 6, mUpdateTypeDropDown, 8, 1);
173  int n = 7;
174  if (mUpdateHostDropDown != nullptr)
175  {
176  place(0, 7, mUpdateHostDropDown, 9, 1);
177  n += 1;
178  }
179  place(0, n, mCustomUpdateHost, 9, 1);
180  place(0, n + 1, mUpdateHostText, 9, 1);
181  place(0, n + 2, mKeepCheck, 9, 1);
183  place(2, n + 3, mServerButton, 1, 1);
184  place(3, n + 3, mLoginButton, 1, 1);
185 
186  addKeyListener(this);
187 }
const std::string BUTTON_SKIN
Definition: button.h:89
#define CAST_S32
Definition: cast.h:30
Definition: button.h:102
bool isSelected() const
Definition: checkbox.h:147
std::string getValue(const std::string &key, const std::string &deflt) const
void setSelected(int selected)
Definition: dropdown.cpp:514
Definition: label.h:91
LayoutCell & setHAlign(const Alignment a)
Definition: layoutcell.h:84
std::string username
Definition: logindata.h:59
std::string password
Definition: logindata.h:60
UpdateTypeT updateType
Definition: logindata.h:65
bool remember
Definition: logindata.h:74
Button * mLoginButton
Definition: logindialog.h:103
TextField * mPassField
Definition: logindialog.h:97
UpdateListModel * mUpdateListModel
Definition: logindialog.h:107
static std::string savedPassword
Definition: logindialog.h:80
ServerInfo * mServer
Definition: logindialog.h:94
std::string * mUpdateHost
Definition: logindialog.h:110
Button * mServerButton
Definition: logindialog.h:102
TextField * mUserField
Definition: logindialog.h:96
LoginData * mLoginData
Definition: logindialog.h:93
std::string mServerName
Definition: logindialog.h:111
CheckBox * mCustomUpdateHost
Definition: logindialog.h:105
TextField * mUpdateHostText
Definition: logindialog.h:106
CheckBox * mKeepCheck
Definition: logindialog.h:98
Label * mUpdateTypeLabel
Definition: logindialog.h:99
Button * mRegisterButton
Definition: logindialog.h:104
UpdateTypeModel * mUpdateTypeModel
Definition: logindialog.h:100
DropDown * mUpdateHostDropDown
Definition: logindialog.h:108
DropDown * mUpdateTypeDropDown
Definition: logindialog.h:101
std::string hostname
Definition: serverinfo.h:45
const std::string & getText() const
Definition: textfield.h:224
void adjustSize()
Definition: textfield.cpp:716
void setVisible(Visible visible)
Definition: widget.cpp:225
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:109
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1384
Configuration serverConfig
#define _(s)
Definition: gettext.h:35
if(!vert) return
const bool LoseFocusOnTab_true
uint32_t data
const bool Modal_false
Definition: modal.h:30
const bool Visible_false
Definition: visible.h:30

References _, Widget::addActionListener(), Widget::addKeyListener(), Label::adjustSize(), TextField::adjustSize(), CAST_S32, charServerHandler, Net::CharServerHandler::clear(), UpdateType::Custom, TextField::getText(), ConfigurationObject::getValue(), CheckBox::isSelected(), LayoutCell::LEFT, mCustomUpdateHost, mergeUpdateHosts(), mKeepCheck, mLoginButton, mLoginData, Modal_false, mPassField, mRegisterButton, mServer, mServerButton, mServerName, mUpdateHostDropDown, mUpdateHostText, mUpdateListModel, mUpdateTypeDropDown, mUpdateTypeLabel, mUserField, Window::place(), savedPassword, serverConfig, Widget::setActionEventId(), Window::setCloseButton(), LayoutCell::setHAlign(), DropDown::setSelected(), DropDown::setSelectedString(), TextField::setText(), Widget::setVisible(), Window::setWindowName(), ServerInfo::updateHosts, LoginData::updateType, and Visible_false.

◆ ~LoginDialog()

LoginDialog::~LoginDialog ( )

Definition at line 230 of file logindialog.cpp.

231 {
232  if (mUpdateTypeDropDown != nullptr)
234  if (mUpdateHostDropDown != nullptr)
236 
239 }
void hideDrop(bool event)
Definition: dropdown.cpp:378
#define delete2(var)
Definition: delete2.h:25

References delete2, DropDown::hideDrop(), mUpdateHostDropDown, mUpdateListModel, mUpdateTypeDropDown, and mUpdateTypeModel.

Member Function Documentation

◆ action()

void LoginDialog::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 241 of file logindialog.cpp.

242 {
243  const std::string &eventId = event.getId();
244  if (eventId == "login" && canSubmit())
245  {
246  prepareUpdate();
247  mLoginData->registerLogin = false;
249  }
250  else if (eventId == "server")
251  {
252  close();
253  }
254  else if (eventId == "register")
255  {
257  {
258  prepareUpdate();
260  }
261  else if (!mLoginData->registerUrl.empty())
262  {
263  const std::string &url = mLoginData->registerUrl;
264  urlListener.url = url;
266  // TRANSLATORS: question dialog
267  _("Open register url"),
268  url,
270  false,
271  Modal_true,
272  nullptr);
274  }
275  }
276  else if (eventId == "customhost")
277  {
280  }
281  else if (eventId == "updateselect")
282  {
285  }
286 }
#define fromBool(val, name)
Definition: booldefines.h:49
void setSelected(const bool selected)
Definition: checkbox.h:156
void setState(const StateT state)
Definition: client.h:66
std::string registerUrl
Definition: logindata.h:69
bool registerLogin
Definition: logindata.h:75
bool canSubmit() const
void prepareUpdate()
virtual bool isRegistrationEnabled() const =0
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
Client * client
Definition: client.cpp:118
Net::LoginHandler * loginHandler
Definition: net.cpp:90
const bool Modal_true
Definition: modal.h:30
bool url(InputEvent &event)
Definition: commands.cpp:64
@ REGISTER_PREP
Definition: state.h:53
@ LOGIN_ATTEMPT
Definition: state.h:41
ConfirmDialog * confirmDlg
Definition: traderecv.cpp:49
static const std::string SOUND_REQUEST
Definition: sound.h:29
std::string url
bool Visible
Definition: visible.h:30

References _, Widget::addActionListener(), canSubmit(), client, close(), confirmDlg, CREATEWIDGETR, fromBool, Net::LoginHandler::isRegistrationEnabled(), CheckBox::isSelected(), State::LOGIN_ATTEMPT, loginHandler, mCustomUpdateHost, mLoginData, Modal_true, mUpdateHostText, prepareUpdate(), State::REGISTER_PREP, LoginData::registerLogin, LoginData::registerUrl, CheckBox::setSelected(), Client::setState(), Widget::setVisible(), SOUND_REQUEST, OpenUrlListener::url, Actions::url(), anonymous_namespace{logindialog.cpp}::urlListener, and Visible_false.

Referenced by keyPressed().

◆ canSubmit()

bool LoginDialog::canSubmit ( ) const
private

Returns whether submit can be enabled. This is true in the login state, when all necessary fields have some text.

Definition at line 316 of file logindialog.cpp.

317 {
318  return !mUserField->getText().empty() &&
319  !mPassField->getText().empty() &&
321 }
StateT getState() const
Definition: client.h:69
@ LOGIN
Definition: state.h:40

References client, Client::getState(), TextField::getText(), State::LOGIN, mPassField, and mUserField.

Referenced by action(), keyPressed(), and postInit().

◆ close()

void LoginDialog::close ( )
virtual

Overrideable functionality for when the window is to close. This allows for class implementations to clean up or do certain actions on window close they couldn't do otherwise.

Reimplemented from Window.

Definition at line 403 of file logindialog.cpp.

404 {
406  Window::close();
407 }
virtual void close()
Definition: window.cpp:902
@ SWITCH_SERVER
Definition: state.h:62

References client, Window::close(), Client::setState(), and State::SWITCH_SERVER.

Referenced by action().

◆ keyPressed()

void LoginDialog::keyPressed ( KeyEvent event)
virtual

Called when a key is pressed in one of the text fields.

Reimplemented from KeyListener.

Definition at line 288 of file logindialog.cpp.

289 {
290  if (event.isConsumed())
291  {
293  return;
294  }
295 
296  const InputActionT actionId = event.getActionId();
297  if (actionId == InputAction::GUI_CANCEL)
298  {
300  }
301 #ifdef USE_SDL2
302  else if (actionId == InputAction::GUI_SELECT2)
303 #else // USE_SDL2
304  else if (actionId == InputAction::GUI_SELECT ||
305  actionId == InputAction::GUI_SELECT2)
306 #endif // USE_SDL2
307  {
309  }
310  else
311  {
313  }
314 }
bool isConsumed() const
void action(const ActionEvent &event)
void setEnabled(const bool enabled)
Definition: widget.h:352
const std::string & getActionEventId() const
Definition: widget.h:605
InputAction ::T InputActionT
Definition: inputaction.h:717

References action(), canSubmit(), Widget::getActionEventId(), InputAction::GUI_CANCEL, InputAction::GUI_SELECT, InputAction::GUI_SELECT2, InputGuiEvent::isConsumed(), mLoginButton, mServerButton, and Widget::setEnabled().

◆ mergeUpdateHosts()

void LoginDialog::mergeUpdateHosts ( )
private

Definition at line 409 of file logindialog.cpp.

410 {
411  HostsGroup group;
412 
413  group.name = mServer->defaultHostName;
414  if (group.name.empty())
415  {
416  // TRANSLATORS: update hosts group default name
417  group.name = _("default updates");
418  }
419  group.hosts = mLoginData->updateHosts;
420  mServer->updateHosts.insert(mServer->updateHosts.begin(), group);
421 }
StringVect updateHosts
Definition: logindata.h:63
std::vector< HostsGroup > updateHosts
Definition: serverinfo.h:54
std::string defaultHostName
Definition: serverinfo.h:52
std::string name
Definition: hostsgroup.h:39
StringVect hosts
Definition: hostsgroup.h:40

References _, ServerInfo::defaultHostName, HostsGroup::hosts, mLoginData, mServer, HostsGroup::name, LoginData::updateHosts, and ServerInfo::updateHosts.

Referenced by LoginDialog().

◆ postInit()

void LoginDialog::postInit ( )
virtual

Reimplemented from Window.

Definition at line 189 of file logindialog.cpp.

190 {
193 
194  const int h = 200;
195  if (mUpdateHostDropDown != nullptr)
196  setContentSize(310, 250);
197  setContentSize(310, h);
198 #ifdef ANDROID
200 #else // ANDROID
201 
202  setDefaultSize(310, h, ImagePosition::CENTER, 0, 0);
203 #endif // ANDROID
204 
205  center();
206  loadWindowState();
207  reflowLayout(0, 0);
208 
209 #ifdef SAVE_PASSWORD
211 #else
212  if (mUserField->getText().empty())
214  else
216 #endif
217 
219  if (loginHandler != nullptr)
220  {
222  || !mLoginData->registerUrl.empty());
223  }
224  else
225  {
226  mRegisterButton->setEnabled(false);
227  }
228 }
void setText(const std::string &text)
Definition: textfield.cpp:803
virtual void requestFocus()
Definition: widget.cpp:204
void center()
Definition: window.cpp:1417
virtual void setVisible(Visible visible)
Definition: window.cpp:778
void setContentSize(int width, int height)
Definition: window.cpp:492
void reflowLayout(int w, int h)
Definition: window.cpp:1396
void postInit()
Definition: window.cpp:249
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
const bool Visible_true
Definition: visible.h:30

References canSubmit(), ImagePosition::CENTER, Window::center(), TextField::getText(), Net::LoginHandler::isRegistrationEnabled(), Window::loadWindowState(), loginHandler, mLoginButton, mLoginData, mPassField, mRegisterButton, mUpdateHostDropDown, mUserField, Window::postInit(), Window::reflowLayout(), LoginData::registerUrl, Widget::requestFocus(), savedPassword, Window::setContentSize(), Window::setDefaultSize(), Widget::setEnabled(), TextField::setText(), Window::setVisible(), ImagePosition::UPPER_CENTER, and Visible_true.

◆ prepareUpdate()

void LoginDialog::prepareUpdate ( )
private

Definition at line 323 of file logindialog.cpp.

324 {
328  UpdateTypeT updateType = static_cast<UpdateTypeT>(
330 
332  && !mUpdateHostText->getText().empty())
333  {
334  updateType = static_cast<UpdateTypeT>(
335  updateType | UpdateType::Custom);
336  serverConfig.setValue("customUpdateHost",
338 
340  {
343  }
344  else
345  {
346  mLoginData->updateHost.clear();
347  (*mUpdateHost).clear();
348  }
349  }
350  else
351  {
352  std::string str;
353  if (mUpdateHostDropDown != nullptr)
354  {
355  const int sel = mUpdateHostDropDown->getSelected();
356  if (sel >= 0)
357  {
358  const HostsGroup &group = mServer->updateHosts[sel];
359  if (!group.hosts.empty())
360  {
361  str = group.hosts[0];
362  mLoginData->updateHosts = group.hosts;
363  serverConfig.setValue("updateHost2", group.name);
364  }
365  else
366  {
367  serverConfig.setValue("updateHost2", "");
368  }
369  }
370  }
371  else if (mLoginData->updateHost.empty()
372  && !mLoginData->updateHosts.empty())
373  {
374  str = mLoginData->updateHosts[0];
375  serverConfig.setValue("updateHost2", str);
376  }
377  if (!str.empty() && checkPath(str))
378  {
379  mLoginData->updateHost = str;
380  *mUpdateHost = STD_MOVE(str);
381  }
382  else
383  {
384  mLoginData->updateHost.clear();
385  (*mUpdateHost).clear();
386  }
387  }
388 
389  mLoginData->updateType = updateType;
390  serverConfig.setValue("updateType", CAST_S32(updateType));
391 
392  mRegisterButton->setEnabled(false);
393  mServerButton->setEnabled(false);
394  mLoginButton->setEnabled(false);
395 
397  if (mLoginData->remember)
399  else
401 }
void setValue(const std::string &key, const std::string &value)
int getSelected() const
Definition: dropdown.cpp:509
std::string updateHost
Definition: logindata.h:62
static std::string savedPasswordKey
Definition: logindialog.h:79
bool checkPath(const std::string &path)
Definition: paths.cpp:121
#define STD_MOVE(var)
Definition: stdmove.h:28
UpdateType ::T UpdateTypeT
Definition: updatetype.h:36

References CAST_S32, checkPath(), UpdateType::Custom, DropDown::getSelected(), TextField::getText(), HostsGroup::hosts, CheckBox::isSelected(), mCustomUpdateHost, mKeepCheck, mLoginButton, mLoginData, mPassField, mRegisterButton, mServer, mServerButton, mServerName, mUpdateHost, mUpdateHostDropDown, mUpdateHostText, mUpdateTypeDropDown, mUserField, HostsGroup::name, LoginData::password, LoginData::remember, savedPassword, savedPasswordKey, serverConfig, Widget::setEnabled(), Configuration::setValue(), STD_MOVE, LoginData::updateHost, LoginData::updateHosts, ServerInfo::updateHosts, LoginData::updateType, and LoginData::username.

Referenced by action().

Field Documentation

◆ mCustomUpdateHost

CheckBox* LoginDialog::mCustomUpdateHost
private

Definition at line 105 of file logindialog.h.

Referenced by action(), LoginDialog(), and prepareUpdate().

◆ mKeepCheck

CheckBox* LoginDialog::mKeepCheck
private

Definition at line 98 of file logindialog.h.

Referenced by LoginDialog(), and prepareUpdate().

◆ mLoginButton

Button* LoginDialog::mLoginButton
private

Definition at line 103 of file logindialog.h.

Referenced by keyPressed(), LoginDialog(), postInit(), and prepareUpdate().

◆ mLoginData

LoginData* LoginDialog::mLoginData
private

Definition at line 93 of file logindialog.h.

Referenced by action(), LoginDialog(), mergeUpdateHosts(), postInit(), and prepareUpdate().

◆ mPassField

TextField* LoginDialog::mPassField
private

Definition at line 97 of file logindialog.h.

Referenced by canSubmit(), LoginDialog(), postInit(), and prepareUpdate().

◆ mRegisterButton

Button* LoginDialog::mRegisterButton
private

Definition at line 104 of file logindialog.h.

Referenced by LoginDialog(), postInit(), and prepareUpdate().

◆ mServer

ServerInfo* LoginDialog::mServer
private

Definition at line 94 of file logindialog.h.

Referenced by LoginDialog(), mergeUpdateHosts(), and prepareUpdate().

◆ mServerButton

Button* LoginDialog::mServerButton
private

Definition at line 102 of file logindialog.h.

Referenced by keyPressed(), LoginDialog(), and prepareUpdate().

◆ mServerName

std::string LoginDialog::mServerName
private

Definition at line 111 of file logindialog.h.

Referenced by LoginDialog(), and prepareUpdate().

◆ mUpdateHost

std::string* LoginDialog::mUpdateHost
private

Definition at line 110 of file logindialog.h.

Referenced by prepareUpdate().

◆ mUpdateHostDropDown

DropDown* LoginDialog::mUpdateHostDropDown
private

Definition at line 108 of file logindialog.h.

Referenced by LoginDialog(), postInit(), prepareUpdate(), and ~LoginDialog().

◆ mUpdateHostText

TextField* LoginDialog::mUpdateHostText
private

Definition at line 106 of file logindialog.h.

Referenced by action(), LoginDialog(), and prepareUpdate().

◆ mUpdateListModel

UpdateListModel* LoginDialog::mUpdateListModel
private

Definition at line 107 of file logindialog.h.

Referenced by LoginDialog(), and ~LoginDialog().

◆ mUpdateTypeDropDown

DropDown* LoginDialog::mUpdateTypeDropDown
private

Definition at line 101 of file logindialog.h.

Referenced by LoginDialog(), prepareUpdate(), and ~LoginDialog().

◆ mUpdateTypeLabel

Label* LoginDialog::mUpdateTypeLabel
private

Definition at line 99 of file logindialog.h.

Referenced by LoginDialog().

◆ mUpdateTypeModel

UpdateTypeModel* LoginDialog::mUpdateTypeModel
private

Definition at line 100 of file logindialog.h.

Referenced by ~LoginDialog().

◆ mUserField

TextField* LoginDialog::mUserField
private

Definition at line 96 of file logindialog.h.

Referenced by canSubmit(), LoginDialog(), postInit(), and prepareUpdate().

◆ savedPassword

std::string LoginDialog::savedPassword
static

◆ savedPasswordKey

std::string LoginDialog::savedPasswordKey
static

Definition at line 79 of file logindialog.h.

Referenced by ServerDialog::connectToSelectedServer(), and prepareUpdate().


The documentation for this class was generated from the following files: