aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-01 17:37:37 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-01 17:37:37 +0000
commite0ace084d8e6b71c0f06ea1d4b25b5a79f3c26c3 (patch)
tree2ab46ee20d69148bef5d70d7d88c41a61a32a00c
parent3356d4d2d6fe49820a5718abbb00f5bc23fbc9b8 (diff)
downloadgnunet-gtk-e0ace084d8e6b71c0f06ea1d4b25b5a79f3c26c3.tar.gz
gnunet-gtk-e0ace084d8e6b71c0f06ea1d4b25b5a79f3c26c3.zip
-moving code around plus some DCE
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_namespace.c153
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_search.c3
-rw-r--r--src/fs/gnunet-fs-gtk.c191
-rw-r--r--src/fs/gnunet-fs-gtk.h7
4 files changed, 169 insertions, 185 deletions
diff --git a/src/fs/gnunet-fs-gtk-main_window_namespace.c b/src/fs/gnunet-fs-gtk-main_window_namespace.c
index 3af3845d..7c61c882 100644
--- a/src/fs/gnunet-fs-gtk-main_window_namespace.c
+++ b/src/fs/gnunet-fs-gtk-main_window_namespace.c
@@ -25,6 +25,10 @@
25 */ 25 */
26#include "gnunet-fs-gtk-common.h" 26#include "gnunet-fs-gtk-common.h"
27#include <gdk/gdk.h> 27#include <gdk/gdk.h>
28#include "gnunet-fs-gtk.h"
29
30
31static guint namespace_selector_window_leave_timeout_source;
28 32
29 33
30void 34void
@@ -321,4 +325,153 @@ namespace_selector_treeview_button_release_event_cb (GtkWidget * widget,
321 325
322 326
323 327
328/**
329 * Add pseudonym data to tree store
330 *
331 * @param cls closure (the 'GtkListStore')
332 * @param pseudonym hash code of public key of pseudonym
333 * @param md meta data known about the pseudonym
334 * @param rating the local rating of the pseudonym
335 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
336 */
337static int
338add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym,
339 const struct GNUNET_CONTAINER_MetaData *md, int rating)
340{
341 GtkTreeStore *ts = cls;
342 char *root;
343 char *ns_name;
344 GNUNET_HashCode *nsid;
345 char *description;
346 char *uris;
347 char *emsg;
348 struct GNUNET_FS_Uri *uri;
349 GtkTreeIter iter;
350
351 ns_name =
352 GNUNET_PSEUDONYM_id_to_name (GNUNET_FS_GTK_get_configuration (),
353 pseudonym);
354 nsid = GNUNET_malloc (sizeof (GNUNET_HashCode));
355 *nsid = *pseudonym;
356 root = NULL;
357 uris = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_URI);
358 if (uris != NULL)
359 {
360 emsg = NULL;
361 uri = GNUNET_FS_uri_parse (uris, &emsg);
362 if (uri == NULL)
363 GNUNET_free (emsg);
364 root = GNUNET_FS_uri_sks_get_content_id (uri);
365 GNUNET_FS_uri_destroy (uri);
366 }
367 description =
368 GNUNET_CONTAINER_meta_data_get_first_by_types (md,
369 EXTRACTOR_METATYPE_TITLE,
370 EXTRACTOR_METATYPE_BOOK_TITLE,
371 EXTRACTOR_METATYPE_DESCRIPTION,
372 EXTRACTOR_METATYPE_SUMMARY,
373 EXTRACTOR_METATYPE_ALBUM,
374 EXTRACTOR_METATYPE_COMMENT,
375 EXTRACTOR_METATYPE_SUBJECT,
376 EXTRACTOR_METATYPE_KEYWORDS,
377 -1);
378 if (description == NULL)
379 description = g_strdup (_("no description supplied"));
380 else
381 {
382 char *utf8_desc = NULL;
383
384 utf8_desc =
385 GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8,
386 description, strlen (description));
387 GNUNET_free (description);
388 if (utf8_desc != NULL)
389 description = utf8_desc;
390 else
391 description = NULL;
392 }
393 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1,
394 nsid, 2, root, 3, description, -1);
395 GNUNET_free (ns_name);
396 GNUNET_free_non_null (root);
397 GNUNET_free_non_null (description);
398 return GNUNET_OK;
399}
400
401
402void
403GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data)
404{
405 GtkTreeIter iter;
406 GtkTreeView *namespace_tree;
407 GtkTreeStore *namespace_treestore;
408 GtkBuilder *builder;
409 GtkWidget *namespace_selector_window;
410
411 builder = GTK_BUILDER (user_data);
412
413 /* Make sure button class is realized */
414 g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON));
415 /* GNUnet main window assumes that images on buttons are visible,
416 * override the theme's gtkrc setting
417 */
418 g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL);
419
420 namespace_treestore =
421 GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object
422 ("main_window_search_namespace_treestore"));
423 namespace_tree =
424 GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
425 ("namespace_selector_treeview"));
426
427 /* FIXME: find a way to manage pseudonyms.
428 * Right now the list will be filled with ALL and ANY pseudonyms that we
429 * find, these are held as files in a special directory.
430 * I don't see an easy way to ignore certain pseudonyms in that directory,
431 * and that require for pseudonym management. Also, pseudonyms are presented
432 * in arbitrary order. We must either sort them (by name?) or let the user
433 * drag them around to change the order in which they appear in the list.
434 * All that is not possible with a simple "files in a directory" concept.
435 */
436 gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, G_MAXINT,
437 0, "Any", 1, NULL, 2, "", 3,
438 "Do not search in any particular namespace",
439 -1);
440 /*
441 * GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (),
442 * &add_namespace_to_ts, namespace_treestore);
443 */
444 /* FIXME: when do we unregister? */
445 GNUNET_PSEUDONYM_discovery_callback_register (GNUNET_FS_GTK_get_configuration (),
446 &add_namespace_to_ts,
447 namespace_treestore);
448
449 /* FIXME: read currently selected namespace from somewhere instead of selecting 0th item */
450 if (gtk_tree_model_get_iter_first
451 (GTK_TREE_MODEL (namespace_treestore), &iter))
452 {
453 gchar *value;
454 GtkLabel *sel_namespace_label;
455 GtkTreePath *treepath = gtk_tree_path_new_first ();
456
457 gtk_tree_selection_select_iter (gtk_tree_view_get_selection
458 (namespace_tree), &iter);
459 sel_namespace_label =
460 GTK_LABEL (gtk_builder_get_object
461 (builder, "main_window_search_selected_namespace_label"));
462 if (GNUNET_GTK_get_tree_string (namespace_tree, treepath, 0, &value))
463 gtk_label_set_text (sel_namespace_label, value);
464 gtk_tree_path_free (treepath);
465 }
466
467 /* How the window (to trigger certain events) and immediately hide it */
468 namespace_selector_window =
469 GTK_WIDGET (gtk_builder_get_object
470 (builder, "namespace_selector_window"));
471 gtk_widget_show (namespace_selector_window);
472 gtk_widget_hide (namespace_selector_window);
473
474}
475
476
324/* end of gnunet-fs-gtk-main_window_namespace.c */ 477/* end of gnunet-fs-gtk-main_window_namespace.c */
diff --git a/src/fs/gnunet-fs-gtk-main_window_search.c b/src/fs/gnunet-fs-gtk-main_window_search.c
index 870b5f18..b67de6b3 100644
--- a/src/fs/gnunet-fs-gtk-main_window_search.c
+++ b/src/fs/gnunet-fs-gtk-main_window_search.c
@@ -24,8 +24,9 @@
24 * @brief event handlers for the search function in the main window 24 * @brief event handlers for the search function in the main window
25 */ 25 */
26#include "gnunet-fs-gtk-common.h" 26#include "gnunet-fs-gtk-common.h"
27#include "gnunet-fs-gtk.h"
27#include <gdk/gdk.h> 28#include <gdk/gdk.h>
28 29#include "gnunet-fs-gtk-anonymity_spin_buttons.h"
29 30
30 31
31void 32void
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index b3d05be2..0c359d3c 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -25,7 +25,6 @@
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"
29#include <gdk/gdkkeysyms.h> 28#include <gdk/gdkkeysyms.h>
30 29
31/** 30/**
@@ -43,12 +42,6 @@ static struct GNUNET_GTK_MainLoop *ml;
43 */ 42 */
44static struct GNUNET_FS_Handle *fs; 43static struct GNUNET_FS_Handle *fs;
45 44
46/**
47 * List of plugins for meta data extraction.
48 */
49static struct EXTRACTOR_PluginList *plugins;
50
51guint namespace_selector_window_leave_timeout_source = 0;
52 45
53/** 46/**
54 * Return handle for file-sharing operations. 47 * Return handle for file-sharing operations.
@@ -61,17 +54,6 @@ GNUNET_FS_GTK_get_fs_handle ()
61 return fs; 54 return fs;
62} 55}
63 56
64
65/**
66 * Get LE plugin list.
67 */
68struct EXTRACTOR_PluginList *
69GNUNET_FS_GTK_get_le_plugins ()
70{
71 return plugins;
72}
73
74
75/** 57/**
76 * Get cfg. 58 * Get cfg.
77 */ 59 */
@@ -111,8 +93,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
111 GNUNET_FS_stop (fs); 93 GNUNET_FS_stop (fs);
112 fs = NULL; 94 fs = NULL;
113 } 95 }
114 EXTRACTOR_plugin_remove_all (plugins);
115 plugins = NULL;
116} 96}
117 97
118 98
@@ -129,160 +109,6 @@ GNUNET_GTK_quit_cb (GObject * object, gpointer user_data)
129 109
130 110
131/** 111/**
132 * Add pseudonym data to tree store
133 *
134 * @param cls closure (the 'GtkListStore')
135 * @param pseudonym hash code of public key of pseudonym
136 * @param md meta data known about the pseudonym
137 * @param rating the local rating of the pseudonym
138 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
139 */
140static int
141add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym,
142 const struct GNUNET_CONTAINER_MetaData *md, int rating)
143{
144 GtkTreeStore *ts = cls;
145 char *root;
146 char *ns_name;
147 GNUNET_HashCode *nsid;
148 char *description;
149 char *uris;
150 char *emsg;
151 struct GNUNET_FS_Uri *uri;
152 GtkTreeIter iter;
153
154 ns_name =
155 GNUNET_PSEUDONYM_id_to_name (GNUNET_FS_GTK_get_configuration (),
156 pseudonym);
157 nsid = GNUNET_malloc (sizeof (GNUNET_HashCode));
158 *nsid = *pseudonym;
159 root = NULL;
160 uris = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_URI);
161 if (uris != NULL)
162 {
163 emsg = NULL;
164 uri = GNUNET_FS_uri_parse (uris, &emsg);
165 if (uri == NULL)
166 GNUNET_free (emsg);
167 root = GNUNET_FS_uri_sks_get_content_id (uri);
168 GNUNET_FS_uri_destroy (uri);
169 }
170 description =
171 GNUNET_CONTAINER_meta_data_get_first_by_types (md,
172 EXTRACTOR_METATYPE_TITLE,
173 EXTRACTOR_METATYPE_BOOK_TITLE,
174 EXTRACTOR_METATYPE_DESCRIPTION,
175 EXTRACTOR_METATYPE_SUMMARY,
176 EXTRACTOR_METATYPE_ALBUM,
177 EXTRACTOR_METATYPE_COMMENT,
178 EXTRACTOR_METATYPE_SUBJECT,
179 EXTRACTOR_METATYPE_KEYWORDS,
180 -1);
181 if (description == NULL)
182 description = g_strdup (_("no description supplied"));
183 else
184 {
185 char *utf8_desc = NULL;
186
187 utf8_desc =
188 GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8,
189 description, strlen (description));
190 GNUNET_free (description);
191 if (utf8_desc != NULL)
192 description = utf8_desc;
193 else
194 description = NULL;
195 }
196 gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1,
197 nsid, 2, root, 3, description, -1);
198 GNUNET_free (ns_name);
199 GNUNET_free_non_null (root);
200 GNUNET_free_non_null (description);
201 return GNUNET_OK;
202}
203
204void
205GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data)
206{
207 GtkTreeIter iter;
208 GtkTreeView *namespace_tree;
209 GtkTreeStore *namespace_treestore;
210 GtkBuilder *builder;
211 GtkWidget *namespace_selector_window;
212 GtkTreeView *metadata_tree;
213
214 builder = GTK_BUILDER (user_data);
215
216 /* Make sure button class is realized */
217 g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON));
218 /* GNUnet main window assumes that images on buttons are visible,
219 * override the theme's gtkrc setting
220 */
221 g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL);
222
223 namespace_treestore =
224 GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object
225 ("main_window_search_namespace_treestore"));
226 namespace_tree =
227 GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
228 ("namespace_selector_treeview"));
229 metadata_tree =
230 GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
231 ("GNUNET_GTK_main_window_metadata_treeview"));
232
233 /* Allow multiple selection in metadata view */
234 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (metadata_tree),
235 GTK_SELECTION_MULTIPLE);
236
237 /* FIXME: find a way to manage pseudonyms.
238 * Right now the list will be filled with ALL and ANY pseudonyms that we
239 * find, these are held as files in a special directory.
240 * I don't see an easy way to ignore certain pseudonyms in that directory,
241 * and that require for pseudonym management. Also, pseudonyms are presented
242 * in arbitrary order. We must either sort them (by name?) or let the user
243 * drag them around to change the order in which they appear in the list.
244 * All that is not possible with a simple "files in a directory" concept.
245 */
246 gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL, G_MAXINT,
247 0, "Any", 1, NULL, 2, "", 3,
248 "Do not search in any particular namespace",
249 -1);
250 /*
251 * GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (),
252 * &add_namespace_to_ts, namespace_treestore);
253 */
254 GNUNET_PSEUDONYM_discovery_callback_register (GNUNET_FS_GTK_get_configuration
255 (), &add_namespace_to_ts,
256 namespace_treestore);
257
258 /* FIXME: read currently selected namespace from somewhere instead of selecting 0th item */
259 if (gtk_tree_model_get_iter_first
260 (GTK_TREE_MODEL (namespace_treestore), &iter))
261 {
262 gchar *value;
263 GtkLabel *sel_namespace_label;
264 GtkTreePath *treepath = gtk_tree_path_new_first ();
265
266 gtk_tree_selection_select_iter (gtk_tree_view_get_selection
267 (namespace_tree), &iter);
268 sel_namespace_label =
269 GTK_LABEL (gtk_builder_get_object
270 (builder, "main_window_search_selected_namespace_label"));
271 if (GNUNET_GTK_get_tree_string (namespace_tree, treepath, 0, &value))
272 gtk_label_set_text (sel_namespace_label, value);
273 gtk_tree_path_free (treepath);
274 }
275
276 /* How the window (to trigger certain events) and immediately hide it */
277 namespace_selector_window =
278 GTK_WIDGET (gtk_builder_get_object
279 (builder, "namespace_selector_window"));
280 gtk_widget_show (namespace_selector_window);
281 gtk_widget_hide (namespace_selector_window);
282
283}
284
285/**
286 * Actual main function run right after GNUnet's scheduler 112 * Actual main function run right after GNUnet's scheduler
287 * is initialized. Initializes up GTK and Glade. 113 * is initialized. Initializes up GTK and Glade.
288 */ 114 */
@@ -290,6 +116,7 @@ static void
290run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 116run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
291{ 117{
292 GtkWidget *main_window; 118 GtkWidget *main_window;
119 GtkTreeView *metadata_tree;
293 120
294 ml = cls; 121 ml = cls;
295 122
@@ -301,14 +128,23 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
301 GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object 128 GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object
302 ("GNUNET_GTK_main_window")); 129 ("GNUNET_GTK_main_window"));
303 gtk_window_maximize (GTK_WINDOW (main_window)); 130 gtk_window_maximize (GTK_WINDOW (main_window));
131
132 /* Allow multiple selection in metadata view; FIXME: can we do this with glade now? */
133 metadata_tree =
134 GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
135 ("GNUNET_GTK_main_window_metadata_treeview"));
136 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (metadata_tree),
137 GTK_SELECTION_MULTIPLE);
138
304 GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), 139 GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window),
305 "gnunet-gtk" /* FIXME: rename icon? */ , 140 "gnunet-gtk" /* FIXME: rename icon? */ ,
306 "gnunet-fs-gtk"); 141 "gnunet-fs-gtk");
307 142
308 /* initialize file-sharing */ 143 /* initialize file-sharing */
309 plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); 144 fs = GNUNET_FS_start (GNUNET_GTK_main_loop_get_configuration (ml),
310 fs = GNUNET_FS_start (GNUNET_GTK_main_loop_get_configuration (ml), "gnunet-gtk", &GNUNET_GTK_fs_event_handler, NULL, GNUNET_FS_FLAGS_NONE /* | GNUNET_FS_FLAGS_PERSISTENCE | 145 "gnunet-gtk", &GNUNET_GTK_fs_event_handler, NULL,
311 * GNUNET_FS_FLAGS_DO_PROBES */ , 146 GNUNET_FS_FLAGS_NONE /* | GNUNET_FS_FLAGS_PERSISTENCE |
147 * GNUNET_FS_FLAGS_DO_PROBES */ ,
312 GNUNET_FS_OPTIONS_END); 148 GNUNET_FS_OPTIONS_END);
313 if (fs != NULL) 149 if (fs != NULL)
314 { 150 {
@@ -346,6 +182,7 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
346 182
347} 183}
348 184
185
349int 186int
350main (int argc, char *const *argv) 187main (int argc, char *const *argv)
351{ 188{
diff --git a/src/fs/gnunet-fs-gtk.h b/src/fs/gnunet-fs-gtk.h
index 0040fffe..567b2ea0 100644
--- a/src/fs/gnunet-fs-gtk.h
+++ b/src/fs/gnunet-fs-gtk.h
@@ -32,13 +32,6 @@
32 32
33 33
34/** 34/**
35 * Get GNU libextractor plugin list.
36 */
37struct EXTRACTOR_PluginList *
38GNUNET_FS_GTK_get_le_plugins (void);
39
40
41/**
42 * Get our configuration. 35 * Get our configuration.
43 */ 36 */
44const struct GNUNET_CONFIGURATION_Handle * 37const struct GNUNET_CONFIGURATION_Handle *