aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-01 21:47:49 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-01 21:47:49 +0000
commit611f99639c81c4f119f3e14d29cfc8deedabdef2 (patch)
tree70113d9a279b617c9f47c7bd2f04747287f3a0bd
parent432949612a8eead5074c74507900a129becfc414 (diff)
downloadgnunet-gtk-611f99639c81c4f119f3e14d29cfc8deedabdef2.tar.gz
gnunet-gtk-611f99639c81c4f119f3e14d29cfc8deedabdef2.zip
-more documentation and code simplification
-rw-r--r--src/fs/gnunet-fs-gtk-common.h2
-rw-r--r--src/fs/gnunet-fs-gtk-edit_publish_dialog.c347
2 files changed, 227 insertions, 122 deletions
diff --git a/src/fs/gnunet-fs-gtk-common.h b/src/fs/gnunet-fs-gtk-common.h
index 1c9b0392..3d7f9f7b 100644
--- a/src/fs/gnunet-fs-gtk-common.h
+++ b/src/fs/gnunet-fs-gtk-common.h
@@ -42,7 +42,6 @@ GNUNET_FS_GTK_get_thumbnail_from_meta_data (const struct
42 GNUNET_CONTAINER_MetaData *meta); 42 GNUNET_CONTAINER_MetaData *meta);
43 43
44 44
45
46/** 45/**
47 * Initialize the 'expiration_year_adjustment' of the given 46 * Initialize the 'expiration_year_adjustment' of the given
48 * builder to have a lower range of current-year+1 and a 47 * builder to have a lower range of current-year+1 and a
@@ -104,6 +103,7 @@ GNUNET_FS_GTK_add_meta_data_to_list_store (void *cls, const char *plugin_name,
104 const char *data_mime_type, 103 const char *data_mime_type,
105 const char *data, size_t data_len); 104 const char *data, size_t data_len);
106 105
106
107/** 107/**
108 * Converts metadata specified by @data of size @data_len 108 * Converts metadata specified by @data of size @data_len
109 * and saved in format @format to UTF-8 encoded string. 109 * and saved in format @format to UTF-8 encoded string.
diff --git a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
index f125788b..6f8f907a 100644
--- a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
+++ b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c
@@ -197,48 +197,63 @@ free_edit_dialog_context (struct EditPublicationDialogContext *ctx)
197{ 197{
198 gtk_widget_destroy (GTK_WIDGET (ctx->edit_publication_window)); 198 gtk_widget_destroy (GTK_WIDGET (ctx->edit_publication_window));
199 GNUNET_free_non_null (ctx->short_fn); 199 GNUNET_free_non_null (ctx->short_fn);
200 // FIXME: destroy builder! 200 // FIXME-LEAK: destroy builder!
201 GNUNET_free (ctx); 201 GNUNET_free (ctx);
202} 202}
203 203
204 204
205
206/* ****************** metadata editing ******************** */
207
208
209
210/**
211 * Update the set of metatypes listed in the dialog based on the
212 * given code.
213 *
214 * @param ctx main dialog context
215 * @param code which set of metatypes is desired?
216 */
205static void 217static void
206change_metatypes (struct EditPublicationDialogContext *ctx, gint code) 218change_metatypes (struct EditPublicationDialogContext *ctx, gint code)
207{ 219{
208 gint pub_type = 0, i; 220 gint pubtype_count;
209 gint pubtype_count = 0;
210 gint max_type; 221 gint max_type;
222 gint i;
211 GtkTreeIter iter; 223 GtkTreeIter iter;
212 224
213 for (pub_type = 0; types[pub_type] != NULL; pub_type++) 225 /* double-check that 'code' is valid */
214 pubtype_count += 1; 226 for (pubtype_count = 0; NULL != types[pubtype_count]; pubtype_count++) ;
215 227 GNUNET_assert (code < pubtype_count);
216 if (code < pubtype_count) 228
217 pub_type = code; 229 /* clear existing selection of metatypes */
218 else
219 pub_type = 0;
220
221 gtk_list_store_clear (ctx->metatypes_liststore); 230 gtk_list_store_clear (ctx->metatypes_liststore);
222 max_type = EXTRACTOR_metatype_get_max (); 231 max_type = EXTRACTOR_metatype_get_max ();
223 for (i = 0; types[pub_type][i] != EXTRACTOR_METATYPE_RESERVED; i++) 232 /* add new types based on selection */
224 { 233 for (i = 0; types[code][i] != EXTRACTOR_METATYPE_RESERVED; i++)
225 if (types[pub_type][i] < max_type && types[pub_type][i] > 0) 234 if ( (types[code][i] < max_type) && (types[code][i] > 0) )
226 gtk_list_store_insert_with_values (ctx->metatypes_liststore, &iter, G_MAXINT, 0, 235 gtk_list_store_insert_with_values (ctx->metatypes_liststore,
227 types[pub_type][i], 1, 236 &iter, G_MAXINT,
228 EXTRACTOR_METAFORMAT_UTF8, 2, 237 0, types[code][i],
229 EXTRACTOR_metatype_to_string (types 238 1, EXTRACTOR_METAFORMAT_UTF8,
230 [pub_type] 239 2, EXTRACTOR_metatype_to_string (types [code][i]),
231 [i]), 3, 240 3, EXTRACTOR_metatype_to_description (types[code][i]),
232 EXTRACTOR_metatype_to_description 241 -1);
233 (types[pub_type][i]), -1);
234 }
235} 242}
236 243
237 244
245/**
246 * The user has selected a different publication type.
247 * Update the meta type selection.
248 *
249 * @param widget the publication type combo box widget
250 * @param user_data the 'struct EditPublicationDialogContext'
251 */
238void 252void
239GNUNET_GTK_edit_publication_type_combo_changed_cb (GtkComboBox * widget, 253GNUNET_GTK_edit_publication_type_combo_changed_cb (GtkComboBox * widget,
240 struct EditPublicationDialogContext *ctx) 254 gpointer user_data)
241{ 255{
256 struct EditPublicationDialogContext *ctx = user_data;
242 GtkTreeIter iter; 257 GtkTreeIter iter;
243 gint code; 258 gint code;
244 259
@@ -249,61 +264,34 @@ GNUNET_GTK_edit_publication_type_combo_changed_cb (GtkComboBox * widget,
249} 264}
250 265
251 266
267/**
268 * The user has changed the selection in the meta data tree view.
269 * Update the sensitivity of the 'delete' button.
270 *
271 * @param ts the tree selection object
272 * @param user_data the 'struct EditPublicationDialogContext'
273 */
274/* FIXME: connect this signal via glade (modern versions of Glade support this) */
252static void 275static void
253metadata_selection_changed_cb (GtkTreeSelection *ts, struct EditPublicationDialogContext *ctx) 276metadata_selection_changed_cb (GtkTreeSelection *ts,
277 gpointer user_data)
254{ 278{
255 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object 279 struct EditPublicationDialogContext *ctx = user_data;
256 (ctx->builder, "GNUNET_GTK_edit_publication_delete_button")),
257 gtk_tree_selection_get_selected (ts, NULL, NULL));
258}
259 280
260
261static void
262keywords_selection_changed_cb (GtkTreeSelection *ts, struct EditPublicationDialogContext *ctx)
263{
264 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object 281 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object
265 (ctx->builder, 282 (ctx->builder,
266 "GNUNET_GTK_edit_publication_keyword_list_del_button")), 283 "GNUNET_GTK_edit_publication_delete_button")),
267 gtk_tree_selection_get_selected (ts, NULL, NULL)); 284 gtk_tree_selection_get_selected (ts, NULL, NULL));
268} 285}
269 286
270 287
271void 288void
272GNUNET_GTK_edit_publication_add_button_clicked_cb (GtkButton * button, 289GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb (GtkCellRendererText * renderer,
273 struct EditPublicationDialogContext *ctx) 290 gchar * path,
274{ 291 gchar * new_text,
275 GtkTreeIter iter; 292 gpointer user_data)
276
277 gtk_list_store_insert (ctx->meta_liststore, &iter, 0);
278 /* type == 0 means "not set" */
279 gtk_list_store_set (ctx->meta_liststore, &iter, 0, 0, 1, EXTRACTOR_METAFORMAT_UTF8, 2,
280 _("Select a type"), 3, _("Specify a value"), 4, NULL, -1);
281}
282
283
284gboolean
285GNUNET_GTK_edit_publication_keyword_entry_key_press_event_cb (GtkWidget *
286 widget,
287 GdkEventKey *
288 event,
289 struct EditPublicationDialogContext *ctx)
290{
291 if (event->keyval == GDK_KEY_Return)
292 {
293 GNUNET_GTK_edit_publication_add_button_clicked_cb (GTK_BUTTON (gtk_builder_get_object (ctx->builder,
294 "GNUNET_GTK_edit_publication_keyword_list_add_button")),
295
296 ctx);
297 return TRUE;
298 }
299 return FALSE;
300}
301
302
303void GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb
304 (GtkCellRendererText * renderer, gchar * path, gchar * new_text,
305 struct EditPublicationDialogContext *ctx)
306{ 293{
294 struct EditPublicationDialogContext *ctx = user_data;
307 GtkTreeModel *combo_model; 295 GtkTreeModel *combo_model;
308 GtkTreeIter iter; 296 GtkTreeIter iter;
309 gint type_id; 297 gint type_id;
@@ -331,10 +319,13 @@ void GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_edited_cb
331} 319}
332 320
333 321
334void GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb 322void
335 (GtkCellRendererCombo * combo, gchar * path_string, GtkTreeIter * new_iter, 323GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb (GtkCellRendererCombo * combo,
336 struct EditPublicationDialogContext *ctx) 324 gchar * path_string,
325 GtkTreeIter * new_iter,
326 gpointer user_data)
337{ 327{
328 struct EditPublicationDialogContext *ctx = user_data;
338 if (ctx->meta_combo_selected_iter) 329 if (ctx->meta_combo_selected_iter)
339 g_free (ctx->meta_combo_selected_iter); 330 g_free (ctx->meta_combo_selected_iter);
340 ctx->meta_combo_selected_iter = g_new0 (GtkTreeIter, 1); 331 ctx->meta_combo_selected_iter = g_new0 (GtkTreeIter, 1);
@@ -342,10 +333,13 @@ void GNUNET_GTK_edit_publication_metadata_tree_view_type_renderer_changed_cb
342} 333}
343 334
344 335
345void GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb 336void
346 (GtkCellRendererText * renderer, gchar * path, gchar * new_text, 337GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb (GtkCellRendererText * renderer,
347 struct EditPublicationDialogContext *ctx) 338 gchar * path,
339 gchar * new_text,
340 gpointer user_data)
348{ 341{
342 struct EditPublicationDialogContext *ctx = user_data;
349 GtkTreeIter iter; 343 GtkTreeIter iter;
350 gint metatype; 344 gint metatype;
351 char *avalue; 345 char *avalue;
@@ -392,10 +386,44 @@ void GNUNET_GTK_edit_publication_metadata_tree_view_value_renderer_edited_cb
392} 386}
393 387
394 388
389
390/**
391 * The user has pushed the 'add' button for metadata. Add a 'dummy' value
392 * to our meta data store (to be edited by the user).
393 *
394 * @param button the 'add' button
395 * @param user_data the 'struct EditPublicationDialogContext'
396 */
397void
398GNUNET_GTK_edit_publication_add_button_clicked_cb (GtkButton * button,
399 gpointer user_data)
400{
401 struct EditPublicationDialogContext *ctx = user_data;
402 GtkTreeIter iter;
403
404 gtk_list_store_insert_with_values (ctx->meta_liststore,
405 &iter, 0,
406 0, 0,
407 1, EXTRACTOR_METAFORMAT_UTF8,
408 2, _("Select a type"),
409 3, _("Specify a value"),
410 4, NULL,
411 -1);
412}
413
414
415/**
416 * The user has pushed the 'del' button for metadata.
417 * If there is a metadata selected, remove it from the list store.
418 *
419 * @param widget the button
420 * @param user_data the 'struct EditPublicationDialogContext'
421 */
395void 422void
396GNUNET_GTK_edit_publication_delete_button_clicked_cb (GtkButton * button, 423GNUNET_GTK_edit_publication_delete_button_clicked_cb (GtkButton * button,
397 struct EditPublicationDialogContext *ctx) 424 gpointer user_data)
398{ 425{
426 struct EditPublicationDialogContext *ctx = user_data;
399 GtkTreeIter iter; 427 GtkTreeIter iter;
400 GtkTreeSelection *meta_selection; 428 GtkTreeSelection *meta_selection;
401 429
@@ -405,99 +433,172 @@ GNUNET_GTK_edit_publication_delete_button_clicked_cb (GtkButton * button,
405 GNUNET_break (0); 433 GNUNET_break (0);
406 return; 434 return;
407 } 435 }
408 if (gtk_list_store_remove (ctx->meta_liststore, &iter)) 436 GNUNET_break (gtk_list_store_remove (ctx->meta_liststore, &iter));
409 gtk_tree_selection_select_iter (meta_selection, &iter); 437 gtk_tree_selection_select_iter (meta_selection, &iter);
410} 438}
411 439
412 440
441/**
442 * The user has selected another preview image file. Update the
443 * preview image.
444 *
445 * @param widget the file chooser dialog that completed
446 * @param user_data the 'struct EditPublicationDialogContext'
447 */
413void 448void
414GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb (GtkButton * 449GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button_file_set_cb (GtkFileChooserButton * widget,
415 button, 450 gpointer user_data)
416 struct EditPublicationDialogContext *ctx)
417{ 451{
418 const char *keyword; 452 struct EditPublicationDialogContext *ctx = user_data;
419 GtkTreeIter iter; 453 gchar *fn;
420 454
421 keyword = gtk_entry_get_text (ctx->keyword_entry); 455 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
422 if (strlen (keyword) > 0) 456 gtk_image_set_from_file (ctx->preview_image, fn);
423 { 457 g_free (fn);
424 gtk_list_store_insert_with_values (ctx->keywords_liststore, &iter, G_MAXINT, 0, keyword, 1, TRUE, 458 ctx->preview_changed = GNUNET_YES;
425 -1);
426 gtk_widget_set_sensitive (ctx->confirm_button, TRUE);
427 }
428 gtk_entry_set_text (ctx->keyword_entry, "");
429} 459}
430 460
431 461
432static gboolean 462/* ****************** keyword list editing ******************** */
433gtk_tree_model_has_items_cb (GtkTreeModel * model, GtkTreePath * path,
434 GtkTreeIter * iter, gpointer data)
435{
436 gboolean *val = (gboolean *) data;
437 463
438 *val = TRUE;
439 return TRUE;
440}
441 464
442 465
443static gboolean 466/**
444gtk_tree_model_has_items (GtkTreeModel * model) 467 * The user has changed the selection in the keyword tree view.
468 * Update the sensitivity of the 'delete' button.
469 *
470 * @param ts the tree selection object
471 * @param user_data the 'struct EditPublicationDialogContext'
472 */
473/* FIXME: connect this signal via glade (modern versions of Glade support this) */
474static void
475keywords_selection_changed_cb (GtkTreeSelection *ts,
476 gpointer user_data)
445{ 477{
446 gboolean b = FALSE; 478 struct EditPublicationDialogContext *ctx = user_data;
447 479
448 gtk_tree_model_foreach (model, &gtk_tree_model_has_items_cb, &b); 480 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object
449 return b; 481 (ctx->builder,
482 "GNUNET_GTK_edit_publication_keyword_list_del_button")),
483 gtk_tree_selection_get_selected (ts, NULL, NULL));
450} 484}
451 485
452 486
487/**
488 * The user has edited the keyword entry line. Update the
489 * sensitivity of the 'add' button.
490 *
491 * @param editable the entry line for keywords
492 * @param user_data the 'struct EditPublicationDialogContext'
493 */
453void 494void
454GNUNET_GTK_edit_publication_keyword_entry_changed_cb (GtkEditable * editable, 495GNUNET_GTK_edit_publication_keyword_entry_changed_cb (GtkEditable * editable,
455 struct EditPublicationDialogContext *ctx) 496 gpointer user_data)
456{ 497{
498 struct EditPublicationDialogContext *ctx = user_data;
457 const char *keyword; 499 const char *keyword;
458 500
459 keyword = gtk_entry_get_text (ctx->keyword_entry); 501 keyword = gtk_entry_get_text (ctx->keyword_entry);
460 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (ctx->builder, 502 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (ctx->builder,
461 "GNUNET_GTK_edit_publication_keyword_list_add_button")), 503 "GNUNET_GTK_edit_publication_keyword_list_add_button")),
462 (strlen (keyword) > 0) ? TRUE : FALSE); 504 (strlen (keyword) > 0) ? TRUE : FALSE);
463} 505}
464 506
465 507
508/**
509 * The user has pushed the 'del' button for the keyword.
510 * If there is a keyword selected, remove it from the list store.
511 *
512 * @param widget the button
513 * @param user_data the 'struct EditPublicationDialogContext'
514 */
466void 515void
467GNUNET_GTK_edit_publication_keyword_list_del_button_clicked_cb (GtkButton * 516GNUNET_GTK_edit_publication_keyword_list_del_button_clicked_cb (GtkButton *
468 button, 517 button,
469 struct EditPublicationDialogContext *ctx) 518 gpointer user_data)
470{ 519{
520 struct EditPublicationDialogContext *ctx = user_data;
471 GtkTreeIter iter; 521 GtkTreeIter iter;
472 GtkTreeSelection *keywords_selection; 522 GtkTreeSelection *keywords_selection;
473 523
474 keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview); 524 keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview);
475 525 if (! gtk_tree_selection_get_selected (keywords_selection, NULL, &iter))
476 if (TRUE != gtk_tree_selection_get_selected (keywords_selection, NULL, &iter))
477 { 526 {
478 GNUNET_break (0); 527 GNUNET_break (0);
479 return; 528 return;
480 } 529 }
481 if (gtk_list_store_remove (GTK_LIST_STORE (ctx->keywords_liststore), &iter)) 530 GNUNET_break (gtk_list_store_remove (GTK_LIST_STORE (ctx->keywords_liststore), &iter));
482 gtk_tree_selection_select_iter (keywords_selection, &iter); 531 gtk_tree_selection_select_iter (keywords_selection, &iter);
483 532
484 if (!ctx->allow_no_keywords && !gtk_tree_model_has_items (GTK_TREE_MODEL (ctx->keywords_liststore))) 533 /* disable confirm button if keywords are required and we have no more keywords */
534 if ( (! ctx->allow_no_keywords) &&
535 (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->keywords_liststore),
536 &iter)) )
485 gtk_widget_set_sensitive (ctx->confirm_button, FALSE); 537 gtk_widget_set_sensitive (ctx->confirm_button, FALSE);
486} 538}
487 539
488 540
489void GNUNET_GTK_edit_publication_metadata_preview_file_chooser_button_file_set_cb ( 541/**
490 GtkFileChooserButton * widget, struct EditPublicationDialogContext *ctx) 542 * The user has pushed the 'add' button for the keyword (or pressed RETURN).
543 * If there is a keyword in the line, add it to the list store.
544 *
545 * @param widget the entry line, or NULL (if we are called from 'RETURN')
546 * @param user_data the 'struct EditPublicationDialogContext'
547 */
548void
549GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb (GtkButton *
550 button,
551 gpointer user_data)
552{
553 struct EditPublicationDialogContext *ctx = user_data;
554 const char *keyword;
555 GtkTreeIter iter;
556
557 keyword = gtk_entry_get_text (ctx->keyword_entry);
558 if (strlen (keyword) == 0)
559 return;
560 gtk_list_store_insert_with_values (ctx->keywords_liststore,
561 &iter, G_MAXINT,
562 0, keyword,
563 1, TRUE,
564 -1);
565 gtk_widget_set_sensitive (ctx->confirm_button, TRUE);
566 gtk_entry_set_text (ctx->keyword_entry, "");
567}
568
569
570/**
571 * The user has pushed a button in the entry line. Check if it was 'RETURN'
572 * and if so consider executing the 'add' action.
573 *
574 * @param widget the entry line
575 * @param event the event information
576 * @param user_data the 'struct EditPublicationDialogContext'
577 */
578gboolean
579GNUNET_GTK_edit_publication_keyword_entry_key_press_event_cb (GtkWidget *
580 widget,
581 GdkEventKey *
582 event,
583 gpointer user_data)
491{ 584{
492 gchar *fn; 585 struct EditPublicationDialogContext *ctx = user_data;
493 586
494 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)); 587 if (event->keyval != GDK_KEY_Return)
495 gtk_image_set_from_file (ctx->preview_image, fn); 588 return FALSE;
496 g_free (fn); 589 GNUNET_GTK_edit_publication_keyword_list_add_button_clicked_cb (NULL, ctx);
497 ctx->preview_changed = GNUNET_YES; 590 return TRUE;
498} 591}
499 592
500 593
594/* ****************** handlers for closing the dialog ******************** */
595
596
597
598
599
600
601
501/** 602/**
502 * Copy binary meta data from to the new container and also 603 * Copy binary meta data from to the new container and also
503 * preserve all entries that were not changed. 604 * preserve all entries that were not changed.
@@ -752,6 +853,10 @@ GNUNET_GTK_edit_publication_window_delete_event_cb (GtkWidget * widget,
752 return TRUE; 853 return TRUE;
753} 854}
754 855
856
857/* ****************** code for initialization of the dialog ******************** */
858
859
755/** 860/**
756 * Add each of the keywords to the keyword list store. 861 * Add each of the keywords to the keyword list store.
757 * 862 *