/** * Set default application for files with given extensions * @param fileExts string of space separated extensions * @return NS_OK when application was set as default for given extensions, * NS_ERROR_FAILURE otherwise */ NS_IMETHODIMP nsGIOMimeApp::SetAsDefaultForFileExtensions(nsACString const& fileExts) { GError *error = NULL; char *extensions = g_strdup(PromiseFlatCString(fileExts).get()); char *ext_pos = extensions; char *space_pos; while ( (space_pos = strchr(ext_pos, ' ')) || (*ext_pos != '\0') ) { if (space_pos) { *space_pos = '\0'; } g_app_info_set_as_default_for_extension(mApp, ext_pos, &error); if (error) { g_warning("Cannot set application as default for extension (%s): %s", ext_pos, error->message); g_error_free(error); g_free(extensions); return NS_ERROR_FAILURE; } if (space_pos) { ext_pos = space_pos + 1; } else { *ext_pos = '\0'; } } g_free(extensions); return NS_OK; }
static VALUE appinfo_set_as_default_for_extension(VALUE self, VALUE value) { GError *error = NULL; if (!g_app_info_set_as_default_for_extension(_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; }