1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:07:34 +00:00

IRCClient: Implement the "part from channel" action.

Also make sure the action is disabled while we're not in a window that
corresponds to an open channel. :^)

Fixes #277.
This commit is contained in:
Andreas Kling 2019-07-07 21:51:08 +02:00
parent d47432487d
commit ea9340aeca
5 changed files with 32 additions and 2 deletions

View file

@ -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);