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="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
 
virtual ~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=0, int offsetY=0)
 
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=0, const int offsetY=0)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w=0, int h=0)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w=1, const int h=1)
 
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)
 
virtual ~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)
 
virtual ~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)
 
virtual ~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=255U) 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=0) const
 
bool getOptionBool (const std::string &name, const bool def=false) 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 46 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 63 of file logindialog.cpp.

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(), ServerCommandType::str, ServerInfo::updateHosts, LoginData::updateType, and Visible_false.

65  :
66  // TRANSLATORS: login dialog name
67  Window(_("Login"), Modal_false, nullptr, "login.xml"),
69  KeyListener(),
70  mLoginData(&data),
71  mServer(server),
74  // TRANSLATORS: login dialog label
75  mKeepCheck(new CheckBox(this, _("Remember username"),
77  // TRANSLATORS: login dialog label
78  mUpdateTypeLabel(new Label(this, _("Update:"))),
81  // TRANSLATORS: login dialog button
82  mServerButton(new Button(this, _("Change Server"), "server", this)),
83  // TRANSLATORS: login dialog button
84  mLoginButton(new Button(this, _("Login"), "login", this)),
85  // TRANSLATORS: login dialog button
86  mRegisterButton(new Button(this, _("Register"), "register", this)),
87  // TRANSLATORS: login dialog checkbox
88  mCustomUpdateHost(new CheckBox(this, _("Custom update host"),
90  this, "customhost")),
92  "customUpdateHost", ""))),
93  mUpdateListModel(nullptr),
94  mUpdateHostDropDown(nullptr),
95  mUpdateHost(updateHost),
96  mServerName(server->hostname)
97 {
98  setCloseButton(true);
99  setWindowName("Login");
100 
101  if (charServerHandler != nullptr)
103 
105 
106  // TRANSLATORS: login dialog label
107  Label *const serverLabel1 = new Label(this, _("Server:"));
108  Label *const serverLabel2 = new Label(this, mServerName);
109  serverLabel2->adjustSize();
110  // TRANSLATORS: login dialog label
111  Label *const userLabel = new Label(this, _("Name:"));
112  // TRANSLATORS: login dialog label
113  Label *const passLabel = new Label(this, _("Password:"));
114  if (mServer->updateHosts.size() > 1)
115  {
118  false, Modal_false, this, "updateselect");
119  const std::string str = serverConfig.getValue("updateHost2", "");
120  if (!str.empty())
122  }
123  else
124  {
125  mUpdateListModel = nullptr;
126  mUpdateHostDropDown = nullptr;
127  }
129 
130  if (mPassField->getText().empty() &&
132  {
134  }
135 
136  mUpdateTypeDropDown->setActionEventId("updatetype");
139 
142 
143  mUserField->setActionEventId("login");
144  mPassField->setActionEventId("login");
145 
146  mUserField->addKeyListener(this);
147  mPassField->addKeyListener(this);
150 
151  place(0, 0, serverLabel1);
152  place(1, 0, serverLabel2, 8);
153  place(0, 1, userLabel);
154  place(1, 1, mUserField, 8);
155  place(0, 2, passLabel);
156  place(1, 2, mPassField, 8);
157  place(0, 6, mUpdateTypeLabel, 1);
158  place(1, 6, mUpdateTypeDropDown, 8);
159  int n = 7;
160  if (mUpdateHostDropDown != nullptr)
161  {
162  place(0, 7, mUpdateHostDropDown, 9);
163  n += 1;
164  }
165  place(0, n, mCustomUpdateHost, 9);
166  place(0, n + 1, mUpdateHostText, 9);
167  place(0, n + 2, mKeepCheck, 9);
169  place(2, n + 3, mServerButton);
170  place(3, n + 3, mLoginButton);
171 
172  addKeyListener(this);
173 }
#define _(s)
Definition: gettext.h:34
std::string * mUpdateHost
Definition: logindialog.h:109
void adjustSize()
Definition: textfield.cpp:712
std::string hostname
Definition: serverinfo.h:44
TextField * mPassField
Definition: logindialog.h:96
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void setVisible(Visible visible)
Definition: widget.cpp:224
UpdateListModel * mUpdateListModel
Definition: logindialog.h:106
CheckBox * mKeepCheck
Definition: logindialog.h:97
CheckBox * mCustomUpdateHost
Definition: logindialog.h:104
Definition: button.h:94
Button * mServerButton
Definition: logindialog.h:101
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
TextField * mUpdateHostText
Definition: logindialog.h:105
Configuration serverConfig
LoginData * mLoginData
Definition: logindialog.h:92
virtual void clear() const =0
Label * mUpdateTypeLabel
Definition: logindialog.h:98
void setText(const std::string &text)
Definition: textfield.cpp:799
void setSelectedString(const std::string &str)
Definition: dropdown.cpp:441
Button * mLoginButton
Definition: logindialog.h:102
DropDown * mUpdateHostDropDown
Definition: logindialog.h:107
#define CAST_S32
Definition: cast.h:29
const bool Visible_false
Definition: visible.h:29
Definition: label.h:87
LayoutCell & place(const int x, const int y, Widget *const wg, const int w=1, const int h=1)
Definition: window.cpp:1372
Button * mRegisterButton
Definition: logindialog.h:103
void mergeUpdateHosts()
std::string username
Definition: logindata.h:58
std::vector< HostsGroup > updateHosts
Definition: serverinfo.h:53
DropDown * mUpdateTypeDropDown
Definition: logindialog.h:100
TextField * mUserField
Definition: logindialog.h:95
void setCloseButton(const bool flag)
Definition: window.cpp:737
static std::string savedPassword
Definition: logindialog.h:79
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
UpdateTypeT updateType
Definition: logindata.h:64
std::string getValue(const std::string &key, const std::string &deflt) const
std::string password
Definition: logindata.h:59
ServerInfo * mServer
Definition: logindialog.h:93
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
LayoutCell & setHAlign(const Alignment a)
Definition: layoutcell.h:77
bool remember
Definition: logindata.h:73
bool isSelected() const
Definition: checkbox.h:146
std::string mServerName
Definition: logindialog.h:110
Net::CharServerHandler * charServerHandler
Definition: net.cpp:79
void setSelected(int selected)
Definition: dropdown.cpp:510
void adjustSize()
Definition: label.cpp:192
const std::string & getText() const
Definition: textfield.h:225
UpdateTypeModel * mUpdateTypeModel
Definition: logindialog.h:99
void setWindowName(const std::string &name)
Definition: window.h:353

