示例#1
0
    def on_server_entry_focus_out(self, widget, event):
        if self.ignore_events:
            return
        (model, iter_) = self.selection.get_selected()
        if not iter_:
            return
        server = widget.get_text()
        if not server:
            return
        if '@' in server:
            ErrorDialog(_('Invalid server'),
                        _('Character not allowed'),
                        transient_for=self.window)
            widget.set_text(server.replace('@', ''))

        room = self.room_entry.get_text().strip()
        if not room:
            return
        room_jid = room + '@' + server.strip()
        try:
            room_jid = helpers.parse_jid(room_jid)
        except helpers.InvalidFormat as e:
            ErrorDialog(_('Invalid server'),
                        _('Character not allowed'),
                        transient_for=self.window)
            self.server_entry.set_text(model[iter_][2].split('@')[1])
            return True
        model[iter_][2] = room_jid
示例#2
0
 def get_send_file_props(self,
                         account,
                         contact,
                         file_path,
                         file_name,
                         file_desc=''):
     """
     Create new file_props object and set initial file transfer
     properties in it
     """
     if os.path.isfile(file_path):
         stat = os.stat(file_path)
     else:
         ErrorDialog(_('Invalid File'), _('File: ') + file_path)
         return None
     if stat[6] == 0:
         ErrorDialog(_('Invalid File'),
                     _('It is not possible to send empty files'))
         return None
     file_props = FilesProp.getNewFileProp(
         account, sid=helpers.get_random_string_16())
     mod_date = os.path.getmtime(file_path)
     file_props.file_name = file_path
     file_props.name = file_name
     file_props.date = self.__convert_date(mod_date)
     file_props.type_ = 's'
     file_props.desc = file_desc
     file_props.elapsed_time = 0
     file_props.size = stat[6]
     file_props.sender = account
     file_props.receiver = contact
     file_props.tt_account = account
     return file_props
示例#3
0
    def _on_theme_name_edit(self, renderer, path, new_name):
        iter_ = self._theme_store.get_iter(path)
        old_name = self._theme_store[iter_][Column.THEME]

        if new_name == 'default':
            ErrorDialog(
                _('Invalid Name'),
                _('Name <b>default</b> is not allowed'),
                transient_for=self)
            return

        if ' ' in new_name:
            ErrorDialog(
                _('Invalid Name'),
                _('Spaces are not allowed'),
                transient_for=self)
            return

        if new_name == '':
            return

        result = app.css_config.rename_theme(old_name, new_name)
        if result is False:
            return

        self._theme_store.set_value(iter_, Column.THEME, new_name)
示例#4
0
    def send_single_message(self):
        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 True
        if isinstance(self.to, list):
            sender_list = []
            for i in self.to:
                if i[0].resource:
                    sender_list.append(i[0].jid + '/' + i[0].resource)
                else:
                    sender_list.append(i[0].jid)
        else:
            sender_list = [j.strip() for j in self.to_entry.get_text().split(
                ',')]

        subject = self.subject_entry.get_text()
        begin, end = self.message_tv_buffer.get_bounds()
        message = self.message_tv_buffer.get_text(begin, end, True)

        if self.form_widget:
            form_node = self.form_widget.data_form
        else:
            form_node = None

        recipient_list = []

        for to_whom_jid in sender_list:
            if to_whom_jid in self.completion_dict:
                to_whom_jid = self.completion_dict[to_whom_jid].jid
            try:
                to_whom_jid = helpers.parse_jid(to_whom_jid)
            except helpers.InvalidFormat:
                ErrorDialog(_('Invalid JID'),
                    _('It is not possible to send a message to %s, this JID is not '
                    'valid.') % to_whom_jid)
                return True

            if '/announce/' in to_whom_jid:
                app.connections[self.account].send_motd(to_whom_jid, subject,
                    message)
                continue

            recipient_list.append(to_whom_jid)

        app.nec.push_outgoing_event(MessageOutgoingEvent(None,
            account=self.account, jid=recipient_list, message=message,
            type_='normal', subject=subject, form_node=form_node))

        self.subject_entry.set_text('') # we sent ok, clear the subject
        self.message_tv_buffer.set_text('') # we sent ok, clear the textview
