The Battle for Wesnoth  1.17.0-dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Mark de Wever <>
4  Part of the Battle for Wesnoth Project
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,
13  See the COPYING file for more details.
14 */
16 #define GETTEXT_DOMAIN "wesnoth-lib"
22 #include "gui/auxiliary/field.hpp"
23 #include "gui/widgets/button.hpp"
25 #include "gui/widgets/settings.hpp"
28 #include "gui/widgets/window.hpp"
30 namespace gui2::dialogs
31 {
33 REGISTER_DIALOG(mp_login)
35 mp_login::mp_login(const std::string& host, const std::string& label, const bool focus_password)
36  : host_(host), focus_password_(focus_password)
37 {
38  register_label("login_label", false, label);
39  username_ = register_text("user_name", true,
42  !focus_password);
44  register_bool("remember_password", false,
47 }
50 {
51  text_box& pwd = find_widget<text_box>(get_window(), "password", false);
53 }
56 {
57  password_box& pwd = find_widget<password_box>(get_window(), "password", false);
59 }
62 {
63  text_box& login = find_widget<text_box>(&win, "user_name", false);
66  load_password();
68  if(focus_password_) {
69  win.keyboard_capture(find_widget<text_box>(&win, "password", false, true));
70  }
72  win.add_to_tab_order(&login);
73  win.add_to_tab_order(find_widget<text_box>(&win, "password", false, true));
74 }
76 void mp_login::post_show(window& /*win*/) {
77  if(get_retval() == retval::OK) {
78  save_password();
79  }
80 }
82 } // namespace dialogs
field_text * username_
Definition: mp_login.hpp:56
bool remember_password()
void load_password() const
Definition: mp_login.cpp:49
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:55
STL namespace.
window * get_window() const
Returns a pointer to the dialog&#39;s window.
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:57
T get_widget_value(window &window)
Gets the value of the field.
Definition: field.hpp:396
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
Widget gains keyboard focus.
Definition: handler.hpp:100
Class for a single line text area.
Definition: text_box.hpp:141
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: mp_login.cpp:61
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)
std::string login()
void save_password() const
Definition: mp_login.cpp:55
std::enable_if_t< is_general_event(E)> connect_signal(const signal_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_event.
Definition: dispatcher.hpp:506
std::string get_real_value() const
std::string password(const std::string &server, const std::string &login)
This shows the dialog to log in to the MP server.
Definition: mp_login.hpp:40
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
int get_retval() const
Returns the cached window exit code.
Dialog was closed with the OK button.
Definition: retval.hpp:35
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: mp_login.cpp:76
Key Type Default Description label t_string"" The initial text of the password box.