diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-01 19:55:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-01 19:55:56 +0000 |
commit | dd0c112e07fa9e6ab2617c7d2f87cca0a058170c (patch) | |
tree | 18797c49cac0402c36f895ba75991e0689f19900 | |
parent | 4b77e8f99e957f463eafa4c80c46280fab8de072 (diff) | |
download | gnunet-gtk-dd0c112e07fa9e6ab2617c7d2f87cca0a058170c.tar.gz gnunet-gtk-dd0c112e07fa9e6ab2617c7d2f87cca0a058170c.zip |
-some work towards 2041, fixing some memory leaks, dead code limination in nls.c, some renaming to fix naming conventions, some API changes to allow nicer connecting of signal handlers to custom closures
-rw-r--r-- | src/fs/gnunet-fs-gtk-download.c | 77 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk-event_handler.c | 60 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c | 2 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk-main_window_open_directory.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_gtk.h | 38 | ||||
-rw-r--r-- | src/lib/about.c | 2 | ||||
-rw-r--r-- | src/lib/eventloop.c | 2 | ||||
-rw-r--r-- | src/lib/glade.c | 7 | ||||
-rw-r--r-- | src/lib/nls.c | 164 | ||||
-rw-r--r-- | src/lib/trayicon.c | 2 |
10 files changed, 158 insertions, 198 deletions
diff --git a/src/fs/gnunet-fs-gtk-download.c b/src/fs/gnunet-fs-gtk-download.c index 61b34419..05a5ae95 100644 --- a/src/fs/gnunet-fs-gtk-download.c +++ b/src/fs/gnunet-fs-gtk-download.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -27,7 +27,7 @@ | |||
27 | #include "gnunet-fs-gtk.h" | 27 | #include "gnunet-fs-gtk.h" |
28 | #include "gnunet-fs-gtk-event_handler.h" | 28 | #include "gnunet-fs-gtk-event_handler.h" |
29 | 29 | ||
30 | struct dialog_context | 30 | struct DownloadAsDialogContext |
31 | { | 31 | { |
32 | GtkBuilder *builder; | 32 | GtkBuilder *builder; |
33 | GtkWidget *dialog; | 33 | GtkWidget *dialog; |
@@ -36,12 +36,27 @@ struct dialog_context | |||
36 | }; | 36 | }; |
37 | 37 | ||
38 | 38 | ||
39 | static void | ||
40 | free_download_context (struct DownloadContext *dc) | ||
41 | { | ||
42 | if (NULL != dc->rr) | ||
43 | gtk_tree_row_reference_free (dc->rr); | ||
44 | GNUNET_free_non_null (dc->mime); | ||
45 | GNUNET_free_non_null (dc->filename); | ||
46 | if (NULL != dc->meta) | ||
47 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); | ||
48 | if (NULL != dc->uri) | ||
49 | GNUNET_FS_uri_destroy (dc->uri); | ||
50 | GNUNET_free (dc); | ||
51 | } | ||
52 | |||
53 | |||
39 | gboolean | 54 | gboolean |
40 | GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | 55 | GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, |
41 | gpointer user_data) | 56 | gpointer user_data) |
42 | { | 57 | { |
58 | struct DownloadAsDialogContext *dlc = user_data; | ||
43 | GtkBuilder *builder; | 59 | GtkBuilder *builder; |
44 | struct dialog_context *dlc; | ||
45 | struct DownloadContext *dc; | 60 | struct DownloadContext *dc; |
46 | enum GNUNET_FS_DownloadOptions opt; | 61 | enum GNUNET_FS_DownloadOptions opt; |
47 | struct GNUNET_FS_Handle *fs; | 62 | struct GNUNET_FS_Handle *fs; |
@@ -50,26 +65,20 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
50 | uint32_t anonymity; | 65 | uint32_t anonymity; |
51 | uint64_t len; | 66 | uint64_t len; |
52 | 67 | ||
53 | builder = GTK_BUILDER (user_data); | ||
54 | dlc = g_object_get_data (G_OBJECT (widget), "dialog-context"); | ||
55 | if (dlc == NULL) | 68 | if (dlc == NULL) |
56 | { | 69 | { |
57 | g_object_unref (G_OBJECT (builder)); | 70 | GNUNET_break (0); |
58 | return FALSE; | 71 | return FALSE; |
59 | } | 72 | } |
73 | builder = dlc->builder; | ||
60 | dc = dlc->dc; | 74 | dc = dlc->dc; |
61 | cb = GTK_WIDGET (gtk_builder_get_object | 75 | cb = GTK_WIDGET (gtk_builder_get_object |
62 | (builder, "GNUNET_GTK_save_as_recursive_check_button")); | 76 | (builder, "GNUNET_GTK_save_as_recursive_check_button")); |
63 | if (GTK_RESPONSE_OK != dlc->response) | 77 | if (GTK_RESPONSE_OK != dlc->response) |
64 | { | 78 | { |
79 | free_download_context (dc); | ||
65 | g_object_unref (G_OBJECT (dlc->builder)); | 80 | g_object_unref (G_OBJECT (dlc->builder)); |
66 | if (dc->rr != NULL) | 81 | GNUNET_free (dlc); |
67 | gtk_tree_row_reference_free (dc->rr); | ||
68 | GNUNET_free_non_null (dc->mime); | ||
69 | GNUNET_free_non_null (dc->filename); | ||
70 | GNUNET_FS_uri_destroy (dc->uri); | ||
71 | GNUNET_free (dc); | ||
72 | g_free (dlc); | ||
73 | return FALSE; | 82 | return FALSE; |
74 | } | 83 | } |
75 | GNUNET_free_non_null (dc->filename); | 84 | GNUNET_free_non_null (dc->filename); |
@@ -90,9 +99,12 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
90 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); | 99 | "GNUNET_GTK_save_as_dialog_anonymity_spin_button"))); |
91 | len = GNUNET_FS_uri_chk_get_file_size (dc->uri); | 100 | len = GNUNET_FS_uri_chk_get_file_size (dc->uri); |
92 | g_object_unref (G_OBJECT (builder)); | 101 | g_object_unref (G_OBJECT (builder)); |
102 | |||
93 | de = GNUNET_malloc (sizeof (struct DownloadEntry)); | 103 | de = GNUNET_malloc (sizeof (struct DownloadEntry)); |
94 | de->uri = dc->uri; | 104 | de->uri = dc->uri; |
105 | dc->uri = NULL; | ||
95 | de->meta = dc->meta; | 106 | de->meta = dc->meta; |
107 | dc->meta = NULL; | ||
96 | if (dc->rr != NULL) | 108 | if (dc->rr != NULL) |
97 | { | 109 | { |
98 | de->rr = dc->rr; | 110 | de->rr = dc->rr; |
@@ -117,18 +129,18 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | |||
117 | len, anonymity, opt, de, | 129 | len, anonymity, opt, de, |
118 | NULL /* parent download ctx */ )); | 130 | NULL /* parent download ctx */ )); |
119 | } | 131 | } |
120 | GNUNET_free (dc); | 132 | free_download_context (dc); |
121 | GNUNET_free (dlc); | 133 | GNUNET_free (dlc); |
122 | return FALSE; | 134 | return FALSE; |
123 | } | 135 | } |
124 | 136 | ||
137 | |||
125 | void | 138 | void |
126 | GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, gint response_id, | 139 | GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, gint response_id, |
127 | gpointer user_data) | 140 | gpointer user_data) |
128 | { | 141 | { |
129 | struct dialog_context *dlc; | 142 | struct DownloadAsDialogContext *dlc = user_data; |
130 | 143 | ||
131 | dlc = g_object_get_data (G_OBJECT (dialog), "dialog-context"); | ||
132 | if (dlc != NULL) | 144 | if (dlc != NULL) |
133 | dlc->response = response_id; | 145 | dlc->response = response_id; |
134 | /* dialogs don't get delete-event the way normal windows do, | 146 | /* dialogs don't get delete-event the way normal windows do, |
@@ -139,24 +151,24 @@ GNUNET_GTK_save_as_dialog_response_cb (GtkDialog * dialog, gint response_id, | |||
139 | gtk_widget_destroy (GTK_WIDGET (dialog)); | 151 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
140 | } | 152 | } |
141 | 153 | ||
154 | |||
142 | void | 155 | void |
143 | GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | 156 | GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) |
144 | { | 157 | { |
145 | GtkWidget *ad; | 158 | GtkWidget *ad; |
146 | GtkBuilder *builder; | 159 | GtkBuilder *builder; |
147 | GtkWidget *cb; | 160 | GtkWidget *cb; |
148 | struct dialog_context *dlc; | 161 | struct DownloadAsDialogContext *dlc; |
149 | 162 | ||
163 | dlc = GNUNET_malloc (sizeof (struct DownloadAsDialogContext)); | ||
150 | builder = | 164 | builder = |
151 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade"); | 165 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_download_as_dialog.glade", |
166 | dlc); | ||
152 | if (builder == NULL) | 167 | if (builder == NULL) |
153 | { | 168 | { |
154 | if (dc->rr != NULL) | 169 | GNUNET_break (0); |
155 | gtk_tree_row_reference_free (dc->rr); | 170 | free_download_context (dc); |
156 | GNUNET_free_non_null (dc->mime); | 171 | GNUNET_free (dlc); |
157 | GNUNET_free_non_null (dc->filename); | ||
158 | GNUNET_FS_uri_destroy (dc->uri); | ||
159 | GNUNET_free (dc); | ||
160 | return; | 172 | return; |
161 | } | 173 | } |
162 | cb = GTK_WIDGET (gtk_builder_get_object | 174 | cb = GTK_WIDGET (gtk_builder_get_object |
@@ -166,26 +178,11 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | |||
166 | ad = GTK_WIDGET (gtk_builder_get_object | 178 | ad = GTK_WIDGET (gtk_builder_get_object |
167 | (builder, "GNUNET_GTK_save_as_dialog")); | 179 | (builder, "GNUNET_GTK_save_as_dialog")); |
168 | if (dc->filename != NULL) | 180 | if (dc->filename != NULL) |
169 | { | 181 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), dc->filename); |
170 | char buf[FILENAME_MAX]; | ||
171 | |||
172 | if (NULL != getcwd (buf, sizeof (buf))) | ||
173 | { | ||
174 | if (strlen (buf) + strlen (dc->filename) + 2 < sizeof (buf)) | ||
175 | { | ||
176 | strcat (buf, DIR_SEPARATOR_STR); | ||
177 | strcat (buf, dc->filename); | ||
178 | } | ||
179 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf); | ||
180 | } | ||
181 | } | ||
182 | dlc = g_new0 (struct dialog_context, 1); | ||
183 | |||
184 | dlc->builder = builder; | 182 | dlc->builder = builder; |
185 | dlc->dialog = ad; | 183 | dlc->dialog = ad; |
186 | dlc->response = 0; | 184 | dlc->response = 0; |
187 | dlc->dc = dc; | 185 | dlc->dc = dc; |
188 | g_object_set_data (G_OBJECT (ad), "dialog-context", dlc); | ||
189 | gtk_window_present (GTK_WINDOW (ad)); | 186 | gtk_window_present (GTK_WINDOW (ad)); |
190 | } | 187 | } |
191 | 188 | ||
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c index 272c9b1d..83bfcb50 100644 --- a/src/fs/gnunet-fs-gtk-event_handler.c +++ b/src/fs/gnunet-fs-gtk-event_handler.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -627,6 +627,11 @@ start_download (GtkTreeView * tree_view, GtkTreePath * path, | |||
627 | struct SearchResult *sr; | 627 | struct SearchResult *sr; |
628 | gchar *mime; | 628 | gchar *mime; |
629 | struct DownloadContext *dlc; | 629 | struct DownloadContext *dlc; |
630 | char *buf; | ||
631 | char *tmp; | ||
632 | size_t tmplen; | ||
633 | char cwd[FILENAME_MAX]; | ||
634 | char *filename; | ||
630 | 635 | ||
631 | GNUNET_assert (tab != NULL); | 636 | GNUNET_assert (tab != NULL); |
632 | tm = gtk_tree_view_get_model (tree_view); | 637 | tm = gtk_tree_view_get_model (tree_view); |
@@ -642,10 +647,52 @@ start_download (GtkTreeView * tree_view, GtkTreePath * path, | |||
642 | g_free (mime); | 647 | g_free (mime); |
643 | return; | 648 | return; |
644 | } | 649 | } |
650 | |||
651 | |||
652 | /* FIXME: we should check if this download is a file in some directory | ||
653 | (gtk_tree_model_iter_get_parent) and if so obtain the name under which | ||
654 | the directory was stored! */ | ||
655 | /* Calculate suggested filename; first, pre-pend current working directory */ | ||
656 | filename = GNUNET_FS_meta_data_suggest_filename (meta); | ||
657 | if (NULL != getcwd (cwd, sizeof (cwd))) | ||
658 | { | ||
659 | if (NULL == filename) | ||
660 | { | ||
661 | buf = GNUNET_strdup (cwd); | ||
662 | } | ||
663 | else | ||
664 | { | ||
665 | GNUNET_asprintf (&tmp, "%s%s%s", | ||
666 | cwd, | ||
667 | DIR_SEPARATOR_STR, | ||
668 | filename); | ||
669 | tmplen = strlen (tmp); | ||
670 | /* now, if we have a directory, replace trailing '/' with ".gnd" */ | ||
671 | if (GNUNET_YES == | ||
672 | GNUNET_FS_meta_data_test_for_directory (meta)) | ||
673 | { | ||
674 | if ( (tmp[tmplen-1] == '/') || | ||
675 | (tmp[tmplen-1] == '\\') ) | ||
676 | tmp[tmplen-1] = '\0'; | ||
677 | GNUNET_asprintf (&buf, | ||
678 | "%s%s", | ||
679 | tmp, | ||
680 | GNUNET_FS_DIRECTORY_EXT); | ||
681 | GNUNET_free (tmp); | ||
682 | } | ||
683 | else | ||
684 | { | ||
685 | buf = tmp; | ||
686 | } | ||
687 | } | ||
688 | } | ||
689 | GNUNET_free_non_null (filename); | ||
690 | |||
691 | /* now setup everything for the save-as dialog */ | ||
645 | dlc = GNUNET_malloc (sizeof (struct DownloadContext)); | 692 | dlc = GNUNET_malloc (sizeof (struct DownloadContext)); |
646 | dlc->uri = GNUNET_FS_uri_dup (uri); | 693 | dlc->uri = GNUNET_FS_uri_dup (uri); |
647 | dlc->mime = (NULL != mime) ? GNUNET_strdup (mime) : NULL; | 694 | dlc->mime = (NULL != mime) ? GNUNET_strdup (mime) : NULL; |
648 | dlc->filename = GNUNET_FS_meta_data_suggest_filename (meta); | 695 | dlc->filename = buf; |
649 | dlc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 696 | dlc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
650 | dlc->rr = gtk_tree_row_reference_new (tm, path); | 697 | dlc->rr = gtk_tree_row_reference_new (tm, path); |
651 | dlc->sr = sr->result; | 698 | dlc->sr = sr->result; |
@@ -1129,7 +1176,8 @@ setup_search (struct GNUNET_FS_SearchContext *sc, | |||
1129 | else | 1176 | else |
1130 | tab->query_txt = GNUNET_FS_uri_to_string (query); | 1177 | tab->query_txt = GNUNET_FS_uri_to_string (query); |
1131 | } | 1178 | } |
1132 | tab->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_search_tab.glade"); | 1179 | tab->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_search_tab.glade", |
1180 | tab); | ||
1133 | tab->ts = | 1181 | tab->ts = |
1134 | GTK_TREE_STORE (gtk_builder_get_object | 1182 | GTK_TREE_STORE (gtk_builder_get_object |
1135 | (tab->builder, | 1183 | (tab->builder, |
@@ -1154,7 +1202,7 @@ setup_search (struct GNUNET_FS_SearchContext *sc, | |||
1154 | tab->label = | 1202 | tab->label = |
1155 | GTK_LABEL (gtk_builder_get_object | 1203 | GTK_LABEL (gtk_builder_get_object |
1156 | (tab->builder, "_search_result_label_window_label")); | 1204 | (tab->builder, "_search_result_label_window_label")); |
1157 | 1205 | /* FIXME: connect these signals using glade!!! */ | |
1158 | tab->close_button = | 1206 | tab->close_button = |
1159 | GTK_WIDGET (gtk_builder_get_object | 1207 | GTK_WIDGET (gtk_builder_get_object |
1160 | (tab->builder, "_search_result_label_close_button")); | 1208 | (tab->builder, "_search_result_label_close_button")); |
@@ -1660,7 +1708,8 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn, | |||
1660 | /* create new tab */ | 1708 | /* create new tab */ |
1661 | publish_tab = GNUNET_malloc (sizeof (struct PublishTab)); | 1709 | publish_tab = GNUNET_malloc (sizeof (struct PublishTab)); |
1662 | publish_tab->builder = | 1710 | publish_tab->builder = |
1663 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade"); | 1711 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade", |
1712 | publish_tab); | ||
1664 | df = GTK_WINDOW (gtk_builder_get_object | 1713 | df = GTK_WINDOW (gtk_builder_get_object |
1665 | (publish_tab->builder, "_publish_frame_window")); | 1714 | (publish_tab->builder, "_publish_frame_window")); |
1666 | publish_tab->frame = gtk_bin_get_child (GTK_BIN (df)); | 1715 | publish_tab->frame = gtk_bin_get_child (GTK_BIN (df)); |
@@ -1676,6 +1725,7 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn, | |||
1676 | gtk_container_remove (GTK_CONTAINER (df), tab_label); | 1725 | gtk_container_remove (GTK_CONTAINER (df), tab_label); |
1677 | gtk_widget_destroy (GTK_WIDGET (df)); | 1726 | gtk_widget_destroy (GTK_WIDGET (df)); |
1678 | 1727 | ||
1728 | /* FIXME: connect these signals using GLADE!!! */ | ||
1679 | /* get refs to widgets */ | 1729 | /* get refs to widgets */ |
1680 | close_button = | 1730 | close_button = |
1681 | GTK_WIDGET (gtk_builder_get_object | 1731 | GTK_WIDGET (gtk_builder_get_object |
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 996b6ad1..85bf7ec7 100644 --- a/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c +++ b/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c | |||
@@ -73,7 +73,7 @@ GNUNET_GTK_main_menu_create_pseudonym_activate_cb (GtkWidget * dummy, | |||
73 | 73 | ||
74 | builder = | 74 | builder = |
75 | GNUNET_GTK_get_new_builder | 75 | GNUNET_GTK_get_new_builder |
76 | ("gnunet_fs_gtk_create_namespace_dialog.glade"); | 76 | ("gnunet_fs_gtk_create_namespace_dialog.glade", NULL); |
77 | if (builder == NULL) | 77 | if (builder == NULL) |
78 | { | 78 | { |
79 | GNUNET_break (0); | 79 | GNUNET_break (0); |
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 bf28109a..8b4717b5 100644 --- a/src/fs/gnunet-fs-gtk-main_window_open_directory.c +++ b/src/fs/gnunet-fs-gtk-main_window_open_directory.c | |||
@@ -130,7 +130,7 @@ GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy, | |||
130 | 130 | ||
131 | 131 | ||
132 | builder = | 132 | builder = |
133 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_open_directory_dialog.glade"); | 133 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_open_directory_dialog.glade", NULL); |
134 | if (builder == NULL) | 134 | if (builder == NULL) |
135 | { | 135 | { |
136 | GNUNET_break (0); | 136 | GNUNET_break (0); |
diff --git a/src/include/gnunet_gtk.h b/src/include/gnunet_gtk.h index b2242e96..cbf5c966 100644 --- a/src/include/gnunet_gtk.h +++ b/src/include/gnunet_gtk.h | |||
@@ -57,7 +57,7 @@ GNUNET_GTK_setup_nls (void); | |||
57 | * Initialize GTK search path for icons. | 57 | * Initialize GTK search path for icons. |
58 | */ | 58 | */ |
59 | void | 59 | void |
60 | GNUNET_GTK_set_icon_search_path (); | 60 | GNUNET_GTK_set_icon_search_path (void); |
61 | 61 | ||
62 | 62 | ||
63 | /** | 63 | /** |
@@ -87,10 +87,13 @@ GNUNET_GTK_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind); | |||
87 | * file. | 87 | * file. |
88 | * | 88 | * |
89 | * @param filename name of the resource file to load | 89 | * @param filename name of the resource file to load |
90 | * @param user_data user_data to pass to signal handlers, | ||
91 | * use "NULL" to pass the GtkBuilder itself. | ||
90 | * @return NULL on error | 92 | * @return NULL on error |
91 | */ | 93 | */ |
92 | GtkBuilder * | 94 | GtkBuilder * |
93 | GNUNET_GTK_get_new_builder (const char *filename); | 95 | GNUNET_GTK_get_new_builder (const char *filename, |
96 | void *user_data); | ||
94 | 97 | ||
95 | 98 | ||
96 | /** | 99 | /** |
@@ -121,31 +124,24 @@ GNUNET_GTK_tray_icon_create (GtkWindow * main, const char *icon_name, | |||
121 | void | 124 | void |
122 | GNUNET_GTK_tray_icon_destroy (void); | 125 | GNUNET_GTK_tray_icon_destroy (void); |
123 | 126 | ||
124 | char * | ||
125 | GNUNET_GTK_from_utf8_to_loc (gchar * str_utf8); | ||
126 | |||
127 | char * | ||
128 | GNUNET_GTK_from_loc_to_utf8 (gchar * str_loc); | ||
129 | |||
130 | char * | ||
131 | GNUNET_GTK_from_filename_to_utf8 (gchar * filename); | ||
132 | |||
133 | char * | ||
134 | GNUNET_GTK_from_utf8_to_filename (gchar * str_utf8); | ||
135 | 127 | ||
128 | /** | ||
129 | * Convert a string from the current locale to UTF-8. | ||
130 | * | ||
131 | * @param str_loc string in current locale | ||
132 | * @return string in UTF-8, NULL if str_loc was NULL | ||
133 | */ | ||
136 | char * | 134 | char * |
137 | GNUNET_GTK_from_loc_to_filename (gchar * str_loc); | 135 | GNUNET_GTK_from_loc_to_utf8 (const char * str_loc); |
138 | 136 | ||
139 | char * | ||
140 | GNUNET_GTK_from_filename_to_loc (gchar * filename); | ||
141 | 137 | ||
142 | /* Returns filename form filechooser, encoded in locale-dependent | 138 | /** |
143 | * encoding, suitable to be given to CRT and/or GNUnet | 139 | * Returns filename form filechooser, encoded in UTF-8. |
140 | * | ||
141 | * @param fc file chooser to inspect | ||
142 | * @return selected filename as UTF-8, NULL on errors | ||
144 | */ | 143 | */ |
145 | char * | 144 | char * |
146 | GNUNET_GTK_filechooser_get_filename_loc (GtkFileChooser * fc); | ||
147 | |||
148 | gchar * | ||
149 | GNUNET_GTK_filechooser_get_filename_utf8 (GtkFileChooser * fc); | 145 | GNUNET_GTK_filechooser_get_filename_utf8 (GtkFileChooser * fc); |
150 | 146 | ||
151 | 147 | ||
diff --git a/src/lib/about.c b/src/lib/about.c index ad0735e8..99ef3774 100644 --- a/src/lib/about.c +++ b/src/lib/about.c | |||
@@ -141,7 +141,7 @@ GNUNET_GTK_display_about (const char *dialogfile) | |||
141 | GtkBuilder *builder; | 141 | GtkBuilder *builder; |
142 | GtkWidget *ad; | 142 | GtkWidget *ad; |
143 | 143 | ||
144 | builder = GNUNET_GTK_get_new_builder (dialogfile); | 144 | builder = GNUNET_GTK_get_new_builder (dialogfile, NULL); |
145 | if (builder == NULL) | 145 | if (builder == NULL) |
146 | return; | 146 | return; |
147 | ad = GTK_WIDGET (gtk_builder_get_object (builder, "about_window")); | 147 | ad = GTK_WIDGET (gtk_builder_get_object (builder, "about_window")); |
diff --git a/src/lib/eventloop.c b/src/lib/eventloop.c index b4459d86..7b2be94a 100644 --- a/src/lib/eventloop.c +++ b/src/lib/eventloop.c | |||
@@ -844,7 +844,7 @@ run_main_loop (void *cls, char *const *args, const char *cfgfile, | |||
844 | gtk_init (&argc, (char ***) &args); | 844 | gtk_init (&argc, (char ***) &args); |
845 | 845 | ||
846 | /* setup main context */ | 846 | /* setup main context */ |
847 | ml->builder = GNUNET_GTK_get_new_builder (ml->main_window_file); | 847 | ml->builder = GNUNET_GTK_get_new_builder (ml->main_window_file, ml); |
848 | if (ml->builder == NULL) | 848 | if (ml->builder == NULL) |
849 | return; | 849 | return; |
850 | ml->rs = GNUNET_NETWORK_fdset_create (); | 850 | ml->rs = GNUNET_NETWORK_fdset_create (); |
diff --git a/src/lib/glade.c b/src/lib/glade.c index 4e5957cd..4bfb0f7c 100644 --- a/src/lib/glade.c +++ b/src/lib/glade.c | |||
@@ -63,10 +63,13 @@ GNUNET_GTK_get_data_dir () | |||
63 | * GNUnet-GTK glade file. | 63 | * GNUnet-GTK glade file. |
64 | * | 64 | * |
65 | * @param filename name of the resource file to load | 65 | * @param filename name of the resource file to load |
66 | * @param user_data user_data to pass to signal handlers, | ||
67 | * use "NULL" to pass the GtkBuilder itself. | ||
66 | * @return NULL on error | 68 | * @return NULL on error |
67 | */ | 69 | */ |
68 | GtkBuilder * | 70 | GtkBuilder * |
69 | GNUNET_GTK_get_new_builder (const char *filename) | 71 | GNUNET_GTK_get_new_builder (const char *filename, |
72 | void *user_data) | ||
70 | { | 73 | { |
71 | char *glade_path; | 74 | char *glade_path; |
72 | GtkBuilder *ret; | 75 | GtkBuilder *ret; |
@@ -84,7 +87,7 @@ GNUNET_GTK_get_new_builder (const char *filename) | |||
84 | GNUNET_free (glade_path); | 87 | GNUNET_free (glade_path); |
85 | return NULL; | 88 | return NULL; |
86 | } | 89 | } |
87 | gtk_builder_connect_signals (ret, ret); | 90 | gtk_builder_connect_signals (ret, (user_data == NULL) ? ret : user_data); |
88 | GNUNET_free (glade_path); | 91 | GNUNET_free (glade_path); |
89 | return ret; | 92 | return ret; |
90 | } | 93 | } |
diff --git a/src/lib/nls.c b/src/lib/nls.c index 08f74df8..29cb419b 100644 --- a/src/lib/nls.c +++ b/src/lib/nls.c | |||
@@ -54,28 +54,36 @@ GNUNET_GTK_setup_nls () | |||
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | char * | 57 | /* This is copied from GLib */ |
58 | GNUNET_GTK_from_utf8_to_loc (gchar * str_utf8) | 58 | /** |
59 | * Obtain character set used for filenames on this system. | ||
60 | * | ||
61 | * @param filename_charset set to the character set used for filenames | ||
62 | * @return TRUE if the locale is utf-8 | ||
63 | */ | ||
64 | static gboolean | ||
65 | get_filename_charset (const gchar ** filename_charset) | ||
59 | { | 66 | { |
60 | char *str_loc; | 67 | const gchar **charsets; |
61 | const char *loc_charset; | 68 | gboolean is_utf8; |
62 | gboolean is_UTF8; | ||
63 | 69 | ||
64 | if (NULL == str_utf8) | 70 | is_utf8 = g_get_filename_charsets (&charsets); |
65 | return NULL; | ||
66 | 71 | ||
67 | is_UTF8 = g_get_charset (&loc_charset); | 72 | if (filename_charset) |
68 | if (is_UTF8) | 73 | *filename_charset = charsets[0]; |
69 | str_loc = GNUNET_strdup (str_utf8); | ||
70 | else | ||
71 | str_loc = | ||
72 | GNUNET_STRINGS_from_utf8 (str_utf8, strlen (str_utf8), loc_charset); | ||
73 | 74 | ||
74 | return str_loc; | 75 | return is_utf8; |
75 | } | 76 | } |
76 | 77 | ||
78 | |||
79 | /** | ||
80 | * Convert a string from the current locale to UTF-8. | ||
81 | * | ||
82 | * @param str_loc string in current locale | ||
83 | * @return string in UTF-8, NULL if str_loc was NULL | ||
84 | */ | ||
77 | char * | 85 | char * |
78 | GNUNET_GTK_from_loc_to_utf8 (gchar * str_loc) | 86 | GNUNET_GTK_from_loc_to_utf8 (const char * str_loc) |
79 | { | 87 | { |
80 | char *str_utf8; | 88 | char *str_utf8; |
81 | const char *loc_charset; | 89 | const char *loc_charset; |
@@ -89,27 +97,18 @@ GNUNET_GTK_from_loc_to_utf8 (gchar * str_loc) | |||
89 | str_utf8 = GNUNET_strdup (str_loc); | 97 | str_utf8 = GNUNET_strdup (str_loc); |
90 | else | 98 | else |
91 | str_utf8 = GNUNET_STRINGS_to_utf8 (str_loc, strlen (str_loc), loc_charset); | 99 | str_utf8 = GNUNET_STRINGS_to_utf8 (str_loc, strlen (str_loc), loc_charset); |
92 | |||
93 | return str_utf8; | 100 | return str_utf8; |
94 | } | 101 | } |
95 | 102 | ||
96 | /* This is copied from GLib */ | ||
97 | static gboolean | ||
98 | get_filename_charset (const gchar ** filename_charset) | ||
99 | { | ||
100 | const gchar **charsets; | ||
101 | gboolean is_utf8; | ||
102 | |||
103 | is_utf8 = g_get_filename_charsets (&charsets); | ||
104 | |||
105 | if (filename_charset) | ||
106 | *filename_charset = charsets[0]; | ||
107 | 103 | ||
108 | return is_utf8; | 104 | /** |
109 | } | 105 | * Convert from locale used for filenames to UTF-8. |
110 | 106 | * | |
111 | char * | 107 | * @param filename filename in locale encoding |
112 | GNUNET_GTK_from_filename_to_utf8 (gchar * filename) | 108 | * @return filename in utf-8 encoding |
109 | */ | ||
110 | static char * | ||
111 | from_filename_to_utf8 (gchar * filename) | ||
113 | { | 112 | { |
114 | char *str_utf8; | 113 | char *str_utf8; |
115 | const char *filename_charset; | 114 | const char *filename_charset; |
@@ -128,107 +127,22 @@ GNUNET_GTK_from_filename_to_utf8 (gchar * filename) | |||
128 | return str_utf8; | 127 | return str_utf8; |
129 | } | 128 | } |
130 | 129 | ||
131 | char * | ||
132 | GNUNET_GTK_from_utf8_to_filename (gchar * str_utf8) | ||
133 | { | ||
134 | char *filename; | ||
135 | const char *filename_charset; | ||
136 | gboolean is_UTF8; | ||
137 | 130 | ||
138 | if (NULL == str_utf8) | 131 | /** |
139 | return NULL; | 132 | * Returns filename form filechooser, encoded in UTF-8. |
140 | 133 | * | |
141 | is_UTF8 = get_filename_charset (&filename_charset); | 134 | * @param fc file chooser to inspect |
142 | if (is_UTF8) | 135 | * @return selected filename as UTF-8, NULL on errors |
143 | filename = GNUNET_strdup (str_utf8); | ||
144 | else | ||
145 | filename = | ||
146 | GNUNET_STRINGS_from_utf8 (str_utf8, strlen (str_utf8), | ||
147 | filename_charset); | ||
148 | |||
149 | return filename; | ||
150 | } | ||
151 | |||
152 | char * | ||
153 | GNUNET_GTK_from_loc_to_filename (gchar * str_loc) | ||
154 | { | ||
155 | char *filename; | ||
156 | const char *filename_charset; | ||
157 | const char *loc_charset; | ||
158 | gboolean is_filename_UTF8, is_loc_UTF8; | ||
159 | |||
160 | if (NULL == str_loc) | ||
161 | return NULL; | ||
162 | |||
163 | is_filename_UTF8 = get_filename_charset (&filename_charset); | ||
164 | is_loc_UTF8 = g_get_charset (&loc_charset); | ||
165 | if (is_filename_UTF8 && is_loc_UTF8) | ||
166 | filename = GNUNET_strdup (str_loc); | ||
167 | else if (is_filename_UTF8) | ||
168 | filename = GNUNET_STRINGS_to_utf8 (str_loc, strlen (str_loc), loc_charset); | ||
169 | else if (is_loc_UTF8) | ||
170 | filename = | ||
171 | GNUNET_STRINGS_from_utf8 (str_loc, strlen (str_loc), filename_charset); | ||
172 | else | ||
173 | /* Pray that iconv() knows these charsets */ | ||
174 | filename = | ||
175 | GNUNET_STRINGS_conv (str_loc, strlen (str_loc), loc_charset, | ||
176 | filename_charset); | ||
177 | |||
178 | return filename; | ||
179 | } | ||
180 | |||
181 | char * | ||
182 | GNUNET_GTK_from_filename_to_loc (gchar * filename) | ||
183 | { | ||
184 | char *str_loc; | ||
185 | const char *loc_charset; | ||
186 | const char *filename_charset; | ||
187 | gboolean is_loc_UTF8, is_filename_UTF8; | ||
188 | |||
189 | if (NULL == filename) | ||
190 | return NULL; | ||
191 | |||
192 | is_filename_UTF8 = get_filename_charset (&filename_charset); | ||
193 | is_loc_UTF8 = g_get_charset (&loc_charset); | ||
194 | if (is_loc_UTF8 && is_filename_UTF8) | ||
195 | str_loc = GNUNET_strdup (filename); | ||
196 | else if (is_loc_UTF8) | ||
197 | str_loc = | ||
198 | GNUNET_STRINGS_to_utf8 (filename, strlen (filename), filename_charset); | ||
199 | else if (is_filename_UTF8) | ||
200 | str_loc = | ||
201 | GNUNET_STRINGS_from_utf8 (filename, strlen (filename), loc_charset); | ||
202 | else | ||
203 | /* Pray that iconv() knows these charsets */ | ||
204 | str_loc = | ||
205 | GNUNET_STRINGS_conv (filename, strlen (filename), filename_charset, | ||
206 | loc_charset); | ||
207 | |||
208 | return str_loc; | ||
209 | } | ||
210 | |||
211 | /* Returns filename form filechooser, encoded in locale-dependent | ||
212 | * encoding, suitable to be given to CRT and/or GNUnet | ||
213 | */ | 136 | */ |
214 | char * | 137 | char * |
215 | GNUNET_GTK_filechooser_get_filename_loc (GtkFileChooser * fc) | ||
216 | { | ||
217 | char *filename_loc; | ||
218 | gchar *filename = gtk_file_chooser_get_filename (fc); | ||
219 | |||
220 | filename_loc = GNUNET_GTK_from_filename_to_loc (filename); | ||
221 | g_free (filename); | ||
222 | return filename_loc; | ||
223 | } | ||
224 | |||
225 | gchar * | ||
226 | GNUNET_GTK_filechooser_get_filename_utf8 (GtkFileChooser * fc) | 138 | GNUNET_GTK_filechooser_get_filename_utf8 (GtkFileChooser * fc) |
227 | { | 139 | { |
228 | char *filename_utf8; | 140 | char *filename_utf8; |
229 | gchar *filename = gtk_file_chooser_get_filename (fc); | 141 | gchar *filename = gtk_file_chooser_get_filename (fc); |
230 | 142 | ||
231 | filename_utf8 = GNUNET_GTK_from_filename_to_utf8 (filename); | 143 | if (NULL == filename) |
144 | return NULL; | ||
145 | filename_utf8 = from_filename_to_utf8 (filename); | ||
232 | g_free (filename); | 146 | g_free (filename); |
233 | return filename_utf8; | 147 | return filename_utf8; |
234 | } | 148 | } |
diff --git a/src/lib/trayicon.c b/src/lib/trayicon.c index 57018abf..6c426f00 100644 --- a/src/lib/trayicon.c +++ b/src/lib/trayicon.c | |||
@@ -68,7 +68,7 @@ tray_icon_on_menu (GtkWidget * widget, GdkEvent * event, gpointer user_data) | |||
68 | event_button = (GdkEventButton *) event; | 68 | event_button = (GdkEventButton *) event; |
69 | if (event_button->button == 3) | 69 | if (event_button->button == 3) |
70 | { | 70 | { |
71 | builder = GNUNET_GTK_get_new_builder ("gnunet_gtk_status_bar_menu.glade"); | 71 | builder = GNUNET_GTK_get_new_builder ("gnunet_gtk_status_bar_menu.glade", NULL); |
72 | tray_menu = | 72 | tray_menu = |
73 | GTK_MENU (gtk_builder_get_object | 73 | GTK_MENU (gtk_builder_get_object |
74 | (builder, "GNUNET_GTK_status_bar_popup_menu")); | 74 | (builder, "GNUNET_GTK_status_bar_popup_menu")); |