示例#5
0
        def remove():
            if self.account in app.connections and \
            app.connections[self.account].connected and \
            not self.remove_and_unregister_radiobutton.get_active():
                # change status to offline only if we will not remove this JID from
                # server
                app.connections[self.account].change_status('offline', 'offline')
            if self.remove_and_unregister_radiobutton.get_active():
                if not self.account in app.connections:
                    ErrorDialog(
                        _('Account is disabled'),
                        _('To unregister from a server, account must be '
                        'enabled.'),
                        transient_for=self.window)
                    return
                if not app.connections[self.account].password:
                    def on_ok(passphrase, checked):
                        if passphrase == -1:
                            # We don't remove account cause we canceled pw window
                            return
                        app.connections[self.account].password = passphrase
                        app.connections[self.account].unregister_account(
                                self._on_remove_success)

                    dialogs.PassphraseDialog(
                            _('Password Required'),
                            _('Enter your password for account %s') % self.account,
                            _('Save password'), ok_handler=on_ok,
                            transient_for=self.window)
                    return
                app.connections[self.account].unregister_account(
                        self._on_remove_success)
            else:
                self._on_remove_success(True)
示例#6
0
 def on_room_entry_changed(self, widget):
     if self.ignore_events:
         return
     (model, iter_) = self.selection.get_selected()
     if not iter_:
         return
     room = widget.get_text()
     if not room:
         return
     if '@' in room:
         room, server = room.split('@', 1)
         widget.set_text(room)
         if server:
             self.server_entry.set_text(server)
         self.server_entry.grab_focus()
     server = self.server_entry.get_text().strip()
     if not server:
         return
     room_jid = room.strip() + '@' + server
     try:
         room_jid = helpers.parse_jid(room_jid)
     except helpers.InvalidFormat:
         ErrorDialog(_('Invalid room'),
                     _('Character not allowed'),
                     transient_for=self.window)
         return True
     model[iter_][2] = room_jid
示例#7
0
 def on_ok_button_clicked(self, widget):
     if self.update_progressbar_timeout_id:
         # Operation in progress
         return
     if app.connections[self.account].connected < 2:
         ErrorDialog(
             _('You are not connected to the server'),
             _('Without a connection, you can not publish your contact '
               'information.'),
             transient_for=self)
         return
     vcard_, sha = self.make_vcard()
     nick = ''
     if 'NICKNAME' in vcard_:
         nick = vcard_['NICKNAME']
         app.connections[self.account].get_module('UserNickname').send(nick)
     if nick == '':
         app.connections[self.account].get_module('UserNickname').retract()
         nick = app.config.get_per('accounts', self.account, 'name')
     app.nicks[self.account] = nick
     app.connections[self.account].get_module('VCardTemp').send_vcard(
         vcard_, sha)
     self.message_id = self.statusbar.push(self.context_id,
                                           _('Sending profile…'))
     self.progressbar.show()
     self.update_progressbar_timeout_id = GLib.timeout_add(
         100, self.update_progressbar)
示例#8
0
    def on_add_button_clicked(self, widget):
        """
        When Subscribe button is clicked
        """
        jid = self.uid_entry.get_text().strip()
        if not jid:
            ErrorDialog(
                _('%s Missing') % self.uid_label.get_text(),
                _('You must supply the %s of the new contact.' %
                  self.uid_label.get_text()))
            return

        model = self.protocol_combobox.get_model()
        row = self.protocol_combobox.get_active_iter()
        type_ = model[row][2]
        if type_ != 'jabber':
            model = self.protocol_jid_combobox.get_model()
            row = self.protocol_jid_combobox.get_active()
            transport = model[row][0]
            if self.account and not self.jid_escaped:
                self.adding_jid = (jid, transport, type_)
                app.connections[self.account].request_gateway_prompt(
                    transport, jid)
            else:
                jid = jid.replace('@', '%') + '@' + transport
                self._add_jid(jid, type_)
        else:
            self._add_jid(jid, type_)
