The Battle for Wesnoth  1.15.12+dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <>
3  Part of the Battle for Wesnoth Project
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
12  See the COPYING file for more details.
13 */
15 #define GETTEXT_DOMAIN "wesnoth-lib"
21 #include "gui/auxiliary/field.hpp"
22 #include "gui/widgets/button.hpp"
24 #include "gui/widgets/settings.hpp"
27 #include "gui/widgets/window.hpp"
29 namespace gui2::dialogs
30 {
32 REGISTER_DIALOG(mp_login)
34 mp_login::mp_login(const std::string& host, const std::string& label, const bool focus_password)
35  : host_(host), focus_password_(focus_password)
36 {
37  register_label("login_label", false, label);
38  username_ = register_text("user_name", true,
41  !focus_password);
43  register_bool("remember_password", false,
46 }
49 {
50  text_box& pwd = find_widget<text_box>(get_window(), "password", false);
52 }
55 {
56  password_box& pwd = find_widget<password_box>(get_window(), "password", false);
58 }
61 {
62  text_box& login = find_widget<text_box>(&win, "user_name", false);
65  load_password();
67  if(focus_password_) {
68  win.keyboard_capture(find_widget<text_box>(&win, "password", false, true));
69  }
71  win.add_to_tab_order(&login);
72  win.add_to_tab_order(find_widget<text_box>(&win, "password", false, true));
73 }
75 void mp_login::post_show(window& /*win*/) {
76  if(get_retval() == retval::OK) {
77  save_password();
78  }
79 }
81 } // namespace dialogs
field_text * username_
Definition: mp_login.hpp:55
bool remember_password()
void load_password() const
Definition: mp_login.cpp:48
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:54
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:56
T get_widget_value(window &window)
Gets the value of the field.
Definition: field.hpp:395
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
Widget gains keyboard focus.
Definition: handler.hpp:99
Class for a single line text area.
Definition: text_box.hpp:140
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: mp_login.cpp:60
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:54
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:505
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:39
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:34
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: mp_login.cpp:75
Key Type Default Description label t_string"" The initial text of the password box.