diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk_event-handler.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk_event-handler.c | 239 |
1 files changed, 228 insertions, 11 deletions
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c index 8bae5f0e..14d68675 100644 --- a/src/fs/gnunet-fs-gtk_event-handler.c +++ b/src/fs/gnunet-fs-gtk_event-handler.c | |||
@@ -553,11 +553,10 @@ abort_download_ctx_menu (GtkMenuItem *item, gpointer user_data) | |||
553 | * Copy current URI to clipboard was selected in the current context menu. | 553 | * Copy current URI to clipboard was selected in the current context menu. |
554 | * | 554 | * |
555 | * @param item the 'copy-to-clipboard' menu item | 555 | * @param item the 'copy-to-clipboard' menu item |
556 | * @parma user_data NULL | ||
557 | * @parma user_data the 'struct SearchListPopupContext' of the menu | 556 | * @parma user_data the 'struct SearchListPopupContext' of the menu |
558 | */ | 557 | */ |
559 | static void | 558 | static void |
560 | copy_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data) | 559 | copy_search_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data) |
561 | { | 560 | { |
562 | struct SearchListPopupContext *spc = user_data; | 561 | struct SearchListPopupContext *spc = user_data; |
563 | GtkTreePath *path; | 562 | GtkTreePath *path; |
@@ -619,8 +618,6 @@ search_list_popup (GtkTreeModel *tm, | |||
619 | struct GNUNET_FS_Uri *uri; | 618 | struct GNUNET_FS_Uri *uri; |
620 | struct SearchListPopupContext *spc; | 619 | struct SearchListPopupContext *spc; |
621 | 620 | ||
622 | /* FIXME-UNCLEAN: move these to some menu context struct | ||
623 | (de-globalize) */ | ||
624 | spc = GNUNET_malloc (sizeof (struct SearchListPopupContext)); | 621 | spc = GNUNET_malloc (sizeof (struct SearchListPopupContext)); |
625 | spc->tab = tab; | 622 | spc->tab = tab; |
626 | path = gtk_tree_model_get_path (tm, iter); | 623 | path = gtk_tree_model_get_path (tm, iter); |
@@ -651,7 +648,6 @@ search_list_popup (GtkTreeModel *tm, | |||
651 | gtk_widget_show (child); | 648 | gtk_widget_show (child); |
652 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); | 649 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); |
653 | 650 | ||
654 | |||
655 | child = gtk_menu_item_new_with_label (_("Download _as...")); | 651 | child = gtk_menu_item_new_with_label (_("Download _as...")); |
656 | g_signal_connect (child, "activate", | 652 | g_signal_connect (child, "activate", |
657 | G_CALLBACK (start_download_as_ctx_menu), spc); | 653 | G_CALLBACK (start_download_as_ctx_menu), spc); |
@@ -677,14 +673,14 @@ search_list_popup (GtkTreeModel *tm, | |||
677 | { | 673 | { |
678 | child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); | 674 | child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); |
679 | g_signal_connect (child, "activate", | 675 | g_signal_connect (child, "activate", |
680 | G_CALLBACK (copy_uri_to_clipboard_ctx_menu), spc); | 676 | G_CALLBACK (copy_search_uri_to_clipboard_ctx_menu), spc); |
681 | gtk_label_set_use_underline (GTK_LABEL | 677 | gtk_label_set_use_underline (GTK_LABEL |
682 | (gtk_bin_get_child (GTK_BIN (child))), TRUE); | 678 | (gtk_bin_get_child (GTK_BIN (child))), TRUE); |
683 | gtk_widget_show (child); | 679 | gtk_widget_show (child); |
680 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); | ||
684 | } | 681 | } |
685 | g_signal_connect (menu, "selection-done", | 682 | g_signal_connect (menu, "selection-done", |
686 | G_CALLBACK (search_list_popup_selection_done), spc); | 683 | G_CALLBACK (search_list_popup_selection_done), spc); |
687 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); | ||
688 | gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time); | 684 | gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time); |
689 | return TRUE; | 685 | return TRUE; |
690 | } | 686 | } |
@@ -2439,7 +2435,7 @@ GNUNET_FS_GTK_publish_label_close_button_clicked (GtkButton * button, | |||
2439 | gpointer user_data) | 2435 | gpointer user_data) |
2440 | { | 2436 | { |
2441 | struct PublishTab *tab = user_data; | 2437 | struct PublishTab *tab = user_data; |
2442 | struct PublishEntry *ent; | 2438 | struct PublishEntry *pe; |
2443 | GtkTreeIter iter; | 2439 | GtkTreeIter iter; |
2444 | GtkTreeModel *tm; | 2440 | GtkTreeModel *tm; |
2445 | GtkNotebook *notebook; | 2441 | GtkNotebook *notebook; |
@@ -2453,9 +2449,9 @@ GNUNET_FS_GTK_publish_label_close_button_clicked (GtkButton * button, | |||
2453 | { | 2449 | { |
2454 | do | 2450 | do |
2455 | { | 2451 | { |
2456 | gtk_tree_model_get (tm, &iter, 4, &ent, -1); | 2452 | gtk_tree_model_get (tm, &iter, 4, &pe, -1); |
2457 | GNUNET_FS_publish_stop (ent->pc); | 2453 | GNUNET_FS_publish_stop (pe->pc); |
2458 | ent->pc = NULL; | 2454 | pe->pc = NULL; |
2459 | } | 2455 | } |
2460 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | 2456 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); |
2461 | } | 2457 | } |
@@ -2574,6 +2570,227 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn, | |||
2574 | 2570 | ||
2575 | 2571 | ||
2576 | 2572 | ||
2573 | /** | ||
2574 | * Context for the publish list popup menu. | ||
2575 | */ | ||
2576 | struct PublishListPopupContext | ||
2577 | { | ||
2578 | /** | ||
2579 | * Tab where the publish list popup was created. | ||
2580 | */ | ||
2581 | struct PublishTab *tab; | ||
2582 | |||
2583 | /** | ||
2584 | * Row where the publish list popup was created. | ||
2585 | */ | ||
2586 | GtkTreeRowReference *rr; | ||
2587 | |||
2588 | |||
2589 | /** | ||
2590 | * Publishing entry at the respective row. | ||
2591 | */ | ||
2592 | struct PublishEntry *pe; | ||
2593 | |||
2594 | }; | ||
2595 | |||
2596 | |||
2597 | /** | ||
2598 | * An item was selected from the context menu; destroy the menu shell. | ||
2599 | * | ||
2600 | * @param menushell menu to destroy | ||
2601 | * @param user_data the 'struct PublishListPopupContext' of the menu | ||
2602 | */ | ||
2603 | static void | ||
2604 | publish_list_popup_selection_done (GtkMenuShell *menushell, | ||
2605 | gpointer user_data) | ||
2606 | { | ||
2607 | struct PublishListPopupContext *ppc = user_data; | ||
2608 | |||
2609 | gtk_widget_destroy (GTK_WIDGET (menushell)); | ||
2610 | gtk_tree_row_reference_free (ppc->rr); | ||
2611 | GNUNET_free (ppc); | ||
2612 | } | ||
2613 | |||
2614 | |||
2615 | /** | ||
2616 | * Publish "abort" was selected in the current publish context menu. | ||
2617 | * | ||
2618 | * @param item the 'abort' menu item | ||
2619 | * @parma user_data the 'struct PublishListPopupContext' with the operation to abort. | ||
2620 | */ | ||
2621 | static void | ||
2622 | abort_publish_ctx_menu (GtkMenuItem *item, gpointer user_data) | ||
2623 | { | ||
2624 | struct PublishListPopupContext *ppc = user_data; | ||
2625 | struct PublishEntry *pe = ppc->pe; | ||
2626 | |||
2627 | if (NULL != pe->pc) | ||
2628 | GNUNET_FS_publish_stop (pe->pc); | ||
2629 | } | ||
2630 | |||
2631 | |||
2632 | /** | ||
2633 | * Copy current URI to clipboard was selected in the current context menu. | ||
2634 | * | ||
2635 | * @param item the 'copy-to-clipboard' menu item | ||
2636 | * @parma user_data the 'struct DownloadListPopupContext' of the menu | ||
2637 | */ | ||
2638 | static void | ||
2639 | copy_publish_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data) | ||
2640 | { | ||
2641 | struct PublishListPopupContext *ppc = user_data; | ||
2642 | struct GNUNET_FS_Uri *uri; | ||
2643 | char *uris; | ||
2644 | GtkClipboard *cb; | ||
2645 | |||
2646 | uri = ppc->pe->uri; | ||
2647 | if (uri == NULL) | ||
2648 | { | ||
2649 | GNUNET_break (0); | ||
2650 | return; | ||
2651 | } | ||
2652 | uris = GNUNET_FS_uri_to_string (uri); | ||
2653 | cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); | ||
2654 | gtk_clipboard_set_text (cb, uris, -1); | ||
2655 | gtk_clipboard_store (cb); | ||
2656 | GNUNET_free (uris); | ||
2657 | } | ||
2658 | |||
2659 | |||
2660 | /** | ||
2661 | * Context menu was requested for a publish result list. | ||
2662 | * Compute which menu items are applicable and display | ||
2663 | * an appropriate menu. | ||
2664 | * | ||
2665 | * @param tm tree model underlying the tree view where the event happened | ||
2666 | * @param tab tab where the event happened | ||
2667 | * @param event_button the event | ||
2668 | * @return FALSE if no menu could be popped up, | ||
2669 | * TRUE if there is now a pop-up menu | ||
2670 | */ | ||
2671 | static gboolean | ||
2672 | publish_list_popup (GtkTreeModel *tm, | ||
2673 | struct PublishTab *tab, | ||
2674 | gint init_button, | ||
2675 | guint32 event_time, | ||
2676 | GtkTreeIter *iter) | ||
2677 | { | ||
2678 | GtkMenu *menu; | ||
2679 | GtkWidget *child; | ||
2680 | GtkTreePath *path; | ||
2681 | struct PublishEntry *pe; | ||
2682 | struct PublishListPopupContext *ppc; | ||
2683 | |||
2684 | gtk_tree_model_get (tm, iter, 4, &pe, -1); | ||
2685 | if ( (NULL == pe->uri) && | ||
2686 | ( (NULL == pe->pc) || | ||
2687 | (GNUNET_NO == pe->is_top) ) ) | ||
2688 | { | ||
2689 | /* no actions available, refuse to pop up */ | ||
2690 | return FALSE; | ||
2691 | } | ||
2692 | |||
2693 | ppc = GNUNET_malloc (sizeof (struct PublishListPopupContext)); | ||
2694 | ppc->tab = tab; | ||
2695 | path = gtk_tree_model_get_path (tm, iter); | ||
2696 | ppc->rr = gtk_tree_row_reference_new (tm, path); | ||
2697 | gtk_tree_path_free (path); | ||
2698 | ppc->pe = pe; | ||
2699 | menu = GTK_MENU (gtk_menu_new ()); | ||
2700 | if (NULL != pe->uri) | ||
2701 | { | ||
2702 | child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); | ||
2703 | g_signal_connect (child, "activate", | ||
2704 | G_CALLBACK (copy_publish_uri_to_clipboard_ctx_menu), ppc); | ||
2705 | gtk_label_set_use_underline (GTK_LABEL | ||
2706 | (gtk_bin_get_child (GTK_BIN (child))), TRUE); | ||
2707 | gtk_widget_show (child); | ||
2708 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); | ||
2709 | } | ||
2710 | else if (NULL != pe->pc) | ||
2711 | { | ||
2712 | child = gtk_menu_item_new_with_label (_("_Abort publishing")); | ||
2713 | g_signal_connect (child, "activate", | ||
2714 | G_CALLBACK (abort_publish_ctx_menu), ppc); | ||
2715 | gtk_label_set_use_underline (GTK_LABEL | ||
2716 | (gtk_bin_get_child (GTK_BIN (child))), | ||
2717 | TRUE); | ||
2718 | gtk_widget_show (child); | ||
2719 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); | ||
2720 | } | ||
2721 | g_signal_connect (menu, "selection-done", | ||
2722 | G_CALLBACK (publish_list_popup_selection_done), ppc); | ||
2723 | gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time); | ||
2724 | return TRUE; | ||
2725 | } | ||
2726 | |||
2727 | |||
2728 | /** | ||
2729 | * We got a 'popup-menu' event, display the context menu. | ||
2730 | * | ||
2731 | * @param widget the tree view where the event happened | ||
2732 | * @param user_data the 'struct PublishTab' of the tree view | ||
2733 | * @return FALSE if no menu could be popped up, | ||
2734 | * TRUE if there is now a pop-up menu | ||
2735 | */ | ||
2736 | gboolean | ||
2737 | GNUNET_FS_GTK_publish_treeview_popup_menu (GtkWidget *widget, | ||
2738 | gpointer user_data) | ||
2739 | { | ||
2740 | GtkTreeView *tv = GTK_TREE_VIEW (widget); | ||
2741 | struct PublishTab *tab = user_data; | ||
2742 | GtkTreeSelection *sel; | ||
2743 | GtkTreeIter iter; | ||
2744 | GtkTreeModel *tm; | ||
2745 | |||
2746 | sel = gtk_tree_view_get_selection (tv); | ||
2747 | if (! gtk_tree_selection_get_selected (sel, &tm, &iter)) | ||
2748 | return FALSE; /* nothing selected */ | ||
2749 | return publish_list_popup (tm, tab, 0, gtk_get_current_event_time (), &iter); | ||
2750 | } | ||
2751 | |||
2752 | |||
2753 | /** | ||
2754 | * We got a right-click on the search result list. Display the context | ||
2755 | * menu. | ||
2756 | * | ||
2757 | * @param widget the GtkTreeView with the search result list | ||
2758 | * @param event the event, we only care about button events | ||
2759 | * @param user_data the 'struct SearchTab' the widget is in | ||
2760 | * @return FALSE if no menu could be popped up, | ||
2761 | * TRUE if there is now a pop-up menu | ||
2762 | */ | ||
2763 | gboolean | ||
2764 | GNUNET_FS_GTK_publish_treeview_button_press_event (GtkWidget * widget, | ||
2765 | GdkEvent * event, | ||
2766 | gpointer user_data) | ||
2767 | { | ||
2768 | GtkTreeView *tv = GTK_TREE_VIEW (widget); | ||
2769 | GdkEventButton *event_button = (GdkEventButton *) event; | ||
2770 | struct PublishTab *tab = user_data; | ||
2771 | GtkTreeModel *tm; | ||
2772 | GtkTreePath *path; | ||
2773 | GtkTreeIter iter; | ||
2774 | |||
2775 | if ( (event->type != GDK_BUTTON_PRESS) || | ||
2776 | (event_button->button != 3) ) | ||
2777 | return FALSE; /* not a right-click */ | ||
2778 | if (! gtk_tree_view_get_path_at_pos (tv, | ||
2779 | event_button->x, event_button->y, | ||
2780 | &path, NULL, NULL, NULL)) | ||
2781 | return FALSE; /* click outside of area with values, ignore */ | ||
2782 | tm = gtk_tree_view_get_model (tv); | ||
2783 | if (! gtk_tree_model_get_iter (tm, &iter, path)) | ||
2784 | return FALSE; /* not sure how we got a path but no iter... */ | ||
2785 | gtk_tree_path_free (path); | ||
2786 | return publish_list_popup (tm, tab, | ||
2787 | event_button->button, | ||
2788 | event_button->time, | ||
2789 | &iter); | ||
2790 | } | ||
2791 | |||
2792 | |||
2793 | |||
2577 | /* ***************** Master event handler ****************** */ | 2794 | /* ***************** Master event handler ****************** */ |
2578 | 2795 | ||
2579 | 2796 | ||