diff options
Diffstat (limited to 'src/identity/gnunet-identity-gtk.c')
-rw-r--r-- | src/identity/gnunet-identity-gtk.c | 550 |
1 files changed, 0 insertions, 550 deletions
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 | */ | ||
34 | enum 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 | */ | ||
57 | static struct GNUNET_GTK_MainLoop *ml; | ||
58 | |||
59 | /** | ||
60 | * Handle to IDENTITY service. | ||
61 | */ | ||
62 | static struct GNUNET_IDENTITY_Handle *identity; | ||
63 | |||
64 | /** | ||
65 | * Main window list store. | ||
66 | */ | ||
67 | static GtkListStore *ls; | ||
68 | |||
69 | |||
70 | /** | ||
71 | * We need to track active operations with the identity service. | ||
72 | */ | ||
73 | struct 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 | */ | ||
97 | static struct OperationContext *oc_head; | ||
98 | |||
99 | /** | ||
100 | * Tail of operations. | ||
101 | */ | ||
102 | static struct OperationContext *oc_tail; | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Get our configuration. | ||
107 | * | ||
108 | * @return configuration handle | ||
109 | */ | ||
110 | const struct GNUNET_CONFIGURATION_Handle * | ||
111 | GIG_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 | */ | ||
123 | static GObject * | ||
124 | get_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 | */ | ||
136 | static void | ||
137 | operation_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 | */ | ||
154 | struct 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 | */ | ||
170 | static void | ||
171 | advertise_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 | */ | ||
188 | static void | ||
189 | advertise_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 | */ | ||
209 | gboolean | ||
210 | GNUNET_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 | */ | ||
271 | gboolean | ||
272 | GNUNET_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 | */ | ||
311 | void | ||
312 | GNUNET_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 | */ | ||
377 | static void | ||
378 | shutdown_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 | */ | ||
409 | void | ||
410 | GNUNET_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 | */ | ||
425 | static void | ||
426 | add_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 | */ | ||
492 | static void | ||
493 | run (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 | */ | ||
532 | int | ||
533 | main (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 */ | ||