Exemple #1
0
    def set_img(self):
        """
        Apart from image, we also update tooltip text here
        """
        def really_set_img():
            if image.get_storage_type() == gtk.IMAGE_PIXBUF:
                self.status_icon.set_from_pixbuf(image.get_pixbuf())
            # FIXME: oops they forgot to support GIF animation?
            # or they were lazy to get it to work under Windows! WTF!
            elif image.get_storage_type() == gtk.IMAGE_ANIMATION:
                self.status_icon.set_from_pixbuf(
                        image.get_animation().get_static_image())
            #       self.status_icon.set_from_animation(image.get_animation())

        if not gajim.interface.systray_enabled:
            return
        if gajim.config.get('trayicon') == 'always':
            self.status_icon.set_visible(True)
        if gajim.events.get_nb_systray_events():
            self.status_icon.set_visible(True)
            if gajim.config.get('trayicon_blink'):
                self.status_icon.set_blinking(True)
            else:
                image = gtkgui_helpers.load_icon('event')
                really_set_img()
                return
        else:
            if gajim.config.get('trayicon') == 'on_event':
                self.status_icon.set_visible(False)
            self.status_icon.set_blinking(False)

        image = gajim.interface.jabber_state_images[self.statusicon_size][
                                                                self.status]
        really_set_img()
Exemple #2
0
    def set_img(self):
        """
        Apart from image, we also update tooltip text here
        """
        def really_set_img():
            if image.get_storage_type() == Gtk.ImageType.PIXBUF:
                self.status_icon.set_from_pixbuf(image.get_pixbuf())
            # FIXME: oops they forgot to support GIF animation?
            # or they were lazy to get it to work under Windows! WTF!
            elif image.get_storage_type() == Gtk.ImageType.ANIMATION:
                self.status_icon.set_from_pixbuf(
                        image.get_animation().get_static_image())
            #       self.status_icon.set_from_animation(image.get_animation())

        if not gajim.interface.systray_enabled:
            return
        if gajim.config.get('trayicon') == 'always':
            self.status_icon.set_visible(True)
        if gajim.events.get_nb_systray_events():
            self.status_icon.set_visible(True)
#            if gajim.config.get('trayicon_blink'):
#                self.status_icon.set_blinking(True)
#            else:
            image = gtkgui_helpers.load_icon('event')
            really_set_img()
            return
        else:
            if gajim.config.get('trayicon') == 'on_event':
                self.status_icon.set_visible(False)
#            self.status_icon.set_blinking(False)

        image = gajim.interface.jabber_state_images[self.statusicon_size][
                                                                self.status]
        really_set_img()
Exemple #3
0
    def make_link_menu(self, event, kind, text):
        from gtkgui_helpers import get_gtk_builder, load_icon
        xml = get_gtk_builder('chat_context_menu.ui')
        menu = xml.get_object('chat_context_menu')
        childs = menu.get_children()
        if kind == 'url':
            childs[0].connect('activate', self.on_copy_link_activate, text)
            childs[1].connect('activate', self.on_open_link_activate, kind,
                text)
            childs[2].hide() # copy mail address
            childs[3].hide() # open mail composer
            childs[4].hide() # jid section separator
            childs[5].hide() # start chat
            childs[6].hide() # join group chat
            childs[7].hide() # add to roster
        else: # It's a mail or a JID
            # load muc icon
            join_group_chat_menuitem = xml.get_object('join_group_chat_menuitem')
            muc_icon = load_icon('muc_active')
            if muc_icon:
                join_group_chat_menuitem.set_image(muc_icon)

            text = text.lower()
            if text.startswith('xmpp:'):
                text = text[5:]
            childs[2].connect('activate', self.on_copy_link_activate, text)
            childs[3].connect('activate', self.on_open_link_activate, kind,
                text)
#            childs[5].connect('activate', self.on_start_chat_activate, text)
            childs[6].connect('activate',
                self.on_join_group_chat_menuitem_activate, text)

