IRCWindow.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "IRCWindow.h"
  2. #include "IRCChannel.h"
  3. #include "IRCChannelMemberListModel.h"
  4. #include "IRCClient.h"
  5. #include <LibGUI/GBoxLayout.h>
  6. #include <LibGUI/GSplitter.h>
  7. #include <LibGUI/GTableView.h>
  8. #include <LibGUI/GTextBox.h>
  9. #include <LibGUI/GTextEditor.h>
  10. #include <LibHTML/HtmlView.h>
  11. IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& name, GWidget* parent)
  12. : GWidget(parent)
  13. , m_client(client)
  14. , m_owner(owner)
  15. , m_type(type)
  16. , m_name(name)
  17. {
  18. set_layout(make<GBoxLayout>(Orientation::Vertical));
  19. // Make a container for the log buffer view + (optional) member list.
  20. auto container = GSplitter::construct(Orientation::Horizontal, this);
  21. m_html_view = HtmlView::construct(container);
  22. if (m_type == Channel) {
  23. auto member_view = GTableView::construct(container);
  24. member_view->set_headers_visible(false);
  25. member_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
  26. member_view->set_preferred_size(100, 0);
  27. member_view->set_alternating_row_colors(false);
  28. member_view->set_model(channel().member_model());
  29. member_view->set_activates_on_selection(true);
  30. }
  31. m_text_editor = GTextEditor::construct(GTextEditor::SingleLine, this);
  32. m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
  33. m_text_editor->set_preferred_size(0, 19);
  34. m_text_editor->on_return_pressed = [this] {
  35. if (m_type == Channel)
  36. m_client.handle_user_input_in_channel(m_name, m_text_editor->text());
  37. else if (m_type == Query)
  38. m_client.handle_user_input_in_query(m_name, m_text_editor->text());
  39. else if (m_type == Server)
  40. m_client.handle_user_input_in_server(m_text_editor->text());
  41. m_text_editor->clear();
  42. };
  43. m_client.register_subwindow(*this);
  44. }
  45. IRCWindow::~IRCWindow()
  46. {
  47. m_client.unregister_subwindow(*this);
  48. }
  49. void IRCWindow::set_log_buffer(const IRCLogBuffer& log_buffer)
  50. {
  51. m_log_buffer = &log_buffer;
  52. m_html_view->set_document(const_cast<Document*>(&log_buffer.document()));
  53. }
  54. bool IRCWindow::is_active() const
  55. {
  56. return m_client.current_window() == this;
  57. }
  58. void IRCWindow::did_add_message()
  59. {
  60. if (!is_active()) {
  61. ++m_unread_count;
  62. m_client.aid_update_window_list();
  63. return;
  64. }
  65. m_html_view->scroll_to_bottom();
  66. }
  67. void IRCWindow::clear_unread_count()
  68. {
  69. if (!m_unread_count)
  70. return;
  71. m_unread_count = 0;
  72. m_client.aid_update_window_list();
  73. }
  74. int IRCWindow::unread_count() const
  75. {
  76. return m_unread_count;
  77. }