示例#1
0
def build_resources_submenu(contacts, account, action, room_jid=None,
                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
    """
    roster = gajim.interface.roster
    sub_menu = gtk.Menu()

    iconset = gajim.config.get('iconset')
    if not iconset:
        iconset = gajim.config.DEFAULT_ICONSET
    path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
    for c in contacts:
        # icon MUST be different instance for every item
        state_images = gtkgui_helpers.load_iconset(path)
        item = gtk.ImageMenuItem('%s (%s)' % (c.resource, str(c.priority)))
        icon_name = helpers.get_icon_name_to_show(c, account)
        icon = state_images[icon_name]
        item.set_image(icon)
        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
    def connect_with_roster_draw_contact(self, roster, jid, account, contact):
        if not self.active:
            return
        if gajim.jid_is_transport(jid):
            return

        child_iters = roster._get_contact_iter(jid, account, contact,
            roster.model)
        if not child_iters:
            return

        icon_name = helpers.get_icon_name_to_show(contact, account)
        if gajim.events.get_events(account, jid) or icon_name == 'requested':
            return

        host = jid.split('@')[1]
        server = self.known_servers.get(host, False)
        if not server:
            return

        if server not in roster.transports_state_images['16']:
            # we don't have iconset for this transport loaded yet. Let's do it
            self.make_transport_state_images(roster, server)
        if server in roster.transports_state_images['16'] and \
            icon_name in roster.transports_state_images['16'][server]:
            state_images = roster.transports_state_images['16'][server]
            img = state_images[icon_name]
            for child_iter in child_iters:
                roster.model[child_iter][0] = img
    def connect_with_roster_draw_contact(self, roster, jid, account, contact):
        if not self.active:
            return
        if gajim.jid_is_transport(jid):
            return

        child_iters = roster._get_contact_iter(jid, account, contact,
                                               roster.model)
        if not child_iters:
            return

        icon_name = helpers.get_icon_name_to_show(contact, account)
        if gajim.events.get_events(account, jid) or icon_name == 'requested':
            return

        host = jid.split('@')[1]
        server = self.known_servers.get(host, False)
        if not server:
            return

        if server not in roster.transports_state_images['16']:
            # we don't have iconset for this transport loaded yet. Let's do it
            self.make_transport_state_images(roster, server)
        if server in roster.transports_state_images['16'] and \
            icon_name in roster.transports_state_images['16'][server]:
            state_images = roster.transports_state_images['16'][server]
            img = state_images[icon_name]
            for child_iter in child_iters:
                roster.model[child_iter][0] = img
示例#4
0
    def populate(self, contacts):
        self.create_window()
        self.hbox = gtk.HBox()
        self.hbox.set_homogeneous(False)
        self.hbox.set_spacing(0)
        self.create_table()
        if not contacts or len(contacts) == 0:
            # Tooltip for merged accounts row
            accounts = self.get_accounts_info()
            self.current_row = 0
            self.table.resize(2, 1)
            self.spacer_label = ""
            self.fill_table_with_accounts(accounts)
            self.hbox.add(self.table)
            self.win.add(self.hbox)
            return
            # primary contact
        prim_contact = gajim.get_highest_prio_contact_from_contacts(contacts)

        # try to find the image for the contact status
        icon_name = helpers.get_icon_name_to_show(prim_contact)
        state_file = icon_name.replace(" ", "_")
        transport = gajim.get_transport_name_from_jid(prim_contact.jid)
        if transport:
            file_path = os.path.join(gajim.DATA_DIR, "iconsets", "transports", transport, "16x16")
        else:
            iconset = gajim.config.get("iconset")
            if not iconset:
                iconset = "dcraven"
            file_path = os.path.join(gajim.DATA_DIR, "iconsets", iconset, "16x16")

        files = []
        file_full_path = os.path.join(file_path, state_file)
        files.append(file_full_path + ".png")
        files.append(file_full_path + ".gif")
        self.image.set_from_pixbuf(None)
        for file in files:
            if os.path.exists(file):
                self.image.set_from_file(file)
                break

        info = '<span size="large" weight="bold">' + prim_contact.jid + "</span>"
        info += (
            '\n<span weight="bold">'
            + _("Name: ")
            + "</span>"
            + gtkgui_helpers.escape_for_pango_markup(prim_contact.name)
        )
        if prim_contact.sub:
            info += (
                '\n<span weight="bold">'
                + _("Subscription: ")
                + "</span>"
                + gtkgui_helpers.escape_for_pango_markup(prim_contact.sub)
            )

        if prim_contact.keyID:
            keyID = None
            if len(prim_contact.keyID) == 8:
                keyID = prim_contact.keyID
            elif len(prim_contact.keyID) == 16:
                keyID = prim_contact.keyID[8:]
            if keyID:
                info += (
                    '\n<span weight="bold">'
                    + _("OpenPGP: ")
                    + "</span>"
                    + gtkgui_helpers.escape_for_pango_markup(keyID)
                )

        num_resources = 0
        for contact in contacts:
            if contact.resource:
                num_resources += 1
        if num_resources > 1:
            self.current_row = 1
            self.table.resize(2, 1)
            info += '\n<span weight="bold">' + _("Status: ") + "</span>"
            for contact in contacts:
                if contact.resource:
                    status_line = self.get_status_info(contact.resource, contact.priority, contact.show, contact.status)
                    icon_name = helpers.get_icon_name_to_show(contact)
                    self.add_status_row(file_path, icon_name, status_line)

        else:  # only one resource
            if contact.resource:
                info += (
                    '\n<span weight="bold">'
                    + _("Resource: ")
                    + "</span>"
                    + gtkgui_helpers.escape_for_pango_markup(contact.resource)
                    + " ("
                    + unicode(contact.priority)
                    + ")"
                )
            if contact.show:
                info += '\n<span weight="bold">' + _("Status: ") + "</span>" + helpers.get_uf_show(contact.show)
                if contact.status:
                    status = contact.status.strip()
                    if status != "":
                        # reduce long status
                        # (no more than 130 chars on line and no more than 5 lines)
                        status = gtkgui_helpers.reduce_chars_newlines(status, 130, 5)
                        # escape markup entities.
                        info += " - " + gtkgui_helpers.escape_for_pango_markup(status)

        self.text_label.set_markup(info)
        self.hbox.pack_start(self.image, False, False)
        self.hbox.pack_start(self.table, True, True)
        self.win.add(self.hbox)