示例#9
0
    def on_calendar_month_changed(self, widget):
        """
        Ask for days in this month, if they have logs it bolds them
        (marks them)
        """
        if not self.jid:
            return
        year, month, day = widget.get_date()  # integers
        if year < 1900:
            widget.select_month(0, 1900)
            widget.select_day(1)
            return

        widget.clear_marks()
        month = python_month(month)

        try:
            log_days = app.logger.get_days_with_logs(self.account, self.jid,
                                                     year, month)
        except exceptions.PysqliteOperationalError as e:
            ErrorDialog(_('Disk Error'), str(e))
            return

        for date in log_days:
            widget.mark_day(date.day)
示例#10
0
    def send_file(self, account, contact, file_path, file_desc=''):
        """
        Start the real transfer(upload) of the file
        """
        if gtkgui_helpers.file_is_locked(file_path):
            pritext = _('Gajim can not read this file')
            sextext = _('Another process is using this file.')
            ErrorDialog(pritext, sextext)
            return

        if isinstance(contact, str):
            if contact.find('/') == -1:
                return
            (jid, resource) = contact.split('/', 1)
            contact = app.contacts.create_contact(jid=jid,
                                                  account=account,
                                                  resource=resource)
        file_name = os.path.split(file_path)[1]
        file_props = self.get_send_file_props(account, contact, file_path,
                                              file_name, file_desc)
        if file_props is None:
            return False
        if contact.supports(NS_JINGLE_FILE_TRANSFER_5):
            log.info("contact %s supports jingle file transfer" %
                     (contact.get_full_jid()))
            app.connections[account].start_file_transfer(
                contact.get_full_jid(), file_props)
            self.add_transfer(account, contact, file_props)
        else:
            log.info("contact does not support jingle file transfer")
            file_props.transport_sid = file_props.sid
            app.connections[account].send_file_request(file_props)
            self.add_transfer(account, contact, file_props)
        return True
示例#11
0
    def _on_remove_theme(self, *args):
        store, iter_ = self._theme_treeview.get_selection().get_selected()
        if iter_ is None:
            return

        theme = store[iter_][Column.THEME]
        if theme == app.config.get('roster_theme'):
            ErrorDialog(
                _('Active Theme'),
                _('You tried to delete the currently active theme. '
                  'Please switch to a different theme first.'),
                transient_for=self)
            return

        def _remove_theme():
            app.css_config.remove_theme(theme)
            store.remove(iter_)

            first = store.get_iter_first()
            if first is None:
                self._remove_theme_button.set_sensitive(False)
                self._add_option_button.set_sensitive(False)
                self._clear_options()

        buttons = {
            Gtk.ResponseType.CANCEL: DialogButton('Keep Theme'),
            Gtk.ResponseType.OK: DialogButton('Delete',
                                              _remove_theme,
                                              ButtonAction.DESTRUCTIVE),
        }

        NewConfirmationDialog('Delete Theme',
                              'Do you want to permanently delete this theme?',
                              buttons,
                              transient_for=self)
示例#12
0
        def on_ok(account, contact, file_props, file_path):
            if os.path.exists(file_path):
                app.config.set('last_save_dir', os.path.dirname(file_path))
                # check if we have write permissions
                if not os.access(file_path, os.W_OK):
                    file_name = GLib.markup_escape_text(
                        os.path.basename(file_path))
                    ErrorDialog(
                        _('Cannot overwrite existing file "%s"' % file_name),
                        _('A file with this name already exists and you do not '
                          'have permission to overwrite it.'))
                    return
                stat = os.stat(file_path)
                dl_size = stat.st_size
                file_size = file_props.size
                dl_finished = dl_size >= file_size

                def on_response(response):
                    if response < 0:
                        return
                    elif response == 100:
                        file_props.offset = dl_size
                    self._start_receive(file_path, account, contact,
                                        file_props)

                dialog = FTOverwriteConfirmationDialog(
                    _('This file already exists'),
                    _('What do you want to do?'),
                    propose_resume=not dl_finished,
                    on_response=on_response)
                dialog.set_destroy_with_parent(True)
                return
            else:
                dirname = os.path.dirname(file_path)
                if not os.access(dirname, os.W_OK) and os.name != 'nt':
                    # read-only bit is used to mark special folder under
                    # windows, not to mark that a folder is read-only.
                    # See ticket #3587
                    ErrorDialog(_('Directory "%s" is not writable') % \
                        dirname, _('You do not have permission to create files '
                        'in this directory.'))
                    return
            self._start_receive(file_path, account, contact, file_props)
