Example #1
0
 def fill_status_label(self):
     if self.xml.get_object('information_notebook').get_n_pages() < 5:
         return
     contact_list = app.contacts.get_contacts(self.account,
                                              self.contact.jid)
     connected_contact_list = []
     for c in contact_list:
         if c.show not in ('offline', 'error'):
             connected_contact_list.append(c)
     if not connected_contact_list:
         # no connected contact, get the offline one
         connected_contact_list = contact_list
     # stats holds show and status message
     stats = ''
     if connected_contact_list:
         # Start with self.contact, as with resources
         stats = helpers.get_uf_show(self.contact.show)
         if self.contact.status:
             stats += ': ' + self.contact.status
         for c in connected_contact_list:
             if c.resource != self.contact.resource:
                 stats += '\n'
                 stats += helpers.get_uf_show(c.show)
                 if c.status:
                     stats += ': ' + c.status
     else:  # Maybe gc_vcard ?
         stats = helpers.get_uf_show(self.contact.show)
         if self.contact.status:
             stats += ': ' + self.contact.status
     status_label = self.xml.get_object('status_label')
     status_label.set_text(stats)
     status_label.set_tooltip_text(stats)
Example #2
0
    def _set_idle_time(self, contact):
        if contact.idle_time:
            idle_color = app.config.get('tooltip_idle_color')
            idle_time = contact.idle_time
            idle_time = time.localtime(contact.idle_time)
            idle_time = datetime(*(idle_time[:6]))
            current = datetime.now()
            if idle_time.date() == current.date():
                formatted = idle_time.strftime("%X")
            else:
                formatted = idle_time.strftime("%c")
            idle_markup = "<span foreground='{}'>{}</span>".format(idle_color,
                formatted)
            self.idle_since.set_markup(idle_markup)
            self.idle_since.show()
            self.idle_since_label.show()

        if contact.show and self.num_resources < 2:
            show = helpers.get_uf_show(contact.show)
            # Contact is Groupchat
            if (self.account and
                    self.prim_contact.jid in app.gc_connected[self.account]):
                if app.gc_connected[self.account][self.prim_contact.jid]:
                    show = _('Connected')
                else:
                    show = _('Disconnected')

            self.user_show.set_markup(colorize_status(show))
            self.user_show.show()
Example #3
0
    def _set_idle_time(self, contact):
        if contact.idle_time:
            idle_time = contact.idle_time
            idle_time = time.localtime(contact.idle_time)
            idle_time = datetime(*(idle_time[:6]))
            current = datetime.now()
            if idle_time.date() == current.date():
                formatted = idle_time.strftime('%X')
            else:
                formatted = idle_time.strftime('%c')
            self._ui.idle_since.set_text(formatted)
            self._ui.idle_since.show()
            self._ui.idle_since_label.show()

        if contact.show and self.num_resources < 2:
            show = helpers.get_uf_show(contact.show)
            # Contact is Groupchat
            if (self.account and self.prim_contact.jid
                    in app.gc_connected[self.account]):
                if app.gc_connected[self.account][self.prim_contact.jid]:
                    show = _('Connected')
                else:
                    show = _('Disconnected')

            colorize_status(self._ui.user_show, contact.show)
            self._ui.user_show.set_text(show)
            self._ui.user_show.show()
Example #4
0
    def _on_status_show_changed(self, event):
        if event.properties.jid != self.gc_contact.get_full_jid():
            return

        nick = event.properties.muc_nickname
        status = event.properties.status
        status = '' if status is None else ' - %s' % status
        show = helpers.get_uf_show(event.properties.show.value)

        if not app.settings.get_group_chat_setting(
                self.account, self.gc_contact.room_jid, 'print_status'):
            self.parent_win.redraw_tab(self)
            self.update_ui()
            return

        if event.properties.is_muc_self_presence:
            message = _('You are now {show}{status}').format(show=show,
                                                             status=status)

        else:
            message = _('{nick} is now {show}{status}').format(nick=nick,
                                                               show=show,
                                                               status=status)
        self.add_status_message(message)
        self.parent_win.redraw_tab(self)
        self.update_ui()
Example #5
0
    def _on_status_show_changed(self, event):
        if event.account != self.account:
            return
        if event.properties.jid != self.gc_contact.get_full_jid():
            return

        nick = event.properties.muc_nickname
        status = event.properties.status
        status = '' if status is None else ' - %s' % status
        show = helpers.get_uf_show(event.properties.show.value)

        status_default = app.config.get('print_status_muc_default')

        if event.properties.is_muc_self_presence:
            message = _('You are now {show}{status}').format(show=show,
                                                             status=status)
            self.add_status_message(message)

        elif app.config.get_per('rooms', self.room_name,
                                'print_status', status_default):
            message = _('{nick} is now {show}{status}').format(nick=nick,
                                                               show=show,
                                                               status=status)
            self.add_status_message(message)

        self.parent_win.redraw_tab(self)
        self.update_ui()
