The Battle for Wesnoth  1.19.0-dev
mp_login.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
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 
19 
22 #include "gui/auxiliary/field.hpp"
24 #include "gui/widgets/window.hpp"
25 
26 namespace gui2::dialogs
27 {
28 
29 REGISTER_DIALOG(mp_login)
30 
31 mp_login::mp_login(const std::string& host, const std::string& label, const bool focus_password)
32  : modal_dialog(window_id())
33  , host_(host)
34  , focus_password_(focus_password)
35 {
36  register_label("login_label", false, label);
37  username_ = register_text("user_name", true,
40  !focus_password);
41 
42  register_bool("remember_password", false,
45 }
46 
48 {
49  text_box& pwd = find_widget<text_box>(this, "password", false);
51 }
52 
54 {
55  password_box& pwd = find_widget<password_box>(this, "password", false);
57 }
58 
60 {
61  text_box& login = find_widget<text_box>(&win, "user_name", false);
62  login.connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(std::bind(&mp_login::load_password, this));
63 
64  load_password();
65 
66  if(focus_password_) {
67  win.keyboard_capture(find_widget<text_box>(&win, "password", false, true));
68  }
69 
70  win.add_to_tab_order(&login);
71  win.add_to_tab_order(find_widget<text_box>(&win, "password", false, true));
72 }
73 
74 void mp_login::post_show(window& /*win*/) {
75  if(get_retval() == retval::OK) {
76  save_password();
77  }
78 }
79 
80 } // namespace dialogs
Abstract base class for all modal dialogs.
int get_retval() const
Returns the cached window exit code.
This shows the dialog to log in to the MP server.
Definition: mp_login.hpp:41
field_text * username_
Definition: mp_login.hpp:56
const std::string host_
Definition: mp_login.hpp:55
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: mp_login.cpp:74
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: mp_login.cpp:59
T get_widget_value()
Gets the value of the field.
Definition: field.hpp:379
A label displays text that can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
std::string get_real_value() const
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
Class for a single line text area.
Definition: text_box.hpp:142
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
void keyboard_capture(widget *widget)
Definition: window.cpp:1215
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1233
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed.
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(tod_new_schedule)
@ RECEIVE_KEYBOARD_FOCUS
Definition: handler.hpp:160
@ OK
Dialog was closed with the OK button.
Definition: retval.hpp:35
void set_remember_password(bool remember)
std::string password(const std::string &server, const std::string &login)
bool remember_password()
void set_login(const std::string &login)
std::string login()
void set_password(const std::string &server, const std::string &login, const std::string &key)