spacepaste

  1.  
  2. static SCM
  3. gnc_get_export_type_choice (SCM export_types)
  4. {
  5. GList * choices = NULL;
  6. gboolean bad = FALSE;
  7. GList * node;
  8. int choice;
  9. SCM tail;
  10. if (!scm_is_list (export_types))
  11. return SCM_BOOL_F;
  12. for (tail = export_types; !scm_is_null (tail); tail = SCM_CDR (tail))
  13. {
  14. SCM pair = SCM_CAR (tail);
  15. const gchar * name;
  16. SCM scm;
  17. if (!scm_is_pair (pair))
  18. {
  19. g_warning ("unexpected list element");
  20. bad = TRUE;
  21. break;
  22. }
  23. scm = SCM_CAR (pair);
  24. if (!scm_is_string (scm))
  25. {
  26. g_warning ("unexpected pair element");
  27. bad = TRUE;
  28. break;
  29. }
  30. name = scm_to_locale_string (scm);
  31. choices = g_list_prepend (choices, g_strdup (name));
  32. }
  33. if (!bad)
  34. {
  35. choices = g_list_reverse (choices);
  36. choices = g_list_prepend (choices, g_strdup (_("HTML")));
  37. //I believe by extending the below logic I can add option for exporting the files to Google docs
  38. choice = gnc_choose_radio_option_dialog
  39. (NULL, _("Choose export format"),
  40. _("Choose the export format for this report:"),
  41. NULL, 0, choices);
  42. }
  43. else
  44. choice = -1;
  45. for (node = choices; node; node = node->next)
  46. g_free (node->data);
  47. g_list_free (choices);
  48. if (choice < 0)
  49. return SCM_BOOL_F;
  50. if (choice == 0)
  51. return SCM_BOOL_T;
  52. choice--;
  53. if (choice >= scm_ilength (export_types))
  54. return SCM_BOOL_F;
  55. return scm_list_ref (export_types, scm_int2num (choice));
  56. //this part dealing with the filepath
  57. static char *
  58. gnc_get_export_filename (SCM choice)
  59. {
  60. char * filepath;
  61. struct stat statbuf;
  62. char * title;
  63. const gchar * type;
  64. int rc;
  65. char * default_dir;
  66. if (choice == SCM_BOOL_T)
  67. type = _("HTML");
  68. else
  69. {
  70. type = scm_to_locale_string(SCM_CAR (choice));
  71. }
  72. /* %s is the type of what is about to be saved, e.g. "HTML". */
  73. title = g_strdup_printf (_("Save %s To File"), type);
  74. default_dir = gnc_get_default_directory(GCONF_DIR_REPORT);
  75. filepath = gnc_file_dialog (title, NULL, default_dir, GNC_FILE_DIALOG_EXPORT);
  76. /* Try to test for extension on file name, add if missing */
  77. if (g_strrstr(filepath, ".") == NULL)
  78. filepath = g_strconcat(filepath, ".", g_ascii_strdown(type, strlen(type)), NULL);
  79. g_free (title);
  80. g_free (default_dir);
  81. if (!filepath)
  82. return NULL;
  83. default_dir = g_path_get_dirname(filepath);
  84. gnc_set_default_directory (GCONF_DIR_REPORT, default_dir);
  85. g_free(default_dir);
  86. rc = g_stat (filepath, &statbuf);
  87. /* Check for an error that isn't a non-existent file. */
  88. if (rc != 0 && errno != ENOENT)
  89. {
  90. /* %s is the strerror(3) string of the error that occurred. */
  91. const char *format = _("You cannot save to that filename.\n\n%s");
  92. gnc_error_dialog (NULL, format, strerror(errno));
  93. g_free(filepath);
  94. return NULL;
  95. }
  96. /* Check for a file that isn't a regular file. */
  97. if (rc == 0 && !S_ISREG (statbuf.st_mode))
  98. {
  99. const char *message = _("You cannot save to that file.");
  100. gnc_error_dialog (NULL, "%s", message);
  101. g_free(filepath);
  102. return NULL;
  103. }
  104. if (rc == 0)
  105. {
  106. const char *format = _("The file %s already exists. "
  107. "Are you sure you want to overwrite it?");
  108. if (!gnc_verify_dialog (NULL, FALSE, format, filepath))
  109. {
  110. g_free(filepath);
  111. return NULL;
  112. }
  113. }
  114. return filepath;
  115. }
  116. }
  117.