summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Applications/IRCClient/IRCWindow.cpp88
-rw-r--r--Applications/IRCClient/IRCWindow.h1
2 files changed, 89 insertions, 0 deletions
diff --git a/Applications/IRCClient/IRCWindow.cpp b/Applications/IRCClient/IRCWindow.cpp
index 8fbca5a57e..c3dc4e2e4e 100644
--- a/Applications/IRCClient/IRCWindow.cpp
+++ b/Applications/IRCClient/IRCWindow.cpp
@@ -29,7 +29,10 @@
#include "IRCChannelMemberListModel.h"
#include "IRCClient.h"
#include <AK/StringBuilder.h>
+#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
+#include <LibGUI/Menu.h>
+#include <LibGUI/InputBox.h>
#include <LibGUI/Notification.h>
#include <LibGUI/Splitter.h>
#include <LibGUI/TableView.h>
@@ -59,6 +62,91 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
member_view.set_alternating_row_colors(false);
member_view.set_model(channel().member_model());
member_view.set_activates_on_selection(true);
+ member_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
+ if (!index.is_valid())
+ return;
+
+ m_context_menu = GUI::Menu::construct();
+
+ m_context_menu->add_action(GUI::Action::create("Open query", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-open-query.png"), [&](const GUI::Action&) {
+ GUI::ModelIndex new_index = member_view.selection().first();
+ auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
+ if (nick.is_empty())
+ return;
+ if (IRCClient::is_nick_prefix(nick[0]))
+ nick = nick.substring(1, nick.length() - 1);
+ m_client.handle_open_query_action(nick.characters());
+ }));
+
+ m_context_menu->add_action(GUI::Action::create("Whois", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-whois.png"), [&](const GUI::Action&) {
+ GUI::ModelIndex new_index = member_view.selection().first();
+ auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
+ if (nick.is_empty())
+ return;
+ if (IRCClient::is_nick_prefix(nick[0]))
+ nick = nick.substring(1, nick.length() - 1);
+ m_client.handle_whois_action(nick.characters());
+ }));
+
+ m_context_menu->add_separator();
+
+ m_context_menu->add_action(GUI::Action::create("Voice", [&](const GUI::Action&) {
+ GUI::ModelIndex new_index = member_view.selection().first();
+ auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
+ if (nick.is_empty())
+ return;
+ if (IRCClient::is_nick_prefix(nick[0]))
+ nick = nick.substring(1, nick.length() - 1);
+ auto input_box = GUI::InputBox::construct("Enter reason:", "Reason");
+ m_client.handle_voice_user_action(m_name.characters(), nick.characters());
+ }));
+
+ m_context_menu->add_action(GUI::Action::create("DeVoice", [&](const GUI::Action&) {
+ GUI::ModelIndex new_index = member_view.selection().first();
+ auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
+ if (nick.is_empty())
+ return;
+ if (IRCClient::is_nick_prefix(nick[0]))
+ nick = nick.substring(1, nick.length() - 1);
+ m_client.handle_devoice_user_action(m_name.characters(), nick.characters());
+ }));
+
+ m_context_menu->add_action(GUI::Action::create("Op", [&](const GUI::Action&) {
+ GUI::ModelIndex new_index = member_view.selection().first();
+ auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
+ if (nick.is_empty())
+ return;
+ if (IRCClient::is_nick_prefix(nick[0]))
+ nick = nick.substring(1, nick.length() - 1);
+ m_client.handle_op_user_action(m_name.characters(), nick.characters());
+ }));
+
+ m_context_menu->add_action(GUI::Action::create("DeOp", [&](const GUI::Action&) {
+ GUI::ModelIndex new_index = member_view.selection().first();
+ auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
+ if (nick.is_empty())
+ return;
+ if (IRCClient::is_nick_prefix(nick[0]))
+ nick = nick.substring(1, nick.length() - 1);
+ m_client.handle_deop_user_action(m_name.characters(), nick.characters());
+ }));
+
+ m_context_menu->add_separator();
+
+ m_context_menu->add_action(GUI::Action::create("Kick", [&](const GUI::Action&) {
+ GUI::ModelIndex new_index = member_view.selection().first();
+ auto nick = member_view.model()->data(new_index, IRCChannelMemberListModel::Role::Display).to_string();
+ if (nick.is_empty())
+ return;
+ if (IRCClient::is_nick_prefix(nick[0]))
+ nick = nick.substring(1, nick.length() - 1);
+ auto input_box = GUI::InputBox::construct("Enter reason:", "Reason");
+ if (input_box->exec() == GUI::InputBox::ExecOK)
+ m_client.handle_kick_user_action(m_name.characters(), nick.characters(), input_box->text_value());
+ }));
+
+ m_context_menu->popup(event.screen_position());
+ };
}
m_text_editor = add<GUI::TextBox>();
diff --git a/Applications/IRCClient/IRCWindow.h b/Applications/IRCClient/IRCWindow.h
index ca8369b8bb..137ea90991 100644
--- a/Applications/IRCClient/IRCWindow.h
+++ b/Applications/IRCClient/IRCWindow.h
@@ -77,5 +77,6 @@ private:
RefPtr<Web::HtmlView> m_html_view;
RefPtr<GUI::TextEditor> m_text_editor;
RefPtr<IRCLogBuffer> m_log_buffer;
+ RefPtr<GUI::Menu> m_context_menu;
int m_unread_count { 0 };
};