示例#13
0
 def show_stopped(self, jid, file_props, error_msg=''):
     if file_props.type_ == 'r':
         file_name = os.path.basename(file_props.file_name)
     else:
         file_name = file_props.name
     sectext = '\t' + _('Filename: %s') % GLib.markup_escape_text(file_name)
     sectext += '\n\t' + _('Recipient: %s') % jid
     if error_msg:
         sectext += '\n\t' + _('Error message: %s') % error_msg
     ErrorDialog(_('File transfer stopped'), sectext)
     self.tree.get_selection().unselect_all()
示例#14
0
 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('')
示例#15
0
 def on_BDAY_entry_focus_out_event(self, widget, event):
     txt = widget.get_text()
     if not txt:
         return
     try:
         time.strptime(txt, '%Y-%m-%d')
     except ValueError:
         if not widget.is_focus():
             pritext = _('Wrong date format')
             ErrorDialog(pritext,
                         _('Format of the date must be YYYY-MM-DD'),
                         transient_for=self)
             GLib.idle_add(lambda: widget.grab_focus())
         return True
示例#16
0
    def save_account(self, login, server, savepass, password, anonymous=False):
        if self.account in app.connections:
            ErrorDialog(_('Account name is in use'),
                        _('You already have an account using this name.'))
            return
        con = connection.Connection(self.account)
        con.password = password

        config = self.get_config(login, server, savepass, password, anonymous)

        if not self.modify:
            con.new_account(self.account, config)
            return
        app.connections[self.account] = con
        self.create_vars(config)
示例#17
0
 def on_new_privacy_list_button_clicked(self, widget):
     name = self.new_privacy_list_entry.get_text()
     if not name:
         ErrorDialog(
             _('Invalid List Name'),
             _('You must enter a name to create a privacy list.'),
             transient_for=self.window)
         return
     key_name = 'privacy_list_%s' % name
     if key_name in app.interface.instances[self.account]:
         app.interface.instances[self.account][key_name].window.present()
     else:
         app.interface.instances[self.account][key_name] = \
             PrivacyListWindow(self.account, name, 'NEW')
     self.new_privacy_list_entry.set_text('')
示例#18
0
    def on_ok(file_path):
        if os.path.exists(file_path):
            # check if we have write permissions
            if not os.access(file_path, os.W_OK):
                file_name = os.path.basename(file_path)
                ErrorDialog(_('Cannot overwrite existing file "%s"') % \
                    file_name, _('A file with this name already exists and you '
                    'do not have permission to overwrite it.'))
                return
            dialog2 = FTOverwriteConfirmationDialog(
                _('This file already exists'),
                _('What do you want to do?'),
                propose_resume=False,
                on_response=(on_continue, file_path))
            dialog2.set_destroy_with_parent(True)
        else:
            dirname = os.path.dirname(file_path)
            if not os.access(dirname, os.W_OK):
                ErrorDialog(_('Directory "%s" is not writable') % \
                    dirname, _('You do not have permission to create files in '
                    'this directory.'))
                return

        on_continue(0, file_path)
示例#19
0
 def on_nick_entry_changed(self, widget):
     if self.ignore_events:
         return
     (model, iter_) = self.selection.get_selected()
     if iter_:
         nick = self.nick_entry.get_text()
         try:
             nick = helpers.parse_resource(nick)
         except helpers.InvalidFormat:
             ErrorDialog(_('Invalid nickname'),
                         _('Character not allowed'),
                         transient_for=self.window)
             self.nick_entry.set_text(model[iter_][6])
             return True
         model[iter_][6] = nick
