Przeglądaj źródła

IRCClient: Add application and context menu items to hop/dehop users

Brendan Coles 5 lat temu
rodzic
commit
5c90cfa90f

+ 24 - 0
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);

+ 2 - 0
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;

+ 20 - 0
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);

+ 4 - 0
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&);

+ 14 - 0
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())