-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendToBluetooth.py
executable file
·76 lines (58 loc) · 2.24 KB
/
SendToBluetooth.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
#!/usr/bin/env python3
import os, subprocess
from urllib.parse import unquote, urlparse
from gi.repository import GObject, Nautilus
import dbus
def uri_to_path(file):
p = urlparse(file.get_activation_uri())
return os.path.abspath(os.path.join(p.netloc, unquote(p.path)))
class SendToBluetoothExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
GObject.Object.__init__(self)
def send_action(self, menu, files, properties):
paths = []
for file in files:
paths.append(uri_to_path(file))
subprocess.Popen(["/usr/bin/bluetooth-sendto"] + ['--device='+ properties] + paths)
def get_file_items(self, *args):
files = args[-1]
if len(files) < 1:
return
for file in files:
if file.is_directory():
return
listdevice = []
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
"org.freedesktop.DBus.ObjectManager")
objects = manager.GetManagedObjects()
all_devices = (str(path) for path, interfaces in objects.items() if
"org.bluez.Device1" in interfaces.keys())
for path, interfaces in objects.items():
if "org.bluez.Adapter1" not in interfaces.keys():
continue
device_list = [d for d in all_devices if d.startswith(path + "/")]
for dev_path in device_list:
btdevice = []
devp = objects[dev_path]["org.bluez.Device1"]
btdevice.append (devp["Alias"])
btdevice.append (devp["Address"])
listdevice.append (btdevice)
if len (listdevice) < 1:
return
submenu = Nautilus.Menu()
item = Nautilus.MenuItem(
name="SendToBluetooth::MenuItem",
label="Send to bluetooth device",
tip="Send to bluetooth device",
)
item.set_submenu(submenu)
for btmenu in listdevice:
item_two = Nautilus.MenuItem(
name=btmenu[1] + "::MenuItem",
label=btmenu[0],
tip=btmenu[1],
)
submenu.append_item(item_two)
item_two.connect("activate", self.send_action, files, btmenu[1])
return [item]