diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-31 20:02:12 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-31 20:02:12 +0000 |
commit | 5b5d0f42600276ff39efb56057ac0249e5304e48 (patch) | |
tree | 470300489bb06dbdfa4f3700faa32ccc9f05c13b | |
parent | 9ea7d08b66349bc4f666f9d301b995dffbb8cf4c (diff) | |
download | gnunet-gtk-5b5d0f42600276ff39efb56057ac0249e5304e48.tar.gz gnunet-gtk-5b5d0f42600276ff39efb56057ac0249e5304e48.zip |
-documenting main_window_file_download.c code
-rw-r--r-- | src/fs/gnunet-fs-gtk-download.c | 2 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk-main_window_file_download.c | 117 |
2 files changed, 75 insertions, 44 deletions
diff --git a/src/fs/gnunet-fs-gtk-download.c b/src/fs/gnunet-fs-gtk-download.c index 8c4f8ee6..233f3fcc 100644 --- a/src/fs/gnunet-fs-gtk-download.c +++ b/src/fs/gnunet-fs-gtk-download.c | |||
@@ -49,6 +49,7 @@ GNUNET_GTK_save_as_dialog_free_download_context (struct DownloadContext *dc) | |||
49 | GNUNET_free (dc); | 49 | GNUNET_free (dc); |
50 | } | 50 | } |
51 | 51 | ||
52 | |||
52 | gboolean | 53 | gboolean |
53 | GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, | 54 | GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event, |
54 | gpointer user_data) | 55 | gpointer user_data) |
@@ -158,6 +159,7 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc) | |||
158 | gtk_window_present (GTK_WINDOW (ad)); | 159 | gtk_window_present (GTK_WINDOW (ad)); |
159 | } | 160 | } |
160 | 161 | ||
162 | |||
161 | void | 163 | void |
162 | GNUNET_FS_GTK_default_open_download_as_callback (struct DownloadContext *dc) | 164 | GNUNET_FS_GTK_default_open_download_as_callback (struct DownloadContext *dc) |
163 | { | 165 | { |
diff --git a/src/fs/gnunet-fs-gtk-main_window_file_download.c b/src/fs/gnunet-fs-gtk-main_window_file_download.c index ec0191b4..9fce0c65 100644 --- a/src/fs/gnunet-fs-gtk-main_window_file_download.c +++ b/src/fs/gnunet-fs-gtk-main_window_file_download.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2005, 2006, 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2005, 2006, 2010, 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 |
@@ -21,6 +21,11 @@ | |||
21 | /** | 21 | /** |
22 | * @file src/fs/gnunet-fs-gtk-main_window_file_download.c | 22 | * @file src/fs/gnunet-fs-gtk-main_window_file_download.c |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @brief code for the 'Open URI' dialog. | ||
25 | * | ||
26 | * TODO: | ||
27 | * - automatically populate dialog from clipboard? | ||
28 | * - use our own builder instead of the main builder? | ||
24 | */ | 29 | */ |
25 | #include "gnunet-fs-gtk-common.h" | 30 | #include "gnunet-fs-gtk-common.h" |
26 | #include "gnunet-fs-gtk-download.h" | 31 | #include "gnunet-fs-gtk-download.h" |
@@ -29,22 +34,23 @@ | |||
29 | 34 | ||
30 | /** | 35 | /** |
31 | * User selected "Open URI" in main window. | 36 | * User selected "Open URI" in main window. |
37 | * | ||
38 | * @param dummy some widget | ||
39 | * @param user_data unused | ||
32 | */ | 40 | */ |
33 | void | 41 | void |
34 | GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy, | 42 | GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy, |
35 | gpointer user_data) | 43 | gpointer user_data) |
36 | { | 44 | { |
37 | GtkBuilder *builder; | 45 | GtkBuilder *builder = GTK_BUILDER (user_data); |
38 | GtkWidget *dialog; | 46 | GtkWidget *dialog; |
39 | GtkTextBuffer *tb; | 47 | GtkTextBuffer *tb; |
40 | GtkTextIter ti_start, ti_end; | 48 | GtkTextIter ti_start; |
41 | 49 | GtkTextIter ti_end; | |
42 | builder = GTK_BUILDER (user_data); | ||
43 | |||
44 | dialog = | ||
45 | GTK_WIDGET (gtk_builder_get_object | ||
46 | (builder, "GNUNET_GTK_open_url_window")); | ||
47 | 50 | ||
51 | dialog = GTK_WIDGET (gtk_builder_get_object | ||
52 | (builder, | ||
53 | "GNUNET_GTK_open_url_window")); | ||
48 | tb = GTK_TEXT_BUFFER (gtk_builder_get_object | 54 | tb = GTK_TEXT_BUFFER (gtk_builder_get_object |
49 | (builder, | 55 | (builder, |
50 | "GNUNET_GTK_open_url_dialog_url_textview_buffer")); | 56 | "GNUNET_GTK_open_url_dialog_url_textview_buffer")); |
@@ -52,12 +58,18 @@ GNUNET_GTK_main_menu_file_download_uri_activate_cb (GtkWidget * dummy, | |||
52 | gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); | 58 | gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); |
53 | gtk_text_buffer_delete (tb, &ti_start, &ti_end); | 59 | gtk_text_buffer_delete (tb, &ti_start, &ti_end); |
54 | 60 | ||
55 | /* TODO: queue the clipboard, maybe there's valid URI in there? | 61 | /* TODO: query the clipboard, maybe there's valid URI in there? |
56 | * If so, get it. */ | 62 | * If so, get it. */ |
57 | |||
58 | gtk_widget_show (dialog); | 63 | gtk_widget_show (dialog); |
59 | } | 64 | } |
60 | 65 | ||
66 | |||
67 | /** | ||
68 | * User selected "execute" in the open-URI dialog. | ||
69 | * | ||
70 | * @param button the execute button | ||
71 | * @param user_data the 'GtkBuilder' of the URI dialog | ||
72 | */ | ||
61 | void | 73 | void |
62 | GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, | 74 | GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, |
63 | gpointer user_data) | 75 | gpointer user_data) |
@@ -125,28 +137,38 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button, | |||
125 | GNUNET_FS_uri_destroy (uri); | 137 | GNUNET_FS_uri_destroy (uri); |
126 | } | 138 | } |
127 | 139 | ||
140 | |||
141 | /** | ||
142 | * User selected "cancel" in the open-URI dialog. | ||
143 | * | ||
144 | * @param button the cancel button | ||
145 | * @param user_data the 'GtkBuilder' of the URI dialog | ||
146 | */ | ||
128 | void | 147 | void |
129 | GNUNET_GTK_open_url_dialog_cancel_button_clicked_cb (GtkButton * button, | 148 | GNUNET_GTK_open_url_dialog_cancel_button_clicked_cb (GtkButton * button, |
130 | gpointer user_data) | 149 | gpointer user_data) |
131 | { | 150 | { |
132 | GtkBuilder *builder; | 151 | GtkBuilder *builder = GTK_BUILDER (user_data); |
133 | |||
134 | builder = GTK_BUILDER (user_data); | ||
135 | 152 | ||
136 | gtk_widget_hide (GTK_WIDGET | 153 | gtk_widget_hide (GTK_WIDGET |
137 | (gtk_builder_get_object | 154 | (gtk_builder_get_object |
138 | (builder, "GNUNET_GTK_open_url_window"))); | 155 | (builder, "GNUNET_GTK_open_url_window"))); |
139 | return; | ||
140 | } | 156 | } |
141 | 157 | ||
158 | |||
159 | /** | ||
160 | * User closed the window of the open-URI dialog. | ||
161 | * | ||
162 | * @param widget the window | ||
163 | * @param event the deletion event | ||
164 | * @param user_data the 'GtkBuilder' of the URI dialog | ||
165 | */ | ||
142 | gboolean | 166 | gboolean |
143 | GNUNET_GTK_open_url_window_delete_event_cb (GtkWidget * widget, | 167 | GNUNET_GTK_open_url_window_delete_event_cb (GtkWidget * widget, |
144 | GdkEvent * event, | 168 | GdkEvent * event, |
145 | gpointer user_data) | 169 | gpointer user_data) |
146 | { | 170 | { |
147 | GtkBuilder *builder; | 171 | GtkBuilder *builder = GTK_BUILDER (user_data); |
148 | |||
149 | builder = GTK_BUILDER (user_data); | ||
150 | 172 | ||
151 | gtk_widget_hide (GTK_WIDGET | 173 | gtk_widget_hide (GTK_WIDGET |
152 | (gtk_builder_get_object | 174 | (gtk_builder_get_object |
@@ -154,54 +176,61 @@ GNUNET_GTK_open_url_window_delete_event_cb (GtkWidget * widget, | |||
154 | return TRUE; | 176 | return TRUE; |
155 | } | 177 | } |
156 | 178 | ||
157 | #ifndef GDK_KEY_Return | ||
158 | #define GDK_KEY_Return GDK_Return | ||
159 | #endif | ||
160 | 179 | ||
180 | |||
181 | /** | ||
182 | * User pushed a key in the open-URI dialog, check if we currently | ||
183 | * have valid URI and if the key was 'RETURN', run the action. | ||
184 | * | ||
185 | * @param widget the window | ||
186 | * @param event the deletion event | ||
187 | * @param user_data the 'GtkBuilder' of the URI dialog | ||
188 | */ | ||
161 | gboolean | 189 | gboolean |
162 | GNUNET_GTK_open_url_dialog_url_textview_key_press_event_cb (GtkWidget * widget, | 190 | GNUNET_GTK_open_url_dialog_url_textview_key_press_event_cb (GtkWidget * widget, |
163 | GdkEventKey * event, | 191 | GdkEventKey * event, |
164 | gpointer user_data) | 192 | gpointer user_data) |
165 | { | 193 | { |
166 | GtkBuilder *builder; | 194 | GtkBuilder *builder = GTK_BUILDER (user_data); |
167 | 195 | GtkWidget *execute; | |
168 | builder = GTK_BUILDER (user_data); | 196 | |
169 | 197 | if (event->keyval != GDK_KEY_Return) | |
170 | if (event->keyval == GDK_KEY_Return) | 198 | return FALSE; |
171 | { | 199 | execute = GTK_WIDGET (gtk_builder_get_object (builder, |
172 | GtkWidget *execute = GTK_WIDGET (gtk_builder_get_object (builder, | 200 | "GNUNET_GTK_open_url_dialog_execute_button")); |
173 | "GNUNET_GTK_open_url_dialog_execute_button")); | 201 | if (gtk_widget_get_sensitive (execute)) |
174 | 202 | GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GTK_BUTTON (execute), | |
175 | if (gtk_widget_get_sensitive (execute)) | 203 | user_data); |
176 | GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GTK_BUTTON | 204 | return TRUE; |
177 | (execute), | ||
178 | user_data); | ||
179 | return TRUE; | ||
180 | } | ||
181 | return FALSE; | ||
182 | } | 205 | } |
183 | 206 | ||
207 | |||
208 | /** | ||
209 | * User edited the URI of the open-URI dialog, check if it is currently | ||
210 | * a valid URI and update the sensitivity of the 'execute' button accordingly. | ||
211 | * | ||
212 | * @param textbuffer the updated buffer | ||
213 | * @param user_data the 'GtkBuilder' of the URI dialog | ||
214 | */ | ||
184 | void | 215 | void |
185 | GNUNET_GTK_open_url_dialog_url_textview_buffer_changed_cb (GtkTextBuffer * | 216 | GNUNET_GTK_open_url_dialog_url_textview_buffer_changed_cb (GtkTextBuffer * |
186 | textbuffer, | 217 | textbuffer, |
187 | gpointer user_data) | 218 | gpointer user_data) |
188 | { | 219 | { |
220 | GtkBuilder *builder = GTK_BUILDER (user_data); | ||
189 | struct GNUNET_FS_Uri *uri; | 221 | struct GNUNET_FS_Uri *uri; |
190 | GtkTextBuffer *tb; | 222 | GtkTextBuffer *tb; |
191 | GtkTextIter ti_start, ti_end; | 223 | GtkTextIter ti_start; |
192 | GtkBuilder *builder; | 224 | GtkTextIter ti_end; |
193 | char *perr; | 225 | char *perr; |
194 | char *uris; | 226 | char *uris; |
195 | 227 | ||
196 | builder = GTK_BUILDER (user_data); | ||
197 | |||
198 | perr = NULL; | 228 | perr = NULL; |
199 | tb = GTK_TEXT_BUFFER (gtk_builder_get_object | 229 | tb = GTK_TEXT_BUFFER (gtk_builder_get_object |
200 | (builder, | 230 | (builder, |
201 | "GNUNET_GTK_open_url_dialog_url_textview_buffer")); | 231 | "GNUNET_GTK_open_url_dialog_url_textview_buffer")); |
202 | gtk_text_buffer_get_iter_at_offset (tb, &ti_start, 0); | 232 | gtk_text_buffer_get_iter_at_offset (tb, &ti_start, 0); |
203 | gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); | 233 | gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); |
204 | |||
205 | uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE); | 234 | uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE); |
206 | if (uris != NULL) | 235 | if (uris != NULL) |
207 | uri = GNUNET_FS_uri_parse (uris, &perr); | 236 | uri = GNUNET_FS_uri_parse (uris, &perr); |
@@ -215,8 +244,8 @@ GNUNET_GTK_open_url_dialog_url_textview_buffer_changed_cb (GtkTextBuffer * | |||
215 | (uri == NULL) ? FALSE : TRUE); | 244 | (uri == NULL) ? FALSE : TRUE); |
216 | if (uri != NULL) | 245 | if (uri != NULL) |
217 | GNUNET_FS_uri_destroy (uri); | 246 | GNUNET_FS_uri_destroy (uri); |
218 | else | 247 | GNUNET_free_non_null (perr); |
219 | GNUNET_free_non_null (perr); | ||
220 | } | 248 | } |
221 | 249 | ||
250 | |||
222 | /* end of gnunet-fs-gtk-main_window_file_download.c */ | 251 | /* end of gnunet-fs-gtk-main_window_file_download.c */ |