Commit 0d1fe255 authored by jvoisin's avatar jvoisin

Clean up a bit the nautilus-extensio code

parent 4b56ff25
......@@ -25,53 +25,52 @@ import libmat.strippers
class MatExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
logging.debug("nautilus-mat: initialising")
pass
def get_file_items(self, window, files):
if len(files) != 1: # no multi-files support
return
file = files.pop()
current_file = files.pop()
# We're only going to put ourselves on supported mimetypes' context menus
if not (file.get_mime_type()
if not (current_file.get_mime_type()
in [i["mimetype"] for i in libmat.mat.list_supported_formats()]):
logging.debug("%s is not supported by MAT", file.get_mime_type())
logging.debug("%s is not supported by MAT", current_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())
if current_file.get_uri_scheme() != 'file':
logging.debug("%s files not supported by MAT", current_file.get_uri_scheme())
return
# MAT can not clean non-writable files
if not file.can_write():
logging.debug("%s is not writable by MAT", file.get_uri_scheme())
if not current_file.can_write():
logging.debug("%s is not writable by MAT", current_file.get_uri_scheme())
return
item = Nautilus.MenuItem(name="Nautilus::clean_metadata",
label=_("Clean metadata"),
tip=_("Clean file's metadata with MAT"),
icon="gtk-clear")
item.connect('activate', self.menu_activate_cb, file)
item.connect('activate', self.menu_activate_cb, current_file)
return item,
@staticmethod
def show_message(message, type=Gtk.MessageType.INFO):
def show_message(message, msg_type=Gtk.MessageType.INFO):
dialog = Gtk.MessageDialog(parent=None,
flags=Gtk.DialogFlags.MODAL,
type=type,
type=msg_type,
buttons=Gtk.ButtonsType.OK,
message_format=message)
ret = dialog.run()
dialog.destroy()
return ret
def menu_activate_cb(self, menu, file):
def menu_activate_cb(self, menu, current_file):
if file.is_gone():
return
file_path = urllib.unquote(file.get_uri()[7:])
file_path = urllib.unquote(current_file.get_uri()[7:])
class_file = libmat.mat.create_class_file(file_path,
backup=True,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment