From 5c0ad58374a4250f25ef9d9608d37116a1376f74 Mon Sep 17 00:00:00 2001 From: Tails developers Date: Sat, 13 Jul 2013 10:41:14 +0000 Subject: Add nautilus extension --- nautilus/nautilus-mat.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 1 + 2 files changed, 77 insertions(+) create mode 100644 nautilus/nautilus-mat.py diff --git a/nautilus/nautilus-mat.py b/nautilus/nautilus-mat.py new file mode 100644 index 0000000..69f8157 --- /dev/null +++ b/nautilus/nautilus-mat.py @@ -0,0 +1,76 @@ +#! /usr/bin/python + +import os +import urllib +import logging +try: + import gettext + gettext.install("mat") +except: + logging.warning("Failed to initialize gettext") + _ = lambda x: x + +import xml.sax + +from gi.repository import Nautilus, GObject, Gtk + +import MAT.mat +import MAT.strippers + +class MatExtension(GObject.GObject, Nautilus.MenuProvider): + def __init__(self): + logging.debug("nautilus-mat: initializing") + pass + + def get_file_items(self, window, files): + if len(files) != 1: + return + + file = files[0] + + # We're only going to put ourselves on supported mimetypes' context menus + if not (file.get_mime_type() + in [i["mimetype"] for i in MAT.mat.list_supported_formats()]): + logging.debug("%s is not supported by MAT" % file.get_mime_type()) + return + + # MAT can only handle local file: + if file.get_uri_scheme() != 'file': + logging.debug("%s files not supported by MAT" % file.get_uri_scheme()) + return + + item = Nautilus.MenuItem(name="Nautilus::clean_metadata", + label=_("Clean metadata"), + tip=_("Clean file's metadata with MAT")) + item.connect('activate', self.menu_activate_cb, file) + return item, + + def show_message(self, message, type = Gtk.MessageType.INFO): + dialog = Gtk.MessageDialog(parent=None, + flags=Gtk.DialogFlags.MODAL, + type=type, + buttons=Gtk.ButtonsType.OK, + message_format=message) + ret = dialog.run() + dialog.destroy() + return ret + + def menu_activate_cb(self, menu, file): + if file.is_gone(): + return + + file_path = urllib.unquote(file.get_uri()[7:]) + + class_file = MAT.mat.create_class_file(file_path, + backup=True, + add2archive=False) + if class_file: + if class_file.is_clean(): + self.show_message(_("%s is already clean") % file_path) + else: + if not class_file.remove_all(): + self.show_message(_("Unable to clean %s") % file_path, Gtk.MessageType.ERROR) + else: + self.show_message(_("Unable to process %s") % file_path, Gtk.MessageType.ERROR) + + diff --git a/setup.py b/setup.py index 2faa570..b40a22e 100755 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ setup( ( 'share/pixmaps', ['data/mat.png'] ), ( 'share/doc/mat', ['README', 'TODO'] ), ( 'share/man/man1', ['mat.1', 'mat-gui.1'] ), + ( 'share/nautilus-python/extensions', ['nautilus/nautilus-mat.py']) ], cmdclass = { 'build': build_extra.build_extra, -- cgit v1.3