diff options
Diffstat (limited to 'src/edit_publish_dialog.c')
-rw-r--r-- | src/edit_publish_dialog.c | 663 |
1 files changed, 663 insertions, 0 deletions
diff --git a/src/edit_publish_dialog.c b/src/edit_publish_dialog.c new file mode 100644 index 00000000..932088af --- /dev/null +++ b/src/edit_publish_dialog.c | |||
@@ -0,0 +1,663 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2005, 2006, 2010 Christian Grothoff (and other contributing authors) | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/edit_publish_dialog.c | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "common.h" | ||
26 | #include "edit_publish_dialog.h" | ||
27 | #include <gnunet/gnunet_util_lib.h> | ||
28 | |||
29 | /** | ||
30 | * Builder for the current dialog. | ||
31 | */ | ||
32 | static GtkBuilder *builder; | ||
33 | |||
34 | |||
35 | void | ||
36 | GNUNET_GTK_edit_file_information_keyword_list_normalize_button_clicked_cb () | ||
37 | { | ||
38 | GNUNET_break (0); | ||
39 | } | ||
40 | |||
41 | void | ||
42 | GNUNET_GTK_edit_file_information_keyword_list_del_button_clicked_cb () | ||
43 | { | ||
44 | GtkTreeView *tv; | ||
45 | GtkTreeSelection *sel; | ||
46 | GtkTreeModel *tm; | ||
47 | GtkTreeIter iter; | ||
48 | |||
49 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
50 | "GNUNET_GTK_edit_file_information_keyword_list_tree_view")); | ||
51 | sel = gtk_tree_view_get_selection (tv); | ||
52 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
53 | { | ||
54 | GNUNET_break (0); | ||
55 | return; | ||
56 | } | ||
57 | gtk_list_store_remove (GTK_LIST_STORE (tm), | ||
58 | &iter); | ||
59 | } | ||
60 | |||
61 | void | ||
62 | GNUNET_GTK_edit_file_information_keyword_list_add_button_clicked_cb () | ||
63 | { | ||
64 | const char *keyword; | ||
65 | GtkEntry *entry; | ||
66 | GtkListStore *ls; | ||
67 | GtkTreeIter iter; | ||
68 | |||
69 | ls = GTK_LIST_STORE (gtk_builder_get_object (builder, | ||
70 | "GNUNET_GTK_keyword_list_store")); | ||
71 | entry = GTK_ENTRY (gtk_builder_get_object (builder, | ||
72 | "GNUNET_GTK_edit_file_information_keyword_entry")); | ||
73 | keyword = gtk_entry_get_text (entry); | ||
74 | if (strlen (keyword) > 0) | ||
75 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, keyword, -1); | ||
76 | gtk_entry_set_text (entry, ""); | ||
77 | } | ||
78 | |||
79 | |||
80 | void | ||
81 | GNUNET_GTK_edit_file_information_keyword_entry_changed_cb () | ||
82 | { | ||
83 | const char *keyword; | ||
84 | GtkEntry *entry; | ||
85 | GtkWidget *button; | ||
86 | |||
87 | button = GTK_WIDGET (gtk_builder_get_object (builder, | ||
88 | "GNUNET_GTK_edit_file_information_keyword_list_add_button")); | ||
89 | entry = GTK_ENTRY (gtk_builder_get_object (builder, | ||
90 | "GNUNET_GTK_edit_file_information_keyword_entry")); | ||
91 | keyword = gtk_entry_get_text (entry); | ||
92 | gtk_widget_set_sensitive (button, | ||
93 | (strlen (keyword) > 0) ? TRUE : FALSE); | ||
94 | } | ||
95 | |||
96 | |||
97 | static void | ||
98 | metadata_selection_changed_cb (GtkTreeSelection *ts, | ||
99 | gpointer user_data) | ||
100 | { | ||
101 | GtkTreeView *tv; | ||
102 | GtkTreeSelection *sel; | ||
103 | GtkWidget *button; | ||
104 | |||
105 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
106 | "GNUNET_GTK_edit_file_information_metadata_tree_view")); | ||
107 | sel = gtk_tree_view_get_selection (tv); | ||
108 | button = GTK_WIDGET (gtk_builder_get_object (builder, | ||
109 | "GNUNET_GTK_edit_file_information_metadata_delete_button")); | ||
110 | gtk_widget_set_sensitive (button, | ||
111 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | ||
112 | } | ||
113 | |||
114 | |||
115 | static void | ||
116 | keyword_selection_changed_cb (GtkTreeSelection *ts, | ||
117 | gpointer user_data) | ||
118 | { | ||
119 | GtkTreeView *tv; | ||
120 | GtkTreeSelection *sel; | ||
121 | GtkWidget *button; | ||
122 | |||
123 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
124 | "GNUNET_GTK_edit_file_information_keyword_list_tree_view")); | ||
125 | sel = gtk_tree_view_get_selection (tv); | ||
126 | button = GTK_WIDGET (gtk_builder_get_object (builder, | ||
127 | "GNUNET_GTK_edit_file_information_keyword_list_del_button")); | ||
128 | |||
129 | gtk_widget_set_sensitive (button, | ||
130 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | ||
131 | button = GTK_WIDGET (gtk_builder_get_object (builder, | ||
132 | "GNUNET_GTK_edit_file_information_keyword_list_normalize_button")); | ||
133 | gtk_widget_set_sensitive (button, | ||
134 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | ||
135 | } | ||
136 | |||
137 | |||
138 | void | ||
139 | GNUNET_GTK_edit_file_information_metadata_value_entry_changed_cb () | ||
140 | { | ||
141 | GtkTreeView *tv; | ||
142 | GtkTreeSelection *sel; | ||
143 | const char *value; | ||
144 | GtkEntry *entry; | ||
145 | GtkWidget *button; | ||
146 | |||
147 | entry = GTK_ENTRY (gtk_builder_get_object (builder, | ||
148 | "GNUNET_GTK_edit_file_information_metadata_value_entry")); | ||
149 | value = gtk_entry_get_text (entry); | ||
150 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
151 | "GNUNET_GTK_edit_file_information_metadata_type_tree_view")); | ||
152 | sel = gtk_tree_view_get_selection (tv); | ||
153 | button = GTK_WIDGET (gtk_builder_get_object (builder, | ||
154 | "GNUNET_GTK_edit_file_information_metadata_add_button")); | ||
155 | gtk_widget_set_sensitive (button, | ||
156 | (strlen (value) > 0) | ||
157 | ? gtk_tree_selection_get_selected (sel, NULL, NULL) | ||
158 | : FALSE); | ||
159 | } | ||
160 | |||
161 | |||
162 | void | ||
163 | GNUNET_GTK_edit_file_information_keyword_entry_activate_cb () | ||
164 | { | ||
165 | GNUNET_GTK_edit_file_information_keyword_list_add_button_clicked_cb (); | ||
166 | } | ||
167 | |||
168 | |||
169 | void | ||
170 | GNUNET_GTK_edit_file_information_metadata_preview_file_chooser_button_file_set_cb () | ||
171 | { | ||
172 | GNUNET_break (0); | ||
173 | } | ||
174 | |||
175 | void | ||
176 | GNUNET_GTK_edit_file_information_metadata_delete_button_clicked_cb() | ||
177 | { | ||
178 | GtkTreeView *tv; | ||
179 | GtkTreeSelection *sel; | ||
180 | GtkTreeModel *tm; | ||
181 | GtkTreeIter iter; | ||
182 | |||
183 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
184 | "GNUNET_GTK_edit_file_information_metadata_tree_view")); | ||
185 | sel = gtk_tree_view_get_selection (tv); | ||
186 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
187 | { | ||
188 | GNUNET_break (0); | ||
189 | return; | ||
190 | } | ||
191 | gtk_list_store_remove (GTK_LIST_STORE (tm), | ||
192 | &iter); | ||
193 | } | ||
194 | |||
195 | |||
196 | void | ||
197 | GNUNET_GTK_edit_file_information_metadata_add_button_clicked_cb () | ||
198 | { | ||
199 | const char *value; | ||
200 | GtkEntry *entry; | ||
201 | GtkListStore *ls; | ||
202 | GtkTreeModel *tm; | ||
203 | GtkTreeView *tv; | ||
204 | GtkTreeSelection *sel; | ||
205 | GtkTreeIter iter; | ||
206 | guint type; | ||
207 | |||
208 | entry = GTK_ENTRY (gtk_builder_get_object (builder, | ||
209 | "GNUNET_GTK_edit_file_information_metadata_value_entry")); | ||
210 | value = gtk_entry_get_text (entry); | ||
211 | if ((value == NULL) || (strlen (value) == 0)) | ||
212 | { | ||
213 | GNUNET_break (0); | ||
214 | return; | ||
215 | } | ||
216 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
217 | "GNUNET_GTK_edit_file_information_metadata_type_tree_view")); | ||
218 | tm = gtk_tree_view_get_model (tv); | ||
219 | sel = gtk_tree_view_get_selection (tv); | ||
220 | if (TRUE != gtk_tree_selection_get_selected (sel, | ||
221 | &tm, | ||
222 | &iter)) | ||
223 | { | ||
224 | GNUNET_break (0); | ||
225 | return; | ||
226 | } | ||
227 | gtk_tree_model_get (tm, | ||
228 | &iter, | ||
229 | 1, &type, -1); | ||
230 | ls = GTK_LIST_STORE (gtk_builder_get_object (builder, | ||
231 | "GNUNET_GTK_meta_data_list_store")); | ||
232 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, | ||
233 | 0, type, | ||
234 | 1, (guint) EXTRACTOR_METAFORMAT_UTF8, | ||
235 | 2, EXTRACTOR_metatype_to_string (type), | ||
236 | 3, value, | ||
237 | -1); | ||
238 | gtk_entry_set_text (GTK_ENTRY (entry), ""); | ||
239 | } | ||
240 | |||
241 | |||
242 | /** | ||
243 | * Add each of the keywords to the keyword list store. | ||
244 | * | ||
245 | * @param cls closure | ||
246 | * @param keyword the keyword | ||
247 | * @param is_mandatory is the keyword mandatory (in a search) | ||
248 | * @return GNUNET_OK to continue to iterate | ||
249 | */ | ||
250 | static int | ||
251 | add_keyword (void *cls, | ||
252 | const char *keyword, | ||
253 | int is_mandatory) | ||
254 | { | ||
255 | GtkListStore *ls; | ||
256 | GtkTreeIter iter; | ||
257 | |||
258 | ls = GTK_LIST_STORE (gtk_builder_get_object (builder, | ||
259 | "GNUNET_GTK_keyword_list_store")); | ||
260 | gtk_list_store_insert_with_values (ls, &iter, | ||
261 | G_MAXINT, | ||
262 | 0, keyword, | ||
263 | -1); | ||
264 | return GNUNET_OK; | ||
265 | } | ||
266 | |||
267 | |||
268 | /** | ||
269 | * Add the given meta data to the model (or make it the preview | ||
270 | * image if it is an image). | ||
271 | * | ||
272 | * @param cls closure, NULL | ||
273 | * @param plugin_name name of the plugin that produced this value; | ||
274 | * special values can be used (i.e. '<zlib>' for zlib being | ||
275 | * used in the main libextractor library and yielding | ||
276 | * meta data). | ||
277 | * @param type libextractor-type describing the meta data | ||
278 | * @param format basic format information about data | ||
279 | * @param data_mime_type mime-type of data (not of the original file); | ||
280 | * can be NULL (if mime-type is not known) | ||
281 | * @param data actual meta-data found | ||
282 | * @param data_len number of bytes in data | ||
283 | * @return 0 to continue extracting | ||
284 | */ | ||
285 | static int | ||
286 | add_meta_item (void *cls, | ||
287 | const char *plugin_name, | ||
288 | enum EXTRACTOR_MetaType type, | ||
289 | enum EXTRACTOR_MetaFormat format, | ||
290 | const char *data_mime_type, | ||
291 | const char *data, | ||
292 | size_t data_len) | ||
293 | { | ||
294 | GtkListStore *ls; | ||
295 | GtkTreeIter iter; | ||
296 | |||
297 | switch (format) | ||
298 | { | ||
299 | case EXTRACTOR_METAFORMAT_UTF8: | ||
300 | case EXTRACTOR_METAFORMAT_C_STRING: | ||
301 | ls = GTK_LIST_STORE (gtk_builder_get_object (builder, | ||
302 | "GNUNET_GTK_meta_data_list_store")); | ||
303 | gtk_list_store_insert_with_values (ls, &iter, | ||
304 | G_MAXINT, | ||
305 | 0, (guint) type, | ||
306 | 1, (guint) format, | ||
307 | 2, EXTRACTOR_metatype_to_string (type), | ||
308 | 3, data, | ||
309 | -1); | ||
310 | break; | ||
311 | case EXTRACTOR_METAFORMAT_UNKNOWN: | ||
312 | break; | ||
313 | case EXTRACTOR_METAFORMAT_BINARY: | ||
314 | break; | ||
315 | default: | ||
316 | GNUNET_break (0); | ||
317 | } | ||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | |||
322 | /** | ||
323 | * Function called to extract the information from FI. | ||
324 | * | ||
325 | * @param cls closure | ||
326 | * @param fi the entry in the publish-structure | ||
327 | * @param length length of the file or directory | ||
328 | * @param meta metadata for the file or directory (can be modified) | ||
329 | * @param uri pointer to the keywords that will be used for this entry (can be modified) | ||
330 | * @param anonymity pointer to selected anonymity level (can be modified) | ||
331 | * @param priority pointer to selected priority (can be modified) | ||
332 | * @param do_index should we index (can be modified) | ||
333 | * @param expirationTime pointer to selected expiration time (can be modified) | ||
334 | * @param client_info pointer to client context set upon creation (can be modified) | ||
335 | * @return GNUNET_SYSERR (aborts after first call) | ||
336 | */ | ||
337 | static int | ||
338 | file_information_extract (void *cls, | ||
339 | struct GNUNET_FS_FileInformation *fi, | ||
340 | uint64_t length, | ||
341 | struct GNUNET_CONTAINER_MetaData *meta, | ||
342 | struct GNUNET_FS_Uri **uri, | ||
343 | uint32_t *anonymity, | ||
344 | uint32_t *priority, | ||
345 | int *do_index, | ||
346 | struct GNUNET_TIME_Absolute *expirationTime, | ||
347 | void **client_info) | ||
348 | { | ||
349 | GtkImage *img; | ||
350 | GdkPixbuf *pixbuf; | ||
351 | |||
352 | if (NULL != *uri) | ||
353 | GNUNET_FS_uri_ksk_get_keywords (*uri, &add_keyword, NULL); | ||
354 | if (NULL != meta) | ||
355 | { | ||
356 | GNUNET_CONTAINER_meta_data_iterate (meta, | ||
357 | &add_meta_item, | ||
358 | NULL); | ||
359 | pixbuf = GNUNET_GTK_get_thumbnail_from_meta_data (meta); | ||
360 | if (pixbuf != NULL) | ||
361 | { | ||
362 | img = GTK_IMAGE (gtk_builder_get_object (builder, | ||
363 | "GNUNET_GTK_edit_file_information_metadata_preview_image")); | ||
364 | gtk_image_set_from_pixbuf (img, | ||
365 | pixbuf); | ||
366 | } | ||
367 | } | ||
368 | /* FIXME: set expiration time (not yet in dialog!) */ | ||
369 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, | ||
370 | "GNUNET_GTK_edit_file_information_anonymity_spin_button")), | ||
371 | *anonymity); | ||
372 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, | ||
373 | "GNUNET_GTK_edit_file_information_priority_spin_button")), | ||
374 | *priority); | ||
375 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, | ||
376 | "GNUNET_GTK_edit_file_information_index_check_button")), | ||
377 | *do_index); | ||
378 | return GNUNET_SYSERR; /* only visit top-level item */ | ||
379 | } | ||
380 | |||
381 | |||
382 | /** | ||
383 | * Copy binary meta data from to the new container and also | ||
384 | * preserve all entries that were not changed. | ||
385 | * | ||
386 | * @param cls closure, new meta data container | ||
387 | * @param plugin_name name of the plugin that produced this value; | ||
388 | * special values can be used (i.e. '<zlib>' for zlib being | ||
389 | * used in the main libextractor library and yielding | ||
390 | * meta data). | ||
391 | * @param type libextractor-type describing the meta data | ||
392 | * @param format basic format information about data | ||
393 | * @param data_mime_type mime-type of data (not of the original file); | ||
394 | * can be NULL (if mime-type is not known) | ||
395 | * @param data actual meta-data found | ||
396 | * @param data_len number of bytes in data | ||
397 | * @return 0 to continue extracting | ||
398 | */ | ||
399 | static int | ||
400 | preserve_meta_items (void *cls, | ||
401 | const char *plugin_name, | ||
402 | enum EXTRACTOR_MetaType type, | ||
403 | enum EXTRACTOR_MetaFormat format, | ||
404 | const char *data_mime_type, | ||
405 | const char *data, | ||
406 | size_t data_len) | ||
407 | { | ||
408 | struct GNUNET_CONTAINER_MetaData *md = cls; | ||
409 | GtkTreeModel *tm; | ||
410 | GtkTreeIter iter; | ||
411 | char *value; | ||
412 | guint ntype; | ||
413 | guint nformat; | ||
414 | int keep; | ||
415 | |||
416 | keep = GNUNET_NO; | ||
417 | switch (format) | ||
418 | { | ||
419 | case EXTRACTOR_METAFORMAT_UTF8: | ||
420 | case EXTRACTOR_METAFORMAT_C_STRING: | ||
421 | tm = GTK_TREE_MODEL (gtk_builder_get_object (builder, | ||
422 | "GNUNET_GTK_meta_data_list_store")); | ||
423 | if (TRUE == | ||
424 | gtk_tree_model_get_iter_first (tm, &iter)) | ||
425 | { | ||
426 | do | ||
427 | { | ||
428 | gtk_tree_model_get (tm, &iter, | ||
429 | 0, &ntype, | ||
430 | 1, &nformat, | ||
431 | 3, &value, | ||
432 | -1); | ||
433 | if ( (ntype == type) && | ||
434 | (nformat == format) && | ||
435 | (0 == strcmp (value, data)) ) | ||
436 | { | ||
437 | gtk_list_store_remove (GTK_LIST_STORE (tm), &iter); | ||
438 | keep = GNUNET_YES; | ||
439 | g_free (value); | ||
440 | break; | ||
441 | } | ||
442 | g_free (value); | ||
443 | } | ||
444 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | ||
445 | } | ||
446 | break; | ||
447 | case EXTRACTOR_METAFORMAT_UNKNOWN: | ||
448 | break; | ||
449 | case EXTRACTOR_METAFORMAT_BINARY: | ||
450 | /* FIXME: this is here since we don't have preview support yet */ | ||
451 | keep = GNUNET_YES; | ||
452 | break; | ||
453 | default: | ||
454 | GNUNET_break (0); | ||
455 | break; | ||
456 | } | ||
457 | if (GNUNET_YES == keep) | ||
458 | GNUNET_break (GNUNET_OK == | ||
459 | GNUNET_CONTAINER_meta_data_insert (md, | ||
460 | plugin_name, type, format, | ||
461 | data_mime_type, data, data_len)); | ||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | |||
466 | /** | ||
467 | * Function called to update the information in FI. | ||
468 | * | ||
469 | * @param cls closure (short_fn to update) | ||
470 | * @param fi the entry in the publish-structure | ||
471 | * @param length length of the file or directory | ||
472 | * @param meta metadata for the file or directory (can be modified) | ||
473 | * @param uri pointer to the keywords that will be used for this entry (can be modified) | ||
474 | * @param anonymity pointer to selected anonymity level (can be modified) | ||
475 | * @param priority pointer to selected priority (can be modified) | ||
476 | * @param do_index should we index (can be modified) | ||
477 | * @param expirationTime pointer to selected expiration time (can be modified) | ||
478 | * @param client_info pointer to client context set upon creation (can be modified) | ||
479 | * @return GNUNET_SYSERR (aborts after first call) | ||
480 | */ | ||
481 | static int | ||
482 | file_information_update (void *cls, | ||
483 | struct GNUNET_FS_FileInformation *fi, | ||
484 | uint64_t length, | ||
485 | struct GNUNET_CONTAINER_MetaData *meta, | ||
486 | struct GNUNET_FS_Uri **uri, | ||
487 | uint32_t *anonymity, | ||
488 | uint32_t *priority, | ||
489 | int *do_index, | ||
490 | struct GNUNET_TIME_Absolute *expirationTime, | ||
491 | void **client_info) | ||
492 | { | ||
493 | char **short_fn = cls; | ||
494 | struct GNUNET_CONTAINER_MetaData *nm; | ||
495 | GtkTreeModel *tm; | ||
496 | GtkTreeIter iter; | ||
497 | struct GNUNET_FS_Uri *nxt; | ||
498 | struct GNUNET_FS_Uri *mrg; | ||
499 | char *value; | ||
500 | guint ntype; | ||
501 | guint nformat; | ||
502 | |||
503 | *anonymity = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, | ||
504 | "GNUNET_GTK_edit_file_information_anonymity_spin_button"))); | ||
505 | *priority = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, | ||
506 | "GNUNET_GTK_edit_file_information_priority_spin_button"))); | ||
507 | *do_index = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, | ||
508 | "GNUNET_GTK_edit_file_information_index_check_button"))); | ||
509 | /* update URI */ | ||
510 | if (NULL != (*uri)) | ||
511 | GNUNET_FS_uri_destroy (*uri); | ||
512 | *uri = NULL; | ||
513 | nxt = NULL; | ||
514 | mrg = NULL; | ||
515 | |||
516 | tm = GTK_TREE_MODEL (gtk_builder_get_object (builder, | ||
517 | "GNUNET_GTK_keyword_list_store")); | ||
518 | if (TRUE == | ||
519 | gtk_tree_model_get_iter_first (tm, &iter)) | ||
520 | { | ||
521 | do | ||
522 | { | ||
523 | gtk_tree_model_get (tm, &iter, | ||
524 | 0, &value, | ||
525 | -1); | ||
526 | nxt = GNUNET_FS_uri_ksk_create_from_args (1, (const char**) &value); | ||
527 | mrg = GNUNET_FS_uri_ksk_merge (nxt, *uri); | ||
528 | GNUNET_FS_uri_destroy (nxt); | ||
529 | if (NULL != *uri) | ||
530 | GNUNET_FS_uri_destroy (*uri); | ||
531 | *uri = mrg; | ||
532 | g_free (value); | ||
533 | } | ||
534 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | ||
535 | } | ||
536 | |||
537 | /* update meta */ | ||
538 | nm = GNUNET_CONTAINER_meta_data_create (); | ||
539 | GNUNET_CONTAINER_meta_data_iterate (meta, | ||
540 | &preserve_meta_items, | ||
541 | nm); | ||
542 | |||
543 | GNUNET_CONTAINER_meta_data_clear (meta); | ||
544 | tm = GTK_TREE_MODEL (gtk_builder_get_object (builder, | ||
545 | "GNUNET_GTK_meta_data_list_store")); | ||
546 | if (TRUE == | ||
547 | gtk_tree_model_get_iter_first (tm, &iter)) | ||
548 | { | ||
549 | do | ||
550 | { | ||
551 | gtk_tree_model_get (tm, &iter, | ||
552 | 0, &ntype, | ||
553 | 1, &nformat, | ||
554 | 3, &value, | ||
555 | -1); | ||
556 | GNUNET_CONTAINER_meta_data_insert (nm, | ||
557 | "<user>", | ||
558 | ntype, | ||
559 | nformat, | ||
560 | "text/plain", | ||
561 | value, | ||
562 | strlen (value)+1); | ||
563 | g_free (value); | ||
564 | } | ||
565 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | ||
566 | } | ||
567 | GNUNET_CONTAINER_meta_data_merge (meta, nm); | ||
568 | GNUNET_CONTAINER_meta_data_destroy (nm); | ||
569 | |||
570 | /* update short_fn */ | ||
571 | GNUNET_free_non_null (*short_fn); | ||
572 | *short_fn = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, | ||
573 | EXTRACTOR_METATYPE_FILENAME, | ||
574 | -1); | ||
575 | /* FIXME: update expiration time? (not yet in dialog!) */ | ||
576 | return GNUNET_SYSERR; /* only visit top-level item */ | ||
577 | } | ||
578 | |||
579 | |||
580 | /** | ||
581 | * Open the dialog to edit file information data. | ||
582 | */ | ||
583 | void | ||
584 | GNUNET_GTK_edit_publish_dialog (int *do_index, | ||
585 | char **short_fn, | ||
586 | guint *anonymity_level, | ||
587 | guint *priority, | ||
588 | struct GNUNET_FS_FileInformation *fip) | ||
589 | { | ||
590 | GtkWidget *ad; | ||
591 | GtkListStore *ls; | ||
592 | GtkTreeIter iter; | ||
593 | guint type; | ||
594 | guint max_type; | ||
595 | GtkTreeView *tv; | ||
596 | GtkTreeSelection *sel; | ||
597 | |||
598 | GNUNET_assert (builder == NULL); | ||
599 | builder = GNUNET_GTK_get_new_builder ("publish_edit_dialog.glade"); | ||
600 | if (builder == NULL) | ||
601 | { | ||
602 | GNUNET_break (0); | ||
603 | return; | ||
604 | } | ||
605 | ad = GTK_WIDGET (gtk_builder_get_object (builder, | ||
606 | "GNUNET_GTK_edit_file_information_dialog")); | ||
607 | ls = GTK_LIST_STORE (gtk_builder_get_object (builder, | ||
608 | "GNUNET_GTK_metatype_list_store")); | ||
609 | max_type = EXTRACTOR_metatype_get_max (); | ||
610 | type = 1; | ||
611 | while (type < max_type - 1) | ||
612 | { | ||
613 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, | ||
614 | 0, EXTRACTOR_metatype_to_string (type), | ||
615 | 1, type, | ||
616 | 2, EXTRACTOR_metatype_to_description (type), | ||
617 | -1); | ||
618 | type++; | ||
619 | } | ||
620 | |||
621 | GNUNET_FS_file_information_inspect (fip, | ||
622 | &file_information_extract, | ||
623 | NULL); | ||
624 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
625 | "GNUNET_GTK_edit_file_information_metadata_type_tree_view")); | ||
626 | sel = gtk_tree_view_get_selection (tv); | ||
627 | g_signal_connect(G_OBJECT(sel), "changed", | ||
628 | G_CALLBACK(GNUNET_GTK_edit_file_information_metadata_value_entry_changed_cb), NULL); | ||
629 | |||
630 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
631 | "GNUNET_GTK_edit_file_information_metadata_tree_view")); | ||
632 | sel = gtk_tree_view_get_selection (tv); | ||
633 | g_signal_connect(G_OBJECT(sel), "changed", | ||
634 | G_CALLBACK(metadata_selection_changed_cb), NULL); | ||
635 | |||
636 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
637 | "GNUNET_GTK_edit_file_information_keyword_list_tree_view")); | ||
638 | sel = gtk_tree_view_get_selection (tv); | ||
639 | g_signal_connect(G_OBJECT(sel), "changed", | ||
640 | G_CALLBACK(keyword_selection_changed_cb), NULL); | ||
641 | gtk_window_set_title (GTK_WINDOW (ad), *short_fn); | ||
642 | if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) | ||
643 | { | ||
644 | gtk_widget_destroy (ad); | ||
645 | g_object_unref (G_OBJECT (builder)); | ||
646 | builder = NULL; | ||
647 | return; | ||
648 | } | ||
649 | GNUNET_FS_file_information_inspect (fip, | ||
650 | &file_information_update, | ||
651 | short_fn); | ||
652 | *anonymity_level = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, | ||
653 | "GNUNET_GTK_edit_file_information_anonymity_spin_button"))); | ||
654 | *priority = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, | ||
655 | "GNUNET_GTK_edit_file_information_priority_spin_button"))); | ||
656 | *do_index = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, | ||
657 | "GNUNET_GTK_edit_file_information_index_check_button"))); | ||
658 | gtk_widget_destroy (ad); | ||
659 | g_object_unref (G_OBJECT (builder)); | ||
660 | builder = NULL; | ||
661 | } | ||
662 | |||
663 | /* end of edit_publish_dialog.c */ | ||