Example #6
0
 def set_treeview_string(self):
     (model,
      iter_) = self._ui.conditions_treeview.get_selection().get_selected()
     if not iter_:
         return
     ind = self._ui.event_combobox.get_active()
     event = ''
     if ind > -1:
         event = self._ui.event_combobox.get_model()[ind][0]
     ind = self._ui.recipient_type_combobox.get_active()
     recipient_type = ''
     if ind > -1:
         recipient_type = self._ui.recipient_type_combobox.get_model(
         )[ind][0]
     recipient = ''
     if recipient_type != 'everybody':
         recipient = self._ui.recipient_list_entry.get_text()
     if self._ui.all_status_rb.get_active():
         status = ''
     else:
         status = _('and I am: ')
         for st in ('online', 'away', 'xa', 'dnd', 'invisible'):
             if self._ui.__dict__[st + '_cb'].get_active():
                 status += helpers.get_uf_show(st) + ' '
     model[iter_][1] = _('When event: %(event)s for category: '
                         '%(recipient_type)s %(recipient)s %(status)s') % {
                             'event': event,
                             'recipient_type': recipient_type,
                             'recipient': recipient,
                             'status': status
                         }
Example #7
0
    def _populate_grid(self, contact):
        """
        Populate the Tooltip Grid with data of from the contact
        """
        self._hide_grid_childs()

        self.nick.set_text(contact.get_shown_name())
        self.nick.show()

        # Status Message
        if contact.status:
            status = contact.status.strip()
            if status != '':
                self.status.set_text(status)
                self.status.show()

        # Status
        show = helpers.get_uf_show(contact.show)
        self.user_show.set_markup(colorize_status(show))
        self.user_show.show()

        # JID
        if contact.jid.strip():
            self.jid.set_text(contact.jid)
            self.jid.show()
            self.jid_label.show()
        # Resource
        if hasattr(contact, 'resource') and contact.resource.strip():
            self.resource.set_text(contact.resource)
            self.resource.show()
            self.resource_label.show()

        # Affiliation
        if contact.affiliation != 'none':
            uf_affiliation = helpers.get_uf_affiliation(contact.affiliation)
            uf_affiliation = \
                _('%(owner_or_admin_or_member)s of this group chat') \
                % {'owner_or_admin_or_member': uf_affiliation}
            uf_affiliation = self.colorize_affiliation(uf_affiliation)
            self.affiliation.set_markup(uf_affiliation)
            self.affiliation.show()

        # Avatar
        if contact.avatar_sha is not None:
            app.log('avatar').debug('Load GCTooltip: %s %s', contact.name,
                                    contact.avatar_sha)
            scale = self.tooltip_grid.get_scale_factor()
            surface = app.interface.get_avatar(contact.avatar_sha,
                                               AvatarSize.TOOLTIP, scale)
            if surface is not None:
                self.avatar.set_from_surface(surface)
                self.avatar.show()
                self.fillelement.show()

        app.plugin_manager.gui_extension_point('gc_tooltip_populate', self,
                                               contact, self.tooltip_grid)
Example #8
0
    def _create_popover(self):
        popover_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        popover_box.get_style_context().add_class('margin-3')
        popover_items = [
            'online',
            'away',
            'xa',
            'dnd',
            'separator',
            'change_status_message',
            'separator',
            'offline',
        ]

        for item in popover_items:
            if item == 'separator':
                popover_box.add(Gtk.Separator())
                continue

            show_icon = Gtk.Image()
            show_label = Gtk.Label()
            show_label.set_halign(Gtk.Align.START)

            if item == 'change_status_message':
                show_icon.set_from_icon_name('document-edit-symbolic',
                                             Gtk.IconSize.MENU)
                show_label.set_text_with_mnemonic(_('_Change Status Message'))
            else:
                show_icon.set_from_icon_name(get_icon_name(item),
                                             Gtk.IconSize.MENU)
                show_label.set_text_with_mnemonic(
                    get_uf_show(item, use_mnemonic=True))

            show_box = Gtk.Box(spacing=6)
            show_box.add(show_icon)
            show_box.add(show_label)

            button = Gtk.Button()
            button.set_name(item)
            button.set_relief(Gtk.ReliefStyle.NONE)
            button.add(show_box)
            button.connect('clicked', self._on_change_status)

            if item == 'change_status_message':
                self._change_status_message = button

            popover_box.add(button)

        popover_box.show_all()
        self._status_popover = Gtk.Popover()
        self._status_popover.add(popover_box)
        self.set_popover(self._status_popover)
Example #9
0
 def fill_status_label(self):
     if self.xml.get_object('information_notebook').get_n_pages() < 2:
         return
     contact_list = app.contacts.get_contacts(self.account, self.contact.jid)
     # stats holds show and status message
     stats = ''
     one = True # Are we adding the first line ?
     if contact_list:
         for c in contact_list:
             if not one:
                 stats += '\n'
             stats += helpers.get_uf_show(c.show)
             if c.status:
                 stats += ': ' + c.status
             one = False
     else: # Maybe gc_vcard ?
         stats = helpers.get_uf_show(self.contact.show)
         if self.contact.status:
             stats += ': ' + self.contact.status
     status_label = self.xml.get_object('status_label')
     status_label.set_text(stats)
     status_label.set_tooltip_text(stats)
