Ejemplo n.º 1
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(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)
        dialogs.ConfirmationDialog(pri_text,
                                   _('This is an irreversible operation.'),
                                   on_response_ok=(on_ok, liststore,
                                                   list_of_paths))
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def on_continue(response, file_path):
        if response < 0:
            return
        # Get pixbuf
        pixbuf = None
        is_fake = False
        if account and gajim.contacts.is_pm_from_jid(account, jid):
            is_fake = True
        pixbuf = get_avatar_pixbuf_from_cache(jid, is_fake, False)
        ext = file_path.split('.')[-1]
        type_ = ''
        if not ext:
            # Silently save as Jpeg image
            file_path += '.jpeg'
            type_ = 'jpeg'
        elif ext == 'jpg':
            type_ = 'jpeg'
        else:
            type_ = ext

        # Save image
        try:
            pixbuf.save(file_path, type_)
        except:
            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.save(file_path, 'jpeg')

            dialogs.ConfirmationDialog(
                _('Extension not supported'),
                _('Image cannot be saved in %(type)s format. Save as %(new_filename)s?'
                  ) % {
                      'type': type_,
                      'new_filename': new_file_path
                  },
                on_response_ok=(on_ok, new_file_path, pixbuf))
        else:
            dialog.destroy()
Ejemplo n.º 4
0
    def on_continue(response, file_path):
        if response < 0:
            return
        pixbuf = get_avatar_pixbuf_from_cache(jid)
        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.debug('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()