├── .gitignore ├── screenshot.png ├── kdeconnect.py ├── Makefile ├── kdeconnect-ext.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forabi/nautilus-kdeconnect/HEAD/screenshot.png -------------------------------------------------------------------------------- /kdeconnect.py: -------------------------------------------------------------------------------- 1 | from subprocess import check_output, call 2 | import re 3 | 4 | def send_files(files, device_id, device_name): 5 | for file in files: 6 | return_code=call(["kdeconnect-cli", "-d", device_id, "--share", file.get_uri()]) 7 | 8 | def get_available_devices(): 9 | devices_a=[] 10 | devices = check_output(["kdeconnect-cli", "-a"]).decode("utf-8").strip().split("\n") 11 | devices.pop() 12 | print(devices) 13 | for device in devices: 14 | device_name=re.search("(?<=-\s).+(?=:\s)", device).group(0) 15 | device_id=re.search("(?<=:\s)[a-z0-9_]+(?=\s\()", device).group(0).strip() 16 | devices_a.append({ "name": device_name, "id": device_id }) 17 | print(devices_a) 18 | return devices_a 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TARGET ?= Nautilus 2 | 3 | # To lower case function 4 | lc = $(shell echo "$1" | tr '[:upper:]' '[:lower:]') 5 | 6 | # File manager extension directory 7 | directory-ext := ${HOME}/.local/share/$(call lc,${TARGET})-python/extensions 8 | directory-build := build 9 | 10 | .PHONY: all 11 | all: build 12 | 13 | # Copy files to build directory and substitute %%TARGET%% for the given target name 14 | .PHONY: build 15 | build: 16 | mkdir -p "${directory-build}" 17 | cp $(wildcard *.py) "${directory-build}/" 18 | sed -i "s/%%TARGET%%/$(call lc,${TARGET})/g" "${directory-build}"/* 19 | 20 | # Copy files from build directory to the target's python extension directory 21 | .PHONY: install 22 | install: build 23 | mkdir -p "${directory-ext}" 24 | cp "${directory-build}"/* "${directory-ext}/" 25 | @echo "Done. Please restart ${TARGET}." 26 | 27 | # Remove build directory 28 | .PHONY: clean 29 | clean: 30 | rm -rf "${directory-build}" 31 | -------------------------------------------------------------------------------- /kdeconnect-ext.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | from subprocess import check_output, call 3 | from gi.repository import GObject 4 | from kdeconnect import send_files, get_available_devices 5 | import zipfile 6 | import urllib 7 | import urlparse 8 | 9 | TARGET = "%%TARGET%%".title() 10 | Nautilus = importlib.import_module("gi.repository.{}".format(TARGET)) 11 | 12 | 13 | class KDEConnectExtension(GObject.GObject, Nautilus.MenuProvider): 14 | def __init__(self): 15 | GObject.Object.__init__(self) 16 | 17 | def zipdir(self, path, ziph): 18 | # ziph is zipfile handle 19 | import os 20 | for root, dirs, files in os.walk(path): 21 | for file in files: 22 | print(dirs + [file]) 23 | ziph.write(os.path.join(root, file), os.path.join(*(dirs + [file]))) 24 | 25 | def menu_activate_cb(self, menu, files, device_id, device_name, folder_list): 26 | import zipfile 27 | import os 28 | for folder_name in folder_list: 29 | zip_name = urllib.url2pathname(urlparse.urlparse(folder_name + '.zip').path) 30 | zipf = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) 31 | self.zipdir(zip_name[:-4] + '/', zipf) 32 | zipf.close() 33 | zipfile = Nautilus.FileInfo.create_for_uri(folder_name + '.zip') 34 | files.append(zipfile) 35 | 36 | send_files(files, device_id, device_name) 37 | 38 | def get_file_items(self, window, files): 39 | try: 40 | devices = get_available_devices() 41 | except Exception as e: 42 | raise Exception("Failed to get available devices") 43 | 44 | files_new = [] 45 | folder_list = [] 46 | for i in range(len(files)): 47 | if (files[i].is_directory() == False): 48 | files_new.append(files[i]) 49 | else: 50 | folder_list.append(files[i].get_uri()) 51 | 52 | files = files_new 53 | print(files) 54 | print(folder_list) 55 | 56 | if (len(files_new) + len(folder_list) < 1): 57 | return [] 58 | 59 | items = [] 60 | for device in devices: 61 | item = Nautilus.MenuItem( 62 | name="KDEConnectExtension::Send_File", 63 | label="Send to %s" % device["name"] 64 | ) 65 | item.connect('activate', self.menu_activate_cb, 66 | files, device["id"], device["name"], folder_list) 67 | items.append(item) 68 | 69 | return items 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nautilus-kdeconnect 2 | ==================== 3 | Nautilus extension for sending files to devices connected via KDE Connect. 4 | 5 | KDE Connect is a service that connects your Android device with your Linux PC via Wi-Fi, enabling many features like shared clipboard, notification syncing, file sharing and media playback control. This extension provides file sharing support in Nautilus via context menu (right-click menu). 6 | 7 | ![Screenshot](./screenshot.png) 8 | 9 | Features 10 | --------- 11 | * Send any number of files at once. _(Directories are also supported and sent as ZIPs)_. 12 | * Send files to any connected device. 13 | 14 | Installation 15 | ------------- 16 | In addition to [KDE Connect](https://community.kde.org/KDEConnect), this extension requires [nautilus-python](https://wiki.gnome.org/Projects/NautilusPython) and libnotify. 17 | 18 | ## Instructions for Arch Linux 19 | 20 | 1. On your PC, install `kdeconnect-git`, `kde-cli-tools`, `python2-nautilus` and `libnotify`. 21 | 2. Install the KDE Connect companion app for Android, available on [Google Play](https://play.google.com/store/apps/details?id=org.kde.kdeconnect_tp) and [F-Droid](https://f-droid.org/repository/browse/?fdid=org.kde.kdeconnect_tp). 22 | 3. Launch KDE Connect on your PC and on your Android device. Pair the two devices and enable the sharing plugin. 23 | 4. Clone this repository and install the extension: `git clone https://github.com/forabi/nautilus-kdeconnect && make -C nautilus-kdeconnect install`. 24 | 25 | ## Instructions for Fedora 26 | 27 | 1. On your PC, install `kdeconnectd`, `kde-cli-tools`, `nautilus-python-devel`, `libnotify` 28 | and `libnotify-devel`. 29 | 2. Install the KDE Connect companion app for Android, available on [Google Play](https://play.google.com/store/apps/details?id=org.kde.kdeconnect_tp) and [F-Droid](https://f-droid.org/repository/browse/?fdid=org.kde.kdeconnect_tp). 30 | 3. Launch KDE Connect on your PC and on your Android device. Pair the two devices and enable the sharing plugin. 31 | 4. Clone this repository and install the extension: `git clone https://github.com/forabi/nautilus-kdeconnect && make -C nautilus-kdeconnect install`. 32 | 33 | ### Nemo file manager 34 | 35 | *nautilus-kdeconnect* can also be used with the Nemo file manager: 36 | 37 | 1. On your PC, install the `kdeconnect`, `python-nemo`, `libnotify-bin` and `git` packages. 38 | * If you are using some Debian-based distribution that is not *Linux Mint*, you won't find the `python-nemo` package in the software repositories: 39 | 1. Download and install the [`python-nemo` package](http://packages.linuxmint.com/pool/backport/n/nemo-python/) from the *Linux Mint* package archive site. 40 | 2. Run `sudo ln -s /usr/lib/nemo/extensions-3.0/libnemo-python.so /usr/lib/x86_64-linux-gnu/nemo/extensions-3.0/` to create a compatibility symlink to newly installed the extension file. 41 | 2. Install the KDE Connect app for Android as mentioned above ([Google Play](https://play.google.com/store/apps/details?id=org.kde.kdeconnect_tp) / [F-Droid](https://f-droid.org/repository/browse/?fdid=org.kde.kdeconnect_tp)). 42 | 3. Launch KDE Connect on your PC and on your Android device. Pair the two devices and enable the sharing plugin. 43 | 4. Clone this repository and install the extension with the `Nemo` target: `git clone https://github.com/forabi/nautilus-kdeconnect nemo-kdeconnect && make -C nemo-kdeconnect install TARGET=Nemo`. 44 | 45 | ### Caja file manager 46 | 47 | *nautilus-kdeconnect* can also be used with the Caja file manager: 48 | 49 | 1. On your PC, install the `kdeconnect`, `python-caja`, `libnotify-bin` and `git` packages. 50 | 2. Install the KDE Connect app for Android as mentioned above ([Google Play](https://play.google.com/store/apps/details?id=org.kde.kdeconnect_tp) / [F-Droid](https://f-droid.org/repository/browse/?fdid=org.kde.kdeconnect_tp)). 51 | 3. Launch KDE Connect on your PC and on your Android device. Pair the two devices and enable the sharing plugin. 52 | 4. Clone this repository and install the extension with the `Caja` target: `git clone https://github.com/forabi/nautilus-kdeconnect caja-kdeconnect && make -C caja-kdeconnect install TARGET=Caja` 53 | --------------------------------------------------------------------------------