dbus.c 62.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: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
4
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
 *  Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
Julien Bonjean's avatar
Julien Bonjean committed
6
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
7 8
 *  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
9
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
10
 *  (at your option) any later version.
Julien Bonjean's avatar
Julien Bonjean committed
11
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty f
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
14 15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
Julien Bonjean's avatar
Julien Bonjean committed
16
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
17 18 19
 *  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.
20 21 22 23 24 25 26 27 28 29 30
 *
 *  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
31
 */
32
#ifdef HAVE_CONFIG_H
33
#include "config.h"
34
#endif
Alexandre Savard's avatar
Alexandre Savard committed
35

36
#include <glib/gi18n.h>
37
#include "str_utils.h"
38 39 40 41
#include "logger.h"
#include "calltab.h"
#include "callmanager-glue.h"
#include "configurationmanager-glue.h"
42
#ifdef SFL_VIDEO
43
#include "video_controls-glue.h"
44
#endif
45 46 47 48 49 50 51
#include "instance-glue.h"
#include "preferencesdialog.h"
#include "mainwindow.h"
#include "marshaller.h"
#include "sliders.h"
#include "statusicon.h"
#include "assistant.h"
52
#include "accountlist.h"
53
#include "accountlistconfigdialog.h"
Emmanuel Lepage's avatar
Emmanuel Lepage committed
54
#include "messaging/message_tab.h"
Alexandre Savard's avatar
Alexandre Savard committed
55

56 57
#include "dbus.h"
#include "actions.h"
58
#include "unused.h"
Alexandre Savard's avatar
Alexandre Savard committed
59

60
#ifdef SFL_VIDEO
Rafaël Carré's avatar
Rafaël Carré committed
61
#include "config/videoconf.h"
62
#include "video/video_callbacks.h"
63
#endif
64
#include "eel-gconf-extensions.h"
65
#include "account_schema.h"
66
#include "mainwindow.h"
67

68
#ifdef SFL_VIDEO
Tristan Matthews's avatar
Tristan Matthews committed
69
static DBusGProxy *video_proxy;
70
#endif
Tristan Matthews's avatar
Tristan Matthews committed
71 72 73
static DBusGProxy *call_proxy;
static DBusGProxy *config_proxy;
static DBusGProxy *instance_proxy;
74 75
// static DBusGProxy *session_manager_proxy;
static GDBusProxy *session_manager_proxy;
76 77

/* Returns TRUE if there was an error, FALSE otherwise */
78
static gboolean check_error(GError *error)
79 80
{
    if (error) {
81
        ERROR("%s", error->message);
82 83 84 85 86
        g_error_free(error);
        return TRUE;
    }
    return FALSE;
}
87

88
static void
89 90
new_call_created_cb(DBusGProxy *proxy UNUSED, const gchar *accountID,
                    const gchar *callID, const gchar *to, void *foo UNUSED)
91
{
Tristan Matthews's avatar
Tristan Matthews committed
92 93
    callable_obj_t *c = create_new_call(CALL, CALL_STATE_RINGING, callID,
                                        accountID, to, to);
94

Tristan Matthews's avatar
Tristan Matthews committed
95 96
    calllist_add_call(current_calls_tab, c);
    calltree_add_call(current_calls_tab, c, NULL);
97

98
    update_actions();
Tristan Matthews's avatar
Tristan Matthews committed
99
    calltree_display(current_calls_tab);
100 101
}