Example #10
0
    def populate(self, contact):
        """
        Populate the Tooltip Grid with data of from the contact
        """
        self.clear_tooltip()

        self.nick.set_text(contact.get_shown_name())
        self.nick.show()

        # Status Message
        if contact.status:
            status = contact.status.strip()
            if status != '':
                self.status.set_text(status)
                self.status.show()

        # Status
        show = helpers.get_uf_show(contact.show)
        self.user_show.set_markup(colorize_status(show))
        self.user_show.show()

        # JID
        if contact.jid.strip():
            self.jid.set_text(contact.jid)
            self.jid.show()
            self.jid_label.show()
        # Resource
        if hasattr(contact, 'resource') and contact.resource.strip():
            self.resource.set_text(contact.resource)
            self.resource.show()
            self.resource_label.show()

        # Affiliation
        if contact.affiliation != 'none':
            uf_affiliation = helpers.get_uf_affiliation(contact.affiliation)
            uf_affiliation = \
                _('%(owner_or_admin_or_member)s of this group chat') \
                % {'owner_or_admin_or_member': uf_affiliation}
            uf_affiliation = self.colorize_affiliation(uf_affiliation)
            self.affiliation.set_markup(uf_affiliation)
            self.affiliation.show()

        # Avatar
        if contact.avatar_sha is not None:
            app.log('avatar').debug(
                'Load GCTooltip: %s %s', contact.name, contact.avatar_sha)
            pixbuf = app.interface.get_avatar(contact.avatar_sha, AvatarSize.TOOLTIP)
            if pixbuf is not None:
                self.avatar.set_from_pixbuf(pixbuf)
                self.avatar.show()
                self.fillelement.show()
Example #11
0
 def fill_default_msg_treeview(self):
     model = self._ui.default_msg_treeview.get_model()
     model.clear()
     status = []
     for status_ in app.config.get_per('defaultstatusmsg'):
         status.append(status_)
     status.sort()
     for status_ in status:
         msg = app.config.get_per('defaultstatusmsg', status_, 'message')
         msg = helpers.from_one_line(msg)
         enabled = app.config.get_per('defaultstatusmsg', status_,
                                      'enabled')
         iter_ = model.append()
         uf_show = helpers.get_uf_show(status_)
         model.set(iter_, 0, status_, 1, uf_show, 2, msg, 3, enabled)
Example #12
0
    def __init__(self, compact=False):
        Gtk.MenuButton.__init__(self)
        self.set_direction(Gtk.ArrowType.UP)
        self._compact = compact
        self._create_popover()
        self.set_no_show_all(True)

        self._current_show_icon = Gtk.Image()
        self._current_show_icon.set_from_icon_name(get_icon_name('offline'),
                                                   Gtk.IconSize.MENU)

        box = Gtk.Box(spacing=6)
        box.add(self._current_show_icon)
        if not self._compact:
            self._current_show_label = Gtk.Label(label=get_uf_show('offline'))
            self._current_show_label.set_ellipsize(Pango.EllipsizeMode.END)
            self._current_show_label.set_halign(Gtk.Align.START)
            self._current_show_label.set_xalign(0)
            box.add(self._current_show_label)
            box.show_all()
        self.add(box)
Example #13
0
    def update(self):
        if not app.connections:
            self.hide()
            return

        self.show()
        show = get_global_show()
        uf_show = get_uf_show(show)
        self._current_show_icon.set_from_icon_name(get_icon_name(show),
                                                   Gtk.IconSize.MENU)
        if statuses_unified():
            self._current_show_icon.set_tooltip_text(_('Status: %s') % uf_show)
            if not self._compact:
                self._current_show_label.set_text(uf_show)
        else:
            show_label = _('%s (desynced)') % uf_show
            self._current_show_icon.set_tooltip_text(
                _('Status: %s') % show_label)
            if not self._compact:
                self._current_show_label.set_text(show_label)

        self._change_status_message.set_sensitive(show != 'offline')
