diff --git a/thunar/thunar-dbus-service-infos.xml b/thunar/thunar-dbus-service-infos.xml index 0a8dba8e63c96206e27be5504fdc225b576aa3a5..9322e29fb9b668fcc3a00e80ee25f580ea2ea116 100644 --- a/thunar/thunar-dbus-service-infos.xml +++ b/thunar/thunar-dbus-service-infos.xml @@ -115,7 +115,7 @@ <!-- - Launch (uri : STRING, display : STRING) : VOID + Launch (uri : STRING, display : STRING, startup_id : STRING) : VOID uri : either a file:-URI or an absolute path. display : the screen on which to launch the file or "" @@ -130,6 +130,27 @@ </method> + <!-- + Execute (working_directory : STRING, uri : STRING, files : ARRAY OF STRING, display : STRING, startup_id : STRING) : VOID + + working_directory : working directory used to resolve relative filenames. + uri : either a file:-URI or an relative or absolute path. + files : an array of file:-URIs, relative or absolute paths to supply to + the executed URI on execution. + display : the screen on which to launch the file or "" + to use the default screen of the file manager. + startup_id : the DESKTOP_STARTUP_ID environment variable for properly + handling startup notification and focus stealing. + --> + <method name="Execute"> + <arg direction="in" name="working_directory" type="s" /> + <arg direction="in" name="uri" type="s" /> + <arg direction="in" name="files" type="as" /> + <arg direction="in" name="display" type="s" /> + <arg direction="in" name="startup_id" type="s" /> + </method> + + <!-- DisplayPreferencesDialog (display : STRING) : VOID diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c index 8a864a9ced9d7c2552241b6e494078f2d9056ff7..202b06cb297ceac533298b4ddc09a6c612f51dca 100644 --- a/thunar/thunar-dbus-service.c +++ b/thunar/thunar-dbus-service.c @@ -103,6 +103,13 @@ static gboolean thunar_dbus_service_launch (ThunarDBusServi const gchar *display, const gchar *startup_id, GError **error); +static gboolean thunar_dbus_service_execute (ThunarDBusService *dbus_service, + const gchar *working_directory, + const gchar *uri, + const gchar **files, + const gchar *display, + const gchar *startup_id, + GError **error); static gboolean thunar_dbus_service_display_preferences_dialog (ThunarDBusService *dbus_service, const gchar *display, const gchar *startup_id, @@ -552,6 +559,59 @@ thunar_dbus_service_launch (ThunarDBusService *dbus_service, +static gboolean +thunar_dbus_service_execute (ThunarDBusService *dbus_service, + const gchar *working_directory, + const gchar *uri, + const gchar **files, + const gchar *display, + const gchar *startup_id, + GError **error) +{ + ThunarFile *file; + GdkScreen *screen; + gboolean result = FALSE; + GFile *working_dir; + GList *file_list = NULL; + gchar *tmp_working_dir = NULL; + gchar *old_working_dir = NULL; + guint n; + + /* parse uri and display parameters */ + if (thunar_dbus_service_parse_uri_and_display (dbus_service, uri, display, &file, &screen, error)) + { + if (working_directory != NULL && *working_directory != '\0') + old_working_dir = thunar_util_change_working_directory (working_directory); + + for (n = 0; files != NULL && files[n] != NULL; ++n) + file_list = g_list_prepend (file_list, g_file_new_for_commandline_arg (files[n])); + + file_list = g_list_reverse (file_list); + + if (old_working_dir != NULL) + { + tmp_working_dir = thunar_util_change_working_directory (old_working_dir); + g_free (tmp_working_dir); + g_free (old_working_dir); + } + + /* try to launch the file on the given screen */ + working_dir = g_file_new_for_commandline_arg (working_directory); + result = thunar_file_execute (file, working_dir, screen, file_list, error); + g_object_unref (working_dir); + + /* cleanup */ + g_list_foreach (file_list, (GFunc) g_object_unref, NULL); + g_list_free (file_list); + g_object_unref (screen); + g_object_unref (file); + } + + return result; +} + + + static gboolean thunar_dbus_service_display_preferences_dialog (ThunarDBusService *dbus_service, const gchar *display,