Polish the tmp_login class.

- Use the new register functions.
- Updated wiki comment.
- change the scroll_label by a wrapping label.
This commit is contained in:
Mark de Wever 2011-03-13 07:49:40 +00:00
parent 62ed384d10
commit 925d897241
3 changed files with 26 additions and 44 deletions

View file

@ -52,12 +52,12 @@
border = "all"
border_size = 5
horizontal_alignment = "left"
[scroll_label]
[label]
id = "login_label"
definition = "default"
label = ""
[/scroll_label]
wrap = "true"
[/label]
[/column]

View file

@ -43,6 +43,10 @@ namespace gui2 {
* password & & text_box & m &
* The password. $
*
* remember_password & & toggle_button & o &
* A toggle button to offer to remember the password in the
* preferences.$
*
* password_reminder & & button & o &
* Request a password reminder. $
*
@ -57,24 +61,29 @@ namespace gui2 {
REGISTER_DIALOG(mp_login)
tmp_login::tmp_login(const t_string& label, const bool focus_password)
: label_(label)
, focus_password_(focus_password)
tmp_login::tmp_login(const std::string& label, const bool focus_password)
{
register_label2("login_label", false, label);
register_text2("user_name"
, true
, &preferences::login
, &preferences::set_login
, !focus_password);
register_text2("password"
, true
, &preferences::password
, NULL /* The password box returns '*' as value. */
, focus_password);
register_bool("remember_password"
, true
, &preferences::remember_password
, &preferences::set_remember_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)) {
@ -86,32 +95,11 @@ void tmp_login::pre_show(CVideo& /*video*/, twindow& window)
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());
}

View file

@ -17,14 +17,13 @@
#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,
tmp_login(const std::string& label,
const bool focus_password);
private:
@ -37,11 +36,6 @@ private:
/** 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