aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-edit_publish_dialog.c')
-rw-r--r--src/fs/gnunet-fs-gtk-edit_publish_dialog.c367
1 files changed, 244 insertions, 123 deletions
diff --git a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
index d787bff8..f125788b 100644
--- a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
+++ b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
@@ -29,66 +29,179 @@
29 29
30#include "metatypes.c" 30#include "metatypes.c"
31 31
32
33/**
34 * Internal state kept for each "edit" dialog where the user can edit
35 * publishing information for a file.
36 */
32struct EditPublicationDialogContext 37struct EditPublicationDialogContext
33{ 38{
39 /**
40 * Builder for the dialog.
41 */
34 GtkBuilder *builder; 42 GtkBuilder *builder;
35 43
36 GtkListStore *metatypes_liststore; 44 /**
45 * The 'window' object for the dialog.
46 */
47 GtkWindow *edit_publication_window;
37 48
38 GtkListStore *meta_liststore; 49 /**
50 * The confirmation button which closes the dialog (only sensitive
51 * if the values entered are valid).
52 */
53 GtkWidget *confirm_button;
54
55 /**
56 * Tree view showing the meta data for the file.
57 */
39 GtkTreeView *meta_treeview; 58 GtkTreeView *meta_treeview;
40 GtkTreeSelection *meta_selection;
41 GtkButton *meta_add_button;
42 GtkWidget *meta_del_button;
43 59
44 GtkCellRendererCombo *meta_combo; 60 /**
61 * Tree view showing the keywords for the file.
62 */
63 GtkTreeView *keywords_treeview;
64
65 /**
66 * Image showing the preview image for the file.
67 */
68 GtkImage *preview_image;
69
70 /**
71 * Combo box where the user can select the anonymity level.
72 */
73 GtkComboBox *anonymity_combo;
74
75 /**
76 * Liststore of the 'anonymity_combo' with the anonymity levels.
77 */
78 GtkListStore *anonymity_liststore;
45 79
80 /**
81 * Liststore of possible publication types.
82 */
46 GtkListStore *pubtypes_liststore; 83 GtkListStore *pubtypes_liststore;
47 GtkComboBox *pubtypes_combo;
48 84
85 /**
86 * Liststore of all possible meta types the user can choose from.
87 * (updated to based on the selected publication type).
88 */
89 GtkListStore *metatypes_liststore;
90
91 /**
92 * Liststore showing the meta data of the file (associated with
93 * the 'meta_treeview'.
94 */
95 GtkListStore *meta_liststore;
96
97 /**
98 * Liststore with the keywords of the file (associated with the
99 * 'keywords_treeview'.
100 */
49 GtkListStore *keywords_liststore; 101 GtkListStore *keywords_liststore;
50 GtkTreeView *keywords_treeview;
51 GtkTreeSelection *keywords_selection;
52 GtkWidget *keyword_add_button;
53 GtkWidget *keyword_del_button;
54 102
55 GtkEntry *keyword_entry; 103 /**
104 * Spin button to select content priority level for the file.
105 */
106 GtkSpinButton *priority_spin;
56 107
57 GObject *pubwindow; 108 /**
109 * Spin button to select the expiration year.
110 */
111 GtkSpinButton *expiration_year_spin;
58 112
59 GtkWidget *ok; 113 /**
60 GtkButton *cancel; 114 * Spin button to select the replication level.
115 */
116 GtkSpinButton *replication_spin;
61 117
62 GtkImage *image; 118 /**
119 * Entry line for adding additional keywords.
120 */
121 GtkEntry *keyword_entry;
63 122
64 GtkToggleButton *index_checkbutton; 123 /**
65 GtkLabel *index_label; 124 * Entry line for setting a namespace root (possibly invisible).
125 */
66 GtkEntry *root_entry; 126 GtkEntry *root_entry;
67 GtkLabel *root_label;
68 127
69 GtkSpinButton *priority_spin; 128 /**
70 GtkSpinButton *year_spin; 129 * Entry line to check indexing vs. inserting (possibly invisible)
71 GtkSpinButton *replication_spin; 130 */
131 GtkToggleButton *index_checkbutton;
72 132
73 GtkComboBox *anonymity_combo; 133 /**
74 GtkListStore *anonymity_liststore; 134 * ???
135 */
136 GtkTreeIter *meta_combo_selected_iter;
75 137
76 int do_index; 138 /**
77 char *short_fn; 139 * Continuation to call once the dialog has been closed
78 struct GNUNET_FS_BlockOptions bo; 140 */
79 struct GNUNET_FS_FileInformation *fip;
80 gint preview_changed;
81 gboolean allow_no_keywords;
82 gboolean is_directory;
83 GNUNET_FS_GTK_EditPublishDialogCallback cb; 141 GNUNET_FS_GTK_EditPublishDialogCallback cb;
84 gchar *root;
85 gpointer cls;
86 142
143 /**
144 * Closure for 'cb'.
145 */
146 void *cb_cls;
147
148 /**
149 * Short name of the file being published (or NULL).
150 */
151 char *short_fn;
152
153 /**
154 * Briefly used temporary meta data set.
155 */
87 struct GNUNET_CONTAINER_MetaData *md; 156 struct GNUNET_CONTAINER_MetaData *md;
88 157
89 GtkTreeIter *meta_combo_selected_iter; 158 /**
159 * Information about the file being published as seen by the FS-API.
160 * This is what we are primarily editing.
161 */
162 struct GNUNET_FS_FileInformation *fip;
163
164 /**
165 * Overall options for the publish operation. This is also what
166 * we are primarily editing.
167 */
168 struct GNUNET_FS_BlockOptions bo;
169
170 /**
171 * Flag to track if we changed the preview and thus should keep/discard
172 * certain metadata. (FIXME: yucky!)
173 */
174 int preview_changed;
175
176 /**
177 * Is this operation for a directory?
178 */
179 int is_directory;
180
181 /**
182 * Is it allowed for the user to supply keywords in this dialog?
183 * FIXME: why 'gboolean'?
184 */
185 gboolean allow_no_keywords;
186
90}; 187};
91 188
189
190/**
191 * Free resources associated with the edit publication dialog.
192 *
193 * @param ctx the context of the dialog to release resources of
194 */
195static void
196free_edit_dialog_context (struct EditPublicationDialogContext *ctx)
197{
198 gtk_widget_destroy (GTK_WIDGET (ctx->edit_publication_window));
199 GNUNET_free_non_null (ctx->short_fn);
200 // FIXME: destroy builder!
201 GNUNET_free (ctx);
202}
203
204
92static void 205static void
93change_metatypes (struct EditPublicationDialogContext *ctx, gint code) 206change_metatypes (struct EditPublicationDialogContext *ctx, gint code)
94{ 207{
@@ -129,11 +242,9 @@ GNUNET_GTK_edit_publication_type_combo_changed_cb (GtkComboBox * widget,
129 GtkTreeIter iter; 242 GtkTreeIter iter;
130 gint code; 243 gint code;
131 244
132 if (!gtk_combo_box_get_active_iter (widget, &iter)) 245 if (! gtk_combo_box_get_active_iter (widget, &iter))
133 return; 246 return;
134
135 gtk_tree_model_get (GTK_TREE_MODEL (ctx->pubtypes_liststore), &iter, 0, &code, -1); 247 gtk_tree_model_get (GTK_TREE_MODEL (ctx->pubtypes_liststore), &iter, 0, &code, -1);
136
137 change_metatypes (ctx, code); 248 change_metatypes (ctx, code);
138} 249}
139 250
@@ -141,7 +252,8 @@ GNUNET_GTK_edit_publication_type_combo_changed_cb (GtkComboBox * widget,
141static void 252static void
142metadata_selection_changed_cb (GtkTreeSelection *ts, struct EditPublicationDialogContext *ctx) 253metadata_selection_changed_cb (GtkTreeSelection *ts, struct EditPublicationDialogContext *ctx)
143{ 254{
144 gtk_widget_set_sensitive (ctx->meta_del_button, 255 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object
256 (ctx->builder, "GNUNET_GTK_edit_publication_delete_button")),
145 gtk_tree_selection_get_selected (ts, NULL, NULL)); 257 gtk_tree_selection_get_selected (ts, NULL, NULL));
146} 258}
147 259
@@ -149,7 +261,9 @@ metadata_selection_changed_cb (GtkTreeSelection *ts, struct EditPublicationDialo
149static void 261static void
150keywords_selection_changed_cb (GtkTreeSelection *ts, struct EditPublicationDialogContext *ctx) 262keywords_selection_changed_cb (GtkTreeSelection *ts, struct EditPublicationDialogContext *ctx)
151{ 263{
152 gtk_widget_set_sensitive (ctx->keyword_del_button, 264 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object
265 (ctx->builder,
266 "GNUNET_GTK_edit_publication_keyword_list_del_button")),
153 gtk_tree_selection_get_selected (ts, NULL, NULL)); 267 gtk_tree_selection_get_selected (ts, NULL, NULL));
154} 268}
155 269
@@ -176,7 +290,10 @@ GNUNET_GTK_edit_publication_keyword_entry_key_press_event_cb (GtkWidget *
176{ 290{
177 if (event->keyval == GDK_KEY_Return) 291 if (event->keyval == GDK_KEY_Return)
178 { 292 {
179 GNUNET_GTK_edit_publication_add_button_clicked_cb (GTK_BUTTON (ctx->keyword_add_button), ctx); 293 GNUNET_GTK_edit_publication_add_button_clicked_cb (GTK_BUTTON (gtk_builder_get_object (ctx->builder,
294 "GNUNET_GTK_edit_publication_keyword_list_add_button")),
295
296 ctx);
180 return TRUE; 297 return TRUE;
181 } 298 }
182 return FALSE; 299 return FALSE;
@@ -198,7 +315,10 @@ void GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb
198 315
199 if (!ctx->meta_combo_selected_iter) 316 if (!ctx->meta_combo_selected_iter)
200 return; 317 return;
201 g_object_get (ctx->meta_combo, "model", &combo_model, NULL); 318 g_object_get (GTK_CELL_RENDERER_COMBO (gtk_builder_get_object
319 (ctx->builder,
320 "GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer")),
321 "model", &combo_model, NULL);
202 gtk_tree_model_get (combo_model, ctx->meta_combo_selected_iter, 0, &type_id, 2, &description, -1); 322 gtk_tree_model_get (combo_model, ctx->meta_combo_selected_iter, 0, &type_id, 2, &description, -1);
203 g_object_unref (combo_model); 323 g_object_unref (combo_model);
204 g_free (ctx->meta_combo_selected_iter); 324 g_free (ctx->meta_combo_selected_iter);
@@ -277,14 +397,16 @@ GNUNET_GTK_edit_publication_delete_button_clicked_cb (GtkButton * button,
277 struct EditPublicationDialogContext *ctx) 397 struct EditPublicationDialogContext *ctx)
278{ 398{
279 GtkTreeIter iter; 399 GtkTreeIter iter;
400 GtkTreeSelection *meta_selection;
280 401
281 if (TRUE != gtk_tree_selection_get_selected (ctx->meta_selection, NULL, &iter)) 402 meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview);
403 if (! gtk_tree_selection_get_selected (meta_selection, NULL, &iter))
282 { 404 {
283 GNUNET_break (0); 405 GNUNET_break (0);
284 return; 406 return;
285 } 407 }
286 if (gtk_list_store_remove (ctx->meta_liststore, &iter)) 408 if (gtk_list_store_remove (ctx->meta_liststore, &iter))
287 gtk_tree_selection_select_iter (ctx->meta_selection, &iter); 409 gtk_tree_selection_select_iter (meta_selection, &iter);
288} 410}
289 411
290 412
@@ -301,7 +423,7 @@ GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb (GtkButton *
301 { 423 {
302 gtk_list_store_insert_with_values (ctx->keywords_liststore, &iter, G_MAXINT, 0, keyword, 1, TRUE, 424 gtk_list_store_insert_with_values (ctx->keywords_liststore, &iter, G_MAXINT, 0, keyword, 1, TRUE,
303 -1); 425 -1);
304 gtk_widget_set_sensitive (ctx->ok, TRUE); 426 gtk_widget_set_sensitive (ctx->confirm_button, TRUE);
305 } 427 }
306 gtk_entry_set_text (ctx->keyword_entry, ""); 428 gtk_entry_set_text (ctx->keyword_entry, "");
307} 429}
@@ -335,7 +457,9 @@ GNUNET_GTK_edit_publication_keyword_entry_changed_cb (GtkEditable * editable,
335 const char *keyword; 457 const char *keyword;
336 458
337 keyword = gtk_entry_get_text (ctx->keyword_entry); 459 keyword = gtk_entry_get_text (ctx->keyword_entry);
338 gtk_widget_set_sensitive (ctx->keyword_add_button, (strlen (keyword) > 0) ? TRUE : FALSE); 460 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (ctx->builder,
461 "GNUNET_GTK_edit_publication_keyword_list_add_button")),
462 (strlen (keyword) > 0) ? TRUE : FALSE);
339} 463}
340 464
341 465
@@ -345,17 +469,20 @@ GNUNET_GTK_edit_publication_keyword_list_del_button_clicked_cb (GtkButton *
345 struct EditPublicationDialogContext *ctx) 469 struct EditPublicationDialogContext *ctx)
346{ 470{
347 GtkTreeIter iter; 471 GtkTreeIter iter;
472 GtkTreeSelection *keywords_selection;
473
474 keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview);
348 475
349 if (TRUE != gtk_tree_selection_get_selected (ctx->keywords_selection, NULL, &iter)) 476 if (TRUE != gtk_tree_selection_get_selected (keywords_selection, NULL, &iter))
350 { 477 {
351 GNUNET_break (0); 478 GNUNET_break (0);
352 return; 479 return;
353 } 480 }
354 if (gtk_list_store_remove (GTK_LIST_STORE (ctx->keywords_liststore), &iter)) 481 if (gtk_list_store_remove (GTK_LIST_STORE (ctx->keywords_liststore), &iter))
355 gtk_tree_selection_select_iter (ctx->keywords_selection, &iter); 482 gtk_tree_selection_select_iter (keywords_selection, &iter);
356 483
357 if (!ctx->allow_no_keywords && !gtk_tree_model_has_items (GTK_TREE_MODEL (ctx->keywords_liststore))) 484 if (!ctx->allow_no_keywords && !gtk_tree_model_has_items (GTK_TREE_MODEL (ctx->keywords_liststore)))
358 gtk_widget_set_sensitive (ctx->ok, FALSE); 485 gtk_widget_set_sensitive (ctx->confirm_button, FALSE);
359} 486}
360 487
361 488
@@ -365,7 +492,7 @@ void GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button_file_set_c
365 gchar *fn; 492 gchar *fn;
366 493
367 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)); 494 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
368 gtk_image_set_from_file (ctx->image, fn); 495 gtk_image_set_from_file (ctx->preview_image, fn);
369 g_free (fn); 496 g_free (fn);
370 ctx->preview_changed = GNUNET_YES; 497 ctx->preview_changed = GNUNET_YES;
371} 498}
@@ -478,6 +605,7 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
478 const char *mime; 605 const char *mime;
479 GFile *f; 606 GFile *f;
480 GFileInfo *finfo; 607 GFileInfo *finfo;
608 char *sfn;
481 609
482 if (!GNUNET_GTK_get_selected_anonymity_combo_level 610 if (!GNUNET_GTK_get_selected_anonymity_combo_level
483 (ctx->anonymity_combo, &ctx->bo.anonymity_level)) 611 (ctx->anonymity_combo, &ctx->bo.anonymity_level))
@@ -485,13 +613,8 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
485 ctx->bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin); 613 ctx->bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin);
486 ctx->bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin); 614 ctx->bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin);
487 *do_index = gtk_toggle_button_get_active (ctx->index_checkbutton); 615 *do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
488 ctx->bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (ctx->year_spin); 616 ctx->bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (ctx->expiration_year_spin);
489 617
490 if (!ctx->allow_no_keywords)
491 {
492 g_free (ctx->root);
493 ctx->root = g_strdup (gtk_entry_get_text (ctx->root_entry));
494 }
495 /* update URI */ 618 /* update URI */
496 if (NULL != (*uri)) 619 if (NULL != (*uri))
497 GNUNET_FS_uri_destroy (*uri); 620 GNUNET_FS_uri_destroy (*uri);
@@ -564,13 +687,17 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
564 g_free (fn); 687 g_free (fn);
565 } 688 }
566 GNUNET_CONTAINER_meta_data_destroy (ctx->md); 689 GNUNET_CONTAINER_meta_data_destroy (ctx->md);
690 ctx->md = NULL;
567 691
568 /* update short_fn */ 692 /* update short_fn */
569 GNUNET_free_non_null (ctx->short_fn); 693 sfn = GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
570 ctx->short_fn = 694 EXTRACTOR_METATYPE_FILENAME,
571 GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 695 -1);
572 EXTRACTOR_METATYPE_FILENAME, 696 if (NULL != sfn)
573 -1); 697 {
698 GNUNET_free_non_null (ctx->short_fn);
699 ctx->short_fn = sfn;
700 }
574 return GNUNET_SYSERR; /* only visit top-level item */ 701 return GNUNET_SYSERR; /* only visit top-level item */
575} 702}
576 703
@@ -579,17 +706,24 @@ void
579GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GtkButton * button, 706GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GtkButton * button,
580 struct EditPublicationDialogContext *ctx) 707 struct EditPublicationDialogContext *ctx)
581{ 708{
582 ctx->cb (ctx->cls, ctx->do_index, ctx->short_fn, 709 int do_index;
583 &ctx->bo, NULL, GTK_RESPONSE_CANCEL); 710
584 gtk_widget_destroy (GTK_WIDGET (ctx->pubwindow)); 711 /* FIXME: why are we passing half of these values here? */
712 do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
713 ctx->cb (ctx->cb_cls, do_index, ctx->short_fn,
714 &ctx->bo, NULL, GTK_RESPONSE_CANCEL);
715 free_edit_dialog_context (ctx);
585} 716}
586 717
587 718
719
588void 720void
589GNUNET_GTK_edit_publication_confirm_button_clicked_cb (GtkButton * button, 721GNUNET_GTK_edit_publication_confirm_button_clicked_cb (GtkButton * button,
590 struct EditPublicationDialogContext *ctx) 722 struct EditPublicationDialogContext *ctx)
591{ 723{
592 gint year; 724 gint year;
725 const char *root;
726 int do_index;
593 727
594 GNUNET_FS_file_information_inspect (ctx->fip, &file_information_update, ctx); 728 GNUNET_FS_file_information_inspect (ctx->fip, &file_information_update, ctx);
595 if (!GNUNET_GTK_get_selected_anonymity_combo_level (ctx->anonymity_combo, 729 if (!GNUNET_GTK_get_selected_anonymity_combo_level (ctx->anonymity_combo,
@@ -597,13 +731,13 @@ GNUNET_GTK_edit_publication_confirm_button_clicked_cb (GtkButton * button,
597 ctx->bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin); 731 ctx->bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin);
598 ctx->bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin); 732 ctx->bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin);
599 733
600 ctx->do_index = gtk_toggle_button_get_active (ctx->index_checkbutton); 734 do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
601 year = gtk_spin_button_get_value (ctx->year_spin); 735 year = gtk_spin_button_get_value (ctx->expiration_year_spin);
602 ctx->bo.expiration_time = GNUNET_FS_year_to_time (year); 736 ctx->bo.expiration_time = GNUNET_FS_year_to_time (year);
603 ctx->cb (ctx->cls, ctx->do_index, ctx->short_fn, 737 root = gtk_entry_get_text (ctx->root_entry);
604 &ctx->bo, ctx->root, GTK_RESPONSE_OK); 738 ctx->cb (ctx->cb_cls, do_index, ctx->short_fn,
605 GNUNET_free_non_null (ctx->short_fn); 739 &ctx->bo, root, GTK_RESPONSE_OK);
606 gtk_widget_destroy (GTK_WIDGET (ctx->pubwindow)); 740 free_edit_dialog_context (ctx);
607} 741}
608 742
609 743
@@ -612,7 +746,9 @@ GNUNET_GTK_edit_publication_window_delete_event_cb (GtkWidget * widget,
612 GdkEvent * event, 746 GdkEvent * event,
613 struct EditPublicationDialogContext *ctx) 747 struct EditPublicationDialogContext *ctx)
614{ 748{
615 GNUNET_GTK_edit_publication_cancel_button_clicked_cb (ctx->cancel, ctx); 749 GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GTK_BUTTON (gtk_builder_get_object
750 (ctx->builder, "GNUNET_GTK_edit_publication_cancel_button")),
751 ctx);
616 return TRUE; 752 return TRUE;
617} 753}
618 754
@@ -672,11 +808,11 @@ file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi,
672 pixbuf = GNUNET_FS_GTK_get_thumbnail_from_meta_data (meta); 808 pixbuf = GNUNET_FS_GTK_get_thumbnail_from_meta_data (meta);
673 if (pixbuf != NULL) 809 if (pixbuf != NULL)
674 { 810 {
675 gtk_image_set_from_pixbuf (ctx->image, pixbuf); 811 gtk_image_set_from_pixbuf (ctx->preview_image, pixbuf);
676 } 812 }
677 } 813 }
678 year = (int) GNUNET_FS_time_to_year (ctx->bo.expiration_time); 814 year = (int) GNUNET_FS_time_to_year (ctx->bo.expiration_time);
679 gtk_spin_button_set_value (ctx->year_spin, year); 815 gtk_spin_button_set_value (ctx->expiration_year_spin, year);
680 GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo, 816 GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo,
681 ctx->bo.anonymity_level); 817 ctx->bo.anonymity_level);
682 gtk_spin_button_set_value (ctx->priority_spin, ctx->bo.content_priority); 818 gtk_spin_button_set_value (ctx->priority_spin, ctx->bo.content_priority);
@@ -689,13 +825,17 @@ file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi,
689void 825void
690GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget, struct EditPublicationDialogContext *ctx) 826GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget, struct EditPublicationDialogContext *ctx)
691{ 827{
692 ctx->keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview); 828 GtkTreeSelection *meta_selection;
693 ctx->meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview); 829 GtkTreeSelection *keywords_selection;
830
831 /* FIXME: these can be set by (modern) versions of Glade */
832 keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview);
833 meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview);
694 834
695 g_signal_connect (G_OBJECT (ctx->keywords_selection), "changed", 835 g_signal_connect (G_OBJECT (keywords_selection), "changed",
696 G_CALLBACK (keywords_selection_changed_cb), ctx); 836 G_CALLBACK (keywords_selection_changed_cb), ctx);
697 837
698 g_signal_connect (G_OBJECT (ctx->meta_selection), "changed", 838 g_signal_connect (G_OBJECT (meta_selection), "changed",
699 G_CALLBACK (metadata_selection_changed_cb), ctx); 839 G_CALLBACK (metadata_selection_changed_cb), ctx);
700} 840}
701 841
@@ -705,17 +845,20 @@ GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget, struct EditPub
705 */ 845 */
706void 846void
707GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, 847GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
708 int do_index, const char *short_fn, 848 int do_index /* FIXME: not needed? */,
849 const char *short_fn,
709 const struct GNUNET_FS_BlockOptions bo, 850 const struct GNUNET_FS_BlockOptions bo,
710 struct GNUNET_FS_FileInformation *fip, 851 struct GNUNET_FS_FileInformation *fip,
711 gboolean allow_no_keywords, 852 gboolean allow_no_keywords,
712 GtkListStore *anon_liststore, 853 GtkListStore *anon_liststore,
713 GNUNET_FS_GTK_EditPublishDialogCallback cb, 854 GNUNET_FS_GTK_EditPublishDialogCallback cb,
714 gpointer cls) 855 gpointer cb_cls)
715{ 856{
716 GtkTreeIter iter; 857 GtkTreeIter iter;
717 gint code; 858 gint code;
718 859 GtkComboBox *pubtypes_combo;
860 GtkLabel *index_label;
861 GtkLabel *root_label;
719 struct EditPublicationDialogContext *ctx; 862 struct EditPublicationDialogContext *ctx;
720 863
721 ctx = GNUNET_malloc (sizeof (struct EditPublicationDialogContext)); 864 ctx = GNUNET_malloc (sizeof (struct EditPublicationDialogContext));
@@ -737,59 +880,31 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
737 ctx->meta_treeview = GTK_TREE_VIEW (gtk_builder_get_object 880 ctx->meta_treeview = GTK_TREE_VIEW (gtk_builder_get_object
738 (ctx->builder, 881 (ctx->builder,
739 "GNUNET_GTK_edit_publication_metadata_tree_view")); 882 "GNUNET_GTK_edit_publication_metadata_tree_view"));
740 ctx->meta_del_button =
741 GTK_WIDGET (gtk_builder_get_object
742 (ctx->builder, "GNUNET_GTK_edit_publication_delete_button"));
743 ctx->keywords_treeview = GTK_TREE_VIEW (gtk_builder_get_object 883 ctx->keywords_treeview = GTK_TREE_VIEW (gtk_builder_get_object
744 (ctx->builder, 884 (ctx->builder,
745 "GNUNET_GTK_edit_publication_keyword_list_tree_view")); 885 "GNUNET_GTK_edit_publication_keyword_list_tree_view"));
746 ctx->keyword_del_button = 886 ctx->edit_publication_window =
747 GTK_WIDGET (gtk_builder_get_object 887 GTK_WINDOW (gtk_builder_get_object (ctx->builder, "GNUNET_GTK_edit_publication_window"));
748 (ctx->builder,
749 "GNUNET_GTK_edit_publication_keyword_list_del_button"));
750 ctx->meta_add_button =
751 GTK_BUTTON (gtk_builder_get_object
752 (ctx->builder, "GNUNET_GTK_edit_publication_add_button"));
753 ctx->meta_combo =
754 GTK_CELL_RENDERER_COMBO (gtk_builder_get_object
755 (ctx->builder,
756 "GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer"));
757 ctx->pubwindow =
758 gtk_builder_get_object (ctx->builder, "GNUNET_GTK_edit_publication_window");
759 ctx->keywords_liststore = GTK_LIST_STORE (gtk_builder_get_object 888 ctx->keywords_liststore = GTK_LIST_STORE (gtk_builder_get_object
760 (ctx->builder, "GNUNET_GTK_publication_keywords_liststore")); 889 (ctx->builder, "GNUNET_GTK_publication_keywords_liststore"));
761 ctx->keyword_entry = 890 ctx->keyword_entry =
762 GTK_ENTRY (gtk_builder_get_object 891 GTK_ENTRY (gtk_builder_get_object
763 (ctx->builder, "GNUNET_GTK_edit_publication_keyword_entry")); 892 (ctx->builder, "GNUNET_GTK_edit_publication_keyword_entry"));
764 ctx->ok = GTK_WIDGET (gtk_builder_get_object 893 ctx->confirm_button = GTK_WIDGET (gtk_builder_get_object
765 (ctx->builder, "GNUNET_GTK_edit_publication_confirm_button")); 894 (ctx->builder, "GNUNET_GTK_edit_publication_confirm_button"));
766 ctx->keyword_add_button = 895 ctx->preview_image =
767 GTK_WIDGET (gtk_builder_get_object
768 (ctx->builder,
769 "GNUNET_GTK_edit_publication_keyword_list_add_button"));
770 ctx->image =
771 GTK_IMAGE (gtk_builder_get_object 896 GTK_IMAGE (gtk_builder_get_object
772 (ctx->builder, 897 (ctx->builder,
773 "GNUNET_GTK_edit_publication_metadata_preview_image")); 898 "GNUNET_GTK_edit_publication_metadata_preview_image"));
774 ctx->meta_liststore = GTK_LIST_STORE (gtk_builder_get_object 899 ctx->meta_liststore = GTK_LIST_STORE (gtk_builder_get_object
775 (ctx->builder, 900 (ctx->builder,
776 "GNUNET_GTK_publication_metadata_liststore")); 901 "GNUNET_GTK_publication_metadata_liststore"));
777 ctx->cancel =
778 GTK_BUTTON (gtk_builder_get_object
779 (ctx->builder, "GNUNET_GTK_edit_publication_cancel_button"));
780 902
781 ctx->index_label = GTK_LABEL (gtk_builder_get_object
782 (ctx->builder, "GNUNET_GTK_edit_publication_index_label"));
783 ctx->root_entry = GTK_ENTRY (gtk_builder_get_object 903 ctx->root_entry = GTK_ENTRY (gtk_builder_get_object
784 (ctx->builder, "GNUNET_GTK_edit_publication_root_entry")); 904 (ctx->builder, "GNUNET_GTK_edit_publication_root_entry"));
785 ctx->root_label = GTK_LABEL (gtk_builder_get_object
786 (ctx->builder, "GNUNET_GTK_edit_publication_root_label"));
787 905
788 ctx->pubtypes_combo =
789 GTK_COMBO_BOX (gtk_builder_get_object
790 (ctx->builder, "GNUNET_GTK_edit_publication_type_combo"));
791 906
792 ctx->year_spin = GTK_SPIN_BUTTON 907 ctx->expiration_year_spin = GTK_SPIN_BUTTON
793 (gtk_builder_get_object 908 (gtk_builder_get_object
794 (ctx->builder, 909 (ctx->builder,
795 "GNUNET_GTK_edit_publication_expiration_year_spin_button")); 910 "GNUNET_GTK_edit_publication_expiration_year_spin_button"));
@@ -814,30 +929,36 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
814 /* indexing does not apply to directories */ 929 /* indexing does not apply to directories */
815 gtk_widget_set_visible (GTK_WIDGET (ctx->index_checkbutton), 930 gtk_widget_set_visible (GTK_WIDGET (ctx->index_checkbutton),
816 !GNUNET_FS_file_information_is_directory (fip)); 931 !GNUNET_FS_file_information_is_directory (fip));
817 gtk_widget_set_visible (GTK_WIDGET (ctx->index_label), 932 index_label = GTK_LABEL (gtk_builder_get_object
933 (ctx->builder, "GNUNET_GTK_edit_publication_index_label"));
934 gtk_widget_set_visible (GTK_WIDGET (index_label),
818 !GNUNET_FS_file_information_is_directory (fip)); 935 !GNUNET_FS_file_information_is_directory (fip));
819 gtk_widget_set_visible (GTK_WIDGET (ctx->root_entry), 936 gtk_widget_set_visible (GTK_WIDGET (ctx->root_entry),
820 !allow_no_keywords); 937 !allow_no_keywords);
821 gtk_widget_set_visible (GTK_WIDGET (ctx->root_label), 938 root_label = GTK_LABEL (gtk_builder_get_object
939 (ctx->builder, "GNUNET_GTK_edit_publication_root_label"));
940 gtk_widget_set_visible (GTK_WIDGET (root_label),
822 !allow_no_keywords); 941 !allow_no_keywords);
823 942
824 gtk_list_store_clear (ctx->keywords_liststore); 943 gtk_list_store_clear (ctx->keywords_liststore);
825 gtk_list_store_clear (ctx->meta_liststore); 944 gtk_list_store_clear (ctx->meta_liststore);
826 945
827 if (NULL != short_fn) 946 if (NULL != short_fn)
828 gtk_window_set_title (GTK_WINDOW (ctx->pubwindow), short_fn); 947 gtk_window_set_title (ctx->edit_publication_window, short_fn);
829 else 948 else
830 gtk_window_set_title (GTK_WINDOW (ctx->pubwindow), _("<unnamed>")); 949 gtk_window_set_title (ctx->edit_publication_window, _("<unnamed>"));
831 950
832 if (gtk_combo_box_get_active_iter (ctx->pubtypes_combo, &iter)) 951 pubtypes_combo =
952 GTK_COMBO_BOX (gtk_builder_get_object
953 (ctx->builder, "GNUNET_GTK_edit_publication_type_combo"));
954 if (gtk_combo_box_get_active_iter (pubtypes_combo, &iter))
833 { 955 {
834 gtk_tree_model_get (GTK_TREE_MODEL (ctx->pubtypes_liststore), &iter, 0, &code, -1); 956 gtk_tree_model_get (GTK_TREE_MODEL (ctx->pubtypes_liststore), &iter, 0, &code, -1);
835 change_metatypes (ctx, 0); 957 change_metatypes (ctx, 0);
836 } 958 }
837 else 959 else
838 gtk_combo_box_set_active (ctx->pubtypes_combo, 0); 960 gtk_combo_box_set_active (pubtypes_combo, 0);
839 961
840 ctx->do_index = do_index;
841 if (NULL != short_fn) 962 if (NULL != short_fn)
842 ctx->short_fn = GNUNET_strdup (short_fn); 963 ctx->short_fn = GNUNET_strdup (short_fn);
843 ctx->bo = bo; 964 ctx->bo = bo;
@@ -846,14 +967,14 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
846 ctx->allow_no_keywords = allow_no_keywords; 967 ctx->allow_no_keywords = allow_no_keywords;
847 ctx->is_directory = GNUNET_FS_file_information_is_directory (fip); 968 ctx->is_directory = GNUNET_FS_file_information_is_directory (fip);
848 ctx->cb = cb; 969 ctx->cb = cb;
849 ctx->cls = cls; 970 ctx->cb_cls = cb_cls;
850 971
851 GNUNET_FS_file_information_inspect (fip, &file_information_extract, ctx); 972 GNUNET_FS_file_information_inspect (fip, &file_information_extract, ctx);
852 973
853 gtk_entry_set_text (ctx->keyword_entry, ""); 974 gtk_entry_set_text (ctx->keyword_entry, "");
854 gtk_widget_set_sensitive (ctx->ok, allow_no_keywords ? TRUE : FALSE); 975 gtk_widget_set_sensitive (ctx->confirm_button, allow_no_keywords ? TRUE : FALSE);
855 gtk_window_set_transient_for (GTK_WINDOW (ctx->pubwindow), parent); 976 gtk_window_set_transient_for (ctx->edit_publication_window, parent);
856 gtk_window_present (GTK_WINDOW (ctx->pubwindow)); 977 gtk_window_present (ctx->edit_publication_window);
857} 978}
858 979
859 980