/** * fm_choose_app_for_mime_type * @parent: (allow-none): a parent window * @mime_type: (allow-none): MIME type for list creation * @can_set_default: %TRUE if widget can set selected item as default for @mime_type * * Creates a dialog to choose application for @mime_type, lets user to * choose then returns the chosen application. * * If user creates custom application and @mime_type isn't %NULL then this * custom application will be added to list of supporting the @mime_type. * Otherwise that custom application file will be deleted after usage. * * Returns: user choise. * * Since: 0.1.0 */ GAppInfo* fm_choose_app_for_mime_type(GtkWindow* parent, FmMimeType* mime_type, gboolean can_set_default) { GAppInfo* app = NULL; GtkDialog* dlg = fm_app_chooser_dlg_new(mime_type, can_set_default); if(parent) gtk_window_set_transient_for(GTK_WINDOW(dlg), parent); if(gtk_dialog_run(dlg) == GTK_RESPONSE_OK) { gboolean set_default; app = fm_app_chooser_dlg_dup_selected_app(dlg, &set_default); if(app && mime_type && fm_mime_type_get_type(mime_type) && g_app_info_get_name(app)[0]) /* don't add empty name */ { GError* err = NULL; /* add this app to the mime-type */ #if GLIB_CHECK_VERSION(2, 27, 6) if(!g_app_info_set_as_last_used_for_type(app, #else if(!g_app_info_add_supports_type(app, #endif fm_mime_type_get_type(mime_type), &err)) { g_debug("error: %s", err->message); g_error_free(err); } /* if need to set default */ if(set_default) g_app_info_set_as_default_for_type(app, fm_mime_type_get_type(mime_type), NULL); }
static VALUE appinfo_add_supports_type(VALUE self, VALUE value) { GError *error = NULL; if (!g_app_info_add_supports_type(_SELF(self), RVAL2CSTR(value), &error)) rbgio_raise_error(error); return self; }
/* This will check if the application the user wanted exists will return that * application. If it doesn't exist, it will create one and return that. * It also sets the app info as the default for this type. */ static GAppInfo * add_or_find_application (CajaOpenWithDialog *dialog) { GAppInfo *app; char *app_name; const char *commandline; GError *error; gboolean success, should_set_default; char *message; GList *applications; error = NULL; app = NULL; if (dialog->details->selected_app_info) { app = g_object_ref (dialog->details->selected_app_info); } else { commandline = gtk_entry_get_text (GTK_ENTRY (dialog->details->entry)); app_name = get_app_name (commandline, &error); if (app_name != NULL) { app = g_app_info_create_from_commandline (commandline, app_name, G_APP_INFO_CREATE_NONE, &error); g_free (app_name); } } if (app == NULL) { message = g_strdup_printf (_("Could not add application to the application database: %s"), error->message); eel_show_error_dialog (_("Could not add application"), message, GTK_WINDOW (dialog)); g_free (message); g_error_free (error); return NULL; } should_set_default = (dialog->details->add_mode) || (!dialog->details->add_mode && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->details->checkbox))); success = TRUE; if (should_set_default) { if (dialog->details->content_type) { success = g_app_info_set_as_default_for_type (app, dialog->details->content_type, &error); } else { success = g_app_info_set_as_default_for_extension (app, dialog->details->extension, &error); } } else { applications = g_app_info_get_all_for_type (dialog->details->content_type); if (dialog->details->content_type && applications != NULL) { /* we don't care about reporting errors here */ g_app_info_add_supports_type (app, dialog->details->content_type, NULL); } if (applications != NULL) { g_list_foreach(applications, (GFunc) g_object_unref, NULL); g_list_free(applications); } } if (!success && should_set_default) { message = g_strdup_printf (_("Could not set application as the default: %s"), error->message); eel_show_error_dialog (_("Could not set as default application"), message, GTK_WINDOW (dialog)); g_free (message); g_error_free (error); } g_signal_emit_by_name (caja_signaller_get_current (), "mime_data_changed"); return app; }