From e5a7fa50c8813dedd8130d0ae58d9d4a83660a6f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 31 Jan 2012 23:48:22 +0000 Subject: -misc code cleanup --- src/fs/gnunet-fs-gtk-event_handler.c | 286 +++++++++++++++++++---------------- 1 file changed, 159 insertions(+), 127 deletions(-) diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c index 81b61725..3b4dc667 100644 --- a/src/fs/gnunet-fs-gtk-event_handler.c +++ b/src/fs/gnunet-fs-gtk-event_handler.c @@ -163,11 +163,12 @@ static struct SearchTab *current_context_search_tab; * somewhere else, at least until application restart, or maybe even * between application restarts). * - * Fills the @buffer up to @size bytes, returns a pointer to it. + * Fills the 'buffer' up to 'size' bytes, returns a pointer to it. */ static char * get_default_download_directory (char *buffer, size_t size) { + /* FIXME: implement... */ return NULL; } @@ -208,6 +209,8 @@ get_suggested_filename_anonymity (GtkTreeModel *tm, const char *basename; char *dot; + /* FIXME: this function is likely responsible for not always + suggesting the best filename... To be investigated some more... */ gtk_tree_model_get (tm, iter, 0, &meta, 15, &local_filename, 16, &downloaded_anonymity, @@ -289,8 +292,8 @@ get_suggested_filename_anonymity (GtkTreeModel *tm, * @param is_recursive was the request for a recursive download? */ static void -start_download (GtkTreeView * tree_view, - GtkTreePath * path, +start_download (GtkTreeView *tree_view, + GtkTreePath *path, struct SearchTab *tab, int is_recursive) { @@ -346,7 +349,9 @@ start_download (GtkTreeView * tree_view, local_parents = GNUNET_YES; anonymity = -1; filename_is_absolute = GNUNET_NO; - filename = get_suggested_filename_anonymity (tm, &iter, GNUNET_YES, &local_parents, &anonymity, &filename_is_absolute); + filename = get_suggested_filename_anonymity (tm, &iter, GNUNET_YES, + &local_parents, &anonymity, + &filename_is_absolute); have_a_suggestion = GNUNET_NO; if (NULL != download_directory) { @@ -397,7 +402,8 @@ start_download (GtkTreeView * tree_view, dc->anonymity = anonymity; dc->is_recursive = is_recursive; dc->tab = tab; - if (local_parents && have_a_suggestion) + if ( (GNUNET_YES == local_parents) && + (GNUNET_YES == have_a_suggestion) ) /* Skip the dialog, call directly */ GNUNET_FS_GTK_download_context_start_download (dc); else @@ -406,8 +412,7 @@ start_download (GtkTreeView * tree_view, /** - * An item was selected from the context menu; destroy - * the menu shell. + * An item was selected from the context menu; destroy the menu shell. * * @param menushell menu to destroy * @parma user_data the 'struct DownloadEntry' for the menu (unused) @@ -423,7 +428,6 @@ search_list_popup_selection_done (GtkMenuShell *menushell, } - /** * This function is called when the user double-clicks on a search * result. Begins the download, if necessary by opening the "save as" @@ -523,10 +527,10 @@ abort_download_ctx_menu (GtkMenuItem *item, gpointer user_data) /** - * Copy current URI to clipboard. + * Copy current URI to clipboard was selected in the current context menu. * * @param item the 'copy-to-clipboard' menu item - * @parma user_data the 'struct DownloadEntry' to copy from + * @parma user_data NULL */ static void copy_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data) @@ -573,89 +577,73 @@ copy_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data) } +/** + * Context menu was requested for a search result list. + * Compute which menu items are applicable and display + * an appropriate menu. + * + * @param tm tree model underlying the tree view where the event happened + * @param tab tab where the event happened + * @param event_button the event + * @return FALSE if no menu could be popped up, + * TRUE if there is now a pop-up menu + */ static gboolean -search_list_popup (GtkTreeView *tv, struct SearchTab *tab, GdkEventButton *event_button) +search_list_popup (GtkTreeModel *tm, + struct SearchTab *tab, + gint init_button, + guint32 event_time, + GtkTreeIter *iter) { GtkMenu *menu; GtkWidget *child; - GtkTreeSelection *sel; GtkTreePath *path; - GtkTreeModel *tm; - GtkTreeIter iter; struct SearchResult *sr; struct GNUNET_FS_Uri *uri; - gboolean got_selection; - gint init_button; - guint32 event_time; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Creating a menu for SR=%p, DE=%p\n", + sr, + sr->download); + + /* FIXME: move these to some menu context struct + (de-globalize) */ current_context_search_tab = tab; if (current_context_row_reference != NULL) { gtk_tree_row_reference_free (current_context_row_reference); current_context_row_reference = NULL; } - path = NULL; - if (event_button != NULL) - { - got_selection = - gtk_tree_view_get_path_at_pos (tv, event_button->x, event_button->y, - &path, NULL, NULL, NULL); - if (got_selection) - { - tm = gtk_tree_view_get_model (tv); - got_selection = gtk_tree_model_get_iter (tm, &iter, path); - current_context_row_reference = gtk_tree_row_reference_new (tm, path); - gtk_tree_path_free (path); - } - init_button = event_button->button; - event_time = event_button->time; - } - else - { - sel = gtk_tree_view_get_selection (tv); - got_selection = gtk_tree_selection_get_selected (sel, &tm, &iter); - path = gtk_tree_model_get_path (tm, &iter); - current_context_row_reference = gtk_tree_row_reference_new (tm, path); - gtk_tree_path_free (path); - init_button = 0; - event_time = gtk_get_current_event_time (); - } - if (!got_selection) - { - /* nothing selected or model empty? */ - current_context_search_tab = NULL; - return FALSE; - } - gtk_tree_model_get (tm, &iter, 1, &uri, 9, &sr, -1); + path = gtk_tree_model_get_path (tm, iter); + current_context_row_reference = gtk_tree_row_reference_new (tm, path); + gtk_tree_path_free (path); + + gtk_tree_model_get (tm, iter, 1, &uri, 9, &sr, -1); menu = GTK_MENU (gtk_menu_new ()); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating a menu for SR=%p, DE=%p\n", sr, sr->download); - if (sr->download == NULL) - { - if (NULL != uri) - { - /* only display download menus if there is a URI */ - child = gtk_menu_item_new_with_label (_("_Download")); - g_signal_connect (child, "activate", - G_CALLBACK (start_download_ctx_menu), NULL); - gtk_label_set_use_underline (GTK_LABEL - (gtk_bin_get_child (GTK_BIN (child))), - TRUE); - gtk_widget_show (child); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); - - child = gtk_menu_item_new_with_label (_("Download _recursively")); - g_signal_connect (child, "activate", - G_CALLBACK (start_download_recursively_ctx_menu), NULL); - gtk_label_set_use_underline (GTK_LABEL - (gtk_bin_get_child (GTK_BIN (child))), - TRUE); - gtk_widget_show (child); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); - } + if ( (NULL == sr->download) && + (NULL != uri) ) + { + /* only display download menus if there is a URI */ + child = gtk_menu_item_new_with_label (_("_Download")); + g_signal_connect (child, "activate", + G_CALLBACK (start_download_ctx_menu), NULL); + gtk_label_set_use_underline (GTK_LABEL + (gtk_bin_get_child (GTK_BIN (child))), + TRUE); + gtk_widget_show (child); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); + + child = gtk_menu_item_new_with_label (_("Download _recursively")); + g_signal_connect (child, "activate", + G_CALLBACK (start_download_recursively_ctx_menu), NULL); + gtk_label_set_use_underline (GTK_LABEL + (gtk_bin_get_child (GTK_BIN (child))), + TRUE); + gtk_widget_show (child); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); } - else + if (NULL != sr->download) { child = gtk_menu_item_new_with_label (_("_Abort download")); g_signal_connect (child, "activate", @@ -666,31 +654,100 @@ search_list_popup (GtkTreeView *tv, struct SearchTab *tab, GdkEventButton *event gtk_widget_show (child); gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); } - - child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); - g_signal_connect (child, "activate", - G_CALLBACK (copy_uri_to_clipboard_ctx_menu), NULL); - gtk_label_set_use_underline (GTK_LABEL - (gtk_bin_get_child (GTK_BIN (child))), TRUE); - gtk_widget_show (child); - + if (NULL != uri) + { + child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); + g_signal_connect (child, "activate", + G_CALLBACK (copy_uri_to_clipboard_ctx_menu), NULL); + gtk_label_set_use_underline (GTK_LABEL + (gtk_bin_get_child (GTK_BIN (child))), TRUE); + gtk_widget_show (child); + } g_signal_connect (menu, "selection-done", - G_CALLBACK (search_list_popup_selection_done), NULL); - + G_CALLBACK (search_list_popup_selection_done), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time); return TRUE; } -static void -closure_notify_free (gpointer data, GClosure *closure) +/** + * We got a 'popup-menu' event, display the context menu. + * + * @param widget the tree view where the event happened + * @param user_data the 'struct SearchTab' of the tree view + * @return FALSE if no menu could be popped up, + * TRUE if there is now a pop-up menu + */ +static gboolean +search_list_on_popup (GtkWidget *widget, gpointer user_data) { - GNUNET_free (data); + GtkTreeView *tv = GTK_TREE_VIEW (widget); + struct SearchTab *tab = user_data; + GtkTreeSelection *sel; + GtkTreeIter iter; + GtkTreeModel *tm; + + sel = gtk_tree_view_get_selection (tv); + if (! gtk_tree_selection_get_selected (sel, &tm, &iter)) + return FALSE; /* nothing selected */ + return search_list_popup (tm, tab, 0, gtk_get_current_event_time (), &iter); } + +/** + * We got a right-click on the search result list. Display the context + * menu. + * + * @param widget the GtkTreeView with the search result list + * @param event the event, we only care about button events + * @param user_data the 'struct SearchTab' the widget is in + * @return FALSE if no menu could be popped up, + * TRUE if there is now a pop-up menu + */ +static gboolean +search_list_on_menu (GtkWidget * widget, + GdkEvent * event, + gpointer user_data) +{ + GtkTreeView *tv = GTK_TREE_VIEW (widget); + GdkEventButton *event_button = (GdkEventButton *) event; + struct SearchTab *tab = user_data; + GtkTreeModel *tm; + GtkTreePath *path; + GtkTreeIter iter; + + if ( (event->type != GDK_BUTTON_PRESS) || + (event_button->button != 3) ) + return FALSE; /* not a right-click */ + if (! gtk_tree_view_get_path_at_pos (tv, + event_button->x, event_button->y, + &path, NULL, NULL, NULL)) + return FALSE; /* click outside of area with values, ignore */ + tm = gtk_tree_view_get_model (tv); + if (! gtk_tree_model_get_iter (tm, &iter, path)) + return FALSE; /* not sure how we got a path but no iter... */ + gtk_tree_path_free (path); + return search_list_popup (tm, tab, + event_button->button, + event_button->time, + &iter); +} + + + + + +/* FIXME: go over code from here on and document & clean up... */ + + + + + + static struct DownloadEntry * -change_download_colour (struct DownloadEntry *de, const char *colour) +change_download_colour (struct DownloadEntry *de, + const char *colour) { GtkTreeIter iter; GtkTreePath *path; @@ -782,7 +839,7 @@ struct AddDirectoryEntryContext { /** - * + * FIXME */ struct DownloadEntry *de; @@ -1243,40 +1300,6 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde, -static gboolean -search_list_on_popup (GtkWidget *widget, gpointer user_data) -{ - GtkTreeView *tv; - struct SearchTab *tab = user_data; - - tv = GTK_TREE_VIEW (widget); - return search_list_popup (tv, tab, NULL); -} - - - -/** - * We got a right-click on the search result list. Display the context - * menu. - */ -static int -search_list_on_menu (GtkWidget * widget, GdkEvent * event, gpointer user_data) -{ - GdkEventButton *event_button; - struct SearchTab *tab = user_data; - GtkTreeView *tv; - - tv = GTK_TREE_VIEW (widget); - if (event->type == GDK_BUTTON_PRESS) - { - event_button = (GdkEventButton *) event; - if (event_button->button == 3) - { - return search_list_popup (tv, tab, event_button); - } - } - return FALSE; -} /** * Selected row has changed, update preview and metadata @@ -1573,6 +1596,16 @@ continue_search (GtkButton * button, gpointer user_data) } +/** + * FIXME: what exactly are we freeing here on 'row_activated'? + */ +static void +closure_notify_free (gpointer data, GClosure *closure) +{ + GNUNET_free (data); +} + + /** * Setup a new search tab. * @@ -1688,7 +1721,7 @@ setup_search (struct GNUNET_FS_SearchContext *sc, /** - * Setup an inner search. + * Setup an inner search. FIXME: explain what an 'inner' search is... * * @param sc context with FS for the search * @param parent parent search tab @@ -1716,7 +1749,6 @@ setup_inner_search (struct GNUNET_FS_SearchContext *sc, } - /** * Add a search result to the given search tab. * -- cgit v1.2.3