Commit ffa79c74 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Menu: Port groupchat roster menu to Gio.Menu

parent 863cd8f2
Pipeline #9031 passed with stages
in 4 minutes and 27 seconds
......@@ -365,27 +365,31 @@ def _on_roster_button_press_event(self,
return
if event.button == 3: # right click
self._show_contact_menu(nick)
rec = Gdk.Rectangle()
rec.x, rec.y = int(event.x), int(event.y)
rec.height, rec.width = 1, 1
self._show_contact_menu(nick, rec)
if event.button == 2: # middle click
self.emit('row-activated', nick)
def _show_contact_menu(self, nick: str) -> None:
def _show_contact_menu(self, nick: str, rect: Gdk.Rectangle) -> None:
self_contact = self._group_chat_contact.get_self()
assert self_contact is not None
contact = self._group_chat_contact.get_resource(nick)
menu = get_groupchat_roster_menu(self._account,
self._control_id,
self_contact,
contact)
def destroy(menu: Gtk.Menu, _pspec: GObject.ParamSpec) -> None:
visible = menu.get_property('visible')
if not visible:
GLib.idle_add(menu.destroy)
def destroy(popover: Gtk.Popover) -> None:
app.check_finalize(popover)
GLib.idle_add(popover.set_relative_to, None)
menu.attach_to_widget(self, None)
menu.connect('notify::visible', destroy)
menu.popup_at_pointer()
popover = Gtk.Popover.new_from_model(self, menu)
popover.set_pointing_to(rect)
popover.connect('closed', destroy)
popover.popup()
def _tree_compare_iters(self,
model: Gtk.TreeModel,
......
......@@ -525,107 +525,92 @@ def build_workspaces_submenu(current_workspace_id: str,
return submenu
def get_groupchat_roster_menu(account: str,
control_id: str,
self_contact: types.GroupchatParticipant,
contact: types.GroupchatParticipant
) -> Gtk.Menu:
menu = Gtk.Menu()
real_jid = ''
if contact.real_jid is not None:
real_jid = contact.real_jid.bare
item = Gtk.MenuItem(label=_('Information'))
action = f'win.contact-information-{control_id}::{contact.name}'
item.set_detailed_action_name(action)
menu.append(item)
item = Gtk.MenuItem(label=_('Add to Contact List…'))
action = f'app.{account}-add-contact(["{account}", "{real_jid}"])'
if contact.real_jid is None:
item.set_sensitive(False)
else:
item.set_detailed_action_name(action)
menu.append(item)
item = Gtk.MenuItem(label=_('Execute Command…'))
action = f'win.execute-command-{control_id}::{contact.name}'
item.set_detailed_action_name(action)
menu.append(item)
menu.append(Gtk.SeparatorMenuItem())
item = Gtk.MenuItem(label=_('Kick'))
action = f'win.kick-{control_id}::{contact.name}'
if is_role_change_allowed(self_contact, contact):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
menu.append(item)
def get_groupchat_admin_menu(control_id: str,
self_contact: types.GroupchatParticipant,
contact: types.GroupchatParticipant) -> Gio.Menu:
item = Gtk.MenuItem(label=_('Ban'))
action = f'win.ban-{control_id}::{real_jid}'
if is_affiliation_change_allowed(self_contact, contact, 'outcast'):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
menu.append(item)
adminitems: MenuItemListT = []
menu.append(Gtk.SeparatorMenuItem())
action = f'win.change-affiliation-{control_id}'
item = Gtk.MenuItem(label=_('Make Owner'))
action = (f'win.change-affiliation-{control_id}'
f'(["{contact.real_jid}", "owner"])')
if is_affiliation_change_allowed(self_contact, contact, 'owner'):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
menu.append(item)
value = f'["{contact.real_jid}", "owner"]'
adminitems.append((_('Make Owner'), action, value))
item = Gtk.MenuItem(label=_('Make Admin'))
action = (f'win.change-affiliation-{control_id}'
f'(["{contact.real_jid}", "admin"])')
if is_affiliation_change_allowed(self_contact, contact, 'admin'):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
menu.append(item)
value = f'["{contact.real_jid}", "admin"]'
adminitems.append((_('Make Admin'), action, value))
item = Gtk.MenuItem(label=_('Make Member'))
action = (f'win.change-affiliation-{control_id}'
f'(["{contact.real_jid}", "member"])')
if is_affiliation_change_allowed(self_contact, contact, 'member'):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
menu.append(item)
value = f'["{contact.real_jid}", "member"]'
adminitems.append((_('Make Member'), action, value))
item = Gtk.MenuItem(label=_('Revoke Member'))
action = (f'win.change-affiliation-{control_id}'
f'(["{contact.real_jid}", "none"])')
if is_affiliation_change_allowed(self_contact, contact, 'none'):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
menu.append(item)
value = f'["{contact.real_jid}", "none"]'
adminitems.append((_('Revoke Member'), action, value))
if contact.role.is_visitor:
label = _('Grant Voice')
role = 'participant'
else:
label = _('Revoke Voice')
role = 'visitor'
if is_affiliation_change_allowed(self_contact, contact, 'outcast'):
value = f'"{contact.real_jid}"'
adminitems.append((_('Ban…'), f'win.ban-{control_id}', value))
if not adminitems:
adminitems.append((_('Not Available'), 'dummy', None))
return make_menu(adminitems)
def get_groupchat_mod_menu(control_id: str,
self_contact: types.GroupchatParticipant,
contact: types.GroupchatParticipant
) -> Gio.Menu:
moditems: MenuItemListT = []
item = Gtk.MenuItem(label=label)
action = (f'win.change-role-{control_id}'
f'(["{contact.name}", "{role}"])')
if is_role_change_allowed(self_contact, contact):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
menu.append(item)
value = f'"{contact.name}"'
moditems.append((_('Kick…'), f'win.kick-{control_id}', value))
action = f'win.change-role-{control_id}'
if is_role_change_allowed(self_contact, contact):
if contact.role.is_visitor:
value = f'["{contact.name}", "participant"]'
moditems.append((_('Grant Voice'), action, value))
else:
value = f'["{contact.name}", "visitor"]'
moditems.append((_('Revoke Voice'), action, value))
if not moditems:
moditems.append((_('Not Available'), 'dummy', None))
return make_menu(moditems)
def get_groupchat_roster_menu(account: str,
control_id: str,
self_contact: types.GroupchatParticipant,
contact: types.GroupchatParticipant
) -> Gio.Menu:
value = f'"{contact.name}"'
general_items: MenuItemListT = [
(_('Information'), f'win.contact-information-{control_id}', value),
(_('Execute Command…'), f'win.execute-command-{control_id}', value),
]
real_contact = contact.get_real_contact()
if real_contact is not None and not real_contact.is_in_roster:
value = f'["{account}", "{real_contact.jid}"]'
action = f'app.{account}-add-contact'
general_items.insert(1, (_('Add to Contact List…'), action, value))
mod_menu = get_groupchat_mod_menu(control_id, self_contact, contact)
admin_menu = get_groupchat_admin_menu(control_id, self_contact, contact)
menu.show_all()
menu = make_menu(general_items)
menu.append_section(_('Moderation'), mod_menu)
menu.append_section(_('Administration'), admin_menu)
return menu
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment