actions.c 35.4 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 <gtk/gtk.h>
33 34 35 36
/* Backward compatibility for gtk < 2.22.0 */
#if GTK_CHECK_VERSION(2,22,0)
#include <gdk/gdkkeysyms-compat.h>
#else
37
#include <gdk/gdkkeysyms.h>
38
#endif
39 40
#include <glib/gprintf.h>
#include <stdlib.h>
41
#include <string.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
42 43 44
#include <sys/types.h>
#include <unistd.h>

45
#include <arpa/nameser.h>
46
#include <netinet/in.h>
47 48
#include <resolv.h>

49
#include <linux/if.h>
50 51 52 53
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>

54 55
#include "actions.h"
#include "dbus/dbus.h"
56
#include "logger.h"
57
#include "contacts/calltab.h"
58 59 60 61 62
#include "contacts/searchbar.h"
#include "contacts/addrbookfactory.h"
#include "icons/icon_factory.h"
#include "imwindow.h"
#include "statusicon.h"
63
#include "unused.h"
64 65
#include "widget/imwidget.h"

66

67
static GHashTable * ip2ip_profile;
68

69
static gchar ** sflphone_order_history_hash_table(GHashTable *result)
70 71
{
    GHashTableIter iter;
72 73
    gint size = 0;
    gchar **ordered_list = NULL;
74

75
    g_assert(result);
76 77

    while (g_hash_table_size(result)) {
78 79
        gpointer key, value;
        gpointer key_to_min = NULL;
80 81

        // find lowest timestamp in map
82
        g_hash_table_iter_init(&iter, result);
83

84
        gint min_timestamp = G_MAXINT;
85 86 87 88

        while (g_hash_table_iter_next(&iter, &key, &value))  {
            gint timestamp = atoi((gchar*) key);

89
            if (timestamp < min_timestamp) {
90 91 92 93 94
                min_timestamp = timestamp;
                key_to_min = key;
            }
        }

Tristan Matthews's avatar
Tristan Matthews committed
95 96
        if (g_hash_table_lookup_extended(result, key_to_min, &key, &value)) {
            GSList *llist = (GSList *)value;
97

Tristan Matthews's avatar
Tristan Matthews committed
98
            while (llist) {
99
                ordered_list = (gchar **) g_realloc(ordered_list, (size + 1) * sizeof(gchar *));
Tristan Matthews's avatar
Tristan Matthews committed
100 101 102 103
                *(ordered_list + size) = g_strdup((gchar *)llist->data);
                size++;
                llist = g_slist_next(llist);
            }
104

Tristan Matthews's avatar
Tristan Matthews committed
105
            g_hash_table_remove(result, key_to_min);
106 107 108
        }
    }

109 110
    ordered_list = (gchar **) g_realloc(ordered_list, (size + 1) * sizeof(gchar *));
    ordered_list[size] = NULL;
111

112
    return ordered_list;
113 114
}

115
void
116
sflphone_notify_voice_mail(const gchar* accountID , guint count)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
117
{
118
    // We want to notify only the current account; ie the first in the list
119 120
    gchar *id = g_strdup(accountID);
    const gchar * const current_id = account_list_get_current_id();
121

122
    DEBUG("sflphone_notify_voice_mail begin");
123

124
    if (g_ascii_strcasecmp(id, current_id) != 0 || account_list_get_size() == 0)
125 126
        return;

127
    // Set the number of voice messages for the current account
128 129
    current_account_set_message_number(count);
    account_t *current = account_list_get_current();
130

131
    // Update the voicemail tool button
132
    update_voicemail_status();
Emmanuel Milou's avatar
Emmanuel Milou committed
133

134
    if (current)
135
        notify_voice_mails(count, current);
Emmanuel Milou's avatar
Emmanuel Milou committed
136

137
    DEBUG("sflphone_notify_voice_mail end");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
138 139
}

140 141 142 143 144 145 146
/*
 * 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
 */

