[shotwell/wip/phako/misc-fixes: 4/8] Use DBus to launch file manager



commit 8bbea52f86b28898095ac86d4cba2260bd921bf4
Author: Jens Georg <mail jensge org>
Date:   Mon Sep 3 12:46:55 2018 +0200

    Use DBus to launch file manager
    
    Instead of explicitly checking for nautilus. Fall back to
    gtk_show_uri() if DBus fails
    
    https://bugzilla.gnome.org/show_bug.cgi?id=718676

 src/AppWindow.vala   | 12 +-----------
 src/util/system.vala | 26 ++++++++++++++++++++++----
 2 files changed, 23 insertions(+), 15 deletions(-)
---
diff --git a/src/AppWindow.vala b/src/AppWindow.vala
index 56e4383b..e50a254f 100644
--- a/src/AppWindow.vala
+++ b/src/AppWindow.vala
@@ -657,17 +657,7 @@ public abstract class AppWindow : PageWindow {
     }
     
     public void show_file_uri(File file) throws Error {
-        string tmp;
-        
-        // if file manager is nautilus then pass the full path to file; otherwise pass
-        // the enclosing directory
-        if(get_nautilus_install_location() != null) {
-            tmp = file.get_uri().replace("'","\\\'");
-            show_file_in_nautilus(tmp);
-        } else {
-            tmp = file.get_parent().get_uri().replace("'","\\\'");
-            show_uri(tmp);
-        }
+        show_file_in_filemanager.begin(file);
     }
     
     public void show_uri(string url) throws Error {
diff --git a/src/util/system.vala b/src/util/system.vala
index 0269d3d2..1e693044 100644
--- a/src/util/system.vala
+++ b/src/util/system.vala
@@ -21,11 +21,29 @@ File? get_sys_install_dir(File exec_dir) {
     return null;
 }
 
-string get_nautilus_install_location() {
-    return Environment.find_program_in_path("nautilus");
+[DBus (name = "org.freedesktop.FileManager1")]
+public interface org.freedesktop.FileManager1 : Object {
+    public const string NAME = "org.freedesktop.FileManager1";
+    public const string PATH = "/org/freedesktop/FileManager1";
+
+    public abstract async void show_folders(string[] uris, string startup_id) throws IOError, DBusError;
+    public abstract async void show_items(string[] uris, string startup_id) throws IOError, DBusError;
+    public abstract async void show_item_properties(string[] uris, string startup_id) throws IOError, 
DBusError;
 }
 
-void show_file_in_nautilus(string filename) throws Error {
-    GLib.Process.spawn_command_line_async(get_nautilus_install_location() + " " + filename);
+async void show_file_in_filemanager(File file) throws Error {
+    try {
+        org.freedesktop.FileManager1? manager = yield Bus.get_proxy (BusType.SESSION,
+                                                                     org.freedesktop.FileManager1.NAME,
+                                                                     org.freedesktop.FileManager1.PATH,
+                                                                     DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
+                                                                     DBusProxyFlags.DO_NOT_CONNECT_SIGNALS);
+        var id = "%s_%s_%d_%s".printf(Environment.get_prgname(), Environment.get_host_name(),
+                                      Posix.getpid(), TimeVal().to_iso8601());
+        yield manager.show_items({file.get_uri()}, id);
+    } catch (Error e) {
+        warning("Failed to launch file manager using DBus, using fall-back: %s", e.message);
+        Gtk.show_uri_on_window(AppWindow.get_instance(), file.get_parent().get_uri(), Gdk.CURRENT_TIME);
+    }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]