diff options
Diffstat (limited to 'nautilus/nautilus-mat.py')
| -rw-r--r-- | nautilus/nautilus-mat.py | 76 |
1 files changed, 76 insertions, 0 deletions
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 @@ | |||
| 1 | #! /usr/bin/python | ||
| 2 | |||
| 3 | import os | ||
| 4 | import urllib | ||
| 5 | import logging | ||
| 6 | try: | ||
| 7 | import gettext | ||
| 8 | gettext.install("mat") | ||
| 9 | except: | ||
| 10 | logging.warning("Failed to initialize gettext") | ||
| 11 | _ = lambda x: x | ||
| 12 | |||
| 13 | import xml.sax | ||
| 14 | |||
| 15 | from gi.repository import Nautilus, GObject, Gtk | ||
| 16 | |||
| 17 | import MAT.mat | ||
| 18 | import MAT.strippers | ||
| 19 | |||
| 20 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): | ||
| 21 | def __init__(self): | ||
| 22 | logging.debug("nautilus-mat: initializing") | ||
| 23 | pass | ||
| 24 | |||
| 25 | def get_file_items(self, window, files): | ||
| 26 | if len(files) != 1: | ||
| 27 | return | ||
| 28 | |||
| 29 | file = files[0] | ||
| 30 | |||
| 31 | # We're only going to put ourselves on supported mimetypes' context menus | ||
| 32 | if not (file.get_mime_type() | ||
| 33 | in [i["mimetype"] for i in MAT.mat.list_supported_formats()]): | ||
| 34 | logging.debug("%s is not supported by MAT" % file.get_mime_type()) | ||
| 35 | return | ||
| 36 | |||
| 37 | # MAT can only handle local file: | ||
| 38 | if file.get_uri_scheme() != 'file': | ||
| 39 | logging.debug("%s files not supported by MAT" % file.get_uri_scheme()) | ||
| 40 | return | ||
| 41 | |||
| 42 | item = Nautilus.MenuItem(name="Nautilus::clean_metadata", | ||
| 43 | label=_("Clean metadata"), | ||
| 44 | tip=_("Clean file's metadata with MAT")) | ||
| 45 | item.connect('activate', self.menu_activate_cb, file) | ||
| 46 | return item, | ||
| 47 | |||
| 48 | def show_message(self, message, type = Gtk.MessageType.INFO): | ||
| 49 | dialog = Gtk.MessageDialog(parent=None, | ||
| 50 | flags=Gtk.DialogFlags.MODAL, | ||
| 51 | type=type, | ||
| 52 | buttons=Gtk.ButtonsType.OK, | ||
| 53 | message_format=message) | ||
| 54 | ret = dialog.run() | ||
| 55 | dialog.destroy() | ||
| 56 | return ret | ||
| 57 | |||
| 58 | def menu_activate_cb(self, menu, file): | ||
| 59 | if file.is_gone(): | ||
| 60 | return | ||
| 61 | |||
| 62 | file_path = urllib.unquote(file.get_uri()[7:]) | ||
| 63 | |||
| 64 | class_file = MAT.mat.create_class_file(file_path, | ||
| 65 | backup=True, | ||
| 66 | add2archive=False) | ||
| 67 | if class_file: | ||
| 68 | if class_file.is_clean(): | ||
| 69 | self.show_message(_("%s is already clean") % file_path) | ||
| 70 | else: | ||
| 71 | if not class_file.remove_all(): | ||
| 72 | self.show_message(_("Unable to clean %s") % file_path, Gtk.MessageType.ERROR) | ||
| 73 | else: | ||
| 74 | self.show_message(_("Unable to process %s") % file_path, Gtk.MessageType.ERROR) | ||
| 75 | |||
| 76 | |||
