aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-06-28 19:00:47 +0200
committerChristian Grothoff <christian@grothoff.org>2018-06-28 19:00:47 +0200
commit32d05eb8d248a61258aa8e506b8a512fc2d54006 (patch)
tree4a3ab931d6f7919781dd83ad235c204995961068
parentb98c54d55b216e6e4e55c59565de200395b3d66b (diff)
downloadgnunet-gtk-32d05eb8d248a61258aa8e506b8a512fc2d54006.tar.gz
gnunet-gtk-32d05eb8d248a61258aa8e506b8a512fc2d54006.zip
kill gnunet-identity-gtk, does not do anything more useful than gnunet-namestore-gtk
-rw-r--r--configure.ac1
-rw-r--r--src/Makefile.am2
-rw-r--r--src/identity/.gitignore1
-rw-r--r--src/identity/Makefile.am24
-rw-r--r--src/identity/gnunet-identity-gtk.c550
-rw-r--r--src/identity/gnunet-identity-gtk.h40
-rw-r--r--src/identity/gnunet-identity-gtk_about.c41
-rw-r--r--src/identity/gnunet-identity-gtk_advertise.c688
-rw-r--r--src/identity/gnunet-identity-gtk_advertise.h51
9 files changed, 1 insertions, 1397 deletions
diff --git a/configure.ac b/configure.ac
index 8379d2a7..9795ac06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -541,7 +541,6 @@ src/include/Makefile
541src/lib/Makefile 541src/lib/Makefile
542src/fs/Makefile 542src/fs/Makefile
543src/fs/gnunet-fs-gtk.conf 543src/fs/gnunet-fs-gtk.conf
544src/identity/Makefile
545src/peerinfo/Makefile 544src/peerinfo/Makefile
546src/namestore/Makefile 545src/namestore/Makefile
547src/setup/Makefile 546src/setup/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 4fefc153..fea6f370 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,2 +1,2 @@
1# This Makefile.am is in the public domain 1# This Makefile.am is in the public domain
2SUBDIRS = . include lib $(GNUNET_FS_APP) $(GNUNET_SETUP_APP) $(GNUNET_PEERINFO_APP) $(GNUNET_CONVERSATION_APP) statistics identity namestore 2SUBDIRS = . include lib $(GNUNET_FS_APP) $(GNUNET_SETUP_APP) $(GNUNET_PEERINFO_APP) $(GNUNET_CONVERSATION_APP) statistics namestore
diff --git a/src/identity/.gitignore b/src/identity/.gitignore
deleted file mode 100644
index 7c1303af..00000000
--- a/src/identity/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
1gnunet-identity-gtk
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am
deleted file mode 100644
index 33f9a62c..00000000
--- a/src/identity/Makefile.am
+++ /dev/null
@@ -1,24 +0,0 @@
1# This Makefile.am is in the public domain
2SUBDIRS = .
3
4AM_CPPFLAGS = \
5 -I$(top_srcdir)/ \
6 -I$(top_srcdir)/src/include \
7 @GTK_CFLAGS@ \
8 @GNUNET_CFLAGS@ \
9 @GLADE_CFLAGS@
10
11bin_PROGRAMS = gnunet-identity-gtk
12
13gnunet_identity_gtk_SOURCES = \
14 gnunet-identity-gtk.c gnunet-identity-gtk.h \
15 gnunet-identity-gtk_about.c \
16 gnunet-identity-gtk_advertise.c gnunet-identity-gtk_advertise.h
17gnunet_identity_gtk_LDADD = \
18 $(top_builddir)/src/lib/libgnunetgtk.la \
19 @GTK_LIBS@ \
20 @GLADE_LIBS@ @GNUNET_LIBS@ \
21 -lgnunetutil -lgnunetidentity -lgnunetfs -lextractor \
22 $(INTLLIBS)
23gnunet_identity_gtk_LDFLAGS = \
24 -export-dynamic
diff --git a/src/identity/gnunet-identity-gtk.c b/src/identity/gnunet-identity-gtk.c
deleted file mode 100644
index 11800fce..00000000
--- a/src/identity/gnunet-identity-gtk.c
+++ /dev/null
@@ -1,550 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file src/identity/gnunet-identity-gtk.c
23 * @brief Main function of gnunet-identity-gtk
24 * @author Christian Grothoff
25 */
26#include "gnunet_gtk.h"
27#include <gnunet/gnunet_identity_service.h>
28#include "gnunet-identity-gtk_advertise.h"
29
30
31/**
32 * Columns in the identity model.
33 */
34enum IDENTITY_ModelColumns
35 {
36 /**
37 * A gchararray
38 */
39 IDENTITY_MC_NAME = 0,
40
41 /**
42 * A gchararray
43 */
44 IDENTITY_MC_IDENTIFIER = 1,
45
46 /**
47 * A 'struct GNUNET_IDENTIFIER_Ego'
48 */
49 IDENTITY_MC_EGO = 2
50
51 };
52
53
54/**
55 * Handle to our main loop.
56 */
57static struct GNUNET_GTK_MainLoop *ml;
58
59/**
60 * Handle to IDENTITY service.
61 */
62static struct GNUNET_IDENTITY_Handle *identity;
63
64/**
65 * Main window list store.
66 */
67static GtkListStore *ls;
68
69
70/**
71 * We need to track active operations with the identity service.
72 */
73struct OperationContext
74{
75
76 /**
77 * Kept in a DLL.
78 */
79 struct OperationContext *next;
80
81 /**
82 * Kept in a DLL.
83 */
84 struct OperationContext *prev;
85
86 /**
87 * Operation handle with the identity service.
88 */
89 struct GNUNET_IDENTITY_Operation *op;
90
91};
92
93
94/**
95 * Head of operations.
96 */
97static struct OperationContext *oc_head;
98
99/**
100 * Tail of operations.
101 */
102static struct OperationContext *oc_tail;
103
104
105/**
106 * Get our configuration.
107 *
108 * @return configuration handle
109 */
110const struct GNUNET_CONFIGURATION_Handle *
111GIG_get_configuration ()
112{
113 return GNUNET_GTK_main_loop_get_configuration (ml);
114}
115
116
117/**
118 * Get an object from the main window.
119 *
120 * @param name name of the object
121 * @return NULL on error
122 */
123static GObject *
124get_object (const char *name)
125{
126 return GNUNET_GTK_main_loop_get_object (ml, name);
127}
128
129
130/**
131 * Identity operation was finished, clean up.
132 *
133 * @param cls the 'struct OperationContext'
134 * @param emsg error message (NULL on success)
135 */
136static void
137operation_finished (void *cls,
138 const char *emsg)
139{
140 struct OperationContext *oc = cls;
141
142 GNUNET_CONTAINER_DLL_remove (oc_head,
143 oc_tail,
144 oc);
145 gtk_widget_set_sensitive (GTK_WIDGET (get_object ("GNUNET_GTK_identity_treeview")),
146 TRUE);
147 GNUNET_free (oc);
148}
149
150
151/**
152 * Context for the advertise popup menu.
153 */
154struct AdvertisePopupContext
155{
156 /**
157 * Ego to advertise.
158 */
159 struct GNUNET_IDENTITY_Ego *ego;
160
161};
162
163
164/**
165 * "Advertise" was selected in the current context menu.
166 *
167 * @param item the 'advertise' menu item
168 * @param user_data the 'struct AdvertisePopupContext' of the menu
169 */
170static void
171advertise_ctx_menu (GtkMenuItem *item,
172 gpointer user_data)
173{
174 struct AdvertisePopupContext *apc = user_data;
175 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv;
176
177 priv = GNUNET_IDENTITY_ego_get_private_key (apc->ego);
178 GIG_advertise_dialog_start_ (priv);
179}
180
181
182/**
183 * An item was selected from the context menu; destroy the menu shell.
184 *
185 * @param menushell menu to destroy
186 * @param user_data the 'struct AdvertisePopupContext' of the menu
187 */
188static void
189advertise_popup_selection_done (GtkMenuShell *menushell,
190 gpointer user_data)
191{
192 struct AdvertisePopupContext *apc = user_data;
193
194 gtk_widget_destroy (GTK_WIDGET (menushell));
195 GNUNET_free (apc);
196}
197
198
199/**
200 * User clicked in the treeview widget. Check for right button
201 * to possibly launch advertise window.
202 *
203 * @param widget the treeview widget
204 * @param event the event, we only care about button events
205 * @param user_data unused
206 * @return FALSE if no menu could be popped up,
207 * TRUE if there is now a pop-up menu
208 */
209gboolean
210GNUNET_GTK_identity_treeview_button_press_event_cb (GtkWidget *widget,
211 GdkEvent *event,
212 gpointer user_data)
213{
214 GtkTreeView *tv = GTK_TREE_VIEW (widget);
215 GdkEventButton *event_button = (GdkEventButton *) event;
216 GtkTreeModel *tm;
217 GtkTreePath *path;
218 GtkTreeIter iter;
219 GtkMenu *menu;
220 GtkWidget *child;
221 struct AdvertisePopupContext *apc;
222 struct GNUNET_IDENTITY_Ego *ego;
223
224 if ( (GDK_BUTTON_PRESS != event->type) ||
225 (3 != event_button->button) )
226 return FALSE;
227 if (! gtk_tree_view_get_path_at_pos (tv,
228 event_button->x, event_button->y,
229 &path, NULL, NULL, NULL))
230 return FALSE; /* click outside of area with values, ignore */
231 tm = gtk_tree_view_get_model (tv);
232 if (! gtk_tree_model_get_iter (tm, &iter, path))
233 {
234 gtk_tree_path_free (path);
235 return FALSE; /* not sure how we got a path but no iter... */
236 }
237 gtk_tree_path_free (path);
238 gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter,
239 IDENTITY_MC_EGO, &ego,
240 -1);
241 if (NULL == ego)
242 return FALSE;
243 apc = GNUNET_new (struct AdvertisePopupContext);
244 apc->ego = ego;
245 menu = GTK_MENU (gtk_menu_new ());
246 child = gtk_menu_item_new_with_label (_("_Advertise"));
247 g_signal_connect (child, "activate",
248 G_CALLBACK (advertise_ctx_menu), apc);
249 gtk_label_set_use_underline (GTK_LABEL
250 (gtk_bin_get_child (GTK_BIN (child))),
251 TRUE);
252 gtk_widget_show (child);
253 gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
254 g_signal_connect (menu, "selection-done",
255 G_CALLBACK (advertise_popup_selection_done), apc);
256 gtk_menu_popup_at_pointer (menu,
257 event);
258 return FALSE;
259}
260
261
262/**
263 * User pushed a key (possibly DEL) in the treeview widget.
264 * Delete the selected entry if the key was DEL.
265 *
266 * @param widget the entry widget
267 * @param event the key stroke
268 * @param user_data the main window context
269 * @return FALSE if this was not ENTER, TRUE if it was
270 */
271gboolean
272GNUNET_GTK_identity_treeview_key_press_event_cb (GtkWidget * widget,
273 GdkEventKey * event,
274 gpointer user_data)
275{
276 gchar *old;
277 struct OperationContext *oc;
278 GtkTreeSelection *sel;
279 GtkTreeIter iter;
280
281 if (GDK_KEY_Delete != event->keyval)
282 return FALSE;
283 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (get_object ("GNUNET_GTK_identity_treeview")));
284 if (! gtk_tree_selection_get_selected (sel, NULL, &iter))
285 return FALSE;
286 gtk_tree_model_get (GTK_TREE_MODEL (ls),
287 &iter,
288 IDENTITY_MC_NAME, &old,
289 -1);
290 oc = GNUNET_new (struct OperationContext);
291 GNUNET_CONTAINER_DLL_insert (oc_head,
292 oc_tail,
293 oc);
294 oc->op = GNUNET_IDENTITY_delete (identity,
295 old,
296 &operation_finished,
297 oc);
298 return TRUE;
299}
300
301
302/**
303 * The user edited one of the names of the egos. Change it
304 * in the IDENTITY service.
305 *
306 * @param renderer renderer where the change happened
307 * @param path location in the model where the change happened
308 * @param new_text updated text
309 * @param user_data internal context (not used)
310 */
311void
312GNUNET_GTK_namespace_organizer_namespaces_treeview_column_name_text_edited_cb
313(GtkCellRendererText *renderer,
314 gchar *path,
315 gchar *new_text,
316 gpointer user_data)
317{
318 GtkTreePath *treepath;
319 GtkTreeIter iter;
320 struct GNUNET_IDENTITY_Ego *ego;
321 gchar *old;
322 struct OperationContext *oc;
323
324 treepath = gtk_tree_path_new_from_string (path);
325 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (ls),
326 &iter,
327 treepath))
328 {
329 GNUNET_break (0);
330 gtk_tree_path_free (treepath);
331 return;
332 }
333 gtk_tree_path_free (treepath);
334 gtk_tree_model_get (GTK_TREE_MODEL (ls),
335 &iter,
336 IDENTITY_MC_NAME, &old,
337 IDENTITY_MC_EGO, &ego,
338 -1);
339 gtk_widget_set_sensitive (GTK_WIDGET (get_object ("GNUNET_GTK_identity_treeview")),
340 FALSE);
341 oc = GNUNET_new (struct OperationContext);
342 GNUNET_CONTAINER_DLL_insert (oc_head,
343 oc_tail,
344 oc);
345 if (NULL == ego)
346 {
347 /* create operation */
348 oc->op = GNUNET_IDENTITY_create (identity,
349 new_text,
350 &operation_finished,
351 oc);
352 }
353 else if (0 != strlen (new_text))
354 {
355 /* rename operation */
356 oc->op = GNUNET_IDENTITY_rename (identity,
357 old, new_text,
358 &operation_finished,
359 oc);
360 }
361 else
362 {
363 /* delete operation */
364 oc->op = GNUNET_IDENTITY_delete (identity,
365 old,
366 &operation_finished,
367 oc);
368 }
369}
370
371
372/**
373 * Task run on shutdown.
374 *
375 * @param cls unused
376 */
377static void
378shutdown_task (void *cls)
379{
380 struct OperationContext *oc;
381
382 GIG_advertise_shutdown_ ();
383 while (NULL != (oc = oc_head))
384 {
385 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
386 _("Operation not completed due to shutdown\n"));
387 GNUNET_IDENTITY_cancel (oc->op);
388 GNUNET_CONTAINER_DLL_remove (oc_head,
389 oc_tail,
390 oc);
391 GNUNET_free (oc);
392 }
393 if (NULL != identity)
394 {
395 GNUNET_IDENTITY_disconnect (identity);
396 identity = NULL;
397 }
398 GNUNET_GTK_main_loop_quit (ml);
399 ml = NULL;
400}
401
402
403/**
404 * Callback invoked if the application is supposed to exit.
405 *
406 * @param object
407 * @param user_data unused
408 */
409void
410GNUNET_GTK_identity_quit_cb (GObject * object, gpointer user_data)
411{
412 GNUNET_SCHEDULER_shutdown ();
413}
414
415
416/**
417 * Add all updateable entries of the current namespace to the
418 * tree store.
419 *
420 * @param cls our 'struct MainPublishingDialogContext'
421 * @param ego identity of the namespace to add
422 * @param ego_ctx where to store context data
423 * @param name name of the namespace to add
424 */
425static void
426add_ego (void *cls,
427 struct GNUNET_IDENTITY_Ego *ego,
428 void **ego_ctx,
429 const char *name)
430{
431 GtkTreePath *path;
432 GtkTreeRowReference *rr;
433 GtkTreeIter iter;
434 char *id;
435 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
436
437 if (NULL == ego)
438 return; /* nothing to be done */
439 rr = *ego_ctx;
440 if (NULL == rr)
441 {
442 /* insert operation */
443 GNUNET_assert (NULL != name);
444 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
445 id = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub);
446 gtk_list_store_insert_with_values (ls,
447 &iter, G_MAXINT,
448 IDENTITY_MC_NAME, name,
449 IDENTITY_MC_IDENTIFIER, id,
450 IDENTITY_MC_EGO, ego,
451 -1);
452 GNUNET_free (id);
453 path = gtk_tree_model_get_path (GTK_TREE_MODEL (ls),
454 &iter);
455 rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ls),
456 path);
457 gtk_tree_path_free (path);
458 *ego_ctx = rr;
459 }
460 else if (NULL == name)
461 {
462 /* delete operation */
463 path = gtk_tree_row_reference_get_path (rr);
464 gtk_tree_row_reference_free (rr);
465 GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ls),
466 &iter, path));
467 gtk_tree_path_free (path);
468 gtk_list_store_remove (ls, &iter);
469 *ego_ctx = NULL;
470 }
471 else
472 {
473 /* rename operation */
474 path = gtk_tree_row_reference_get_path (rr);
475 GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ls),
476 &iter, path));
477 gtk_list_store_set (ls,
478 &iter,
479 IDENTITY_MC_NAME, name,
480 -1);
481 gtk_tree_path_free (path);
482 }
483}
484
485
486/**
487 * Actual main function run right after GNUnet's scheduler
488 * is initialized. Initializes up GTK and Glade.
489 *
490 * @param cls NULL
491 */
492static void
493run (void *cls)
494{
495 GtkWidget *main_window;
496 GtkTreeIter iter;
497
498 ml = cls;
499 if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL))
500 return;
501 GNUNET_GTK_set_icon_search_path ();
502 GNUNET_GTK_setup_nls ();
503 /* setup main window */
504 main_window = GTK_WIDGET (get_object ("GNUNET_GTK_identity_window"));
505 main_window = GNUNET_GTK_plug_me ("GNUNET_IDENTITY_GTK_PLUG",
506 main_window);
507 ls = GTK_LIST_STORE (get_object ("GNUNET_GTK_identity_liststore"));
508 GNUNET_assert (NULL != ls);
509 gtk_list_store_insert_with_values (ls,
510 &iter, G_MAXINT,
511 IDENTITY_MC_NAME, "<create>",
512 -1);
513
514 gtk_window_maximize (GTK_WINDOW (main_window));
515 /* make GUI visible */
516 gtk_widget_show (main_window);
517 gtk_window_present (GTK_WINDOW (main_window));
518 identity = GNUNET_IDENTITY_connect (GIG_get_configuration (),
519 &add_ego,
520 NULL);
521 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
522}
523
524
525/**
526 * Main function of gnunet-identity-gtk.
527 *
528 * @param argc number of arguments
529 * @param argv arguments
530 * @return 0 on success
531 */
532int
533main (int argc, char *const *argv)
534{
535 static struct GNUNET_GETOPT_CommandLineOption options[] = {
536 GNUNET_GETOPT_OPTION_END
537 };
538
539 if (GNUNET_OK !=
540 GNUNET_GTK_main_loop_start ("gnunet-identity-gtk",
541 "GTK GUI for managing egos", argc,
542 argv, options,
543 "gnunet_identity_gtk_main_window.glade",
544 &run))
545 return 1;
546 return 0;
547}
548
549
550/* end of gnunet-identity-gtk.c */
diff --git a/src/identity/gnunet-identity-gtk.h b/src/identity/gnunet-identity-gtk.h
deleted file mode 100644
index 8e7bdbef..00000000
--- a/src/identity/gnunet-identity-gtk.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file src/identity/gnunet-identity-gtk.h
23 * @author Christian Grothoff
24 */
25#include <gnunet/gnunet_util_lib.h>
26
27
28#ifndef GNUNET_IDENTITY_GTK_H
29#define GNUNET_IDENTITY_GTK_H
30
31/**
32 * Get our configuration.
33 *
34 * @return configuration handle
35 */
36const struct GNUNET_CONFIGURATION_Handle *
37GIG_get_configuration (void);
38
39
40#endif
diff --git a/src/identity/gnunet-identity-gtk_about.c b/src/identity/gnunet-identity-gtk_about.c
deleted file mode 100644
index a6c079b3..00000000
--- a/src/identity/gnunet-identity-gtk_about.c
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2005-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file src/identity/gnunet-identity-gtk_about.c
22 * @author Christian Grothoff
23 * @author Igor Wronsky
24 *
25 * This file contains the about dialog.
26 */
27#include "gnunet_gtk.h"
28
29
30/**
31 * This displays an about window
32 */
33void
34GNUNET_GTK_identity_about_imagemenuitem_activate_cb (GtkWidget * dummy,
35 gpointer data)
36{
37 GNUNET_GTK_display_about ("gnunet_identity_gtk_about_window.glade");
38}
39
40
41/* end of gnunet-peerinfo-gtk_about.c */
diff --git a/src/identity/gnunet-identity-gtk_advertise.c b/src/identity/gnunet-identity-gtk_advertise.c
deleted file mode 100644
index d5a8eecf..00000000
--- a/src/identity/gnunet-identity-gtk_advertise.c
+++ /dev/null
@@ -1,688 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2005-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file src/identity/gnunet-identity-gtk_advertise.c
23 * @author LRN
24 * @author Christian Grothoff
25 */
26#include "gnunet-identity-gtk_advertise.h"
27#include "gnunet-identity-gtk.h"
28#include <gnunet/gnunet_fs_service.h>
29#if HAVE_EXTRACTOR_H
30#include <extractor.h>
31#endif
32
33#define NEW_KEYWORD_TEXT "<add>"
34
35
36/**
37 * Types of metadata we offer for namespaces.
38 */
39static gint types[] =
40{
41 EXTRACTOR_METATYPE_TITLE,
42 EXTRACTOR_METATYPE_KEYWORDS,
43 EXTRACTOR_METATYPE_SUBJECT,
44 EXTRACTOR_METATYPE_DESCRIPTION,
45 EXTRACTOR_METATYPE_COMMENT,
46 EXTRACTOR_METATYPE_URI,
47#if HAVE_EXTRACTOR_H
48 EXTRACTOR_METATYPE_COPYRIGHT,
49 EXTRACTOR_METATYPE_CREATOR,
50 EXTRACTOR_METATYPE_CREATION_DATE,
51#endif
52 EXTRACTOR_METATYPE_RESERVED
53};
54
55
56/**
57 * Columns in the metadata list store.
58 */
59enum METADATA_ModelColumns
60{
61
62 /**
63 * A guint
64 */
65 METADATA_MC_TYPE_AS_ENUM = 0,
66
67 /**
68 * A gchararray
69 */
70 METADATA_MC_TYPE_AS_STRING = 1,
71
72 /**
73 * A gchararray
74 */
75 METADATA_MC_VALUE = 2
76
77};
78
79
80/**
81 * Columns in the keyword list tree store.
82 */
83enum KEYWORDS_ModelColumns
84{
85
86 /**
87 * A gchararray
88 */
89 KEYWORDS_MC_KEYWORD = 0
90
91};
92
93
94/**
95 * Columns in the meta types list tree store.
96 */
97enum METATYPES_ModelColumns
98{
99
100 /**
101 * A gchararray
102 */
103 METATYPES_MC_TYPE_AS_STRING = 0,
104
105 /**
106 * A guint
107 */
108 METATYPES_MC_TYPE_AS_ENUM = 1
109
110};
111
112
113/**
114 * Context for advertisement operations.
115 */
116struct AdvertiseContext
117{
118 /**
119 * Builder for accessing objects in the dialog.
120 */
121 GtkBuilder *builder;
122
123 /**
124 * Private key of the namespace we will be advertising.
125 */
126 struct GNUNET_CRYPTO_EcdsaPrivateKey priv;
127
128 /**
129 * Main dialog object.
130 */
131 GtkWidget *dialog;
132
133 /**
134 * List of keywords to advertise under.
135 */
136 GtkListStore *keywords;
137
138 /**
139 * Metadata to include in the advertisement.
140 */
141 GtkListStore *metadata;
142
143 /**
144 * Model with the meta types.
145 */
146 GtkListStore *meta_types;
147
148 /**
149 * Number of keywords in the view.
150 */
151 unsigned int num_keywords;
152
153};
154
155
156/**
157 * Context for the publishing operation.
158 */
159struct PublishContext
160{
161
162 /**
163 * Kept in a DLL.
164 */
165 struct PublishContext *next;
166
167 /**
168 * Kept in a DLL.
169 */
170 struct PublishContext *prev;
171
172 /**
173 * Handle to FS subsystem.
174 */
175 struct GNUNET_FS_Handle *fs;
176
177 /**
178 * Handle to the publish operation.
179 */
180 struct GNUNET_FS_PublishKskContext *pub;
181
182};
183
184
185/**
186 * Kept in a DLL.
187 */
188static struct PublishContext *pc_head;
189
190/**
191 * Kept in a DLL.
192 */
193static struct PublishContext *pc_tail;
194
195
196/**
197 * Shutdown advertisement subsystem, this process is terminating.
198 */
199void
200GIG_advertise_shutdown_ ()
201{
202 struct PublishContext *pc;
203
204 while (NULL != (pc = pc_head))
205 {
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
207 _("Aborting advertising operation due to shutdown.\n"));
208 GNUNET_CONTAINER_DLL_remove (pc_head,
209 pc_tail,
210 pc);
211 GNUNET_FS_publish_ksk_cancel (pc->pub);
212 GNUNET_FS_stop (pc->fs);
213 GNUNET_free (pc);
214 }
215}
216
217
218/**
219 * Function called once we published the advertisement.
220 *
221 * @param cls closure with the `struct PublishContext`
222 * @param uri URI under which the block is now available, NULL on error
223 * @param emsg error message, NULL on success
224 */
225static void
226publish_continuation (void *cls,
227 const struct GNUNET_FS_Uri *uri,
228 const char *emsg)
229{
230 struct PublishContext *pc = cls;
231
232 pc->pub = NULL;
233 if (NULL == uri)
234 {
235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
236 _("Failed to advertise ego: %s\n"),
237 emsg);
238 /* FIXME: might want to output to GUI... */
239 }
240 GNUNET_FS_stop (pc->fs);
241 GNUNET_CONTAINER_DLL_remove (pc_head,
242 pc_tail,
243 pc);
244 GNUNET_free (pc);
245}
246
247
248/**
249 * Notification of FS to a client about the progress of an
250 * operation. Callbacks of this type will be used for uploads,
251 * downloads and searches. Some of the arguments depend a bit
252 * in their meaning on the context in which the callback is used.
253 *
254 * @param cls closure
255 * @param info details about the event, specifying the event type
256 * and various bits about the event
257 * @return client-context (for the next progress call
258 * for this operation; should be set to NULL for
259 * SUSPEND and STOPPED events). The value returned
260 * will be passed to future callbacks in the respective
261 * field in the `struct GNUNET_FS_ProgressInfo`.
262 */
263static void *
264progress_cb (void *cls,
265 const struct GNUNET_FS_ProgressInfo *info)
266{
267 return NULL;
268}
269
270
271/**
272 * The user terminated the dialog. Perform the appropriate action.
273 *
274 * @param dialog the advertisement dialog
275 * @param response_id action selected by the user
276 * @param user_data our 'struct AdvertiseContext' (to be cleaned up)
277 */
278void
279GNUNET_GTK_identity_advertise_dialog_response_cb (GtkDialog *dialog,
280 gint response_id,
281 gpointer user_data)
282{
283 struct AdvertiseContext *ac = user_data;
284 struct GNUNET_FS_Uri *ksk_uri;
285 struct GNUNET_FS_Uri *uri;
286 gchar *keyword;
287 struct GNUNET_CONTAINER_MetaData *meta;
288 guint ntype;
289 gchar *value;
290 GtkTreeIter iter;
291 struct GNUNET_FS_BlockOptions bo;
292 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
293 struct PublishContext *pc;
294 guint anonymity;
295 const char *id;
296
297 if (GTK_RESPONSE_OK != response_id)
298 goto cleanup;
299 ksk_uri = NULL;
300 if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->keywords), &iter))
301 {
302 GNUNET_break (0);
303 goto cleanup;
304 }
305 do
306 {
307 gtk_tree_model_get (GTK_TREE_MODEL (ac->keywords), &iter,
308 KEYWORDS_MC_KEYWORD, &keyword,
309 -1);
310 if (NULL == ksk_uri)
311 ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &keyword);
312 else
313 GNUNET_FS_uri_ksk_add_keyword (ksk_uri, keyword, GNUNET_NO);
314 g_free (keyword);
315 }
316 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->keywords), &iter));
317
318 meta = GNUNET_CONTAINER_meta_data_create ();
319 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->metadata),
320 &iter))
321 {
322 do
323 {
324 gtk_tree_model_get (GTK_TREE_MODEL (ac->metadata), &iter,
325 METADATA_MC_TYPE_AS_ENUM, &ntype,
326 METADATA_MC_VALUE, &value,
327 -1);
328 if (ntype > 0)
329 {
330 GNUNET_CONTAINER_meta_data_insert (meta, "<user>",
331 ntype,
332 EXTRACTOR_METAFORMAT_UTF8,
333 "text/plain", value,
334 strlen (value) + 1);
335 }
336 g_free (value);
337 }
338 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->metadata), &iter));
339 }
340
341 bo.expiration_time = GNUNET_GTK_get_expiration_time
342 (GTK_SPIN_BUTTON
343 (gtk_builder_get_object
344 (ac->builder,
345 "GNUNET_GTK_identity_advertise_expiration_year_spin_button")));
346 anonymity = 1;
347 GNUNET_break (GNUNET_GTK_get_selected_anonymity_level (ac->builder,
348 "GNUNET_GTK_identity_advertise_anonymity_combobox",
349 &anonymity));
350 bo.anonymity_level = anonymity;
351 bo.content_priority
352 = (unsigned int) gtk_spin_button_get_value
353 (GTK_SPIN_BUTTON
354 (gtk_builder_get_object
355 (ac->builder,
356 "GNUNET_GTK_identity_advertise_priority_spin_button")));
357 bo.replication_level
358 = (unsigned int) gtk_spin_button_get_value
359 (GTK_SPIN_BUTTON
360 (gtk_builder_get_object
361 (ac->builder,
362 "GNUNET_GTK_identity_advertise_replication_spin_button")));
363 GNUNET_CRYPTO_ecdsa_key_get_public (&ac->priv,
364 &pk);
365 id = gtk_entry_get_text
366 (GTK_ENTRY
367 (gtk_builder_get_object
368 (ac->builder,
369 "GNUNET_GTK_identity_advertise_root_entry")));
370 uri = GNUNET_FS_uri_sks_create (&pk, id);
371
372 pc = GNUNET_new (struct PublishContext);
373 pc->fs = GNUNET_FS_start (GIG_get_configuration (),
374 "gnunet-identity-gtk",
375 &progress_cb, pc,
376 GNUNET_FS_FLAGS_NONE,
377 GNUNET_FS_OPTIONS_END);
378 pc->pub = GNUNET_FS_publish_ksk (pc->fs,
379 ksk_uri,
380 meta,
381 uri,
382 &bo,
383 GNUNET_FS_PUBLISH_OPTION_NONE,
384 &publish_continuation, pc);
385 GNUNET_CONTAINER_DLL_insert (pc_head,
386 pc_tail,
387 pc);
388 GNUNET_FS_uri_destroy (uri);
389 GNUNET_CONTAINER_meta_data_destroy (meta);
390 cleanup:
391 gtk_widget_destroy (ac->dialog);
392 g_object_unref (G_OBJECT (ac->builder));
393 GNUNET_free (ac);
394}
395
396
397/**
398 * User edited keywords in the keyword tree view. Update
399 * the model accordingly.
400 *
401 * @param renderer the object that created the signal
402 * @param path the path identifying the edited cell
403 * @param new_text the new text
404 * @param user_data the 'struct AdvertiseContext'
405 */
406void
407GNUNET_GTK_identity_advertise_keywords_text_edited_cb (GtkCellRendererText *renderer,
408 gchar *path,
409 gchar *new_text,
410 gpointer user_data)
411{
412 struct AdvertiseContext *ac = user_data;
413 GtkTreePath *tree_path;
414 GtkTreeIter iter;
415 char *old_text;
416
417 tree_path = gtk_tree_path_new_from_string (path);
418 if (NULL == tree_path)
419 {
420 GNUNET_break (0);
421 return;
422 }
423 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (ac->keywords),
424 &iter, tree_path))
425 {
426 GNUNET_break (0);
427 gtk_tree_path_free (tree_path);
428 return;
429 }
430 gtk_tree_path_free (tree_path);
431 gtk_tree_model_get (GTK_TREE_MODEL (ac->keywords), &iter,
432 KEYWORDS_MC_KEYWORD, &old_text,
433 -1);
434 if (0 == strcmp (NEW_KEYWORD_TEXT, old_text))
435 {
436 if ( (NULL != new_text) &&
437 (0 != strlen (new_text)) )
438 {
439 gtk_list_store_insert_with_values (ac->keywords, &iter, -1,
440 KEYWORDS_MC_KEYWORD, new_text,
441 -1);
442 ac->num_keywords++;
443 }
444 }
445 else
446 {
447 if ( (NULL != new_text) &&
448 (0 != strlen (new_text)) )
449 {
450 gtk_list_store_set (ac->keywords, &iter,
451 KEYWORDS_MC_KEYWORD, new_text,
452 -1);
453 }
454 else
455 {
456 gtk_list_store_remove (ac->keywords, &iter);
457 ac->num_keywords--;
458 }
459 }
460 g_free (old_text);
461 gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object
462 (ac->builder,
463 "GNUNET_GTK_identity_advertise_ok_button")),
464 0 != ac->num_keywords);
465}
466
467
468/**
469 * User pushed a key in the metadata tree view. Check if it was
470 * "DEL" and if so, remove the selected values.
471 *
472 * @param widget widget creating the signal
473 * @param event the event to process
474 * @param user_data the 'struct AdvertiseContext'
475 * @return TRUE if we handled the event, FALSE if not
476 */
477gboolean
478GNUNET_GTK_identity_advertise_metadata_treeview_key_press_event_cb (GtkWidget *widget,
479 GdkEventKey *event,
480 gpointer user_data)
481{
482 struct AdvertiseContext *ac = user_data;
483 GtkTreeSelection *sel;
484 GtkTreeModel *model;
485 GtkTreeIter iter;
486
487 if (event->keyval != GDK_KEY_Delete)
488 return FALSE;
489 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW
490 (gtk_builder_get_object
491 (ac->builder,
492 "GNUNET_GTK_identity_advertise_metadata_treeview")));
493 if (! gtk_tree_selection_get_selected (sel,
494 &model,
495 &iter))
496 {
497 gdk_beep ();
498 return TRUE;
499 }
500 gtk_list_store_remove (ac->metadata,
501 &iter);
502 return TRUE;
503}
504
505
506/**
507 * User edited metadata value in the tree view. Update the model.
508 *
509 * @param renderer the object that created the signal
510 * @param path the path identifying the edited cell
511 * @param new_text the new text, if empty, remove the line
512 * @param user_data the 'struct AdvertiseContext'
513 */
514void
515GNUNET_GTK_identity_advertise_metadata_value_text_edited_cb (GtkCellRendererText *renderer,
516 gchar *path,
517 gchar *new_text,
518 gpointer user_data)
519{
520 struct AdvertiseContext *ac = user_data;
521 GtkTreePath *tree_path;
522 GtkTreeIter iter;
523
524 tree_path = gtk_tree_path_new_from_string (path);
525 if (NULL == tree_path)
526 {
527 GNUNET_break (0);
528 return;
529 }
530 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (ac->metadata),
531 &iter, tree_path))
532 {
533 GNUNET_break (0);
534 gtk_tree_path_free (tree_path);
535 return;
536 }
537 gtk_tree_path_free (tree_path);
538 if ( (NULL != new_text) &&
539 (0 != strlen (new_text)) )
540 gtk_list_store_set (ac->metadata, &iter,
541 METADATA_MC_VALUE, new_text,
542 -1);
543 else
544 gtk_list_store_remove (ac->metadata, &iter);
545}
546
547
548/**
549 * User edited the 'value' field for inserting meta data. Update
550 * sensitivity of the 'add' button accordingly.
551 *
552 * @param editable the widget that was edited
553 * @param user_data the 'struct AdvertiseContext'
554 */
555void
556GNUNET_GTK_identity_advertise_metadata_value_entry_changed_cb (GtkEditable *editable,
557 gpointer user_data)
558{
559 struct AdvertiseContext *ac = user_data;
560 const char *value;
561 GtkEntry *value_entry;
562 GtkWidget * add_button;
563
564 value_entry = GTK_ENTRY (gtk_builder_get_object (ac->builder,
565 "GNUNET_GTK_identity_advertise_metadata_value_entry"));
566 value = gtk_entry_get_text (value_entry);
567 add_button = GTK_WIDGET (gtk_builder_get_object (ac->builder,
568 "GNUNET_GTK_identity_advertise_metadata_add_button"));
569 if ( (NULL == value) ||
570 (0 == strlen (value)) )
571 {
572 gtk_widget_set_sensitive (add_button,
573 FALSE);
574 return;
575 }
576 gtk_widget_set_sensitive (add_button,
577 TRUE);
578}
579
580
581/**
582 * User clicked the 'add' button, get the type and value and update
583 * the metadata model.
584 *
585 * @param button the 'add' button
586 * @param user_data the 'struct AdvertiseContext'
587 */
588void
589GNUNET_GTK_identity_advertise_metadata_add_button_clicked_cb (GtkButton * button,
590 gpointer user_data)
591{
592 struct AdvertiseContext *ac = user_data;
593 GtkTreeIter iter;
594 guint type;
595 const char *value;
596 GtkEntry *value_entry;
597 GtkComboBox *type_box;
598
599 type_box = GTK_COMBO_BOX (gtk_builder_get_object (ac->builder,
600 "GNUNET_GTK_identity_advertise_metadata_type_combobox"));
601 if (! gtk_combo_box_get_active_iter (type_box,
602 &iter))
603 {
604 GNUNET_break (0);
605 return;
606 }
607 gtk_tree_model_get (GTK_TREE_MODEL (ac->meta_types),
608 &iter,
609 METATYPES_MC_TYPE_AS_ENUM, &type,
610 -1);
611 value_entry = GTK_ENTRY (gtk_builder_get_object (ac->builder,
612 "GNUNET_GTK_identity_advertise_metadata_value_entry"));
613 value = gtk_entry_get_text (value_entry);
614 if ( (NULL == value) ||
615 (0 == strlen (value)) )
616 {
617 GNUNET_break (0);
618 return;
619 }
620 gtk_list_store_insert_with_values (ac->metadata,
621 &iter, 0,
622 METADATA_MC_TYPE_AS_ENUM, type,
623#if HAVE_EXTRACTOR
624 METADATA_MC_TYPE_AS_STRING, EXTRACTOR_metatype_to_string (type),
625#endif
626 METADATA_MC_VALUE, value,
627 -1);
628 gtk_entry_set_text (value_entry, "");
629}
630
631
632/**
633 * Run the dialog for advertising a namespace.
634 *
635 * @param priv private key of the namespace to advertise
636 */
637void
638GIG_advertise_dialog_start_ (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
639{
640 struct AdvertiseContext *ac;
641 gint i;
642 GtkTreeIter iter;
643
644 ac = GNUNET_new (struct AdvertiseContext);
645 ac->priv = *priv;
646 ac->builder =
647 GNUNET_GTK_get_new_builder ("gnunet_identity_gtk_advertise_dialog.glade",
648 ac);
649 if (NULL == ac->builder)
650 {
651 GNUNET_break (0);
652 GNUNET_free (ac);
653 return;
654 }
655 GNUNET_GTK_setup_expiration_year_adjustment (ac->builder);
656 ac->dialog = GTK_WIDGET (gtk_builder_get_object
657 (ac->builder, "GNUNET_GTK_identity_advertise_dialog"));
658 ac->keywords = GTK_LIST_STORE (gtk_builder_get_object
659 (ac->builder, "GNUNET_GTK_identity_advertise_keywords_liststore"));
660 ac->metadata = GTK_LIST_STORE (gtk_builder_get_object
661 (ac->builder, "GNUNET_GTK_identity_advertise_metadata_liststore"));
662 ac->meta_types = GTK_LIST_STORE (gtk_builder_get_object
663 (ac->builder, "GNUNET_GTK_identity_metadata_types_liststore"));
664 for (i = 0; EXTRACTOR_METATYPE_RESERVED != types[i]; i++)
665 {
666 gtk_list_store_insert_with_values (ac->meta_types,
667 &iter, G_MAXINT,
668#if HAVE_EXTRACTOR
669 METATYPES_MC_TYPE_AS_STRING, EXTRACTOR_metatype_to_string (types[i]),
670#endif
671 METATYPES_MC_TYPE_AS_ENUM, types[i],
672 -1);
673 if (0 == i)
674 gtk_combo_box_set_active_iter (GTK_COMBO_BOX
675 (gtk_builder_get_object
676 (ac->builder,
677 "GNUNET_GTK_identity_advertise_metadata_type_combobox")),
678 &iter);
679 }
680 gtk_list_store_insert_with_values (ac->keywords,
681 &iter, G_MAXINT,
682 KEYWORDS_MC_KEYWORD, NEW_KEYWORD_TEXT,
683 -1);
684 gtk_window_present (GTK_WINDOW (ac->dialog));
685}
686
687
688/* end of gnunet-identity-gtk_advertise.c */
diff --git a/src/identity/gnunet-identity-gtk_advertise.h b/src/identity/gnunet-identity-gtk_advertise.h
deleted file mode 100644
index a9bcc5fb..00000000
--- a/src/identity/gnunet-identity-gtk_advertise.h
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2005-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file src/identity/gnunet-identity-gtk_advertise.h
23 * @author LRN
24 * @author Christian Grothoff
25 */
26
27#ifndef GNUNET_IDENTITY_GTK_ADVERTISE_H
28#define GNUNET_IDENTITY_GTK_ADVERTISE_H
29
30#include "gnunet_gtk.h"
31
32
33/**
34 * Shutdown advertisement subsystem, this process is terminating.
35 */
36void
37GIG_advertise_shutdown_ (void);
38
39
40/**
41 * Run the dialog for advertising a namespace.
42 *
43 * @param priv private key of the namespace to advertise
44 */
45void
46GIG_advertise_dialog_start_ (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv);
47
48#endif
49/* GNUNET_FS_GTK_NAMESPACE_MANAGER_H */
50
51/* end of gnunet-identity-gtk_advertise.h */