diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-02-02 18:29:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-02-02 18:29:18 +0000 |
commit | 1bab689e627882afa76876410c2a0f8be373515d (patch) | |
tree | 975f41d73b7f71fbc199fb3eb710f931d9782ced | |
parent | cb59fc9a28dd75dcf326b632bcd97fb10551c4f4 (diff) | |
download | gnunet-gtk-1bab689e627882afa76876410c2a0f8be373515d.tar.gz gnunet-gtk-1bab689e627882afa76876410c2a0f8be373515d.zip |
-renaming and using our own builder in the open-URI dialog
-rw-r--r-- | src/fs/Makefile.am | 4 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_open-uri.c (renamed from src/fs/gnunet-fs-gtk-main_window_file_download.c) | 116 |
2 files changed, 70 insertions, 50 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 2e19b9b6..0fc819d8 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -12,9 +12,9 @@ bin_PROGRAMS = gnunet-fs-gtk | |||
12 | gnunet_fs_gtk_SOURCES = \ | 12 | gnunet_fs_gtk_SOURCES = \ |
13 | gnunet-fs-gtk.c gnunet-fs-gtk.h \ | 13 | gnunet-fs-gtk.c gnunet-fs-gtk.h \ |
14 | gnunet-fs-gtk_about.c \ | 14 | gnunet-fs-gtk_about.c \ |
15 | gnunet-fs-gtk_advertise-pseudonym.c \ | ||
15 | gnunet-fs-gtk_anonymity-widgets.c gnunet-fs-gtk_anonymity-widgets.h \ | 16 | gnunet-fs-gtk_anonymity-widgets.c gnunet-fs-gtk_anonymity-widgets.h \ |
16 | gnunet-fs-gtk_common.c gnunet-fs-gtk_common.h \ | 17 | gnunet-fs-gtk_common.c gnunet-fs-gtk_common.h \ |
17 | gnunet-fs-gtk_advertise-pseudonym.c \ | ||
18 | gnunet-fs-gtk_create-pseudonym.c \ | 18 | gnunet-fs-gtk_create-pseudonym.c \ |
19 | gnunet-fs-gtk_download-save-as.c gnunet-fs-gtk_download-save-as.h \ | 19 | gnunet-fs-gtk_download-save-as.c gnunet-fs-gtk_download-save-as.h \ |
20 | gnunet-fs-gtk_event-handler.c gnunet-fs-gtk_event-handler.h \ | 20 | gnunet-fs-gtk_event-handler.c gnunet-fs-gtk_event-handler.h \ |
@@ -22,9 +22,9 @@ gnunet_fs_gtk_SOURCES = \ | |||
22 | gnunet-fs-gtk_main-window-search.c \ | 22 | gnunet-fs-gtk_main-window-search.c \ |
23 | gnunet-fs-gtk_main-window-view-toggles.c \ | 23 | gnunet-fs-gtk_main-window-view-toggles.c \ |
24 | gnunet-fs-gtk_open-directory.c \ | 24 | gnunet-fs-gtk_open-directory.c \ |
25 | gnunet-fs-gtk_open-uri.c \ | ||
25 | gnunet-fs-gtk_publish-dialog.c \ | 26 | gnunet-fs-gtk_publish-dialog.c \ |
26 | gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \ | 27 | gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \ |
27 | gnunet-fs-gtk-main_window_file_download.c \ | ||
28 | gnunet-fs-gtk-main_window_namespace.c | 28 | gnunet-fs-gtk-main_window_namespace.c |
29 | gnunet_fs_gtk_LDADD = \ | 29 | gnunet_fs_gtk_LDADD = \ |
30 | $(top_builddir)/src/lib/libgnunetgtk.la \ | 30 | $(top_builddir)/src/lib/libgnunetgtk.la \ |
diff --git a/src/fs/gnunet-fs-gtk-main_window_file_download.c b/src/fs/gnunet-fs-gtk_open-uri.c index 73ec3bb9..6962c2a5 100644 --- a/src/fs/gnunet-fs-gtk-main_window_file_download.c +++ b/src/fs/gnunet-fs-gtk_open-uri.c | |||
@@ -19,50 +19,18 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file src/fs/gnunet-fs-gtk-main_window_file_download.c | 22 | * @file src/fs/gnunet-fs-gtk_open-uri.c |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @brief code for the 'Open URI' dialog. | 24 | * @brief code for the 'Open URI' dialog. |
25 | * | 25 | * |
26 | * TODO: | 26 | * TODO: |
27 | * - automatically populate dialog from clipboard? | 27 | * - automatically populate dialog from clipboard? |
28 | * - use our own builder instead of the main builder? | ||
29 | */ | 28 | */ |
30 | #include "gnunet-fs-gtk_common.h" | 29 | #include "gnunet-fs-gtk_common.h" |
31 | #include "gnunet-fs-gtk_download-save-as.h" | 30 | #include "gnunet-fs-gtk_download-save-as.h" |
32 | #include "gnunet-fs-gtk.h" | 31 | #include "gnunet-fs-gtk.h" |
33 | #include <gdk/gdkkeysyms.h> | 32 | #include <gdk/gdkkeysyms.h> |
34 | 33 | ||
35 | /** | ||
36 | * User selected "Open URI" in main window. | ||
37 | * | ||
38 | * @param dummy some widget | ||
39 | * @param user_data unused | ||
40 | */ | ||
41 | void | ||
42 | GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy, | ||
43 | gpointer user_data) | ||
44 | { | ||
45 | GtkBuilder *builder = GTK_BUILDER (user_data); | ||
46 | GtkWidget *dialog; | ||
47 | GtkTextBuffer *tb; | ||
48 | GtkTextIter ti_start; | ||
49 | GtkTextIter ti_end; | ||
50 | |||
51 | dialog = GTK_WIDGET (gtk_builder_get_object | ||
52 | (builder, | ||
53 | "GNUNET_GTK_open_url_window")); | ||
54 | tb = GTK_TEXT_BUFFER (gtk_builder_get_object | ||
55 | (builder, | ||
56 | "GNUNET_GTK_open_url_dialog_url_textview_buffer")); | ||
57 | gtk_text_buffer_get_iter_at_offset (tb, &ti_start, 0); | ||
58 | gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); | ||
59 | gtk_text_buffer_delete (tb, &ti_start, &ti_end); | ||
60 | |||
61 | /* TODO: query the clipboard, maybe there's valid URI in there? | ||
62 | * If so, get it. */ | ||
63 | gtk_widget_show (dialog); | ||
64 | } | ||
65 | |||
66 | 34 | ||
67 | /** | 35 | /** |
68 | * User selected "execute" in the open-URI dialog. | 36 | * User selected "execute" in the open-URI dialog. |
@@ -84,13 +52,9 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, | |||
84 | struct GNUNET_FS_Uri *uri; | 52 | struct GNUNET_FS_Uri *uri; |
85 | 53 | ||
86 | builder = GTK_BUILDER (user_data); | 54 | builder = GTK_BUILDER (user_data); |
87 | |||
88 | dialog = | 55 | dialog = |
89 | GTK_WIDGET (gtk_builder_get_object | 56 | GTK_WIDGET (gtk_builder_get_object |
90 | (builder, "GNUNET_GTK_open_url_window")); | 57 | (builder, "GNUNET_GTK_open_url_window")); |
91 | |||
92 | gtk_widget_hide (dialog); | ||
93 | |||
94 | tb = GTK_TEXT_BUFFER (gtk_builder_get_object | 58 | tb = GTK_TEXT_BUFFER (gtk_builder_get_object |
95 | (builder, | 59 | (builder, |
96 | "GNUNET_GTK_open_url_dialog_url_textview_buffer")); | 60 | "GNUNET_GTK_open_url_dialog_url_textview_buffer")); |
@@ -101,25 +65,32 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, | |||
101 | 65 | ||
102 | if (!GNUNET_GTK_get_selected_anonymity_level | 66 | if (!GNUNET_GTK_get_selected_anonymity_level |
103 | (builder, "main_window_search_anonymity_combobox", &anonymity_level)) | 67 | (builder, "main_window_search_anonymity_combobox", &anonymity_level)) |
68 | { | ||
69 | GNUNET_break (0); | ||
70 | gtk_widget_destroy (dialog); | ||
71 | g_object_unref (G_OBJECT (builder)); | ||
104 | return; | 72 | return; |
105 | 73 | } | |
106 | uri = GNUNET_FS_uri_parse (uris, &perr); | 74 | uri = GNUNET_FS_uri_parse (uris, &perr); |
107 | g_free (uris); | 75 | g_free (uris); |
108 | if (uri == NULL) | 76 | if (uri == NULL) |
109 | { | 77 | { |
110 | GNUNET_free (perr); | ||
111 | /* Why was "execute" button sensitive!? */ | 78 | /* Why was "execute" button sensitive!? */ |
112 | GNUNET_break (0); | 79 | GNUNET_break (0); |
80 | GNUNET_free (perr); | ||
81 | gtk_widget_destroy (dialog); | ||
82 | g_object_unref (G_OBJECT (builder)); | ||
113 | return; | 83 | return; |
114 | } | 84 | } |
115 | if (GNUNET_FS_uri_test_sks (uri) || GNUNET_FS_uri_test_ksk (uri)) | 85 | if (GNUNET_FS_uri_test_sks (uri) || GNUNET_FS_uri_test_ksk (uri)) |
116 | { | 86 | { |
117 | fprintf (stderr, "Starting search!\n"); | ||
118 | GNUNET_break (NULL != | 87 | GNUNET_break (NULL != |
119 | GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri, | 88 | GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri, |
120 | anonymity_level, | 89 | anonymity_level, |
121 | GNUNET_FS_SEARCH_OPTION_NONE, NULL)); | 90 | GNUNET_FS_SEARCH_OPTION_NONE, NULL)); |
122 | GNUNET_FS_uri_destroy (uri); | 91 | GNUNET_FS_uri_destroy (uri); |
92 | gtk_widget_destroy (dialog); | ||
93 | g_object_unref (G_OBJECT (builder)); | ||
123 | return; | 94 | return; |
124 | } | 95 | } |
125 | if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)) | 96 | if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)) |
@@ -130,10 +101,14 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, | |||
130 | dc->uri = uri; | 101 | dc->uri = uri; |
131 | dc->anonymity = anonymity_level; | 102 | dc->anonymity = anonymity_level; |
132 | GNUNET_FS_GTK_open_download_as_dialog (dc); | 103 | GNUNET_FS_GTK_open_download_as_dialog (dc); |
104 | gtk_widget_destroy (dialog); | ||
105 | g_object_unref (G_OBJECT (builder)); | ||
133 | return; | 106 | return; |
134 | } | 107 | } |
135 | GNUNET_break (0); | 108 | GNUNET_break (0); |
136 | GNUNET_FS_uri_destroy (uri); | 109 | GNUNET_FS_uri_destroy (uri); |
110 | gtk_widget_destroy (dialog); | ||
111 | g_object_unref (G_OBJECT (builder)); | ||
137 | } | 112 | } |
138 | 113 | ||
139 | 114 | ||
@@ -148,10 +123,13 @@ GNUNET_GTK_open_url_dialog_cancel_button_clicked_cb (GtkButton * button, | |||
148 | gpointer user_data) | 123 | gpointer user_data) |
149 | { | 124 | { |
150 | GtkBuilder *builder = GTK_BUILDER (user_data); | 125 | GtkBuilder *builder = GTK_BUILDER (user_data); |
126 | GtkWidget *dialog; | ||
151 | 127 | ||
152 | gtk_widget_hide (GTK_WIDGET | 128 | dialog = GTK_WIDGET (gtk_builder_get_object |
153 | (gtk_builder_get_object | 129 | (builder, |
154 | (builder, "GNUNET_GTK_open_url_window"))); | 130 | "GNUNET_GTK_open_url_window")); |
131 | gtk_widget_destroy (GTK_WIDGET (dialog)); | ||
132 | g_object_unref (G_OBJECT (builder)); | ||
155 | } | 133 | } |
156 | 134 | ||
157 | 135 | ||
@@ -161,6 +139,7 @@ GNUNET_GTK_open_url_dialog_cancel_button_clicked_cb (GtkButton * button, | |||
161 | * @param widget the window | 139 | * @param widget the window |
162 | * @param event the deletion event | 140 | * @param event the deletion event |
163 | * @param user_data the 'GtkBuilder' of the URI dialog | 141 | * @param user_data the 'GtkBuilder' of the URI dialog |
142 | * @return TRUE (allow destruction) | ||
164 | */ | 143 | */ |
165 | gboolean | 144 | gboolean |
166 | GNUNET_GTK_open_url_window_delete_event_cb (GtkWidget * widget, | 145 | GNUNET_GTK_open_url_window_delete_event_cb (GtkWidget * widget, |
@@ -169,14 +148,11 @@ GNUNET_GTK_open_url_window_delete_event_cb (GtkWidget * widget, | |||
169 | { | 148 | { |
170 | GtkBuilder *builder = GTK_BUILDER (user_data); | 149 | GtkBuilder *builder = GTK_BUILDER (user_data); |
171 | 150 | ||
172 | gtk_widget_hide (GTK_WIDGET | 151 | g_object_unref (G_OBJECT (builder)); |
173 | (gtk_builder_get_object | ||
174 | (builder, "GNUNET_GTK_open_url_window"))); | ||
175 | return TRUE; | 152 | return TRUE; |
176 | } | 153 | } |
177 | 154 | ||
178 | 155 | ||
179 | |||
180 | /** | 156 | /** |
181 | * User pushed a key in the open-URI dialog, check if we currently | 157 | * User pushed a key in the open-URI dialog, check if we currently |
182 | * have valid URI and if the key was 'RETURN', run the action. | 158 | * have valid URI and if the key was 'RETURN', run the action. |
@@ -247,4 +223,48 @@ GNUNET_GTK_open_url_dialog_url_textview_buffer_changed_cb (GtkTextBuffer * | |||
247 | } | 223 | } |
248 | 224 | ||
249 | 225 | ||
250 | /* end of gnunet-fs-gtk-main_window_file_download.c */ | 226 | /** |
227 | * User selected "Open URI" in main window. | ||
228 | * | ||
229 | * @param dummy the menu entry | ||
230 | * @param user_data unused | ||
231 | */ | ||
232 | void | ||
233 | GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy, | ||
234 | gpointer user_data) | ||
235 | { | ||
236 | GtkBuilder *builder; | ||
237 | GtkWidget *dialog; | ||
238 | GtkTextBuffer *tb; | ||
239 | GtkTextIter ti_start; | ||
240 | GtkTextIter ti_end; | ||
241 | GtkWidget *toplevel; | ||
242 | |||
243 | builder = | ||
244 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_open_url_dialog.glade", NULL); | ||
245 | if (NULL == builder) | ||
246 | { | ||
247 | GNUNET_break (0); | ||
248 | return; | ||
249 | } | ||
250 | dialog = GTK_WIDGET (gtk_builder_get_object | ||
251 | (builder, | ||
252 | "GNUNET_GTK_open_url_window")); | ||
253 | tb = GTK_TEXT_BUFFER (gtk_builder_get_object | ||
254 | (builder, | ||
255 | "GNUNET_GTK_open_url_dialog_url_textview_buffer")); | ||
256 | gtk_text_buffer_get_iter_at_offset (tb, &ti_start, 0); | ||
257 | gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); | ||
258 | gtk_text_buffer_delete (tb, &ti_start, &ti_end); | ||
259 | |||
260 | /* FIXME-FEATURE: query the clipboard, maybe there's valid URI in there? | ||
261 | * If so, get it. */ | ||
262 | |||
263 | toplevel = gtk_widget_get_toplevel (dummy); | ||
264 | if (GTK_IS_WINDOW (toplevel)) | ||
265 | gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel)); | ||
266 | gtk_widget_show (dialog); | ||
267 | } | ||
268 | |||
269 | |||
270 | /* end of gnunet-fs-gtk_open-uri.c */ | ||