The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
gui
dialogs
multiplayer
mp_login.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2008 - 2025
3
by Mark de Wever <koraq@xs4all.nl>
4
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY.
12
13
See the COPYING file for more details.
14
*/
15
16
#define GETTEXT_DOMAIN "wesnoth-lib"
17
18
#include "
gui/dialogs/multiplayer/mp_login.hpp
"
19
20
#include "
preferences/preferences.hpp
"
21
#include "
gui/auxiliary/field.hpp
"
22
#include "
gui/widgets/password_box.hpp
"
23
#include "
gui/widgets/window.hpp
"
24
25
namespace
gui2::dialogs
26
{
27
28
REGISTER_DIALOG
(mp_login)
29
30
mp_login
::
mp_login
(const
std
::
string
& host, const
std
::
string
&
label
, const
bool
focus_password)
31
:
modal_dialog
(window_id())
32
, host_(host)
33
, focus_password_(focus_password)
34
{
35
register_label(
"login_label"
,
false
,
label
);
36
username_ = register_text(
"user_name"
,
true
,
37
[]() {
return
prefs::get
().
login
();},
38
[](
const
std::string& v) {
prefs::get
().
set_login
(v);},
39
!focus_password);
40
41
register_bool(
"remember_password"
,
false
,
42
[]() {
return
prefs::get
().
remember_password
();},
43
[](
bool
v) {
prefs::get
().
set_remember_password
(v);});
44
}
45
46
void
mp_login::load_password
()
47
{
48
text_box
& pwd = find_widget<text_box>(
"password"
);
49
pwd.
set_value
(
prefs::get
().password(
host_
,
username_
->
get_widget_value
()));
50
}
51
52
void
mp_login::save_password
()
53
{
54
password_box
& pwd = find_widget<password_box>(
"password"
);
55
prefs::get
().
set_password
(
host_
,
username_
->
get_widget_value
(), pwd.
get_real_value
());
56
}
57
58
void
mp_login::pre_show
()
59
{
60
text_box
& login = find_widget<text_box>(
"user_name"
);
61
login.
connect_signal
<
event::RECEIVE_KEYBOARD_FOCUS
>(std::bind(&
mp_login::load_password
,
this
));
62
63
load_password
();
64
65
if
(
focus_password_
) {
66
keyboard_capture
(find_widget<text_box>(
"password"
,
false
,
true
));
67
}
68
69
add_to_tab_order
(&login);
70
add_to_tab_order
(find_widget<text_box>(
"password"
,
false
,
true
));
71
}
72
73
void
mp_login::post_show
() {
74
if
(
get_retval
() ==
retval::OK
) {
75
save_password
();
76
}
77
}
78
79
}
// namespace dialogs
gui2::dialogs::modal_dialog
Abstract base class for all modal dialogs.
Definition
modal_dialog.hpp:146
gui2::dialogs::mp_login
Definition
mp_login.hpp:28
gui2::dialogs::mp_login::load_password
void load_password()
Definition
mp_login.cpp:46
gui2::dialogs::mp_login::post_show
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition
mp_login.cpp:73
gui2::dialogs::mp_login::pre_show
virtual void pre_show() override
Actions to be taken before showing the window.
Definition
mp_login.cpp:58
gui2::dialogs::mp_login::username_
field_text * username_
Definition
mp_login.hpp:43
gui2::dialogs::mp_login::focus_password_
bool focus_password_
Definition
mp_login.hpp:44
gui2::dialogs::mp_login::host_
const std::string host_
Definition
mp_login.hpp:42
gui2::dialogs::mp_login::save_password
void save_password()
Definition
mp_login.cpp:52
gui2::event::dispatcher::connect_signal
void connect_signal(const F &func, const queue_position position=back_child)
Adds a callback to the appropriate queue based on event type.
Definition
dispatcher.hpp:351
gui2::field::get_widget_value
T get_widget_value()
Gets the value of the field.
Definition
field.hpp:378
gui2::label
Definition
label.hpp:32
gui2::password_box
Definition
password_box.hpp:38
gui2::password_box::get_real_value
std::string get_real_value() const
Definition
password_box.hpp:44
gui2::text_box_base::set_value
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
Definition
text_box_base.cpp:134
gui2::text_box
A widget that allows the user to input text in single line.
Definition
text_box.hpp:125
gui2::window::keyboard_capture
void keyboard_capture(widget *widget)
Definition
window.cpp:1197
gui2::window::add_to_tab_order
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition
window.cpp:1223
gui2::window::get_retval
int get_retval()
Definition
window.hpp:394
prefs::set_remember_password
void set_remember_password(bool remember)
Definition
preferences.cpp:2207
prefs::get
static prefs & get()
Definition
preferences.hpp:201
prefs::set_login
void set_login(const std::string &login)
Definition
preferences.cpp:2234
prefs::set_password
void set_password(const std::string &server, const std::string &login, const std::string &key)
Definition
preferences.cpp:2266
prefs::login
std::string login()
Definition
preferences.cpp:2218
prefs::remember_password
bool remember_password()
Definition
preferences.cpp:2202
field.hpp
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed.
window.hpp
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
Definition
modal_dialog.hpp:89
mp_login.hpp
gui2::dialogs
Definition
achievements_dialog.cpp:35
gui2::event::RECEIVE_KEYBOARD_FOCUS
@ RECEIVE_KEYBOARD_FOCUS
Definition
handler.hpp:177
gui2::OK
@ OK
Dialog was closed with the OK button.
Definition
retval.hpp:35
std
STL namespace.
password_box.hpp
preferences.hpp
Generated by
1.9.8