コード例 #1
0
def cleaner_change_dialog(changes, parent):
    """Present a dialog regarding the change of cleaner definitions"""
    def toggled(cell, path, model):
        """Callback for clicking the checkbox"""
        __iter = model.get_iter_from_string(path)
        value = not model.get_value(__iter, 0)
        model.set(__iter, 0, value)

    # TODO: move to GuiBasic
    from bleachbit.GuiBasic import Gtk
    from gi.repository import GObject

    dialog = Gtk.Dialog(title=_("Security warning"),
                        transient_for=parent,
                        modal=True,
                        destroy_with_parent=True)
    dialog.set_default_size(600, 500)

    # create warning
    warnbox = Gtk.Box()
    image = Gtk.Image()
    image.set_from_icon_name("dialog-warning", Gtk.IconSize.DIALOG)
    warnbox.pack_start(image, False, True, 0)

    # TRANSLATORS: Cleaner definitions are XML data files that define
    # which files will be cleaned.
    label = Gtk.Label(label=_(
        "These cleaner definitions are new or have changed. Malicious definitions can damage your system. If you do not trust these changes, delete the files or quit."
    ))
    label.set_line_wrap(True)
    warnbox.pack_start(label, True, True, 0)
    dialog.vbox.pack_start(warnbox, False, True, 0)

    # create tree view
    liststore = Gtk.ListStore(GObject.TYPE_BOOLEAN, GObject.TYPE_STRING)
    treeview = Gtk.TreeView(model=liststore)

    renderer0 = Gtk.CellRendererToggle()
    renderer0.set_property('activatable', True)
    renderer0.connect('toggled', toggled, liststore)
    # TRANSLATORS: This is the column label (header) in the tree view for the
    # security dialog
    treeview.append_column(
        Gtk.TreeViewColumn(_p('column_label', 'Delete'), renderer0, active=0))
    renderer1 = Gtk.CellRendererText()
    # TRANSLATORS: This is the column label (header) in the tree view for the
    # security dialog
    treeview.append_column(
        Gtk.TreeViewColumn(_p('column_label', 'Filename'), renderer1, text=1))

    # populate tree view
    for change in changes:
        liststore.append([False, change[0]])

    # populate dialog with widgets
    scrolled_window = Gtk.ScrolledWindow()
    scrolled_window.add(treeview)
    dialog.vbox.pack_start(scrolled_window, True, True, 0)

    dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
    dialog.add_button(Gtk.STOCK_QUIT, Gtk.ResponseType.CLOSE)

    # run dialog
    dialog.show_all()
    while True:
        if Gtk.ResponseType.ACCEPT != dialog.run():
            sys.exit(0)
        delete = []
        for row in liststore:
            b = row[0]
            path = row[1]
            if b:
                delete.append(path)
        if 0 == len(delete):
            # no files selected to delete
            break
        import GuiBasic
        if not GuiBasic.delete_confirmation_dialog(parent,
                                                   mention_preview=False):
            # confirmation not accepted, so do not delete files
            continue
        for path in delete:
            logger.info("deleting unrecognized CleanerML '%s'", path)
            os.remove(path)
        break
    dialog.destroy()
コード例 #2
0
ファイル: Cleaner.py プロジェクト: hrukalive/bleachbit
 def gtk_purge_items():
     """Purge GTK items"""
     Gtk.RecentManager().purge_items()
     yield 0