Move tmp_login to its own files.

This commit is contained in:
Mark de Wever 2011-03-06 08:39:35 +00:00
parent 7cb892abff
commit 36022c9cb2
9 changed files with 176 additions and 118 deletions

View file

@ -81,6 +81,7 @@ src/gui/dialogs/mp_cmd_wrapper.cpp
src/gui/dialogs/mp_connect.cpp
src/gui/dialogs/mp_create_game.cpp
src/gui/dialogs/mp_create_game_set_password.cpp
src/gui/dialogs/mp_login.cpp
src/gui/dialogs/mp_method_selection.cpp
src/gui/dialogs/popup.cpp
src/gui/dialogs/simple_item_selector.cpp

View file

@ -444,6 +444,7 @@ set(wesnoth-main_SRC
gui/dialogs/mp_connect.cpp
gui/dialogs/mp_create_game.cpp
gui/dialogs/mp_create_game_set_password.cpp
gui/dialogs/mp_login.cpp
gui/dialogs/mp_method_selection.cpp
gui/dialogs/popup.cpp
gui/dialogs/simple_item_selector.cpp

View file

@ -310,6 +310,7 @@ wesnoth_sources = Split("""
gui/dialogs/mp_connect.cpp
gui/dialogs/mp_create_game.cpp
gui/dialogs/mp_create_game_set_password.cpp
gui/dialogs/login.cpp
gui/dialogs/mp_method_selection.cpp
gui/dialogs/popup.cpp
gui/dialogs/simple_item_selector.cpp

View file

@ -26,11 +26,7 @@
#else
#include "gui/widgets/listbox.hpp"
#endif
#include "gui/widgets/label.hpp"
#include "gui/widgets/password_box.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/scroll_label.hpp"
#include "gui/widgets/toggle_button.hpp"
#include <boost/bind.hpp>
@ -185,95 +181,5 @@ void tmp_connect::pre_show(CVideo& video, twindow& window)
}
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_mp_login
*
* == Multiplayer connect ==
*
* This shows the dialog to log in to the MP server
*
* @begin{table}{dialog_widgets}
*
* user_name & & text_box & m &
* The login user name. $
*
* password & & text_box & m &
* The password. $
*
* password_reminder & & button & o &
* Request a password reminder. $
*
* change_username & & button & o &
* Use a different username. $
*
* login_label & & button & o &
* Displays the information received from the server. $
*
* @end{table}
*/
REGISTER_DIALOG(mp_login)
tmp_login::tmp_login(const t_string& label, const bool focus_password)
: label_(label)
, focus_password_(focus_password)
{
}
void tmp_login::pre_show(CVideo& /*video*/, twindow& window)
{
ttext_box* username =
find_widget<ttext_box>(&window, "user_name", false, true);
username->set_value(preferences::login());
tpassword_box* password =
find_widget<tpassword_box>(&window, "password", false, true);
password->set_value(preferences::password());
window.keyboard_capture(focus_password_ ? password : username);
if(tbutton* button = find_widget<tbutton>(
&window, "password_reminder", false, false)) {
button->set_retval(1);
}
if(tbutton* button = find_widget<tbutton>(
&window, "change_username", false, false)) {
button->set_retval(2);
}
// Needs to be a scroll_label since the text can get long and a normal
// label can't wrap (at the moment).
tcontrol* label =
dynamic_cast<tscroll_label*>(window.find("login_label", false));
if(label) label->set_label(label_);
if(ttoggle_button* button = find_widget<ttoggle_button>(
&window, "remember_password", false, false)) {
button->set_value(preferences::remember_password());
}
}
void tmp_login::post_show(twindow& window)
{
if(get_retval() == twindow::OK) {
if(ttoggle_button* button = find_widget<ttoggle_button>(
&window, "remember_password", false, false)) {
preferences::set_remember_password(button->get_value());
}
preferences::set_login(find_widget<ttext_box>(
&window, "user_name", false).get_value());
preferences::set_password(find_widget<tpassword_box>(
&window, "password", false).get_real_value());
}
}
} // namespace gui2

View file

@ -17,7 +17,6 @@
#define GUI_DIALOGS_MP_CONNECT_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "tstring.hpp"
namespace gui2 {
@ -38,29 +37,6 @@ private:
tfield_text* host_name_;
};
class tmp_login : public tdialog
{
public:
tmp_login(const t_string& label,
const bool focus_password);
private:
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
t_string label_;
/** Should the password box be focussed upon showing the dialog? */
bool focus_password_;
};
} // namespace gui2
#endif

View file

@ -0,0 +1,121 @@
/* $Id$ */
/*
Copyright (C) 2008 - 2011 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/mp_login.hpp"
#include "game_preferences.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/password_box.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/scroll_label.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
namespace gui2 {
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_mp_login
*
* == Multiplayer connect ==
*
* This shows the dialog to log in to the MP server
*
* @begin{table}{dialog_widgets}
*
* user_name & & text_box & m &
* The login user name. $
*
* password & & text_box & m &
* The password. $
*
* password_reminder & & button & o &
* Request a password reminder. $
*
* change_username & & button & o &
* Use a different username. $
*
* login_label & & button & o &
* Displays the information received from the server. $
*
* @end{table}
*/
REGISTER_DIALOG(mp_login)
tmp_login::tmp_login(const t_string& label, const bool focus_password)
: label_(label)
, focus_password_(focus_password)
{
}
void tmp_login::pre_show(CVideo& /*video*/, twindow& window)
{
ttext_box* username =
find_widget<ttext_box>(&window, "user_name", false, true);
username->set_value(preferences::login());
tpassword_box* password =
find_widget<tpassword_box>(&window, "password", false, true);
password->set_value(preferences::password());
window.keyboard_capture(focus_password_ ? password : username);
if(tbutton* button = find_widget<tbutton>(
&window, "password_reminder", false, false)) {
button->set_retval(1);
}
if(tbutton* button = find_widget<tbutton>(
&window, "change_username", false, false)) {
button->set_retval(2);
}
// Needs to be a scroll_label since the text can get long and a normal
// label can't wrap (at the moment).
tcontrol* label =
dynamic_cast<tscroll_label*>(window.find("login_label", false));
if(label) label->set_label(label_);
if(ttoggle_button* button = find_widget<ttoggle_button>(
&window, "remember_password", false, false)) {
button->set_value(preferences::remember_password());
}
}
void tmp_login::post_show(twindow& window)
{
if(get_retval() == twindow::OK) {
if(ttoggle_button* button = find_widget<ttoggle_button>(
&window, "remember_password", false, false)) {
preferences::set_remember_password(button->get_value());
}
preferences::set_login(find_widget<ttext_box>(
&window, "user_name", false).get_value());
preferences::set_password(find_widget<tpassword_box>(
&window, "password", false).get_real_value());
}
}
} // namespace gui2

View file

@ -0,0 +1,50 @@
/* $Id$ */
/*
Copyright (C) 2008 - 2011 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_DIALOGS_MP_LOGIN_HPP_INCLUDED
#define GUI_DIALOGS_MP_LOGIN_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "tstring.hpp"
namespace gui2 {
class tmp_login : public tdialog
{
public:
tmp_login(const t_string& label,
const bool focus_password);
private:
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
t_string label_;
/** Should the password box be focussed upon showing the dialog? */
bool focus_password_;
};
} // namespace gui2
#endif

View file

@ -23,6 +23,7 @@
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/mp_connect.hpp"
#include "gui/dialogs/mp_create_game.hpp"
#include "gui/dialogs/mp_login.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "hash.hpp"

View file

@ -46,6 +46,7 @@
#include "gui/dialogs/mp_cmd_wrapper.hpp"
#include "gui/dialogs/mp_connect.hpp"
#include "gui/dialogs/mp_create_game.hpp"
#include "gui/dialogs/mp_login.hpp"
#include "gui/dialogs/mp_method_selection.hpp"
#include "gui/dialogs/simple_item_selector.hpp"
#include "gui/dialogs/title_screen.hpp"