◆ ~LoginDialog()

LoginDialog::~LoginDialog ( )

Definition at line 212 of file logindialog.cpp.

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

213 {
214  if (mUpdateTypeDropDown != nullptr)
216  if (mUpdateHostDropDown != nullptr)
218 
221 }
UpdateListModel * mUpdateListModel
Definition: logindialog.h:106
#define delete2(var)
Definition: delete2.h:24
DropDown * mUpdateHostDropDown
Definition: logindialog.h:107
DropDown * mUpdateTypeDropDown
Definition: logindialog.h:100
void hideDrop(bool event=true)
Definition: dropdown.cpp:374
UpdateTypeModel * mUpdateTypeModel
Definition: logindialog.h:99

Member Function Documentation

◆ action()

void LoginDialog::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 223 of file logindialog.cpp.

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().

224 {
225  const std::string &eventId = event.getId();
226  if (eventId == "login" && canSubmit())
227  {
228  prepareUpdate();
229  mLoginData->registerLogin = false;
231  }
232  else if (eventId == "server")
233  {
234  close();
235  }
236  else if (eventId == "register")
237  {
239  {
240  prepareUpdate();
242  }
243  else if (!mLoginData->registerUrl.empty())
244  {
245  const std::string &url = mLoginData->registerUrl;
246  urlListener.url = url;
248  // TRANSLATORS: question dialog
249  _("Open register url"),
250  url,
252  false,
253  Modal_true);
254  confirmDlg->addActionListener(&urlListener);
255  }
256  }
257  else if (eventId == "customhost")
258  {
261  }
262  else if (eventId == "updateselect")
263  {
266  }
267 }
#define _(s)
Definition: gettext.h:34
std::string registerUrl
Definition: logindata.h:68
void setState(const StateT state)
Definition: client.h:65
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void setVisible(Visible visible)
Definition: widget.cpp:224
bool registerLogin
Definition: logindata.h:74
CheckBox * mCustomUpdateHost
Definition: logindialog.h:104
static const std::string SOUND_REQUEST
Definition: sound.h:28
Client * client
Definition: client.cpp:113
TextField * mUpdateHostText
Definition: logindialog.h:105
LoginData * mLoginData
Definition: logindialog.h:92
std::string url
const bool Visible_false
Definition: visible.h:29
Net::LoginHandler * loginHandler
Definition: net.cpp:83
#define fromBool(val, name)
Definition: booldefines.h:48
virtual bool isRegistrationEnabled() const =0
void prepareUpdate()
bool canSubmit() const
bool Visible
Definition: visible.h:29
ConfirmDialog * confirmDlg
Definition: traderecv.cpp:46
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
void setSelected(const bool selected)
Definition: checkbox.h:155
bool isSelected() const
Definition: checkbox.h:146
bool url(InputEvent &event)
Definition: commands.cpp:63

