X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fxo-file.c;h=a241df396e81d7f4819d473c2bfd507fc7d7a05b;hb=78c2f8fa93f7adcb9157699c92b1498d878f66b2;hp=a052475c94b7c217f6d5b14b67f348ea284d9563;hpb=b3fe26e023d4f1cafbadd383574bc0971291f784;p=xournal.git diff --git a/src/xo-file.c b/src/xo-file.c index a052475..a241df3 100644 --- a/src/xo-file.c +++ b/src/xo-file.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "xournal.h" #include "xo-interface.h" @@ -81,6 +82,8 @@ gboolean save_journal(const char *filename) f = gzopen(filename, "w"); if (f==NULL) return FALSE; chk_attach_names(); + + setlocale(LC_NUMERIC, "C"); gzprintf(f, "\n" "Xournal document - see http://math.mit.edu/~auroux/software/xournal/\n" @@ -138,6 +141,7 @@ gboolean save_journal(const char *filename) tmpf = fopen(tmpfn, "w"); if (tmpf != NULL && fwrite(pdfbuf, 1, pdflen, tmpf) == pdflen) success = TRUE; + g_free(pdfbuf); fclose(tmpf); } if (!success) { @@ -178,6 +182,8 @@ gboolean save_journal(const char *filename) gzprintf(f, "\n"); } gzclose(f); + setlocale(LC_NUMERIC, ""); + return TRUE; } @@ -200,6 +206,13 @@ gboolean close_journal(void) use new_journal() to reinitialize them */ } +// sanitize a string containing floats, in case it may have , instead of . + +void cleanup_numeric(char *s) +{ + while (*s!=0) { if (*s==',') *s='.'; s++; } +} + // the XML parser functions for open_journal() struct Journal tmpJournal; @@ -252,13 +265,15 @@ void xoj_parser_start_element(GMarkupParseContext *context, while (*attribute_names!=NULL) { if (!strcmp(*attribute_names, "width")) { if (has_attr & 1) *error = xoj_invalid(); - tmpPage->width = strtod(*attribute_values, &ptr); + cleanup_numeric((gchar *)*attribute_values); + tmpPage->width = g_ascii_strtod(*attribute_values, &ptr); if (ptr == *attribute_values) *error = xoj_invalid(); has_attr |= 1; } else if (!strcmp(*attribute_names, "height")) { if (has_attr & 2) *error = xoj_invalid(); - tmpPage->height = strtod(*attribute_values, &ptr); + cleanup_numeric((gchar *)*attribute_values); + tmpPage->height = g_ascii_strtod(*attribute_values, &ptr); if (ptr == *attribute_values) *error = xoj_invalid(); has_attr |= 2; } @@ -373,7 +388,7 @@ void xoj_parser_start_element(GMarkupParseContext *context, else if (!strcmp(*attribute_names, "pageno")) { if (tmpPage->bg->type != BG_PDF || (has_attr & 32)) { *error = xoj_invalid(); return; } - tmpPage->bg->file_page_seq = strtod(*attribute_values, &ptr); + tmpPage->bg->file_page_seq = strtol(*attribute_values, &ptr, 10); if (ptr == *attribute_values) *error = xoj_invalid(); has_attr |= 32; } @@ -414,7 +429,8 @@ void xoj_parser_start_element(GMarkupParseContext *context, while (*attribute_names!=NULL) { if (!strcmp(*attribute_names, "width")) { if (has_attr & 1) *error = xoj_invalid(); - tmpItem->brush.thickness = strtod(*attribute_values, &ptr); + cleanup_numeric((gchar *)*attribute_values); + tmpItem->brush.thickness = g_ascii_strtod(*attribute_values, &ptr); if (ptr == *attribute_values) *error = xoj_invalid(); has_attr |= 1; } @@ -495,11 +511,12 @@ void xoj_parser_text(GMarkupParseContext *context, element_name = g_markup_parse_context_get_element(context); if (element_name == NULL) return; if (!strcmp(element_name, "stroke")) { + cleanup_numeric((gchar *)text); ptr = text; n = 0; while (text_len > 0) { realloc_cur_path(n/2 + 1); - ui.cur_path.coords[n] = strtod(text, (char **)(&ptr)); + ui.cur_path.coords[n] = g_ascii_strtod(text, (char **)(&ptr)); if (ptr == text) break; text_len -= (ptr - text); text = ptr; @@ -526,7 +543,7 @@ gboolean user_wants_second_chance(char **filename) if (response != GTK_RESPONSE_YES) return FALSE; dialog = gtk_file_chooser_dialog_new("Open PDF", GTK_WINDOW (winMain), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); filt_all = gtk_file_filter_new(); gtk_file_filter_set_name(filt_all, "All files"); @@ -537,7 +554,7 @@ gboolean user_wants_second_chance(char **filename) gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_pdf); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all); - if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) { + if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) { gtk_widget_destroy(dialog); return FALSE; } @@ -1107,3 +1124,93 @@ void bgpdf_update_bg(int pageno, struct BgPdfPage *bgpg) } } +// initialize the recent files list +void init_mru(void) +{ + int i; + gsize lfptr; + char s[5]; + GIOChannel *f; + gchar *str; + GIOStatus status; + + g_strlcpy(s, "mru0", 5); + for (s[3]='0', i=0; i0) { + str[lfptr] = 0; + ui.mru[i] = str; + i++; + } + } + if (f) { + g_io_channel_shutdown(f, FALSE, NULL); + g_io_channel_unref(f); + } + update_mru_menu(); +} + +void update_mru_menu(void) +{ + int i; + gboolean anyone = FALSE; + + for (i=0; i=1; j--) ui.mru[j] = ui.mru[j-1]; + ui.mru[0] = g_strdup(name); + update_mru_menu(); +} + +void delete_mru_entry(int which) +{ + int i; + + if (ui.mru[which]!=NULL) g_free(ui.mru[which]); + for (i=which+1;i