1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
|
/*
* Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include <glib/gi18n.h>
#include <gtk/gtk.h>
/* Backward compatibility for gtk < 2.22.0 */
#if GTK_CHECK_VERSION(2,22,0)
#include <gdk/gdkkeysyms-compat.h>
#else
#include <gdk/gdkkeysyms.h>
#endif
#include "str_utils.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <arpa/nameser.h>
#include <netinet/in.h>
#include <resolv.h>
#include <linux/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include "actions.h"
#include "dbus/dbus.h"
#include "logger.h"
#include "contacts/calltab.h"
#include "contacts/searchbar.h"
#include "contacts/addrbookfactory.h"
#include "icons/icon_factory.h"
#include "imwindow.h"
#include "statusicon.h"
#include "unused.h"
#include "widget/imwidget.h"
#include "sliders.h"
static GHashTable * ip2ip_profile;
void
sflphone_notify_voice_mail(const gchar* accountID , guint count)
{
// We want to notify only the current account; ie the first in the list
gchar *id = g_strdup(accountID);
const gchar * const current_id = account_list_get_current_id();
DEBUG("sflphone_notify_voice_mail begin");
if (g_ascii_strcasecmp(id, current_id) != 0 ||
account_list_get_size() == 0)
return;
// Set the number of voice messages for the current account
current_account_set_message_number(count);
account_t *current = account_list_get_current();
// Update the voicemail tool button
update_voicemail_status();
if (current)
notify_voice_mails(count, current);
DEBUG("sflphone_notify_voice_mail end");
}
/*
* Place a call with the current account.
* If there is no default account selected, place a call with the first
* registered account of the account list
* Else, check if it an IP call. if not, popup an error message
*/
static gboolean is_direct_call(callable_obj_t * c)
{
if (utf8_case_equal(c->_accountID, "empty")) {
if (!g_str_has_prefix(c->_peer_number, "sip:")) {
gchar * new_number = g_strconcat("sip:", c->_peer_number, NULL);
g_free(c->_peer_number);
c->_peer_number = new_number;
}
return TRUE;
}
return g_str_has_prefix(c->_peer_number, "sip:") ||
g_str_has_prefix(c->_peer_number, "sips:");
}
void
status_bar_display_account()
{
statusbar_pop_message(__MSG_ACCOUNT_DEFAULT);
account_t *acc = account_list_get_current();
status_tray_icon_online(acc != NULL);
gchar* msg;
if (acc) {
msg = g_markup_printf_escaped("%s %s (%s)" ,
_("Using account"),
(gchar*) account_lookup(acc, ACCOUNT_ALIAS),
(gchar*) account_lookup(acc, ACCOUNT_TYPE));
} else {
msg = g_markup_printf_escaped(_("No registered accounts"));
}
statusbar_push_message(msg, NULL, __MSG_ACCOUNT_DEFAULT);
g_free(msg);
}
void
sflphone_quit()
{
if (calllist_get_size(current_calls_tab) == 0 || main_window_ask_quit()) {
dbus_unregister(getpid());
dbus_clean();
account_list_free();
calllist_clean(current_calls_tab);
calllist_clean(contacts_tab);
calllist_clean(history_tab);
gtk_main_quit();
}
}
void
sflphone_hold(callable_obj_t * c)
{
c->_state = CALL_STATE_HOLD;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_ringing(callable_obj_t * c)
{
c->_state = CALL_STATE_RINGING;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_hung_up(callable_obj_t * c)
{
DEBUG("%s", __PRETTY_FUNCTION__);
calllist_remove_call(current_calls_tab, c->_callID);
calltree_remove_call(current_calls_tab, c->_callID);
c->_state = CALL_STATE_DIALING;
call_remove_all_errors(c);
update_actions();
// test whether the widget contains text, if not remove it
if ((im_window_get_nb_tabs() > 1) && c->_im_widget && !(IM_WIDGET(c->_im_widget)->containText))
im_window_remove_tab(c->_im_widget);
else
im_widget_update_state(IM_WIDGET(c->_im_widget), FALSE);
status_tray_icon_blink(FALSE);
statusbar_update_clock("");
}
void sflphone_fill_account_list(void)
{
account_list_init();
gchar **array = dbus_account_list();
for (gchar **accountID = array; accountID && *accountID; ++accountID) {
account_t *acc = create_account_with_ID(*accountID);
if (acc->properties == NULL) {
ERROR("SFLphone: Error: Could not fetch details for account %s",
accountID);
break;
}
account_list_add(acc);
/* Fill the actual array of credentials */
dbus_get_credentials(acc);
gchar * status = account_lookup(acc, ACCOUNT_REGISTRATION_STATUS);
if (g_strcmp0(status, "REGISTERED") == 0)
acc->state = ACCOUNT_STATE_REGISTERED;
else if (g_strcmp0(status, "UNREGISTERED") == 0)
acc->state = ACCOUNT_STATE_UNREGISTERED;
else if (g_strcmp0(status, "TRYING") == 0)
acc->state = ACCOUNT_STATE_TRYING;
else if (g_strcmp0(status, "ERROR") == 0)
acc->state = ACCOUNT_STATE_ERROR;
else if (g_strcmp0(status, "ERROR_AUTH") == 0)
acc->state = ACCOUNT_STATE_ERROR_AUTH;
else if (g_strcmp0(status, "ERROR_NETWORK") == 0)
acc->state = ACCOUNT_STATE_ERROR_NETWORK;
else if (g_strcmp0(status, "ERROR_HOST") == 0)
acc->state = ACCOUNT_STATE_ERROR_HOST;
else if (g_strcmp0(status, "ERROR_NOT_ACCEPTABLE") == 0)
acc->state = ACCOUNT_STATE_ERROR_NOT_ACCEPTABLE;
else if (g_strcmp0(status, "ERROR_EXIST_STUN") == 0)
acc->state = ACCOUNT_STATE_ERROR_EXIST_STUN;
else if (g_strcmp0(status, "ACCOUNT_STATE_IP2IP_READY") == 0)
acc->state = ACCOUNT_STATE_IP2IP_READY;
else
acc->state = ACCOUNT_STATE_INVALID;
gchar * code = account_lookup(acc, ACCOUNT_REGISTRATION_STATE_CODE);
if (code != NULL)
acc->protocol_state_code = atoi(code);
acc->protocol_state_description = account_lookup(acc, ACCOUNT_REGISTRATION_STATE_DESC);
}
g_strfreev(array);
// Set the current account message number
current_account_set_message_number(current_account_get_message_number());
}
gboolean sflphone_init(GError **error)
{
if (!dbus_connect(error) || !dbus_register(getpid(), "Gtk+ Client", error))
return FALSE;
abook_init();
// Init icons factory
init_icon_factory();
current_calls_tab = calltab_init(FALSE, CURRENT_CALLS);
contacts_tab = calltab_init(TRUE, CONTACTS);
history_tab = calltab_init(TRUE, HISTORY);
codec_capabilities_load();
conferencelist_init(current_calls_tab);
// Fetch the configured accounts
sflphone_fill_account_list();
// Fetch the ip2ip profile
sflphone_fill_ip2ip_profile();
return TRUE;
}
void sflphone_fill_ip2ip_profile(void)
{
ip2ip_profile = (GHashTable *) dbus_get_ip2_ip_details();
}
GHashTable *sflphone_get_ip2ip_properties(void)
{
return ip2ip_profile;
}
void
sflphone_hang_up()
{
callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
DEBUG("%s", __PRETTY_FUNCTION__);
if (selectedConf) {
im_widget_update_state(IM_WIDGET(selectedConf->_im_widget), FALSE);
dbus_hang_up_conference(selectedConf);
} else if (selectedCall) {
switch (selectedCall->_state) {
case CALL_STATE_DIALING:
dbus_hang_up(selectedCall);
break;
case CALL_STATE_RINGING:
dbus_hang_up(selectedCall);
call_remove_all_errors(selectedCall);
selectedCall->_state = CALL_STATE_DIALING;
//selectedCall->_stop = 0;
break;
case CALL_STATE_CURRENT:
case CALL_STATE_HOLD:
case CALL_STATE_BUSY:
case CALL_STATE_RECORD:
dbus_hang_up(selectedCall);
call_remove_all_errors(selectedCall);
selectedCall->_state = CALL_STATE_DIALING;
time(&selectedCall->_time_stop);
im_widget_update_state(IM_WIDGET(selectedCall->_im_widget), FALSE);
break;
case CALL_STATE_FAILURE:
dbus_hang_up(selectedCall);
call_remove_all_errors(selectedCall);
selectedCall->_state = CALL_STATE_DIALING;
break;
case CALL_STATE_INCOMING:
dbus_refuse(selectedCall);
call_remove_all_errors(selectedCall);
selectedCall->_state = CALL_STATE_DIALING;
DEBUG("from sflphone_hang_up : ");
break;
case CALL_STATE_TRANSFER:
dbus_hang_up(selectedCall);
call_remove_all_errors(selectedCall);
time(&selectedCall->_time_stop);
break;
default:
WARN("Should not happen in sflphone_hang_up()!");
break;
}
}
calltree_update_call(history_tab, selectedCall);
statusbar_update_clock("");
// Allow screen saver to start
guint nbcall = calllist_get_size(current_calls_tab);
if(nbcall == 1)
dbus_screensaver_uninhibit();
}
void
sflphone_pick_up()
{
callable_obj_t *selectedCall = calltab_get_selected_call(active_calltree_tab);
// Disable screensaver if the list is empty call
guint nbcall = calllist_get_size(current_calls_tab);
if(nbcall == 0)
dbus_screensaver_inhibit();
if (!selectedCall) {
sflphone_new_call();
return;
}
switch (selectedCall->_state) {
case CALL_STATE_DIALING:
sflphone_place_call(selectedCall);
// if instant messaging window is visible, create new tab (deleted automatically if not used)
if (im_window_is_visible())
if (!selectedCall->_im_widget)
selectedCall->_im_widget = im_widget_display(selectedCall->_callID);
break;
case CALL_STATE_INCOMING:
selectedCall->_history_state = g_strdup(INCOMING_STRING);
calltree_update_call(history_tab, selectedCall);
// if instant messaging window is visible, create new tab (deleted automatically if not used)
if (im_window_is_visible())
if (!selectedCall->_im_widget)
selectedCall->_im_widget = im_widget_display(selectedCall->_callID);
dbus_accept(selectedCall);
break;
case CALL_STATE_TRANSFER:
dbus_transfer(selectedCall);
time(&selectedCall->_time_stop);
calltree_remove_call(current_calls_tab, selectedCall->_callID);
update_actions();
calllist_remove_call(current_calls_tab, selectedCall->_callID);
break;
case CALL_STATE_CURRENT:
case CALL_STATE_HOLD:
case CALL_STATE_RECORD:
case CALL_STATE_RINGING:
sflphone_new_call();
break;
default:
WARN("Should not happen in sflphone_pick_up()!");
break;
}
}
void
sflphone_on_hold()
{
callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
if (selectedCall) {
switch (selectedCall->_state) {
case CALL_STATE_CURRENT:
case CALL_STATE_RECORD:
dbus_hold(selectedCall);
break;
default:
WARN("Should not happen in sflphone_on_hold!");
break;
}
} else if (selectedConf)
dbus_hold_conference(selectedConf);
}
void
sflphone_off_hold()
{
DEBUG("%s", __PRETTY_FUNCTION__);
callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
if (selectedCall) {
switch (selectedCall->_state) {
case CALL_STATE_HOLD:
dbus_unhold(selectedCall);
break;
default:
WARN("Should not happen in sflphone_off_hold ()!");
break;
}
} else if (selectedConf)
dbus_unhold_conference(selectedConf);
}
void
sflphone_fail(callable_obj_t * c)
{
c->_state = CALL_STATE_FAILURE;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_busy(callable_obj_t * c)
{
c->_state = CALL_STATE_BUSY;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_current(callable_obj_t * c)
{
if (c->_state != CALL_STATE_HOLD)
time(&c->_time_start);
c->_state = CALL_STATE_CURRENT;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_record(callable_obj_t * c)
{
if (c->_state != CALL_STATE_HOLD)
time(&c->_time_start);
c->_state = CALL_STATE_RECORD;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_set_transfer()
{
callable_obj_t * c = calltab_get_selected_call(current_calls_tab);
if (c) {
c->_state = CALL_STATE_TRANSFER;
g_free(c->_trsft_to);
c->_trsft_to = g_strdup("");
calltree_update_call(current_calls_tab, c);
}
update_actions();
}
void
sflphone_unset_transfer()
{
callable_obj_t * c = calltab_get_selected_call(current_calls_tab);
if (c) {
c->_state = CALL_STATE_CURRENT;
g_free(c->_trsft_to);
c->_trsft_to = g_strdup("");
calltree_update_call(current_calls_tab, c);
}
update_actions();
}
void
sflphone_display_transfer_status(const gchar* message)
{
statusbar_push_message(message , NULL, __MSG_ACCOUNT_DEFAULT);
}
void
sflphone_incoming_call(callable_obj_t * c)
{
c->_history_state = g_strdup(MISSED_STRING);
calllist_add_call(current_calls_tab, c);
calltree_add_call(current_calls_tab, c, NULL);
update_actions();
calltree_display(current_calls_tab);
// Change the status bar if we are dealing with a direct SIP call
if (is_direct_call(c)) {
gchar *msg = g_markup_printf_escaped(_("Direct SIP call"));
statusbar_pop_message(__MSG_ACCOUNT_DEFAULT);
statusbar_push_message(msg , NULL, __MSG_ACCOUNT_DEFAULT);
g_free(msg);
}
}
static void
process_dialing(callable_obj_t *c, guint keyval, gchar *key)
{
// We stop the tone
if (!*c->_peer_number && c->_state != CALL_STATE_TRANSFER)
dbus_start_tone(FALSE, 0);
switch (keyval) {
case GDK_Return:
case GDK_KP_Enter:
sflphone_place_call(c);
break;
case GDK_Escape:
sflphone_hang_up();
break;
case GDK_BackSpace: {
gchar *num = (c->_state == CALL_STATE_TRANSFER) ? c->_trsft_to : c->_peer_number;
size_t len = strlen(num);
if (len) {
len--; // delete one character
num[len] = '\0';
calltree_update_call(current_calls_tab, c);
/* If number is now empty, hang up immediately */
if (c->_state != CALL_STATE_TRANSFER && len == 0)
dbus_hang_up(c);
}
break;
}
case GDK_Tab:
case GDK_Alt_L:
case GDK_Control_L:
case GDK_Super_L:
case GDK_Caps_Lock:
break;
default:
if (keyval < 127 /* ascii */ ||
(keyval >= GDK_Mode_switch && keyval <= GDK_KP_9) /* num keypad */) {
if (c->_state == CALL_STATE_TRANSFER) {
gchar *new_trsft = g_strconcat(c->_trsft_to, key, NULL);
g_free(c->_trsft_to);
c->_trsft_to = new_trsft;
} else {
dbus_play_dtmf(key);
gchar *new_peer_number = g_strconcat(c->_peer_number, key, NULL);
g_free(c->_peer_number);
c->_peer_number = new_peer_number;
}
calltree_update_call(current_calls_tab, c);
}
break;
}
}
callable_obj_t *
sflphone_new_call()
{
// Disable screensaver if the list is empty call
guint nbcall = calllist_get_size(current_calls_tab);
if(nbcall == 0)
dbus_screensaver_inhibit();
callable_obj_t *current_selected_call = calltab_get_selected_call(current_calls_tab);
if (current_selected_call != NULL) {
gchar *confID = dbus_get_conference_id(current_selected_call->_callID);
if(g_strcmp0(confID, "") != 0) {
sflphone_on_hold();
}
}
// Play a tone when creating a new call
if (calllist_get_size(current_calls_tab) == 0)
dbus_start_tone(TRUE , (current_account_has_new_message() > 0) ? TONE_WITH_MESSAGE : TONE_WITHOUT_MESSAGE) ;
callable_obj_t *c = create_new_call(CALL, CALL_STATE_DIALING, "", "", "", "");
c->_history_state = g_strdup(OUTGOING_STRING);
calllist_add_call(current_calls_tab, c);
calltree_add_call(current_calls_tab, c, NULL);
update_actions();
return c;
}
void
sflphone_keypad(guint keyval, gchar * key)
{
callable_obj_t * c = calltab_get_selected_call(current_calls_tab);
if ((active_calltree_tab != current_calls_tab) || (active_calltree_tab == current_calls_tab && !c)) {
switch (keyval) {
case GDK_Return:
case GDK_KP_Enter:
case GDK_Escape:
case GDK_BackSpace:
break;
default:
calltree_display(current_calls_tab);
process_dialing(sflphone_new_call(), keyval, key);
break;
}
} else if (c) {
switch (c->_state) {
case CALL_STATE_DIALING: // Currently dialing => edit number
process_dialing(c, keyval, key);
break;
case CALL_STATE_RECORD:
case CALL_STATE_CURRENT:
switch (keyval) {
case GDK_Escape:
dbus_hang_up(c);
time(&c->_time_stop);
calltree_update_call(history_tab, c);
break;
default:
// To play the dtmf when calling mail box for instance
dbus_play_dtmf(key);
break;
}
break;
case CALL_STATE_INCOMING:
switch (keyval) {
case GDK_Return:
case GDK_KP_Enter:
c->_history_state = g_strdup(INCOMING_STRING);
calltree_update_call(history_tab, c);
dbus_accept(c);
break;
case GDK_Escape:
dbus_refuse(c);
break;
}
break;
case CALL_STATE_TRANSFER:
switch (keyval) {
case GDK_Return:
case GDK_KP_Enter:
dbus_transfer(c);
time(&c->_time_stop);
calltree_remove_call(current_calls_tab, c->_callID);
update_actions();
break;
case GDK_Escape:
sflphone_unset_transfer();
break;
default: // When a call is on transfer, typing new numbers will add it to c->_peer_number
process_dialing(c, keyval, key);
break;
}
break;
case CALL_STATE_HOLD:
switch (keyval) {
case GDK_Return:
case GDK_KP_Enter:
dbus_unhold(c);
break;
case GDK_Escape:
dbus_hang_up(c);
break;
default: // When a call is on hold, typing new numbers will create a new call
process_dialing(sflphone_new_call(), keyval, key);
break;
}
break;
case CALL_STATE_RINGING:
case CALL_STATE_BUSY:
case CALL_STATE_FAILURE:
switch (keyval) {
case GDK_Escape:
dbus_hang_up(c);
calltree_update_call(history_tab, c);
break;
}
break;
default:
break;
}
} else
sflphone_new_call();
}
int
sflphone_place_call(callable_obj_t * c)
{
account_t * account = NULL;
if (c == NULL) {
ERROR("Callable object is NULL while making new call");
return -1;
}
DEBUG("Placing call from %s to %s using account %s", c->_display_name, c->_peer_number, c->_accountID);
if (c->_state != CALL_STATE_DIALING) {
ERROR("Call not in state dialing, cannot place call");
return -1;
}
if (!c->_peer_number || strlen(c->_peer_number) == 0) {
ERROR("No peer number set for this call");
return -1;
}
// Get the account for this call
if (strlen(c->_accountID) != 0) {
DEBUG("Account %s already set for this call", c->_accountID);
account = account_list_get_by_id(c->_accountID);
} else {
DEBUG("No account set for this call, use first of the list");
account = account_list_get_current();
}
// Make sure the previously found account is registered, take first one registered elsewhere
if (account) {
gpointer status = g_hash_table_lookup(account->properties, "Status");
if (!utf8_case_equal(status, "REGISTERED")) {
// Place the call with the first registered account
account = account_list_get_by_state(ACCOUNT_STATE_REGISTERED);
}
}
// If there is no account specified or found, fallback on IP2IP call
if(account == NULL) {
DEBUG("Could not find an account for this call, making ip to ip call");
account = account_list_get_by_id("IP2IP");
if (account == NULL) {
ERROR("Actions: Could not determine any account for this call");
return -1;
}
}
// free memory for previous account id and use the new one in case it changed
g_free(c->_accountID);
c->_accountID = g_strdup(account->accountID);
dbus_place_call(c);
notify_current_account(account);
c->_history_state = g_strdup(OUTGOING_STRING);
return 0;
}
void
sflphone_detach_participant(const gchar* callID)
{
callable_obj_t * selectedCall;
if (callID == NULL)
selectedCall = calltab_get_selected_call(current_calls_tab);
else
selectedCall = calllist_get_call(current_calls_tab, callID);
DEBUG("Detach participant %s", selectedCall->_callID);
im_widget_update_state(IM_WIDGET(selectedCall->_im_widget), TRUE);
calltree_remove_call(current_calls_tab, selectedCall->_callID);
calltree_add_call(current_calls_tab, selectedCall, NULL);
dbus_detach_participant(selectedCall->_callID);
}
void
sflphone_add_participant(const gchar* callID, const gchar* confID)
{
DEBUG("Add participant %s to conference %s", callID, confID);
callable_obj_t *call = calllist_get_call(current_calls_tab, callID);
if (call == NULL) {
ERROR("Could not find call");
return;
}
dbus_add_participant(callID, confID);
}
void
sflphone_add_main_participant(const conference_obj_t * c)
{
DEBUG("%s", __PRETTY_FUNCTION__);
dbus_add_main_participant(c->_confID);
}
void
sflphone_rec_call()
{
callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
conference_obj_t * selectedConf = calltab_get_selected_conf(current_calls_tab);
if (selectedCall) {
DEBUG("Set record for selected call");
dbus_set_record(selectedCall->_callID);
switch (selectedCall->_state) {
case CALL_STATE_CURRENT:
selectedCall->_state = CALL_STATE_RECORD;
break;
case CALL_STATE_RECORD:
selectedCall->_state = CALL_STATE_CURRENT;
break;
default:
WARN("Should not happen in sflphone_off_hold ()!");
break;
}
calltree_update_call(current_calls_tab, selectedCall);
} else if (selectedConf) {
DEBUG("Set record for selected conf");
dbus_set_record(selectedConf->_confID);
switch (selectedConf->_state) {
case CONFERENCE_STATE_ACTIVE_ATTACHED:
selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
break;
case CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD:
selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED;
break;
case CONFERENCE_STATE_ACTIVE_DETACHED:
selectedConf->_state = CONFERENCE_STATE_ACTIVE_DETACHED_RECORD;
break;
case CONFERENCE_STATE_ACTIVE_DETACHED_RECORD:
selectedConf->_state = CONFERENCE_STATE_ACTIVE_DETACHED_RECORD;
break;
default:
WARN("Should not happen in sflphone_off_hold ()!");
break;
}
DEBUG("Remove and add conference %s", selectedConf->_confID);
calltree_remove_conference(current_calls_tab, selectedConf);
calltree_add_conference_to_current_calls(selectedConf);
}
update_actions();
}
void
sflphone_mute_call()
{
DEBUG("%s", __PRETTY_FUNCTION__);
toggle_slider_mute_microphone();
}
void sflphone_fill_codec_list_per_account(account_t *account)
{
GArray *order = dbus_get_active_audio_codec_list(account->accountID);
GQueue *codeclist = account->codecs;
// First clean the list
codec_list_clear(&codeclist);
for (guint i = 0; i < order->len; i++) {
gint payload = g_array_index(order, gint, i);
// Each account will have a copy of the system-wide capabilities
codec_t *cpy = codec_create_new_from_caps(codec_list_get_by_payload((gconstpointer)(uintptr_t) payload, NULL));
if (cpy)
codec_list_add(cpy, &codeclist);
else
ERROR("SFLphone: Couldn't find codec");
}
g_array_unref(order);
guint caps_size = codec_list_get_size();
for (guint i = 0; i < caps_size; i++) {
codec_t * current_cap = capabilities_get_nth(i);
// Check if this codec has already been enabled for this account
if (codec_list_get_by_payload((gconstpointer)(size_t)(current_cap->_payload), codeclist) == NULL) {
current_cap->is_active = FALSE;
codec_list_add(current_cap, &codeclist);
}
}
account->codecs = codeclist;
}
void sflphone_fill_call_list(void)
{
gchar **call_list = dbus_get_call_list();
for (gchar **callp = call_list; callp && *callp; ++callp) {
gchar *callID = *callp;
if (!calllist_get_call(current_calls_tab, callID)) {
callable_obj_t *call = create_new_call_from_details(*callp, dbus_get_call_details(*callp));
call->_zrtp_confirmed = FALSE;
calllist_add_call(current_calls_tab, call);
// add in treeview only if does not participate to a conference
gchar *confID = dbus_get_conference_id(call->_callID);
if(g_strcmp0(confID, "") == 0)
calltree_add_call(current_calls_tab, call, NULL);
}
}
g_strfreev(call_list);
}
void sflphone_fill_conference_list(void)
{
// TODO Fetch the active conferences at client startup
gchar **conferences = dbus_get_conference_list();
for (gchar **list = conferences; list && *list; list++) {
const gchar * const conf_id = *list;
GHashTable *conference_details = dbus_get_conference_details(conf_id);
conference_obj_t *conf = create_new_conference_from_details(conf_id, conference_details);
conferencelist_add(current_calls_tab, conf);
calltree_add_conference_to_current_calls(conf);
}
g_strfreev(conferences);
}
static void
create_callable_from_entry(gpointer data, gpointer user_data UNUSED)
{
GHashTable *entry = (GHashTable *) data;
callable_obj_t *history_call = create_history_entry_from_hashtable(entry);
/* Add it and update the GUI */
calllist_add_call_to_front(history_tab, history_call);
}
static void fill_treeview_with_calls(void)
{
guint n = calllist_get_size(history_tab);
for (guint i = 0; i < n; ++i) {
callable_obj_t *call = calllist_get_nth(history_tab, i);
if (call)
calltree_add_history_entry(call);
}
}
void sflphone_fill_history(void)
{
GPtrArray *entries = dbus_get_history();
if (entries)
g_ptr_array_foreach(entries, create_callable_from_entry, NULL);
fill_treeview_with_calls();
}
void
sflphone_srtp_sdes_on(callable_obj_t * c)
{
c->_srtp_state = SRTP_STATE_SDES_SUCCESS;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_srtp_sdes_off(callable_obj_t * c)
{
c->_srtp_state = SRTP_STATE_UNLOCKED;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_srtp_zrtp_on(callable_obj_t * c)
{
c->_srtp_state = SRTP_STATE_ZRTP_SAS_UNCONFIRMED;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_srtp_zrtp_off(callable_obj_t * c)
{
c->_srtp_state = SRTP_STATE_UNLOCKED;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_srtp_zrtp_show_sas(callable_obj_t * c, const gchar* sas, const gboolean verified)
{
c->_sas = g_strdup(sas);
c->_srtp_state = verified ? SRTP_STATE_ZRTP_SAS_CONFIRMED : SRTP_STATE_ZRTP_SAS_UNCONFIRMED;
calltree_update_call(current_calls_tab, c);
update_actions();
}
void
sflphone_request_go_clear(void)
{
callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
if (selectedCall)
dbus_request_go_clear(selectedCall);
}
void
sflphone_call_state_changed(callable_obj_t * c, const gchar * description, const guint code)
{
DEBUG("Call State changed %s", description);
if (c == NULL) {
ERROR("SFLphone: Error: callable obj is NULL in %s at %d", __FILE__, __LINE__);
return;
}
g_free(c->_state_code_description);
c->_state_code_description = g_strdup(description);
c->_state_code = code;
calltree_update_call(current_calls_tab, c);
update_actions();
}
|