From c3369f03043ec5f2a9b4ff5b3b7cc5a3ee6004d1 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Fri, 22 Dec 2017 12:21:57 +0100 Subject: [PATCH] ability to call ad hoc commands on groupchats and groupchats occupants. Fixes #8819 --- gajim/data/gui/gc_occupants_menu.ui | 10 +++++++++- gajim/groupchat_control.py | 20 ++++++++++++++++++++ gajim/gui_menu_builder.py | 1 + gajim/roster_window.py | 10 +++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/gajim/data/gui/gc_occupants_menu.ui b/gajim/data/gui/gc_occupants_menu.ui index 1c2824474..584de7b29 100644 --- a/gajim/data/gui/gc_occupants_menu.ui +++ b/gajim/data/gui/gc_occupants_menu.ui @@ -1,5 +1,5 @@ - + @@ -125,6 +125,14 @@ True + + + True + False + _Execute command + True + + True diff --git a/gajim/groupchat_control.py b/gajim/groupchat_control.py index 6741d57d4..64e31ae02 100644 --- a/gajim/groupchat_control.py +++ b/gajim/groupchat_control.py @@ -46,6 +46,7 @@ from gajim import config from gajim import vcard from gajim import cell_renderer_image from gajim import dataforms_widget +from gajim import adhoc_commands from gajim.common.const import AvatarSize from gajim.common.caps_cache import muc_caps_cache import nbxmpp @@ -514,6 +515,7 @@ class GroupchatControl(ChatControlBase): ('configure-', self._on_configure_room), ('bookmark-', self._on_bookmark_room), ('request-voice-', self._on_request_voice), + ('execute-command-', self._on_execute_command), ] for action in actions: @@ -582,6 +584,10 @@ class GroupchatControl(ChatControlBase): win.lookup_action('change-nick-' + self.control_id).set_enabled( online) + # Execute command + win.lookup_action('execute-command-' + self.control_id).set_enabled( + online) + # Actions def _on_change_subject(self, action, param): @@ -679,6 +685,12 @@ class GroupchatControl(ChatControlBase): app.config.set_per('rooms', self.contact.jid, 'notify_on_all_messages', param.get_boolean()) + def _on_execute_command(self, action, param): + """ + Execute AdHoc commands on the current room + """ + adhoc_commands.CommandWindow(self.account, self.room_jid) + def show_roster(self): new_state = not self.hpaned.get_child2().is_visible() image = self.hide_roster_button.get_image() @@ -2560,6 +2572,10 @@ class GroupchatControl(ChatControlBase): id_ = item.connect('activate', self.on_add_to_roster, jid) self.handlers[id_] = item + item = xml.get_object('execute_command_menuitem') + id_ = item.connect('activate', self._on_execute_command_occupant, nick) + self.handlers[id_] = item + item = xml.get_object('block_menuitem') item2 = xml.get_object('unblock_menuitem') if not app.connections[self.account].privacy_rules_supported: @@ -2608,6 +2624,10 @@ class GroupchatControl(ChatControlBase): return ctrl + def _on_execute_command_occupant(self, widget, nick): + jid = self.room_jid + '/' + nick + adhoc_commands.CommandWindow(self.account, jid) + def on_row_activated(self, widget, path): """ When an iter is activated (dubblick or single click if gnome is set this diff --git a/gajim/gui_menu_builder.py b/gajim/gui_menu_builder.py index b70460fe4..2477ddc1a 100644 --- a/gajim/gui_menu_builder.py +++ b/gajim/gui_menu_builder.py @@ -642,6 +642,7 @@ def get_groupchat_menu(control_id): ('win.request-voice-', _('Request Voice')), ('win.notify-on-message-', _('Notify on all messages')), ('win.minimize-', _('Minimize on close')), + ('win.execute-command-', _('Execute command')), ('win.browse-history-', _('History')), ('win.disconnect-', _('Disconnect')), ] diff --git a/gajim/roster_window.py b/gajim/roster_window.py index e3a97d950..7edaa55ab 100644 --- a/gajim/roster_window.py +++ b/gajim/roster_window.py @@ -5389,8 +5389,16 @@ class RosterWindow: item = Gtk.SeparatorMenuItem.new() # separator menu.append(item) + adhoc_menuitem = Gtk.MenuItem.new_with_mnemonic(_('Execute command')) + adhoc_menuitem.connect('activate', self.on_execute_command, contact, + account) + menu.append(adhoc_menuitem) + + item = Gtk.SeparatorMenuItem.new() # separator + menu.append(item) + history_menuitem = Gtk.MenuItem.new_with_mnemonic(_('_History')) - history_menuitem .connect('activate', self.on_history, contact, account) + history_menuitem.connect('activate', self.on_history, contact, account) menu.append(history_menuitem) event_button = gtkgui_helpers.get_possible_button_event(event)