aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-conversation-gtk_phone.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversation/gnunet-conversation-gtk_phone.c')
-rw-r--r--src/conversation/gnunet-conversation-gtk_phone.c271
1 files changed, 240 insertions, 31 deletions
diff --git a/src/conversation/gnunet-conversation-gtk_phone.c b/src/conversation/gnunet-conversation-gtk_phone.c
index d3cf0797..addc641e 100644
--- a/src/conversation/gnunet-conversation-gtk_phone.c
+++ b/src/conversation/gnunet-conversation-gtk_phone.c
@@ -148,7 +148,17 @@ enum InCallState
148 /** 148 /**
149 * The call is currently suspended (by us). 149 * The call is currently suspended (by us).
150 */ 150 */
151 IN_STATE_SUSPENDED 151 IN_STATE_SUSPENDED_LOCAL,
152
153 /**
154 * The call is currently suspended (by remote).
155 */
156 IN_STATE_SUSPENDED_REMOTE,
157
158 /**
159 * The call is currently suspended (by both).
160 */
161 IN_STATE_SUSPENDED_BOTH
152}; 162};
153 163
154 164
@@ -436,12 +446,125 @@ check_call_sensitivity ()
436 446
437 447
438/** 448/**
449 * Update sensitivity of buttons associated with the call list.
450 *
451 * @param sel selection that changed (belongs to #active_treeview)
452 */
453static void
454update_call_buttons (GtkTreeSelection *sel)
455{
456 GtkTreeIter iter;
457 GtkTreeModel *model;
458 gint type;
459 gint in_state;
460 gint out_state;
461 gboolean in_call;
462
463 if (! gtk_tree_selection_get_selected (sel,
464 &model,
465 &iter))
466 {
467 /* nothing selected, disable buttons */
468 gtk_widget_set_sensitive (b_add_contact, FALSE);
469 gtk_widget_set_sensitive (b_accept, FALSE);
470 gtk_widget_set_sensitive (b_refuse, FALSE);
471 gtk_widget_set_sensitive (b_resume, FALSE);
472 return;
473 }
474 in_call = (NULL != active_in) || (NULL != active_out);
475 gtk_tree_model_get (model,
476 &iter,
477 GCG_PHONE_LS_TYPE, &type,
478 GCG_PHONE_LS_CALL_STATE, &out_state,
479 GCG_PHONE_LS_CALLER_STATE, &in_state,
480 -1);
481 switch ((enum TypeOfConversation) type)
482 {
483 case CALL_IN:
484 switch ((enum InCallState) in_state)
485 {
486 case IN_STATE_NONE:
487 GNUNET_break (0);
488 break;
489 case IN_STATE_RINGING:
490 gtk_widget_set_sensitive (b_add_contact, TRUE);
491 gtk_widget_set_sensitive (b_accept, ! in_call);
492 gtk_widget_set_sensitive (b_refuse, TRUE);
493 gtk_widget_set_sensitive (b_resume, ! in_call);
494 break;
495 case IN_STATE_CONNECTED:
496 gtk_widget_set_sensitive (b_add_contact, TRUE);
497 gtk_widget_set_sensitive (b_accept, FALSE);
498 gtk_widget_set_sensitive (b_refuse, FALSE);
499 gtk_widget_set_sensitive (b_resume, FALSE);
500 break;
501 case IN_STATE_SUSPENDED_LOCAL:
502 gtk_widget_set_sensitive (b_add_contact, TRUE);
503 gtk_widget_set_sensitive (b_accept, FALSE);
504 gtk_widget_set_sensitive (b_refuse, TRUE);
505 gtk_widget_set_sensitive (b_resume, TRUE);
506 case IN_STATE_SUSPENDED_REMOTE:
507 gtk_widget_set_sensitive (b_add_contact, TRUE);
508 gtk_widget_set_sensitive (b_accept, FALSE);
509 gtk_widget_set_sensitive (b_refuse, TRUE);
510 gtk_widget_set_sensitive (b_resume, FALSE);
511 case IN_STATE_SUSPENDED_BOTH:
512 gtk_widget_set_sensitive (b_add_contact, TRUE);
513 gtk_widget_set_sensitive (b_accept, FALSE);
514 gtk_widget_set_sensitive (b_refuse, TRUE);
515 gtk_widget_set_sensitive (b_resume, TRUE);
516 break;
517 default:
518 GNUNET_assert (0);
519 }
520 break;
521 case CALL_OUT:
522 switch ((enum OutCallState) out_state)
523 {
524 case OUT_STATE_NONE:
525 GNUNET_break (0);
526 break;
527 case OUT_STATE_RESOLVING:
528 gtk_widget_set_sensitive (b_add_contact, TRUE);
529 gtk_widget_set_sensitive (b_accept, FALSE);
530 gtk_widget_set_sensitive (b_refuse, TRUE);
531 gtk_widget_set_sensitive (b_resume, FALSE);
532 case OUT_STATE_RINGING:
533 gtk_widget_set_sensitive (b_add_contact, TRUE);
534 gtk_widget_set_sensitive (b_accept, ! in_call);
535 gtk_widget_set_sensitive (b_refuse, TRUE);
536 gtk_widget_set_sensitive (b_resume, ! in_call);
537 case OUT_STATE_ACTIVE:
538 gtk_widget_set_sensitive (b_add_contact, TRUE);
539 gtk_widget_set_sensitive (b_accept, FALSE);
540 gtk_widget_set_sensitive (b_refuse, FALSE);
541 gtk_widget_set_sensitive (b_resume, FALSE);
542 case OUT_STATE_SUSPENDED:
543 gtk_widget_set_sensitive (b_add_contact, TRUE);
544 gtk_widget_set_sensitive (b_accept, ! in_call);
545 gtk_widget_set_sensitive (b_refuse, TRUE);
546 gtk_widget_set_sensitive (b_resume, ! in_call);
547 default:
548 GNUNET_assert (0);
549 }
550 break;
551 default:
552 GNUNET_assert (0);
553 }
554}
555
556
557/**
439 * @brief executed when selecting a different item in active call list 558 * @brief executed when selecting a different item in active call list
559 *
560 * @param sel selection that changed (belongs to #active_treeview)
561 * @param user_data builder context (unused)
440 */ 562 */
441void 563void
442gnunet_conversation_gtk_active_calls_treeview_selection_changed_cb () 564gnunet_conversation_gtk_active_calls_treeview_selection_changed_cb (GtkTreeSelection *sel,
565 gpointer user_data)
443{ 566{
444 // FIXME 567 update_call_buttons (sel);
445} 568}
446 569
447 570
@@ -458,6 +581,7 @@ set_outgoing_call_state (struct OutgoingCall *oc,
458 GtkTreePath *path; 581 GtkTreePath *path;
459 GtkTreeIter iter; 582 GtkTreeIter iter;
460 583
584 oc->state = state;
461 path = gtk_tree_row_reference_get_path (oc->rr); 585 path = gtk_tree_row_reference_get_path (oc->rr);
462 GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (active_liststore), 586 GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (active_liststore),
463 &iter, 587 &iter,
@@ -482,6 +606,7 @@ set_outgoing_call_state (struct OutgoingCall *oc,
482 &iter, 606 &iter,
483 GCG_PHONE_LS_CALL_STATE, state, 607 GCG_PHONE_LS_CALL_STATE, state,
484 -1); 608 -1);
609 update_call_buttons (gtk_tree_view_get_selection (active_treeview));
485} 610}
486 611
487 612
@@ -498,6 +623,7 @@ set_incoming_call_state (struct IncomingCall *ic,
498 GtkTreePath *path; 623 GtkTreePath *path;
499 GtkTreeIter iter; 624 GtkTreeIter iter;
500 625
626 ic->state = state;
501 path = gtk_tree_row_reference_get_path (ic->rr); 627 path = gtk_tree_row_reference_get_path (ic->rr);
502 GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (active_liststore), 628 GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (active_liststore),
503 &iter, 629 &iter,
@@ -513,13 +639,18 @@ set_incoming_call_state (struct IncomingCall *ic,
513 break; 639 break;
514 case IN_STATE_CONNECTED: 640 case IN_STATE_CONNECTED:
515 break; 641 break;
516 case IN_STATE_SUSPENDED: 642 case IN_STATE_SUSPENDED_LOCAL:
643 break;
644 case IN_STATE_SUSPENDED_REMOTE:
645 break;
646 case IN_STATE_SUSPENDED_BOTH:
517 break; 647 break;
518 } 648 }
519 gtk_list_store_set (active_liststore, 649 gtk_list_store_set (active_liststore,
520 &iter, 650 &iter,
521 GCG_PHONE_LS_CALLER_STATE, state, 651 GCG_PHONE_LS_CALLER_STATE, state,
522 -1); 652 -1);
653 update_call_buttons (gtk_tree_view_get_selection (active_treeview));
523} 654}
524 655
525 656
@@ -540,10 +671,12 @@ phone_event_handler (void *cls,
540 GtkTreeIter iter; 671 GtkTreeIter iter;
541 gboolean valid; 672 gboolean valid;
542 struct IncomingCall *ic; 673 struct IncomingCall *ic;
674 GtkTreePath *path;
543 675
544 switch (code) 676 switch (code)
545 { 677 {
546 case GNUNET_CONVERSATION_EC_PHONE_RING: 678 case GNUNET_CONVERSATION_EC_PHONE_RING:
679 in_ring_counter++;
547 ic = GNUNET_new (struct IncomingCall); 680 ic = GNUNET_new (struct IncomingCall);
548 ic->caller = caller; 681 ic->caller = caller;
549 ic->caller_id = GNUNET_strdup (caller_id); 682 ic->caller_id = GNUNET_strdup (caller_id);
@@ -557,40 +690,39 @@ phone_event_handler (void *cls,
557 GCG_PHONE_LS_CALLER_STATE, IN_STATE_RINGING, 690 GCG_PHONE_LS_CALLER_STATE, IN_STATE_RINGING,
558 GCG_PHONE_LS_TYPE, CALL_IN, 691 GCG_PHONE_LS_TYPE, CALL_IN,
559 -1); 692 -1);
560 // FIXME: initialize ic->rr 693 path = gtk_tree_model_get_path (GTK_TREE_MODEL (active_liststore),
694 &iter);
695 ic->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (active_liststore),
696 path);
697 gtk_tree_path_free (path);
561 GCG_log (_("A Incoming call from `%s' with number %u\n"), 698 GCG_log (_("A Incoming call from `%s' with number %u\n"),
562 caller_id, 699 caller_id,
563 caller_num_gen); 700 caller_num_gen);
564 break; 701 break;
565 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: 702 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
703 in_ring_counter--;
566 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (active_liststore), 704 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (active_liststore),
567 &iter); 705 &iter);
568 GNUNET_break (valid); 706 GNUNET_break (valid);
569 while (valid) 707 while (valid)
570 { 708 {
571 gchar *str_data;
572 gint int_data;
573 struct IncomingCall *ic;
574
575 gtk_tree_model_get (GTK_TREE_MODEL (active_liststore), 709 gtk_tree_model_get (GTK_TREE_MODEL (active_liststore),
576 &iter, 710 &iter,
577 GCG_PHONE_LS_CALLER, &ic, 711 GCG_PHONE_LS_CALLER, &ic,
578 GCG_PHONE_LS_CALLER_ID, &str_data,
579 GCG_PHONE_LS_CALLER_NUM, &int_data,
580 -1); 712 -1);
581 if (caller == ic->caller) 713 if (caller == ic->caller)
582 { 714 {
583 GCG_log (_("phone hung up:%s number: %u "), 715 GCG_log (_("phone hung up: %s number: %u"),
584 str_data, 716 ic->caller_id,
585 int_data); 717 ic->caller_num);
586 set_incoming_call_state (ic, 718 set_incoming_call_state (ic,
587 IN_STATE_NONE); 719 IN_STATE_NONE);
588 break; 720 break;
589 } 721 }
590 g_free (str_data);
591 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (active_liststore), 722 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (active_liststore),
592 &iter); 723 &iter);
593 } 724 }
725 GNUNET_break (valid);
594 phone_state = PS_LISTEN; 726 phone_state = PS_LISTEN;
595 break; 727 break;
596 } 728 }
@@ -601,16 +733,17 @@ phone_event_handler (void *cls,
601/** 733/**
602 * Function called with an event emitted by a caller. 734 * Function called with an event emitted by a caller.
603 * 735 *
604 * @param cls closure with the `struct CallList` of the caller 736 * @param cls closure with the `struct IncomingCall` of the caller
605 * @param code type of the event issued by the caller 737 * @param code type of the event issued by the caller
606 */ 738 */
607static void 739static void
608caller_event_handler (void *cls, 740caller_event_handler (void *cls,
609 enum GNUNET_CONVERSATION_CallerEventCode code) 741 enum GNUNET_CONVERSATION_CallerEventCode code)
610{ 742{
611 struct IncomingCall *cl = cls; 743 struct IncomingCall *ic = cls;
744 enum InCallState is;
612 745
613 if (NULL == cl) 746 if (NULL == ic)
614 { 747 {
615 GNUNET_break (0); 748 GNUNET_break (0);
616 return; 749 return;
@@ -618,17 +751,66 @@ caller_event_handler (void *cls,
618 switch (code) 751 switch (code)
619 { 752 {
620 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: 753 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
621 //TODO: should this be cls? not cl->caller 754 is = ic->state;
622 set_incoming_call_state (cl, 755 switch (ic->state)
623 IN_STATE_SUSPENDED); 756 {
757 case IN_STATE_NONE:
758 GNUNET_assert (0);
759 break;
760 case IN_STATE_RINGING:
761 GNUNET_assert (0);
762 break;
763 case IN_STATE_CONNECTED:
764 is = IN_STATE_SUSPENDED_REMOTE;
765 break;
766 case IN_STATE_SUSPENDED_LOCAL:
767 is = IN_STATE_SUSPENDED_BOTH;
768 break;
769 case IN_STATE_SUSPENDED_REMOTE:
770 GNUNET_assert (0);
771 break;
772 case IN_STATE_SUSPENDED_BOTH:
773 GNUNET_assert (0);
774 break;
775 default:
776 GNUNET_assert (0);
777 break;
778 }
779 set_incoming_call_state (ic,
780 is);
624 GCG_log (_("Call from `%s' suspended by other user\n"), 781 GCG_log (_("Call from `%s' suspended by other user\n"),
625 cl->caller_id); 782 ic->caller_id);
626 break; 783 break;
627 case GNUNET_CONVERSATION_EC_CALLER_RESUME: 784 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
628 set_incoming_call_state(cl, 785 is = ic->state;
629 IN_STATE_CONNECTED); 786 switch (ic->state)
787 {
788 case IN_STATE_NONE:
789 GNUNET_assert (0);
790 break;
791 case IN_STATE_RINGING:
792 GNUNET_assert (0);
793 break;
794 case IN_STATE_CONNECTED:
795 GNUNET_assert (0);
796 break;
797 case IN_STATE_SUSPENDED_LOCAL:
798 GNUNET_assert (0);
799 break;
800 case IN_STATE_SUSPENDED_REMOTE:
801 is = IN_STATE_CONNECTED;
802 break;
803 case IN_STATE_SUSPENDED_BOTH:
804 is = IN_STATE_SUSPENDED_LOCAL;
805 break;
806 default:
807 GNUNET_assert (0);
808 break;
809 }
810 set_incoming_call_state (ic,
811 is);
630 GCG_log (_("Call from `%s' resumed by other user\n"), 812 GCG_log (_("Call from `%s' resumed by other user\n"),
631 cl->caller_id); 813 ic->caller_id);
632 break; 814 break;
633 } 815 }
634 do_status(); 816 do_status();
@@ -646,6 +828,9 @@ GNUNET_CONVERSATION_GTK_on_accept_clicked (GtkButton *button,
646 gpointer user_data) 828 gpointer user_data)
647{ 829{
648 struct IncomingCall *ic; 830 struct IncomingCall *ic;
831 GtkTreeSelection *sel;
832 GtkTreeIter iter;
833 GtkTreeModel *model;
649 834
650 if ( (NULL != active_in) || 835 if ( (NULL != active_in) ||
651 (NULL != active_out) || 836 (NULL != active_out) ||
@@ -656,7 +841,26 @@ GNUNET_CONVERSATION_GTK_on_accept_clicked (GtkButton *button,
656 return; 841 return;
657 } 842 }
658 phone_state = PS_ACCEPTED; 843 phone_state = PS_ACCEPTED;
659 ic = NULL; // FIXME: get 'ic' from selection! 844 sel = gtk_tree_view_get_selection (active_treeview);
845 if (! gtk_tree_selection_get_selected (sel,
846 &model,
847 &iter))
848 {
849 /* accept button should not have been sensitive! */
850 GNUNET_break (0);
851 return;
852 }
853 gtk_tree_model_get (model,
854 &iter,
855 GCG_PHONE_LS_CALLER_STATE, &ic,
856 -1);
857 if (NULL == ic)
858 {
859 /* accept button should not have been sensitive! */
860 GNUNET_break (0);
861 return;
862 }
863 active_in = ic;
660 set_incoming_call_state (ic, 864 set_incoming_call_state (ic,
661 IN_STATE_CONNECTED); 865 IN_STATE_CONNECTED);
662 GCG_update_status_bar (_("Started a conversation with `%s'.\n"), 866 GCG_update_status_bar (_("Started a conversation with `%s'.\n"),
@@ -667,7 +871,6 @@ GNUNET_CONVERSATION_GTK_on_accept_clicked (GtkButton *button,
667 speaker, mic); 871 speaker, mic);
668 GCG_HISTORY_add (GCG_HISTORY_TYPE_ACCEPTED, 872 GCG_HISTORY_add (GCG_HISTORY_TYPE_ACCEPTED,
669 ic->caller_id); 873 ic->caller_id);
670 // FIXME: update visibility properly...
671 do_status (); 874 do_status ();
672} 875}
673 876
@@ -800,7 +1003,7 @@ GNUNET_CONVERSATION_GTK_on_pause_clicked (GtkButton *button,
800 /* incoming */ 1003 /* incoming */
801 GNUNET_CONVERSATION_caller_suspend (active_in->caller); 1004 GNUNET_CONVERSATION_caller_suspend (active_in->caller);
802 set_incoming_call_state (active_in, 1005 set_incoming_call_state (active_in,
803 IN_STATE_SUSPENDED); 1006 IN_STATE_SUSPENDED_LOCAL);
804 active_in = NULL; 1007 active_in = NULL;
805 phone_state = PS_LISTEN; 1008 phone_state = PS_LISTEN;
806 // FIXME: visibility 1009 // FIXME: visibility
@@ -990,7 +1193,8 @@ void
990GSC_PHONE_make_call (const char *arg) 1193GSC_PHONE_make_call (const char *arg)
991{ 1194{
992 struct GNUNET_IDENTITY_Ego *caller_id; 1195 struct GNUNET_IDENTITY_Ego *caller_id;
993 GtkTreeIter gtkiter; 1196 GtkTreePath *path;
1197 GtkTreeIter iter;
994 struct OutgoingCall *oc; 1198 struct OutgoingCall *oc;
995 1199
996 gtk_entry_set_text (address_entry, 1200 gtk_entry_set_text (address_entry,
@@ -1042,7 +1246,7 @@ GSC_PHONE_make_call (const char *arg)
1042 speaker, mic, 1246 speaker, mic,
1043 &call_event_handler, oc); 1247 &call_event_handler, oc);
1044 gtk_list_store_insert_with_values (active_liststore, 1248 gtk_list_store_insert_with_values (active_liststore,
1045 &gtkiter, 1249 &iter,
1046 -1, 1250 -1,
1047 GCG_PHONE_LS_CALLER_ID, oc->peer_name, 1251 GCG_PHONE_LS_CALLER_ID, oc->peer_name,
1048 GCG_PHONE_LS_CALLER, NULL, 1252 GCG_PHONE_LS_CALLER, NULL,
@@ -1052,7 +1256,12 @@ GSC_PHONE_make_call (const char *arg)
1052 GCG_PHONE_LS_CALL, oc, 1256 GCG_PHONE_LS_CALL, oc,
1053 GCG_PHONE_LS_CALL_NUM, call_counter, 1257 GCG_PHONE_LS_CALL_NUM, call_counter,
1054 GCG_PHONE_LS_CALL_STATE, OUT_STATE_RESOLVING, 1258 GCG_PHONE_LS_CALL_STATE, OUT_STATE_RESOLVING,
1055 -1); 1259 -1);
1260 path = gtk_tree_model_get_path (GTK_TREE_MODEL (active_liststore),
1261 &iter);
1262 oc->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (active_liststore),
1263 path);
1264 gtk_tree_path_free (path);
1056 /* log event */ 1265 /* log event */
1057 GCG_log (_("Resolving `%s'.\n"), 1266 GCG_log (_("Resolving `%s'.\n"),
1058 oc->peer_name); 1267 oc->peer_name);