-
Notifications
You must be signed in to change notification settings - Fork 0
/
clamtk-mate.py
executable file
·79 lines (64 loc) · 2.62 KB
/
clamtk-mate.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
#!/usr/bin/python
# clamtk-mate version 0.02.01
#
# ClamTk, copyright (C) 2004-2017 Dave M
# clamtk-mate, copyright (C) 2017-2018 Joel Barrios
#
# This file was part of ClamTk (https://dave-theunsub.github.io/clamtk/).
#
# 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 os
import pipes
import locale
locale.setlocale(locale.LC_ALL, '')
import gettext
_ = lambda x: gettext.ldgettext("clamtk-mate", x)
from gi.repository import Caja, GObject
class OpenTerminalExtension(GObject.GObject, Caja.MenuProvider):
def __init__(self):
print("Initializing clamtk-mate")
def _open_scanner(self, file):
filename = file.get_location().get_path()
#- file is of type caja-vsf-file
# https://github.com/GNOME/nautilus/blob/master/src/nautilus-file.h
# which inherits from caja-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
filename = pipes.quote(filename)
# - when switching to Python 3 we can use shlex.quote() instead
os.system('clamtk %s &' % filename)
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, window, files):
if len(files) != 1:
return
file = files[0]
item = Caja.MenuItem(
name='CajaPython::openscanner',
label=_('Scan for threats...') ,
tip=_('Scan %s for threats...') % file.get_name(),
icon='clamtk')
# - the tooltips are not shown any longer in Caja
# (the code is kept here in case this changes again for Caja
item.connect('activate', self.menu_activate_cb, file)
return [item]
def get_background_items(self, window, file):
item = Caja.MenuItem(
name='CajaPython::openscanner_directory',
label=_('Scan directory for threats...'),
tip=_('Scan this directory for threats...'),
icon='clamtk')
# - the tooltips are not shown any longer in Caja
# (the code is kept here in case this changes again for Caja
item.connect('activate', self.menu_background_activate_cb, file)
return [item]