Example #14
0
    def _add_message(self, msg):
        if not msg.message and msg.kind not in (KindConstant.STATUS,
                                                KindConstant.GCSTATUS):
            return

        tim = msg.time
        kind = msg.kind
        show = msg.show
        message = msg.message
        subject = msg.subject
        log_line_id = msg.log_line_id
        contact_name = msg.contact_name
        additional_data = msg.additional_data

        buf = self.history_buffer
        end_iter = buf.get_end_iter()

        # Make the beginning of every message searchable by its log_line_id
        buf.create_mark(str(log_line_id), end_iter, left_gravity=True)

        if app.config.get('print_time') == 'always':
            timestamp_str = app.config.get('time_stamp')
            timestamp_str = helpers.from_one_line(timestamp_str)
            tim = time.strftime(timestamp_str, time.localtime(float(tim)))
            buf.insert(end_iter, tim)
        elif app.config.get('print_time') == 'sometimes':
            every_foo_seconds = 60 * app.config.get(
                'print_ichat_every_foo_minutes')
            seconds_passed = tim - self.last_time_printout
            if seconds_passed > every_foo_seconds:
                self.last_time_printout = tim
                tim = time.strftime('%X ', time.localtime(float(tim)))
                buf.insert_with_tags_by_name(
                    end_iter, tim + '\n', 'time_sometimes')

        # print the encryption icon
        if kind in (KindConstant.CHAT_MSG_SENT,
                    KindConstant.CHAT_MSG_RECV):
            self.history_textview.print_encryption_status(
                end_iter, additional_data)

        tag_name = ''
        tag_msg = ''

        show = self._get_string_show_from_constant_int(show)

        if kind == KindConstant.GC_MSG:
            tag_name = 'incoming'
        elif kind in (KindConstant.SINGLE_MSG_RECV,
                      KindConstant.CHAT_MSG_RECV):
            contact_name = self.completion_dict[self.jid][InfoColumn.NAME]
            tag_name = 'incoming'
            tag_msg = 'incomingtxt'
        elif kind in (KindConstant.SINGLE_MSG_SENT,
                      KindConstant.CHAT_MSG_SENT):
            if self.account:
                contact_name = app.nicks[self.account]
            else:
                # we don't have roster, we don't know our own nick, use first
                # account one (urk!)
                account = list(app.contacts.get_accounts())[0]
                contact_name = app.nicks[account]
            tag_name = 'outgoing'
            tag_msg = 'outgoingtxt'
        elif kind == KindConstant.GCSTATUS:
            # message here (if not None) is status message
            if message:
                message = _('%(nick)s is now %(status)s: %(status_msg)s') % {
                    'nick': contact_name,
                    'status': helpers.get_uf_show(show),
                    'status_msg': message}
            else:
                message = _('%(nick)s is now %(status)s') % {
                    'nick': contact_name,
                    'status': helpers.get_uf_show(show)}
            tag_msg = 'status'
        else:  # 'status'
            # message here (if not None) is status message
            if show is None:  # it means error
                if message:
                    message = _('Error: %s') % message
                else:
                    message = _('Error')
            elif message:
                message = _('Status is now: %(status)s: %(status_msg)s') % {
                    'status': helpers.get_uf_show(show),
                    'status_msg': message}
            else:
                message = _('Status is now: %(status)s') % {
                    'status': helpers.get_uf_show(show)}
            tag_msg = 'status'

        if message.startswith('/me ') or message.startswith('/me\n'):
            tag_msg = tag_name
        else:
            # do not do this if gcstats, avoid dupping contact_name
            # eg. nkour: nkour is now Offline
            if contact_name and kind != KindConstant.GCSTATUS:
                # add stuff before and after contact name
                before_str = app.config.get('before_nickname')
                before_str = helpers.from_one_line(before_str)
                after_str = app.config.get('after_nickname')
                after_str = helpers.from_one_line(after_str)
                format_ = before_str + contact_name + after_str + ' '
                if tag_name:
                    buf.insert_with_tags_by_name(end_iter, format_, tag_name)
                else:
                    buf.insert(end_iter, format_)
        if subject:
            message = _('Subject: %s\n') % subject + message
        xhtml = None
        if message.startswith('<body '):
            xhtml = message

        if tag_msg:
            self.history_textview.print_real_text(
                message, [tag_msg],
                name=contact_name,
                xhtml=xhtml,
                additional_data=additional_data)
        else:
            self.history_textview.print_real_text(
                message,
                name=contact_name,
                xhtml=xhtml,
                additional_data=additional_data)
        self.history_textview.print_real_text('\n', text_tags=['eol'])
