diff options
author | Brendan Coles <bcoles@gmail.com> | 2020-04-08 17:12:37 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-08 19:53:40 +0200 |
commit | 5c90cfa90f644be90e1dad8a48920f7b58aa742e (patch) | |
tree | 6a71ea267f6b27b14ad5f6f1b07c44fe7e8a665a | |
parent | 755b2066185016d0408dc63424064bfc229df791 (diff) | |
download | serenity-5c90cfa90f644be90e1dad8a48920f7b58aa742e.zip |
IRCClient: Add application and context menu items to hop/dehop users
-rw-r--r-- | Applications/IRCClient/IRCAppWindow.cpp | 24 | ||||
-rw-r--r-- | Applications/IRCClient/IRCAppWindow.h | 2 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.cpp | 20 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.h | 4 | ||||
-rw-r--r-- | Applications/IRCClient/IRCWindow.cpp | 14 |
5 files changed, 64 insertions, 0 deletions
diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index 6b71136d10..f9a388bb7e 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -196,6 +196,26 @@ void IRCAppWindow::setup_actions() m_client->handle_devoice_user_action(window->channel().name(), input_box->text_value()); }); + m_hop_user_action = GUI::Action::create("Hop user", [this](auto&) { + auto* window = m_client->current_window(); + if (!window || window->type() != IRCWindow::Type::Channel) { + return; + } + auto input_box = GUI::InputBox::construct("Enter nick:", "Hop user", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) + m_client->handle_hop_user_action(window->channel().name(), input_box->text_value()); + }); + + m_dehop_user_action = GUI::Action::create("DeHop user", [this](auto&) { + auto* window = m_client->current_window(); + if (!window || window->type() != IRCWindow::Type::Channel) { + return; + } + auto input_box = GUI::InputBox::construct("Enter nick:", "DeHop user", this); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) + m_client->handle_dehop_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) { @@ -264,6 +284,8 @@ void IRCAppWindow::setup_menus() 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_hop_user_action); + channel_menu.add_action(*m_dehop_user_action); channel_menu.add_action(*m_op_user_action); channel_menu.add_action(*m_deop_user_action); channel_menu.add_separator(); @@ -341,6 +363,8 @@ void IRCAppWindow::update_gui_actions() m_banlist_action->set_enabled(is_open_channel); m_voice_user_action->set_enabled(is_open_channel); m_devoice_user_action->set_enabled(is_open_channel); + m_hop_user_action->set_enabled(is_open_channel); + m_dehop_user_action->set_enabled(is_open_channel); m_op_user_action->set_enabled(is_open_channel); m_deop_user_action->set_enabled(is_open_channel); m_kick_user_action->set_enabled(is_open_channel); diff --git a/Applications/IRCClient/IRCAppWindow.h b/Applications/IRCClient/IRCAppWindow.h index 71a4ed631e..2faedf0cf0 100644 --- a/Applications/IRCClient/IRCAppWindow.h +++ b/Applications/IRCClient/IRCAppWindow.h @@ -67,6 +67,8 @@ private: RefPtr<GUI::Action> m_banlist_action; RefPtr<GUI::Action> m_voice_user_action; RefPtr<GUI::Action> m_devoice_user_action; + RefPtr<GUI::Action> m_hop_user_action; + RefPtr<GUI::Action> m_dehop_user_action; RefPtr<GUI::Action> m_op_user_action; RefPtr<GUI::Action> m_deop_user_action; RefPtr<GUI::Action> m_kick_user_action; diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index c00d814654..820a727d53 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -367,6 +367,16 @@ 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_hop_user(const String& channel_name, const String& nick) +{ + send(String::format("MODE %s +h %s\r\n", channel_name.characters(), nick.characters())); +} + +void IRCClient::send_dehop_user(const String& channel_name, const String& nick) +{ + send(String::format("MODE %s -h %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())); @@ -1008,6 +1018,16 @@ void IRCClient::handle_devoice_user_action(const String& channel, const String& send_devoice_user(channel, nick); } +void IRCClient::handle_hop_user_action(const String& channel, const String& nick) +{ + send_hop_user(channel, nick); +} + +void IRCClient::handle_dehop_user_action(const String& channel, const String& nick) +{ + send_dehop_user(channel, nick); +} + void IRCClient::handle_op_user_action(const String& channel, const String& nick) { send_op_user(channel, nick); diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index a9a3b81e22..141786e41f 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -118,6 +118,8 @@ public: void handle_banlist_action(const String& channel_name); 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_hop_user_action(const String& channel_name, const String& nick); + void handle_dehop_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&); @@ -154,6 +156,8 @@ private: void send_banlist(const String& channel_name); void send_voice_user(const String& channel_name, const String& nick); void send_devoice_user(const String& channel_name, const String& nick); + void send_hop_user(const String& channel_name, const String& nick); + void send_dehop_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&); diff --git a/Applications/IRCClient/IRCWindow.cpp b/Applications/IRCClient/IRCWindow.cpp index 68742817ed..04ffb57a0d 100644 --- a/Applications/IRCClient/IRCWindow.cpp +++ b/Applications/IRCClient/IRCWindow.cpp @@ -107,6 +107,20 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na m_client.handle_devoice_user_action(m_name.characters(), m_client.nick_without_prefix(nick.characters())); })); + m_context_menu->add_action(GUI::Action::create("Hop", [&](const GUI::Action&) { + auto nick = channel().member_model()->nick_at(member_view.selection().first()); + if (nick.is_empty()) + return; + m_client.handle_hop_user_action(m_name.characters(), m_client.nick_without_prefix(nick.characters())); + })); + + m_context_menu->add_action(GUI::Action::create("DeHop", [&](const GUI::Action&) { + auto nick = channel().member_model()->nick_at(member_view.selection().first()); + if (nick.is_empty()) + return; + m_client.handle_dehop_user_action(m_name.characters(), m_client.nick_without_prefix(nick.characters())); + })); + m_context_menu->add_action(GUI::Action::create("Op", [&](const GUI::Action&) { auto nick = channel().member_model()->nick_at(member_view.selection().first()); if (nick.is_empty()) |