[dia] Bug 570592 - allow to pass filenames as URIs



commit 9a5f438d4b3e718c8ab0efe01d08ee2c3a0d9a86
Author: Hans Breuer <hans breuer org>
Date:   Sun Jan 24 16:06:02 2010 +0100

    Bug 570592 - allow to pass filenames as URIs
    
    The command line has to have locale encoding, usually not utf-8 on windows. To pass filenames not representable in the locale encoding hey have to be encoded as URIs (ASCII charset is assumed to be representable in every locale).

 app/app_procs.c |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/app/app_procs.c b/app/app_procs.c
index 2ddeb4a..7f4851e 100644
--- a/app/app_procs.c
+++ b/app/app_procs.c
@@ -775,9 +775,30 @@ app_init (int argc, char **argv)
     /* second level check of command line options, existance of input files etc. */
     if (filenames) {
       while (filenames[i] != NULL) {
-	gchar *filename = g_filename_to_utf8 (filenames[i], -1, NULL, NULL, NULL);
-	gchar *testpath = g_path_is_absolute(filename) ? filename :
-	  g_build_filename(input_directory ? input_directory : ".", filename, NULL);
+	gchar *filename; 
+	gchar *testpath;	  
+
+	if (g_str_has_prefix (filenames[i], "file://")) {
+	  filename = g_filename_from_uri (filenames[i], NULL, NULL);
+	  if (!g_utf8_validate(filename, -1, NULL)) {
+	    gchar *tfn = filename;
+	    filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
+	    g_free(tfn);
+	  }
+	} else
+	  filename = g_filename_to_utf8 (filenames[i], -1, NULL, NULL, NULL);
+
+	if (!filename) {
+	  g_print (_("Filename conversion failed: %s\n"), filenames[i]);
+	  continue;
+	}
+
+	if (g_path_is_absolute(filename))
+	  testpath = filename;
+	else
+	  testpath = g_build_filename(input_directory ? input_directory : ".", filename, NULL);
+
+	/* we still have a problem here, if GLib's file name encoding would not be utf-8 */
 	if (g_file_test (testpath, G_FILE_TEST_IS_REGULAR))
 	  files = g_slist_append(files, filename);
 	else {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]