◆ 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 297 of file logindialog.cpp.

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

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

298 {
299  return !mUserField->getText().empty() &&
300  !mPassField->getText().empty() &&
302 }
TextField * mPassField
Definition: logindialog.h:96
Client * client
Definition: client.cpp:113
TextField * mUserField
Definition: logindialog.h:95
StateT getState() const
Definition: client.h:68
const std::string & getText() const
Definition: textfield.h:225

◆ 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 384 of file logindialog.cpp.

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

Referenced by action().

385 {
387  Window::close();
388 }
void setState(const StateT state)
Definition: client.h:65
Client * client
Definition: client.cpp:113
virtual void close()
Definition: window.cpp:890

◆ 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 269 of file logindialog.cpp.

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

270 {
271  if (event.isConsumed())
272  {
274  return;
275  }
276 
277  const InputActionT actionId = event.getActionId();
278  if (actionId == InputAction::GUI_CANCEL)
279  {
281  }
282 #ifdef USE_SDL2
283  else if (actionId == InputAction::GUI_SELECT2)
284 #else // USE_SDL2
285  else if (actionId == InputAction::GUI_SELECT ||
286  actionId == InputAction::GUI_SELECT2)
287 #endif // USE_SDL2
288  {
290  }
291  else
292  {
294  }
295 }
Button * mServerButton
Definition: logindialog.h:101
const std::string & getActionEventId() const
Definition: widget.h:604
Button * mLoginButton
Definition: logindialog.h:102
InputAction ::T InputActionT
Definition: inputaction.h:714
void action(const ActionEvent &event)
bool isConsumed() const
void setEnabled(const bool enabled)
Definition: widget.h:351
bool canSubmit() const

◆ mergeUpdateHosts()

void LoginDialog::mergeUpdateHosts ( )
private

Definition at line 390 of file logindialog.cpp.

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

Referenced by LoginDialog().

391 {
392  HostsGroup group;
393 
394  group.name = mServer->defaultHostName;
395  if (group.name.empty())
396  {
397  // TRANSLATORS: update hosts group default name
398  group.name = _("default updates");
399  }
400  group.hosts = mLoginData->updateHosts;
401  mServer->updateHosts.insert(mServer->updateHosts.begin(), group);
402 }
std::string defaultHostName
Definition: serverinfo.h:51
#define _(s)
Definition: gettext.h:34
StringVect hosts
Definition: hostsgroup.h:39
StringVect updateHosts
Definition: logindata.h:62
LoginData * mLoginData
Definition: logindialog.h:92
std::string name
Definition: hostsgroup.h:38
std::vector< HostsGroup > updateHosts
Definition: serverinfo.h:53
ServerInfo * mServer
Definition: logindialog.h:93

◆ postInit()

void LoginDialog::postInit ( )
virtual

Reimplemented from Window.

Definition at line 175 of file logindialog.cpp.

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(), Window::setContentSize(), Window::setDefaultSize(), Widget::setEnabled(), Window::setVisible(), ImagePosition::UPPER_CENTER, and Visible_true.

