The Battle for Wesnoth  1.15.7+dev
chatbox.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 The Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #define GETTEXT_DOMAIN "wesnoth-lib"
15 
16 #include "gui/widgets/chatbox.hpp"
17 
19 
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/image.hpp"
23 #include "gui/widgets/label.hpp"
24 #include "gui/widgets/listbox.hpp"
27 #include "gui/widgets/settings.hpp"
28 #include "gui/widgets/text_box.hpp"
29 #include "gui/widgets/window.hpp"
30 
31 #include "font/pango/escape.hpp"
32 #include "formatter.hpp"
33 #include "formula/string_utils.hpp"
34 #include "gettext.hpp"
35 #include "log.hpp"
37 #include "preferences/game.hpp"
38 #include "preferences/lobby.hpp"
40 #include "wesnothd_connection.hpp"
41 
42 static lg::log_domain log_lobby("lobby");
43 #define DBG_LB LOG_STREAM(debug, log_lobby)
44 #define LOG_LB LOG_STREAM(info, log_lobby)
45 #define ERR_LB LOG_STREAM(err, log_lobby)
46 
47 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
48 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
49 
50 namespace gui2
51 {
52 
53 // ------------ WIDGET -----------{
54 
55 REGISTER_WIDGET(chatbox)
56 
57 chatbox::chatbox(const implementation::builder_chatbox& builder)
58  : container_base(builder, type())
59  , roomlistbox_(nullptr)
60  , chat_log_container_(nullptr)
61  , chat_input_(nullptr)
62  , active_window_(0)
63  , active_window_changed_callback_()
64  , chat_info_()
65  , wesnothd_connection_(nullptr)
66  , log_(nullptr)
67 {
68  // We only implement a RECEIVE_KEYBOARD_FOCUS handler; LOSE_KEYBOARD_FOCUS
69  // isn't needed. This handler forwards focus to the input textbox, meaning
70  // if keyboard_focus is called on a chatbox, distributor::keyboard_focus_
71  // will immediately be set to the input textbox, which will then handle focus
72  // loss itself when applicable. Nothing else happens in the interim while
73  // keyboard_focus_ equals `this` to warrent cleanup.
74  connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
76 }
77 
79 {
80  roomlistbox_ = find_widget<listbox>(this, "room_list", false, true);
81 
82  // We need to bind a lambda here since switch_to_window is overloaded.
83  // A lambda alone would be more verbose because it'd need to specify all the parameters.
85  std::bind([this]() { switch_to_window(roomlistbox_->get_selected_row()); }));
86 
87  chat_log_container_ = find_widget<multi_page>(this, "chat_log_container", false, true);
88 
89  chat_input_ = find_widget<text_box>(this, "chat_input", false, true);
90 
91  connect_signal_pre_key_press(*chat_input_,
92  std::bind(&chatbox::chat_input_keypress_callback, this, _5));
93 }
94 
95 void chatbox::load_log(std::map<std::string, chatroom_log>& log, bool show_lobby)
96 {
97  for(const auto& l : log) {
98  const bool is_lobby = l.first == "lobby";
99 
100  if(!show_lobby && is_lobby && !l.second.whisper) {
101  continue;
102  }
103 
104  find_or_create_window(l.first, l.second.whisper, true, !is_lobby, l.second.log);
105  }
106 
107  log_ = &log;
108 }
109 
111 {
113 
114  // Clear pending messages notification in room listbox
116  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::hidden);
117 
118  t.pending_messages = 0;
119 
122  }
123 }
124 
126 {
128 }
129 
130 void chatbox::switch_to_window(std::size_t id)
131 {
132  active_window_ = id;
133  assert(active_window_ < open_windows_.size());
134 
137 
138  // Grab input focus
140 
142 }
143 
144 void chatbox::chat_input_keypress_callback(const SDL_Keycode key)
145 {
146  std::string input = chat_input_->get_value();
147  if(input.empty() || chat_input_->is_composing()) {
148  return;
149  }
150 
152 
153  switch(key) {
154  case SDLK_RETURN:
155  case SDLK_KP_ENTER: {
156  if(input[0] == '/') {
157  // TODO: refactor do_speak so it uses context information about
158  // opened window, so e.g. /ignore in a whisper session ignores
159  // the other party without having to specify it's nick.
160  chat_handler::do_speak(input);
161  } else {
162  if(t.whisper) {
163  send_whisper(t.name, input);
164  add_whisper_sent(t.name, input);
165  } else {
166  send_chat_room_message(t.name, input);
168  }
169  }
170 
172  chat_input_->set_value("");
173 
174  break;
175  }
176 
177  case SDLK_TAB: {
179 
180  // TODO: very inefficient! Very! D:
181  std::vector<std::string> matches;
182  for(const std::string& ui : ri->members()) {
183  if(ui != preferences::login()) {
184  matches.push_back(ui);
185  }
186  }
187 
188  const bool line_start = utils::word_completion(input, matches);
189 
190  if(matches.empty()) {
191  return;
192  }
193 
194  if(matches.size() == 1) {
195  input.append(line_start ? ": " : " ");
196  } else {
197  std::string completion_list = utils::join(matches, " ");
198  append_to_chatbox(completion_list);
199  }
200 
201  chat_input_->set_value(input);
202 
203  break;
204  }
205 
206  default:
207  break;
208  }
209 }
210 
211 void chatbox::append_to_chatbox(const std::string& text, const bool force_scroll)
212 {
213  append_to_chatbox(text, active_window_, force_scroll);
214 }
215 
216 void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const bool force_scroll)
217 {
219 
220  scroll_label& log = find_widget<scroll_label>(&grid, "log_text", false);
221  const bool chatbox_at_end = log.vertical_scrollbar_at_end();
222  const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
223 
224  const std::string new_text = formatter()
225  << log.get_label() << "\n" << "<span color='#bcb088'>" << preferences::get_chat_timestamp(std::time(0)) << text << "</span>";
226 
227  log.set_use_markup(true);
228  log.set_label(new_text);
229 
230  if(log_ != nullptr) {
231  try {
232  const std::string& room_name = open_windows_[id].name;
233  log_->at(room_name).log = new_text;
234  } catch(const std::out_of_range&) {
235  }
236  }
237 
238  if(chatbox_at_end || force_scroll) {
240  } else {
241  log.set_vertical_scrollbar_item_position(chatbox_position);
242  }
243 }
244 
245 void chatbox::send_chat_message(const std::string& message, bool /*allies_only*/)
246 {
247  add_chat_message(std::time(nullptr), preferences::login(), 0, message);
248 
249  ::config c {"message", ::config {"message", message, "sender", preferences::login()}};
250  send_to_server(c);
251 }
252 
254 {
257  }
258 }
259 
260 void chatbox::add_chat_message(const std::time_t& /*time*/,
261  const std::string& speaker,
262  int /*side*/,
263  const std::string& message,
265 {
266  std::string text;
267 
268  // FIXME: the chat_command_handler class (which handles chat commands) dispatches a
269  // message consisting of '/me insert text here' in the case the '/me' or '/emote'
270  // commands are used, so we need to do some manual preprocessing here.
271  if(message.compare(0, 4, "/me ") == 0) {
272  text = formatter() << "<i>" << speaker << " " << font::escape_text(message.substr(4)) << "</i>";
273  } else {
274  text = formatter() << "<b>" << speaker << ":</b> " << font::escape_text(message);
275  }
276 
277  append_to_chatbox(text);
278 }
279 
281 {
282  if(whisper_window_active(receiver)) {
287  } else {
288  add_active_window_whisper(VGETTEXT("whisper to $receiver", {{"receiver", receiver}}), message, true);
289  }
290 
292 }
293 
295 {
296  bool can_go_to_active = !preferences::whisper_friends_only() || preferences::is_friend(sender);
297  bool can_open_new = preferences::auto_open_whisper_windows() && can_go_to_active;
298 
299  chat_info_.get_whisper_log(sender).add_message(sender, message);
300 
301  if(whisper_window_open(sender, can_open_new)) {
302  if(whisper_window_active(sender)) {
303  add_active_window_message(sender, message);
304 
305  do_notify(mp::NOTIFY_WHISPER, sender, message);
306  } else {
307  add_whisper_window_whisper(sender, message);
309 
310  do_notify(mp::NOTIFY_WHISPER_OTHER_WINDOW, sender, message);
311  }
312  } else if(can_go_to_active) {
313  add_active_window_whisper(sender, message);
314  do_notify(mp::NOTIFY_WHISPER, sender, message);
315  } else {
316  LOG_LB << "Ignoring whisper from " << sender << "\n";
317  }
318 }
319 
321 {
322  lobby_chat_window* t = room_window_open(room, false);
323  if(!t) {
324  LOG_LB << "Cannot add sent message to ui for room " << room << ", player not in the room\n";
325  return;
326  }
327 
328  // Do not open room window here. The player should be in the room before sending messages
329  mp::room_info* ri = chat_info_.get_room(room);
330  assert(ri);
331 
332  if(!room_window_active(room)) {
333  switch_to_window(t);
334  }
335 
336  ri->log().add_message(preferences::login(), message);
338 }
339 
341  const std::string& speaker,
342  const std::string& message)
343 {
344  mp::room_info* ri = chat_info_.get_room(room);
345  if(!ri) {
346  LOG_LB << "Discarding message to room " << room << " from " << speaker << " (room not open)\n";
347  return;
348  }
349 
351  ri->log().add_message(speaker, message);
352 
353  if(room_window_active(room)) {
354  add_active_window_message(speaker, message);
355  notify_mode = mp::NOTIFY_MESSAGE;
356  } else {
357  add_room_window_message(room, speaker, message);
359  notify_mode = mp::NOTIFY_MESSAGE_OTHER_WINDOW;
360  }
361 
362  if(speaker == "server") {
363  notify_mode = mp::NOTIFY_SERVER_MESSAGE;
364  } else if (utils::word_match(message, preferences::login())) {
365  notify_mode = mp::NOTIFY_OWN_NICK;
366  } else if (preferences::is_friend(speaker)) {
367  notify_mode = mp::NOTIFY_FRIEND_MESSAGE;
368  }
369 
370  do_notify(notify_mode, speaker, message);
371 }
372 
374 {
376  return t.name == name && t.whisper == true;
377 }
378 
380 {
382  return t.name == room && t.whisper == false;
383 }
384 
385 lobby_chat_window* chatbox::room_window_open(const std::string& room, const bool open_new, const bool allow_close)
386 {
387  return find_or_create_window(room, false, open_new, allow_close,
388  VGETTEXT("Joined <i>$name</i>", { { "name", translation::dsgettext("wesnoth-lib", room.c_str()) } }));
389 }
390 
392 {
393  return find_or_create_window(name, true, open_new, true,
394  VGETTEXT("Started private message with <i>$name</i>. "
395  "If you do not want to receive messages from this player, type <i>/ignore $name</i>", { { "name", name } }));
396 }
397 
399  const bool whisper,
400  const bool open_new,
401  const bool allow_close,
402  const std::string& initial_text)
403 {
404  for(auto& t : open_windows_) {
405  if(t.name == name && t.whisper == whisper) {
406  return &t;
407  }
408  }
409 
410  if(!open_new) {
411  return nullptr;
412  }
413 
414  open_windows_.emplace_back(name, whisper);
415 
416  //
417  // Add a new chat log page.
418  //
420  item["use_markup"] = "true";
421  item["label"] = initial_text;
422  std::map<std::string, string_map> data{{"log_text", item}};
423 
424  if(!whisper) {
425  chat_info_.open_room(name);
426  }
427 
428  if(log_ != nullptr) {
429  log_->emplace(name, chatroom_log{item["label"], whisper});
430  }
431 
433 
434  //
435  // Add a new room window tab.
436  //
437  data.clear();
438  item.clear();
439 
440  if(!whisper) {
441  item["label"] = translation::dsgettext("wesnoth-lib", name.c_str());
442  } else {
443  item["label"] = "<" + name + ">";
444  }
445 
446  data.emplace("room", item);
447 
448  grid& row_grid = roomlistbox_->add_row(data);
449 
450  //
451  // Set up the Close Window button.
452  //
453  button& close_button = find_widget<button>(&row_grid, "close_window", false);
454 
455  if(!allow_close) {
457  } else {
458  connect_signal_mouse_left_click(close_button,
459  std::bind(&chatbox::close_window_button_callback, this, open_windows_.back().name, _3, _4));
460  }
461 
462  return &open_windows_.back();
463 }
464 
465 void chatbox::close_window_button_callback(std::string room_name, bool& handled, bool& halt)
466 {
467  const int index = std::distance(open_windows_.begin(), std::find_if(open_windows_.begin(), open_windows_.end(),
468  [&room_name](const lobby_chat_window& room) { return room.name == room_name; }
469  ));
470 
471  close_window(index);
472 
473  handled = halt = true;
474 }
475 
476 void chatbox::send_to_server(const ::config& cfg)
477 {
480  }
481 }
482 
484 {
485  if(lobby_chat_window* t = whisper_window_open(name, false)) {
486  ++t->pending_messages;
487 
488  if(t->pending_messages == 1) {
489  DBG_LB << "do whisper pending mark row " << (t - &open_windows_[0]) << " with " << t->name << "\n";
490 
492  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::visible);
493  }
494  }
495 }
496 
498 {
499  if(lobby_chat_window* t = room_window_open(room, false)) {
500  ++t->pending_messages;
501 
502  if(t->pending_messages == 1) {
503  int idx = t - &open_windows_[0];
504 
505  DBG_LB << "do room pending mark row " << idx << " with " << t->name << "\n";
506 
508  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::visible);
509  }
510  }
511 }
512 
514 {
515  lobby_chat_window* t = whisper_window_open(sender, false);
516  if(!t) {
517  ERR_LB << "Whisper window not open in add_whisper_window_whisper for " << sender << "\n";
518  return;
519  }
520 
521  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
522  append_to_chatbox(text, t - &open_windows_[0], false);
523 }
524 
526  const std::string& message,
527  const bool force_scroll)
528 {
529  const std::string text = formatter() << "<b>" << "whisper: " << sender << ":</b> " << font::escape_text(message);
530  append_to_chatbox(text, force_scroll);
531 }
532 
533 void chatbox::close_window(std::size_t idx)
534 {
535  const lobby_chat_window& t = open_windows_[idx];
536 
537  DBG_LB << "Close window " << idx << " - " << t.name << "\n";
538 
539  // Can't close the lobby!
540  if((t.name == "lobby" && t.whisper == false) || open_windows_.size() == 1) {
541  return;
542  }
543 
544  if(t.whisper == false) {
545  // closing a room window -- send a part to the server
546  ::config data, msg;
547  msg["room"] = t.name;
548  msg["player"] = preferences::login();
549  data.add_child("room_part", std::move(msg));
550 
551  send_to_server(data);
552  }
553 
554  // Check if we're closing the currently-active window.
555  const bool active_changed = idx == active_window_;
556 
557  if(active_window_ == open_windows_.size() - 1) {
558  --active_window_;
559  }
560 
561  if(t.whisper) {
563  } else {
565  }
566 
567  if(log_ != nullptr) {
568  log_->erase(t.name);
569  }
570 
571  open_windows_.erase(open_windows_.begin() + idx);
572 
573  roomlistbox_->remove_row(idx);
575 
578 
579  if(active_changed) {
581  }
582 }
583 
585  const std::string& sender,
586  const std::string& message)
587 {
588  lobby_chat_window* t = room_window_open(room, false);
589  if(!t) {
590  ERR_LB << "Room window not open in add_room_window_message for " << room << "\n";
591  return;
592  }
593 
594  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
595  append_to_chatbox(text, t - &open_windows_[0], false);
596 }
597 
599  const std::string& message,
600  const bool force_scroll)
601 {
602  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
603  append_to_chatbox(text, force_scroll);
604 }
605 
607 {
609  if(t.whisper) {
610  return nullptr;
611  }
612 
613  return chat_info_.get_room(t.name);
614 }
615 
616 void chatbox::process_room_join(const ::config& data)
617 {
618  const std::string& room = data["room"];
619  const std::string& player = data["player"];
620 
621  DBG_LB << "room join: " << room << " " << player << "\n";
622 
623  mp::room_info* r = chat_info_.get_room(room);
624  if(r) {
625  if(player == preferences::login()) {
626  if(const auto& members = data.child("members")) {
627  r->process_room_members(members);
628  }
629  } else {
630  r->add_member(player);
631 
632  /* TODO: add/use preference */
633  add_room_window_message(room, "server", VGETTEXT("$player has entered the room", {{"player", player}}));
634  }
635 
636  if(r == active_window_room()) {
638  }
639  } else {
640  if(player == preferences::login()) {
641  lobby_chat_window* t = room_window_open(room, true);
642 
643  chat_info_.open_room(room);
644  r = chat_info_.get_room(room);
645  assert(r);
646 
647  if(const auto& members = data.child("members")) {
648  r->process_room_members(members);
649  }
650 
651  switch_to_window(t);
652 
653  const std::string& topic = data["topic"];
654  if(!topic.empty()) {
655  add_chat_room_message_received("room", "server", room + ": " + topic);
656  }
657  } else {
658  LOG_LB << "Discarding join info for a room the player is not in\n";
659  }
660  }
661 }
662 
663 void chatbox::process_room_part(const ::config& data)
664 {
665  // TODO: close room window when the part message is sent
666  const std::string& room = data["room"];
667  const std::string& player = data["player"];
668 
669  DBG_LB << "Room part: " << room << " " << player << "\n";
670 
671  if(mp::room_info* r = chat_info_.get_room(room)) {
672  r->remove_member(player);
673 
674  /* TODO: add/use preference */
675  add_room_window_message(room, "server", VGETTEXT("$player has left the room", {{"player", player}}));
676  if(active_window_room() == r) {
678  }
679  } else {
680  LOG_LB << "Discarding part info for a room the player is not in\n";
681  }
682 }
683 
685 {
686  const std::string& room = data["room"];
687  const std::string& message = data["message"];
688 
689  DBG_LB << "room query response: " << room << " " << message << "\n";
690 
691  if(room.empty()) {
692  if(!message.empty()) {
693  add_active_window_message("server", message);
694  }
695 
696  if(const ::config& rooms = data.child("rooms")) {
697  // TODO: this should really open a nice join room dialog instead
698  std::stringstream ss;
699  ss << "Rooms:";
700 
701  for(const auto & r : rooms.child_range("room")) {
702  ss << " " << r["name"];
703  }
704 
705  add_active_window_message("server", ss.str());
706  }
707  } else {
708  if(room_window_open(room, false)) {
709  if(!message.empty()) {
710  add_chat_room_message_received(room, "server", message);
711  }
712 
713  if(const ::config& members = data.child("members")) {
714  mp::room_info* r = chat_info_.get_room(room);
715  assert(r);
716  r->process_room_members(members);
717  if(r == active_window_room()) {
719  }
720  }
721  } else {
722  if(!message.empty()) {
723  add_active_window_message("server", room + ": " + message);
724  }
725  }
726  }
727 }
728 
729 void chatbox::process_message(const ::config& data, bool whisper /*= false*/)
730 {
731  std::string sender = data["sender"];
732  DBG_LB << "process message from " << sender << " " << (whisper ? "(w)" : "")
733  << ", len " << data["message"].str().size() << '\n';
734 
735  if(preferences::is_ignored(sender)) {
736  return;
737  }
738 
739  const std::string& message = data["message"];
741 
742  if(whisper) {
743  add_whisper_received(sender, message);
744  } else {
745  std::string room = data["room"];
746 
747  // Attempt to send to the currently active room first.
748  if(room.empty()) {
749  LOG_LB << "Message without a room from " << sender << ", falling back to active window\n";
750  room = open_windows_[active_window_].name;
751  }
752 
753  // If we still don't have a name, fall back to lobby.
754  if(room.empty()) {
755  LOG_LB << "Message without a room from " << sender << ", assuming lobby\n";
756  room = "lobby";
757  }
758 
759  if(log_ != nullptr && data["type"].str() == "motd") {
760  if(log_->at("lobby").received_motd == message) {
761  LOG_LB << "Ignoring repeated motd\n";
762  return;
763  } else {
764  log_->at("lobby").received_motd = message;
765  }
766  }
767 
768  add_chat_room_message_received(room, sender, message);
769  }
770 
771  // Notify plugins about the message
772  ::config plugin_data = data;
773  plugin_data["whisper"] = whisper;
774  plugins_manager::get()->notify_event("chat", plugin_data);
775 }
776 
777 void chatbox::process_network_data(const ::config& data)
778 {
779  if(const ::config& message = data.child("message")) {
781  } else if(const ::config& whisper = data.child("whisper")) {
782  process_message(whisper, true);
783  } else if(const ::config& room_join = data.child("room_join")) {
784  process_room_join(room_join);
785  } else if(const ::config& room_part = data.child("room_part")) {
786  process_room_part(room_part);
787  } else if(const ::config& room_query_response = data.child("room_query_response")) {
788  process_room_query_response(room_query_response);
789  }
790 }
791 
793 {
794  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
795 
796  // Forward focus to the input textbox.
798 }
799 
800 // }---------- DEFINITION ---------{
801 
804 {
805  load_resolutions<resolution>(cfg);
806 }
807 
809  : resolution_definition(cfg), grid()
810 {
811  state.emplace_back(cfg.child("background"));
812  state.emplace_back(cfg.child("foreground"));
813 
814  const config& child = cfg.child("grid");
815  VALIDATE(child, _("No grid defined."));
816 
817  grid = std::make_shared<builder_grid>(child);
818 }
819 // }---------- BUILDER -----------{
820 
821 namespace implementation
822 {
823 
824 builder_chatbox::builder_chatbox(const config& cfg)
825  : builder_styled_widget(cfg)
826 {
827 }
828 
830 {
831  chatbox* widget = new chatbox(*this);
832 
833  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
834  << "' with definition '" << definition << "'.\n";
835 
836  const auto conf = widget->cast_config_to<chatbox_definition>();
837  assert(conf);
838 
839  widget->init_grid(conf->grid);
840  widget->finalize_setup();
841 
842  return widget;
843 }
844 
845 } // namespace implementation
846 
847 // }------------ END --------------
848 
849 } // namespace gui2
bool is_composing() const
void send_data(const configr_of &request)
void switch_to_window(lobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
Definition: chatbox.cpp:125
void active_window_changed()
Definition: chatbox.cpp:110
Base class of a resolution, contains the common keys for a resolution.
void keyboard_capture(widget *widget)
Definition: window.cpp:1282
#define LOG_HEADER
Definition: chatbox.cpp:48
wesnothd_connection * wesnothd_connection_
Definition: chatbox.hpp:144
void increment_waiting_messages(const std::string &room)
Mark the room window for "room" as having one more pending message.
Definition: chatbox.cpp:497
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:420
void add_message(const std::time_t &timestamp, const std::string &user, const std::string &message)
Definition: lobby_data.cpp:64
multi_page * chat_log_container_
Definition: chatbox.hpp:132
std::vector< state_definition > state
virtual void set_use_markup(bool use_markup) override
See styled_widget::set_use_markup.
bool room_window_active(const std::string &room)
Definition: chatbox.cpp:379
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
void add_room_window_message(const std::string &room, const std::string &sender, const std::string &message)
Add a message to the window for room "room".
Definition: chatbox.cpp:584
void signal_handler_receive_keyboard_focus(const event::ui_event event)
Definition: chatbox.cpp:792
#define LOG_LB
Definition: chatbox.cpp:44
Main class to show messages to the user.
Definition: message.hpp:34
grid & add_page(const string_map &item)
Adds single page to the grid.
Definition: multi_page.cpp:43
chatbox_definition(const config &cfg)
Definition: chatbox.cpp:802
const std::string & id() const
Definition: widget.cpp:109
std::string get_value() const
This file contains the window object, this object is a top level container which has the event manage...
Base class for all widgets.
Definition: widget.hpp:49
std::map< std::string, chatroom_log > * log_
Definition: chatbox.hpp:146
void parse_admin_authentication(const std::string &sender, const std::string &message)
Definition: game.cpp:184
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
Definition: multi_page.cpp:77
void save_to_history()
Saves the text in the widget to the history.
Definition: text_box.hpp:129
std::vector< lobby_chat_window > open_windows_
Definition: chatbox.hpp:136
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
void process_room_query_response(const ::config &data)
Definition: chatbox.cpp:684
void send_to_server(const ::config &cfg) override
Definition: chatbox.cpp:476
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:277
std::string str
Definition: statement.cpp:110
bool whisper_window_active(const std::string &name)
Definition: chatbox.cpp:373
const chat_session & log() const
Definition: lobby_data.hpp:85
std::size_t active_window_
Definition: chatbox.hpp:138
std::string dsgettext(const char *domainname, const char *msgid)
Definition: gettext.cpp:403
bool whisper_friends_only()
Definition: lobby.cpp:20
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:252
text_box * chat_input_
Definition: chatbox.hpp:134
mp::chat_info chat_info_
Definition: chatbox.hpp:142
void process_room_part(const ::config &data)
Definition: chatbox.cpp:663
virtual void set_label(const t_string &label) override
See styled_widget::set_label.
Generic file dialog.
Definition: field-fwd.hpp:22
Go to the end position.
Definition: scrollbar.hpp:60
#define DBG_LB
Definition: chatbox.cpp:43
void process_message(const ::config &data, bool whisper=false)
Definition: chatbox.cpp:729
Base container class.
Definition: grid.hpp:30
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:100
std::string definition
Parameters for the styled_widget.
void do_notify(notify_mode mode, const std::string &sender, const std::string &message)
Definition: lobby_info.cpp:51
bool auto_open_whisper_windows()
Definition: lobby.cpp:30
virtual void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &message, events::chat_handler::MESSAGE_TYPE type=events::chat_handler::MESSAGE_PRIVATE) override
Inherited form chat_handler.
Definition: chatbox.cpp:260
virtual void send_whisper(const std::string &receiver, const std::string &message)
void close_window_button_callback(std::string room_name, bool &handled, bool &halt)
Definition: chatbox.cpp:465
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:186
chat_session & get_whisper_log(const std::string &name)
Definition: lobby_info.hpp:170
#define ERR_LB
Definition: chatbox.cpp:45
bool is_friend(const std::string &nick)
Definition: game.cpp:302
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
This file contains the settings handling of the widget library.
const grid & page_grid(const unsigned page) const
Returns the grid for the page.
Definition: multi_page.cpp:121
std::ostringstream wrapper.
Definition: formatter.hpp:38
void set_visible(const visibility visible)
Definition: widget.cpp:475
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:171
lobby_chat_window * whisper_window_open(const std::string &name, bool open_new)
Check if a whisper window for user "name" is open, if open_new is true then it will be created if not...
Definition: chatbox.cpp:391
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
Definition: chatbox.cpp:245
std::function< void(void)> active_window_changed_callback_
Definition: chatbox.hpp:140
void add_active_window_message(const std::string &sender, const std::string &message, const bool force_scroll=false)
Add a message to the window for room "room".
Definition: chatbox.cpp:598
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
Definition: chatbox.cpp:95
room_info * get_room(const std::string &name)
Returns info on room with the given name, or nullptr if it doesn&#39;t exist.
Definition: lobby_info.cpp:285
Label showing a text.
void init_grid(const std::shared_ptr< builder_grid > &grid_builder)
Initializes and builds the grid.
void process_room_join(const ::config &data)
Definition: chatbox.cpp:616
listbox * roomlistbox_
Definition: chatbox.hpp:130
bool is_ignored(const std::string &nick)
Definition: game.cpp:315
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
mp::room_info * active_window_room()
Get the room* corresponding to the currently active window, or nullptr if a whisper window is active ...
Definition: chatbox.cpp:606
void process_network_data(const ::config &data)
Definition: chatbox.cpp:777
static lg::log_domain log_lobby("lobby")
std::string login()
virtual void user_relation_changed(const std::string &name) override
Inherited form chat_handler.
Definition: chatbox.cpp:253
std::string escape_text(const std::string &text)
Escapes the pango markup characters in a text.
Definition: escape.hpp:32
#define DBG_GUI_E
Definition: log.hpp:34
std::shared_ptr< const typename T::resolution > cast_config_to() const
Casts the current resolution definition config to the respective type of a derived widget...
void increment_waiting_whispers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
Definition: chatbox.cpp:483
void set_vertical_scrollbar_item_position(const unsigned position)
Move the vertical scrollbar to a position.
void chat_input_keypress_callback(const SDL_Keycode key)
Definition: chatbox.cpp:144
virtual void add_whisper_received(const std::string &sender, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:294
void select_page(const unsigned page, const bool select=true)
Selectes a page.
Definition: multi_page.cpp:106
window * get_window()
Get the parent window.
Definition: widget.cpp:116
void scroll_vertical_scrollbar(const scrollbar_base::scroll_mode scroll)
Scrolls the vertical scrollbar.
std::string name
Definition: sdl_ttf.cpp:70
std::map< std::string, t_string > string_map
Definition: widget.hpp:26
grid & add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:68
This class represents the information a client has about a room.
Definition: lobby_data.hpp:67
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
A generic container base class.
config & add_child(config_key_type key)
Definition: config.cpp:476
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:895
bool grid()
Definition: general.cpp:504
virtual void add_chat_room_message_received(const std::string &room, const std::string &speaker, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:340
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:239
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
const t_string & get_label() const
void append_to_chatbox(const std::string &text, const bool force_scroll=false)
Definition: chatbox.cpp:211
The user sets the widget visible, that means:
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard_function &signal)
Connects the signal for &#39;snooping&#39; on the keypress.
Definition: dispatcher.cpp:166
double t
Definition: astarsearch.cpp:64
The user sets the widget hidden, that means:
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:320
Simple push button.
Definition: button.hpp:35
Standard logging facilities (interface).
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
Definition: listbox.cpp:88
unsigned get_vertical_scrollbar_item_position() const
Returns current position of the vertical scrollbar.
notify_mode
Definition: lobby_info.hpp:186
void close_room(const std::string &name)
Close the chat room with the given name.
Definition: lobby_info.cpp:325
void add_active_window_whisper(const std::string &sender, const std::string &message, const bool force_scroll=false)
Add a whisper message to the current window which is not the whisper window for "name".
Definition: chatbox.cpp:525
lobby_chat_window * find_or_create_window(const std::string &name, const bool whisper, const bool open_new, const bool allow_close, const std::string &initial_text)
Helper function to find and open a new window, used by *_window_open.
Definition: chatbox.cpp:398
virtual void add_whisper_sent(const std::string &receiver, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:280
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
void notify_event(const std::string &name, const config &data)
Definition: manager.cpp:144
mock_char c
const std::set< std::string > & members() const
Definition: lobby_data.hpp:76
void finalize_setup()
Initializes the internal sub-widget pointers.
Definition: chatbox.cpp:78
void open_room(const std::string &name)
Open a new chat room with the given name.
Definition: lobby_info.cpp:319
#define DBG_GUI_G
Definition: log.hpp:40
virtual void send_chat_room_message(const std::string &room, const std::string &message)
bool word_completion(std::string &text, std::vector< std::string > &wordlist)
Try to complete the last word of &#39;text&#39; with the &#39;wordlist&#39;.
lobby_chat_window * room_window_open(const std::string &room, const bool open_new, const bool allow_close=true)
Check if a room window for "room" is open, if open_new is true then it will be created if not found...
Definition: chatbox.cpp:385
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
ui_event
The event send to the dispatcher.
Definition: handler.hpp:47
static plugins_manager * get()
Definition: manager.cpp:58
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:384
void process_room_members(const config &data)
Definition: lobby_data.cpp:101
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.
auto * ss
Definition: result_set.cpp:281
void close_window(std::size_t idx)
Definition: chatbox.cpp:533
void add_whisper_window_whisper(const std::string &sender, const std::string &message)
Add a whisper message to the whisper window.
Definition: chatbox.cpp:513
void add_member(const std::string &user)
Definition: lobby_data.cpp:91