#            if self.account and gajim.connections[self.account].\
#            roster_supported:
#                childs[7].connect('activate',
#                    self.on_add_to_roster_activate, text)
#                childs[7].show() # show add to roster menuitem
#            else:
#                childs[7].hide() # hide add to roster menuitem

            if kind == 'xmpp':
                childs[0].connect('activate', self.on_copy_link_activate,
                    'xmpp:' + text)
                childs[2].hide() # copy mail address
                childs[3].hide() # open mail composer
            elif kind == 'mail':
                childs[6].hide() # join group chat

            if kind != 'xmpp':
                childs[0].hide() # copy link location
            childs[1].hide() # open link in browser
            childs[4].hide() # jid section separator
            childs[5].hide() # start chat
            childs[7].hide() # add to roster

        menu.popup(None, None, None, event.button, event.time)
	def make_link_menu(self, event, kind, text):
		xml = gtkgui_helpers.get_glade('chat_context_menu.glade')
		menu = xml.get_widget('chat_context_menu')
		childs = menu.get_children()
		if kind == 'url':
			id = childs[0].connect('activate', self.on_copy_link_activate, text)
			self.handlers[id] = childs[0]
			id = childs[1].connect('activate', self.on_open_link_activate, kind,
				text)
			self.handlers[id] = childs[1]
			childs[2].hide() # copy mail address
			childs[3].hide() # open mail composer
			childs[4].hide() # jid section separator
			childs[5].hide() # start chat
			childs[6].hide() # join group chat
			childs[7].hide() # add to roster
		else: # It's a mail or a JID
			# load muc icon
			join_group_chat_menuitem = xml.get_widget('join_group_chat_menuitem')
			muc_icon = gtkgui_helpers.load_icon('muc_active')
			if muc_icon:
				join_group_chat_menuitem.set_image(muc_icon)

			text = text.lower()
			id = childs[2].connect('activate', self.on_copy_link_activate, text)
			self.handlers[id] = childs[2]
			id = childs[3].connect('activate', self.on_open_link_activate, kind,
				text)
			self.handlers[id] = childs[3]
			id = childs[5].connect('activate', self.on_start_chat_activate, text)
			self.handlers[id] = childs[5]
			id = childs[6].connect('activate',
				self.on_join_group_chat_menuitem_activate, text)
			self.handlers[id] = childs[6]

			allow_add = False
			c = gajim.contacts.get_first_contact_from_jid(self.account, text)
			if c and not gajim.contacts.is_pm_from_contact(self.account, c):
				if _('Not in Roster') in c.groups:
					allow_add = True
			else: # he or she's not at all in the account contacts
				allow_add = True

			if allow_add:
				id = childs[7].connect('activate', self.on_add_to_roster_activate,
					text)
				self.handlers[id] = childs[7]
				childs[7].show() # show add to roster menuitem
			else:
				childs[7].hide() # hide add to roster menuitem

			childs[0].hide() # copy link location
			childs[1].hide() # open link in browser

		menu.popup(None, None, None, event.button, event.time)
Exemple #5
0
 def show_icon(self):
     window_mode = gajim.interface.msg_win_mgr.mode
     icon = None
     if window_mode == MessageWindowMgr.ONE_MSG_WINDOW_NEVER:
         ctrl = self.get_active_control()
         if not ctrl:
             return
         icon = ctrl.get_tab_image(count_unread=False)
     elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS:
         pass # keep default icon
     elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
         pass # keep default icon
     elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERACCT:
         pass # keep default icon
     elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERTYPE:
         if self.type_ == 'gc':
             icon = gtkgui_helpers.load_icon('muc_active')
         else:
             # chat, pm
             icon = gtkgui_helpers.load_icon('online')
     if icon:
         self.window.set_icon(icon.get_pixbuf())
