Added a simple nautilus extension, written by the Subgraph developers (fixes #293)

This commit is contained in:
Micah Lee 2016-06-10 17:56:34 -07:00
parent 900276a524
commit 57dd6db166
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
3 changed files with 49 additions and 1 deletions

View File

@ -8,3 +8,4 @@ include resources/html/*
include install/onionshare.desktop
include install/onionshare.appdata.xml
include install/onionshare80.xpm
include install/scripts/onionshare-nautilus.py

View File

@ -0,0 +1,46 @@
#!/usr/bin/env python
import os
import subprocess
import urllib
import gi
gi.require_version('Nautilus', '3.0')
from gi.repository import Nautilus
from gi.repository import GObject
# Put me in /usr/share/nautilus-python/extensions/
class OnionShareExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
pass
def url2path(self,url):
file_uri = url.get_activation_uri()
arg_uri = file_uri[7:]
path = urllib.url2pathname(arg_uri)
return path
def exec_onionshare(self, filenames):
# Would prefer this method but there is a conflict between GTK 2.0 vs GTK 3.0 components being loaded at once
# (nautilus:3090): Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
# sys.argv = ["", "--filenames"] + filenames
# sys.exit(onionshare_gui.main())
path = os.path.join(os.sep, 'usr', 'bin', 'onionshare-gui')
cmd = [path, "--filenames"] + filenames
subprocess.Popen(cmd)
def get_file_items(self, window, files):
menuitem = Nautilus.MenuItem(name='OnionShare::Nautilus',
label='Share via OnionShare',
tip='',
icon='')
menu = Nautilus.Menu()
menu.append_item(menuitem)
menuitem.connect("activate", self.menu_activate_cb, files)
return menuitem,
def menu_activate_cb(self, menu, files):
file_list = []
for file in files:
file_list.append(self.url2path(file))
self.exec_onionshare(file_list)

View File

@ -100,6 +100,7 @@ setup(
]),
(os.path.join(sys.prefix, 'share/onionshare/images'), images),
(os.path.join(sys.prefix, 'share/onionshare/locale'), locale),
(os.path.join(sys.prefix, 'share/onionshare/html'), html)
(os.path.join(sys.prefix, 'share/onionshare/html'), html),
('/usr/share/nautilus-python/extensions/', ['install/scripts/onionshare-nautilus.py']),
]
)