From 855f9286fad4b1e6ab09345fb96f30cc9b9f568c Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Thu, 2 Apr 2020 10:03:42 +0000 Subject: [PATCH] IRCClient: Add channel operations to Channel application menu Add menu options to invite user, op/deop/voice/devoice user, and cycle channel. --- Applications/IRCClient/IRCAppWindow.cpp | 72 +++++++++++++++++++++++++ Applications/IRCClient/IRCAppWindow.h | 6 +++ Applications/IRCClient/IRCClient.cpp | 56 +++++++++++++++++++ Applications/IRCClient/IRCClient.h | 19 +++++-- 4 files changed, 149 insertions(+), 4 deletions(-) diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index 9fbac2f840..ca3b560247 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -160,6 +160,61 @@ void IRCAppWindow::setup_actions() m_client->handle_change_topic_action(window->channel().name(), input_box->text_value()); }); + m_invite_user_action = GUI::Action::create("Invite user", [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; + } + auto input_box = GUI::InputBox::construct("Enter nick:", "Invite user", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) + m_client->handle_invite_user_action(window->channel().name(), input_box->text_value()); + }); + + m_voice_user_action = GUI::Action::create("Voice user", [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; + } + auto input_box = GUI::InputBox::construct("Enter nick:", "Voice user", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) + m_client->handle_voice_user_action(window->channel().name(), input_box->text_value()); + }); + + m_devoice_user_action = GUI::Action::create("DeVoice user", [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; + } + auto input_box = GUI::InputBox::construct("Enter nick:", "DeVoice user", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) + m_client->handle_devoice_user_action(window->channel().name(), input_box->text_value()); + }); + + m_op_user_action = GUI::Action::create("Op user", [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; + } + auto input_box = GUI::InputBox::construct("Enter nick:", "Op user", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) + m_client->handle_op_user_action(window->channel().name(), input_box->text_value()); + }); + + m_deop_user_action = GUI::Action::create("DeOp user", [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; + } + auto input_box = GUI::InputBox::construct("Enter nick:", "DeOp user", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) + m_client->handle_deop_user_action(window->channel().name(), input_box->text_value()); + }); + m_kick_user_action = GUI::Action::create("Kick user", [this](auto&) { auto* window = m_client->current_window(); if (!window || window->type() != IRCWindow::Type::Channel) { @@ -172,6 +227,15 @@ void IRCAppWindow::setup_actions() if (reason_box->exec() == GUI::InputBox::ExecOK) m_client->handle_kick_user_action(window->channel().name(), input_box->text_value(), reason_box->text_value().characters()); }); + + m_cycle_channel_action = GUI::Action::create("Cycle channel", [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_cycle_channel_action(window->channel().name()); + }); } void IRCAppWindow::setup_menus() @@ -198,8 +262,16 @@ void IRCAppWindow::setup_menus() auto channel_menu = GUI::Menu::construct("Channel"); channel_menu->add_action(*m_change_topic_action); + channel_menu->add_action(*m_invite_user_action); + channel_menu->add_separator(); + channel_menu->add_action(*m_voice_user_action); + channel_menu->add_action(*m_devoice_user_action); + channel_menu->add_action(*m_op_user_action); + channel_menu->add_action(*m_deop_user_action); + channel_menu->add_separator(); channel_menu->add_action(*m_kick_user_action); channel_menu->add_separator(); + channel_menu->add_action(*m_cycle_channel_action); channel_menu->add_action(*m_part_action); menubar->add_menu(move(channel_menu)); diff --git a/Applications/IRCClient/IRCAppWindow.h b/Applications/IRCClient/IRCAppWindow.h index 249daa6ed7..3ec5b8b85f 100644 --- a/Applications/IRCClient/IRCAppWindow.h +++ b/Applications/IRCClient/IRCAppWindow.h @@ -57,10 +57,16 @@ private: RefPtr m_join_action; RefPtr m_list_channels_action; RefPtr m_part_action; + RefPtr m_cycle_channel_action; RefPtr m_whois_action; RefPtr m_open_query_action; RefPtr m_close_query_action; RefPtr m_change_nick_action; RefPtr m_change_topic_action; + RefPtr m_invite_user_action; + RefPtr m_voice_user_action; + RefPtr m_devoice_user_action; + RefPtr m_op_user_action; + RefPtr m_deop_user_action; RefPtr m_kick_user_action; }; diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index b2006da09d..bf8d8c1119 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -317,6 +317,31 @@ void IRCClient::send_topic(const String& channel_name, const String& text) send(String::format("TOPIC %s :%s\r\n", channel_name.characters(), text.characters())); } +void IRCClient::send_invite(const String& channel_name, const String& nick) +{ + send(String::format("INVITE %s %s\r\n", nick.characters(), channel_name.characters())); +} + +void IRCClient::send_voice_user(const String& channel_name, const String& nick) +{ + send(String::format("MODE %s +v %s\r\n", channel_name.characters(), nick.characters())); +} + +void IRCClient::send_devoice_user(const String& channel_name, const String& nick) +{ + send(String::format("MODE %s -v %s\r\n", channel_name.characters(), nick.characters())); +} + +void IRCClient::send_op_user(const String& channel_name, const String& nick) +{ + send(String::format("MODE %s +o %s\r\n", channel_name.characters(), nick.characters())); +} + +void IRCClient::send_deop_user(const String& channel_name, const String& nick) +{ + send(String::format("MODE %s -o %s\r\n", channel_name.characters(), nick.characters())); +} + void IRCClient::send_kick(const String& channel_name, const String& nick, const String& comment) { send(String::format("KICK %s %s :%s\r\n", channel_name.characters(), nick.characters(), comment.characters())); @@ -815,6 +840,31 @@ void IRCClient::handle_change_topic_action(const String& channel, const String& send_topic(channel, topic); } +void IRCClient::handle_invite_user_action(const String& channel, const String& nick) +{ + send_invite(channel, nick); +} + +void IRCClient::handle_voice_user_action(const String& channel, const String& nick) +{ + send_voice_user(channel, nick); +} + +void IRCClient::handle_devoice_user_action(const String& channel, const String& nick) +{ + send_devoice_user(channel, nick); +} + +void IRCClient::handle_op_user_action(const String& channel, const String& nick) +{ + send_op_user(channel, nick); +} + +void IRCClient::handle_deop_user_action(const String& channel, const String& nick) +{ + send_deop_user(channel, nick); +} + void IRCClient::handle_kick_user_action(const String& channel, const String& nick, const String& message) { send_kick(channel, nick, message); @@ -836,6 +886,12 @@ void IRCClient::handle_part_action(const String& channel) part_channel(channel); } +void IRCClient::handle_cycle_channel_action(const String& channel) +{ + part_channel(channel); + join_channel(channel); +} + void IRCClient::did_part_from_channel(Badge, IRCChannel& channel) { if (on_part_from_channel) diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index a463260606..b9eadecbea 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -100,13 +100,19 @@ public: void handle_user_input_in_server(const String&); void handle_list_channels_action(); - void handle_whois_action(const String&); + void handle_whois_action(const String& nick); void handle_open_query_action(const String&); void handle_close_query_action(const String&); - void handle_join_action(const String&); - void handle_part_action(const String&); - void handle_change_nick_action(const String&); + void handle_join_action(const String& channel_name); + void handle_part_action(const String& channel_name); + void handle_cycle_channel_action(const String& channel_name); + void handle_change_nick_action(const String& nick); void handle_change_topic_action(const String& channel_name, const String&); + void handle_invite_user_action(const String& channel_name, const String& nick); + void handle_voice_user_action(const String& channel_name, const String& nick); + void handle_devoice_user_action(const String& channel_name, const String& nick); + void handle_op_user_action(const String& channel_name, const String& nick); + void handle_deop_user_action(const String& channel_name, const String& nick); void handle_kick_user_action(const String& channel_name, const String& nick, const String&); IRCQuery* query_with_name(const String&); @@ -137,6 +143,11 @@ private: void send_privmsg(const String& target, const String&); void send_notice(const String& target, const String&); void send_topic(const String& channel_name, const String&); + void send_invite(const String& channel_name, const String& nick); + void send_voice_user(const String& channel_name, const String& nick); + void send_devoice_user(const String& channel_name, const String& nick); + void send_op_user(const String& channel_name, const String& nick); + void send_deop_user(const String& channel_name, const String& nick); void send_kick(const String& channel_name, const String& nick, const String&); void send_list(); void send_whois(const String&);