gboolean panel_app_info_launch_uris (GAppInfo *appinfo, GList *uris, GdkScreen *screen, guint32 timestamp, GError **error) { GdkAppLaunchContext *context; GError *local_error; gboolean retval; g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (appinfo), FALSE); g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); GdkDisplay *display = gdk_display_get_default (); context = gdk_display_get_app_launch_context (display); gdk_app_launch_context_set_screen (context, screen); gdk_app_launch_context_set_timestamp (context, timestamp); local_error = NULL; retval = g_desktop_app_info_launch_uris_as_manager ((GDesktopAppInfo*)appinfo, uris, (GAppLaunchContext *) context, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, gather_pid_callback, appinfo, &local_error); g_object_unref (context); if ((local_error == NULL) && (retval == TRUE)) return TRUE; return _panel_launch_handle_error (g_app_info_get_name ((GAppInfo*) appinfo), screen, local_error, error); }
/** * cinnamon_app_launch: * @timestamp: Event timestamp, or 0 for current event timestamp * @uris: (element-type utf8): List of uris to pass to application * @workspace: Start on this workspace, or -1 for default * @startup_id: (out): Returned startup notification ID, or %NULL if none * @error: A #GError */ gboolean cinnamon_app_launch (CinnamonApp *app, guint timestamp, GList *uris, int workspace, char **startup_id, GError **error) { GDesktopAppInfo *gapp; GdkAppLaunchContext *context; gboolean ret; CinnamonGlobal *global; MetaScreen *screen; GdkDisplay *gdisplay; if (startup_id) *startup_id = NULL; if (app->entry == NULL) { MetaWindow *window = window_backed_app_get_window (app); /* We can't pass URIs into a window; shouldn't hit this * code path. If we do, fix the caller to disallow it. */ g_return_val_if_fail (uris == NULL, TRUE); meta_window_activate (window, timestamp); return TRUE; } global = cinnamon_global_get (); screen = cinnamon_global_get_screen (global); gdisplay = gdk_screen_get_display (cinnamon_global_get_gdk_screen (global)); if (timestamp == 0) timestamp = cinnamon_global_get_current_time (global); if (workspace < 0) workspace = meta_screen_get_active_workspace_index (screen); context = gdk_display_get_app_launch_context (gdisplay); gdk_app_launch_context_set_timestamp (context, timestamp); gdk_app_launch_context_set_desktop (context, workspace); gapp = gmenu_tree_entry_get_app_info (app->entry); ret = g_desktop_app_info_launch_uris_as_manager (gapp, uris, G_APP_LAUNCH_CONTEXT (context), G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, _gather_pid_callback, app, error); g_object_unref (context); return ret; }
void caja_launch_desktop_file (GdkScreen *screen, const char *desktop_file_uri, const GList *parameter_uris, GtkWindow *parent_window) { GError *error; char *message, *desktop_file_path; const GList *p; GList *files; int total, count; GFile *file, *desktop_file; GDesktopAppInfo *app_info; GdkAppLaunchContext *context; /* Don't allow command execution from remote locations * to partially mitigate the security * risk of executing arbitrary commands. */ desktop_file = g_file_new_for_uri (desktop_file_uri); desktop_file_path = g_file_get_path (desktop_file); if (!g_file_is_native (desktop_file)) { g_free (desktop_file_path); g_object_unref (desktop_file); eel_show_error_dialog (_("Sorry, but you cannot execute commands from " "a remote site."), _("This is disabled due to security considerations."), parent_window); return; } g_object_unref (desktop_file); app_info = g_desktop_app_info_new_from_filename (desktop_file_path); g_free (desktop_file_path); if (app_info == NULL) { eel_show_error_dialog (_("There was an error launching the application."), NULL, parent_window); return; } /* count the number of uris with local paths */ count = 0; total = g_list_length ((GList *) parameter_uris); files = NULL; for (p = parameter_uris; p != NULL; p = p->next) { file = g_file_new_for_uri ((const char *) p->data); if (g_file_is_native (file)) { count++; } files = g_list_prepend (files, file); } /* check if this app only supports local files */ if (g_app_info_supports_files (G_APP_INFO (app_info)) && !g_app_info_supports_uris (G_APP_INFO (app_info)) && parameter_uris != NULL) { if (count == 0) { /* all files are non-local */ eel_show_error_dialog (_("This drop target only supports local files."), _("To open non-local files copy them to a local folder and then" " drop them again."), parent_window); g_list_free_full (files, g_object_unref); g_object_unref (app_info); return; } else if (count != total) { /* some files are non-local */ eel_show_warning_dialog (_("This drop target only supports local files."), _("To open non-local files copy them to a local folder and then" " drop them again. The local files you dropped have already been opened."), parent_window); } } error = NULL; context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (parent_window))); /* TODO: Ideally we should accept a timestamp here instead of using GDK_CURRENT_TIME */ gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME); gdk_app_launch_context_set_screen (context, gtk_window_get_screen (parent_window)); g_desktop_app_info_launch_uris_as_manager (app_info, (GList *) parameter_uris, G_APP_LAUNCH_CONTEXT (context), G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, gather_pid_callback, app_info, &error); if (error != NULL) { message = g_strconcat (_("Details: "), error->message, NULL); eel_show_error_dialog (_("There was an error launching the application."), message, parent_window); g_error_free (error); g_free (message); } g_list_free_full (files, g_object_unref); g_object_unref (context); g_object_unref (app_info); }
/** * shell_app_info_launch_full: * @timestamp: Event timestamp, or 0 for current event timestamp * @uris: List of uris to pass to application * @workspace: Start on this workspace, or -1 for default * @startup_id: (out): Returned startup notification ID, or %NULL if none * @error: A #GError */ gboolean shell_app_info_launch_full (ShellAppInfo *info, guint timestamp, GList *uris, int workspace, char **startup_id, GError **error) { ShellApp *shell_app; GDesktopAppInfo *gapp; GdkAppLaunchContext *context; gboolean ret; ShellGlobal *global; MetaScreen *screen; if (startup_id) *startup_id = NULL; if (info->type == SHELL_APP_INFO_TYPE_WINDOW) { /* We can't pass URIs into a window; shouldn't hit this * code path. If we do, fix the caller to disallow it. */ g_return_val_if_fail (uris == NULL, TRUE); meta_window_activate (info->window, timestamp); return TRUE; } else if (info->type == SHELL_APP_INFO_TYPE_ENTRY) { /* Can't use g_desktop_app_info_new, see bug 614879 */ const char *filename = gmenu_tree_entry_get_desktop_file_path ((GMenuTreeEntry *)info->entry); gapp = g_desktop_app_info_new_from_filename (filename); } else { char *filename = shell_app_info_get_desktop_file_path (info); gapp = g_desktop_app_info_new_from_filename (filename); g_free (filename); } if (!gapp) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Not found"); return FALSE; } global = shell_global_get (); screen = shell_global_get_screen (global); if (timestamp == 0) timestamp = clutter_get_current_event_time (); if (workspace < 0) workspace = meta_screen_get_active_workspace_index (screen); context = gdk_app_launch_context_new (); gdk_app_launch_context_set_timestamp (context, timestamp); gdk_app_launch_context_set_desktop (context, workspace); shell_app = shell_app_system_get_app (shell_app_system_get_default (), shell_app_info_get_id (info)); /* In the case where we know an app, we handle reaping the child internally, * in the window tracker. */ if (shell_app != NULL) ret = g_desktop_app_info_launch_uris_as_manager (gapp, uris, G_APP_LAUNCH_CONTEXT (context), G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, _gather_pid_callback, shell_app, error); else ret = g_desktop_app_info_launch_uris_as_manager (gapp, uris, G_APP_LAUNCH_CONTEXT (context), G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, error); g_object_unref (G_OBJECT (gapp)); return ret; }
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); }