示例#1
0
    def _delete_jid_logs(self, liststore, list_of_paths):
        paths_len = len(list_of_paths)
        if paths_len == 0:  # nothing is selected
            return

        def on_ok(liststore, list_of_paths):
            # delete all rows from db that match jid_id
            list_of_rowrefs = []
            for path in list_of_paths:  # make them treerowrefs (it's needed)
                list_of_rowrefs.append(
                    Gtk.TreeRowReference.new(liststore, path))

            for rowref in list_of_rowrefs:
                path = rowref.get_path()
                if path is None:
                    continue
                jid_id = liststore[path][1]
                del liststore[path]  # remove from UI
                # remove from db
                self.cur.execute(
                    '''
                        DELETE FROM logs
                        WHERE jid_id = ?
                        ''', (jid_id, ))

                # now delete "jid, jid_id" row from jids table
                self.cur.execute(
                    '''
                                DELETE FROM jids
                                WHERE jid_id = ?
                                ''', (jid_id, ))

            self.con.commit()

            self.AT_LEAST_ONE_DELETION_DONE = True

        if paths_len == 1:
            jid_id = '<i>%s</i>' % liststore[list_of_paths[0]][0]
            pri_text = _('Do you wish to delete all correspondence with %(jid)s?') \
                % {'jid': jid_id}
        else:
            pri_text = _(
                'Do you wish to delete all correspondence with the selected contacts?'
            )
        dialog = dialogs.ConfirmationDialog('',
                                            _('This can not be undone.'),
                                            on_response_ok=(on_ok, liststore,
                                                            list_of_paths))
        dialog.set_title(_('Deletion Confirmation'))
        dialog.set_markup(pri_text)
        ok_button = dialog.get_children()[0].get_children()[1].get_children(
        )[0]
        ok_button.grab_focus()
        dialog.set_transient_for(self.window)
示例#2
0
    def on_remove_account(self, button, account):
        if app.events.get_events(account):
            dialogs.ErrorDialog(
                _('Unread events'),
                _('Read all pending events before removing this account.'),
                transient_for=self)
            return

        if app.config.get_per('accounts', account, 'is_zeroconf'):
            # Should never happen as button is insensitive
            return

        win_opened = False
        if app.interface.msg_win_mgr.get_controls(acct=account):
            win_opened = True
        elif account in app.interface.instances:
            for key in app.interface.instances[account]:
                if (app.interface.instances[account][key]
                        and key != 'remove_account'):
                    win_opened = True
                    break

        # Detect if we have opened windows for this account

        def remove(account):
            if (account in app.interface.instances
                    and 'remove_account' in app.interface.instances[account]):
                dialog = app.interface.instances[account]['remove_account']
                dialog.window.present()
            else:
                if account not in app.interface.instances:
                    app.interface.instances[account] = {}
                app.interface.instances[account]['remove_account'] = \
                    config.RemoveAccountWindow(account)

        if win_opened:
            dialogs.ConfirmationDialog(
                _('You have opened chat in account %s') % account,
                _('All chat and groupchat windows will be closed. '
                  'Do you want to continue?'),
                on_response_ok=(remove, account))
        else:
            remove(account)
示例#3
0
    def on_continue(response, file_path):
        if response < 0:
            return

        if isinstance(avatar, str):
            # We got a SHA
            pixbuf = app.interface.get_avatar(avatar)
        else:
            # We got a pixbuf
            pixbuf = avatar
        extension = os.path.splitext(file_path)[1]
        if not extension:
            # Silently save as Jpeg image
            image_format = 'jpeg'
            file_path += '.jpeg'
        elif extension == 'jpg':
            image_format = 'jpeg'
        else:
            image_format = extension[1:]  # remove leading dot

        # Save image
        try:
            pixbuf.savev(file_path, image_format, [], [])
        except Exception as e:
            log.error('Error saving avatar: %s' % str(e))
            if os.path.exists(file_path):
                os.remove(file_path)
            new_file_path = '.'.join(file_path.split('.')[:-1]) + '.jpeg'

            def on_ok(file_path, pixbuf):
                pixbuf.savev(file_path, 'jpeg', [], [])

            dialogs.ConfirmationDialog(
                _('Extension not supported'),
                _('Image cannot be saved in %(type)s format. Save as '
                  '%(new_filename)s?') % {
                      'type': image_format,
                      'new_filename': new_file_path
                  },
                on_response_ok=(on_ok, new_file_path, pixbuf))
        else:
            dialog.destroy()
示例#4
0
    def _delete_logs(self, liststore, list_of_paths):
        paths_len = len(list_of_paths)
        if paths_len == 0:  # nothing is selected
            return

        def on_ok(liststore, list_of_paths):
            # delete rows from db that match log_line_id
            list_of_rowrefs = []
            for path in list_of_paths:  # make them treerowrefs (it's needed)
                list_of_rowrefs.append(
                    Gtk.TreeRowReference.new(liststore, path))

            for rowref in list_of_rowrefs:
                path = rowref.get_path()
                if path is None:
                    continue
                log_line_id = liststore[path][0]
                del liststore[path]  # remove from UI
                # remove from db
                self.cur.execute(
                    '''
                        DELETE FROM logs
                        WHERE log_line_id = ?
                        ''', (log_line_id, ))

            self.con.commit()

            self.AT_LEAST_ONE_DELETION_DONE = True

        pri_text = i18n.ngettext(
            'Do you really want to delete the selected message?',
            'Do you really want to delete the selected messages?', paths_len)
        dialog = dialogs.ConfirmationDialog(
            pri_text,
            _('This is an irreversible operation.'),
            on_response_ok=(on_ok, liststore, list_of_paths))
        dialog.set_title(_('Deletion Confirmation'))
        ok_button = dialog.get_children()[0].get_children()[1].get_children(
        )[0]
        ok_button.grab_focus()
        dialog.set_transient_for(self.window)