Example #15
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 == 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
Example #16
0
    def make_menu(self, event_button, event_time):
        """
        Create chat with and new message (sub) menus/menuitems
        """
        for m in self.popup_menus:
            m.destroy()

        chat_with_menuitem = self.xml.get_object('chat_with_menuitem')
        single_message_menuitem = self.xml.get_object(
            'single_message_menuitem')
        status_menuitem = self.xml.get_object('status_menu')
        join_gc_menuitem = self.xml.get_object('join_gc_menuitem')
        sounds_mute_menuitem = self.xml.get_object('sounds_mute_menuitem')
        show_roster_menuitem = self.xml.get_object('show_roster_menuitem')

        if self.single_message_handler_id:
            single_message_menuitem.handler_disconnect(
                self.single_message_handler_id)
            self.single_message_handler_id = None
        if self.new_chat_handler_id:
            chat_with_menuitem.disconnect(self.new_chat_handler_id)
            self.new_chat_handler_id = None

        sub_menu = Gtk.Menu()
        self.popup_menus.append(sub_menu)
        status_menuitem.set_submenu(sub_menu)

        gc_sub_menu = Gtk.Menu()  # gc is always a submenu
        join_gc_menuitem.set_submenu(gc_sub_menu)

        # We need our own set of status icons, let's make 'em!
        iconset = app.config.get('iconset')
        path = os.path.join(helpers.get_iconset_path(iconset), '16x16')

        for show in ('online', 'chat', 'away', 'xa', 'dnd', 'invisible'):
            uf_show = helpers.get_uf_show(show, use_mnemonic=True)
            item = Gtk.MenuItem.new_with_mnemonic(uf_show)
            sub_menu.append(item)
            item.connect('activate', self.on_show_menuitem_activate, show)

        item = Gtk.SeparatorMenuItem.new()
        sub_menu.append(item)

        item = Gtk.MenuItem.new_with_mnemonic(_('_Change Status Message…'))
        sub_menu.append(item)
        item.connect('activate', self.on_change_status_message_activate)

        connected_accounts = app.get_number_of_connected_accounts()
        if connected_accounts < 1:
            item.set_sensitive(False)

        connected_accounts_with_private_storage = 0

        item = Gtk.SeparatorMenuItem.new()
        sub_menu.append(item)

        uf_show = helpers.get_uf_show('offline', use_mnemonic=True)
        item = Gtk.MenuItem.new_with_mnemonic(uf_show)
        sub_menu.append(item)
        item.connect('activate', self.on_show_menuitem_activate, 'offline')

        iskey = connected_accounts > 0 and not (connected_accounts == 1 and
                                                app.zeroconf_is_connected())
        chat_with_menuitem.set_sensitive(iskey)
        single_message_menuitem.set_sensitive(iskey)
        join_gc_menuitem.set_sensitive(iskey)

        accounts_list = sorted(app.contacts.get_accounts())
        # items that get shown whether an account is zeroconf or not
        if connected_accounts > 1:  # 2 or more connections? make submenus
            account_menu_for_chat_with = Gtk.Menu()
            chat_with_menuitem.set_submenu(account_menu_for_chat_with)
            self.popup_menus.append(account_menu_for_chat_with)

            for account in accounts_list:
                account_label = app.config.get_per('accounts', account,
                                                   'account_label') or account
                if app.account_is_connected(account):
                    # for chat_with
                    item = Gtk.MenuItem.new_with_label(
                        _('using account %s') % account_label)
                    account_menu_for_chat_with.append(item)
                    item.connect('activate', self.on_new_chat, account)

        elif connected_accounts == 1:  # one account
            # one account connected, no need to show 'as jid'
            for account in app.connections:
                if app.connections[account].connected > 1:
                    # for start chat
                    self.new_chat_handler_id = chat_with_menuitem.connect(
                        'activate', self.on_new_chat, account)
                    break  # No other connected account

        # menu items that don't apply to zeroconf connections
        if connected_accounts == 1 or (connected_accounts == 2 and \
        app.zeroconf_is_connected()):
            # only one 'real' (non-zeroconf) account is connected, don't need
            # submenus
            for account in app.connections:
                if app.account_is_connected(account) and \
                not app.config.get_per('accounts', account, 'is_zeroconf'):
                    if app.connections[account].private_storage_supported:
                        connected_accounts_with_private_storage += 1

                    # for single message
                    single_message_menuitem.set_submenu(None)
                    self.single_message_handler_id = single_message_menuitem.\
                            connect('activate',
                            self.on_single_message_menuitem_activate, account)
                    # join gc
                    app.interface.roster.add_bookmarks_list(
                        gc_sub_menu, account)
                    break  # No other account connected
        else:
            # 2 or more 'real' accounts are connected, make submenus
            account_menu_for_single_message = Gtk.Menu()
            single_message_menuitem.set_submenu(
                account_menu_for_single_message)
            self.popup_menus.append(account_menu_for_single_message)

            for account in accounts_list:
                account_label = app.config.get_per('accounts', account,
                                                   'account_label') or account
                if app.connections[account].is_zeroconf or \
                not app.account_is_connected(account):
                    continue
                if app.connections[account].private_storage_supported:
                    connected_accounts_with_private_storage += 1
                # for single message
                item = Gtk.MenuItem.new_with_label(
                    _('using account %s') % account_label)
                item.connect('activate',
                             self.on_single_message_menuitem_activate, account)
                account_menu_for_single_message.append(item)

                # join gc
                gc_item = Gtk.MenuItem.new_with_label(
                    _('using account %s') % account_label)
                gc_sub_menu.append(gc_item)
                gc_menuitem_menu = Gtk.Menu()
                app.interface.roster.add_bookmarks_list(
                    gc_menuitem_menu, account)
                gc_item.set_submenu(gc_menuitem_menu)
                gc_sub_menu.show_all()

        newitem = Gtk.SeparatorMenuItem.new()  # separator
        gc_sub_menu.append(newitem)
        newitem = Gtk.MenuItem.new_with_mnemonic(_('_Manage Bookmarks…'))
        newitem.connect(
            'activate',
            app.interface.roster.on_manage_bookmarks_menuitem_activate)
        gc_sub_menu.append(newitem)
        if connected_accounts_with_private_storage == 0:
            newitem.set_sensitive(False)

        sounds_mute_menuitem.set_active(not app.config.get('sounds_on'))

        win = app.interface.roster.window
        if self.show_roster_handler_id:
            show_roster_menuitem.handler_disconnect(
                self.show_roster_handler_id)
        if win.get_property('has-toplevel-focus'):
            show_roster_menuitem.get_children()[0].set_label(_('Hide _Roster'))
            self.show_roster_handler_id = show_roster_menuitem.connect(
                'activate', self.on_hide_roster_menuitem_activate)
        else:
            show_roster_menuitem.get_children()[0].set_label(_('Show _Roster'))
            self.show_roster_handler_id = show_roster_menuitem.connect(
                'activate', self.on_show_roster_menuitem_activate)

        if os.name == 'nt':
            if self.added_hide_menuitem is False:
                self.systray_context_menu.prepend(Gtk.SeparatorMenuItem.new())
                item = Gtk.MenuItem.new_with_label(_('Hide this menu'))
                self.systray_context_menu.prepend(item)
                self.added_hide_menuitem = True

        self.systray_context_menu.show_all()
        self.systray_context_menu.popup(None, None, None, None, 0, event_time)
