From e8a2d9c32ad06fd5b06fd6ad85675ddd66b1ab38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 26 May 2018 02:50:55 +0200 Subject: [PATCH] Add file managers integration for qvm-open-in-dvm --view-only Rename existing entry from 'Open In DisposableVM' to 'Edit in DisposableVM', then add new 'View In DisposableVM'. Fixes QubesOS/qubes-issues#1118 --- misc/uca_qubes.xml | 15 ++++++++++++++- qubes-rpc/qvm-actions.sh | 6 ++++++ qubes-rpc/qvm-dvm.desktop | 9 +++++++-- qubes-rpc/qvm_dvm_nautilus.py | 26 ++++++++++++++++++++------ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/misc/uca_qubes.xml b/misc/uca_qubes.xml index 2e4ad8d..64a3ce9 100644 --- a/misc/uca_qubes.xml +++ b/misc/uca_qubes.xml @@ -59,7 +59,7 @@ document-open - Open in DisposableVM + Edit in DisposableVM 1507455559234996-8 /usr/lib/qubes/qvm-actions.sh opendvm %F @@ -70,3 +70,16 @@ + + document-open + View in DisposableVM + 1507455559234997-9 + /usr/lib/qubes/qvm-actions.sh viewdvm %F + + * + + + + + + diff --git a/qubes-rpc/qvm-actions.sh b/qubes-rpc/qvm-actions.sh index 691b3f2..3e4a968 100755 --- a/qubes-rpc/qvm-actions.sh +++ b/qubes-rpc/qvm-actions.sh @@ -45,6 +45,12 @@ case "$action" in qvm-open-in-dvm "$file" | zenity --notification --text "Opening $file in DisposableVM..." --timeout 3 & done ;; + viewdvm) + for file in "$@" + do + qvm-open-in-dvm --view-only "$file" | zenity --notification --text "Opening $file in DisposableVM..." --timeout 3 & + done + ;; *) echo "Unknown action. Aborting..." exit 1 diff --git a/qubes-rpc/qvm-dvm.desktop b/qubes-rpc/qvm-dvm.desktop index ba34250..e293b01 100644 --- a/qubes-rpc/qvm-dvm.desktop +++ b/qubes-rpc/qvm-dvm.desktop @@ -1,10 +1,15 @@ [Desktop Entry] -Actions=QvmDvm; +Actions=QvmDvm;QvmViewDvm Type=Service X-KDE-ServiceTypes=KonqPopupMenu/Plugin,all/allfiles [Desktop Action QvmDvm] Exec=/usr/bin/qvm-open-in-dvm %U Icon=kget -Name=Open In DisposableVM +Name=Edit In DisposableVM + +[Desktop Action QvmViewDvm] +Exec=/usr/bin/qvm-open-in-dvm --view-only %U +Icon=kget +Name=View In DisposableVM diff --git a/qubes-rpc/qvm_dvm_nautilus.py b/qubes-rpc/qvm_dvm_nautilus.py index a4311a4..7614396 100755 --- a/qubes-rpc/qvm_dvm_nautilus.py +++ b/qubes-rpc/qvm_dvm_nautilus.py @@ -17,15 +17,24 @@ class OpenInDvmItemExtension(GObject.GObject, Nautilus.MenuProvider): if not files: return - menu_item = Nautilus.MenuItem(name='QubesMenuProvider::OpenInDvm', - label='Open In DisposableVM', + menu_item1 = Nautilus.MenuItem(name='QubesMenuProvider::OpenInDvm', + label='Edit In DisposableVM', tip='', icon='') - menu_item.connect('activate', self.on_menu_item_clicked, files) - return menu_item, + menu_item1.connect('activate', self.on_menu_item_clicked, files) - def on_menu_item_clicked(self, menu, files): + menu_item2 = Nautilus.MenuItem(name='QubesMenuProvider::ViewInDvm', + label='View In DisposableVM', + tip='', + icon='') + + menu_item2.connect('activate', + self.on_menu_item_clicked, + files, True) + return menu_item1, menu_item2, + + def on_menu_item_clicked(self, menu, files, view_only=False): '''Called when user chooses files though Nautilus context menu. ''' for file_obj in files: @@ -38,6 +47,11 @@ class OpenInDvmItemExtension(GObject.GObject, Nautilus.MenuProvider): # Use subprocess.DEVNULL in python >= 3.3 devnull = open(os.devnull, 'wb') + command = ['nohup', '/usr/bin/qvm-open-in-dvm'] + if view_only: + command.append('--view-only') + command.append(gio_file.get_path()) # Use Popen instead of subprocess.call to spawn the process - Popen(['nohup', '/usr/bin/qvm-open-in-dvm', gio_file.get_path()], stdout=devnull, stderr=devnull) + Popen(command, stdout=devnull, stderr=devnull) + devnull.close()