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 "config/accountlistconfigdialog.h"
61
#include "contacts/calltab.h"
62 63 64 65 66
#include "contacts/searchbar.h"
#include "contacts/addrbookfactory.h"
#include "icons/icon_factory.h"
#include "imwindow.h"
#include "statusicon.h"
67
#include "unused.h"
68
#include "widget/imwidget.h"
69
#include "sliders.h"
70

71
static GHashTable * ip2ip_profile;
72

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

80
    DEBUG("sflphone_notify_voice_mail begin");
81

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

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

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

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

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

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

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

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

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


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

127
    statusbar_pop_message(__MSG_ACCOUNT_DEFAULT);
128

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

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

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

Emmanuel Milou's avatar
Emmanuel Milou committed
145

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

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

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

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

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

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

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

201
    status_tray_icon_blink(FALSE);
202

203
    statusbar_update_clock("");
204 205
}

206
void sflphone_fill_account_list(void)
207
{
Rafaël Carré's avatar
Cleanup  
Rafaël Carré committed
208
    account_list_init();
209

210
    gchar **array = dbus_account_list();
211

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

220
        g_strfreev(array);
221
    }
222

223
    for (unsigned i = 0; i < account_list_get_size(); i++) {
224
        account_t *a = account_list_get_nth(i);
225 226

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

231 232
        GHashTable * details = (GHashTable *) dbus_get_account_details(a->accountID);

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

238
        a->properties = details;
239 240

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

243
        gchar * status = g_hash_table_lookup(details, REGISTRATION_STATUS);
244

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

268 269
        gchar * code = g_hash_table_lookup(details, REGISTRATION_STATE_CODE);

270
        if (code != NULL)
271
            a->protocol_state_code = atoi(code);
272

273 274
        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
275 276
    }

277
    // Set the current account message number
278
    current_account_set_message_number(current_account_get_message_number());
279

280
    sflphone_fill_codec_list();
281
    account_store_fill();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
282 283
}

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

Rafaël Carré's avatar
Rafaël Carré committed
289
    abook_init();
290

291
    // Init icons factory
292
    init_icon_factory();
293

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

298
    codec_capabilities_load();
Tristan Matthews's avatar
Tristan Matthews committed
299
    conferencelist_init(current_calls_tab);
300

301
    // Fetch the configured accounts
302
    sflphone_fill_account_list();
303

304 305
    // Fetch the ip2ip profile
    sflphone_fill_ip2ip_profile();
306

307
    // Fetch the conference list
308
    sflphone_fill_conference_list();
309

310
    return TRUE;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
311 312
}

313
void sflphone_fill_ip2ip_profile(void)
314 315 316 317
{
    ip2ip_profile = (GHashTable *) dbus_get_ip2_ip_details();
}

318
GHashTable *sflphone_get_ip2ip_properties(void)
319
{
320
    return ip2ip_profile;
321 322
}

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

329
    DEBUG("SFLphone: Hang up");
330

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

354
                im_widget_update_state(IM_WIDGET(selectedCall->_im_widget), FALSE);
355

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

Tristan Matthews's avatar
Tristan Matthews committed
379
    calltree_update_call(history_tab, selectedCall);
380

381
    statusbar_update_clock("");
382 383 384 385 386

    // 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
387 388
}

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

394 395 396 397 398
    // Disable screensaver if the list is empty call
    guint nbcall = calllist_get_size(current_calls_tab);
    if(nbcall == 0)
        dbus_screensaver_inhibit();

399 400 401 402
    if (!selectedCall) {
        sflphone_new_call();
        return;
    }
403

404 405
    switch (selectedCall->_state) {
        case CALL_STATE_DIALING:
406
            sflphone_place_call(selectedCall);
407

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

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

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

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

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

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

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

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


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

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

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

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

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

517
    c->_state = CALL_STATE_RECORD;
Tristan Matthews's avatar
Tristan Matthews committed
518
    calltree_update_call(current_calls_tab, c);
519
    update_actions();
alexandresavard's avatar
alexandresavard committed
520 521
}

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

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

534
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
535 536
}

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

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

549
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
550
}
Emmanuel Milou's avatar
Emmanuel Milou committed
551

552
void
553
sflphone_display_transfer_status(const gchar* message)
554
{
555
    statusbar_push_message(message , NULL, __MSG_ACCOUNT_DEFAULT);
556 557
}

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

565
    update_actions();
Tristan Matthews's avatar
Tristan Matthews committed
566
    calltree_display(current_calls_tab);
567 568

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

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

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

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

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

606
            break;
607
        }
608 609 610 611 612
        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
613 614
            break;
        default:
615

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

619
                if (c->_state == CALL_STATE_TRANSFER) {
620 621
                    gchar *new_trsft = g_strconcat(c->_trsft_to, key, NULL);
                    g_free(c->_trsft_to);
Tristan Matthews's avatar
Tristan Matthews committed
622
                    c->_trsft_to = new_trsft;
623
                } else {
624 625 626
                    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
627
                    c->_peer_number = new_peer_number;
Emmanuel Milou's avatar
Emmanuel Milou committed
628
                }
629

Tristan Matthews's avatar
Tristan Matthews committed
630
                calltree_update_call(current_calls_tab, c);
Emmanuel Milou's avatar
Emmanuel Milou committed
631
            }
632

Emmanuel Milou's avatar
Emmanuel Milou committed
633 634
            break;
    }
635 636
}

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

638
callable_obj_t *
areversat's avatar
areversat committed
639
sflphone_new_call()
Pierre-Luc Beaudoin's avatar