The Battle for Wesnoth  1.15.2+dev
mp_login.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
21 #include "gui/auxiliary/field.hpp"
22 #include "gui/widgets/button.hpp"
24 #include "gui/widgets/settings.hpp"
27 #include "gui/widgets/window.hpp"
28 
29 namespace gui2
30 {
31 namespace dialogs
32 {
33 
34 /*WIKI
35  * @page = GUIWindowDefinitionWML
36  * @order = 2_mp_login
37  *
38  * == Multiplayer connect ==
39  *
40  * This shows the dialog to log in to the MP server
41  *
42  * @begin{table}{dialog_widgets}
43  *
44  * user_name & & text_box & m &
45  * The login user name. $
46  *
47  * password & & text_box & m &
48  * The password. $
49  *
50  * remember_password & & toggle_button & o &
51  * A toggle button to offer to remember the password in the
52  * preferences. $
53  *
54  * change_username & & button & o &
55  * Use a different username. $
56  *
57  * login_label & & button & o &
58  * Displays the information received from the server. $
59  *
60  * @end{table}
61  */
62 
63 REGISTER_DIALOG(mp_login)
64 
65 mp_login::mp_login(const std::string& host, const std::string& label, const bool focus_password)
66  : host_(host), focus_password_(focus_password)
67 {
68  register_label("login_label", false, label);
69  username_ = register_text("user_name", true,
72  !focus_password);
73 
74  register_bool("remember_password", false,
77 }
78 
80 {
81  text_box& pwd = find_widget<text_box>(&win, "password", false);
83 }
84 
86 {
87  password_box& pwd = find_widget<password_box>(&win, "password", false);
89 }
90 
92 {
93  text_box& login = find_widget<text_box>(&win, "user_name", false);
94  login.connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(std::bind(&mp_login::load_password, this, std::ref(win)));
95 
96  load_password(win);
97 
98  if(focus_password_) {
99  win.keyboard_capture(find_widget<text_box>(&win, "password", false, true));
100  }
101 
102  win.add_to_tab_order(&login);
103  win.add_to_tab_order(find_widget<text_box>(&win, "password", false, true));
104 }
105 
107  if(get_retval() == retval::OK) {
108  save_password(win);
109  }
110 }
111 
112 } // namespace dialogs
113 } // namespace gui2
field_text * username_
Definition: mp_login.hpp:45
bool remember_password()
void set_remember_password(bool remember)
This file contains the window object, this object is a top level container which has the event manage...
const std::string host_
Definition: mp_login.hpp:44
STL namespace.
Label showing a text.
Definition: label.hpp:32
T get_widget_value(window &window)
Gets the value of the field.
Definition: field.hpp:395
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
std::enable_if_t< has_key< set_event, E >::value > connect_signal(const signal_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_event.
Definition: dispatcher.hpp:393
Widget gains keyboard focus.
Definition: handler.hpp:107
Class for a single line text area.
Definition: text_box.hpp:121
Generic file dialog.
Definition: field-fwd.hpp:22
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: mp_login.cpp:91
This file contains the settings handling of the widget library.
void set_login(const std::string &login)
void set_password(const std::string &server, const std::string &login, const std::string &key)
void load_password(window &win) const
Definition: mp_login.cpp:79
Various uncategorised dialogs.
std::string login()
std::string get_real_value() const
std::string password(const std::string &server, const std::string &login)
void save_password(window &win) const
Definition: mp_login.cpp:85
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
Dialog was closed with the OK button.
Definition: retval.hpp:34
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
virtual void post_show(window &window) override
Inherited from modal_dialog.
Definition: mp_login.cpp:106