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 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 65 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.

67  :
68  // TRANSLATORS: login dialog name
69  Window(_("Login"), Modal_false, nullptr, "login.xml"),
71  KeyListener(),
72  mLoginData(&data),
73  mServer(server),
75  LoseFocusOnTab_true, nullptr, std::string(), false)),
77  // TRANSLATORS: login dialog label
78  mKeepCheck(new CheckBox(this, _("Remember username"),
79  mLoginData->remember, nullptr, std::string())),
80  // TRANSLATORS: login dialog label
81  mUpdateTypeLabel(new Label(this, _("Update:"))),
84  false, Modal_false, nullptr, std::string())),
85  // TRANSLATORS: login dialog button
86  mServerButton(new Button(this, _("Change Server"), "server",
87  BUTTON_SKIN, this)),
88  // TRANSLATORS: login dialog button
89  mLoginButton(new Button(this, _("Login"), "login",
90  BUTTON_SKIN, this)),
91  // TRANSLATORS: login dialog button
92  mRegisterButton(new Button(this, _("Register"), "register",
93  BUTTON_SKIN, this)),
94  // TRANSLATORS: login dialog checkbox
95  mCustomUpdateHost(new CheckBox(this, _("Custom update host"),
97  this, "customhost")),
99  "customUpdateHost", ""),
100  LoseFocusOnTab_true, nullptr, std::string(), false)),
101  mUpdateListModel(nullptr),
102  mUpdateHostDropDown(nullptr),
103  mUpdateHost(updateHost),
104  mServerName(server->hostname)
105 {
106  setCloseButton(true);
107  setWindowName("Login");
108 
109  if (charServerHandler != nullptr)
111 
113 
114  // TRANSLATORS: login dialog label
115  Label *const serverLabel1 = new Label(this, _("Server:"));
116  Label *const serverLabel2 = new Label(this, mServerName);
117  serverLabel2->adjustSize();
118  // TRANSLATORS: login dialog label
119  Label *const userLabel = new Label(this, _("Name:"));
120  // TRANSLATORS: login dialog label
121  Label *const passLabel = new Label(this, _("Password:"));
122  if (mServer->updateHosts.size() > 1)
123  {
126  false, Modal_false, this, "updateselect");
127  const std::string str = serverConfig.getValue("updateHost2", "");
128  if (!str.empty())
130  }
131  else
132  {
133  mUpdateListModel = nullptr;
134  mUpdateHostDropDown = nullptr;
135  }
137 
138  if (mPassField->getText().empty() &&
140  {
142  }
143 
144  mUpdateTypeDropDown->setActionEventId("updatetype");
147 
150 
151  mUserField->setActionEventId("login");
152  mPassField->setActionEventId("login");
153 
154  mUserField->addKeyListener(this);
155  mPassField->addKeyListener(this);
158 
159  place(0, 0, serverLabel1, 1, 1);
160  place(1, 0, serverLabel2, 8, 1);
161  place(0, 1, userLabel, 1, 1);
162  place(1, 1, mUserField, 8, 1);
163  place(0, 2, passLabel, 1, 1);
164  place(1, 2, mPassField, 8, 1);
165  place(0, 6, mUpdateTypeLabel, 1, 1);
166  place(1, 6, mUpdateTypeDropDown, 8, 1);
167  int n = 7;
168  if (mUpdateHostDropDown != nullptr)
169  {
170  place(0, 7, mUpdateHostDropDown, 9, 1);
171  n += 1;
172  }
173  place(0, n, mCustomUpdateHost, 9, 1);
174  place(0, n + 1, mUpdateHostText, 9, 1);
175  place(0, n + 2, mKeepCheck, 9, 1);
177  place(2, n + 3, mServerButton, 1, 1);
178  place(3, n + 3, mLoginButton, 1, 1);
179 
180  addKeyListener(this);
181 }
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1383
#define _(s)
Definition: gettext.h:34
std::string * mUpdateHost
Definition: logindialog.h:109
const bool LoseFocusOnTab_true
void adjustSize()
Definition: textfield.cpp:715
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:96
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:802
void setSelectedString(const std::string &str)
Definition: dropdown.cpp:445
Button * mLoginButton
Definition: logindialog.h:102
DropDown * mUpdateHostDropDown
Definition: logindialog.h:107
#define CAST_S32
Definition: cast.h:29
const std::string BUTTON_SKIN
Definition: button.h:88
const bool Visible_false
Definition: visible.h:29
Definition: label.h:87
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:748
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
LayoutCell & setHAlign(const Alignment a)
Definition: layoutcell.h:83
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:82
void setSelected(int selected)
Definition: dropdown.cpp:514
void adjustSize()
Definition: label.cpp:197
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
const std::string & getText() const
Definition: textfield.h:223
UpdateTypeModel * mUpdateTypeModel
Definition: logindialog.h:99
void setWindowName(const std::string &name)
Definition: window.h:354

◆ ~LoginDialog()

LoginDialog::~LoginDialog ( )

Definition at line 220 of file logindialog.cpp.

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

221 {
222  if (mUpdateTypeDropDown != nullptr)
224  if (mUpdateHostDropDown != nullptr)
226 
229 }
void hideDrop(bool event)
Definition: dropdown.cpp:378
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
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 231 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().

