diff -ur gnucash-2.2.4.orig/lib/libqof/backend/file/qsf-backend.c gnucash-2.2.4/lib/libqof/backend/file/qsf-backend.c --- gnucash-2.2.4.orig/lib/libqof/backend/file/qsf-backend.c 2008-03-02 16:26:47 +0300 +++ gnucash-2.2.4/lib/libqof/backend/file/qsf-backend.c 2008-03-31 12:49:39 +0400 @@ -236,9 +236,9 @@ return; } if (g_str_has_prefix (book_path, "file:")) { - qsf_be->fullpath = g_strdup (book_path + 5); + qsf_be->fullpath = filename_from_utf8 (book_path + 5); } else { - qsf_be->fullpath = g_strdup (book_path); + qsf_be->fullpath = filename_from_utf8 (book_path); } if(create_if_nonexistent) { diff -ur gnucash-2.2.4.orig/lib/libqof/qof/qofutil.c gnucash-2.2.4/lib/libqof/qof/qofutil.c --- gnucash-2.2.4.orig/lib/libqof/qof/qofutil.c 2008-03-02 16:26:47 +0300 +++ gnucash-2.2.4/lib/libqof/qof/qofutil.c 2008-03-31 12:49:39 +0400 @@ -80,6 +80,33 @@ return retval; } +gchar* +filename_from_utf8 (const gchar *filename) +{ + gchar *fn; + + if(g_utf8_validate(filename, -1, NULL)) + fn = g_filename_from_utf8(filename, -1, NULL, NULL, NULL); + else + fn = g_strdup(filename); + + return fn; +} + +gchar * +filename_to_utf8 (const gchar *oldname) +{ + gchar *file_name = NULL; // need to be freed after use + + if (!g_utf8_validate(oldname, -1, NULL)) { + file_name = g_filename_to_utf8(oldname, -1, NULL, NULL, NULL); + if(!file_name) + g_warning("Some characters in the filename is neither UTF-8 nor your local encoding\n"); + } + if(!file_name) + file_name = g_strdup(oldname); +} + gint safe_strcmp (const gchar * da, const gchar * db) { diff -ur gnucash-2.2.4.orig/lib/libqof/qof/qofutil.h gnucash-2.2.4/lib/libqof/qof/qofutil.h --- gnucash-2.2.4.orig/lib/libqof/qof/qofutil.h 2008-03-02 16:26:47 +0300 +++ gnucash-2.2.4/lib/libqof/qof/qofutil.h 2008-03-31 12:49:39 +0400 @@ -176,6 +176,9 @@ * equal, > 0 if da compares after db. */ gint qof_utf8_strcasecmp (const gchar *da, const gchar *db); +gchar* filename_from_utf8 (const gchar *filename); +gchar* filename_to_utf8 (const gchar *filename); + /** The safe_strcmp compares strings da and db the same way that strcmp() does, except that either may be null. This routine assumes that a non-null string is always greater than a null string. diff -ur gnucash-2.2.4.orig/src/backend/file/gnc-backend-file.c gnucash-2.2.4/src/backend/file/gnc-backend-file.c --- gnucash-2.2.4.orig/src/backend/file/gnc-backend-file.c 2008-03-02 16:24:27 +0300 +++ gnucash-2.2.4/src/backend/file/gnc-backend-file.c 2008-03-31 12:49:39 +0400 @@ -202,11 +202,14 @@ gboolean ignore_lock, gboolean create_if_nonexistent) { FileBackend *be = (FileBackend*) be_start; + gchar *tmpfile; ENTER (" "); /* Make sure the directory is there */ - be->fullpath = xaccResolveFilePath(book_id); + tmpfile = xaccResolveFilePath(book_id); + be->fullpath = filename_from_utf8(tmpfile); + g_free(tmpfile); if (NULL == be->fullpath) { qof_backend_set_error (be_start, ERR_FILEIO_FILE_NOT_FOUND); diff -ur gnucash-2.2.4.orig/src/bin/gnucash-bin.c gnucash-2.2.4/src/bin/gnucash-bin.c --- gnucash-2.2.4.orig/src/bin/gnucash-bin.c 2008-03-02 16:24:51 +0300 +++ gnucash-2.2.4/src/bin/gnucash-bin.c 2008-03-31 12:49:39 +0400 @@ -426,7 +426,7 @@ get_file_to_load() { if (file_to_load) - return g_strdup(file_to_load); + return filename_to_utf8(file_to_load); else return gnc_history_get_last(); } diff -ur gnucash-2.2.4.orig/src/core-utils/gnc-gkeyfile-utils.c gnucash-2.2.4/src/core-utils/gnc-gkeyfile-utils.c --- gnucash-2.2.4.orig/src/core-utils/gnc-gkeyfile-utils.c 2008-03-02 16:24:24 +0300 +++ gnucash-2.2.4/src/core-utils/gnc-gkeyfile-utils.c 2008-03-31 12:49:39 +0400 @@ -262,6 +262,33 @@ #endif +static inline gchar* +filename_from_utf8 (const gchar *filename) +{ + gchar *fn; + + if(g_utf8_validate(filename, -1, NULL)) + fn = g_filename_from_utf8(filename, -1, NULL, NULL, NULL); + else + fn = g_strdup(filename); + + return fn; +} + +static inline gchar * +filename_to_utf8 (const gchar *oldname) +{ + gchar *file_name = NULL; // need to be freed after use + + if (!g_utf8_validate(oldname, -1, NULL)) { + file_name = g_filename_to_utf8(oldname, -1, NULL, NULL, NULL); + if(!file_name) + g_warning("Some characters in the filename is neither UTF-8 nor your local encoding\n"); + } + if(!file_name) + file_name = g_strdup(oldname); +} + GKeyFile * gnc_key_file_load_from_file (const gchar *filename, gboolean ignore_error, @@ -289,8 +316,12 @@ key_file = NULL; } - if (!ignore_error) - g_warning("Unable to read file %s: %s\n", filename, error->message); + if (!ignore_error) { + gchar *fname_utf8 = filename_to_utf8(filename); + + g_warning("Unable to read file %s: %s\n", fname_utf8, error->message); + g_free(fname_utf8); + } g_propagate_error(caller_error, error); return key_file; } @@ -301,7 +332,7 @@ GKeyFile *key_file, GError **error) { - gchar *contents; + gchar *contents, *fname_local; gint fd; extern int errno; gint length; @@ -315,7 +346,9 @@ contents = g_key_file_to_data(key_file, NULL, NULL); length = strlen(contents); - fd = g_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); + fname_local = filename_from_utf8(filename); + fd = g_open(fname_local, O_WRONLY | O_CREAT | O_TRUNC, 0666); + g_free(fname_local); if (fd == -1) { if (error) { *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), diff -ur gnucash-2.2.4.orig/src/engine/gnc-filepath-utils.c gnucash-2.2.4/src/engine/gnc-filepath-utils.c --- gnucash-2.2.4.orig/src/engine/gnc-filepath-utils.c 2008-03-02 16:26:08 +0300 +++ gnucash-2.2.4/src/engine/gnc-filepath-utils.c 2008-03-31 12:49:39 +0400 @@ -60,14 +60,16 @@ MakeHomeDir (void) { const gchar *home; - char *path; + char *path, *utfpath; char *data; /* Punt. Can't figure out where home is. */ home = g_get_home_dir(); if (!home) return; - path = g_build_filename(home, ".gnucash", (gchar *)NULL); + utfpath = g_build_filename(home, ".gnucash", (gchar *)NULL); + path = filename_from_utf8(utfpath); + g_free(utfpath); if (!g_file_test(path, G_FILE_TEST_EXISTS)) { @@ -220,14 +222,17 @@ int j; for(j = 0; gens[i](pathbuf, j) ; j++) { - gchar *fullpath = g_build_filename(pathbuf, filefrag, (gchar *)NULL); + gchar *utfpath = g_build_filename(pathbuf, filefrag, (gchar *)NULL); + gchar *fullpath = filename_from_utf8(utfpath); if (g_file_test(fullpath, G_FILE_TEST_IS_REGULAR)) { LEAVE("found %s", fullpath); - return fullpath; + g_free (fullpath); + return utfpath; } g_free (fullpath); + g_free (utfpath); } } /* OK, we didn't find the file. */ @@ -422,7 +427,12 @@ gchar * gnc_build_book_path (const gchar *filename) { - return g_build_filename(gnc_dotgnucash_dir(), "books", filename, (gchar *)NULL); + gchar *fn, *fname; + + fn = g_build_filename(gnc_dotgnucash_dir(), "books", filename, (gchar *)NULL); + fname = filename_from_utf8(fn); + g_free(fn); + return fname; } /* =============================== END OF FILE ========================== */ diff -ur gnucash-2.2.4.orig/src/engine/TransLog.c gnucash-2.2.4/src/engine/TransLog.c --- gnucash-2.2.4.orig/src/engine/TransLog.c 2008-03-02 16:26:12 +0300 +++ gnucash-2.2.4/src/engine/TransLog.c 2008-03-31 12:49:39 +0400 @@ -107,7 +107,7 @@ if (!basepath) return; g_free (log_base_name); - log_base_name = g_strdup (basepath); + log_base_name = filename_from_utf8 (basepath); if (trans_log) { xaccCloseLog(); diff -ur gnucash-2.2.4.orig/src/gnome-utils/gnc-file.c gnucash-2.2.4/src/gnome-utils/gnc-file.c --- gnucash-2.2.4.orig/src/gnome-utils/gnc-file.c 2008-03-02 16:25:54 +0300 +++ gnucash-2.2.4/src/gnome-utils/gnc-file.c 2008-03-31 12:49:39 +0400 @@ -129,9 +129,12 @@ gtk_dialog_add_button(GTK_DIALOG(file_box), okbutton, GTK_RESPONSE_ACCEPT); - if (starting_dir) + if (starting_dir) { + char *local_starting_dir = g_filename_from_utf8(starting_dir, -1, NULL, NULL, NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (file_box), - starting_dir); + local_starting_dir); + g_free(local_starting_dir); + } gtk_window_set_modal(GTK_WINDOW(file_box), TRUE); /* @@ -172,7 +175,7 @@ /* nope, a local file name */ internal_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (file_box)); } - file_name = g_strdup(internal_name); + file_name = filename_to_utf8(internal_name); } gtk_widget_destroy(GTK_WIDGET(file_box)); LEAVE("%s", file_name ? file_name : "(null)"); --- gnucash-2.2.4/src/gnome/gnc-plugin-basic-commands.c.orig 2008-03-02 16:26:02 +0300 +++ gnucash-2.2.4/src/gnome/gnc-plugin-basic-commands.c 2008-03-31 13:17:52 +0400 @@ -370,12 +370,13 @@ ENTER (" "); qof_event_suspend(); - filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (fs)); + filename = filename_to_utf8(gtk_file_selection_get_filename(GTK_FILE_SELECTION (fs))); gtk_widget_destroy((GtkWidget*) fs); first_session = gnc_get_current_session(); original = qof_session_get_book(first_session); qsf_session = qof_session_new(); qof_session_begin(qsf_session, filename, TRUE, FALSE); + g_free(filename); qof_session_load(qsf_session, NULL); err = qof_session_get_error(qsf_session); if (err != ERR_BACKEND_NO_ERR) {