Skip to content

Commit b2dc622

Browse files
committed
Allow recent:/// in Nautilus for Copy/Move/Open
fixes: QubesOS/qubes-issues#8589
1 parent 5b860df commit b2dc622

File tree

3 files changed

+77
-17
lines changed

3 files changed

+77
-17
lines changed

qubes-rpc/nautilus/qvm_copy_nautilus.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,30 @@ def get_file_items(self, *args):
2828
def on_menu_item_clicked(self, menu, files):
2929
'''Called when user chooses files though Nautilus context menu.
3030
'''
31-
cmd = [file_obj.get_location().get_path()
32-
for file_obj in files
33-
# Check if file is not gone
34-
if not file_obj.is_gone()]
31+
paths = []
32+
for file_obj in files:
33+
file_location = file_obj.get_location()
34+
file_uri = file_location.get_uri()
35+
if file_uri.startswith('file:///'):
36+
if not file_obj.is_gone():
37+
# Check if file is not gone
38+
paths.append(file_location.get_path())
39+
elif file_uri.startswith('recent:///'):
40+
try:
41+
file_info = file_location.query_info(
42+
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI, 0, None)
43+
target_uri = file_info.get_attribute_string(
44+
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI)
45+
if target_uri.startswith('file://'):
46+
paths.append(target_uri[7:])
47+
except GLib.GError:
48+
# TODO: Decide what to do if the recent item does not exist
49+
pass
50+
else:
51+
# TODO: Decide what to do with other weird URIs (eg. smb:///)
52+
pass
53+
# Double-check if the file is not gone in the meantime
54+
cmd = [path for path in paths if os.path.exists(path)]
3555
cmd.insert(0, '/usr/lib/qubes/qvm-copy-to-vm.gnome')
3656
pid = GLib.spawn_async(cmd)[0]
3757
GLib.spawn_close_pid(pid)

qubes-rpc/nautilus/qvm_dvm_nautilus.py

100755100644
+26-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from gi.repository import Nautilus, GObject, GLib
1+
import os.path
2+
from gi.repository import Nautilus, GObject, GLib, Gio
23

34

45
class OpenInDvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
@@ -39,17 +40,35 @@ def on_menu_item_clicked(self, menu, files, view_only=False):
3940
'''Called when user chooses files though Nautilus context menu.
4041
'''
4142
for file_obj in files:
42-
43-
# Check if file still exists
44-
if file_obj.is_gone():
43+
file_location = file_obj.get_location()
44+
file_uri = file_location.get_uri()
45+
if file_uri.startswith('file:///'):
46+
if not file_obj.is_gone():
47+
# Check if file still exists
48+
file_path = file_location.get_path()
49+
else:
50+
return
51+
elif file_uri.startswith('recent:///'):
52+
try:
53+
file_info = file_location.query_info(
54+
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI, 0, None)
55+
target_uri = file_info.get_attribute_string(
56+
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI)
57+
if target_uri.startswith('file://'):
58+
file_path = target_uri[7:]
59+
if not os.path.exists(file_path):
60+
return
61+
except GLib.GError:
62+
#TODO: Decide what to do if the recent item does not exist
63+
return
64+
else:
65+
# TODO: Decide what to do with other weird URIs (eg. smb:///)
4566
return
4667

47-
gio_file = file_obj.get_location()
48-
4968
command = ['/usr/bin/qvm-open-in-dvm']
5069
if view_only:
5170
command.append('--view-only')
52-
command.append(gio_file.get_path())
71+
command.append(file_path)
5372

5473
pid = GLib.spawn_async(command)[0]
5574
GLib.spawn_close_pid(pid)

qubes-rpc/nautilus/qvm_move_nautilus.py

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from gi.repository import Nautilus, GObject, GLib
2-
1+
import os.path
2+
from gi.repository import Nautilus, GObject, GLib, Gio
33

44
class MoveToAppvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
55
'''Move file(s) to AppVM.
@@ -28,10 +28,31 @@ def get_file_items(self, *args):
2828
def on_menu_item_clicked(self, menu, files):
2929
'''Called when user chooses files though Nautilus context menu.
3030
'''
31-
cmd = [file_obj.get_location().get_path()
32-
for file_obj in files
33-
# Check if file is not gone
34-
if not file_obj.is_gone()]
31+
paths = []
32+
for file_obj in files:
33+
file_location = file_obj.get_location()
34+
file_uri = file_location.get_uri()
35+
if file_uri.startswith('file:///'):
36+
if not file_obj.is_gone():
37+
# Check if file is not gone
38+
paths.append(file_location.get_path())
39+
elif file_uri.startswith('recent:///'):
40+
try:
41+
file_info = file_location.query_info(
42+
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI, 0, None)
43+
target_uri = file_info.get_attribute_string(
44+
Gio.FILE_ATTRIBUTE_STANDARD_TARGET_URI)
45+
if target_uri.startswith('file://'):
46+
paths.append(target_uri[7:])
47+
except GLib.GError:
48+
# TODO: Decide what to do if the recent item does not exist
49+
pass
50+
else:
51+
# TODO: Decide what to do with other weird URIs (eg. smb:///)
52+
pass
53+
# Double-check if the file is not gone in the meantime
54+
cmd = [path for path in paths if os.path.exists(path)]
3555
cmd.insert(0, '/usr/lib/qubes/qvm-move-to-vm.gnome')
3656
pid = GLib.spawn_async(cmd)[0]
3757
GLib.spawn_close_pid(pid)
58+
# TODO: Refresh Nautilus to remove moved files from recents list

0 commit comments

Comments
 (0)