示例#20
0
    def show_dialog(self, parent):
        secret_keys = app.connections[self.account].ask_gpg_secrete_keys()
        secret_keys[_('None')] = _('None')

        if not secret_keys:
            ErrorDialog(_('Failed to get secret keys'),
                        _('There is no OpenPGP secret key available.'),
                        transient_for=parent)
            return

        dialog = dialogs.ChooseGPGKeyDialog(_('OpenPGP Key Selection'),
                                            _('Choose your OpenPGP key'),
                                            secret_keys,
                                            self.on_key_selected,
                                            transient_for=parent)
        dialog.window.connect('destroy', self.on_destroy)
示例#21
0
    def __init__(self):
        pixs = []
        for size in (16, 32, 48, 64, 128):
            pix = gtkgui_helpers.get_icon_pixmap('org.gajim.Gajim', size)
            if pix:
                pixs.append(pix)
        if pixs:
            # set the icon to all windows
            Gtk.Window.set_default_icon_list(pixs)

        log_db_path = configpaths.get('LOG_DB')
        if not os.path.exists(log_db_path):
            ErrorDialog(_('Cannot find history logs database'),
                        '%s does not exist.' % log_db_path)
            sys.exit()

        xml = gtkgui_helpers.get_gtk_builder('history_manager.ui')
        self.window = xml.get_object('history_manager_window')
        self.jids_listview = xml.get_object('jids_listview')
        self.logs_listview = xml.get_object('logs_listview')
        self.search_results_listview = xml.get_object('search_results_listview')
        self.search_entry = xml.get_object('search_entry')
        self.logs_scrolledwindow = xml.get_object('logs_scrolledwindow')
        self.search_results_scrolledwindow = xml.get_object(
                'search_results_scrolledwindow')
        self.welcome_vbox = xml.get_object('welcome_vbox')

        self.jids_already_in = []  # holds jids that we already have in DB
        self.AT_LEAST_ONE_DELETION_DONE = False

        self.con = sqlite3.connect(
            log_db_path, timeout=20.0, isolation_level='IMMEDIATE')
        self.con.execute("PRAGMA secure_delete=1")
        self.cur = self.con.cursor()

        self._init_jids_listview()
        self._init_logs_listview()
        self._init_search_results_listview()

        self._fill_jids_listview()

        self.search_entry.grab_focus()

        self.window.show_all()

        xml.connect_signals(self)
示例#22
0
    def _change_date(self, widget):
        # Get day selected in calendar
        y, m, d = self.calendar.get_date()
        py_m = python_month(m)
        _date = datetime.datetime(y, py_m, d)

        if widget is self.button_first_day:
            gtk_m = gtk_month(self.first_day.month)
            self.calendar.select_month(gtk_m, self.first_day.year)
            self.calendar.select_day(self.first_day.day)
            return
        elif widget is self.button_last_day:
            gtk_m = gtk_month(self.last_day.month)
            self.calendar.select_month(gtk_m, self.last_day.year)
            self.calendar.select_day(self.last_day.day)
            return
        elif widget is self.button_previous_day:
            end_date = self.first_day
            timedelta = datetime.timedelta(days=-1)
            if end_date >= _date:
                return
        elif widget is self.button_next_day:
            end_date = self.last_day
            timedelta = datetime.timedelta(days=1)
            if end_date <= _date:
                return

        # Iterate through days until log entry found or
        # supplied end_date (first_log / last_log) reached
        logs = None
        while logs is None:
            _date = _date + timedelta
            if _date == end_date:
                break
            try:
                logs = app.logger.get_date_has_logs(self.account, self.jid,
                                                    _date)
            except exceptions.PysqliteOperationalError as e:
                ErrorDialog(_('Disk Error'), str(e))
                return

        gtk_m = gtk_month(_date.month)
        self.calendar.select_month(gtk_m, _date.year)
        self.calendar.select_day(_date.day)
