diff options
-rw-r--r-- | Applications/IRCClient/IRCAppWindow.cpp | 23 | ||||
-rw-r--r-- | Applications/IRCClient/IRCAppWindow.h | 1 | ||||
-rw-r--r-- | Applications/IRCClient/IRCChannel.cpp | 1 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.cpp | 6 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.h | 3 |
5 files changed, 32 insertions, 2 deletions
diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index 37bd471571..36ce7ee383 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -1,4 +1,5 @@ #include "IRCAppWindow.h" +#include "IRCChannel.h" #include "IRCWindow.h" #include "IRCWindowListModel.h" #include <LibGUI/GAction.h> @@ -48,6 +49,9 @@ void IRCAppWindow::setup_client() m_client.on_nickname_changed = [this](const String&) { update_title(); }; + m_client.on_part_from_channel = [this](auto&) { + update_part_action(); + }; if (m_client.hostname().is_empty()) { GInputBox input_box("Enter server:", "Connect to server", this); @@ -70,8 +74,13 @@ void IRCAppWindow::setup_actions() m_client.handle_join_action(input_box.text_value()); }); - m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-part.png"), [](auto&) { - printf("FIXME: Implement part action\n"); + m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-part.png"), [this](auto&) { + auto* window = m_client.current_window(); + if (!window || window->type() != IRCWindow::Type::Channel) { + // FIXME: Perhaps this action should have been disabled instead of allowing us to activate it. + return; + } + m_client.handle_part_action(window->channel().name()); }); m_whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-whois.png"), [&](auto&) { @@ -163,10 +172,20 @@ void IRCAppWindow::setup_widgets() }; m_container = new GStackWidget(horizontal_container); + m_container->on_active_widget_change = [this](auto*) { + update_part_action(); + }; create_window(&m_client, IRCWindow::Server, "Server"); } +void IRCAppWindow::update_part_action() +{ + auto* window = static_cast<IRCWindow*>(m_container->active_widget()); + bool is_open_channel = window && window->type() == IRCWindow::Type::Channel && window->channel().is_open(); + m_part_action->set_enabled(is_open_channel); +} + IRCWindow& IRCAppWindow::create_window(void* owner, IRCWindow::Type type, const String& name) { return *new IRCWindow(m_client, owner, type, name, m_container); diff --git a/Applications/IRCClient/IRCAppWindow.h b/Applications/IRCClient/IRCAppWindow.h index 1d376f164a..128371c42d 100644 --- a/Applications/IRCClient/IRCAppWindow.h +++ b/Applications/IRCClient/IRCAppWindow.h @@ -19,6 +19,7 @@ private: void setup_menus(); void setup_widgets(); void update_title(); + void update_part_action(); IRCWindow& create_window(void* owner, IRCWindow::Type, const String& name); IRCClient m_client; diff --git a/Applications/IRCClient/IRCChannel.cpp b/Applications/IRCClient/IRCChannel.cpp index 75bf4c7d76..df9756b795 100644 --- a/Applications/IRCClient/IRCChannel.cpp +++ b/Applications/IRCClient/IRCChannel.cpp @@ -78,6 +78,7 @@ void IRCChannel::handle_part(const String& nick, const String& hostmask) if (nick == m_client.nickname()) { m_open = false; m_members.clear(); + m_client.did_part_from_channel({}, *this); } else { remove_member(nick); } diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index 9a89780622..7afeddaa8d 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -647,3 +647,9 @@ void IRCClient::handle_part_action(const String& channel) { part_channel(channel); } + +void IRCClient::did_part_from_channel(IRCChannel& channel) +{ + if (on_part_from_channel) + on_part_from_channel(channel); +} diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index d591f4b527..e72b7cfc7a 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -44,6 +44,7 @@ public: Function<void()> on_disconnect; Function<void()> on_server_message; Function<void(const String&)> on_nickname_changed; + Function<void(IRCChannel&)> on_part_from_channel; Function<IRCWindow*(void*, IRCWindow::Type, const String&)> aid_create_window; Function<IRCWindow*()> aid_get_active_window; @@ -59,6 +60,8 @@ public: const IRCWindow& window_at(int index) const { return *m_windows.at(index); } IRCWindow& window_at(int index) { return *m_windows.at(index); } + void did_part_from_channel(Badge<IRCChannel>, IRCChannel&); + void handle_user_input_in_channel(const String& channel_name, const String&); void handle_user_input_in_query(const String& query_name, const String&); void handle_user_input_in_server(const String&); |