147
static gboolean _is_direct_call(callable_obj_t * c)
148
{
149 150 151 152
    if (g_strcasecmp(c->_accountID, "empty") == 0) {
        if (!g_str_has_prefix(c->_peer_number, "sip:")) {
            gchar * new_number = g_strconcat("sip:", c->_peer_number, NULL);
            g_free(c->_peer_number);
153 154
            c->_peer_number = new_number;
        }
155

156
        return TRUE;
Alexandre Savard's avatar
Alexandre Savard committed
157 158
    }

159 160
    return g_str_has_prefix(c->_peer_number, "sip:") ||
           g_str_has_prefix(c->_peer_number, "sips:");
161 162 163
}


164
void
165
status_bar_display_account()
166
{
167
    gchar* msg;
168

169
    statusbar_pop_message(__MSG_ACCOUNT_DEFAULT);
170

171 172
    account_t *acc = account_list_get_current();
    status_tray_icon_online(acc != NULL);
173 174

    if (acc) {
175 176 177 178
        msg = g_markup_printf_escaped("%s %s (%s)" ,
                                      _("Using account"),
                                      (gchar*) g_hash_table_lookup(acc->properties , ACCOUNT_ALIAS),
                                      (gchar*) g_hash_table_lookup(acc->properties , ACCOUNT_TYPE));
179
    } else {
180
        msg = g_markup_printf_escaped(_("No registered accounts"));
181
    }
182

183 184
    statusbar_push_message(msg, NULL,  __MSG_ACCOUNT_DEFAULT);
    g_free(msg);
185 186
}

Emmanuel Milou's avatar
Emmanuel Milou committed
187

188
void
189
sflphone_quit()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
190
{
Tristan Matthews's avatar
Tristan Matthews committed
191
    if (calllist_get_size(current_calls_tab) == 0 || main_window_ask_quit()) {
192
        // Save the history
193
        sflphone_save_history();
194

195 196
        dbus_unregister(getpid());
        dbus_clean();
Rafaël Carré's avatar
Cleanup  
Rafaël Carré committed
197
        account_list_free();
Tristan Matthews's avatar
Tristan Matthews committed
198 199 200 201 202 203
        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);
204
        gtk_main_quit();
Emmanuel Milou's avatar
Emmanuel Milou committed
205
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
206 207
}