示例#23
0
        def on_ok(path_to_file):
            sha = app.interface.save_avatar(path_to_file, publish=True)
            if sha is None:
                ErrorDialog(_('Could not load image'), transient_for=self)
                return

            scale = self.get_scale_factor()
            surface = app.interface.get_avatar(sha, AvatarSize.VCARD, scale)

            button = self.xml.get_object('PHOTO_button')
            image = self.xml.get_object('PHOTO_image')
            image.set_from_surface(surface)
            button.show()
            text_button = self.xml.get_object('NOPHOTO_button')
            text_button.hide()

            self.avatar_sha = sha
            publish = app.interface.get_avatar(sha, publish=True)
            self.avatar_encoded = base64.b64encode(publish).decode('utf-8')
            self.avatar_mime_type = 'image/png'
示例#24
0
    def check_valid_bookmark(self):
        """
        Check if all necessary fields are entered correctly
        """
        (model, iter_) = self.selection.get_selected()

        if not model.iter_parent(iter_):
            # Account data can't be changed
            return

        server = self.server_entry.get_text()
        room = self.room_entry.get_text()

        if server == '' or room == '':
            ErrorDialog(
                _('This bookmark has invalid data'),
                _('Please be sure to fill out server and room fields '
                  'or remove this bookmark.'))
            return False

        return True
示例#25
0
 def _nec_gateway_prompt_received(self, obj):
     if self.adding_jid:
         jid, transport, type_ = self.adding_jid
         if obj.stanza.getError():
             ErrorDialog(
                 _('Error while adding transport contact'),
                 _('This error occured while adding a contact for transport '
                   '%(transport)s:\n\n%(error)s') % {
                       'transport': transport,
                       'error': obj.stanza.getErrorMsg()
                   })
             return
         if obj.prompt_jid:
             self._add_jid(obj.prompt_jid, type_)
         else:
             jid = jid.replace('@', '%') + '@' + transport
             self._add_jid(jid, type_)
     elif obj.jid in self.gateway_prompt:
         if obj.desc:
             self.gateway_prompt[obj.jid]['desc'] = obj.desc
         if obj.prompt:
             self.gateway_prompt[obj.jid]['prompt'] = obj.prompt
示例#26
0
    def _disco_info_received(self, from_, identities, features, data, node):
        if nbxmpp.NS_MUC not in features:
            ErrorDialog(_('Wrong server'),
                        _('%s is not a groupchat server') % from_,
                        transient_for=self)
            return

        jid = str(from_)
        if jid in app.interface.instances[self.account]['disco']:
            app.interface.instances[self.account]['disco'][jid].window.\
                present()
        else:
            try:
                # Object will add itself to the window dict
                from gajim.disco import ServiceDiscoveryWindow
                ServiceDiscoveryWindow(self.account,
                                       jid,
                                       initial_identities=[{
                                           'category': 'conference',
                                           'type': 'text'
                                       }])
            except GajimGeneralException:
                pass
