aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-05 18:08:04 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-05 18:08:04 +0000
commit3bec617a3326452a32fbd132df017148cb96ea8e (patch)
tree4b1d6b7dcd622bed9fb1714a2470c7a44f2e8edb
parentcb41d92db22af9b231051612a73249d93203011d (diff)
downloadgnunet-gtk-3bec617a3326452a32fbd132df017148cb96ea8e.tar.gz
gnunet-gtk-3bec617a3326452a32fbd132df017148cb96ea8e.zip
-moving globals into struct for the menu shell
-rw-r--r--src/fs/gnunet-fs-gtk_event-handler.c136
1 files changed, 64 insertions, 72 deletions
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c
index 09d8b0c5..8bae5f0e 100644
--- a/src/fs/gnunet-fs-gtk_event-handler.c
+++ b/src/fs/gnunet-fs-gtk_event-handler.c
@@ -110,19 +110,6 @@ static struct SearchTab *uri_tab;
110 */ 110 */
111static struct PublishTab *publish_tab; 111static struct PublishTab *publish_tab;
112 112
113/**
114 * Row reference for the current search context menu.
115 * FIXME-UNCLEAN: de-globalize?
116 */
117static GtkTreeRowReference *current_context_row_reference;
118
119/**
120 * Search tab used for the current search context menu.
121 * FIXME-UNCLEAN: de-globalize?
122 */
123static struct SearchTab *current_context_search_tab;
124
125
126 113
127/* ***************** Search event handling ****************** */ 114/* ***************** Search event handling ****************** */
128 115
@@ -412,19 +399,43 @@ start_download (GtkTreeView *tree_view,
412 399
413 400
414/** 401/**
402 * Context for the search list popup menu.
403 */
404struct SearchListPopupContext
405{
406 /**
407 * Tab where the search list popup was created.
408 */
409 struct SearchTab *tab;
410
411 /**
412 * Row where the search list popup was created.
413 */
414 GtkTreeRowReference *rr;
415
416 /**
417 * Search result at the respective row.
418 */
419 struct SearchResult *sr;
420
421};
422
423
424/**
415 * An item was selected from the context menu; destroy the menu shell. 425 * An item was selected from the context menu; destroy the menu shell.
416 * 426 *
417 * @param menushell menu to destroy 427 * @param menushell menu to destroy
418 * @parma user_data the 'struct DownloadEntry' for the menu (unused) 428 * @param user_data the 'struct SearchListPopupContext' of the menu
419 */ 429 */
420static void 430static void
421search_list_popup_selection_done (GtkMenuShell *menushell, 431search_list_popup_selection_done (GtkMenuShell *menushell,
422 gpointer user_data) 432 gpointer user_data)
423{ 433{
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 434 struct SearchListPopupContext *spc = user_data;
425 "Item selected in menu shell %p, destroying it.\n", 435
426 menushell);
427 gtk_widget_destroy (GTK_WIDGET (menushell)); 436 gtk_widget_destroy (GTK_WIDGET (menushell));
437 gtk_tree_row_reference_free (spc->rr);
438 GNUNET_free (spc);
428} 439}
429 440
430 441
@@ -453,32 +464,26 @@ GNUNET_FS_GTK_search_treeview_row_activated (GtkTreeView * tree_view,
453/** 464/**
454 * "Download" was selected in the current search context menu. 465 * "Download" was selected in the current search context menu.
455 * 466 *
467 * @param spc the 'struct SearchListPopupContext' of the menu
456 * @param is_recursive was this the 'recursive' option? 468 * @param is_recursive was this the 'recursive' option?
457 * @parma save_as was this the 'save as' option? 469 * @parma save_as was this the 'save as' option?
458 */ 470 */
459static void 471static void
460start_download_ctx_menu_helper (int is_recursive, 472start_download_ctx_menu_helper (struct SearchListPopupContext *spc,
473 int is_recursive,
461 int save_as) 474 int save_as)
462{ 475{
463 GtkTreePath *path; 476 GtkTreePath *path;
464 GtkTreeView *tv; 477 GtkTreeView *tv;
465 478
466 if (current_context_row_reference == NULL) 479 path = gtk_tree_row_reference_get_path (spc->rr);
467 {
468 GNUNET_break (0);
469 return;
470 }
471 path = gtk_tree_row_reference_get_path (current_context_row_reference);
472 gtk_tree_row_reference_free (current_context_row_reference);
473 current_context_row_reference = NULL;
474 tv = GTK_TREE_VIEW (gtk_builder_get_object 480 tv = GTK_TREE_VIEW (gtk_builder_get_object
475 (current_context_search_tab->builder, 481 (spc->tab->builder,
476 "_search_result_frame")); 482 "_search_result_frame"));
477 start_download (tv, path, current_context_search_tab, 483 start_download (tv, path, spc->tab,
478 is_recursive, 484 is_recursive,
479 save_as); 485 save_as);
480 gtk_tree_path_free (path); 486 gtk_tree_path_free (path);
481 current_context_search_tab = NULL;
482} 487}
483 488
484 489
@@ -486,12 +491,14 @@ start_download_ctx_menu_helper (int is_recursive,
486 * "Download" was selected in the current search context menu. 491 * "Download" was selected in the current search context menu.
487 * 492 *
488 * @param item the 'download' menu item 493 * @param item the 'download' menu item
489 * @parma user_data FIXME 494 * @param user_data the 'struct SearchListPopupContext' of the menu
490 */ 495 */
491static void 496static void
492start_download_ctx_menu (GtkMenuItem *item, gpointer user_data) 497start_download_ctx_menu (GtkMenuItem *item, gpointer user_data)
493{ 498{
494 start_download_ctx_menu_helper (GNUNET_NO, GNUNET_NO); 499 struct SearchListPopupContext *spc = user_data;
500
501 start_download_ctx_menu_helper (spc, GNUNET_NO, GNUNET_NO);
495} 502}
496 503
497 504
@@ -499,12 +506,14 @@ start_download_ctx_menu (GtkMenuItem *item, gpointer user_data)
499 * "Download recursively" was selected in the current search context menu. 506 * "Download recursively" was selected in the current search context menu.
500 * 507 *
501 * @param item the 'download recursively' menu item 508 * @param item the 'download recursively' menu item
502 * @parma user_data FIXME 509 * @param user_data the 'struct SearchListPopupContext' of the menu
503 */ 510 */
504static void 511static void
505start_download_recursively_ctx_menu (GtkMenuItem *item, gpointer user_data) 512start_download_recursively_ctx_menu (GtkMenuItem *item, gpointer user_data)
506{ 513{
507 start_download_ctx_menu_helper (GNUNET_YES, GNUNET_NO); 514 struct SearchListPopupContext *spc = user_data;
515
516 start_download_ctx_menu_helper (spc, GNUNET_YES, GNUNET_NO);
508} 517}
509 518
510 519
@@ -512,12 +521,14 @@ start_download_recursively_ctx_menu (GtkMenuItem *item, gpointer user_data)
512 * "Download as..." was selected in the current search context menu. 521 * "Download as..." was selected in the current search context menu.
513 * 522 *
514 * @param item the 'download as...' menu item 523 * @param item the 'download as...' menu item
515 * @parma user_data FIXME 524 * @param user_data the 'struct SearchListPopupContext' of the menu
516 */ 525 */
517static void 526static void
518start_download_as_ctx_menu (GtkMenuItem *item, gpointer user_data) 527start_download_as_ctx_menu (GtkMenuItem *item, gpointer user_data)
519{ 528{
520 start_download_ctx_menu_helper (GNUNET_NO, GNUNET_YES); 529 struct SearchListPopupContext *spc = user_data;
530
531 start_download_ctx_menu_helper (spc, GNUNET_NO, GNUNET_YES);
521} 532}
522 533
523 534
@@ -525,19 +536,16 @@ start_download_as_ctx_menu (GtkMenuItem *item, gpointer user_data)
525 * Download "abort" was selected in the current search context menu. 536 * Download "abort" was selected in the current search context menu.
526 * 537 *
527 * @param item the 'abort' menu item 538 * @param item the 'abort' menu item
528 * @parma user_data the 'struct DownloadEntry' to abort. 539 * @parma user_data the 'struct SearchListPopupContext' with the download to abort.
529 */ 540 */
530static void 541static void
531abort_download_ctx_menu (GtkMenuItem *item, gpointer user_data) 542abort_download_ctx_menu (GtkMenuItem *item, gpointer user_data)
532{ 543{
533 struct DownloadEntry *de = user_data; 544 struct SearchListPopupContext *spc = user_data;
545 struct DownloadEntry *de = spc->sr->download;
534 546
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
536 "Aborting download DE=%p\n",
537 de);
538 GNUNET_assert (de->dc != NULL); 547 GNUNET_assert (de->dc != NULL);
539 GNUNET_FS_download_stop (de->dc, GNUNET_YES); 548 GNUNET_FS_download_stop (de->dc, GNUNET_YES);
540 current_context_search_tab = NULL;
541} 549}
542 550
543 551
@@ -546,10 +554,12 @@ abort_download_ctx_menu (GtkMenuItem *item, gpointer user_data)
546 * 554 *
547 * @param item the 'copy-to-clipboard' menu item 555 * @param item the 'copy-to-clipboard' menu item
548 * @parma user_data NULL 556 * @parma user_data NULL
557 * @parma user_data the 'struct SearchListPopupContext' of the menu
549 */ 558 */
550static void 559static void
551copy_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data) 560copy_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data)
552{ 561{
562 struct SearchListPopupContext *spc = user_data;
553 GtkTreePath *path; 563 GtkTreePath *path;
554 GtkTreeView *tv; 564 GtkTreeView *tv;
555 GtkTreeModel *tm; 565 GtkTreeModel *tm;
@@ -558,16 +568,9 @@ copy_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data)
558 char *uris; 568 char *uris;
559 GtkClipboard *cb; 569 GtkClipboard *cb;
560 570
561 if (NULL == current_context_row_reference) 571 path = gtk_tree_row_reference_get_path (spc->rr);
562 {
563 GNUNET_break (0);
564 return;
565 }
566 path = gtk_tree_row_reference_get_path (current_context_row_reference);
567 gtk_tree_row_reference_free (current_context_row_reference);
568 current_context_row_reference = NULL;
569 tv = GTK_TREE_VIEW (gtk_builder_get_object 572 tv = GTK_TREE_VIEW (gtk_builder_get_object
570 (current_context_search_tab->builder, 573 (spc->tab->builder,
571 "_search_result_frame")); 574 "_search_result_frame"));
572 tm = gtk_tree_view_get_model (tv); 575 tm = gtk_tree_view_get_model (tv);
573 if (! gtk_tree_model_get_iter (tm, &iter, path)) 576 if (! gtk_tree_model_get_iter (tm, &iter, path))
@@ -578,7 +581,6 @@ copy_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data)
578 } 581 }
579 gtk_tree_model_get (tm, &iter, 1, &uri, -1); 582 gtk_tree_model_get (tm, &iter, 1, &uri, -1);
580 gtk_tree_path_free (path); 583 gtk_tree_path_free (path);
581 current_context_search_tab = NULL;
582 if (uri == NULL) 584 if (uri == NULL)
583 { 585 {
584 GNUNET_break (0); 586 GNUNET_break (0);
@@ -615,27 +617,17 @@ search_list_popup (GtkTreeModel *tm,
615 GtkTreePath *path; 617 GtkTreePath *path;
616 struct SearchResult *sr; 618 struct SearchResult *sr;
617 struct GNUNET_FS_Uri *uri; 619 struct GNUNET_FS_Uri *uri;
620 struct SearchListPopupContext *spc;
618 621
619 /* FIXME-UNCLEAN: move these to some menu context struct 622 /* FIXME-UNCLEAN: move these to some menu context struct
620 (de-globalize) */ 623 (de-globalize) */
621 current_context_search_tab = tab; 624 spc = GNUNET_malloc (sizeof (struct SearchListPopupContext));
622 if (current_context_row_reference != NULL) 625 spc->tab = tab;
623 {
624 gtk_tree_row_reference_free (current_context_row_reference);
625 current_context_row_reference = NULL;
626 }
627 path = gtk_tree_model_get_path (tm, iter); 626 path = gtk_tree_model_get_path (tm, iter);
628 current_context_row_reference = gtk_tree_row_reference_new (tm, path); 627 spc->rr = gtk_tree_row_reference_new (tm, path);
629 gtk_tree_path_free (path); 628 gtk_tree_path_free (path);
630
631 gtk_tree_model_get (tm, iter, 1, &uri, 9, &sr, -1); 629 gtk_tree_model_get (tm, iter, 1, &uri, 9, &sr, -1);
632 /* FIXME-BUG: 'sr' can be NULL here, somehow some code fails to setup the record.. */ 630 spc->sr = sr;
633 if (NULL == sr)
634 {
635 /* FIXME-BUG: this prevents the crash for now, but does not solve the problem */
636 GNUNET_break (0);
637 return FALSE;
638 }
639 menu = GTK_MENU (gtk_menu_new ()); 631 menu = GTK_MENU (gtk_menu_new ());
640 if ( (NULL == sr->download) && 632 if ( (NULL == sr->download) &&
641 (NULL != uri) ) 633 (NULL != uri) )
@@ -643,7 +635,7 @@ search_list_popup (GtkTreeModel *tm,
643 /* only display download menus if there is a URI */ 635 /* only display download menus if there is a URI */
644 child = gtk_menu_item_new_with_label (_("_Download")); 636 child = gtk_menu_item_new_with_label (_("_Download"));
645 g_signal_connect (child, "activate", 637 g_signal_connect (child, "activate",
646 G_CALLBACK (start_download_ctx_menu), NULL); 638 G_CALLBACK (start_download_ctx_menu), spc);
647 gtk_label_set_use_underline (GTK_LABEL 639 gtk_label_set_use_underline (GTK_LABEL
648 (gtk_bin_get_child (GTK_BIN (child))), 640 (gtk_bin_get_child (GTK_BIN (child))),
649 TRUE); 641 TRUE);
@@ -652,7 +644,7 @@ search_list_popup (GtkTreeModel *tm,
652 644
653 child = gtk_menu_item_new_with_label (_("Download _recursively")); 645 child = gtk_menu_item_new_with_label (_("Download _recursively"));
654 g_signal_connect (child, "activate", 646 g_signal_connect (child, "activate",
655 G_CALLBACK (start_download_recursively_ctx_menu), NULL); 647 G_CALLBACK (start_download_recursively_ctx_menu), spc);
656 gtk_label_set_use_underline (GTK_LABEL 648 gtk_label_set_use_underline (GTK_LABEL
657 (gtk_bin_get_child (GTK_BIN (child))), 649 (gtk_bin_get_child (GTK_BIN (child))),
658 TRUE); 650 TRUE);
@@ -662,7 +654,7 @@ search_list_popup (GtkTreeModel *tm,
662 654
663 child = gtk_menu_item_new_with_label (_("Download _as...")); 655 child = gtk_menu_item_new_with_label (_("Download _as..."));
664 g_signal_connect (child, "activate", 656 g_signal_connect (child, "activate",
665 G_CALLBACK (start_download_as_ctx_menu), NULL); 657 G_CALLBACK (start_download_as_ctx_menu), spc);
666 gtk_label_set_use_underline (GTK_LABEL 658 gtk_label_set_use_underline (GTK_LABEL
667 (gtk_bin_get_child (GTK_BIN (child))), 659 (gtk_bin_get_child (GTK_BIN (child))),
668 TRUE); 660 TRUE);
@@ -674,7 +666,7 @@ search_list_popup (GtkTreeModel *tm,
674 { 666 {
675 child = gtk_menu_item_new_with_label (_("_Abort download")); 667 child = gtk_menu_item_new_with_label (_("_Abort download"));
676 g_signal_connect (child, "activate", 668 g_signal_connect (child, "activate",
677 G_CALLBACK (abort_download_ctx_menu), sr->download); 669 G_CALLBACK (abort_download_ctx_menu), spc);
678 gtk_label_set_use_underline (GTK_LABEL 670 gtk_label_set_use_underline (GTK_LABEL
679 (gtk_bin_get_child (GTK_BIN (child))), 671 (gtk_bin_get_child (GTK_BIN (child))),
680 TRUE); 672 TRUE);
@@ -685,13 +677,13 @@ search_list_popup (GtkTreeModel *tm,
685 { 677 {
686 child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); 678 child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard"));
687 g_signal_connect (child, "activate", 679 g_signal_connect (child, "activate",
688 G_CALLBACK (copy_uri_to_clipboard_ctx_menu), NULL); 680 G_CALLBACK (copy_uri_to_clipboard_ctx_menu), spc);
689 gtk_label_set_use_underline (GTK_LABEL 681 gtk_label_set_use_underline (GTK_LABEL
690 (gtk_bin_get_child (GTK_BIN (child))), TRUE); 682 (gtk_bin_get_child (GTK_BIN (child))), TRUE);
691 gtk_widget_show (child); 683 gtk_widget_show (child);
692 } 684 }
693 g_signal_connect (menu, "selection-done", 685 g_signal_connect (menu, "selection-done",
694 G_CALLBACK (search_list_popup_selection_done), NULL); 686 G_CALLBACK (search_list_popup_selection_done), spc);
695 gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); 687 gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
696 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time); 688 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time);
697 return TRUE; 689 return TRUE;