102
static void
103 104
incoming_call_cb(DBusGProxy *proxy UNUSED, const gchar *accountID,
                 const gchar *callID, const gchar *from, void *foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
105
{
106
    // We receive the from field under a formatted way. We want to extract the number and the name of the caller
107
    gchar *display_name = call_get_display_name(from);
108
    gchar *peer_number = call_get_peer_number(from);
109

Tristan Matthews's avatar
Tristan Matthews committed
110 111
    callable_obj_t *c = create_new_call(CALL, CALL_STATE_INCOMING, callID,
                                        accountID, display_name, peer_number);
112

113
    g_free(peer_number);
114
    g_free(display_name);
115

116
    status_tray_icon_blink(TRUE);
117
    popup_main_window();
118

119 120
    notify_incoming_call(c);
    sflphone_incoming_call(c);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
121 122
}

123
static void
124 125 126
zrtp_negotiation_failed_cb(DBusGProxy *proxy UNUSED, const gchar *callID,
                           const gchar *reason, const gchar *severity,
                           void *foo UNUSED)
127
{
128
    main_window_zrtp_negotiation_failed(callID, reason, severity);
Tristan Matthews's avatar
Tristan Matthews committed
129
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
130

Rafaël Carré's avatar
Rafaël Carré committed
131
    if (c)
132
        notify_zrtp_negotiation_failed(c);
Alexandre Savard's avatar
Alexandre Savard committed
133
}
134

135
static void
136 137
volume_changed_cb(DBusGProxy *proxy UNUSED, const gchar *device, gdouble value,
                  void *foo UNUSED)
138
{
139
    set_slider_no_update(device, value);
140 141
}

142
static void
143 144
voice_mail_cb(DBusGProxy *proxy UNUSED, const gchar *accountID, guint nb,
              void *foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
145
{
146
    sflphone_notify_voice_mail(accountID, nb);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
147 148
}

149
static void
Tristan Matthews's avatar
Tristan Matthews committed
150
incoming_message_cb(DBusGProxy *proxy UNUSED, const gchar *callID UNUSED,
Emmanuel Lepage's avatar
Emmanuel Lepage committed
151
                    const gchar *from UNUSED, const gchar *msg, void *foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
152
{
153
    // do not display message if instant messaging is disabled
154 155
    if (eel_gconf_key_exists(INSTANT_MESSAGING_ENABLED) &&
        !eel_gconf_get_integer(INSTANT_MESSAGING_ENABLED))
156 157
        return;

Tristan Matthews's avatar
Tristan Matthews committed
158
    callable_obj_t *call = calllist_get_call(current_calls_tab, callID);
159

160
    if (call) {
161
        new_text_message(call,msg);
162
    } else {
Tristan Matthews's avatar
Tristan Matthews committed
163
        conference_obj_t *conf = conferencelist_get(current_calls_tab, callID);
Rafaël Carré's avatar
Rafaël Carré committed
164
        if (!conf) {
165
            ERROR("Message received, but no recipient found");
Rafaël Carré's avatar
Rafaël Carré committed
166 167
            return;
        }
168

169
        new_text_message_conf(conf,msg,from);
170
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
171 172
}

173 174 175
/**
 * Perform the right sflphone action based on the requested state
 */
Tristan Matthews's avatar
Tristan Matthews committed
176 177
static void
process_existing_call_state_change(callable_obj_t *c, const gchar *state)
178
{
179
    if (c == NULL) {
180 181
        ERROR("Pointer to call is NULL in %s\n", __func__);
        return;
Tristan Matthews's avatar
Tristan Matthews committed
182
    } else if (state == NULL) {
183 184 185
        ERROR("Pointer to state is NULL in %s\n", __func__);
        return;
    }
186

187 188 189
    if (g_strcmp0(state, "HUNGUP") == 0) {
        if (c->_state == CALL_STATE_CURRENT) {
            time(&c->_time_stop);
Tristan Matthews's avatar
Tristan Matthews committed
190
            calltree_update_call(history_tab, c);
191
        }
192

193 194 195
        calltree_update_call(history_tab, c);
        status_bar_display_account();
        sflphone_hung_up(c);
196
    } else if (g_strcmp0(state, "UNHOLD") == 0 || g_strcmp0(state, "CURRENT") == 0)
197
        sflphone_current(c);
198
    else if (g_strcmp0(state, "HOLD") == 0)
199
        sflphone_hold(c);
200
    else if (g_strcmp0(state, "RINGING") == 0)
201
        sflphone_ringing(c);
202
    else if (g_strcmp0(state, "FAILURE") == 0)
203
        sflphone_fail(c);
204
    else if (g_strcmp0(state, "BUSY") == 0)
205 206
        sflphone_busy(c);
}
207 208


209
/**
210
 * This function process call state changes in case the call have not been created yet.
211
 * This mainly occurs when another SFLphone client takes actions.
212
 */
213 214
static void
process_nonexisting_call_state_change(const gchar *callID, const gchar *state)
215
{
216
    if (callID == NULL) {
217 218
        ERROR("Pointer to call id is NULL in %s\n", __func__);
        return;
Tristan Matthews's avatar
Tristan Matthews committed
219
    } else if (state == NULL) {
220 221
        ERROR("Pointer to state is NULL in %s\n", __func__);
        return;
Tristan Matthews's avatar
Tristan Matthews committed
222 223
    } else if (g_strcmp0(state, "HUNGUP") == 0)
        return; // Could occur if a user picked up the phone and hung up without making a call
224

225
    // The callID is unknown, treat it like a new call
226 227
    // If it were an incoming call, we won't be here
    // It means that a new call has been initiated with an other client (cli for instance)
228
    if (g_strcmp0(state, "RINGING") == 0 || g_strcmp0(state, "CURRENT") == 0) {
Alexandre Savard's avatar
Alexandre Savard committed
229

230
        DEBUG("New ringing call! accountID: %s", callID);
Alexandre Savard's avatar
Alexandre Savard committed
231

232 233 234 235
        restore_call(callID);
        callable_obj_t *new_call = calllist_get_call(current_calls_tab, callID);
        if (new_call)
            calltree_add_call(current_calls_tab, new_call, NULL);
236 237 238 239 240 241
        update_actions();
        calltree_display(current_calls_tab);
    }
}

static void
Tristan Matthews's avatar
Tristan Matthews committed
242 243
call_state_cb(DBusGProxy *proxy UNUSED, const gchar *callID,
              const gchar *state, void *foo UNUSED)
244 245 246
{
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);

247 248 249
    if (c)
        process_existing_call_state_change(c, state);
    else {
Tristan Matthews's avatar
Tristan Matthews committed
250
        WARN("Call does not exist");
251
        process_nonexisting_call_state_change(callID, state);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
252
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
253 254
}

Tristan Matthews's avatar
Tristan Matthews committed
255
static void
256
toggle_im(conference_obj_t *conf, gboolean activate UNUSED)
Rafaël Carré's avatar
Rafaël Carré committed
257
{
258
    for (GSList *p = conf->participant_list; p; p = g_slist_next(p)) {
259
        //callable_obj_t *call = calllist_get_call(current_calls_tab, p->data);
260

261
        /*TODO elepage(2012) Implement IM messaging toggle here*/
Rafaël Carré's avatar
Rafaël Carré committed
262 263 264
    }
}

265
static void
266 267
conference_changed_cb(DBusGProxy *proxy UNUSED, const gchar *confID,
                      const gchar *state, void *foo UNUSED)
268
{
269 270 271
    DEBUG("Conference state changed: %s\n", state);

    conference_obj_t* changed_conf = conferencelist_get(current_calls_tab, confID);
272
    if (changed_conf == NULL) {
273
        ERROR("Conference is NULL in conference state changed");
274
        return;
275
    }
276

277
    // remove old conference from calltree
Tristan Matthews's avatar
Tristan Matthews committed
278
    calltree_remove_conference(current_calls_tab, changed_conf);
279 280

    // update conference state
281
    if (g_strcmp0(state, "ACTIVE_ATTACHED") == 0)
282
        changed_conf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED;
283
    else if (g_strcmp0(state, "ACTIVE_DETACHED") == 0)
284
        changed_conf->_state = CONFERENCE_STATE_ACTIVE_DETACHED;
285
    else if (g_strcmp0(state, "ACTIVE_ATTACHED_REC") == 0)
286
        changed_conf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
287
    else if (g_strcmp0(state, "ACTIVE_DETACHED_REC") == 0)
288
        changed_conf->_state = CONFERENCE_STATE_ACTIVE_DETACHED_RECORD;
289
    else if (g_strcmp0(state, "HOLD") == 0)
290
        changed_conf->_state = CONFERENCE_STATE_HOLD;
291
    else if (g_strcmp0(state, "HOLD_REC") == 0)
292
        changed_conf->_state = CONFERENCE_STATE_HOLD_RECORD;
293
    else
294
        DEBUG("Error: conference state not recognized");
295

296
    // reactivate instant messaging window for these calls
Rafaël Carré's avatar
Rafaël Carré committed
297
    toggle_im(changed_conf, TRUE);
298

Rafaël Carré's avatar
Rafaël Carré committed
299 300 301
    gchar **list = dbus_get_participant_list(changed_conf->_confID);
    conference_participant_list_update(list, changed_conf);
    g_strfreev(list);
302

303
    // deactivate instant messaging window for new participants
Rafaël Carré's avatar
Rafaël Carré committed
304
    toggle_im(changed_conf, FALSE);
Tristan Matthews's avatar
Tristan Matthews committed
305
    calltree_add_conference_to_current_calls(changed_conf);
306 307 308
}

static void
309
conference_created_cb(DBusGProxy *proxy UNUSED, const gchar *confID, void *foo UNUSED)
310
{
311 312
    DEBUG("Conference %s added", confID);

313
    conference_obj_t *new_conf = create_new_conference(CONFERENCE_STATE_ACTIVE_ATTACHED, confID);
314

315
    gchar **participants = dbus_get_participant_list(new_conf->_confID);
316

317
    // Update conference list
318
    conference_participant_list_update(participants, new_conf);
319

320
    // Add conference ID in in each calls
321 322 323
    for (gchar **part = participants; part && *part; ++part) {
        callable_obj_t *call = calllist_get_call(current_calls_tab, *part);

324
        /*TODO elepage (2012) implement merging IM conversation here*/
325

Tristan Matthews's avatar
Tristan Matthews committed
326
        // if one of these participants is currently recording, the whole conference will be recorded
327
        if (dbus_get_is_recording(call))
328
            new_conf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
329

330
        call->_historyConfID = g_strdup(confID);
331 332
    }

Rafaël Carré's avatar
Rafaël Carré committed
333 334
    g_strfreev(participants);

335
    time(&new_conf->_time_start);
336

Tristan Matthews's avatar
Tristan Matthews committed
337 338
    conferencelist_add(current_calls_tab, new_conf);
    calltree_add_conference_to_current_calls(new_conf);
339 340 341
}

static void
Tristan Matthews's avatar
Tristan Matthews committed
342 343
conference_removed_cb(DBusGProxy *proxy UNUSED, const gchar *confID,
                      void *foo UNUSED)
344
{
345
    DEBUG("Conference removed %s", confID);
Tristan Matthews's avatar
Tristan Matthews committed
346
    conference_obj_t *c = conferencelist_get(current_calls_tab, confID);
347 348 349 350 351
    if(c == NULL) {
        ERROR("Could not find conference %s from list", confID);
        return;
    }

Tristan Matthews's avatar
Tristan Matthews committed
352
    calltree_remove_conference(current_calls_tab, c);
353

354
    /*TODO elepage(2012) implement unmerging of IM here*/
355

356
    // remove all participants for this conference
357
    for (GSList *p = c->participant_list; p; p = g_slist_next(p)) {
358
        //callable_obj_t *call = calllist_get_call(current_calls_tab, p->data);
Emmanuel Lepage's avatar
Emmanuel Lepage committed
359
        /*TODO elepage(2012) implement unmerging of IM here*/
360
    }
361

Tristan Matthews's avatar
Tristan Matthews committed
362
    conferencelist_remove(current_calls_tab, c->_confID);
363 364
}

365
static void
Tristan Matthews's avatar
Tristan Matthews committed
366 367
record_playback_filepath_cb(DBusGProxy *proxy UNUSED, const gchar *id,
                            const gchar *filepath)
368
{
369
    DEBUG("Filepath for %s: %s", id, filepath);
Tristan Matthews's avatar
Tristan Matthews committed
370 371
    callable_obj_t *call = calllist_get_call(current_calls_tab, id);
    conference_obj_t *conf = conferencelist_get(current_calls_tab, id);
372

Tristan Matthews's avatar
Tristan Matthews committed
373
    if (call && conf) {
374
        ERROR("Two objects for this callid");
Tristan Matthews's avatar
Tristan Matthews committed
375
        return;
376 377
    }

Tristan Matthews's avatar
Tristan Matthews committed
378
    if (!call && !conf) {
379
        ERROR("Could not get object");
Tristan Matthews's avatar
Tristan Matthews committed
380
        return;
381
    }
Tristan Matthews's avatar
Tristan Matthews committed
382

383
    if (call && call->_recordfile == NULL)
Tristan Matthews's avatar
Tristan Matthews committed
384
        call->_recordfile = g_strdup(filepath);
385
    else if (conf && conf->_recordfile == NULL)
Tristan Matthews's avatar
Tristan Matthews committed
386
        conf->_recordfile = g_strdup(filepath);
387 388
}

389
static void
390
record_playback_stopped_cb(DBusGProxy *proxy UNUSED, const gchar *filepath)
391
{
392
    DEBUG("Playback stopped for %s", filepath);
Tristan Matthews's avatar
Tristan Matthews committed
393
    const gint calllist_size = calllist_get_size(history_tab);
394

395 396
    for (gint i = 0; i < calllist_size; i++) {
        callable_obj_t *call = calllist_get_nth(history_tab, i);
397

398 399
        if (call == NULL) {
            ERROR("Could not find %dth call", i);
400
            break;
401
        }
402 403
        if (g_strcmp0(call->_recordfile, filepath) == 0)
            call->_record_is_playing = FALSE;
404 405
    }

Tristan Matthews's avatar
Tristan Matthews committed
406
    update_actions();
407
}
408

409
static void
410
update_playback_scale_cb(DBusGProxy *proxy UNUSED, guint position, guint size)
411
{
412
    main_window_update_playback_scale(position, size);
413 414
}

415 416 417 418 419 420 421
static void
registration_state_changed_cb(DBusGProxy *proxy UNUSED, const gchar *accountID,
                              guint state, void *foo UNUSED)
{
    DEBUG("DBus: Registration state changed to %s for account %s",
          account_state_name(state), accountID);
    account_t *acc = account_list_get_by_id(accountID);
422
    if (acc) {
423
        acc->state = state;
424 425
        update_account_list_status_bar(acc);
    }
426 427
}

428
static void
429
accounts_changed_cb(DBusGProxy *proxy UNUSED, void *foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
430
{
431 432 433
    sflphone_fill_account_list();
    sflphone_fill_ip2ip_profile();
    status_bar_display_account();
434
    statusicon_set_tooltip();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
435 436
}

437
static void
438
stun_status_failure_cb(DBusGProxy *proxy UNUSED, const gchar *accountID, void *foo UNUSED)
439
{
440 441 442 443 444
    ERROR("Error: Stun status failure: account %s failed to setup STUN",
          accountID);
    // Disable STUN for the account that tried to create the STUN transport
    account_t *account = account_list_get_by_id(accountID);
    if (account) {
445
        account_replace(account, CONFIG_STUN_ENABLE, "false");
446 447
        dbus_set_account_details(account);
    }
448 449 450 451 452
}

static void
stun_status_success_cb(DBusGProxy *proxy UNUSED, const gchar *message UNUSED, void *foo UNUSED)
{
453
    DEBUG("STUN setup successful");
454 455
}

456
static void
457
transfer_succeeded_cb(DBusGProxy *proxy UNUSED, void *foo UNUSED)
458
{
459
    sflphone_display_transfer_status("Transfer successful");
460 461
}

462
static void
463
transfer_failed_cb(DBusGProxy *proxy UNUSED, void *foo UNUSED)
464
{
465
    sflphone_display_transfer_status("Transfer failed");
466 467
}

468
static void
469
secure_sdes_on_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
470
{
471
    DEBUG("SRTP using SDES is on");
Tristan Matthews's avatar
Tristan Matthews committed
472
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
473

474
    if (c) {
475 476
        sflphone_srtp_sdes_on(c);
        notify_secure_on(c);
477 478 479 480
    }
}

static void
481
secure_sdes_off_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
482
{
483
    DEBUG("SRTP using SDES is off");
Tristan Matthews's avatar
Tristan Matthews committed
484
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
485

486
    if (c) {
487 488
        sflphone_srtp_sdes_off(c);
        notify_secure_off(c);
489 490 491
    }
}

492
static void
493 494
secure_zrtp_on_cb(DBusGProxy *proxy UNUSED, const gchar *callID,
                  const gchar *cipher, void *foo UNUSED)
495
{
496
    DEBUG("SRTP using ZRTP is ON secure_on_cb");
Tristan Matthews's avatar
Tristan Matthews committed
497
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
498

499
    if (c) {
500 501 502
        c->_srtp_cipher = g_strdup(cipher);
        sflphone_srtp_zrtp_on(c);
        notify_secure_on(c);
503 504 505
    }
}

506
static void
507
secure_zrtp_off_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
508
{
509
    DEBUG("SRTP using ZRTP is OFF");
Tristan Matthews's avatar
Tristan Matthews committed
510
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
511

512
    if (c) {
513 514
        sflphone_srtp_zrtp_off(c);
        notify_secure_off(c);
515 516 517
    }
}

518
static void
519 520
show_zrtp_sas_cb(DBusGProxy *proxy UNUSED, const gchar *callID, const gchar *sas,
                 gboolean verified, void *foo UNUSED)
521
{
522
    DEBUG("Showing SAS");
523
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
524

Tristan Matthews's avatar
Tristan Matthews committed
525
    if (c)
526
        sflphone_srtp_zrtp_show_sas(c, sas, verified);
527 528
}

529
static void
530
confirm_go_clear_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
531
{
532
    DEBUG("Confirm Go Clear request");
533
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
534

535
    if (c)
536
        main_window_confirm_go_clear(c);
537 538
}

539
static void
540
zrtp_not_supported_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
541
{
542
    DEBUG("ZRTP not supported on the other end");
543
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
544

545
    if (c) {
546 547
        main_window_zrtp_not_supported(c);
        notify_zrtp_not_supported(c);
548 549 550
    }
}

551
static void
552
sip_call_state_cb(DBusGProxy *proxy UNUSED, const gchar *callID,
553
                  const gchar *description, guint code, void *foo UNUSED)
554
{
555
    DEBUG("Sip call state changed %s", callID);
Tristan Matthews's avatar
Tristan Matthews committed
556
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
557

Rafaël Carré's avatar
Rafaël Carré committed
558
    if (c)
559
        sflphone_call_state_changed(c, description, code);
560
}
561

562
static void
563
error_alert(DBusGProxy *proxy UNUSED, int err, void *foo UNUSED)
564
{
565
    const gchar *msg;
566

Rafaël Carré's avatar
Rafaël Carré committed
567 568
    switch (err) {
        case ALSA_PLAYBACK_DEVICE:
569
            msg = _("ALSA notification: Error while opening playback device");
Rafaël Carré's avatar
Rafaël Carré committed
570 571
            break;
        case ALSA_CAPTURE_DEVICE:
572
            msg = _("ALSA notification: Error while opening capture device");
Rafaël Carré's avatar
Rafaël Carré committed
573 574
            break;
        case PULSEAUDIO_NOT_RUNNING:
575
            msg = _("Pulseaudio notification: Pulseaudio is not running");
Rafaël Carré's avatar
Rafaël Carré committed
576
            break;
577
        case CODECS_NOT_LOADED:
578
            msg = _("Codecs notification: Codecs not found");
579
            break;
580 581
        default:
            return;
Rafaël Carré's avatar
Rafaël Carré committed
582
    }
583

584
    ERROR("%s", msg);
585 586
}

587 588 589
static void
screensaver_dbus_proxy_new_cb (GObject * source UNUSED, GAsyncResult *result, gpointer user_data UNUSED)
{
590
    DEBUG("Session manager connection callback");
591 592 593

    session_manager_proxy = g_dbus_proxy_new_for_bus_finish (result, NULL);
    if (session_manager_proxy == NULL)
594
        ERROR("could not initialize gnome session manager");
595 596 597 598 599 600 601 602 603
}

#define GS_SERVICE   "org.gnome.SessionManager"
#define GS_PATH      "/org/gnome/SessionManager"
#define GS_INTERFACE "org.gnome.SessionManager"

gboolean dbus_connect_session_manager(DBusGConnection *connection)
{

604
    if (connection == NULL) {
605
        ERROR("connection is NULL");
606 607 608 609 610 611 612 613
        return FALSE;
    }
/*
    session_manager_proxy = dbus_g_proxy_new_for_name(connection,
                            "org.gnome.SessionManager", "/org/gnome/SessionManager/Inhibitor",
                            "org.gnome.SessionManager.Inhibitor");

    if(session_manager_proxy == NULL) {
614
        ERROR("Error, could not create session manager proxy");
615 616 617 618
        return FALSE;
    }
*/

619 620 621 622
    g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION,
                             G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
                             NULL, GS_SERVICE, GS_PATH, GS_INTERFACE, NULL,
                             screensaver_dbus_proxy_new_cb, NULL);
623

624
    DEBUG("Connected to gnome session manager");
625 626 627 628

    return TRUE;
}

Tristan Matthews's avatar
Tristan Matthews committed
629
gboolean dbus_connect(GError **error)
630
{
631 632 633 634 635 636 637 638
    const char *dbus_message_bus_name = "org.sflphone.SFLphone";
    const char *dbus_object_instance = "/org/sflphone/SFLphone/Instance";
    const char *dbus_interface = "org.sflphone.SFLphone.Instance";
    const char *callmanager_object_instance = "/org/sflphone/SFLphone/CallManager";
    const char *callmanager_interface = "org.sflphone.SFLphone.CallManager";
    const char *configurationmanager_object_instance = "/org/sflphone/SFLphone/ConfigurationManager";
    const char *configurationmanager_interface = "org.sflphone.SFLphone.ConfigurationManager";

639 640
    g_type_init();

641
    DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, error);
642
    if (connection == NULL) {
643
        ERROR("could not establish connection with session bus");
644
        return FALSE;
645
    }
646 647

    /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
648 649 650
    DEBUG("Connect to message bus:     %s", dbus_message_bus_name);
    DEBUG("           object instance: %s", dbus_object_instance);
    DEBUG("           dbus interface:  %s", dbus_interface);
651

652
    instance_proxy = dbus_g_proxy_new_for_name(connection, dbus_message_bus_name, dbus_object_instance, dbus_interface);
Tristan Matthews's avatar
Tristan Matthews committed
653
    if (instance_proxy == NULL) {
654
        ERROR("Error: Failed to connect to %s", dbus_message_bus_name);
655 656 657
        return FALSE;
    }

658 659
    DEBUG("Connect to object instance: %s", callmanager_object_instance);
    DEBUG("           dbus interface:  %s", callmanager_interface);