示例#27
0
    def on_forward_button_clicked(self, widget):
        cur_page = self.notebook.get_current_page()

        if cur_page == 0:
            widget = self.xml.get_object('use_existing_account_radiobutton')
            if widget.get_active():
                self.modify = True
                self.notebook.set_current_page(1)
            else:
                self.modify = False
                self.notebook.set_current_page(2)
            self.back_button.set_sensitive(True)
            return

        elif cur_page == 1:
            # We are adding an existing account
            anonymous = self.xml.get_object('anonymous_checkbutton1').\
                get_active()
            username = self.xml.get_object('username_entry').get_text().strip()
            if not username and not anonymous:
                pritext = _('Invalid username')
                sectext = _(
                    'You must provide a username to configure this account.')
                ErrorDialog(pritext, sectext)
                return
            server = self.xml.get_object('server_comboboxtext_entry').\
                get_text().strip()
            savepass = self.xml.get_object('save_password_checkbutton').\
                get_active()
            password = self.xml.get_object('password_entry').get_text()

            if anonymous:
                jid = ''
            else:
                jid = username + '@'
            jid += server
            # check if jid is conform to RFC and stringprep it
            try:
                jid = helpers.parse_jid(jid)
            except helpers.InvalidFormat as s:
                pritext = _('Invalid JID')
                ErrorDialog(pritext, str(s))
                return

            self.account = server
            i = 1
            while self.account in app.config.get_per('accounts'):
                self.account = server + str(i)
                i += 1

            username, server = app.get_name_and_server_from_jid(jid)
            if self.xml.get_object('anonymous_checkbutton1').get_active():
                self.save_account('', server, False, '', anonymous=True)
            else:
                self.save_account(username, server, savepass, password)
            self.show_finish_page()
        elif cur_page == 2:
            # We are creating a new account
            server = self.xml.get_object('server_comboboxtext_entry1').\
                get_text()

            if not server:
                ErrorDialog(
                    _('Invalid server'),
                    _('Please provide a server on which you want to register.')
                )
                return
            self.account = server
            i = 1
            while self.account in app.config.get_per('accounts'):
                self.account = server + str(i)
                i += 1

            config = self.get_config('', server, '', '')
            # Get advanced options
            proxies_combobox = self.xml.get_object('proxies_combobox')
            active = proxies_combobox.get_active()
            proxy = proxies_combobox.get_model()[active][0]
            if proxy == _('None'):
                proxy = ''
            config['proxy'] = proxy

            config['use_custom_host'] = self.xml.get_object(
                'custom_host_port_checkbutton').get_active()
            custom_port = self.xml.get_object('custom_port_entry').get_text()
            try:
                custom_port = int(custom_port)
            except Exception:
                ErrorDialog(_('Invalid entry'),
                            _('Custom port must be a port number.'))
                return
            config['custom_port'] = custom_port
            config['custom_host'] = self.xml.get_object(
                'custom_host_entry').get_text()

            if self.xml.get_object('anonymous_checkbutton2').get_active():
                self.modify = True
                self.save_account('', server, False, '', anonymous=True)
                self.show_finish_page()
            else:
                self.notebook.set_current_page(5)  # show creating page
                self.back_button.hide()
                self.forward_button.hide()
                self.update_progressbar_timeout_id = GLib.timeout_add(
                    100, self.update_progressbar)
                # Get form from serveur
                con = connection.Connection(self.account)
                app.connections[self.account] = con
                con.new_account(self.account, config)
        elif cur_page == 3:
            checked = self.xml.get_object('ssl_checkbutton').get_active()
            if checked:
                hostname = app.connections[
                    self.account].new_account_info['hostname']
                # Check if cert is already in file
                certs = ''
                my_ca_certs = configpaths.get('MY_CACERTS')
                if os.path.isfile(my_ca_certs):
                    with open(my_ca_certs) as f:
                        certs = f.read()
                if self.ssl_cert in certs:
                    ErrorDialog(
                        _('Certificate Already in File'),
                        _('This certificate is already in file %s, so it\'s '
                          'not added again.') % my_ca_certs)
                else:
                    with open(my_ca_certs, 'a') as f:
                        f.write(hostname + '\n')
                        f.write(self.ssl_cert + '\n\n')
                    app.connections[self.account].new_account_info[
                        'ssl_fingerprint_sha1'] = self.ssl_fingerprint_sha1
                    app.connections[self.account].new_account_info[
                        'ssl_fingerprint_sha256'] = self.ssl_fingerprint_sha256
            self.notebook.set_current_page(4)  # show fom page
        elif cur_page == 4:
            if self.is_form:
                form = self.data_form_widget.data_form
            else:
                form = self.data_form_widget.get_infos()
            app.connections[self.account].send_new_account_infos(
                form, self.is_form)
            self.xml.get_object('form_vbox').remove(self.data_form_widget)
            self.xml.get_object('progressbar_label').set_markup(
                '<b>Account is being created</b>\n\nPlease wait…')
            self.notebook.set_current_page(5)  # show creating page
            self.back_button.hide()
            self.forward_button.hide()
            self.update_progressbar_timeout_id = GLib.timeout_add(
                100, self.update_progressbar)
