actions.c 33.5 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
4
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
Emmanuel Milou's avatar
Emmanuel Milou committed
5
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
6 7
 *  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
8
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
9
 *  (at your option) any later version.
Emmanuel Milou's avatar
Emmanuel Milou committed
10
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
11 12 13 14
 *  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.
Emmanuel Milou's avatar
Emmanuel Milou committed
15
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
16 17 18
 *  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.
19 20 21 22 23 24 25 26 27 28 29
 *
 *  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.
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
30
 */
31

32
#include <glib/gi18n.h>
33
#include <gtk/gtk.h>
34 35 36 37
/* Backward compatibility for gtk < 2.22.0 */
#if GTK_CHECK_VERSION(2,22,0)
#include <gdk/gdkkeysyms-compat.h>
#else
38
#include <gdk/gdkkeysyms.h>
39
#endif
40 41

#include "str_utils.h"
42
#include <glib.h>
43
#include <stdlib.h>
44
#include <string.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
45 46 47
#include <sys/types.h>
#include <unistd.h>

48
#include <arpa/nameser.h>
49
#include <netinet/in.h>
50 51
#include <resolv.h>

52
#include <linux/if.h>
53 54 55 56
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>

57 58
#include "actions.h"
#include "dbus/dbus.h"
59
#include "logger.h"
60
#include "contacts/calltab.h"
61 62 63 64 65
#include "contacts/searchbar.h"
#include "contacts/addrbookfactory.h"
#include "icons/icon_factory.h"
#include "imwindow.h"
#include "statusicon.h"
66
#include "unused.h"
67
#include "widget/imwidget.h"
68
#include "sliders.h"
69

70
static GHashTable * ip2ip_profile;
71

72
void
73
sflphone_notify_voice_mail(const gchar* accountID , guint count)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
74
{
75
    // We want to notify only the current account; ie the first in the list
76 77
    gchar *id = g_strdup(accountID);
    const gchar * const current_id = account_list_get_current_id();
78

79
    DEBUG("sflphone_notify_voice_mail begin");
80

81
    if (g_ascii_strcasecmp(id, current_id) != 0 || account_list_get_size() == 0)
82 83
        return;

84
    // Set the number of voice messages for the current account
85 86
    current_account_set_message_number(count);
    account_t *current = account_list_get_current();
87

88
    // Update the voicemail tool button
89
    update_voicemail_status();
Emmanuel Milou's avatar
Emmanuel Milou committed
90

91
    if (current)
92
        notify_voice_mails(count, current);
Emmanuel Milou's avatar
Emmanuel Milou committed
93

94
    DEBUG("sflphone_notify_voice_mail end");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
95 96
}

97 98 99 100 101 102 103
/*
 * 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
 */

104
static gboolean is_direct_call(callable_obj_t * c)
105
{
106
    if (utf8_case_cmp(c->_accountID, "empty") == 0) {
107 108 109
        if (!g_str_has_prefix(c->_peer_number, "sip:")) {
            gchar * new_number = g_strconcat("sip:", c->_peer_number, NULL);
            g_free(c->_peer_number);
110 111
            c->_peer_number = new_number;
        }
112

113
        return TRUE;
Alexandre Savard's avatar
Alexandre Savard committed
114 115
    }

116 117
    return g_str_has_prefix(c->_peer_number, "sip:") ||
           g_str_has_prefix(c->_peer_number, "sips:");
118 119 120
}


121
void
122
status_bar_display_account()
123
{
124
    gchar* msg;
125

126
    statusbar_pop_message(__MSG_ACCOUNT_DEFAULT);
127

128 129
    account_t *acc = account_list_get_current();
    status_tray_icon_online(acc != NULL);
130 131

    if (acc) {
132 133
        msg = g_markup_printf_escaped("%s %s (%s)" ,
                                      _("Using account"),
134 135
                                      (gchar*) g_hash_table_lookup(acc->properties, ACCOUNT_ALIAS),
                                      (gchar*) g_hash_table_lookup(acc->properties, ACCOUNT_TYPE));
136
    } else {
137
        msg = g_markup_printf_escaped(_("No registered accounts"));
138
    }
139

140 141
    statusbar_push_message(msg, NULL,  __MSG_ACCOUNT_DEFAULT);
    g_free(msg);
142 143
}

