gui/dialogs/lobby_player_info.cpp

Go to the documentation of this file.
00001 /* $Id: lobby_player_info.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Tomasz Sniatowski <kailoran@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #include "gui/dialogs/helper.hpp"
00017 #include "gui/dialogs/lobby_player_info.hpp"
00018 #include "gui/widgets/button.hpp"
00019 #include "gui/widgets/label.hpp"
00020 #include "gui/widgets/settings.hpp"
00021 #include "gui/widgets/text_box.hpp"
00022 
00023 #include "game_preferences.hpp"
00024 #include "gettext.hpp"
00025 
00026 #include <boost/bind.hpp>
00027 
00028 namespace gui2 {
00029 
00030 REGISTER_DIALOG(lobby_player_info)
00031 
00032 tlobby_player_info::tlobby_player_info(events::chat_handler& chat, user_info& info, const lobby_info& li)
00033 : chat_(chat), info_(info), reason_(NULL), time_(NULL), relation_(NULL),
00034 add_to_friends_(NULL), add_to_ignores_(NULL), remove_from_list_(NULL),
00035 result_open_whisper_(false), lobby_info_(li)
00036 {
00037 }
00038 
00039 tlobby_player_info::~tlobby_player_info()
00040 {
00041 }
00042 
00043 void tlobby_player_info::pre_show(CVideo& /*video*/, twindow& window)
00044 {
00045     relation_ = find_widget<tlabel>(&window, "relation_info", false, true);
00046     connect_signal_mouse_left_click(
00047             find_widget<tbutton>(&window, "start_whisper", false)
00048             , boost::bind(
00049                   &tlobby_player_info::start_whisper_button_callback
00050                 , this
00051                 , boost::ref(window)));
00052 
00053     add_to_friends_ = &find_widget<tbutton>(&window, "add_to_friends", false);
00054     connect_signal_mouse_left_click(*add_to_friends_, boost::bind(
00055                   &tlobby_player_info::add_to_friends_button_callback
00056                 , this
00057                 , boost::ref(window)));
00058 
00059     add_to_ignores_ = &find_widget<tbutton>(&window, "add_to_ignores", false);
00060     connect_signal_mouse_left_click(*add_to_ignores_, boost::bind(
00061                   &tlobby_player_info::add_to_ignores_button_callback
00062                 , this
00063                 , boost::ref(window)));
00064 
00065     remove_from_list_ = &find_widget<tbutton>(&window, "remove_from_list", false);
00066     connect_signal_mouse_left_click(*remove_from_list_, boost::bind(
00067                   &tlobby_player_info::remove_from_list_button_callback
00068                 , this
00069                 , boost::ref(window)));
00070 
00071     connect_signal_mouse_left_click(
00072               find_widget<tbutton>(&window, "check_status", false)
00073             , boost::bind(
00074                   &tlobby_player_info::check_status_button_callback
00075                 , this
00076                 , boost::ref(window)));
00077 
00078     connect_signal_mouse_left_click(
00079               find_widget<tbutton>(&window, "kick", false)
00080             , boost::bind(
00081                   &tlobby_player_info::kick_button_callback
00082                 , this
00083                 , boost::ref(window)));
00084 
00085     connect_signal_mouse_left_click(
00086               find_widget<tbutton>(&window, "kick_ban", false)
00087             , boost::bind(
00088                   &tlobby_player_info::kick_ban_button_callback
00089                 , this
00090                 , boost::ref(window)));
00091 
00092     find_widget<tlabel>(&window, "player_name", false)
00093             .set_label(info_.name);
00094 
00095     std::stringstream loc;
00096     const game_info* game = lobby_info_.get_game_by_id(info_.game_id);
00097     if (game != NULL) {
00098         loc << _("In game:") << " " << game->name << " ";
00099         if (info_.observing) {
00100             loc << _("(observing)");
00101         } else {
00102             loc << _("(playing)");
00103         }
00104     } else {
00105         loc << _("In lobby");
00106     }
00107 
00108     find_widget<tlabel>(&window, "location_info", false).set_label(loc.str());
00109 
00110     update_relation(window);
00111 
00112     if (!preferences::is_authenticated()) {
00113         twidget* aw = window.find("admin", false);
00114         aw->set_visible(twidget::INVISIBLE);
00115     }
00116 }
00117 
00118 void tlobby_player_info::post_show(twindow& /*window*/)
00119 {
00120 }
00121 
00122 void tlobby_player_info::update_relation(twindow& w)
00123 {
00124     add_to_friends_->set_active(false);
00125     add_to_ignores_->set_active(false);
00126     remove_from_list_->set_active(false);
00127     switch (info_.relation) {
00128         case user_info::FRIEND:
00129             relation_->set_label(_("On friends list"));
00130             add_to_ignores_->set_active(true);
00131             remove_from_list_->set_active(true);
00132             break;
00133         case user_info::IGNORED:
00134             relation_->set_label(_("On ignores list"));
00135             add_to_friends_->set_active(true);
00136             remove_from_list_->set_active(true);
00137             break;
00138         case user_info::NEUTRAL:
00139             relation_->set_label(_("Neither a friend nor ignored"));
00140             add_to_friends_->set_active(true);
00141             add_to_ignores_->set_active(true);
00142             break;
00143         case user_info::ME:
00144             relation_->set_label(_("You"));
00145             break;
00146         default:
00147             relation_->set_label(_("Error"));
00148     }
00149     w.invalidate_layout();
00150 }
00151 
00152 void tlobby_player_info::add_to_friends_button_callback(twindow& w)
00153 {
00154     preferences::add_friend(info_.name);
00155     info_.relation = user_info::FRIEND;
00156     update_relation(w);
00157 }
00158 
00159 void tlobby_player_info::add_to_ignores_button_callback(twindow& w)
00160 {
00161     preferences::add_ignore(info_.name);
00162     info_.relation = user_info::IGNORED;
00163     update_relation(w);
00164 }
00165 
00166 void tlobby_player_info::remove_from_list_button_callback(twindow& w)
00167 {
00168     preferences::remove_friend(info_.name);
00169     preferences::remove_ignore(info_.name);
00170     info_.relation = user_info::NEUTRAL;
00171     update_relation(w);
00172 }
00173 
00174 void tlobby_player_info::start_whisper_button_callback(twindow& w)
00175 {
00176     result_open_whisper_ = true;
00177     w.close();
00178 }
00179 
00180 void tlobby_player_info::check_status_button_callback(twindow& w)
00181 {
00182     chat_.send_command("query", "status " + info_.name);
00183     w.close();
00184 }
00185 
00186     void tlobby_player_info::kick_button_callback(twindow& w)
00187 {
00188     do_kick_ban(false);
00189     w.close();
00190 }
00191 
00192 void tlobby_player_info::kick_ban_button_callback(twindow& w)
00193 {
00194     do_kick_ban(true);
00195     w.close();
00196 }
00197 
00198 void tlobby_player_info::do_kick_ban(bool ban)
00199 {
00200     std::stringstream ss;
00201     ss << (ban ? "kban" : "kick ") << info_.name;
00202     if (ban && !time_->get_value().empty()) {
00203         ss << " " << time_->get_value();
00204     }
00205     if (!reason_->get_value().empty()) {
00206         ss << " " << reason_->get_value();
00207     }
00208 
00209     chat_.send_command("query", ss.str());
00210 }
00211 
00212 } //end namespace gui2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:58 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs