2018-09-05 02:59:34 +02:00
|
|
|
# Copyright (C) 2009-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2009-10-27 10:39:40 +01:00
|
|
|
|
2018-09-16 11:37:38 +02:00
|
|
|
from gi.repository import Gtk, Gio, GLib
|
2018-03-26 01:06:56 +02:00
|
|
|
from nbxmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC
|
2017-06-14 21:31:29 +02:00
|
|
|
from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER_5, NS_CONFERENCE
|
2018-09-16 11:37:38 +02:00
|
|
|
|
|
|
|
from gajim import gtkgui_helpers
|
|
|
|
from gajim import message_control
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.gtkgui_helpers import get_action
|
2018-09-16 11:37:38 +02:00
|
|
|
from gajim.common import app
|
|
|
|
from gajim.common import helpers
|
2018-09-15 20:45:38 +02:00
|
|
|
from gajim.common.i18n import ngettext
|
2018-10-04 23:55:35 +02:00
|
|
|
from gajim.common.i18n import _
|
2018-09-16 11:37:38 +02:00
|
|
|
|
2009-10-27 10:39:40 +01:00
|
|
|
|
|
|
|
def build_resources_submenu(contacts, account, action, room_jid=None,
|
2010-02-08 15:08:40 +01:00
|
|
|
room_account=None, cap=None):
|
|
|
|
"""
|
|
|
|
Build a submenu with contact's resources. room_jid and room_account are for
|
|
|
|
action self.on_invite_to_room
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
roster = app.interface.roster
|
2012-12-23 16:23:43 +01:00
|
|
|
sub_menu = Gtk.Menu()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
iconset = app.config.get('iconset')
|
2010-02-08 15:08:40 +01:00
|
|
|
if not iconset:
|
2017-08-13 13:18:56 +02:00
|
|
|
iconset = app.config.DEFAULT_ICONSET
|
2010-02-08 15:08:40 +01:00
|
|
|
for c in contacts:
|
2014-11-11 23:11:15 +01:00
|
|
|
item = Gtk.MenuItem.new_with_label(
|
2014-10-20 17:20:38 +02:00
|
|
|
'%s (%s)' % (c.resource, str(c.priority)))
|
2010-02-08 15:08:40 +01:00
|
|
|
sub_menu.append(item)
|
|
|
|
if action == roster.on_invite_to_room:
|
|
|
|
item.connect('activate', action, [(c, account)], room_jid,
|
|
|
|
room_account, c.resource)
|
|
|
|
elif action == roster.on_invite_to_new_room:
|
|
|
|
item.connect('activate', action, [(c, account)], c.resource)
|
|
|
|
else: # start_chat, execute_command, send_file
|
|
|
|
item.connect('activate', action, c, account, c.resource)
|
|
|
|
|
|
|
|
if cap and not c.supports(cap):
|
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
return sub_menu
|
2009-10-27 10:39:40 +01:00
|
|
|
|
2017-02-08 03:12:41 +01:00
|
|
|
def build_invite_submenu(invite_menuitem, list_, ignore_rooms=None,
|
2014-01-13 20:25:07 +01:00
|
|
|
show_bookmarked=False, force_resource=False):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
list_ in a list of (contact, account)
|
2014-01-13 20:25:07 +01:00
|
|
|
force_resource means we want to send invitation even if there is only one
|
|
|
|
resource
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2017-02-08 03:12:41 +01:00
|
|
|
if ignore_rooms is None:
|
|
|
|
ignore_rooms = []
|
2017-08-13 13:18:56 +02:00
|
|
|
roster = app.interface.roster
|
2010-02-08 15:08:40 +01:00
|
|
|
# used if we invite only one contact with several resources
|
|
|
|
contact_list = []
|
|
|
|
if len(list_) == 1:
|
|
|
|
contact, account = list_[0]
|
2017-08-13 13:18:56 +02:00
|
|
|
contact_list = app.contacts.get_contacts(account, contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
contacts_transport = -1
|
|
|
|
connected_accounts = []
|
|
|
|
# -1 is at start, False when not from the same, None when jabber
|
|
|
|
for (contact, account) in list_:
|
|
|
|
if not account in connected_accounts:
|
|
|
|
connected_accounts.append(account)
|
2017-08-13 13:18:56 +02:00
|
|
|
transport = app.get_transport_name_from_jid(contact.jid)
|
2013-08-29 21:28:58 +02:00
|
|
|
if transport == 'jabber':
|
|
|
|
transport = None
|
2010-02-08 15:08:40 +01:00
|
|
|
if contacts_transport == -1:
|
|
|
|
contacts_transport = transport
|
|
|
|
elif contacts_transport != transport:
|
|
|
|
contacts_transport = False
|
|
|
|
|
2018-09-18 10:26:27 +02:00
|
|
|
if contacts_transport is False:
|
2010-02-08 15:08:40 +01:00
|
|
|
# they are not all from the same transport
|
|
|
|
invite_menuitem.set_sensitive(False)
|
|
|
|
return
|
2012-12-23 16:23:43 +01:00
|
|
|
invite_to_submenu = Gtk.Menu()
|
2010-02-08 15:08:40 +01:00
|
|
|
invite_menuitem.set_submenu(invite_to_submenu)
|
2014-11-11 23:11:15 +01:00
|
|
|
invite_to_new_room_menuitem = Gtk.MenuItem.new_with_mnemonic(_(
|
2013-01-12 19:15:33 +01:00
|
|
|
'_New Group Chat'))
|
2010-02-08 15:08:40 +01:00
|
|
|
if len(contact_list) > 1: # several resources
|
|
|
|
invite_to_new_room_menuitem.set_submenu(build_resources_submenu(
|
2010-04-24 09:51:32 +02:00
|
|
|
contact_list, account, roster.on_invite_to_new_room, cap=NS_MUC))
|
2010-02-08 15:08:40 +01:00
|
|
|
elif len(list_) == 1 and contact.supports(NS_MUC):
|
|
|
|
invite_menuitem.set_sensitive(True)
|
|
|
|
# use resource if it's self contact
|
2017-08-13 13:18:56 +02:00
|
|
|
if contact.jid == app.get_jid_from_account(account) or force_resource:
|
2010-02-08 15:08:40 +01:00
|
|
|
resource = contact.resource
|
|
|
|
else:
|
|
|
|
resource = None
|
|
|
|
invite_to_new_room_menuitem.connect('activate',
|
2010-04-24 09:51:32 +02:00
|
|
|
roster.on_invite_to_new_room, list_, resource)
|
2013-11-01 12:08:05 +01:00
|
|
|
elif len(list_) > 1:
|
|
|
|
list2 = []
|
|
|
|
for (c, a) in list_:
|
|
|
|
if c.supports(NS_MUC):
|
|
|
|
list2.append((c, a))
|
2018-09-16 01:10:04 +02:00
|
|
|
if list2:
|
2013-11-01 12:08:05 +01:00
|
|
|
invite_to_new_room_menuitem.connect('activate',
|
|
|
|
roster.on_invite_to_new_room, list2, None)
|
|
|
|
else:
|
|
|
|
invite_menuitem.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2013-11-01 12:08:05 +01:00
|
|
|
invite_menuitem.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
# transform None in 'jabber'
|
|
|
|
c_t = contacts_transport or 'jabber'
|
|
|
|
muc_jid = {}
|
|
|
|
for account in connected_accounts:
|
2017-08-13 13:18:56 +02:00
|
|
|
for t in app.connections[account].muc_jid:
|
|
|
|
muc_jid[t] = app.connections[account].muc_jid[t]
|
2010-02-08 15:08:40 +01:00
|
|
|
if c_t not in muc_jid:
|
|
|
|
invite_to_new_room_menuitem.set_sensitive(False)
|
|
|
|
rooms = [] # a list of (room_jid, account) tuple
|
|
|
|
invite_to_submenu.append(invite_to_new_room_menuitem)
|
|
|
|
minimized_controls = []
|
|
|
|
for account in connected_accounts:
|
2010-04-24 09:51:32 +02:00
|
|
|
minimized_controls += \
|
2017-08-13 13:18:56 +02:00
|
|
|
list(app.interface.minimized_controls[account].values())
|
|
|
|
for gc_control in app.interface.msg_win_mgr.get_controls(
|
2010-02-08 15:08:40 +01:00
|
|
|
message_control.TYPE_GC) + minimized_controls:
|
|
|
|
acct = gc_control.account
|
2012-08-27 22:07:29 +02:00
|
|
|
if acct not in connected_accounts:
|
|
|
|
continue
|
2010-02-08 15:08:40 +01:00
|
|
|
room_jid = gc_control.room_jid
|
2011-03-30 15:23:10 +02:00
|
|
|
if room_jid in ignore_rooms:
|
|
|
|
continue
|
2017-08-13 13:18:56 +02:00
|
|
|
if room_jid in app.gc_connected[acct] and \
|
|
|
|
app.gc_connected[acct][room_jid] and \
|
2013-08-12 23:10:59 +02:00
|
|
|
contacts_transport in ['jabber', None]:
|
2010-02-08 15:08:40 +01:00
|
|
|
rooms.append((room_jid, acct))
|
2018-09-16 01:10:04 +02:00
|
|
|
if rooms:
|
2013-01-01 16:46:04 +01:00
|
|
|
item = Gtk.SeparatorMenuItem.new() # separator
|
2010-02-08 15:08:40 +01:00
|
|
|
invite_to_submenu.append(item)
|
|
|
|
for (room_jid, account) in rooms:
|
2014-11-11 23:11:15 +01:00
|
|
|
menuitem = Gtk.MenuItem.new_with_label(room_jid.split('@')[0])
|
2010-02-08 15:08:40 +01:00
|
|
|
if len(contact_list) > 1: # several resources
|
|
|
|
menuitem.set_submenu(build_resources_submenu(
|
2013-08-12 23:10:59 +02:00
|
|
|
contact_list, account, roster.on_invite_to_room, room_jid,
|
|
|
|
account))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# use resource if it's self contact
|
2017-08-13 13:18:56 +02:00
|
|
|
if contact.jid == app.get_jid_from_account(account):
|
2010-02-08 15:08:40 +01:00
|
|
|
resource = contact.resource
|
|
|
|
else:
|
|
|
|
resource = None
|
|
|
|
menuitem.connect('activate', roster.on_invite_to_room, list_,
|
2013-12-02 12:17:32 +01:00
|
|
|
room_jid, account, resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
invite_to_submenu.append(menuitem)
|
2009-10-27 10:39:40 +01:00
|
|
|
|
2013-12-02 12:17:32 +01:00
|
|
|
if not show_bookmarked:
|
|
|
|
return
|
|
|
|
rooms2 = [] # a list of (room_jid, account) tuple
|
|
|
|
r_jids = [] # list of room jids
|
|
|
|
for account in connected_accounts:
|
2018-07-01 02:16:33 +02:00
|
|
|
con = app.connections[account]
|
|
|
|
boomarks = con.get_module('Bookmarks').bookmarks
|
2018-09-17 21:11:45 +02:00
|
|
|
for jid in boomarks.keys():
|
2018-07-01 02:16:33 +02:00
|
|
|
if jid in r_jids:
|
2013-12-02 12:17:32 +01:00
|
|
|
continue
|
2018-07-01 02:16:33 +02:00
|
|
|
if jid not in app.gc_connected[account] or not \
|
|
|
|
app.gc_connected[account][jid]:
|
|
|
|
rooms2.append((jid, account))
|
|
|
|
r_jids.append(jid)
|
2013-12-18 17:08:45 +01:00
|
|
|
|
2013-12-02 12:17:32 +01:00
|
|
|
if not rooms2:
|
|
|
|
return
|
|
|
|
item = Gtk.SeparatorMenuItem.new() # separator
|
|
|
|
invite_to_submenu.append(item)
|
|
|
|
for (room_jid, account) in rooms2:
|
2014-11-11 23:11:15 +01:00
|
|
|
menuitem = Gtk.MenuItem.new_with_label(room_jid.split('@')[0])
|
2013-12-02 12:17:32 +01:00
|
|
|
if len(contact_list) > 1: # several resources
|
|
|
|
menuitem.set_submenu(build_resources_submenu(
|
|
|
|
contact_list, account, roster.on_invite_to_room, room_jid,
|
|
|
|
account))
|
|
|
|
else:
|
|
|
|
# use resource if it's self contact
|
2017-08-13 13:18:56 +02:00
|
|
|
if contact.jid == app.get_jid_from_account(account):
|
2013-12-02 12:17:32 +01:00
|
|
|
resource = contact.resource
|
|
|
|
else:
|
|
|
|
resource = None
|
|
|
|
menuitem.connect('activate', roster.on_invite_to_room, list_,
|
|
|
|
room_jid, account, resource)
|
|
|
|
invite_to_submenu.append(menuitem)
|
|
|
|
|
2009-10-27 18:58:27 +01:00
|
|
|
def get_contact_menu(contact, account, use_multiple_contacts=True,
|
2010-04-24 09:51:32 +02:00
|
|
|
show_start_chat=True, show_encryption=False, show_buttonbar_items=True,
|
2012-04-16 23:03:30 +02:00
|
|
|
control=None, gc_contact=None, is_anonymous=True):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Build contact popup menu for roster and chat window. If control is not set,
|
|
|
|
we hide invite_contacts_menuitem
|
|
|
|
"""
|
|
|
|
if not contact:
|
|
|
|
return
|
|
|
|
|
|
|
|
jid = contact.jid
|
2017-08-13 13:18:56 +02:00
|
|
|
our_jid = jid == app.get_jid_from_account(account)
|
|
|
|
roster = app.interface.roster
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
xml = gtkgui_helpers.get_gtk_builder('contact_context_menu.ui')
|
|
|
|
contact_context_menu = xml.get_object('contact_context_menu')
|
|
|
|
|
|
|
|
start_chat_menuitem = xml.get_object('start_chat_menuitem')
|
|
|
|
execute_command_menuitem = xml.get_object('execute_command_menuitem')
|
|
|
|
rename_menuitem = xml.get_object('rename_menuitem')
|
|
|
|
edit_groups_menuitem = xml.get_object('edit_groups_menuitem')
|
|
|
|
send_file_menuitem = xml.get_object('send_file_menuitem')
|
|
|
|
assign_openpgp_key_menuitem = xml.get_object('assign_openpgp_key_menuitem')
|
|
|
|
information_menuitem = xml.get_object('information_menuitem')
|
|
|
|
history_menuitem = xml.get_object('history_menuitem')
|
|
|
|
send_custom_status_menuitem = xml.get_object('send_custom_status_menuitem')
|
|
|
|
send_single_message_menuitem = xml.get_object('send_single_message_menuitem')
|
|
|
|
invite_menuitem = xml.get_object('invite_menuitem')
|
|
|
|
block_menuitem = xml.get_object('block_menuitem')
|
|
|
|
unblock_menuitem = xml.get_object('unblock_menuitem')
|
|
|
|
ignore_menuitem = xml.get_object('ignore_menuitem')
|
|
|
|
unignore_menuitem = xml.get_object('unignore_menuitem')
|
|
|
|
# Subscription submenu
|
|
|
|
subscription_menuitem = xml.get_object('subscription_menuitem')
|
|
|
|
send_auth_menuitem, ask_auth_menuitem, revoke_auth_menuitem = \
|
|
|
|
subscription_menuitem.get_submenu().get_children()
|
|
|
|
add_to_roster_menuitem = xml.get_object('add_to_roster_menuitem')
|
|
|
|
remove_from_roster_menuitem = xml.get_object(
|
|
|
|
'remove_from_roster_menuitem')
|
|
|
|
manage_contact_menuitem = xml.get_object('manage_contact')
|
|
|
|
convert_to_gc_menuitem = xml.get_object('convert_to_groupchat_menuitem')
|
|
|
|
last_separator = xml.get_object('last_separator')
|
|
|
|
|
|
|
|
items_to_hide = []
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
contacts = app.contacts.get_contacts(account, jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
if len(contacts) > 1 and use_multiple_contacts: # several resources
|
|
|
|
start_chat_menuitem.set_submenu(build_resources_submenu(contacts,
|
2017-08-13 13:18:56 +02:00
|
|
|
account, app.interface.on_open_chat_window))
|
2010-02-08 15:08:40 +01:00
|
|
|
send_file_menuitem.set_submenu(build_resources_submenu(contacts,
|
|
|
|
account, roster.on_send_file_menuitem_activate, cap=NS_FILE))
|
|
|
|
execute_command_menuitem.set_submenu(build_resources_submenu(
|
|
|
|
contacts, account, roster.on_execute_command, cap=NS_COMMANDS))
|
|
|
|
else:
|
|
|
|
start_chat_menuitem.connect('activate',
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.on_open_chat_window, contact, account)
|
2017-06-14 21:31:29 +02:00
|
|
|
if contact.supports(NS_FILE) or contact.supports(NS_JINGLE_FILE_TRANSFER_5):
|
2010-02-08 15:08:40 +01:00
|
|
|
send_file_menuitem.set_sensitive(True)
|
|
|
|
send_file_menuitem.connect('activate',
|
|
|
|
roster.on_send_file_menuitem_activate, contact, account)
|
|
|
|
else:
|
|
|
|
send_file_menuitem.set_sensitive(False)
|
|
|
|
|
|
|
|
if contact.supports(NS_COMMANDS):
|
|
|
|
execute_command_menuitem.set_sensitive(True)
|
2012-04-16 23:03:30 +02:00
|
|
|
if gc_contact and gc_contact.jid and not is_anonymous:
|
|
|
|
execute_command_menuitem.connect('activate',
|
|
|
|
roster.on_execute_command, gc_contact, account,
|
|
|
|
gc_contact.resource)
|
|
|
|
else:
|
|
|
|
execute_command_menuitem.connect('activate',
|
|
|
|
roster.on_execute_command, contact, account,
|
|
|
|
contact.resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
execute_command_menuitem.set_sensitive(False)
|
|
|
|
|
|
|
|
rename_menuitem.connect('activate', roster.on_rename, 'contact', jid,
|
2014-11-11 23:11:15 +01:00
|
|
|
account)
|
2010-02-08 15:08:40 +01:00
|
|
|
history_menuitem.connect('activate', roster.on_history, contact, account)
|
|
|
|
|
|
|
|
if control:
|
|
|
|
convert_to_gc_menuitem.connect('activate',
|
2014-11-11 23:11:15 +01:00
|
|
|
control._on_convert_to_gc_menuitem_activate)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
items_to_hide.append(convert_to_gc_menuitem)
|
|
|
|
|
|
|
|
if _('Not in Roster') not in contact.get_shown_groups():
|
|
|
|
# contact is in normal group
|
|
|
|
edit_groups_menuitem.connect('activate', roster.on_edit_groups, [(contact,
|
|
|
|
account)])
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.connections[account].gpg:
|
2010-02-08 15:08:40 +01:00
|
|
|
assign_openpgp_key_menuitem.connect('activate',
|
|
|
|
roster.on_assign_pgp_key, contact, account)
|
|
|
|
else:
|
|
|
|
assign_openpgp_key_menuitem.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
# contact is in group 'Not in Roster'
|
|
|
|
edit_groups_menuitem.set_sensitive(False)
|
|
|
|
assign_openpgp_key_menuitem.set_sensitive(False)
|
|
|
|
|
|
|
|
# Hide items when it's self contact row
|
|
|
|
if our_jid:
|
|
|
|
items_to_hide += [rename_menuitem, edit_groups_menuitem]
|
|
|
|
|
|
|
|
# Unsensitive many items when account is offline
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2012-01-22 11:25:22 +01:00
|
|
|
for widget in (start_chat_menuitem, rename_menuitem,
|
|
|
|
edit_groups_menuitem, send_file_menuitem, convert_to_gc_menuitem,
|
|
|
|
information_menuitem):
|
2010-02-08 15:08:40 +01:00
|
|
|
widget.set_sensitive(False)
|
|
|
|
|
|
|
|
if not show_start_chat:
|
|
|
|
items_to_hide.append(start_chat_menuitem)
|
|
|
|
|
|
|
|
if not show_buttonbar_items:
|
|
|
|
items_to_hide += [history_menuitem, send_file_menuitem,
|
|
|
|
information_menuitem, convert_to_gc_menuitem, last_separator]
|
|
|
|
|
|
|
|
if not control:
|
|
|
|
items_to_hide.append(convert_to_gc_menuitem)
|
|
|
|
|
2013-12-23 21:39:23 +01:00
|
|
|
# Hide items when it's a pm
|
|
|
|
if gc_contact:
|
|
|
|
items_to_hide += [rename_menuitem, edit_groups_menuitem,
|
|
|
|
subscription_menuitem, remove_from_roster_menuitem]
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
for item in items_to_hide:
|
|
|
|
item.set_no_show_all(True)
|
|
|
|
item.hide()
|
|
|
|
|
|
|
|
# Zeroconf Account
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get_per('accounts', account, 'is_zeroconf'):
|
2010-02-08 15:08:40 +01:00
|
|
|
for item in (send_custom_status_menuitem, send_single_message_menuitem,
|
|
|
|
invite_menuitem, block_menuitem, unblock_menuitem, ignore_menuitem,
|
2017-09-16 11:49:31 +02:00
|
|
|
unignore_menuitem, subscription_menuitem,
|
2010-02-08 15:08:40 +01:00
|
|
|
manage_contact_menuitem, convert_to_gc_menuitem):
|
|
|
|
item.set_no_show_all(True)
|
|
|
|
item.hide()
|
|
|
|
|
|
|
|
if contact.show in ('offline', 'error'):
|
|
|
|
information_menuitem.set_sensitive(False)
|
|
|
|
send_file_menuitem.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
information_menuitem.connect('activate', roster.on_info_zeroconf,
|
|
|
|
contact, account)
|
|
|
|
|
|
|
|
contact_context_menu.connect('selection-done',
|
|
|
|
gtkgui_helpers.destroy_widget)
|
|
|
|
contact_context_menu.show_all()
|
|
|
|
return contact_context_menu
|
|
|
|
|
|
|
|
# normal account
|
|
|
|
|
|
|
|
# send custom status icon
|
|
|
|
blocked = False
|
|
|
|
if helpers.jid_is_blocked(account, jid):
|
|
|
|
blocked = True
|
|
|
|
else:
|
|
|
|
for group in contact.get_shown_groups():
|
|
|
|
if helpers.group_is_blocked(account, group):
|
|
|
|
blocked = True
|
|
|
|
break
|
2017-08-13 13:18:56 +02:00
|
|
|
transport = app.get_transport_name_from_jid(jid, use_config_setting=False)
|
2013-08-08 21:53:21 +02:00
|
|
|
if transport and transport != 'jabber':
|
2010-02-08 15:08:40 +01:00
|
|
|
# Transport contact, send custom status unavailable
|
|
|
|
send_custom_status_menuitem.set_sensitive(False)
|
|
|
|
elif blocked:
|
|
|
|
send_custom_status_menuitem.set_sensitive(False)
|
|
|
|
|
2011-03-18 10:09:06 +01:00
|
|
|
if gc_contact:
|
|
|
|
if not gc_contact.jid:
|
|
|
|
# it's a pm and we don't know real JID
|
|
|
|
invite_menuitem.set_sensitive(False)
|
|
|
|
else:
|
2013-12-02 12:17:32 +01:00
|
|
|
bookmarked = False
|
2017-08-13 13:18:56 +02:00
|
|
|
c_ = app.contacts.get_contact(account, gc_contact.jid,
|
2013-12-02 12:17:32 +01:00
|
|
|
gc_contact.resource)
|
2013-12-18 17:08:45 +01:00
|
|
|
if c_ and c_.supports(NS_CONFERENCE):
|
2018-09-18 12:06:01 +02:00
|
|
|
bookmarked = True
|
2013-12-02 12:17:32 +01:00
|
|
|
build_invite_submenu(invite_menuitem, [(gc_contact, account)],
|
|
|
|
show_bookmarked=bookmarked)
|
2011-03-18 10:09:06 +01:00
|
|
|
else:
|
2014-01-13 20:25:07 +01:00
|
|
|
force_resource = False
|
|
|
|
if control and control.resource:
|
|
|
|
force_resource = True
|
2013-12-02 12:17:32 +01:00
|
|
|
build_invite_submenu(invite_menuitem, [(contact, account)],
|
2014-01-13 20:25:07 +01:00
|
|
|
show_bookmarked=contact.supports(NS_CONFERENCE),
|
|
|
|
force_resource=force_resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2012-07-15 22:33:33 +02:00
|
|
|
invite_menuitem.set_sensitive(False)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# One or several resource, we do the same for send_custom_status
|
2012-12-23 16:23:43 +01:00
|
|
|
status_menuitems = Gtk.Menu()
|
2010-02-08 15:08:40 +01:00
|
|
|
send_custom_status_menuitem.set_submenu(status_menuitems)
|
|
|
|
for s in ('online', 'chat', 'away', 'xa', 'dnd', 'offline'):
|
|
|
|
# icon MUST be different instance for every item
|
2014-11-11 23:11:15 +01:00
|
|
|
status_menuitem = Gtk.MenuItem.new_with_label(helpers.get_uf_show(s))
|
2010-02-08 15:08:40 +01:00
|
|
|
status_menuitem.connect('activate', roster.on_send_custom_status,
|
2014-10-20 17:20:38 +02:00
|
|
|
[(contact, account)], s)
|
2010-02-08 15:08:40 +01:00
|
|
|
status_menuitems.append(status_menuitem)
|
|
|
|
|
|
|
|
send_single_message_menuitem.connect('activate',
|
2014-11-11 23:11:15 +01:00
|
|
|
roster.on_send_single_message_menuitem_activate, account, contact)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
remove_from_roster_menuitem.connect('activate', roster.on_req_usub,
|
2014-11-11 23:11:15 +01:00
|
|
|
[(contact, account)])
|
2010-02-08 15:08:40 +01:00
|
|
|
information_menuitem.connect('activate', roster.on_info, contact, account)
|
|
|
|
|
|
|
|
if _('Not in Roster') not in contact.get_shown_groups():
|
|
|
|
# contact is in normal group
|
|
|
|
add_to_roster_menuitem.hide()
|
|
|
|
add_to_roster_menuitem.set_no_show_all(True)
|
|
|
|
|
|
|
|
if contact.sub in ('from', 'both'):
|
|
|
|
send_auth_menuitem.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
send_auth_menuitem.connect('activate', roster.authorize, jid, account)
|
|
|
|
if contact.sub in ('to', 'both'):
|
|
|
|
ask_auth_menuitem.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
ask_auth_menuitem.connect('activate', roster.req_sub, jid,
|
|
|
|
_('I would like to add you to my roster'), account,
|
|
|
|
contact.groups, contact.name)
|
2017-08-13 13:18:56 +02:00
|
|
|
transport = app.get_transport_name_from_jid(jid,
|
2013-08-12 23:07:47 +02:00
|
|
|
use_config_setting=False)
|
|
|
|
if contact.sub in ('to', 'none') or transport not in ['jabber', None]:
|
2010-02-08 15:08:40 +01:00
|
|
|
revoke_auth_menuitem.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
revoke_auth_menuitem.connect('activate', roster.revoke_auth, jid,
|
|
|
|
account)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
elif app.connections[account].roster_supported:
|
2010-02-08 15:08:40 +01:00
|
|
|
# contact is in group 'Not in Roster'
|
|
|
|
add_to_roster_menuitem.set_no_show_all(False)
|
|
|
|
subscription_menuitem.set_sensitive(False)
|
|
|
|
|
|
|
|
add_to_roster_menuitem.connect('activate', roster.on_add_to_roster,
|
|
|
|
contact, account)
|
2011-08-09 17:14:13 +02:00
|
|
|
else:
|
|
|
|
add_to_roster_menuitem.hide()
|
|
|
|
add_to_roster_menuitem.set_no_show_all(True)
|
|
|
|
subscription_menuitem.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# Hide items when it's self contact row
|
|
|
|
if our_jid:
|
|
|
|
manage_contact_menuitem.set_sensitive(False)
|
|
|
|
|
|
|
|
# Unsensitive items when account is offline
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2010-02-08 15:08:40 +01:00
|
|
|
for widget in (send_single_message_menuitem, subscription_menuitem,
|
|
|
|
add_to_roster_menuitem, remove_from_roster_menuitem,
|
|
|
|
execute_command_menuitem, send_custom_status_menuitem):
|
|
|
|
widget.set_sensitive(False)
|
|
|
|
|
2018-07-22 12:18:24 +02:00
|
|
|
|
|
|
|
con = app.connections[account]
|
|
|
|
if con and (con.get_module('PrivacyLists').supported or
|
|
|
|
con.get_module('Blocking').supported):
|
2010-02-08 15:08:40 +01:00
|
|
|
if helpers.jid_is_blocked(account, jid):
|
|
|
|
block_menuitem.set_no_show_all(True)
|
|
|
|
block_menuitem.hide()
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.get_transport_name_from_jid(jid, use_config_setting=False)\
|
2013-10-25 19:49:07 +02:00
|
|
|
and transport != 'jabber':
|
2010-02-08 15:08:40 +01:00
|
|
|
unblock_menuitem.set_no_show_all(True)
|
|
|
|
unblock_menuitem.hide()
|
|
|
|
unignore_menuitem.set_no_show_all(False)
|
|
|
|
unignore_menuitem.connect('activate', roster.on_unblock, [(contact,
|
|
|
|
account)])
|
|
|
|
else:
|
|
|
|
unblock_menuitem.connect('activate', roster.on_unblock, [(contact,
|
|
|
|
account)])
|
|
|
|
else:
|
|
|
|
unblock_menuitem.set_no_show_all(True)
|
|
|
|
unblock_menuitem.hide()
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.get_transport_name_from_jid(jid, use_config_setting=False)\
|
2013-10-25 19:49:07 +02:00
|
|
|
and transport != 'jabber':
|
2010-02-08 15:08:40 +01:00
|
|
|
block_menuitem.set_no_show_all(True)
|
|
|
|
block_menuitem.hide()
|
|
|
|
ignore_menuitem.set_no_show_all(False)
|
|
|
|
ignore_menuitem.connect('activate', roster.on_block, [(contact,
|
|
|
|
account)])
|
|
|
|
else:
|
|
|
|
block_menuitem.connect('activate', roster.on_block, [(contact,
|
|
|
|
account)])
|
|
|
|
else:
|
|
|
|
unblock_menuitem.set_no_show_all(True)
|
|
|
|
block_menuitem.set_sensitive(False)
|
|
|
|
unblock_menuitem.hide()
|
|
|
|
|
|
|
|
contact_context_menu.connect('selection-done', gtkgui_helpers.destroy_widget)
|
|
|
|
contact_context_menu.show_all()
|
|
|
|
return contact_context_menu
|
2013-10-31 15:14:06 +01:00
|
|
|
|
|
|
|
def get_transport_menu(contact, account):
|
2017-08-13 13:18:56 +02:00
|
|
|
roster = app.interface.roster
|
2013-10-31 15:14:06 +01:00
|
|
|
jid = contact.jid
|
|
|
|
|
|
|
|
menu = Gtk.Menu()
|
|
|
|
|
|
|
|
# Send single message
|
2017-02-04 23:29:45 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('Send Single _Message…'))
|
2013-10-31 15:14:06 +01:00
|
|
|
item.connect('activate', roster.on_send_single_message_menuitem_activate,
|
|
|
|
account, contact)
|
|
|
|
menu.append(item)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2013-10-31 15:14:06 +01:00
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
blocked = False
|
|
|
|
if helpers.jid_is_blocked(account, jid):
|
|
|
|
blocked = True
|
|
|
|
|
|
|
|
# Send Custom Status
|
2014-11-11 23:11:15 +01:00
|
|
|
send_custom_status_menuitem = Gtk.MenuItem.new_with_mnemonic(
|
2013-10-31 15:14:06 +01:00
|
|
|
_('Send Cus_tom Status'))
|
|
|
|
if blocked:
|
|
|
|
send_custom_status_menuitem.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
status_menuitems = Gtk.Menu()
|
|
|
|
send_custom_status_menuitem.set_submenu(status_menuitems)
|
|
|
|
for s in ('online', 'chat', 'away', 'xa', 'dnd', 'offline'):
|
2014-11-11 23:11:15 +01:00
|
|
|
status_menuitem = Gtk.MenuItem.new_with_label(helpers.get_uf_show(
|
|
|
|
s))
|
2013-10-31 15:14:06 +01:00
|
|
|
status_menuitem.connect('activate', roster.on_send_custom_status,
|
|
|
|
[(contact, account)], s)
|
|
|
|
status_menuitems.append(status_menuitem)
|
|
|
|
menu.append(send_custom_status_menuitem)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2013-10-31 15:14:06 +01:00
|
|
|
send_custom_status_menuitem.set_sensitive(False)
|
|
|
|
|
|
|
|
item = Gtk.SeparatorMenuItem.new() # separator
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
# Execute Command
|
2017-02-04 23:29:45 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('E_xecute Command…'))
|
2013-10-31 15:14:06 +01:00
|
|
|
menu.append(item)
|
|
|
|
item.connect('activate', roster.on_execute_command, contact, account,
|
|
|
|
contact.resource)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2013-10-31 15:14:06 +01:00
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
# Manage Transport submenu
|
2014-11-11 23:11:15 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Manage Transport'))
|
2013-10-31 15:14:06 +01:00
|
|
|
manage_transport_submenu = Gtk.Menu()
|
|
|
|
item.set_submenu(manage_transport_submenu)
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
# Modify Transport
|
2014-11-11 23:11:15 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Modify Transport'))
|
2013-10-31 15:14:06 +01:00
|
|
|
manage_transport_submenu.append(item)
|
|
|
|
item.connect('activate', roster.on_edit_agent, contact, account)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2013-10-31 15:14:06 +01:00
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
# Rename
|
2017-02-04 23:29:45 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Rename…'))
|
2013-10-31 15:14:06 +01:00
|
|
|
manage_transport_submenu.append(item)
|
|
|
|
item.connect('activate', roster.on_rename, 'agent', jid, account)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2013-10-31 15:14:06 +01:00
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
item = Gtk.SeparatorMenuItem.new() # separator
|
|
|
|
manage_transport_submenu.append(item)
|
|
|
|
|
|
|
|
# Block
|
|
|
|
if blocked:
|
2014-11-11 23:11:15 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Unblock'))
|
2013-10-31 15:14:06 +01:00
|
|
|
item.connect('activate', roster.on_unblock, [(contact, account)])
|
|
|
|
else:
|
2014-11-11 23:11:15 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Block'))
|
2013-10-31 15:14:06 +01:00
|
|
|
item.connect('activate', roster.on_block, [(contact, account)])
|
|
|
|
|
|
|
|
manage_transport_submenu.append(item)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2013-10-31 15:14:06 +01:00
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
# Remove
|
2014-11-11 23:11:15 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('Remo_ve'))
|
2013-10-31 15:14:06 +01:00
|
|
|
manage_transport_submenu.append(item)
|
|
|
|
item.connect('activate', roster.on_remove_agent, [(contact, account)])
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2013-10-31 15:14:06 +01:00
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
item = Gtk.SeparatorMenuItem.new() # separator
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
# Information
|
2014-11-11 23:11:15 +01:00
|
|
|
information_menuitem = Gtk.MenuItem.new_with_mnemonic(_('_Information'))
|
2013-10-31 15:14:06 +01:00
|
|
|
menu.append(information_menuitem)
|
|
|
|
information_menuitem.connect('activate', roster.on_info, contact, account)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_disconnected(account):
|
2013-10-31 15:14:06 +01:00
|
|
|
information_menuitem.set_sensitive(False)
|
|
|
|
|
|
|
|
menu.connect('selection-done', gtkgui_helpers.destroy_widget)
|
|
|
|
menu.show_all()
|
|
|
|
return menu
|
2013-12-02 12:17:32 +01:00
|
|
|
|
2017-01-26 21:34:54 +01:00
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
def get_singlechat_menu(control_id):
|
|
|
|
singlechat_menu = [
|
2018-02-22 22:45:15 +01:00
|
|
|
(_('Send File…'), [
|
2018-03-25 18:20:37 +02:00
|
|
|
('win.send-file-httpupload-', _('Upload File…')),
|
2018-03-25 18:29:17 +02:00
|
|
|
('win.send-file-jingle-', _('Send File Directly…')),
|
2017-12-27 13:17:13 +01:00
|
|
|
]),
|
2017-10-03 13:08:06 +02:00
|
|
|
('win.invite-contacts-', _('Invite Contacts')),
|
|
|
|
('win.add-to-roster-', _('Add to Roster')),
|
|
|
|
('win.toggle-audio-', _('Audio Session')),
|
|
|
|
('win.toggle-video-', _('Video Session')),
|
|
|
|
('win.information-', _('Information')),
|
|
|
|
('win.browse-history-', _('History')),
|
|
|
|
]
|
|
|
|
|
|
|
|
def build_menu(preset):
|
|
|
|
menu = Gio.Menu()
|
|
|
|
for item in preset:
|
2017-12-27 13:17:13 +01:00
|
|
|
if isinstance(item[1], str):
|
|
|
|
action_name, label = item
|
|
|
|
if action_name == 'win.browse-history-':
|
|
|
|
menu.append(label, action_name + control_id + '::none')
|
|
|
|
else:
|
|
|
|
menu.append(label, action_name + control_id)
|
2017-10-03 13:08:06 +02:00
|
|
|
else:
|
2017-12-27 13:17:13 +01:00
|
|
|
label, sub_menu = item
|
|
|
|
# This is a submenu
|
|
|
|
submenu = build_menu(sub_menu)
|
|
|
|
menu.append_submenu(label, submenu)
|
2017-10-03 13:08:06 +02:00
|
|
|
return menu
|
|
|
|
|
|
|
|
return build_menu(singlechat_menu)
|
|
|
|
|
|
|
|
|
|
|
|
def get_groupchat_menu(control_id):
|
|
|
|
groupchat_menu = [
|
|
|
|
(_('Manage Room'), [
|
|
|
|
('win.change-subject-', _('Change Subject')),
|
|
|
|
('win.configure-', _('Configure Room')),
|
2018-05-06 09:08:52 +02:00
|
|
|
('win.upload-avatar-', _('Upload Avatar…')),
|
2017-10-03 13:08:06 +02:00
|
|
|
('win.destroy-', _('Destroy Room')),
|
2018-09-15 20:45:38 +02:00
|
|
|
]),
|
|
|
|
(_('Sync Threshold'), []),
|
2017-10-03 13:08:06 +02:00
|
|
|
('win.change-nick-', _('Change Nick')),
|
|
|
|
('win.bookmark-', _('Bookmark Room')),
|
|
|
|
('win.request-voice-', _('Request Voice')),
|
|
|
|
('win.notify-on-message-', _('Notify on all messages')),
|
|
|
|
('win.minimize-', _('Minimize on close')),
|
2017-12-22 12:21:57 +01:00
|
|
|
('win.execute-command-', _('Execute command')),
|
2017-10-03 13:08:06 +02:00
|
|
|
('win.browse-history-', _('History')),
|
|
|
|
('win.disconnect-', _('Disconnect')),
|
2018-09-15 20:45:38 +02:00
|
|
|
]
|
2017-10-03 13:08:06 +02:00
|
|
|
|
|
|
|
def build_menu(preset):
|
|
|
|
menu = Gio.Menu()
|
|
|
|
for item in preset:
|
|
|
|
if isinstance(item[1], str):
|
|
|
|
action_name, label = item
|
|
|
|
if action_name == 'win.browse-history-':
|
|
|
|
menu.append(label, action_name + control_id + '::none')
|
|
|
|
else:
|
|
|
|
menu.append(label, action_name + control_id)
|
|
|
|
else:
|
|
|
|
label, sub_menu = item
|
2018-09-15 20:45:38 +02:00
|
|
|
if not sub_menu:
|
|
|
|
# Sync threshold menu
|
|
|
|
submenu = build_sync_menu()
|
|
|
|
else:
|
|
|
|
# This is a submenu
|
|
|
|
submenu = build_menu(sub_menu)
|
2017-10-03 13:08:06 +02:00
|
|
|
menu.append_submenu(label, submenu)
|
|
|
|
return menu
|
|
|
|
|
2018-09-15 20:45:38 +02:00
|
|
|
def build_sync_menu():
|
|
|
|
menu = Gio.Menu()
|
|
|
|
days = app.config.get('threshold_options').split(',')
|
|
|
|
days = [int(day) for day in days]
|
|
|
|
action_name = 'win.choose-sync-%s::' % control_id
|
|
|
|
for day in days:
|
|
|
|
if day == 0:
|
|
|
|
label = _('No threshold')
|
|
|
|
else:
|
|
|
|
label = ngettext('%i day', '%i days', day, day, day)
|
|
|
|
menu.append(label, '%s%s' % (action_name, day))
|
|
|
|
return menu
|
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
return build_menu(groupchat_menu)
|
|
|
|
|
|
|
|
|
2017-01-26 21:34:54 +01:00
|
|
|
def get_bookmarks_menu(account, rebuild=False):
|
2018-07-01 02:16:33 +02:00
|
|
|
con = app.connections[account]
|
2018-12-10 22:24:52 +01:00
|
|
|
boomarks = con.get_module('Bookmarks').get_sorted_bookmarks(short_name=True)
|
|
|
|
|
2017-01-26 21:34:54 +01:00
|
|
|
menu = Gio.Menu()
|
|
|
|
|
|
|
|
# Build Join Groupchat
|
|
|
|
action = 'app.{}-join-groupchat'.format(account)
|
|
|
|
menuitem = Gio.MenuItem.new(_('Join Group Chat'), action)
|
2018-09-22 11:59:07 +02:00
|
|
|
variant = GLib.Variant('as', [account, ''])
|
2017-01-26 21:34:54 +01:00
|
|
|
menuitem.set_action_and_target_value(action, variant)
|
|
|
|
menu.append_item(menuitem)
|
|
|
|
|
|
|
|
# Build Bookmarks
|
|
|
|
section = Gio.Menu()
|
2018-07-01 02:16:33 +02:00
|
|
|
for jid, bookmark in boomarks.items():
|
2017-01-26 21:34:54 +01:00
|
|
|
name = bookmark['name']
|
|
|
|
|
|
|
|
action = 'app.{}-activate-bookmark'.format(account)
|
|
|
|
menuitem = Gio.MenuItem.new(name, action)
|
|
|
|
|
|
|
|
# Create Variant Dict
|
|
|
|
dict_ = {'account': GLib.Variant('s', account),
|
2018-07-01 02:16:33 +02:00
|
|
|
'jid': GLib.Variant('s', jid)}
|
2017-01-26 21:34:54 +01:00
|
|
|
if bookmark['nick']:
|
|
|
|
dict_['nick'] = GLib.Variant('s', bookmark['nick'])
|
|
|
|
if bookmark['password']:
|
|
|
|
dict_['password'] = GLib.Variant('s', bookmark['password'])
|
|
|
|
variant_dict = GLib.Variant('a{sv}', dict_)
|
|
|
|
|
|
|
|
menuitem.set_action_and_target_value(action, variant_dict)
|
|
|
|
section.append_item(menuitem)
|
|
|
|
menu.append_section(None, section)
|
|
|
|
if not rebuild:
|
|
|
|
get_action(account + '-activate-bookmark').set_enabled(True)
|
|
|
|
|
|
|
|
return menu
|
|
|
|
|
|
|
|
|
|
|
|
def get_account_menu(account):
|
|
|
|
'''
|
|
|
|
[(action, label/sub_menu)]
|
|
|
|
action: string
|
|
|
|
label: string
|
|
|
|
sub menu: list
|
|
|
|
'''
|
|
|
|
account_menu = [
|
2018-05-21 21:18:38 +02:00
|
|
|
('-add-contact', _('Add Contact…')),
|
|
|
|
('-join-groupchat', _('Join Group Chat')),
|
|
|
|
('-profile', _('Profile')),
|
|
|
|
('-services', _('Discover Services')),
|
|
|
|
('-start-single-chat', _('Send Single Message…')),
|
|
|
|
(_('Advanced'), [
|
|
|
|
('-archive', _('Archiving Preferences')),
|
|
|
|
('-sync-history', _('Synchronise History')),
|
|
|
|
('-privacylists', _('Privacy Lists')),
|
|
|
|
('-server-info', _('Server Info')),
|
|
|
|
('-xml-console', _('XML Console'))
|
|
|
|
]),
|
|
|
|
(_('Admin'), [
|
|
|
|
('-send-server-message', _('Send Server Message…')),
|
|
|
|
('-set-motd', _('Set MOTD…')),
|
|
|
|
('-update-motd', _('Update MOTD…')),
|
|
|
|
('-delete-motd', _('Delete MOTD…'))
|
|
|
|
]),
|
|
|
|
]
|
|
|
|
|
|
|
|
zeroconf_menu = [
|
|
|
|
('-xml-console', _('XML Console')),
|
|
|
|
]
|
2017-01-26 21:34:54 +01:00
|
|
|
|
|
|
|
def build_menu(preset):
|
|
|
|
menu = Gio.Menu()
|
|
|
|
for item in preset:
|
|
|
|
if isinstance(item[1], str):
|
|
|
|
action, label = item
|
|
|
|
if action == '-join-groupchat':
|
|
|
|
bookmark_menu = get_bookmarks_menu(account, True)
|
|
|
|
if bookmark_menu:
|
|
|
|
menu.append_submenu(label, bookmark_menu)
|
|
|
|
continue
|
|
|
|
action = 'app.{}{}'.format(account, action)
|
|
|
|
menuitem = Gio.MenuItem.new(label, action)
|
2018-09-30 15:34:08 +02:00
|
|
|
if 'add-contact' in action:
|
2018-09-22 11:59:07 +02:00
|
|
|
variant = GLib.Variant('as', [account, ''])
|
|
|
|
else:
|
|
|
|
variant = GLib.Variant('s', account)
|
2017-01-26 21:34:54 +01:00
|
|
|
menuitem.set_action_and_target_value(action, variant)
|
|
|
|
menu.append_item(menuitem)
|
|
|
|
else:
|
|
|
|
label, sub_menu = item
|
|
|
|
# This is a submenu
|
|
|
|
submenu = build_menu(sub_menu)
|
|
|
|
menu.append_submenu(label, submenu)
|
|
|
|
return menu
|
|
|
|
|
2018-05-21 21:18:38 +02:00
|
|
|
if account == 'Local':
|
|
|
|
return build_menu(zeroconf_menu)
|
2017-01-26 21:34:54 +01:00
|
|
|
return build_menu(account_menu)
|
|
|
|
|
|
|
|
|
|
|
|
def build_accounts_menu():
|
2017-08-13 13:18:56 +02:00
|
|
|
menubar = app.app.get_menubar()
|
2017-01-26 21:34:54 +01:00
|
|
|
# Accounts Submenu
|
2017-11-24 18:54:30 +01:00
|
|
|
menu_position = 1
|
|
|
|
if app.prefers_app_menu():
|
|
|
|
menu_position = 0
|
2017-10-03 13:08:06 +02:00
|
|
|
|
|
|
|
acc_menu = menubar.get_item_link(menu_position, 'submenu')
|
2017-01-26 21:34:54 +01:00
|
|
|
acc_menu.remove_all()
|
2018-05-21 21:18:38 +02:00
|
|
|
accounts_list = sorted(app.contacts.get_accounts())
|
2017-01-26 21:34:54 +01:00
|
|
|
if not accounts_list:
|
|
|
|
no_accounts = _('No Accounts available')
|
|
|
|
acc_menu.append_item(Gio.MenuItem.new(no_accounts, None))
|
|
|
|
return
|
|
|
|
if len(accounts_list) > 1:
|
|
|
|
for acc in accounts_list:
|
2018-08-30 19:27:40 +02:00
|
|
|
label = escape_mnemonic(app.get_account_label(acc))
|
2017-01-26 21:34:54 +01:00
|
|
|
acc_menu.append_submenu(
|
2018-08-30 19:27:40 +02:00
|
|
|
label, get_account_menu(acc))
|
2017-01-26 21:34:54 +01:00
|
|
|
else:
|
|
|
|
acc_menu = get_account_menu(accounts_list[0])
|
2017-10-03 13:08:06 +02:00
|
|
|
menubar.remove(menu_position)
|
2018-01-11 15:12:07 +01:00
|
|
|
menubar.insert_submenu(menu_position, _('Accounts'), acc_menu)
|
2017-01-26 21:34:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
def build_bookmark_menu(account):
|
2017-08-13 13:18:56 +02:00
|
|
|
menubar = app.app.get_menubar()
|
2017-01-26 21:34:54 +01:00
|
|
|
bookmark_menu = get_bookmarks_menu(account)
|
|
|
|
if not bookmark_menu:
|
|
|
|
return
|
|
|
|
|
2017-11-24 18:54:30 +01:00
|
|
|
menu_position = 1
|
|
|
|
if app.prefers_app_menu():
|
|
|
|
menu_position = 0
|
2017-10-03 13:08:06 +02:00
|
|
|
|
2017-01-26 21:34:54 +01:00
|
|
|
# Accounts Submenu
|
2017-10-03 13:08:06 +02:00
|
|
|
acc_menu = menubar.get_item_link(menu_position, 'submenu')
|
2017-01-26 21:34:54 +01:00
|
|
|
|
|
|
|
# We have more than one Account active
|
|
|
|
if acc_menu.get_item_link(0, 'submenu'):
|
|
|
|
for i in range(acc_menu.get_n_items()):
|
|
|
|
label = acc_menu.get_item_attribute_value(i, 'label')
|
2017-11-11 17:10:17 +01:00
|
|
|
account_label = escape_mnemonic(
|
|
|
|
app.config.get_per('accounts', account, 'account_label'))
|
2017-11-06 23:29:07 +01:00
|
|
|
if label.get_string() in (account_label, account):
|
2017-01-26 21:34:54 +01:00
|
|
|
menu = acc_menu.get_item_link(i, 'submenu')
|
|
|
|
else:
|
|
|
|
# We have only one Account active
|
|
|
|
menu = acc_menu
|
|
|
|
label = menu.get_item_attribute_value(1, 'label').get_string()
|
|
|
|
menu.remove(1)
|
|
|
|
menu.insert_submenu(1, label, bookmark_menu)
|
2017-04-13 22:58:51 +02:00
|
|
|
|
|
|
|
|
2018-05-21 18:08:46 +02:00
|
|
|
def get_encryption_menu(control_id, type_id, zeroconf=False):
|
2017-04-13 22:58:51 +02:00
|
|
|
menu = Gio.Menu()
|
|
|
|
menu.append(
|
2017-08-18 18:52:04 +02:00
|
|
|
'Disabled', 'win.set-encryption-{}::{}'.format(control_id, 'disabled'))
|
2017-08-13 13:18:56 +02:00
|
|
|
for name, plugin in app.plugin_manager.encryption_plugins.items():
|
2017-05-07 14:02:11 +02:00
|
|
|
if type_id == 'gc':
|
|
|
|
if not hasattr(plugin, 'allow_groupchat'):
|
|
|
|
continue
|
|
|
|
if type_id == 'pm':
|
2018-07-01 04:32:41 +02:00
|
|
|
if not hasattr(plugin, 'allow_privatechat'):
|
2017-05-07 14:02:11 +02:00
|
|
|
continue
|
2018-05-21 18:08:46 +02:00
|
|
|
if zeroconf:
|
|
|
|
if not hasattr(plugin, 'allow_zeroconf'):
|
|
|
|
continue
|
2017-08-18 18:52:04 +02:00
|
|
|
menu_action = 'win.set-encryption-{}::{}'.format(
|
|
|
|
control_id, name)
|
2017-05-07 14:02:11 +02:00
|
|
|
menu.append(name, menu_action)
|
|
|
|
if menu.get_n_items() == 1:
|
|
|
|
return None
|
2017-04-13 22:58:51 +02:00
|
|
|
return menu
|
2017-11-11 17:10:17 +01:00
|
|
|
|
|
|
|
|
2018-09-22 11:59:07 +02:00
|
|
|
def get_conv_context_menu(account, kind, text):
|
|
|
|
if kind == 'xmpp':
|
|
|
|
if '?join' in text:
|
|
|
|
context_menu = [
|
|
|
|
('copy-link', _('Copy JID')),
|
|
|
|
('-join-groupchat', _('Join Groupchat')),
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
context_menu = [
|
|
|
|
('copy-link', _('Copy JID')),
|
|
|
|
('-start-chat', _('Start Chat')),
|
|
|
|
('-add-contact', _('Add to Roster…')),
|
|
|
|
]
|
|
|
|
|
|
|
|
elif kind == 'url':
|
|
|
|
context_menu = [
|
|
|
|
('copy-link', _('Copy Link Location')),
|
|
|
|
('open-link', _('Open Link in Browser')),
|
|
|
|
]
|
|
|
|
|
|
|
|
elif kind == 'mail':
|
|
|
|
context_menu = [
|
|
|
|
('copy-link', _('Copy Email Address')),
|
|
|
|
('open-link', _('Open Email Composer')),
|
|
|
|
]
|
|
|
|
|
|
|
|
elif kind == 'sth_at_sth':
|
|
|
|
context_menu = [
|
|
|
|
('copy-link', _('Copy JID/Email')),
|
|
|
|
('open-link', _('Open Email Composer')),
|
|
|
|
('-start-chat', _('Start Chat')),
|
|
|
|
('-join-groupchat', _('Join Groupchat')),
|
|
|
|
('-add-contact', _('Add to Roster…')),
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
menu = Gtk.Menu()
|
|
|
|
for item in context_menu:
|
|
|
|
action, label = item
|
|
|
|
menuitem = Gtk.MenuItem()
|
|
|
|
menuitem.set_label(label)
|
|
|
|
|
|
|
|
if action.startswith('-'):
|
2018-12-12 23:35:36 +01:00
|
|
|
text = text.replace('xmpp:', '')
|
|
|
|
text = text.split('?')[0]
|
2018-09-22 11:59:07 +02:00
|
|
|
action = 'app.%s%s' % (account, action)
|
|
|
|
else:
|
|
|
|
action = 'app.%s' % action
|
|
|
|
menuitem.set_action_name(action)
|
|
|
|
|
|
|
|
if action == 'app.open-link':
|
|
|
|
value = GLib.Variant.new_strv([kind, text])
|
|
|
|
elif action == 'app.copy-link':
|
|
|
|
value = GLib.Variant.new_string(text)
|
|
|
|
else:
|
|
|
|
value = GLib.Variant.new_strv([account, text])
|
|
|
|
menuitem.set_action_target_value(value)
|
|
|
|
menuitem.show()
|
|
|
|
menu.append(menuitem)
|
|
|
|
return menu
|
|
|
|
|
|
|
|
|
2017-11-11 17:10:17 +01:00
|
|
|
def escape_mnemonic(label):
|
|
|
|
if label is None:
|
|
|
|
return
|
|
|
|
# Underscore inside a label means the next letter is a keyboard
|
|
|
|
# shortcut. To show an underscore we have to use double underscore
|
|
|
|
return label.replace('_', '__')
|