Example #17
0
    def __init__(self, on_response, show=None, show_pep=True):
        countdown_time = app.config.get('change_status_window_timeout')
        TimeoutDialog.__init__(self, countdown_time)
        self.show = show
        self.pep_dict = {}
        self.show_pep = show_pep
        self.on_response = on_response
        self.xml = get_builder('change_status_message_dialog.ui')
        self.dialog = self.xml.get_object('change_status_message_dialog')
        self.dialog.set_transient_for(app.interface.roster.window)
        msg = None
        if show:
            uf_show = helpers.get_uf_show(show)
            self.title_text = _('%s Status Message') % uf_show
            msg = app.config.get_per('statusmsg', '_last_' + self.show,
                                     'message')
            self.pep_dict['activity'] = app.config.get_per(
                'statusmsg', '_last_' + self.show, 'activity')
            self.pep_dict['subactivity'] = app.config.get_per(
                'statusmsg', '_last_' + self.show, 'subactivity')
            self.pep_dict['activity_text'] = app.config.get_per(
                'statusmsg', '_last_' + self.show, 'activity_text')
            self.pep_dict['mood'] = app.config.get_per('statusmsg',
                                                       '_last_' + self.show,
                                                       'mood')
            self.pep_dict['mood_text'] = app.config.get_per(
                'statusmsg', '_last_' + self.show, 'mood_text')
        else:
            self.title_text = _('Status Message')
        self.dialog.set_title(self.title_text)

        message_textview = self.xml.get_object('message_textview')
        self.message_buffer = message_textview.get_buffer()

        if app.config.get('use_speller') and app.is_installed('GSPELL'):
            lang = app.config.get('speller_language')
            gspell_lang = Gspell.language_lookup(lang)
            if gspell_lang is None:
                AspellDictError(lang)
            else:
                spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(
                    self.message_buffer)
                spell_buffer.set_spell_checker(Gspell.Checker.new(gspell_lang))
                spell_view = Gspell.TextView.get_from_gtk_text_view(
                    message_textview)
                spell_view.set_inline_spell_checking(True)
                spell_view.set_enable_language_menu(True)

        self.message_buffer.connect('changed', self.on_message_buffer_changed)
        if not msg:
            msg = ''
        msg = helpers.from_one_line(msg)
        self.message_buffer.set_text(msg)

        # have an empty string selectable, so user can clear msg
        self.preset_messages_dict = {'': ['', '', '', '', '', '']}
        for msg_name in app.config.get_per('statusmsg'):
            if msg_name.startswith('_last_'):
                continue
            opts = []
            for opt in [
                    'message', 'activity', 'subactivity', 'activity_text',
                    'mood', 'mood_text'
            ]:
                opts.append(app.config.get_per('statusmsg', msg_name, opt))
            opts[0] = helpers.from_one_line(opts[0])
            self.preset_messages_dict[msg_name] = opts
        sorted_keys_list = helpers.get_sorted_keys(self.preset_messages_dict)

        self.message_liststore = Gtk.ListStore(str)  # msg_name
        self.message_combobox = self.xml.get_object('message_combobox')
        self.message_combobox.set_model(self.message_liststore)
        cellrenderertext = Gtk.CellRendererText()
        self.message_combobox.pack_start(cellrenderertext, True)
        self.message_combobox.add_attribute(cellrenderertext, 'text', 0)
        for msg_name in sorted_keys_list:
            self.message_liststore.append((msg_name, ))

        if show_pep:
            self.draw_activity()
            self.draw_mood()
        else:
            # remove acvtivity / mood lines
            self.xml.get_object('activity_label').set_no_show_all(True)
            self.xml.get_object('activity_button').set_no_show_all(True)
            self.xml.get_object('mood_label').set_no_show_all(True)
            self.xml.get_object('mood_button').set_no_show_all(True)
            self.xml.get_object('activity_label').hide()
            self.xml.get_object('activity_button').hide()
            self.xml.get_object('mood_label').hide()
            self.xml.get_object('mood_button').hide()

        self.xml.connect_signals(self)
        self.run_timeout()
        self.dialog.connect('response', self.on_dialog_response)
        self.dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
        self.dialog.show_all()
