1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# ClamTk, copyright (C) 2004-2020 Dave M, Tord Dellsén
#
# This file is part of ClamTk
# (https://gitlab.com/dave_m/clamtk/wikis/Home)
#
# ClamTk is free software; you can redistribute it and/or modify it
# under the terms of either:
#
# a) the GNU General Public License as published by the Free Software
# Foundation; either version 1, or (at your option) any later version, or
#
# b) the "Artistic License".
import locale
import subprocess
locale.setlocale(locale.LC_ALL, "")
import gettext
gettext.bindtextdomain("clamtk", "/usr/share/locale")
gettext.textdomain("clamtk")
_ = gettext.gettext
import gi
from gi.repository import Nautilus
from gi.repository import GObject
class OpenTerminalExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
print("Initializing clamtk-gnome")
def _open_scanner(self, file):
filename = file.get_location().get_path()
# - file is of type nautiuls-vsf-file
# https://github.com/GNOME/nautilus/blob/master/src/nautilus-file.h
# which inherits from nautilus-file
# https://github.com/GNOME/nautilus/blob/master/src/nautilus-vfs-file.h
# - get_location returns a GFile
# https://developer.gnome.org/gio/stable/GFile.html
# which has the get_path function which returns the absolute path as a string
cmd = ["clamtk", filename]
subprocess.Popen(cmd)
def menu_activate_cb(self, menu, file):
self._open_scanner(file)
def menu_background_activate_cb(self, menu, file):
self._open_scanner(file)
def get_file_items(self, *args):
# `args` will be `[files: List[Nautilus.FileInfo]]` in Nautilus 4.0 API,
# and `[window: Gtk.Widget, files: List[Nautilus.FileInfo]]` in Nautilus 3.0 API.
files = args[-1]
if len(files) != 1:
return
file = files[0]
item = Nautilus.MenuItem(
name="NautilusPython::openscanner",
label=_("Scan for threats..."),
tip=_("Scan for threats..."),
icon="clamtk",
)
# - the tooltips are not shown any longer in Nautilus
# (the code is kept here in case this changes again for Nautilus)
item.connect("activate", self.menu_activate_cb, file)
return [item]
def get_background_items(self, *args):
file = args[-1]
item = Nautilus.MenuItem(
name="NautilusPython::openscanner_directory",
label=_("Scan directory for threats..."),
tip=_("Scan this directory for threats..."),
icon="clamtk",
)
# - the tooltips are not shown any longer in Nautilus
# (the code is kept here in case this changes again for Nautilus
item.connect("activate", self.menu_background_activate_cb, file)
return [item]
|