208
void
209
sflphone_hold(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
210
{
211
    c->_state = CALL_STATE_HOLD;
Tristan Matthews's avatar
Tristan Matthews committed
212
    calltree_update_call(current_calls_tab, c);
213
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
214 215
}

216
void
217
sflphone_ringing(callable_obj_t * c)
218
{
219
    c->_state = CALL_STATE_RINGING;
Tristan Matthews's avatar
Tristan Matthews committed
220
    calltree_update_call(current_calls_tab, c);
221
    update_actions();
222
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
223

224
void
225
sflphone_hung_up(callable_obj_t * c)
Emmanuel Milou's avatar
Emmanuel Milou committed
226
{
227
    DEBUG("SFLphone: Hung up");
228

Tristan Matthews's avatar
Tristan Matthews committed
229 230
    calllist_remove_call(current_calls_tab, c->_callID);
    calltree_remove_call(current_calls_tab, c);
231
    c->_state = CALL_STATE_DIALING;
232
    call_remove_all_errors(c);
233
    update_actions();
234

235 236 237
    if (c->_confID) {
        g_free(c->_confID);
        c->_confID = NULL;
238 239
    }

240
    // test wether the widget contain text, if not remove it
241 242
    if ((im_window_get_nb_tabs() > 1) && c->_im_widget && !(IM_WIDGET(c->_im_widget)->containText))
        im_window_remove_tab(c->_im_widget);
243
    else
244
        im_widget_update_state(IM_WIDGET(c->_im_widget), FALSE);
245

246
    status_tray_icon_blink(FALSE);
247

248
    statusbar_update_clock("");
249 250
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
251
/** Internal to actions: Fill account list */
252
void sflphone_fill_account_list(void)
253
{
254
    int count = current_account_get_message_number();
255

Rafaël Carré's avatar
Cleanup  
Rafaël Carré committed
256 257
    account_list_free();
    account_list_init();
258

259
    gchar **array = dbus_account_list();
260

261
    if (array) {
262
        for (gchar **accountID = array; accountID && *accountID; accountID++) {
263 264
            account_t * a = g_new0(account_t,1);
            a->accountID = g_strdup(*accountID);
265
            a->credential_information = NULL;
266
            account_list_add(a);
Emmanuel Milou's avatar
Emmanuel Milou committed
267
        }
268

269
        g_strfreev(array);
270
    }
271

272
    for (unsigned i = 0; i < account_list_get_size(); i++) {
273 274 275
        account_t  * a = account_list_get_nth(i);

        if (a == NULL) {
276
            ERROR("SFLphone: Error: Could not find account %d in list", i);
277
            break;
278
        }
279

280 281
        GHashTable * details = (GHashTable *) dbus_get_account_details(a->accountID);

282 283
        if (details == NULL) {
            ERROR("SFLphone: Error: Could not fetch detais for account %s", a->accountID);
284
            break;
285
        }
286

287
        a->properties = details;
288 289

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

292
        gchar * status = g_hash_table_lookup(details, REGISTRATION_STATUS);
293

294
        if (g_strcmp0(status, "REGISTERED") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
295
            a->state = ACCOUNT_STATE_REGISTERED;
296
        else if (g_strcmp0(status, "UNREGISTERED") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
297
            a->state = ACCOUNT_STATE_UNREGISTERED;
298
        else if (g_strcmp0(status, "TRYING") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
299
            a->state = ACCOUNT_STATE_TRYING;
300
        else if (g_strcmp0(status, "ERROR") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
301
            a->state = ACCOUNT_STATE_ERROR;
302
        else if (g_strcmp0(status , "ERROR_AUTH") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
303
            a->state = ACCOUNT_STATE_ERROR_AUTH;
304
        else if (g_strcmp0(status , "ERROR_NETWORK") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
305
            a->state = ACCOUNT_STATE_ERROR_NETWORK;
306
        else if (g_strcmp0(status , "ERROR_HOST") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
307
            a->state = ACCOUNT_STATE_ERROR_HOST;
308
        else if (g_strcmp0(status , "ERROR_CONF_STUN") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
309
            a->state = ACCOUNT_STATE_ERROR_CONF_STUN;
310
        else if (g_strcmp0(status , "ERROR_EXIST_STUN") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
311
            a->state = ACCOUNT_STATE_ERROR_EXIST_STUN;
312
        else if (g_strcmp0(status, "READY") == 0)
313
            a->state = IP2IP_PROFILE_STATUS;
314
        else
Emmanuel Milou's avatar
Emmanuel Milou committed
315 316
            a->state = ACCOUNT_STATE_INVALID;

317 318
        gchar * code = g_hash_table_lookup(details, REGISTRATION_STATE_CODE);

319
        if (code != NULL)
320
            a->protocol_state_code = atoi(code);
321

322 323
        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
324 325
    }

326
    // Set the current account message number
327
    current_account_set_message_number(count);
328

329
    sflphone_fill_codec_list();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
330 331
}

332
gboolean sflphone_init(GError **error)
333
{
334
    if (!dbus_connect(error) || !dbus_register(getpid(), "Gtk+ Client", error))
335
        return FALSE;
336

Rafaël Carré's avatar
Rafaël Carré committed
337
    abook_init();
338

339
    // Init icons factory
340
    init_icon_factory();
341

Tristan Matthews's avatar
Tristan Matthews committed
342 343 344
    current_calls_tab = calltab_init(FALSE, CURRENT_CALLS);
    contacts_tab = calltab_init(TRUE, CONTACTS);
    history_tab = calltab_init(TRUE, HISTORY);
345

346 347
    account_list_init();
    codec_capabilities_load();
Tristan Matthews's avatar
Tristan Matthews committed
348
    conferencelist_init(current_calls_tab);
349

350
    // Fetch the configured accounts
351
    sflphone_fill_account_list();
352

353 354
    // Fetch the ip2ip profile
    sflphone_fill_ip2ip_profile();
355

356
    // Fetch the conference list
357
    sflphone_fill_conference_list();
358

359
    return TRUE;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
360 361
}

362
void sflphone_fill_ip2ip_profile(void)
363 364 365 366
{
    ip2ip_profile = (GHashTable *) dbus_get_ip2_ip_details();
}

367
GHashTable *sflphone_get_ip2ip_properties(void)
368
{
369
    return ip2ip_profile;
370 371
}

372
void
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
373
sflphone_hang_up()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
374
{
Tristan Matthews's avatar
Tristan Matthews committed
375 376
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
377

378
    DEBUG("SFLphone: Hang up");
379

380
    if (selectedConf) {
381 382 383
        im_widget_update_state(IM_WIDGET(selectedConf->_im_widget), FALSE);
        dbus_hang_up_conference(selectedConf);
    } else if (selectedCall) {
384
        switch (selectedCall->_state) {
Emmanuel Milou's avatar
Emmanuel Milou committed
385
            case CALL_STATE_DIALING:
386
                dbus_hang_up(selectedCall);
Emmanuel Milou's avatar
Emmanuel Milou committed
387 388
                break;
            case CALL_STATE_RINGING:
389 390
                dbus_hang_up(selectedCall);
                call_remove_all_errors(selectedCall);
391 392
                selectedCall->_state = CALL_STATE_DIALING;
                //selectedCall->_stop = 0;
Emmanuel Milou's avatar
Emmanuel Milou committed
393 394 395 396
                break;
            case CALL_STATE_CURRENT:
            case CALL_STATE_HOLD:
            case CALL_STATE_BUSY:
397
            case CALL_STATE_RECORD:
398 399
                dbus_hang_up(selectedCall);
                call_remove_all_errors(selectedCall);
400
                selectedCall->_state = CALL_STATE_DIALING;
401
                time(&selectedCall->_time_stop);
402

403
                im_widget_update_state(IM_WIDGET(selectedCall->_im_widget), FALSE);
404

Emmanuel Milou's avatar
Emmanuel Milou committed
405 406
                break;
            case CALL_STATE_FAILURE:
407 408
                dbus_hang_up(selectedCall);
                call_remove_all_errors(selectedCall);
409
                selectedCall->_state = CALL_STATE_DIALING;
Emmanuel Milou's avatar
Emmanuel Milou committed
410 411
                break;
            case CALL_STATE_INCOMING:
412 413
                dbus_refuse(selectedCall);
                call_remove_all_errors(selectedCall);
414
                selectedCall->_state = CALL_STATE_DIALING;
415
                DEBUG("from sflphone_hang_up : ");
Emmanuel Milou's avatar
Emmanuel Milou committed
416
                break;
417
            case CALL_STATE_TRANSFER:
418 419 420
                dbus_hang_up(selectedCall);
                call_remove_all_errors(selectedCall);
                time(&selectedCall->_time_stop);
Emmanuel Milou's avatar
Emmanuel Milou committed
421 422
                break;
            default:
423
                WARN("Should not happen in sflphone_hang_up()!");
Emmanuel Milou's avatar
Emmanuel Milou committed
424 425
                break;
        }
426 427
    }

Tristan Matthews's avatar
Tristan Matthews committed
428
    calltree_update_call(history_tab, selectedCall);
429

430
    statusbar_update_clock("");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
431 432
}

433
void
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
434 435
sflphone_pick_up()
{
Tristan Matthews's avatar
Tristan Matthews committed
436
    callable_obj_t *selectedCall = calltab_get_selected_call(active_calltree_tab);
437

438 439 440 441
    if (!selectedCall) {
        sflphone_new_call();
        return;
    }
442

443 444
    switch (selectedCall->_state) {
        case CALL_STATE_DIALING:
445
            sflphone_place_call(selectedCall);
446

447 448
            // if instant messaging window is visible, create new tab (deleted automatically if not used)
            if (im_window_is_visible())
449 450
                if (!selectedCall->_im_widget)
                    selectedCall->_im_widget = im_widget_display(selectedCall->_callID);
451

452 453 454
            break;
        case CALL_STATE_INCOMING:
            selectedCall->_history_state = INCOMING;
Tristan Matthews's avatar
Tristan Matthews committed
455
            calltree_update_call(history_tab, selectedCall);
456

457
            // if instant messaging window is visible, create new tab (deleted automatically if not used)
458 459 460
            if (im_window_is_visible())
                if (!selectedCall->_im_widget)
                    selectedCall->_im_widget = im_widget_display(selectedCall->_callID);
461

462
            dbus_accept(selectedCall);
463
            break;
464
        case CALL_STATE_TRANSFER:
465 466
            dbus_transfer(selectedCall);
            time(&selectedCall->_time_stop);
Tristan Matthews's avatar
Tristan Matthews committed
467 468
            calltree_remove_call(current_calls_tab, selectedCall);
            calllist_remove_call(current_calls_tab, selectedCall->_callID);
469 470 471 472 473 474 475 476
            break;
        case CALL_STATE_CURRENT:
        case CALL_STATE_HOLD:
        case CALL_STATE_RECORD:
        case CALL_STATE_RINGING:
            sflphone_new_call();
            break;
        default:
477
            WARN("Should not happen in sflphone_pick_up()!");
478
            break;
479
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
480 481
}

482
void
483
sflphone_on_hold()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
484
{
Tristan Matthews's avatar
Tristan Matthews committed
485 486
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
487

488 489
    if (selectedCall) {
        switch (selectedCall->_state) {
Emmanuel Milou's avatar
Emmanuel Milou committed
490 491
            case CALL_STATE_CURRENT:
            case CALL_STATE_RECORD:
492
                dbus_hold(selectedCall);
Emmanuel Milou's avatar
Emmanuel Milou committed
493 494
                break;
            default:
495
                WARN("Should not happen in sflphone_on_hold!");
Emmanuel Milou's avatar
Emmanuel Milou committed
496 497
                break;
        }
498
    } else if (selectedConf)
499
        dbus_hold_conference(selectedConf);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
500 501
}

502
void
503
sflphone_off_hold()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
504
{
505
    DEBUG("sflphone_off_hold");
Tristan Matthews's avatar
Tristan Matthews committed
506 507
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
508

509 510
    if (selectedCall) {
        switch (selectedCall->_state) {
Emmanuel Milou's avatar
Emmanuel Milou committed
511
            case CALL_STATE_HOLD:
512
                dbus_unhold(selectedCall);
Emmanuel Milou's avatar
Emmanuel Milou committed
513 514
                break;
            default:
515
                WARN("Should not happen in sflphone_off_hold ()!");
Emmanuel Milou's avatar
Emmanuel Milou committed
516 517
                break;
        }
518
    } else if (selectedConf)
519
        dbus_unhold_conference(selectedConf);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
520 521 522
}


523
void
524
sflphone_fail(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
525
{
526
    c->_state = CALL_STATE_FAILURE;
Tristan Matthews's avatar
Tristan Matthews committed
527
    calltree_update_call(current_calls_tab, c);
528
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
529 530
}

531
void
532
sflphone_busy(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
533
{
534
    c->_state = CALL_STATE_BUSY;
Tristan Matthews's avatar
Tristan Matthews committed
535
    calltree_update_call(current_calls_tab, c);
536
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
537 538
}

539
void
540
sflphone_current(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
541
{
542
    if (c->_state != CALL_STATE_HOLD)
543
        time(&c->_time_start);
544

545
    c->_state = CALL_STATE_CURRENT;
Tristan Matthews's avatar
Tristan Matthews committed
546
    calltree_update_call(current_calls_tab, c);
547
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
548 549
}

550
void
551
sflphone_record(callable_obj_t * c)
alexandresavard's avatar
alexandresavard committed
552
{
553
    if (c->_state != CALL_STATE_HOLD)
554
        time(&c->_time_start);
555

556
    c->_state = CALL_STATE_RECORD;
Tristan Matthews's avatar
Tristan Matthews committed
557
    calltree_update_call(current_calls_tab, c);
558
    update_actions();
alexandresavard's avatar
alexandresavard committed
559 560
}

561
void
562
sflphone_set_transfer()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
563
{
Tristan Matthews's avatar
Tristan Matthews committed
564
    callable_obj_t * c = calltab_get_selected_call(current_calls_tab);
565 566

    if (c) {
567
        c->_state = CALL_STATE_TRANSFER;
Tristan Matthews's avatar
Tristan Matthews committed
568
        g_free(c->_trsft_to);
569
        c->_trsft_to = g_strdup("");
Tristan Matthews's avatar
Tristan Matthews committed
570
        calltree_update_call(current_calls_tab, c);
Emmanuel Milou's avatar
Emmanuel Milou committed
571
    }
572

573
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
574 575
}

576
void
577
sflphone_unset_transfer()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
578
{
Tristan Matthews's avatar
Tristan Matthews committed
579
    callable_obj_t * c = calltab_get_selected_call(current_calls_tab);
580 581

    if (c) {
582
        c->_state = CALL_STATE_CURRENT;
Tristan Matthews's avatar
Tristan Matthews committed
583
        g_free(c->_trsft_to);
584
        c->_trsft_to = g_strdup("");
Tristan Matthews's avatar
Tristan Matthews committed
585
        calltree_update_call(current_calls_tab, c);
Emmanuel Milou's avatar
Emmanuel Milou committed
586
    }
587

588
    update_actions();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
589
}
Emmanuel Milou's avatar
Emmanuel Milou committed
590

591
void
592
sflphone_display_transfer_status(const gchar* message)
593
{
594
    statusbar_push_message(message , NULL, __MSG_ACCOUNT_DEFAULT);
595 596
}

597
void
598
sflphone_incoming_call(callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
599
{
600
    c->_history_state = MISSED;
Tristan Matthews's avatar
Tristan Matthews committed
601 602
    calllist_add_call(current_calls_tab, c);
    calltree_add_call(current_calls_tab, c, NULL);
603

604
    update_actions();
Tristan Matthews's avatar
Tristan Matthews committed
605
    calltree_display(current_calls_tab);
606 607

    // Change the status bar if we are dealing with a direct SIP call
608 609 610 611 612
    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);
613
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
614
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
615

616
static void
617
process_dialing(callable_obj_t *c, guint keyval, gchar *key)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
618
{
Emmanuel Milou's avatar
Emmanuel Milou committed
619
    // We stop the tone
620
    if (!*c->_peer_number && c->_state != CALL_STATE_TRANSFER)
621
        dbus_start_tone(FALSE, 0);
622

623
    switch (keyval) {
624 625
        case GDK_Return:
        case GDK_KP_Enter:
626
            sflphone_place_call(c);
Emmanuel Milou's avatar
Emmanuel Milou committed
627
            break;
628
        case GDK_Escape:
629
            sflphone_hang_up();
Emmanuel Milou's avatar
Emmanuel Milou committed
630
            break;
631
        case GDK_BackSpace: {
632 633
            gchar *num = (c->_state == CALL_STATE_TRANSFER) ? c->_trsft_to : c->_peer_number;
            size_t len = strlen(num);
634

635 636 637
            if (len) {
                len--; // delete one character
                num[len] = '\0';
Tristan Matthews's avatar
Tristan Matthews committed
638
                calltree_update_call(current_calls_tab, c);
639

640
                /* If number is now empty, hang up immediately */
641
                if (c->_state != CALL_STATE_TRANSFER && len == 0)
642
                    dbus_hang_up(c);
Emmanuel Milou's avatar
Emmanuel Milou committed
643
            }
644

645
            break;
646
        }
647 648 649 650