void caja_launch_application_by_uri (GAppInfo *application, GList *uris, GtkWindow *parent_window) { char *uri, *uri_scheme; GList *locations, *l; GFile *location; CajaFile *file; gboolean result; GError *error; GdkAppLaunchContext *launch_context; CajaIconInfo *icon; int count, total; g_assert (uris != NULL); /* count the number of uris with local paths */ count = 0; total = g_list_length (uris); locations = NULL; for (l = uris; l != NULL; l = l->next) { uri = l->data; location = g_file_new_for_uri (uri); if (g_file_is_native (location)) { count++; } locations = g_list_prepend (locations, location); } locations = g_list_reverse (locations); launch_context = gdk_app_launch_context_new (); if (parent_window) gdk_app_launch_context_set_screen (launch_context, gtk_window_get_screen (parent_window)); file = caja_file_get_by_uri (uris->data); icon = caja_file_get_icon (file, 48, 0); caja_file_unref (file); if (icon) { gdk_app_launch_context_set_icon_name (launch_context, caja_icon_info_get_used_name (icon)); g_object_unref (icon); } error = NULL; if (count == total) { /* All files are local, so we can use g_app_info_launch () with * the file list we constructed before. */ result = g_app_info_launch (application, locations, G_APP_LAUNCH_CONTEXT (launch_context), &error); } else { /* Some files are non local, better use g_app_info_launch_uris (). */ result = g_app_info_launch_uris (application, uris, G_APP_LAUNCH_CONTEXT (launch_context), &error); } g_object_unref (launch_context); if (!result) { if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_SUPPORTED) { uri_scheme = g_uri_parse_scheme (uris->data); application_cannot_open_location (application, file, uri_scheme, parent_window); g_free (uri_scheme); } else { #ifdef NEW_MIME_COMPLETE caja_program_chooser_show_invalid_message (MATE_VFS_MIME_ACTION_TYPE_APPLICATION, file, parent_window); #else g_warning ("Cannot open app: %s\n", error->message); #endif } g_error_free (error); } else { for (l = uris; l != NULL; l = l->next) { file = caja_file_get_by_uri (l->data); caja_recent_add_file (file, application); caja_file_unref (file); } } g_list_free_full (locations, g_object_unref); }
void caja_launch_application_by_uri (GAppInfo *application, GList *uris, GtkWindow *parent_window) { char *uri, *uri_scheme; GList *locations, *l; GFile *location; CajaFile *file; gboolean result; GError *error; GdkDisplay *display; GdkAppLaunchContext *launch_context; CajaIconInfo *icon; int count, total; g_assert (uris != NULL); /* count the number of uris with local paths */ count = 0; total = g_list_length (uris); locations = NULL; for (l = uris; l != NULL; l = l->next) { uri = l->data; location = g_file_new_for_uri (uri); if (g_file_is_native (location)) { count++; } locations = g_list_prepend (locations, location); } locations = g_list_reverse (locations); if (parent_window != NULL) { display = gtk_widget_get_display (GTK_WIDGET (parent_window)); } else { display = gdk_display_get_default (); } launch_context = gdk_display_get_app_launch_context (display); if (parent_window != NULL) { gdk_app_launch_context_set_screen (launch_context, gtk_window_get_screen (parent_window)); } file = caja_file_get_by_uri (uris->data); icon = caja_file_get_icon (file, 48, 0); caja_file_unref (file); if (icon) { gdk_app_launch_context_set_icon_name (launch_context, caja_icon_info_get_used_name (icon)); g_object_unref (icon); } error = NULL; result = g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (application), uris, G_APP_LAUNCH_CONTEXT (launch_context), G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, gather_pid_callback, application, &error); g_object_unref (launch_context); if (!result) { if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_SUPPORTED) { uri_scheme = g_uri_parse_scheme (uris->data); application_cannot_open_location (application, file, uri_scheme, parent_window); g_free (uri_scheme); } else { #ifdef NEW_MIME_COMPLETE caja_program_chooser_show_invalid_message (MATE_VFS_MIME_ACTION_TYPE_APPLICATION, file, parent_window); #else g_warning ("Cannot open app: %s\n", error->message); #endif } g_error_free (error); } else { for (l = uris; l != NULL; l = l->next) { file = caja_file_get_by_uri (l->data); caja_recent_add_file (file, application); caja_file_unref (file); } } g_list_free_full (locations, g_object_unref); }