Skip to content

Commit

Permalink
Allow recent:/// in Nautilus for Copy/Move/Open
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Aug 16, 2024
1 parent 5b860df commit b2dc622
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 17 deletions.
28 changes: 24 additions & 4 deletions qubes-rpc/nautilus/qvm_copy_nautilus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,30 @@ def get_file_items(self, *args):
def on_menu_item_clicked(self, menu, files):
'''Called when user chooses files though Nautilus context menu.
'''
cmd = [file_obj.get_location().get_path()
for file_obj in files
# Check if file is not gone
if not file_obj.is_gone()]
paths = []
for file_obj in files:
file_location = file_obj.get_location()
file_uri = file_location.get_uri()
if file_uri.startswith('file:///'):
if not file_obj.is_gone():
# Check if file is not gone
paths.append(file_location.get_path())
elif file_uri.startswith('recent:///'):
try:
file_info = file_location.query_info(
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI, 0, None)
target_uri = file_info.get_attribute_string(
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI)
if target_uri.startswith('file://'):
paths.append(target_uri[7:])
except GLib.GError:
# TODO: Decide what to do if the recent item does not exist
pass
else:
# TODO: Decide what to do with other weird URIs (eg. smb:///)
pass
# Double-check if the file is not gone in the meantime
cmd = [path for path in paths if os.path.exists(path)]
cmd.insert(0, '/usr/lib/qubes/qvm-copy-to-vm.gnome')
pid = GLib.spawn_async(cmd)[0]
GLib.spawn_close_pid(pid)
33 changes: 26 additions & 7 deletions qubes-rpc/nautilus/qvm_dvm_nautilus.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from gi.repository import Nautilus, GObject, GLib
import os.path
from gi.repository import Nautilus, GObject, GLib, Gio


class OpenInDvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
Expand Down Expand Up @@ -39,17 +40,35 @@ 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:

# Check if file still exists
if file_obj.is_gone():
file_location = file_obj.get_location()
file_uri = file_location.get_uri()
if file_uri.startswith('file:///'):
if not file_obj.is_gone():
# Check if file still exists
file_path = file_location.get_path()
else:
return
elif file_uri.startswith('recent:///'):
try:
file_info = file_location.query_info(
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI, 0, None)
target_uri = file_info.get_attribute_string(
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI)
if target_uri.startswith('file://'):
file_path = target_uri[7:]
if not os.path.exists(file_path):
return
except GLib.GError:
#TODO: Decide what to do if the recent item does not exist
return
else:
# TODO: Decide what to do with other weird URIs (eg. smb:///)
return

gio_file = file_obj.get_location()

command = ['/usr/bin/qvm-open-in-dvm']
if view_only:
command.append('--view-only')
command.append(gio_file.get_path())
command.append(file_path)

pid = GLib.spawn_async(command)[0]
GLib.spawn_close_pid(pid)
33 changes: 27 additions & 6 deletions qubes-rpc/nautilus/qvm_move_nautilus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from gi.repository import Nautilus, GObject, GLib

import os.path
from gi.repository import Nautilus, GObject, GLib, Gio

class MoveToAppvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
'''Move file(s) to AppVM.
Expand Down Expand Up @@ -28,10 +28,31 @@ def get_file_items(self, *args):
def on_menu_item_clicked(self, menu, files):
'''Called when user chooses files though Nautilus context menu.
'''
cmd = [file_obj.get_location().get_path()
for file_obj in files
# Check if file is not gone
if not file_obj.is_gone()]
paths = []
for file_obj in files:
file_location = file_obj.get_location()
file_uri = file_location.get_uri()
if file_uri.startswith('file:///'):
if not file_obj.is_gone():
# Check if file is not gone
paths.append(file_location.get_path())
elif file_uri.startswith('recent:///'):
try:
file_info = file_location.query_info(
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI, 0, None)
target_uri = file_info.get_attribute_string(
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI)
if target_uri.startswith('file://'):
paths.append(target_uri[7:])
except GLib.GError:
# TODO: Decide what to do if the recent item does not exist
pass
else:
# TODO: Decide what to do with other weird URIs (eg. smb:///)
pass
# Double-check if the file is not gone in the meantime
cmd = [path for path in paths if os.path.exists(path)]
cmd.insert(0, '/usr/lib/qubes/qvm-move-to-vm.gnome')
pid = GLib.spawn_async(cmd)[0]
GLib.spawn_close_pid(pid)
# TODO: Refresh Nautilus to remove moved files from recents list

0 comments on commit b2dc622

Please sign in to comment.