176 {
179 
180  const int h = 200;
181  if (mUpdateHostDropDown != nullptr)
182  setContentSize(310, 250);
183  setContentSize(310, h);
184 #ifdef ANDROID
186 #else // ANDROID
187 
188  setDefaultSize(310, h, ImagePosition::CENTER, 0, 0);
189 #endif // ANDROID
190 
191  center();
192  loadWindowState();
193  reflowLayout();
194 
195  if (mUserField->getText().empty())
197  else
199 
201  if (loginHandler != nullptr)
202  {
204  || !mLoginData->registerUrl.empty());
205  }
206  else
207  {
208  mRegisterButton->setEnabled(false);
209  }
210 }
void setDefaultSize()
Definition: window.cpp:1186
std::string registerUrl
Definition: logindata.h:68
const bool Visible_true
Definition: visible.h:29
void loadWindowState()
Definition: window.cpp:1075
TextField * mPassField
Definition: logindialog.h:96
LoginData * mLoginData
Definition: logindialog.h:92
void reflowLayout(int w=0, int h=0)
Definition: window.cpp:1384
void setContentSize(int width, int height)
Definition: window.cpp:484
Button * mLoginButton
Definition: logindialog.h:102
DropDown * mUpdateHostDropDown
Definition: logindialog.h:107
virtual void requestFocus()
Definition: widget.cpp:203
Net::LoginHandler * loginHandler
Definition: net.cpp:83
virtual bool isRegistrationEnabled() const =0
Button * mRegisterButton
Definition: logindialog.h:103
TextField * mUserField
Definition: logindialog.h:95
void setEnabled(const bool enabled)
Definition: widget.h:351
bool canSubmit() const
virtual void setVisible(Visible visible)
Definition: window.cpp:766
void center()
Definition: window.cpp:1405
const std::string & getText() const
Definition: textfield.h:225
void postInit()
Definition: window.cpp:241

◆ prepareUpdate()

void LoginDialog::prepareUpdate ( )
private

Definition at line 304 of file logindialog.cpp.

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, ServerCommandType::str, LoginData::updateHost, ServerInfo::updateHosts, LoginData::updateHosts, LoginData::updateType, and LoginData::username.

Referenced by action().

