static SCM gnc_get_export_type_choice (SCM export_types) { GList * choices = NULL; gboolean bad = FALSE; GList * node; int choice; SCM tail; if (!scm_is_list (export_types)) return SCM_BOOL_F; for (tail = export_types; !scm_is_null (tail); tail = SCM_CDR (tail)) { SCM pair = SCM_CAR (tail); const gchar * name; SCM scm; if (!scm_is_pair (pair)) { g_warning ("unexpected list element"); bad = TRUE; break; } scm = SCM_CAR (pair); if (!scm_is_string (scm)) { g_warning ("unexpected pair element"); bad = TRUE; break; } name = scm_to_locale_string (scm); choices = g_list_prepend (choices, g_strdup (name)); } if (!bad) { choices = g_list_reverse (choices); choices = g_list_prepend (choices, g_strdup (_("HTML"))); //I believe by extending the below logic I can add option for exporting the files to Google docs choice = gnc_choose_radio_option_dialog (NULL, _("Choose export format"), _("Choose the export format for this report:"), NULL, 0, choices); } else choice = -1; for (node = choices; node; node = node->next) g_free (node->data); g_list_free (choices); if (choice < 0) return SCM_BOOL_F; if (choice == 0) return SCM_BOOL_T; choice--; if (choice >= scm_ilength (export_types)) return SCM_BOOL_F; return scm_list_ref (export_types, scm_int2num (choice)); //this part dealing with the filepath static char * gnc_get_export_filename (SCM choice) { char * filepath; struct stat statbuf; char * title; const gchar * type; int rc; char * default_dir; if (choice == SCM_BOOL_T) type = _("HTML"); else { type = scm_to_locale_string(SCM_CAR (choice)); } /* %s is the type of what is about to be saved, e.g. "HTML". */ title = g_strdup_printf (_("Save %s To File"), type); default_dir = gnc_get_default_directory(GCONF_DIR_REPORT); filepath = gnc_file_dialog (title, NULL, default_dir, GNC_FILE_DIALOG_EXPORT); /* Try to test for extension on file name, add if missing */ if (g_strrstr(filepath, ".") == NULL) filepath = g_strconcat(filepath, ".", g_ascii_strdown(type, strlen(type)), NULL); g_free (title); g_free (default_dir); if (!filepath) return NULL; default_dir = g_path_get_dirname(filepath); gnc_set_default_directory (GCONF_DIR_REPORT, default_dir); g_free(default_dir); rc = g_stat (filepath, &statbuf); /* Check for an error that isn't a non-existent file. */ if (rc != 0 && errno != ENOENT) { /* %s is the strerror(3) string of the error that occurred. */ const char *format = _("You cannot save to that filename.\n\n%s"); gnc_error_dialog (NULL, format, strerror(errno)); g_free(filepath); return NULL; } /* Check for a file that isn't a regular file. */ if (rc == 0 && !S_ISREG (statbuf.st_mode)) { const char *message = _("You cannot save to that file."); gnc_error_dialog (NULL, "%s", message); g_free(filepath); return NULL; } if (rc == 0) { const char *format = _("The file %s already exists. " "Are you sure you want to overwrite it?"); if (!gnc_verify_dialog (NULL, FALSE, format, filepath)) { g_free(filepath); return NULL; } } return filepath; } }