-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclamtk-gnome.py
executable file
·87 lines (72 loc) · 2.76 KB
/
clamtk-gnome.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# clamtk, copyright (C) 2004-2024 Dave M, Tord Dellsén
#
# This file is part of clamtk
# Dave M <dave.nerd@gmail.com>
# https://github.com/dave-theunsub/clamtk
# https://github.com/dave-theunsub/clamtk-gnome
#
# 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
import gettext
import gi
gi.require_version("Nautilus", "4.0")
from gi.repository import Nautilus
from gi.repository import GObject
locale.setlocale(locale.LC_ALL, "")
gettext.bindtextdomain("clamtk", "/usr/share/locale")
gettext.textdomain("clamtk")
_ = gettext.gettext
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):
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]