forked from Dragoncraft89/nautilus-kdeconnect
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a4c24f7
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
all: | ||
mkdir -p ~/.local/share/nautilus-python/extensions && cp *.py ~/.local/share/nautilus-python/extensions | ||
echo "Done. Please restart Nautilus." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from gi.repository import Nautilus, GObject | ||
from kdeconnect import send_files, get_available_devices | ||
|
||
class KDEConnectExtension(GObject.GObject, Nautilus.MenuProvider): | ||
def __init__(self): | ||
pass | ||
|
||
def menu_activate_cb(self, menu, files, device_id, device_name): | ||
send_files(files, device_id, device_name) | ||
|
||
def get_file_items(self, window, files): | ||
try: | ||
devices = get_available_devices() | ||
except Exception as e: | ||
raise Exception("Failed to get available devices") | ||
|
||
files_new = [] | ||
for i in range(len(files)): | ||
if (files[i].is_directory() == False): | ||
files_new.append(files[i]) | ||
files = files_new | ||
|
||
if (len(files_new) < 1): | ||
return [] | ||
|
||
items=[] | ||
for device in devices: | ||
item = Nautilus.MenuItem( | ||
name="KDEConnectExtension::Send_File", | ||
label="Send to %s" % device["name"] | ||
) | ||
item.connect('activate', self.menu_activate_cb, files, device["id"], device["name"]) | ||
items.append(item) | ||
|
||
return items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from subprocess import check_output, call | ||
import re | ||
|
||
def send_files(files, device_id, device_name): | ||
# results=[] | ||
# failed=0 | ||
for file in files: | ||
print "filename", file.get_uri() | ||
return_code=call(["kdeconnect-cli", "-d", device_id, "--share", file.get_uri()]) | ||
# if (return_code != 0): | ||
# failed += 1 | ||
# results.append(return_code) | ||
call(["notify-send", "Sending {num_files} file(s) to {device_name}. Check your device.".format(num_files=len(files), device_name=device_name)]) | ||
# return results | ||
|
||
def get_available_devices(): | ||
# return [ {"name": "Xperia Z", "id": "stuff"} ] | ||
devices_a=[] | ||
devices = check_output(["kdeconnect-cli", "-a"]).strip().split("\n") | ||
devices.pop() | ||
for device in devices: | ||
device_name=re.search("(?<=-\s).+(?=:\s)", device).group(0) | ||
device_id=re.search("(?<=:\s)[a-z0-9]+(?=\s\()", device).group(0).strip() | ||
devices_a.append({ "name": device_name, "id": device_id }) | ||
return devices_a |