aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-02 18:44:08 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-02 18:44:08 +0000
commit6947159069572443210bca0046697b7f41d9a0c5 (patch)
tree13ea267198510de4647fe5cef758af83abe70e3a
parent7e3d03f407be711d74844e4ec893e677cc57e261 (diff)
downloadgnunet-gtk-6947159069572443210bca0046697b7f41d9a0c5.tar.gz
gnunet-gtk-6947159069572443210bca0046697b7f41d9a0c5.zip
-starting to clean up dropdown code
-rw-r--r--src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c157
1 files 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 @@
26#include "gnunet-fs-gtk_common.h" 26#include "gnunet-fs-gtk_common.h"
27#include "gnunet-fs-gtk.h" 27#include "gnunet-fs-gtk.h"
28 28
29 29/**
30 *
31 */
30static guint namespace_selector_window_leave_timeout_source; 32static guint namespace_selector_window_leave_timeout_source;
31 33
32 34
35/**
36 *
37 */
33void 38void
34main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton * 39main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *
35 togglebutton, 40 togglebutton,
@@ -82,17 +87,9 @@ main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *
82} 87}
83 88
84 89
85gboolean 90/**
86namespace_selector_window_leave_timeout_cb (gpointer user_data) 91 *
87{ 92 */
88 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data);
89
90 /* This will eventually hide the namespace selector */
91 gtk_toggle_button_set_active (toggle_button, FALSE);
92 return FALSE;
93}
94
95
96gboolean 93gboolean
97main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget * 94main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget *
98 widget, 95 widget,
@@ -107,6 +104,23 @@ main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget *
107} 104}
108 105
109 106
107/**
108 *
109 */
110static gboolean
111namespace_selector_window_leave_timeout_cb (gpointer user_data)
112{
113 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data);
114
115 /* This will eventually hide the namespace selector */
116 gtk_toggle_button_set_active (toggle_button, FALSE);
117 return FALSE;
118}
119
120
121/**
122 *
123 */
110gboolean 124gboolean
111namespace_selector_window_leave_notify_event_cb (GtkWidget * widget, 125namespace_selector_window_leave_notify_event_cb (GtkWidget * widget,
112 GdkEvent * event, 126 GdkEvent * event,
@@ -137,8 +151,10 @@ namespace_selector_window_leave_notify_event_cb (GtkWidget * widget,
137} 151}
138 152
139 153
140 154/**
141gboolean 155 *
156 */
157static gboolean
142get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder, 158get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder,
143 GtkTreePath ** p_treepath, 159 GtkTreePath ** p_treepath,
144 GtkTreeIter * p_iter, 160 GtkTreeIter * p_iter,
@@ -190,11 +206,15 @@ get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder,
190 return TRUE; 206 return TRUE;
191} 207}
192 208
209
210/**
211 *
212 */
193void 213void
194namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget, 214namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget,
195 gpointer user_data) 215 gpointer user_data)
196{ 216{
197 GtkBuilder *builder; 217 GtkBuilder *builder = GTK_BUILDER (user_data);
198 GtkToggleButton *toggle_button; 218 GtkToggleButton *toggle_button;
199 GtkLabel *sel_namespace_label; 219 GtkLabel *sel_namespace_label;
200 GtkTreeModel *model; 220 GtkTreeModel *model;
@@ -203,8 +223,6 @@ namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget,
203 GtkEntry *search_entry; 223 GtkEntry *search_entry;
204 GtkTreeRowReference *ref, *old; 224 GtkTreeRowReference *ref, *old;
205 225
206 builder = GTK_BUILDER (user_data);
207
208 toggle_button = 226 toggle_button =
209 GTK_TOGGLE_BUTTON (gtk_builder_get_object 227 GTK_TOGGLE_BUTTON (gtk_builder_get_object
210 (builder, 228 (builder,
@@ -252,7 +270,11 @@ namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget,
252 gtk_toggle_button_set_active (toggle_button, FALSE); 270 gtk_toggle_button_set_active (toggle_button, FALSE);
253} 271}
254 272
255GtkTreeRowReference * 273
274/**
275 *
276 */
277static GtkTreeRowReference *
256get_ns_selected_row (GtkTreeView * tree) 278get_ns_selected_row (GtkTreeView * tree)
257{ 279{
258 GtkTreeSelection *sel; 280 GtkTreeSelection *sel;
@@ -273,6 +295,10 @@ get_ns_selected_row (GtkTreeView * tree)
273 return ref; 295 return ref;
274} 296}
275 297
298
299/**
300 *
301 */
276gboolean 302gboolean
277namespace_selector_treeview_button_press_event_cb (GtkWidget * widget, 303namespace_selector_treeview_button_press_event_cb (GtkWidget * widget,
278 GdkEvent * event, 304 GdkEvent * event,
@@ -292,6 +318,10 @@ namespace_selector_treeview_button_press_event_cb (GtkWidget * widget,
292 return FALSE; 318 return FALSE;
293} 319}
294 320
321
322/**
323 *
324 */
295gboolean 325gboolean
296namespace_selector_treeview_button_release_event_cb (GtkWidget * widget, 326namespace_selector_treeview_button_release_event_cb (GtkWidget * widget,
297 GdkEvent * event, 327 GdkEvent * event,
@@ -323,7 +353,6 @@ namespace_selector_treeview_button_release_event_cb (GtkWidget * widget,
323} 353}
324 354
325 355
326
327/** 356/**
328 * Add pseudonym data to tree store 357 * Add pseudonym data to tree store
329 * 358 *
@@ -389,8 +418,12 @@ add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym,
389 else 418 else
390 description = NULL; 419 description = NULL;
391 } 420 }
392 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1, 421 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT,
393 nsid, 2, root, 3, description, -1); 422 0, ns_name,
423 1, nsid,
424 2, root,
425 3, description,
426 -1);
394 GNUNET_free (ns_name); 427 GNUNET_free (ns_name);
395 GNUNET_free_non_null (root); 428 GNUNET_free_non_null (root);
396 GNUNET_free_non_null (description); 429 GNUNET_free_non_null (description);
@@ -398,17 +431,20 @@ add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym,
398} 431}
399 432
400 433
434/**
435 * Startup hook to initialize the namespace dropdown widget.
436 *
437 * @param widget the main window
438 * @param user_data the builder for the main window
439 */
401void 440void
402GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data) 441GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data)
403{ 442{
443 GtkBuilder *builder = GTK_BUILDER (user_data);
404 GtkTreeIter iter; 444 GtkTreeIter iter;
405 GtkTreeView *namespace_tree;
406 GtkTreeStore *namespace_treestore; 445 GtkTreeStore *namespace_treestore;
407 GtkBuilder *builder;
408 GtkWidget *namespace_selector_window;
409
410 builder = GTK_BUILDER (user_data);
411 446
447 /* FIXME: can't we do the button initialization when we create the main window? */
412 /* Make sure button class is realized */ 448 /* Make sure button class is realized */
413 g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON)); 449 g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON));
414 /* GNUnet main window assumes that images on buttons are visible, 450 /* 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)
416 */ 452 */
417 g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL); 453 g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL);
418 454
419 namespace_treestore = 455 /* setup namespace treestore */
456 {
457 namespace_treestore =
420 GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object 458 GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object
421 ("main_window_search_namespace_treestore")); 459 ("main_window_search_namespace_treestore"));
422 namespace_tree = 460
423 GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object 461 /* FIXME: find a way to manage pseudonyms.
424 ("namespace_selector_treeview")); 462 * Right now the list will be filled with ALL and ANY pseudonyms that we
425 463 * find, these are held as files in a special directory.
426 /* FIXME: find a way to manage pseudonyms. 464 * I don't see an easy way to ignore certain pseudonyms in that directory,
427 * Right now the list will be filled with ALL and ANY pseudonyms that we 465 * and that require for pseudonym management. Also, pseudonyms are presented
428 * find, these are held as files in a special directory. 466 * in arbitrary order. We must either sort them (by name?) or let the user
429 * I don't see an easy way to ignore certain pseudonyms in that directory, 467 * drag them around to change the order in which they appear in the list.
430 * and that require for pseudonym management. Also, pseudonyms are presented 468 * All that is not possible with a simple "files in a directory" concept.
431 * in arbitrary order. We must either sort them (by name?) or let the user 469 */
432 * drag them around to change the order in which they appear in the list. 470 gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, G_MAXINT,
433 * All that is not possible with a simple "files in a directory" concept. 471 0, "Any", 1, NULL, 2, "", 3,
434 */ 472 "Do not search in any particular namespace",
435 gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, G_MAXINT, 473 -1);
436 0, "Any", 1, NULL, 2, "", 3, 474 /* FIXME: when do we unregister? */
437 "Do not search in any particular namespace", 475 GNUNET_PSEUDONYM_discovery_callback_register (GNUNET_FS_GTK_get_configuration (),
438 -1); 476 &add_namespace_to_ts,
439 /* 477 namespace_treestore);
440 * GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (), 478 }
441 * &add_namespace_to_ts, namespace_treestore);
442 */
443 /* FIXME: when do we unregister? */
444 GNUNET_PSEUDONYM_discovery_callback_register (GNUNET_FS_GTK_get_configuration (),
445 &add_namespace_to_ts,
446 namespace_treestore);
447 479
448 /* FIXME: read currently selected namespace from somewhere instead of selecting 0th item */ 480 /* select the first item and update the label */
481 /* FIXME: is this even necessary? If the first item is "Any", we can
482 just have the label have the right default, or not? */
449 if (gtk_tree_model_get_iter_first 483 if (gtk_tree_model_get_iter_first
450 (GTK_TREE_MODEL (namespace_treestore), &iter)) 484 (GTK_TREE_MODEL (namespace_treestore), &iter))
451 { 485 {
452 gchar *value; 486 gchar *value;
453 GtkLabel *sel_namespace_label; 487 GtkLabel *sel_namespace_label;
454 GtkTreePath *treepath = gtk_tree_path_new_first (); 488 GtkTreePath *treepath = gtk_tree_path_new_first ();
489 GtkTreeView *namespace_tree;
455 490
491 namespace_tree =
492 GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
493 ("namespace_selector_treeview"));
456 gtk_tree_selection_select_iter (gtk_tree_view_get_selection 494 gtk_tree_selection_select_iter (gtk_tree_view_get_selection
457 (namespace_tree), &iter); 495 (namespace_tree), &iter);
458 sel_namespace_label = 496 sel_namespace_label =
@@ -463,13 +501,16 @@ GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data)
463 gtk_tree_path_free (treepath); 501 gtk_tree_path_free (treepath);
464 } 502 }
465 503
466 /* How the window (to trigger certain events) and immediately hide it */ 504 /* show the window (to trigger certain events) and immediately hide it */
467 namespace_selector_window = 505 {
506 GtkWidget *namespace_selector_window;
507
508 namespace_selector_window =
468 GTK_WIDGET (gtk_builder_get_object 509 GTK_WIDGET (gtk_builder_get_object
469 (builder, "namespace_selector_window")); 510 (builder, "namespace_selector_window"));
470 gtk_widget_show (namespace_selector_window); 511 gtk_widget_show (namespace_selector_window);
471 gtk_widget_hide (namespace_selector_window); 512 gtk_widget_hide (namespace_selector_window);
472 513 }
473} 514}
474 515
475 516