305 {
309  UpdateTypeT updateType = static_cast<UpdateTypeT>(
311 
313  && !mUpdateHostText->getText().empty())
314  {
315  updateType = static_cast<UpdateTypeT>(
316  updateType | UpdateType::Custom);
317  serverConfig.setValue("customUpdateHost",
319 
321  {
324  }
325  else
326  {
327  mLoginData->updateHost.clear();
328  (*mUpdateHost).clear();
329  }
330  }
331  else
332  {
333  std::string str;
334  if (mUpdateHostDropDown != nullptr)
335  {
336  const int sel = mUpdateHostDropDown->getSelected();
337  if (sel >= 0)
338  {
339  const HostsGroup &group = mServer->updateHosts[sel];
340  if (!group.hosts.empty())
341  {
342  str = group.hosts[0];
343  mLoginData->updateHosts = group.hosts;
344  serverConfig.setValue("updateHost2", group.name);
345  }
346  else
347  {
348  serverConfig.setValue("updateHost2", "");
349  }
350  }
351  }
352  else if (mLoginData->updateHost.empty()
353  && !mLoginData->updateHosts.empty())
354  {
355  str = mLoginData->updateHosts[0];
356  serverConfig.setValue("updateHost2", str);
357  }
358  if (!str.empty() && checkPath(str))
359  {
361  *mUpdateHost = STD_MOVE(str);
362  }
363  else
364  {
365  mLoginData->updateHost.clear();
366  (*mUpdateHost).clear();
367  }
368  }
369 
370  mLoginData->updateType = updateType;
371  serverConfig.setValue("updateType", CAST_S32(updateType));
372 
373  mRegisterButton->setEnabled(false);
374  mServerButton->setEnabled(false);
375  mLoginButton->setEnabled(false);
376 
378  if (mLoginData->remember)
380  else
382 }
std::string * mUpdateHost
Definition: logindialog.h:109
TextField * mPassField
Definition: logindialog.h:96
CheckBox * mKeepCheck
Definition: logindialog.h:97
CheckBox * mCustomUpdateHost
Definition: logindialog.h:104
Button * mServerButton
Definition: logindialog.h:101
bool checkPath(const std::string &path)
Definition: paths.cpp:102
StringVect hosts
Definition: hostsgroup.h:39
TextField * mUpdateHostText
Definition: logindialog.h:105
Configuration serverConfig
StringVect updateHosts
Definition: logindata.h:62
LoginData * mLoginData
Definition: logindialog.h:92
Button * mLoginButton
Definition: logindialog.h:102
DropDown * mUpdateHostDropDown
Definition: logindialog.h:107
std::string updateHost
Definition: logindata.h:61
#define CAST_S32
Definition: cast.h:29
std::string name
Definition: hostsgroup.h:38
Button * mRegisterButton
Definition: logindialog.h:103
std::string username
Definition: logindata.h:58
std::vector< HostsGroup > updateHosts
Definition: serverinfo.h:53
DropDown * mUpdateTypeDropDown
Definition: logindialog.h:100
TextField * mUserField
Definition: logindialog.h:95
static std::string savedPassword
Definition: logindialog.h:79
void setEnabled(const bool enabled)
Definition: widget.h:351
#define STD_MOVE(var)
Definition: stdmove.h:27
UpdateTypeT updateType
Definition: logindata.h:64
std::string password
Definition: logindata.h:59
ServerInfo * mServer
Definition: logindialog.h:93
UpdateType ::T UpdateTypeT
Definition: updatetype.h:35
bool remember
Definition: logindata.h:73
bool isSelected() const
Definition: checkbox.h:146
std::string mServerName
Definition: logindialog.h:110
void setValue(const std::string &key, const std::string &value)
const std::string & getText() const
Definition: textfield.h:225
int getSelected() const
Definition: dropdown.cpp:505
static std::string savedPasswordKey
Definition: logindialog.h:78

Field Documentation

◆ mCustomUpdateHost

CheckBox* LoginDialog::mCustomUpdateHost
private

Definition at line 104 of file logindialog.h.

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

◆ mKeepCheck

CheckBox* LoginDialog::mKeepCheck
private

Definition at line 97 of file logindialog.h.

Referenced by LoginDialog(), and prepareUpdate().

◆ mLoginButton

Button* LoginDialog::mLoginButton
private

Definition at line 102 of file logindialog.h.

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

◆ mLoginData

LoginData* LoginDialog::mLoginData
private

Definition at line 92 of file logindialog.h.

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

◆ mPassField

TextField* LoginDialog::mPassField
private

Definition at line 96 of file logindialog.h.

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

◆ mRegisterButton

Button* LoginDialog::mRegisterButton
private

Definition at line 103 of file logindialog.h.

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

◆ mServer

ServerInfo* LoginDialog::mServer
private

Definition at line 93 of file logindialog.h.

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

◆ mServerButton

Button* LoginDialog::mServerButton
private

Definition at line 101 of file logindialog.h.

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

◆ mServerName

std::string LoginDialog::mServerName
private

Definition at line 110 of file logindialog.h.

Referenced by LoginDialog(), and prepareUpdate().

◆ mUpdateHost

std::string* LoginDialog::mUpdateHost
private

Definition at line 109 of file logindialog.h.

Referenced by prepareUpdate().

◆ mUpdateHostDropDown

DropDown* LoginDialog::mUpdateHostDropDown
private

Definition at line 107 of file logindialog.h.

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

◆ mUpdateHostText

TextField* LoginDialog::mUpdateHostText
private

Definition at line 105 of file logindialog.h.

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

◆ mUpdateListModel

UpdateListModel* LoginDialog::mUpdateListModel
private

Definition at line 106 of file logindialog.h.

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

◆ mUpdateTypeDropDown

DropDown* LoginDialog::mUpdateTypeDropDown
private

Definition at line 100 of file logindialog.h.

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

◆ mUpdateTypeLabel

Label* LoginDialog::mUpdateTypeLabel
private

Definition at line 98 of file logindialog.h.

Referenced by LoginDialog().

◆ mUpdateTypeModel

UpdateTypeModel* LoginDialog::mUpdateTypeModel
private

Definition at line 99 of file logindialog.h.

Referenced by ~LoginDialog().

◆ mUserField

TextField* LoginDialog::mUserField
private

Definition at line 95 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 78 of file logindialog.h.

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


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