diff options
Diffstat (limited to 'src/conversation')
17 files changed, 2267 insertions, 2004 deletions
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am index 4b7810e9..256131c9 100644 --- a/src/conversation/Makefile.am +++ b/src/conversation/Makefile.am | |||
@@ -14,14 +14,20 @@ endif | |||
14 | gnunet_conversation_gtk_SOURCES = \ | 14 | gnunet_conversation_gtk_SOURCES = \ |
15 | gnunet-conversation-gtk.c \ | 15 | gnunet-conversation-gtk.c \ |
16 | gnunet-conversation-gtk.h \ | 16 | gnunet-conversation-gtk.h \ |
17 | gnunet-conversation-gtk_phone.c \ | ||
18 | gnunet-conversation-gtk_phone.h \ | ||
19 | gnunet-conversation-gtk_egos.c \ | 17 | gnunet-conversation-gtk_egos.c \ |
20 | gnunet-conversation-gtk_egos.h \ | 18 | gnunet-conversation-gtk_egos.h \ |
21 | gnunet-conversation-gtk_contacts.c \ | 19 | gnunet-conversation-gtk_contacts.c \ |
22 | gnunet-conversation-gtk_contacts.h \ | 20 | gnunet-conversation-gtk_contacts.h \ |
23 | gnunet-conversation-gtk_history.c \ | 21 | gnunet-conversation-gtk_history.c \ |
24 | gnunet-conversation-gtk_history.h \ | 22 | gnunet-conversation-gtk_history.h \ |
23 | gnunet-conversation-gtk_import.c \ | ||
24 | gnunet-conversation-gtk_import.h \ | ||
25 | gnunet-conversation-gtk_log.c \ | ||
26 | gnunet-conversation-gtk_log.h \ | ||
27 | gnunet-conversation-gtk_phone.c \ | ||
28 | gnunet-conversation-gtk_phone.h \ | ||
29 | gnunet-conversation-gtk_zones.c \ | ||
30 | gnunet-conversation-gtk_zones.h \ | ||
25 | gnunet-conversation-gtk_about.c | 31 | gnunet-conversation-gtk_about.c |
26 | 32 | ||
27 | gnunet_conversation_gtk_LDADD = \ | 33 | gnunet_conversation_gtk_LDADD = \ |
diff --git a/src/conversation/gnunet-conversation-gtk.c b/src/conversation/gnunet-conversation-gtk.c index f6675966..767c2fab 100644 --- a/src/conversation/gnunet-conversation-gtk.c +++ b/src/conversation/gnunet-conversation-gtk.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -23,61 +23,14 @@ | |||
23 | * @brief Main function of gnunet-conversation-gtk | 23 | * @brief Main function of gnunet-conversation-gtk |
24 | * @author yids | 24 | * @author yids |
25 | * @author hark | 25 | * @author hark |
26 | * @author Christian Grothoff | ||
26 | */ | 27 | */ |
27 | #include "gnunet-conversation-gtk.h" | 28 | #include "gnunet-conversation-gtk.h" |
28 | #include "gnunet-conversation-gtk_history.h" | ||
29 | #include "gnunet-conversation-gtk_contacts.h" | 29 | #include "gnunet-conversation-gtk_contacts.h" |
30 | #include "gnunet-conversation-gtk_egos.h" | 30 | #include "gnunet-conversation-gtk_egos.h" |
31 | 31 | #include "gnunet-conversation-gtk_history.h" | |
32 | 32 | #include "gnunet-conversation-gtk_import.h" | |
33 | /** | 33 | #include "gnunet-conversation-gtk_phone.h" |
34 | * List of incoming calls | ||
35 | */ | ||
36 | struct CallList | ||
37 | { | ||
38 | |||
39 | /** | ||
40 | * A DLL. | ||
41 | */ | ||
42 | struct CallList *prev; | ||
43 | |||
44 | /** | ||
45 | * A DLL. | ||
46 | */ | ||
47 | struct CallList *next; | ||
48 | |||
49 | /** | ||
50 | * Handle to hang up or activate. | ||
51 | */ | ||
52 | struct GNUNET_CONVERSATION_Caller *caller; | ||
53 | |||
54 | /** | ||
55 | * Handle to call currently selected in list | ||
56 | */ | ||
57 | struct GNUNET_CONVERSATION_Caller *caller_selected; | ||
58 | |||
59 | /** | ||
60 | * String identifying the caller. | ||
61 | */ | ||
62 | char *caller_id; | ||
63 | |||
64 | /** | ||
65 | * Unique number of the caller. | ||
66 | */ | ||
67 | unsigned int caller_num; | ||
68 | |||
69 | }; | ||
70 | |||
71 | |||
72 | /** | ||
73 | * | ||
74 | */ | ||
75 | static struct GNUNET_CONVERSATION_Caller *caller_selected; | ||
76 | |||
77 | /** | ||
78 | * | ||
79 | */ | ||
80 | static struct GNUNET_CONVERSATION_Call *call_selected; | ||
81 | 34 | ||
82 | /** | 35 | /** |
83 | * Handle to our main loop. | 36 | * Handle to our main loop. |
@@ -85,138 +38,24 @@ static struct GNUNET_CONVERSATION_Call *call_selected; | |||
85 | static struct GNUNET_GTK_MainLoop *ml; | 38 | static struct GNUNET_GTK_MainLoop *ml; |
86 | 39 | ||
87 | /** | 40 | /** |
88 | * Our configurations. | 41 | * Our configuration. |
89 | */ | 42 | */ |
90 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 43 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
91 | 44 | ||
92 | /** | 45 | /** |
93 | * Name of our ego. | 46 | * Should gnunet-conversation-gtk start in tray mode? |
94 | */ | ||
95 | static char *ego_name; | ||
96 | |||
97 | /** | ||
98 | * Be verbose. | ||
99 | */ | ||
100 | static int verbose = 1; | ||
101 | |||
102 | /** | ||
103 | * Should gnunet-identity-gtk start in tray mode? | ||
104 | */ | 47 | */ |
105 | static int tray_only; | 48 | static int tray_only; |
106 | 49 | ||
107 | /** | 50 | /** |
108 | * List of active calls | ||
109 | */ | ||
110 | static GtkListStore *active_liststore; | ||
111 | |||
112 | /** | ||
113 | * List of active calls | ||
114 | */ | ||
115 | static GtkTreeView *active_treeview; | ||
116 | |||
117 | /** | ||
118 | * Unique number of call (outgoing) | ||
119 | */ | ||
120 | static unsigned int call_counter; | ||
121 | |||
122 | /** | ||
123 | * Phone handle | ||
124 | */ | ||
125 | static struct GNUNET_CONVERSATION_Phone *phone; | ||
126 | |||
127 | /** | ||
128 | * Call handle (for active outgoing call). | ||
129 | */ | ||
130 | static struct GNUNET_CONVERSATION_Call *call; | ||
131 | |||
132 | /** | ||
133 | * Caller handle (for active incoming call). | ||
134 | */ | ||
135 | static struct CallList *cl_active; | ||
136 | |||
137 | /** | ||
138 | * Head of calls waiting to be accepted. | ||
139 | */ | ||
140 | static struct CallList *cl_head; | ||
141 | |||
142 | /** | ||
143 | * Tail of calls waiting to be accepted. | ||
144 | */ | ||
145 | static struct CallList *cl_tail; | ||
146 | |||
147 | /** | ||
148 | * Desired phone line. | 51 | * Desired phone line. |
149 | */ | 52 | */ |
150 | static unsigned int line; | 53 | static unsigned int line; |
151 | 54 | ||
152 | /** | 55 | /** |
153 | * debug box enabled | 56 | * Ego the user wants to use. |
154 | */ | ||
155 | static unsigned int debug_box_enabled; | ||
156 | |||
157 | /** | ||
158 | * Our speaker. | ||
159 | */ | ||
160 | static struct GNUNET_SPEAKER_Handle *speaker; | ||
161 | |||
162 | /** | ||
163 | * Our microphone. | ||
164 | */ | ||
165 | static struct GNUNET_MICROPHONE_Handle *mic; | ||
166 | |||
167 | /** | ||
168 | * Name of conversation partner (if any). | ||
169 | */ | 57 | */ |
170 | static char *peer_name; | 58 | static char *ego_name; |
171 | |||
172 | /** | ||
173 | * Our phone's current state. | ||
174 | */ | ||
175 | static enum PhoneState phone_state; | ||
176 | |||
177 | /** | ||
178 | * Our call's current state. | ||
179 | */ | ||
180 | static enum CallState call_state; | ||
181 | |||
182 | /** | ||
183 | * Counts the number of incoming calls we have had so far. | ||
184 | */ | ||
185 | static unsigned int caller_num_gen; | ||
186 | |||
187 | /** | ||
188 | * GNS address for this phone. | ||
189 | */ | ||
190 | static char *address; | ||
191 | |||
192 | static GtkWidget *b_contact; | ||
193 | |||
194 | static GtkWidget *b_accept; | ||
195 | |||
196 | static GtkWidget *b_hangup; | ||
197 | |||
198 | static GtkWidget *b_suspend; | ||
199 | |||
200 | static GtkWidget *b_resume; | ||
201 | |||
202 | /** | ||
203 | * list of zones | ||
204 | */ | ||
205 | static GtkListStore *zone_liststore; | ||
206 | |||
207 | /** | ||
208 | * Our ego. | ||
209 | */ | ||
210 | static struct GNUNET_IDENTITY_Ego *caller_id; | ||
211 | |||
212 | |||
213 | void | ||
214 | GNUNET_CONVERSATION_GTK_on_active_calls_selection_changed (void); | ||
215 | |||
216 | |||
217 | static void | ||
218 | set_status_icon (const char *icon_name); | ||
219 | |||
220 | 59 | ||
221 | /** | 60 | /** |
222 | * Get an object from the main window. | 61 | * Get an object from the main window. |
@@ -232,342 +71,8 @@ GCG_get_main_window_object (const char *name) | |||
232 | 71 | ||
233 | 72 | ||
234 | /** | 73 | /** |
235 | * log a message to gtk log textbuffer | 74 | * Updates the status icon to the image of the given name. |
236 | * | 75 | * TODO: support animations. |
237 | * @param message format string for message to be logged | ||
238 | * @param ... arguments for the format string | ||
239 | */ | ||
240 | void | ||
241 | GCG_log (const char *message, | ||
242 | ...) | ||
243 | { | ||
244 | GtkTextBuffer *logbuff; | ||
245 | GtkTextView *log_view; | ||
246 | GtkTextIter iter; | ||
247 | gchar *fmsg; | ||
248 | va_list ap; | ||
249 | |||
250 | log_view = GTK_TEXT_VIEW (GCG_get_main_window_object ("GNUNET_GTK_conversation_log")); | ||
251 | logbuff = GTK_TEXT_BUFFER (gtk_text_view_get_buffer (log_view)); | ||
252 | va_start (ap, message); | ||
253 | fmsg = g_strdup_vprintf (message, | ||
254 | ap); | ||
255 | va_end (ap); | ||
256 | gtk_text_buffer_get_start_iter (logbuff, | ||
257 | &iter); | ||
258 | gtk_text_buffer_insert (logbuff, | ||
259 | &iter, | ||
260 | fmsg, | ||
261 | -1); | ||
262 | g_free (fmsg); | ||
263 | } | ||
264 | |||
265 | |||
266 | /** | ||
267 | * update status bar | ||
268 | * | ||
269 | * @param message format string for message to put in statusbar | ||
270 | * @param ... arguments for the format string | ||
271 | */ | ||
272 | void | ||
273 | GCG_update_status (const gchar *message, | ||
274 | ...) | ||
275 | { | ||
276 | GtkStatusbar *status_bar; | ||
277 | guint status_bar_context; | ||
278 | gchar *buff; | ||
279 | va_list ap; | ||
280 | |||
281 | status_bar = GTK_STATUSBAR (GCG_get_main_window_object ("GNUNET_GTK_conversation_statusbar")); | ||
282 | status_bar_context = gtk_statusbar_get_context_id (status_bar, "blaat"); | ||
283 | va_start (ap, message); | ||
284 | buff = g_strdup_vprintf (message, | ||
285 | ap); | ||
286 | va_end (ap); | ||
287 | gtk_statusbar_push (GTK_STATUSBAR (status_bar), | ||
288 | GPOINTER_TO_INT (status_bar_context), buff); | ||
289 | g_free (buff); | ||
290 | GNUNET_CONVERSATION_GTK_on_active_calls_selection_changed (); // FIXME: why do this here? | ||
291 | } | ||
292 | |||
293 | |||
294 | /** | ||
295 | * update status based on current phone state. | ||
296 | * | ||
297 | * @param args arguments given to the command | ||
298 | */ | ||
299 | static void | ||
300 | do_status () | ||
301 | { | ||
302 | switch (phone_state) | ||
303 | { | ||
304 | case PS_LOOKUP_EGO: | ||
305 | GCG_update_status (_("We are currently trying to locate the private key for the ego `%s'."), | ||
306 | ego_name); | ||
307 | set_status_icon ("gnunet-conversation-gtk-tray-pending"); | ||
308 | break; | ||
309 | case PS_LISTEN: | ||
310 | GCG_update_status (_("We are listening for incoming calls for ego `%s' on line %u."), | ||
311 | ego_name, | ||
312 | line); | ||
313 | set_status_icon ("gnunet-conversation-gtk-tray-available"); | ||
314 | break; | ||
315 | case PS_ACCEPTED: | ||
316 | GCG_update_status (_("You are having a conversation with `%s'.\n"), | ||
317 | peer_name); | ||
318 | set_status_icon ("gnunet-conversation-call-active"); | ||
319 | break; | ||
320 | case PS_ERROR: | ||
321 | GCG_update_status (_("We had an internal error setting up our phone line. You can still make calls.")); | ||
322 | set_status_icon ("gnunet-conversation-offline"); | ||
323 | break; | ||
324 | } | ||
325 | if (NULL != call) | ||
326 | { | ||
327 | switch (call_state) | ||
328 | { | ||
329 | case CS_RESOLVING: | ||
330 | GCG_update_status (_("We are trying to find the network address to call `%s'."), | ||
331 | peer_name); | ||
332 | set_status_icon ("gnunet-conversation-gtk-tray-call-pending"); | ||
333 | break; | ||
334 | case CS_RINGING: | ||
335 | GCG_update_status (_("We are calling `%s', his phone should be ringing."), | ||
336 | peer_name); | ||
337 | set_status_icon ("gnunet-conversation-gtk-tray-call-ringing"); | ||
338 | break; | ||
339 | case CS_CONNECTED: | ||
340 | GCG_update_status (_("You are having a conversation with `%s'."), | ||
341 | peer_name); | ||
342 | set_status_icon ("gnunet-conversation-gtk-tray-call-active"); | ||
343 | break; | ||
344 | case CS_SUSPENDED: | ||
345 | GCG_update_status (_("Conversation suspended, you can accept or initiate another call now."), | ||
346 | peer_name); | ||
347 | set_status_icon ("gnunet-conversation-gtk-tray-call-suspended"); | ||
348 | break; | ||
349 | } | ||
350 | } | ||
351 | if ( ( (NULL == call) || | ||
352 | (CS_SUSPENDED == call_state) ) && | ||
353 | (NULL != cl_head) && | ||
354 | ( (cl_head != cl_active) || | ||
355 | (cl_head != cl_tail) ) ) | ||
356 | set_status_icon ("gnunet-conversation-gtk-tray-call-incoming"); | ||
357 | } | ||
358 | |||
359 | |||
360 | /** | ||
361 | * @brief print info for currently selected call | ||
362 | */ | ||
363 | static void | ||
364 | print_call_info () | ||
365 | { | ||
366 | GtkTreeIter gtkiter; | ||
367 | gboolean valid; | ||
368 | gint row_count = 0; | ||
369 | |||
370 | valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (active_liststore), | ||
371 | >kiter); | ||
372 | if (! valid) | ||
373 | GNUNET_break(0); | ||
374 | |||
375 | while (valid) | ||
376 | { | ||
377 | gchar *str_data; | ||
378 | gint int_data; | ||
379 | gpointer cl_caller; | ||
380 | gpointer cl_call; | ||
381 | |||
382 | gtk_tree_model_get (GTK_TREE_MODEL (active_liststore), | ||
383 | >kiter, | ||
384 | AL_caller, &cl_caller, | ||
385 | AL_caller_id, &str_data, | ||
386 | AL_caller_num, &int_data, | ||
387 | AL_call, &cl_call, | ||
388 | -1); | ||
389 | if (call_selected == cl_call) | ||
390 | { | ||
391 | GCG_log (_("info for active outgoing call:%s number: %u row: %u"), | ||
392 | str_data, | ||
393 | int_data, | ||
394 | row_count); | ||
395 | break; | ||
396 | } | ||
397 | g_free (str_data); | ||
398 | row_count++; | ||
399 | valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(active_liststore), >kiter); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | |||
404 | /** | ||
405 | * @brief sets caller_selected, and enables or disables the active call list buttons | ||
406 | */ | ||
407 | static void | ||
408 | update_active_call_list_buttons() | ||
409 | { | ||
410 | gchar *caller_id; | ||
411 | gpointer cl_caller; | ||
412 | gpointer cl_call; | ||
413 | gint cl_caller_state; | ||
414 | gint cl_type; | ||
415 | //gint cl_caller_type; | ||
416 | GtkTreeSelection *active_selection; | ||
417 | GtkTreeIter gcl_selected; | ||
418 | // active_liststore_selection = GCG_get_main_window_object(ml,"GNUNET_CONVERSATION_GTK_active_calls_selection"); | ||
419 | |||
420 | // reset references to selected call/caller | ||
421 | //caller_selected = NULL; | ||
422 | //call_selected = NULL; | ||
423 | GCG_log("reset caller selected"); | ||
424 | active_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (active_treeview)); | ||
425 | if (gtk_tree_selection_get_selected (active_selection, | ||
426 | NULL, | ||
427 | &gcl_selected)) | ||
428 | { | ||
429 | // get selected call | ||
430 | gtk_tree_model_get (GTK_TREE_MODEL(active_liststore), &gcl_selected, | ||
431 | AL_caller, &cl_caller, // reference to incoming call | ||
432 | AL_caller_id, &caller_id, | ||
433 | AL_caller_state, &cl_caller_state, | ||
434 | AL_type, &cl_type, | ||
435 | AL_call, &cl_call, // reference to outgoing call | ||
436 | -1); | ||
437 | // check if selected call is a incoming or outgoing call | ||
438 | switch (cl_type) | ||
439 | { | ||
440 | case CALL_IN: | ||
441 | call_selected = NULL; | ||
442 | caller_selected = cl_caller; | ||
443 | GNUNET_break (NULL != caller_selected); | ||
444 | break; | ||
445 | case CALL_OUT: | ||
446 | caller_selected = NULL; | ||
447 | call_selected = cl_call; | ||
448 | GCG_log("outgoing selected"); | ||
449 | GNUNET_break (NULL != call_selected); | ||
450 | break; | ||
451 | default: | ||
452 | GNUNET_break(0); | ||
453 | break; | ||
454 | } | ||
455 | gtk_widget_show(GTK_WIDGET(GCG_get_main_window_object("GNUNET_GTK_conversation_active_call_list_buttons"))); | ||
456 | GCG_log("caller state: %u phone_state: %u", | ||
457 | cl_caller_state, | ||
458 | phone_state); | ||
459 | switch (cl_caller_state) | ||
460 | { | ||
461 | /* buttons: | ||
462 | * contact | ||
463 | * accept | ||
464 | * hangup | ||
465 | * suspend | ||
466 | * resume | ||
467 | * | ||
468 | * TODO: check if there is incoming or outgoing call, | ||
469 | * disable resume and accept buttons. | ||
470 | * or suspend that other call | ||
471 | */ | ||
472 | case CT_active: | ||
473 | // hangup, pause | ||
474 | //GCG_log("CT_active state: %u ",cl_caller_state); | ||
475 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
476 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
477 | gtk_widget_set_sensitive (b_hangup, TRUE); | ||
478 | gtk_widget_set_sensitive (b_suspend, TRUE); | ||
479 | gtk_widget_set_sensitive (b_resume, FALSE); | ||
480 | break; | ||
481 | case CT_ringing: | ||
482 | // pickup, phonebook | ||
483 | //GCG_log("CT_ring show button"); | ||
484 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
485 | if (phone_state == PS_LISTEN) | ||
486 | { | ||
487 | gtk_widget_set_sensitive (b_accept, TRUE); | ||
488 | } | ||
489 | else | ||
490 | { | ||
491 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
492 | } | ||
493 | gtk_widget_set_sensitive (b_hangup, FALSE); | ||
494 | gtk_widget_set_sensitive (b_suspend, FALSE); | ||
495 | gtk_widget_set_sensitive (b_resume, FALSE); | ||
496 | break; | ||
497 | case CT_rejected: | ||
498 | //add to phonebook | ||
499 | //GCG_log("CT_rejected "); | ||
500 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
501 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
502 | gtk_widget_set_sensitive (b_hangup, FALSE); | ||
503 | gtk_widget_set_sensitive (b_suspend, FALSE); | ||
504 | gtk_widget_set_sensitive (b_resume, FALSE); | ||
505 | break; | ||
506 | case CT_suspended: | ||
507 | // resume, hangup | ||
508 | //GCG_log("CT_suspended "); | ||
509 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
510 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
511 | gtk_widget_set_sensitive (b_hangup, TRUE); | ||
512 | gtk_widget_set_sensitive (b_suspend, FALSE); | ||
513 | if (phone_state == PS_LISTEN) | ||
514 | { | ||
515 | GCG_log("enable resume button"); | ||
516 | gtk_widget_set_sensitive (b_resume, TRUE); | ||
517 | } | ||
518 | else | ||
519 | { | ||
520 | GCG_log("do not disable resume button (for test)"); | ||
521 | gtk_widget_set_sensitive (b_resume, TRUE); | ||
522 | } | ||
523 | break; | ||
524 | case CT_other: | ||
525 | //add to phonebook | ||
526 | //GCG_log("CT_rejected "); | ||
527 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
528 | gtk_widget_set_sensitive (b_accept, TRUE); | ||
529 | gtk_widget_set_sensitive (b_hangup, TRUE); | ||
530 | gtk_widget_set_sensitive (b_suspend, TRUE); | ||
531 | gtk_widget_set_sensitive (b_resume, TRUE); | ||
532 | break; | ||
533 | |||
534 | default: | ||
535 | GNUNET_break(0); | ||
536 | break; | ||
537 | } | ||
538 | print_call_info(); | ||
539 | } | ||
540 | else | ||
541 | { | ||
542 | GCG_log("nothing selected"); | ||
543 | //gtk_widget_hide(GTK_WIDGET(GCG_get_main_window_object("GNUNET_GTK_conversation_active_call_list_buttons" ))); | ||
544 | } | ||
545 | } | ||
546 | |||
547 | |||
548 | /** | ||
549 | * @brief executed when selecting a different item in active call list | ||
550 | */ | ||
551 | void | ||
552 | GNUNET_CONVERSATION_GTK_on_active_calls_selection_changed() | ||
553 | { | ||
554 | update_active_call_list_buttons(); | ||
555 | } | ||
556 | |||
557 | |||
558 | void | ||
559 | disable_list_buttons() | ||
560 | { | ||
561 | gtk_widget_set_sensitive (b_contact, FALSE); | ||
562 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
563 | gtk_widget_set_sensitive (b_hangup, FALSE); | ||
564 | gtk_widget_set_sensitive (b_suspend, FALSE); | ||
565 | gtk_widget_set_sensitive (b_resume, FALSE); | ||
566 | } | ||
567 | |||
568 | |||
569 | /** | ||
570 | * set_status_icon | ||
571 | * | 76 | * |
572 | * available icons: | 77 | * available icons: |
573 | * gnunet-conversation-gtk-tray-pending | 78 | * gnunet-conversation-gtk-tray-pending |
@@ -579,13 +84,15 @@ disable_list_buttons() | |||
579 | * gnunet-conversation-gtk-tray-call-suspended | 84 | * gnunet-conversation-gtk-tray-call-suspended |
580 | * gnunet-conversation-gtk-tray-call-incoming | 85 | * gnunet-conversation-gtk-tray-call-incoming |
581 | * | 86 | * |
87 | * @param icon_name name of the icon to use | ||
582 | */ | 88 | */ |
583 | void | 89 | void |
584 | set_status_icon (const char *icon_name) | 90 | GCG_set_status_icon (const char *icon_name) |
585 | { | 91 | { |
586 | GtkImage *status_icon; | 92 | GtkImage *status_icon; |
587 | 93 | ||
588 | status_icon = GTK_IMAGE (GCG_get_main_window_object ("GNUNET_GTK_status_icon")); | 94 | status_icon = GTK_IMAGE (GCG_get_main_window_object |
95 | ("GNUNET_GTK_status_icon")); | ||
589 | gtk_image_set_from_icon_name (status_icon, | 96 | gtk_image_set_from_icon_name (status_icon, |
590 | icon_name, | 97 | icon_name, |
591 | GTK_ICON_SIZE_BUTTON); | 98 | GTK_ICON_SIZE_BUTTON); |
@@ -595,768 +102,6 @@ set_status_icon (const char *icon_name) | |||
595 | 102 | ||
596 | 103 | ||
597 | /** | 104 | /** |
598 | * set button text | ||
599 | * | ||
600 | * @param button_name name of button | ||
601 | * @param label label on the button | ||
602 | */ | ||
603 | void | ||
604 | set_button_text (const char *button_name, | ||
605 | const char *label) | ||
606 | { | ||
607 | GtkWidget *button; | ||
608 | |||
609 | button = GTK_WIDGET (GCG_get_main_window_object (button_name)); | ||
610 | gtk_widget_hide (button); | ||
611 | } | ||
612 | |||
613 | |||
614 | /** | ||
615 | * disable button | ||
616 | */ | ||
617 | void | ||
618 | disable_button (const char *button_name) | ||
619 | { | ||
620 | GtkWidget *button; | ||
621 | |||
622 | button = GTK_WIDGET (GCG_get_main_window_object (button_name)); | ||
623 | gtk_widget_hide (button); | ||
624 | } | ||
625 | |||
626 | |||
627 | /** | ||
628 | * enable button | ||
629 | */ | ||
630 | void | ||
631 | enable_button (const char *button_name) | ||
632 | { | ||
633 | //GtkButton *button; | ||
634 | GtkWidget *button; | ||
635 | |||
636 | button = GTK_WIDGET (GCG_get_main_window_object (button_name)); | ||
637 | gtk_widget_show (button); | ||
638 | } | ||
639 | |||
640 | |||
641 | /** | ||
642 | * set state of outgoing call | ||
643 | */ | ||
644 | void | ||
645 | set_outgoing_call_state (struct GNUNET_CONVERSATION_Call *call, | ||
646 | int state) | ||
647 | { | ||
648 | GtkTreeIter gtkiter; | ||
649 | gint valid = 0; | ||
650 | gint cl_type; | ||
651 | |||
652 | GCG_log("set state to: %u", state); | ||
653 | valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( active_liststore ), >kiter); | ||
654 | |||
655 | if (!valid) | ||
656 | GNUNET_break(0); | ||
657 | while (valid) | ||
658 | { | ||
659 | gchar *cl_caller_id; | ||
660 | gint cl_caller_num; | ||
661 | gpointer cl_call; | ||
662 | |||
663 | gtk_tree_model_get ( GTK_TREE_MODEL( active_liststore ), >kiter, | ||
664 | AL_call, &cl_call, | ||
665 | AL_caller_id,&cl_caller_id, | ||
666 | AL_caller_num,&cl_caller_num, | ||
667 | AL_type, &cl_type, | ||
668 | -1); | ||
669 | if (cl_type == CALL_OUT) | ||
670 | { | ||
671 | if (call == NULL) // function called by phone event handler | ||
672 | { | ||
673 | GCG_log("event handler"); | ||
674 | gtk_list_store_set(active_liststore, >kiter, | ||
675 | AL_call_state, state, | ||
676 | -1); | ||
677 | switch (state) | ||
678 | { | ||
679 | /** | ||
680 | * We are the caller and are now ringing the other party (GNS lookup | ||
681 | * succeeded). | ||
682 | */ | ||
683 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | ||
684 | break; | ||
685 | /** | ||
686 | * We are the caller and are now ready to talk as the callee picked up. | ||
687 | */ | ||
688 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | ||
689 | break; | ||
690 | /** | ||
691 | * We are the caller and failed to locate a phone record in GNS. | ||
692 | * After this invocation, the respective call handle will be | ||
693 | * automatically destroyed and the client must no longer call | ||
694 | * #GNUNET_CONVERSATION_call_stop or any other function on the | ||
695 | * call object. | ||
696 | */ | ||
697 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | ||
698 | gtk_list_store_remove(active_liststore,>kiter); | ||
699 | disable_list_buttons(); | ||
700 | break; | ||
701 | /** | ||
702 | * We are the caller and the callee called | ||
703 | * #GNUNET_CONVERSATION_caller_hang_up. After this invocation, the | ||
704 | * respective call handle will be automatically destroyed and the | ||
705 | * client must no longer call #GNUNET_CONVERSATION_call_stop. | ||
706 | */ | ||
707 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | ||
708 | gtk_list_store_remove(active_liststore,>kiter); | ||
709 | disable_list_buttons(); | ||
710 | break; | ||
711 | /** | ||
712 | * We are the caller and the callee suspended the call. Note that | ||
713 | * both sides can independently suspend and resume calls; a call is | ||
714 | * only "working" of both sides are active. | ||
715 | */ | ||
716 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | ||
717 | break; | ||
718 | /** | ||
719 | * We are the caller and the callee suspended the call. Note that | ||
720 | * both sides can independently suspend and resume calls; a call is | ||
721 | * only "working" of both sides are active. | ||
722 | */ | ||
723 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | ||
724 | break; | ||
725 | /** | ||
726 | * We had an error handing the call, and are now restarting it | ||
727 | * (back to lookup). This happens, for example, if the peer | ||
728 | * is restarted during a call. | ||
729 | */ | ||
730 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | ||
731 | break; | ||
732 | default: | ||
733 | break; | ||
734 | } | ||
735 | } | ||
736 | else if (call == cl_call) // function called for specific call | ||
737 | { | ||
738 | //GCG_log (_("setting state for call:%u row: %u state: %u"),cl_caller_num,row_count,state); | ||
739 | |||
740 | switch (state) | ||
741 | { | ||
742 | case CT_hangup: | ||
743 | //GCG_log("remove line cause hangup"); | ||
744 | gtk_list_store_remove(active_liststore,>kiter); | ||
745 | disable_list_buttons(); | ||
746 | break; | ||
747 | case CT_rejected: | ||
748 | //GCG_log("remove line cause rejected"); | ||
749 | gtk_list_store_remove(active_liststore,>kiter); | ||
750 | disable_list_buttons(); | ||
751 | break; | ||
752 | default: | ||
753 | gtk_list_store_set(active_liststore, >kiter, | ||
754 | AL_caller_state, state, | ||
755 | -1); | ||
756 | break; | ||
757 | }//end switch | ||
758 | }//end call=cl_call | ||
759 | } //end cl_type | ||
760 | g_free (cl_caller_id); | ||
761 | valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(active_liststore), >kiter); | ||
762 | |||
763 | }//end while | ||
764 | GCG_update_status (""); | ||
765 | } | ||
766 | |||
767 | |||
768 | /** | ||
769 | * set call state of a incoming call | ||
770 | */ | ||
771 | static void | ||
772 | set_incoming_call_state (struct GNUNET_CONVERSATION_Caller *caller, | ||
773 | int state) | ||
774 | { | ||
775 | GtkTreeIter gtkiter; | ||
776 | gint valid = 0; | ||
777 | //FPRINTF (stderr,"set incoming call state:%u caller: ",state); | ||
778 | |||
779 | // GCG_log (_("set incoming call state:%u caller: "),state); | ||
780 | |||
781 | valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( active_liststore ), >kiter ); | ||
782 | |||
783 | if (!valid) | ||
784 | GNUNET_break(0); | ||
785 | |||
786 | while (valid) | ||
787 | { | ||
788 | gchar *cl_caller_id; | ||
789 | gint cl_caller_num; | ||
790 | gpointer cl_caller; | ||
791 | |||
792 | gtk_tree_model_get ( GTK_TREE_MODEL( active_liststore ), >kiter, | ||
793 | AL_caller, &cl_caller, | ||
794 | AL_caller_id,&cl_caller_id, | ||
795 | AL_caller_num,&cl_caller_num | ||
796 | ,-1); | ||
797 | |||
798 | if (caller == cl_caller) | ||
799 | { | ||
800 | //GCG_log (_("setting state for call:%u row: %u state: %u"),cl_caller_num,row_count,state); | ||
801 | |||
802 | switch (state) | ||
803 | { | ||
804 | case CT_hangup: | ||
805 | //GCG_log("remove line cause hangup"); | ||
806 | gtk_list_store_remove(active_liststore,>kiter); | ||
807 | disable_list_buttons(); | ||
808 | |||
809 | break; | ||
810 | |||
811 | case CT_rejected: | ||
812 | //GCG_log("remove line cause rejected"); | ||
813 | gtk_list_store_remove(active_liststore,>kiter); | ||
814 | disable_list_buttons(); | ||
815 | |||
816 | break; | ||
817 | default: | ||
818 | |||
819 | gtk_list_store_set(active_liststore, >kiter, | ||
820 | AL_caller_state, state, | ||
821 | -1); | ||
822 | break; | ||
823 | |||
824 | }//end switch | ||
825 | }//endif | ||
826 | |||
827 | g_free (cl_caller_id); | ||
828 | valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(active_liststore), >kiter); | ||
829 | |||
830 | }//end while | ||
831 | GCG_update_status(""); | ||
832 | } | ||
833 | |||
834 | |||
835 | /** | ||
836 | * Function called with an event emitted by a phone. | ||
837 | * | ||
838 | * @param cls closure | ||
839 | * @param code type of the event | ||
840 | * @param caller handle for the caller | ||
841 | * @param caller_id name of the caller in GNS | ||
842 | */ | ||
843 | static void | ||
844 | phone_event_handler (void *cls, | ||
845 | enum GNUNET_CONVERSATION_PhoneEventCode code, | ||
846 | struct GNUNET_CONVERSATION_Caller *caller, | ||
847 | const char *caller_id) | ||
848 | { | ||
849 | GtkTreeIter gtkiter; | ||
850 | GtkTreeIter gtkiter1; | ||
851 | gboolean valid; | ||
852 | |||
853 | switch (code) | ||
854 | { | ||
855 | case GNUNET_CONVERSATION_EC_PHONE_RING: | ||
856 | //increment call # | ||
857 | caller_num_gen++; | ||
858 | |||
859 | |||
860 | GCG_log (_("A Incoming call from `%s' with number %u\n"), caller_id, | ||
861 | caller_num_gen); | ||
862 | |||
863 | //old | ||
864 | struct CallList *cl; | ||
865 | |||
866 | cl = GNUNET_new (struct CallList); | ||
867 | cl->caller = caller; | ||
868 | cl->caller_id = GNUNET_strdup (caller_id); | ||
869 | cl->caller_num = caller_num_gen; | ||
870 | GNUNET_CONTAINER_DLL_insert (cl_head, cl_tail, cl); | ||
871 | //gtk | ||
872 | gtk_list_store_append (active_liststore, >kiter); | ||
873 | |||
874 | gtk_list_store_set (active_liststore, >kiter, | ||
875 | AL_caller_id, caller_id, | ||
876 | AL_caller, caller, | ||
877 | AL_caller_num, caller_num_gen, | ||
878 | AL_caller_state, CT_ringing, | ||
879 | AL_type, CALL_IN | ||
880 | ,-1); | ||
881 | |||
882 | |||
883 | break; | ||
884 | |||
885 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
886 | //gtk | ||
887 | |||
888 | valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( active_liststore ), >kiter1 ); | ||
889 | |||
890 | if (!valid) | ||
891 | GNUNET_break(0); | ||
892 | |||
893 | while (valid) | ||
894 | { | ||
895 | //FPRINTF(stderr,"GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: while valid"); | ||
896 | |||
897 | gchar *str_data; | ||
898 | gint int_data; | ||
899 | gpointer cl_caller; | ||
900 | |||
901 | gtk_tree_model_get (GTK_TREE_MODEL(active_liststore), >kiter1, | ||
902 | AL_caller, &cl_caller, | ||
903 | AL_caller_id,&str_data, | ||
904 | AL_caller_num,&int_data,-1); | ||
905 | if (caller == cl_caller) | ||
906 | { | ||
907 | |||
908 | GCG_log (_("phone hung up:%s number: %u "), str_data,int_data); | ||
909 | set_incoming_call_state(caller,CT_rejected); | ||
910 | break ; | ||
911 | } | ||
912 | g_free (str_data); | ||
913 | valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(active_liststore), >kiter1); | ||
914 | } | ||
915 | |||
916 | |||
917 | |||
918 | phone_state = PS_LISTEN; | ||
919 | //add to call history list | ||
920 | //history_add(CH_HANGUP, cl->caller_id); | ||
921 | |||
922 | break; | ||
923 | |||
924 | } | ||
925 | do_status(); | ||
926 | } | ||
927 | |||
928 | |||
929 | /** | ||
930 | * Function called with an event emitted by a caller. | ||
931 | * | ||
932 | * @param cls closure with the `struct CallList` of the caller | ||
933 | * @param code type of the event issued by the caller | ||
934 | */ | ||
935 | static void | ||
936 | caller_event_handler (void *cls, | ||
937 | enum GNUNET_CONVERSATION_CallerEventCode code) | ||
938 | { | ||
939 | |||
940 | if (cls == NULL) | ||
941 | { | ||
942 | GCG_log("caller_event_handler: cls == NULL"); | ||
943 | GNUNET_break(0); | ||
944 | } | ||
945 | else | ||
946 | { | ||
947 | struct CallList *cl = cls; | ||
948 | |||
949 | switch (code) | ||
950 | { | ||
951 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: | ||
952 | //TODO: should this be cls? not cl->caller | ||
953 | set_incoming_call_state(cl->caller,CT_suspended); | ||
954 | GCG_log (_("Call from `%s' suspended by other user\n"), cl->caller_id); | ||
955 | break; | ||
956 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: | ||
957 | set_incoming_call_state(cl->caller,CT_active); | ||
958 | GCG_log (_("Call from `%s' resumed by other user\n"), cl->caller_id); | ||
959 | break; | ||
960 | } | ||
961 | } | ||
962 | do_status(); | ||
963 | } | ||
964 | |||
965 | |||
966 | /** | ||
967 | * Start our phone. | ||
968 | */ | ||
969 | static void | ||
970 | start_phone () | ||
971 | { | ||
972 | struct GNUNET_GNSRECORD_Data rd; | ||
973 | GtkLabel *label; | ||
974 | if (NULL == caller_id) | ||
975 | { | ||
976 | GCG_log (_("Ego `%s' no longer available, phone is now down.\n"), ego_name); | ||
977 | phone_state = PS_LOOKUP_EGO; | ||
978 | return; | ||
979 | } | ||
980 | //GNUNET_assert (NULL == phone); | ||
981 | phone = | ||
982 | GNUNET_CONVERSATION_phone_create (cfg, caller_id, &phone_event_handler, | ||
983 | NULL); | ||
984 | /* FIXME: get record and print full GNS record info later here... */ | ||
985 | if (NULL == phone) | ||
986 | { | ||
987 | GCG_log ("%s", _("Failed to setup phone (internal error)\n")); | ||
988 | phone_state = PS_ERROR; | ||
989 | } | ||
990 | else | ||
991 | { | ||
992 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); | ||
993 | GNUNET_free_non_null (address); | ||
994 | address = | ||
995 | GNUNET_GNSRECORD_value_to_string (rd.record_type, rd.data, | ||
996 | rd.data_size); | ||
997 | |||
998 | GCG_log (_("address: `%s' \n"), address); | ||
999 | |||
1000 | label = GTK_LABEL(GCG_get_main_window_object("GNUNET_CONVERSATION_GTK_my_address")); | ||
1001 | gtk_label_set_text(label, address); | ||
1002 | |||
1003 | if (verbose) | ||
1004 | GCG_log (_("Phone active on line %u\n"), | ||
1005 | (unsigned int) line); | ||
1006 | phone_state = PS_LISTEN; | ||
1007 | } | ||
1008 | do_status(); | ||
1009 | } | ||
1010 | |||
1011 | |||
1012 | /** | ||
1013 | * Function called with an event emitted by a call. | ||
1014 | * | ||
1015 | * @param cls closure, NULL | ||
1016 | * @param code type of the event on the call | ||
1017 | */ | ||
1018 | static void | ||
1019 | call_event_handler (void *cls, | ||
1020 | enum GNUNET_CONVERSATION_CallEventCode code) | ||
1021 | { | ||
1022 | //struct OutgoingCallClosure *cl = cls; | ||
1023 | |||
1024 | //GCG_log("call event handler code: %u num: %u", code, cl->call_num); | ||
1025 | |||
1026 | //if (cls == NULL){ | ||
1027 | set_outgoing_call_state(NULL, code); | ||
1028 | //GNUNET_break(0); | ||
1029 | //} else | ||
1030 | //{ | ||
1031 | switch (code) | ||
1032 | { | ||
1033 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | ||
1034 | GNUNET_break (CS_RESOLVING == call_state); | ||
1035 | GCG_log (_("Resolved address of `%s'. Now ringing other party."), peer_name); | ||
1036 | // set_outgoing_call_state(cls, CT_ringing); | ||
1037 | |||
1038 | call_state = CS_RINGING; | ||
1039 | break; | ||
1040 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | ||
1041 | GNUNET_break (CS_RINGING == call_state); | ||
1042 | GCG_log (_("Connection established to `%s'"), peer_name); | ||
1043 | call_state = CS_CONNECTED; | ||
1044 | break; | ||
1045 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | ||
1046 | GNUNET_break (CS_RESOLVING == call_state); | ||
1047 | GCG_log (_("Failed to resolve %s in ego `%s'"), peer_name, ego_name); | ||
1048 | call = NULL; | ||
1049 | break; | ||
1050 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | ||
1051 | GCG_log ("%s", _("Call terminated")); | ||
1052 | call = NULL; | ||
1053 | break; | ||
1054 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | ||
1055 | GNUNET_break (CS_CONNECTED == call_state); | ||
1056 | GCG_log (_("Connection to `%s' suspended (by other user)\n"), peer_name); | ||
1057 | break; | ||
1058 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | ||
1059 | GNUNET_break (CS_CONNECTED == call_state); | ||
1060 | GCG_log (_("Connection to `%s' resumed (by other user)\n"), peer_name); | ||
1061 | break; | ||
1062 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | ||
1063 | GCG_log ("GNUNET_CONVERSATION_EC_CALL_ERROR %s", peer_name); | ||
1064 | } | ||
1065 | //} | ||
1066 | } | ||
1067 | |||
1068 | |||
1069 | |||
1070 | /** | ||
1071 | * Initiating a new call | ||
1072 | * | ||
1073 | * @param arg arguments given to the command | ||
1074 | */ | ||
1075 | void | ||
1076 | GSC_do_call (const char *arg) | ||
1077 | { | ||
1078 | GtkEntry *address_entry; | ||
1079 | |||
1080 | address_entry = GTK_ENTRY (GCG_get_main_window_object ("GNUNET_GTK_conversation_address")); | ||
1081 | gtk_entry_set_text (address_entry, | ||
1082 | address); | ||
1083 | |||
1084 | if (NULL == caller_id) | ||
1085 | { | ||
1086 | GCG_log (_("Ego `%s' not available\n"), ego_name); | ||
1087 | return; | ||
1088 | } | ||
1089 | if (NULL != call) | ||
1090 | { | ||
1091 | GCG_log (_("You are calling someone else already, hang up first!\n")); | ||
1092 | return; | ||
1093 | } | ||
1094 | switch (phone_state) | ||
1095 | { | ||
1096 | case PS_LOOKUP_EGO: | ||
1097 | GCG_log (_("Ego `%s' not available\n"), ego_name); | ||
1098 | return; | ||
1099 | case PS_LISTEN: | ||
1100 | /* ok to call! */ | ||
1101 | break; | ||
1102 | case PS_ACCEPTED: | ||
1103 | GCG_log (_ | ||
1104 | ("You are answering call from `%s', hang up or suspend that call first!\n"), | ||
1105 | peer_name); | ||
1106 | GNUNET_break(0); | ||
1107 | return; | ||
1108 | case PS_ERROR: | ||
1109 | /* ok to call */ | ||
1110 | break; | ||
1111 | } | ||
1112 | //GNUNET_free_non_null (peer_name); | ||
1113 | peer_name = GNUNET_strdup (arg); | ||
1114 | GCG_log (_("now calling: %s"), peer_name); | ||
1115 | call_state = CS_RESOLVING; | ||
1116 | GNUNET_assert (NULL == call); | ||
1117 | |||
1118 | call_counter++; | ||
1119 | call = | ||
1120 | GNUNET_CONVERSATION_call_start (cfg, caller_id, arg, speaker, mic, | ||
1121 | &call_event_handler, NULL); | ||
1122 | //call = newcall; | ||
1123 | |||
1124 | // add call to active call list | ||
1125 | GtkTreeIter gtkiter; | ||
1126 | |||
1127 | gtk_list_store_append (active_liststore, >kiter); | ||
1128 | |||
1129 | gtk_list_store_set (active_liststore, >kiter, | ||
1130 | AL_caller_id, peer_name, | ||
1131 | AL_caller, NULL, | ||
1132 | AL_caller_num, NULL, | ||
1133 | AL_caller_state, CT_other, | ||
1134 | AL_type, CALL_OUT, | ||
1135 | AL_call, call, | ||
1136 | AL_call_num, call_counter, | ||
1137 | AL_call_state, CS_RESOLVING, | ||
1138 | -1 | ||
1139 | ); | ||
1140 | |||
1141 | |||
1142 | GCG_update_status (_("We are calling `%s', his phone should be ringing."), | ||
1143 | peer_name); | ||
1144 | GNUNET_CONVERSATION_GTK_history_add (CH_OUTGOING, peer_name); | ||
1145 | } | ||
1146 | |||
1147 | |||
1148 | /** | ||
1149 | * Accepting an incoming call | ||
1150 | * | ||
1151 | * @param args arguments given to the command | ||
1152 | */ | ||
1153 | static void | ||
1154 | do_accept (struct GNUNET_CONVERSATION_Caller *sel_caller) | ||
1155 | { | ||
1156 | struct CallList *cl; | ||
1157 | //char buf[32]; | ||
1158 | |||
1159 | |||
1160 | if ((NULL != call) && (CS_SUSPENDED != call_state)) | ||
1161 | { | ||
1162 | GCG_log (_("You are calling someone else already, hang up first!\n")); | ||
1163 | GNUNET_break(0); | ||
1164 | return; | ||
1165 | } | ||
1166 | switch (phone_state) | ||
1167 | { | ||
1168 | case PS_LOOKUP_EGO: | ||
1169 | GNUNET_break (0); | ||
1170 | break; | ||
1171 | case PS_LISTEN: | ||
1172 | /* this is the expected state */ | ||
1173 | break; | ||
1174 | case PS_ACCEPTED: | ||
1175 | GCG_log (_ | ||
1176 | ("You are answering call from `%s', hang up or suspend that call first!\n"), | ||
1177 | peer_name); | ||
1178 | GNUNET_break(0); | ||
1179 | return; | ||
1180 | case PS_ERROR: | ||
1181 | GNUNET_break (0); | ||
1182 | break; | ||
1183 | }//endswitch | ||
1184 | |||
1185 | phone_state = PS_ACCEPTED; | ||
1186 | set_incoming_call_state(sel_caller,CT_active); | ||
1187 | |||
1188 | for (cl = cl_head; cl; cl = cl->next) | ||
1189 | { | ||
1190 | /* FIXME: this may not be unique enough to identify the right item! | ||
1191 | * Why not store CallList items in treeview instead of just callers? | ||
1192 | */ | ||
1193 | if (cl->caller == sel_caller) | ||
1194 | break; | ||
1195 | } | ||
1196 | GNUNET_CONVERSATION_caller_pick_up (sel_caller, &caller_event_handler, cl, | ||
1197 | speaker, mic); | ||
1198 | |||
1199 | GNUNET_CONVERSATION_GTK_history_add (CH_ACCEPTED, peer_name); | ||
1200 | |||
1201 | } | ||
1202 | |||
1203 | |||
1204 | /** | ||
1205 | * Suspending a call | ||
1206 | * | ||
1207 | * @param args arguments given to the command | ||
1208 | */ | ||
1209 | static void | ||
1210 | do_suspend () | ||
1211 | { | ||
1212 | /* | ||
1213 | switch (phone_state) | ||
1214 | { | ||
1215 | case PS_LOOKUP_EGO: | ||
1216 | case PS_LISTEN: | ||
1217 | case PS_ERROR: | ||
1218 | GCG_log ("%s", _(" There is no call that could be suspended right now. (PS_ERROR)")); | ||
1219 | return; | ||
1220 | case PS_ACCEPTED: | ||
1221 | // expected state, do rejection logic | ||
1222 | break; | ||
1223 | } | ||
1224 | */ | ||
1225 | if (call_selected != NULL && caller_selected != NULL) | ||
1226 | { | ||
1227 | GCG_log("this shoud not be possible"); | ||
1228 | GNUNET_break(0); | ||
1229 | } | ||
1230 | else | ||
1231 | { | ||
1232 | // outgoing | ||
1233 | if (NULL != call_selected) | ||
1234 | { | ||
1235 | GNUNET_CONVERSATION_call_suspend (call_selected); | ||
1236 | set_outgoing_call_state(call_selected,CT_suspended); | ||
1237 | |||
1238 | return; | ||
1239 | } | ||
1240 | |||
1241 | // incoming | ||
1242 | if (NULL != caller_selected) | ||
1243 | { | ||
1244 | GNUNET_CONVERSATION_caller_suspend (caller_selected); | ||
1245 | set_incoming_call_state(caller_selected,CT_suspended); | ||
1246 | phone_state = PS_LISTEN; | ||
1247 | return; | ||
1248 | |||
1249 | } | ||
1250 | } | ||
1251 | } | ||
1252 | |||
1253 | |||
1254 | /** | ||
1255 | * Resuming a call | ||
1256 | * | ||
1257 | * @param args arguments given to the command | ||
1258 | */ | ||
1259 | static void | ||
1260 | do_resume () | ||
1261 | { | ||
1262 | |||
1263 | switch (phone_state) | ||
1264 | { | ||
1265 | case PS_LOOKUP_EGO: | ||
1266 | case PS_ERROR: | ||
1267 | GCG_log ("%s", _("There is no call that could be resumed right now.(PS_ERROR)")); | ||
1268 | return; | ||
1269 | case PS_LISTEN: | ||
1270 | break; | ||
1271 | case PS_ACCEPTED: | ||
1272 | GCG_log (_("Already talking with `%s', cannot resume a call right now."), | ||
1273 | peer_name); | ||
1274 | return; | ||
1275 | } | ||
1276 | //// | ||
1277 | if (call_selected != NULL && caller_selected != NULL) | ||
1278 | { | ||
1279 | GCG_log("this shoud not be possible"); | ||
1280 | GNUNET_break(0); | ||
1281 | return; | ||
1282 | } | ||
1283 | else | ||
1284 | { | ||
1285 | |||
1286 | // outgoing | ||
1287 | if (NULL != call_selected) | ||
1288 | { | ||
1289 | GNUNET_CONVERSATION_call_resume (call_selected, speaker, mic); | ||
1290 | set_outgoing_call_state(call_selected,CT_active); | ||
1291 | |||
1292 | return; | ||
1293 | } | ||
1294 | |||
1295 | // incoming | ||
1296 | if (NULL != caller_selected) | ||
1297 | { | ||
1298 | GNUNET_CONVERSATION_caller_resume (caller_selected, speaker, mic); | ||
1299 | set_incoming_call_state(caller_selected,CT_active); | ||
1300 | phone_state = PS_ACCEPTED; | ||
1301 | return; | ||
1302 | |||
1303 | } | ||
1304 | GNUNET_break(0); | ||
1305 | } | ||
1306 | |||
1307 | // | ||
1308 | //// | ||
1309 | } | ||
1310 | |||
1311 | |||
1312 | /** | ||
1313 | / Rejecting a call | ||
1314 | * | ||
1315 | * @param args arguments given to the command | ||
1316 | */ | ||
1317 | static void | ||
1318 | do_reject () | ||
1319 | { | ||
1320 | if (call_selected == NULL && caller_selected == NULL) | ||
1321 | { | ||
1322 | GNUNET_break(0); | ||
1323 | } | ||
1324 | else | ||
1325 | { | ||
1326 | // if selected call is outgoing, stop it | ||
1327 | if (NULL != call_selected) | ||
1328 | { | ||
1329 | set_outgoing_call_state(call_selected,CT_hangup); | ||
1330 | |||
1331 | GNUNET_CONVERSATION_call_stop(call); | ||
1332 | //GNUNET_CONVERSATION_call_stop (call_selected); | ||
1333 | |||
1334 | call = NULL; | ||
1335 | call_selected = NULL; | ||
1336 | return; | ||
1337 | } | ||
1338 | else | ||
1339 | { | ||
1340 | // if selected call is incoming, hang it up | ||
1341 | if (NULL != caller_selected) | ||
1342 | { | ||
1343 | set_incoming_call_state(caller_selected,CT_hangup); | ||
1344 | //FPRINTF(stderr,"hangup: %u", caller_selected); | ||
1345 | GNUNET_CONVERSATION_caller_hang_up(caller_selected); | ||
1346 | //cl_active = NULL; | ||
1347 | phone_state = PS_LISTEN; | ||
1348 | caller_selected = NULL; | ||
1349 | } | ||
1350 | else | ||
1351 | { | ||
1352 | GNUNET_break(0); | ||
1353 | } | ||
1354 | } | ||
1355 | } | ||
1356 | } | ||
1357 | |||
1358 | |||
1359 | /** | ||
1360 | * Get our configuration. | 105 | * Get our configuration. |
1361 | * | 106 | * |
1362 | * @return configuration handle | 107 | * @return configuration handle |
@@ -1364,7 +109,6 @@ do_reject () | |||
1364 | const struct GNUNET_CONFIGURATION_Handle * | 109 | const struct GNUNET_CONFIGURATION_Handle * |
1365 | GCG_get_configuration () | 110 | GCG_get_configuration () |
1366 | { | 111 | { |
1367 | /* FIXME: Configuration handle returned is const, but we DO alter the config */ | ||
1368 | return GNUNET_GTK_main_loop_get_configuration (ml); | 112 | return GNUNET_GTK_main_loop_get_configuration (ml); |
1369 | } | 113 | } |
1370 | 114 | ||
@@ -1379,25 +123,10 @@ static void | |||
1379 | shutdown_task (void *cls, | 123 | shutdown_task (void *cls, |
1380 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 124 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1381 | { | 125 | { |
1382 | 126 | GCG_PHONE_shutdown (); | |
1383 | //TODO: make this work | 127 | GCG_CONTACTS_shutdown (); |
1384 | //struct OperationContext *oc; | 128 | GCG_IMPORT_shutdown (); |
1385 | 129 | GCG_EGOS_shutdown (); | |
1386 | /* | ||
1387 | GCG_advertise_shutdown_ (); | ||
1388 | while (NULL != (oc = oc_head)) | ||
1389 | { | ||
1390 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1391 | _("Operation not completed due to shutdown\n")); | ||
1392 | GNUNET_IDENTITY_cancel (oc->op); | ||
1393 | GNUNET_CONTAINER_DLL_remove (oc_head, | ||
1394 | oc_tail, | ||
1395 | oc); | ||
1396 | GNUNET_free (oc); | ||
1397 | } | ||
1398 | */ | ||
1399 | GCG_CONTACTS_shutdown(); | ||
1400 | GCG_EGOS_shutdown(); | ||
1401 | GNUNET_GTK_tray_icon_destroy (); | 130 | GNUNET_GTK_tray_icon_destroy (); |
1402 | GNUNET_GTK_main_loop_quit (ml); | 131 | GNUNET_GTK_main_loop_quit (ml); |
1403 | ml = NULL; | 132 | ml = NULL; |
@@ -1414,23 +143,6 @@ void | |||
1414 | GNUNET_GTK_conversation_quit_cb (GObject *object, | 143 | GNUNET_GTK_conversation_quit_cb (GObject *object, |
1415 | gpointer user_data) | 144 | gpointer user_data) |
1416 | { | 145 | { |
1417 | if (NULL != call) | ||
1418 | { | ||
1419 | GNUNET_CONVERSATION_call_stop (call); | ||
1420 | call = NULL; | ||
1421 | } | ||
1422 | if (NULL != phone) | ||
1423 | { | ||
1424 | GNUNET_CONVERSATION_phone_destroy (phone); | ||
1425 | phone = NULL; | ||
1426 | } | ||
1427 | GNUNET_SPEAKER_destroy (speaker); | ||
1428 | speaker = NULL; | ||
1429 | GNUNET_MICROPHONE_destroy (mic); | ||
1430 | mic = NULL; | ||
1431 | ego_name = NULL; | ||
1432 | //GNUNET_free_non_null (peer_name); | ||
1433 | phone_state = PS_ERROR; | ||
1434 | GNUNET_SCHEDULER_shutdown (); | 146 | GNUNET_SCHEDULER_shutdown (); |
1435 | } | 147 | } |
1436 | 148 | ||
@@ -1454,32 +166,24 @@ run (void *cls, | |||
1454 | GNUNET_GTK_set_icon_search_path (); | 166 | GNUNET_GTK_set_icon_search_path (); |
1455 | GNUNET_GTK_setup_nls (); | 167 | GNUNET_GTK_setup_nls (); |
1456 | /* setup main window */ | 168 | /* setup main window */ |
1457 | main_window = GTK_WINDOW (GCG_get_main_window_object ("GNUNET_GTK_conversation_window")); | 169 | main_window = GTK_WINDOW (GCG_get_main_window_object |
170 | ("gnunet_conversation_gtk_main_window")); | ||
1458 | main_window = | 171 | main_window = |
1459 | GTK_WINDOW (GNUNET_GTK_plug_me | 172 | GTK_WINDOW (GNUNET_GTK_plug_me |
1460 | ("GNUNET_CONVERSATION_GTK_PLUG", | 173 | ("GNUNET_CONVERSATION_GTK_PLUG", |
1461 | GTK_WIDGET (main_window))); | 174 | GTK_WIDGET (main_window))); |
1462 | // active calls | ||
1463 | active_liststore = | ||
1464 | GTK_LIST_STORE (GCG_get_main_window_object ("gnunet_conversation_gtk_active_calls_liststore")); | ||
1465 | active_treeview = | ||
1466 | GTK_TREE_VIEW (GCG_get_main_window_object ("gnunet_conversation_gtk_active_calls_treeview")); | ||
1467 | |||
1468 | if (NULL == getenv ("GNUNET_CONVERSATION_GTK_PLUG")) | 175 | if (NULL == getenv ("GNUNET_CONVERSATION_GTK_PLUG")) |
1469 | GNUNET_GTK_tray_icon_create (ml, GTK_WINDOW (main_window), | 176 | GNUNET_GTK_tray_icon_create (ml, GTK_WINDOW (main_window), |
1470 | "gnunet-conversation-gtk" | 177 | "gnunet-conversation-gtk" |
1471 | /* FIXME: different icon? */ , | 178 | /* FIXME: different icon? */ , |
1472 | "gnunet-conversation-gtk"); | 179 | "gnunet-conversation-gtk"); |
1473 | /* make GUI visible */ | 180 | /* make GUI visible */ |
1474 | if (!tray_only) | 181 | if (! tray_only) |
1475 | { | 182 | { |
1476 | gtk_widget_show (GTK_WIDGET (main_window)); | 183 | gtk_widget_show (GTK_WIDGET (main_window)); |
1477 | gtk_window_present (GTK_WINDOW (main_window)); | 184 | gtk_window_present (GTK_WINDOW (main_window)); |
1478 | } | 185 | } |
1479 | 186 | ||
1480 | /* get gui objects */ | ||
1481 | if (debug_box_enabled) | ||
1482 | gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object ("GNUNET_CONVERSATION_log_box"))); | ||
1483 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 187 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
1484 | &shutdown_task, | 188 | &shutdown_task, |
1485 | NULL); | 189 | NULL); |
@@ -1489,20 +193,18 @@ run (void *cls, | |||
1489 | "CONVERSATION", | 193 | "CONVERSATION", |
1490 | "LINE", | 194 | "LINE", |
1491 | line); | 195 | line); |
1492 | speaker = GNUNET_SPEAKER_create_from_hardware (cfg); | ||
1493 | mic = GNUNET_MICROPHONE_create_from_hardware (cfg); | ||
1494 | b_contact = GTK_WIDGET (GCG_get_main_window_object ("GNUNET_GTK_conversation_use_current_button")); | ||
1495 | b_accept = GTK_WIDGET (GCG_get_main_window_object ("GNUNET_GTK_conversation_accept_button")); | ||
1496 | b_hangup = GTK_WIDGET (GCG_get_main_window_object ("GNUNET_GTK_conversation_hangup_button")); | ||
1497 | b_suspend = GTK_WIDGET (GCG_get_main_window_object ("GNUNET_GTK_conversation_suspend_button")); | ||
1498 | b_resume = GTK_WIDGET (GCG_get_main_window_object ("GNUNET_GTK_conversation_resume_button")); | ||
1499 | if (NULL == ego_name) | 196 | if (NULL == ego_name) |
197 | ego_name = GNUNET_strdup ("phone-ego"); | ||
198 | GCG_HISTORY_init (); | ||
199 | GCG_EGOS_init (ego_name); | ||
200 | GCG_IMPORT_init (); | ||
201 | GCG_CONTACTS_init (); | ||
202 | GCG_PHONE_init (); | ||
203 | if (NULL != ego_name) | ||
1500 | { | 204 | { |
1501 | ego_name = "phone-ego"; | 205 | GNUNET_free (ego_name); |
1502 | GCG_log (_("No ego given, using default: %s "), ego_name); | 206 | ego_name = NULL; |
1503 | } | 207 | } |
1504 | GCG_EGOS_init (); | ||
1505 | GCG_CONTACTS_init (); | ||
1506 | } | 208 | } |
1507 | 209 | ||
1508 | 210 | ||
@@ -1523,9 +225,6 @@ main (int argc, char *const *argv) | |||
1523 | {'e', "ego", "ego", | 225 | {'e', "ego", "ego", |
1524 | gettext_noop ("select ego to use"), 1, | 226 | gettext_noop ("select ego to use"), 1, |
1525 | &GNUNET_GETOPT_set_string, &ego_name}, | 227 | &GNUNET_GETOPT_set_string, &ego_name}, |
1526 | {'d', "debug_box", "1 or 0", | ||
1527 | gettext_noop ("enable debug box"), 1, | ||
1528 | &GNUNET_GETOPT_set_uint, &debug_box_enabled}, | ||
1529 | {'t', "tray", NULL, | 228 | {'t', "tray", NULL, |
1530 | gettext_noop ("start in tray mode"), 0, | 229 | gettext_noop ("start in tray mode"), 0, |
1531 | &GNUNET_GETOPT_set_one, &tray_only}, | 230 | &GNUNET_GETOPT_set_one, &tray_only}, |
@@ -1552,247 +251,4 @@ main (int argc, char *const *argv) | |||
1552 | } | 251 | } |
1553 | 252 | ||
1554 | 253 | ||
1555 | /** | ||
1556 | * call clicked | ||
1557 | */ | ||
1558 | void | ||
1559 | GNUNET_CONVERSATION_GTK_on_call_clicked () | ||
1560 | { | ||
1561 | GtkEntry *address_entry; | ||
1562 | |||
1563 | address_entry = GTK_ENTRY (GCG_get_main_window_object ("GNUNET_GTK_conversation_address")); | ||
1564 | |||
1565 | GSC_do_call (gtk_entry_get_text(address_entry)); | ||
1566 | //disable_button ("GNUNET_GTK_conversation_accept_button"); | ||
1567 | do_status (); | ||
1568 | // free(to_addr); | ||
1569 | } | ||
1570 | |||
1571 | /** | ||
1572 | * hangup clicked | ||
1573 | */ | ||
1574 | void | ||
1575 | GNUNET_CONVERSATION_GTK_on_hangup_clicked () | ||
1576 | { | ||
1577 | |||
1578 | do_reject (); | ||
1579 | |||
1580 | do_status (); | ||
1581 | //history_add(3,peer_name); | ||
1582 | } | ||
1583 | |||
1584 | /** | ||
1585 | * accept clicked | ||
1586 | */ | ||
1587 | void | ||
1588 | GNUNET_CONVERSATION_GTK_on_accept_clicked () | ||
1589 | { | ||
1590 | if (caller_selected != NULL) | ||
1591 | { | ||
1592 | do_accept (caller_selected); | ||
1593 | } else { | ||
1594 | GNUNET_break(0); | ||
1595 | } | ||
1596 | do_status(); | ||
1597 | } | ||
1598 | |||
1599 | |||
1600 | /** | ||
1601 | * reject clicked | ||
1602 | */ | ||
1603 | void | ||
1604 | GNUNET_CONVERSATION_GTK_on_reject_clicked () | ||
1605 | { | ||
1606 | do_reject (); | ||
1607 | do_status(); | ||
1608 | } | ||
1609 | |||
1610 | /** | ||
1611 | * pause clicked | ||
1612 | */ | ||
1613 | void | ||
1614 | GNUNET_CONVERSATION_GTK_on_pause_clicked () | ||
1615 | { | ||
1616 | do_suspend (); | ||
1617 | do_status(); | ||
1618 | } | ||
1619 | |||
1620 | /** | ||
1621 | * resume clicked | ||
1622 | */ | ||
1623 | void | ||
1624 | GNUNET_CONVERSATION_GTK_on_resume_clicked () | ||
1625 | { | ||
1626 | do_resume (); | ||
1627 | do_status(); | ||
1628 | } | ||
1629 | |||
1630 | /** | ||
1631 | * status clicked | ||
1632 | */ | ||
1633 | void | ||
1634 | GNUNET_CONVERSATION_GTK_on_status_clicked () | ||
1635 | { | ||
1636 | do_status (); | ||
1637 | } | ||
1638 | |||
1639 | /* | ||
1640 | * test function | ||
1641 | */ | ||
1642 | void | ||
1643 | GNUNET_contact_test () | ||
1644 | { | ||
1645 | GtkTreeIter iter; | ||
1646 | char *caller_id = "testje"; | ||
1647 | int caller_num = 10; | ||
1648 | |||
1649 | enum { | ||
1650 | AL_caller_id, // *gchar | ||
1651 | AL_caller, // * | ||
1652 | AL_caller_num //gint | ||
1653 | }; | ||
1654 | |||
1655 | gtk_list_store_append (active_liststore, &iter); | ||
1656 | gtk_list_store_set (active_liststore, &iter, 2, caller_num, 0, caller_id, -1); | ||
1657 | |||
1658 | gtk_list_store_insert_with_values (zone_liststore, | ||
1659 | &iter, -1, | ||
1660 | 0, "test", | ||
1661 | -1); | ||
1662 | } | ||
1663 | |||
1664 | /* | ||
1665 | * @brief outgoing ego selector changed | ||
1666 | */ | ||
1667 | void | ||
1668 | gnunet_conversation_gtk_outgoing_zone_combobox_changed_cb (GtkComboBox *widget, | ||
1669 | gpointer user_data) | ||
1670 | { | ||
1671 | GtkTreeIter iter; | ||
1672 | struct GNUNET_IDENTITY_Ego *tempEgo; | ||
1673 | char *tempName; | ||
1674 | //struct GNUNET_CRYPTO_EcdsaPrivateKey temp_zone_pkey; | ||
1675 | //GtkTreeSelection *selection; | ||
1676 | |||
1677 | |||
1678 | gtk_combo_box_get_active_iter(widget, &iter); | ||
1679 | |||
1680 | gtk_tree_model_get (GTK_TREE_MODEL (zone_liststore), | ||
1681 | &iter, | ||
1682 | 0, &tempName, | ||
1683 | 1, &tempEgo, | ||
1684 | -1); | ||
1685 | //GCG_log(stderr,"outgoing ego: %s", tempName); | ||
1686 | // caller_id = tempEgo; | ||
1687 | /* | ||
1688 | if ( NULL != phone) | ||
1689 | { | ||
1690 | GNUNET_CONVERSATION_phone_destroy (phone); | ||
1691 | phone == NULL; | ||
1692 | } | ||
1693 | start_phone(); | ||
1694 | */ | ||
1695 | } | ||
1696 | |||
1697 | /* | ||
1698 | * @brief active call list type data function | ||
1699 | */ | ||
1700 | void | ||
1701 | active_calls_type_data_function (GtkTreeViewColumn *col, | ||
1702 | GtkCellRenderer *renderer, | ||
1703 | GtkTreeModel *model, | ||
1704 | GtkTreeIter *iter, | ||
1705 | gpointer user_data) | ||
1706 | { | ||
1707 | gint state; | ||
1708 | gchar buf[20]; | ||
1709 | |||
1710 | gtk_tree_model_get(model, iter, AL_caller_state, &state, -1); | ||
1711 | g_snprintf(buf, sizeof(buf), "status %u", state); | ||
1712 | g_object_set(renderer, "text", buf, NULL); | ||
1713 | /* set 'cell-background' property of the cell renderer */ | ||
1714 | |||
1715 | switch (state) | ||
1716 | { | ||
1717 | case CT_active: | ||
1718 | g_object_set(renderer, | ||
1719 | "cell-background", "Green", | ||
1720 | "cell-background-set", TRUE, | ||
1721 | NULL); | ||
1722 | |||
1723 | |||
1724 | break; | ||
1725 | case CT_ringing: | ||
1726 | g_object_set(renderer, | ||
1727 | "cell-background", "Blue", | ||
1728 | "cell-background-set", TRUE, | ||
1729 | NULL); | ||
1730 | |||
1731 | |||
1732 | break; | ||
1733 | case CT_rejected: | ||
1734 | |||
1735 | break; | ||
1736 | case CT_suspended: | ||
1737 | g_object_set(renderer, | ||
1738 | "cell-background", "Orange", | ||
1739 | "cell-background-set", TRUE, | ||
1740 | NULL); | ||
1741 | |||
1742 | |||
1743 | break; | ||
1744 | default: | ||
1745 | GNUNET_break(0); | ||
1746 | break; | ||
1747 | } | ||
1748 | |||
1749 | //gtk_tree_model_get(model, iter, AL_caller_state, &state, -1); | ||
1750 | |||
1751 | //g_snprintf(buf, sizeof(buf), "state: %u", state); | ||
1752 | |||
1753 | //g_object_set(renderer, "text", buf, NULL); | ||
1754 | // | ||
1755 | // if (foo->is_important) | ||
1756 | g_object_set(renderer, "markup", "<b>important</b>", "text", NULL, NULL); | ||
1757 | // else | ||
1758 | // g_object_set(renderer, "markup", NULL, "text", "not important", NULL); | ||
1759 | // | ||
1760 | } | ||
1761 | |||
1762 | |||
1763 | /** | ||
1764 | * @brief second test button | ||
1765 | */ | ||
1766 | void | ||
1767 | GNUNET_CONVERSATION_GTK_test_button_two() | ||
1768 | { | ||
1769 | GtkTreeViewColumn *column; | ||
1770 | // GtkCellRenderer *cell; | ||
1771 | GtkCellRenderer *renderer; | ||
1772 | //GCG_log("test"); | ||
1773 | // treeview = GCG_get_main_window_object(ml,"gnunet_conversation_gtk_active_calls_treeview"); | ||
1774 | |||
1775 | // column = GCG_get_main_window_object(ml,"GNUNET_CONVERSATION_GTK_caller_typeColumn"); | ||
1776 | //cell = gtk_cell_renderer_text_new(); | ||
1777 | // cell = GCG_get_main_window_object(ml,"GNUNET_CONVERSATION_GTK_active_calls_type"); | ||
1778 | // gtk_tree_view_column_set_cell_data_func(column, cell, active_calls_type_data_function, NULL, NULL ); | ||
1779 | |||
1780 | column = GTK_TREE_VIEW_COLUMN(GCG_get_main_window_object("caller_testcolumn")); | ||
1781 | gtk_tree_view_column_set_title(column, "test stateC"); | ||
1782 | renderer = gtk_cell_renderer_text_new(); | ||
1783 | |||
1784 | /* pack cell renderer into tree view column */ | ||
1785 | gtk_tree_view_column_pack_start(column, renderer, TRUE); | ||
1786 | |||
1787 | /* set 'text' property of the cell renderer */ | ||
1788 | g_object_set(renderer, "text", "Boooo!", NULL); | ||
1789 | /* set 'cell-background' property of the cell renderer */ | ||
1790 | g_object_set(renderer, | ||
1791 | "cell-background", "Orange", | ||
1792 | "cell-background-set", TRUE, | ||
1793 | NULL); | ||
1794 | gtk_tree_view_column_add_attribute(column, renderer, "text", AL_caller_state); | ||
1795 | gtk_tree_view_column_set_cell_data_func(column, renderer, active_calls_type_data_function, NULL, NULL ); | ||
1796 | } | ||
1797 | |||
1798 | /* end of gnunet-conversation-gtk.c */ | 254 | /* end of gnunet-conversation-gtk.c */ |
diff --git a/src/conversation/gnunet-conversation-gtk.h b/src/conversation/gnunet-conversation-gtk.h index 1064be4e..9f807d82 100644 --- a/src/conversation/gnunet-conversation-gtk.h +++ b/src/conversation/gnunet-conversation-gtk.h | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <stdbool.h> | 28 | #include <stdbool.h> |
29 | #include <stdint.h> | 29 | #include <stdint.h> |
30 | #include "gnunet_gtk.h" | 30 | #include "gnunet_gtk.h" |
31 | #include <gnunet/gnunet_dnsparser_lib.h> | ||
31 | #include <gnunet/gnunet_identity_service.h> | 32 | #include <gnunet/gnunet_identity_service.h> |
32 | #include <gnunet/gnunet_namestore_service.h> | 33 | #include <gnunet/gnunet_namestore_service.h> |
33 | #include <gnunet/gnunet_conversation_service.h> | 34 | #include <gnunet/gnunet_conversation_service.h> |
@@ -39,116 +40,11 @@ | |||
39 | 40 | ||
40 | 41 | ||
41 | /** | 42 | /** |
42 | * active calls treeview columns | ||
43 | */ | ||
44 | enum ActiveCallsTreeViewColumns | ||
45 | { | ||
46 | AL_caller_id, //*gchar | ||
47 | AL_caller, //* | ||
48 | AL_caller_num, //gint | ||
49 | AL_type, //gint | ||
50 | AL_caller_state, //gint | ||
51 | AL_call, //* | ||
52 | AL_call_state, //gint | ||
53 | AL_call_num //gint | ||
54 | }; | ||
55 | |||
56 | |||
57 | /** | ||
58 | * callerstate (state of incoming call) | ||
59 | */ | ||
60 | enum CallerState | ||
61 | { | ||
62 | CT_active, | ||
63 | CT_suspended, | ||
64 | CT_ringing, | ||
65 | CT_dead, | ||
66 | CT_hangup, | ||
67 | CT_rejected, | ||
68 | CT_other | ||
69 | }; | ||
70 | |||
71 | |||
72 | /** | ||
73 | * type of call | ||
74 | */ | ||
75 | enum TypeOfCall | ||
76 | { | ||
77 | CALL_IN, | ||
78 | CALL_OUT | ||
79 | }; | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Possible states of the phone. | ||
84 | */ | ||
85 | enum PhoneState | ||
86 | { | ||
87 | /** | ||
88 | * We're waiting for our own idenitty. | ||
89 | */ | ||
90 | PS_LOOKUP_EGO, | ||
91 | |||
92 | /** | ||
93 | * We're listening for calls | ||
94 | */ | ||
95 | PS_LISTEN, | ||
96 | |||
97 | /** | ||
98 | * We accepted an incoming phone call. | ||
99 | */ | ||
100 | PS_ACCEPTED, | ||
101 | |||
102 | /** | ||
103 | * Internal error | ||
104 | */ | ||
105 | PS_ERROR | ||
106 | }; | ||
107 | |||
108 | |||
109 | /** | ||
110 | * States for current outgoing call. | ||
111 | */ | ||
112 | enum CallState | ||
113 | { | ||
114 | /** | ||
115 | * We are looking up some other participant. | ||
116 | */ | ||
117 | CS_RESOLVING, | ||
118 | |||
119 | /** | ||
120 | * We are now ringing the other participant. | ||
121 | */ | ||
122 | CS_RINGING, | ||
123 | |||
124 | /** | ||
125 | * The other party accepted our call and we are now connected. | ||
126 | */ | ||
127 | CS_CONNECTED, | ||
128 | |||
129 | /** | ||
130 | * The call is currently suspended (by us). | ||
131 | */ | ||
132 | CS_SUSPENDED | ||
133 | }; | ||
134 | |||
135 | |||
136 | enum CallHistoryType | ||
137 | { | ||
138 | CH_ACCEPTED, | ||
139 | CH_REJECTED, | ||
140 | CH_OUTGOING, | ||
141 | CH_HANGUP, | ||
142 | CH_MISSED | ||
143 | }; | ||
144 | |||
145 | |||
146 | /** | ||
147 | * Get our configuration. | 43 | * Get our configuration. |
148 | * | 44 | * |
149 | * @return configuration handle | 45 | * @return configuration handle |
150 | */ | 46 | */ |
151 | extern const struct GNUNET_CONFIGURATION_Handle * | 47 | const struct GNUNET_CONFIGURATION_Handle * |
152 | GCG_get_configuration (void); | 48 | GCG_get_configuration (void); |
153 | 49 | ||
154 | 50 | ||
@@ -158,8 +54,8 @@ GCG_get_configuration (void); | |||
158 | * @param name name of the object | 54 | * @param name name of the object |
159 | * @return NULL on error | 55 | * @return NULL on error |
160 | */ | 56 | */ |
161 | extern GObject * | 57 | GObject * |
162 | GCG_get_main_window_object (const char *); | 58 | GCG_get_main_window_object (const char *name); |
163 | 59 | ||
164 | 60 | ||
165 | /** | 61 | /** |
@@ -173,28 +69,24 @@ GCG_update_status (const gchar *message, | |||
173 | ...); | 69 | ...); |
174 | 70 | ||
175 | 71 | ||
176 | #define UPDATE_INFOBAR(format, ...) set_infobar_text(g_strdup_printf (format, ## __VA_ARGS__)) | ||
177 | |||
178 | |||
179 | /** | 72 | /** |
180 | * log a message to gtk log textbuffer | 73 | * log a message to gtk log textbuffer |
181 | * | 74 | * |
182 | * @param message format string for message to be logged | 75 | * @param message format string for message to be logged |
183 | * @param ... arguments for the format string | 76 | * @param ... arguments for the format string |
184 | */ | 77 | */ |
185 | extern void | 78 | void |
186 | GCG_log (const char *message, | 79 | GCG_log (const char *message, |
187 | ...); | 80 | ...); |
188 | 81 | ||
189 | 82 | ||
190 | /** | 83 | /** |
191 | * Initiate a call to the given address. | 84 | * Updates the status icon to the image of the given name. |
192 | * | 85 | * |
193 | * @param address address to call | 86 | * @param icon_name name of the icon to use |
194 | */ | 87 | */ |
195 | extern void | 88 | void |
196 | GSC_do_call (const char *address); | 89 | GCG_set_status_icon (const char *icon_name); |
197 | |||
198 | 90 | ||
199 | 91 | ||
200 | #endif | 92 | #endif |
diff --git a/src/conversation/gnunet-conversation-gtk_contacts.c b/src/conversation/gnunet-conversation-gtk_contacts.c index 70dec478..35ecb1d7 100644 --- a/src/conversation/gnunet-conversation-gtk_contacts.c +++ b/src/conversation/gnunet-conversation-gtk_contacts.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -20,9 +20,11 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file src/conversation/gnunet-conversation-gtk_contacts.c | 22 | * @file src/conversation/gnunet-conversation-gtk_contacts.c |
23 | * @brief | 23 | * @brief display the address book with the list of known contacts |
24 | * and launch calls if user activates entry in address book | ||
24 | * @author yids | 25 | * @author yids |
25 | * @author hark | 26 | * @author hark |
27 | * @author Christian Grothoff | ||
26 | */ | 28 | */ |
27 | #include "gnunet-conversation-gtk.h" | 29 | #include "gnunet-conversation-gtk.h" |
28 | #include "gnunet-conversation-gtk_contacts.h" | 30 | #include "gnunet-conversation-gtk_contacts.h" |
@@ -47,22 +49,12 @@ enum ContactsListstoreValues | |||
47 | 49 | ||
48 | 50 | ||
49 | /** | 51 | /** |
50 | * Our ego. | ||
51 | */ | ||
52 | static struct GNUNET_IDENTITY_Ego *contacts_ego; | ||
53 | |||
54 | /** | ||
55 | * List of contacts (records). | 52 | * List of contacts (records). |
56 | */ | 53 | */ |
57 | static GtkListStore *contacts_liststore; | 54 | static GtkListStore *contacts_liststore; |
58 | 55 | ||
59 | /** | 56 | /** |
60 | * The main tree view for 'gns' that shows the records. | 57 | * Tree model of the contacts treeview, same objects as #contacts_liststore. |
61 | */ | ||
62 | static GtkTreeView *contacts_treeview; | ||
63 | |||
64 | /** | ||
65 | * Tree model of the #contacts_treeview, same objects as #contacts_liststore. | ||
66 | */ | 58 | */ |
67 | static GtkTreeModel *contacts_treemodel; | 59 | static GtkTreeModel *contacts_treemodel; |
68 | 60 | ||
@@ -71,230 +63,9 @@ static GtkTreeModel *contacts_treemodel; | |||
71 | */ | 63 | */ |
72 | static struct GNUNET_NAMESTORE_ZoneMonitor *zone_mon; | 64 | static struct GNUNET_NAMESTORE_ZoneMonitor *zone_mon; |
73 | 65 | ||
74 | /** | ||
75 | * Handle to the namestore. | ||
76 | */ | ||
77 | static struct GNUNET_NAMESTORE_Handle *ns; | ||
78 | |||
79 | /** | ||
80 | * Private key for the our zone. | ||
81 | */ | ||
82 | static struct GNUNET_CRYPTO_EcdsaPrivateKey zone_pkey; | ||
83 | |||
84 | /** | ||
85 | * Name of the records to add/list/remove. | ||
86 | */ | ||
87 | static char *name; | ||
88 | |||
89 | /** | ||
90 | * Queue entry for the 'add' operation. | ||
91 | */ | ||
92 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; | ||
93 | |||
94 | /** | ||
95 | * Queue entry for the 'del' operation. | ||
96 | */ | ||
97 | static struct GNUNET_NAMESTORE_QueueEntry *del_qe; | ||
98 | |||
99 | |||
100 | |||
101 | /** | ||
102 | * Continuation called to notify client about result of the | ||
103 | * operation. | ||
104 | * | ||
105 | * @param cls closure, location of the QueueEntry pointer to NULL out | ||
106 | * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
107 | * #GNUNET_NO if content was already there | ||
108 | * #GNUNET_YES (or other positive value) on success | ||
109 | * @param emsg NULL on success, otherwise an error message | ||
110 | */ | ||
111 | static void | ||
112 | add_continuation (void *cls, | ||
113 | int32_t success, | ||
114 | const char *emsg) | ||
115 | { | ||
116 | |||
117 | struct GNUNET_NAMESTORE_QueueEntry **qe = cls; | ||
118 | |||
119 | *qe = NULL; | ||
120 | if (GNUNET_YES != success) | ||
121 | { | ||
122 | fprintf (stderr, _("Adding record failed: %s\n"), | ||
123 | (GNUNET_NO == success) ? "record exists" : emsg); | ||
124 | if (GNUNET_NO != success) | ||
125 | GCG_log("GNUNET_NO != success"); | ||
126 | //ret = 1; | ||
127 | } | ||
128 | GCG_log("blaat"); | ||
129 | //ret = 0; | ||
130 | //test_finished (); | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Continuation called to notify client about result of the | ||
136 | * operation. | ||
137 | * | ||
138 | * @param cls closure, unused | ||
139 | * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
140 | * #GNUNET_NO if content was already there | ||
141 | * #GNUNET_YES (or other positive value) on success | ||
142 | * @param emsg NULL on success, otherwise an error message | ||
143 | */ | ||
144 | static void | ||
145 | del_continuation (void *cls, | ||
146 | int32_t success, | ||
147 | const char *emsg) | ||
148 | { | ||
149 | del_qe = NULL; | ||
150 | if (GNUNET_NO == success) | ||
151 | { | ||
152 | fprintf (stderr, _("Deleting record failed, record does not exist%s%s\n"), | ||
153 | (NULL != emsg) ? ": " : "", (NULL != emsg) ? emsg : ""); | ||
154 | } | ||
155 | if (GNUNET_SYSERR == success) | ||
156 | { | ||
157 | fprintf (stderr, _("Deleting record failed%s%s\n"), | ||
158 | (NULL != emsg) ? ": " : "", (NULL != emsg) ? emsg : ""); | ||
159 | } | ||
160 | // test_finished (); | ||
161 | } | ||
162 | |||
163 | |||
164 | /** | ||
165 | * add a new contact | ||
166 | * | ||
167 | * @param name | ||
168 | * @param address | ||
169 | */ | ||
170 | static void | ||
171 | add_contact (const gchar *name, | ||
172 | const gchar *address) | ||
173 | { | ||
174 | GtkTreeIter iter; | ||
175 | struct GNUNET_GNSRECORD_Data rd; | ||
176 | struct GNUNET_GNSRECORD_Data *rde; | ||
177 | static void *data; | ||
178 | static size_t data_size; | ||
179 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | ||
180 | struct GNUNET_IDENTITY_Ego *ego; | ||
181 | |||
182 | ego = GCG_EGOS_get_selected_ego (); | ||
183 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
184 | GNUNET_CRYPTO_ecdsa_public_key_from_string (address, | ||
185 | strlen (address), | ||
186 | &pkey); | ||
187 | rde = &rd; | ||
188 | rd.data = &pkey; | ||
189 | rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
190 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | ||
191 | rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; // always set to relative for testing purposes | ||
192 | rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE; | ||
193 | rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
194 | //FPRINTF (stderr, "adding\n"); | ||
195 | //FPRINTF (stderr, "name: %s\n", name); | ||
196 | //FPRINTF (stderr, "address: %s\n", address); | ||
197 | if (GNUNET_OK != | ||
198 | GNUNET_GNSRECORD_string_to_value (65536, address, &data, &data_size)) | ||
199 | { | ||
200 | FPRINTF (stderr, "invalid address\n"); | ||
201 | } | ||
202 | else | ||
203 | { | ||
204 | add_qe = | ||
205 | GNUNET_NAMESTORE_records_store (ns, &zone_pkey, name, 1, rde, | ||
206 | &add_continuation, &add_qe); | ||
207 | gtk_list_store_append (contacts_liststore, &iter); | ||
208 | gtk_list_store_set (contacts_liststore, &iter, 1, "PKEY", 0, name, -1); | ||
209 | } | ||
210 | } | ||
211 | |||
212 | |||
213 | /** | ||
214 | * executed when clicked on add contact | ||
215 | * @param button | ||
216 | * @param user_data | ||
217 | */ | ||
218 | void | ||
219 | GNUNET_CONVERSATION_GTK_on_add_clicked (GtkButton * button, | ||
220 | gpointer * user_data) | ||
221 | { | ||
222 | GtkEntry *nameEntry; | ||
223 | GtkEntry *addressEntry; | ||
224 | |||
225 | nameEntry = GTK_ENTRY (GCG_get_main_window_object ("GNUNET_GTK_conversation_nameAdd")); | ||
226 | addressEntry = GTK_ENTRY (GCG_get_main_window_object ("GNUNET_GTK_conversation_addressAdd")); | ||
227 | add_contact (gtk_entry_get_text (nameEntry),gtk_entry_get_text(addressEntry)); | ||
228 | } | ||
229 | |||
230 | |||
231 | void | ||
232 | GNUNET_CONVERSATION_GTK_on_remove_clicked (GtkButton * button, | ||
233 | gpointer * user_data) | ||
234 | { | ||
235 | GtkTreeSelection *selection; | ||
236 | GtkTreeModel *model; | ||
237 | GtkTreeIter iter; | ||
238 | GtkDialog *confirm; | ||
239 | GtkWindow *main_window; | ||
240 | GtkLabel *notification; | ||
241 | GtkHBox *content_area; | ||
242 | |||
243 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (contacts_treeview)); | ||
244 | if (gtk_tree_selection_get_selected (selection, &model, &iter)) | ||
245 | { | ||
246 | gtk_tree_model_get (model, &iter, 0, &name, -1); | ||
247 | //FPRINTF (stderr, "selected %s \n", name); | ||
248 | main_window = GTK_WINDOW (GCG_get_main_window_object ("GNUNET_GTK_conversation_window")); | ||
249 | confirm = | ||
250 | GTK_DIALOG (gtk_dialog_new_with_buttons | ||
251 | ("Removing contact", main_window, | ||
252 | GTK_DIALOG_DESTROY_WITH_PARENT, _("Yes"), | ||
253 | GTK_RESPONSE_ACCEPT, _("No"), GTK_RESPONSE_CANCEL, NULL)); | ||
254 | content_area = | ||
255 | GTK_HBOX (gtk_dialog_get_content_area (GTK_DIALOG (confirm))); | ||
256 | notification = | ||
257 | GTK_LABEL (gtk_label_new | ||
258 | ("Do you really want to remove this contact?")); | ||
259 | gtk_container_add (GTK_CONTAINER (content_area), GTK_WIDGET (notification)); | ||
260 | gtk_widget_show_all (GTK_WIDGET (confirm)); | ||
261 | switch (gtk_dialog_run (confirm)) | ||
262 | { | ||
263 | case GTK_RESPONSE_ACCEPT: | ||
264 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (contacts_ego); | ||
265 | del_qe = | ||
266 | GNUNET_NAMESTORE_records_store (ns, &zone_pkey, name, 0, NULL, | ||
267 | &del_continuation, NULL); | ||
268 | gtk_list_store_remove (contacts_liststore, &iter); | ||
269 | gtk_widget_destroy (GTK_WIDGET (confirm)); | ||
270 | break; | ||
271 | case GTK_RESPONSE_CANCEL: | ||
272 | FPRINTF (stderr, "not removing \n"); | ||
273 | gtk_widget_destroy (GTK_WIDGET (confirm)); | ||
274 | break; | ||
275 | } | ||
276 | |||
277 | } | ||
278 | } | ||
279 | |||
280 | 66 | ||
281 | /** | 67 | /** |
282 | * FIXME: what was clicked where? | 68 | * A row was activated in the contacts list. Initiate call. |
283 | */ | ||
284 | void | ||
285 | GNUNET_CONVERSATION_GTK_use_current_button_clicked (GtkButton *button, | ||
286 | gpointer *user_data) | ||
287 | { | ||
288 | GtkEntry *addressEntry; | ||
289 | |||
290 | addressEntry = GTK_ENTRY (GCG_get_main_window_object ("GNUNET_GTK_conversation_addressAdd")); | ||
291 | gtk_entry_set_text (addressEntry, | ||
292 | "FIXME"); | ||
293 | } | ||
294 | |||
295 | |||
296 | /** | ||
297 | * A row was activated in the contacts list. Initiate call. | ||
298 | * | 69 | * |
299 | * @param tree_view view where the row was activated | 70 | * @param tree_view view where the row was activated |
300 | * @param path path to the activated element | 71 | * @param path path to the activated element |
@@ -302,18 +73,19 @@ GNUNET_CONVERSATION_GTK_use_current_button_clicked (GtkButton *button, | |||
302 | * @param user_data builder context (unused) | 73 | * @param user_data builder context (unused) |
303 | */ | 74 | */ |
304 | void | 75 | void |
305 | GNUNET_CONVERSATION_GTK_row_activated (GtkTreeView *tree_view, | 76 | gnunet_conversation_gtk_contact_list_treeview_row_activated_cb (GtkTreeView *tree_view, |
306 | GtkTreePath *path, | 77 | GtkTreePath *path, |
307 | GtkTreeViewColumn *column, | 78 | GtkTreeViewColumn *column, |
308 | gpointer user_data) | 79 | gpointer user_data) |
309 | { | 80 | { |
310 | char *address; | 81 | char *address; |
311 | gchar *type; | 82 | gchar *type; |
312 | GtkTreeIter iter; | 83 | GtkTreeIter iter; |
84 | gchar *name; | ||
313 | 85 | ||
314 | gtk_tree_model_get_iter (contacts_treemodel, | 86 | gtk_tree_model_get_iter (contacts_treemodel, |
315 | path, | 87 | &iter, |
316 | &iter); | 88 | path); |
317 | gtk_tree_model_get (contacts_treemodel, | 89 | gtk_tree_model_get (contacts_treemodel, |
318 | &iter, | 90 | &iter, |
319 | CONTACTS_LS_NAME, &name, | 91 | CONTACTS_LS_NAME, &name, |
@@ -327,7 +99,6 @@ GNUNET_CONVERSATION_GTK_row_activated (GtkTreeView *tree_view, | |||
327 | } | 99 | } |
328 | else | 100 | else |
329 | { | 101 | { |
330 | GNUNET_assert (0 == strcmp (type, "PHONE")); | ||
331 | GNUNET_asprintf (&address, | 102 | GNUNET_asprintf (&address, |
332 | "%s.gnu", | 103 | "%s.gnu", |
333 | name); | 104 | name); |
@@ -378,6 +149,10 @@ display_record (void *cls, | |||
378 | type = "PKEY"; | 149 | type = "PKEY"; |
379 | do_display = TRUE; | 150 | do_display = TRUE; |
380 | break; | 151 | break; |
152 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
153 | type = "CNAME"; | ||
154 | do_display = TRUE; | ||
155 | break; | ||
381 | case GNUNET_GNSRECORD_TYPE_PHONE: | 156 | case GNUNET_GNSRECORD_TYPE_PHONE: |
382 | type = "PHONE"; | 157 | type = "PHONE"; |
383 | do_display = TRUE; | 158 | do_display = TRUE; |
@@ -489,6 +264,8 @@ gnunet_conversation_gtk_contacts_zone_combobox_changed_cb (GtkComboBox *widget, | |||
489 | void | 264 | void |
490 | GCG_CONTACTS_init () | 265 | GCG_CONTACTS_init () |
491 | { | 266 | { |
267 | GtkTreeView *contacts_treeview; | ||
268 | |||
492 | contacts_liststore | 269 | contacts_liststore |
493 | = GTK_LIST_STORE (GCG_get_main_window_object | 270 | = GTK_LIST_STORE (GCG_get_main_window_object |
494 | ("gnunet_conversation_gtk_contacts_liststore")); | 271 | ("gnunet_conversation_gtk_contacts_liststore")); |
@@ -496,8 +273,8 @@ GCG_CONTACTS_init () | |||
496 | = GTK_TREE_MODEL (contacts_liststore); | 273 | = GTK_TREE_MODEL (contacts_liststore); |
497 | contacts_treeview | 274 | contacts_treeview |
498 | = GTK_TREE_VIEW (GCG_get_main_window_object ("gnunet_conversation_gtk_treeview")); | 275 | = GTK_TREE_VIEW (GCG_get_main_window_object ("gnunet_conversation_gtk_treeview")); |
499 | // gtk_tree_view_set_activate_on_single_click (contacts_treeview, TRUE); | 276 | gtk_tree_view_set_activate_on_single_click (contacts_treeview, |
500 | ns = GNUNET_NAMESTORE_connect (GCG_get_configuration ()); | 277 | TRUE); |
501 | } | 278 | } |
502 | 279 | ||
503 | 280 | ||
@@ -512,12 +289,9 @@ GCG_CONTACTS_shutdown () | |||
512 | GNUNET_NAMESTORE_zone_monitor_stop (zone_mon); | 289 | GNUNET_NAMESTORE_zone_monitor_stop (zone_mon); |
513 | zone_mon = NULL; | 290 | zone_mon = NULL; |
514 | } | 291 | } |
515 | if (NULL != ns) | 292 | gtk_list_store_clear (contacts_liststore); |
516 | { | 293 | contacts_liststore = NULL; |
517 | GNUNET_NAMESTORE_disconnect (ns); | 294 | contacts_treemodel = NULL; |
518 | ns = NULL; | ||
519 | } | ||
520 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | ||
521 | } | 295 | } |
522 | 296 | ||
523 | /* end of gnunet-conversation-gtk_contacts.c */ | 297 | /* end of gnunet-conversation-gtk_contacts.c */ |
diff --git a/src/conversation/gnunet-conversation-gtk_contacts.h b/src/conversation/gnunet-conversation-gtk_contacts.h index ccfd230d..8b1366b9 100644 --- a/src/conversation/gnunet-conversation-gtk_contacts.h +++ b/src/conversation/gnunet-conversation-gtk_contacts.h | |||
@@ -30,14 +30,14 @@ | |||
30 | /** | 30 | /** |
31 | * Initialize the contact list | 31 | * Initialize the contact list |
32 | */ | 32 | */ |
33 | extern void | 33 | void |
34 | GCG_CONTACTS_init (void); | 34 | GCG_CONTACTS_init (void); |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Shutdown the contact list | 38 | * Shutdown the contact list |
39 | */ | 39 | */ |
40 | extern void | 40 | void |
41 | GCG_CONTACTS_shutdown(void); | 41 | GCG_CONTACTS_shutdown (void); |
42 | 42 | ||
43 | #endif | 43 | #endif |
diff --git a/src/conversation/gnunet-conversation-gtk_egos.c b/src/conversation/gnunet-conversation-gtk_egos.c index 29aa3501..5136a938 100644 --- a/src/conversation/gnunet-conversation-gtk_egos.c +++ b/src/conversation/gnunet-conversation-gtk_egos.c | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file src/conversation/gnunet-conversation-gtk_egos.c | 22 | * @file src/conversation/gnunet-conversation-gtk_egos.c |
23 | * @brief | 23 | * @brief Manages the list of egos for selecting our caller-ID |
24 | * @author yids | 24 | * @author yids |
25 | * @author hark | 25 | * @author hark |
26 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
@@ -30,19 +30,19 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Columns in the #zone_liststore. | 33 | * Columns in the #ego_liststore. |
34 | */ | 34 | */ |
35 | enum ZoneListstoreValues | 35 | enum EgoListstoreValues |
36 | { | 36 | { |
37 | /** | 37 | /** |
38 | * Human-readable name of the ego. | 38 | * Human-readable name of the ego. |
39 | */ | 39 | */ |
40 | ZONE_LS_NAME = 0, | 40 | EGO_LS_NAME = 0, |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Handel to the ego (of type `struct GNUNET_IDENTITY_Ego *ego`). | 43 | * Handel to the ego (of type `struct GNUNET_IDENTITY_Ego *ego`). |
44 | */ | 44 | */ |
45 | ZONE_LS_EGO = 1 | 45 | EGO_LS_EGO = 1 |
46 | }; | 46 | }; |
47 | 47 | ||
48 | 48 | ||
@@ -52,10 +52,14 @@ enum ZoneListstoreValues | |||
52 | static struct GNUNET_IDENTITY_Handle *id; | 52 | static struct GNUNET_IDENTITY_Handle *id; |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * list of zones | 55 | * list of egos |
56 | */ | 56 | */ |
57 | static GtkListStore *zone_liststore; | 57 | static GtkListStore *ego_liststore; |
58 | 58 | ||
59 | /** | ||
60 | * Default ego to pre-select. | ||
61 | */ | ||
62 | static char *default_ego; | ||
59 | 63 | ||
60 | /** | 64 | /** |
61 | * Obtain the currently selected ego. | 65 | * Obtain the currently selected ego. |
@@ -63,18 +67,19 @@ static GtkListStore *zone_liststore; | |||
63 | * @return NULL if no ego is selected | 67 | * @return NULL if no ego is selected |
64 | */ | 68 | */ |
65 | struct GNUNET_IDENTITY_Ego * | 69 | struct GNUNET_IDENTITY_Ego * |
66 | GCG_EGOS_get_selected_ego (void) | 70 | GCG_EGOS_get_selected_ego () |
67 | { | 71 | { |
68 | struct GNUNET_IDENTITY_Ego *ego; | 72 | struct GNUNET_IDENTITY_Ego *ego; |
69 | GtkTreeIter iter; | 73 | GtkTreeIter iter; |
70 | GtkComboBox *cb; | 74 | GtkComboBox *cb; |
71 | 75 | ||
72 | cb = GTK_COMBO_BOX (GCG_get_main_window_object ("gnunet_conversation_gtk_contacts_zone_combobox")); | 76 | cb = GTK_COMBO_BOX (GCG_get_main_window_object |
77 | ("gnunet_conversation_gtk_ego_combobox")); | ||
73 | gtk_combo_box_get_active_iter (cb, | 78 | gtk_combo_box_get_active_iter (cb, |
74 | &iter); | 79 | &iter); |
75 | gtk_tree_model_get (GTK_TREE_MODEL (zone_liststore), | 80 | gtk_tree_model_get (GTK_TREE_MODEL (ego_liststore), |
76 | &iter, | 81 | &iter, |
77 | ZONE_LS_EGO, &ego, | 82 | EGO_LS_EGO, &ego, |
78 | -1); | 83 | -1); |
79 | return ego; | 84 | return ego; |
80 | } | 85 | } |
@@ -97,20 +102,33 @@ identity_cb (void *cls, | |||
97 | GtkTreeIter iter; | 102 | GtkTreeIter iter; |
98 | GtkTreeRowReference *rr; | 103 | GtkTreeRowReference *rr; |
99 | GtkTreePath *path; | 104 | GtkTreePath *path; |
105 | GtkComboBox *cb; | ||
100 | 106 | ||
101 | rr = *ctx; | 107 | rr = *ctx; |
102 | if (NULL == rr) | 108 | if (NULL == rr) |
103 | { | 109 | { |
104 | /* new identity */ | 110 | /* new identity */ |
105 | GNUNET_assert (NULL != name); | 111 | GNUNET_assert (NULL != name); |
106 | gtk_list_store_insert_with_values (zone_liststore, | 112 | gtk_list_store_insert_with_values (ego_liststore, |
107 | &iter, -1, | 113 | &iter, -1, |
108 | ZONE_LS_NAME, name, | 114 | EGO_LS_NAME, name, |
109 | ZONE_LS_EGO, ego, | 115 | EGO_LS_EGO, ego, |
110 | -1); | 116 | -1); |
111 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (zone_liststore), | 117 | if ( (NULL != default_ego) && |
118 | (0 == strcmp (name, | ||
119 | default_ego)) ) | ||
120 | { | ||
121 | /* found the ego that we were supposed to use by default, select | ||
122 | it! */ | ||
123 | GNUNET_free (default_ego); | ||
124 | default_ego = NULL; | ||
125 | cb = GTK_COMBO_BOX (GCG_get_main_window_object | ||
126 | ("gnunet_conversation_gtk_ego_combobox")); | ||
127 | gtk_combo_box_set_active_iter (cb, &iter); | ||
128 | } | ||
129 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ego_liststore), | ||
112 | &iter); | 130 | &iter); |
113 | rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (zone_liststore), | 131 | rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ego_liststore), |
114 | path); | 132 | path); |
115 | gtk_tree_path_free (path); | 133 | gtk_tree_path_free (path); |
116 | *ctx = rr; | 134 | *ctx = rr; |
@@ -118,7 +136,7 @@ identity_cb (void *cls, | |||
118 | } | 136 | } |
119 | /* existing ego, locate and execute rename/delete */ | 137 | /* existing ego, locate and execute rename/delete */ |
120 | path = gtk_tree_row_reference_get_path (rr); | 138 | path = gtk_tree_row_reference_get_path (rr); |
121 | gtk_tree_model_get_iter (GTK_TREE_MODEL (zone_liststore), | 139 | gtk_tree_model_get_iter (GTK_TREE_MODEL (ego_liststore), |
122 | &iter, | 140 | &iter, |
123 | path); | 141 | path); |
124 | gtk_tree_path_free (path); | 142 | gtk_tree_path_free (path); |
@@ -127,26 +145,30 @@ identity_cb (void *cls, | |||
127 | /* deletion operation */ | 145 | /* deletion operation */ |
128 | gtk_tree_row_reference_free (rr); | 146 | gtk_tree_row_reference_free (rr); |
129 | *ctx = NULL; | 147 | *ctx = NULL; |
130 | gtk_list_store_remove (zone_liststore, | 148 | gtk_list_store_remove (ego_liststore, |
131 | &iter); | 149 | &iter); |
132 | return; | 150 | return; |
133 | } | 151 | } |
134 | /* rename operation */ | 152 | /* rename operation */ |
135 | gtk_list_store_set (zone_liststore, | 153 | gtk_list_store_set (ego_liststore, |
136 | &iter, | 154 | &iter, |
137 | ZONE_LS_NAME, &name, | 155 | EGO_LS_NAME, &name, |
138 | -1); | 156 | -1); |
139 | } | 157 | } |
140 | 158 | ||
141 | 159 | ||
142 | /** | 160 | /** |
143 | * Initialize the ego list | 161 | * Initialize the ego list |
162 | * | ||
163 | * @param ego_name default ego to pre-select | ||
144 | */ | 164 | */ |
145 | void | 165 | void |
146 | GCG_EGOS_init () | 166 | GCG_EGOS_init (const char *ego_name) |
147 | { | 167 | { |
148 | zone_liststore | 168 | default_ego = GNUNET_strdup (ego_name); |
149 | = GTK_LIST_STORE (GCG_get_main_window_object ("gnunet_conversation_gtk_contacts_zone_liststore")); | 169 | ego_liststore |
170 | = GTK_LIST_STORE (GCG_get_main_window_object | ||
171 | ("gnunet_conversation_gtk_ego_liststore")); | ||
150 | id = GNUNET_IDENTITY_connect (GCG_get_configuration (), | 172 | id = GNUNET_IDENTITY_connect (GCG_get_configuration (), |
151 | &identity_cb, | 173 | &identity_cb, |
152 | NULL); | 174 | NULL); |
@@ -164,6 +186,11 @@ GCG_EGOS_shutdown () | |||
164 | GNUNET_IDENTITY_disconnect (id); | 186 | GNUNET_IDENTITY_disconnect (id); |
165 | id = NULL; | 187 | id = NULL; |
166 | } | 188 | } |
189 | if (NULL != default_ego) | ||
190 | { | ||
191 | GNUNET_free (default_ego); | ||
192 | default_ego = NULL; | ||
193 | } | ||
167 | } | 194 | } |
168 | 195 | ||
169 | /* end of gnunet-conversation-gtk_egos.c */ | 196 | /* end of gnunet-conversation-gtk_egos.c */ |
diff --git a/src/conversation/gnunet-conversation-gtk_egos.h b/src/conversation/gnunet-conversation-gtk_egos.h index c939fece..79f3cd7c 100644 --- a/src/conversation/gnunet-conversation-gtk_egos.h +++ b/src/conversation/gnunet-conversation-gtk_egos.h | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file src/conversation/gnunet-conversation-gtk_egos.h | 22 | * @file src/conversation/gnunet-conversation-gtk_egos.h |
23 | * @brief | 23 | * @brief Manages the list of egos for selecting our caller-ID |
24 | * @author yids | 24 | * @author yids |
25 | * @author hark | 25 | * @author hark |
26 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
@@ -39,16 +39,18 @@ GCG_EGOS_get_selected_ego (void); | |||
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Initialize the contact list | 42 | * Initialize the contact list. |
43 | * | ||
44 | * @param ego_name default ego to pre-select | ||
43 | */ | 45 | */ |
44 | extern void | 46 | void |
45 | GCG_EGOS_init (void); | 47 | GCG_EGOS_init (const char *ego_name); |
46 | 48 | ||
47 | 49 | ||
48 | /** | 50 | /** |
49 | * Shutdown the contact list | 51 | * Shutdown the contact list. |
50 | */ | 52 | */ |
51 | extern void | 53 | void |
52 | GCG_EGOS_shutdown(void); | 54 | GCG_EGOS_shutdown (void); |
53 | 55 | ||
54 | #endif | 56 | #endif |
diff --git a/src/conversation/gnunet-conversation-gtk_history.c b/src/conversation/gnunet-conversation-gtk_history.c index 5956b611..296f6ccd 100644 --- a/src/conversation/gnunet-conversation-gtk_history.c +++ b/src/conversation/gnunet-conversation-gtk_history.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -19,23 +19,21 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file src/conversation/gnunet-conversation-gtk_history.c | 21 | * @file src/conversation/gnunet-conversation-gtk_history.c |
22 | * @brief | 22 | * @brief manages the call history view |
23 | * @author yids | 23 | * @author yids |
24 | * @author hark | 24 | * @author hark |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #include "gnunet-conversation-gtk.h" | 27 | #include "gnunet-conversation-gtk.h" |
28 | #include "gnunet-conversation-gtk_history.h" | ||
27 | 29 | ||
28 | |||
29 | /******* | ||
30 | * history | ||
31 | ********/ | ||
32 | /** | 30 | /** |
33 | * call history liststore | 31 | * call history liststore // FIXME: which one is it? |
34 | */ | 32 | */ |
35 | static GtkListStore *history_liststore; | 33 | static GtkListStore *history_liststore; |
36 | 34 | ||
37 | /** | 35 | /** |
38 | * call history treestore | 36 | * call history treestore // FIXME: which one is it? |
39 | */ | 37 | */ |
40 | static GtkTreeStore *history_treestore; | 38 | static GtkTreeStore *history_treestore; |
41 | 39 | ||
@@ -50,16 +48,15 @@ static GtkTreeView *history_treeview; | |||
50 | static GtkTreeModel *history_treemodel; | 48 | static GtkTreeModel *history_treemodel; |
51 | 49 | ||
52 | 50 | ||
53 | /* | 51 | /** |
54 | * | ||
55 | * adds a item to the call history | 52 | * adds a item to the call history |
56 | * | 53 | * |
57 | * @param type type of call: 0: accepted 1: rejected 2: outgoing call | 54 | * @param type type of call: 0: accepted 1: rejected 2: outgoing call |
58 | * @return void | 55 | * @return void |
59 | */ | 56 | */ |
60 | 57 | void | |
61 | extern void | 58 | GCG_HISTORY_add (int type, |
62 | GNUNET_CONVERSATION_GTK_history_add (int type, char *contactName) | 59 | char *contactName) |
63 | { | 60 | { |
64 | GtkTreeIter iter; | 61 | GtkTreeIter iter; |
65 | time_t t; | 62 | time_t t; |
@@ -92,15 +89,24 @@ GNUNET_CONVERSATION_GTK_history_add (int type, char *contactName) | |||
92 | contactName, -1); | 89 | contactName, -1); |
93 | } | 90 | } |
94 | 91 | ||
95 | extern void | 92 | |
96 | GNUNET_CONVERSATION_GTK_history_init(){ | 93 | /** |
94 | * Intialize history subsystem. | ||
95 | */ | ||
96 | void | ||
97 | GCG_HISTORY_init () | ||
98 | { | ||
97 | // call history | 99 | // call history |
98 | history_liststore = | 100 | history_liststore = |
99 | GTK_LIST_STORE (GCG_get_main_window_object ("gnunet_conversation_gtk_history_liststore")); | 101 | GTK_LIST_STORE (GCG_get_main_window_object |
102 | ("gnunet_conversation_gtk_history_liststore")); | ||
100 | history_treeview = | 103 | history_treeview = |
101 | GTK_TREE_VIEW (GCG_get_main_window_object ("gnunet_conversation_gtk_history_treeview")); | 104 | GTK_TREE_VIEW (GCG_get_main_window_object |
105 | ("gnunet_conversation_gtk_history_treeview")); | ||
102 | history_treestore = | 106 | history_treestore = |
103 | GTK_TREE_STORE (GCG_get_main_window_object ("gnunet_conversation_gtk_history_treestore")); | 107 | GTK_TREE_STORE (GCG_get_main_window_object |
108 | ("gnunet_conversation_gtk_history_treestore")); | ||
104 | history_treemodel = GTK_TREE_MODEL (history_treestore); | 109 | history_treemodel = GTK_TREE_MODEL (history_treestore); |
105 | |||
106 | } | 110 | } |
111 | |||
112 | /* end of gnunet-conversation-gtk_history.c */ | ||
diff --git a/src/conversation/gnunet-conversation-gtk_history.h b/src/conversation/gnunet-conversation-gtk_history.h index 604e0831..79a21946 100644 --- a/src/conversation/gnunet-conversation-gtk_history.h +++ b/src/conversation/gnunet-conversation-gtk_history.h | |||
@@ -1,11 +1,63 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010-2014 Christian Grothoff (and other contributing authors) | ||
1 | 4 | ||
2 | /**************** | 5 | GNUnet is free software; you can redistribute it and/or modify |
3 | * history * | 6 | it under the terms of the GNU General Public License as published |
4 | ****************/ | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | ||
5 | 9 | ||
6 | extern void | 10 | GNUnet is distributed in the hope that it will be useful, but |
7 | GNUNET_CONVERSATION_GTK_history_add (int, char *); | 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. | ||
8 | 14 | ||
9 | extern void | 15 | You should have received a copy of the GNU General Public License |
10 | GNUNET_CONVERSATION_GTK_history_init(); | 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 | */ | ||
11 | 20 | ||
21 | /** | ||
22 | * @file src/conversation/gnunet-conversation-gtk_history.h | ||
23 | * @brief manages the call history view | ||
24 | * @author yids | ||
25 | * @author hark | ||
26 | */ | ||
27 | #ifndef GNUNET_CONVERSATION_GTK_HISTORY_H | ||
28 | #define GNUNET_CONVERSATION_GTK_HISTORY_H | ||
29 | |||
30 | |||
31 | /** | ||
32 | * FIXME: used? | ||
33 | */ | ||
34 | enum CallHistoryType | ||
35 | { | ||
36 | CH_ACCEPTED, | ||
37 | CH_REJECTED, | ||
38 | CH_OUTGOING, | ||
39 | CH_HANGUP, | ||
40 | CH_MISSED | ||
41 | }; | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Add an entry to the history. | ||
46 | * | ||
47 | * FIXME: use `enum CallHistoryType` here? | ||
48 | * @param type type of call: 0: accepted 1: rejected 2: outgoing call | ||
49 | * @param contactName name of the contact person | ||
50 | */ | ||
51 | void | ||
52 | GCG_HISTORY_add (int type, | ||
53 | char *contactName); | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Intialize history subsystem. | ||
58 | */ | ||
59 | void | ||
60 | GCG_HISTORY_init (void); | ||
61 | |||
62 | |||
63 | #endif | ||
diff --git a/src/conversation/gnunet-conversation-gtk_import.c b/src/conversation/gnunet-conversation-gtk_import.c new file mode 100644 index 00000000..428894d7 --- /dev/null +++ b/src/conversation/gnunet-conversation-gtk_import.c | |||
@@ -0,0 +1,148 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010-2014 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/conversation/gnunet-conversation-gtk_import.c | ||
23 | * @brief handle request to import caller into address book | ||
24 | * @author yids | ||
25 | * @author hark | ||
26 | * @author Christian Grothoff | ||
27 | */ | ||
28 | #include "gnunet-conversation-gtk.h" | ||
29 | #include "gnunet-conversation-gtk_contacts.h" | ||
30 | #include "gnunet-conversation-gtk_egos.h" | ||
31 | |||
32 | /** | ||
33 | * Handle to the namestore. | ||
34 | */ | ||
35 | static struct GNUNET_NAMESTORE_Handle *ns; | ||
36 | |||
37 | /** | ||
38 | * Queue entry for the 'add' operation. | ||
39 | */ | ||
40 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Continuation called to notify client about result of the | ||
45 | * operation. | ||
46 | * | ||
47 | * @param cls NULL | ||
48 | * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
49 | * #GNUNET_NO if content was already there | ||
50 | * #GNUNET_YES (or other positive value) on success | ||
51 | * @param emsg NULL on success, otherwise an error message | ||
52 | */ | ||
53 | static void | ||
54 | add_continuation (void *cls, | ||
55 | int32_t success, | ||
56 | const char *emsg) | ||
57 | { | ||
58 | if (GNUNET_YES != success) | ||
59 | GCG_log (_("Adding contact failed: %s\n"), | ||
60 | (GNUNET_NO == success) ? _("record exists") : emsg); | ||
61 | add_qe = NULL; | ||
62 | } | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Add new contact to the address book. | ||
67 | * | ||
68 | * @param name name to use for the contact | ||
69 | * @param address public key of the contact | ||
70 | */ | ||
71 | void | ||
72 | GSC_add_contact (const gchar *name, | ||
73 | const gchar *address) | ||
74 | { | ||
75 | struct GNUNET_GNSRECORD_Data rd; | ||
76 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | ||
77 | struct GNUNET_IDENTITY_Ego *ego; | ||
78 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_pkey; | ||
79 | |||
80 | if (NULL != add_qe) | ||
81 | { | ||
82 | GCG_log (_("Adding contact failed: %s\n"), | ||
83 | _("previous operation still pending")); | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | // FIXME: what should really be the preferred address format here? | ||
88 | // (CNAME? PKEY? PHONE?) | ||
89 | if (GNUNET_OK != | ||
90 | GNUNET_CRYPTO_ecdsa_public_key_from_string (address, | ||
91 | strlen (address), | ||
92 | &pkey)) | ||
93 | { | ||
94 | GCG_log (_("Adding contact failed: %s\n"), | ||
95 | _("invalid address")); | ||
96 | return; | ||
97 | } | ||
98 | rd.data = &pkey; | ||
99 | rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
100 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | ||
101 | rd.flags | ||
102 | = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION | ||
103 | | GNUNET_GNSRECORD_RF_PRIVATE; | ||
104 | rd.expiration_time | ||
105 | = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
106 | ego = GCG_EGOS_get_selected_ego (); | ||
107 | zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
108 | /* FIXME: we should check if the 'name' already exists, | ||
109 | and not do this if it does... */ | ||
110 | add_qe | ||
111 | = GNUNET_NAMESTORE_records_store (ns, | ||
112 | zone_pkey, | ||
113 | name, | ||
114 | 1, &rd, | ||
115 | &add_continuation, NULL); | ||
116 | } | ||
117 | |||
118 | |||
119 | /** | ||
120 | * Initialize the import subsystem. | ||
121 | */ | ||
122 | void | ||
123 | GCG_IMPORT_init () | ||
124 | { | ||
125 | ns = GNUNET_NAMESTORE_connect (GCG_get_configuration ()); | ||
126 | } | ||
127 | |||
128 | |||
129 | /** | ||
130 | * Shutdown the import subsystem. | ||
131 | */ | ||
132 | void | ||
133 | GCG_IMPORT_shutdown () | ||
134 | { | ||
135 | if (NULL != add_qe) | ||
136 | { | ||
137 | GNUNET_NAMESTORE_cancel (add_qe); | ||
138 | add_qe = NULL; | ||
139 | } | ||
140 | if (NULL != ns) | ||
141 | { | ||
142 | GNUNET_NAMESTORE_disconnect (ns); | ||
143 | ns = NULL; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | /* end of gnunet-conversation-gtk_import.c */ | ||
148 | |||
diff --git a/src/conversation/gnunet-conversation-gtk_import.h b/src/conversation/gnunet-conversation-gtk_import.h new file mode 100644 index 00000000..759a5e07 --- /dev/null +++ b/src/conversation/gnunet-conversation-gtk_import.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010-2014 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/conversation/gnunet-conversation-gtk_contacts.h | ||
23 | * @brief handle requests from user to import new contacts | ||
24 | * @author yids | ||
25 | * @author hark | ||
26 | * @author Christian Grothoff | ||
27 | */ | ||
28 | #ifndef GNUNET_CONVERSATION_GTK_IMPORTS_H | ||
29 | #define GNUNET_CONVERSATION_GTK_IMPORTS_H | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Add new contact to the address book. | ||
34 | * | ||
35 | * @param name | ||
36 | * @param address | ||
37 | */ | ||
38 | void | ||
39 | GSC_add_contact (const gchar *name, | ||
40 | const gchar *address); | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Initialize the import subsystem. | ||
45 | */ | ||
46 | void | ||
47 | GCG_IMPORT_init (void); | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Shutdown the import subsystem. | ||
52 | */ | ||
53 | void | ||
54 | GCG_IMPORT_shutdown (void); | ||
55 | |||
56 | #endif | ||
diff --git a/src/conversation/gnunet-conversation-gtk_log.c b/src/conversation/gnunet-conversation-gtk_log.c new file mode 100644 index 00000000..a77954af --- /dev/null +++ b/src/conversation/gnunet-conversation-gtk_log.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010-2014 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/conversation/gnunet-conversation-gtk_log.c | ||
23 | * @brief logging-related functions for gnunet-conversation-gtk | ||
24 | * @author yids | ||
25 | * @author hark | ||
26 | * @author Christian Grothoff | ||
27 | */ | ||
28 | #include "gnunet-conversation-gtk.h" | ||
29 | #include "gnunet-conversation-gtk_log.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Log a message to gtk log textbuffer | ||
34 | * | ||
35 | * @param message format string for message to be logged | ||
36 | * @param ... arguments for the format string | ||
37 | */ | ||
38 | void | ||
39 | GCG_log (const char *message, | ||
40 | ...) | ||
41 | { | ||
42 | GtkTextBuffer *logbuff; | ||
43 | GtkTextView *log_view; | ||
44 | GtkTextIter iter; | ||
45 | gchar *fmsg; | ||
46 | va_list ap; | ||
47 | |||
48 | log_view = GTK_TEXT_VIEW (GCG_get_main_window_object | ||
49 | ("GNUNET_GTK_conversation_log")); | ||
50 | logbuff = GTK_TEXT_BUFFER (gtk_text_view_get_buffer (log_view)); | ||
51 | va_start (ap, message); | ||
52 | fmsg = g_strdup_vprintf (message, | ||
53 | ap); | ||
54 | va_end (ap); | ||
55 | gtk_text_buffer_get_start_iter (logbuff, | ||
56 | &iter); | ||
57 | gtk_text_buffer_insert (logbuff, | ||
58 | &iter, | ||
59 | fmsg, | ||
60 | -1); | ||
61 | g_free (fmsg); | ||
62 | } | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Update status bar. | ||
67 | * | ||
68 | * @param message format string for message to put in statusbar | ||
69 | * @param ... arguments for the format string | ||
70 | */ | ||
71 | void | ||
72 | GCG_update_status_bar (const gchar *message, | ||
73 | ...) | ||
74 | { | ||
75 | GtkStatusbar *status_bar; | ||
76 | guint status_bar_context; | ||
77 | gchar *buff; | ||
78 | va_list ap; | ||
79 | |||
80 | status_bar = GTK_STATUSBAR (GCG_get_main_window_object | ||
81 | ("GNUNET_GTK_conversation_statusbar")); | ||
82 | status_bar_context = gtk_statusbar_get_context_id (status_bar, | ||
83 | "blaat"); // blaat!? | ||
84 | va_start (ap, message); | ||
85 | buff = g_strdup_vprintf (message, | ||
86 | ap); | ||
87 | va_end (ap); | ||
88 | gtk_statusbar_push (GTK_STATUSBAR (status_bar), | ||
89 | GPOINTER_TO_INT (status_bar_context), | ||
90 | buff); | ||
91 | g_free (buff); | ||
92 | } | ||
93 | |||
94 | /* end of gnunet-conversation-gtk_log.c */ | ||
diff --git a/src/conversation/gnunet-conversation-gtk_log.h b/src/conversation/gnunet-conversation-gtk_log.h new file mode 100644 index 00000000..b63400a0 --- /dev/null +++ b/src/conversation/gnunet-conversation-gtk_log.h | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2013-2014 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/identity/gnunet-identity-gtk_log.h | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #ifndef GNUNET_CONVERSATION_GTK_LOG_H | ||
26 | #define GNUNET_CONVERSATION_GTK_LOG_H | ||
27 | |||
28 | #include <stdbool.h> | ||
29 | #include <stdint.h> | ||
30 | #include "gnunet_gtk.h" | ||
31 | #include <gnunet/gnunet_dnsparser_lib.h> | ||
32 | #include <gnunet/gnunet_identity_service.h> | ||
33 | #include <gnunet/gnunet_namestore_service.h> | ||
34 | #include <gnunet/gnunet_conversation_service.h> | ||
35 | #include <gnunet/gnunet_speaker_lib.h> | ||
36 | #include <gnunet/gnunet_microphone_lib.h> | ||
37 | #include <gnunet/gnunet_identity_service.h> | ||
38 | #include <gnunet/gnunet_namestore_service.h> | ||
39 | #include <gnunet/gnunet_gnsrecord_lib.h> | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Update status bar. | ||
44 | * | ||
45 | * @param message format string for message to put in statusbar | ||
46 | * @param ... arguments for the format string | ||
47 | */ | ||
48 | void | ||
49 | GCG_update_status_bar (const gchar *message, | ||
50 | ...); | ||
51 | |||
52 | |||
53 | /** | ||
54 | * Log a message to the log textbuffer. | ||
55 | * | ||
56 | * @param message format string for message to be logged | ||
57 | * @param ... arguments for the format string | ||
58 | */ | ||
59 | void | ||
60 | GCG_log (const char *message, | ||
61 | ...); | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Updates the status icon to the image of the given name. | ||
66 | * | ||
67 | * @param icon_name name of the icon to use | ||
68 | */ | ||
69 | void | ||
70 | GCG_set_status_icon (const char *icon_name); | ||
71 | |||
72 | |||
73 | #endif | ||
diff --git a/src/conversation/gnunet-conversation-gtk_phone.c b/src/conversation/gnunet-conversation-gtk_phone.c index d04fc84d..59a8a23d 100644 --- a/src/conversation/gnunet-conversation-gtk_phone.c +++ b/src/conversation/gnunet-conversation-gtk_phone.c | |||
@@ -20,9 +20,1443 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file src/conversation/gnunet-conversation-gtk_phone.c | 22 | * @file src/conversation/gnunet-conversation-gtk_phone.c |
23 | * @brief | 23 | * @brief |
24 | * @author yids | 24 | * @author yids |
25 | * @author hark | 25 | * @author hark |
26 | * @author Christian Grothoff | ||
26 | */ | 27 | */ |
28 | #include "gnunet-conversation-gtk.h" | ||
29 | #include "gnunet-conversation-gtk_egos.h" | ||
30 | #include "gnunet-conversation-gtk_history.h" | ||
31 | #include "gnunet-conversation-gtk_log.h" | ||
32 | #include "gnunet-conversation-gtk_phone.h" | ||
27 | 33 | ||
28 | 34 | ||
35 | /** | ||
36 | * active calls treeview columns | ||
37 | */ | ||
38 | enum ActiveCallsTreeViewColumns | ||
39 | { | ||
40 | AL_caller_id, //*gchar | ||
41 | AL_caller, //* | ||
42 | AL_caller_num, //gint | ||
43 | AL_type, //gint | ||
44 | AL_caller_state, //gint | ||
45 | AL_call, //* | ||
46 | AL_call_state, //gint | ||
47 | AL_call_num //gint | ||
48 | }; | ||
49 | |||
50 | |||
51 | /** | ||
52 | * callerstate (state of incoming call) | ||
53 | */ | ||
54 | enum CallerState | ||
55 | { | ||
56 | CT_active, | ||
57 | CT_suspended, | ||
58 | CT_ringing, | ||
59 | CT_dead, | ||
60 | CT_hangup, | ||
61 | CT_rejected, | ||
62 | CT_other | ||
63 | }; | ||
64 | |||
65 | |||
66 | /** | ||
67 | * type of call | ||
68 | */ | ||
69 | enum TypeOfCall | ||
70 | { | ||
71 | CALL_IN, | ||
72 | CALL_OUT | ||
73 | }; | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Possible states of the phone. | ||
78 | */ | ||
79 | enum PhoneState | ||
80 | { | ||
81 | /** | ||
82 | * We're waiting for our own idenitty. | ||
83 | */ | ||
84 | PS_LOOKUP_EGO, | ||
85 | |||
86 | /** | ||
87 | * We're listening for calls | ||
88 | */ | ||
89 | PS_LISTEN, | ||
90 | |||
91 | /** | ||
92 | * We accepted an incoming phone call. | ||
93 | */ | ||
94 | PS_ACCEPTED, | ||
95 | |||
96 | /** | ||
97 | * Internal error | ||
98 | */ | ||
99 | PS_ERROR | ||
100 | }; | ||
101 | |||
102 | |||
103 | /** | ||
104 | * States for current outgoing call. | ||
105 | */ | ||
106 | enum CallState | ||
107 | { | ||
108 | /** | ||
109 | * We are looking up some other participant. | ||
110 | */ | ||
111 | CS_RESOLVING, | ||
112 | |||
113 | /** | ||
114 | * We are now ringing the other participant. | ||
115 | */ | ||
116 | CS_RINGING, | ||
117 | |||
118 | /** | ||
119 | * The other party accepted our call and we are now connected. | ||
120 | */ | ||
121 | CS_CONNECTED, | ||
122 | |||
123 | /** | ||
124 | * The call is currently suspended (by us). | ||
125 | */ | ||
126 | CS_SUSPENDED | ||
127 | }; | ||
128 | |||
129 | |||
130 | |||
131 | /** | ||
132 | * List of incoming calls | ||
133 | */ | ||
134 | struct CallList | ||
135 | { | ||
136 | |||
137 | /** | ||
138 | * A DLL. | ||
139 | */ | ||
140 | struct CallList *prev; | ||
141 | |||
142 | /** | ||
143 | * A DLL. | ||
144 | */ | ||
145 | struct CallList *next; | ||
146 | |||
147 | /** | ||
148 | * Handle to hang up or activate. | ||
149 | */ | ||
150 | struct GNUNET_CONVERSATION_Caller *caller; | ||
151 | |||
152 | /** | ||
153 | * Handle to call currently selected in list | ||
154 | */ | ||
155 | struct GNUNET_CONVERSATION_Caller *caller_selected; | ||
156 | |||
157 | /** | ||
158 | * String identifying the caller. | ||
159 | */ | ||
160 | char *caller_id; | ||
161 | |||
162 | /** | ||
163 | * Unique number of the caller. | ||
164 | */ | ||
165 | unsigned int caller_num; | ||
166 | |||
167 | }; | ||
168 | |||
169 | |||
170 | /** | ||
171 | * | ||
172 | */ | ||
173 | static struct GNUNET_CONVERSATION_Caller *caller_selected; | ||
174 | |||
175 | /** | ||
176 | * | ||
177 | */ | ||
178 | static struct GNUNET_CONVERSATION_Call *call_selected; | ||
179 | |||
180 | |||
181 | /** | ||
182 | * List of active calls | ||
183 | */ | ||
184 | static GtkListStore *active_liststore; | ||
185 | |||
186 | /** | ||
187 | * List of active calls | ||
188 | */ | ||
189 | static GtkTreeView *active_treeview; | ||
190 | |||
191 | /** | ||
192 | * Unique number of call (outgoing) | ||
193 | */ | ||
194 | static unsigned int call_counter; | ||
195 | |||
196 | /** | ||
197 | * Counts the number of incoming calls we have had so far. | ||
198 | */ | ||
199 | static unsigned int caller_num_gen; | ||
200 | |||
201 | /** | ||
202 | * Phone handle | ||
203 | */ | ||
204 | static struct GNUNET_CONVERSATION_Phone *phone; | ||
205 | |||
206 | /** | ||
207 | * Call handle (for active outgoing call). | ||
208 | */ | ||
209 | static struct GNUNET_CONVERSATION_Call *call; | ||
210 | |||
211 | /** | ||
212 | * Caller handle (for active incoming call). | ||
213 | */ | ||
214 | static struct CallList *cl_active; | ||
215 | |||
216 | /** | ||
217 | * Head of calls waiting to be accepted. | ||
218 | */ | ||
219 | static struct CallList *cl_head; | ||
220 | |||
221 | /** | ||
222 | * Tail of calls waiting to be accepted. | ||
223 | */ | ||
224 | static struct CallList *cl_tail; | ||
225 | |||
226 | /** | ||
227 | * Our speaker. | ||
228 | */ | ||
229 | static struct GNUNET_SPEAKER_Handle *speaker; | ||
230 | |||
231 | /** | ||
232 | * Our microphone. | ||
233 | */ | ||
234 | static struct GNUNET_MICROPHONE_Handle *mic; | ||
235 | |||
236 | /** | ||
237 | * Our phone's current state. | ||
238 | */ | ||
239 | static enum PhoneState phone_state; | ||
240 | |||
241 | /** | ||
242 | * Our call's current state. | ||
243 | */ | ||
244 | static enum CallState call_state; | ||
245 | |||
246 | /** | ||
247 | * Name of conversation partner (if any). | ||
248 | */ | ||
249 | static char *peer_name; | ||
250 | |||
251 | /** | ||
252 | * GNS address for this phone. | ||
253 | */ | ||
254 | static char *address; | ||
255 | |||
256 | static GtkWidget *b_contact; | ||
257 | |||
258 | static GtkWidget *b_accept; | ||
259 | |||
260 | static GtkWidget *b_hangup; | ||
261 | |||
262 | static GtkWidget *b_suspend; | ||
263 | |||
264 | static GtkWidget *b_resume; | ||
265 | |||
266 | |||
267 | |||
268 | /** | ||
269 | * Update status based on current phone state. | ||
270 | * | ||
271 | * @param args arguments given to the command | ||
272 | */ | ||
273 | static void | ||
274 | do_status () | ||
275 | { | ||
276 | switch (phone_state) | ||
277 | { | ||
278 | case PS_LOOKUP_EGO: | ||
279 | GCG_update_status_bar ("%s", | ||
280 | _("Phone inactive: no ego selected for the caller ID.")); | ||
281 | GCG_set_status_icon ("gnunet-conversation-gtk-tray-pending"); | ||
282 | break; | ||
283 | case PS_LISTEN: | ||
284 | GCG_update_status_bar ("%s", | ||
285 | _("We are listening for incoming calls")); | ||
286 | GCG_set_status_icon ("gnunet-conversation-gtk-tray-available"); | ||
287 | break; | ||
288 | case PS_ACCEPTED: | ||
289 | GCG_update_status_bar (_("You are having a conversation with `%s'.\n"), | ||
290 | peer_name); | ||
291 | GCG_set_status_icon ("gnunet-conversation-call-active"); | ||
292 | break; | ||
293 | case PS_ERROR: | ||
294 | GCG_update_status_bar (_("We had an internal error setting up our phone line. You can still make calls.")); | ||
295 | GCG_set_status_icon ("gnunet-conversation-offline"); | ||
296 | break; | ||
297 | } | ||
298 | if (NULL != call) | ||
299 | { | ||
300 | switch (call_state) | ||
301 | { | ||
302 | case CS_RESOLVING: | ||
303 | GCG_update_status_bar (_("We are trying to find the network address to call `%s'."), | ||
304 | peer_name); | ||
305 | GCG_set_status_icon ("gnunet-conversation-gtk-tray-call-pending"); | ||
306 | break; | ||
307 | case CS_RINGING: | ||
308 | GCG_update_status_bar (_("We are calling `%s', his phone should be ringing."), | ||
309 | peer_name); | ||
310 | GCG_set_status_icon ("gnunet-conversation-gtk-tray-call-ringing"); | ||
311 | break; | ||
312 | case CS_CONNECTED: | ||
313 | GCG_update_status_bar (_("You are having a conversation with `%s'."), | ||
314 | peer_name); | ||
315 | GCG_set_status_icon ("gnunet-conversation-gtk-tray-call-active"); | ||
316 | break; | ||
317 | case CS_SUSPENDED: | ||
318 | GCG_update_status_bar (_("Conversation suspended, you can accept or initiate another call now."), | ||
319 | peer_name); | ||
320 | GCG_set_status_icon ("gnunet-conversation-gtk-tray-call-suspended"); | ||
321 | break; | ||
322 | } | ||
323 | } | ||
324 | if ( ( (NULL == call) || | ||
325 | (CS_SUSPENDED == call_state) ) && | ||
326 | (NULL != cl_head) && | ||
327 | ( (cl_head != cl_active) || | ||
328 | (cl_head != cl_tail) ) ) | ||
329 | GCG_set_status_icon ("gnunet-conversation-gtk-tray-call-incoming"); | ||
330 | } | ||
331 | |||
332 | |||
333 | |||
334 | /** | ||
335 | * @brief print info for currently selected call | ||
336 | */ | ||
337 | static void | ||
338 | print_call_info () | ||
339 | { | ||
340 | GtkTreeIter gtkiter; | ||
341 | gboolean valid; | ||
342 | gint row_count = 0; | ||
343 | |||
344 | valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (active_liststore), | ||
345 | >kiter); | ||
346 | if (! valid) | ||
347 | GNUNET_break(0); | ||
348 | |||
349 | while (valid) | ||
350 | { | ||
351 | gchar *str_data; | ||
352 | gint int_data; | ||
353 | gpointer cl_caller; | ||
354 | gpointer cl_call; | ||
355 | |||
356 | gtk_tree_model_get (GTK_TREE_MODEL (active_liststore), | ||
357 | >kiter, | ||
358 | AL_caller, &cl_caller, | ||
359 | AL_caller_id, &str_data, | ||
360 | AL_caller_num, &int_data, | ||
361 | AL_call, &cl_call, | ||
362 | -1); | ||
363 | if (call_selected == cl_call) | ||
364 | { | ||
365 | GCG_log (_("info for active outgoing call:%s number: %u row: %u"), | ||
366 | str_data, | ||
367 | int_data, | ||
368 | row_count); | ||
369 | break; | ||
370 | } | ||
371 | g_free (str_data); | ||
372 | row_count++; | ||
373 | valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(active_liststore), >kiter); | ||
374 | } | ||
375 | } | ||
376 | |||
377 | |||
378 | /** | ||
379 | * @brief sets caller_selected, and enables or disables the active call list buttons | ||
380 | */ | ||
381 | static void | ||
382 | update_active_call_list_buttons() | ||
383 | { | ||
384 | gchar *caller_id; | ||
385 | gpointer cl_caller; | ||
386 | gpointer cl_call; | ||
387 | gint cl_caller_state; | ||
388 | gint cl_type; | ||
389 | //gint cl_caller_type; | ||
390 | GtkTreeSelection *active_selection; | ||
391 | GtkTreeIter gcl_selected; | ||
392 | // active_liststore_selection = GCG_get_main_window_object(ml,"GNUNET_CONVERSATION_GTK_active_calls_selection"); | ||
393 | |||
394 | // reset references to selected call/caller | ||
395 | //caller_selected = NULL; | ||
396 | //call_selected = NULL; | ||
397 | GCG_log("reset caller selected"); | ||
398 | active_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (active_treeview)); | ||
399 | if (gtk_tree_selection_get_selected (active_selection, | ||
400 | NULL, | ||
401 | &gcl_selected)) | ||
402 | { | ||
403 | // get selected call | ||
404 | gtk_tree_model_get (GTK_TREE_MODEL(active_liststore), &gcl_selected, | ||
405 | AL_caller, &cl_caller, // reference to incoming call | ||
406 | AL_caller_id, &caller_id, | ||
407 | AL_caller_state, &cl_caller_state, | ||
408 | AL_type, &cl_type, | ||
409 | AL_call, &cl_call, // reference to outgoing call | ||
410 | -1); | ||
411 | // check if selected call is a incoming or outgoing call | ||
412 | switch (cl_type) | ||
413 | { | ||
414 | case CALL_IN: | ||
415 | call_selected = NULL; | ||
416 | caller_selected = cl_caller; | ||
417 | GNUNET_break (NULL != caller_selected); | ||
418 | break; | ||
419 | case CALL_OUT: | ||
420 | caller_selected = NULL; | ||
421 | call_selected = cl_call; | ||
422 | GCG_log("outgoing selected"); | ||
423 | GNUNET_break (NULL != call_selected); | ||
424 | break; | ||
425 | default: | ||
426 | GNUNET_break(0); | ||
427 | break; | ||
428 | } | ||
429 | gtk_widget_show(GTK_WIDGET(GCG_get_main_window_object("GNUNET_GTK_conversation_active_call_list_buttons"))); | ||
430 | GCG_log("caller state: %u phone_state: %u", | ||
431 | cl_caller_state, | ||
432 | phone_state); | ||
433 | switch (cl_caller_state) | ||
434 | { | ||
435 | /* buttons: | ||
436 | * contact | ||
437 | * accept | ||
438 | * hangup | ||
439 | * suspend | ||
440 | * resume | ||
441 | * | ||
442 | * TODO: check if there is incoming or outgoing call, | ||
443 | * disable resume and accept buttons. | ||
444 | * or suspend that other call | ||
445 | */ | ||
446 | case CT_active: | ||
447 | // hangup, pause | ||
448 | //GCG_log("CT_active state: %u ",cl_caller_state); | ||
449 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
450 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
451 | gtk_widget_set_sensitive (b_hangup, TRUE); | ||
452 | gtk_widget_set_sensitive (b_suspend, TRUE); | ||
453 | gtk_widget_set_sensitive (b_resume, FALSE); | ||
454 | break; | ||
455 | case CT_ringing: | ||
456 | // pickup, phonebook | ||
457 | //GCG_log("CT_ring show button"); | ||
458 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
459 | if (phone_state == PS_LISTEN) | ||
460 | { | ||
461 | gtk_widget_set_sensitive (b_accept, TRUE); | ||
462 | } | ||
463 | else | ||
464 | { | ||
465 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
466 | } | ||
467 | gtk_widget_set_sensitive (b_hangup, FALSE); | ||
468 | gtk_widget_set_sensitive (b_suspend, FALSE); | ||
469 | gtk_widget_set_sensitive (b_resume, FALSE); | ||
470 | break; | ||
471 | case CT_rejected: | ||
472 | //add to phonebook | ||
473 | //GCG_log("CT_rejected "); | ||
474 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
475 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
476 | gtk_widget_set_sensitive (b_hangup, FALSE); | ||
477 | gtk_widget_set_sensitive (b_suspend, FALSE); | ||
478 | gtk_widget_set_sensitive (b_resume, FALSE); | ||
479 | break; | ||
480 | case CT_suspended: | ||
481 | // resume, hangup | ||
482 | //GCG_log("CT_suspended "); | ||
483 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
484 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
485 | gtk_widget_set_sensitive (b_hangup, TRUE); | ||
486 | gtk_widget_set_sensitive (b_suspend, FALSE); | ||
487 | if (phone_state == PS_LISTEN) | ||
488 | { | ||
489 | GCG_log("enable resume button"); | ||
490 | gtk_widget_set_sensitive (b_resume, TRUE); | ||
491 | } | ||
492 | else | ||
493 | { | ||
494 | GCG_log("do not disable resume button (for test)"); | ||
495 | gtk_widget_set_sensitive (b_resume, TRUE); | ||
496 | } | ||
497 | break; | ||
498 | case CT_other: | ||
499 | //add to phonebook | ||
500 | //GCG_log("CT_rejected "); | ||
501 | gtk_widget_set_sensitive (b_contact, TRUE); | ||
502 | gtk_widget_set_sensitive (b_accept, TRUE); | ||
503 | gtk_widget_set_sensitive (b_hangup, TRUE); | ||
504 | gtk_widget_set_sensitive (b_suspend, TRUE); | ||
505 | gtk_widget_set_sensitive (b_resume, TRUE); | ||
506 | break; | ||
507 | |||
508 | default: | ||
509 | GNUNET_break(0); | ||
510 | break; | ||
511 | } | ||
512 | print_call_info(); | ||
513 | } | ||
514 | else | ||
515 | { | ||
516 | GCG_log("nothing selected"); | ||
517 | //gtk_widget_hide(GTK_WIDGET(GCG_get_main_window_object("GNUNET_GTK_conversation_active_call_list_buttons" ))); | ||
518 | } | ||
519 | } | ||
520 | |||
521 | |||
522 | /** | ||
523 | * @brief executed when selecting a different item in active call list | ||
524 | */ | ||
525 | void | ||
526 | gnunet_conversation_gtk_active_calls_treeview_selection_changed_cb () | ||
527 | { | ||
528 | update_active_call_list_buttons(); | ||
529 | } | ||
530 | |||
531 | |||
532 | static void | ||
533 | disable_list_buttons() | ||
534 | { | ||
535 | gtk_widget_set_sensitive (b_contact, FALSE); | ||
536 | gtk_widget_set_sensitive (b_accept, FALSE); | ||
537 | gtk_widget_set_sensitive (b_hangup, FALSE); | ||
538 | gtk_widget_set_sensitive (b_suspend, FALSE); | ||
539 | gtk_widget_set_sensitive (b_resume, FALSE); | ||
540 | } | ||
541 | |||
542 | |||
543 | /** | ||
544 | * set state of outgoing call | ||
545 | */ | ||
546 | void | ||
547 | set_outgoing_call_state (struct GNUNET_CONVERSATION_Call *call, | ||
548 | int state) | ||
549 | { | ||
550 | GtkTreeIter gtkiter; | ||
551 | gint valid = 0; | ||
552 | gint cl_type; | ||
553 | |||
554 | GCG_log("set state to: %u", state); | ||
555 | valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( active_liststore ), >kiter); | ||
556 | |||
557 | if (!valid) | ||
558 | GNUNET_break(0); | ||
559 | while (valid) | ||
560 | { | ||
561 | gchar *cl_caller_id; | ||
562 | gint cl_caller_num; | ||
563 | gpointer cl_call; | ||
564 | |||
565 | gtk_tree_model_get ( GTK_TREE_MODEL( active_liststore ), >kiter, | ||
566 | AL_call, &cl_call, | ||
567 | AL_caller_id,&cl_caller_id, | ||
568 | AL_caller_num,&cl_caller_num, | ||
569 | AL_type, &cl_type, | ||
570 | -1); | ||
571 | if (cl_type == CALL_OUT) | ||
572 | { | ||
573 | if (call == NULL) // function called by phone event handler | ||
574 | { | ||
575 | GCG_log("event handler"); | ||
576 | gtk_list_store_set(active_liststore, >kiter, | ||
577 | AL_call_state, state, | ||
578 | -1); | ||
579 | switch (state) | ||
580 | { | ||
581 | /** | ||
582 | * We are the caller and are now ringing the other party (GNS lookup | ||
583 | * succeeded). | ||
584 | */ | ||
585 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | ||
586 | break; | ||
587 | /** | ||
588 | * We are the caller and are now ready to talk as the callee picked up. | ||
589 | */ | ||
590 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | ||
591 | break; | ||
592 | /** | ||
593 | * We are the caller and failed to locate a phone record in GNS. | ||
594 | * After this invocation, the respective call handle will be | ||
595 | * automatically destroyed and the client must no longer call | ||
596 | * #GNUNET_CONVERSATION_call_stop or any other function on the | ||
597 | * call object. | ||
598 | */ | ||
599 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | ||
600 | gtk_list_store_remove(active_liststore,>kiter); | ||
601 | disable_list_buttons(); | ||
602 | break; | ||
603 | /** | ||
604 | * We are the caller and the callee called | ||
605 | * #GNUNET_CONVERSATION_caller_hang_up. After this invocation, the | ||
606 | * respective call handle will be automatically destroyed and the | ||
607 | * client must no longer call #GNUNET_CONVERSATION_call_stop. | ||
608 | */ | ||
609 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | ||
610 | gtk_list_store_remove(active_liststore,>kiter); | ||
611 | disable_list_buttons(); | ||
612 | break; | ||
613 | /** | ||
614 | * We are the caller and the callee suspended the call. Note that | ||
615 | * both sides can independently suspend and resume calls; a call is | ||
616 | * only "working" of both sides are active. | ||
617 | */ | ||
618 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | ||
619 | break; | ||
620 | /** | ||
621 | * We are the caller and the callee suspended the call. Note that | ||
622 | * both sides can independently suspend and resume calls; a call is | ||
623 | * only "working" of both sides are active. | ||
624 | */ | ||
625 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | ||
626 | break; | ||
627 | /** | ||
628 | * We had an error handing the call, and are now restarting it | ||
629 | * (back to lookup). This happens, for example, if the peer | ||
630 | * is restarted during a call. | ||
631 | */ | ||
632 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | ||
633 | break; | ||
634 | default: | ||
635 | break; | ||
636 | } | ||
637 | } | ||
638 | else if (call == cl_call) // function called for specific call | ||
639 | { | ||
640 | //GCG_log (_("setting state for call:%u row: %u state: %u"),cl_caller_num,row_count,state); | ||
641 | |||
642 | switch (state) | ||
643 | { | ||
644 | case CT_hangup: | ||
645 | //GCG_log("remove line cause hangup"); | ||
646 | gtk_list_store_remove(active_liststore,>kiter); | ||
647 | disable_list_buttons(); | ||
648 | break; | ||
649 | case CT_rejected: | ||
650 | //GCG_log("remove line cause rejected"); | ||
651 | gtk_list_store_remove(active_liststore,>kiter); | ||
652 | disable_list_buttons(); | ||
653 | break; | ||
654 | default: | ||
655 | gtk_list_store_set(active_liststore, >kiter, | ||
656 | AL_caller_state, state, | ||
657 | -1); | ||
658 | break; | ||
659 | }//end switch | ||
660 | }//end call=cl_call | ||
661 | } //end cl_type | ||
662 | g_free (cl_caller_id); | ||
663 | valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(active_liststore), >kiter); | ||
664 | |||
665 | }//end while | ||
666 | GCG_update_status_bar (""); | ||
667 | } | ||
668 | |||
669 | |||
670 | /** | ||
671 | * set call state of a incoming call | ||
672 | */ | ||
673 | static void | ||
674 | set_incoming_call_state (struct GNUNET_CONVERSATION_Caller *caller, | ||
675 | int state) | ||
676 | { | ||
677 | GtkTreeIter gtkiter; | ||
678 | gint valid = 0; | ||
679 | //FPRINTF (stderr,"set incoming call state:%u caller: ",state); | ||
680 | |||
681 | // GCG_log (_("set incoming call state:%u caller: "),state); | ||
682 | |||
683 | valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( active_liststore ), >kiter ); | ||
684 | |||
685 | if (!valid) | ||
686 | GNUNET_break(0); | ||
687 | |||
688 | while (valid) | ||
689 | { | ||
690 | gchar *cl_caller_id; | ||
691 | gint cl_caller_num; | ||
692 | gpointer cl_caller; | ||
693 | |||
694 | gtk_tree_model_get ( GTK_TREE_MODEL( active_liststore ), >kiter, | ||
695 | AL_caller, &cl_caller, | ||
696 | AL_caller_id,&cl_caller_id, | ||
697 | AL_caller_num,&cl_caller_num | ||
698 | ,-1); | ||
699 | |||
700 | if (caller == cl_caller) | ||
701 | { | ||
702 | //GCG_log (_("setting state for call:%u row: %u state: %u"),cl_caller_num,row_count,state); | ||
703 | |||
704 | switch (state) | ||
705 | { | ||
706 | case CT_hangup: | ||
707 | //GCG_log("remove line cause hangup"); | ||
708 | gtk_list_store_remove(active_liststore,>kiter); | ||
709 | disable_list_buttons(); | ||
710 | |||
711 | break; | ||
712 | |||
713 | case CT_rejected: | ||
714 | //GCG_log("remove line cause rejected"); | ||
715 | gtk_list_store_remove(active_liststore,>kiter); | ||
716 | disable_list_buttons(); | ||
717 | |||
718 | break; | ||
719 | default: | ||
720 | |||
721 | gtk_list_store_set(active_liststore, >kiter, | ||
722 | AL_caller_state, state, | ||
723 | -1); | ||
724 | break; | ||
725 | |||
726 | }//end switch | ||
727 | }//endif | ||
728 | |||
729 | g_free (cl_caller_id); | ||
730 | valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(active_liststore), >kiter); | ||
731 | |||
732 | }//end while | ||
733 | GCG_update_status_bar(""); | ||
734 | } | ||
735 | |||
736 | |||
737 | /** | ||
738 | * Function called with an event emitted by a phone. | ||
739 | * | ||
740 | * @param cls closure | ||
741 | * @param code type of the event | ||
742 | * @param caller handle for the caller | ||
743 | * @param caller_id name of the caller in GNS | ||
744 | */ | ||
745 | static void | ||
746 | phone_event_handler (void *cls, | ||
747 | enum GNUNET_CONVERSATION_PhoneEventCode code, | ||
748 | struct GNUNET_CONVERSATION_Caller *caller, | ||
749 | const char *caller_id) | ||
750 | { | ||
751 | GtkTreeIter gtkiter; | ||
752 | GtkTreeIter gtkiter1; | ||
753 | gboolean valid; | ||
754 | |||
755 | switch (code) | ||
756 | { | ||
757 | case GNUNET_CONVERSATION_EC_PHONE_RING: | ||
758 | //increment call # | ||
759 | caller_num_gen++; | ||
760 | |||
761 | |||
762 | GCG_log (_("A Incoming call from `%s' with number %u\n"), | ||
763 | caller_id, | ||
764 | caller_num_gen); | ||
765 | |||
766 | //old | ||
767 | struct CallList *cl; | ||
768 | |||
769 | cl = GNUNET_new (struct CallList); | ||
770 | cl->caller = caller; | ||
771 | cl->caller_id = GNUNET_strdup (caller_id); | ||
772 | cl->caller_num = caller_num_gen; | ||
773 | GNUNET_CONTAINER_DLL_insert (cl_head, cl_tail, cl); | ||
774 | //gtk | ||
775 | gtk_list_store_append (active_liststore, >kiter); | ||
776 | |||
777 | gtk_list_store_set (active_liststore, >kiter, | ||
778 | AL_caller_id, caller_id, | ||
779 | AL_caller, caller, | ||
780 | AL_caller_num, caller_num_gen, | ||
781 | AL_caller_state, CT_ringing, | ||
782 | AL_type, CALL_IN | ||
783 | ,-1); | ||
784 | |||
785 | |||
786 | break; | ||
787 | |||
788 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
789 | //gtk | ||
790 | |||
791 | valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( active_liststore ), >kiter1 ); | ||
792 | |||
793 | if (!valid) | ||
794 | GNUNET_break(0); | ||
795 | |||
796 | while (valid) | ||
797 | { | ||
798 | //FPRINTF(stderr,"GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: while valid"); | ||
799 | |||
800 | gchar *str_data; | ||
801 | gint int_data; | ||
802 | gpointer cl_caller; | ||
803 | |||
804 | gtk_tree_model_get (GTK_TREE_MODEL(active_liststore), >kiter1, | ||
805 | AL_caller, &cl_caller, | ||
806 | AL_caller_id,&str_data, | ||
807 | AL_caller_num,&int_data,-1); | ||
808 | if (caller == cl_caller) | ||
809 | { | ||
810 | |||
811 | GCG_log (_("phone hung up:%s number: %u "), str_data,int_data); | ||
812 | set_incoming_call_state(caller,CT_rejected); | ||
813 | break ; | ||
814 | } | ||
815 | g_free (str_data); | ||
816 | valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(active_liststore), >kiter1); | ||
817 | } | ||
818 | |||
819 | |||
820 | |||
821 | phone_state = PS_LISTEN; | ||
822 | //add to call history list | ||
823 | //history_add(CH_HANGUP, cl->caller_id); | ||
824 | |||
825 | break; | ||
826 | |||
827 | } | ||
828 | do_status(); | ||
829 | } | ||
830 | |||
831 | |||
832 | /** | ||
833 | * Function called with an event emitted by a caller. | ||
834 | * | ||
835 | * @param cls closure with the `struct CallList` of the caller | ||
836 | * @param code type of the event issued by the caller | ||
837 | */ | ||
838 | static void | ||
839 | caller_event_handler (void *cls, | ||
840 | enum GNUNET_CONVERSATION_CallerEventCode code) | ||
841 | { | ||
842 | |||
843 | if (cls == NULL) | ||
844 | { | ||
845 | GCG_log("caller_event_handler: cls == NULL"); | ||
846 | GNUNET_break(0); | ||
847 | } | ||
848 | else | ||
849 | { | ||
850 | struct CallList *cl = cls; | ||
851 | |||
852 | switch (code) | ||
853 | { | ||
854 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: | ||
855 | //TODO: should this be cls? not cl->caller | ||
856 | set_incoming_call_state(cl->caller,CT_suspended); | ||
857 | GCG_log (_("Call from `%s' suspended by other user\n"), cl->caller_id); | ||
858 | break; | ||
859 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: | ||
860 | set_incoming_call_state(cl->caller,CT_active); | ||
861 | GCG_log (_("Call from `%s' resumed by other user\n"), cl->caller_id); | ||
862 | break; | ||
863 | } | ||
864 | } | ||
865 | do_status(); | ||
866 | } | ||
867 | |||
868 | |||
869 | |||
870 | /** | ||
871 | * Start our phone. | ||
872 | */ | ||
873 | static void | ||
874 | start_phone () | ||
875 | { | ||
876 | struct GNUNET_GNSRECORD_Data rd; | ||
877 | struct GNUNET_IDENTITY_Ego *caller_id; | ||
878 | |||
879 | caller_id = GCG_EGOS_get_selected_ego (); | ||
880 | if (NULL == caller_id) | ||
881 | { | ||
882 | GCG_log ("%s\n", | ||
883 | _("No ego selected, phone is now down.")); | ||
884 | phone_state = PS_LOOKUP_EGO; | ||
885 | do_status(); | ||
886 | return; | ||
887 | } | ||
888 | phone = | ||
889 | GNUNET_CONVERSATION_phone_create (GCG_get_configuration (), | ||
890 | caller_id, | ||
891 | &phone_event_handler, | ||
892 | NULL); | ||
893 | if (NULL == phone) | ||
894 | { | ||
895 | GCG_log ("%s", | ||
896 | _("Failed to setup phone (internal error)\n")); | ||
897 | phone_state = PS_ERROR; | ||
898 | do_status(); | ||
899 | return; | ||
900 | } | ||
901 | GNUNET_CONVERSATION_phone_get_record (phone, | ||
902 | &rd); | ||
903 | /* FIXME: publish record to GNS! */ | ||
904 | GCG_log ("%s\n", | ||
905 | _("Phone active")); | ||
906 | phone_state = PS_LISTEN; | ||
907 | do_status(); | ||
908 | } | ||
909 | |||
910 | |||
911 | /** | ||
912 | * Function called with an event emitted by a call. | ||
913 | * | ||
914 | * @param cls closure, NULL | ||
915 | * @param code type of the event on the call | ||
916 | */ | ||
917 | static void | ||
918 | call_event_handler (void *cls, | ||
919 | enum GNUNET_CONVERSATION_CallEventCode code) | ||
920 | { | ||
921 | //struct OutgoingCallClosure *cl = cls; | ||
922 | |||
923 | //GCG_log("call event handler code: %u num: %u", code, cl->call_num); | ||
924 | |||
925 | //if (cls == NULL){ | ||
926 | set_outgoing_call_state(NULL, code); | ||
927 | //GNUNET_break(0); | ||
928 | //} else | ||
929 | //{ | ||
930 | switch (code) | ||
931 | { | ||
932 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | ||
933 | GNUNET_break (CS_RESOLVING == call_state); | ||
934 | GCG_log (_("Resolved address of `%s'. Now ringing other party."), | ||
935 | peer_name); | ||
936 | // set_outgoing_call_state(cls, CT_ringing); | ||
937 | call_state = CS_RINGING; | ||
938 | break; | ||
939 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | ||
940 | GNUNET_break (CS_RINGING == call_state); | ||
941 | GCG_log (_("Connection established to `%s'."), | ||
942 | peer_name); | ||
943 | call_state = CS_CONNECTED; | ||
944 | break; | ||
945 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | ||
946 | GNUNET_break (CS_RESOLVING == call_state); | ||
947 | GCG_log (_("Failed to resolve %s in current zone."), | ||
948 | peer_name); | ||
949 | call = NULL; | ||
950 | break; | ||
951 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | ||
952 | GCG_log ("%s", _("Call terminated")); | ||
953 | call = NULL; | ||
954 | break; | ||
955 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | ||
956 | GNUNET_break (CS_CONNECTED == call_state); | ||
957 | GCG_log (_("Connection to `%s' suspended (by other user)\n"), | ||
958 | peer_name); | ||
959 | break; | ||
960 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | ||
961 | GNUNET_break (CS_CONNECTED == call_state); | ||
962 | GCG_log (_("Connection to `%s' resumed (by other user)\n"), | ||
963 | peer_name); | ||
964 | break; | ||
965 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | ||
966 | GCG_log ("GNUNET_CONVERSATION_EC_CALL_ERROR %s", | ||
967 | peer_name); | ||
968 | } | ||
969 | //} | ||
970 | } | ||
971 | |||
972 | |||
973 | |||
974 | /** | ||
975 | * Initiating a new call | ||
976 | * | ||
977 | * @param arg arguments given to the command | ||
978 | */ | ||
979 | void | ||
980 | GSC_do_call (const char *arg) | ||
981 | { | ||
982 | GtkEntry *address_entry; | ||
983 | struct GNUNET_IDENTITY_Ego *caller_id; | ||
984 | |||
985 | address_entry = GTK_ENTRY (GCG_get_main_window_object ("GNUNET_GTK_conversation_address")); | ||
986 | gtk_entry_set_text (address_entry, | ||
987 | address); | ||
988 | caller_id = GCG_EGOS_get_selected_ego (); | ||
989 | if (NULL == caller_id) | ||
990 | { | ||
991 | // should not be possible! | ||
992 | GCG_log ("%s\n", | ||
993 | _("Caller ID unavailable, cannot initiate call.")); | ||
994 | return; | ||
995 | } | ||
996 | if (NULL != call) | ||
997 | { | ||
998 | GCG_log (_("You are calling someone else already, hang up first!\n")); | ||
999 | return; | ||
1000 | } | ||
1001 | switch (phone_state) | ||
1002 | { | ||
1003 | case PS_LOOKUP_EGO: | ||
1004 | GCG_log ("%s\n", | ||
1005 | _("Caller ID unavailable, cannot initiate call.")); | ||
1006 | // should not be possible! | ||
1007 | return; | ||
1008 | case PS_LISTEN: | ||
1009 | /* ok to call! */ | ||
1010 | break; | ||
1011 | case PS_ACCEPTED: | ||
1012 | GCG_log (_ | ||
1013 | ("You are answering call from `%s', hang up or suspend that call first!\n"), | ||
1014 | peer_name); | ||
1015 | GNUNET_break(0); | ||
1016 | return; | ||
1017 | case PS_ERROR: | ||
1018 | /* ok to call */ | ||
1019 | break; | ||
1020 | } | ||
1021 | //GNUNET_free_non_null (peer_name); | ||
1022 | peer_name = GNUNET_strdup (arg); | ||
1023 | GCG_log (_("now calling: %s"), peer_name); | ||
1024 | call_state = CS_RESOLVING; | ||
1025 | GNUNET_assert (NULL == call); | ||
1026 | |||
1027 | call_counter++; | ||
1028 | call = | ||
1029 | GNUNET_CONVERSATION_call_start (GCG_get_configuration (), | ||
1030 | caller_id, | ||
1031 | arg, | ||
1032 | speaker, mic, | ||
1033 | &call_event_handler, NULL); | ||
1034 | //call = newcall; | ||
1035 | |||
1036 | // add call to active call list | ||
1037 | GtkTreeIter gtkiter; | ||
1038 | |||
1039 | gtk_list_store_append (active_liststore, >kiter); | ||
1040 | |||
1041 | gtk_list_store_set (active_liststore, >kiter, | ||
1042 | AL_caller_id, peer_name, | ||
1043 | AL_caller, NULL, | ||
1044 | AL_caller_num, NULL, | ||
1045 | AL_caller_state, CT_other, | ||
1046 | AL_type, CALL_OUT, | ||
1047 | AL_call, call, | ||
1048 | AL_call_num, call_counter, | ||
1049 | AL_call_state, CS_RESOLVING, | ||
1050 | -1 | ||
1051 | ); | ||
1052 | |||
1053 | |||
1054 | GCG_update_status_bar (_("We are calling `%s', his phone should be ringing."), | ||
1055 | peer_name); | ||
1056 | GCG_HISTORY_add (CH_OUTGOING, | ||
1057 | peer_name); | ||
1058 | } | ||
1059 | |||
1060 | |||
1061 | /** | ||
1062 | * Accepting an incoming call | ||
1063 | * | ||
1064 | * @param args arguments given to the command | ||
1065 | */ | ||
1066 | static void | ||
1067 | do_accept (struct GNUNET_CONVERSATION_Caller *sel_caller) | ||
1068 | { | ||
1069 | struct CallList *cl; | ||
1070 | //char buf[32]; | ||
1071 | |||
1072 | |||
1073 | if ((NULL != call) && (CS_SUSPENDED != call_state)) | ||
1074 | { | ||
1075 | GCG_log (_("You are calling someone else already, hang up first!\n")); | ||
1076 | GNUNET_break(0); | ||
1077 | return; | ||
1078 | } | ||
1079 | switch (phone_state) | ||
1080 | { | ||
1081 | case PS_LOOKUP_EGO: | ||
1082 | GNUNET_break (0); | ||
1083 | break; | ||
1084 | case PS_LISTEN: | ||
1085 | /* this is the expected state */ | ||
1086 | break; | ||
1087 | case PS_ACCEPTED: | ||
1088 | GCG_log (_ | ||
1089 | ("You are answering call from `%s', hang up or suspend that call first!\n"), | ||
1090 | peer_name); | ||
1091 | GNUNET_break(0); | ||
1092 | return; | ||
1093 | case PS_ERROR: | ||
1094 | GNUNET_break (0); | ||
1095 | break; | ||
1096 | }//endswitch | ||
1097 | |||
1098 | phone_state = PS_ACCEPTED; | ||
1099 | set_incoming_call_state(sel_caller,CT_active); | ||
1100 | |||
1101 | for (cl = cl_head; cl; cl = cl->next) | ||
1102 | { | ||
1103 | /* FIXME: this may not be unique enough to identify the right item! | ||
1104 | * Why not store CallList items in treeview instead of just callers? | ||
1105 | */ | ||
1106 | if (cl->caller == sel_caller) | ||
1107 | break; | ||
1108 | } | ||
1109 | GNUNET_CONVERSATION_caller_pick_up (sel_caller, | ||
1110 | &caller_event_handler, cl, | ||
1111 | speaker, mic); | ||
1112 | GCG_HISTORY_add (CH_ACCEPTED, peer_name); | ||
1113 | } | ||
1114 | |||
1115 | |||
1116 | /** | ||
1117 | * Suspending a call | ||
1118 | * | ||
1119 | * @param args arguments given to the command | ||
1120 | */ | ||
1121 | static void | ||
1122 | do_suspend () | ||
1123 | { | ||
1124 | /* | ||
1125 | switch (phone_state) | ||
1126 | { | ||
1127 | case PS_LOOKUP_EGO: | ||
1128 | case PS_LISTEN: | ||
1129 | case PS_ERROR: | ||
1130 | GCG_log ("%s", _(" There is no call that could be suspended right now. (PS_ERROR)")); | ||
1131 | return; | ||
1132 | case PS_ACCEPTED: | ||
1133 | // expected state, do rejection logic | ||
1134 | break; | ||
1135 | } | ||
1136 | */ | ||
1137 | if (call_selected != NULL && caller_selected != NULL) | ||
1138 | { | ||
1139 | GCG_log("this shoud not be possible"); | ||
1140 | GNUNET_break(0); | ||
1141 | } | ||
1142 | else | ||
1143 | { | ||
1144 | // outgoing | ||
1145 | if (NULL != call_selected) | ||
1146 | { | ||
1147 | GNUNET_CONVERSATION_call_suspend (call_selected); | ||
1148 | set_outgoing_call_state(call_selected,CT_suspended); | ||
1149 | |||
1150 | return; | ||
1151 | } | ||
1152 | |||
1153 | // incoming | ||
1154 | if (NULL != caller_selected) | ||
1155 | { | ||
1156 | GNUNET_CONVERSATION_caller_suspend (caller_selected); | ||
1157 | set_incoming_call_state(caller_selected,CT_suspended); | ||
1158 | phone_state = PS_LISTEN; | ||
1159 | return; | ||
1160 | |||
1161 | } | ||
1162 | } | ||
1163 | } | ||
1164 | |||
1165 | |||
1166 | /** | ||
1167 | * Resuming a call | ||
1168 | * | ||
1169 | * @param args arguments given to the command | ||
1170 | */ | ||
1171 | static void | ||
1172 | do_resume () | ||
1173 | { | ||
1174 | |||
1175 | switch (phone_state) | ||
1176 | { | ||
1177 | case PS_LOOKUP_EGO: | ||
1178 | case PS_ERROR: | ||
1179 | GCG_log ("%s", _("There is no call that could be resumed right now.(PS_ERROR)")); | ||
1180 | return; | ||
1181 | case PS_LISTEN: | ||
1182 | break; | ||
1183 | case PS_ACCEPTED: | ||
1184 | GCG_log (_("Already talking with `%s', cannot resume a call right now."), | ||
1185 | peer_name); | ||
1186 | return; | ||
1187 | } | ||
1188 | //// | ||
1189 | if (call_selected != NULL && caller_selected != NULL) | ||
1190 | { | ||
1191 | GCG_log("this shoud not be possible"); | ||
1192 | GNUNET_break(0); | ||
1193 | return; | ||
1194 | } | ||
1195 | else | ||
1196 | { | ||
1197 | |||
1198 | // outgoing | ||
1199 | if (NULL != call_selected) | ||
1200 | { | ||
1201 | GNUNET_CONVERSATION_call_resume (call_selected, speaker, mic); | ||
1202 | set_outgoing_call_state(call_selected,CT_active); | ||
1203 | |||
1204 | return; | ||
1205 | } | ||
1206 | |||
1207 | // incoming | ||
1208 | if (NULL != caller_selected) | ||
1209 | { | ||
1210 | GNUNET_CONVERSATION_caller_resume (caller_selected, speaker, mic); | ||
1211 | set_incoming_call_state(caller_selected,CT_active); | ||
1212 | phone_state = PS_ACCEPTED; | ||
1213 | return; | ||
1214 | |||
1215 | } | ||
1216 | GNUNET_break(0); | ||
1217 | } | ||
1218 | |||
1219 | // | ||
1220 | //// | ||
1221 | } | ||
1222 | |||
1223 | |||
1224 | /** | ||
1225 | / Rejecting a call | ||
1226 | * | ||
1227 | * @param args arguments given to the command | ||
1228 | */ | ||
1229 | static void | ||
1230 | do_reject () | ||
1231 | { | ||
1232 | if (call_selected == NULL && caller_selected == NULL) | ||
1233 | { | ||
1234 | GNUNET_break(0); | ||
1235 | } | ||
1236 | else | ||
1237 | { | ||
1238 | // if selected call is outgoing, stop it | ||
1239 | if (NULL != call_selected) | ||
1240 | { | ||
1241 | set_outgoing_call_state(call_selected,CT_hangup); | ||
1242 | |||
1243 | GNUNET_CONVERSATION_call_stop(call); | ||
1244 | //GNUNET_CONVERSATION_call_stop (call_selected); | ||
1245 | |||
1246 | call = NULL; | ||
1247 | call_selected = NULL; | ||
1248 | return; | ||
1249 | } | ||
1250 | else | ||
1251 | { | ||
1252 | // if selected call is incoming, hang it up | ||
1253 | if (NULL != caller_selected) | ||
1254 | { | ||
1255 | set_incoming_call_state(caller_selected,CT_hangup); | ||
1256 | //FPRINTF(stderr,"hangup: %u", caller_selected); | ||
1257 | GNUNET_CONVERSATION_caller_hang_up(caller_selected); | ||
1258 | //cl_active = NULL; | ||
1259 | phone_state = PS_LISTEN; | ||
1260 | caller_selected = NULL; | ||
1261 | } | ||
1262 | else | ||
1263 | { | ||
1264 | GNUNET_break(0); | ||
1265 | } | ||
1266 | } | ||
1267 | } | ||
1268 | } | ||
1269 | |||
1270 | |||
1271 | /** | ||
1272 | * hangup clicked | ||
1273 | */ | ||
1274 | void | ||
1275 | GNUNET_CONVERSATION_GTK_on_hangup_clicked () | ||
1276 | { | ||
1277 | |||
1278 | do_reject (); | ||
1279 | |||
1280 | do_status (); | ||
1281 | //history_add(3,peer_name); | ||
1282 | } | ||
1283 | |||
1284 | /** | ||
1285 | * accept clicked | ||
1286 | */ | ||
1287 | void | ||
1288 | GNUNET_CONVERSATION_GTK_on_accept_clicked () | ||
1289 | { | ||
1290 | if (caller_selected != NULL) | ||
1291 | { | ||
1292 | do_accept (caller_selected); | ||
1293 | } else { | ||
1294 | GNUNET_break(0); | ||
1295 | } | ||
1296 | do_status(); | ||
1297 | } | ||
1298 | |||
1299 | |||
1300 | /** | ||
1301 | * reject clicked | ||
1302 | */ | ||
1303 | void | ||
1304 | GNUNET_CONVERSATION_GTK_on_reject_clicked () | ||
1305 | { | ||
1306 | do_reject (); | ||
1307 | do_status(); | ||
1308 | } | ||
1309 | |||
1310 | |||
1311 | /** | ||
1312 | * User clicked the '> contact' button to move the selected | ||
1313 | * caller's information into our address book. | ||
1314 | */ | ||
1315 | void | ||
1316 | GNUNET_CONVERSATION_GTK_use_current_button_clicked (GtkButton *button, | ||
1317 | gpointer *user_data) | ||
1318 | { | ||
1319 | // FIXME: implement, use "GSC_add_contact" | ||
1320 | #if 0 | ||
1321 | GtkEntry *addressEntry; | ||
1322 | |||
1323 | addressEntry = GTK_ENTRY (GCG_get_main_window_object ("GNUNET_GTK_conversation_addressAdd")); | ||
1324 | gtk_entry_set_text (addressEntry, | ||
1325 | "FIXME"); | ||
1326 | #endif | ||
1327 | } | ||
1328 | |||
1329 | |||
1330 | |||
1331 | /** | ||
1332 | * pause clicked | ||
1333 | */ | ||
1334 | void | ||
1335 | GNUNET_CONVERSATION_GTK_on_pause_clicked () | ||
1336 | { | ||
1337 | do_suspend (); | ||
1338 | do_status(); | ||
1339 | } | ||
1340 | |||
1341 | /** | ||
1342 | * resume clicked | ||
1343 | */ | ||
1344 | void | ||
1345 | GNUNET_CONVERSATION_GTK_on_resume_clicked () | ||
1346 | { | ||
1347 | do_resume (); | ||
1348 | do_status(); | ||
1349 | } | ||
1350 | |||
1351 | /** | ||
1352 | * status clicked | ||
1353 | */ | ||
1354 | void | ||
1355 | GNUNET_CONVERSATION_GTK_on_status_clicked () | ||
1356 | { | ||
1357 | do_status (); | ||
1358 | } | ||
1359 | |||
1360 | |||
1361 | /** | ||
1362 | * call clicked | ||
1363 | */ | ||
1364 | void | ||
1365 | GNUNET_CONVERSATION_GTK_on_call_clicked () | ||
1366 | { | ||
1367 | GtkEntry *address_entry; | ||
1368 | |||
1369 | address_entry = GTK_ENTRY (GCG_get_main_window_object ("GNUNET_GTK_conversation_address")); | ||
1370 | |||
1371 | GSC_do_call (gtk_entry_get_text(address_entry)); | ||
1372 | //disable_button ("GNUNET_GTK_conversation_accept_button"); | ||
1373 | do_status (); | ||
1374 | // free(to_addr); | ||
1375 | } | ||
1376 | |||
1377 | |||
1378 | /** | ||
1379 | * @brief outgoing ego selector changed, (re)start the phone. | ||
1380 | * | ||
1381 | * @param widget the combo box that changed | ||
1382 | * @param user_data builder (unused) | ||
1383 | */ | ||
1384 | void | ||
1385 | gnunet_conversation_gtk_ego_combobox_changed_cb (GtkComboBox *widget, | ||
1386 | gpointer user_data) | ||
1387 | { | ||
1388 | if (NULL != phone) | ||
1389 | { | ||
1390 | GNUNET_CONVERSATION_phone_destroy (phone); | ||
1391 | phone = NULL; | ||
1392 | } | ||
1393 | start_phone(); | ||
1394 | } | ||
1395 | |||
1396 | |||
1397 | void | ||
1398 | GCG_PHONE_init () | ||
1399 | { | ||
1400 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
1401 | |||
1402 | cfg = GCG_get_configuration (); | ||
1403 | speaker = GNUNET_SPEAKER_create_from_hardware (cfg); | ||
1404 | mic = GNUNET_MICROPHONE_create_from_hardware (cfg); | ||
1405 | /* get gui objects */ | ||
1406 | b_contact = GTK_WIDGET (GCG_get_main_window_object | ||
1407 | ("GNUNET_GTK_conversation_use_current_button")); | ||
1408 | b_accept = GTK_WIDGET (GCG_get_main_window_object | ||
1409 | ("GNUNET_GTK_conversation_accept_button")); | ||
1410 | b_hangup = GTK_WIDGET (GCG_get_main_window_object | ||
1411 | ("GNUNET_GTK_conversation_hangup_button")); | ||
1412 | b_suspend = GTK_WIDGET (GCG_get_main_window_object | ||
1413 | ("GNUNET_GTK_conversation_suspend_button")); | ||
1414 | b_resume = GTK_WIDGET (GCG_get_main_window_object | ||
1415 | ("GNUNET_GTK_conversation_resume_button")); | ||
1416 | |||
1417 | active_liststore = | ||
1418 | GTK_LIST_STORE (GCG_get_main_window_object | ||
1419 | ("gnunet_conversation_gtk_active_calls_liststore")); | ||
1420 | active_treeview = | ||
1421 | GTK_TREE_VIEW (GCG_get_main_window_object | ||
1422 | ("gnunet_conversation_gtk_active_calls_treeview")); | ||
1423 | } | ||
1424 | |||
1425 | |||
1426 | void | ||
1427 | GCG_PHONE_shutdown () | ||
1428 | { | ||
1429 | //TODO: make this work | ||
1430 | //struct OperationContext *oc; | ||
1431 | |||
1432 | /* | ||
1433 | GCG_advertise_shutdown_ (); | ||
1434 | while (NULL != (oc = oc_head)) | ||
1435 | { | ||
1436 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1437 | _("Operation not completed due to shutdown\n")); | ||
1438 | GNUNET_IDENTITY_cancel (oc->op); | ||
1439 | GNUNET_CONTAINER_DLL_remove (oc_head, | ||
1440 | oc_tail, | ||
1441 | oc); | ||
1442 | GNUNET_free (oc); | ||
1443 | } | ||
1444 | */ | ||
1445 | if (NULL != call) | ||
1446 | { | ||
1447 | GNUNET_CONVERSATION_call_stop (call); | ||
1448 | call = NULL; | ||
1449 | } | ||
1450 | if (NULL != phone) | ||
1451 | { | ||
1452 | GNUNET_CONVERSATION_phone_destroy (phone); | ||
1453 | phone = NULL; | ||
1454 | } | ||
1455 | GNUNET_SPEAKER_destroy (speaker); | ||
1456 | speaker = NULL; | ||
1457 | GNUNET_MICROPHONE_destroy (mic); | ||
1458 | mic = NULL; | ||
1459 | GNUNET_free_non_null (peer_name); | ||
1460 | peer_name = NULL; | ||
1461 | phone_state = PS_ERROR; | ||
1462 | } | ||
diff --git a/src/conversation/gnunet-conversation-gtk_phone.h b/src/conversation/gnunet-conversation-gtk_phone.h index e69de29b..f8cfc6ce 100644 --- a/src/conversation/gnunet-conversation-gtk_phone.h +++ b/src/conversation/gnunet-conversation-gtk_phone.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010-2014 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/conversation/gnunet-conversation-gtk_phone.h | ||
23 | * @brief main logic to manage phone calls | ||
24 | * @author yids | ||
25 | * @author hark | ||
26 | */ | ||
27 | #ifndef GNUNET_CONVERSATION_GTK_PHONE_H | ||
28 | #define GNUNET_CONVERSATION_GTK_PHONE_H | ||
29 | |||
30 | |||
31 | |||
32 | /** | ||
33 | * Initiate a call to the given address. | ||
34 | * | ||
35 | * @param address address to call | ||
36 | */ | ||
37 | void | ||
38 | GSC_do_call (const char *address); | ||
39 | |||
40 | |||
41 | void | ||
42 | GCG_PHONE_init (void); | ||
43 | |||
44 | |||
45 | void | ||
46 | GCG_PHONE_shutdown (void); | ||
47 | |||
48 | |||
49 | #endif | ||
diff --git a/src/conversation/gnunet-conversation-gtk_zones.c b/src/conversation/gnunet-conversation-gtk_zones.c new file mode 100644 index 00000000..459c9492 --- /dev/null +++ b/src/conversation/gnunet-conversation-gtk_zones.c | |||
@@ -0,0 +1,148 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2013-2014 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/conversation/gnunet-conversation-gtk_zones.c | ||
23 | * @brief manages the widget which shows the zones (to select | ||
24 | * which one will be used to populate the address book) | ||
25 | * @author yids | ||
26 | * @author hark | ||
27 | * @author Christian Grothoff | ||
28 | */ | ||
29 | #include "gnunet-conversation-gtk.h" | ||
30 | #include "gnunet-conversation-gtk_zones.h" | ||
31 | |||
32 | |||
33 | /** | ||
34 | * Columns in the #zone_liststore. | ||
35 | */ | ||
36 | enum ZoneListstoreValues | ||
37 | { | ||
38 | /** | ||
39 | * Human-readable name of the ego. | ||
40 | */ | ||
41 | ZONE_LS_NAME = 0, | ||
42 | |||
43 | /** | ||
44 | * Handel to the ego (of type `struct GNUNET_IDENTITY_Ego *ego`). | ||
45 | */ | ||
46 | ZONE_LS_EGO = 1 | ||
47 | }; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Handle to identity service. | ||
52 | */ | ||
53 | static struct GNUNET_IDENTITY_Handle *id; | ||
54 | |||
55 | /** | ||
56 | * list of zones | ||
57 | */ | ||
58 | static GtkListStore *zone_liststore; | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Function called by identity service with information about zones. | ||
63 | * | ||
64 | * @param cls NULL | ||
65 | * @param ego ego handle for the zone | ||
66 | * @param ctx unused | ||
67 | * @param name name of the zone | ||
68 | */ | ||
69 | static void | ||
70 | identity_cb (void *cls, | ||
71 | struct GNUNET_IDENTITY_Ego *ego, | ||
72 | void **ctx, | ||
73 | const char *name) | ||
74 | { | ||
75 | GtkTreeIter iter; | ||
76 | GtkTreeRowReference *rr; | ||
77 | GtkTreePath *path; | ||
78 | |||
79 | rr = *ctx; | ||
80 | if (NULL == rr) | ||
81 | { | ||
82 | /* new identity */ | ||
83 | GNUNET_assert (NULL != name); | ||
84 | gtk_list_store_insert_with_values (zone_liststore, | ||
85 | &iter, -1, | ||
86 | ZONE_LS_NAME, name, | ||
87 | ZONE_LS_EGO, ego, | ||
88 | -1); | ||
89 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (zone_liststore), | ||
90 | &iter); | ||
91 | rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (zone_liststore), | ||
92 | path); | ||
93 | gtk_tree_path_free (path); | ||
94 | *ctx = rr; | ||
95 | return; | ||
96 | } | ||
97 | /* existing ego, locate and execute rename/delete */ | ||
98 | path = gtk_tree_row_reference_get_path (rr); | ||
99 | gtk_tree_model_get_iter (GTK_TREE_MODEL (zone_liststore), | ||
100 | &iter, | ||
101 | path); | ||
102 | gtk_tree_path_free (path); | ||
103 | if (NULL == name) | ||
104 | { | ||
105 | /* deletion operation */ | ||
106 | gtk_tree_row_reference_free (rr); | ||
107 | *ctx = NULL; | ||
108 | gtk_list_store_remove (zone_liststore, | ||
109 | &iter); | ||
110 | return; | ||
111 | } | ||
112 | /* rename operation */ | ||
113 | gtk_list_store_set (zone_liststore, | ||
114 | &iter, | ||
115 | ZONE_LS_NAME, &name, | ||
116 | -1); | ||
117 | } | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Initialize the zones list | ||
122 | */ | ||
123 | void | ||
124 | GCG_ZONES_init () | ||
125 | { | ||
126 | zone_liststore | ||
127 | = GTK_LIST_STORE (GCG_get_main_window_object | ||
128 | ("gnunet_conversation_gtk_contacts_zone_liststore")); | ||
129 | id = GNUNET_IDENTITY_connect (GCG_get_configuration (), | ||
130 | &identity_cb, | ||
131 | NULL); | ||
132 | } | ||
133 | |||
134 | |||
135 | /** | ||
136 | * Shutdown the zone list | ||
137 | */ | ||
138 | void | ||
139 | GCG_ZONES_shutdown () | ||
140 | { | ||
141 | if (NULL != id) | ||
142 | { | ||
143 | GNUNET_IDENTITY_disconnect (id); | ||
144 | id = NULL; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /* end of gnunet-conversation-gtk_zones.c */ | ||
diff --git a/src/conversation/gnunet-conversation-gtk_zones.h b/src/conversation/gnunet-conversation-gtk_zones.h new file mode 100644 index 00000000..2484425f --- /dev/null +++ b/src/conversation/gnunet-conversation-gtk_zones.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010-2014 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/conversation/gnunet-conversation-gtk_zones.h | ||
23 | * @brief manages the widget which shows the zones (to select | ||
24 | * which one will be used to populate the address book) | ||
25 | * @author yids | ||
26 | * @author hark | ||
27 | * @author Christian Grothoff | ||
28 | */ | ||
29 | #ifndef GNUNET_CONVERSATION_GTK_ZONES_H | ||
30 | #define GNUNET_CONVERSATION_GTK_ZONES_H | ||
31 | |||
32 | |||
33 | /** | ||
34 | * Initialize the contact list | ||
35 | */ | ||
36 | void | ||
37 | GCG_ZONES_init (void); | ||
38 | |||
39 | |||
40 | /** | ||
41 | * Shutdown the contact list | ||
42 | */ | ||
43 | void | ||
44 | GCG_ZONES_shutdown(void); | ||
45 | |||
46 | #endif | ||