aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk.c')
-rw-r--r--src/fs/gnunet-fs-gtk.c417
1 files changed, 4 insertions, 413 deletions
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)