Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    def fill_jabber_page(self):
        self.xml.get_object('nickname_label').set_markup(
            '<b><span size="x-large">' + self.contact.get_shown_name() +
            '</span></b>')
        self.xml.get_object('jid_label').set_text(self.contact.jid)

        subscription_label = self.xml.get_object('subscription_label')
        ask_label = self.xml.get_object('ask_label')
        if self.gc_contact:
            self.xml.get_object('subscription_title_label').set_markup(
                Q_("?Role in Group Chat:<b>Role:</b>"))
            uf_role = helpers.get_uf_role(self.gc_contact.role)
            subscription_label.set_text(uf_role)

            self.xml.get_object('ask_title_label').set_markup(
                _("<b>Affiliation:</b>"))
            uf_affiliation = helpers.get_uf_affiliation(
                self.gc_contact.affiliation)
            ask_label.set_text(uf_affiliation)
        else:
            uf_sub = helpers.get_uf_sub(self.contact.sub)
            subscription_label.set_text(uf_sub)
            if self.contact.sub == 'from':
                tt_text = _(
                    "This contact is interested in your presence information, but you are not interested in their presence"
                )
            elif self.contact.sub == 'to':
                tt_text = _(
                    "You are interested in the contact's presence information, but it is not mutual"
                )
            elif self.contact.sub == 'both':
                tt_text = _(
                    "The contact and you want to exchange presence information"
                )
            else:  # None
                tt_text = _(
                    "You and the contact have a mutual disinterest in each-others presence information"
                )
            subscription_label.set_tooltip_text(tt_text)

            uf_ask = helpers.get_uf_ask(self.contact.ask)
            ask_label.set_text(uf_ask)
            if self.contact.ask == 'subscribe':
                tt_text = _(
                    "You are waiting contact's answer about your subscription request"
                )
            else:
                tt_text = _("There is no pending subscription request.")
            ask_label.set_tooltip_text(tt_text)

        resources = '%s (%s)' % (self.contact.resource,
                                 str(self.contact.priority))
        uf_resources = self.contact.resource + _(' resource with priority ')\
                + str(self.contact.priority)
        if not self.contact.status:
            self.contact.status = ''

        con = app.connections[self.account]

        # do not wait for os_info if contact is not connected or has error
        # additional check for observer is needed, as show is offline for him
        if self.contact.show in ('offline', 'error')\
        and not self.contact.is_observer():
            self.os_info_arrived = True
        else:  # Request os info if contact is connected
            if self.gc_contact:
                con.get_module('SoftwareVersion').request_software_version(
                    self.real_jid,
                    callback=self.set_os_info,
                    user_data=self.real_jid)
            else:
                jid = self.contact.get_full_jid()
                con.get_module('SoftwareVersion').request_software_version(
                    jid, callback=self.set_os_info, user_data=jid)

        # do not wait for entity_time if contact is not connected or has error
        # additional check for observer is needed, as show is offline for him
        if self.contact.show in ('offline', 'error')\
        and not self.contact.is_observer():
            self.entity_time_arrived = True
        else:  # Request entity time if contact is connected
            if self.gc_contact:
                j, r = app.get_room_and_nick_from_fjid(self.real_jid)
                GLib.idle_add(
                    con.get_module('EntityTime').request_entity_time, j, r)
            else:
                GLib.idle_add(
                    con.get_module('EntityTime').request_entity_time,
                    self.contact.jid, self.contact.resource)

        self.os_info = {
            0: {
                'resource': self.real_resource,
                'client': '',
                'os': ''
            }
        }
        self.time_info = {0: {'resource': self.real_resource, 'time': ''}}
        i = 1
        contact_list = app.contacts.get_contacts(self.account,
                                                 self.contact.jid)
        if contact_list:
            for c in contact_list:
                if c.resource != self.contact.resource:
                    resources += '\n%s (%s)' % (c.resource, str(c.priority))
                    uf_resources += '\n' + c.resource + \
                            _(' resource with priority ') + str(c.priority)
                    if c.show not in ('offline', 'error'):
                        jid = c.get_full_jid()
                        con.get_module(
                            'SoftwareVersion').request_software_version(
                                jid, callback=self.set_os_info, user_data=jid)
                        GLib.idle_add(
                            con.get_module('EntityTime').request_entity_time,
                            c.jid, c.resource)
                    self.os_info[i] = {
                        'resource': c.resource,
                        'client': '',
                        'os': ''
                    }
                    self.time_info[i] = {'resource': c.resource, 'time': ''}
                    i += 1

        self.xml.get_object('resource_prio_label').set_text(resources)
        resource_prio_label_eventbox = self.xml.get_object(
            'resource_prio_label_eventbox')
        resource_prio_label_eventbox.set_tooltip_text(uf_resources)

        self.fill_status_label()

        if self.gc_contact:
            con.get_module('VCardTemp').request_vcard(
                self._nec_vcard_received,
                self.gc_contact.get_full_jid(),
                room=True)
        else:
            con.get_module('VCardTemp').request_vcard(self._nec_vcard_received,
                                                      self.contact.jid)
Exemple #4
0
    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)