Exemple #6
0
    def _fill_completion_dict(self):
        """
        Fill completion_dict for key auto completion. Then load history for
        current jid (by calling another function)

        Key will be either jid or full_completion_name (contact name or long
        description like "pm-contact from groupchat....").

        {key : (jid, account, nick_name, full_completion_name}
        This is a generator and does pseudo-threading via idle_add().
        """
        liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry)

        # Add all jids in logs.db:
        db_jids = gajim.logger.get_jids_in_db()
        completion_dict = dict.fromkeys(db_jids)

        self.accounts_seen_online = list(gajim.contacts.get_accounts())

        # Enhance contacts of online accounts with contact. Needed for mapping below
        for account in self.accounts_seen_online:
            completion_dict.update(
                helpers.get_contact_dict_for_account(account))

        muc_active_img = gtkgui_helpers.load_icon('muc_active')
        contact_img = gajim.interface.jabber_state_images['16']['online']
        muc_active_pix = muc_active_img.get_pixbuf()
        contact_pix = contact_img.get_pixbuf()

        keys = list(completion_dict.keys())
        # Move the actual jid at first so we load history faster
        actual_jid = self.jid_entry.get_text()
        if actual_jid in keys:
            keys.remove(actual_jid)
            keys.insert(0, actual_jid)
        if '' in keys:
            keys.remove('')
        if None in keys:
            keys.remove(None)
        # Map jid to info tuple
        # Warning : This for is time critical with big DB
        for key in keys:
            completed = key
            completed2 = None
            contact = completion_dict[completed]
            if contact:
                info_name = contact.get_shown_name()
                info_completion = info_name
                info_jid = contact.jid
            else:
                # Corrensponding account is offline, we know nothing
                info_name = completed.split('@')[0]
                info_completion = completed
                info_jid = completed

            info_acc = self._get_account_for_jid(info_jid)

            if gajim.logger.jid_is_room_jid(completed) or\
            gajim.logger.jid_is_from_pm(completed):
                pix = muc_active_pix
                if gajim.logger.jid_is_from_pm(completed):
                    # It's PM. Make it easier to find
                    room, nick = gajim.get_room_and_nick_from_fjid(completed)
                    info_completion = '%s from %s' % (nick, room)
                    completed = info_completion
                    info_completion2 = '%s/%s' % (room, nick)
                    completed2 = info_completion2
                    info_name = nick
            else:
                pix = contact_pix

            if len(completed) > 70:
                completed = completed[:70] + '[\u2026]'
            liststore.append((pix, completed))
            self.completion_dict[key] = (info_jid, info_acc, info_name,
                                         info_completion)
            self.completion_dict[completed] = (info_jid, info_acc, info_name,
                                               info_completion)
            if completed2:
                if len(completed2) > 70:
                    completed2 = completed2[:70] + '[\u2026]'
                liststore.append((pix, completed2))
                self.completion_dict[completed2] = (info_jid, info_acc,
                                                    info_name,
                                                    info_completion2)
            if key == actual_jid:
                self._load_history(info_jid, info_acc)
            yield True
        keys.sort()
        yield False
