diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-edit_publish_dialog.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-edit_publish_dialog.c | 1074 |
1 files changed, 684 insertions, 390 deletions
diff --git a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c index 2465e6ac..37fe1a2a 100644 --- a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c +++ b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c | |||
@@ -24,87 +24,26 @@ | |||
24 | */ | 24 | */ |
25 | #include "gnunet-fs-gtk-common.h" | 25 | #include "gnunet-fs-gtk-common.h" |
26 | #include "gnunet-fs-gtk-edit_publish_dialog.h" | 26 | #include "gnunet-fs-gtk-edit_publish_dialog.h" |
27 | #include "gnunet-fs-gtk.h" | ||
27 | #include <gnunet/gnunet_util_lib.h> | 28 | #include <gnunet/gnunet_util_lib.h> |
29 | #include <gdk/gdkkeysyms.h> | ||
28 | 30 | ||
29 | /** | 31 | #define PUBSTATE "edit-publication-state" |
30 | * Builder for the current dialog. | ||
31 | */ | ||
32 | static GtkBuilder *builder; | ||
33 | |||
34 | /** | ||
35 | * Are we editing metadata for a directory? | ||
36 | */ | ||
37 | static int is_directory; | ||
38 | |||
39 | /** | ||
40 | * Set to YES if the preview was changed. | ||
41 | */ | ||
42 | static int preview_changed; | ||
43 | |||
44 | void | ||
45 | GNUNET_GTK_edit_file_information_keyword_list_normalize_button_clicked_cb () | ||
46 | { | ||
47 | GNUNET_break (0); | ||
48 | } | ||
49 | |||
50 | void | ||
51 | GNUNET_GTK_edit_file_information_keyword_list_del_button_clicked_cb () | ||
52 | { | ||
53 | GtkTreeView *tv; | ||
54 | GtkTreeSelection *sel; | ||
55 | GtkTreeModel *tm; | ||
56 | GtkTreeIter iter; | ||
57 | |||
58 | tv = GTK_TREE_VIEW (gtk_builder_get_object | ||
59 | (builder, | ||
60 | "GNUNET_GTK_edit_file_information_keyword_list_tree_view")); | ||
61 | sel = gtk_tree_view_get_selection (tv); | ||
62 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
63 | { | ||
64 | GNUNET_break (0); | ||
65 | return; | ||
66 | } | ||
67 | gtk_list_store_remove (GTK_LIST_STORE (tm), &iter); | ||
68 | } | ||
69 | |||
70 | void | ||
71 | GNUNET_GTK_edit_file_information_keyword_list_add_button_clicked_cb () | ||
72 | { | ||
73 | const char *keyword; | ||
74 | GtkEntry *entry; | ||
75 | GtkListStore *ls; | ||
76 | GtkTreeIter iter; | ||
77 | |||
78 | ls = GTK_LIST_STORE (gtk_builder_get_object | ||
79 | (builder, "GNUNET_GTK_keyword_list_store")); | ||
80 | entry = | ||
81 | GTK_ENTRY (gtk_builder_get_object | ||
82 | (builder, "GNUNET_GTK_edit_file_information_keyword_entry")); | ||
83 | keyword = gtk_entry_get_text (entry); | ||
84 | if (strlen (keyword) > 0) | ||
85 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, keyword, -1); | ||
86 | gtk_entry_set_text (entry, ""); | ||
87 | } | ||
88 | 32 | ||
89 | 33 | struct edit_publication_state | |
90 | void | ||
91 | GNUNET_GTK_edit_file_information_keyword_entry_changed_cb () | ||
92 | { | 34 | { |
93 | const char *keyword; | 35 | int *do_index; |
94 | GtkEntry *entry; | 36 | char **short_fn; |
95 | GtkWidget *button; | 37 | guint *anonymity_level; |
96 | 38 | guint *priority; | |
97 | button = | 39 | struct GNUNET_FS_FileInformation *fip; |
98 | GTK_WIDGET (gtk_builder_get_object | 40 | gint preview_changed; |
99 | (builder, | 41 | gboolean allow_no_keywords; |
100 | "GNUNET_GTK_edit_file_information_keyword_list_add_button")); | 42 | gboolean is_directory; |
101 | entry = | 43 | GNUNET_FS_GTK_edit_publish_dialog_cb cb; |
102 | GTK_ENTRY (gtk_builder_get_object | 44 | gchar *root; |
103 | (builder, "GNUNET_GTK_edit_file_information_keyword_entry")); | 45 | gpointer cls; |
104 | keyword = gtk_entry_get_text (entry); | 46 | }; |
105 | gtk_widget_set_sensitive (button, (strlen (keyword) > 0) ? TRUE : FALSE); | ||
106 | } | ||
107 | |||
108 | 47 | ||
109 | static void | 48 | static void |
110 | metadata_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) | 49 | metadata_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) |
@@ -112,165 +51,222 @@ metadata_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) | |||
112 | GtkTreeView *tv; | 51 | GtkTreeView *tv; |
113 | GtkTreeSelection *sel; | 52 | GtkTreeSelection *sel; |
114 | GtkWidget *button; | 53 | GtkWidget *button; |
54 | GtkBuilder *builder; | ||
55 | |||
56 | builder = GTK_BUILDER (user_data); | ||
115 | 57 | ||
116 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 58 | tv = GTK_TREE_VIEW (gtk_builder_get_object |
117 | (builder, | 59 | (builder, |
118 | "GNUNET_GTK_edit_file_information_metadata_tree_view")); | 60 | "GNUNET_GTK_edit_publication_metadata_tree_view")); |
119 | sel = gtk_tree_view_get_selection (tv); | 61 | sel = gtk_tree_view_get_selection (tv); |
120 | button = | 62 | button = |
121 | GTK_WIDGET (gtk_builder_get_object | 63 | GTK_WIDGET (gtk_builder_get_object |
122 | (builder, | 64 | (builder, |
123 | "GNUNET_GTK_edit_file_information_metadata_delete_button")); | 65 | "GNUNET_GTK_edit_publication_delete_button")); |
124 | gtk_widget_set_sensitive (button, | 66 | gtk_widget_set_sensitive (button, |
125 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | 67 | gtk_tree_selection_get_selected (sel, NULL, NULL)); |
126 | } | 68 | } |
127 | 69 | ||
128 | |||
129 | static void | 70 | static void |
130 | keyword_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) | 71 | keywords_selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) |
131 | { | 72 | { |
132 | GtkTreeView *tv; | 73 | GtkTreeView *tv; |
133 | GtkTreeSelection *sel; | 74 | GtkTreeSelection *sel; |
134 | GtkWidget *button; | 75 | GtkWidget *button; |
76 | GtkBuilder *builder; | ||
77 | |||
78 | builder = GTK_BUILDER (user_data); | ||
79 | |||
135 | 80 | ||
136 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 81 | tv = GTK_TREE_VIEW (gtk_builder_get_object |
137 | (builder, | 82 | (builder, |
138 | "GNUNET_GTK_edit_file_information_keyword_list_tree_view")); | 83 | "GNUNET_GTK_edit_publication_keyword_list_tree_view")); |
139 | sel = gtk_tree_view_get_selection (tv); | 84 | sel = gtk_tree_view_get_selection (tv); |
140 | button = | 85 | button = |
141 | GTK_WIDGET (gtk_builder_get_object | 86 | GTK_WIDGET (gtk_builder_get_object |
142 | (builder, | 87 | (builder, |
143 | "GNUNET_GTK_edit_file_information_keyword_list_del_button")); | 88 | "GNUNET_GTK_edit_publication_keyword_list_del_button")); |
144 | 89 | ||
145 | gtk_widget_set_sensitive (button, | 90 | gtk_widget_set_sensitive (button, |
146 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | 91 | gtk_tree_selection_get_selected (sel, NULL, NULL)); |
147 | button = | 92 | button = |
148 | GTK_WIDGET (gtk_builder_get_object | 93 | GTK_WIDGET (gtk_builder_get_object |
149 | (builder, | 94 | (builder, |
150 | "GNUNET_GTK_edit_file_information_keyword_list_normalize_button")); | 95 | "GNUNET_GTK_edit_publication_keyword_list_normalize_button")); |
151 | gtk_widget_set_sensitive (button, | 96 | gtk_widget_set_sensitive (button, |
152 | gtk_tree_selection_get_selected (sel, NULL, NULL)); | 97 | gtk_tree_selection_get_selected (sel, NULL, NULL)); |
153 | } | 98 | } |
154 | 99 | ||
155 | 100 | ||
156 | void | 101 | void |
157 | GNUNET_GTK_edit_file_information_metadata_value_entry_changed_cb () | 102 | GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget, |
103 | gpointer user_data) | ||
158 | { | 104 | { |
105 | GtkBuilder *builder; | ||
106 | GtkListStore *metatypes_list; | ||
107 | GtkTreeIter iter; | ||
159 | GtkTreeView *tv; | 108 | GtkTreeView *tv; |
160 | GtkTreeSelection *sel; | 109 | GtkTreeSelection *sel; |
161 | const char *value; | 110 | guint type; |
162 | GtkEntry *entry; | 111 | guint max_type; |
163 | GtkWidget *button; | ||
164 | 112 | ||
165 | entry = | 113 | builder = GTK_BUILDER (user_data); |
166 | GTK_ENTRY (gtk_builder_get_object | 114 | metatypes_list = GTK_LIST_STORE (gtk_builder_get_object (builder, |
167 | (builder, | 115 | "GNUNET_GTK_publication_metadata_types_liststore")); |
168 | "GNUNET_GTK_edit_file_information_metadata_value_entry")); | 116 | |
169 | value = gtk_entry_get_text (entry); | 117 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, |
170 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 118 | "GNUNET_GTK_edit_publication_metadata_tree_view")); |
171 | (builder, | ||
172 | "GNUNET_GTK_edit_file_information_metadata_type_tree_view")); | ||
173 | sel = gtk_tree_view_get_selection (tv); | 119 | sel = gtk_tree_view_get_selection (tv); |
174 | button = | 120 | g_signal_connect (G_OBJECT (sel), "changed", |
175 | GTK_WIDGET (gtk_builder_get_object | 121 | G_CALLBACK (metadata_selection_changed_cb), builder); |
176 | (builder, | ||
177 | "GNUNET_GTK_edit_file_information_metadata_add_button")); | ||
178 | gtk_widget_set_sensitive (button, | ||
179 | (strlen (value) > | ||
180 | 0) ? gtk_tree_selection_get_selected (sel, NULL, | ||
181 | NULL) : | ||
182 | FALSE); | ||
183 | } | ||
184 | 122 | ||
123 | tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
124 | "GNUNET_GTK_edit_publication_keyword_list_tree_view")); | ||
125 | sel = gtk_tree_view_get_selection (tv); | ||
126 | g_signal_connect (G_OBJECT (sel), "changed", | ||
127 | G_CALLBACK (keywords_selection_changed_cb), builder); | ||
185 | 128 | ||
186 | void | 129 | max_type = EXTRACTOR_metatype_get_max (); |
187 | GNUNET_GTK_edit_file_information_keyword_entry_activate_cb () | 130 | for (type = 1; type < max_type - 1; type++) |
188 | { | 131 | gtk_list_store_insert_with_values (metatypes_list, &iter, G_MAXINT, |
189 | GNUNET_GTK_edit_file_information_keyword_list_add_button_clicked_cb (); | 132 | 0, type, |
133 | 1, EXTRACTOR_METAFORMAT_UTF8, | ||
134 | 2, EXTRACTOR_metatype_to_string (type), | ||
135 | 3, EXTRACTOR_metatype_to_description (type), -1); | ||
190 | } | 136 | } |
191 | 137 | ||
192 | |||
193 | void | 138 | void |
194 | GNUNET_GTK_edit_file_information_metadata_preview_file_chooser_button_file_set_cb | 139 | GNUNET_GTK_edit_publication_add_button_clicked_cb (GtkButton *button, |
195 | (GtkFileChooserButton * widget, gpointer user_data) | 140 | gpointer user_data) |
196 | { | 141 | { |
197 | gchar *fn; | 142 | GtkBuilder *builder; |
198 | GtkImage *image; | 143 | GtkTreeView *meta_tree; |
144 | GtkListStore *meta_list; | ||
145 | GtkTreeIter iter; | ||
199 | 146 | ||
200 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)); | 147 | builder = GTK_BUILDER (user_data); |
201 | image = | 148 | meta_tree = GTK_TREE_VIEW (gtk_builder_get_object (builder, |
202 | GTK_IMAGE (gtk_builder_get_object | 149 | "GNUNET_GTK_edit_publication_metadata_tree_view")); |
203 | (builder, | 150 | meta_list = GTK_LIST_STORE (gtk_tree_view_get_model (meta_tree)); |
204 | "GNUNET_GTK_edit_file_information_metadata_preview_image")); | 151 | |
205 | gtk_image_set_from_file (image, fn); | 152 | gtk_list_store_insert (meta_list, &iter, 0); |
206 | preview_changed = GNUNET_YES; | 153 | /* type == -1 means "not set" */ |
154 | gtk_list_store_set (meta_list, &iter, 0, -1, 1, EXTRACTOR_METAFORMAT_UTF8, | ||
155 | 2, _("Select a type"), 3, _("Specify a value"), 4, NULL, -1); | ||
207 | } | 156 | } |
208 | 157 | ||
158 | gboolean | ||
159 | GNUNET_GTK_edit_publication_keyword_entry_key_press_event_cb (GtkWidget *widget, | ||
160 | GdkEventKey *event, gpointer user_data) | ||
161 | { | ||
162 | GtkBuilder *builder; | ||
163 | GtkButton *add_button; | ||
164 | builder = GTK_BUILDER (user_data); | ||
165 | |||
166 | if (event->keyval == GDK_KEY_Return) | ||
167 | { | ||
168 | add_button = GTK_BUTTON (gtk_builder_get_object (builder, | ||
169 | "GNUNET_GTK_edit_publication_add_button")); | ||
170 | GNUNET_GTK_edit_publication_add_button_clicked_cb (add_button, user_data); | ||
171 | return TRUE; | ||
172 | } | ||
173 | return FALSE; | ||
174 | } | ||
209 | 175 | ||
210 | void | 176 | void |
211 | GNUNET_GTK_edit_file_information_metadata_delete_button_clicked_cb () | 177 | GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb ( |
178 | GtkCellRendererText *renderer, gchar *path, gchar *new_text, | ||
179 | gpointer user_data) | ||
212 | { | 180 | { |
213 | GtkTreeView *tv; | 181 | GtkBuilder *builder; |
214 | GtkTreeSelection *sel; | 182 | GtkTreeView *meta_tree; |
215 | GtkTreeModel *tm; | 183 | GtkListStore *meta_list; |
184 | GtkCellRendererCombo *combo; | ||
185 | GtkTreeModel *combo_model; | ||
216 | GtkTreeIter iter; | 186 | GtkTreeIter iter; |
187 | gint type_id; | ||
188 | gchar *description = NULL; | ||
189 | GtkTreeIter *pass_data = NULL; | ||
190 | |||
191 | builder = GTK_BUILDER (user_data); | ||
192 | meta_tree = GTK_TREE_VIEW (gtk_builder_get_object (builder, | ||
193 | "GNUNET_GTK_edit_publication_metadata_tree_view")); | ||
194 | meta_list = GTK_LIST_STORE (gtk_tree_view_get_model (meta_tree)); | ||
195 | if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (meta_list), &iter, path)) | ||
196 | return; | ||
217 | 197 | ||
218 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 198 | combo = GTK_CELL_RENDERER_COMBO (gtk_builder_get_object (builder, |
219 | (builder, | 199 | "GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer")); |
220 | "GNUNET_GTK_edit_file_information_metadata_tree_view")); | 200 | |
221 | sel = gtk_tree_view_get_selection (tv); | 201 | pass_data = g_object_get_data (G_OBJECT (combo), "selected-type"); |
222 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | 202 | if (!pass_data) |
223 | { | ||
224 | GNUNET_break (0); | ||
225 | return; | 203 | return; |
226 | } | 204 | g_object_get (combo, "model", &combo_model, NULL); |
227 | gtk_list_store_remove (GTK_LIST_STORE (tm), &iter); | 205 | gtk_tree_model_get (combo_model, pass_data, 0, &type_id, 2, &description, -1); |
206 | g_free (combo_model); | ||
207 | g_free (pass_data); | ||
208 | g_object_set_data (G_OBJECT (combo), "selected-type", NULL); | ||
209 | |||
210 | gtk_list_store_set (meta_list, &iter, 0, type_id, 1, | ||
211 | EXTRACTOR_METAFORMAT_UTF8, 2, new_text, 4, description, -1); | ||
212 | g_free (description); | ||
228 | } | 213 | } |
229 | 214 | ||
215 | void | ||
216 | GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb ( | ||
217 | GtkCellRendererCombo *combo, gchar *path_string, GtkTreeIter *new_iter, | ||
218 | gpointer user_data) | ||
219 | { | ||
220 | GtkTreeIter *pass_data; | ||
221 | |||
222 | pass_data = g_object_get_data (G_OBJECT (combo), "selected-type"); | ||
223 | if (pass_data) | ||
224 | g_free (pass_data); | ||
225 | pass_data = g_new0 (GtkTreeIter, 1); | ||
226 | *pass_data = *new_iter; | ||
227 | g_object_set_data (G_OBJECT (combo), "selected-type", pass_data); | ||
228 | } | ||
230 | 229 | ||
231 | void | 230 | void |
232 | GNUNET_GTK_edit_file_information_metadata_add_button_clicked_cb () | 231 | GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb ( |
232 | GtkCellRendererText *renderer, gchar *path, gchar *new_text, | ||
233 | gpointer user_data) | ||
233 | { | 234 | { |
234 | const char *value; | 235 | GtkBuilder *builder; |
236 | GtkTreeView *meta_tree; | ||
237 | GtkListStore *meta_list; | ||
238 | GtkTreeIter iter; | ||
239 | gint metatype; | ||
235 | char *avalue; | 240 | char *avalue; |
236 | const char *ivalue; | 241 | const char *ivalue; |
237 | GtkEntry *entry; | ||
238 | GtkListStore *ls; | ||
239 | GtkTreeModel *tm; | ||
240 | GtkTreeView *tv; | ||
241 | GtkTreeSelection *sel; | ||
242 | GtkTreeIter iter; | ||
243 | guint type; | ||
244 | size_t slen; | 242 | size_t slen; |
245 | char *pos; | 243 | char *pos; |
246 | 244 | ||
247 | entry = | 245 | GObject *pubwindow; |
248 | GTK_ENTRY (gtk_builder_get_object | 246 | struct edit_publication_state *state = NULL; |
249 | (builder, | 247 | |
250 | "GNUNET_GTK_edit_file_information_metadata_value_entry")); | 248 | builder = GTK_BUILDER (user_data); |
251 | value = gtk_entry_get_text (entry); | 249 | meta_tree = GTK_TREE_VIEW (gtk_builder_get_object (builder, |
252 | if ((value == NULL) || (strlen (value) == 0)) | 250 | "GNUNET_GTK_edit_publication_metadata_tree_view")); |
253 | { | 251 | meta_list = GTK_LIST_STORE (gtk_tree_view_get_model (meta_tree)); |
254 | GNUNET_break (0); | 252 | if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (meta_list), &iter, path)) |
255 | return; | 253 | return; |
256 | } | 254 | |
257 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 255 | pubwindow = gtk_builder_get_object (builder, |
258 | (builder, | 256 | "GNUNET_GTK_edit_publication_window"); |
259 | "GNUNET_GTK_edit_file_information_metadata_type_tree_view")); | 257 | state = g_object_get_data (pubwindow, PUBSTATE); |
260 | tm = gtk_tree_view_get_model (tv); | 258 | if (!state) |
261 | sel = gtk_tree_view_get_selection (tv); | ||
262 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
263 | { | 259 | { |
264 | GNUNET_break (0); | 260 | GNUNET_break (0); |
265 | return; | 261 | return; |
266 | } | 262 | } |
267 | gtk_tree_model_get (tm, &iter, 1, &type, -1); | 263 | |
268 | ls = GTK_LIST_STORE (gtk_builder_get_object | 264 | gtk_tree_model_get (GTK_TREE_MODEL (meta_list), &iter, 0, &metatype, -1); |
269 | (builder, "GNUNET_GTK_meta_data_list_store")); | 265 | if (metatype == EXTRACTOR_METATYPE_FILENAME |
270 | if ((type == EXTRACTOR_METATYPE_FILENAME) && | 266 | && new_text[strlen (new_text) - 1] != '/' |
271 | (value[strlen (value) - 1] != '/') && (is_directory)) | 267 | && state->is_directory) |
272 | { | 268 | { |
273 | GNUNET_asprintf (&avalue, "%s/", value); | 269 | GNUNET_asprintf (&avalue, "%s/", new_text); |
274 | /* if user typed '\' instead of '/', change it! */ | 270 | /* if user typed '\' instead of '/', change it! */ |
275 | slen = strlen (avalue); | 271 | slen = strlen (avalue); |
276 | while ((slen > 1) && (avalue[slen - 2] == '\\')) | 272 | while ((slen > 1) && (avalue[slen - 2] == '\\')) |
@@ -281,7 +277,7 @@ GNUNET_GTK_edit_file_information_metadata_add_button_clicked_cb () | |||
281 | } | 277 | } |
282 | while (NULL != (pos = strstr (avalue, "\\"))) | 278 | while (NULL != (pos = strstr (avalue, "\\"))) |
283 | *pos = '/'; | 279 | *pos = '/'; |
284 | /* remove '../' everywhere */ | 280 | // remove '../' everywhere |
285 | while (NULL != (pos = strstr (avalue, "../"))) | 281 | while (NULL != (pos = strstr (avalue, "../"))) |
286 | { | 282 | { |
287 | pos[0] = '_'; | 283 | pos[0] = '_'; |
@@ -292,158 +288,260 @@ GNUNET_GTK_edit_file_information_metadata_add_button_clicked_cb () | |||
292 | } | 288 | } |
293 | else | 289 | else |
294 | { | 290 | { |
295 | ivalue = value; | 291 | ivalue = new_text; |
296 | avalue = NULL; | 292 | avalue = NULL; |
297 | } | 293 | } |
298 | 294 | ||
299 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, type, 1, | 295 | gtk_list_store_set (meta_list, &iter, 3, ivalue, -1); |
300 | (guint) EXTRACTOR_METAFORMAT_UTF8, 2, | ||
301 | EXTRACTOR_metatype_to_string (type), 3, | ||
302 | ivalue, -1); | ||
303 | GNUNET_free_non_null (avalue); | 296 | GNUNET_free_non_null (avalue); |
304 | gtk_entry_set_text (GTK_ENTRY (entry), ""); | ||
305 | } | 297 | } |
306 | 298 | ||
299 | void | ||
300 | GNUNET_GTK_edit_publication_delete_button_clicked_cb (GtkButton *button, | ||
301 | gpointer user_data) | ||
302 | { | ||
303 | GtkTreeView *tv; | ||
304 | GtkTreeSelection *sel; | ||
305 | GtkTreeModel *tm; | ||
306 | GtkTreeIter iter; | ||
307 | GtkBuilder *builder = GTK_BUILDER (user_data); | ||
307 | 308 | ||
308 | /** | 309 | tv = GTK_TREE_VIEW (gtk_builder_get_object |
309 | * Add each of the keywords to the keyword list store. | 310 | (builder, |
310 | * | 311 | "GNUNET_GTK_edit_publication_metadata_tree_view")); |
311 | * @param cls closure | 312 | sel = gtk_tree_view_get_selection (tv); |
312 | * @param keyword the keyword | 313 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) |
313 | * @param is_mandatory is the keyword mandatory (in a search) | 314 | { |
314 | * @return GNUNET_OK to continue to iterate | 315 | GNUNET_break (0); |
315 | */ | 316 | return; |
316 | static int | 317 | } |
317 | add_keyword (void *cls, const char *keyword, int is_mandatory) | 318 | if (gtk_list_store_remove (GTK_LIST_STORE (tm), &iter)) |
319 | gtk_tree_selection_select_iter (sel, &iter); | ||
320 | } | ||
321 | |||
322 | void | ||
323 | GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb ( | ||
324 | GtkButton *button, gpointer user_data) | ||
318 | { | 325 | { |
326 | const char *keyword; | ||
327 | GtkEntry *entry; | ||
319 | GtkListStore *ls; | 328 | GtkListStore *ls; |
320 | GtkTreeIter iter; | 329 | GtkTreeIter iter; |
330 | GtkBuilder *builder; | ||
331 | GtkWidget *ok; | ||
332 | |||
333 | builder = GTK_BUILDER (user_data); | ||
321 | 334 | ||
322 | ls = GTK_LIST_STORE (gtk_builder_get_object | 335 | ls = GTK_LIST_STORE (gtk_builder_get_object |
323 | (builder, "GNUNET_GTK_keyword_list_store")); | 336 | (builder, "GNUNET_GTK_publication_keywords_liststore")); |
324 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, keyword, -1); | 337 | entry = |
325 | return GNUNET_OK; | 338 | GTK_ENTRY (gtk_builder_get_object |
339 | (builder, "GNUNET_GTK_edit_publication_keyword_entry")); | ||
340 | keyword = gtk_entry_get_text (entry); | ||
341 | if (strlen (keyword) > 0) | ||
342 | { | ||
343 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, keyword, 1, TRUE, -1); | ||
344 | ok = GTK_WIDGET (gtk_builder_get_object (builder, | ||
345 | "GNUNET_GTK_edit_publication_confirm_button")); | ||
346 | gtk_widget_set_sensitive (ok, TRUE); | ||
347 | } | ||
348 | gtk_entry_set_text (entry, ""); | ||
326 | } | 349 | } |
327 | 350 | ||
351 | gboolean | ||
352 | gtk_tree_model_get_item_count_cb (GtkTreeModel *model, GtkTreePath *path, | ||
353 | GtkTreeIter *iter, gpointer data) | ||
354 | { | ||
355 | gint *counter = (gint *) data; | ||
356 | *counter += 1; | ||
357 | return FALSE; | ||
358 | } | ||
328 | 359 | ||
329 | /** | 360 | void |
330 | * Add the given meta data to the model (or make it the preview | 361 | GNUNET_GTK_edit_publication_keyword_entry_changed_cb (GtkEditable *editable, |
331 | * image if it is an image). | 362 | gpointer user_data) |
332 | * | ||
333 | * @param cls closure, NULL | ||
334 | * @param plugin_name name of the plugin that produced this value; | ||
335 | * special values can be used (i.e. '<zlib>' for zlib being | ||
336 | * used in the main libextractor library and yielding | ||
337 | * meta data). | ||
338 | * @param type libextractor-type describing the meta data | ||
339 | * @param format basic format information about data | ||
340 | * @param data_mime_type mime-type of data (not of the original file); | ||
341 | * can be NULL (if mime-type is not known) | ||
342 | * @param data actual meta-data found | ||
343 | * @param data_len number of bytes in data | ||
344 | * @return 0 to continue extracting | ||
345 | */ | ||
346 | static int | ||
347 | add_meta_item (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, | ||
348 | enum EXTRACTOR_MetaFormat format, const char *data_mime_type, | ||
349 | const char *data, size_t data_len) | ||
350 | { | 363 | { |
351 | GtkListStore *ls; | 364 | const char *keyword; |
365 | GtkEntry *entry; | ||
366 | GtkWidget *button; | ||
367 | GtkBuilder *builder; | ||
368 | |||
369 | builder = GTK_BUILDER (user_data); | ||
370 | |||
371 | button = | ||
372 | GTK_WIDGET (gtk_builder_get_object | ||
373 | (builder, | ||
374 | "GNUNET_GTK_edit_publication_keyword_list_add_button")); | ||
375 | entry = | ||
376 | GTK_ENTRY (gtk_builder_get_object | ||
377 | (builder, "GNUNET_GTK_edit_publication_keyword_entry")); | ||
378 | keyword = gtk_entry_get_text (entry); | ||
379 | gtk_widget_set_sensitive (button, (strlen (keyword) > 0) ? TRUE : FALSE); | ||
380 | } | ||
381 | |||
382 | |||
383 | gint | ||
384 | gtk_tree_model_get_item_count (GtkTreeModel *model) | ||
385 | { | ||
386 | gint c = 0; | ||
387 | gtk_tree_model_foreach (model, >k_tree_model_get_item_count_cb, &c); | ||
388 | return c; | ||
389 | } | ||
390 | |||
391 | gboolean | ||
392 | gtk_tree_model_has_items_cb (GtkTreeModel *model, GtkTreePath *path, | ||
393 | GtkTreeIter *iter, gpointer data) | ||
394 | { | ||
395 | gboolean *val = (gboolean *) data; | ||
396 | *val = TRUE; | ||
397 | return TRUE; | ||
398 | } | ||
399 | |||
400 | gboolean | ||
401 | gtk_tree_model_has_items (GtkTreeModel *model) | ||
402 | { | ||
403 | gboolean b = FALSE; | ||
404 | gtk_tree_model_foreach (model, >k_tree_model_has_items_cb, &b); | ||
405 | return b; | ||
406 | } | ||
407 | |||
408 | void | ||
409 | GNUNET_GTK_edit_publication_keyword_list_del_button_clicked_cb ( | ||
410 | GtkButton *button, gpointer user_data) | ||
411 | { | ||
412 | GtkTreeView *tv; | ||
413 | GtkTreeSelection *sel; | ||
414 | GtkTreeModel *tm; | ||
352 | GtkTreeIter iter; | 415 | GtkTreeIter iter; |
416 | GtkBuilder *builder; | ||
417 | GtkWidget *ok; | ||
418 | GObject *pubwindow; | ||
419 | struct edit_publication_state *state = NULL; | ||
420 | builder = GTK_BUILDER (user_data); | ||
353 | 421 | ||
354 | switch (format) | 422 | tv = GTK_TREE_VIEW (gtk_builder_get_object |
423 | (builder, | ||
424 | "GNUNET_GTK_edit_publication_keyword_list_tree_view")); | ||
425 | |||
426 | sel = gtk_tree_view_get_selection (tv); | ||
427 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
355 | { | 428 | { |
356 | case EXTRACTOR_METAFORMAT_UTF8: | ||
357 | case EXTRACTOR_METAFORMAT_C_STRING: | ||
358 | ls = GTK_LIST_STORE (gtk_builder_get_object | ||
359 | (builder, "GNUNET_GTK_meta_data_list_store")); | ||
360 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, (guint) type, 1, | ||
361 | (guint) format, 2, | ||
362 | EXTRACTOR_metatype_to_string (type), 3, | ||
363 | data, -1); | ||
364 | break; | ||
365 | case EXTRACTOR_METAFORMAT_UNKNOWN: | ||
366 | break; | ||
367 | case EXTRACTOR_METAFORMAT_BINARY: | ||
368 | break; | ||
369 | default: | ||
370 | GNUNET_break (0); | 429 | GNUNET_break (0); |
430 | return; | ||
371 | } | 431 | } |
372 | return 0; | 432 | if (gtk_list_store_remove (GTK_LIST_STORE (tm), &iter)) |
433 | gtk_tree_selection_select_iter (sel, &iter); | ||
434 | |||
435 | ok = GTK_WIDGET (gtk_builder_get_object (builder, | ||
436 | "GNUNET_GTK_edit_publication_confirm_button")); | ||
437 | |||
438 | pubwindow = gtk_builder_get_object (builder, | ||
439 | "GNUNET_GTK_edit_publication_window"); | ||
440 | state = g_object_get_data (pubwindow, PUBSTATE); | ||
441 | if (!state) | ||
442 | { | ||
443 | GNUNET_break (0); | ||
444 | return; | ||
445 | } | ||
446 | |||
447 | if (!state->allow_no_keywords && !gtk_tree_model_has_items (tm)) | ||
448 | gtk_widget_set_sensitive (ok, FALSE); | ||
373 | } | 449 | } |
374 | 450 | ||
451 | void | ||
452 | GNUNET_GTK_edit_publication_keyword_list_normalize_button_clicked_cb ( | ||
453 | GtkButton *button, gpointer user_data) | ||
454 | { | ||
455 | GtkTreeView *tv; | ||
456 | GtkTreeSelection *sel; | ||
457 | GtkTreeModel *tm; | ||
458 | GtkTreeIter iter, inserted; | ||
459 | gchar *value; | ||
460 | struct GNUNET_FS_Uri *uri; | ||
461 | struct GNUNET_FS_Uri *nuri; | ||
462 | char *nvalue; | ||
463 | char *emsg; | ||
464 | GtkBuilder *builder; | ||
465 | builder = GTK_BUILDER (user_data); | ||
375 | 466 | ||
376 | /** | 467 | tv = GTK_TREE_VIEW (gtk_builder_get_object |
377 | * Function called to extract the information from FI. | 468 | (builder, |
378 | * | 469 | "GNUNET_GTK_edit_publication_keyword_list_tree_view")); |
379 | * @param cls closure | 470 | sel = gtk_tree_view_get_selection (tv); |
380 | * @param fi the entry in the publish-structure | 471 | if (TRUE != gtk_tree_selection_get_selected (sel, &tm, &iter)) |
381 | * @param length length of the file or directory | 472 | return; |
382 | * @param meta metadata for the file or directory (can be modified) | 473 | gtk_tree_model_get (tm, &iter, 0, &value, -1); |
383 | * @param uri pointer to the keywords that will be used for this entry (can be modified) | 474 | emsg = NULL; |
384 | * @param bo block options | 475 | uri = GNUNET_FS_uri_ksk_create (value, &emsg); |
385 | * @param do_index should we index (can be modified) | 476 | if (uri == NULL) |
386 | * @param client_info pointer to client context set upon creation (can be modified) | 477 | { |
387 | * @return GNUNET_SYSERR (aborts after first call) | 478 | GNUNET_break (0); |
388 | */ | 479 | GNUNET_free (emsg); |
389 | static int | 480 | g_free (value); |
390 | file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi, | 481 | return; |
391 | uint64_t length, | 482 | } |
392 | struct GNUNET_CONTAINER_MetaData *meta, | 483 | nuri = GNUNET_FS_uri_ksk_canonicalize (uri); |
393 | struct GNUNET_FS_Uri **uri, | 484 | nvalue = GNUNET_FS_uri_ksk_to_string_fancy (nuri); |
394 | struct GNUNET_FS_BlockOptions *bo, int *do_index, | 485 | |
395 | void **client_info) | 486 | if (strcmp (value, nvalue) != 0) |
487 | { | ||
488 | gtk_list_store_insert_after (GTK_LIST_STORE (tm), &inserted, &iter); | ||
489 | gtk_list_store_set (GTK_LIST_STORE (tm), &inserted, 0, nvalue, -1); | ||
490 | } | ||
491 | GNUNET_FS_uri_destroy (nuri); | ||
492 | GNUNET_FS_uri_destroy (uri); | ||
493 | GNUNET_free (nvalue); | ||
494 | g_free (value); | ||
495 | } | ||
496 | |||
497 | void | ||
498 | GNUNET_GTK_edit_publication_normalization_checkbox_toggled_cb ( | ||
499 | GtkToggleButton *button, gpointer user_data) | ||
396 | { | 500 | { |
397 | GtkImage *img; | 501 | GtkBuilder *builder; |
398 | GdkPixbuf *pixbuf; | 502 | GtkToggleButton *norm_button; |
399 | struct tm *t; | 503 | builder = GTK_BUILDER (user_data); |
400 | int year; | 504 | norm_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, |
401 | time_t tp; | 505 | "GNUNET_GTK_edit_publication_keyword_list_normalize_button")); |
506 | gtk_widget_set_sensitive (GTK_WIDGET (norm_button), | ||
507 | !gtk_toggle_button_get_active (norm_button)); | ||
508 | } | ||
402 | 509 | ||
403 | if (NULL != *uri) | 510 | void |
404 | GNUNET_FS_uri_ksk_get_keywords (*uri, &add_keyword, NULL); | 511 | GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button_file_set_cb ( |
405 | if (NULL != meta) | 512 | GtkFileChooserButton *widget, gpointer user_data) |
513 | { | ||
514 | gchar *fn; | ||
515 | GtkImage *image; | ||
516 | GObject *pubwindow; | ||
517 | GtkBuilder *builder = GTK_BUILDER (user_data); | ||
518 | struct edit_publication_state *state = NULL; | ||
519 | |||
520 | pubwindow = gtk_builder_get_object (builder, | ||
521 | "GNUNET_GTK_edit_publication_window"); | ||
522 | state = g_object_get_data (pubwindow, PUBSTATE); | ||
523 | if (!state) | ||
406 | { | 524 | { |
407 | GNUNET_CONTAINER_meta_data_iterate (meta, &add_meta_item, NULL); | 525 | GNUNET_break (0); |
408 | pixbuf = GNUNET_FS_GTK_get_thumbnail_from_meta_data (meta); | 526 | return; |
409 | if (pixbuf != NULL) | ||
410 | { | ||
411 | img = | ||
412 | GTK_IMAGE (gtk_builder_get_object | ||
413 | (builder, | ||
414 | "GNUNET_GTK_edit_file_information_metadata_preview_image")); | ||
415 | gtk_image_set_from_pixbuf (img, pixbuf); | ||
416 | } | ||
417 | } | 527 | } |
418 | tp = bo->expiration_time.abs_value / 1000; /* ms to seconds */ | 528 | |
419 | t = gmtime (&tp); | 529 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)); |
420 | if (t == NULL) | 530 | image = |
421 | year = 0; | 531 | GTK_IMAGE (gtk_builder_get_object |
422 | else | 532 | (builder, |
423 | year = t->tm_year + 1900; | 533 | "GNUNET_GTK_edit_publication_metadata_preview_image")); |
424 | gtk_spin_button_set_value (GTK_SPIN_BUTTON | 534 | gtk_image_set_from_file (image, fn); |
425 | (gtk_builder_get_object | 535 | state->preview_changed = GNUNET_YES; |
426 | (builder, | ||
427 | "GNUNET_GTK_edit_file_information_expiration_year_spin_button")), | ||
428 | year); | ||
429 | gtk_spin_button_set_value (GTK_SPIN_BUTTON | ||
430 | (gtk_builder_get_object | ||
431 | (builder, | ||
432 | "GNUNET_GTK_edit_file_information_anonymity_spin_button")), | ||
433 | bo->anonymity_level); | ||
434 | gtk_spin_button_set_value (GTK_SPIN_BUTTON | ||
435 | (gtk_builder_get_object | ||
436 | (builder, | ||
437 | "GNUNET_GTK_edit_file_information_priority_spin_button")), | ||
438 | bo->content_priority); | ||
439 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON | ||
440 | (gtk_builder_get_object | ||
441 | (builder, | ||
442 | "GNUNET_GTK_edit_file_information_index_check_button")), | ||
443 | *do_index); | ||
444 | return GNUNET_SYSERR; /* only visit top-level item */ | ||
445 | } | 536 | } |
446 | 537 | ||
538 | struct fiu_context | ||
539 | { | ||
540 | GtkBuilder *builder; | ||
541 | char **short_fn; | ||
542 | gchar *root; | ||
543 | struct GNUNET_CONTAINER_MetaData *md; | ||
544 | }; | ||
447 | 545 | ||
448 | /** | 546 | /** |
449 | * Copy binary meta data from to the new container and also | 547 | * Copy binary meta data from to the new container and also |
@@ -469,7 +567,9 @@ preserve_meta_items (void *cls, const char *plugin_name, | |||
469 | const char *data_mime_type, const char *data, | 567 | const char *data_mime_type, const char *data, |
470 | size_t data_len) | 568 | size_t data_len) |
471 | { | 569 | { |
472 | struct GNUNET_CONTAINER_MetaData *md = cls; | 570 | struct fiu_context *context = (struct fiu_context *) cls; |
571 | GtkBuilder *builder = context->builder; | ||
572 | struct GNUNET_CONTAINER_MetaData *md = context->md; | ||
473 | GtkTreeModel *tm; | 573 | GtkTreeModel *tm; |
474 | GtkTreeIter iter; | 574 | GtkTreeIter iter; |
475 | gchar *value; | 575 | gchar *value; |
@@ -477,13 +577,25 @@ preserve_meta_items (void *cls, const char *plugin_name, | |||
477 | guint nformat; | 577 | guint nformat; |
478 | int keep; | 578 | int keep; |
479 | 579 | ||
580 | GObject *pubwindow; | ||
581 | struct edit_publication_state *state = NULL; | ||
582 | |||
583 | pubwindow = gtk_builder_get_object (builder, | ||
584 | "GNUNET_GTK_edit_publication_window"); | ||
585 | state = g_object_get_data (pubwindow, PUBSTATE); | ||
586 | if (!state) | ||
587 | { | ||
588 | GNUNET_break (0); | ||
589 | return 0; | ||
590 | } | ||
591 | |||
480 | keep = GNUNET_NO; | 592 | keep = GNUNET_NO; |
481 | switch (format) | 593 | switch (format) |
482 | { | 594 | { |
483 | case EXTRACTOR_METAFORMAT_UTF8: | 595 | case EXTRACTOR_METAFORMAT_UTF8: |
484 | case EXTRACTOR_METAFORMAT_C_STRING: | 596 | case EXTRACTOR_METAFORMAT_C_STRING: |
485 | tm = GTK_TREE_MODEL (gtk_builder_get_object | 597 | tm = GTK_TREE_MODEL (gtk_builder_get_object |
486 | (builder, "GNUNET_GTK_meta_data_list_store")); | 598 | (builder, "GNUNET_GTK_publication_metadata_liststore")); |
487 | if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) | 599 | if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) |
488 | { | 600 | { |
489 | do | 601 | do |
@@ -505,7 +617,7 @@ preserve_meta_items (void *cls, const char *plugin_name, | |||
505 | case EXTRACTOR_METAFORMAT_UNKNOWN: | 617 | case EXTRACTOR_METAFORMAT_UNKNOWN: |
506 | break; | 618 | break; |
507 | case EXTRACTOR_METAFORMAT_BINARY: | 619 | case EXTRACTOR_METAFORMAT_BINARY: |
508 | if (preview_changed == GNUNET_NO) | 620 | if (state->preview_changed == GNUNET_NO) |
509 | keep = GNUNET_YES; | 621 | keep = GNUNET_YES; |
510 | break; | 622 | break; |
511 | default: | 623 | default: |
@@ -542,7 +654,9 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
542 | struct GNUNET_FS_BlockOptions *bo, int *do_index, | 654 | struct GNUNET_FS_BlockOptions *bo, int *do_index, |
543 | void **client_info) | 655 | void **client_info) |
544 | { | 656 | { |
545 | char **short_fn = cls; | 657 | struct fiu_context *context = (struct fiu_context *) cls; |
658 | char **short_fn = context->short_fn; | ||
659 | GtkBuilder *builder = context->builder; | ||
546 | struct GNUNET_CONTAINER_MetaData *nm; | 660 | struct GNUNET_CONTAINER_MetaData *nm; |
547 | GtkTreeModel *tm; | 661 | GtkTreeModel *tm; |
548 | GtkTreeIter iter; | 662 | GtkTreeIter iter; |
@@ -558,26 +672,49 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
558 | const char *mime; | 672 | const char *mime; |
559 | GFile *f; | 673 | GFile *f; |
560 | GFileInfo *finfo; | 674 | GFileInfo *finfo; |
675 | gboolean auto_normalize = FALSE; | ||
561 | 676 | ||
562 | bo->anonymity_level = | 677 | GObject *pubwindow; |
563 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | 678 | struct edit_publication_state *state = NULL; |
564 | (gtk_builder_get_object | 679 | |
565 | (builder, | 680 | pubwindow = gtk_builder_get_object (builder, |
566 | "GNUNET_GTK_edit_file_information_anonymity_spin_button"))); | 681 | "GNUNET_GTK_edit_publication_window"); |
682 | state = g_object_get_data (pubwindow, PUBSTATE); | ||
683 | if (!state) | ||
684 | { | ||
685 | GNUNET_break (0); | ||
686 | return GNUNET_SYSERR; | ||
687 | } | ||
688 | |||
689 | if (!GNUNET_GTK_get_selected_anonymity_level (builder, | ||
690 | "GNUNET_GTK_edit_publication_anonymity_combobox", &bo->anonymity_level)) | ||
691 | return GNUNET_SYSERR; | ||
567 | bo->content_priority = | 692 | bo->content_priority = |
568 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | 693 | gtk_spin_button_get_value (GTK_SPIN_BUTTON |
569 | (gtk_builder_get_object | 694 | (gtk_builder_get_object |
570 | (builder, | 695 | (builder, |
571 | "GNUNET_GTK_edit_file_information_priority_spin_button"))); | 696 | "GNUNET_GTK_edit_publication_priority_spin_button"))); |
572 | *do_index = | 697 | *do_index = |
573 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON | 698 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON |
574 | (gtk_builder_get_object | 699 | (gtk_builder_get_object |
575 | (builder, | 700 | (builder, |
576 | "GNUNET_GTK_edit_file_information_index_check_button"))); | 701 | "GNUNET_GTK_edit_publication_index_checkbutton"))); |
702 | auto_normalize = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON | ||
703 | (gtk_builder_get_object | ||
704 | (builder, | ||
705 | "GNUNET_GTK_edit_publication_normalization_checkbox"))); | ||
577 | sb = GTK_SPIN_BUTTON (gtk_builder_get_object | 706 | sb = GTK_SPIN_BUTTON (gtk_builder_get_object |
578 | (builder, | 707 | (builder, |
579 | "GNUNET_GTK_edit_file_information_expiration_year_spin_button")); | 708 | "GNUNET_GTK_edit_publication_expiration_year_spin_button")); |
580 | bo->expiration_time = GNUNET_FS_GTK_get_expiration_time (sb); | 709 | bo->expiration_time = GNUNET_FS_GTK_get_expiration_time (sb); |
710 | |||
711 | g_free (context->root); | ||
712 | context->root = | ||
713 | g_strdup (gtk_entry_get_text (GTK_ENTRY | ||
714 | (gtk_builder_get_object | ||
715 | (builder, | ||
716 | "GNUNET_GTK_edit_publication_root_entry")))); | ||
717 | |||
581 | /* update URI */ | 718 | /* update URI */ |
582 | if (NULL != (*uri)) | 719 | if (NULL != (*uri)) |
583 | GNUNET_FS_uri_destroy (*uri); | 720 | GNUNET_FS_uri_destroy (*uri); |
@@ -586,7 +723,7 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
586 | mrg = NULL; | 723 | mrg = NULL; |
587 | 724 | ||
588 | tm = GTK_TREE_MODEL (gtk_builder_get_object | 725 | tm = GTK_TREE_MODEL (gtk_builder_get_object |
589 | (builder, "GNUNET_GTK_keyword_list_store")); | 726 | (builder, "GNUNET_GTK_publication_keywords_liststore")); |
590 | if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) | 727 | if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) |
591 | { | 728 | { |
592 | do | 729 | do |
@@ -598,6 +735,24 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
598 | if (NULL != *uri) | 735 | if (NULL != *uri) |
599 | GNUNET_FS_uri_destroy (*uri); | 736 | GNUNET_FS_uri_destroy (*uri); |
600 | *uri = mrg; | 737 | *uri = mrg; |
738 | if (auto_normalize) | ||
739 | { | ||
740 | char *emsg = NULL; | ||
741 | struct GNUNET_FS_Uri *nuri; | ||
742 | |||
743 | nuri = GNUNET_FS_uri_ksk_create (value, &emsg); | ||
744 | if (nuri == NULL) | ||
745 | GNUNET_free_non_null (emsg); | ||
746 | else | ||
747 | { | ||
748 | nxt = GNUNET_FS_uri_ksk_canonicalize (nuri); | ||
749 | mrg = GNUNET_FS_uri_ksk_merge (nxt, *uri); | ||
750 | GNUNET_FS_uri_destroy (nxt); | ||
751 | if (NULL != *uri) | ||
752 | GNUNET_FS_uri_destroy (*uri); | ||
753 | *uri = mrg; | ||
754 | } | ||
755 | } | ||
601 | g_free (value); | 756 | g_free (value); |
602 | } | 757 | } |
603 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | 758 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); |
@@ -605,30 +760,31 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
605 | 760 | ||
606 | /* update meta */ | 761 | /* update meta */ |
607 | nm = GNUNET_CONTAINER_meta_data_create (); | 762 | nm = GNUNET_CONTAINER_meta_data_create (); |
608 | GNUNET_CONTAINER_meta_data_iterate (meta, &preserve_meta_items, nm); | 763 | context->md = nm; |
764 | GNUNET_CONTAINER_meta_data_iterate (meta, &preserve_meta_items, context); | ||
609 | 765 | ||
610 | GNUNET_CONTAINER_meta_data_clear (meta); | 766 | GNUNET_CONTAINER_meta_data_clear (meta); |
611 | tm = GTK_TREE_MODEL (gtk_builder_get_object | 767 | tm = GTK_TREE_MODEL (gtk_builder_get_object |
612 | (builder, "GNUNET_GTK_meta_data_list_store")); | 768 | (builder, "GNUNET_GTK_publication_metadata_liststore")); |
613 | if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) | 769 | if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) |
614 | { | 770 | { |
615 | do | 771 | do |
616 | { | 772 | { |
617 | gtk_tree_model_get (tm, &iter, 0, &ntype, 1, &nformat, 3, &value, -1); | 773 | gtk_tree_model_get (tm, &iter, 0, &ntype, 1, &nformat, 3, &value, -1); |
618 | GNUNET_CONTAINER_meta_data_insert (nm, "<user>", ntype, nformat, | 774 | if (ntype >= 0) |
619 | "text/plain", value, | 775 | GNUNET_CONTAINER_meta_data_insert (nm, "<user>", ntype, nformat, |
620 | strlen (value) + 1); | 776 | "text/plain", value, strlen (value) + 1); |
621 | g_free (value); | 777 | g_free (value); |
622 | } | 778 | } |
623 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | 779 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); |
624 | } | 780 | } |
625 | GNUNET_CONTAINER_meta_data_merge (meta, nm); | 781 | GNUNET_CONTAINER_meta_data_merge (meta, nm); |
626 | if (preview_changed == GNUNET_YES) | 782 | if (state->preview_changed == GNUNET_YES) |
627 | { | 783 | { |
628 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER | 784 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER |
629 | (gtk_builder_get_object | 785 | (gtk_builder_get_object |
630 | (builder, | 786 | (builder, |
631 | "GNUNET_GTK_edit_file_information_metadata_preview_file_chooser_button"))); | 787 | "GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button"))); |
632 | f = g_file_new_for_path (fn); | 788 | f = g_file_new_for_path (fn); |
633 | finfo = | 789 | finfo = |
634 | g_file_query_info (f, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, | 790 | g_file_query_info (f, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, |
@@ -663,32 +819,190 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
663 | return GNUNET_SYSERR; /* only visit top-level item */ | 819 | return GNUNET_SYSERR; /* only visit top-level item */ |
664 | } | 820 | } |
665 | 821 | ||
822 | void | ||
823 | GNUNET_GTK_edit_publication_cancel_button_clicked_cb ( | ||
824 | GtkButton *button, gpointer user_data) | ||
825 | { | ||
826 | GtkBuilder *builder; | ||
827 | GObject *pubwindow; | ||
828 | struct edit_publication_state *state = NULL; | ||
829 | |||
830 | builder = GTK_BUILDER (user_data); | ||
831 | |||
832 | pubwindow = gtk_builder_get_object (builder, | ||
833 | "GNUNET_GTK_edit_publication_window"); | ||
834 | state = g_object_get_data (pubwindow, PUBSTATE); | ||
835 | if (!state) | ||
836 | { | ||
837 | GNUNET_break (0); | ||
838 | return; | ||
839 | } | ||
840 | |||
841 | state->cb (state->cls, state->do_index, state->short_fn, | ||
842 | state->anonymity_level, state->priority, NULL, state->fip, GTK_RESPONSE_CANCEL); | ||
843 | g_free (state); | ||
844 | g_object_set_data (pubwindow, PUBSTATE, NULL); | ||
845 | gtk_widget_hide (GTK_WIDGET (pubwindow)); | ||
846 | } | ||
847 | |||
848 | void | ||
849 | GNUNET_GTK_edit_publication_confirm_button_clicked_cb ( | ||
850 | GtkButton *button, gpointer user_data) | ||
851 | { | ||
852 | GtkBuilder *builder; | ||
853 | GObject *pubwindow; | ||
854 | struct edit_publication_state *state = NULL; | ||
855 | struct fiu_context ctx; | ||
856 | |||
857 | builder = GTK_BUILDER (user_data); | ||
858 | |||
859 | pubwindow = gtk_builder_get_object (builder, | ||
860 | "GNUNET_GTK_edit_publication_window"); | ||
861 | state = g_object_get_data (pubwindow, PUBSTATE); | ||
862 | if (!state) | ||
863 | { | ||
864 | GNUNET_break (0); | ||
865 | return; | ||
866 | } | ||
867 | |||
868 | ctx.builder = builder; | ||
869 | ctx.short_fn = state->short_fn; | ||
870 | ctx.root = NULL; | ||
871 | ctx.md = NULL; | ||
872 | |||
873 | GNUNET_FS_file_information_inspect (state->fip, &file_information_update, &ctx); | ||
874 | if (!GNUNET_GTK_get_selected_anonymity_level (builder, | ||
875 | "GNUNET_GTK_edit_publication_anonymity_combobox", state->anonymity_level)) | ||
876 | *state->priority = | ||
877 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | ||
878 | (gtk_builder_get_object | ||
879 | (builder, | ||
880 | "GNUNET_GTK_edit_publication_priority_spin_button"))); | ||
881 | *state->do_index = | ||
882 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON | ||
883 | (gtk_builder_get_object | ||
884 | (builder, | ||
885 | "GNUNET_GTK_edit_publication_index_checkbutton"))); | ||
886 | |||
887 | |||
888 | state->cb (state->cls, state->do_index, state->short_fn, | ||
889 | state->anonymity_level, state->priority, ctx.root, state->fip, | ||
890 | GTK_RESPONSE_OK); | ||
891 | g_free (state); | ||
892 | g_object_set_data (pubwindow, PUBSTATE, NULL); | ||
893 | gtk_widget_hide (GTK_WIDGET (pubwindow)); | ||
894 | } | ||
666 | 895 | ||
667 | /** | 896 | /** |
668 | * Open the dialog to edit file information data. | 897 | * Add each of the keywords to the keyword list store. |
898 | * | ||
899 | * @param cls closure | ||
900 | * @param keyword the keyword | ||
901 | * @param is_mandatory is the keyword mandatory (in a search) | ||
902 | * @return GNUNET_OK to continue to iterate | ||
669 | */ | 903 | */ |
670 | void | 904 | static int |
671 | GNUNET_FS_GTK_edit_publish_dialog (int *do_index, char **short_fn, | 905 | add_keyword (void *cls, const char *keyword, int is_mandatory) |
672 | guint * anonymity_level, guint * priority, | ||
673 | struct GNUNET_FS_FileInformation *fip) | ||
674 | { | 906 | { |
675 | GtkWidget *ad; | ||
676 | GtkListStore *ls; | 907 | GtkListStore *ls; |
677 | GtkTreeIter iter; | 908 | GtkTreeIter iter; |
678 | guint type; | ||
679 | guint max_type; | ||
680 | GtkTreeView *tv; | ||
681 | GtkTreeSelection *sel; | ||
682 | 909 | ||
683 | GNUNET_assert (builder == NULL); | 910 | ls = GTK_LIST_STORE (cls); |
684 | builder = | 911 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, keyword, 1, FALSE, -1); |
685 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_edit_dialog.glade"); | 912 | return GNUNET_OK; |
686 | if (builder == NULL) | 913 | } |
914 | |||
915 | /** | ||
916 | * Function called to extract the information from FI. | ||
917 | * | ||
918 | * @param cls closure | ||
919 | * @param fi the entry in the publish-structure | ||
920 | * @param length length of the file or directory | ||
921 | * @param meta metadata for the file or directory (can be modified) | ||
922 | * @param uri pointer to the keywords that will be used for this entry (can be modified) | ||
923 | * @param bo block options | ||
924 | * @param do_index should we index (can be modified) | ||
925 | * @param client_info pointer to client context set upon creation (can be modified) | ||
926 | * @return GNUNET_SYSERR (aborts after first call) | ||
927 | */ | ||
928 | static int | ||
929 | file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi, | ||
930 | uint64_t length, | ||
931 | struct GNUNET_CONTAINER_MetaData *meta, | ||
932 | struct GNUNET_FS_Uri **uri, | ||
933 | struct GNUNET_FS_BlockOptions *bo, int *do_index, | ||
934 | void **client_info) | ||
935 | { | ||
936 | GtkBuilder *builder = GTK_BUILDER (cls); | ||
937 | GtkImage *img; | ||
938 | GdkPixbuf *pixbuf; | ||
939 | struct tm *t; | ||
940 | int year; | ||
941 | time_t tp; | ||
942 | GtkListStore *ls; | ||
943 | |||
944 | ls = GTK_LIST_STORE (gtk_builder_get_object | ||
945 | (builder, "GNUNET_GTK_publication_keywords_liststore")); | ||
946 | |||
947 | if (NULL != *uri) | ||
948 | GNUNET_FS_uri_ksk_get_keywords (*uri, &add_keyword, ls); | ||
949 | if (NULL != meta) | ||
687 | { | 950 | { |
688 | GNUNET_break (0); | 951 | ls = GTK_LIST_STORE (gtk_builder_get_object (builder, |
689 | return; | 952 | "GNUNET_GTK_publication_metadata_liststore")); |
953 | GNUNET_CONTAINER_meta_data_iterate (meta, &GNUNET_FS_GTK_add_meta_data_to_list_store, ls); | ||
954 | pixbuf = GNUNET_FS_GTK_get_thumbnail_from_meta_data (meta); | ||
955 | if (pixbuf != NULL) | ||
956 | { | ||
957 | img = | ||
958 | GTK_IMAGE (gtk_builder_get_object | ||
959 | (builder, | ||
960 | "GNUNET_GTK_publication_metadata_preview_image")); | ||
961 | gtk_image_set_from_pixbuf (img, pixbuf); | ||
962 | } | ||
690 | } | 963 | } |
691 | preview_changed = GNUNET_NO; | 964 | tp = bo->expiration_time.abs_value / 1000; /* ms to seconds */ |
965 | t = gmtime (&tp); | ||
966 | if (t == NULL) | ||
967 | year = 0; | ||
968 | else | ||
969 | year = t->tm_year + 1900; | ||
970 | gtk_spin_button_set_value (GTK_SPIN_BUTTON | ||
971 | (gtk_builder_get_object | ||
972 | (builder, | ||
973 | "GNUNET_GTK_edit_publication_expiration_year_spin_button")), | ||
974 | year); | ||
975 | GNUNET_GTK_select_anonymity_level (builder, | ||
976 | "GNUNET_GTK_edit_publication_anonymity_combobox", bo->anonymity_level); | ||
977 | gtk_spin_button_set_value (GTK_SPIN_BUTTON | ||
978 | (gtk_builder_get_object | ||
979 | (builder, | ||
980 | "GNUNET_GTK_edit_publication_priority_spin_button")), | ||
981 | bo->content_priority); | ||
982 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON | ||
983 | (gtk_builder_get_object | ||
984 | (builder, | ||
985 | "GNUNET_GTK_edit_publication_index_checkbutton")), | ||
986 | *do_index); | ||
987 | return GNUNET_SYSERR; /* only visit top-level item */ | ||
988 | } | ||
989 | |||
990 | |||
991 | /** | ||
992 | * Open the dialog to edit file information data. | ||
993 | */ | ||
994 | void | ||
995 | GNUNET_FS_GTK_edit_publish_dialog (GtkBuilder *builder, GtkWindow *parent, int *do_index, | ||
996 | char **short_fn, guint *anonymity_level, guint *priority, | ||
997 | struct GNUNET_FS_FileInformation *fip, gboolean allow_no_keywords, | ||
998 | GNUNET_FS_GTK_edit_publish_dialog_cb cb, gpointer cls) | ||
999 | { | ||
1000 | GtkWidget *dialog; | ||
1001 | GObject *pubwindow; | ||
1002 | GtkEntry *entry; | ||
1003 | GtkWidget *ok; | ||
1004 | struct edit_publication_state *state; | ||
1005 | |||
692 | GNUNET_FS_GTK_setup_expiration_year_adjustment (builder); | 1006 | GNUNET_FS_GTK_setup_expiration_year_adjustment (builder); |
693 | if (GNUNET_FS_file_information_is_directory (fip)) | 1007 | if (GNUNET_FS_file_information_is_directory (fip)) |
694 | { | 1008 | { |
@@ -696,80 +1010,60 @@ GNUNET_FS_GTK_edit_publish_dialog (int *do_index, char **short_fn, | |||
696 | gtk_widget_hide (GTK_WIDGET | 1010 | gtk_widget_hide (GTK_WIDGET |
697 | (gtk_builder_get_object | 1011 | (gtk_builder_get_object |
698 | (builder, | 1012 | (builder, |
699 | "GNUNET_GTK_edit_file_information_index_check_button"))); | 1013 | "GNUNET_GTK_edit_publication_index_checkbutton"))); |
700 | gtk_widget_hide (GTK_WIDGET | 1014 | gtk_widget_hide (GTK_WIDGET |
701 | (gtk_builder_get_object | 1015 | (gtk_builder_get_object |
702 | (builder, | 1016 | (builder, |
703 | "GNUNET_GTK_edit_file_information_index_label"))); | 1017 | "GNUNET_GTK_edit_publication_index_label"))); |
704 | |||
705 | } | 1018 | } |
706 | 1019 | if (allow_no_keywords) | |
707 | ad = GTK_WIDGET (gtk_builder_get_object | ||
708 | (builder, "GNUNET_GTK_edit_file_information_dialog")); | ||
709 | ls = GTK_LIST_STORE (gtk_builder_get_object | ||
710 | (builder, "GNUNET_GTK_metatype_list_store")); | ||
711 | max_type = EXTRACTOR_metatype_get_max (); | ||
712 | type = 1; | ||
713 | while (type < max_type - 1) | ||
714 | { | 1020 | { |
715 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, | 1021 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (builder, |
716 | EXTRACTOR_metatype_to_string (type), 1, | 1022 | "GNUNET_GTK_edit_publication_root_entry"))); |
717 | type, 2, | 1023 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (builder, |
718 | EXTRACTOR_metatype_to_description (type), | 1024 | "GNUNET_GTK_edit_publication_root_label"))); |
719 | -1); | ||
720 | type++; | ||
721 | } | 1025 | } |
1026 | gtk_list_store_clear (GTK_LIST_STORE (gtk_builder_get_object ( | ||
1027 | builder, "GNUNET_GTK_publication_keywords_liststore"))); | ||
1028 | gtk_list_store_clear (GTK_LIST_STORE (gtk_builder_get_object ( | ||
1029 | builder, "GNUNET_GTK_publication_metadata_liststore"))); | ||
1030 | |||
1031 | GNUNET_FS_file_information_inspect (fip, &file_information_extract, builder); | ||
1032 | |||
1033 | dialog = GTK_WIDGET (gtk_builder_get_object (builder, | ||
1034 | "GNUNET_GTK_edit_publication_window")); | ||
1035 | |||
1036 | gtk_window_set_title (GTK_WINDOW (dialog), *short_fn); | ||
1037 | |||
1038 | state = g_new0 (struct edit_publication_state, 1); | ||
1039 | state->do_index = do_index; | ||
1040 | state->short_fn = short_fn; | ||
1041 | state->root = NULL; | ||
1042 | state->anonymity_level = anonymity_level; | ||
1043 | state->priority = priority; | ||
1044 | state->fip = fip; | ||
1045 | state->preview_changed = GNUNET_NO; | ||
1046 | state->allow_no_keywords = allow_no_keywords; | ||
1047 | state->is_directory = GNUNET_FS_file_information_is_directory (fip); | ||
1048 | state->cb = cb; | ||
1049 | state->cls = cls; | ||
722 | 1050 | ||
723 | GNUNET_FS_file_information_inspect (fip, &file_information_extract, NULL); | 1051 | entry = |
724 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 1052 | GTK_ENTRY (gtk_builder_get_object |
725 | (builder, | 1053 | (builder, "GNUNET_GTK_edit_publication_keyword_entry")); |
726 | "GNUNET_GTK_edit_file_information_metadata_type_tree_view")); | 1054 | gtk_entry_set_text (entry, ""); |
727 | sel = gtk_tree_view_get_selection (tv); | ||
728 | g_signal_connect (G_OBJECT (sel), "changed", | ||
729 | G_CALLBACK | ||
730 | (GNUNET_GTK_edit_file_information_metadata_value_entry_changed_cb), | ||
731 | NULL); | ||
732 | 1055 | ||
733 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 1056 | pubwindow = gtk_builder_get_object (builder, |
734 | (builder, | 1057 | "GNUNET_GTK_edit_publication_window"); |
735 | "GNUNET_GTK_edit_file_information_metadata_tree_view")); | 1058 | g_object_set_data (pubwindow, PUBSTATE, state); |
736 | sel = gtk_tree_view_get_selection (tv); | ||
737 | g_signal_connect (G_OBJECT (sel), "changed", | ||
738 | G_CALLBACK (metadata_selection_changed_cb), NULL); | ||
739 | 1059 | ||
740 | tv = GTK_TREE_VIEW (gtk_builder_get_object | 1060 | ok = GTK_WIDGET (gtk_builder_get_object (builder, |
741 | (builder, | 1061 | "GNUNET_GTK_edit_publication_confirm_button")); |
742 | "GNUNET_GTK_edit_file_information_keyword_list_tree_view")); | 1062 | gtk_widget_set_sensitive (ok, allow_no_keywords ? TRUE : FALSE); |
743 | sel = gtk_tree_view_get_selection (tv); | 1063 | |
744 | g_signal_connect (G_OBJECT (sel), "changed", | 1064 | gtk_window_set_transient_for (GTK_WINDOW (pubwindow), parent); |
745 | G_CALLBACK (keyword_selection_changed_cb), NULL); | 1065 | |
746 | gtk_window_set_title (GTK_WINDOW (ad), *short_fn); | 1066 | gtk_window_present (GTK_WINDOW (dialog)); |
747 | if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) | ||
748 | { | ||
749 | gtk_widget_destroy (ad); | ||
750 | g_object_unref (G_OBJECT (builder)); | ||
751 | builder = NULL; | ||
752 | return; | ||
753 | } | ||
754 | GNUNET_FS_file_information_inspect (fip, &file_information_update, short_fn); | ||
755 | *anonymity_level = | ||
756 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | ||
757 | (gtk_builder_get_object | ||
758 | (builder, | ||
759 | "GNUNET_GTK_edit_file_information_anonymity_spin_button"))); | ||
760 | *priority = | ||
761 | gtk_spin_button_get_value (GTK_SPIN_BUTTON | ||
762 | (gtk_builder_get_object | ||
763 | (builder, | ||
764 | "GNUNET_GTK_edit_file_information_priority_spin_button"))); | ||
765 | *do_index = | ||
766 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON | ||
767 | (gtk_builder_get_object | ||
768 | (builder, | ||
769 | "GNUNET_GTK_edit_file_information_index_check_button"))); | ||
770 | gtk_widget_destroy (ad); | ||
771 | g_object_unref (G_OBJECT (builder)); | ||
772 | builder = NULL; | ||
773 | } | 1067 | } |
774 | 1068 | ||
775 | /* end of gnunet-fs-gtk-edit_publish_dialog.c */ | 1069 | /* end of gnunet-fs-gtk-edit_publish_dialog.c */ |