Ejemplo n.º 1
0
    def __init__(self, account, parent):

        options = [
            Option(OptionKind.ENTRY,
                   _('Password'),
                   OptionType.ACCOUNT_CONFIG,
                   'password',
                   name='password',
                   enabledif=('savepass', True)),
            Option(OptionKind.SWITCH,
                   _('Save Password'),
                   OptionType.ACCOUNT_CONFIG,
                   'savepass',
                   name='savepass'),
            Option(OptionKind.CHANGEPASSWORD,
                   _('Change Password'),
                   OptionType.DIALOG,
                   callback=self.on_password_change,
                   props={'dialog': None}),
        ]

        OptionsDialog.__init__(self, parent, _('Login Options'),
                               Gtk.DialogFlags.MODAL, options, account)

        self.connect('destroy', self.on_destroy)
Ejemplo n.º 2
0
    def __init__(self, account, parent):

        options = [
            Option(OptionKind.FILECHOOSER,
                   _('Client Certificate'),
                   OptionType.ACCOUNT_CONFIG,
                   'client_cert',
                   props={'filefilter': (_('PKCS12 Files'), '*.p12')}),
            Option(OptionKind.SWITCH, _('Encrypted Certificate'),
                   OptionType.ACCOUNT_CONFIG, 'client_cert_encrypted'),
        ]

        OptionsDialog.__init__(self, parent, _('Certificate Options'),
                               Gtk.DialogFlags.MODAL, options, account)
Ejemplo n.º 3
0
    def __init__(self, account, parent):

        options = [
            Option(OptionKind.ENTRY, _('First Name'),
                   OptionType.ACCOUNT_CONFIG, 'zeroconf_first_name'),
            Option(OptionKind.ENTRY, _('Last Name'), OptionType.ACCOUNT_CONFIG,
                   'zeroconf_last_name'),
            Option(OptionKind.ENTRY, _('Jabber ID'), OptionType.ACCOUNT_CONFIG,
                   'zeroconf_jabber_id'),
            Option(OptionKind.ENTRY, _('Email'), OptionType.ACCOUNT_CONFIG,
                   'zeroconf_email'),
        ]

        OptionsDialog.__init__(self, parent, _('Profile'),
                               Gtk.DialogFlags.MODAL, options, account)
Ejemplo n.º 4
0
    def on_filter_options(self, *args):
        if self.filter_dialog:
            self.filter_dialog.present()
            return
        options = [
            Option(OptionKind.SWITCH,
                   'Presence',
                   OptionType.VALUE,
                   self.presence,
                   callback=self.on_option,
                   data='presence'),
            Option(OptionKind.SWITCH,
                   'Message',
                   OptionType.VALUE,
                   self.message,
                   callback=self.on_option,
                   data='message'),
            Option(OptionKind.SWITCH,
                   'Iq',
                   OptionType.VALUE,
                   self.iq,
                   callback=self.on_option,
                   data='iq'),
            Option(OptionKind.SWITCH,
                   'Stream\nManagement',
                   OptionType.VALUE,
                   self.stream,
                   callback=self.on_option,
                   data='stream'),
            Option(OptionKind.SWITCH,
                   'In',
                   OptionType.VALUE,
                   self.incoming,
                   callback=self.on_option,
                   data='incoming'),
            Option(OptionKind.SWITCH,
                   'Out',
                   OptionType.VALUE,
                   self.outgoing,
                   callback=self.on_option,
                   data='outgoing'),
        ]

        self.filter_dialog = OptionsDialog(self, 'Filter',
                                           Gtk.DialogFlags.DESTROY_WITH_PARENT,
                                           options, self.account)
        self.filter_dialog.connect('destroy', self.on_filter_destroyed)
Ejemplo n.º 5
0
    def __init__(self, account, parent):

        options = [
            Option(OptionKind.SWITCH,
                   _('Enable'),
                   OptionType.ACCOUNT_CONFIG,
                   'use_custom_host',
                   name='custom'),
            Option(OptionKind.ENTRY,
                   _('Hostname'),
                   OptionType.ACCOUNT_CONFIG,
                   'custom_host',
                   enabledif=('custom', True)),
            Option(OptionKind.ENTRY,
                   _('Port'),
                   OptionType.ACCOUNT_CONFIG,
                   'custom_port',
                   enabledif=('custom', True)),
        ]

        OptionsDialog.__init__(self, parent, _('Connection Options'),
                               Gtk.DialogFlags.MODAL, options, account)
