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.c138
1 files changed, 122 insertions, 16 deletions
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index 3223ec7b..d5a6cb52 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -137,7 +137,9 @@ main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *toggle
137 gboolean active; 137 gboolean active;
138 GtkBuilder *builder = GTK_BUILDER (user_data); 138 GtkBuilder *builder = GTK_BUILDER (user_data);
139 GtkWidget *namespace_selector_window; 139 GtkWidget *namespace_selector_window;
140 GtkWidget *namespace_selector_treeview;
140 namespace_selector_window = GTK_WIDGET (gtk_builder_get_object (builder, "namespace_selector_window")); 141 namespace_selector_window = GTK_WIDGET (gtk_builder_get_object (builder, "namespace_selector_window"));
142 namespace_selector_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "namespace_selector_treeview"));
141 g_object_get (G_OBJECT (togglebutton), "active", &active, NULL); 143 g_object_get (G_OBJECT (togglebutton), "active", &active, NULL);
142 if (active) 144 if (active)
143 { 145 {
@@ -162,10 +164,14 @@ main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *toggle
162 164
163 gtk_window_move (GTK_WINDOW (namespace_selector_window), popup_x, popup_y); 165 gtk_window_move (GTK_WINDOW (namespace_selector_window), popup_x, popup_y);
164 166
165 gtk_widget_show (namespace_selector_window); 167 gtk_widget_show_all (namespace_selector_window);
168 gtk_widget_grab_focus (namespace_selector_treeview);
166 } 169 }
167 else 170 else
171 {
168 gtk_widget_hide (namespace_selector_window); 172 gtk_widget_hide (namespace_selector_window);
173 gtk_widget_grab_focus (GTK_WIDGET (togglebutton));
174 }
169} 175}
170 176
171gboolean 177gboolean
@@ -314,18 +320,26 @@ namespace_selector_treeview_cursor_changed_cb (GtkWidget *widget,
314 GtkBuilder *builder; 320 GtkBuilder *builder;
315 GtkToggleButton *toggle_button; 321 GtkToggleButton *toggle_button;
316 GtkLabel *sel_namespace_label; 322 GtkLabel *sel_namespace_label;
323 GtkTreeModel *model;
317 gchar *value; 324 gchar *value;
318 GtkTreePath *treepath; 325 GtkTreePath *treepath;
326 GtkTreeRowReference *ref, *old;
319 327
320 builder = GTK_BUILDER (user_data); 328 builder = GTK_BUILDER (user_data);
321 329
322 if (!get_selected_namespace_treepath_iter_model_widget (builder, &treepath, NULL, NULL, NULL))
323 return;
324
325 toggle_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "main_window_search_namespace_dropdown_button")); 330 toggle_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "main_window_search_namespace_dropdown_button"));
326 if (!toggle_button) 331 if (!toggle_button)
327 return; 332 return;
328 333
334 if (!get_selected_namespace_treepath_iter_model_widget (builder, &treepath, NULL, &model, NULL))
335 return;
336 ref = gtk_tree_row_reference_new (model, treepath);
337 old = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
338 if (old)
339 gtk_tree_row_reference_free (old);
340 g_object_set_data (G_OBJECT (toggle_button), "selected-row-reference", ref);
341
342
329 sel_namespace_label = GTK_LABEL (gtk_builder_get_object (builder, "main_window_search_selected_namespace_label")); 343 sel_namespace_label = GTK_LABEL (gtk_builder_get_object (builder, "main_window_search_selected_namespace_label"));
330 if (!sel_namespace_label) 344 if (!sel_namespace_label)
331 return; 345 return;
@@ -340,6 +354,72 @@ namespace_selector_treeview_cursor_changed_cb (GtkWidget *widget,
340 gtk_toggle_button_set_active (toggle_button, FALSE); 354 gtk_toggle_button_set_active (toggle_button, FALSE);
341} 355}
342 356
357GtkTreeRowReference *
358get_ns_selected_row (GtkTreeView *tree)
359{
360 GtkTreeSelection *sel;
361 GList *rows, *row;
362 GtkTreeModel *model;
363 GtkTreeRowReference *ref = NULL;
364
365 sel = gtk_tree_view_get_selection (tree);
366 rows = gtk_tree_selection_get_selected_rows (sel, &model);
367 for (row = rows; row; row = row->next)
368 {
369 ref = gtk_tree_row_reference_new (model, row->data);
370 if (ref != NULL)
371 break;
372 }
373 g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
374 g_list_free (rows);
375 return ref;
376}
377
378gboolean
379namespace_selector_treeview_button_press_event_cb (GtkWidget *widget,
380 GdkEvent *event, gpointer user_data)
381{
382 GtkTreeRowReference *ref = NULL;
383
384 ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
385 if (ref != NULL)
386 {
387 gpointer old = g_object_get_data (G_OBJECT (widget), "pushed-rowreference");
388 if (old)
389 gtk_tree_row_reference_free (old);
390 g_object_set_data (G_OBJECT (widget), "pushed-rowreference", ref);
391 }
392 return FALSE;
393}
394
395gboolean
396namespace_selector_treeview_button_release_event_cb (GtkWidget *widget,
397 GdkEvent *event, gpointer user_data)
398{
399 GtkTreeRowReference *ref = NULL;
400 gpointer old = g_object_get_data (G_OBJECT (widget), "pushed-rowreference");
401
402 ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
403 if (ref && old)
404 {
405 GtkTreePath *path_ref, *path_old;
406 path_ref = gtk_tree_row_reference_get_path (ref);
407 path_old = gtk_tree_row_reference_get_path (old);
408 if (gtk_tree_path_compare (path_ref, path_old) == 0)
409 namespace_selector_treeview_cursor_changed_cb (widget, user_data);
410 if (path_ref)
411 gtk_tree_path_free (path_ref);
412 if (path_old)
413 gtk_tree_path_free (path_old);
414 }
415 if (ref)
416 gtk_tree_row_reference_free (ref);
417 if (old)
418 gtk_tree_row_reference_free (old);
419 g_object_set_data (G_OBJECT (widget), "pushed-rowreference", NULL);
420 return FALSE;
421}
422
343void 423void
344main_window_search_button_clicked_cb (GtkButton *button, gpointer user_data) 424main_window_search_button_clicked_cb (GtkButton *button, gpointer user_data)
345{ 425{
@@ -350,17 +430,23 @@ main_window_search_button_clicked_cb (GtkButton *button, gpointer user_data)
350 GtkTreeModel *mime_model; 430 GtkTreeModel *mime_model;
351 GtkEntry *query_entry; 431 GtkEntry *query_entry;
352 guint anonymity_level; 432 guint anonymity_level;
433 GtkTreeRowReference *ref = NULL;
353 GtkTreeIter iter; 434 GtkTreeIter iter;
435 GtkToggleButton *toggle_button;
354 const char *entry_keywords; 436 const char *entry_keywords;
355 gchar *keywords; 437 gchar *keywords;
356 gchar *mime_keyword; 438 gchar *mime_keyword;
357 439
358 GNUNET_HashCode *nsid = NULL; 440 GNUNET_HashCode *nsid = NULL;
359 struct GNUNET_FS_Uri *uri; 441 struct GNUNET_FS_Uri *uri;
442 gchar *root = NULL;
360 char *emsg; 443 char *emsg;
361 444
362 builder = GTK_BUILDER (user_data); 445 builder = GTK_BUILDER (user_data);
363 446
447 toggle_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder,
448 "main_window_search_namespace_dropdown_button"));
449
364 if (!get_selected_anonymity_level (builder, &anonymity_level)) 450 if (!get_selected_anonymity_level (builder, &anonymity_level))
365 return; 451 return;
366 452
@@ -372,23 +458,30 @@ main_window_search_button_clicked_cb (GtkButton *button, gpointer user_data)
372 mime_keyword = NULL; 458 mime_keyword = NULL;
373 gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1); 459 gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1);
374 } 460 }
461 if (mime_keyword == NULL)
462 mime_keyword = g_strdup ("");
375 463
376 get_selected_namespace_treepath_iter_model_widget (builder, 464 ref = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
377 &namespace_treepath, &iter, &namespace_model, NULL); 465 if (ref)
466 {
467 namespace_model = gtk_tree_row_reference_get_model (ref);
468 namespace_treepath = gtk_tree_row_reference_get_path (ref);
469 gtk_tree_model_get_iter (namespace_model, &iter, namespace_treepath);
470 }
378 471
379 query_entry = GTK_ENTRY (gtk_builder_get_object (builder, 472 query_entry = GTK_ENTRY (gtk_builder_get_object (builder,
380 "main_window_search_entry")); 473 "main_window_search_entry"));
381 474
382 entry_keywords = gtk_entry_get_text (query_entry);
383 if (mime_keyword != NULL)
384 {
385 keywords = g_strdup_printf ("%s %s", entry_keywords, mime_keyword);
386 g_free (mime_keyword);
387 }
388 else
389 keywords = g_strdup (entry_keywords);
390 if (namespace_treepath != NULL) 475 if (namespace_treepath != NULL)
391 gtk_tree_model_get (namespace_model, &iter, 1, &nsid, -1); 476 gtk_tree_model_get (namespace_model, &iter, 1, &nsid, 2, &root, -1);
477 if (root == NULL)
478 root = g_strdup ("");
479
480 entry_keywords = gtk_entry_get_text (query_entry);
481
482 keywords = g_strdup_printf ("%s %s %s", entry_keywords, mime_keyword, root);
483 g_free (mime_keyword);
484 g_free (root);
392 if (nsid != NULL) 485 if (nsid != NULL)
393 { 486 {
394 uri = GNUNET_FS_uri_sks_create_from_nsid (nsid, keywords); 487 uri = GNUNET_FS_uri_sks_create_from_nsid (nsid, keywords);
@@ -487,11 +580,25 @@ GNUNET_GTK_main_window_realize_cb (GtkWidget *widget, gpointer user_data)
487 namespace_tree = GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object 580 namespace_tree = GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
488 ("namespace_selector_treeview")); 581 ("namespace_selector_treeview"));
489 582
583 /* FIXME: find a way to manage pseudonyms.
584 * Right now the list will be filled with ALL and ANY pseudonyms that we
585 * find, these are held as files in a special directory.
586 * I don't see an easy way to ignore certain pseudonyms in that directory,
587 * and that require for pseudonym management. Also, pseudonyms are presented
588 * in arbitrary order. We must either sort them (by name?) or let the user
589 * drag them around to change the order in which they appear in the list.
590 * All that is not possible with a simple "files in a directory" concept.
591 */
490 gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, 592 gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL,
491 G_MAXINT, 0, "Any", 1, NULL, 2, "", 3, 593 G_MAXINT, 0, "Any", 1, NULL, 2, "", 3,
492 "Do not search in any particular namespace", -1); 594 "Do not search in any particular namespace", -1);
595 /*
493 GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (), 596 GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (),
494 &add_namespace_to_ts, namespace_treestore); 597 &add_namespace_to_ts, namespace_treestore);
598 */
599 GNUNET_PSEUDONYM_discovery_callback_register (
600 GNUNET_FS_GTK_get_configuration (),
601 &add_namespace_to_ts, namespace_treestore);
495 602
496 /* FIXME: read currently selected namespace from somewhere instead of selecting 0th item */ 603 /* FIXME: read currently selected namespace from somewhere instead of selecting 0th item */
497 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (namespace_treestore), &iter)) 604 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (namespace_treestore), &iter))
@@ -581,7 +688,6 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
581 688
582} 689}
583 690
584
585int 691int
586main (int argc, char *const *argv) 692main (int argc, char *const *argv)
587{ 693{