Example #18
0
    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')
Example #19
0
def get_transport_menu(contact, account):
    roster = app.interface.roster
    jid = contact.jid

    menu = Gtk.Menu()

    # Send single message
    item = Gtk.MenuItem.new_with_mnemonic(_('Send Single _Message…'))
    item.connect('activate', roster.on_send_single_message_menuitem_activate,
                 account, contact)
    menu.append(item)
    if app.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.MenuItem.new_with_mnemonic(
        _('Send Cus_tom Status'))
    if blocked:
        send_custom_status_menuitem.set_sensitive(False)
    else:
        status_menuitems = Gtk.Menu()
        send_custom_status_menuitem.set_submenu(status_menuitems)
        for s in ('online', 'chat', 'away', 'xa', 'dnd', 'offline'):
            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)
    menu.append(send_custom_status_menuitem)
    if app.account_is_disconnected(account):
        send_custom_status_menuitem.set_sensitive(False)

    item = Gtk.SeparatorMenuItem.new()  # separator
    menu.append(item)

    # Execute Command
    item = Gtk.MenuItem.new_with_mnemonic(_('E_xecute Command…'))
    menu.append(item)
    item.connect('activate', roster.on_execute_command, contact, account,
                 contact.resource)
    if app.account_is_disconnected(account):
        item.set_sensitive(False)

    # Manage Transport submenu
    item = Gtk.MenuItem.new_with_mnemonic(_('_Manage Transport'))
    manage_transport_submenu = Gtk.Menu()
    item.set_submenu(manage_transport_submenu)
    menu.append(item)

    # Modify Transport
    item = Gtk.MenuItem.new_with_mnemonic(_('_Modify Transport'))
    manage_transport_submenu.append(item)
    item.connect('activate', roster.on_edit_agent, contact, account)
    if app.account_is_disconnected(account):
        item.set_sensitive(False)

    # Rename
    item = Gtk.MenuItem.new_with_mnemonic(_('_Rename…'))
    manage_transport_submenu.append(item)
    item.connect('activate', roster.on_rename, 'agent', jid, account)
    if app.account_is_disconnected(account):
        item.set_sensitive(False)

    item = Gtk.SeparatorMenuItem.new()  # separator
    manage_transport_submenu.append(item)

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

    manage_transport_submenu.append(item)
    if app.account_is_disconnected(account):
        item.set_sensitive(False)

    # Remove
    item = Gtk.MenuItem.new_with_mnemonic(_('Remo_ve'))
    manage_transport_submenu.append(item)
    item.connect('activate', roster.on_remove_agent, [(contact, account)])
    if app.account_is_disconnected(account):
        item.set_sensitive(False)

    item = Gtk.SeparatorMenuItem.new()  # separator
    menu.append(item)

    # Information
    information_menuitem = Gtk.MenuItem.new_with_mnemonic(_('_Information'))
    menu.append(information_menuitem)
    information_menuitem.connect('activate', roster.on_info, contact, account)
    if app.account_is_disconnected(account):
        information_menuitem.set_sensitive(False)

    menu.connect('selection-done', gtkgui_helpers.destroy_widget)
    menu.show_all()
    return menu
    def _fill_logs_listview(self, jid):
        """
        Fill the listview with all messages that user sent to or received from
        JID
        """
        # no need to lower jid in this context as jid is already lowered
        # as we use those jids from db
        jid_id = self._get_jid_id(jid)
        self.cur.execute('''
                SELECT log_line_id, jid_id, time, kind, message, subject, contact_name, show
                FROM logs
                WHERE jid_id = ?
                ORDER BY time
                ''', (jid_id,))

        results = self.cur.fetchall()

        if self._jid_is_room_type(jid):  # is it room?
            self.nickname_col_for_logs.set_visible(True)
            self.subject_col_for_logs.set_visible(False)
        else:
            self.nickname_col_for_logs.set_visible(False)
            self.subject_col_for_logs.set_visible(True)

        for row in results:
            # exposed in UI (TreeViewColumns) are only
            # time, message, subject, nickname
            # but store in liststore
            # log_line_id, jid_id, time, message, subject, nickname
            log_line_id, jid_id, time_, kind, message, subject, nickname, \
                show = row
            try:
                time_ = time.strftime('%x', time.localtime(float(time_)))
            except ValueError:
                pass
            else:
                color = None
                if kind in (KindConstant.SINGLE_MSG_RECV,
                KindConstant.CHAT_MSG_RECV, KindConstant.GC_MSG):
                    # it is the other side
                    color = app.css_config.get_value('.gajim-incoming-nickname', StyleAttr.COLOR)  # so incoming color
                elif kind in (KindConstant.SINGLE_MSG_SENT,
                KindConstant.CHAT_MSG_SENT):  # it is us
                    color = app.css_config.get_value('.gajim-outgoing-nickname', StyleAttr.COLOR)  # so outgoing color
                elif kind in (KindConstant.STATUS,
                KindConstant.GCSTATUS):  # is is statuses
                    # so status color
                    color = app.css_config.get_value('.gajim-status-message', StyleAttr.COLOR)
                    # include status into (status) message
                    if message is None:
                        message = ''
                    else:
                        message = ' : ' + message
                    message = helpers.get_uf_show(app.SHOW_LIST[show]) + \
                        message

                message_ = '<span'
                if color:
                    message_ += ' foreground="%s"' % color
                message_ += '>%s</span>' % GLib.markup_escape_text(message)
                self.logs_liststore.append((str(log_line_id), str(jid_id),
                    time_, message_, subject, nickname))
