static void browse_python_scripts_dir(GtkAction *action, gpointer data) { gchar *uri; GdkAppLaunchContext *launch_context; GError *error = NULL; MainWindow *mainwin; mainwin = mainwindow_get_mainwindow(); if(!mainwin) { debug_print("Browse Python scripts: Problems getting the mainwindow\n"); return; } launch_context = gdk_app_launch_context_new(); gdk_app_launch_context_set_screen(launch_context, gtk_widget_get_screen(mainwin->window)); uri = g_strconcat("file://", get_rc_dir(), G_DIR_SEPARATOR_S, PYTHON_SCRIPTS_BASE_DIR, G_DIR_SEPARATOR_S, NULL); g_app_info_launch_default_for_uri(uri, G_APP_LAUNCH_CONTEXT(launch_context), &error); if(error) { debug_print("Could not open scripts dir browser: '%s'\n", error->message); g_error_free(error); } g_object_unref(launch_context); g_free(uri); }
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_APP_INFO (appinfo), FALSE); g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); context = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (context, screen); gdk_app_launch_context_set_timestamp (context, timestamp); local_error = NULL; retval = g_app_info_launch_uris (appinfo, uris, (GAppLaunchContext *) context, &local_error); g_object_unref (context); if ((local_error == NULL) && (retval == TRUE)) return TRUE; return _panel_launch_handle_error (g_app_info_get_name (appinfo), screen, local_error, error); }
void _g_launch_command (GtkWidget *parent, const char *command, const char *name, GList *files) { GError *error = NULL; GAppInfo *app_info; GdkAppLaunchContext *launch_context; app_info = g_app_info_create_from_commandline (command, name, G_APP_INFO_CREATE_SUPPORTS_URIS, &error); if (app_info == NULL) { _gtk_error_dialog_from_gerror_show(GTK_WINDOW (parent), _("Could not launch the application"), &error); return; } launch_context = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (launch_context, gtk_widget_get_screen (parent)); if (! g_app_info_launch (app_info, files, G_APP_LAUNCH_CONTEXT (launch_context), &error)) { _gtk_error_dialog_from_gerror_show(GTK_WINDOW (parent), _("Could not launch the application"), &error); return; } g_object_unref (app_info); }
/** * shell_global_get_app_launch_context: * @global: A #ShellGlobal * * Create a #GAppLaunchContext set up with the correct timestamp, and * targeted to activate on the current workspace. * * Return value: A new #GAppLaunchContext */ GAppLaunchContext * shell_global_create_app_launch_context (ShellGlobal *global) { GdkAppLaunchContext *context; context = gdk_app_launch_context_new (); gdk_app_launch_context_set_timestamp (context, shell_global_get_current_time (global)); // Make sure that the app is opened on the current workspace even if // the user switches before it starts gdk_app_launch_context_set_desktop (context, meta_screen_get_active_workspace_index (shell_global_get_screen (global))); return (GAppLaunchContext *)context; }
static void dialog_cb(GtkAction* action, AccessxStatusApplet* sapplet) { GError* error = NULL; GdkScreen *screen; GdkAppLaunchContext *launch_context; GAppInfo *appinfo; if (sapplet->error_type != ACCESSX_STATUS_ERROR_NONE) { popup_error_dialog(sapplet); return; } screen = gtk_widget_get_screen (GTK_WIDGET (sapplet->applet)); appinfo = g_app_info_create_from_commandline ("mate-keyboard-properties --a11y", _("Open the keyboard preferences dialog"), G_APP_INFO_CREATE_NONE, &error); if (!error) { #if GTK_CHECK_VERSION (3, 0, 0) launch_context = gdk_display_get_app_launch_context ( gtk_widget_get_display (GTK_WIDGET (screen))); #else launch_context = gdk_app_launch_context_new (); #endif gdk_app_launch_context_set_screen (launch_context, screen); g_app_info_launch (appinfo, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error); g_object_unref (launch_context); } if (error != NULL) { GtkWidget* dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("There was an error launching the keyboard preferences dialog: %s"), error->message); g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(gtk_widget_destroy), NULL); gtk_window_set_screen(GTK_WINDOW(dialog), screen); gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); gtk_widget_show(dialog); g_error_free(error); } g_object_unref (appinfo); }
/** * mate_url_show_on_screen: * @url: The url to display. Should begin with the protocol to use (e.g. * "http:", "ghelp:", etc) * @screen: a #GdkScreen. * @error: Used to store any errors that result from trying to display the @url. * * Description: Like mate_url_show(), but ensures that the viewer application * appears on @screen. * * Returns: %TRUE if everything went fine, %FALSE otherwise (in which case * @error will contain the actual error). * * Since: 2.6 **/ gboolean mate_url_show_on_screen (const char *url, GdkScreen *screen, GError **error) { gboolean retval; GdkAppLaunchContext *context; context = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (context, screen); retval = g_app_info_launch_default_for_uri (url, context, error); g_object_unref (context); return retval; }
static void csd_autorun_launch_for_mount (GMount *mount, GAppInfo *app_info) { GFile *root; GdkAppLaunchContext *launch_context; GError *error; gboolean result; GList *list; gchar *uri_scheme; gchar *uri; root = g_mount_get_root (mount); list = g_list_append (NULL, root); launch_context = gdk_app_launch_context_new (); error = NULL; result = g_app_info_launch (app_info, list, 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 = g_file_get_uri (root); uri_scheme = g_uri_parse_scheme (uri); /* FIXME: Present user a dialog to choose another app when the last one failed to handle a file */ g_warning ("Cannot open location: %s\n", error->message); g_free (uri_scheme); g_free (uri); } else { g_warning ("Cannot open app: %s\n", error->message); } g_error_free (error); } g_list_free (list); g_object_unref (root); }
gboolean dawati_netbook_launch_application_from_desktop_file (const gchar *desktop, GList *files, gint workspace, gboolean no_chooser) { GAppInfo *app; GAppLaunchContext *ctx; GError *error = NULL; gboolean retval = TRUE; g_return_val_if_fail (desktop, FALSE); app = G_APP_INFO (g_desktop_app_info_new_from_filename (desktop)); if (!app) { g_warning ("Failed to create GAppInfo for file %s", desktop); return FALSE; } ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ()); retval = g_app_info_launch (app, files, ctx, &error); if (error) { g_warning ("Failed to lauch %s (%s)", #if GLIB_CHECK_VERSION(2,20,0) g_app_info_get_commandline (app), #else g_app_info_get_name (app), #endif error->message); g_error_free (error); } g_object_unref (ctx); g_object_unref (app); return retval; }
gboolean open_file_with_application (GtkWidget * window, const gchar * file, GAppInfo * app) { GdkAppLaunchContext * context; GdkScreen * screen; gboolean result; if (g_file_test (file, G_FILE_TEST_IS_DIR) == TRUE) { return FALSE; } context = gdk_app_launch_context_new (); screen = gtk_widget_get_screen (window); gdk_app_launch_context_set_screen (context, screen); if (app == NULL) { gchar * uri; uri = g_filename_to_uri (file, NULL, NULL); result = g_app_info_launch_default_for_uri (uri, (GAppLaunchContext *) context, NULL); g_free (uri); } else { GList * g_file_list = NULL; GFile * g_file = NULL; g_file = g_file_new_for_path (file); if (g_file == NULL) { result = FALSE; } else { g_file_list = g_list_prepend (g_file_list, g_file); result = g_app_info_launch (app, g_file_list, (GAppLaunchContext *) context, NULL); g_list_free (g_file_list); g_object_unref (g_file); } } return result; }
GAppLaunchContext * giggle_create_app_launch_context (GtkWidget *widget) { #if GTK_CHECK_VERSION(2,14,0) GdkAppLaunchContext *context; GdkScreen *screen = NULL; context = gdk_app_launch_context_new (); if (widget) { screen = gtk_widget_get_screen (widget); gdk_app_launch_context_set_screen (context, screen); } return G_APP_LAUNCH_CONTEXT (context); #else return g_app_launch_context_new (); #endif }
void caja_connect_server_dialog_display_location_async (CajaConnectServerDialog *self, CajaApplication *application, GFile *location, GAsyncReadyCallback callback, gpointer user_data) { GError *error; GdkAppLaunchContext *launch_context; gchar *uri; display_location_res = g_simple_async_result_new (G_OBJECT (self), callback, user_data, caja_connect_server_dialog_display_location_async); error = NULL; uri = g_file_get_uri (location); launch_context = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (launch_context, gtk_widget_get_screen (GTK_WIDGET (self))); g_app_info_launch_default_for_uri (uri, G_APP_LAUNCH_CONTEXT (launch_context), &error); g_object_unref (launch_context); if (error != NULL) { g_simple_async_result_set_from_error (display_location_res, error); g_error_free (error); } g_simple_async_result_complete_in_idle (display_location_res); g_object_unref (display_location_res); display_location_res = NULL; }
static void CappletResponse (GtkDialog * dialog, gint response) { if (response == GTK_RESPONSE_HELP) { GError *error = NULL; GdkAppLaunchContext *ctx = gdk_app_launch_context_new (); g_app_info_launch_default_for_uri ("ghelp:matekbd?gkb-indicator-applet-plugins", G_APP_LAUNCH_CONTEXT (ctx), &error); if (error) { GtkWidget *d = NULL; d = gtk_message_dialog_new (GTK_WINDOW (dialog), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _ ("Unable to open help file")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (d), "%s", error->message); g_signal_connect (d, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_window_present (GTK_WINDOW (d)); g_error_free (error); } return; } g_main_loop_quit (loop); }
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_app_launch_context_new (); /* 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)); if (count == total) { /* All files are local, so we can use g_app_info_launch () with * the file list we constructed before. */ g_app_info_launch (G_APP_INFO (app_info), files, G_APP_LAUNCH_CONTEXT (context), &error); } else { /* Some files are non local, better use g_app_info_launch_uris (). */ g_app_info_launch_uris (G_APP_INFO (app_info), (GList *) parameter_uris, G_APP_LAUNCH_CONTEXT (context), &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); }
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); }
/** * 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) { GDesktopAppInfo *gapp; char *filename; GdkAppLaunchContext *context; gboolean ret; ShellGlobal *global; MetaScreen *screen; MetaDisplay *display; 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) { gapp = g_desktop_app_info_new (shell_app_info_get_id (info)); } else { 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); display = meta_screen_get_display (screen); 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); ret = g_app_info_launch (G_APP_INFO (gapp), uris, (GAppLaunchContext*) context, error); g_object_unref (G_OBJECT (gapp)); return ret; }
static void action_caja_manual_callback (GtkAction *action, gpointer user_data) { CajaWindow *window; GError *error; GtkWidget *dialog; error = NULL; window = CAJA_WINDOW (user_data); if (CAJA_IS_DESKTOP_WINDOW (window)) { #if GTK_CHECK_VERSION (3, 0, 0) GdkScreen *screen; GdkAppLaunchContext *launch_context; GAppInfo *app_info = NULL; app_info = g_app_info_create_from_commandline ("mate-help", NULL, G_APP_INFO_CREATE_NONE, &error); if (error == NULL) { screen = gtk_window_get_screen(GTK_WINDOW(window)); launch_context = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (launch_context, screen); g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error); g_object_unref (launch_context); } if (app_info != NULL) g_object_unref (app_info); #else #if GTK_CHECK_VERSION (2, 24, 0) gdk_spawn_command_line_on_screen(gtk_window_get_screen(GTK_WINDOW(window)), "mate-help", &error); #else g_spawn_command_line_async("mate-help", &error); #endif #endif } else { gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (window)), "help:mate-user-guide/goscaja-1", gtk_get_current_event_time (), &error); } if (error) { dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("There was an error displaying help: \n%s"), error->message); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); gtk_widget_show (dialog); g_error_free (error); } }
/** * 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; }
static void ev_spawn (const char *uri, GdkScreen *screen, EvLinkDest *dest, EvWindowRunMode mode, const gchar *search_string, guint timestamp) { GString *cmd; gchar *path, *cmdline; GAppInfo *app; GdkAppLaunchContext *ctx; GError *error = NULL; cmd = g_string_new (NULL); #ifdef G_OS_WIN32 { gchar *dir; dir = g_win32_get_package_installation_directory_of_module (NULL); path = g_build_filename (dir, "bin", "atril", NULL); g_free (dir); } #else path = g_build_filename (BINDIR, "atril", NULL); #endif g_string_append_printf (cmd, " %s", path); g_free (path); /* Page label */ if (dest) { const gchar *page_label; page_label = ev_link_dest_get_page_label (dest); if (page_label) g_string_append_printf (cmd, " --page-label=%s", page_label); else g_string_append_printf (cmd, " --page-label=%d", ev_link_dest_get_page (dest)); } /* Find string */ if (search_string) { g_string_append_printf (cmd, " --find=%s", search_string); } /* Mode */ switch (mode) { case EV_WINDOW_MODE_FULLSCREEN: g_string_append (cmd, " -f"); break; case EV_WINDOW_MODE_PRESENTATION: g_string_append (cmd, " -s"); break; default: break; } cmdline = g_string_free (cmd, FALSE); app = g_app_info_create_from_commandline (cmdline, NULL, 0, &error); if (app != NULL) { GList uri_list; GList *uris = NULL; #if GTK_CHECK_VERSION (3, 0, 0) ctx = gdk_display_get_app_launch_context (gdk_screen_get_display (screen)); #else ctx = gdk_app_launch_context_new (); gdk_app_launch_context_set_display (ctx, gdk_screen_get_display (screen)); #endif gdk_app_launch_context_set_screen (ctx, screen); gdk_app_launch_context_set_timestamp (ctx, timestamp); if (uri) { uri_list.data = (gchar *)uri; uri_list.prev = uri_list.next = NULL; uris = &uri_list; } g_app_info_launch_uris (app, uris, G_APP_LAUNCH_CONTEXT (ctx), &error); g_object_unref (app); g_object_unref (ctx); } if (error != NULL) { g_warning ("Error launching atril %s: %s\n", uri, error->message); g_error_free (error); } g_free (cmdline); }
gboolean open_file_with_filemanager (GtkWidget * window, const gchar * file) { GDesktopAppInfo * d_app_info; GKeyFile * key_file; GdkAppLaunchContext * ctx = NULL; GList * list = NULL; GAppInfo * g_app_info; GFile * g_file; gchar * command; gchar * contents; gchar * uri; gboolean result = TRUE; uri = g_filename_to_uri (file, NULL, NULL); list = g_list_prepend (list, uri); g_file = g_file_new_for_path (file); g_app_info = g_file_query_default_handler (g_file, NULL, NULL); if (strcmp (g_app_info_get_executable (g_app_info), "nautilus") == 0) { command = g_strconcat ("nautilus ", "--sm-disable ", "--no-desktop ", "--no-default-window ", NULL); } else { command = g_strconcat (g_app_info_get_executable (g_app_info), " ", NULL); } contents = g_strdup_printf ("[Desktop Entry]\n" "Name=Nautilus\n" "Icon=file-manager\n" "Exec=%s\n" "Terminal=false\n" "StartupNotify=true\n" "Type=Application\n", command); key_file = g_key_file_new (); g_key_file_load_from_data (key_file, contents, strlen(contents), G_KEY_FILE_NONE, NULL); d_app_info = g_desktop_app_info_new_from_keyfile (key_file); if (d_app_info != NULL) { ctx = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (ctx, gtk_widget_get_screen (window)); result = g_app_info_launch_uris (G_APP_INFO (d_app_info), list, G_APP_LAUNCH_CONTEXT (ctx), NULL); } else { result = FALSE; } g_object_unref (g_app_info); g_object_unref (d_app_info); g_object_unref (g_file); g_object_unref (ctx); g_key_file_free (key_file); g_list_free (list); g_free (contents); g_free (command); g_free (uri); return result; }