The Battle for Wesnoth  1.19.2+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,
38  []() {return prefs::get().login();},
39  [](std::string v) {prefs::get().set_login(v);},
40  !focus_password);
41 
42  register_bool("remember_password", false,
43  []() {return prefs::get().remember_password();},
44  [](bool v) {prefs::get().set_remember_password(v);});
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);
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.
field_text * username_
Definition: mp_login.hpp:43
const std::string host_
Definition: mp_login.hpp:42
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
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
T get_widget_value()
Gets the value of the field.
Definition: field.hpp:379
std::string get_real_value() const
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
A widget that allows the user to input text in single line.
Definition: text_box.hpp:125
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
void keyboard_capture(widget *widget)
Definition: window.cpp:1221
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1239
void set_remember_password(bool remember)
void set_login(const std::string &login)
static prefs & get()
void set_password(const std::string &server, const std::string &login, const std::string &key)
std::string login()
bool remember_password()
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(editor_edit_unit)
@ RECEIVE_KEYBOARD_FOCUS
Definition: handler.hpp:160
@ OK
Dialog was closed with the OK button.
Definition: retval.hpp:35