mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +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:
parent
d47432487d
commit
ea9340aeca
5 changed files with 32 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include "IRCAppWindow.h"
|
#include "IRCAppWindow.h"
|
||||||
|
#include "IRCChannel.h"
|
||||||
#include "IRCWindow.h"
|
#include "IRCWindow.h"
|
||||||
#include "IRCWindowListModel.h"
|
#include "IRCWindowListModel.h"
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
|
@ -48,6 +49,9 @@ void IRCAppWindow::setup_client()
|
||||||
m_client.on_nickname_changed = [this](const String&) {
|
m_client.on_nickname_changed = [this](const String&) {
|
||||||
update_title();
|
update_title();
|
||||||
};
|
};
|
||||||
|
m_client.on_part_from_channel = [this](auto&) {
|
||||||
|
update_part_action();
|
||||||
|
};
|
||||||
|
|
||||||
if (m_client.hostname().is_empty()) {
|
if (m_client.hostname().is_empty()) {
|
||||||
GInputBox input_box("Enter server:", "Connect to server", this);
|
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_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&) {
|
m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-part.png"), [this](auto&) {
|
||||||
printf("FIXME: Implement part action\n");
|
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&) {
|
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 = new GStackWidget(horizontal_container);
|
||||||
|
m_container->on_active_widget_change = [this](auto*) {
|
||||||
|
update_part_action();
|
||||||
|
};
|
||||||
|
|
||||||
create_window(&m_client, IRCWindow::Server, "Server");
|
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)
|
IRCWindow& IRCAppWindow::create_window(void* owner, IRCWindow::Type type, const String& name)
|
||||||
{
|
{
|
||||||
return *new IRCWindow(m_client, owner, type, name, m_container);
|
return *new IRCWindow(m_client, owner, type, name, m_container);
|
||||||
|
|
|
@ -19,6 +19,7 @@ private:
|
||||||
void setup_menus();
|
void setup_menus();
|
||||||
void setup_widgets();
|
void setup_widgets();
|
||||||
void update_title();
|
void update_title();
|
||||||
|
void update_part_action();
|
||||||
|
|
||||||
IRCWindow& create_window(void* owner, IRCWindow::Type, const String& name);
|
IRCWindow& create_window(void* owner, IRCWindow::Type, const String& name);
|
||||||
IRCClient m_client;
|
IRCClient m_client;
|
||||||
|
|
|
@ -78,6 +78,7 @@ void IRCChannel::handle_part(const String& nick, const String& hostmask)
|
||||||
if (nick == m_client.nickname()) {
|
if (nick == m_client.nickname()) {
|
||||||
m_open = false;
|
m_open = false;
|
||||||
m_members.clear();
|
m_members.clear();
|
||||||
|
m_client.did_part_from_channel({}, *this);
|
||||||
} else {
|
} else {
|
||||||
remove_member(nick);
|
remove_member(nick);
|
||||||
}
|
}
|
||||||
|
|
|
@ -647,3 +647,9 @@ void IRCClient::handle_part_action(const String& channel)
|
||||||
{
|
{
|
||||||
part_channel(channel);
|
part_channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IRCClient::did_part_from_channel(IRCChannel& channel)
|
||||||
|
{
|
||||||
|
if (on_part_from_channel)
|
||||||
|
on_part_from_channel(channel);
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
Function<void()> on_disconnect;
|
Function<void()> on_disconnect;
|
||||||
Function<void()> on_server_message;
|
Function<void()> on_server_message;
|
||||||
Function<void(const String&)> on_nickname_changed;
|
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*(void*, IRCWindow::Type, const String&)> aid_create_window;
|
||||||
Function<IRCWindow*()> aid_get_active_window;
|
Function<IRCWindow*()> aid_get_active_window;
|
||||||
|
@ -59,6 +60,8 @@ public:
|
||||||
const IRCWindow& window_at(int index) const { return *m_windows.at(index); }
|
const IRCWindow& window_at(int index) const { return *m_windows.at(index); }
|
||||||
IRCWindow& window_at(int index) { 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_channel(const String& channel_name, const String&);
|
||||||
void handle_user_input_in_query(const String& query_name, const String&);
|
void handle_user_input_in_query(const String& query_name, const String&);
|
||||||
void handle_user_input_in_server(const String&);
|
void handle_user_input_in_server(const String&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue