gboolean libre_impuesto_file_launch_handler (const char *mime_type, GFile *file, guint32 user_time) { GAppInfo *app = NULL; gboolean ret = FALSE; g_return_val_if_fail (file != NULL, FALSE); if (mime_type != NULL) { app = g_app_info_get_default_for_type (mime_type, FALSE); } else { GFileInfo *file_info; char *type; /* Sniff mime type and check if it's safe to open */ file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); if (file_info == NULL) { return FALSE; } type = g_strdup (g_file_info_get_content_type (file_info)); g_object_unref (file_info); if (type != NULL && type[0] != '\0' && libre_impuesto_file_check_mime (type) == LIBRE_IMPUESTO_MIME_PERMISSION_SAFE) { /* FIXME rename tmp file to right extension ? */ app = g_app_info_get_default_for_type (type, FALSE); } g_free (type); } if (app != NULL) { GList *list = NULL; list = g_list_append (list, file); ret = libre_impuesto_file_launch_application (app, list, user_time, NULL); g_list_free (list); } else ret = FALSE; return ret; }
/* Helper function to decide what EphyDownloadActionType should be the * default for the download. This implies that you want something to * happen, this function will never return EPHY_DOWNLOAD_ACTION_NONE. */ static EphyDownloadActionType decide_action_from_mime (EphyDownload *ephy_download) { char *content_type; GAppInfo *helper_app = NULL; EphyDownloadActionType action; content_type = ephy_download_get_content_type (ephy_download); if (content_type) { helper_app = g_app_info_get_default_for_type (content_type, FALSE); if (helper_app) action = EPHY_DOWNLOAD_ACTION_OPEN; g_free (content_type); } /* Downloads that have no content_type, or no helper_app, are * considered unsafe/unable to open. Default them to BROWSE_TO. */ if (helper_app == NULL) action = EPHY_DOWNLOAD_ACTION_BROWSE_TO; else g_object_unref (helper_app); return action; }
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); }
gboolean panel_show_uri_force_mime_type (GdkScreen *screen, const gchar *uri, const gchar *mime_type, guint32 timestamp, GError **error) { GFile *file; GAppInfo *app; gboolean ret; g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (mime_type != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); file = g_file_new_for_uri (uri); app = g_app_info_get_default_for_type (mime_type, !g_file_is_native (file)); g_object_unref (file); if (app == NULL) { /* no application for the mime type, so let's fallback on * automatic detection */ return panel_show_uri (screen, uri, timestamp, error); } ret = panel_app_info_launch_uri (app, uri, screen, timestamp, error); g_object_unref (app); return ret; }
static void custom_entry_changed_cb (GtkEditable *entry, gpointer user_data) { NemoMimeApplicationChooser *chooser = user_data; const gchar *entry_text = gtk_entry_get_text (GTK_ENTRY (entry)); if (g_strcmp0 (entry_text, "") != 0) { GAppInfo *default_app; gchar *cl = g_strdup_printf ("%s", entry_text); GAppInfo *info = g_app_info_create_from_commandline (cl, NULL, G_APP_INFO_CREATE_NONE, NULL); default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE); gtk_widget_set_sensitive (chooser->details->set_as_default_button, !g_app_info_equal (info, default_app)); gtk_widget_set_sensitive (chooser->details->add_button, app_info_can_add (info, chooser->details->content_type)); g_object_unref (default_app); if (chooser->details->custom_info != NULL) { g_object_unref (chooser->details->custom_info); chooser->details->custom_info = NULL; } chooser->details->custom_info = info; } else { if (chooser->details->custom_info != NULL) { g_object_unref (chooser->details->custom_info); chooser->details->custom_info = NULL; } gtk_widget_set_sensitive (chooser->details->set_as_default_button, FALSE); gtk_widget_set_sensitive (chooser->details->add_button, FALSE); } }
gboolean ev_attachment_open (EvAttachment *attachment, GdkScreen *screen, guint32 timestamp, GError **error) { GAppInfo *app_info; gboolean retval = FALSE; g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), FALSE); if (!attachment->priv->app) { app_info = g_app_info_get_default_for_type (attachment->priv->mime_type, FALSE); attachment->priv->app = app_info; } if (!attachment->priv->app) { g_set_error (error, EV_ATTACHMENT_ERROR, 0, _("Couldn't open attachment “%s”"), attachment->priv->name); return FALSE; } if (attachment->priv->tmp_file) { retval = ev_attachment_launch_app (attachment, screen, timestamp, error); } else { char *template; GFile *file;
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)); }
static VALUE appinfo_get_default_for_type(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self) { VALUE content_type, must_support_uris; rb_scan_args(argc, argv, "11", &content_type, &must_support_uris); return GOBJ2RVAL_UNREF(g_app_info_get_default_for_type(RVAL2CSTR(content_type), RVAL2CBOOL(must_support_uris))); }
static gboolean display_file (GFile* file, const char* content_type) { gboolean res = TRUE; GAppInfo *app = g_app_info_get_default_for_type(content_type, FALSE); GList* list = g_list_append(NULL, file); res = g_app_info_launch(app, list, NULL, NULL); g_list_free(list); g_object_unref(app); return res; }
void open_file_with_application (GFile *file) { GAppInfo *application; gchar *primary; GFileInfo *info; gchar *uri_scheme; const char *content; gboolean local = FALSE; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (!info) return; uri_scheme = g_file_get_uri_scheme (file); if (g_ascii_strcasecmp(uri_scheme,"file") == 0) local = TRUE; content = g_file_info_get_content_type (info); application = g_app_info_get_default_for_type (content, TRUE); if (!application) { primary = g_strdup_printf (_("Could not open folder \"%s\""), g_file_get_basename (file)); message (primary, _("There is no installed viewer capable " "of displaying the folder."), GTK_MESSAGE_ERROR, baobab.window); g_free (primary); } else { GList *uris = NULL; gchar *uri; uri = g_file_get_uri (file); uris = g_list_append (uris, uri); g_app_info_launch_uris (application, uris, NULL, NULL); g_list_free (uris); g_free (uri); } g_free (uri_scheme); if (application) g_object_unref (application); g_object_unref (info); }
static void button_clicked_callback (GtkWidget *button, NautilusXContentBar *bar) { GAppInfo *default_app; if (bar->priv->x_content_type == NULL || bar->priv->mount == NULL) return; default_app = g_app_info_get_default_for_type (bar->priv->x_content_type, FALSE); if (default_app != NULL) { nautilus_autorun_launch_for_mount (bar->priv->mount, default_app); g_object_unref (default_app); } }
static void application_selected_cb (GtkAppChooserWidget *widget, GAppInfo *info, gpointer user_data) { NemoMimeApplicationChooser *chooser = user_data; GAppInfo *default_app; default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE); gtk_widget_set_sensitive (chooser->details->set_as_default_button, !g_app_info_equal (info, default_app)); gtk_widget_set_sensitive (chooser->details->add_button, app_info_can_add (info, chooser->details->content_type)); g_object_unref (default_app); }
static void application_selected_cb (GtkAppChooserWidget *widget, GAppInfo *info, gpointer user_data) { NemoMimeApplicationChooser *chooser = user_data; GAppInfo *default_app; default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE); gtk_widget_set_sensitive (chooser->details->set_as_default_button, !g_app_info_equal (info, default_app)); gtk_widget_set_sensitive (chooser->details->add_button, app_info_can_add (info, chooser->details->content_type)); gtk_entry_set_text (GTK_ENTRY (chooser->details->custom_entry), ""); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (chooser->details->file_button), ""); g_object_unref (default_app); }
gboolean panel_show_uri_force_mime_type (GdkScreen *screen, const gchar *uri, const gchar *mime_type, guint32 timestamp, GError **error) { GFile *file; GAppInfo *appinfo; gboolean ret; GdkDisplay *display; GdkAppLaunchContext *context; GList *uris; g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (mime_type != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); file = g_file_new_for_uri (uri); appinfo = g_app_info_get_default_for_type (mime_type, !g_file_is_native (file)); g_object_unref (file); if (appinfo == NULL) { /* no application for the mime type, so let's fallback on * automatic detection */ return panel_show_uri (screen, uri, timestamp, error); } uris = g_list_append (NULL, (gpointer)uri); display = gdk_screen_get_display (screen); context = gdk_display_get_app_launch_context (display); ret = g_app_info_launch_uris (appinfo, uris, G_APP_LAUNCH_CONTEXT(context), error); g_object_unref (context); g_list_free (uris); g_object_unref (appinfo); return ret; }
NS_IMETHODIMP nsGIOService::GetAppForMimeType(const nsACString& aMimeType, nsIGIOMimeApp** aApp) { *aApp = nsnull; char *content_type = get_content_type_from_mime_type(PromiseFlatCString(aMimeType).get()); if (!content_type) return NS_ERROR_FAILURE; GAppInfo *app_info = g_app_info_get_default_for_type(content_type, false); if (app_info) { nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info); NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(*aApp = mozApp); } else { g_free(content_type); return NS_ERROR_FAILURE; } g_free(content_type); return NS_OK; }
static void photos_local_item_constructed (GObject *object) { PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (object); GAppInfo *default_app = NULL; const gchar *default_app_name; const gchar *mime_type; G_OBJECT_CLASS (photos_local_item_parent_class)->constructed (object); mime_type = photos_base_item_get_mime_type (PHOTOS_BASE_ITEM (self)); if (mime_type == NULL) return; default_app = g_app_info_get_default_for_type (mime_type, FALSE); if (default_app == NULL) return; default_app_name = g_app_info_get_name (default_app); photos_base_item_set_default_app_name (PHOTOS_BASE_ITEM (self), default_app_name); g_object_unref (default_app); }
/** * 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; }
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; }
void nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar, const char *x_content_type) { char *message; char *description; GAppInfo *default_app; g_free (bar->priv->x_content_type); bar->priv->x_content_type = g_strdup (x_content_type); description = g_content_type_get_description (x_content_type); /* Customize greeting for well-known x-content types */ if (strcmp (x_content_type, "x-content/audio-cdda") == 0) { message = g_strdup (_("These files are on an Audio CD.")); } else if (strcmp (x_content_type, "x-content/audio-dvd") == 0) { message = g_strdup (_("These files are on an Audio DVD.")); } else if (strcmp (x_content_type, "x-content/video-dvd") == 0) { message = g_strdup (_("These files are on a Video DVD.")); } else if (strcmp (x_content_type, "x-content/video-vcd") == 0) { message = g_strdup (_("These files are on a Video CD.")); } else if (strcmp (x_content_type, "x-content/video-svcd") == 0) { message = g_strdup (_("These files are on a Super Video CD.")); } else if (strcmp (x_content_type, "x-content/image-photocd") == 0) { message = g_strdup (_("These files are on a Photo CD.")); } else if (strcmp (x_content_type, "x-content/image-picturecd") == 0) { message = g_strdup (_("These files are on a Picture CD.")); } else if (strcmp (x_content_type, "x-content/image-dcf") == 0) { message = g_strdup (_("The media contains digital photos.")); } else if (strcmp (x_content_type, "x-content/audio-player") == 0) { message = g_strdup (_("These files are on a digital audio player.")); } else if (strcmp (x_content_type, "x-content/software") == 0) { message = g_strdup (_("The media contains software.")); } else { /* fallback to generic greeting */ message = g_strdup_printf (_("The media has been detected as \"%s\"."), description); } gtk_label_set_text (GTK_LABEL (bar->priv->label), message); gtk_widget_show (bar->priv->label); /* TODO: We really need a GtkBrowserBackButton-ish widget here.. until then, we only * show the default application. */ default_app = g_app_info_get_default_for_type (x_content_type, FALSE); if (default_app != NULL) { char *button_text; const char *name; GIcon *icon; GtkWidget *image; icon = g_app_info_get_icon (default_app); if (icon != NULL) { GdkPixbuf *pixbuf; int icon_size; NautilusIconInfo *icon_info; icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON); icon_info = nautilus_icon_info_lookup (icon, icon_size); pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size); image = gtk_image_new_from_pixbuf (pixbuf); g_object_unref (pixbuf); g_object_unref (icon_info); } else { image = NULL; } name = g_app_info_get_name (default_app); button_text = g_strdup_printf (_("Open %s"), name); gtk_button_set_image (GTK_BUTTON (bar->priv->button), image); gtk_button_set_label (GTK_BUTTON (bar->priv->button), button_text); gtk_widget_show (bar->priv->button); g_free (button_text); g_object_unref (default_app); } else { gtk_widget_hide (bar->priv->button); } g_free (message); g_free (description); }
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 = 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) { icon_name = g_strdup("binary"); // default icon } 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 */ if (default_app != NULL && g_app_info_equal(item, default_app)) { gtk_combo_box_set_active(combo_box, index); } g_free(icon_name); index++; } }
/** * fm_app_chooser_combo_box_setup * @combo: a #GtkComboBox * @mime_type: (allow-none): a #FmMimeType to select application * @apps: (allow-none) (element-type GAppInfo): custom list of applications * @sel: (allow-none): a selected application in @apps * * Setups a combobox for selecting default application either for * specified mime-type or from a list of pre-defined applications. * If @mime_type is %NULL, and @sel is provided and found in the @apps, * then it will be selected. If @mime_type is not %NULL then default * application for the @mime_type will be selected. * When set up, the combobox will contain a list of available applications. * * Since: 0.1.5 */ void fm_app_chooser_combo_box_setup(GtkComboBox* combo, FmMimeType* mime_type, GList* apps, GAppInfo* sel) { FmAppChooserComboBoxData* data = g_slice_new0(FmAppChooserComboBoxData); GtkListStore* store = gtk_list_store_new(3, G_TYPE_ICON, G_TYPE_STRING, G_TYPE_APP_INFO); GtkTreeIter it; GList* l; GtkCellRenderer* render; gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo)); render = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), render, FALSE); gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), render, "gicon", 0); render = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), render, FALSE); gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), render, "text", 1); if(mime_type) { data->mime_type = fm_mime_type_ref(mime_type); apps = g_app_info_get_all_for_type(fm_mime_type_get_type(data->mime_type)); sel = g_app_info_get_default_for_type(fm_mime_type_get_type(data->mime_type), FALSE); } for(l = apps; l; l = l->next) { GAppInfo* app = G_APP_INFO(l->data); gtk_list_store_insert_with_values(store, &it, -1, 0, g_app_info_get_icon(app), 1, g_app_info_get_name(app), 2, app, -1); if(sel && g_app_info_equal(app, sel)) { /* this is the initially selected app */ data->initial_sel_iter = it; data->initial_sel_app = (GAppInfo*)g_object_ref(app); } } if(mime_type) /* if this list is retrived with g_app_info_get_all_for_type() */ { if(apps) { g_list_foreach(apps, (GFunc)g_object_unref, NULL); g_list_free(apps); } if(sel) g_object_unref(sel); } gtk_list_store_append(store, &it); /* separator */ data->separator_iter = it; /* other applications */ gtk_list_store_insert_with_values(store, &it, -1, 0, NULL, 1, _("Customize"), // FIXME: should be "Customize..." 2, NULL, -1); data->other_apps_iter = it; gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store)); if(data->initial_sel_iter.user_data) /* intital selection is set */ { data->prev_sel_iter = data->initial_sel_iter; gtk_combo_box_set_active_iter(combo, &data->initial_sel_iter); } gtk_combo_box_set_row_separator_func(combo, is_row_separator, data, NULL); g_object_unref(store); g_signal_connect(combo, "changed", G_CALLBACK(on_app_selected), data); g_object_set_qdata_full(G_OBJECT(combo), fm_qdata_id, data, free_data); }
int main (int argc, char *argv[]) { GError *error; GOptionContext *context; const char *mimetype; setlocale (LC_ALL, ""); g_type_init (); error = NULL; context = g_option_context_new (_("- get/set handler for <mimetype>")); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL || query == set) { g_printerr (_("Error parsing commandline options: %s\n"), error ? error->message : _("Specify one of --query and --set")); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); if (error != NULL) g_error_free(error); return 1; } if (query && argc != 2) { g_printerr (_("Must specify a single mime-type.\n")); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } else if (set && argc != 3) { g_printerr (_("Must specify the mime-type followed by the default handler.\n")); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } mimetype = argv[1]; if (query) { GAppInfo *info; info = g_app_info_get_default_for_type (mimetype, FALSE); if (!info) { g_print (_("No default applications for '%s'\n"), mimetype); } else { GList *list, *l; g_print (_("Default application for '%s': %s\n"), mimetype, g_app_info_get_id (info)); g_object_unref (info); list = g_app_info_get_all_for_type (mimetype); if (list != NULL) g_print (_("Registered applications:\n")); for (l = list; l != NULL; l = l->next) { info = l->data; g_print ("\t%s\n", g_app_info_get_id (info)); g_object_unref (info); } g_list_free (list); list = g_app_info_get_recommended_for_type (mimetype); if (list != NULL) g_print (_("Recommended applications:\n")); for (l = list; l != NULL; l = l->next) { info = l->data; g_print ("\t%s\n", g_app_info_get_id (info)); g_object_unref (info); } g_list_free (list); } } else if (set) { const char *handler; GAppInfo *info; handler = argv[2]; info = get_app_info_for_id (handler); if (info == NULL) { g_printerr (_("Failed to load info for handler '%s'\n"), handler); return 1; } if (g_app_info_set_as_default_for_type (info, mimetype, &error) == FALSE) { g_printerr (_("Failed to set '%s' as the default handler for '%s': %s\n"), handler, mimetype, error->message); g_error_free (error); g_object_unref (info); return 1; } g_print ("Set %s as the default for %s\n", g_app_info_get_id (info), mimetype); g_object_unref (info); } return 0; }
static void gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self) { GList *all_applications = NULL; GList *recommended_apps = NULL; GList *fallback_apps = NULL; GList *exclude_apps = NULL; GAppInfo *default_app = NULL; gboolean show_headings; gboolean apps_added; show_headings = TRUE; apps_added = FALSE; if (self->priv->show_all) show_headings = FALSE; if (self->priv->show_default && self->priv->content_type) { default_app = g_app_info_get_default_for_type (self->priv->content_type, FALSE); if (default_app != NULL) { gtk_app_chooser_add_default (self, default_app); apps_added = TRUE; exclude_apps = g_list_prepend (exclude_apps, default_app); } } #ifndef G_OS_WIN32 if ((self->priv->content_type && self->priv->show_recommended) || self->priv->show_all) { if (self->priv->content_type) recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type); apps_added |= gtk_app_chooser_widget_add_section (self, _("Recommended Applications"), show_headings, !self->priv->show_all, /* mark as recommended */ FALSE, /* mark as fallback */ recommended_apps, exclude_apps); exclude_apps = g_list_concat (exclude_apps, g_list_copy (recommended_apps)); } if ((self->priv->content_type && self->priv->show_fallback) || self->priv->show_all) { if (self->priv->content_type) fallback_apps = g_app_info_get_fallback_for_type (self->priv->content_type); apps_added |= gtk_app_chooser_widget_add_section (self, _("Related Applications"), show_headings, FALSE, /* mark as recommended */ !self->priv->show_all, /* mark as fallback */ fallback_apps, exclude_apps); exclude_apps = g_list_concat (exclude_apps, g_list_copy (fallback_apps)); } #endif if (self->priv->show_other || self->priv->show_all) { all_applications = g_app_info_get_all (); apps_added |= gtk_app_chooser_widget_add_section (self, _("Other Applications"), show_headings, FALSE, FALSE, all_applications, exclude_apps); } if (!apps_added) update_no_applications_label (self); gtk_widget_set_visible (self->priv->no_apps, !apps_added); gtk_app_chooser_widget_select_first (self); if (default_app != NULL) g_object_unref (default_app); g_list_free_full (all_applications, g_object_unref); g_list_free_full (recommended_apps, g_object_unref); g_list_free_full (fallback_apps, g_object_unref); g_list_free (exclude_apps); }
/** * shell_doc_system_open: * @system: A #ShellDocSystem * @info: A #GtkRecentInfo * @workspace: Open on this workspace, or -1 for default * * Launch the default application associated with the mime type of * @info, using its uri. */ void shell_doc_system_open (ShellDocSystem *system, GtkRecentInfo *info, int workspace) { GFile *file; GAppInfo *app_info; gboolean needs_uri; GAppLaunchContext *context; context = shell_global_create_app_launch_context (shell_global_get ()); if (workspace != -1) gdk_app_launch_context_set_desktop ((GdkAppLaunchContext *)context, workspace); file = g_file_new_for_uri (gtk_recent_info_get_uri (info)); needs_uri = g_file_get_path (file) == NULL; g_object_unref (file); app_info = g_app_info_get_default_for_type (gtk_recent_info_get_mime_type (info), needs_uri); if (app_info != NULL) { GList *uris; uris = g_list_prepend (NULL, (gpointer)gtk_recent_info_get_uri (info)); g_app_info_launch_uris (app_info, uris, context, NULL); g_list_free (uris); } else { char *app_name; const char *app_exec; char *app_exec_quoted; guint count; time_t time; app_name = gtk_recent_info_last_application (info); if (gtk_recent_info_get_application_info (info, app_name, &app_exec, &count, &time)) { GRegex *regex; /* TODO: Change this once better support for creating GAppInfo is added to GtkRecentInfo, as right now this relies on the fact that the file uri is already a part of appExec, so we don't supply any files to app_info.launch(). The 'command line' passed to create_from_command_line is allowed to contain '%<something>' macros that are expanded to file name / icon name, etc, so we need to escape % as %% */ regex = g_regex_new ("%", 0, 0, NULL); app_exec_quoted = g_regex_replace (regex, app_exec, -1, 0, "%%", 0, NULL); g_regex_unref (regex); app_info = g_app_info_create_from_commandline (app_exec_quoted, NULL, 0, NULL); g_free (app_exec_quoted); /* The point of passing an app launch context to launch() is mostly to get startup notification and associated benefits like the app appearing on the right desktop; but it doesn't really work for now because with the way we create the appInfo we aren't reading the application's desktop file, and thus don't find the StartupNotify=true in it. So, despite passing the app launch context, no startup notification occurs. */ g_app_info_launch (app_info, NULL, context, NULL); } g_free (app_name); } g_object_unref (context); }
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; }
int main (int argc, char *argv[]) { GError *error; GOptionContext *context; const char *mimetype; gchar *param; gchar *summary; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); error = NULL; param = g_strdup_printf ("%s [%s]", _("MIMETYPE"), _("HANDLER")); summary = _("Get or set the handler for a mime-type."); context = g_option_context_new (param); g_option_context_set_summary (context, summary); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); g_free (param); if (error != NULL || (query == set && !show_version)) { g_printerr (_("Error parsing commandline options: %s\n"), error ? error->message : _("Specify either --query or --set")); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); if (error != NULL) g_error_free (error); return 1; } if (show_version) { g_print (PACKAGE_STRING "\n"); return 0; } if (query && argc != 2) { g_printerr (_("Must specify a single mime-type.\n")); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } else if (set && argc != 3) { g_printerr (_("Must specify the mime-type followed by the default handler.\n")); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } mimetype = argv[1]; if (query) { GAppInfo *info; info = g_app_info_get_default_for_type (mimetype, FALSE); if (!info) { g_print (_("No default applications for '%s'\n"), mimetype); } else { GList *list, *l; g_print (_("Default application for '%s': %s\n"), mimetype, g_app_info_get_id (info)); g_object_unref (info); list = g_app_info_get_all_for_type (mimetype); if (list != NULL) g_print (_("Registered applications:\n")); else g_print (_("No registered applications\n")); for (l = list; l != NULL; l = l->next) { info = l->data; g_print ("\t%s\n", g_app_info_get_id (info)); g_object_unref (info); } g_list_free (list); list = g_app_info_get_recommended_for_type (mimetype); if (list != NULL) g_print (_("Recommended applications:\n")); else g_print (_("No recommended applications\n")); for (l = list; l != NULL; l = l->next) { info = l->data; g_print ("\t%s\n", g_app_info_get_id (info)); g_object_unref (info); } g_list_free (list); } } else if (set) { const char *handler; GAppInfo *info; handler = argv[2]; info = get_app_info_for_id (handler); if (info == NULL) { g_printerr (_("Failed to load info for handler '%s'\n"), handler); return 1; } if (g_app_info_set_as_default_for_type (info, mimetype, &error) == FALSE) { g_printerr (_("Failed to set '%s' as the default handler for '%s': %s\n"), handler, mimetype, error->message); g_error_free (error); g_object_unref (info); return 1; } g_print ("Set %s as the default for %s\n", g_app_info_get_id (info), mimetype); g_object_unref (info); } return 0; }
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++; } }
gboolean fm_launch_files(GAppLaunchContext* ctx, GList* file_infos, FmFileLauncher* launcher, gpointer user_data) { GList* l; GHashTable* hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); GList* folders = NULL; FmFileInfo* fi; GError* err = NULL; GAppInfo* app; for(l = file_infos; l; l=l->next) { GList* fis; fi = (FmFileInfo*)l->data; if(fm_file_info_is_dir(fi)) folders = g_list_prepend(folders, fi); else { /* FIXME: handle shortcuts, such as the items in menu:// */ if(fm_path_is_native(fi->path)) { char* filename; if(fm_file_info_is_desktop_entry(fi)) { /* if it's a desktop entry file, directly launch it. */ filename = fm_path_to_str(fi->path); if(!fm_launch_desktop_entry(ctx, filename, NULL, &err)) { if(launcher->error) launcher->error(ctx, err, user_data); g_error_free(err); err = NULL; } continue; } else if(fm_file_info_is_executable_type(fi)) { /* if it's an executable file, directly execute it. */ filename = fm_path_to_str(fi->path); /* FIXME: we need to use eaccess/euidaccess here. */ if(g_file_test(filename, G_FILE_TEST_IS_EXECUTABLE)) { app = g_app_info_create_from_commandline(filename, NULL, 0, NULL); if(app) { if(!g_app_info_launch(app, NULL, ctx, &err)) { if(launcher->error) launcher->error(ctx, err, user_data); g_error_free(err); err = NULL; } g_object_unref(app); continue; } } g_free(filename); } } else /* not a native path */ { if(fm_file_info_is_shortcut(fi) && !fm_file_info_is_dir(fi)) { /* FIXME: special handling for shortcuts */ if(fm_path_is_xdg_menu(fi->path) && fi->target) { if(!fm_launch_desktop_entry(ctx, fi->target, NULL, &err)) { if(launcher->error) launcher->error(ctx, err, user_data); g_error_free(err); err = NULL; } continue; } } } if(fi->type && fi->type->type) { fis = g_hash_table_lookup(hash, fi->type->type); fis = g_list_prepend(fis, fi); g_hash_table_insert(hash, fi->type->type, fis); } } } if(g_hash_table_size(hash) > 0) { GHashTableIter it; const char* type; GList* fis; g_hash_table_iter_init(&it, hash); while(g_hash_table_iter_next(&it, &type, &fis)) { GAppInfo* app = g_app_info_get_default_for_type(type, FALSE); if(!app) { if(launcher->get_app) { FmMimeType* mime_type = ((FmFileInfo*)fis->data)->type; app = launcher->get_app(fis, mime_type, user_data, NULL); } } if(app) { for(l=fis; l; l=l->next) { char* uri; fi = (FmFileInfo*)l->data; uri = fm_path_to_uri(fi->path); l->data = uri; } fis = g_list_reverse(fis); g_app_info_launch_uris(app, fis, ctx, err); /* free URI strings */ g_list_foreach(fis, (GFunc)g_free, NULL); g_object_unref(app); } g_list_free(fis); } } g_hash_table_destroy(hash); if(folders) { folders = g_list_reverse(folders); if(launcher->open_folder) { launcher->open_folder(ctx, folders, user_data, &err); if(err) { if(launcher->error) launcher->error(ctx, err, user_data); g_error_free(err); err = NULL; } } g_list_free(folders); } return TRUE; }
/* returns TRUE if a folder window should be opened */ static gboolean do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAutorunOpenWindow open_window_func, gpointer user_data) { AutorunDialogData *data; GtkWidget *dialog; GtkWidget *hbox; GtkWidget *vbox; GtkWidget *label; GtkWidget *combo_box; GtkWidget *always_check_button; GtkWidget *eject_button; GtkWidget *image; char *markup; char *content_description; char *mount_name; GIcon *icon; GdkPixbuf *pixbuf; CajaIconInfo *icon_info; int icon_size; gboolean user_forced_dialog; gboolean pref_ask; gboolean pref_start_app; gboolean pref_ignore; gboolean pref_open_folder; char *media_greeting; gboolean ret; ret = FALSE; mount_name = NULL; if (g_content_type_is_a (x_content_type, "x-content/win32-software")) { /* don't pop up the dialog anyway if the content type says * windows software. */ goto out; } user_forced_dialog = is_shift_pressed (); caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder); pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder; if (user_forced_dialog) { goto show_dialog; } if (!pref_ask && !pref_ignore && !pref_open_folder) { GAppInfo *app_info; app_info = g_app_info_get_default_for_type (x_content_type, FALSE); if (app_info != NULL) { caja_autorun_launch_for_mount (mount, app_info); } goto out; } if (pref_open_folder) { ret = TRUE; goto out; } if (pref_ignore) { goto out; } show_dialog: mount_name = g_mount_get_name (mount); dialog = gtk_dialog_new (); hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (hbox), 12); icon = g_mount_get_icon (mount); icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG); icon_info = caja_icon_info_lookup (icon, icon_size); pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size); g_object_unref (icon_info); g_object_unref (icon); image = gtk_image_new_from_pixbuf (pixbuf); gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0); /* also use the icon on the dialog */ gtk_window_set_title (GTK_WINDOW (dialog), mount_name); gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); g_object_unref (pixbuf); vbox = gtk_vbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); label = gtk_label_new (NULL); /* Customize greeting for well-known x-content types */ if (strcmp (x_content_type, "x-content/audio-cdda") == 0) { media_greeting = _("You have just inserted an Audio CD."); } else if (strcmp (x_content_type, "x-content/audio-dvd") == 0) { media_greeting = _("You have just inserted an Audio DVD."); } else if (strcmp (x_content_type, "x-content/video-dvd") == 0) { media_greeting = _("You have just inserted a Video DVD."); } else if (strcmp (x_content_type, "x-content/video-vcd") == 0) { media_greeting = _("You have just inserted a Video CD."); } else if (strcmp (x_content_type, "x-content/video-svcd") == 0) { media_greeting = _("You have just inserted a Super Video CD."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank CD."); } else if (strcmp (x_content_type, "x-content/blank-dvd") == 0) { media_greeting = _("You have just inserted a blank DVD."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank Blu-Ray disc."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank HD DVD."); } else if (strcmp (x_content_type, "x-content/image-photocd") == 0) { media_greeting = _("You have just inserted a Photo CD."); } else if (strcmp (x_content_type, "x-content/image-picturecd") == 0) { media_greeting = _("You have just inserted a Picture CD."); } else if (strcmp (x_content_type, "x-content/image-dcf") == 0) { media_greeting = _("You have just inserted a medium with digital photos."); } else if (strcmp (x_content_type, "x-content/audio-player") == 0) { media_greeting = _("You have just inserted a digital audio player."); } else if (g_content_type_is_a (x_content_type, "x-content/software")) { media_greeting = _("You have just inserted a medium with software intended to be automatically started."); } else { /* fallback to generic greeting */ media_greeting = _("You have just inserted a medium."); } markup = g_strdup_printf ("<big><b>%s %s</b></big>", media_greeting, _("Choose what application to launch.")); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); label = gtk_label_new (NULL); content_description = g_content_type_get_description (x_content_type); markup = g_strdup_printf (_("Select how to open \"%s\" and whether to perform this action in the future for other media of type \"%s\"."), mount_name, content_description); g_free (content_description); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); data = g_new0 (AutorunDialogData, 1); data->dialog = dialog; data->mount = g_object_ref (mount); data->remember = !pref_ask; data->selected_ignore = pref_ignore; data->x_content_type = g_strdup (x_content_type); data->selected_app = g_app_info_get_default_for_type (x_content_type, FALSE); data->open_window_func = open_window_func; data->user_data = user_data; combo_box = gtk_combo_box_new (); caja_autorun_prepare_combo_box (combo_box, x_content_type, FALSE, TRUE, FALSE, autorun_combo_changed, data); g_signal_connect (G_OBJECT (combo_box), "key-press-event", G_CALLBACK (combo_box_enter_ok), dialog); gtk_box_pack_start (GTK_BOX (vbox), combo_box, TRUE, TRUE, 0); always_check_button = gtk_check_button_new_with_mnemonic (_("_Always perform this action")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (always_check_button), data->remember); g_signal_connect (G_OBJECT (always_check_button), "toggled", G_CALLBACK (autorun_always_toggled), data); gtk_box_pack_start (GTK_BOX (vbox), always_check_button, TRUE, TRUE, 0); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); if (g_mount_can_eject (mount)) { GtkWidget *eject_image; eject_button = gtk_button_new_with_mnemonic (_("_Eject")); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "media-eject", caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON), 0, NULL); eject_image = gtk_image_new_from_pixbuf (pixbuf); g_object_unref (pixbuf); gtk_button_set_image (GTK_BUTTON (eject_button), eject_image); data->should_eject = TRUE; } else { eject_button = gtk_button_new_with_mnemonic (_("_Unmount")); data->should_eject = FALSE; } gtk_dialog_add_action_widget (GTK_DIALOG (dialog), eject_button, AUTORUN_DIALOG_RESPONSE_EJECT); gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), eject_button, TRUE); /* show the dialog */ gtk_widget_show_all (dialog); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (autorun_dialog_response), data); g_signal_connect (G_OBJECT (data->mount), "unmounted", G_CALLBACK (autorun_dialog_mount_unmounted), data); out: g_free (mount_name); return ret; }
void caja_autorun_prepare_combo_box (GtkWidget *combo_box, const char *x_content_type, gboolean include_ask, gboolean include_open_with_other_app, gboolean update_settings, CajaAutorunComboBoxChanged changed_cb, gpointer user_data) { GList *l; GList *app_info_list; GAppInfo *default_app_info; GtkListStore *list_store; GtkTreeIter iter; GdkPixbuf *pixbuf; int icon_size; int set_active; int n; int num_apps; gboolean pref_ask; gboolean pref_start_app; gboolean pref_ignore; gboolean pref_open_folder; CajaAutorunComboBoxData *data; GtkCellRenderer *renderer; gboolean new_data; caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder); pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder; icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); set_active = -1; data = NULL; new_data = TRUE; app_info_list = g_app_info_get_all_for_type (x_content_type); default_app_info = g_app_info_get_default_for_type (x_content_type, FALSE); num_apps = g_list_length (app_info_list); list_store = gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_APP_INFO, G_TYPE_STRING, G_TYPE_INT); /* no apps installed */ if (num_apps == 0) { gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), GTK_STOCK_DIALOG_ERROR, icon_size, 0, NULL); /* TODO: integrate with PackageKit-mate to find applications */ gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("No applications found"), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK, -1); g_object_unref (pixbuf); } else { if (include_ask) { gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), GTK_STOCK_DIALOG_QUESTION, icon_size, 0, NULL); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("Ask what to do"), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK, -1); g_object_unref (pixbuf); } gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), GTK_STOCK_CLOSE, icon_size, 0, NULL); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("Do Nothing"), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_IGNORE, -1); g_object_unref (pixbuf); gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "folder-open", icon_size, 0, NULL); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("Open Folder"), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OPEN_FOLDER, -1); g_object_unref (pixbuf); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, NULL, COLUMN_AUTORUN_NAME, NULL, COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, NULL, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP, -1); for (l = app_info_list, n = include_ask ? 4 : 3; l != NULL; l = l->next, n++) { GIcon *icon; CajaIconInfo *icon_info; char *open_string; GAppInfo *app_info = l->data; /* we deliberately ignore should_show because some apps might want * to install special handlers that should be hidden in the regular * application launcher menus */ icon = g_app_info_get_icon (app_info); icon_info = caja_icon_info_lookup (icon, icon_size); pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size); g_object_unref (icon_info); open_string = g_strdup_printf (_("Open %s"), g_app_info_get_display_name (app_info)); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, open_string, COLUMN_AUTORUN_APP_INFO, app_info, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_APP, -1); if (pixbuf != NULL) { g_object_unref (pixbuf); } g_free (open_string); if (g_app_info_equal (app_info, default_app_info)) { set_active = n; } } } if (include_open_with_other_app) { gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, NULL, COLUMN_AUTORUN_NAME, NULL, COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, NULL, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP, -1); gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "application-x-executable", icon_size, 0, NULL); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("Open with other Application..."), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OTHER_APP, -1); g_object_unref (pixbuf); } if (default_app_info != NULL) { g_object_unref (default_app_info); } g_list_foreach (app_info_list, (GFunc) g_object_unref, NULL); g_list_free(app_info_list); gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (list_store)); g_object_unref (G_OBJECT (list_store)); gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box)); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer, "pixbuf", COLUMN_AUTORUN_PIXBUF, 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", COLUMN_AUTORUN_NAME, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box), combo_box_separator_func, NULL, NULL); if (num_apps == 0) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0); gtk_widget_set_sensitive (combo_box, FALSE); } else { gtk_widget_set_sensitive (combo_box, TRUE); if (pref_ask && include_ask) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0); } else if (pref_ignore) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0); } else if (pref_open_folder) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 2 : 1); } else if (set_active != -1) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), set_active); } else { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0); } /* See if we have an old data around */ data = g_object_get_data (G_OBJECT (combo_box), "caja_autorun_combobox_data"); if (data) { new_data = FALSE; g_free (data->x_content_type); } else { data = g_new0 (CajaAutorunComboBoxData, 1); } data->x_content_type = g_strdup (x_content_type); data->include_ask = include_ask; data->include_open_with_other_app = include_open_with_other_app; data->update_settings = update_settings; data->changed_cb = changed_cb; data->user_data = user_data; data->combo_box = combo_box; if (data->changed_signal_id == 0) { data->changed_signal_id = g_signal_connect (G_OBJECT (combo_box), "changed", G_CALLBACK (combo_box_changed), data); } } if (new_data) { g_object_set_data_full (G_OBJECT (combo_box), "caja_autorun_combobox_data", data, (GDestroyNotify) caja_autorun_combobox_data_destroy); } }