qvm_copy_nautilus.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import subprocess
  2. from gi.repository import Nautilus, GObject
  3. class CopyToAppvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
  4. '''Copy file(s) to AppVM.
  5. Uses the nautilus-python api to previce a context menu with Nautilus which
  6. will enable the user to select file(s) to to copy to another AppVM
  7. '''
  8. def get_file_items(self, window, files):
  9. '''Attaches context menu in Nautilus
  10. '''
  11. if not files:
  12. return
  13. menu_item = Nautilus.MenuItem(name='QubesMenuProvider::CopyToAppvm',
  14. label='Copy To Other AppVM...',
  15. tip='',
  16. icon='')
  17. menu_item.connect('activate', self.on_menu_item_clicked, files)
  18. return menu_item,
  19. def on_menu_item_clicked(self, menu, files):
  20. '''Called when user chooses files though Nautilus context menu.
  21. '''
  22. for file_obj in files:
  23. # Check if file still exists
  24. if file_obj.is_gone():
  25. return
  26. gio_file = file_obj.get_location()
  27. subprocess.call(['/usr/lib/qubes/qvm-copy-to-vm.gnome', gio_file.get_path()])