def get_icon_name_to_show(contact, account=None): """ Get the icon name to show in online, away, requested, etc """ if account and app.events.get_nb_roster_events(account, contact.jid): return 'event' if account and app.events.get_nb_roster_events(account, contact.get_full_jid()): return 'event' if account and account in app.interface.minimized_controls and \ contact.jid in app.interface.minimized_controls[account] and app.interface.\ minimized_controls[account][contact.jid].get_nb_unread_pm() > 0: return 'event' if account and contact.jid in app.gc_connected[account]: if app.gc_connected[account][contact.jid]: return 'muc-active' return 'muc-inactive' if contact.jid.find('@') <= 0: # if not '@' or '@' starts the jid ==> agent return contact.show if contact.sub in ('both', 'to'): return contact.show if contact.ask == 'subscribe': return 'requested' transport = app.get_transport_name_from_jid(contact.jid) if transport: return contact.show if contact.show in SHOW_LIST: return contact.show return 'notinroster'
def get_tab_image(self, count_unread=True): jid = self.gc_contact.get_full_jid() if app.config.get('show_avatar_in_tabs'): scale = self.parent_win.window.get_scale_factor() surface = app.contacts.get_avatar( self.account, jid, AvatarSize.TAB, scale) if surface is not None: return surface if count_unread: num_unread = len(app.events.get_events( self.account, jid, ['printed_' + self.type_id, self.type_id])) else: num_unread = 0 transport = None if app.jid_is_transport(jid): transport = app.get_transport_name_from_jid(jid) if self.gc_contact.presence.is_unavailable: show = 'offline' else: show = self.gc_contact.show.value if num_unread and app.config.get('show_unread_tab_icon'): icon_name = get_icon_name('event', transport=transport) else: icon_name = get_icon_name(show, transport=transport) return icon_name
def __init__(self, account=None, jid=None, user_nick=None, group=None): Gtk.ApplicationWindow.__init__(self) self.set_application(app.app) self.set_position(Gtk.WindowPosition.CENTER) self.set_show_menubar(False) self.set_resizable(False) self.set_title(_('Add Contact')) self.connect('destroy', self._on_destroy) self.connect('key-press-event', self._on_key_press) self.account = account self.adding_jid = False # fill accounts with active accounts accounts = app.get_enabled_accounts_with_labels() if not accounts: return if not account: self.account = accounts[0][0] self.xml = get_builder('add_new_contact_window.ui') self.add(self.xml.get_object('add_contact_box')) self.xml.connect_signals(self) for w in ('account_combobox', 'account_label', 'prompt_label', 'uid_label', 'uid_entry', 'show_contact_info_button', 'protocol_combobox', 'protocol_jid_combobox', 'protocol_label', 'nickname_entry', 'message_scrolledwindow', 'save_message_checkbutton', 'register_hbox', 'add_button', 'message_textview', 'connected_label', 'group_comboboxentry', 'auto_authorize_checkbutton', 'save_message_revealer', 'nickname_label', 'group_label'): self.__dict__[w] = self.xml.get_object(w) self.subscription_table = [ self.uid_label, self.uid_entry, self.show_contact_info_button, self.nickname_label, self.nickname_entry, self.group_label, self.group_comboboxentry ] self.add_button.grab_default() self.agents = {'jabber': []} self.gateway_prompt = {} # types to which we are not subscribed but account has an agent for it self.available_types = [] for acct in accounts: for j in app.contacts.get_jid_list(acct[0]): if app.jid_is_transport(j): type_ = app.get_transport_name_from_jid(j, False) if not type_: continue if type_ in self.agents: self.agents[type_].append(j) else: self.agents[type_] = [j] self.gateway_prompt[j] = {'desc': None, 'prompt': None} # Now add the one to which we can register for acct in accounts: for type_ in app.connections[acct[0]].available_transports: if type_ in self.agents: continue self.agents[type_] = [] for jid_ in app.connections[ acct[0]].available_transports[type_]: if jid_ not in self.agents[type_]: self.agents[type_].append(jid_) self.gateway_prompt[jid_] = { 'desc': None, 'prompt': None } self.available_types.append(type_) uf_type = {'jabber': 'XMPP', 'gadu-gadu': 'Gadu Gadu', 'icq': 'ICQ'} # Jabber as first liststore = self.protocol_combobox.get_model() liststore.append(['XMPP', 'xmpp', 'jabber']) for type_ in self.agents: if type_ == 'jabber': continue if type_ in uf_type: liststore.append([uf_type[type_], type_ + '-online', type_]) else: liststore.append([type_, type_ + '-online', type_]) if account: for service in self.agents[type_]: con = app.connections[account] con.get_module('Gateway').request_gateway_prompt(service) self.protocol_combobox.set_active(0) self.auto_authorize_checkbutton.show() if jid: self.jid_escaped = True type_ = app.get_transport_name_from_jid(jid) if not type_: type_ = 'jabber' if type_ == 'jabber': self.uid_entry.set_text(jid) transport = None else: uid, transport = app.get_name_and_server_from_jid(jid) self.uid_entry.set_text(uid.replace('%', '@', 1)) # set protocol_combobox model = self.protocol_combobox.get_model() iter_ = model.get_iter_first() i = 0 while iter_: if model[iter_][2] == type_: self.protocol_combobox.set_active(i) break iter_ = model.iter_next(iter_) i += 1 # set protocol_jid_combobox self.protocol_jid_combobox.set_active(0) model = self.protocol_jid_combobox.get_model() iter_ = model.get_iter_first() i = 0 while iter_: if model[iter_][0] == transport: self.protocol_jid_combobox.set_active(i) break iter_ = model.iter_next(iter_) i += 1 if user_nick: self.nickname_entry.set_text(user_nick) self.nickname_entry.grab_focus() else: self.jid_escaped = False self.uid_entry.grab_focus() group_names = [] for acct in accounts: for g in app.groups[acct[0]].keys(): if g not in helpers.special_groups and g not in group_names: group_names.append(g) group_names.sort() i = 0 for g in group_names: self.group_comboboxentry.append_text(g) if group == g: self.group_comboboxentry.set_active(i) i += 1 if len(accounts) > 1: liststore = self.account_combobox.get_model() for acc in accounts: liststore.append(acc) self.account_combobox.set_active_id(self.account) self.account_label.show() self.account_combobox.show() if len(self.agents) > 1: self.protocol_label.show() self.protocol_combobox.show() if self.account: message_buffer = self.message_textview.get_buffer() msg = helpers.from_one_line( helpers.get_subscription_request_msg(self.account)) message_buffer.set_text(msg) self.uid_entry.connect('changed', self.on_uid_entry_changed) self.show_all() app.ged.register_event_handler('gateway-prompt-received', ged.GUI1, self._nec_gateway_prompt_received) app.ged.register_event_handler('presence-received', ged.GUI1, self._nec_presence_received)
def handle_incoming_pres_event(self, pres_obj): if app.jid_is_transport(pres_obj.jid): return True account = pres_obj.conn.name self.jid = pres_obj.jid resource = pres_obj.resource or '' # It isn't an agent for c in pres_obj.contact_list: if c.resource == resource: # we look for other connected resources continue if c.show not in ('offline', 'error'): return True # no other resource is connected, let's look in metacontacts family = app.contacts.get_metacontacts_family(account, self.jid) for info in family: acct_ = info['account'] jid_ = info['jid'] c_ = app.contacts.get_contact_with_highest_priority(acct_, jid_) if not c_: continue if c_.jid == self.jid: continue if c_.show not in ('offline', 'error'): return True if pres_obj.old_show < 2 and pres_obj.new_show > 1: event = 'contact_connected' server = app.get_server_from_jid(self.jid) account_server = account + '/' + server block_transport = False if account_server in app.block_signed_in_notifications and \ app.block_signed_in_notifications[account_server]: block_transport = True if helpers.allow_showing_notification(account, 'notify_on_signin') \ and not app.block_signed_in_notifications[account] and \ not block_transport: self.do_popup = True if app.config.get_per('soundevents', 'contact_connected', 'enabled') and not app.block_signed_in_notifications[account] and\ not block_transport and helpers.allow_sound_notification(account, 'contact_connected'): self.sound_event = event self.do_sound = True elif pres_obj.old_show > 1 and pres_obj.new_show < 2: event = 'contact_disconnected' if helpers.allow_showing_notification(account, 'notify_on_signout'): self.do_popup = True if app.config.get_per('soundevents', 'contact_disconnected', 'enabled') and helpers.allow_sound_notification(account, event): self.sound_event = event self.do_sound = True # Status change (not connected/disconnected or error (<1)) elif pres_obj.new_show > 1: event = 'status_change' else: return True if app.jid_is_transport(self.jid): self.transport_name = app.get_transport_name_from_jid(self.jid) self.show = pres_obj.show self.popup_timeout = app.config.get('notification_timeout') nick = i18n.direction_mark + app.get_name_from_jid(account, self.jid) if event == 'status_change': self.popup_title = _('%(nick)s Changed Status') % \ {'nick': nick} self.popup_text = _('%(nick)s is now %(status)s') % \ {'nick': nick, 'status': helpers.get_uf_show(pres_obj.show)} if pres_obj.status: self.popup_text = self.popup_text + " : " + pres_obj.status self.popup_event_type = _('Contact Changed Status') elif event == 'contact_connected': self.popup_title = _('%(nickname)s Signed In') % {'nickname': nick} self.popup_text = '' if pres_obj.status: self.popup_text = pres_obj.status self.popup_event_type = _('Contact Signed In') elif event == 'contact_disconnected': self.popup_title = _('%(nickname)s Signed Out') % {'nickname': nick} self.popup_text = '' if pres_obj.status: self.popup_text = pres_obj.status self.popup_event_type = _('Contact Signed Out')
def populate(self, contacts, account, typ): """ Populate the Tooltip Grid with data of from the contact """ self.current_row = 0 self.account = account if self.last_widget: self.last_widget.set_vexpand(False) self.clear_tooltip() if account == 'all': # Tooltip for merged accounts row accounts = helpers.get_notification_icon_tooltip_dict() self.spacer_label = '' self.fill_table_with_accounts(accounts) self.tooltip_grid.attach(self.table, 0, 3, 2, 1) self.table.show_all() return if typ == 'account': jid = app.get_jid_from_account(account) contacts = [] connection = app.connections[account] # get our current contact info nbr_on, nbr_total = app.\ contacts.get_nb_online_total_contacts( accounts=[account]) account_name = account if app.account_is_connected(account): account_name += ' (%s/%s)' % (repr(nbr_on), repr(nbr_total)) contact = app.contacts.create_self_contact(jid=jid, account=account, name=account_name, show=connection.get_status(), status=connection.status, resource=connection.server_resource, priority=connection.priority) if app.connections[account].gpg: contact.keyID = app.config.get_per('accounts', connection.name, 'keyid') contacts.append(contact) # if we're online ... if connection.connection: roster = connection.connection.getRoster() # in threadless connection when no roster stanza is sent # 'roster' is None if roster and roster.getItem(jid): resources = roster.getResources(jid) # ...get the contact info for our other online # resources for resource in resources: # Check if we already have this resource found = False for contact_ in contacts: if contact_.resource == resource: found = True break if found: continue show = roster.getShow(jid + '/' + resource) if not show: show = 'online' contact = app.contacts.create_self_contact( jid=jid, account=account, show=show, status=roster.getStatus( jid + '/' + resource), priority=roster.getPriority( jid + '/' + resource), resource=resource) contacts.append(contact) # Username/Account/Groupchat self.prim_contact = app.contacts.get_highest_prio_contact_from_contacts( contacts) self.contact_jid = self.prim_contact.jid name = GLib.markup_escape_text(self.prim_contact.get_shown_name()) name_markup = '<b>{}</b>'.format(name) if app.config.get('mergeaccounts'): color = app.config.get('tooltip_account_name_color') account_name = GLib.markup_escape_text(self.prim_contact.account.name) name_markup += " <span foreground='{}'>({})</span>".format( color, account_name) if account and helpers.jid_is_blocked(account, self.prim_contact.jid): name_markup += _(' [blocked]') try: if self.prim_contact.jid in app.interface.minimized_controls[account]: name_markup += _(' [minimized]') except KeyError: pass self.name.set_markup(name_markup) self.name.show() self.num_resources = 0 # put contacts in dict, where key is priority contacts_dict = {} for contact in contacts: if contact.resource: self.num_resources += 1 priority = int(contact.priority) if priority in contacts_dict: contacts_dict[priority].append(contact) else: contacts_dict[priority] = [contact] if self.num_resources > 1: self.status_label.show() transport = app.get_transport_name_from_jid(self.prim_contact.jid) if transport: file_path = os.path.join(helpers.get_transport_path(transport), '16x16') else: iconset = app.config.get('iconset') if not iconset: iconset = 'dcraven' file_path = os.path.join(helpers.get_iconset_path(iconset), '16x16') contact_keys = sorted(contacts_dict.keys()) contact_keys.reverse() for priority in contact_keys: for acontact in contacts_dict[priority]: icon_name = self._get_icon_name_for_tooltip(acontact) if acontact.status and len(acontact.status) > 25: status = '' add_text = True else: status = acontact.status add_text = False status_line = self.get_status_info(acontact.resource, acontact.priority, acontact.show, status) self.add_status_row(file_path, icon_name, status_line) if add_text: self.add_text_row(acontact.status, 2) self.tooltip_grid.attach(self.table, 0, 3, 2, 1) self.table.show_all() else: # only one resource if contact.show and contact.status: status = contact.status.strip() if status: self.status.set_text(status) self.status.show() self.status_label.show() # PEP Info self._append_pep_info(contact) # JID self.jid.set_text(self.prim_contact.jid) self.jid.show() self.jid_label.show() # contact has only one ressource if self.num_resources == 1 and contact.resource: res = GLib.markup_escape_text(contact.resource) prio = str(contact.priority) self.resource.set_text("{} ({})".format(res, prio)) self.resource.show() self.resource_label.show() if self.prim_contact.jid not in app.gc_connected[account]: if (account and self.prim_contact.sub and self.prim_contact.sub != 'both'): # ('both' is the normal sub so we don't show it) self.sub.set_text(helpers.get_uf_sub(self.prim_contact.sub)) self.sub.show() self.sub_label.show() if self.prim_contact.keyID: keyID = None if len(self.prim_contact.keyID) == 8: keyID = self.prim_contact.keyID elif len(self.prim_contact.keyID) == 16: keyID = self.prim_contact.keyID[8:] if keyID: self.pgp.set_text(keyID) self.pgp.show() self.pgp_label.show() self._set_idle_time(contact) # Avatar pixbuf = app.contacts.get_avatar( account, self.prim_contact.jid, AvatarSize.TOOLTIP) if pixbuf is None: return self.avatar.set_from_pixbuf(pixbuf) self.avatar.show() # Sets the Widget that is at the bottom to expand. # This is needed in case the Picture takes more Space then the Labels i = 1 while i < 15: if self.tooltip_grid.get_child_at(0, i): if self.tooltip_grid.get_child_at(0, i).get_visible(): self.last_widget = self.tooltip_grid.get_child_at(0, i) i += 1 self.last_widget.set_vexpand(True)
def build_invite_submenu(invite_menuitem, list_, ignore_rooms=None, show_bookmarked=False, force_resource=False): """ list_ in a list of (contact, account) force_resource means we want to send invitation even if there is only one resource """ if ignore_rooms is None: ignore_rooms = [] roster = app.interface.roster # used if we invite only one contact with several resources contact_list = [] if len(list_) == 1: contact, account = list_[0] contact_list = app.contacts.get_contacts(account, contact.jid) 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) transport = app.get_transport_name_from_jid(contact.jid) if transport == 'jabber': transport = None if contacts_transport == -1: contacts_transport = transport elif contacts_transport != transport: contacts_transport = False if contacts_transport is False: # they are not all from the same transport invite_menuitem.set_sensitive(False) return invite_to_submenu = Gtk.Menu() invite_menuitem.set_submenu(invite_to_submenu) rooms = [] # a list of (room_jid, account) tuple minimized_controls = [] for account in connected_accounts: minimized_controls += \ list(app.interface.minimized_controls[account].values()) for gc_control in app.interface.msg_win_mgr.get_controls( message_control.TYPE_GC) + minimized_controls: acct = gc_control.account if acct not in connected_accounts: continue room_jid = gc_control.room_jid if room_jid in ignore_rooms: continue if room_jid in app.gc_connected[acct] and \ app.gc_connected[acct][room_jid] and \ contacts_transport in ['jabber', None]: rooms.append((room_jid, acct)) if rooms: item = Gtk.SeparatorMenuItem.new() # separator invite_to_submenu.append(item) for (room_jid, account) in rooms: menuitem = Gtk.MenuItem.new_with_label(room_jid.split('@')[0]) 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 if contact.jid == app.get_jid_from_account(account): resource = contact.resource else: resource = None menuitem.connect('activate', roster.on_invite_to_room, list_, room_jid, account, resource) invite_to_submenu.append(menuitem) if not show_bookmarked: return rooms2 = [] # a list of (room_jid, account) tuple r_jids = [] # list of room jids for account in connected_accounts: con = app.connections[account] for bookmark in con.get_module('Bookmarks').bookmarks: if bookmark.jid in r_jids: continue if bookmark.jid not in app.gc_connected[account] or not \ app.gc_connected[account][bookmark.jid]: rooms2.append((bookmark.jid, account)) r_jids.append(bookmark.jid) if not rooms2: return item = Gtk.SeparatorMenuItem.new() # separator invite_to_submenu.append(item) for (room_jid, account) in rooms2: menuitem = Gtk.MenuItem.new_with_label(room_jid.getNode()) if len(contact_list) > 1: # several resources menuitem.set_submenu(build_resources_submenu( contact_list, account, roster.on_invite_to_room, str(room_jid), account)) else: # use resource if it's self contact if contact.jid == app.get_jid_from_account(account): resource = contact.resource else: resource = None menuitem.connect('activate', roster.on_invite_to_room, list_, str(room_jid), account, resource) invite_to_submenu.append(menuitem)
def get_contact_menu(contact, account, use_multiple_contacts=True, show_start_chat=True, show_encryption=False, show_buttonbar_items=True, control=None, gc_contact=None, is_anonymous=True): """ 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 our_jid = jid == app.get_jid_from_account(account) roster = app.interface.roster xml = get_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') information_menuitem = xml.get_object('information_menuitem') history_menuitem = xml.get_object('history_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 = [] contacts = app.contacts.get_contacts(account, jid) if len(contacts) > 1 and use_multiple_contacts: # several resources start_chat_menuitem.set_submenu(build_resources_submenu(contacts, account, app.interface.on_open_chat_window)) 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', app.interface.on_open_chat_window, contact, account) if contact.supports(NS_FILE) or contact.supports(NS_JINGLE_FILE_TRANSFER_5): 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) 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) else: execute_command_menuitem.set_sensitive(False) rename_menuitem.connect('activate', roster.on_rename, 'contact', jid, account) history_menuitem.set_action_name('app.browse-history') dict_ = {'jid': GLib.Variant('s', contact.jid), 'account': GLib.Variant('s', account)} variant = GLib.Variant('a{sv}', dict_) history_menuitem.set_action_target_value(variant) if control: convert_to_gc_menuitem.connect('activate', control._on_convert_to_gc_menuitem_activate) else: items_to_hide.append(convert_to_gc_menuitem) if _('Not in contact list') not in contact.get_shown_groups(): # contact is in normal group edit_groups_menuitem.connect('activate', roster.on_edit_groups, [(contact, account)]) else: # contact is in group 'Not in contact list' edit_groups_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 if app.account_is_disconnected(account): for widget in (start_chat_menuitem, rename_menuitem, edit_groups_menuitem, send_file_menuitem, convert_to_gc_menuitem, information_menuitem): 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) # Hide items when it's a pm if gc_contact: items_to_hide += [rename_menuitem, edit_groups_menuitem, subscription_menuitem, remove_from_roster_menuitem] for item in items_to_hide: item.set_no_show_all(True) item.hide() # Zeroconf Account if app.config.get_per('accounts', account, 'is_zeroconf'): for item in (send_single_message_menuitem, invite_menuitem, block_menuitem, unblock_menuitem, ignore_menuitem, unignore_menuitem, subscription_menuitem, 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 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: bookmarked = False c_ = app.contacts.get_contact(account, gc_contact.jid, gc_contact.resource) if c_ and c_.supports(NS_CONFERENCE): bookmarked = True build_invite_submenu(invite_menuitem, [(gc_contact, account)], show_bookmarked=bookmarked) else: force_resource = False if control and control.resource: force_resource = True build_invite_submenu(invite_menuitem, [(contact, account)], show_bookmarked=contact.supports(NS_CONFERENCE), force_resource=force_resource) if app.account_is_disconnected(account): invite_menuitem.set_sensitive(False) send_single_message_menuitem.connect('activate', roster.on_send_single_message_menuitem_activate, account, contact) remove_from_roster_menuitem.connect('activate', roster.on_req_usub, [(contact, account)]) information_menuitem.connect('activate', roster.on_info, contact, account) if _('Not in contact list') 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 contact list'), account, contact.groups, contact.name) transport = app.get_transport_name_from_jid(jid, use_config_setting=False) if contact.sub in ('to', 'none') or transport not in ['jabber', None]: revoke_auth_menuitem.set_sensitive(False) else: revoke_auth_menuitem.connect('activate', roster.revoke_auth, jid, account) elif app.connections[account].roster_supported: # contact is in group 'Not in contact list' 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) else: add_to_roster_menuitem.hide() add_to_roster_menuitem.set_no_show_all(True) subscription_menuitem.set_sensitive(False) # Hide items when it's self contact row if our_jid: manage_contact_menuitem.set_sensitive(False) # Unsensitive items when account is offline if app.account_is_disconnected(account): for widget in (send_single_message_menuitem, subscription_menuitem, add_to_roster_menuitem, remove_from_roster_menuitem, execute_command_menuitem): widget.set_sensitive(False) con = app.connections[account] if con and (con.get_module('PrivacyLists').supported or con.get_module('Blocking').supported): transport = app.get_transport_name_from_jid(jid, use_config_setting=False) if helpers.jid_is_blocked(account, jid): block_menuitem.set_no_show_all(True) block_menuitem.hide() if transport != 'jabber': 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() if transport != 'jabber': 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
def __init__(self, account, jids, preselected=None): """ This window is used to transform a one-to-one chat to a MUC. We do 2 things: first select the server and then make a guests list """ self.instances.append(self) self.account = account self.auto_jids = jids self.preselected_jids = preselected self.xml = get_builder('chat_to_muc_window.ui') self.window = self.xml.get_object('chat_to_muc_window') for widget_to_add in ('invite_button', 'cancel_button', 'server_list_comboboxentry', 'guests_treeview', 'guests_store', 'server_and_guests_hseparator', 'server_select_label'): self.__dict__[widget_to_add] = self.xml.get_object(widget_to_add) server_list = [] self.servers = Gtk.ListStore(str) self.server_list_comboboxentry.set_model(self.servers) cell = Gtk.CellRendererText() self.server_list_comboboxentry.pack_start(cell, True) self.server_list_comboboxentry.add_attribute(cell, 'text', 0) # get the muc server of our server con = app.connections[account] service_jid = con.get_module('MUC').service_jid if service_jid is not None: server_list.append(str(service_jid)) # add servers or recently joined groupchats recently_groupchat = app.settings.get_account_setting( account, 'recent_groupchats').split() for g in recently_groupchat: server = app.get_server_from_jid(g) if server not in server_list and not server.startswith('irc'): server_list.append(server) # add a default server if not server_list: server_list.append('conference.jabber.org') for s in server_list: self.servers.append([s]) self.server_list_comboboxentry.set_active(0) # set treeview # name, jid self.guests_store.set_sort_column_id(1, Gtk.SortType.ASCENDING) self.guests_treeview.get_selection().set_mode( Gtk.SelectionMode.MULTIPLE) # All contacts beside the following can be invited: # transports, zeroconf contacts, minimized groupchats def invitable(contact, contact_transport=None): return (contact.jid not in self.auto_jids and contact.jid != app.get_jid_from_account(account) and contact.jid not in app.interface.minimized_controls[account] and not contact.is_transport() and contact_transport in ('jabber', None)) # set jabber id and pseudos for account_ in app.contacts.get_accounts(): if app.connections[account_].is_zeroconf: continue for jid in app.contacts.get_jid_list(account_): contact = app.contacts.get_contact_with_highest_priority( account_, jid) contact_transport = app.get_transport_name_from_jid(jid) # Add contact if it can be invited if invitable(contact, contact_transport) and \ contact.show not in ('offline', 'error'): icon_name = get_icon_name(contact.show) name = contact.name if name == '': name = jid.split('@')[0] iter_ = self.guests_store.append([icon_name, name, jid]) # preselect treeview rows if self.preselected_jids and jid in self.preselected_jids: path = self.guests_store.get_path(iter_) self.guests_treeview.get_selection().select_path(path) # show all self.window.show_all() self.xml.connect_signals(self)
def _populate_grid(self, contacts, account, typ): """ Populate the Tooltip Grid with data of from the contact """ self.current_row = 0 self.account = account if self.last_widget: self.last_widget.set_vexpand(False) self.clear_tooltip() if account == 'all': # Tooltip for merged accounts row accounts = helpers.get_notification_icon_tooltip_dict() self.spacer_label = '' self.fill_table_with_accounts(accounts) self._ui.tooltip_grid.attach(self.table, 1, 3, 2, 1) self.table.show_all() return if typ == 'account': jid = app.get_jid_from_account(account) contacts = [] connection = app.connections[account] # get our current contact info nbr_on, nbr_total = app.\ contacts.get_nb_online_total_contacts(accounts=[account]) account_name = app.get_account_label(account) if app.account_is_connected(account): account_name += ' (%s/%s)' % (repr(nbr_on), repr(nbr_total)) contact = app.contacts.create_self_contact( jid=jid, account=account, name=account_name, show=connection.get_status(), status=connection.status, resource=connection.server_resource, priority=connection.priority) contacts.append(contact) # Username/Account/Groupchat self.prim_contact = app.contacts.get_highest_prio_contact_from_contacts( contacts) if self.prim_contact is None: log.error('No contact for Roster tooltip found') log.error('contacts: %s, typ: %s, account: %s', contacts, typ, account) return self.contact_jid = self.prim_contact.jid name = GLib.markup_escape_text(self.prim_contact.get_shown_name()) name_markup = '<b>{}</b>'.format(name) if app.config.get('mergeaccounts'): color = app.config.get('tooltip_account_name_color') account_name = GLib.markup_escape_text(self.prim_contact.account.name) name_markup += " <span foreground='{}'>({})</span>".format( color, account_name) if account and helpers.jid_is_blocked(account, self.prim_contact.jid): name_markup += _(' [blocked]') try: if self.prim_contact.jid in app.interface.minimized_controls[account]: name_markup += _(' [minimized]') except KeyError: pass self._ui.name.set_markup(name_markup) self._ui.name.show() self.num_resources = 0 # put contacts in dict, where key is priority contacts_dict = {} for contact in contacts: if contact.resource: self.num_resources += 1 priority = int(contact.priority) if priority in contacts_dict: contacts_dict[priority].append(contact) else: contacts_dict[priority] = [contact] if self.num_resources > 1: transport = app.get_transport_name_from_jid(self.prim_contact.jid) if transport == 'jabber': transport = None contact_keys = sorted(contacts_dict.keys()) contact_keys.reverse() for priority in contact_keys: for acontact in contacts_dict[priority]: show = self._get_icon_name_for_tooltip(acontact) if acontact.status and len(acontact.status) > 25: status = '' add_text = True else: status = acontact.status add_text = False status_line = self.get_status_info( acontact.resource, acontact.priority, acontact.show, status) self.add_status_row(show, status_line, transport=transport) if add_text: self.add_text_row(acontact.status, 2) self._ui.tooltip_grid.attach(self.table, 1, 3, 2, 1) self.table.show_all() else: # only one resource if contact.show and contact.status: status = contact.status.strip() if status: self._ui.status.set_text(status) self._ui.status.show() # PEP Info self._append_pep_info(contact) # JID self._ui.jid.set_text(self.prim_contact.jid) self._ui.jid.show() # contact has only one resource if self.num_resources == 1 and contact.resource: res = GLib.markup_escape_text(contact.resource) prio = str(contact.priority) self._ui.resource.set_text("{} ({})".format(res, prio)) self._ui.resource.show() self._ui.resource_label.show() if self.prim_contact.jid not in app.gc_connected[account]: if (account and self.prim_contact.sub and self.prim_contact.sub != 'both'): # ('both' is the normal sub so we don't show it) self._ui.sub.set_text(helpers.get_uf_sub(self.prim_contact.sub)) self._ui.sub.show() self._ui.sub_label.show() self._set_idle_time(contact) # Avatar scale = self._ui.tooltip_grid.get_scale_factor() surface = app.contacts.get_avatar( account, self.prim_contact.jid, AvatarSize.TOOLTIP, scale) self._ui.avatar.set_from_surface(surface) self._ui.avatar.show() app.plugin_manager.gui_extension_point( 'roster_tooltip_populate', self, contacts, self._ui.tooltip_grid) # Sets the Widget that is at the bottom to expand. # This is needed in case the Picture takes more Space than the Labels i = 1 while i < 15: if self._ui.tooltip_grid.get_child_at(1, i): if self._ui.tooltip_grid.get_child_at(1, i).get_visible(): self.last_widget = self._ui.tooltip_grid.get_child_at(1, i) i += 1 self.last_widget.set_vexpand(True)
def build_invite_submenu(invite_menuitem, list_, ignore_rooms=None, show_bookmarked=False, force_resource=False): """ list_ in a list of (contact, account) force_resource means we want to send invitation even if there is only one resource """ if ignore_rooms is None: ignore_rooms = [] roster = app.interface.roster # used if we invite only one contact with several resources contact_list = [] if len(list_) == 1: contact, account = list_[0] contact_list = app.contacts.get_contacts(account, contact.jid) 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) transport = app.get_transport_name_from_jid(contact.jid) if transport == 'jabber': transport = None if contacts_transport == -1: contacts_transport = transport elif contacts_transport != transport: contacts_transport = False if contacts_transport == False: # they are not all from the same transport invite_menuitem.set_sensitive(False) return invite_to_submenu = Gtk.Menu() invite_menuitem.set_submenu(invite_to_submenu) invite_to_new_room_menuitem = Gtk.MenuItem.new_with_mnemonic( _('_New Group Chat')) if len(contact_list) > 1: # several resources invite_to_new_room_menuitem.set_submenu( build_resources_submenu(contact_list, account, roster.on_invite_to_new_room, cap=NS_MUC)) elif len(list_) == 1 and contact.supports(NS_MUC): invite_menuitem.set_sensitive(True) # use resource if it's self contact if contact.jid == app.get_jid_from_account(account) or force_resource: resource = contact.resource else: resource = None invite_to_new_room_menuitem.connect('activate', roster.on_invite_to_new_room, list_, resource) elif len(list_) > 1: list2 = [] for (c, a) in list_: if c.supports(NS_MUC): list2.append((c, a)) if len(list2) > 0: invite_to_new_room_menuitem.connect('activate', roster.on_invite_to_new_room, list2, None) else: invite_menuitem.set_sensitive(False) else: invite_menuitem.set_sensitive(False) # transform None in 'jabber' c_t = contacts_transport or 'jabber' muc_jid = {} for account in connected_accounts: for t in app.connections[account].muc_jid: muc_jid[t] = app.connections[account].muc_jid[t] 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: minimized_controls += \ list(app.interface.minimized_controls[account].values()) for gc_control in app.interface.msg_win_mgr.get_controls( message_control.TYPE_GC) + minimized_controls: acct = gc_control.account if acct not in connected_accounts: continue room_jid = gc_control.room_jid if room_jid in ignore_rooms: continue if room_jid in app.gc_connected[acct] and \ app.gc_connected[acct][room_jid] and \ contacts_transport in ['jabber', None]: rooms.append((room_jid, acct)) if len(rooms): item = Gtk.SeparatorMenuItem.new() # separator invite_to_submenu.append(item) for (room_jid, account) in rooms: menuitem = Gtk.MenuItem.new_with_label(room_jid.split('@')[0]) 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 if contact.jid == app.get_jid_from_account(account): resource = contact.resource else: resource = None menuitem.connect('activate', roster.on_invite_to_room, list_, room_jid, account, resource) invite_to_submenu.append(menuitem) if not show_bookmarked: return rooms2 = [] # a list of (room_jid, account) tuple r_jids = [] # list of room jids for account in connected_accounts: for room in app.connections[account].bookmarks: r_jid = room['jid'] if r_jid in r_jids: continue if r_jid not in app.gc_connected[account] or not \ app.gc_connected[account][r_jid]: rooms2.append((r_jid, account)) r_jids.append(r_jid) if not rooms2: return item = Gtk.SeparatorMenuItem.new() # separator invite_to_submenu.append(item) for (room_jid, account) in rooms2: menuitem = Gtk.MenuItem.new_with_label(room_jid.split('@')[0]) 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 if contact.jid == app.get_jid_from_account(account): resource = contact.resource else: resource = None menuitem.connect('activate', roster.on_invite_to_room, list_, room_jid, account, resource) invite_to_submenu.append(menuitem)
def get_contact_menu(contact, account, use_multiple_contacts=True, show_start_chat=True, show_encryption=False, show_buttonbar_items=True, control=None, gc_contact=None, is_anonymous=True): """ 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 our_jid = jid == app.get_jid_from_account(account) roster = app.interface.roster 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') add_special_notification_menuitem = xml.get_object( 'add_special_notification_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 = [] contacts = app.contacts.get_contacts(account, jid) if len(contacts) > 1 and use_multiple_contacts: # several resources start_chat_menuitem.set_submenu( build_resources_submenu(contacts, account, app.interface.on_open_chat_window)) 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', app.interface.on_open_chat_window, contact, account) if contact.supports(NS_FILE) or contact.supports( NS_JINGLE_FILE_TRANSFER_5): 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) 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) else: execute_command_menuitem.set_sensitive(False) rename_menuitem.connect('activate', roster.on_rename, 'contact', jid, account) history_menuitem.connect('activate', roster.on_history, contact, account) if control: convert_to_gc_menuitem.connect( 'activate', control._on_convert_to_gc_menuitem_activate) 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)]) if app.connections[account].gpg: 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 if app.account_is_disconnected(account): for widget in (start_chat_menuitem, rename_menuitem, edit_groups_menuitem, send_file_menuitem, convert_to_gc_menuitem, information_menuitem): 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) # Hide items when it's a pm if gc_contact: items_to_hide += [ rename_menuitem, edit_groups_menuitem, subscription_menuitem, remove_from_roster_menuitem ] for item in items_to_hide: item.set_no_show_all(True) item.hide() # Zeroconf Account if app.config.get_per('accounts', account, 'is_zeroconf'): for item in (send_custom_status_menuitem, send_single_message_menuitem, invite_menuitem, block_menuitem, unblock_menuitem, ignore_menuitem, unignore_menuitem, subscription_menuitem, 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 transport = app.get_transport_name_from_jid(jid, use_config_setting=False) if transport and transport != 'jabber': # Transport contact, send custom status unavailable send_custom_status_menuitem.set_sensitive(False) elif blocked: send_custom_status_menuitem.set_sensitive(False) 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: bookmarked = False c_ = app.contacts.get_contact(account, gc_contact.jid, gc_contact.resource) if c_ and c_.supports(NS_CONFERENCE): bookmarked = True build_invite_submenu(invite_menuitem, [(gc_contact, account)], show_bookmarked=bookmarked) else: force_resource = False if control and control.resource: force_resource = True build_invite_submenu(invite_menuitem, [(contact, account)], show_bookmarked=contact.supports(NS_CONFERENCE), force_resource=force_resource) if app.account_is_disconnected(account): invite_menuitem.set_sensitive(False) # One or several resource, we do the same for send_custom_status status_menuitems = Gtk.Menu() 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 status_menuitem = Gtk.MenuItem.new_with_label(helpers.get_uf_show(s)) status_menuitem.connect('activate', roster.on_send_custom_status, [(contact, account)], s) status_menuitems.append(status_menuitem) send_single_message_menuitem.connect( 'activate', roster.on_send_single_message_menuitem_activate, account, contact) remove_from_roster_menuitem.connect('activate', roster.on_req_usub, [(contact, account)]) 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) add_special_notification_menuitem.connect( 'activate', roster.on_add_special_notification_menuitem_activate, jid) else: ask_auth_menuitem.connect( 'activate', roster.req_sub, jid, _('I would like to add you to my roster'), account, contact.groups, contact.name) transport = app.get_transport_name_from_jid(jid, use_config_setting=False) if contact.sub in ('to', 'none') or transport not in ['jabber', None]: revoke_auth_menuitem.set_sensitive(False) else: revoke_auth_menuitem.connect('activate', roster.revoke_auth, jid, account) elif app.connections[account].roster_supported: # 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) else: add_to_roster_menuitem.hide() add_to_roster_menuitem.set_no_show_all(True) subscription_menuitem.set_sensitive(False) # Hide items when it's self contact row if our_jid: manage_contact_menuitem.set_sensitive(False) # Unsensitive items when account is offline if app.account_is_disconnected(account): 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) if app.connections[account] and (app.connections[account].\ privacy_rules_supported or app.connections[account].blocking_supported): if helpers.jid_is_blocked(account, jid): block_menuitem.set_no_show_all(True) block_menuitem.hide() if app.get_transport_name_from_jid(jid, use_config_setting=False)\ and transport != 'jabber': 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() if app.get_transport_name_from_jid(jid, use_config_setting=False)\ and transport != 'jabber': 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
def _populate_grid(self, contacts, account, typ): """ Populate the Tooltip Grid with data of from the contact """ self.current_row = 0 self.account = account if self.last_widget: self.last_widget.set_vexpand(False) self.clear_tooltip() if account == 'all': # Tooltip for merged accounts row self._show_merged_account_tooltip() return if typ == 'account': jid = app.get_jid_from_account(account) contacts = [] connection = app.connections[account] # get our current contact info nbr_on, nbr_total = app.\ contacts.get_nb_online_total_contacts(accounts=[account]) account_name = app.get_account_label(account) if app.account_is_available(account): account_name += ' (%s/%s)' % (repr(nbr_on), repr(nbr_total)) contact = app.contacts.create_self_contact( jid=jid, account=account, name=account_name, show=get_connection_status(account), status=connection.status_message, resource=connection.get_own_jid().resource, priority=connection.priority) contacts.append(contact) # Username/Account/Groupchat self.prim_contact = app.contacts.get_highest_prio_contact_from_contacts( contacts) if self.prim_contact is None: log.error('No contact for Roster tooltip found') log.error('contacts: %s, typ: %s, account: %s', contacts, typ, account) return self.contact_jid = self.prim_contact.jid name = GLib.markup_escape_text(self.prim_contact.get_shown_name()) if app.settings.get('mergeaccounts'): name = GLib.markup_escape_text(self.prim_contact.account.name) self._ui.name.set_markup(name) self._ui.name.show() self.num_resources = 0 # put contacts in dict, where key is priority contacts_dict = {} for contact in contacts: if contact.resource: self.num_resources += 1 priority = int(contact.priority) if priority in contacts_dict: contacts_dict[priority].append(contact) else: contacts_dict[priority] = [contact] if self.num_resources > 1: transport = app.get_transport_name_from_jid(self.prim_contact.jid) if transport == 'jabber': transport = None contact_keys = sorted(contacts_dict.keys()) contact_keys.reverse() for priority in contact_keys: for acontact in contacts_dict[priority]: show = self._get_icon_name_for_tooltip(acontact) status = acontact.status resource_line = '%s (%s)' % (acontact.resource, str(acontact.priority)) self.add_status_row(show, resource_line, transport=transport) if status: self.add_text_row(status, 2) self._ui.tooltip_grid.attach(self.table, 1, 3, 2, 1) self.table.show_all() else: # only one resource if contact.is_groupchat: disco_info = app.storage.cache.get_last_disco_info(contact.jid) if disco_info is not None: description = disco_info.muc_description if description: self._ui.status.set_text(description) self._ui.status.show() elif contact.show and contact.status: status = contact.status.strip() if status: self._ui.status.set_text(status) self._ui.status.show() # PEP Info self._append_pep_info(contact) # JID self._ui.jid.set_text(self.prim_contact.jid) self._ui.jid.show() # contact has only one resource if self.num_resources == 1 and contact.resource: res = GLib.markup_escape_text(contact.resource) prio = str(contact.priority) self._ui.resource.set_text("{} ({})".format(res, prio)) self._ui.resource.show() self._ui.resource_label.show() if self.prim_contact.jid not in app.gc_connected[account]: if (account and self.prim_contact.sub and self.prim_contact.sub != 'both'): # ('both' is the normal sub so we don't show it) self._ui.sub.set_text(helpers.get_uf_sub( self.prim_contact.sub)) self._ui.sub.show() self._ui.sub_label.show() self._set_idle_time(contact) # Avatar scale = self._ui.tooltip_grid.get_scale_factor() surface = app.contacts.get_avatar(account, self.prim_contact.jid, AvatarSize.TOOLTIP, scale) self._ui.avatar.set_from_surface(surface) self._ui.avatar.show() app.plugin_manager.gui_extension_point('roster_tooltip_populate', self, contacts, self._ui.tooltip_grid) # Sets the Widget that is at the bottom to expand. # This is needed in case the Picture takes more Space than the Labels i = 1 while i < 15: if self._ui.tooltip_grid.get_child_at(1, i): if self._ui.tooltip_grid.get_child_at(1, i).get_visible(): self.last_widget = self._ui.tooltip_grid.get_child_at(1, i) i += 1 self.last_widget.set_vexpand(True)