aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-12-24 21:43:31 +0000
committerChristian Grothoff <christian@grothoff.org>2011-12-24 21:43:31 +0000
commita5c0a556120d1ffa1aba820443c49b8c299cae44 (patch)
tree77ba7ae309e7ab1de05084f8a04aa9cf1520885d
parent380409315646ec606ce5b76bd42f54ac9e92dc1f (diff)
downloadgnunet-gtk-a5c0a556120d1ffa1aba820443c49b8c299cae44.tar.gz
gnunet-gtk-a5c0a556120d1ffa1aba820443c49b8c299cae44.zip
-LRN: make code more robust to LE and files not being in utf-8; 0001-Temporary-fix-for-charset-conversion patch from #2031
-rw-r--r--src/fs/gnunet-fs-gtk-common.c87
-rw-r--r--src/fs/gnunet-fs-gtk-common.h18
-rw-r--r--src/fs/gnunet-fs-gtk-download.c10
-rw-r--r--src/fs/gnunet-fs-gtk-edit_publish_dialog.c5
-rw-r--r--src/fs/gnunet-fs-gtk-event_handler.c36
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c6
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c10
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_file_publish.c53
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_open_directory.c10
-rw-r--r--src/fs/gnunet-fs-gtk.c21
-rw-r--r--src/include/gnunet_gtk.h28
-rw-r--r--src/lib/nls.c167
12 files changed, 391 insertions, 60 deletions
diff --git a/src/fs/gnunet-fs-gtk-common.c b/src/fs/gnunet-fs-gtk-common.c
index b2bf9b26..bd33d17a 100644
--- a/src/fs/gnunet-fs-gtk-common.c
+++ b/src/fs/gnunet-fs-gtk-common.c
@@ -26,6 +26,53 @@
26#include "gnunet-fs-gtk-common.h" 26#include "gnunet-fs-gtk-common.h"
27 27
28/** 28/**
29 * Converts metadata specified by @data of size @data_len
30 * and saved in format @format to UTF-8 encoded string.
31 * Works only for C-string and UTF8 metadata formats
32 * (returns NULL for everything else).
33 * Verifies UTF-8 strings.
34 *
35 * @param format format of the @data
36 * @param data data to convert
37 * @param data_len length of the data buffer (in bytes)
38 * @return NULL if can't be converted, allocated string otherwise,
39 * freeable with GNUNET_free* ().
40 */
41char *
42GNUNET_FS_GTK_dubious_meta_to_utf8 (enum EXTRACTOR_MetaFormat format, const char *data, size_t data_len)
43{
44 gchar *result = NULL;
45
46 if (format == EXTRACTOR_METAFORMAT_UTF8)
47 {
48 /* data must not contain NULLs (hence the -1) */
49 if (g_utf8_validate (data, data_len - 1, NULL))
50 result = GNUNET_strdup (data);
51 else
52 {
53 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
54 "Failed to validate supposedly utf-8 string `%s' of length %u, assuming it to be a C string\n",
55 data, data_len);
56 format = EXTRACTOR_METAFORMAT_C_STRING;
57 }
58 }
59 if (format == EXTRACTOR_METAFORMAT_C_STRING)
60 {
61 if (data_len > 0)
62 { /* There are no guarantees that data is NULL-terminated, AFAIU,
63 * so let's play it safe, shall we?
64 */
65 char *data_copy = GNUNET_malloc (data_len + 1);
66 memcpy (data_copy, data, data_len);
67 data_copy[data_len] = '\0';
68 result = GNUNET_GTK_from_loc_to_utf8 (data_copy);
69 GNUNET_free (data_copy);
70 }
71 }
72 return result;
73}
74
75/**
29 * Add meta data to list store. 76 * Add meta data to list store.
30 * 77 *
31 * @param cls closure (the GtkListStore) 78 * @param cls closure (the GtkListStore)
@@ -49,44 +96,17 @@ GNUNET_FS_GTK_add_meta_data_to_list_store (void *cls, const char *plugin_name,
49 const char *data, size_t data_len) 96 const char *data, size_t data_len)
50{ 97{
51 GtkListStore *ls = GTK_LIST_STORE (cls); 98 GtkListStore *ls = GTK_LIST_STORE (cls);
52 const gchar *data_to_insert = NULL; 99 gchar *data_to_insert = NULL;
53 gchar *free_data = NULL;
54 gsize rd;
55 gsize wr;
56 100
57 if (format == EXTRACTOR_METAFORMAT_UTF8) 101 data_to_insert = GNUNET_FS_GTK_dubious_meta_to_utf8 (format, data, data_len);
58 {
59 if (g_utf8_validate (data, data_len, NULL))
60 data_to_insert = data;
61 else
62 {
63 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
64 "Failed to validate supposedly utf-8 string `%s' of length %u, assuming it to be a C string\n",
65 data, data_len);
66 format = EXTRACTOR_METAFORMAT_C_STRING;
67 }
68 }
69 if (format == EXTRACTOR_METAFORMAT_C_STRING)
70 {
71 GError *gerr = NULL;
72 rd = wr = 0;
73 free_data = g_locale_to_utf8 (data, data_len, &rd, &wr, &gerr);
74 if (gerr != NULL)
75 {
76 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
77 "Error when converting a C string `%s' of length %u to utf-8 (converted %u to %u bytes): %s\n",
78 data, data_len, rd, wr, gerr->message);
79 g_error_free (gerr);
80 }
81 data_to_insert = free_data;
82 }
83 102
84 if (NULL != data_to_insert) 103 if (NULL != data_to_insert)
104 {
85 gtk_list_store_insert_with_values (ls, NULL, G_MAXINT, 0, type, 1, format, 105 gtk_list_store_insert_with_values (ls, NULL, G_MAXINT, 0, type, 1, format,
86 2, EXTRACTOR_metatype_to_string (type), 106 2, EXTRACTOR_metatype_to_string (type),
87 3, data_to_insert, -1); 107 3, data_to_insert, -1);
88 if (NULL != free_data) 108 g_free (data_to_insert);
89 g_free (free_data); 109 }
90 110
91 return 0; 111 return 0;
92} 112}
@@ -194,5 +214,4 @@ GNUNET_FS_GTK_mmap_and_scan (const char *filename,
194 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); 214 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
195} 215}
196 216
197
198/* end of gnunet-fs-gtk-common.c */ 217/* end of gnunet-fs-gtk-common.c */
diff --git a/src/fs/gnunet-fs-gtk-common.h b/src/fs/gnunet-fs-gtk-common.h
index 9484b0e7..d0d7b4f9 100644
--- a/src/fs/gnunet-fs-gtk-common.h
+++ b/src/fs/gnunet-fs-gtk-common.h
@@ -101,5 +101,23 @@ GNUNET_FS_GTK_add_meta_data_to_list_store (void *cls, const char *plugin_name,
101 const char *data_mime_type, 101 const char *data_mime_type,
102 const char *data, size_t data_len); 102 const char *data, size_t data_len);
103 103
104/**
105 * Converts metadata specified by @data of size @data_len
106 * and saved in format @format to UTF-8 encoded string.
107 * Works only for C-string and UTF8 metadata formats
108 * (returns NULL for everything else).
109 * Verifies UTF-8 strings.
110 *
111 * @param format format of the @data
112 * @param data data to convert
113 * @param data_len length of the data buffer (in bytes)
114 * @return NULL if can't be converted, allocated string otherwise,
115 * freeable with GNUNET_free* ().
116 */
117char *
118GNUNET_FS_GTK_dubious_meta_to_utf8 (enum EXTRACTOR_MetaFormat format,
119 const char *data, size_t data_len);
120
121
104#endif 122#endif
105/* end of gnunet-fs-gtk-common.h */ 123/* end of gnunet-fs-gtk-common.h */
diff --git a/src/fs/gnunet-fs-gtk-download.c b/src/fs/gnunet-fs-gtk-download.c
index 3f5f213b..09ae7e1f 100644
--- a/src/fs/gnunet-fs-gtk-download.c
+++ b/src/fs/gnunet-fs-gtk-download.c
@@ -73,7 +73,7 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget *widget, GdkEvent *event,
73 return FALSE; 73 return FALSE;
74 } 74 }
75 GNUNET_free_non_null (dc->filename); 75 GNUNET_free_non_null (dc->filename);
76 dc->filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlc->dialog)); 76 dc->filename = GNUNET_GTK_filechooser_get_filename_loc (GTK_FILE_CHOOSER (dlc->dialog));
77 dc->is_recursive = 77 dc->is_recursive =
78 (TRUE == 78 (TRUE ==
79 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES : 79 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES :
@@ -165,6 +165,7 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc)
165 if (dc->filename != NULL) 165 if (dc->filename != NULL)
166 { 166 {
167 char buf[1024]; 167 char buf[1024];
168 char *buf_utf8;
168 169
169 if (NULL != getcwd (buf, sizeof (buf))) 170 if (NULL != getcwd (buf, sizeof (buf)))
170 { 171 {
@@ -173,7 +174,12 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc)
173 strcat (buf, DIR_SEPARATOR_STR); 174 strcat (buf, DIR_SEPARATOR_STR);
174 strcat (buf, dc->filename); 175 strcat (buf, dc->filename);
175 } 176 }
176 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf); 177 buf_utf8 = GNUNET_GTK_from_loc_to_utf8 (buf);
178 if (buf_utf8 != NULL)
179 {
180 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf_utf8);
181 GNUNET_free (buf_utf8);
182 }
177 } 183 }
178 } 184 }
179 dlc = g_new0 (struct dialog_context, 1); 185 dlc = g_new0 (struct dialog_context, 1);
diff --git a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
index 34dd9613..955cf655 100644
--- a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
+++ b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
@@ -530,6 +530,7 @@ GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button_file_set_cb (
530 (builder, 530 (builder,
531 "GNUNET_GTK_edit_publication_metadata_preview_image")); 531 "GNUNET_GTK_edit_publication_metadata_preview_image"));
532 gtk_image_set_from_file (image, fn); 532 gtk_image_set_from_file (image, fn);
533 g_free (fn);
533 state->preview_changed = GNUNET_YES; 534 state->preview_changed = GNUNET_YES;
534} 535}
535 536
@@ -589,7 +590,7 @@ preserve_meta_items (void *cls, const char *plugin_name,
589 GNUNET_break (0); 590 GNUNET_break (0);
590 return 0; 591 return 0;
591 } 592 }
592 593 /* FIXME: make sure this is all correct UTF-8-wise */
593 keep = GNUNET_NO; 594 keep = GNUNET_NO;
594 switch (format) 595 switch (format)
595 { 596 {
@@ -808,6 +809,7 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
808 } 809 }
809 g_object_unref (finfo); 810 g_object_unref (finfo);
810 g_object_unref (f); 811 g_object_unref (f);
812 g_free (fn);
811 } 813 }
812 GNUNET_CONTAINER_meta_data_destroy (nm); 814 GNUNET_CONTAINER_meta_data_destroy (nm);
813 815
@@ -1016,6 +1018,7 @@ file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi,
1016 1018
1017/** 1019/**
1018 * Open the dialog to edit file information data. 1020 * Open the dialog to edit file information data.
1021 * short_fn MUST be UTF-8-encoded
1019 */ 1022 */
1020void 1023void
1021GNUNET_FS_GTK_edit_publish_dialog (GtkBuilder *builder, 1024GNUNET_FS_GTK_edit_publish_dialog (GtkBuilder *builder,
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c
index 23129eb6..631c3426 100644
--- a/src/fs/gnunet-fs-gtk-event_handler.c
+++ b/src/fs/gnunet-fs-gtk-event_handler.c
@@ -548,6 +548,7 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
548 GtkTreeIter iter; 548 GtkTreeIter iter;
549 GtkTreePath *path; 549 GtkTreePath *path;
550 struct SearchResult *srp; 550 struct SearchResult *srp;
551 gchar *filename_utf8;
551 552
552 if (de == NULL) 553 if (de == NULL)
553 { 554 {
@@ -587,13 +588,15 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
587 return de; 588 return de;
588 } 589 }
589 gtk_tree_path_free (path); 590 gtk_tree_path_free (path);
591 filename_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) filename);
590 gtk_tree_store_set (de->ts, &iter, 4, 592 gtk_tree_store_set (de->ts, &iter, 4,
591 (guint) ((size > 593 (guint) ((size >
592 0) ? (100 * completed / 594 0) ? (100 * completed /
593 size) : 100) /* progress */ , 595 size) : 100) /* progress */ ,
594 6, filename /* filename/description */ , 596 6, filename_utf8 /* filename/description */ ,
595 8, "blue" /* status colour: pending */ , 597 8, "blue" /* status colour: pending */ ,
596 -1); 598 -1);
599 GNUNET_free_non_null (filename_utf8);
597 return de; 600 return de;
598} 601}
599 602
@@ -1111,6 +1114,7 @@ setup_search (struct GNUNET_FS_SearchContext *sc,
1111 } 1114 }
1112 else 1115 else
1113 { 1116 {
1117 /* FS_uri functions should produce UTF-8, so let them be */
1114 if (GNUNET_FS_uri_test_ksk (query)) 1118 if (GNUNET_FS_uri_test_ksk (query))
1115 tab->query_txt = GNUNET_FS_uri_ksk_to_string_fancy (query); 1119 tab->query_txt = GNUNET_FS_uri_ksk_to_string_fancy (query);
1116 else 1120 else
@@ -1291,6 +1295,16 @@ GNUNET_GTK_add_search_result (struct SearchTab *tab, GtkTreeIter * iter,
1291 -1); 1295 -1);
1292 if (desc == NULL) 1296 if (desc == NULL)
1293 desc = GNUNET_strdup (_("no description supplied")); 1297 desc = GNUNET_strdup (_("no description supplied"));
1298 else
1299 {
1300 char *utf8_desc = NULL;
1301 utf8_desc = GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8, desc, strlen (desc) + 1);
1302 GNUNET_free (desc);
1303 if (utf8_desc != NULL)
1304 desc = utf8_desc;
1305 else
1306 desc = NULL;
1307 }
1294 if (uri == NULL) 1308 if (uri == NULL)
1295 uris = GNUNET_strdup (_("no URI")); 1309 uris = GNUNET_strdup (_("no URI"));
1296 else 1310 else
@@ -1348,7 +1362,7 @@ GNUNET_GTK_add_search_result (struct SearchTab *tab, GtkTreeIter * iter,
1348 if (pixbuf != NULL) 1362 if (pixbuf != NULL)
1349 g_object_unref (pixbuf); 1363 g_object_unref (pixbuf);
1350 GNUNET_free (uris); 1364 GNUNET_free (uris);
1351 GNUNET_free (desc); 1365 GNUNET_free_non_null (desc);
1352 GNUNET_free_non_null (mime); 1366 GNUNET_free_non_null (mime);
1353 tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), iter); 1367 tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), iter);
1354 sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tp); 1368 sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tp);
@@ -1468,6 +1482,16 @@ update_search_result (struct SearchResult *sr,
1468 -1); 1482 -1);
1469 if (desc == NULL) 1483 if (desc == NULL)
1470 desc = GNUNET_strdup (_("no description supplied")); 1484 desc = GNUNET_strdup (_("no description supplied"));
1485 else
1486 {
1487 char *utf8_desc = NULL;
1488 utf8_desc = GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8, desc, strlen (desc) + 1);
1489 GNUNET_free (desc);
1490 if (utf8_desc != NULL)
1491 desc = utf8_desc;
1492 else
1493 desc = NULL;
1494 }
1471 mime = 1495 mime =
1472 GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 1496 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
1473 EXTRACTOR_METATYPE_MIMETYPE, 1497 EXTRACTOR_METATYPE_MIMETYPE,
@@ -1497,7 +1521,7 @@ update_search_result (struct SearchResult *sr,
1497 (gint) availability_rank, -1); 1521 (gint) availability_rank, -1);
1498 if (pixbuf != NULL) 1522 if (pixbuf != NULL)
1499 g_object_unref (pixbuf); 1523 g_object_unref (pixbuf);
1500 GNUNET_free (desc); 1524 GNUNET_free_non_null (desc);
1501 GNUNET_free_non_null (mime); 1525 GNUNET_free_non_null (mime);
1502 1526
1503 notebook = 1527 notebook =
@@ -1610,6 +1634,7 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
1610 GtkWidget *close_button; 1634 GtkWidget *close_button;
1611 GtkNotebook *notebook; 1635 GtkNotebook *notebook;
1612 char *size_fancy; 1636 char *size_fancy;
1637 char *fn_utf8 = NULL;
1613 1638
1614 if (NULL == parent) 1639 if (NULL == parent)
1615 { 1640 {
@@ -1676,11 +1701,14 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
1676 ent = GNUNET_malloc (sizeof (struct PublishEntry)); 1701 ent = GNUNET_malloc (sizeof (struct PublishEntry));
1677 ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO; 1702 ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO;
1678 ent->tab = publish_tab; 1703 ent->tab = publish_tab;
1679 gtk_tree_store_insert_with_values (publish_tab->ts, &iter, pitrptr, G_MAXINT, 0, fn, 1704 fn_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) fn);
1705 gtk_tree_store_insert_with_values (publish_tab->ts, &iter, pitrptr, G_MAXINT,
1706 0, fn_utf8,
1680 1, size_fancy, 2, "white", 3, 1707 1, size_fancy, 2, "white", 3,
1681 (guint) 0 /* progress */ , 1708 (guint) 0 /* progress */ ,
1682 4, ent, 1709 4, ent,
1683 -1); 1710 -1);
1711 GNUNET_free_non_null (fn_utf8);
1684 path = gtk_tree_model_get_path (GTK_TREE_MODEL (publish_tab->ts), &iter); 1712 path = gtk_tree_model_get_path (GTK_TREE_MODEL (publish_tab->ts), &iter);
1685 GNUNET_assert (NULL != path); 1713 GNUNET_assert (NULL != path);
1686 ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (publish_tab->ts), path); 1714 ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (publish_tab->ts), path);
diff --git a/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c b/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
index b15060ba..711b78fa 100644
--- a/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
+++ b/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
@@ -48,12 +48,14 @@ add_to_list (void *cls, const char *name, const GNUNET_HashCode * id)
48{ 48{
49 GtkListStore *ls = cls; 49 GtkListStore *ls = cls;
50 GtkTreeIter iter; 50 GtkTreeIter iter;
51 char *name_utf8;
52 name_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) name);
51 53
52 gtk_list_store_insert_with_values (ls, &iter, -1, 0, name, 1, 54 gtk_list_store_insert_with_values (ls, &iter, -1, 0, name_utf8, 1,
53 GNUNET_FS_namespace_create 55 GNUNET_FS_namespace_create
54 (GNUNET_FS_GTK_get_fs_handle (), name), 56 (GNUNET_FS_GTK_get_fs_handle (), name),
55 -1); 57 -1);
56 58 GNUNET_free_non_null (name_utf8);
57} 59}
58 60
59 61
diff --git a/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c b/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c
index e0a8b0e4..c912aab6 100644
--- a/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c
+++ b/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c
@@ -31,6 +31,7 @@ GNUNET_GTK_create_namespace_dialog_response_cb (GtkDialog *dialog,
31 gint response_id, gpointer user_data) 31 gint response_id, gpointer user_data)
32{ 32{
33 const char *name; 33 const char *name;
34 gchar *name_loc;
34 struct GNUNET_FS_Namespace *ns; 35 struct GNUNET_FS_Namespace *ns;
35 GtkWidget *ad; 36 GtkWidget *ad;
36 GtkBuilder *builder; 37 GtkBuilder *builder;
@@ -51,8 +52,13 @@ GNUNET_GTK_create_namespace_dialog_response_cb (GtkDialog *dialog,
51 (builder, 52 (builder,
52 "GNUNET_GTK_create_namespace_name_entry"))); 53 "GNUNET_GTK_create_namespace_name_entry")));
53 /* FIXME: show busy dialog while doing key creation */ 54 /* FIXME: show busy dialog while doing key creation */
54 ns = GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name); 55 name_loc = GNUNET_GTK_from_utf8_to_loc ((char *) name);
55 GNUNET_FS_namespace_delete (ns, GNUNET_NO); 56 if (NULL != name_loc)
57 {
58 ns = GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name_loc);
59 GNUNET_FS_namespace_delete (ns, GNUNET_NO);
60 GNUNET_free (name_loc);
61 }
56 gtk_widget_destroy (ad); 62 gtk_widget_destroy (ad);
57 g_object_unref (G_OBJECT (builder)); 63 g_object_unref (G_OBJECT (builder));
58} 64}
diff --git a/src/fs/gnunet-fs-gtk-main_window_file_publish.c b/src/fs/gnunet-fs-gtk-main_window_file_publish.c
index 16298427..7172e334 100644
--- a/src/fs/gnunet-fs-gtk-main_window_file_publish.c
+++ b/src/fs/gnunet-fs-gtk-main_window_file_publish.c
@@ -211,6 +211,7 @@ add_file_at_iter (gpointer data, const char *filename, const struct GNUNET_FS_Bl
211 GtkTreePath *path; 211 GtkTreePath *path;
212 uint64_t file_size; 212 uint64_t file_size;
213 const char *short_fn; 213 const char *short_fn;
214 char *short_fn_utf8;
214 struct GNUNET_CONTAINER_MetaData *meta; 215 struct GNUNET_CONTAINER_MetaData *meta;
215 struct GNUNET_FS_Uri *ksk_uri; 216 struct GNUNET_FS_Uri *ksk_uri;
216 GtkTreeStore *ts; 217 GtkTreeStore *ts;
@@ -248,10 +249,11 @@ add_file_at_iter (gpointer data, const char *filename, const struct GNUNET_FS_Bl
248 short_fn = filename; 249 short_fn = filename;
249 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR))) 250 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)))
250 short_fn = 1 + ss; 251 short_fn = 1 + ss;
252 short_fn_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) short_fn);
251 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet-gtk>", 253 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet-gtk>",
252 EXTRACTOR_METATYPE_FILENAME, 254 EXTRACTOR_METATYPE_FILENAME,
253 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 255 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
254 short_fn, strlen (short_fn) + 1); 256 short_fn_utf8, strlen (short_fn_utf8) + 1);
255 ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 257 ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
256 gtk_tree_store_insert_before (ts, &pos, iter, NULL); 258 gtk_tree_store_insert_before (ts, &pos, iter, NULL);
257 path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &pos); 259 path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &pos);
@@ -268,8 +270,9 @@ add_file_at_iter (gpointer data, const char *filename, const struct GNUNET_FS_Bl
268 else 270 else
269 file_size_fancy = GNUNET_STRINGS_byte_size_fancy (file_size); 271 file_size_fancy = GNUNET_STRINGS_byte_size_fancy (file_size);
270 gtk_tree_store_set (ts, &pos, 0, file_size_fancy, 1, (gboolean) do_index, 2, 272 gtk_tree_store_set (ts, &pos, 0, file_size_fancy, 1, (gboolean) do_index, 2,
271 short_fn, 3, (guint) bo->anonymity_level, 4, 273 short_fn_utf8, 3, (guint) bo->anonymity_level, 4,
272 (guint) bo->content_priority, 5, fi, -1); 274 (guint) bo->content_priority, 5, fi, -1);
275 GNUNET_free_non_null (short_fn_utf8);
273 GNUNET_free (file_size_fancy); 276 GNUNET_free (file_size_fancy);
274 update_selectivity (data); 277 update_selectivity (data);
275} 278}
@@ -294,6 +297,7 @@ create_dir_at_iter (gpointer data, const char *name, const struct GNUNET_FS_Bloc
294 GtkTreeStore *ts; 297 GtkTreeStore *ts;
295 GtkBuilder *builder; 298 GtkBuilder *builder;
296 299
300
297 builder = GTK_BUILDER (data); 301 builder = GTK_BUILDER (data);
298 302
299 ts = GTK_TREE_STORE (gtk_builder_get_object 303 ts = GTK_TREE_STORE (gtk_builder_get_object
@@ -504,6 +508,7 @@ extract_file (struct AddDirContext *adc, const char *filename)
504 GNUNET_HashCode hc; 508 GNUNET_HashCode hc;
505 const char *short_fn; 509 const char *short_fn;
506 const char *ss; 510 const char *ss;
511 char *short_fn_utf8;
507 512
508 adc->dir_entry_count++; 513 adc->dir_entry_count++;
509 pd = GNUNET_malloc (sizeof (struct PublishData)); 514 pd = GNUNET_malloc (sizeof (struct PublishData));
@@ -515,11 +520,12 @@ extract_file (struct AddDirContext *adc, const char *filename)
515 short_fn = filename; 520 short_fn = filename;
516 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR))) 521 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)))
517 short_fn = 1 + ss; 522 short_fn = 1 + ss;
523 short_fn_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) short_fn);
518 GNUNET_CONTAINER_meta_data_insert (pd->meta, "<gnunet-gtk>", 524 GNUNET_CONTAINER_meta_data_insert (pd->meta, "<gnunet-gtk>",
519 EXTRACTOR_METATYPE_FILENAME, 525 EXTRACTOR_METATYPE_FILENAME,
520 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 526 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
521 short_fn, strlen (short_fn) + 1); 527 short_fn, strlen (short_fn_utf8) + 1);
522 528 GNUNET_free_non_null (short_fn_utf8);
523 529
524 gtk_tree_store_insert_before (adc->ts, &pd->iter, adc->parent, NULL); 530 gtk_tree_store_insert_before (adc->ts, &pd->iter, adc->parent, NULL);
525 GNUNET_CRYPTO_hash (filename, strlen (filename), &hc); 531 GNUNET_CRYPTO_hash (filename, strlen (filename), &hc);
@@ -576,6 +582,7 @@ add_entry_to_ts (GtkTreeStore * ts, GtkTreeIter * iter, const char *filename,
576 struct GNUNET_FS_Uri *kill_ksk; 582 struct GNUNET_FS_Uri *kill_ksk;
577 const char *ss; 583 const char *ss;
578 const char *short_fn; 584 const char *short_fn;
585 char *short_fn_utf8;
579 struct stat sbuf; 586 struct stat sbuf;
580 587
581 if (0 != STAT (filename, &sbuf)) 588 if (0 != STAT (filename, &sbuf))
@@ -627,9 +634,11 @@ add_entry_to_ts (GtkTreeStore * ts, GtkTreeIter * iter, const char *filename,
627 short_fn = filename; 634 short_fn = filename;
628 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR))) 635 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)))
629 short_fn = 1 + ss; 636 short_fn = 1 + ss;
637 short_fn_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) short_fn);
630 gtk_tree_store_set (ts, iter, 0, file_size_fancy, 1, (gboolean) do_index, 2, 638 gtk_tree_store_set (ts, iter, 0, file_size_fancy, 1, (gboolean) do_index, 2,
631 short_fn, 3, (guint) bo->anonymity_level, 4, 639 short_fn_utf8, 3, (guint) bo->anonymity_level, 4,
632 (guint) bo->content_priority, 5, fi, -1); 640 (guint) bo->content_priority, 5, fi, -1);
641 GNUNET_free_non_null (short_fn_utf8);
633 GNUNET_free (file_size_fancy); 642 GNUNET_free (file_size_fancy);
634} 643}
635 644
@@ -774,8 +783,19 @@ scan_directory (void *cls, const char *filename)
774 } 783 }
775 else 784 else
776 { 785 {
786 char *filename_utf8;
787 const char *ss, *short_fn;
777 GNUNET_assert (mcm == NULL); 788 GNUNET_assert (mcm == NULL);
778 /* we're top-level */ 789 /* we're top-level */
790 short_fn = filename;
791 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)))
792 short_fn = 1 + ss;
793 filename_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) short_fn);
794 GNUNET_CONTAINER_meta_data_insert (pd->meta, "<gnunet-gtk>",
795 EXTRACTOR_METATYPE_FILENAME,
796 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
797 filename_utf8, strlen (filename_utf8) + 1);
798 GNUNET_free_non_null (filename_utf8);
779 add_entry_to_ts (adc->ts, &pd->iter, filename, &adc->bo, adc->do_index, 799 add_entry_to_ts (adc->ts, &pd->iter, filename, &adc->bo, adc->do_index,
780 NULL, pd->meta); 800 NULL, pd->meta);
781 } 801 }
@@ -1384,7 +1404,7 @@ GNUNET_GTK_publish_directory_dialog_response_cb (GtkDialog *dialog,
1384 "GNUNET_GTK_publish_directory_dialog")); 1404 "GNUNET_GTK_publish_directory_dialog"));
1385 if (response_id == -5) 1405 if (response_id == -5)
1386 { 1406 {
1387 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (ad)); 1407 filename = GNUNET_GTK_filechooser_get_filename_loc (GTK_FILE_CHOOSER (ad));
1388 sb = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, 1408 sb = GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
1389 "GNUNET_GTK_publish_directory_dialog_expiration_year_spin_button")); 1409 "GNUNET_GTK_publish_directory_dialog_expiration_year_spin_button"));
1390 if (!GNUNET_GTK_get_selected_anonymity_level (builder, 1410 if (!GNUNET_GTK_get_selected_anonymity_level (builder,
@@ -1539,6 +1559,18 @@ add_updateable_to_ts (void *cls, const char *last_id,
1539 EXTRACTOR_METATYPE_COMMENT, 1559 EXTRACTOR_METATYPE_COMMENT,
1540 EXTRACTOR_METATYPE_SUBJECT, 1560 EXTRACTOR_METATYPE_SUBJECT,
1541 -1); 1561 -1);
1562 if (desc == NULL)
1563 desc = GNUNET_strdup (_("no description supplied"));
1564 else
1565 {
1566 char *utf8_desc = NULL;
1567 utf8_desc = GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8, desc, strlen (desc) + 1);
1568 GNUNET_free (desc);
1569 if (utf8_desc != NULL)
1570 desc = utf8_desc;
1571 else
1572 desc = NULL;
1573 }
1542 gtk_tree_store_insert_with_values (uc->ts, &iter, uc->parent, G_MAXINT, 0, 1574 gtk_tree_store_insert_with_values (uc->ts, &iter, uc->parent, G_MAXINT, 0,
1543 uc->namespace_name, 1, uc->ns, 2, last_id, 1575 uc->namespace_name, 1, uc->ns, 2, last_id,
1544 3, GNUNET_FS_uri_dup (last_uri), 4, 1576 3, GNUNET_FS_uri_dup (last_uri), 4,
@@ -1586,13 +1618,15 @@ add_namespace_to_ts (void *cls, const char *name, const GNUNET_HashCode * id)
1586 GtkTreeStore *ts = cls; 1618 GtkTreeStore *ts = cls;
1587 struct UpdateableContext uc; 1619 struct UpdateableContext uc;
1588 GtkTreeIter iter; 1620 GtkTreeIter iter;
1621 gchar *name_utf8;
1589 1622
1590 uc.parent = &iter; 1623 uc.parent = &iter;
1591 uc.namespace_name = name; 1624 uc.namespace_name = name;
1592 uc.ts = ts; 1625 uc.ts = ts;
1593 uc.ns = GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name); 1626 uc.ns = GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name);
1594 uc.update_called = GNUNET_NO; 1627 uc.update_called = GNUNET_NO;
1595 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, name, 1, 1628 name_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) name);
1629 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, name_utf8, 1,
1596 uc.ns, 2, NULL /* last-id */ , 1630 uc.ns, 2, NULL /* last-id */ ,
1597 3, NULL /* last-uri */ , 1631 3, NULL /* last-uri */ ,
1598 4, NULL /* meta */ , 1632 4, NULL /* meta */ ,
@@ -1601,6 +1635,7 @@ add_namespace_to_ts (void *cls, const char *name, const GNUNET_HashCode * id)
1601 7, TRUE /* update editable */ , 1635 7, TRUE /* update editable */ ,
1602 8, TRUE /* current editable */ , 1636 8, TRUE /* current editable */ ,
1603 -1); 1637 -1);
1638 GNUNET_free_non_null (name_utf8);
1604 uc.seen = GNUNET_CONTAINER_multihashmap_create (128); 1639 uc.seen = GNUNET_CONTAINER_multihashmap_create (128);
1605 GNUNET_FS_namespace_list_updateable (uc.ns, NULL, &add_updateable_to_ts, &uc); 1640 GNUNET_FS_namespace_list_updateable (uc.ns, NULL, &add_updateable_to_ts, &uc);
1606 GNUNET_CONTAINER_multihashmap_destroy (uc.seen); 1641 GNUNET_CONTAINER_multihashmap_destroy (uc.seen);
@@ -1726,6 +1761,7 @@ hide_master_publish_dialog (gpointer user_data, gint ret)
1726 do 1761 do
1727 { 1762 {
1728 fi = get_file_information (tm, &iter); 1763 fi = get_file_information (tm, &iter);
1764 /* FIXME: should we convert namespace id and uid from UTF8? */
1729 GNUNET_FS_publish_start (GNUNET_FS_GTK_get_fs_handle (), fi, namespace, 1765 GNUNET_FS_publish_start (GNUNET_FS_GTK_get_fs_handle (), fi, namespace,
1730 namespace_id, namespace_uid, 1766 namespace_id, namespace_uid,
1731 GNUNET_FS_PUBLISH_OPTION_NONE); 1767 GNUNET_FS_PUBLISH_OPTION_NONE);
@@ -1801,7 +1837,6 @@ GNUNET_GTK_publish_file_dialog_response_cb (GtkDialog *dialog,
1801 if (response_id == -5) 1837 if (response_id == -5)
1802 { 1838 {
1803 /* OK */ 1839 /* OK */
1804 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (ad));
1805 sb = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, 1840 sb = GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
1806 "GNUNET_GTK_publish_file_dialog_expiration_year_spin_button")); 1841 "GNUNET_GTK_publish_file_dialog_expiration_year_spin_button"));
1807 1842
@@ -1816,6 +1851,8 @@ GNUNET_GTK_publish_file_dialog_response_cb (GtkDialog *dialog,
1816 do_index = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ( 1851 do_index = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
1817 gtk_builder_get_object (builder, 1852 gtk_builder_get_object (builder,
1818 "GNUNET_GTK_publish_file_dialog_do_index_checkbutton"))); 1853 "GNUNET_GTK_publish_file_dialog_do_index_checkbutton")));
1854
1855 filename = GNUNET_GTK_filechooser_get_filename_loc (GTK_FILE_CHOOSER (ad));
1819 add_file_at_iter (user_data, filename, &bo, do_index, NULL); 1856 add_file_at_iter (user_data, filename, &bo, do_index, NULL);
1820 g_free (filename); 1857 g_free (filename);
1821 update_selectivity (user_data); 1858 update_selectivity (user_data);
diff --git a/src/fs/gnunet-fs-gtk-main_window_open_directory.c b/src/fs/gnunet-fs-gtk-main_window_open_directory.c
index 23e71fc6..e614451f 100644
--- a/src/fs/gnunet-fs-gtk-main_window_open_directory.c
+++ b/src/fs/gnunet-fs-gtk-main_window_open_directory.c
@@ -67,7 +67,7 @@ add_child (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
67 dmeta = GNUNET_CONTAINER_meta_data_duplicate (meta); 67 dmeta = GNUNET_CONTAINER_meta_data_duplicate (meta);
68 GNUNET_CONTAINER_meta_data_insert (dmeta, "<user>", 68 GNUNET_CONTAINER_meta_data_insert (dmeta, "<user>",
69 EXTRACTOR_METATYPE_FILENAME, 69 EXTRACTOR_METATYPE_FILENAME,
70 EXTRACTOR_METAFORMAT_C_STRING, 70 EXTRACTOR_METAFORMAT_UTF8,
71 "text/plain", acc->filename, 71 "text/plain", acc->filename,
72 strlen (acc->filename) + 1); 72 strlen (acc->filename) + 1);
73 acc->tab = GNUNET_GTK_add_to_uri_tab (&acc->iter, &acc->par, dmeta, NULL); 73 acc->tab = GNUNET_GTK_add_to_uri_tab (&acc->iter, &acc->par, dmeta, NULL);
@@ -91,7 +91,7 @@ GNUNET_GTK_open_directory_dialog_response_cb (GtkDialog *dialog,
91{ 91{
92 GtkBuilder *builder; 92 GtkBuilder *builder;
93 GtkWidget *ad; 93 GtkWidget *ad;
94 char *filename; 94 char *filename, *filename_utf8;
95 struct AddChildContext acc; 95 struct AddChildContext acc;
96 96
97 builder = GTK_BUILDER (user_data); 97 builder = GTK_BUILDER (user_data);
@@ -105,12 +105,14 @@ GNUNET_GTK_open_directory_dialog_response_cb (GtkDialog *dialog,
105 return; 105 return;
106 } 106 }
107 107
108 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (ad)); 108 filename = GNUNET_GTK_filechooser_get_filename_loc (GTK_FILE_CHOOSER (ad));
109 filename_utf8 = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (ad));
109 gtk_widget_destroy (ad); 110 gtk_widget_destroy (ad);
110 g_object_unref (G_OBJECT (builder)); 111 g_object_unref (G_OBJECT (builder));
111 acc.filename = filename; 112 acc.filename = filename_utf8;
112 acc.ts = NULL; 113 acc.ts = NULL;
113 GNUNET_FS_GTK_mmap_and_scan (filename, &add_child, &acc); 114 GNUNET_FS_GTK_mmap_and_scan (filename, &add_child, &acc);
115 g_free (filename_utf8);
114 g_free (filename); 116 g_free (filename);
115} 117}
116 118
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index 8f484a6b..f5e7dad1 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -501,8 +501,11 @@ main_window_search_button_clicked_cb (GtkButton *button, gpointer user_data)
501 mime_keyword = NULL; 501 mime_keyword = NULL;
502 if (mime_model && gtk_combo_box_get_active_iter (mime_combo, &iter)) 502 if (mime_model && gtk_combo_box_get_active_iter (mime_combo, &iter))
503 gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1); 503 gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1);
504 if (mime_keyword == NULL) 504 if (strcmp (mime_keyword, " ") == 0)
505 mime_keyword = g_strdup (""); 505 {
506 g_free (mime_keyword);
507 mime_keyword = NULL;
508 }
506 509
507 ref = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference"); 510 ref = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
508 if (ref) 511 if (ref)
@@ -516,7 +519,7 @@ main_window_search_button_clicked_cb (GtkButton *button, gpointer user_data)
516 query_entry = GTK_ENTRY (gtk_builder_get_object (builder, 519 query_entry = GTK_ENTRY (gtk_builder_get_object (builder,
517 "main_window_search_entry")); 520 "main_window_search_entry"));
518 entry_keywords = gtk_entry_get_text (query_entry); 521 entry_keywords = gtk_entry_get_text (query_entry);
519 keywords = g_strdup_printf ("%s +%s", entry_keywords, mime_keyword); 522 keywords = g_strdup_printf ("%s %s%s", entry_keywords, mime_keyword ? "+" : "", mime_keyword ? mime_keyword : "");
520 g_free (mime_keyword); 523 g_free (mime_keyword);
521 if (nsid != NULL) 524 if (nsid != NULL)
522 { 525 {
@@ -610,6 +613,18 @@ add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym,
610 EXTRACTOR_METATYPE_SUBJECT, 613 EXTRACTOR_METATYPE_SUBJECT,
611 EXTRACTOR_METATYPE_KEYWORDS, 614 EXTRACTOR_METATYPE_KEYWORDS,
612 -1); 615 -1);
616 if (description == NULL)
617 description = g_strdup (_("no description supplied"));
618 else
619 {
620 char *utf8_desc = NULL;
621 utf8_desc = GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8, description, strlen (description));
622 GNUNET_free (description);
623 if (utf8_desc != NULL)
624 description = utf8_desc;
625 else
626 description = NULL;
627 }
613 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1, 628 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1,
614 nsid, 2, root, 3, description, -1); 629 nsid, 2, root, 3, description, -1);
615 GNUNET_free (ns_name); 630 GNUNET_free (ns_name);
diff --git a/src/include/gnunet_gtk.h b/src/include/gnunet_gtk.h
index ee5bbf99..2b8dbcff 100644
--- a/src/include/gnunet_gtk.h
+++ b/src/include/gnunet_gtk.h
@@ -121,6 +121,34 @@ GNUNET_GTK_tray_icon_create (GtkWindow * main, const char *icon_name,
121void 121void
122GNUNET_GTK_tray_icon_destroy (void); 122GNUNET_GTK_tray_icon_destroy (void);
123 123
124char *
125GNUNET_GTK_from_utf8_to_loc (gchar *str_utf8);
126
127char *
128GNUNET_GTK_from_loc_to_utf8 (gchar *str_loc);
129
130char *
131GNUNET_GTK_from_filename_to_utf8 (gchar *filename);
132
133char *
134GNUNET_GTK_from_utf8_to_filename (gchar *str_utf8);
135
136char *
137GNUNET_GTK_from_loc_to_filename (gchar *str_loc);
138
139char *
140GNUNET_GTK_from_filename_to_loc (gchar *filename);
141
142/* Returns filename form filechooser, encoded in locale-dependent
143 * encoding, suitable to be given to CRT and/or GNUnet
144 */
145char *
146GNUNET_GTK_filechooser_get_filename_loc (GtkFileChooser *fc);
147
148gchar *
149GNUNET_GTK_filechooser_get_filename_utf8 (GtkFileChooser *fc);
150
151
124 152
125/* ******************* main loop ***************** */ 153/* ******************* main loop ***************** */
126 154
diff --git a/src/lib/nls.c b/src/lib/nls.c
index a040f8e5..f313ce59 100644
--- a/src/lib/nls.c
+++ b/src/lib/nls.c
@@ -53,4 +53,171 @@ GNUNET_GTK_setup_nls ()
53#endif 53#endif
54} 54}
55 55
56
57char *
58GNUNET_GTK_from_utf8_to_loc (gchar *str_utf8)
59{
60 char *str_loc;
61 const char *loc_charset;
62 gboolean is_UTF8;
63
64 if (NULL == str_utf8)
65 return NULL;
66
67 is_UTF8 = g_get_charset (&loc_charset);
68 if (is_UTF8)
69 str_loc = GNUNET_strdup (str_utf8);
70 else
71 str_loc = GNUNET_STRINGS_from_utf8 (str_utf8, strlen (str_utf8), loc_charset);
72
73 return str_loc;
74}
75
76char *
77GNUNET_GTK_from_loc_to_utf8 (gchar *str_loc)
78{
79 char *str_utf8;
80 const char *loc_charset;
81 gboolean is_UTF8;
82
83 if (NULL == str_loc)
84 return NULL;
85
86 is_UTF8 = g_get_charset (&loc_charset);
87 if (is_UTF8)
88 str_utf8 = GNUNET_strdup (str_loc);
89 else
90 str_utf8 = GNUNET_STRINGS_to_utf8 (str_loc, strlen (str_loc), loc_charset);
91
92 return str_utf8;
93}
94
95/* This is copied from GLib */
96static gboolean
97get_filename_charset (const gchar **filename_charset)
98{
99 const gchar **charsets;
100 gboolean is_utf8;
101
102 is_utf8 = g_get_filename_charsets (&charsets);
103
104 if (filename_charset)
105 *filename_charset = charsets[0];
106
107 return is_utf8;
108}
109
110char *
111GNUNET_GTK_from_filename_to_utf8 (gchar *filename)
112{
113 char *str_utf8;
114 const char *filename_charset;
115 gboolean is_UTF8;
116
117 if (NULL == filename)
118 return NULL;
119
120 is_UTF8 = get_filename_charset (&filename_charset);
121 if (is_UTF8)
122 str_utf8 = GNUNET_strdup (filename);
123 else
124 str_utf8 = GNUNET_STRINGS_to_utf8 (filename, strlen (filename), filename_charset);
125
126 return str_utf8;
127}
128
129char *
130GNUNET_GTK_from_utf8_to_filename (gchar *str_utf8)
131{
132 char *filename;
133 const char *filename_charset;
134 gboolean is_UTF8;
135
136 if (NULL == str_utf8)
137 return NULL;
138
139 is_UTF8 = get_filename_charset (&filename_charset);
140 if (is_UTF8)
141 filename = GNUNET_strdup (str_utf8);
142 else
143 filename = GNUNET_STRINGS_from_utf8 (str_utf8, strlen (str_utf8), filename_charset);
144
145 return filename;
146}
147
148char *
149GNUNET_GTK_from_loc_to_filename (gchar *str_loc)
150{
151 char *filename;
152 const char *filename_charset;
153 const char *loc_charset;
154 gboolean is_filename_UTF8, is_loc_UTF8;
155
156 if (NULL == str_loc)
157 return NULL;
158
159 is_filename_UTF8 = get_filename_charset (&filename_charset);
160 is_loc_UTF8 = g_get_charset (&loc_charset);
161 if (is_filename_UTF8 && is_loc_UTF8)
162 filename = GNUNET_strdup (str_loc);
163 else if (is_filename_UTF8)
164 filename = GNUNET_STRINGS_to_utf8 (str_loc, strlen (str_loc), loc_charset);
165 else if (is_loc_UTF8)
166 filename = GNUNET_STRINGS_from_utf8 (str_loc, strlen (str_loc), filename_charset);
167 else
168 /* Pray that iconv() knows these charsets */
169 filename = GNUNET_STRINGS_conv (str_loc, strlen (str_loc), loc_charset, filename_charset);
170
171 return filename;
172}
173
174char *
175GNUNET_GTK_from_filename_to_loc (gchar *filename)
176{
177 char *str_loc;
178 const char *loc_charset;
179 const char *filename_charset;
180 gboolean is_loc_UTF8, is_filename_UTF8;
181
182 if (NULL == filename)
183 return NULL;
184
185 is_filename_UTF8 = get_filename_charset (&filename_charset);
186 is_loc_UTF8 = g_get_charset (&loc_charset);
187 if (is_loc_UTF8 && is_filename_UTF8)
188 str_loc = GNUNET_strdup (filename);
189 else if (is_loc_UTF8)
190 str_loc = GNUNET_STRINGS_to_utf8 (filename, strlen (filename), filename_charset);
191 else if (is_filename_UTF8)
192 str_loc = GNUNET_STRINGS_from_utf8 (filename, strlen (filename), loc_charset);
193 else
194 /* Pray that iconv() knows these charsets */
195 str_loc = GNUNET_STRINGS_conv (filename, strlen (filename), filename_charset, loc_charset);
196
197 return str_loc;
198}
199
200/* Returns filename form filechooser, encoded in locale-dependent
201 * encoding, suitable to be given to CRT and/or GNUnet
202 */
203char *
204GNUNET_GTK_filechooser_get_filename_loc (GtkFileChooser *fc)
205{
206 char *filename_loc;
207 gchar *filename = gtk_file_chooser_get_filename (fc);
208 filename_loc = GNUNET_GTK_from_filename_to_loc (filename);
209 g_free (filename);
210 return filename_loc;
211}
212
213gchar *
214GNUNET_GTK_filechooser_get_filename_utf8 (GtkFileChooser *fc)
215{
216 char *filename_utf8;
217 gchar *filename = gtk_file_chooser_get_filename (fc);
218 filename_utf8 = GNUNET_GTK_from_filename_to_utf8 (filename);
219 g_free (filename);
220 return filename_utf8;
221}
222
56/* end of nls.c */ 223/* end of nls.c */