mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-08-14 06:54:43 -05:00
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 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17062 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -21,3 +21,5 @@ void gnc_scm_log_debug(const gchar *);
|
||||
|
||||
%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 *);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -229,6 +229,21 @@ gnc_utf8_strip_invalid_strdup(const gchar* str)
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -81,6 +81,19 @@ void gnc_utf8_strip_invalid (gchar *str);
|
||||
* 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);
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,26 +36,33 @@
|
||||
|
||||
;; 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
|
||||
|
||||
Reference in New Issue
Block a user