Ejemplo n.º 6
0
    def __init__(self, account, parent):

        neg_priority = app.config.get('enable_negative_priority')
        if neg_priority:
            range_ = (-128, 127)
        else:
            range_ = (0, 127)

        options = [
            Option(OptionKind.SWITCH, _('Adjust to status'),
                   OptionType.ACCOUNT_CONFIG, 'adjust_priority_with_status',
                   'adjust'),
            Option(OptionKind.SPIN,
                   _('Priority'),
                   OptionType.ACCOUNT_CONFIG,
                   'priority',
                   enabledif=('adjust', False),
                   props={'range_': range_}),
        ]

        OptionsDialog.__init__(self, parent, _('Priority'),
                               Gtk.DialogFlags.MODAL, options, account)

        self.connect('destroy', self.on_destroy)
    def __init__(self, plugin, parent):

        sizes = [('256 KiB', '262144'), ('512 KiB', '524288'),
                 ('1 MiB', '1048576'), ('5 MiB', '5242880'),
                 ('10 MiB', '10485760')]
        actions = [
            (_('Open'), 'open_menuitem'), (_('Save as'), 'save_as_menuitem'),
            (_('Copy Link Location'), 'copy_link_location_menuitem'),
            (_('Open Link in Browser'), 'open_link_in_browser_menuitem'),
            (_('Open File in Browser'), 'open_file_in_browser_menuitem')
        ]

        geo_providers = [(_('No map preview'), 'no_preview'),
                         ('Google Maps', 'Google'), ('OpenStreetMap', 'OSM')]

        self.plugin = plugin
        options = [
            Option('PreviewSizeSpinOption',
                   _('Preview size'),
                   OptionType.VALUE,
                   self.plugin.config['PREVIEW_SIZE'],
                   callback=self.on_option,
                   data='PREVIEW_SIZE',
                   props={'range_': (100, 1000)}),
            Option('PreviewComboOption',
                   _('Accepted filesize'),
                   OptionType.VALUE,
                   self.plugin.config['MAX_FILE_SIZE'],
                   callback=self.on_option,
                   data='MAX_FILE_SIZE',
                   props={
                       'items': sizes,
                       'plugin': self.plugin
                   }),
            Option(OptionKind.SWITCH,
                   _('Preview all Image URLs'),
                   OptionType.VALUE,
                   self.plugin.config['ALLOW_ALL_IMAGES'],
                   callback=self.on_option,
                   data='ALLOW_ALL_IMAGES'),
            Option('PreviewComboOption',
                   _('Left click action'),
                   OptionType.VALUE,
                   self.plugin.config['LEFTCLICK_ACTION'],
                   callback=self.on_option,
                   data='LEFTCLICK_ACTION',
                   props={
                       'items': actions,
                       'plugin': self.plugin
                   }),
            Option('PreviewComboOption',
                   _('Map service for preview'),
                   OptionType.VALUE,
                   self.plugin.config['GEO_PREVIEW_PROVIDER'],
                   callback=self.on_option,
                   data='GEO_PREVIEW_PROVIDER',
                   props={
                       'items': geo_providers,
                       'plugin': self.plugin
                   }),
            Option(OptionKind.SWITCH,
                   _('Enable HTTPS Verification'),
                   OptionType.VALUE,
                   self.plugin.config['VERIFY'],
                   callback=self.on_option,
                   data='VERIFY'),
        ]

        OptionsDialog.__init__(self,
                               parent,
                               _('UrlImagePreview Options'),
                               Gtk.DialogFlags.MODAL,
                               options,
                               None,
                               extend=[('PreviewComboOption', ComboOption),
                                       ('PreviewSizeSpinOption',
                                        SizeSpinOption)])