Exemple #7
0
def build_invite_submenu(invite_menuitem, list_, ignore_rooms=[],
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
    """
    roster = gajim.interface.roster
    # used if we invite only one contact with several resources
    contact_list = []
    if len(list_) == 1:
        contact, account = list_[0]
        contact_list = gajim.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 = gajim.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.ImageMenuItem(_('_New Group Chat'))
    icon = gtk.image_new_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU)
    invite_to_new_room_menuitem.set_image(icon)
    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 == gajim.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 gajim.connections[account].muc_jid:
            muc_jid[t] = gajim.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 += \
            gajim.interface.minimized_controls[account].values()
    for gc_control in gajim.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 gajim.gc_connected[acct] and \
        gajim.gc_connected[acct][room_jid] and \
        contacts_transport in ['jabber', None]:
            rooms.append((room_jid, acct))
    if len(rooms):
        item = gtk.SeparatorMenuItem() # separator
        invite_to_submenu.append(item)
        for (room_jid, account) in rooms:
            menuitem = gtk.ImageMenuItem(room_jid.split('@')[0])
            muc_active_icon = gtkgui_helpers.load_icon('muc_active')
            menuitem.set_image(muc_active_icon)
            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 == gajim.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 gajim.connections[account].bookmarks:
            r_jid = room['jid']
            if r_jid in r_jids:
                continue
            if r_jid not in gajim.gc_connected[account] or not \
            gajim.gc_connected[account][r_jid]:
                rooms2.append((r_jid, account))
                r_jids.append(r_jid)

    if not rooms2:
        return
    item = gtk.SeparatorMenuItem() # separator
    invite_to_submenu.append(item)
    for (room_jid, account) in rooms2:
        menuitem = gtk.ImageMenuItem(room_jid.split('@')[0])
        muc_inactive_icon = gtkgui_helpers.load_icon('muc_inactive')
        menuitem.set_image(muc_inactive_icon)
        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 == gajim.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)
Exemple #8
0
def get_transport_menu(contact, account):
    roster = gajim.interface.roster
    jid = contact.jid

    menu = gtk.Menu()

    # Send single message
    item = gtk.ImageMenuItem(_('Send Single _Message...'))
    icon = gtk.image_new_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU)
    item.set_image(icon)
    item.connect('activate', roster.on_send_single_message_menuitem_activate,
        account, contact)
    menu.append(item)
    if gajim.account_is_disconnected(account):
        item.set_sensitive(False)

    blocked = False
    if helpers.jid_is_blocked(account, jid):
        blocked = True

    # Send Custom Status
    send_custom_status_menuitem = gtk.ImageMenuItem(_('Send Cus_tom Status'))
    # add a special img for this menuitem
    if blocked:
        send_custom_status_menuitem.set_image(gtkgui_helpers.load_icon(
            'offline'))
        send_custom_status_menuitem.set_sensitive(False)
    else:
        if account in gajim.interface.status_sent_to_users and \
        jid in gajim.interface.status_sent_to_users[account]:
            send_custom_status_menuitem.set_image(gtkgui_helpers.load_icon(
                gajim.interface.status_sent_to_users[account][jid]))
        else:
            icon = gtk.image_new_from_stock(gtk.STOCK_NETWORK,
                gtk.ICON_SIZE_MENU)
            send_custom_status_menuitem.set_image(icon)
        status_menuitems = gtk.Menu()
        send_custom_status_menuitem.set_submenu(status_menuitems)
        iconset = gajim.config.get('iconset')
        path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
        for s in ('online', 'chat', 'away', 'xa', 'dnd', 'offline'):
            # icon MUST be different instance for every item
            state_images = gtkgui_helpers.load_iconset(path)
            status_menuitem = gtk.ImageMenuItem(helpers.get_uf_show(s))
            status_menuitem.connect('activate', roster.on_send_custom_status,
                [(contact, account)], s)
            icon = state_images[s]
            status_menuitem.set_image(icon)
            status_menuitems.append(status_menuitem)
    menu.append(send_custom_status_menuitem)
    if gajim.account_is_disconnected(account):
        send_custom_status_menuitem.set_sensitive(False)

    item = gtk.SeparatorMenuItem() # separator
    menu.append(item)

    # Execute Command
    item = gtk.ImageMenuItem(_('E_xecute Command...'))
    icon = gtk.image_new_from_stock(gtk.STOCK_EXECUTE, gtk.ICON_SIZE_MENU)
    item.set_image(icon)
    menu.append(item)
    item.connect('activate', roster.on_execute_command, contact, account,
        contact.resource)
    if gajim.account_is_disconnected(account):
        item.set_sensitive(False)

    # Manage Transport submenu
    item = gtk.ImageMenuItem(_('_Manage Transport'))
    icon = gtk.image_new_from_stock(gtk.STOCK_PROPERTIES, gtk.ICON_SIZE_MENU)
    item.set_image(icon)
    manage_transport_submenu = gtk.Menu()
    item.set_submenu(manage_transport_submenu)
    menu.append(item)

    # Modify Transport
    item = gtk.ImageMenuItem(_('_Modify Transport'))
    icon = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU)
    item.set_image(icon)
    manage_transport_submenu.append(item)
    item.connect('activate', roster.on_edit_agent, contact, account)
    if gajim.account_is_disconnected(account):
        item.set_sensitive(False)

    # Rename
    item = gtk.ImageMenuItem(_('_Rename...'))
    # add a special img for rename menuitem
    gtkgui_helpers.add_image_to_menuitem(item, 'gajim-kbd_input')
    manage_transport_submenu.append(item)
    item.connect('activate', roster.on_rename, 'agent', jid, account)
    if gajim.account_is_disconnected(account):
        item.set_sensitive(False)

    item = gtk.SeparatorMenuItem() # separator
    manage_transport_submenu.append(item)

    # Block
    if blocked:
        item = gtk.ImageMenuItem(_('_Unblock'))
        item.connect('activate', roster.on_unblock, [(contact, account)])
    else:
        item = gtk.ImageMenuItem(_('_Block'))
        item.connect('activate', roster.on_block, [(contact, account)])

    icon = gtk.image_new_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_MENU)
    item.set_image(icon)
    manage_transport_submenu.append(item)
    if gajim.account_is_disconnected(account):
        item.set_sensitive(False)

    # Remove
    item = gtk.ImageMenuItem(_('Remo_ve'))
    icon = gtk.image_new_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU)
    item.set_image(icon)
    manage_transport_submenu.append(item)
    item.connect('activate', roster.on_remove_agent, [(contact, account)])
    if gajim.account_is_disconnected(account):
        item.set_sensitive(False)

    item = gtk.SeparatorMenuItem() # separator
    menu.append(item)

    # Information
    information_menuitem = gtk.ImageMenuItem(_('_Information'))
    icon = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_MENU)
    information_menuitem.set_image(icon)
    menu.append(information_menuitem)
    information_menuitem.connect('activate', roster.on_info, contact, account)
    if gajim.account_is_disconnected(account):
        information_menuitem.set_sensitive(False)

    menu.connect('selection-done', gtkgui_helpers.destroy_widget)
    menu.show_all()
    return menu
Exemple #9
0
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 == gajim.get_jid_from_account(account)
    roster = gajim.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')
    set_custom_avatar_menuitem = xml.get_object('set_custom_avatar_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')
    encryption_separator = xml.get_object('encryption_separator')
    toggle_gpg_menuitem = xml.get_object('toggle_gpg_menuitem')
    toggle_e2e_menuitem = xml.get_object('toggle_e2e_menuitem')
    last_separator = xml.get_object('last_separator')

    items_to_hide = []

    # add a special img for send file menuitem
    pixbuf = gtkgui_helpers.get_icon_pixmap('document-send', quiet=True)
    img = gtk.image_new_from_pixbuf(pixbuf)
    send_file_menuitem.set_image(img)

    if not our_jid:
        # add a special img for rename menuitem
        gtkgui_helpers.add_image_to_menuitem(rename_menuitem, 'gajim-kbd_input')

    muc_icon = gtkgui_helpers.load_icon('muc_active')
    if muc_icon:
        convert_to_gc_menuitem.set_image(muc_icon)

    contacts = gajim.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, gajim.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',
                gajim.interface.on_open_chat_window, contact, account)
        if contact.supports(NS_FILE) or contact.supports(NS_JINGLE_FILE_TRANSFER):
            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 gtkgui_helpers.gtk_icon_theme.has_icon('document-open-recent'):
        img = gtk.Image()
        img.set_from_icon_name('document-open-recent', gtk.ICON_SIZE_MENU)
        history_menuitem.set_image(img)

    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 gajim.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 gajim.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_encryption or not control:
        items_to_hide += [encryption_separator, toggle_gpg_menuitem,
                toggle_e2e_menuitem]
    else:
        e2e_is_active = control.session is not None and \
                control.session.enable_encryption

        # check if we support and use gpg
        if not gajim.config.get_per('accounts', account, 'keyid') or \
        not gajim.connections[account].USE_GPG or gajim.jid_is_transport(
        contact.jid):
            toggle_gpg_menuitem.set_sensitive(False)
        else:
            toggle_gpg_menuitem.set_sensitive(control.gpg_is_active or \
                    not e2e_is_active)
            toggle_gpg_menuitem.set_active(control.gpg_is_active)
            toggle_gpg_menuitem.connect('activate',
                    control._on_toggle_gpg_menuitem_activate)

        # disable esessions if we or the other client don't support them
        if not gajim.HAVE_PYCRYPTO or not contact.supports(NS_ESESSION) or \
        not gajim.config.get_per('accounts', account, 'enable_esessions'):
            toggle_e2e_menuitem.set_sensitive(False)
        else:
            toggle_e2e_menuitem.set_active(e2e_is_active)
            toggle_e2e_menuitem.set_sensitive(e2e_is_active or \
                    not control.gpg_is_active)
            toggle_e2e_menuitem.connect('activate',
                    control._on_toggle_e2e_menuitem_activate)

    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 gajim.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, set_custom_avatar_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 = gajim.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_image(gtkgui_helpers.load_icon('offline'))
        send_custom_status_menuitem.set_sensitive(False)
    elif account in gajim.interface.status_sent_to_users and \
    jid in gajim.interface.status_sent_to_users[account]:
        send_custom_status_menuitem.set_image(gtkgui_helpers.load_icon(
                gajim.interface.status_sent_to_users[account][jid]))
    else:
        icon = gtk.image_new_from_stock(gtk.STOCK_NETWORK, gtk.ICON_SIZE_MENU)
        send_custom_status_menuitem.set_image(icon)

    muc_icon = gtkgui_helpers.load_icon('muc_active')
    if muc_icon:
        invite_menuitem.set_image(muc_icon)

    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_ = gajim.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 gajim.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)
    iconset = gajim.config.get('iconset')
    path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
    for s in ('online', 'chat', 'away', 'xa', 'dnd', 'offline'):
        # icon MUST be different instance for every item
        state_images = gtkgui_helpers.load_iconset(path)
        status_menuitem = gtk.ImageMenuItem(helpers.get_uf_show(s))
        status_menuitem.connect('activate', roster.on_send_custom_status,
                [(contact, account)], s)
        icon = state_images[s]
        status_menuitem.set_image(icon)
        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 = gajim.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 gajim.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)

    set_custom_avatar_menuitem.connect('activate',
            roster.on_set_custom_avatar_activate, contact, account)

    # Hide items when it's self contact row
    if our_jid:
        manage_contact_menuitem.set_sensitive(False)

    # Unsensitive items when account is offline
    if gajim.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 gajim.connections[account] and (gajim.connections[account].\
    privacy_rules_supported or gajim.connections[account].blocking_supported):
        if helpers.jid_is_blocked(account, jid):
            block_menuitem.set_no_show_all(True)
            block_menuitem.hide()
            if gajim.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 gajim.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
Exemple #10
0
    def _fill_completion_dict(self):
        """
        Fill completion_dict for key auto completion. Then load history for
        current jid (by calling another function)

        Key will be either jid or full_completion_name (contact name or long
        description like "pm-contact from groupchat....").

        {key : (jid, account, nick_name, full_completion_name}
        This is a generator and does pseudo-threading via idle_add().
        """
        liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry)

        # Add all jids in logs.db:
        db_jids = gajim.logger.get_jids_in_db()
        completion_dict = dict.fromkeys(db_jids)

        self.accounts_seen_online = list(gajim.contacts.get_accounts())

        # Enhance contacts of online accounts with contact. Needed for mapping below
        for account in self.accounts_seen_online:
            completion_dict.update(helpers.get_contact_dict_for_account(account))

        muc_active_img = gtkgui_helpers.load_icon('muc_active')
        contact_img = gajim.interface.jabber_state_images['16']['online']
        muc_active_pix = muc_active_img.get_pixbuf()
        contact_pix = contact_img.get_pixbuf()

        keys = list(completion_dict.keys())
        # Move the actual jid at first so we load history faster
        actual_jid = self.jid_entry.get_text()
        if actual_jid in keys:
            keys.remove(actual_jid)
            keys.insert(0, actual_jid)
        if '' in keys:
            keys.remove('')
        if None in keys:
            keys.remove(None)
        # Map jid to info tuple
        # Warning : This for is time critical with big DB
        for key in keys:
            completed = key
            completed2 = None
            contact = completion_dict[completed]
            if contact:
                info_name = contact.get_shown_name()
                info_completion = info_name
                info_jid = contact.jid
            else:
                # Corrensponding account is offline, we know nothing
                info_name = completed.split('@')[0]
                info_completion = completed
                info_jid = completed

            info_acc = self._get_account_for_jid(info_jid)

            if gajim.logger.jid_is_room_jid(completed) or\
            gajim.logger.jid_is_from_pm(completed):
                pix = muc_active_pix
                if gajim.logger.jid_is_from_pm(completed):
                    # It's PM. Make it easier to find
                    room, nick = gajim.get_room_and_nick_from_fjid(completed)
                    info_completion = '%s from %s' % (nick, room)
                    completed = info_completion
                    info_completion2 = '%s/%s' % (room, nick)
                    completed2 = info_completion2
                    info_name = nick
            else:
                pix = contact_pix

            if len(completed) > 70:
                completed = completed[:70] + '[\u2026]'
            liststore.append((pix, completed))
            self.completion_dict[key] = (info_jid, info_acc, info_name,
                info_completion)
            self.completion_dict[completed] = (info_jid, info_acc,
                info_name, info_completion)
            if completed2:
                if len(completed2) > 70:
                    completed2 = completed2[:70] + '[\u2026]'
                liststore.append((pix, completed2))
                self.completion_dict[completed2] = (info_jid, info_acc,
                    info_name, info_completion2)
            if key == actual_jid:
                self._load_history(info_jid, info_acc)
            yield True
        keys.sort()
        yield False