Example #21
0
    def _make_menu(self, _event_button, event_time):
        """
        Create chat with and new message (sub) menus/menuitems
        """
        for menu in self.popup_menus:
            menu.destroy()

        start_chat_menuitem = self._ui.start_chat_menuitem
        single_message_menuitem = self._ui.single_message_menuitem
        status_menuitem = self._ui.status_menu
        sounds_mute_menuitem = self._ui.sounds_mute_menuitem
        show_roster_menuitem = self._ui.show_roster_menuitem

        if self._single_message_handler_id:
            single_message_menuitem.handler_disconnect(
                self._single_message_handler_id)
            self._single_message_handler_id = None

        sub_menu = Gtk.Menu()
        self.popup_menus.append(sub_menu)
        status_menuitem.set_submenu(sub_menu)

        for show in ('online', 'chat', 'away', 'xa', 'dnd', 'invisible'):
            uf_show = helpers.get_uf_show(show, use_mnemonic=True)
            item = Gtk.MenuItem.new_with_mnemonic(uf_show)
            sub_menu.append(item)
            item.connect('activate', self._on_show, show)

        item = Gtk.SeparatorMenuItem.new()
        sub_menu.append(item)

        item = Gtk.MenuItem.new_with_mnemonic(_('_Change Status Message…'))
        sub_menu.append(item)
        item.connect('activate', self._on_change_status)

        connected_accounts = app.get_number_of_connected_accounts()
        if connected_accounts < 1:
            item.set_sensitive(False)

        item = Gtk.SeparatorMenuItem.new()
        sub_menu.append(item)

        uf_show = helpers.get_uf_show('offline', use_mnemonic=True)
        item = Gtk.MenuItem.new_with_mnemonic(uf_show)
        sub_menu.append(item)
        item.connect('activate', self._on_show, 'offline')

        is_zeroconf = connected_accounts == 1 and app.zeroconf_is_connected()
        iskey = connected_accounts > 0 and not is_zeroconf
        start_chat_menuitem.set_sensitive(iskey)
        single_message_menuitem.set_sensitive(iskey)

        accounts_list = sorted(app.contacts.get_accounts())

        # menu items that don't apply to zeroconf connections
        if connected_accounts == 1 or (connected_accounts == 2 and \
        app.zeroconf_is_connected()):
            # only one 'real' (non-zeroconf) account is connected, don't need
            # submenus
            for account in app.connections:
                if app.account_is_connected(account) and \
                not app.config.get_per('accounts', account, 'is_zeroconf'):

                    # for single message
                    single_message_menuitem.set_submenu(None)
                    self._single_message_handler_id = single_message_menuitem.\
                            connect('activate',
                                    self._on_single_message, account)
                    break  # No other account connected
        else:
            # 2 or more 'real' accounts are connected, make submenus
            account_menu_for_single_message = Gtk.Menu()
            single_message_menuitem.set_submenu(
                account_menu_for_single_message)
            self.popup_menus.append(account_menu_for_single_message)

            for account in accounts_list:
                account_label = app.get_account_label(account)
                if app.connections[account].is_zeroconf or \
                not app.account_is_connected(account):
                    continue
                # for single message
                item = Gtk.MenuItem.new_with_label(
                    _('using account %s') % account_label)
                item.connect('activate', self._on_single_message, account)
                account_menu_for_single_message.append(item)

        sounds_mute_menuitem.set_active(not app.config.get('sounds_on'))

        win = app.interface.roster.window
        if self._show_roster_handler_id:
            show_roster_menuitem.handler_disconnect(
                self._show_roster_handler_id)
        if win.get_property('has-toplevel-focus'):
            show_roster_menuitem.get_children()[0].set_label(
                _('Hide _Contact List'))
            self._show_roster_handler_id = show_roster_menuitem.connect(
                'activate', self._on_hide_roster)
        else:
            show_roster_menuitem.get_children()[0].set_label(
                _('Show _Contact List'))
            self._show_roster_handler_id = show_roster_menuitem.connect(
                'activate', self._on_show_roster)

        if os.name == 'nt':
            if self.added_hide_menuitem is False:
                self.systray_context_menu.prepend(Gtk.SeparatorMenuItem.new())
                item = Gtk.MenuItem.new_with_label(_('Hide this menu'))
                self.systray_context_menu.prepend(item)
                self.added_hide_menuitem = True

        self.systray_context_menu.show_all()
        self.systray_context_menu.popup(None, None, None, None, 0, event_time)