示例#28
0
    def _add_jid(self, jid, type_):
        # check if jid is conform to RFC and stringprep it
        try:
            jid = helpers.parse_jid(jid)
        except helpers.InvalidFormat as s:
            pritext = _('Invalid User ID')
            ErrorDialog(pritext, str(s))
            return

        # No resource in jid
        if jid.find('/') >= 0:
            pritext = _('Invalid User ID')
            ErrorDialog(pritext, _('The user ID must not contain a resource.'))
            return

        if jid == app.get_jid_from_account(self.account):
            pritext = _('Invalid User ID')
            ErrorDialog(pritext, _('You cannot add yourself to your roster.'))
            return

        if not app.account_is_connected(self.account):
            ErrorDialog(_('Account Offline'),
                        _('Your account must be online to add new contacts.'))
            return

        nickname = self.nickname_entry.get_text() or ''
        # get value of account combobox, if account was not specified
        if not self.account:
            model = self.account_combobox.get_model()
            index = self.account_combobox.get_active()
            self.account = model[index][1]

        # Check if jid is already in roster
        if jid in app.contacts.get_jid_list(self.account):
            c = app.contacts.get_first_contact_from_jid(self.account, jid)
            if _('Not in Roster') not in c.groups and c.sub in ('both', 'to'):
                ErrorDialog(
                    _('Contact already in roster'),
                    _('This contact is already listed in your roster.'))
                return

        if type_ == 'jabber':
            message_buffer = self.message_textview.get_buffer()
            start_iter = message_buffer.get_start_iter()
            end_iter = message_buffer.get_end_iter()
            message = message_buffer.get_text(start_iter, end_iter, True)
            if self.save_message_checkbutton.get_active():
                msg = helpers.to_one_line(message)
                app.config.set_per('accounts', self.account,
                                   'subscription_request_msg', msg)
        else:
            message = ''
        group = self.group_comboboxentry.get_child().get_text()
        groups = []
        if group:
            groups = [group]
        auto_auth = self.auto_authorize_checkbutton.get_active()
        app.interface.roster.req_sub(self,
                                     jid,
                                     message,
                                     self.account,
                                     groups=groups,
                                     nickname=nickname,
                                     auto_auth=auto_auth)
        self.destroy()
示例#29
0
    def _on_join_clicked(self, *args):
        account = self.account_combo.get_active_id()
        nickname = self.nick_entry.get_text()

        invisible_show = app.SHOW_LIST.index('invisible')
        if app.connections[account].connected == invisible_show:
            app.interface.raise_dialog('join-while-invisible')
            return

        server = self.server_combo.get_active_text()
        room = self.room_entry.get_text()

        if room == '':
            ErrorDialog(_('Invalid Room'),
                        _('Please choose a room'),
                        transient_for=self)
            return

        self.room_jid = '%s@%s' % (room, server)
        self.room_jid = self.room_jid.lower()

        if app.in_groupchat(account, self.room_jid):
            # If we already in the groupchat, join_gc_room will bring
            # it to front
            app.interface.join_gc_room(account, self.room_jid, nickname, '')
            self.destroy()
            return

        if nickname == '':
            ErrorDialog(_('Invalid Nickname'),
                        _('Please choose a nickname'),
                        transient_for=self)
            return

        try:
            helpers.parse_resource(nickname)
        except helpers.InvalidFormat as error:
            ErrorDialog(_('Invalid Nickname'), str(error), transient_for=self)
            return

        try:
            helpers.parse_jid(self.room_jid)
        except helpers.InvalidFormat as error:
            ErrorDialog(_('Invalid JID'), str(error), transient_for=self)
            return

        if not app.account_is_connected(account):
            ErrorDialog(
                _('You are not connected to the server'),
                _('You can not join a group chat unless you are connected.'),
                transient_for=self)
            return

        password = self.password_entry.get_text()
        self._add_bookmark(account, nickname, password)
        app.add_recent_groupchat(account, self.room_jid, nickname)

        if self.automatic:
            app.automatic_rooms[self.account][self.room_jid] = self.automatic

        app.interface.join_gc_room(account, self.room_jid, nickname, password)
        self.destroy()
示例#30
0
 def _disco_info_error(self, from_, error):
     ErrorDialog(_('Wrong server'),
                 _('%s is not a groupchat server') % from_,
                 transient_for=self)