Ejemplo n.º 8
0
class XMLConsoleWindow(Gtk.Window):
    def __init__(self, account):
        Gtk.Window.__init__(self)
        self.account = account
        self.enabled = True
        self.presence = True
        self.message = True
        self.iq = True
        self.stream = True
        self.incoming = True
        self.outgoing = True
        self.filter_dialog = None

        glade_objects = [
            'textview', 'input', 'scrolled_input', 'headerbar', 'scrolled',
            'actionbar', 'paned', 'box', 'menubutton'
        ]
        self.builder = get_builder('xml_console_window.ui')
        for obj in glade_objects:
            setattr(self, obj, self.builder.get_object(obj))

        self.set_titlebar(self.headerbar)
        jid = app.get_jid_from_account(account)
        self.headerbar.set_subtitle(jid)
        self.set_default_size(600, 600)
        self.add(self.box)

        self.paned.set_position(self.paned.get_property('max-position'))

        button = get_image_button('edit-clear-all-symbolic', _('Clear'))
        button.connect('clicked', self.on_clear)
        self.actionbar.pack_start(button)

        button = get_image_button('applications-system-symbolic', _('Filter'))
        button.connect('clicked', self.on_filter_options)
        self.actionbar.pack_start(button)

        button = get_image_button('document-edit-symbolic',
                                  _('XML Input'),
                                  toggle=True)
        button.connect('toggled', self.on_input)
        self.actionbar.pack_start(button)

        button = get_image_button('emblem-ok-symbolic', _('Send'))
        button.connect('clicked', self.on_send)
        self.actionbar.pack_end(button)

        self.actionbar.pack_start(self.menubutton)

        self.create_tags()
        self.show_all()

        self.scrolled_input.hide()
        self.menubutton.hide()

        self.connect("destroy", self.on_destroy)
        self.connect('key_press_event', self.on_key_press_event)
        self.builder.connect_signals(self)

        app.ged.register_event_handler('stanza-received', ged.GUI1,
                                       self._nec_stanza_received)
        app.ged.register_event_handler('stanza-sent', ged.GUI1,
                                       self._nec_stanza_sent)

    def create_tags(self):
        buffer_ = self.textview.get_buffer()
        in_color = app.css_config.get_value('.gajim-incoming-nickname',
                                            StyleAttr.COLOR)
        out_color = app.css_config.get_value('.gajim-outgoing-nickname',
                                             StyleAttr.COLOR)

        tags = ['presence', 'message', 'stream', 'iq']

        tag = buffer_.create_tag('incoming')
        tag.set_property('foreground', in_color)
        tag = buffer_.create_tag('outgoing')
        tag.set_property('foreground', out_color)

        for tag_name in tags:
            buffer_.create_tag(tag_name)

    def on_key_press_event(self, widget, event):
        if event.keyval == Gdk.KEY_Escape:
            self.destroy()

    def on_row_activated(self, listbox, row):
        text = row.get_child().get_text()
        input_text = None
        if text == 'Presence':
            input_text = ('<presence>\n'
                          '<show></show>\n'
                          '<status></status>\n'
                          '<priority></priority>\n'
                          '</presence>')
        elif text == 'Message':
            input_text = ('<message to="" type="">\n'
                          '<body></body>\n'
                          '</message>')
        elif text == 'Iq':
            input_text = ('<iq to="" type="">\n'
                          '<query xmlns=""></query>\n'
                          '</iq>')

        if input_text is not None:
            buffer_ = self.input.get_buffer()
            buffer_.set_text(input_text)
            self.input.grab_focus()

    def on_send(self, *args):
        if app.connections[self.account].connected <= 1:
            # if offline or connecting
            ErrorDialog(
                _('Connection not available'),
                _('Please make sure you are connected with "%s".') %
                self.account)
            return
        buffer_ = self.input.get_buffer()
        begin_iter, end_iter = buffer_.get_bounds()
        stanza = buffer_.get_text(begin_iter, end_iter, True)
        if stanza:
            try:
                node = nbxmpp.Protocol(node=stanza)
                if node.getNamespace() == UNDECLARED:
                    node.setNamespace(nbxmpp.NS_CLIENT)
            except Exception as error:
                ErrorDialog(_('Invalid Node'), str(error))
                return
            app.connections[self.account].connection.send(node)
            buffer_.set_text('')

    def on_input(self, button, *args):
        if button.get_active():
            self.paned.get_child2().show()
            self.menubutton.show()
            self.input.grab_focus()
        else:
            self.paned.get_child2().hide()
            self.menubutton.hide()

    def on_filter_options(self, *args):
        if self.filter_dialog:
            self.filter_dialog.present()
            return
        options = [
            Option(OptionKind.SWITCH,
                   'Presence',
                   OptionType.VALUE,
                   self.presence,
                   callback=self.on_option,
                   data='presence'),
            Option(OptionKind.SWITCH,
                   'Message',
                   OptionType.VALUE,
                   self.message,
                   callback=self.on_option,
                   data='message'),
            Option(OptionKind.SWITCH,
                   'Iq',
                   OptionType.VALUE,
                   self.iq,
                   callback=self.on_option,
                   data='iq'),
            Option(OptionKind.SWITCH,
                   'Stream\nManagement',
                   OptionType.VALUE,
                   self.stream,
                   callback=self.on_option,
                   data='stream'),
            Option(OptionKind.SWITCH,
                   'In',
                   OptionType.VALUE,
                   self.incoming,
                   callback=self.on_option,
                   data='incoming'),
            Option(OptionKind.SWITCH,
                   'Out',
                   OptionType.VALUE,
                   self.outgoing,
                   callback=self.on_option,
                   data='outgoing'),
        ]

        self.filter_dialog = OptionsDialog(self, 'Filter',
                                           Gtk.DialogFlags.DESTROY_WITH_PARENT,
                                           options, self.account)
        self.filter_dialog.connect('destroy', self.on_filter_destroyed)

    def on_filter_destroyed(self, win):
        self.filter_dialog = None

    def on_clear(self, *args):
        self.textview.get_buffer().set_text('')

    def on_destroy(self, *args):
        del app.interface.instances[self.account]['xml_console']
        app.ged.remove_event_handler('stanza-received', ged.GUI1,
                                     self._nec_stanza_received)
        app.ged.remove_event_handler('stanza-sent', ged.GUI1,
                                     self._nec_stanza_sent)

    def on_enable(self, switch, param):
        self.enabled = switch.get_active()

    def on_option(self, value, data):
        setattr(self, data, value)
        value = not value
        table = self.textview.get_buffer().get_tag_table()
        tag = table.lookup(data)
        if data in ('incoming', 'outgoing'):
            if value:
                tag.set_priority(table.get_size() - 1)
            else:
                tag.set_priority(0)
        tag.set_property('invisible', value)

    def _nec_stanza_received(self, obj):
        if obj.conn.name != self.account:
            return
        self.print_stanza(obj.stanza_str, 'incoming')

    def _nec_stanza_sent(self, obj):
        if obj.conn.name != self.account:
            return
        self.print_stanza(obj.stanza_str, 'outgoing')

    def print_stanza(self, stanza, kind):
        # kind must be 'incoming' or 'outgoing'
        if not self.enabled:
            return
        if not stanza:
            return

        at_the_end = util.at_the_end(self.scrolled)

        buffer_ = self.textview.get_buffer()
        end_iter = buffer_.get_end_iter()

        type_ = kind
        if stanza.startswith('<presence'):
            type_ = 'presence'
        elif stanza.startswith('<message'):
            type_ = 'message'
        elif stanza.startswith('<iq'):
            type_ = 'iq'
        elif stanza.startswith('<r') or stanza.startswith('<a'):
            type_ = 'stream'

        stanza = '<!-- {kind} {time} -->\n{stanza}\n\n'.format(
            kind=kind.capitalize(),
            time=time.strftime('%c'),
            stanza=stanza.replace('><', '>\n<'))
        buffer_.insert_with_tags_by_name(end_iter, stanza, type_, kind)

        if at_the_end:
            GLib.idle_add(util.scroll_to_end, self.scrolled)