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.c191
1 files changed, 14 insertions, 177 deletions
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{