The Battle for Wesnoth  1.19.7+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 
21 #include "gui/auxiliary/field.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 
47 {
48  text_box& pwd = find_widget<text_box>("password");
50 }
51 
53 {
54  password_box& pwd = find_widget<password_box>("password");
56 }
57 
59 {
60  text_box& login = find_widget<text_box>("user_name");
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 
74  if(get_retval() == retval::OK) {
75  save_password();
76  }
77 }
78 
79 } // namespace dialogs
Abstract base class for all modal dialogs.
int get_retval() const
Returns the cached window exit code.
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition: mp_login.cpp:73
virtual void pre_show() override
Actions to be taken before showing the window.
Definition: mp_login.cpp:58
field_text * username_
Definition: mp_login.hpp:43
const std::string host_
Definition: mp_login.hpp:42
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:378
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
void keyboard_capture(widget *widget)
Definition: window.cpp:1207
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1225
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