GAppInfo * problem_create_app_from_cmdline (const char *cmdline) { GAppInfo *app; GList *apps, *l; GList *shortlist; char *binary; char **cmdargs; binary = problem_get_argv0(cmdline); apps = g_app_info_get_all (); shortlist = NULL; app = NULL; for (l = apps; l != NULL; l = l->next) { GAppInfo *a = l->data; if (!g_app_info_should_show(a)) continue; if (!compare_binaries (binary, g_app_info_get_executable (a))) continue; shortlist = g_list_prepend (shortlist, a); } if (shortlist == NULL) { g_list_free_full (apps, g_object_unref); return NULL; } cmdargs = g_strsplit (cmdline, " ", -1); remove_quotes (cmdargs); for (l = shortlist; l != NULL; l = l->next) { GAppInfo *a = l->data; char **dcmdargs; const char *commandline = g_app_info_get_commandline (a); if (commandline == NULL) continue; dcmdargs = g_strsplit (commandline, " ", -1); remove_quotes (dcmdargs); if (compare_args (cmdargs, dcmdargs)) app = g_object_ref (a); g_strfreev (dcmdargs); if (app != NULL) break; } g_list_free (shortlist); g_list_free_full (apps, g_object_unref); return app; }
static void set_recent_entry (ScreenshotApplication *self) { char *app_exec = NULL; GtkRecentManager *recent; GtkRecentData recent_data; GAppInfo *app; const char *exec_name = NULL; static char * groups[2] = { "Graphics", NULL }; app = g_app_info_get_default_for_type ("image/png", TRUE); if (!app) { /* return early, as this would be an useless recent entry anyway. */ return; } recent = gtk_recent_manager_get_default (); exec_name = g_app_info_get_executable (app); app_exec = g_strjoin (" ", exec_name, "%u", NULL); recent_data.display_name = NULL; recent_data.description = NULL; recent_data.mime_type = "image/png"; recent_data.app_name = "GNOME Screenshot"; recent_data.app_exec = app_exec; recent_data.groups = groups; recent_data.is_private = FALSE; gtk_recent_manager_add_full (recent, self->priv->save_uri, &recent_data); g_object_unref (app); g_free (app_exec); }
const char* getApp(char* name) { GFile* file=g_file_new_for_path(name); GFileInfo* file_info=g_file_query_info(file,"standard::*",G_FILE_QUERY_INFO_NONE,NULL,NULL); const char* content_type=g_file_info_get_content_type(file_info); GAppInfo* app_info=g_app_info_get_default_for_type(content_type,false); return(g_app_info_get_executable(app_info)); }
/* An application is valid if: * * 1) The file exists * 2) The user has permissions to run the file */ static gboolean check_application (CajaOpenWithDialog *dialog) { char *command; char *path = NULL; char **argv = NULL; int argc; GError *error = NULL; gint retval = TRUE; command = NULL; if (dialog->details->selected_app_info != NULL) { command = g_strdup (g_app_info_get_executable (dialog->details->selected_app_info)); } if (command == NULL) { command = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->details->entry))); } g_shell_parse_argv (command, &argc, &argv, &error); if (error) { eel_show_error_dialog (_("Could not run application"), error->message, GTK_WINDOW (dialog)); g_error_free (error); retval = FALSE; goto cleanup; } path = g_find_program_in_path (argv[0]); if (!path) { char *error_message; error_message = g_strdup_printf (_("Could not find '%s'"), argv[0]); eel_show_error_dialog (_("Could not find application"), error_message, GTK_WINDOW (dialog)); g_free (error_message); retval = FALSE; goto cleanup; } cleanup: g_strfreev (argv); g_free (path); g_free (command); return retval; }
static void open_cb (GtkWidget *widget, gpointer callback_data) { DialogData *data = callback_data; const char *application; gboolean present = FALSE; char *command = NULL; GList *scan; char **editors; int i; application = gtk_entry_get_text (GTK_ENTRY (data->o_app_entry)); for (scan = data->app_list; scan; scan = scan->next) { GAppInfo *app = scan->data; if (strcmp (g_app_info_get_executable (app), application) == 0) { fr_window_open_files_with_application (data->window, data->file_list, app); gtk_widget_destroy (data->dialog); return; } } /* add the command to the editors list if not already present. */ editors = g_settings_get_strv (data->settings, PREF_GENERAL_EDITORS); for (i = 0; ! present && editors[i] != NULL; i++) { if (strcmp (editors[i], application) == 0) { command = g_strdup (editors[i]); present = TRUE; } } if (! present) { char **new_editors; new_editors = _g_strv_prepend (editors, g_strdup (application)); command = g_strdup (application); g_settings_set_strv (data->settings, PREF_GENERAL_EDITORS, (const gchar * const *) new_editors); g_strfreev (new_editors); } g_strfreev (editors); /* exec the application */ if (command != NULL) { fr_window_open_files_with_command (data->window, data->file_list, command); g_free (command); } gtk_widget_destroy (data->dialog); }
/* An application is valid if: * * 1) The file exists * 2) The user has permissions to run the file */ static gboolean check_application (GtkAppChooserDialog *self, GAppInfo **app_out) { const char *command; char *path = NULL; char **argv = NULL; int argc; GError *error = NULL; gint retval = TRUE; GAppInfo *info; command = NULL; info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget)); command = g_app_info_get_executable (info); g_shell_parse_argv (command, &argc, &argv, &error); if (error) { show_error_dialog (_("Could not run application"), error->message, GTK_WINDOW (self)); g_error_free (error); retval = FALSE; goto cleanup; } path = g_find_program_in_path (argv[0]); if (!path) { char *error_message; error_message = g_strdup_printf (_("Could not find '%s'"), argv[0]); show_error_dialog (_("Could not find application"), error_message, GTK_WINDOW (self)); g_free (error_message); retval = FALSE; goto cleanup; } *app_out = info; cleanup: g_strfreev (argv); g_free (path); return retval; }
QString LauncherApplication::executable() const { if (m_appInfo != NULL) { return QString::fromUtf8(g_app_info_get_executable(m_appInfo.data())); } if (m_snStartupSequence != NULL) { return QString::fromUtf8(sn_startup_sequence_get_binary_name(m_snStartupSequence.data())); } return QString(""); }
/** * Create or find already existing application info for specified command * and application name. * @param cmd command to execute * @param appName application name * @param appInfo location where created GAppInfo is stored * @return NS_OK when object is created, NS_ERROR_FAILURE otherwise. */ NS_IMETHODIMP nsGIOService::CreateAppFromCommand(nsACString const& cmd, nsACString const& appName, nsIGIOMimeApp** appInfo) { GError *error = NULL; *appInfo = nsnull; GAppInfo *app_info = NULL, *app_info_from_list = NULL; GList *apps = g_app_info_get_all(); GList *apps_p = apps; // Try to find relevant and existing GAppInfo in all installed application // We do this by comparing each GAppInfo's executable with out own while (apps_p) { app_info_from_list = (GAppInfo*) apps_p->data; if (!app_info) { // If the executable is not absolute, get it's full path char *executable = g_find_program_in_path(g_app_info_get_executable(app_info_from_list)); if (executable && strcmp(executable, PromiseFlatCString(cmd).get()) == 0) { g_object_ref (app_info_from_list); app_info = app_info_from_list; } g_free(executable); } g_object_unref(app_info_from_list); apps_p = apps_p->next; } g_list_free(apps); if (!app_info) { app_info = g_app_info_create_from_commandline(PromiseFlatCString(cmd).get(), PromiseFlatCString(appName).get(), G_APP_INFO_CREATE_SUPPORTS_URIS, &error); } if (!app_info) { g_warning("Cannot create application info from command: %s", error->message); g_error_free(error); return NS_ERROR_FAILURE; } nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info); NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(*appInfo = mozApp); return NS_OK; }
JS_EXPORT_API double launcher_weight(GDesktopAppInfo* info, const char* key) { double weight = 0.0; /* desktop file information */ const char* path = g_desktop_app_info_get_filename(info); char* basename = g_path_get_basename(path); *strchr(basename, '.') = '\0'; weight += _get_weight(basename, key, _pred, FILENAME_WEIGHT); g_free(basename); const char* gname = g_desktop_app_info_get_generic_name(info); weight += _get_weight(gname, key, _pred, GENERIC_NAME_WEIGHT); const char* const* keys = g_desktop_app_info_get_keywords(info); if (keys != NULL) { size_t n = g_strv_length((char**)keys); for (size_t i=0; i<n; i++) { weight += _get_weight(keys[i], key, _pred, KEYWORD_WEIGHT); } } const char* categories = g_desktop_app_info_get_categories(info); if (categories) { gchar** category_names = g_strsplit(categories, ";", -1); gsize len = g_strv_length(category_names) - 1; for (gsize i = 0; i < len; ++i) { weight += _get_weight(category_names[i], key, _pred, CATEGORY_WEIGHT); } g_strfreev(category_names); } /* application information */ const char* name = g_app_info_get_name((GAppInfo*)info); weight += _get_weight(name, key, _pred, NAME_WEIGHT); const char* dname = g_app_info_get_display_name((GAppInfo*)info); weight += _get_weight(dname, key, _pred, DISPLAY_NAME_WEIGHT); const char* desc = g_app_info_get_description((GAppInfo*)info); weight += _get_weight(desc, key, _pred, DESCRIPTION_WEIGHT); const char* exec = g_app_info_get_executable((GAppInfo*)info); weight += _get_weight(exec, key, _pred, EXECUTABLE_WEIGHT); return weight; }
static void gtk_app_chooser_add_default (GtkAppChooserWidget *self, GAppInfo *app) { GtkTreeIter iter; GIcon *icon; gchar *string; gboolean unref_icon; unref_icon = FALSE; string = g_strdup_printf ("<b>%s</b>", _("Default Application")); gtk_list_store_append (self->priv->program_list_store, &iter); gtk_list_store_set (self->priv->program_list_store, &iter, COLUMN_HEADING_TEXT, string, COLUMN_HEADING, TRUE, COLUMN_DEFAULT, TRUE, -1); g_free (string); string = g_markup_printf_escaped ("%s", g_app_info_get_name (app) != NULL ? g_app_info_get_name (app) : ""); icon = g_app_info_get_icon (app); if (icon == NULL) { icon = g_themed_icon_new ("application-x-executable"); unref_icon = TRUE; } gtk_list_store_append (self->priv->program_list_store, &iter); gtk_list_store_set (self->priv->program_list_store, &iter, COLUMN_APP_INFO, app, COLUMN_GICON, icon, COLUMN_NAME, g_app_info_get_name (app), COLUMN_DESC, string, COLUMN_EXEC, g_app_info_get_executable (app), COLUMN_HEADING, FALSE, COLUMN_DEFAULT, TRUE, -1); g_free (string); if (unref_icon) g_object_unref (icon); }
static void cinnamon_app_init_search_data (CinnamonApp *app) { const char *name; const char *exec; const char *comment; char *normalized_exec; GDesktopAppInfo *appinfo; appinfo = gmenu_tree_entry_get_app_info (app->entry); name = g_app_info_get_name (G_APP_INFO (appinfo)); app->casefolded_name = cinnamon_util_normalize_and_casefold (name); comment = g_app_info_get_description (G_APP_INFO (appinfo)); app->casefolded_description = cinnamon_util_normalize_and_casefold (comment); exec = g_app_info_get_executable (G_APP_INFO (appinfo)); normalized_exec = cinnamon_util_normalize_and_casefold (exec); app->casefolded_exec = trim_exec_line (normalized_exec); g_free (normalized_exec); }
static void app_activated_cb (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer callback_data) { DialogData *data = callback_data; GtkTreeIter iter; GAppInfo *app; if (! gtk_tree_model_get_iter (data->app_model, &iter, path)) return; gtk_tree_model_get (data->app_model, &iter, DATA_COLUMN, &app, -1); _gtk_entry_set_locale_text (GTK_ENTRY (data->o_app_entry), g_app_info_get_executable (app)); open_cb (NULL, data); }
static void app_list_selection_changed_cb (GtkTreeSelection *selection, gpointer p) { DialogData *data = p; GtkTreeIter iter; GAppInfo *app; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_app_tree_view)); if (selection == NULL) return; if (! gtk_tree_selection_get_selected (selection, NULL, &iter)) return; gtk_tree_model_get (data->app_model, &iter, DATA_COLUMN, &app, -1); _gtk_entry_set_locale_text (GTK_ENTRY (data->o_app_entry), g_app_info_get_executable (app)); data->last_clicked_list = data->o_app_tree_view; }
void nautilus_recent_add_file (NautilusFile *file, GAppInfo *application) { GtkRecentData recent_data; char *uri; uri = nautilus_file_get_uri (file); /* do not add trash:// etc */ if (eel_uri_is_trash (uri) || eel_uri_is_search (uri) || eel_uri_is_desktop (uri)) { g_free (uri); return; } recent_data.display_name = NULL; recent_data.description = NULL; recent_data.mime_type = nautilus_file_get_mime_type (file); recent_data.app_name = g_strdup (g_get_application_name ()); if (application != NULL) recent_data.app_exec = g_strdup (g_app_info_get_executable (application)); else recent_data.app_exec = g_strdup (DEFAULT_APP_EXEC); recent_data.groups = NULL; recent_data.is_private = FALSE; gtk_recent_manager_add_full (nautilus_recent_get_manager (), uri, &recent_data); g_free (recent_data.mime_type); g_free (recent_data.app_name); g_free (recent_data.app_exec); g_free (uri); }
/** * Open default file manager via mime type * Some file managers custom the directory by user **/ int main(int argc, char *argv[]) { GAppInfo *app_info = g_app_info_get_default_for_type(FILE_MANAGER_MIME_TYPE, FALSE); if (!app_info) { g_error("Failed to get default app for %s", FILE_MANAGER_MIME_TYPE); return -1; } g_debug("Executable: %s\n", g_app_info_get_executable(app_info)); g_debug("Commandline: %s\n", g_app_info_get_commandline(app_info)); GError *error = NULL; gboolean ret = g_app_info_launch(app_info, NULL, NULL, &error); if (error) { g_error("Failed to launch %s, error: %s", g_app_info_get_name(app_info), error->message); g_error_free(error); goto EXIT; } EXIT: g_object_unref(app_info); return ret?0:-1; }
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; }
int main (int argc, char *argv[]) { gboolean kill_shell; gboolean no_default_window; gboolean browser_window; gboolean no_desktop; gboolean version; gboolean autostart_mode; const char *autostart_id; gchar *geometry; gchar **remaining; gboolean perform_self_check; CajaApplication *application; GOptionContext *context; GFile *file = NULL; GFileInfo *fileinfo = NULL; GAppInfo *appinfo = NULL; char *uri = NULL; char **uris = NULL; GPtrArray *uris_array; GError *error; int i; const GOptionEntry options[] = { #ifndef CAJA_OMIT_SELF_CHECK { "check", 'c', 0, G_OPTION_ARG_NONE, &perform_self_check, N_("Perform a quick set of self-check tests."), NULL }, #endif { "version", '\0', 0, G_OPTION_ARG_NONE, &version, N_("Show the version of the program."), NULL }, { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, N_("Create the initial window with the given geometry."), N_("GEOMETRY") }, { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, &no_default_window, N_("Only create windows for explicitly specified URIs."), NULL }, { "no-desktop", '\0', 0, G_OPTION_ARG_NONE, &no_desktop, N_("Do not manage the desktop (ignore the preference set in the preferences dialog)."), NULL }, { "browser", '\0', 0, G_OPTION_ARG_NONE, &browser_window, N_("open a browser window."), NULL }, { "quit", 'q', 0, G_OPTION_ARG_NONE, &kill_shell, N_("Quit Caja."), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL, N_("[URI...]") }, { NULL } }; #if defined (HAVE_MALLOPT) && defined(M_MMAP_THRESHOLD) /* Caja uses lots and lots of small and medium size allocations, * and then a few large ones for the desktop background. By default * glibc uses a dynamic treshold for how large allocations should * be mmaped. Unfortunately this triggers quickly for caja when * it does the desktop background allocations, raising the limit * such that a lot of temporary large allocations end up on the * heap and are thus not returned to the OS. To fix this we set * a hardcoded limit. I don't know what a good value is, but 128K * was the old glibc static limit, lets use that. */ mallopt (M_MMAP_THRESHOLD, 128 *1024); #endif g_thread_init (NULL); /* This will be done by gtk+ later, but for now, force it to MATE */ g_desktop_app_info_set_desktop_env ("MATE"); if (g_getenv ("CAJA_DEBUG") != NULL) { eel_make_warnings_and_criticals_stop_in_debugger (); } /* Initialize gettext support */ bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); autostart_mode = FALSE; autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID"); if (autostart_id != NULL && *autostart_id != '\0') { autostart_mode = TRUE; } /* Get parameters. */ remaining = NULL; geometry = NULL; version = FALSE; kill_shell = FALSE; no_default_window = FALSE; no_desktop = FALSE; perform_self_check = FALSE; browser_window = FALSE; g_set_prgname ("caja"); if (g_file_test (DATADIR "/applications/caja.desktop", G_FILE_TEST_EXISTS)) { egg_set_desktop_file (DATADIR "/applications/caja.desktop"); } context = g_option_context_new (_("\n\nBrowse the file system with the file manager")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_group (context, egg_sm_client_get_option_group ()); error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Could not parse arguments: %s\n", error->message); g_error_free (error); return 1; } g_option_context_free (context); if (version) { g_print ("MATE caja " PACKAGE_VERSION "\n"); return 0; } #ifdef HAVE_EXEMPI xmp_init(); #endif setup_debug_log (); /* If in autostart mode (aka started by mate-session), we need to ensure * caja starts with the correct options. */ if (autostart_mode) { no_default_window = TRUE; no_desktop = FALSE; } if (perform_self_check && remaining != NULL) { /* translators: %s is an option (e.g. --check) */ fprintf (stderr, _("caja: %s cannot be used with URIs.\n"), "--check"); return EXIT_FAILURE; } if (perform_self_check && kill_shell) { fprintf (stderr, _("caja: --check cannot be used with other options.\n")); return EXIT_FAILURE; } if (kill_shell && remaining != NULL) { fprintf (stderr, _("caja: %s cannot be used with URIs.\n"), "--quit"); return EXIT_FAILURE; } if (geometry != NULL && remaining != NULL && remaining[0] != NULL && remaining[1] != NULL) { fprintf (stderr, _("caja: --geometry cannot be used with more than one URI.\n")); return EXIT_FAILURE; } /* Initialize the services that we use. */ LIBXML_TEST_VERSION /* Initialize preferences. This is needed so that proper * defaults are available before any preference peeking * happens. */ caja_global_preferences_init (); /* exit_with_last_window being FALSE, caja can run without window. */ exit_with_last_window = g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_EXIT_WITH_LAST_WINDOW); application = NULL; /* Do either the self-check or the real work. */ if (perform_self_check) { #ifndef CAJA_OMIT_SELF_CHECK /* Run the checks (each twice) for caja and libcaja-private. */ caja_run_self_checks (); caja_run_lib_self_checks (); eel_exit_if_self_checks_failed (); caja_run_self_checks (); caja_run_lib_self_checks (); eel_exit_if_self_checks_failed (); #endif } else { /* Convert args to URIs */ if (remaining != NULL) { uris_array = g_ptr_array_new (); for (i = 0; remaining[i] != NULL; i++) { file = g_file_new_for_commandline_arg (remaining[i]); if (file != NULL) { uri = g_file_get_uri (file); if (uri) { fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (fileinfo && g_file_info_get_file_type(fileinfo) == G_FILE_TYPE_DIRECTORY) { g_ptr_array_add (uris_array, uri); } else { if (fileinfo) g_object_unref (fileinfo); fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (fileinfo) { appinfo = g_app_info_get_default_for_type (g_file_info_get_content_type (fileinfo), TRUE); if (appinfo) { if (g_strcmp0 (g_app_info_get_executable (appinfo), "caja") != 0) { g_app_info_launch_default_for_uri (uri, NULL, NULL); } else { fprintf (stderr, _("caja: set erroneously as default application for '%s' content type.\n"), g_file_info_get_content_type (fileinfo)); } g_object_unref (appinfo); } g_free (uri); } else { g_ptr_array_add (uris_array, uri); } } if (fileinfo) g_object_unref (fileinfo); } if (file) g_object_unref (file); } } if (uris_array->len == 0) { /* Caja is being used only to open files (not directories), so closing */ g_strfreev (remaining); return EXIT_SUCCESS; } g_ptr_array_add (uris_array, NULL); uris = (char**) g_ptr_array_free (uris_array, FALSE); g_strfreev (remaining); } /* Run the caja application. */ application = caja_application_new (); if (egg_sm_client_is_resumed (application->smclient)) { no_default_window = TRUE; } caja_application_startup (application, kill_shell, no_default_window, no_desktop, browser_window, geometry, uris); g_strfreev (uris); if (unique_app_is_running (application->unique_app) || kill_shell) { exit_with_last_window = TRUE; } if (is_event_loop_needed ()) { gtk_main (); } } caja_icon_info_clear_caches (); if (application != NULL) { g_object_unref (application); } eel_debug_shut_down (); caja_application_save_accel_map (NULL); return EXIT_SUCCESS; }
static VALUE appinfo_get_executable(VALUE self) { return CSTR2RVAL(g_app_info_get_executable(_SELF(self))); }
static char * gdk_x11_app_launch_context_get_startup_notify_id (GAppLaunchContext *context, GAppInfo *info, GList *files) { static int sequence = 0; GdkDisplay *display; GdkX11Screen *screen; int files_count; char *description; char *icon_name; const char *binary_name; const char *application_id; char *screen_str; char *workspace_str; GIcon *icon; guint32 timestamp; char *startup_id; GFileInfo *fileinfo; GdkAppLaunchContext *ctx; ctx = GDK_APP_LAUNCH_CONTEXT (context); display = ctx->display; screen = GDK_X11_DISPLAY (display)->screen; fileinfo = NULL; files_count = g_list_length (files); if (files_count == 0) { description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info)); } else if (files_count == 1) { gchar *display_name; if (g_file_is_native (files->data)) fileinfo = g_file_query_info (files->data, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_ICON, 0, NULL, NULL); display_name = get_display_name (files->data, fileinfo); description = g_strdup_printf (_("Opening %s"), display_name); g_free (display_name); } else description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Opening %d Item", "Opening %d Items", files_count), files_count); icon_name = NULL; if (ctx->icon_name) icon_name = g_strdup (ctx->icon_name); else { icon = NULL; if (ctx->icon != NULL) icon = g_object_ref (ctx->icon); else if (files_count == 1) icon = get_icon (files->data, fileinfo); if (icon == NULL) { icon = g_app_info_get_icon (info); if (icon != NULL) g_object_ref (icon); } if (icon != NULL) { icon_name = gicon_to_string (icon); g_object_unref (icon); } } binary_name = g_app_info_get_executable (info); timestamp = ctx->timestamp; if (timestamp == GDK_CURRENT_TIME) timestamp = gdk_x11_display_get_user_time (display); screen_str = g_strdup_printf ("%d", gdk_x11_screen_get_screen_number (screen)); if (ctx->workspace > -1) workspace_str = g_strdup_printf ("%d", ctx->workspace); else workspace_str = NULL; if (G_IS_DESKTOP_APP_INFO (info)) application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info)); else application_id = NULL; startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long)getpid (), g_get_host_name (), binary_name, sequence++, (unsigned long)timestamp); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", g_app_info_get_name (info), "SCREEN", screen_str, "BIN", binary_name, "ICON", icon_name, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", NULL, /* FIXME */ "APPLICATION_ID", application_id, NULL); g_free (description); g_free (screen_str); g_free (workspace_str); g_free (icon_name); if (fileinfo) g_object_unref (fileinfo); add_startup_timeout (screen, startup_id); return startup_id; }
static void _gth_browser_update_open_menu (GthBrowser *browser, const char *path) { GtkWidget *openwith_item; GtkWidget *menu; GList *items; GList *file_list; GList *scan; GList *appinfo_list; GHashTable *used_mime_types; GthIconCache *icon_cache; GHashTable *used_apps; openwith_item = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), path); menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (openwith_item)); _gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL); items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser))); file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items); appinfo_list = NULL; used_mime_types = g_hash_table_new (g_str_hash, g_str_equal); for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; const char *mime_type; mime_type = gth_file_data_get_mime_type (file_data); if ((mime_type == NULL) || g_content_type_is_unknown (mime_type)) continue; if (g_hash_table_lookup (used_mime_types, mime_type) != NULL) continue; appinfo_list = g_list_concat (appinfo_list, g_app_info_get_all_for_type (mime_type)); g_hash_table_insert (used_mime_types, (gpointer) mime_type, GINT_TO_POINTER (1)); } g_hash_table_destroy (used_mime_types); icon_cache = gth_browser_get_menu_icon_cache (browser); used_apps = g_hash_table_new (g_str_hash, g_str_equal); for (scan = appinfo_list; scan; scan = scan->next) { GAppInfo *appinfo = scan->data; char *label; GtkWidget *menu_item; GIcon *icon; if (strcmp (g_app_info_get_executable (appinfo), "pix") == 0) continue; if (g_hash_table_lookup (used_apps, g_app_info_get_id (appinfo)) != NULL) continue; g_hash_table_insert (used_apps, (gpointer) g_app_info_get_id (appinfo), GINT_TO_POINTER (1)); label = g_strdup_printf ("%s", g_app_info_get_name (appinfo)); menu_item = gtk_image_menu_item_new_with_label (label); icon = g_app_info_get_icon (appinfo); if (icon != NULL) { GdkPixbuf *pixbuf; pixbuf = gth_icon_cache_get_pixbuf (icon_cache, icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), gtk_image_new_from_pixbuf (pixbuf)); gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menu_item), TRUE); g_object_unref (pixbuf); } gtk_widget_show (menu_item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); g_object_set_data_full (G_OBJECT (menu_item), "appinfo", g_object_ref (appinfo), g_object_unref); g_signal_connect (menu_item, "activate", G_CALLBACK (activate_open_with_application_item), browser); g_free (label); } /* if (appinfo_list == NULL) { GtkWidget *menu_item; menu_item = gtk_image_menu_item_new_with_label (_("No application available")); gtk_widget_set_sensitive (menu_item, FALSE); gtk_widget_show (menu_item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); }*/ gtk_widget_set_sensitive (openwith_item, appinfo_list != NULL); gtk_widget_show (openwith_item); g_hash_table_destroy (used_apps); _g_object_list_unref (appinfo_list); _g_object_list_unref (file_list); _gtk_tree_path_list_free (items); }
/* create the "open with" dialog. */ void dlg_open_with (FrWindow *window, GList *file_list) { DialogData *data; GAppInfo *app; GList *scan, *app_names = NULL; char **editors; int i; GtkWidget *cancel_button; GtkTreeIter iter; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkIconTheme *theme; int icon_size; if (file_list == NULL) return; data = g_new0 (DialogData, 1); data->settings = g_settings_new (EXRED_SCHEMA_GENERAL); data->builder = _gtk_builder_new_from_file ("open-with.ui"); if (data->builder == NULL) { g_free (data); return; } data->file_list = path_list_dup (file_list); data->window = window; /* Get the widgets. */ data->dialog = _gtk_builder_get_widget (data->builder, "open_with_dialog"); data->o_app_tree_view = _gtk_builder_get_widget (data->builder, "o_app_list_tree_view"); data->o_recent_tree_view = _gtk_builder_get_widget (data->builder, "o_recent_tree_view"); data->o_app_entry = _gtk_builder_get_widget (data->builder, "o_app_entry"); data->o_del_button = _gtk_builder_get_widget (data->builder, "o_del_button"); data->ok_button = _gtk_builder_get_widget (data->builder, "o_ok_button"); cancel_button = _gtk_builder_get_widget (data->builder, "o_cancel_button"); gtk_widget_set_sensitive (data->ok_button, FALSE); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (open_with__destroy_cb), data); g_signal_connect (G_OBJECT (data->o_app_entry), "changed", G_CALLBACK (app_entry__changed_cb), data); g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_app_tree_view))), "changed", G_CALLBACK (app_list_selection_changed_cb), data); g_signal_connect (G_OBJECT (data->o_app_tree_view), "row_activated", G_CALLBACK (app_activated_cb), data); g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_recent_tree_view))), "changed", G_CALLBACK (recent_list_selection_changed_cb), data); g_signal_connect (G_OBJECT (data->o_recent_tree_view), "row_activated", G_CALLBACK (recent_activated_cb), data); g_signal_connect (G_OBJECT (data->ok_button), "clicked", G_CALLBACK (open_cb), data); g_signal_connect_swapped (G_OBJECT (cancel_button), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (data->dialog)); g_signal_connect (G_OBJECT (data->o_del_button), "clicked", G_CALLBACK (delete_recent_cb), data); /* Set data. */ /* * registered applications list. */ data->app_list = NULL; for (scan = data->file_list; scan; scan = scan->next) { const char *mime_type; const char *name = scan->data; mime_type = get_file_mime_type_for_path (name, FALSE); if ((mime_type != NULL) && ! g_content_type_is_unknown (mime_type)) data->app_list = g_list_concat (data->app_list, g_app_info_get_all_for_type (mime_type)); } data->app_model = GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER)); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->app_model), TEXT_COLUMN, GTK_SORT_ASCENDING); gtk_tree_view_set_model (GTK_TREE_VIEW (data->o_app_tree_view), data->app_model); g_object_unref (G_OBJECT (data->app_model)); theme = gtk_icon_theme_get_default (); icon_size = get_folder_pixbuf_size_for_list (GTK_WIDGET (data->dialog)); for (scan = data->app_list; scan; scan = scan->next) { gboolean found; char *utf8_name; GdkPixbuf *icon_image = NULL; app = scan->data; found = FALSE; if (app_names != NULL) { GList *p; for (p = app_names; p && !found; p = p->next) if (g_strcmp0 ((char*)p->data, g_app_info_get_executable (app)) == 0) found = TRUE; } if (found) continue; app_names = g_list_prepend (app_names, (char*) g_app_info_get_executable (app)); utf8_name = g_locale_to_utf8 (g_app_info_get_name (app), -1, NULL, NULL, NULL); icon_image = get_icon_pixbuf (g_app_info_get_icon (app), icon_size, theme); gtk_list_store_append (GTK_LIST_STORE (data->app_model), &iter); gtk_list_store_set (GTK_LIST_STORE (data->app_model), &iter, ICON_COLUMN, icon_image, TEXT_COLUMN, utf8_name, DATA_COLUMN, app, -1); g_free (utf8_name); } column = gtk_tree_view_column_new (); renderer = gtk_cell_renderer_pixbuf_new (); gtk_tree_view_column_pack_start (column, renderer, FALSE); gtk_tree_view_column_set_attributes (column, renderer, "pixbuf", ICON_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, renderer, TRUE); gtk_tree_view_column_set_attributes (column, renderer, "text", TEXT_COLUMN, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (data->o_app_tree_view), column); if (app_names) g_list_free (app_names); /* * recent editors list. */ data->recent_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->recent_model), 0, GTK_SORT_ASCENDING); gtk_tree_view_set_model (GTK_TREE_VIEW (data->o_recent_tree_view), data->recent_model); g_object_unref (G_OBJECT (data->recent_model)); editors = g_settings_get_strv (data->settings, PREF_GENERAL_EDITORS); for (i = 0; editors[i] != NULL; i++) { gtk_list_store_append (GTK_LIST_STORE (data->recent_model), &iter); gtk_list_store_set (GTK_LIST_STORE (data->recent_model), &iter, 0, editors[i], -1); } g_strfreev (editors); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes (NULL, renderer, "text", 0, NULL); gtk_tree_view_column_set_sort_column_id (column, 0); gtk_tree_view_append_column (GTK_TREE_VIEW (data->o_recent_tree_view), column); /* Run dialog. */ gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (window)); gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE); gtk_widget_show_all (data->dialog); }
static void set_changed(GtkComboBox* combo, MateDACapplet* capplet, GList* list, gint type) { guint index; GAppInfo* item; GSettings* settings; index = gtk_combo_box_get_active(combo); if (index < g_list_length(list)) { item = (GAppInfo*) g_list_nth_data(list, index); switch (type) { case DA_TYPE_WEB_BROWSER: g_app_info_set_as_default_for_type(item, "x-scheme-handler/http", NULL); g_app_info_set_as_default_for_type(item, "x-scheme-handler/https", NULL); /* about:config is used by firefox and others */ g_app_info_set_as_default_for_type(item, "x-scheme-handler/about", NULL); break; case DA_TYPE_EMAIL: g_app_info_set_as_default_for_type(item, "x-scheme-handler/mailto", NULL); g_app_info_set_as_default_for_type(item, "application/x-extension-eml", NULL); g_app_info_set_as_default_for_type(item, "message/rfc822", NULL); break; case DA_TYPE_FILE: g_app_info_set_as_default_for_type(item, "inode/directory", NULL); break; case DA_TYPE_TEXT: g_app_info_set_as_default_for_type(item, "text/plain", NULL); break; case DA_TYPE_MEDIA: g_app_info_set_as_default_for_type(item, "audio/mpeg", NULL); g_app_info_set_as_default_for_type(item, "audio/x-mpegurl", NULL); g_app_info_set_as_default_for_type(item, "audio/x-scpls", NULL); g_app_info_set_as_default_for_type(item, "audio/x-vorbis+ogg", NULL); g_app_info_set_as_default_for_type(item, "audio/x-wav", NULL); break; case DA_TYPE_VIDEO: g_app_info_set_as_default_for_type(item, "video/mp4", NULL); g_app_info_set_as_default_for_type(item, "video/mpeg", NULL); g_app_info_set_as_default_for_type(item, "video/mp2t", NULL); g_app_info_set_as_default_for_type(item, "video/msvideo", NULL); g_app_info_set_as_default_for_type(item, "video/quicktime", NULL); g_app_info_set_as_default_for_type(item, "video/webm", NULL); g_app_info_set_as_default_for_type(item, "video/x-avi", NULL); g_app_info_set_as_default_for_type(item, "video/x-flv", NULL); g_app_info_set_as_default_for_type(item, "video/x-matroska", NULL); g_app_info_set_as_default_for_type(item, "video/x-mpeg", NULL); g_app_info_set_as_default_for_type(item, "video/x-ogm+ogg", NULL); break; case DA_TYPE_IMAGE: g_app_info_set_as_default_for_type(item, "image/bmp", NULL); g_app_info_set_as_default_for_type(item, "image/gif", NULL); g_app_info_set_as_default_for_type(item, "image/jpeg", NULL); g_app_info_set_as_default_for_type(item, "image/png", NULL); g_app_info_set_as_default_for_type(item, "image/tiff", NULL); break; case DA_TYPE_DOCUMENT: g_app_info_set_as_default_for_type(item, "application/pdf", NULL); break; case DA_TYPE_WORD: g_app_info_set_as_default_for_type(item, "application/vnd.oasis.opendocument.text", NULL); g_app_info_set_as_default_for_type(item, "application/msword", NULL); g_app_info_set_as_default_for_type(item, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", NULL); break; case DA_TYPE_SPREADSHEET: g_app_info_set_as_default_for_type(item, "application/vnd.oasis.opendocument.spreadsheet", NULL); g_app_info_set_as_default_for_type(item, "application/vnd.ms-excel", NULL); g_app_info_set_as_default_for_type(item, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", NULL); break; case DA_TYPE_TERMINAL: g_settings_set_string (capplet->terminal_settings, TERMINAL_KEY, g_app_info_get_executable (item)); break; case DA_TYPE_VISUAL: g_settings_set_string (capplet->visual_settings, VISUAL_KEY, g_app_info_get_executable (item)); break; case DA_TYPE_MOBILITY: g_settings_set_string (capplet->mobility_settings, MOBILITY_KEY, g_app_info_get_executable (item)); break; default: break; } } }
static void fill_combo_box(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list, gchar* mime) { guint index = 0; GList* entry; GtkTreeModel* model; GtkCellRenderer* renderer; GtkTreeIter iter; GdkPixbuf* pixbuf; GAppInfo* default_app; default_app = NULL; if (g_strcmp0(mime, "terminal") == 0) { GSettings *terminal_settings = g_settings_new (TERMINAL_SCHEMA); gchar *default_terminal = g_settings_get_string (terminal_settings, TERMINAL_KEY); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; if (g_strcmp0 (g_app_info_get_executable (item), default_terminal) == 0) { default_app = item; } } g_free (default_terminal); g_object_unref (terminal_settings); } else if (g_strcmp0(mime, "visual") == 0) { GSettings *visual_settings = g_settings_new (VISUAL_SCHEMA); gchar *default_visual = g_settings_get_string (visual_settings, VISUAL_KEY); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; if (g_strcmp0 (g_app_info_get_executable (item), default_visual) == 0) { default_app = item; } } g_free (default_visual); g_object_unref (visual_settings); } else if (g_strcmp0(mime, "mobility") == 0) { GSettings *mobility_settings = g_settings_new (MOBILITY_SCHEMA); gchar *default_mobility = g_settings_get_string (mobility_settings, MOBILITY_KEY); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; if (g_strcmp0 (g_app_info_get_executable (item), default_mobility) == 0) { default_app = item; } } g_free (default_mobility); g_object_unref (mobility_settings); } else { default_app = g_app_info_get_default_for_type (mime, FALSE); } if (theme == NULL) { theme = gtk_icon_theme_get_default(); } model = GTK_TREE_MODEL(gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING)); gtk_combo_box_set_model(combo_box, model); renderer = gtk_cell_renderer_pixbuf_new(); /* Not all cells have a pixbuf, this prevents the combo box to shrink */ gtk_cell_renderer_set_fixed_size(renderer, -1, 22); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer, "pixbuf", PIXBUF_COL, NULL); renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer, "text", TEXT_COL, NULL); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; /* Icon */ GIcon* icon = g_app_info_get_icon(item); gchar* icon_name = g_icon_to_string(icon); if (icon_name == NULL) { /* Default icon */ icon_name = g_strdup("binary"); } pixbuf = gtk_icon_theme_load_icon(theme, icon_name, 22, 0, NULL); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, PIXBUF_COL, pixbuf, TEXT_COL, g_app_info_get_display_name(item), ID_COL, g_app_info_get_id(item), ICONAME_COL, icon_name, -1); if (pixbuf) { g_object_unref(pixbuf); } /* Set the index for the default app */ if (default_app != NULL && g_app_info_equal(item, default_app)) { gtk_combo_box_set_active(combo_box, index); } g_free(icon_name); index++; } }
char * mpl_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context, GAppInfo *info, GList *files) { static int sequence = 0; #if 0 GdkAppLaunchContextPrivate *priv; #endif GdkDisplay *display; GdkScreen *screen; int files_count; char *description; char *icon_name; const char *binary_name; const char *application_id; char *screen_str; char *workspace_str; #if 0 GIcon *icon; #endif guint32 timestamp; char *startup_id; #if 0 priv = GDK_APP_LAUNCH_CONTEXT (context)->priv; if (priv->screen) { screen = priv->screen; display = gdk_screen_get_display (priv->screen); } else if (priv->display) { display = priv->display; screen = gdk_display_get_default_screen (display); } else { display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); } #else display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); #endif files_count = g_list_length (files); if (files_count == 0) description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info)); else if (files_count == 1) description = g_strdup_printf (_("Opening %s"), get_display_name (files->data)); else description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Opening %d Item", "Opening %d Items", files_count), files_count); icon_name = NULL; #if 0 if (priv->icon_name) icon_name = g_strdup (priv->icon_name); else { icon = NULL; if (priv->icon != NULL) icon = g_object_ref (priv->icon); else if (files_count == 1) icon = get_icon (files->data); if (icon == NULL) { icon = g_app_info_get_icon (info); g_object_ref (icon); } if (icon) icon_name = gicon_to_string (icon); g_object_unref (icon); } #endif binary_name = g_app_info_get_executable (info); #if 0 timestamp = priv->timestamp; if (timestamp == GDK_CURRENT_TIME) #endif timestamp = gdk_x11_display_get_user_time (display); screen_str = g_strdup_printf ("%d", gdk_screen_get_number (screen)); #if 0 if (priv->workspace > -1) workspace_str = g_strdup_printf ("%d", priv->workspace); else #endif workspace_str = NULL; if (G_IS_DESKTOP_APP_INFO (info)) application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info)); else application_id = NULL; startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long)getpid (), g_get_host_name (), binary_name, sequence++, (unsigned long)timestamp); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", g_app_info_get_name (info), "SCREEN", screen_str, "BIN", binary_name, "ICON", icon_name, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", NULL, /* FIXME */ "APPLICATION_ID", application_id, NULL); g_free (description); g_free (screen_str); g_free (workspace_str); g_free (icon_name); add_startup_timeout (screen, startup_id); return startup_id; }
static gboolean exo_open_uri (const gchar *uri, GError **error) { GFile *file; gchar *scheme; GFileInfo *file_info; gboolean succeed = FALSE; gboolean retval = FALSE; GFileType file_type; const gchar *content_type; GAppInfo *app_info; gchar *path; const gchar *executable; GList fake_list; const gchar * const *schemes; GError *err = NULL; guint i; g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); #ifndef NDEBUG schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); scheme = g_strjoinv (", ", (gchar **) schemes); g_debug ("vfs supported schemes: %s", scheme); g_free (scheme); #endif file = g_file_new_for_uri (uri); scheme = g_file_get_uri_scheme (file); /* try to launch common schemes for know preferred applications */ if (scheme != NULL && exo_open_uri_known_category (uri, scheme, &retval)) { g_free (scheme); return retval; } /* handle the uri as a file, maybe we succeed... */ file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &err); if (file_info != NULL) { file_type = g_file_info_get_file_type (file_info); if (file_type == G_FILE_TYPE_DIRECTORY) { #ifndef NDEBUG g_debug ("file is directory, use filemanager"); #endif /* directories should go fine with a file manager */ retval = exo_open_launch_category ("FileManager", uri); succeed = TRUE; } else { content_type = g_file_info_get_content_type (file_info); #ifndef NDEBUG g_debug ("content type=%s", content_type); #endif if (G_LIKELY (content_type)) { /* try to find a suitable application for this content type */ path = g_file_get_path (file); app_info = g_app_info_get_default_for_type (content_type, path == NULL); g_free (path); if (app_info != NULL) { /* make sure we don't loop somehow */ executable = g_app_info_get_executable (app_info); #ifndef NDEBUG g_debug ("default executable=%s", executable); #endif if (executable == NULL || strcmp (executable, "exo-open") != 0) { fake_list.data = (gpointer) uri; fake_list.prev = fake_list.next = NULL; /* launch it */ retval = g_app_info_launch_uris (app_info, &fake_list, NULL, &err); succeed = TRUE; } g_object_unref (G_OBJECT (app_info)); } } } g_object_unref (G_OBJECT (file_info)); } else if (err != NULL && scheme != NULL && err->code == G_IO_ERROR_NOT_MOUNTED) { /* check if the scheme is supported by gio */ schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); if (G_LIKELY (schemes != NULL)) { for (i = 0; schemes[i] != NULL; i++) { /* found scheme, open in file manager */ if (strcmp (scheme, schemes[i]) == 0) { retval = succeed = exo_open_launch_category ("FileManager", uri); break; } } } } g_object_unref (G_OBJECT (file)); /* our last try... */ if (!succeed) { #ifndef NDEBUG g_debug ("nothing worked, try ftp(s) or gtk_show_uri()"); #endif /* try ftp uris if the file manager/gio failed to recognize it */ if (scheme != NULL && (strcmp (scheme, "ftp") == 0 || strcmp (scheme, "ftps") == 0)) retval = exo_open_launch_category ("WebBrowser", uri); else retval = gtk_show_uri (NULL, uri, 0, error); } g_free (scheme); if (!retval && error != NULL) *error = err; else if (err != NULL) g_error_free (err); return retval; }
static gboolean gtk_app_chooser_widget_add_section (GtkAppChooserWidget *self, const gchar *heading_title, gboolean show_headings, gboolean recommended, gboolean fallback, GList *applications, GList *exclude_apps) { gboolean heading_added, unref_icon; GtkTreeIter iter; GAppInfo *app; gchar *app_string, *bold_string; GIcon *icon; GList *l; gboolean retval; retval = FALSE; heading_added = FALSE; bold_string = g_strdup_printf ("<b>%s</b>", heading_title); for (l = applications; l != NULL; l = l->next) { app = l->data; if (self->priv->content_type != NULL && !g_app_info_supports_uris (app) && !g_app_info_supports_files (app)) continue; if (g_list_find_custom (exclude_apps, app, (GCompareFunc) compare_apps_func)) continue; if (!heading_added && show_headings) { gtk_list_store_append (self->priv->program_list_store, &iter); gtk_list_store_set (self->priv->program_list_store, &iter, COLUMN_HEADING_TEXT, bold_string, COLUMN_HEADING, TRUE, COLUMN_RECOMMENDED, recommended, COLUMN_FALLBACK, fallback, -1); heading_added = TRUE; } app_string = g_markup_printf_escaped ("%s", g_app_info_get_name (app) != NULL ? g_app_info_get_name (app) : ""); icon = g_app_info_get_icon (app); unref_icon = FALSE; if (icon == NULL) { icon = g_themed_icon_new ("application-x-executable"); unref_icon = TRUE; } gtk_list_store_append (self->priv->program_list_store, &iter); gtk_list_store_set (self->priv->program_list_store, &iter, COLUMN_APP_INFO, app, COLUMN_GICON, icon, COLUMN_NAME, g_app_info_get_name (app), COLUMN_DESC, app_string, COLUMN_EXEC, g_app_info_get_executable (app), COLUMN_HEADING, FALSE, COLUMN_RECOMMENDED, recommended, COLUMN_FALLBACK, fallback, -1); retval = TRUE; g_free (app_string); if (unref_icon) g_object_unref (icon); } g_free (bold_string); return retval; }