aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-01 17:27:02 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-01 17:27:02 +0000
commit6d84b835ac980f4afa7937578f27eab3b63a41f7 (patch)
treea3e2a653319825e8d6c798d626f3d58062b333e0
parent3645d81a7252ceff6748fbe2f03be06e2e266f46 (diff)
downloadgnunet-gtk-6d84b835ac980f4afa7937578f27eab3b63a41f7.tar.gz
gnunet-gtk-6d84b835ac980f4afa7937578f27eab3b63a41f7.zip
-moving code around
-rw-r--r--src/fs/Makefile.am3
-rw-r--r--src/fs/gnunet-fs-gtk-about.c3
-rw-r--r--src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c115
-rw-r--r--src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h50
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_namespace.c349
-rw-r--r--src/fs/gnunet-fs-gtk.c417
-rw-r--r--src/include/gnunet_gtk.h13
-rw-r--r--src/lib/glade.c34
8 files changed, 566 insertions, 418 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 6fe1c6e1..3db3ffed 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -15,12 +15,13 @@ gnunet_fs_gtk_SOURCES = \
15 gnunet-fs-gtk-download.c gnunet-fs-gtk-download.h \ 15 gnunet-fs-gtk-download.c gnunet-fs-gtk-download.h \
16 gnunet-fs-gtk-edit_publish_dialog.c gnunet-fs-gtk-edit_publish_dialog.h \ 16 gnunet-fs-gtk-edit_publish_dialog.c gnunet-fs-gtk-edit_publish_dialog.h \
17 gnunet-fs-gtk-event_handler.c gnunet-fs-gtk-event_handler.h \ 17 gnunet-fs-gtk-event_handler.c gnunet-fs-gtk-event_handler.h \
18 gnunet-fs-gtk-anonymity_spin_buttons.c \ 18 gnunet-fs-gtk-anonymity_spin_buttons.c gnunet-fs-gtk-anonymity_spin_buttons.h \
19 gnunet-fs-gtk-main_window_meta_data_context_menu.c \ 19 gnunet-fs-gtk-main_window_meta_data_context_menu.c \
20 gnunet-fs-gtk.c gnunet-fs-gtk.h \ 20 gnunet-fs-gtk.c gnunet-fs-gtk.h \
21 gnunet-fs-gtk-main_window_create_pseudonym.c \ 21 gnunet-fs-gtk-main_window_create_pseudonym.c \
22 gnunet-fs-gtk-main_window_file_download.c \ 22 gnunet-fs-gtk-main_window_file_download.c \
23 gnunet-fs-gtk-main_window_file_publish.c \ 23 gnunet-fs-gtk-main_window_file_publish.c \
24 gnunet-fs-gtk-main_window_namespace.c \
24 gnunet-fs-gtk-main_window_open_directory.c \ 25 gnunet-fs-gtk-main_window_open_directory.c \
25 gnunet-fs-gtk-main_window_adv_pseudonym.c \ 26 gnunet-fs-gtk-main_window_adv_pseudonym.c \
26 gnunet-fs-gtk-main_window_view_toggles.c 27 gnunet-fs-gtk-main_window_view_toggles.c
diff --git a/src/fs/gnunet-fs-gtk-about.c b/src/fs/gnunet-fs-gtk-about.c
index 4c7701bd..36e0d115 100644
--- a/src/fs/gnunet-fs-gtk-about.c
+++ b/src/fs/gnunet-fs-gtk-about.c
@@ -30,6 +30,9 @@
30 30
31/** 31/**
32 * This displays an about window 32 * This displays an about window
33 *
34 * @param widget widget creating the event, unused
35 * @param data global builder, unused
33 */ 36 */
34void 37void
35GNUNET_GTK_main_menu_help_about_activate_cb (GtkWidget * dummy, gpointer data) 38GNUNET_GTK_main_menu_help_about_activate_cb (GtkWidget * dummy, gpointer data)
diff --git a/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c b/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c
index bf53e859..94829429 100644
--- a/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c
+++ b/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.c
@@ -21,15 +21,17 @@
21/** 21/**
22 * @file src/fs/gnunet-fs-gtk-anonymtiy_spin_buttons.c 22 * @file src/fs/gnunet-fs-gtk-anonymtiy_spin_buttons.c
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * 24 * @brief operations to manage user's anonymity level selections
25 * This file contains callbacks to turn spin buttons red when the
26 * value reaches zero.
27 */ 25 */
28#include "gnunet-fs-gtk-common.h" 26#include "gnunet-fs-gtk-common.h"
29#include <gdk/gdk.h> 27#include <gdk/gdk.h>
30 28
31/** 29/**
32 * Spin button is changed, update its colour. 30 * Spin button is changed, update its color. NOTE: This function will eventually
31 * become obsolete as we migrate to the drop-down style of anonymity-level selection.
32 *
33 * @param w the spin button that changed
34 * @param builder's closure, unused
33 */ 35 */
34void 36void
35GNUNET_GTK_anonymity_spin_button_value_changed_cb (GtkWidget * w, gpointer data) 37GNUNET_GTK_anonymity_spin_button_value_changed_cb (GtkWidget * w, gpointer data)
@@ -69,4 +71,109 @@ GNUNET_GTK_anonymity_spin_button_value_changed_cb (GtkWidget * w, gpointer data)
69} 71}
70 72
71 73
74
75gboolean
76GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
77 gchar * combo_name, guint * p_level)
78{
79 GtkComboBox *combo;
80 GtkTreeIter iter;
81 GtkTreeModel *model;
82 guint level;
83
84 combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
85 if (!combo)
86 return FALSE;
87
88 if (!gtk_combo_box_get_active_iter (combo, &iter))
89 return FALSE;
90
91 model = gtk_combo_box_get_model (combo);
92 if (!model)
93 return FALSE;
94
95 gtk_tree_model_get (model, &iter, 1, &level, -1);
96 if (p_level)
97 *p_level = level;
98 return TRUE;
99}
100
101gboolean
102GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level)
103{
104 GtkTreeIter iter;
105 GtkTreeModel *model;
106 guint level;
107
108 if (!gtk_combo_box_get_active_iter (combo, &iter))
109 return FALSE;
110
111 model = gtk_combo_box_get_model (combo);
112 if (!model)
113 return FALSE;
114
115 gtk_tree_model_get (model, &iter, 1, &level, -1);
116 if (p_level)
117 *p_level = level;
118 return TRUE;
119}
120
121gboolean
122GNUNET_GTK_select_anonymity_level (GtkBuilder * builder, gchar * combo_name,
123 guint sel_level)
124{
125 GtkComboBox *combo;
126 GtkTreeIter iter;
127 GtkTreeModel *model;
128 guint level;
129 gboolean go_on;
130
131 combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
132 if (!combo)
133 return FALSE;
134
135 model = gtk_combo_box_get_model (combo);
136 if (!model)
137 return FALSE;
138
139 for (go_on = gtk_tree_model_get_iter_first (model, &iter); go_on;
140 go_on = gtk_tree_model_iter_next (model, &iter))
141 {
142 gtk_tree_model_get (model, &iter, 1, &level, -1);
143 if (level == sel_level)
144 {
145 gtk_combo_box_set_active_iter (combo, &iter);
146 return TRUE;
147 }
148 }
149 return FALSE;
150}
151
152gboolean
153GNUNET_GTK_select_anonymity_combo_level (GtkComboBox *combo, guint sel_level)
154{
155 GtkTreeIter iter;
156 GtkTreeModel *model;
157 guint level;
158 gboolean go_on;
159
160 model = gtk_combo_box_get_model (combo);
161 if (!model)
162 return FALSE;
163
164 for (go_on = gtk_tree_model_get_iter_first (model, &iter); go_on;
165 go_on = gtk_tree_model_iter_next (model, &iter))
166 {
167 gtk_tree_model_get (model, &iter, 1, &level, -1);
168 if (level == sel_level)
169 {
170 gtk_combo_box_set_active_iter (combo, &iter);
171 return TRUE;
172 }
173 }
174 return FALSE;
175}
176
177
178
72/* end of gnunet-fs-gtk-anonymtiy_spin_buttons.c */ 179/* end of gnunet-fs-gtk-anonymtiy_spin_buttons.c */
diff --git a/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h b/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h
new file mode 100644
index 00000000..0d4e2dac
--- /dev/null
+++ b/src/fs/gnunet-fs-gtk-anonymity_spin_buttons.h
@@ -0,0 +1,50 @@
1/*
2 This file is part of GNUnet
3 (C) 2005, 2006, 2010 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/fs/gnunet-fs-gtk-anonymtiy_spin_buttons.c
23 * @author Christian Grothoff
24 * @brief operations to manage user's anonymity level selections
25 */
26#ifndef GNUNET_FS_GTK_ANONYMITY_SPIN_BUTTONS_H
27#define GNUNET_FS_GTK_ANONYMITY_SPIN_BUTTONS_H
28
29#include "gnunet-fs-gtk-common.h"
30#include <gdk/gdk.h>
31
32
33gboolean
34GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
35 gchar * combo_name, guint * p_level);
36
37
38gboolean
39GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level);
40
41
42
43gboolean
44GNUNET_GTK_select_anonymity_level (GtkBuilder * builder, gchar * combo_name,
45 guint sel_level);
46
47gboolean
48GNUNET_GTK_select_anonymity_combo_level (GtkComboBox *combo, guint sel_level);
49
50#endif
diff --git a/src/fs/gnunet-fs-gtk-main_window_namespace.c b/src/fs/gnunet-fs-gtk-main_window_namespace.c
new file mode 100644
index 00000000..b2ca9b42
--- /dev/null
+++ b/src/fs/gnunet-fs-gtk-main_window_namespace.c
@@ -0,0 +1,349 @@
1/*
2 This file is part of GNUnet
3 (C) 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/fs/gnunet-fs-gtk-main_window_namespace.c
23 * @author Christian Grothoff
24 * @brief event handlers for the namespace selection dropdown box in the main window
25 */
26#include "gnunet-fs-gtk-common.h"
27#include <gdk/gdk.h>
28
29
30void
31main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *
32 togglebutton,
33 gpointer user_data)
34{
35 GtkBuilder *builder = GTK_BUILDER (user_data);
36 gboolean active;
37 GtkWidget *namespace_selector_window;
38 GtkWidget *namespace_selector_treeview;
39
40 namespace_selector_window =
41 GTK_WIDGET (gtk_builder_get_object
42 (builder, "namespace_selector_window"));
43 namespace_selector_treeview =
44 GTK_WIDGET (gtk_builder_get_object
45 (builder, "namespace_selector_treeview"));
46 g_object_get (G_OBJECT (togglebutton), "active", &active, NULL);
47 if (active)
48 {
49 GtkAllocation togglebutton_allocation;
50 GdkWindow *main_window_gdk;
51 gint mwg_x, mwg_y, tgb_x, tgb_y, popup_x, popup_y;
52
53 gtk_widget_get_allocation (GTK_WIDGET (togglebutton),
54 &togglebutton_allocation);
55
56 main_window_gdk = gtk_widget_get_window (GTK_WIDGET (togglebutton));
57
58 gdk_window_get_origin (main_window_gdk, &mwg_x, &mwg_y);
59
60 /* FIXME: this might become a problem in other window managers,
61 * where reference point is not in the top-left corner.
62 * We want to show the window below the button.
63 */
64 tgb_x = mwg_x + togglebutton_allocation.x;
65 tgb_y = mwg_y + togglebutton_allocation.y;
66 popup_x = tgb_x;
67 popup_y = tgb_y + togglebutton_allocation.height;
68
69 gtk_window_move (GTK_WINDOW (namespace_selector_window), popup_x, popup_y);
70
71 gtk_widget_show_all (namespace_selector_window);
72 gtk_widget_grab_focus (namespace_selector_treeview);
73 }
74 else
75 {
76 gtk_widget_hide (namespace_selector_window);
77 gtk_widget_grab_focus (GTK_WIDGET (togglebutton));
78 }
79}
80
81
82gboolean
83namespace_selector_window_leave_timeout_cb (gpointer user_data)
84{
85 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data);
86
87 /* This will eventually hide the namespace selector */
88 gtk_toggle_button_set_active (toggle_button, FALSE);
89 return FALSE;
90}
91
92
93gboolean
94main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget *
95 widget,
96 GdkEvent *
97 event,
98 gpointer
99 user_data)
100{
101 if (namespace_selector_window_leave_timeout_source > 0)
102 g_source_remove (namespace_selector_window_leave_timeout_source);
103 return FALSE;
104}
105
106
107gboolean
108namespace_selector_window_leave_notify_event_cb (GtkWidget * widget,
109 GdkEvent * event,
110 gpointer user_data)
111{
112 GtkBuilder *builder;
113 GtkToggleButton *toggle_button;
114 guint timeout_id;
115
116 builder = GTK_BUILDER (user_data);
117
118 toggle_button =
119 GTK_TOGGLE_BUTTON (gtk_builder_get_object
120 (builder,
121 "main_window_search_namespace_dropdown_button"));
122
123 /* Place a timeout to hide the window. It will be cancelled if the cursor
124 * enters the namespace selector window or the toggle button within 100ms.
125 */
126 timeout_id =
127 g_timeout_add (100, &namespace_selector_window_leave_timeout_cb,
128 toggle_button);
129 if (namespace_selector_window_leave_timeout_source > 0)
130 g_source_remove (namespace_selector_window_leave_timeout_source);
131 namespace_selector_window_leave_timeout_source = timeout_id;
132
133 return FALSE;
134}
135
136
137static gboolean
138GNUNET_GTK_get_tree_string (GtkTreeView * treeview, GtkTreePath * treepath,
139 guint column, gchar ** value)
140{
141 gboolean ok;
142 GtkTreeModel *model;
143
144 model = gtk_tree_view_get_model (treeview);
145 if (!model)
146 return FALSE;
147
148 GtkTreeIter iter;
149
150 ok = gtk_tree_model_get_iter (model, &iter, treepath);
151 if (!ok)
152 return FALSE;
153
154 *value = NULL;
155 gtk_tree_model_get (model, &iter, column, value, -1);
156 if (*value == NULL)
157 return FALSE;
158 return TRUE;
159}
160
161
162
163gboolean
164get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder,
165 GtkTreePath ** p_treepath,
166 GtkTreeIter * p_iter,
167 GtkTreeModel ** p_model,
168 GtkWidget ** p_widget)
169{
170 GtkTreeSelection *selection;
171 GtkTreeModel *model;
172 GList *selected;
173 GtkTreePath *treepath;
174 GtkWidget *widget;
175
176 widget =
177 GTK_WIDGET (gtk_builder_get_object
178 (builder, "namespace_selector_treeview"));
179 if (!widget)
180 return FALSE;
181
182 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
183 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
184 if (!selection || !model)
185 return FALSE;
186
187 selected = gtk_tree_selection_get_selected_rows (selection, NULL);
188 if (!selected)
189 return FALSE;
190 if (selected->data == NULL)
191 {
192 g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
193 g_list_free (selected);
194 return FALSE;
195 }
196 /* Free everything except the first path, keep it */
197 treepath = (GtkTreePath *) selected->data;
198 selected = g_list_remove (selected, selected->data);
199 g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
200 g_list_free (selected);
201
202 if (p_iter && !gtk_tree_model_get_iter (model, p_iter, treepath))
203 {
204 gtk_tree_path_free (treepath);
205 return FALSE;
206 }
207 *p_treepath = treepath;
208 if (p_model)
209 *p_model = model;
210 if (p_widget)
211 *p_widget = widget;
212 return TRUE;
213}
214
215void
216namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget,
217 gpointer user_data)
218{
219 GtkBuilder *builder;
220 GtkToggleButton *toggle_button;
221 GtkLabel *sel_namespace_label;
222 GtkTreeModel *model;
223 gchar *value;
224 GtkTreePath *treepath;
225 GtkEntry *search_entry;
226 GtkTreeRowReference *ref, *old;
227
228 builder = GTK_BUILDER (user_data);
229
230 toggle_button =
231 GTK_TOGGLE_BUTTON (gtk_builder_get_object
232 (builder,
233 "main_window_search_namespace_dropdown_button"));
234 if (!toggle_button)
235 return;
236
237 search_entry =
238 GTK_ENTRY (gtk_builder_get_object (builder, "main_window_search_entry"));
239 if (!search_entry)
240 return;
241
242 if (!get_selected_namespace_treepath_iter_model_widget
243 (builder, &treepath, NULL, &model, NULL))
244 return;
245 ref = gtk_tree_row_reference_new (model, treepath);
246 old = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
247 if (old)
248 gtk_tree_row_reference_free (old);
249 g_object_set_data (G_OBJECT (toggle_button), "selected-row-reference", ref);
250
251
252 sel_namespace_label =
253 GTK_LABEL (gtk_builder_get_object
254 (builder, "main_window_search_selected_namespace_label"));
255 if (!sel_namespace_label)
256 return;
257
258 if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 0, &value)
259 && value != NULL)
260 {
261 gtk_label_set_text (sel_namespace_label, value);
262 g_free (value);
263 }
264 if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 2, &value)
265 && value != NULL)
266 {
267 gtk_entry_set_text (search_entry, value);
268 g_free (value);
269 }
270
271 gtk_tree_path_free (treepath);
272
273 /* This will eventually hide the namespace selector */
274 gtk_toggle_button_set_active (toggle_button, FALSE);
275}
276
277GtkTreeRowReference *
278get_ns_selected_row (GtkTreeView * tree)
279{
280 GtkTreeSelection *sel;
281 GList *rows, *row;
282 GtkTreeModel *model;
283 GtkTreeRowReference *ref = NULL;
284
285 sel = gtk_tree_view_get_selection (tree);
286 rows = gtk_tree_selection_get_selected_rows (sel, &model);
287 for (row = rows; row; row = row->next)
288 {
289 ref = gtk_tree_row_reference_new (model, row->data);
290 if (ref != NULL)
291 break;
292 }
293 g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
294 g_list_free (rows);
295 return ref;
296}
297
298gboolean
299namespace_selector_treeview_button_press_event_cb (GtkWidget * widget,
300 GdkEvent * event,
301 gpointer user_data)
302{
303 GtkTreeRowReference *ref = NULL;
304
305 ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
306 if (ref != NULL)
307 {
308 gpointer old = g_object_get_data (G_OBJECT (widget), "pushed-rowreference");
309
310 if (old)
311 gtk_tree_row_reference_free (old);
312 g_object_set_data (G_OBJECT (widget), "pushed-rowreference", ref);
313 }
314 return FALSE;
315}
316
317gboolean
318namespace_selector_treeview_button_release_event_cb (GtkWidget * widget,
319 GdkEvent * event,
320 gpointer user_data)
321{
322 GtkTreeRowReference *ref = NULL;
323 gpointer old = g_object_get_data (G_OBJECT (widget), "pushed-rowreference");
324
325 ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
326 if (ref && old)
327 {
328 GtkTreePath *path_ref, *path_old;
329
330 path_ref = gtk_tree_row_reference_get_path (ref);
331 path_old = gtk_tree_row_reference_get_path (old);
332 if (gtk_tree_path_compare (path_ref, path_old) == 0)
333 namespace_selector_treeview_cursor_changed_cb (widget, user_data);
334 if (path_ref)
335 gtk_tree_path_free (path_ref);
336 if (path_old)
337 gtk_tree_path_free (path_old);
338 }
339 if (ref)
340 gtk_tree_row_reference_free (ref);
341 if (old)
342 gtk_tree_row_reference_free (old);
343 g_object_set_data (G_OBJECT (widget), "pushed-rowreference", NULL);
344 return FALSE;
345}
346
347
348
349/* end of gnunet-fs-gtk-main_window_namespace.c */
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index a940f459..bd292426 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include "gnunet-fs-gtk-common.h" 26#include "gnunet-fs-gtk-common.h"
27#include "gnunet-fs-gtk-event_handler.h" 27#include "gnunet-fs-gtk-event_handler.h"
28#include "gnunet-fs-gtk-anonymity_spin_buttons.h"
28#include <gdk/gdkkeysyms.h> 29#include <gdk/gdkkeysyms.h>
29 30
30/** 31/**
@@ -97,6 +98,9 @@ GNUNET_FS_GTK_get_main_window_object (const char *name)
97/** 98/**
98 * Task run on shutdown. 99 * Task run on shutdown.
99 * FIXME: does this need to be a separate task!? 100 * FIXME: does this need to be a separate task!?
101 *
102 * @param cls NULL
103 * @param tc scheduler context, unused
100 */ 104 */
101static void 105static void
102shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 106shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -124,419 +128,6 @@ GNUNET_GTK_quit_cb (GObject * object, gpointer user_data)
124} 128}
125 129
126 130
127void
128main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *
129 togglebutton,
130 gpointer user_data)
131{
132 gboolean active;
133 GtkBuilder *builder = GTK_BUILDER (user_data);
134 GtkWidget *namespace_selector_window;
135 GtkWidget *namespace_selector_treeview;
136
137 namespace_selector_window =
138 GTK_WIDGET (gtk_builder_get_object
139 (builder, "namespace_selector_window"));
140 namespace_selector_treeview =
141 GTK_WIDGET (gtk_builder_get_object
142 (builder, "namespace_selector_treeview"));
143 g_object_get (G_OBJECT (togglebutton), "active", &active, NULL);
144 if (active)
145 {
146 GtkAllocation togglebutton_allocation;
147 GdkWindow *main_window_gdk;
148 gint mwg_x, mwg_y, tgb_x, tgb_y, popup_x, popup_y;
149
150 gtk_widget_get_allocation (GTK_WIDGET (togglebutton),
151 &togglebutton_allocation);
152
153 main_window_gdk = gtk_widget_get_window (GTK_WIDGET (togglebutton));
154
155 gdk_window_get_origin (main_window_gdk, &mwg_x, &mwg_y);
156
157 /* FIXME: this might become a problem in other window managers,
158 * where reference point is not in the top-left corner.
159 * We want to show the window below the button.
160 */
161 tgb_x = mwg_x + togglebutton_allocation.x;
162 tgb_y = mwg_y + togglebutton_allocation.y;
163 popup_x = tgb_x;
164 popup_y = tgb_y + togglebutton_allocation.height;
165
166 gtk_window_move (GTK_WINDOW (namespace_selector_window), popup_x, popup_y);
167
168 gtk_widget_show_all (namespace_selector_window);
169 gtk_widget_grab_focus (namespace_selector_treeview);
170 }
171 else
172 {
173 gtk_widget_hide (namespace_selector_window);
174 gtk_widget_grab_focus (GTK_WIDGET (togglebutton));
175 }
176}
177
178gboolean
179namespace_selector_window_leave_timeout_cb (gpointer user_data)
180{
181 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data);
182
183 /* This will eventually hide the namespace selector */
184 gtk_toggle_button_set_active (toggle_button, FALSE);
185 return FALSE;
186}
187
188gboolean
189main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget *
190 widget,
191 GdkEvent *
192 event,
193 gpointer
194 user_data)
195{
196 if (namespace_selector_window_leave_timeout_source > 0)
197 g_source_remove (namespace_selector_window_leave_timeout_source);
198 return FALSE;
199}
200
201
202gboolean
203namespace_selector_window_leave_notify_event_cb (GtkWidget * widget,
204 GdkEvent * event,
205 gpointer user_data)
206{
207 GtkBuilder *builder;
208 GtkToggleButton *toggle_button;
209 guint timeout_id;
210
211 builder = GTK_BUILDER (user_data);
212
213 toggle_button =
214 GTK_TOGGLE_BUTTON (gtk_builder_get_object
215 (builder,
216 "main_window_search_namespace_dropdown_button"));
217
218 /* Place a timeout to hide the window. It will be cancelled if the cursor
219 * enters the namespace selector window or the toggle button within 100ms.
220 */
221 timeout_id =
222 g_timeout_add (100, &namespace_selector_window_leave_timeout_cb,
223 toggle_button);
224 if (namespace_selector_window_leave_timeout_source > 0)
225 g_source_remove (namespace_selector_window_leave_timeout_source);
226 namespace_selector_window_leave_timeout_source = timeout_id;
227
228 return FALSE;
229}
230
231gboolean
232GNUNET_GTK_get_tree_string (GtkTreeView * treeview, GtkTreePath * treepath,
233 guint column, gchar ** value)
234{
235 gboolean ok;
236 GtkTreeModel *model;
237
238 model = gtk_tree_view_get_model (treeview);
239 if (!model)
240 return FALSE;
241
242 GtkTreeIter iter;
243
244 ok = gtk_tree_model_get_iter (model, &iter, treepath);
245 if (!ok)
246 return FALSE;
247
248 *value = NULL;
249 gtk_tree_model_get (model, &iter, column, value, -1);
250 if (*value == NULL)
251 return FALSE;
252 return TRUE;
253}
254
255gboolean
256GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
257 gchar * combo_name, guint * p_level)
258{
259 GtkComboBox *combo;
260 GtkTreeIter iter;
261 GtkTreeModel *model;
262 guint level;
263
264 combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
265 if (!combo)
266 return FALSE;
267
268 if (!gtk_combo_box_get_active_iter (combo, &iter))
269 return FALSE;
270
271 model = gtk_combo_box_get_model (combo);
272 if (!model)
273 return FALSE;
274
275 gtk_tree_model_get (model, &iter, 1, &level, -1);
276 if (p_level)
277 *p_level = level;
278 return TRUE;
279}
280
281gboolean
282GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint *p_level)
283{
284 GtkTreeIter iter;
285 GtkTreeModel *model;
286 guint level;
287
288 if (!gtk_combo_box_get_active_iter (combo, &iter))
289 return FALSE;
290
291 model = gtk_combo_box_get_model (combo);
292 if (!model)
293 return FALSE;
294
295 gtk_tree_model_get (model, &iter, 1, &level, -1);
296 if (p_level)
297 *p_level = level;
298 return TRUE;
299}
300
301gboolean
302GNUNET_GTK_select_anonymity_level (GtkBuilder * builder, gchar * combo_name,
303 guint sel_level)
304{
305 GtkComboBox *combo;
306 GtkTreeIter iter;
307 GtkTreeModel *model;
308 guint level;
309 gboolean go_on;
310
311 combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
312 if (!combo)
313 return FALSE;
314
315 model = gtk_combo_box_get_model (combo);
316 if (!model)
317 return FALSE;
318
319 for (go_on = gtk_tree_model_get_iter_first (model, &iter); go_on;
320 go_on = gtk_tree_model_iter_next (model, &iter))
321 {
322 gtk_tree_model_get (model, &iter, 1, &level, -1);
323 if (level == sel_level)
324 {
325 gtk_combo_box_set_active_iter (combo, &iter);
326 return TRUE;
327 }
328 }
329 return FALSE;
330}
331
332gboolean
333GNUNET_GTK_select_anonymity_combo_level (GtkComboBox *combo, guint sel_level)
334{
335 GtkTreeIter iter;
336 GtkTreeModel *model;
337 guint level;
338 gboolean go_on;
339
340 model = gtk_combo_box_get_model (combo);
341 if (!model)
342 return FALSE;
343
344 for (go_on = gtk_tree_model_get_iter_first (model, &iter); go_on;
345 go_on = gtk_tree_model_iter_next (model, &iter))
346 {
347 gtk_tree_model_get (model, &iter, 1, &level, -1);
348 if (level == sel_level)
349 {
350 gtk_combo_box_set_active_iter (combo, &iter);
351 return TRUE;
352 }
353 }
354 return FALSE;
355}
356
357gboolean
358get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder,
359 GtkTreePath ** p_treepath,
360 GtkTreeIter * p_iter,
361 GtkTreeModel ** p_model,
362 GtkWidget ** p_widget)
363{
364 GtkTreeSelection *selection;
365 GtkTreeModel *model;
366 GList *selected;
367 GtkTreePath *treepath;
368 GtkWidget *widget;
369
370 widget =
371 GTK_WIDGET (gtk_builder_get_object
372 (builder, "namespace_selector_treeview"));
373 if (!widget)
374 return FALSE;
375
376 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
377 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
378 if (!selection || !model)
379 return FALSE;
380
381 selected = gtk_tree_selection_get_selected_rows (selection, NULL);
382 if (!selected)
383 return FALSE;
384 if (selected->data == NULL)
385 {
386 g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
387 g_list_free (selected);
388 return FALSE;
389 }
390 /* Free everything except the first path, keep it */
391 treepath = (GtkTreePath *) selected->data;
392 selected = g_list_remove (selected, selected->data);
393 g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
394 g_list_free (selected);
395
396 if (p_iter && !gtk_tree_model_get_iter (model, p_iter, treepath))
397 {
398 gtk_tree_path_free (treepath);
399 return FALSE;
400 }
401 *p_treepath = treepath;
402 if (p_model)
403 *p_model = model;
404 if (p_widget)
405 *p_widget = widget;
406 return TRUE;
407}
408
409void
410namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget,
411 gpointer user_data)
412{
413 GtkBuilder *builder;
414 GtkToggleButton *toggle_button;
415 GtkLabel *sel_namespace_label;
416 GtkTreeModel *model;
417 gchar *value;
418 GtkTreePath *treepath;
419 GtkEntry *search_entry;
420 GtkTreeRowReference *ref, *old;
421
422 builder = GTK_BUILDER (user_data);
423
424 toggle_button =
425 GTK_TOGGLE_BUTTON (gtk_builder_get_object
426 (builder,
427 "main_window_search_namespace_dropdown_button"));
428 if (!toggle_button)
429 return;
430
431 search_entry =
432 GTK_ENTRY (gtk_builder_get_object (builder, "main_window_search_entry"));
433 if (!search_entry)
434 return;
435
436 if (!get_selected_namespace_treepath_iter_model_widget
437 (builder, &treepath, NULL, &model, NULL))
438 return;
439 ref = gtk_tree_row_reference_new (model, treepath);
440 old = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
441 if (old)
442 gtk_tree_row_reference_free (old);
443 g_object_set_data (G_OBJECT (toggle_button), "selected-row-reference", ref);
444
445
446 sel_namespace_label =
447 GTK_LABEL (gtk_builder_get_object
448 (builder, "main_window_search_selected_namespace_label"));
449 if (!sel_namespace_label)
450 return;
451
452 if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 0, &value)
453 && value != NULL)
454 {
455 gtk_label_set_text (sel_namespace_label, value);
456 g_free (value);
457 }
458 if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 2, &value)
459 && value != NULL)
460 {
461 gtk_entry_set_text (search_entry, value);
462 g_free (value);
463 }
464
465 gtk_tree_path_free (treepath);
466
467 /* This will eventually hide the namespace selector */
468 gtk_toggle_button_set_active (toggle_button, FALSE);
469}
470
471GtkTreeRowReference *
472get_ns_selected_row (GtkTreeView * tree)
473{
474 GtkTreeSelection *sel;
475 GList *rows, *row;
476 GtkTreeModel *model;
477 GtkTreeRowReference *ref = NULL;
478
479 sel = gtk_tree_view_get_selection (tree);
480 rows = gtk_tree_selection_get_selected_rows (sel, &model);
481 for (row = rows; row; row = row->next)
482 {
483 ref = gtk_tree_row_reference_new (model, row->data);
484 if (ref != NULL)
485 break;
486 }
487 g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
488 g_list_free (rows);
489 return ref;
490}
491
492gboolean
493namespace_selector_treeview_button_press_event_cb (GtkWidget * widget,
494 GdkEvent * event,
495 gpointer user_data)
496{
497 GtkTreeRowReference *ref = NULL;
498
499 ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
500 if (ref != NULL)
501 {
502 gpointer old = g_object_get_data (G_OBJECT (widget), "pushed-rowreference");
503
504 if (old)
505 gtk_tree_row_reference_free (old);
506 g_object_set_data (G_OBJECT (widget), "pushed-rowreference", ref);
507 }
508 return FALSE;
509}
510
511gboolean
512namespace_selector_treeview_button_release_event_cb (GtkWidget * widget,
513 GdkEvent * event,
514 gpointer user_data)
515{
516 GtkTreeRowReference *ref = NULL;
517 gpointer old = g_object_get_data (G_OBJECT (widget), "pushed-rowreference");
518
519 ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
520 if (ref && old)
521 {
522 GtkTreePath *path_ref, *path_old;
523
524 path_ref = gtk_tree_row_reference_get_path (ref);
525 path_old = gtk_tree_row_reference_get_path (old);
526 if (gtk_tree_path_compare (path_ref, path_old) == 0)
527 namespace_selector_treeview_cursor_changed_cb (widget, user_data);
528 if (path_ref)
529 gtk_tree_path_free (path_ref);
530 if (path_old)
531 gtk_tree_path_free (path_old);
532 }
533 if (ref)
534 gtk_tree_row_reference_free (ref);
535 if (old)
536 gtk_tree_row_reference_free (old);
537 g_object_set_data (G_OBJECT (widget), "pushed-rowreference", NULL);
538 return FALSE;
539}
540 131
541void 132void
542main_window_search_button_clicked_cb (GtkButton * button, gpointer user_data) 133main_window_search_button_clicked_cb (GtkButton * button, gpointer user_data)
diff --git a/src/include/gnunet_gtk.h b/src/include/gnunet_gtk.h
index cbf5c966..cfd24543 100644
--- a/src/include/gnunet_gtk.h
+++ b/src/include/gnunet_gtk.h
@@ -105,6 +105,19 @@ void
105GNUNET_GTK_display_about (const char *dialogfile); 105GNUNET_GTK_display_about (const char *dialogfile);
106 106
107 107
108/**
109 * Obtain a string from a GtkTreeView's model.
110 *
111 * @param treeview treeview to inspect
112 * @param treepath path that identifies the item
113 * @param column number of the column with the string
114 * @param value where to store the string
115 * @return TRUE on success, FALSE on errors
116 */
117gboolean
118GNUNET_GTK_get_tree_string (GtkTreeView *treeview,
119 GtkTreePath *treepath,
120 guint column, gchar ** value);
108 121
109/** 122/**
110 * Create our tray icon. 123 * Create our tray icon.
diff --git a/src/lib/glade.c b/src/lib/glade.c
index 4bfb0f7c..180a808b 100644
--- a/src/lib/glade.c
+++ b/src/lib/glade.c
@@ -59,6 +59,40 @@ GNUNET_GTK_get_data_dir ()
59 59
60 60
61/** 61/**
62 * Obtain a string from a GtkTreeView's model.
63 *
64 * @param treeview treeview to inspect
65 * @param treepath path that identifies the item
66 * @param column number of the column with the string
67 * @param value where to store the string
68 * @return TRUE on success, FALSE on errors
69 */
70gboolean
71GNUNET_GTK_get_tree_string (GtkTreeView * treeview, GtkTreePath * treepath,
72 guint column, gchar ** value)
73{
74 gboolean ok;
75 GtkTreeModel *model;
76
77 model = gtk_tree_view_get_model (treeview);
78 if (!model)
79 return FALSE;
80
81 GtkTreeIter iter;
82
83 ok = gtk_tree_model_get_iter (model, &iter, treepath);
84 if (!ok)
85 return FALSE;
86
87 *value = NULL;
88 gtk_tree_model_get (model, &iter, column, value, -1);
89 if (*value == NULL)
90 return FALSE;
91 return TRUE;
92}
93
94
95/**
62 * Create an initialize a new builder based on the 96 * Create an initialize a new builder based on the
63 * GNUnet-GTK glade file. 97 * GNUnet-GTK glade file.
64 * 98 *