diff options
| author | jvoisin | 2015-11-25 19:41:58 +0100 |
|---|---|---|
| committer | jvoisin | 2015-11-26 15:47:30 +0100 |
| commit | 0d1fe2555e90db35eeb531a1b6026ff64f1f5ae5 (patch) | |
| tree | 2a67131f0a9273cf11ba87c3782a947ffa10c6dd /nautilus/nautilus-mat.py | |
| parent | 4b56ff254ab45025de76c7a84e6a147691743afa (diff) | |
Clean up a bit the nautilus-extensio code
Diffstat (limited to 'nautilus/nautilus-mat.py')
| -rw-r--r-- | nautilus/nautilus-mat.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/nautilus/nautilus-mat.py b/nautilus/nautilus-mat.py index cdce947..c1f25df 100644 --- a/nautilus/nautilus-mat.py +++ b/nautilus/nautilus-mat.py | |||
| @@ -25,53 +25,52 @@ import libmat.strippers | |||
| 25 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): | 25 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): |
| 26 | def __init__(self): | 26 | def __init__(self): |
| 27 | logging.debug("nautilus-mat: initialising") | 27 | logging.debug("nautilus-mat: initialising") |
| 28 | pass | ||
| 29 | 28 | ||
| 30 | def get_file_items(self, window, files): | 29 | def get_file_items(self, window, files): |
| 31 | if len(files) != 1: # no multi-files support | 30 | if len(files) != 1: # no multi-files support |
| 32 | return | 31 | return |
| 33 | 32 | ||
| 34 | file = files.pop() | 33 | current_file = files.pop() |
| 35 | 34 | ||
| 36 | # We're only going to put ourselves on supported mimetypes' context menus | 35 | # We're only going to put ourselves on supported mimetypes' context menus |
| 37 | if not (file.get_mime_type() | 36 | if not (current_file.get_mime_type() |
| 38 | in [i["mimetype"] for i in libmat.mat.list_supported_formats()]): | 37 | in [i["mimetype"] for i in libmat.mat.list_supported_formats()]): |
| 39 | logging.debug("%s is not supported by MAT", file.get_mime_type()) | 38 | logging.debug("%s is not supported by MAT", current_file.get_mime_type()) |
| 40 | return | 39 | return |
| 41 | 40 | ||
| 42 | # MAT can only handle local file: | 41 | # MAT can only handle local file: |
| 43 | if file.get_uri_scheme() != 'file': | 42 | if current_file.get_uri_scheme() != 'file': |
| 44 | logging.debug("%s files not supported by MAT", file.get_uri_scheme()) | 43 | logging.debug("%s files not supported by MAT", current_file.get_uri_scheme()) |
| 45 | return | 44 | return |
| 46 | 45 | ||
| 47 | # MAT can not clean non-writable files | 46 | # MAT can not clean non-writable files |
| 48 | if not file.can_write(): | 47 | if not current_file.can_write(): |
| 49 | logging.debug("%s is not writable by MAT", file.get_uri_scheme()) | 48 | logging.debug("%s is not writable by MAT", current_file.get_uri_scheme()) |
| 50 | return | 49 | return |
| 51 | 50 | ||
| 52 | item = Nautilus.MenuItem(name="Nautilus::clean_metadata", | 51 | item = Nautilus.MenuItem(name="Nautilus::clean_metadata", |
| 53 | label=_("Clean metadata"), | 52 | label=_("Clean metadata"), |
| 54 | tip=_("Clean file's metadata with MAT"), | 53 | tip=_("Clean file's metadata with MAT"), |
| 55 | icon="gtk-clear") | 54 | icon="gtk-clear") |
| 56 | item.connect('activate', self.menu_activate_cb, file) | 55 | item.connect('activate', self.menu_activate_cb, current_file) |
| 57 | return item, | 56 | return item, |
| 58 | 57 | ||
| 59 | @staticmethod | 58 | @staticmethod |
| 60 | def show_message(message, type=Gtk.MessageType.INFO): | 59 | def show_message(message, msg_type=Gtk.MessageType.INFO): |
| 61 | dialog = Gtk.MessageDialog(parent=None, | 60 | dialog = Gtk.MessageDialog(parent=None, |
| 62 | flags=Gtk.DialogFlags.MODAL, | 61 | flags=Gtk.DialogFlags.MODAL, |
| 63 | type=type, | 62 | type=msg_type, |
| 64 | buttons=Gtk.ButtonsType.OK, | 63 | buttons=Gtk.ButtonsType.OK, |
| 65 | message_format=message) | 64 | message_format=message) |
| 66 | ret = dialog.run() | 65 | ret = dialog.run() |
| 67 | dialog.destroy() | 66 | dialog.destroy() |
| 68 | return ret | 67 | return ret |
| 69 | 68 | ||
| 70 | def menu_activate_cb(self, menu, file): | 69 | def menu_activate_cb(self, menu, current_file): |
| 71 | if file.is_gone(): | 70 | if file.is_gone(): |
| 72 | return | 71 | return |
| 73 | 72 | ||
| 74 | file_path = urllib.unquote(file.get_uri()[7:]) | 73 | file_path = urllib.unquote(current_file.get_uri()[7:]) |
| 75 | 74 | ||
| 76 | class_file = libmat.mat.create_class_file(file_path, | 75 | class_file = libmat.mat.create_class_file(file_path, |
| 77 | backup=True, | 76 | backup=True, |
