aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-05 16:39:39 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-05 16:39:39 +0000
commit50deae3582fb789eb1b73fe4fc6c397e0331b390 (patch)
treea0c38aa49350e15ffbd19d21c693b49bfb6b1ef9
parentb4b5aee70b665e97911adcda5c706a8e3811411a (diff)
downloadgnunet-gtk-50deae3582fb789eb1b73fe4fc6c397e0331b390.tar.gz
gnunet-gtk-50deae3582fb789eb1b73fe4fc6c397e0331b390.zip
-oops, removed wrong file
-rw-r--r--src/fs/Makefile.am2
-rw-r--r--src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c193
-rw-r--r--src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c467
3 files changed, 194 insertions, 468 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 5d2bfab6..f8096675 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -20,7 +20,7 @@ gnunet_fs_gtk_SOURCES = \
20 gnunet-fs-gtk_download-save-as.c gnunet-fs-gtk_download-save-as.h \ 20 gnunet-fs-gtk_download-save-as.c gnunet-fs-gtk_download-save-as.h \
21 gnunet-fs-gtk_event-handler.c gnunet-fs-gtk_event-handler.h \ 21 gnunet-fs-gtk_event-handler.c gnunet-fs-gtk_event-handler.h \
22 gnunet-fs-gtk_main-window-connection.c \ 22 gnunet-fs-gtk_main-window-connection.c \
23 gnunet-fs-gtk_main-window-namespace-dropdown.c \ 23 gnunet-fs-gtk_main-window-meta-data-context-menu.c \
24 gnunet-fs-gtk_main-window-search.c \ 24 gnunet-fs-gtk_main-window-search.c \
25 gnunet-fs-gtk_main-window-view-toggles.c \ 25 gnunet-fs-gtk_main-window-view-toggles.c \
26 gnunet-fs-gtk_open-directory.c \ 26 gnunet-fs-gtk_open-directory.c \
diff --git a/src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c b/src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c
new file mode 100644
index 00000000..06e58b67
--- /dev/null
+++ b/src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c
@@ -0,0 +1,193 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010, 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-meta-data-context-menu.c
23 * @brief context menu for the 'meta data' tree view in the main window
24 * @author Christian Grothoff
25 */
26#include "gnunet-fs-gtk.h"
27#include "gnunet-fs-gtk_download-save-as.h"
28#include "gnunet-fs-gtk_event-handler.h"
29#include <string.h>
30
31
32
33/**
34 * Helper function of GNUNET_GTK_FS_metadata_copy_selection_activated
35 * which copies the (selected) entries from the tree view to the
36 * GList.
37 *
38 * @param model the tree model with the data
39 * @param path unused
40 * @param iter position in the model to access
41 * @param user_data 'GList**' where we should store the types and values found
42 */
43static void
44copy_metadata_to_clipboard (GtkTreeModel * model, GtkTreePath * path,
45 GtkTreeIter * iter, gpointer user_data)
46{
47 GList **l = user_data;
48 gchar *type;
49 gchar *value;
50
51 gtk_tree_model_get (model, iter,
52 GNUNET_GTK_FS_MAIN_WINDOW_META_DATA_MC_META_TYPE_STRING,
53 &type,
54 GNUNET_GTK_FS_MAIN_WINDOW_META_DATA_MC_META_VALUE,
55 &value,
56 -1);
57 *l = g_list_prepend (*l, type);
58 *l = g_list_prepend (*l, value);
59}
60
61
62/**
63 * User activated metadata pop up menu "Copy selection" entry.
64 *
65 * @param menuitem the 'copy selection' menu item
66 * @param user_data the GtkBuilder of the main window
67 */
68void
69GNUNET_GTK_FS_metadata_copy_selection_activated (GtkMenuItem * menuitem,
70 gpointer user_data)
71{
72 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
73 GtkTreeView *tree;
74 GtkClipboard *cb;
75 GList *pairs;
76 GList *pos;
77 GList *value;
78 GList *type;
79 guint total_len;
80 gchar *s;
81 gchar *p;
82
83 tree = main_ctx->md_treeview;
84 pairs = NULL;
85 gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (tree),
86 &copy_metadata_to_clipboard, &pairs);
87 if (NULL == pairs)
88 return; /* nothing selected */
89 total_len = 0;
90 pairs = g_list_reverse (pairs);
91 for (pos = pairs; NULL != pos; pos = value->next)
92 {
93 type = pos;
94 value = pos->next;
95 GNUNET_assert (NULL != value);
96 total_len +=
97 strlen ((gchar *) type->data) + strlen ((gchar *) value->data) +
98 2 /* ": " */ + ((NULL != value->next) ? 1 : 0) /* "\n" */ ;
99 }
100 GNUNET_assert (total_len > 0);
101 total_len++; /* "\0" */
102 s = g_new0 (gchar, total_len);
103 if (NULL == s)
104 {
105 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
106 return;
107 }
108 p = s;
109 for (pos = pairs; NULL != pos; pos = value->next)
110 {
111 type = pos;
112 value = pos->next;
113 GNUNET_assert (NULL != value);
114 p = g_stpcpy (p, (gchar *) type->data);
115 p = g_stpcpy (p, ": ");
116 p = g_stpcpy (p, (gchar *) value->data);
117 if (NULL != value->next)
118 p = g_stpcpy (p, "\n");
119 }
120 g_list_foreach (pairs, (GFunc) &g_free, NULL);
121 g_list_free (pairs);
122 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
123 gtk_clipboard_set_text (cb, s, -1);
124 gtk_clipboard_store (cb);
125 g_free (s);
126}
127
128
129/**
130 * Got asked to pop up the context menu in the metadata treeview in
131 * the main window. Do it.
132 *
133 * @param button which button caused the event (0 for none)
134 * @param event_time time of the event (current time or 'event->time')
135 * @param user_data the context of the main window
136 */
137static void
138do_metadata_popup_menu (int button,
139 int event_time,
140 gpointer user_data)
141{
142 GtkMenu *menu;
143 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
144
145 menu = GTK_MENU (gtk_builder_get_object (main_ctx->builder, "metadata_popup_menu"));
146 gtk_menu_popup (menu, NULL, NULL, NULL, main_ctx, button, event_time);
147}
148
149
150/**
151 * Got a button press event on the metadata treeview in the main window.
152 * If it was a right click, pop up the context menu.
153 *
154 * @param widget the tree view widget
155 * @param user_data the gtk builder of the main window
156 */
157gboolean
158GNUNET_GTK_main_window_metadata_treeview_button_press_event_cb (GtkWidget *
159 widget,
160 GdkEventButton *
161 event,
162 gpointer
163 user_data)
164{
165 /* Ignore double-clicks and triple-clicks */
166 if ( (event->button != 3) || (event->type != GDK_BUTTON_PRESS) )
167 return FALSE;
168 do_metadata_popup_menu (event->button,
169 event->time,
170 user_data);
171 return FALSE;
172}
173
174
175/**
176 * Metadata treeview in the main window got the 'popup-menu' signal.
177 * Pop up the menu.
178 *
179 * @param widget the tree view widget
180 * @param user_data the gtk builder of the main window
181 * @return TRUE we did it
182 */
183gboolean
184GNUNET_GTK_main_window_metadata_treeview_popup_menu_cb (GtkWidget * widget,
185 gpointer user_data)
186{
187 do_metadata_popup_menu (0 /* no button */,
188 gtk_get_current_event_time (),
189 user_data);
190 return TRUE;
191}
192
193/* end of gnunet-fs-gtk_meta-data-context-menu.c */
diff --git a/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c b/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c
deleted file mode 100644
index 666f58bf..00000000
--- a/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c
+++ /dev/null
@@ -1,467 +0,0 @@
1/*
2 This file is part of GNUnet
3 (C) 2011-2013 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 3, 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-dropdown.c
23 * @author LRN
24 * @brief event handlers for the namespace selection dropdown box in the main window
25 */
26#include "gnunet-fs-gtk_common.h"
27#include "gnunet-fs-gtk.h"
28#include "gnunet-fs-gtk_event-handler.h"
29
30/**
31 * How long until we automatically hide the drop-down if the cursor is outside the bounds?
32 */
33#define AUTO_HIDE_TIMEOUT_MS 100
34
35
36/**
37 * ID of a timeout task which we schedule to close the drop-down automatically
38 * if the mouse leaves the area for a while. 0 for no such task.
39 *
40 * FIXME-BUG-MINOR: this task is not cancelled if the main window is closed while
41 * the drop-down is down.
42 */
43static guint namespace_selector_window_leave_timeout_source;
44
45
46/**
47 * The mouse has re-entered the dropdown window. Stop the
48 * timeout task that would hide the dropdown.
49 *
50 * @param widget the dropdown widget
51 * @param event the mouse-enter event
52 * @param user_data the context for the main window
53 */
54gboolean
55GNUNET_FS_GTK_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget *widget,
56 GdkEvent *event,
57 gpointer user_data)
58{
59 if (namespace_selector_window_leave_timeout_source > 0)
60 g_source_remove (namespace_selector_window_leave_timeout_source);
61 namespace_selector_window_leave_timeout_source = 0;
62 return FALSE;
63}
64
65
66/**
67 * Run when the timeout has expired. Hides the drop down window.
68 *
69 * @param user_data the toggle button which we will use to hide the dropdown
70 * @return FALSE
71 */
72static gboolean
73namespace_selector_window_leave_timeout_cb (gpointer user_data)
74{
75 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data);
76
77 /* This will eventually hide the namespace selector */
78 namespace_selector_window_leave_timeout_source = 0;
79 gtk_toggle_button_set_active (toggle_button, FALSE);
80 return FALSE;
81}
82
83
84/**
85 * The cursor has left the window. Place a timeout to hide the
86 * window. It will be cancelled if the cursor re-enters the namespace
87 * selector window or the toggle button within 100ms
88 *
89 * @param user_data the context for the main window
90 */
91gboolean
92GNUNET_FS_GTK_search_namespace_selector_window_leave_notify_event_cb (GtkWidget * widget,
93 GdkEvent * event,
94 gpointer user_data)
95{
96 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
97
98 if (namespace_selector_window_leave_timeout_source > 0)
99 g_source_remove (namespace_selector_window_leave_timeout_source);
100 namespace_selector_window_leave_timeout_source
101 = g_timeout_add (AUTO_HIDE_TIMEOUT_MS,
102 &namespace_selector_window_leave_timeout_cb,
103 main_ctx->ns_dropdown_button);
104 return FALSE;
105}
106
107
108/**
109 * Given a tree view, find out which row is currently selected.
110 *
111 * @param tree a tree view instance
112 * @return a reference to the currently selected row, or NULL for none
113 */
114static GtkTreeRowReference *
115get_selected_row_from_treeview (GtkTreeView * tree)
116{
117 GtkTreeSelection *sel;
118 GtkTreeModel *model;
119 GtkTreePath *path;
120 GtkTreeIter iter;
121 GtkTreeRowReference *ref;
122
123 sel = gtk_tree_view_get_selection (tree);
124 if (! gtk_tree_selection_get_selected (sel, &model, &iter))
125 return NULL;
126 path = gtk_tree_model_get_path (model, &iter);
127 ref = gtk_tree_row_reference_new (model, path);
128 gtk_tree_path_free (path);
129 return ref;
130}
131
132
133/**
134 * Changes were made to the selected entry in the tree view and the
135 * user clicked to confirm. Hide the drop down and display the
136 * selected entry as the new namespace label.
137 *
138 * @param main_ctx the context for the main window
139 * @param tv the tree view that was updated
140 */
141static void
142commit_changes (struct GNUNET_GTK_MainWindowContext *main_ctx,
143 GtkTreeView *tv)
144{
145 GtkTreePath *treepath;
146 gchar *value;
147
148 if (NULL != main_ctx->selected_ns_row)
149 gtk_tree_row_reference_free (main_ctx->selected_ns_row);
150 main_ctx->selected_ns_row = get_selected_row_from_treeview (tv);
151
152 treepath = gtk_tree_row_reference_get_path (main_ctx->selected_ns_row);
153 if (GNUNET_GTK_get_tree_string (tv, treepath,
154 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_NAME,
155 &value))
156 {
157 gtk_label_set_text (main_ctx->search_ns_label, (NULL != value) ? value : "");
158 g_free (value);
159 }
160 if (GNUNET_GTK_get_tree_string (tv, treepath,
161 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_ROOT,
162 &value))
163 {
164 gtk_entry_set_text (main_ctx->search_entry, (NULL != value) ? value : "");
165 g_free (value);
166 }
167 gtk_tree_path_free (treepath);
168
169 /* hide the namespace selector */
170 gtk_toggle_button_set_active (main_ctx->ns_dropdown_button, FALSE);
171}
172
173
174/**
175 * User pushed the button in the treeview. Get the selected entry
176 * and remember it in the "pushed-rowreference" of the widget.
177 * This way, we can use it when the button is released.
178 *
179 * @param widget the tree view widget
180 * @param event the push event
181 * @param user_data the context for the main window
182 * @return FALSE
183 */
184gboolean
185GNUNET_FS_GTK_namespace_selector_treeview_button_press_event_cb (GtkWidget * widget,
186 GdkEvent * event,
187 gpointer user_data)
188{
189 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
190
191 if (NULL != main_ctx->ns_selector_pushed_row)
192 gtk_tree_row_reference_free (main_ctx->ns_selector_pushed_row);
193 main_ctx->ns_selector_pushed_row = get_selected_row_from_treeview (GTK_TREE_VIEW (widget));
194 return FALSE;
195}
196
197
198/**
199 * User released the button in the treeview. Get the selected entry
200 * and update the cursor accordingly, but only if the user pushed the
201 * button down and released it in the same row.
202 *
203 * @param widget the tree view widget
204 * @param event the release event
205 * @param user_data the context for the main window
206 * @return FALSE
207 */
208gboolean
209GNUNET_FS_GTK_namespace_selector_treeview_button_release_event_cb (GtkWidget * widget,
210 GdkEvent * event,
211 gpointer user_data)
212{
213 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
214 GtkTreeRowReference *ref;
215
216 ref = get_selected_row_from_treeview (GTK_TREE_VIEW (widget));
217 if ( (NULL != ref) && (NULL != main_ctx->ns_selector_pushed_row))
218 {
219 GtkTreePath *path_ref;
220 GtkTreePath *path_old;
221
222 path_ref = gtk_tree_row_reference_get_path (ref);
223 path_old = gtk_tree_row_reference_get_path (main_ctx->ns_selector_pushed_row);
224 if (0 == gtk_tree_path_compare (path_ref, path_old))
225 commit_changes (main_ctx, GTK_TREE_VIEW (widget));
226 if (path_ref)
227 gtk_tree_path_free (path_ref);
228 if (path_old)
229 gtk_tree_path_free (path_old);
230 }
231 if (NULL != ref)
232 gtk_tree_row_reference_free (ref);
233 if (NULL != main_ctx->ns_selector_pushed_row)
234 gtk_tree_row_reference_free (main_ctx->ns_selector_pushed_row);
235 main_ctx->ns_selector_pushed_row = NULL;
236 return FALSE;
237}
238
239
240/**
241 * The toggle button that changes the visibility of the namespace dropdown
242 * list was toggled.
243 *
244 * @param togglebutton the button that toggles the namespace dropdown list
245 * @param user_data the contexxt for the main window
246 */
247void
248GNUNET_FS_GTK_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *
249 togglebutton,
250 gpointer user_data)
251{
252 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
253 gboolean active;
254 GtkAllocation togglebutton_allocation;
255 GdkWindow *main_window_gdk;
256 gint mwg_x;
257 gint mwg_y;
258 gint tgb_x;
259 gint tgb_y;
260 gint popup_x;
261 gint popup_y;
262
263 g_object_get (G_OBJECT (togglebutton), "active", &active, NULL);
264 if (! active)
265 {
266 gtk_widget_hide (main_ctx->ns_selector_window);
267 gtk_widget_grab_focus (GTK_WIDGET (togglebutton));
268 return;
269 }
270 gtk_widget_get_allocation (GTK_WIDGET (togglebutton),
271 &togglebutton_allocation);
272 main_window_gdk = gtk_widget_get_window (GTK_WIDGET (togglebutton));
273 gdk_window_get_origin (main_window_gdk, &mwg_x, &mwg_y);
274 /* show the window below the button */
275 tgb_x = mwg_x + togglebutton_allocation.x;
276 tgb_y = mwg_y + togglebutton_allocation.y;
277 popup_x = tgb_x;
278 popup_y = tgb_y + togglebutton_allocation.height;
279 gtk_window_move (GTK_WINDOW (main_ctx->ns_selector_window), popup_x, popup_y);
280 gtk_widget_show_all (main_ctx->ns_selector_window);
281 gtk_widget_grab_focus (GTK_WIDGET (main_ctx->ns_selector_treeview));
282}
283
284
285/**
286 * Add pseudonym data to tree store
287 *
288 * @param cls closure (the 'GtkListStore')
289 * @param pseudonym hash code of public key of pseudonym
290 * @param md meta data known about the pseudonym
291 * @param rating the local rating of the pseudonym
292 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
293 */
294static int
295add_namespace_to_ts (void *cls,
296 const struct GNUNET_CRYPTO_EccPublicKey *pseudonym,
297 const char *name,
298 const char *unique_name,
299 const struct GNUNET_CONTAINER_MetaData *md,
300 int rating)
301{
302 GtkTreeStore *ts = cls;
303 char *root;
304 char *ns_name;
305 char *unique_ns_name;
306 struct GNUNET_CRYPTO_EccPublicKey *nsid;
307 char *description;
308 int desc_is_a_dup;
309 char *uris;
310 char *emsg;
311 struct GNUNET_FS_Uri *uri;
312 GtkTreeIter iter;
313
314 if (rating < 0)
315 return GNUNET_OK;
316
317 GNUNET_FS_pseudonym_get_info (GNUNET_FS_GTK_get_configuration (),
318 pseudonym, NULL, NULL,
319 &ns_name, NULL);
320 unique_ns_name = GNUNET_FS_pseudonym_name_uniquify (GNUNET_FS_GTK_get_configuration (),
321 pseudonym, ns_name, NULL);
322 GNUNET_free (ns_name);
323 nsid = GNUNET_new (struct GNUNET_CRYPTO_EccPublicKey);
324 *nsid = *pseudonym;
325 root = NULL;
326 uris = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_URI);
327 if (uris != NULL)
328 {
329 emsg = NULL;
330 uri = GNUNET_FS_uri_parse (uris, &emsg);
331 if (uri == NULL)
332 GNUNET_free (emsg);
333 root = GNUNET_FS_uri_sks_get_content_id (uri);
334 GNUNET_FS_uri_destroy (uri);
335 }
336 description = GNUNET_FS_GTK_get_description_from_metadata (md, &desc_is_a_dup);
337 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT,
338 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_NAME,
339 unique_ns_name,
340 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_KEY,
341 nsid,
342 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_ROOT,
343 root,
344 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_TOOLTIP,
345 description,
346 -1);
347 GNUNET_free (unique_ns_name);
348 GNUNET_free_non_null (root);
349 GNUNET_free (description);
350 return GNUNET_OK;
351}
352
353
354void
355GNUNET_GTK_main_window_refresh_ns_list (struct GNUNET_GTK_MainWindowContext *main_ctx)
356{
357 GtkTreeIter iter;
358 GtkTreePath *treepath;
359 GtkTreeModel *model;
360 struct GNUNET_CRYPTO_EccPublicKey *key;
361 struct GNUNET_CRYPTO_EccPublicKey *selected_ns_id;
362 gboolean found;
363 gchar *value;
364
365 key = NULL;
366 if (NULL != main_ctx->selected_ns_row)
367 {
368 treepath = gtk_tree_row_reference_get_path (main_ctx->selected_ns_row);
369 model = gtk_tree_view_get_model (main_ctx->ns_selector_treeview);
370 if (gtk_tree_model_get_iter (model, &iter, treepath))
371 gtk_tree_model_get (model, &iter,
372 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_KEY,
373 &key,
374 -1);
375 gtk_tree_path_free (treepath);
376 gtk_tree_row_reference_free (main_ctx->selected_ns_row);
377 main_ctx->selected_ns_row = NULL;
378 }
379 selected_ns_id = NULL;
380 if (NULL != key)
381 {
382 selected_ns_id = GNUNET_new (struct GNUNET_CRYPTO_EccPublicKey);
383 *selected_ns_id = *key;
384 }
385
386 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (main_ctx->search_ns_treestore),
387 &iter))
388 {
389 do
390 {
391 gtk_tree_model_get (GTK_TREE_MODEL (main_ctx->search_ns_treestore), &iter,
392 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_KEY,
393 &key,
394 -1);
395 GNUNET_free_non_null (key);
396 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (main_ctx->search_ns_treestore),
397 &iter));
398 }
399 gtk_tree_store_clear (main_ctx->search_ns_treestore);
400 gtk_tree_store_insert_with_values (main_ctx->search_ns_treestore, &iter, NULL, G_MAXINT,
401 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_NAME,
402 "Any",
403 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_KEY,
404 NULL,
405 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_ROOT,
406 "",
407 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_TOOLTIP,
408 "Do not search in any particular namespace",
409 -1);
410
411 if (NULL != main_ctx->ns_discovery_handle)
412 GNUNET_FS_pseudonym_discovery_callback_unregister (main_ctx->ns_discovery_handle);
413 main_ctx->ns_discovery_handle
414 = GNUNET_FS_pseudonym_discovery_callback_register (main_ctx->cfg,
415 &add_namespace_to_ts,
416 main_ctx->search_ns_treestore);
417
418 found = FALSE;
419 value = NULL;
420 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (main_ctx->search_ns_treestore),
421 &iter))
422 {
423 while (TRUE)
424 {
425 gtk_tree_model_get (GTK_TREE_MODEL (main_ctx->search_ns_treestore), &iter,
426 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_NAME,
427 &value,
428 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_KEY,
429 &key,
430 -1);
431 if (NULL == selected_ns_id)
432 found = TRUE;
433 if ( (key != NULL) &&
434 (0 == memcmp (key, selected_ns_id, sizeof (struct GNUNET_CRYPTO_EccPublicKey))) )
435 found = TRUE;
436 if (found ||
437 (! gtk_tree_model_iter_next (GTK_TREE_MODEL (main_ctx->search_ns_treestore),
438 &iter)))
439 break;
440 g_free (value);
441 }
442 }
443 if ( (!found) &&
444 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (main_ctx->search_ns_treestore),
445 &iter))
446 {
447 gtk_tree_model_get (GTK_TREE_MODEL (main_ctx->search_ns_treestore), &iter,
448 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_NAME,
449 &value,
450 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_NAMESPACE_MC_KEY,
451 &key,
452 -1);
453 found = TRUE;
454 }
455 if (found)
456 gtk_tree_selection_select_iter (gtk_tree_view_get_selection
457 (main_ctx->ns_selector_treeview), &iter);
458 if (value != NULL)
459 {
460 gtk_label_set_text (main_ctx->search_ns_label, value);
461 g_free (value);
462 }
463 GNUNET_free_non_null (selected_ns_id);
464}
465
466
467/* end of gnunet-fs-gtk_main-window-namespace-dropdown.c */