1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 15:27:42 +00:00

IRCClient: Start using GStackWidget for the subwindows.

This commit is contained in:
Andreas Kling 2019-03-15 16:12:51 +01:00
parent 497300c492
commit 1089cd1378
5 changed files with 22 additions and 20 deletions

View file

@ -1,6 +1,7 @@
#include "IRCAppWindow.h" #include "IRCAppWindow.h"
#include "IRCClientWindow.h" #include "IRCClientWindow.h"
#include "IRCClientWindowListModel.h" #include "IRCClientWindowListModel.h"
#include <LibGUI/GStackWidget.h>
#include <LibGUI/GTableView.h> #include <LibGUI/GTableView.h>
#include <LibGUI/GBoxLayout.h> #include <LibGUI/GBoxLayout.h>
@ -28,14 +29,6 @@ void IRCAppWindow::setup_client()
ensure_window(IRCClientWindow::Channel, channel_name); ensure_window(IRCClientWindow::Channel, channel_name);
}; };
m_client.on_query_message = [this] (const String& name) {
// FIXME: Update query view.
};
m_client.on_channel_message = [this] (const String& channel_name) {
// FIXME: Update channel view.
};
m_client.connect(); m_client.connect();
} }
@ -46,22 +39,23 @@ void IRCAppWindow::setup_widgets()
set_main_widget(widget); set_main_widget(widget);
widget->set_layout(make<GBoxLayout>(Orientation::Horizontal)); widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
auto* subwindow_list = new GTableView(widget); auto* window_list = new GTableView(widget);
subwindow_list->set_headers_visible(false); window_list->set_headers_visible(false);
subwindow_list->set_model(OwnPtr<IRCClientWindowListModel>(m_client.client_window_list_model())); window_list->set_model(OwnPtr<IRCClientWindowListModel>(m_client.client_window_list_model()));
subwindow_list->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); window_list->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
subwindow_list->set_preferred_size({ 120, 0 }); window_list->set_preferred_size({ 120, 0 });
m_client.client_window_list_model()->on_activation = [this] (IRCClientWindow& window) {
m_container->set_active_widget(&window);
};
m_subwindow_container = new GWidget(widget); m_container = new GStackWidget(widget);
m_subwindow_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
m_subwindow_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
create_subwindow(IRCClientWindow::Server, "Server"); create_subwindow(IRCClientWindow::Server, "Server");
} }
IRCClientWindow& IRCAppWindow::create_subwindow(IRCClientWindow::Type type, const String& name) IRCClientWindow& IRCAppWindow::create_subwindow(IRCClientWindow::Type type, const String& name)
{ {
return *new IRCClientWindow(m_client, type, name, m_subwindow_container); return *new IRCClientWindow(m_client, type, name, m_container);
} }
IRCClientWindow& IRCAppWindow::ensure_window(IRCClientWindow::Type type, const String& name) IRCClientWindow& IRCAppWindow::ensure_window(IRCClientWindow::Type type, const String& name)

View file

@ -5,6 +5,8 @@
#include "IRCClient.h" #include "IRCClient.h"
#include "IRCClientWindow.h" #include "IRCClientWindow.h"
class GStackWidget;
class IRCAppWindow : public GWindow { class IRCAppWindow : public GWindow {
public: public:
IRCAppWindow(); IRCAppWindow();
@ -19,5 +21,5 @@ private:
IRCClient m_client; IRCClient m_client;
GWidget* m_subwindow_container { nullptr }; GStackWidget* m_container { nullptr };
}; };

View file

@ -199,7 +199,7 @@ void IRCClient::join_channel(const String& channel_name)
send(String::format("JOIN %s\r\n", channel_name.characters())); send(String::format("JOIN %s\r\n", channel_name.characters()));
} }
void IRCClient::handle(const Message& msg, const String& verbatim) void IRCClient::handle(const Message& msg, const String&)
{ {
printf("IRCClient::execute: prefix='%s', command='%s', arguments=%d\n", printf("IRCClient::execute: prefix='%s', command='%s', arguments=%d\n",
msg.prefix.characters(), msg.prefix.characters(),

View file

@ -52,6 +52,8 @@ void IRCClientWindowListModel::update()
did_update(); did_update();
} }
void IRCClientWindowListModel::activate(const GModelIndex&) void IRCClientWindowListModel::activate(const GModelIndex& index)
{ {
if (on_activation)
on_activation(m_client.window_at(index.row()));
} }

View file

@ -1,8 +1,10 @@
#pragma once #pragma once
#include <LibGUI/GTableModel.h> #include <LibGUI/GTableModel.h>
#include <AK/Function.h>
class IRCClient; class IRCClient;
class IRCClientWindow;
class IRCClientWindowListModel final : public GTableModel { class IRCClientWindowListModel final : public GTableModel {
public: public:
@ -21,6 +23,8 @@ public:
virtual void update() override; virtual void update() override;
virtual void activate(const GModelIndex&) override; virtual void activate(const GModelIndex&) override;
Function<void(IRCClientWindow&)> on_activation;
private: private:
IRCClient& m_client; IRCClient& m_client;
}; };