Emmanuel Milou's avatar
Emmanuel Milou committed
144

145
void
146
sflphone_quit()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
147
{
Tristan Matthews's avatar
Tristan Matthews committed
148
    if (calllist_get_size(current_calls_tab) == 0 || main_window_ask_quit()) {
149 150
        dbus_unregister(getpid());
        dbus_clean();
Rafaël Carré's avatar
Cleanup  
Rafaël Carré committed
151
        account_list_free();
Tristan Matthews's avatar
Tristan Matthews committed
152 153 154 155 156 157
        calllist_clean(current_calls_tab);
        calllist_clean(contacts_tab);
        calllist_clean(history_tab);
        gtk_tree_store_clear(history_tab->store);
        gtk_tree_store_clear(current_calls_tab->store);
        gtk_tree_store_clear(contacts_tab->store);
158
        gtk_main_quit();
Emmanuel Milou's avatar
Emmanuel Milou committed
159
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
160 161
}

162
void
163
sflphone_hold(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
164
{
165
    c->_state = CALL_STATE_HOLD;
Tristan Matthews's avatar
Tristan Matthews committed
166
    calltree_update_call(current_calls_tab, c);
167
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
168 169
}

170
void
171
sflphone_ringing(callable_obj_t * c)
172
{
173
    c->_state = CALL_STATE_RINGING;
Tristan Matthews's avatar
Tristan Matthews committed
174
    calltree_update_call(current_calls_tab, c);
175
    update_actions();
176
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
177

178
void
179
sflphone_hung_up(callable_obj_t * c)
Emmanuel Milou's avatar
Emmanuel Milou committed
180
{
181
    DEBUG("SFLphone: Hung up");
182

Tristan Matthews's avatar
Tristan Matthews committed
183 184
    calllist_remove_call(current_calls_tab, c->_callID);
    calltree_remove_call(current_calls_tab, c);
185
    c->_state = CALL_STATE_DIALING;
186
    call_remove_all_errors(c);
187
    update_actions();
188

189 190 191
    if (c->_confID) {
        g_free(c->_confID);
        c->_confID = NULL;
192 193
    }

194
    // test whether the widget contains text, if not remove it
195 196
    if ((im_window_get_nb_tabs() > 1) && c->_im_widget && !(IM_WIDGET(c->_im_widget)->containText))
        im_window_remove_tab(c->_im_widget);
197
    else
198
        im_widget_update_state(IM_WIDGET(c->_im_widget), FALSE);
199

200
    status_tray_icon_blink(FALSE);
201

202
    statusbar_update_clock("");
203 204
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
205
/** Internal to actions: Fill account list */
206
void sflphone_fill_account_list(void)
207
{
208
    int count = current_account_get_message_number();
209

Rafaël Carré's avatar
Cleanup  
Rafaël Carré committed
210 211
    account_list_free();
    account_list_init();
212

213
    gchar **array = dbus_account_list();
214

215
    if (array) {
216
        for (gchar **accountID = array; accountID && *accountID; accountID++) {
217
            account_t * a = g_new0(account_t, 1);
218
            a->accountID = g_strdup(*accountID);
219
            a->credential_information = NULL;
220
            account_list_add(a);
Emmanuel Milou's avatar
Emmanuel Milou committed
221
        }
222

223
        g_strfreev(array);
224
    }
225

226
    for (unsigned i = 0; i < account_list_get_size(); i++) {
227 228 229
        account_t  * a = account_list_get_nth(i);

        if (a == NULL) {
230
            ERROR("SFLphone: Error: Could not find account %d in list", i);
231
            break;
232
        }
233

234 235
        GHashTable * details = (GHashTable *) dbus_get_account_details(a->accountID);

236 237
        if (details == NULL) {
            ERROR("SFLphone: Error: Could not fetch detais for account %s", a->accountID);
238
            break;
239
        }
240

241
        a->properties = details;
242 243

        /* Fill the actual array of credentials */
244
        dbus_get_credentials(a);
Emmanuel Milou's avatar
Emmanuel Milou committed
245

246
        gchar * status = g_hash_table_lookup(details, REGISTRATION_STATUS);
247

248
        if (g_strcmp0(status, "REGISTERED") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
249
            a->state = ACCOUNT_STATE_REGISTERED;
250
        else if (g_strcmp0(status, "UNREGISTERED") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
251
            a->state = ACCOUNT_STATE_UNREGISTERED;
252
        else if (g_strcmp0(status, "TRYING") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
253
            a->state = ACCOUNT_STATE_TRYING;
254
        else if (g_strcmp0(status, "ERROR") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
255
            a->state = ACCOUNT_STATE_ERROR;
256
        else if (g_strcmp0(status , "ERROR_AUTH") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
257
            a->state = ACCOUNT_STATE_ERROR_AUTH;
258
        else if (g_strcmp0(status , "ERROR_NETWORK") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
259
            a->state = ACCOUNT_STATE_ERROR_NETWORK;
260
        else if (g_strcmp0(status , "ERROR_HOST") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
261
            a->state = ACCOUNT_STATE_ERROR_HOST;
262
        else if (g_strcmp0(status , "ERROR_CONF_STUN") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
263
            a->state = ACCOUNT_STATE_ERROR_CONF_STUN;
264
        else if (g_strcmp0(status , "ERROR_EXIST_STUN") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
265
            a->state = ACCOUNT_STATE_ERROR_EXIST_STUN;
266
        else if (g_strcmp0(status, "READY") == 0)
267
            a->state = IP2IP_PROFILE_STATUS;
268
        else
Emmanuel Milou's avatar
Emmanuel Milou committed
269 270
            a->state = ACCOUNT_STATE_INVALID;

271 272
        gchar * code = g_hash_table_lookup(details, REGISTRATION_STATE_CODE);

273
        if (code != NULL)
274
            a->protocol_state_code = atoi(code);
275

276 277
        g_free(a->protocol_state_description);
        a->protocol_state_description = g_hash_table_lookup(details, REGISTRATION_STATE_DESCRIPTION);
Emmanuel Milou's avatar
Emmanuel Milou committed
278 279
    }

280
    // Set the current account message number
281
    current_account_set_message_number(count);
282

283
    sflphone_fill_codec_list();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
284 285
}

286
gboolean sflphone_init(GError **error)
287
{
288
    if (!dbus_connect(error) || !dbus_register(getpid(), "Gtk+ Client", error))
289
        return FALSE;
290

Rafaël Carré's avatar
Rafaël Carré committed
291
    abook_init();
292

293
    // Init icons factory
294
    init_icon_factory();
295

Tristan Matthews's avatar
Tristan Matthews committed
296 297 298
    current_calls_tab = calltab_init(FALSE, CURRENT_CALLS);
    contacts_tab = calltab_init(TRUE, CONTACTS);
    history_tab = calltab_init(TRUE, HISTORY);
299

300 301
    account_list_init();
    codec_capabilities_load();
Tristan Matthews's avatar
Tristan Matthews committed
302
    conferencelist_init(current_calls_tab);
303

304
    // Fetch the configured accounts
305
    sflphone_fill_account_list();
306

307 308
    // Fetch the ip2ip profile
    sflphone_fill_ip2ip_profile();
309

310
    // Fetch the conference list
311
    sflphone_fill_conference_list();
312

313
    return TRUE;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
314 315
}

316
void sflphone_fill_ip2ip_profile(void)
317 318 319 320
{
    ip2ip_profile = (GHashTable *) dbus_get_ip2_ip_details();
}

321
GHashTable *sflphone_get_ip2ip_properties(void)
322
{
323
    return ip2ip_profile;
324 325
}

326
void
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
327
sflphone_hang_up()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
328
{
Tristan Matthews's avatar
Tristan Matthews committed
329 330
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
331

332
    DEBUG("SFLphone: Hang up");
333

334
    if (selectedConf) {
335 336 337
        im_widget_update_state(IM_WIDGET(selectedConf->_im_widget), FALSE);
        dbus_hang_up_conference(selectedConf);
    } else if (selectedCall) {
338
        switch (selectedCall->_state) {
Emmanuel Milou's avatar
Emmanuel Milou committed
339
            case CALL_STATE_DIALING:
340
                dbus_hang_up(selectedCall);
Emmanuel Milou's avatar
Emmanuel Milou committed
341 342
                break;
            case CALL_STATE_RINGING:
343 344
                dbus_hang_up(selectedCall);
                call_remove_all_errors(selectedCall);
345 346
                selectedCall->_state = CALL_STATE_DIALING;
                //selectedCall->_stop = 0;
Emmanuel Milou's avatar
Emmanuel Milou committed
347 348 349 350
                break;
            case CALL_STATE_CURRENT:
            case CALL_STATE_HOLD:
            case CALL_STATE_BUSY:
351
            case CALL_STATE_RECORD:
352 353
                dbus_hang_up(selectedCall);
                call_remove_all_errors(selectedCall);
354
                selectedCall->_state = CALL_STATE_DIALING;
355
                time(&selectedCall->_time_stop);
356

357
                im_widget_update_state(IM_WIDGET(selectedCall->_im_widget), FALSE);
358

Emmanuel Milou's avatar
Emmanuel Milou committed
359 360
                break;
            case CALL_STATE_FAILURE:
361 362
                dbus_hang_up(selectedCall);
                call_remove_all_errors(selectedCall);
363
                selectedCall->_state = CALL_STATE_DIALING;
Emmanuel Milou's avatar
Emmanuel Milou committed
364 365
                break;
            case CALL_STATE_INCOMING:
366 367
                dbus_refuse(selectedCall);
                call_remove_all_errors(selectedCall);
368
                selectedCall->_state = CALL_STATE_DIALING;
369
                DEBUG("from sflphone_hang_up : ");
Emmanuel Milou's avatar
Emmanuel Milou committed
370
                break;
371
            case CALL_STATE_TRANSFER:
372 373 374
                dbus_hang_up(selectedCall);
                call_remove_all_errors(selectedCall);
                time(&selectedCall->_time_stop);
Emmanuel Milou's avatar
Emmanuel Milou committed
375 376
                break;
            default:
377
                WARN("Should not happen in sflphone_hang_up()!");
Emmanuel Milou's avatar
Emmanuel Milou committed
378 379
                break;
        }
380 381
    }

Tristan Matthews's avatar
Tristan Matthews committed
382
    calltree_update_call(history_tab, selectedCall);
383

384
    statusbar_update_clock("");
385 386 387 388 389

    // Allow screen saver to start
    guint nbcall = calllist_get_size(current_calls_tab);
    if(nbcall == 1)
        dbus_screensaver_uninhibit();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
390 391
}

392
void
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
393 394
sflphone_pick_up()
{
Tristan Matthews's avatar
Tristan Matthews committed
395
    callable_obj_t *selectedCall = calltab_get_selected_call(active_calltree_tab);
396

397 398 399 400 401
    // Disable screensaver if the list is empty call
    guint nbcall = calllist_get_size(current_calls_tab);
    if(nbcall == 0)
        dbus_screensaver_inhibit();

402 403 404 405
    if (!selectedCall) {
        sflphone_new_call();
        return;
    }
406

407 408
    switch (selectedCall->_state) {
        case CALL_STATE_DIALING:
409
            sflphone_place_call(selectedCall);
410

411 412
            // if instant messaging window is visible, create new tab (deleted automatically if not used)
            if (im_window_is_visible())
413 414
                if (!selectedCall->_im_widget)
                    selectedCall->_im_widget = im_widget_display(selectedCall->_callID);
415

416 417
            break;
        case CALL_STATE_INCOMING:
418
            selectedCall->_history_state = g_strdup(INCOMING_STRING);
Tristan Matthews's avatar
Tristan Matthews committed
419
            calltree_update_call(history_tab, selectedCall);
420

421
            // if instant messaging window is visible, create new tab (deleted automatically if not used)
422 423 424
            if (im_window_is_visible())
                if (!selectedCall->_im_widget)
                    selectedCall->_im_widget = im_widget_display(selectedCall->_callID);
425

426
            dbus_accept(selectedCall);
427
            break;
428
        case CALL_STATE_TRANSFER:
429 430
            dbus_transfer(selectedCall);
            time(&selectedCall->_time_stop);
Tristan Matthews's avatar
Tristan Matthews committed
431 432
            calltree_remove_call(current_calls_tab, selectedCall);
            calllist_remove_call(current_calls_tab, selectedCall->_callID);
433 434 435 436 437 438 439 440
            break;
        case CALL_STATE_CURRENT:
        case CALL_STATE_HOLD:
        case CALL_STATE_RECORD:
        case CALL_STATE_RINGING:
            sflphone_new_call();
            break;
        default:
441
            WARN("Should not happen in sflphone_pick_up()!");
442
            break;
443
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
444 445
}

446
void
447
sflphone_on_hold()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
448
{
Tristan Matthews's avatar
Tristan Matthews committed
449 450
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
451

452 453
    if (selectedCall) {
        switch (selectedCall->_state) {
Emmanuel Milou's avatar
Emmanuel Milou committed
454 455
            case CALL_STATE_CURRENT:
            case CALL_STATE_RECORD:
456
                dbus_hold(selectedCall);
Emmanuel Milou's avatar
Emmanuel Milou committed
457 458
                break;
            default:
459
                WARN("Should not happen in sflphone_on_hold!");
Emmanuel Milou's avatar
Emmanuel Milou committed
460 461
                break;
        }
462
    } else if (selectedConf)
463
        dbus_hold_conference(selectedConf);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
464 465
}

466
void
467
sflphone_off_hold()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
468
{
469
    DEBUG("sflphone_off_hold");
Tristan Matthews's avatar
Tristan Matthews committed
470 471
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
472

473 474
    if (selectedCall) {
        switch (selectedCall->_state) {
Emmanuel Milou's avatar
Emmanuel Milou committed
475
            case CALL_STATE_HOLD:
476
                dbus_unhold(selectedCall);
Emmanuel Milou's avatar
Emmanuel Milou committed
477 478
                break;
            default:
479
                WARN("Should not happen in sflphone_off_hold ()!");
Emmanuel Milou's avatar
Emmanuel Milou committed
480 481
                break;
        }
482
    } else if (selectedConf)
483
        dbus_unhold_conference(selectedConf);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
484 485 486
}


487
void
488
sflphone_fail(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
489
{
490
    c->_state = CALL_STATE_FAILURE;
Tristan Matthews's avatar
Tristan Matthews committed
491
    calltree_update_call(current_calls_tab, c);
492
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
493 494
}

495
void
496
sflphone_busy(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
497
{
498
    c->_state = CALL_STATE_BUSY;
Tristan Matthews's avatar
Tristan Matthews committed
499
    calltree_update_call(current_calls_tab, c);
500
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
501 502
}

503
void
504
sflphone_current(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
505
{
506
    if (c->_state != CALL_STATE_HOLD)
507
        time(&c->_time_start);
508

509
    c->_state = CALL_STATE_CURRENT;
Tristan Matthews's avatar
Tristan Matthews committed
510
    calltree_update_call(current_calls_tab, c);
511
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
512 513
}

514
void
515
sflphone_record(callable_obj_t * c)
alexandresavard's avatar
alexandresavard committed
516
{
517
    if (c->_state != CALL_STATE_HOLD)
518
        time(&c->_time_start);
519

520
    c->_state = CALL_STATE_RECORD;
Tristan Matthews's avatar
Tristan Matthews committed
521
    calltree_update_call(current_calls_tab, c);
522
    update_actions();
alexandresavard's avatar
alexandresavard committed
523 524
}

525
void
526
sflphone_set_transfer()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
527
{
Tristan Matthews's avatar
Tristan Matthews committed
528
    callable_obj_t * c = calltab_get_selected_call(current_calls_tab);
529 530

    if (c) {
531
        c->_state = CALL_STATE_TRANSFER;
Tristan Matthews's avatar
Tristan Matthews committed
532
        g_free(c->_trsft_to);
533
        c->_trsft_to = g_strdup("");
Tristan Matthews's avatar
Tristan Matthews committed
534
        calltree_update_call(current_calls_tab, c);
Emmanuel Milou's avatar
Emmanuel Milou committed
535
    }
536

537
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
538 539
}

540
void
541
sflphone_unset_transfer()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
542
{
Tristan Matthews's avatar
Tristan Matthews committed
543
    callable_obj_t * c = calltab_get_selected_call(current_calls_tab);
544 545

    if (c) {
546
        c->_state = CALL_STATE_CURRENT;
Tristan Matthews's avatar
Tristan Matthews committed
547
        g_free(c->_trsft_to);
548
        c->_trsft_to = g_strdup("");
Tristan Matthews's avatar
Tristan Matthews committed
549
        calltree_update_call(current_calls_tab, c);
Emmanuel Milou's avatar
Emmanuel Milou committed
550
    }
551

552
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
553
}
Emmanuel Milou's avatar
Emmanuel Milou committed
554

555
void
556
sflphone_display_transfer_status(const gchar* message)
557
{
558
    statusbar_push_message(message , NULL, __MSG_ACCOUNT_DEFAULT);
559 560
}

561
void
562
sflphone_incoming_call(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
563
{
564
    c->_history_state = g_strdup(MISSED_STRING);
Tristan Matthews's avatar
Tristan Matthews committed
565 566
    calllist_add_call(current_calls_tab, c);
    calltree_add_call(current_calls_tab, c, NULL);
567

568
    update_actions();
Tristan Matthews's avatar
Tristan Matthews committed
569
    calltree_display(current_calls_tab);
570 571

    // Change the status bar if we are dealing with a direct SIP call
572
    if (is_direct_call(c)) {
573 574 575 576
        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);
577
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
578
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
579

580
static void
581
process_dialing(callable_obj_t *c, guint keyval, gchar *key)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
582
{
Emmanuel Milou's avatar
Emmanuel Milou committed
583
    // We stop the tone
584
    if (!*c->_peer_number && c->_state != CALL_STATE_TRANSFER)
585
        dbus_start_tone(FALSE, 0);
586

587
    switch (keyval) {
588 589
        case GDK_Return:
        case GDK_KP_Enter:
590
            sflphone_place_call(c);
Emmanuel Milou's avatar
Emmanuel Milou committed
591
            break;
592
        case GDK_Escape:
593
            sflphone_hang_up();
Emmanuel Milou's avatar
Emmanuel Milou committed
594
            break;
595
        case GDK_BackSpace: {
596 597
            gchar *num = (c->_state == CALL_STATE_TRANSFER) ? c->_trsft_to : c->_peer_number;
            size_t len = strlen(num);
598

599 600 601
            if (len) {
                len--; // delete one character
                num[len] = '\0';
Tristan Matthews's avatar
Tristan Matthews committed
602
                calltree_update_call(current_calls_tab, c);
603

604
                /* If number is now empty, hang up immediately */
605
                if (c->_state != CALL_STATE_TRANSFER && len == 0)
606
                    dbus_hang_up(c);
Emmanuel Milou's avatar
Emmanuel Milou committed
607
            }
608

609
            break;
610
        }
611 612 613 614 615
        case GDK_Tab:
        case GDK_Alt_L:
        case GDK_Control_L:
        case GDK_Super_L:
        case GDK_Caps_Lock:
Emmanuel Milou's avatar
Emmanuel Milou committed
616 617
            break;
        default:
618

619
            if (keyval < 127 /* ascii */ ||
620
                    (keyval >= GDK_Mode_switch && keyval <= GDK_KP_9) /* num keypad */) {
Emmanuel Milou's avatar
Emmanuel Milou committed
621

622
                if (c->_state == CALL_STATE_TRANSFER) {
623 624
                    gchar *new_trsft = g_strconcat(c->_trsft_to, key, NULL);
                    g_free(c->_trsft_to);
Tristan Matthews's avatar
Tristan Matthews committed
625
                    c->_trsft_to = new_trsft;
626
                } else {
627 628 629
                    dbus_play_dtmf(key);
                    gchar *new_peer_number = g_strconcat(c->_peer_number, key, NULL);
                    g_free(c->_peer_number);
Tristan Matthews's avatar
Tristan Matthews committed
630
                    c->_peer_number = new_peer_number;
Emmanuel Milou's avatar
Emmanuel Milou committed
631
                }
632

Tristan Matthews's avatar
Tristan Matthews committed
633
                calltree_update_call(current_calls_tab, c);
Emmanuel Milou's avatar
Emmanuel Milou committed
634
            }
635

Emmanuel Milou's avatar
Emmanuel Milou committed
636 637
            break;
    }
638 639
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
640

641
callable_obj_t *
areversat's avatar
areversat committed