232 {
233  const std::string &eventId = event.getId();
234  if (eventId == "login" && canSubmit())
235  {
236  prepareUpdate();
237  mLoginData->registerLogin = false;
239  }
240  else if (eventId == "server")
241  {
242  close();
243  }
244  else if (eventId == "register")
245  {
247  {
248  prepareUpdate();
250  }
251  else if (!mLoginData->registerUrl.empty())
252  {
253  const std::string &url = mLoginData->registerUrl;
254  urlListener.url = url;
256  // TRANSLATORS: question dialog
257  _("Open register url"),
258  url,
260  false,
261  Modal_true,
262  nullptr);
263  confirmDlg->addActionListener(&urlListener);
264  }
265  }
266  else if (eventId == "customhost")
267  {
270  }
271  else if (eventId == "updateselect")
272  {
275  }
276 }
#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:117
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:87
#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:48
#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 306 of file logindialog.cpp.

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

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

307 {
308  return !mUserField->getText().empty() &&
309  !mPassField->getText().empty() &&
311 }
TextField * mPassField
Definition: logindialog.h:96
Client * client
Definition: client.cpp:117
TextField * mUserField
Definition: logindialog.h:95
StateT getState() const
Definition: client.h:68
const std::string & getText() const
Definition: textfield.h:223

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

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

Referenced by action().

394 {
396  Window::close();
397 }
void setState(const StateT state)
Definition: client.h:65
Client * client
Definition: client.cpp:117
virtual void close()
Definition: window.cpp:901

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

279 {
280  if (event.isConsumed())
281  {
283  return;
284  }
285 
286  const InputActionT actionId = event.getActionId();
287  if (actionId == InputAction::GUI_CANCEL)
288  {
290  }
291 #ifdef USE_SDL2
292  else if (actionId == InputAction::GUI_SELECT2)
293 #else // USE_SDL2
294  else if (actionId == InputAction::GUI_SELECT ||
295  actionId == InputAction::GUI_SELECT2)
296 #endif // USE_SDL2
297  {
299  }
300  else
301  {
303  }
304 }
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:715
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 399 of file logindialog.cpp.

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

Referenced by LoginDialog().

400 {
401  HostsGroup group;
402 
403  group.name = mServer->defaultHostName;
404  if (group.name.empty())
405  {
406  // TRANSLATORS: update hosts group default name
407  group.name = _("default updates");
408  }
409  group.hosts = mLoginData->updateHosts;
410  mServer->updateHosts.insert(mServer->updateHosts.begin(), group);
411 }
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 183 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.

184 {
187 
188  const int h = 200;
189  if (mUpdateHostDropDown != nullptr)
190  setContentSize(310, 250);
191  setContentSize(310, h);
192 #ifdef ANDROID
194 #else // ANDROID
195 
196  setDefaultSize(310, h, ImagePosition::CENTER, 0, 0);
197 #endif // ANDROID
198 
199  center();
200  loadWindowState();
201  reflowLayout(0, 0);
202 
203  if (mUserField->getText().empty())
205  else
207 
209  if (loginHandler != nullptr)
210  {
212  || !mLoginData->registerUrl.empty());
213  }
214  else
215  {
216  mRegisterButton->setEnabled(false);
217  }
218 }
void setDefaultSize()
Definition: window.cpp:1197
std::string registerUrl
Definition: logindata.h:68
const bool Visible_true
Definition: visible.h:29
void loadWindowState()
Definition: window.cpp:1086
TextField * mPassField
Definition: logindialog.h:96
LoginData * mLoginData
Definition: logindialog.h:92
void setContentSize(int width, int height)
Definition: window.cpp:491
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:87
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:777
void center()
Definition: window.cpp:1416
const std::string & getText() const
Definition: textfield.h:223
void reflowLayout(int w, int h)
Definition: window.cpp:1395
void postInit()
Definition: window.cpp:248

◆ prepareUpdate()

void LoginDialog::prepareUpdate ( )
private

Definition at line 313 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().

314 {
318  UpdateTypeT updateType = static_cast<UpdateTypeT>(
320 
322  && !mUpdateHostText->getText().empty())
323  {
324  updateType = static_cast<UpdateTypeT>(
325  updateType | UpdateType::Custom);
326  serverConfig.setValue("customUpdateHost",
328 
330  {
333  }
334  else
335  {
336  mLoginData->updateHost.clear();
337  (*mUpdateHost).clear();
338  }
339  }
340  else
341  {
342  std::string str;
343  if (mUpdateHostDropDown != nullptr)
344  {
345  const int sel = mUpdateHostDropDown->getSelected();
346  if (sel >= 0)
347  {
348  const HostsGroup &group = mServer->updateHosts[sel];
349  if (!group.hosts.empty())
350  {
351  str = group.hosts[0];
352  mLoginData->updateHosts = group.hosts;
353  serverConfig.setValue("updateHost2", group.name);
354  }
355  else
356  {
357  serverConfig.setValue("updateHost2", "");
358  }
359  }
360  }
361  else if (mLoginData->updateHost.empty()
362  && !mLoginData->updateHosts.empty())
363  {
364  str = mLoginData->updateHosts[0];
365  serverConfig.setValue("updateHost2", str);
366  }
367  if (!str.empty() && checkPath(str))
368  {
370  *mUpdateHost = STD_MOVE(str);
371  }
372  else
373  {
374  mLoginData->updateHost.clear();
375  (*mUpdateHost).clear();
376  }
377  }
378 
379  mLoginData->updateType = updateType;
380  serverConfig.setValue("updateType", CAST_S32(updateType));
381 
382  mRegisterButton->setEnabled(false);
383  mServerButton->setEnabled(false);
384  mLoginButton->setEnabled(false);
385 
387  if (mLoginData->remember)
389  else
391 }
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:119
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:223
int getSelected() const
Definition: dropdown.cpp:509
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: