diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c | 631 |
1 files changed, 140 insertions, 491 deletions
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 bb3265e0..9b76f2ab 100644 --- a/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c +++ b/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c | |||
@@ -24,343 +24,7 @@ | |||
24 | */ | 24 | */ |
25 | #include "gnunet-fs-gtk-common.h" | 25 | #include "gnunet-fs-gtk-common.h" |
26 | #include "gnunet-fs-gtk.h" | 26 | #include "gnunet-fs-gtk.h" |
27 | 27 | #include "gnunet-fs-gtk-edit_publish_dialog.h" | |
28 | static GtkBuilder *builder; | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Canonicalize spelling of currently selected keyword. | ||
33 | */ | ||
34 | void | ||
35 | GNUNET_GTK_advertise_pseudonym_keyword_list_normalize_button_clicked_cb () | ||
36 | { | ||
37 | GtkTreeView *tv; | ||
38 | GtkTreeSelection *sel; | ||
39 | GtkTreeModel *tm; | ||
40 | GtkTreeIter iter; | ||
41 | gchar *value; | ||
42 | struct GNUNET_FS_Uri *uri; | ||
43 | struct GNUNET_FS_Uri *nuri; | ||
44 | char *nvalue; | ||
45 | char *emsg; | ||
46 | |||
47 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
48 | (builder, | ||
49 | "GNUNET_GTK_advertise_pseudonym_keyword_list_tree_view")); | ||
50 | sel = gtk_tree_view_get_selection (tv); | ||
51 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
52 | { | ||
53 | GNUNET_break (0); | ||
54 | return; | ||
55 | } | ||
56 | gtk_tree_model_get (tm, &iter, 0, &value, -1); | ||
57 | emsg = NULL; | ||
58 | uri = GNUNET_FS_uri_ksk_create (value, &emsg); | ||
59 | if (uri == NULL) | ||
60 | { | ||
61 | GNUNET_break (0); | ||
62 | GNUNET_free (emsg); | ||
63 | g_free (value); | ||
64 | return; | ||
65 | } | ||
66 | nuri = GNUNET_FS_uri_ksk_canonicalize (uri); | ||
67 | nvalue = GNUNET_FS_uri_ksk_to_string_fancy (nuri); | ||
68 | gtk_list_store_set (GTK_LIST_STORE (tm), &iter, 0, nvalue, -1); | ||
69 | GNUNET_FS_uri_destroy (nuri); | ||
70 | GNUNET_FS_uri_destroy (uri); | ||
71 | GNUNET_free (nvalue); | ||
72 | g_free (value); | ||
73 | } | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Remove the currently selected keyword from the list. | ||
78 | */ | ||
79 | void | ||
80 | GNUNET_GTK_advertise_pseudonym_keyword_list_del_button_clicked_cb () | ||
81 | { | ||
82 | GtkTreeView *tv; | ||
83 | GtkTreeSelection *sel; | ||
84 | GtkTreeModel *tm; | ||
85 | GtkTreeIter iter; | ||
86 | GtkWidget *w; | ||
87 | |||
88 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
89 | (builder, | ||
90 | "GNUNET_GTK_advertise_pseudonym_keyword_list_tree_view")); | ||
91 | sel = gtk_tree_view_get_selection (tv); | ||
92 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
93 | { | ||
94 | GNUNET_break (0); | ||
95 | return; | ||
96 | } | ||
97 | gtk_list_store_remove (GTK_LIST_STORE (tm), &iter); | ||
98 | if (TRUE != gtk_tree_model_get_iter_first (tm, &iter)) | ||
99 | { | ||
100 | /* keyword list now empty, disable 'Ok' button! */ | ||
101 | w = GTK_WIDGET (gtk_builder_get_object (builder, | ||
102 | "GNUNET_GTK_advertise_pseudonym_confirm_button")); | ||
103 | gtk_widget_set_sensitive (w, FALSE); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Add keyword from entry line to keyword list. | ||
110 | */ | ||
111 | void | ||
112 | GNUNET_GTK_advertise_pseudonym_keyword_list_add_button_clicked_cb () | ||
113 | { | ||
114 | const char *keyword; | ||
115 | GtkEntry *entry; | ||
116 | GtkListStore *ls; | ||
117 | GtkTreeIter iter; | ||
118 | GtkWidget *w; | ||
119 | |||
120 | ls = GTK_LIST_STORE (gtk_builder_get_object | ||
121 | (builder, "GNUNET_GTK_keyword_list_store")); | ||
122 | entry = | ||
123 | GTK_ENTRY (gtk_builder_get_object | ||
124 | (builder, "GNUNET_GTK_advertise_pseudonym_keyword_entry")); | ||
125 | keyword = gtk_entry_get_text (entry); | ||
126 | if (strlen (keyword) > 0) | ||
127 | { | ||
128 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, keyword, -1); | ||
129 | /* enable OK button */ | ||
130 | w = GTK_WIDGET (gtk_builder_get_object (builder, "GNUNET_GTK_advertise_pseudonym_confirm_button")); | ||
131 | gtk_widget_set_sensitive (w, TRUE); | ||
132 | } | ||
133 | gtk_entry_set_text (entry, ""); | ||
134 | } | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Update sensitivity of keyword add button. | ||
139 | */ | ||
140 | void | ||
141 | GNUNET_GTK_advertise_pseudonym_keyword_entry_changed_cb () | ||
142 | { | ||
143 | const char *keyword; | ||
144 | GtkEntry *entry; | ||
145 | GtkWidget *button; | ||
146 | |||
147 | button = | ||
148 | GTK_WIDGET (gtk_builder_get_object | ||
149 | (builder, | ||
150 | "GNUNET_GTK_advertise_pseudonym_keyword_list_add_button")); | ||
151 | entry = | ||
152 | GTK_ENTRY (gtk_builder_get_object | ||
153 | (builder, "GNUNET_GTK_advertise_pseudonym_keyword_entry")); | ||
154 | keyword = gtk_entry_get_text (entry); | ||
155 | gtk_widget_set_sensitive (button, (strlen (keyword) > 0) ? TRUE : FALSE); | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * Update sensitivity of metadata delete button. | ||
160 | */ | ||
161 | static void | ||
162 | metadata_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) | ||
163 | { | ||
164 | GtkTreeView *tv; | ||
165 | GtkTreeSelection *sel; | ||
166 | GtkWidget *button; | ||
167 | |||
168 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
169 | (builder, | ||
170 | "GNUNET_GTK_advertise_pseudonym_metadata_tree_view")); | ||
171 | sel = gtk_tree_view_get_selection (tv); | ||
172 | button = | ||
173 | GTK_WIDGET (gtk_builder_get_object | ||
174 | (builder, | ||
175 | "GNUNET_GTK_advertise_pseudonym_metadata_delete_button")); | ||
176 | gtk_widget_set_sensitive (button, | ||
177 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | ||
178 | } | ||
179 | |||
180 | |||
181 | /** | ||
182 | * Update sensitivity of keyword delete and normalize button. | ||
183 | */ | ||
184 | static void | ||
185 | keyword_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) | ||
186 | { | ||
187 | GtkTreeView *tv; | ||
188 | GtkTreeSelection *sel; | ||
189 | GtkWidget *button; | ||
190 | |||
191 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
192 | (builder, | ||
193 | "GNUNET_GTK_advertise_pseudonym_keyword_list_tree_view")); | ||
194 | sel = gtk_tree_view_get_selection (tv); | ||
195 | button = | ||
196 | GTK_WIDGET (gtk_builder_get_object | ||
197 | (builder, | ||
198 | "GNUNET_GTK_advertise_pseudonym_keyword_list_del_button")); | ||
199 | |||
200 | gtk_widget_set_sensitive (button, | ||
201 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | ||
202 | button = | ||
203 | GTK_WIDGET (gtk_builder_get_object | ||
204 | (builder, | ||
205 | "GNUNET_GTK_advertise_pseudonym_keyword_list_normalize_button")); | ||
206 | gtk_widget_set_sensitive (button, | ||
207 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | ||
208 | } | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Update sensitivity of metadata add button. | ||
213 | */ | ||
214 | void | ||
215 | GNUNET_GTK_advertise_pseudonym_metadata_value_entry_changed_cb () | ||
216 | { | ||
217 | GtkTreeView *tv; | ||
218 | GtkTreeSelection *sel; | ||
219 | const char *value; | ||
220 | GtkEntry *entry; | ||
221 | GtkWidget *button; | ||
222 | |||
223 | entry = | ||
224 | GTK_ENTRY (gtk_builder_get_object | ||
225 | (builder, | ||
226 | "GNUNET_GTK_advertise_pseudonym_metadata_value_entry")); | ||
227 | value = gtk_entry_get_text (entry); | ||
228 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
229 | (builder, | ||
230 | "GNUNET_GTK_advertise_pseudonym_metadata_type_tree_view")); | ||
231 | sel = gtk_tree_view_get_selection (tv); | ||
232 | button = | ||
233 | GTK_WIDGET (gtk_builder_get_object | ||
234 | (builder, | ||
235 | "GNUNET_GTK_advertise_pseudonym_metadata_add_button")); | ||
236 | gtk_widget_set_sensitive (button, | ||
237 | (strlen (value) > | ||
238 | 0) ? gtk_tree_selection_get_selected (sel, NULL, | ||
239 | NULL) : | ||
240 | FALSE); | ||
241 | } | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Add keyword to keyword list. | ||
246 | */ | ||
247 | void | ||
248 | GNUNET_GTK_advertise_pseudonym_keyword_entry_activate_cb () | ||
249 | { | ||
250 | GNUNET_GTK_advertise_pseudonym_keyword_list_add_button_clicked_cb (); | ||
251 | } | ||
252 | |||
253 | |||
254 | void | ||
255 | GNUNET_GTK_advertise_pseudonym_metadata_preview_file_chooser_button_file_set_cb | ||
256 | () | ||
257 | { | ||
258 | GNUNET_break (0); | ||
259 | } | ||
260 | |||
261 | /** | ||
262 | * Delete currently selected item from meta data list. | ||
263 | */ | ||
264 | void | ||
265 | GNUNET_GTK_advertise_pseudonym_metadata_delete_button_clicked_cb () | ||
266 | { | ||
267 | GtkTreeView *tv; | ||
268 | GtkTreeSelection *sel; | ||
269 | GtkTreeModel *tm; | ||
270 | GtkTreeIter iter; | ||
271 | |||
272 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
273 | (builder, | ||
274 | "GNUNET_GTK_advertise_pseudonym_metadata_tree_view")); | ||
275 | sel = gtk_tree_view_get_selection (tv); | ||
276 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
277 | { | ||
278 | GNUNET_break (0); | ||
279 | return; | ||
280 | } | ||
281 | gtk_list_store_remove (GTK_LIST_STORE (tm), &iter); | ||
282 | } | ||
283 | |||
284 | |||
285 | /** | ||
286 | * Add metadata to metadata list. | ||
287 | */ | ||
288 | void | ||
289 | GNUNET_GTK_advertise_pseudonym_metadata_add_button_clicked_cb () | ||
290 | { | ||
291 | const char *value; | ||
292 | char *avalue; | ||
293 | const char *ivalue; | ||
294 | GtkEntry *entry; | ||
295 | GtkListStore *ls; | ||
296 | GtkTreeModel *tm; | ||
297 | GtkTreeView *tv; | ||
298 | GtkTreeSelection *sel; | ||
299 | GtkTreeIter iter; | ||
300 | guint type; | ||
301 | size_t slen; | ||
302 | char *pos; | ||
303 | |||
304 | entry = | ||
305 | GTK_ENTRY (gtk_builder_get_object | ||
306 | (builder, | ||
307 | "GNUNET_GTK_advertise_pseudonym_metadata_value_entry")); | ||
308 | value = gtk_entry_get_text (entry); | ||
309 | if ((value == NULL) || (strlen (value) == 0)) | ||
310 | { | ||
311 | GNUNET_break (0); | ||
312 | return; | ||
313 | } | ||
314 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
315 | (builder, | ||
316 | "GNUNET_GTK_advertise_pseudonym_metadata_type_tree_view")); | ||
317 | tm = gtk_tree_view_get_model (tv); | ||
318 | sel = gtk_tree_view_get_selection (tv); | ||
319 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
320 | { | ||
321 | GNUNET_break (0); | ||
322 | return; | ||
323 | } | ||
324 | gtk_tree_model_get (tm, &iter, 1, &type, -1); | ||
325 | ls = GTK_LIST_STORE (gtk_builder_get_object | ||
326 | (builder, "GNUNET_GTK_meta_data_list_store")); | ||
327 | if ((type == EXTRACTOR_METATYPE_FILENAME) && | ||
328 | (value[strlen (value) - 1] != '/')) | ||
329 | { | ||
330 | GNUNET_asprintf (&avalue, "%s/", value); | ||
331 | /* if user typed '\' instead of '/', change it! */ | ||
332 | slen = strlen (avalue); | ||
333 | while ((slen > 1) && (avalue[slen - 2] == '\\')) | ||
334 | { | ||
335 | avalue[slen - 2] = '/'; | ||
336 | avalue[slen - 1] = '\0'; | ||
337 | slen--; | ||
338 | } | ||
339 | while (NULL != (pos = strstr (avalue, "\\"))) | ||
340 | *pos = '/'; | ||
341 | /* remove '../' everywhere */ | ||
342 | while (NULL != (pos = strstr (avalue, "../"))) | ||
343 | { | ||
344 | pos[0] = '_'; | ||
345 | pos[1] = '_'; | ||
346 | pos[2] = '_'; | ||
347 | } | ||
348 | ivalue = avalue; | ||
349 | } | ||
350 | else | ||
351 | { | ||
352 | ivalue = value; | ||
353 | avalue = NULL; | ||
354 | } | ||
355 | |||
356 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, type, 1, | ||
357 | (guint) EXTRACTOR_METAFORMAT_UTF8, 2, | ||
358 | EXTRACTOR_metatype_to_string (type), 3, | ||
359 | ivalue, -1); | ||
360 | GNUNET_free_non_null (avalue); | ||
361 | gtk_entry_set_text (GTK_ENTRY (entry), ""); | ||
362 | } | ||
363 | |||
364 | 28 | ||
365 | /** | 29 | /** |
366 | * Callback with information about local (!) namespaces. | 30 | * Callback with information about local (!) namespaces. |
@@ -390,6 +54,8 @@ selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) | |||
390 | { | 54 | { |
391 | GtkTreeIter iter; | 55 | GtkTreeIter iter; |
392 | GtkWidget *ok_button; | 56 | GtkWidget *ok_button; |
57 | GtkBuilder *builder; | ||
58 | builder = GTK_BUILDER (user_data); | ||
393 | 59 | ||
394 | ok_button = | 60 | ok_button = |
395 | GTK_WIDGET (gtk_builder_get_object | 61 | GTK_WIDGET (gtk_builder_get_object |
@@ -400,60 +66,100 @@ selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) | |||
400 | gtk_widget_set_sensitive (ok_button, FALSE); | 66 | gtk_widget_set_sensitive (ok_button, FALSE); |
401 | } | 67 | } |
402 | 68 | ||
69 | struct namespace_data_struct | ||
70 | { | ||
71 | struct GNUNET_FS_Namespace *ns; | ||
72 | int do_index; | ||
73 | char *short_fn; | ||
74 | guint anonymity_level; | ||
75 | guint priority; | ||
76 | gchar *root; | ||
77 | }; | ||
403 | 78 | ||
404 | /** | 79 | /** |
405 | * Advertise pseudonym selected. | 80 | * Function called on entries in a GNUNET_FS_FileInformation publish-structure. |
81 | * | ||
82 | * @param cls closure | ||
83 | * @param fi the entry in the publish-structure | ||
84 | * @param length length of the file or directory | ||
85 | * @param meta metadata for the file or directory (can be modified) | ||
86 | * @param uri pointer to the keywords that will be used for this entry (can be modified) | ||
87 | * @param bo block options (can be modified) | ||
88 | * @param do_index should we index (can be modified) | ||
89 | * @param client_info pointer to client context set upon creation (can be modified) | ||
90 | * @return GNUNET_OK to continue, GNUNET_NO to remove | ||
91 | * this entry from the directory, GNUNET_SYSERR | ||
92 | * to abort the iteration | ||
406 | */ | 93 | */ |
94 | int | ||
95 | advertise_namespace (void *cls, struct GNUNET_FS_FileInformation *fi, | ||
96 | uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, | ||
97 | struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, | ||
98 | int *do_index, void **client_info) | ||
99 | { | ||
100 | struct namespace_data_struct *nds; | ||
101 | nds = (struct namespace_data_struct *) cls; | ||
102 | GNUNET_FS_namespace_advertise (GNUNET_FS_GTK_get_fs_handle (), *uri, | ||
103 | nds->ns, meta, bo, nds->root, NULL, NULL); | ||
104 | return GNUNET_SYSERR; | ||
105 | } | ||
106 | |||
407 | void | 107 | void |
408 | GNUNET_GTK_main_menu_file_advertise_pseudonym_activate_cb (GtkWidget * dummy, | 108 | adv_pseudonym_edit_publish_dialog_cb (gpointer cls, int *do_index, char **short_fn, |
409 | gpointer data) | 109 | guint * anonymity_level, guint * priority, gchar *root, |
110 | struct GNUNET_FS_FileInformation *fip, gint ret) | ||
111 | { | ||
112 | struct namespace_data_struct *nds; | ||
113 | nds = (struct namespace_data_struct *) cls; | ||
114 | |||
115 | if (ret == GTK_RESPONSE_OK) | ||
116 | { | ||
117 | nds->do_index = *do_index; | ||
118 | nds->short_fn = *short_fn; | ||
119 | nds->anonymity_level = *anonymity_level; | ||
120 | nds->priority = *priority; | ||
121 | nds->root = root; | ||
122 | GNUNET_FS_file_information_inspect (fip, | ||
123 | advertise_namespace, nds); | ||
124 | } | ||
125 | g_free (nds->root); | ||
126 | GNUNET_FS_namespace_delete (nds->ns, GNUNET_NO); | ||
127 | g_free (nds); | ||
128 | GNUNET_FS_file_information_destroy (fip, NULL, NULL); | ||
129 | } | ||
130 | |||
131 | void | ||
132 | GNUNET_GTK_select_pseudonym_dialog_response_cb (GtkDialog *dialog, | ||
133 | gint response_id, gpointer user_data) | ||
410 | { | 134 | { |
135 | GtkBuilder *builder; | ||
411 | GtkWidget *ad; | 136 | GtkWidget *ad; |
412 | struct GNUNET_FS_Namespace *ns; | ||
413 | struct GNUNET_FS_Namespace *nso; | ||
414 | GtkListStore *ls; | ||
415 | GtkTreeView *tv; | 137 | GtkTreeView *tv; |
416 | GtkTreeIter iter; | ||
417 | GtkTreeSelection *sel; | 138 | GtkTreeSelection *sel; |
418 | GtkTreeModel *tm; | 139 | GtkTreeModel *tm; |
419 | GtkSpinButton *sb; | 140 | GtkTreeIter iter; |
141 | struct GNUNET_FS_Namespace *ns; | ||
142 | struct GNUNET_FS_Namespace *nso; | ||
143 | GtkWindow *transient; | ||
144 | struct namespace_data_struct *nds; | ||
145 | struct GNUNET_FS_FileInformation *fip; | ||
146 | struct GNUNET_CONTAINER_MetaData *meta; | ||
147 | builder = GTK_BUILDER (user_data); | ||
420 | struct GNUNET_FS_BlockOptions bo; | 148 | struct GNUNET_FS_BlockOptions bo; |
421 | struct GNUNET_FS_Uri *nxt; | ||
422 | struct GNUNET_FS_Uri *mrg; | ||
423 | struct GNUNET_FS_Uri *uri; | ||
424 | struct GNUNET_CONTAINER_MetaData *nm; | ||
425 | const char *root; | ||
426 | char *value; | ||
427 | guint ntype; | ||
428 | guint nformat; | ||
429 | guint type; | ||
430 | guint max_type; | ||
431 | 149 | ||
432 | builder = | ||
433 | GNUNET_GTK_get_new_builder | ||
434 | ("gnunet_fs_gtk_select_pseudonym_dialog.glade"); | ||
435 | if (builder == NULL) | ||
436 | { | ||
437 | GNUNET_break (0); | ||
438 | return; | ||
439 | } | ||
440 | ad = GTK_WIDGET (gtk_builder_get_object | 150 | ad = GTK_WIDGET (gtk_builder_get_object |
441 | (builder, "GNUNET_GTK_select_pseudonym_dialog")); | 151 | (builder, "GNUNET_GTK_select_pseudonym_dialog")); |
442 | ls = GTK_LIST_STORE (gtk_builder_get_object | 152 | |
443 | (builder, "GNUNET_GTK_select_pseudonym_liststore")); | 153 | if (response_id != -5) |
444 | GNUNET_FS_namespace_list (GNUNET_FS_GTK_get_fs_handle (), &add_to_list, ls); | ||
445 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
446 | (builder, "GNUNET_GTK_select_pseudonym_tree_view")); | ||
447 | sel = gtk_tree_view_get_selection (tv); | ||
448 | g_signal_connect (G_OBJECT (sel), "changed", | ||
449 | G_CALLBACK (selection_changed_cb), NULL); | ||
450 | if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) | ||
451 | { | 154 | { |
452 | gtk_widget_destroy (ad); | 155 | gtk_widget_hide (ad); |
453 | g_object_unref (G_OBJECT (builder)); | ||
454 | builder = NULL; | ||
455 | return; | 156 | return; |
456 | } | 157 | } |
158 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
159 | (builder, | ||
160 | "GNUNET_GTK_select_pseudonym_tree_view")); | ||
161 | sel = gtk_tree_view_get_selection (tv); | ||
162 | |||
457 | GNUNET_assert (TRUE == gtk_tree_selection_get_selected (sel, &tm, &iter)); | 163 | GNUNET_assert (TRUE == gtk_tree_selection_get_selected (sel, &tm, &iter)); |
458 | gtk_tree_model_get (tm, &iter, 1, &ns, -1); | 164 | gtk_tree_model_get (tm, &iter, 1, &ns, -1); |
459 | /* free all namespaces from list store except "ns" */ | 165 | /* free all namespaces from list store except "ns" */ |
@@ -467,129 +173,72 @@ GNUNET_GTK_main_menu_file_advertise_pseudonym_activate_cb (GtkWidget * dummy, | |||
467 | } | 173 | } |
468 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | 174 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); |
469 | } | 175 | } |
470 | gtk_widget_destroy (ad); | 176 | transient = gtk_window_get_transient_for (GTK_WINDOW (ad)); |
471 | g_object_unref (G_OBJECT (builder)); | 177 | gtk_widget_hide (ad); |
472 | builder = NULL; | 178 | |
179 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
180 | |||
181 | nds = g_new0 (struct namespace_data_struct, 1); | ||
182 | nds->ns = ns; | ||
183 | nds->do_index = FALSE; | ||
184 | nds->short_fn = NULL; | ||
185 | nds->anonymity_level = 1; | ||
186 | nds->priority = 1000; | ||
187 | nds->root = NULL; | ||
188 | /* This is a bogus fileinfo. It's needed because edit_publish_dialog | ||
189 | * was written to work with fileinfo, and return a fileinfo. | ||
190 | */ | ||
191 | memset (&bo, 0, sizeof (bo)); | ||
192 | fip = GNUNET_FS_file_information_create_empty_directory (NULL, NULL, | ||
193 | NULL, meta, &bo); | ||
194 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
195 | |||
196 | GNUNET_FS_GTK_edit_publish_dialog (builder, transient, &nds->do_index, | ||
197 | &nds->short_fn, &nds->anonymity_level, &nds->priority, | ||
198 | fip, FALSE, &adv_pseudonym_edit_publish_dialog_cb, nds); | ||
199 | } | ||
473 | 200 | ||
201 | void | ||
202 | GNUNET_GTK_select_pseudonym_dialog_realize_cb (GtkWidget *widget, | ||
203 | gpointer user_data) | ||
204 | { | ||
205 | GtkTreeView *tv; | ||
206 | GtkTreeSelection *sel; | ||
207 | GtkBuilder *builder; | ||
474 | 208 | ||
475 | builder = | 209 | builder = GTK_BUILDER (user_data); |
476 | GNUNET_GTK_get_new_builder | ||
477 | ("gnunet_fs_gtk_advertise_pseudonym_dialog.glade"); | ||
478 | if (builder == NULL) | ||
479 | { | ||
480 | GNUNET_break (0); | ||
481 | return; | ||
482 | } | ||
483 | GNUNET_FS_GTK_setup_expiration_year_adjustment (builder); | ||
484 | ad = GTK_WIDGET (gtk_builder_get_object | ||
485 | (builder, "GNUNET_GTK_advertise_pseudonym_dialog")); | ||
486 | ls = GTK_LIST_STORE (gtk_builder_get_object | ||
487 | (builder, "GNUNET_GTK_metatype_list_store")); | ||
488 | max_type = EXTRACTOR_metatype_get_max (); | ||
489 | type = 1; | ||
490 | while (type < max_type - 1) | ||
491 | { | ||
492 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, | ||
493 | EXTRACTOR_metatype_to_string (type), 1, | ||
494 | type, 2, | ||
495 | EXTRACTOR_metatype_to_description (type), | ||
496 | -1); | ||
497 | type++; | ||
498 | } | ||
499 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
500 | (builder, | ||
501 | "GNUNET_GTK_advertise_pseudonym_metadata_type_tree_view")); | ||
502 | sel = gtk_tree_view_get_selection (tv); | ||
503 | g_signal_connect (G_OBJECT (sel), "changed", | ||
504 | G_CALLBACK | ||
505 | (GNUNET_GTK_advertise_pseudonym_metadata_value_entry_changed_cb), | ||
506 | NULL); | ||
507 | 210 | ||
508 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 211 | tv = GTK_TREE_VIEW (gtk_builder_get_object |
509 | (builder, | 212 | (builder, "GNUNET_GTK_select_pseudonym_tree_view")); |
510 | "GNUNET_GTK_advertise_pseudonym_metadata_tree_view")); | ||
511 | sel = gtk_tree_view_get_selection (tv); | 213 | sel = gtk_tree_view_get_selection (tv); |
512 | g_signal_connect (G_OBJECT (sel), "changed", | 214 | g_signal_connect (G_OBJECT (sel), "changed", |
513 | G_CALLBACK (metadata_selection_changed_cb), NULL); | 215 | G_CALLBACK (selection_changed_cb), user_data); |
216 | } | ||
514 | 217 | ||
515 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 218 | /** |
516 | (builder, | 219 | * Advertise pseudonym selected. |
517 | "GNUNET_GTK_advertise_pseudonym_keyword_list_tree_view")); | 220 | */ |
518 | sel = gtk_tree_view_get_selection (tv); | 221 | void |
519 | g_signal_connect (G_OBJECT (sel), "changed", | 222 | GNUNET_GTK_main_menu_file_advertise_pseudonym_activate_cb (GtkWidget * dummy, |
520 | G_CALLBACK (keyword_selection_changed_cb), NULL); | 223 | gpointer data) |
521 | if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) | 224 | { |
522 | { | 225 | GtkWidget *ad; |
523 | gtk_widget_destroy (ad); | 226 | GtkListStore *ls; |
524 | g_object_unref (G_OBJECT (builder)); | 227 | GtkWidget *toplevel; |
525 | builder = NULL; | 228 | GtkBuilder *builder; |
526 | return; | 229 | |
527 | } | 230 | builder = GTK_BUILDER (data); |
528 | /* get keywords from list store */ | 231 | |
529 | nxt = NULL; | 232 | ad = GTK_WIDGET (gtk_builder_get_object |
530 | mrg = NULL; | 233 | (builder, "GNUNET_GTK_select_pseudonym_dialog")); |
531 | uri = NULL; | 234 | ls = GTK_LIST_STORE (gtk_builder_get_object |
532 | tm = GTK_TREE_MODEL (gtk_builder_get_object | 235 | (builder, "GNUNET_GTK_select_pseudonym_liststore")); |
533 | (builder, "GNUNET_GTK_keyword_list_store")); | 236 | gtk_list_store_clear (ls); |
534 | if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) | 237 | GNUNET_FS_namespace_list (GNUNET_FS_GTK_get_fs_handle (), &add_to_list, ls); |
535 | { | 238 | toplevel = gtk_widget_get_toplevel (dummy); |
536 | do | 239 | if (GTK_IS_WINDOW (toplevel)) |
537 | { | 240 | gtk_window_set_transient_for (GTK_WINDOW (ad), GTK_WINDOW (toplevel)); |
538 | gtk_tree_model_get (tm, &iter, 0, &value, -1); | 241 | gtk_window_present (GTK_WINDOW (ad)); |
539 | nxt = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &value); | ||
540 | mrg = GNUNET_FS_uri_ksk_merge (nxt, uri); | ||
541 | GNUNET_FS_uri_destroy (nxt); | ||
542 | if (NULL != uri) | ||
543 | GNUNET_FS_uri_destroy (uri); | ||
544 | uri = mrg; | ||
545 | g_free (value); | ||
546 | } | ||
547 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | ||
548 | } | ||
549 | /* get meta */ | ||
550 | nm = GNUNET_CONTAINER_meta_data_create (); | ||
551 | tm = GTK_TREE_MODEL (gtk_builder_get_object | ||
552 | (builder, "GNUNET_GTK_meta_data_list_store")); | ||
553 | if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) | ||
554 | { | ||
555 | do | ||
556 | { | ||
557 | gtk_tree_model_get (tm, &iter, 0, &ntype, 1, &nformat, 3, &value, -1); | ||
558 | GNUNET_CONTAINER_meta_data_insert (nm, "<user>", ntype, nformat, | ||
559 | "text/plain", value, | ||
560 | strlen (value) + 1); | ||
561 | g_free (value); | ||
562 | } | ||
563 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | ||
564 | } | ||
565 | bo.anonymity_level = | ||
566 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | ||
567 | (gtk_builder_get_object | ||
568 | (builder, | ||
569 | "GNUNET_GTK_advertise_pseudonym_anonymity_spin_button"))); | ||
570 | bo.content_priority = | ||
571 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | ||
572 | (gtk_builder_get_object | ||
573 | (builder, | ||
574 | "GNUNET_GTK_advertise_pseudonym_priority_spin_button"))); | ||
575 | sb = GTK_SPIN_BUTTON (gtk_builder_get_object | ||
576 | (builder, | ||
577 | "GNUNET_GTK_advertise_pseudonym_expiration_year_spin_button")); | ||
578 | bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (sb); | ||
579 | root = | ||
580 | gtk_entry_get_text (GTK_ENTRY | ||
581 | (gtk_builder_get_object | ||
582 | (builder, | ||
583 | "GNUNET_GTK_advertise_pseudonym_root_entry"))); | ||
584 | GNUNET_FS_namespace_advertise (GNUNET_FS_GTK_get_fs_handle (), uri, ns, nm, | ||
585 | &bo, root, NULL, NULL); | ||
586 | GNUNET_FS_namespace_delete (ns, GNUNET_NO); | ||
587 | GNUNET_CONTAINER_meta_data_destroy (nm); | ||
588 | if (NULL != uri) | ||
589 | GNUNET_FS_uri_destroy (uri); | ||
590 | gtk_widget_destroy (ad); | ||
591 | g_object_unref (G_OBJECT (builder)); | ||
592 | builder = NULL; | ||
593 | } | 242 | } |
594 | 243 | ||
595 | 244 | ||