From 6947159069572443210bca0046697b7f41d9a0c5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 2 Feb 2012 18:44:08 +0000 Subject: -starting to clean up dropdown code --- .../gnunet-fs-gtk_main-window-namespace-dropdown.c | 157 +++++++++++++-------- 1 file changed, 99 insertions(+), 58 deletions(-) diff --git a/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c b/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c index 99b26575..66c70831 100644 --- a/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c +++ b/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c @@ -26,10 +26,15 @@ #include "gnunet-fs-gtk_common.h" #include "gnunet-fs-gtk.h" - +/** + * + */ static guint namespace_selector_window_leave_timeout_source; +/** + * + */ void main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton * togglebutton, @@ -82,17 +87,9 @@ main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton * } -gboolean -namespace_selector_window_leave_timeout_cb (gpointer user_data) -{ - GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data); - - /* This will eventually hide the namespace selector */ - gtk_toggle_button_set_active (toggle_button, FALSE); - return FALSE; -} - - +/** + * + */ gboolean main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget * widget, @@ -107,6 +104,23 @@ main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget * } +/** + * + */ +static gboolean +namespace_selector_window_leave_timeout_cb (gpointer user_data) +{ + GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data); + + /* This will eventually hide the namespace selector */ + gtk_toggle_button_set_active (toggle_button, FALSE); + return FALSE; +} + + +/** + * + */ gboolean namespace_selector_window_leave_notify_event_cb (GtkWidget * widget, GdkEvent * event, @@ -137,8 +151,10 @@ namespace_selector_window_leave_notify_event_cb (GtkWidget * widget, } - -gboolean +/** + * + */ +static gboolean get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder, GtkTreePath ** p_treepath, GtkTreeIter * p_iter, @@ -190,11 +206,15 @@ get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder, return TRUE; } + +/** + * + */ void namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget, gpointer user_data) { - GtkBuilder *builder; + GtkBuilder *builder = GTK_BUILDER (user_data); GtkToggleButton *toggle_button; GtkLabel *sel_namespace_label; GtkTreeModel *model; @@ -203,8 +223,6 @@ namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget, GtkEntry *search_entry; GtkTreeRowReference *ref, *old; - builder = GTK_BUILDER (user_data); - toggle_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, @@ -252,7 +270,11 @@ namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget, gtk_toggle_button_set_active (toggle_button, FALSE); } -GtkTreeRowReference * + +/** + * + */ +static GtkTreeRowReference * get_ns_selected_row (GtkTreeView * tree) { GtkTreeSelection *sel; @@ -273,6 +295,10 @@ get_ns_selected_row (GtkTreeView * tree) return ref; } + +/** + * + */ gboolean namespace_selector_treeview_button_press_event_cb (GtkWidget * widget, GdkEvent * event, @@ -292,6 +318,10 @@ namespace_selector_treeview_button_press_event_cb (GtkWidget * widget, return FALSE; } + +/** + * + */ gboolean namespace_selector_treeview_button_release_event_cb (GtkWidget * widget, GdkEvent * event, @@ -323,7 +353,6 @@ namespace_selector_treeview_button_release_event_cb (GtkWidget * widget, } - /** * Add pseudonym data to tree store * @@ -389,8 +418,12 @@ add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym, else description = NULL; } - gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1, - nsid, 2, root, 3, description, -1); + gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, + 0, ns_name, + 1, nsid, + 2, root, + 3, description, + -1); GNUNET_free (ns_name); GNUNET_free_non_null (root); GNUNET_free_non_null (description); @@ -398,17 +431,20 @@ add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym, } +/** + * Startup hook to initialize the namespace dropdown widget. + * + * @param widget the main window + * @param user_data the builder for the main window + */ void GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data) { + GtkBuilder *builder = GTK_BUILDER (user_data); GtkTreeIter iter; - GtkTreeView *namespace_tree; GtkTreeStore *namespace_treestore; - GtkBuilder *builder; - GtkWidget *namespace_selector_window; - - builder = GTK_BUILDER (user_data); + /* FIXME: can't we do the button initialization when we create the main window? */ /* Make sure button class is realized */ g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON)); /* GNUnet main window assumes that images on buttons are visible, @@ -416,43 +452,45 @@ GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data) */ g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL); - namespace_treestore = + /* setup namespace treestore */ + { + namespace_treestore = GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object ("main_window_search_namespace_treestore")); - namespace_tree = - GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object - ("namespace_selector_treeview")); - - /* FIXME: find a way to manage pseudonyms. - * Right now the list will be filled with ALL and ANY pseudonyms that we - * find, these are held as files in a special directory. - * I don't see an easy way to ignore certain pseudonyms in that directory, - * and that require for pseudonym management. Also, pseudonyms are presented - * in arbitrary order. We must either sort them (by name?) or let the user - * drag them around to change the order in which they appear in the list. - * All that is not possible with a simple "files in a directory" concept. - */ - gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, G_MAXINT, - 0, "Any", 1, NULL, 2, "", 3, - "Do not search in any particular namespace", - -1); - /* - * GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (), - * &add_namespace_to_ts, namespace_treestore); - */ - /* FIXME: when do we unregister? */ - GNUNET_PSEUDONYM_discovery_callback_register (GNUNET_FS_GTK_get_configuration (), - &add_namespace_to_ts, - namespace_treestore); + + /* FIXME: find a way to manage pseudonyms. + * Right now the list will be filled with ALL and ANY pseudonyms that we + * find, these are held as files in a special directory. + * I don't see an easy way to ignore certain pseudonyms in that directory, + * and that require for pseudonym management. Also, pseudonyms are presented + * in arbitrary order. We must either sort them (by name?) or let the user + * drag them around to change the order in which they appear in the list. + * All that is not possible with a simple "files in a directory" concept. + */ + gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, G_MAXINT, + 0, "Any", 1, NULL, 2, "", 3, + "Do not search in any particular namespace", + -1); + /* FIXME: when do we unregister? */ + GNUNET_PSEUDONYM_discovery_callback_register (GNUNET_FS_GTK_get_configuration (), + &add_namespace_to_ts, + namespace_treestore); + } - /* FIXME: read currently selected namespace from somewhere instead of selecting 0th item */ + /* select the first item and update the label */ + /* FIXME: is this even necessary? If the first item is "Any", we can + just have the label have the right default, or not? */ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (namespace_treestore), &iter)) { gchar *value; GtkLabel *sel_namespace_label; GtkTreePath *treepath = gtk_tree_path_new_first (); + GtkTreeView *namespace_tree; + namespace_tree = + GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object + ("namespace_selector_treeview")); gtk_tree_selection_select_iter (gtk_tree_view_get_selection (namespace_tree), &iter); sel_namespace_label = @@ -463,13 +501,16 @@ GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data) gtk_tree_path_free (treepath); } - /* How the window (to trigger certain events) and immediately hide it */ - namespace_selector_window = + /* show the window (to trigger certain events) and immediately hide it */ + { + GtkWidget *namespace_selector_window; + + namespace_selector_window = GTK_WIDGET (gtk_builder_get_object (builder, "namespace_selector_window")); - gtk_widget_show (namespace_selector_window); - gtk_widget_hide (namespace_selector_window); - + gtk_widget_show (namespace_selector_window); + gtk_widget_hide (namespace_selector_window); + } } -- cgit v1.2.3