aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-02 00:07:29 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-02 00:07:29 +0000
commit16eed84700a408f5e5e8d1437d0d3ae53263ea8e (patch)
tree6188dc9955753b5f1f75bfe6a6dad2a4c89a3906
parente3b89998cab7d1314f914f591b4d7481270615e8 (diff)
downloadgnunet-gtk-16eed84700a408f5e5e8d1437d0d3ae53263ea8e.tar.gz
gnunet-gtk-16eed84700a408f5e5e8d1437d0d3ae53263ea8e.zip
-simplifying logic some
-rw-r--r--src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c71
-rw-r--r--src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h17
-rw-r--r--src/fs/gnunet-fs-gtk-edit_publish_dialog.c127
-rw-r--r--src/fs/gnunet-fs-gtk-edit_publish_dialog.h3
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c4
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_file_publish.c526
6 files changed, 376 insertions, 372 deletions
diff --git a/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c b/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c
index 94829429..6c22aa7b 100644
--- a/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c
+++ b/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c
@@ -24,6 +24,7 @@
24 * @brief operations to manage user's anonymity level selections 24 * @brief operations to manage user's anonymity level selections
25 */ 25 */
26#include "gnunet-fs-gtk-common.h" 26#include "gnunet-fs-gtk-common.h"
27#include "gnunet-fs-gtk-anonymity_spin_buttons.h"
27#include <gdk/gdk.h> 28#include <gdk/gdk.h>
28 29
29/** 30/**
@@ -71,33 +72,34 @@ GNUNET_GTK_anonymity_spin_button_value_changed_cb (GtkWidget * w, gpointer data)
71} 72}
72 73
73 74
74 75/**
76 * Obtain the numeric anonymity level selected by a GtkComboBox.
77 *
78 * @param builder builder for looking up widgets
79 * @param combo_name name of the GtkComboBox with the anonymity selection
80 * @param p_level where to store the anonymity level
81 * @return TRUE on success, FALSE on failure
82 */
75gboolean 83gboolean
76GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder, 84GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
77 gchar * combo_name, guint * p_level) 85 gchar * combo_name, guint * p_level)
78{ 86{
79 GtkComboBox *combo; 87 GtkComboBox *combo;
80 GtkTreeIter iter;
81 GtkTreeModel *model;
82 guint level;
83 88
84 combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name)); 89 combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
85 if (!combo) 90 if (!combo)
86 return FALSE; 91 return FALSE;
87 92 return GNUNET_GTK_get_selected_anonymity_combo_level (combo, p_level);
88 if (!gtk_combo_box_get_active_iter (combo, &iter))
89 return FALSE;
90
91 model = gtk_combo_box_get_model (combo);
92 if (!model)
93 return FALSE;
94
95 gtk_tree_model_get (model, &iter, 1, &level, -1);
96 if (p_level)
97 *p_level = level;
98 return TRUE;
99} 93}
100 94
95
96/**
97 * Obtain the numeric anonymity level selected by a GtkComboBox.
98 *
99 * @param combo the GtkComboBox with the anonymity selection
100 * @param p_level where to store the anonymity level
101 * @return TRUE on success, FALSE on failure
102 */
101gboolean 103gboolean
102GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level) 104GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level)
103{ 105{
@@ -105,64 +107,44 @@ GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_leve
105 GtkTreeModel *model; 107 GtkTreeModel *model;
106 guint level; 108 guint level;
107 109
108 if (!gtk_combo_box_get_active_iter (combo, &iter)) 110 if (! gtk_combo_box_get_active_iter (combo, &iter))
109 return FALSE; 111 return FALSE;
110
111 model = gtk_combo_box_get_model (combo); 112 model = gtk_combo_box_get_model (combo);
112 if (!model) 113 if (!model)
113 return FALSE; 114 return FALSE;
114
115 gtk_tree_model_get (model, &iter, 1, &level, -1); 115 gtk_tree_model_get (model, &iter, 1, &level, -1);
116 if (p_level) 116 if (p_level)
117 *p_level = level; 117 *p_level = level;
118 return TRUE; 118 return TRUE;
119} 119}
120 120
121
121gboolean 122gboolean
122GNUNET_GTK_select_anonymity_level (GtkBuilder * builder, gchar * combo_name, 123GNUNET_GTK_select_anonymity_level (GtkBuilder * builder, gchar * combo_name,
123 guint sel_level) 124 guint sel_level)
124{ 125{
125 GtkComboBox *combo; 126 GtkComboBox *combo;
126 GtkTreeIter iter;
127 GtkTreeModel *model;
128 guint level;
129 gboolean go_on;
130 127
131 combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name)); 128 combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
132 if (!combo) 129 if (!combo)
133 return FALSE; 130 return FALSE;
134 131 return GNUNET_GTK_select_anonymity_combo_level (combo, sel_level);
135 model = gtk_combo_box_get_model (combo);
136 if (!model)
137 return FALSE;
138
139 for (go_on = gtk_tree_model_get_iter_first (model, &iter); go_on;
140 go_on = gtk_tree_model_iter_next (model, &iter))
141 {
142 gtk_tree_model_get (model, &iter, 1, &level, -1);
143 if (level == sel_level)
144 {
145 gtk_combo_box_set_active_iter (combo, &iter);
146 return TRUE;
147 }
148 }
149 return FALSE;
150} 132}
151 133
134
152gboolean 135gboolean
153GNUNET_GTK_select_anonymity_combo_level (GtkComboBox *combo, guint sel_level) 136GNUNET_GTK_select_anonymity_combo_level (GtkComboBox *combo, guint sel_level)
154{ 137{
155 GtkTreeIter iter; 138 GtkTreeIter iter;
156 GtkTreeModel *model; 139 GtkTreeModel *model;
157 guint level; 140 guint level;
158 gboolean go_on;
159 141
160 model = gtk_combo_box_get_model (combo); 142 model = gtk_combo_box_get_model (combo);
161 if (!model) 143 if (!model)
162 return FALSE; 144 return FALSE;
163 145 if (! gtk_tree_model_get_iter_first (model, &iter))
164 for (go_on = gtk_tree_model_get_iter_first (model, &iter); go_on; 146 return FALSE;
165 go_on = gtk_tree_model_iter_next (model, &iter)) 147 do
166 { 148 {
167 gtk_tree_model_get (model, &iter, 1, &level, -1); 149 gtk_tree_model_get (model, &iter, 1, &level, -1);
168 if (level == sel_level) 150 if (level == sel_level)
@@ -170,7 +152,8 @@ GNUNET_GTK_select_anonymity_combo_level (GtkComboBox *combo, guint sel_level)
170 gtk_combo_box_set_active_iter (combo, &iter); 152 gtk_combo_box_set_active_iter (combo, &iter);
171 return TRUE; 153 return TRUE;
172 } 154 }
173 } 155 }
156 while (gtk_tree_model_iter_next (model, &iter));
174 return FALSE; 157 return FALSE;
175} 158}
176 159
diff --git a/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h b/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h
index 0d4e2dac..7847904a 100644
--- a/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h
+++ b/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file src/fs/gnunet-fs-gtk-anonymtiy_spin_buttons.c 22 * @file src/fs/gnunet-fs-gtk-anonymtiy_spin_buttons.h
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * @brief operations to manage user's anonymity level selections 24 * @brief operations to manage user's anonymity level selections
25 */ 25 */
@@ -30,11 +30,26 @@
30#include <gdk/gdk.h> 30#include <gdk/gdk.h>
31 31
32 32
33/**
34 * Obtain the numeric anonymity level selected by a GtkComboBox.
35 *
36 * @param builder builder for looking up widgets
37 * @param combo_name name of the GtkComboBox with the anonymity selection
38 * @param p_level where to store the anonymity level
39 * @return TRUE on success, FALSE on failure
40 */
33gboolean 41gboolean
34GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder, 42GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
35 gchar * combo_name, guint * p_level); 43 gchar * combo_name, guint * p_level);
36 44
37 45
46/**
47 * Obtain the numeric anonymity level selected by a GtkComboBox.
48 *
49 * @param combo the GtkComboBox with the anonymity selection
50 * @param p_level where to store the anonymity level
51 * @return TRUE on success, FALSE on failure
52 */
38gboolean 53gboolean
39GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level); 54GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level);
40 55
diff --git a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
index 62ed17fd..61832925 100644
--- a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
+++ b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
@@ -163,12 +163,6 @@ struct EditPublicationDialogContext
163 struct GNUNET_FS_FileInformation *fip; 163 struct GNUNET_FS_FileInformation *fip;
164 164
165 /** 165 /**
166 * Overall options for the publish operation. This is also what
167 * we are primarily editing.
168 */
169 struct GNUNET_FS_BlockOptions bo;
170
171 /**
172 * Flag to track if we changed the preview and thus should keep/discard 166 * Flag to track if we changed the preview and thus should keep/discard
173 * certain metadata. (FIXME: yucky!) 167 * certain metadata. (FIXME: yucky!)
174 */ 168 */
@@ -642,12 +636,46 @@ GNUNET_GTK_edit_publication_keyword_entry_key_press_event_cb (GtkWidget *
642} 636}
643 637
644 638
639
645/* ****************** handlers for closing the dialog ******************** */ 640/* ****************** handlers for closing the dialog ******************** */
646 641
647 642
643/**
644 * The user clicked the 'cancel' button. Abort the operation.
645 *
646 * @param button the cancel button
647 * @param user_data the 'struct EditPublicationDialogContext'
648 */
649void
650GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GtkButton * button,
651 gpointer user_data)
652{
653 struct EditPublicationDialogContext *ctx = user_data;
648 654
655 ctx->cb (ctx->cb_cls, GNUNET_SYSERR, NULL, NULL, NULL, GTK_RESPONSE_CANCEL);
656 free_edit_dialog_context (ctx);
657}
649 658
650 659
660/**
661 * The user closed the window. Abort the operation.
662 *
663 * @param widget the window
664 * @param event the event that caused the window to close
665 * @param user_data the 'struct EditPublicationDialogContext'
666 * @return TRUE (always)
667 */
668gboolean
669GNUNET_GTK_edit_publication_window_delete_event_cb (GtkWidget * widget,
670 GdkEvent * event,
671 gpointer user_data)
672{
673 struct EditPublicationDialogContext *ctx = user_data;
674
675 ctx->cb (ctx->cb_cls, GNUNET_SYSERR, NULL, NULL, NULL, GTK_RESPONSE_CANCEL);
676 free_edit_dialog_context (ctx);
677 return TRUE;
678}
651 679
652 680
653/** 681/**
@@ -759,13 +787,7 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
759 GFileInfo *finfo; 787 GFileInfo *finfo;
760 char *sfn; 788 char *sfn;
761 789
762 if (!GNUNET_GTK_get_selected_anonymity_combo_level
763 (ctx->anonymity_combo, &ctx->bo.anonymity_level))
764 return GNUNET_SYSERR;
765 ctx->bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin);
766 ctx->bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin);
767 *do_index = gtk_toggle_button_get_active (ctx->index_checkbutton); 790 *do_index = gtk_toggle_button_get_active (ctx->index_checkbutton);
768 ctx->bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (ctx->expiration_year_spin);
769 791
770 /* update URI */ 792 /* update URI */
771 if (NULL != (*uri)) 793 if (NULL != (*uri))
@@ -792,7 +814,9 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
792 814
793 /* update meta */ 815 /* update meta */
794 ctx->md = GNUNET_CONTAINER_meta_data_create (); 816 ctx->md = GNUNET_CONTAINER_meta_data_create ();
795 GNUNET_CONTAINER_meta_data_iterate (meta, &preserve_meta_items, ctx); 817 GNUNET_CONTAINER_meta_data_iterate (meta,
818 &preserve_meta_items,
819 ctx);
796 820
797 GNUNET_CONTAINER_meta_data_clear (meta); 821 GNUNET_CONTAINER_meta_data_clear (meta);
798 if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->meta_liststore), &iter)) 822 if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->meta_liststore), &iter))
@@ -854,57 +878,41 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi,
854} 878}
855 879
856 880
857void 881/**
858GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GtkButton * button, 882 * The user clicked the 'confirm' button. Push the edits back into the
859 struct EditPublicationDialogContext *ctx) 883 * FileInformation structure and given it and the options back to the
860{ 884 * callback. Then clean up the dialog.
861 int do_index; 885 *
862 886 * @param button the cancel button
863 /* FIXME: why are we passing half of these values here? */ 887 * @param user_data the 'struct EditPublicationDialogContext'
864 do_index = gtk_toggle_button_get_active (ctx->index_checkbutton); 888 */
865 ctx->cb (ctx->cb_cls, do_index, ctx->short_fn,
866 &ctx->bo, NULL, GTK_RESPONSE_CANCEL);
867 free_edit_dialog_context (ctx);
868}
869
870
871
872void 889void
873GNUNET_GTK_edit_publication_confirm_button_clicked_cb (GtkButton * button, 890GNUNET_GTK_edit_publication_confirm_button_clicked_cb (GtkButton * button,
874 struct EditPublicationDialogContext *ctx) 891 gpointer user_data)
875{ 892{
893 struct EditPublicationDialogContext *ctx = user_data;
894 struct GNUNET_FS_BlockOptions bo;
876 gint year; 895 gint year;
877 const char *root;
878 int do_index;
879 896
880 GNUNET_FS_file_information_inspect (ctx->fip, &file_information_update, ctx); 897 GNUNET_FS_file_information_inspect (ctx->fip,
881 if (!GNUNET_GTK_get_selected_anonymity_combo_level (ctx->anonymity_combo, 898 &file_information_update,
882 &ctx->bo.anonymity_level)) 899 ctx);
883 ctx->bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin); 900 GNUNET_break (GNUNET_GTK_get_selected_anonymity_combo_level (ctx->anonymity_combo,
884 ctx->bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin); 901 &bo.anonymity_level));
885 902 bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin);
886 do_index = gtk_toggle_button_get_active (ctx->index_checkbutton); 903 bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin);
887 year = gtk_spin_button_get_value (ctx->expiration_year_spin); 904 year = gtk_spin_button_get_value (ctx->expiration_year_spin);
888 ctx->bo.expiration_time = GNUNET_FS_year_to_time (year); 905 bo.expiration_time = GNUNET_FS_year_to_time (year);
889 root = gtk_entry_get_text (ctx->root_entry); 906 ctx->cb (ctx->cb_cls,
890 ctx->cb (ctx->cb_cls, do_index, ctx->short_fn, 907 gtk_toggle_button_get_active (ctx->index_checkbutton),
891 &ctx->bo, root, GTK_RESPONSE_OK); 908 ctx->short_fn,
909 &bo,
910 gtk_entry_get_text (ctx->root_entry),
911 GTK_RESPONSE_OK);
892 free_edit_dialog_context (ctx); 912 free_edit_dialog_context (ctx);
893} 913}
894 914
895 915
896gboolean
897GNUNET_GTK_edit_publication_window_delete_event_cb (GtkWidget * widget,
898 GdkEvent * event,
899 struct EditPublicationDialogContext *ctx)
900{
901 GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GTK_BUTTON (gtk_builder_get_object
902 (ctx->builder, "GNUNET_GTK_edit_publication_cancel_button")),
903 ctx);
904 return TRUE;
905}
906
907
908/* ****************** code for initialization of the dialog ******************** */ 916/* ****************** code for initialization of the dialog ******************** */
909 917
910 918
@@ -967,12 +975,12 @@ file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi,
967 gtk_image_set_from_pixbuf (ctx->preview_image, pixbuf); 975 gtk_image_set_from_pixbuf (ctx->preview_image, pixbuf);
968 } 976 }
969 } 977 }
970 year = (int) GNUNET_FS_time_to_year (ctx->bo.expiration_time); 978 year = (int) GNUNET_FS_time_to_year (bo->expiration_time);
971 gtk_spin_button_set_value (ctx->expiration_year_spin, year); 979 gtk_spin_button_set_value (ctx->expiration_year_spin, year);
972 GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo, 980 GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo,
973 ctx->bo.anonymity_level); 981 bo->anonymity_level);
974 gtk_spin_button_set_value (ctx->priority_spin, ctx->bo.content_priority); 982 gtk_spin_button_set_value (ctx->priority_spin, bo->content_priority);
975 gtk_spin_button_set_value (ctx->replication_spin, ctx->bo.replication_level); 983 gtk_spin_button_set_value (ctx->replication_spin, bo->replication_level);
976 gtk_toggle_button_set_active (ctx->index_checkbutton, *do_index); 984 gtk_toggle_button_set_active (ctx->index_checkbutton, *do_index);
977 return GNUNET_SYSERR; /* only visit top-level item */ 985 return GNUNET_SYSERR; /* only visit top-level item */
978} 986}
@@ -1001,9 +1009,7 @@ GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget, struct EditPub
1001 */ 1009 */
1002void 1010void
1003GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, 1011GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
1004 int do_index /* FIXME: not needed? */,
1005 const char *short_fn, 1012 const char *short_fn,
1006 const struct GNUNET_FS_BlockOptions bo,
1007 struct GNUNET_FS_FileInformation *fip, 1013 struct GNUNET_FS_FileInformation *fip,
1008 gboolean allow_no_keywords, 1014 gboolean allow_no_keywords,
1009 GtkListStore *anon_liststore, 1015 GtkListStore *anon_liststore,
@@ -1117,7 +1123,6 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
1117 1123
1118 if (NULL != short_fn) 1124 if (NULL != short_fn)
1119 ctx->short_fn = GNUNET_strdup (short_fn); 1125 ctx->short_fn = GNUNET_strdup (short_fn);
1120 ctx->bo = bo;
1121 ctx->fip = fip; 1126 ctx->fip = fip;
1122 ctx->preview_changed = GNUNET_NO; 1127 ctx->preview_changed = GNUNET_NO;
1123 ctx->allow_no_keywords = allow_no_keywords; 1128 ctx->allow_no_keywords = allow_no_keywords;
diff --git a/src/fs/gnunet-fs-gtk-edit_publish_dialog.h b/src/fs/gnunet-fs-gtk-edit_publish_dialog.h
index 1492d2be..68514031 100644
--- a/src/fs/gnunet-fs-gtk-edit_publish_dialog.h
+++ b/src/fs/gnunet-fs-gtk-edit_publish_dialog.h
@@ -54,8 +54,7 @@ typedef void (*GNUNET_FS_GTK_EditPublishDialogCallback) (gpointer cls,
54 */ 54 */
55void 55void
56GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, 56GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent,
57 int do_index, const char *short_fn, 57 const char *short_fn,
58 const struct GNUNET_FS_BlockOptions bo,
59 struct GNUNET_FS_FileInformation *fip, 58 struct GNUNET_FS_FileInformation *fip,
60 gboolean allow_no_keywords, GtkListStore *anon_liststore, 59 gboolean allow_no_keywords, GtkListStore *anon_liststore,
61 GNUNET_FS_GTK_EditPublishDialogCallback cb, 60 GNUNET_FS_GTK_EditPublishDialogCallback cb,
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 b3075eb1..d6008f77 100644
--- a/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
+++ b/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
@@ -205,8 +205,8 @@ GNUNET_GTK_select_pseudonym_dialog_response_cb (GtkDialog * dialog,
205 GNUNET_FS_file_information_create_empty_directory (NULL, NULL, NULL, meta, 205 GNUNET_FS_file_information_create_empty_directory (NULL, NULL, NULL, meta,
206 &nds->bo, NULL); 206 &nds->bo, NULL);
207 GNUNET_CONTAINER_meta_data_destroy (meta); 207 GNUNET_CONTAINER_meta_data_destroy (meta);
208 GNUNET_FS_GTK_edit_publish_dialog (transient, nds->do_index, 208 GNUNET_FS_GTK_edit_publish_dialog (transient,
209 nds->short_fn, nds->bo, nds->fip, FALSE, anon_liststore, 209 nds->short_fn, nds->fip, FALSE, anon_liststore,
210 &adv_pseudonym_edit_publish_dialog_cb, 210 &adv_pseudonym_edit_publish_dialog_cb,
211 nds); 211 nds);
212} 212}
diff --git a/src/fs/gnunet-fs-gtk-main_window_file_publish.c b/src/fs/gnunet-fs-gtk-main_window_file_publish.c
index db349c95..387736b6 100644
--- a/src/fs/gnunet-fs-gtk-main_window_file_publish.c
+++ b/src/fs/gnunet-fs-gtk-main_window_file_publish.c
@@ -94,10 +94,6 @@ struct AddDirClientContext
94 unsigned int total; 94 unsigned int total;
95}; 95};
96 96
97void
98GNUNET_GTK_publish_file_dialog_response_cb (GtkDialog * dialog,
99 gint response_id,
100 struct MainPublishingDialogContext *ctx);
101 97
102static void 98static void
103selection_changed_cb (GtkTreeSelection * ts, struct MainPublishingDialogContext *ctx); 99selection_changed_cb (GtkTreeSelection * ts, struct MainPublishingDialogContext *ctx);
@@ -613,173 +609,6 @@ GNUNET_GTK_master_publish_dialog_new_button_clicked_cb (GtkWidget * dummy,
613} 609}
614 610
615 611
616void
617GNUNET_GTK_master_publish_dialog_add_button_clicked_cb (GtkWidget * dummy,
618 struct MainPublishingDialogContext *ctx)
619{
620 GtkWidget *ad;
621
622 GtkComboBox *combo;
623 GtkTreeModel *anon_treemodel;
624
625 ctx->open_file_builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_file_dialog.glade", ctx);
626 GNUNET_FS_GTK_setup_expiration_year_adjustment (ctx->open_file_builder);
627 ad = GTK_WIDGET (gtk_builder_get_object
628 (ctx->open_file_builder, "GNUNET_GTK_publish_file_dialog"));
629
630 /* FIXME: Use some kind of adjustable defaults instead of 1000, 0 and TRUE */
631 gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (
632 ctx->open_file_builder,
633 "GNUNET_GTK_publish_file_dialog_priority_spin_button")), 1000);
634 gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (
635 ctx->open_file_builder,
636 "GNUNET_GTK_publish_file_dialog_replication_spin_button")), 0);
637 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (
638 ctx->open_file_builder,
639 "GNUNET_GTK_publish_file_dialog_do_index_checkbutton")), TRUE);
640
641 ctx->open_file_handler_id = g_signal_connect (G_OBJECT (ad), "response", G_CALLBACK (GNUNET_GTK_publish_file_dialog_response_cb), ctx);
642
643 anon_treemodel = GTK_TREE_MODEL (gtk_builder_get_object (ctx->main_window_builder,
644 "main_window_search_anonymity_liststore"));
645 combo = GTK_COMBO_BOX (gtk_builder_get_object (ctx->open_file_builder,
646 "GNUNET_GTK_publish_file_dialog_anonymity_combobox"));
647 gtk_combo_box_set_model (combo, anon_treemodel);
648
649 gtk_window_set_transient_for (GTK_WINDOW (ad), ctx->master_pubdialog);
650
651 gtk_window_present (GTK_WINDOW (ad));
652}
653
654
655struct EditPublishContext
656{
657 GtkTreeModel *tm;
658 GtkTreeIter iter;
659};
660
661
662/**
663 * Function called when the edit publish dialog has been closed.
664 *
665 * @param cls closure
666 * @param do_index index flag set?
667 * @param short_fn short filename
668 * @param bo block options for publishing
669 * @param root always NULL here
670 * @param ret GTK_RESPONSE_OK if the dialog was closed with "OK"
671 */
672static void
673master_publish_edit_publish_dialog_cb (gpointer cls, int do_index,
674 const char *short_fn,
675 const struct GNUNET_FS_BlockOptions *bo,
676 const char *root,
677 gint ret)
678{
679 struct EditPublishContext *cbargs = cls;
680 struct GNUNET_FS_FileInformation *fi;
681
682 if (ret == GTK_RESPONSE_OK)
683 {
684 gtk_tree_store_set (GTK_TREE_STORE (cbargs->tm), &cbargs->iter, 1, do_index,
685 2, short_fn, 3, (guint) bo->anonymity_level, 4,
686 (guint) bo->content_priority,
687 6, (guint64) bo->expiration_time.abs_value,
688 7, (guint) bo->replication_level,
689 -1);
690 gtk_tree_model_get (cbargs->tm, &cbargs->iter, 5, &fi, -1);
691 GNUNET_FS_file_information_set_filename (fi, short_fn);
692 }
693 GNUNET_free (cbargs);
694}
695
696
697void
698GNUNET_GTK_master_publish_dialog_edit_button_clicked_cb (GtkWidget * dummy,
699 struct MainPublishingDialogContext *ctx)
700{
701 struct EditPublishContext *cbargs;
702 gint do_index;
703 char *short_fn;
704 guint anonymity_level;
705 guint priority;
706 struct GNUNET_FS_FileInformation *fip;
707 guint64 abs_etime;
708 guint replication_level;
709 struct GNUNET_FS_BlockOptions bo;
710 GtkListStore *anon_liststore;
711
712 anon_liststore = GTK_LIST_STORE (gtk_builder_get_object (ctx->main_window_builder, "main_window_search_anonymity_liststore"));
713
714 cbargs = GNUNET_malloc (sizeof (struct EditPublishContext));
715 cbargs->tm = ctx->file_info_treemodel;
716 if (TRUE != gtk_tree_selection_get_selected (ctx->file_info_selection, NULL, &cbargs->iter))
717 {
718 GNUNET_break (0);
719 GNUNET_free (cbargs);
720 return;
721 }
722
723 gtk_tree_model_get (ctx->file_info_treemodel, &cbargs->iter, 1, &do_index, 2, &short_fn, 3,
724 &anonymity_level, 4, &priority, 5, &fip,
725 6, &abs_etime,
726 7, &replication_level,
727 -1);
728 bo.anonymity_level = anonymity_level;
729 bo.content_priority = priority;
730 bo.expiration_time.abs_value = (uint64_t) abs_etime;
731 bo.replication_level = replication_level;
732 /* FIXME: can we just give our anon_liststore out like this? What about
733 (unintended) sharing of state? */
734 GNUNET_FS_GTK_edit_publish_dialog (ctx->master_pubdialog, do_index,
735 short_fn, bo, fip, TRUE, anon_liststore,
736 &master_publish_edit_publish_dialog_cb,
737 cbargs);
738}
739
740
741/**
742 * Free row reference stored in the file information's
743 * client-info pointer.
744 */
745static int
746free_fi_row_reference (void *cls, struct GNUNET_FS_FileInformation *fi,
747 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
748 struct GNUNET_FS_Uri **uri,
749 struct GNUNET_FS_BlockOptions *bo, int *do_index,
750 void **client_info)
751{
752 GtkTreeRowReference *row = *client_info;
753
754 if (row == NULL)
755 {
756 GNUNET_break (0);
757 return GNUNET_OK;
758 }
759 gtk_tree_row_reference_free (row);
760 return GNUNET_OK;
761}
762
763
764void
765GNUNET_GTK_master_publish_dialog_delete_button_clicked_cb (GtkWidget * dummy,
766 struct MainPublishingDialogContext *ctx)
767{
768 GtkTreeIter iter;
769 struct GNUNET_FS_FileInformation *fip;
770
771 if (TRUE != gtk_tree_selection_get_selected (ctx->file_info_selection, NULL, &iter))
772 {
773 GNUNET_break (0);
774 return;
775 }
776 gtk_tree_model_get (ctx->file_info_treemodel, &iter, 5, &fip, -1);
777 GNUNET_FS_file_information_destroy (fip, &free_fi_row_reference, NULL);
778 gtk_tree_store_remove (GTK_TREE_STORE (ctx->file_info_treemodel), &iter);
779 update_selectivity (ctx);
780}
781
782
783static void 612static void
784insert_progress_dialog_text (struct AddDirClientContext *adcc, 613insert_progress_dialog_text (struct AddDirClientContext *adcc,
785 const char *text) 614 const char *text)
@@ -899,32 +728,6 @@ close_scan (struct AddDirClientContext *adcc)
899} 728}
900 729
901 730
902void
903GNUNET_FS_GTK_progress_dialog_cancel_button_clicked_cb (GtkButton *button,
904 void *cls)
905{
906 struct AddDirClientContext *adcc = cls;
907
908 if (adcc->ds != NULL)
909 {
910 /* Still scanning - signal the scanner to finish */
911 GNUNET_FS_directory_scan_abort (adcc->ds);
912 adcc->ds = NULL;
913 }
914 close_scan (adcc);
915}
916
917
918gboolean
919GNUNET_FS_GTK_progress_dialog_delete_event_cb (GtkWidget *widget,
920 GdkEvent * event,
921 void *cls)
922{
923 /* Don't allow GTK to kill the window, until the scan is finished */
924 return GNUNET_NO;
925}
926
927
928static void 731static void
929directory_scan_cb (void *cls, 732directory_scan_cb (void *cls,
930 const char *filename, int is_directory, 733 const char *filename, int is_directory,
@@ -1081,10 +884,10 @@ scan_file_or_directory (struct MainPublishingDialogContext *ctx,
1081} 884}
1082 885
1083 886
1084void 887static void
1085GNUNET_GTK_publish_directory_dialog_response_cb (GtkDialog * dialog, 888publish_directory_dialog_response_cb (GtkDialog * dialog,
1086 gint response_id, 889 gint response_id,
1087 struct MainPublishingDialogContext *ctx) 890 struct MainPublishingDialogContext *ctx)
1088{ 891{
1089 char *filename; 892 char *filename;
1090 int do_index; 893 int do_index;
@@ -1133,6 +936,265 @@ GNUNET_GTK_publish_directory_dialog_response_cb (GtkDialog * dialog,
1133} 936}
1134 937
1135 938
939static void
940publish_file_dialog_response_cb (GtkDialog * dialog,
941 gint response_id,
942 struct MainPublishingDialogContext *ctx)
943{
944 char *filename;
945 struct GNUNET_FS_BlockOptions bo;
946 int do_index;
947 GtkSpinButton *sb;
948 GtkWidget *ad;
949
950 if (g_signal_handler_is_connected (G_OBJECT (dialog), ctx->open_file_handler_id))
951 g_signal_handler_disconnect (G_OBJECT (dialog), ctx->open_file_handler_id);
952 ctx->open_file_handler_id = 0;
953
954 ad = GTK_WIDGET (gtk_builder_get_object
955 (ctx->open_file_builder, "GNUNET_GTK_publish_file_dialog"));
956
957 if (response_id == -5)
958 {
959 /* OK */
960 sb = GTK_SPIN_BUTTON (gtk_builder_get_object
961 (ctx->open_file_builder,
962 "GNUNET_GTK_publish_file_dialog_expiration_year_spin_button"));
963
964 if (!GNUNET_GTK_get_selected_anonymity_level
965 (ctx->open_file_builder, "GNUNET_GTK_publish_file_dialog_anonymity_combobox",
966 &bo.anonymity_level))
967 bo.anonymity_level = 1;
968 bo.content_priority =
969 gtk_spin_button_get_value (GTK_SPIN_BUTTON
970 (gtk_builder_get_object
971 (ctx->open_file_builder,
972 "GNUNET_GTK_publish_file_dialog_priority_spin_button")));
973 bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (sb);
974 bo.replication_level =
975 gtk_spin_button_get_value (GTK_SPIN_BUTTON
976 (gtk_builder_get_object
977 (ctx->open_file_builder,
978 "GNUNET_GTK_publish_file_dialog_replication_spin_button")));
979 do_index =
980 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
981 (gtk_builder_get_object
982 (ctx->open_file_builder,
983 "GNUNET_GTK_publish_file_dialog_do_index_checkbutton")));
984
985 filename = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (ad));
986
987 scan_file_or_directory (ctx, filename, &bo, do_index);
988
989 g_free (filename);
990 }
991 else
992 {
993 /* Cancel/Escape/close/etc */
994 }
995 gtk_widget_destroy (ad);
996}
997
998
999void
1000GNUNET_GTK_master_publish_dialog_add_button_clicked_cb (GtkWidget * dummy,
1001 struct MainPublishingDialogContext *ctx)
1002{
1003 GtkWidget *ad;
1004
1005 GtkComboBox *combo;
1006 GtkTreeModel *anon_treemodel;
1007
1008 ctx->open_file_builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_file_dialog.glade", ctx);
1009 GNUNET_FS_GTK_setup_expiration_year_adjustment (ctx->open_file_builder);
1010 ad = GTK_WIDGET (gtk_builder_get_object
1011 (ctx->open_file_builder, "GNUNET_GTK_publish_file_dialog"));
1012
1013 /* FIXME: Use some kind of adjustable defaults instead of 1000, 0 and TRUE */
1014 gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (
1015 ctx->open_file_builder,
1016 "GNUNET_GTK_publish_file_dialog_priority_spin_button")), 1000);
1017 gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (
1018 ctx->open_file_builder,
1019 "GNUNET_GTK_publish_file_dialog_replication_spin_button")), 0);
1020 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (
1021 ctx->open_file_builder,
1022 "GNUNET_GTK_publish_file_dialog_do_index_checkbutton")), TRUE);
1023
1024 ctx->open_file_handler_id = g_signal_connect (G_OBJECT (ad), "response", G_CALLBACK (publish_file_dialog_response_cb), ctx);
1025
1026 anon_treemodel = GTK_TREE_MODEL (gtk_builder_get_object (ctx->main_window_builder,
1027 "main_window_search_anonymity_liststore"));
1028 combo = GTK_COMBO_BOX (gtk_builder_get_object (ctx->open_file_builder,
1029 "GNUNET_GTK_publish_file_dialog_anonymity_combobox"));
1030 gtk_combo_box_set_model (combo, anon_treemodel);
1031
1032 gtk_window_set_transient_for (GTK_WINDOW (ad), ctx->master_pubdialog);
1033
1034 gtk_window_present (GTK_WINDOW (ad));
1035}
1036
1037
1038struct EditPublishContext
1039{
1040 GtkTreeModel *tm;
1041 GtkTreeIter iter;
1042};
1043
1044
1045/**
1046 * Function called when the edit publish dialog has been closed.
1047 *
1048 * @param cls closure
1049 * @param do_index index flag set?
1050 * @param short_fn short filename
1051 * @param bo block options for publishing
1052 * @param root always NULL here
1053 * @param ret GTK_RESPONSE_OK if the dialog was closed with "OK"
1054 */
1055static void
1056master_publish_edit_publish_dialog_cb (gpointer cls, int do_index,
1057 const char *short_fn,
1058 const struct GNUNET_FS_BlockOptions *bo,
1059 const char *root,
1060 gint ret)
1061{
1062 struct EditPublishContext *cbargs = cls;
1063 struct GNUNET_FS_FileInformation *fi;
1064
1065 if (ret == GTK_RESPONSE_OK)
1066 {
1067 gtk_tree_store_set (GTK_TREE_STORE (cbargs->tm), &cbargs->iter,
1068 1, do_index,
1069 2, short_fn,
1070 3, (guint) bo->anonymity_level,
1071 4, (guint) bo->content_priority,
1072 6, (guint64) bo->expiration_time.abs_value,
1073 7, (guint) bo->replication_level,
1074 -1);
1075 gtk_tree_model_get (cbargs->tm, &cbargs->iter, 5, &fi, -1);
1076 GNUNET_FS_file_information_set_filename (fi, short_fn);
1077 }
1078 GNUNET_free (cbargs);
1079}
1080
1081
1082void
1083GNUNET_GTK_master_publish_dialog_edit_button_clicked_cb (GtkWidget * dummy,
1084 struct MainPublishingDialogContext *ctx)
1085{
1086 struct EditPublishContext *cbargs;
1087 gint do_index;
1088 char *short_fn;
1089 guint anonymity_level;
1090 guint priority;
1091 struct GNUNET_FS_FileInformation *fip;
1092 guint64 abs_etime;
1093 guint replication_level;
1094 struct GNUNET_FS_BlockOptions bo;
1095 GtkListStore *anon_liststore;
1096
1097 anon_liststore = GTK_LIST_STORE (gtk_builder_get_object (ctx->main_window_builder, "main_window_search_anonymity_liststore"));
1098
1099 cbargs = GNUNET_malloc (sizeof (struct EditPublishContext));
1100 cbargs->tm = ctx->file_info_treemodel;
1101 if (TRUE != gtk_tree_selection_get_selected (ctx->file_info_selection, NULL, &cbargs->iter))
1102 {
1103 GNUNET_break (0);
1104 GNUNET_free (cbargs);
1105 return;
1106 }
1107
1108 gtk_tree_model_get (ctx->file_info_treemodel, &cbargs->iter,
1109 1, &do_index,
1110 2, &short_fn,
1111 3, &anonymity_level,
1112 4, &priority,
1113 5, &fip,
1114 6, &abs_etime,
1115 7, &replication_level,
1116 -1);
1117 bo.anonymity_level = anonymity_level;
1118 bo.content_priority = priority;
1119 bo.expiration_time.abs_value = (uint64_t) abs_etime;
1120 bo.replication_level = replication_level;
1121 /* FIXME: can we just give our anon_liststore out like this? What about
1122 (unintended) sharing of state? */
1123 GNUNET_FS_GTK_edit_publish_dialog (ctx->master_pubdialog,
1124 short_fn, fip, TRUE, anon_liststore,
1125 &master_publish_edit_publish_dialog_cb,
1126 cbargs);
1127}
1128
1129
1130/**
1131 * Free row reference stored in the file information's
1132 * client-info pointer.
1133 */
1134static int
1135free_fi_row_reference (void *cls, struct GNUNET_FS_FileInformation *fi,
1136 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
1137 struct GNUNET_FS_Uri **uri,
1138 struct GNUNET_FS_BlockOptions *bo, int *do_index,
1139 void **client_info)
1140{
1141 GtkTreeRowReference *row = *client_info;
1142
1143 if (row == NULL)
1144 {
1145 GNUNET_break (0);
1146 return GNUNET_OK;
1147 }
1148 gtk_tree_row_reference_free (row);
1149 return GNUNET_OK;
1150}
1151
1152
1153void
1154GNUNET_GTK_master_publish_dialog_delete_button_clicked_cb (GtkWidget * dummy,
1155 struct MainPublishingDialogContext *ctx)
1156{
1157 GtkTreeIter iter;
1158 struct GNUNET_FS_FileInformation *fip;
1159
1160 if (TRUE != gtk_tree_selection_get_selected (ctx->file_info_selection, NULL, &iter))
1161 {
1162 GNUNET_break (0);
1163 return;
1164 }
1165 gtk_tree_model_get (ctx->file_info_treemodel, &iter, 5, &fip, -1);
1166 GNUNET_FS_file_information_destroy (fip, &free_fi_row_reference, NULL);
1167 gtk_tree_store_remove (GTK_TREE_STORE (ctx->file_info_treemodel), &iter);
1168 update_selectivity (ctx);
1169}
1170
1171
1172void
1173GNUNET_FS_GTK_progress_dialog_cancel_button_clicked_cb (GtkButton *button,
1174 void *cls)
1175{
1176 struct AddDirClientContext *adcc = cls;
1177
1178 if (adcc->ds != NULL)
1179 {
1180 /* Still scanning - signal the scanner to finish */
1181 GNUNET_FS_directory_scan_abort (adcc->ds);
1182 adcc->ds = NULL;
1183 }
1184 close_scan (adcc);
1185}
1186
1187
1188gboolean
1189GNUNET_FS_GTK_progress_dialog_delete_event_cb (GtkWidget *widget,
1190 GdkEvent * event,
1191 void *cls)
1192{
1193 /* Don't allow GTK to kill the window, until the scan is finished */
1194 return GNUNET_NO;
1195}
1196
1197
1136void 1198void
1137GNUNET_GTK_master_publish_dialog_open_button_clicked_cb (GtkWidget * dummy, 1199GNUNET_GTK_master_publish_dialog_open_button_clicked_cb (GtkWidget * dummy,
1138 struct MainPublishingDialogContext *ctx) 1200 struct MainPublishingDialogContext *ctx)
@@ -1159,7 +1221,7 @@ GNUNET_GTK_master_publish_dialog_open_button_clicked_cb (GtkWidget * dummy,
1159 ad = GTK_WIDGET (gtk_builder_get_object 1221 ad = GTK_WIDGET (gtk_builder_get_object
1160 (ctx->open_directory_builder, "GNUNET_GTK_publish_directory_dialog")); 1222 (ctx->open_directory_builder, "GNUNET_GTK_publish_directory_dialog"));
1161 1223
1162 ctx->open_directory_handler_id = g_signal_connect (G_OBJECT (ad), "response", G_CALLBACK (GNUNET_GTK_publish_directory_dialog_response_cb), ctx); 1224 ctx->open_directory_handler_id = g_signal_connect (G_OBJECT (ad), "response", G_CALLBACK (publish_directory_dialog_response_cb), ctx);
1163 1225
1164 anon_treemodel = GTK_TREE_MODEL (gtk_builder_get_object (ctx->main_window_builder, 1226 anon_treemodel = GTK_TREE_MODEL (gtk_builder_get_object (ctx->main_window_builder,
1165 "main_window_search_anonymity_liststore")); 1227 "main_window_search_anonymity_liststore"));
@@ -1502,66 +1564,6 @@ GNUNET_GTK_master_publish_dialog_delete_event_cb (GtkWidget * widget,
1502} 1564}
1503 1565
1504 1566
1505void
1506GNUNET_GTK_publish_file_dialog_response_cb (GtkDialog * dialog,
1507 gint response_id,
1508 struct MainPublishingDialogContext *ctx)
1509{
1510 char *filename;
1511 struct GNUNET_FS_BlockOptions bo;
1512 int do_index;
1513 GtkSpinButton *sb;
1514 GtkWidget *ad;
1515
1516 if (g_signal_handler_is_connected (G_OBJECT (dialog), ctx->open_file_handler_id))
1517 g_signal_handler_disconnect (G_OBJECT (dialog), ctx->open_file_handler_id);
1518 ctx->open_file_handler_id = 0;
1519
1520 ad = GTK_WIDGET (gtk_builder_get_object
1521 (ctx->open_file_builder, "GNUNET_GTK_publish_file_dialog"));
1522
1523 if (response_id == -5)
1524 {
1525 /* OK */
1526 sb = GTK_SPIN_BUTTON (gtk_builder_get_object
1527 (ctx->open_file_builder,
1528 "GNUNET_GTK_publish_file_dialog_expiration_year_spin_button"));
1529
1530 if (!GNUNET_GTK_get_selected_anonymity_level
1531 (ctx->open_file_builder, "GNUNET_GTK_publish_file_dialog_anonymity_combobox",
1532 &bo.anonymity_level))
1533 bo.anonymity_level = 1;
1534 bo.content_priority =
1535 gtk_spin_button_get_value (GTK_SPIN_BUTTON
1536 (gtk_builder_get_object
1537 (ctx->open_file_builder,
1538 "GNUNET_GTK_publish_file_dialog_priority_spin_button")));
1539 bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (sb);
1540 bo.replication_level =
1541 gtk_spin_button_get_value (GTK_SPIN_BUTTON
1542 (gtk_builder_get_object
1543 (ctx->open_file_builder,
1544 "GNUNET_GTK_publish_file_dialog_replication_spin_button")));
1545 do_index =
1546 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
1547 (gtk_builder_get_object
1548 (ctx->open_file_builder,
1549 "GNUNET_GTK_publish_file_dialog_do_index_checkbutton")));
1550
1551 filename = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (ad));
1552
1553 scan_file_or_directory (ctx, filename, &bo, do_index);
1554
1555 g_free (filename);
1556 }
1557 else
1558 {
1559 /* Cancel/Escape/close/etc */
1560 }
1561 gtk_widget_destroy (ad);
1562}
1563
1564
1565/** 1567/**
1566 */ 1568 */
1567void 1569void