AUDIT: r17062 - gnucash/trunk/src - Bug #450354: QIF importer now tries using locale-encoded path if UTF-8 encoded
Charles Day
cedayiv at cvs.gnucash.org
Tue Apr 1 18:07:28 EDT 2008
Author: cedayiv
Date: 2008-04-01 18:07:28 -0400 (Tue, 01 Apr 2008)
New Revision: 17062
Trac: http://svn.gnucash.org/trac/changeset/17062
Modified:
gnucash/trunk/src/core-utils/core-utils.i
gnucash/trunk/src/core-utils/core-utils.scm
gnucash/trunk/src/core-utils/gnc-glib-utils.c
gnucash/trunk/src/core-utils/gnc-glib-utils.h
gnucash/trunk/src/import-export/qif-import/qif-file.scm
Log:
Bug #450354: QIF importer now tries using locale-encoded path if UTF-8 encoded
path fails. Adds supports for use of non-ASCII filenames under Win32.
BP
Modified: gnucash/trunk/src/core-utils/core-utils.i
===================================================================
--- gnucash/trunk/src/core-utils/core-utils.i 2008-03-29 13:38:19 UTC (rev 17061)
+++ gnucash/trunk/src/core-utils/core-utils.i 2008-04-01 22:07:28 UTC (rev 17062)
@@ -21,3 +21,5 @@
%newobject gnc_utf8_strip_invalid_strdup;
gchar * gnc_utf8_strip_invalid_strdup(const gchar *);
+%newobject gnc_locale_from_utf8;
+gchar * gnc_locale_from_utf8(const gchar *);
Modified: gnucash/trunk/src/core-utils/core-utils.scm
===================================================================
--- gnucash/trunk/src/core-utils/core-utils.scm 2008-03-29 13:38:19 UTC (rev 17061)
+++ gnucash/trunk/src/core-utils/core-utils.scm 2008-04-01 22:07:28 UTC (rev 17062)
@@ -12,6 +12,7 @@
(re-export gnc-is-debugging)
(re-export g-find-program-in-path)
(re-export gnc-utf8-strip-invalid-strdup)
+(re-export gnc-locale-from-utf8)
(re-export gnc-scm-log-warn)
(re-export gnc-scm-log-error)
(re-export gnc-scm-log-msg)
Modified: gnucash/trunk/src/core-utils/gnc-glib-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-glib-utils.c 2008-03-29 13:38:19 UTC (rev 17061)
+++ gnucash/trunk/src/core-utils/gnc-glib-utils.c 2008-04-01 22:07:28 UTC (rev 17062)
@@ -229,6 +229,21 @@
return result;
}
+gchar *
+gnc_locale_from_utf8(const gchar* str)
+{
+ gchar * locale_str;
+ gsize bytes_written = 0;
+ GError * err = NULL;
+
+ /* Convert from UTF-8 to the encoding used in the current locale. */
+ locale_str = g_locale_from_utf8(str, -1, NULL, &bytes_written, &err);
+ if (err)
+ g_warning("g_locale_from_utf8 failed: %s", err->message);
+
+ return locale_str;
+}
+
GList*
gnc_g_list_map(GList* list, GncGMapFunc fn, gpointer user_data)
{
Modified: gnucash/trunk/src/core-utils/gnc-glib-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-glib-utils.h 2008-03-29 13:38:19 UTC (rev 17061)
+++ gnucash/trunk/src/core-utils/gnc-glib-utils.h 2008-04-01 22:07:28 UTC (rev 17062)
@@ -81,6 +81,19 @@
* caller. */
gchar *gnc_utf8_strip_invalid_strdup (const gchar* str);
+/** Converts a string from UTF-8 to the encoding used for strings
+ * in the current locale.
+ *
+ * This essentially is a wrapper for g_locale_from_utf8 that can
+ * be swigified for use with Scheme to avoid adding a dependency
+ * for guile-glib.
+ *
+ * @param str A pointer to a UTF-8 encoded string to be converted.
+ *
+ * @return A newly allocated string that has to be g_free'd by the
+ * caller. */
+gchar *gnc_locale_from_utf8(const gchar* str);
+
typedef gpointer (*GncGMapFunc)(gpointer data, gpointer user_data);
/**
Modified: gnucash/trunk/src/import-export/qif-import/qif-file.scm
===================================================================
--- gnucash/trunk/src/import-export/qif-import/qif-file.scm 2008-03-29 13:38:19 UTC (rev 17061)
+++ gnucash/trunk/src/import-export/qif-import/qif-file.scm 2008-04-01 22:07:28 UTC (rev 17062)
@@ -36,27 +36,34 @@
;; This procedure does all the work. We'll define it, then call it safely.
(define (private-read)
- (let* ((qstate-type #f)
- (current-xtn #f)
- (current-split #f)
- (current-account-name #f)
- (last-seen-account-name #f)
- (default-split #f)
- (first-xtn #f)
- (ignore-accounts #f)
- (return-val #t)
- (line #f)
- (tag #f)
- (value #f)
- (heinous-error #f)
- (missing-date-warned #f)
- (delimiters (string #\cr #\nl))
- (file-stats (stat path))
- (file-size (stat:size file-stats))
- (bytes-read 0))
+ (let ((qstate-type #f)
+ (current-xtn #f)
+ (current-split #f)
+ (current-account-name #f)
+ (last-seen-account-name #f)
+ (default-split #f)
+ (first-xtn #f)
+ (ignore-accounts #f)
+ (return-val #t)
+ (line #f)
+ (tag #f)
+ (value #f)
+ (heinous-error #f)
+ (missing-date-warned #f)
+ (delimiters (string #\cr #\nl))
+ (file-stats #f)
+ (file-size 0)
+ (bytes-read 0))
(qif-file:set-path! self path)
+ (if (not (access? path R_OK))
+ ;; A UTF-8 encoded path won't succeed on some systems, such as
+ ;; Windows XP. Try encoding the path according to the locale.
+ (set! path (gnc-locale-from-utf8 path)))
+ (set! file-stats (stat path))
+ (set! file-size (stat:size file-stats))
+
(if (> file-size 10000)
(begin
(set! progress-dialog (gnc-progress-dialog-new window #f))
More information about the gnucash-changes
mailing list