~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-client-gnome/src/actions.c

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
#include <sys/ioctl.h>
52
52
#include <linux/if.h>
53
53
 
54
 
 
 
54
#include <widget/imwidget.h>
 
55
#include <imwindow.h>
55
56
 
56
57
GHashTable * ip2ip_profile=NULL;
57
58
 
58
 
    void
 
59
void
59
60
sflphone_notify_voice_mail (const gchar* accountID , guint count)
60
61
{
61
62
    gchar *id;
62
63
    gchar *current_id;
63
 
        account_t *current;
 
64
    account_t *current;
64
65
 
65
66
    // We want to notify only the current account; ie the first in the list
66
67
    id = g_strdup (accountID);
67
68
    current_id = account_list_get_current_id ();
68
69
 
 
70
    DEBUG ("sflphone_notify_voice_mail begin");
 
71
 
69
72
    if (g_strcasecmp (id, current_id) != 0 || account_list_get_size() == 0)
70
73
        return;
71
74
 
72
 
        // Set the number of voice messages for the current account
73
 
        current_account_set_message_number (count);
74
 
        current = account_list_get_current ();
75
 
 
76
 
        // Update the voicemail tool button
77
 
        update_voicemail_status ();
78
 
 
79
 
        if (current)
80
 
                notify_voice_mails (count, current);
 
75
    // Set the number of voice messages for the current account
 
76
    current_account_set_message_number (count);
 
77
    current = account_list_get_current ();
 
78
 
 
79
    // Update the voicemail tool button
 
80
    update_voicemail_status ();
 
81
 
 
82
    if (current)
 
83
        notify_voice_mails (count, current);
 
84
 
 
85
    DEBUG ("sflphone_notify_voice_mail end");
81
86
}
82
87
 
83
88
/*
86
91
 * registered account of the account list
87
92
 * Else, check if it an IP call. if not, popup an error message
88
93
 */
89
 
 
90
 
static gboolean _is_direct_call(callable_obj_t * c) {
91
 
 
92
 
    if(g_strcasecmp(c->_accountID, EMPTY_ENTRY) == 0) {
93
 
        if(!g_str_has_prefix (c->_peer_number, "sip:")) {
94
 
            gchar * new_number = g_strconcat("sip:", c->_peer_number, NULL);
95
 
            g_free(c->_peer_number);
 
94
 
 
95
static gboolean _is_direct_call (callable_obj_t * c)
 
96
{
 
97
 
 
98
    if (g_strcasecmp (c->_accountID, EMPTY_ENTRY) == 0) {
 
99
        if (!g_str_has_prefix (c->_peer_number, "sip:")) {
 
100
            gchar * new_number = g_strconcat ("sip:", c->_peer_number, NULL);
 
101
            g_free (c->_peer_number);
96
102
            c->_peer_number = new_number;
97
103
        }
98
 
        return 1;
99
 
    }
100
 
 
101
 
    if(g_str_has_prefix (c->_peer_number, "sip:")) {
102
 
        return 1;
103
 
    }
104
 
 
105
 
    if(g_str_has_prefix (c->_peer_number, "sips:")) {
 
104
 
 
105
        return 1;
 
106
    }
 
107
 
 
108
    if (g_str_has_prefix (c->_peer_number, "sip:")) {
 
109
        return 1;
 
110
    }
 
111
 
 
112
    if (g_str_has_prefix (c->_peer_number, "sips:")) {
106
113
        return 1;
107
114
    }
108
115
 
110
117
}
111
118
 
112
119
 
113
 
    void
 
120
void
114
121
status_bar_display_account ()
115
122
{
116
123
    gchar* msg;
117
124
    account_t* acc;
118
125
 
119
 
    statusbar_pop_message(__MSG_ACCOUNT_DEFAULT);
 
126
    statusbar_pop_message (__MSG_ACCOUNT_DEFAULT);
 
127
 
 
128
    DEBUG ("status_bar_display_account begin");
120
129
 
121
130
    acc = account_list_get_current ();
122
 
    if(acc){
123
 
        status_tray_icon_online(TRUE);
124
 
        msg = g_markup_printf_escaped("%s %s (%s)" ,
125
 
                _("Using account"),
126
 
                (gchar*)g_hash_table_lookup( acc->properties , ACCOUNT_ALIAS),
127
 
                (gchar*)g_hash_table_lookup( acc->properties , ACCOUNT_TYPE));
128
 
    }
129
 
    else
130
 
    {
131
 
        status_tray_icon_online(FALSE);
132
 
        msg = g_markup_printf_escaped(_("No registered accounts"));
133
 
    }
134
 
    statusbar_push_message( msg , __MSG_ACCOUNT_DEFAULT);
135
 
    g_free(msg);
 
131
 
 
132
    if (acc) {
 
133
        status_tray_icon_online (TRUE);
 
134
        msg = g_markup_printf_escaped ("%s %s (%s)" ,
 
135
                                       _ ("Using account"),
 
136
                                       (gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_ALIAS),
 
137
                                       (gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_TYPE));
 
138
    } else {
 
139
        status_tray_icon_online (FALSE);
 
140
        msg = g_markup_printf_escaped (_ ("No registered accounts"));
 
141
    }
 
142
 
 
143
    statusbar_push_message (msg, NULL,  __MSG_ACCOUNT_DEFAULT);
 
144
    g_free (msg);
 
145
 
 
146
    DEBUG ("status_bar_display_account_end");
136
147
}
137
148
 
138
149
 
139
 
    gboolean
 
150
gboolean
140
151
sflphone_quit ()
141
152
{
142
153
    gboolean quit = FALSE;
143
 
    guint count = calllist_get_size(current_calls);
144
 
    if(count > 0){
 
154
    guint count = calllist_get_size (current_calls);
 
155
 
 
156
    if (count > 0) {
145
157
        quit = main_window_ask_quit();
146
 
    }
147
 
    else{
 
158
    } else {
148
159
        quit = TRUE;
149
160
    }
150
161
 
151
 
    if (quit)
152
 
    {
153
 
        // Save the history 
 
162
    if (quit) {
 
163
        // Save the history
154
164
        sflphone_save_history ();
155
165
 
156
 
        dbus_unregister(getpid());
 
166
        dbus_unregister (getpid());
157
167
        dbus_clean ();
158
168
        //call_list_clean(); TODO
159
169
        //account_list_clean()
160
170
        gtk_main_quit ();
161
171
    }
 
172
 
162
173
    return quit;
163
174
}
164
175
 
165
 
    void
166
 
sflphone_hold (callable_obj_t * c )
 
176
void
 
177
sflphone_hold (callable_obj_t * c)
167
178
{
168
179
    c->_state = CALL_STATE_HOLD;
169
 
    calltree_update_call(current_calls, c, NULL);
 
180
    calltree_update_call (current_calls, c, NULL);
170
181
    update_actions();
171
182
}
172
183
 
173
 
    void
174
 
sflphone_ringing(callable_obj_t * c )
 
184
void
 
185
sflphone_ringing (callable_obj_t * c)
175
186
{
176
187
    c->_state = CALL_STATE_RINGING;
177
 
    calltree_update_call(current_calls, c, NULL);
 
188
    calltree_update_call (current_calls, c, NULL);
178
189
    update_actions();
179
190
}
180
191
 
181
 
    void
182
 
sflphone_hung_up( callable_obj_t * c)
 
192
void
 
193
sflphone_hung_up (callable_obj_t * c)
183
194
{
184
 
    calllist_remove( current_calls, c->_callID);
185
 
    calltree_remove_call(current_calls, c, NULL);
 
195
    DEBUG ("SFLphone: Hung up");
 
196
 
 
197
    calllist_remove (current_calls, c->_callID);
 
198
    calltree_remove_call (current_calls, c, NULL);
186
199
    c->_state = CALL_STATE_DIALING;
187
 
    call_remove_all_errors(c);
 
200
    call_remove_all_errors (c);
188
201
    update_actions();
 
202
 
 
203
    // test wether the widget contain text, if not remove it
 
204
    if ( (im_window_get_nb_tabs() > 1) && c->_im_widget && ! (IM_WIDGET (c->_im_widget)->containText))
 
205
        im_window_remove_tab (c->_im_widget);
 
206
    else
 
207
        im_widget_update_state (IM_WIDGET (c->_im_widget), FALSE);
 
208
 
189
209
#if GTK_CHECK_VERSION(2,10,0)
190
 
    status_tray_icon_blink( FALSE );
 
210
    status_tray_icon_blink (FALSE);
191
211
#endif
192
 
}
193
 
 
194
 
static hashtable_free(gpointer key, gpointer value, gpointer user_data)
195
 
{
196
 
    g_free(key);
197
 
    g_free(value);
 
212
    calltree_update_clock();
198
213
}
199
214
 
200
215
/** Internal to actions: Fill account list */
201
 
void sflphone_fill_account_list (void) {
 
216
void sflphone_fill_account_list (void)
 
217
{
202
218
 
203
219
    gchar** array;
204
220
    gchar** accountID;
205
221
    unsigned int i;
206
 
        int count;
207
 
        GQueue *codeclist;
208
 
 
209
 
        DEBUG("SFLphone: Fill account list");
210
 
 
211
 
        count = current_account_get_message_number ();
 
222
    int count;
 
223
 
 
224
    DEBUG ("SFLphone: Fill account list");
 
225
 
 
226
    count = current_account_get_message_number ();
212
227
 
213
228
    account_list_clear ();
214
229
 
215
 
    array = (gchar **)dbus_account_list();
216
 
    if(array)
217
 
    {
218
 
        for (accountID = array; *accountID; accountID++)
219
 
        {
220
 
            account_t * a = g_new0(account_t,1);
221
 
            a->accountID = g_strdup(*accountID);
 
230
    array = (gchar **) dbus_account_list();
 
231
 
 
232
    if (array) {
 
233
 
 
234
        for (accountID = array; *accountID; accountID++) {
 
235
            account_t * a = g_new0 (account_t,1);
 
236
            a->accountID = g_strdup (*accountID);
222
237
            a->credential_information = NULL;
223
 
                        // TODO Clean codec list QUEUE
224
 
            account_list_add(a);
 
238
            account_list_add (a);
225
239
        }
 
240
 
226
241
        g_strfreev (array);
227
242
    }
228
243
 
229
 
    for( i = 0; i < account_list_get_size(); i++)
230
 
    {
 
244
    for (i = 0; i < account_list_get_size(); i++) {
231
245
        account_t  * a = account_list_get_nth (i);
232
 
        GHashTable * details = (GHashTable *) dbus_account_details(a->accountID);
233
 
        if( details == NULL )
 
246
        GHashTable * details = (GHashTable *) dbus_account_details (a->accountID);
 
247
 
 
248
        if (details == NULL)
234
249
            break;
 
250
 
235
251
        a->properties = details;
236
 
                        
237
 
        /* As this function might be called numberous time, we should free the 
 
252
 
 
253
        /* As this function might be called numberous time, we should free the
238
254
         * previously allocated space to avoid memory leaks.
239
255
         */
240
256
 
241
257
        /* Fill the actual array of credentials */
242
 
        int number_of_credential = dbus_get_number_of_credential(a->accountID);
243
 
        if(number_of_credential) {
 
258
        int number_of_credential = dbus_get_number_of_credential (a->accountID);
 
259
 
 
260
        if (number_of_credential) {
244
261
            a->credential_information = g_ptr_array_new();
245
262
        } else {
246
263
            a->credential_information = NULL;
247
264
        }
248
 
        
 
265
 
249
266
        int credential_index;
250
 
        for(credential_index = 0; credential_index < number_of_credential; credential_index++) {
 
267
 
 
268
        for (credential_index = 0; credential_index < number_of_credential; credential_index++) {
251
269
            GHashTable * credential_information = dbus_get_credential (a->accountID, credential_index);
252
 
            g_ptr_array_add(a->credential_information, credential_information);
 
270
            g_ptr_array_add (a->credential_information, credential_information);
253
271
        }
254
272
 
255
 
        gchar * status = g_hash_table_lookup(details, REGISTRATION_STATUS);
256
 
        if(strcmp(status, "REGISTERED") == 0)
257
 
        {
 
273
        gchar * status = g_hash_table_lookup (details, REGISTRATION_STATUS);
 
274
 
 
275
        if (strcmp (status, "REGISTERED") == 0) {
258
276
            a->state = ACCOUNT_STATE_REGISTERED;
259
 
        }
260
 
        else if(strcmp(status, "UNREGISTERED") == 0)
261
 
        {
 
277
        } else if (strcmp (status, "UNREGISTERED") == 0) {
262
278
            a->state = ACCOUNT_STATE_UNREGISTERED;
263
 
        }
264
 
        else if(strcmp(status, "TRYING") == 0)
265
 
        {
 
279
        } else if (strcmp (status, "TRYING") == 0) {
266
280
            a->state = ACCOUNT_STATE_TRYING;
267
 
        }
268
 
        else if(strcmp(status, "ERROR") == 0)
269
 
        {
 
281
        } else if (strcmp (status, "ERROR") == 0) {
270
282
            a->state = ACCOUNT_STATE_ERROR;
271
 
        }
272
 
        else if(strcmp( status , "ERROR_AUTH") == 0 )
273
 
        {
 
283
        } else if (strcmp (status , "ERROR_AUTH") == 0) {
274
284
            a->state = ACCOUNT_STATE_ERROR_AUTH;
275
 
        }
276
 
        else if(strcmp( status , "ERROR_NETWORK") == 0 )
277
 
        {
 
285
        } else if (strcmp (status , "ERROR_NETWORK") == 0) {
278
286
            a->state = ACCOUNT_STATE_ERROR_NETWORK;
279
 
        }
280
 
        else if(strcmp( status , "ERROR_HOST") == 0 )
281
 
        {
 
287
        } else if (strcmp (status , "ERROR_HOST") == 0) {
282
288
            a->state = ACCOUNT_STATE_ERROR_HOST;
283
 
        }
284
 
        else if(strcmp( status , "ERROR_CONF_STUN") == 0 )
285
 
        {
 
289
        } else if (strcmp (status , "ERROR_CONF_STUN") == 0) {
286
290
            a->state = ACCOUNT_STATE_ERROR_CONF_STUN;
287
 
        }
288
 
        else if(strcmp( status , "ERROR_EXIST_STUN") == 0 )
289
 
        {
 
291
        } else if (strcmp (status , "ERROR_EXIST_STUN") == 0) {
290
292
            a->state = ACCOUNT_STATE_ERROR_EXIST_STUN;
291
 
        }
292
 
                else if (strcmp (status, "READY") == 0) {
293
 
                        a->state = IP2IP_PROFILE_STATUS;
294
 
                }
295
 
        else
296
 
        {
 
293
        } else if (strcmp (status, "READY") == 0) {
 
294
            a->state = IP2IP_PROFILE_STATUS;
 
295
        } else {
297
296
            a->state = ACCOUNT_STATE_INVALID;
298
297
        }
299
298
 
300
299
        gchar * code = NULL;
301
 
        code = g_hash_table_lookup(details, REGISTRATION_STATE_CODE);
 
300
        code = g_hash_table_lookup (details, REGISTRATION_STATE_CODE);
 
301
 
302
302
        if (code != NULL) {
303
 
            a->protocol_state_code = atoi(code);
 
303
            a->protocol_state_code = atoi (code);
304
304
        }
305
 
        g_free(a->protocol_state_description);
306
 
        a->protocol_state_description = g_hash_table_lookup(details, REGISTRATION_STATE_DESCRIPTION);
 
305
 
 
306
        g_free (a->protocol_state_description);
 
307
        a->protocol_state_description = g_hash_table_lookup (details, REGISTRATION_STATE_DESCRIPTION);
307
308
    }
308
309
 
309
 
        // Set the current account message number
310
 
        current_account_set_message_number (count);
 
310
    // Set the current account message number
 
311
    current_account_set_message_number (count);
311
312
 
312
 
        sflphone_fill_codec_list ();
 
313
    sflphone_fill_codec_list ();
313
314
}
314
315
 
315
 
gboolean sflphone_init() {
316
 
 
317
 
    if(!dbus_connect ()){
318
 
 
319
 
        main_window_error_message(_("Unable to connect to the SFLphone server.\nMake sure the daemon is running."));
 
316
gboolean sflphone_init()
 
317
{
 
318
 
 
319
    if (!dbus_connect ()) {
 
320
 
 
321
        main_window_error_message (_ ("Unable to connect to the SFLphone server.\nMake sure the daemon is running."));
320
322
        return FALSE;
321
 
    }
322
 
    else
323
 
    {
324
 
        dbus_register(getpid(), "Gtk+ Client");
325
 
 
326
 
                // Init icons factory
327
 
                init_icon_factory ();
328
 
 
329
 
        current_calls = calltab_init(FALSE, CURRENT_CALLS);
330
 
        contacts = calltab_init(TRUE, CONTACTS);
331
 
        history = calltab_init(TRUE, HISTORY);
 
323
    } else {
 
324
        dbus_register (getpid(), "Gtk+ Client");
 
325
 
 
326
        // Init icons factory
 
327
        init_icon_factory ();
 
328
 
 
329
        current_calls = calltab_init (FALSE, CURRENT_CALLS);
 
330
        contacts = calltab_init (TRUE, CONTACTS);
 
331
        history = calltab_init (TRUE, HISTORY);
332
332
 
333
333
        account_list_init ();
334
334
        codec_capabilities_load ();
335
 
                conferencelist_init ();
 
335
        conferencelist_init ();
336
336
 
337
337
        // Fetch the configured accounts
338
338
        sflphone_fill_account_list ();
339
339
 
340
 
        // Fetch the ip2ip profile 
 
340
        // Fetch the ip2ip profile
341
341
        sflphone_fill_ip2ip_profile();
342
 
        
343
 
                // Fetch the conference list
344
 
                // sflphone_fill_conference_list();
 
342
 
 
343
        // Fetch the conference list
 
344
        // sflphone_fill_conference_list();
345
345
 
346
346
        return TRUE;
347
347
    }
348
348
}
349
349
 
350
 
void sflphone_fill_ip2ip_profile(void)
 
350
void sflphone_fill_ip2ip_profile (void)
351
351
{
352
352
    ip2ip_profile = (GHashTable *) dbus_get_ip2_ip_details();
353
353
}
354
354
 
355
355
void sflphone_get_ip2ip_properties (GHashTable **properties)
356
356
{
357
 
        *properties     = ip2ip_profile;
 
357
    *properties = ip2ip_profile;
358
358
}
359
359
 
360
 
    void
 
360
void
361
361
sflphone_hang_up()
362
362
{
363
 
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls);
364
 
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree);
365
 
 
366
 
    if(selectedCall)
367
 
    {
368
 
        switch(selectedCall->_state)
369
 
        {
 
363
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
 
364
    conference_obj_t * selectedConf = calltab_get_selected_conf (active_calltree);
 
365
 
 
366
    DEBUG ("SFLphone: Hang up");
 
367
 
 
368
    if (selectedCall) {
 
369
        switch (selectedCall->_state) {
370
370
            case CALL_STATE_DIALING:
371
371
                dbus_hang_up (selectedCall);
372
372
                break;
373
373
            case CALL_STATE_RINGING:
374
374
                dbus_hang_up (selectedCall);
375
 
                call_remove_all_errors(selectedCall);
 
375
                call_remove_all_errors (selectedCall);
376
376
                selectedCall->_state = CALL_STATE_DIALING;
377
377
                //selectedCall->_stop = 0;
378
378
                break;
381
381
            case CALL_STATE_BUSY:
382
382
            case CALL_STATE_RECORD:
383
383
                dbus_hang_up (selectedCall);
384
 
                call_remove_all_errors(selectedCall);
 
384
                call_remove_all_errors (selectedCall);
385
385
                selectedCall->_state = CALL_STATE_DIALING;
386
386
                set_timestamp (&selectedCall->_time_stop);
 
387
 
 
388
                //if ( (im_window_get_nb_tabs() > 1) && selectedCall->_im_widget &&
 
389
                //        ! (IM_WIDGET (selectedCall->_im_widget)->containText))
 
390
                //    im_window_remove_tab (selectedCall->_im_widget);
 
391
                //else
 
392
                im_widget_update_state (IM_WIDGET (selectedCall->_im_widget), FALSE);
 
393
 
387
394
                break;
388
395
            case CALL_STATE_FAILURE:
389
396
                dbus_hang_up (selectedCall);
390
 
                call_remove_all_errors(selectedCall);
 
397
                call_remove_all_errors (selectedCall);
391
398
                selectedCall->_state = CALL_STATE_DIALING;
392
399
                break;
393
400
            case CALL_STATE_INCOMING:
394
401
                dbus_refuse (selectedCall);
395
 
                call_remove_all_errors(selectedCall);
 
402
                call_remove_all_errors (selectedCall);
396
403
                selectedCall->_state = CALL_STATE_DIALING;
397
 
                DEBUG("from sflphone_hang_up : "); stop_notification();
 
404
                DEBUG ("from sflphone_hang_up : ");
 
405
                stop_notification();
398
406
                break;
399
407
            case CALL_STATE_TRANSFERT:
400
408
                dbus_hang_up (selectedCall);
401
 
                call_remove_all_errors(selectedCall);
 
409
                call_remove_all_errors (selectedCall);
402
410
                set_timestamp (&selectedCall->_time_stop);
403
411
                break;
404
412
            default:
405
 
                WARN("Should not happen in sflphone_hang_up()!");
 
413
                WARN ("Should not happen in sflphone_hang_up()!");
406
414
                break;
407
415
        }
408
 
    }
409
 
    else if(selectedConf) {
410
 
        dbus_hang_up_conference(selectedConf);
411
 
    }
412
 
 
413
 
    calltree_update_call(history, selectedCall, NULL);
 
416
    } else if (selectedConf) {
 
417
        im_widget_update_state (IM_WIDGET (selectedConf->_im_widget), FALSE);
 
418
        dbus_hang_up_conference (selectedConf);
 
419
    }
 
420
 
 
421
    calltree_update_call (history, selectedCall, NULL);
 
422
 
 
423
    stop_call_clock (selectedCall);
 
424
 
 
425
    calltree_update_clock();
414
426
}
415
427
 
416
428
 
419
431
{
420
432
    conference_obj_t * selectedConf = calltab_get_selected_conf();
421
433
 
422
 
    if(selectedConf)
423
 
        dbus_hang_up_conference(selectedConf);
 
434
    if (selectedConf)
 
435
        dbus_hang_up_conference (selectedConf);
424
436
}
425
437
 
426
438
 
427
 
    void
 
439
void
428
440
sflphone_pick_up()
429
441
{
430
 
    DEBUG("sflphone_pick_up\n");
 
442
    DEBUG ("sflphone_pick_up\n");
431
443
    callable_obj_t * selectedCall = NULL;
432
 
    selectedCall = calltab_get_selected_call(active_calltree);
433
 
    
434
 
    if(selectedCall)
435
 
    {
436
 
        switch(selectedCall->_state)
437
 
        {
 
444
    selectedCall = calltab_get_selected_call (active_calltree);
 
445
 
 
446
    if (selectedCall) {
 
447
        switch (selectedCall->_state) {
438
448
            case CALL_STATE_DIALING:
439
449
                sflphone_place_call (selectedCall);
 
450
 
 
451
                // if instant messaging window is visible, create new tab (deleted automatically if not used)
 
452
                if (im_window_is_visible())
 
453
                    im_widget_display ( (IMWidget **) (&selectedCall->_im_widget), NULL, selectedCall->_callID, NULL);
 
454
 
440
455
                break;
441
456
            case CALL_STATE_INCOMING:
442
457
                selectedCall->_history_state = INCOMING;
443
 
                calltree_update_call( history, selectedCall, NULL);
 
458
                calltree_update_call (history, selectedCall, NULL);
 
459
 
 
460
                // if instant messaging window is visible, create new tab (deleted automatically if not used)
 
461
                if (im_window_is_visible())
 
462
                    im_widget_display ( (IMWidget **) (&selectedCall->_im_widget), NULL, selectedCall->_callID, NULL);
 
463
 
444
464
                dbus_accept (selectedCall);
445
 
                DEBUG("from sflphone_pick_up : "); stop_notification();
 
465
                DEBUG ("from sflphone_pick_up : ");
 
466
                stop_notification();
446
467
                break;
447
468
            case CALL_STATE_HOLD:
448
469
                sflphone_new_call();
459
480
                sflphone_new_call();
460
481
                break;
461
482
            default:
462
 
                WARN("Should not happen in sflphone_pick_up()!");
 
483
                WARN ("Should not happen in sflphone_pick_up()!");
463
484
                break;
464
485
        }
465
 
    }
466
 
    else {
 
486
    } else {
467
487
        sflphone_new_call();
468
488
    }
469
489
 
470
490
}
471
491
 
472
 
    void
 
492
void
473
493
sflphone_on_hold ()
474
494
{
475
 
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls);
476
 
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree);
477
 
 
478
 
    DEBUG("sflphone_on_hold");
479
 
    if(selectedCall)
480
 
    {
481
 
        switch(selectedCall->_state)
482
 
        {
 
495
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
 
496
    conference_obj_t * selectedConf = calltab_get_selected_conf (active_calltree);
 
497
 
 
498
    DEBUG ("sflphone_on_hold");
 
499
 
 
500
    if (selectedCall) {
 
501
        switch (selectedCall->_state) {
483
502
            case CALL_STATE_CURRENT:
484
503
                dbus_hold (selectedCall);
485
504
                break;
488
507
                break;
489
508
 
490
509
            default:
491
 
                WARN("Should not happen in sflphone_on_hold!");
 
510
                WARN ("Should not happen in sflphone_on_hold!");
492
511
                break;
493
512
        }
494
 
    }
495
 
    else if (selectedConf) {
496
 
        dbus_hold_conference(selectedConf);
 
513
    } else if (selectedConf) {
 
514
        dbus_hold_conference (selectedConf);
497
515
    }
498
516
}
499
517
 
500
 
    void
 
518
void
501
519
sflphone_off_hold ()
502
520
{
503
 
    DEBUG("sflphone_off_hold");
504
 
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls);
505
 
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree);
 
521
    DEBUG ("sflphone_off_hold");
 
522
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
 
523
    conference_obj_t * selectedConf = calltab_get_selected_conf (active_calltree);
506
524
 
507
 
    if(selectedCall)
508
 
    {
509
 
        switch(selectedCall->_state)
510
 
        {
 
525
    if (selectedCall) {
 
526
        switch (selectedCall->_state) {
511
527
            case CALL_STATE_HOLD:
512
528
                dbus_unhold (selectedCall);
513
529
                break;
514
530
            default:
515
 
                WARN("Should not happen in sflphone_off_hold ()!");
 
531
                WARN ("Should not happen in sflphone_off_hold ()!");
516
532
                break;
517
533
        }
518
 
    }
519
 
    else if (selectedConf) {
520
 
 
521
 
        
522
 
        dbus_unhold_conference(selectedConf);
523
 
    }
524
 
    /*
525
 
    if(dbus_get_is_recording(selectedCall))
526
 
    {
527
 
        DEBUG("Currently recording!");
528
 
    }
529
 
    else
530
 
    {
531
 
        DEBUG("Not recording currently");
532
 
    }
533
 
    */
 
534
    } else if (selectedConf) {
 
535
 
 
536
 
 
537
        dbus_unhold_conference (selectedConf);
 
538
    }
534
539
}
535
540
 
536
541
 
537
 
    void
538
 
sflphone_fail( callable_obj_t * c )
 
542
void
 
543
sflphone_fail (callable_obj_t * c)
539
544
{
540
545
    c->_state = CALL_STATE_FAILURE;
541
 
    calltree_update_call(current_calls, c, NULL);
 
546
    calltree_update_call (current_calls, c, NULL);
542
547
    update_actions();
543
548
}
544
549
 
545
 
    void
546
 
sflphone_busy( callable_obj_t * c )
 
550
void
 
551
sflphone_busy (callable_obj_t * c)
547
552
{
548
553
    c->_state = CALL_STATE_BUSY;
549
 
    calltree_update_call(current_calls, c, NULL);
 
554
    calltree_update_call (current_calls, c, NULL);
550
555
    update_actions();
551
556
}
552
557
 
553
 
    void
554
 
sflphone_current( callable_obj_t * c )
 
558
void
 
559
sflphone_current (callable_obj_t * c)
555
560
{
556
561
 
557
 
    if( c->_state != CALL_STATE_HOLD )
 
562
    if (c->_state != CALL_STATE_HOLD)
558
563
        set_timestamp (&c->_time_start);
 
564
 
559
565
    c->_state = CALL_STATE_CURRENT;
560
 
    calltree_update_call(current_calls, c, NULL);
 
566
    calltree_update_call (current_calls, c, NULL);
561
567
    update_actions();
562
568
}
563
569
 
564
 
    void
565
 
sflphone_record( callable_obj_t * c )
 
570
void
 
571
sflphone_record (callable_obj_t * c)
566
572
{
567
 
    if( c->_state != CALL_STATE_HOLD )
 
573
    if (c->_state != CALL_STATE_HOLD)
568
574
        set_timestamp (&c->_time_start);
 
575
 
569
576
    c->_state = CALL_STATE_RECORD;
570
 
    calltree_update_call(current_calls, c, NULL);
 
577
    calltree_update_call (current_calls, c, NULL);
571
578
    update_actions();
572
579
}
573
580
 
574
 
    void
 
581
void
575
582
sflphone_set_transfert()
576
583
{
577
 
    callable_obj_t * c = calltab_get_selected_call(current_calls);
578
 
    if(c)
579
 
    {
 
584
    callable_obj_t * c = calltab_get_selected_call (current_calls);
 
585
 
 
586
    if (c) {
580
587
        c->_state = CALL_STATE_TRANSFERT;
581
 
        c->_trsft_to = g_strdup("");
582
 
        calltree_update_call(current_calls, c, NULL);
 
588
        c->_trsft_to = g_strdup ("");
 
589
        calltree_update_call (current_calls, c, NULL);
583
590
    }
 
591
 
584
592
    update_actions();
585
593
}
586
594
 
587
 
    void
 
595
void
588
596
sflphone_unset_transfert()
589
597
{
590
 
    callable_obj_t * c = calltab_get_selected_call(current_calls);
591
 
    if(c)
592
 
    {
 
598
    callable_obj_t * c = calltab_get_selected_call (current_calls);
 
599
 
 
600
    if (c) {
593
601
        c->_state = CALL_STATE_CURRENT;
594
 
        c->_trsft_to = g_strdup("");
595
 
        calltree_update_call(current_calls, c, NULL);
 
602
        c->_trsft_to = g_strdup ("");
 
603
        calltree_update_call (current_calls, c, NULL);
596
604
    }
 
605
 
597
606
    update_actions();
598
607
}
599
608
 
600
 
    void
601
 
sflphone_display_transfer_status(const gchar* message)
 
609
void
 
610
sflphone_display_transfer_status (const gchar* message)
602
611
{
603
 
    statusbar_push_message( message , __MSG_ACCOUNT_DEFAULT);
 
612
    statusbar_push_message (message , NULL, __MSG_ACCOUNT_DEFAULT);
604
613
}
605
614
 
606
 
    void
 
615
void
607
616
sflphone_incoming_call (callable_obj_t * c)
608
617
{
609
 
        gchar *msg = "";
 
618
    gchar *msg = "";
610
619
 
611
620
    c->_history_state = MISSED;
612
 
    calllist_add ( current_calls, c );
613
 
    calllist_add( history, c );
614
 
    calltree_add_call( current_calls, c, NULL);
 
621
    calllist_add (current_calls, c);
 
622
    calllist_add (history, c);
 
623
    calltree_add_call (current_calls, c, NULL);
615
624
    update_actions();
616
625
    calltree_display (current_calls);
617
 
        
618
 
        // Change the status bar if we are dealing with a direct SIP call
619
 
    if(_is_direct_call(c)) {
620
 
                msg = g_markup_printf_escaped (_("Direct SIP call"));
621
 
        statusbar_pop_message(__MSG_ACCOUNT_DEFAULT);
622
 
        statusbar_push_message( msg , __MSG_ACCOUNT_DEFAULT);
623
 
        g_free(msg);
624
 
        }
 
626
 
 
627
    // Change the status bar if we are dealing with a direct SIP call
 
628
    if (_is_direct_call (c)) {
 
629
        msg = g_markup_printf_escaped (_ ("Direct SIP call"));
 
630
        statusbar_pop_message (__MSG_ACCOUNT_DEFAULT);
 
631
        statusbar_push_message (msg , NULL, __MSG_ACCOUNT_DEFAULT);
 
632
        g_free (msg);
 
633
    }
625
634
}
626
635
 
627
 
    void
628
 
process_dialing(callable_obj_t * c, guint keyval, gchar * key)
 
636
void
 
637
process_dialing (callable_obj_t * c, guint keyval, gchar * key)
629
638
{
630
639
    // We stop the tone
631
 
    if(strlen(c->_peer_number) == 0 && c->_state != CALL_STATE_TRANSFERT){
632
 
        dbus_start_tone( FALSE , 0 );
 
640
    if (strlen (c->_peer_number) == 0 && c->_state != CALL_STATE_TRANSFERT) {
 
641
        dbus_start_tone (FALSE , 0);
633
642
        //dbus_play_dtmf( key );
634
643
    }
635
644
 
636
 
    DEBUG("process_dialing : keyval : %i",keyval);
637
 
    DEBUG("process_dialing : key : %s",key);
 
645
    DEBUG ("process_dialing : keyval : %i",keyval);
 
646
    DEBUG ("process_dialing : key : %s",key);
638
647
 
639
 
    switch (keyval)
640
 
    {
 
648
    switch (keyval) {
641
649
        case 65293: /* ENTER */
642
650
        case 65421: /* ENTER numpad */
643
 
            sflphone_place_call(c);
 
651
            sflphone_place_call (c);
644
652
            break;
645
653
        case 65307: /* ESCAPE */
646
 
            sflphone_hang_up(c);
 
654
            sflphone_hang_up (c);
647
655
            break;
648
 
        case 65288: /* BACKSPACE */
649
 
            {  /* Brackets mandatory because of local vars */
650
 
                gchar * before = c->_peer_number;
651
 
                if(strlen(c->_peer_number) >= 1){
652
 
 
653
 
                                        if (c->_state == CALL_STATE_TRANSFERT)
654
 
                                        {
655
 
                                                // Process backspace if and only if string not NULL
656
 
                                                if(strlen(c->_trsft_to) > 0)
657
 
                                                     c->_trsft_to = g_strndup (c->_trsft_to, strlen(c->_trsft_to) - 1);
658
 
                                        }
659
 
                                        else
660
 
                                        {
661
 
                                                c->_peer_number = g_strndup(c->_peer_number, strlen(c->_peer_number) -1);
662
 
                                                g_free(before);
663
 
                                                DEBUG("TO: backspace %s", c->_peer_number);
664
 
                    }
665
 
                                        calltree_update_call(current_calls, c, NULL);
666
 
                }
667
 
                else if(strlen(c->_peer_number) == 0)
668
 
                {
669
 
                    if(c->_state != CALL_STATE_TRANSFERT)
670
 
                        dbus_hang_up(c);
671
 
                }
 
656
        case 65288: { /* BACKSPACE */
 
657
            /* Brackets mandatory because of local vars */
 
658
            gchar * before = c->_peer_number;
 
659
 
 
660
            if (strlen (c->_peer_number) >= 1) {
 
661
 
 
662
                if (c->_state == CALL_STATE_TRANSFERT) {
 
663
                    // Process backspace if and only if string not NULL
 
664
                    if (strlen (c->_trsft_to) > 0)
 
665
                        c->_trsft_to = g_strndup (c->_trsft_to, strlen (c->_trsft_to) - 1);
 
666
                } else {
 
667
                    c->_peer_number = g_strndup (c->_peer_number, strlen (c->_peer_number) -1);
 
668
                    g_free (before);
 
669
                    DEBUG ("TO: backspace %s", c->_peer_number);
 
670
                }
 
671
 
 
672
                calltree_update_call (current_calls, c, NULL);
 
673
            } else if (strlen (c->_peer_number) == 0) {
 
674
                if (c->_state != CALL_STATE_TRANSFERT)
 
675
                    dbus_hang_up (c);
672
676
            }
673
 
            break;
 
677
        }
 
678
        break;
674
679
        case 65289: /* TAB */
675
680
        case 65513: /* ALT */
676
681
        case 65507: /* CTRL */
678
683
        case 65509: /* CAPS */
679
684
            break;
680
685
        default:
 
686
 
681
687
            // if (keyval < 255 || (keyval >65453 && keyval < 65466))
682
 
            if (keyval < 127 || (keyval > 65400 && keyval < 65466))
683
 
            {
684
 
 
685
 
                if (c->_state == CALL_STATE_TRANSFERT)
686
 
                {
687
 
                    c->_trsft_to = g_strconcat(c->_trsft_to, key, NULL);
688
 
                }
689
 
                else
690
 
                {
691
 
                    dbus_play_dtmf( key );
692
 
                    c->_peer_number = g_strconcat(c->_peer_number, key, NULL);
693
 
                }
694
 
 
695
 
                if(c->_state == CALL_STATE_DIALING)
696
 
                {
 
688
            if (keyval < 127 || (keyval > 65400 && keyval < 65466)) {
 
689
 
 
690
                if (c->_state == CALL_STATE_TRANSFERT) {
 
691
                    c->_trsft_to = g_strconcat (c->_trsft_to, key, NULL);
 
692
                } else {
 
693
                    dbus_play_dtmf (key);
 
694
                    c->_peer_number = g_strconcat (c->_peer_number, key, NULL);
 
695
                }
 
696
 
 
697
                if (c->_state == CALL_STATE_DIALING) {
697
698
                    //g_free(c->_peer_name);
698
699
                    //c->_peer_name = g_strconcat("\"\" <", c->_peer_number, ">", NULL);
699
700
                }
700
 
                calltree_update_call(current_calls, c, NULL);
 
701
 
 
702
                calltree_update_call (current_calls, c, NULL);
701
703
            }
 
704
 
702
705
            break;
703
706
    }
704
707
}
705
708
 
706
709
 
707
 
    callable_obj_t *
 
710
callable_obj_t *
708
711
sflphone_new_call()
709
712
{
710
713
 
712
715
    callable_obj_t * current_selected_call;
713
716
    gchar *peer_name, *peer_number;
714
717
 
715
 
    DEBUG("sflphone_new_call");
716
 
 
717
 
    current_selected_call = calltab_get_selected_call(current_calls);
718
 
 
719
 
    if ((current_selected_call != NULL) && (current_selected_call->_confID == NULL))
720
 
        sflphone_on_hold();
 
718
    DEBUG ("Actions: Sflphone new call");
 
719
 
 
720
    current_selected_call = calltab_get_selected_call (current_calls);
 
721
 
 
722
    if ( (current_selected_call != NULL) && (current_selected_call->_confID == NULL))
 
723
        sflphone_on_hold();
721
724
 
722
725
    // Play a tone when creating a new call
723
 
    if( calllist_get_size(current_calls) == 0 )
724
 
        dbus_start_tone( TRUE , (current_account_has_new_message ()  > 0)? TONE_WITH_MESSAGE : TONE_WITHOUT_MESSAGE) ;
 
726
    if (calllist_get_size (current_calls) == 0)
 
727
        dbus_start_tone (TRUE , (current_account_has_new_message ()  > 0) ? TONE_WITH_MESSAGE : TONE_WITHOUT_MESSAGE) ;
725
728
 
726
 
    peer_number = g_strdup("");
 
729
    peer_number = g_strdup ("");
727
730
    peer_name = g_strdup ("");
728
731
    create_new_call (CALL, CALL_STATE_DIALING, "", "", peer_name, peer_number, &c);
729
732
 
737
740
}
738
741
 
739
742
 
740
 
    void
741
 
sflphone_keypad( guint keyval, gchar * key)
 
743
void
 
744
sflphone_keypad (guint keyval, gchar * key)
742
745
{
743
 
    callable_obj_t * c = calltab_get_selected_call(current_calls);
744
 
 
745
 
    if((active_calltree != current_calls) || (active_calltree == current_calls && !c))
746
 
    {
747
 
        DEBUG("Not in a call, not dialing, create a new call");
 
746
    callable_obj_t * c = calltab_get_selected_call (current_calls);
 
747
 
 
748
    if ( (active_calltree != current_calls) || (active_calltree == current_calls && !c)) {
 
749
        DEBUG ("Not in a call, not dialing, create a new call");
 
750
 
748
751
        //dbus_play_dtmf(key);
749
 
        switch (keyval)
750
 
        {
 
752
        switch (keyval) {
751
753
            case 65293: /* ENTER */
752
754
            case 65421: /* ENTER numpad */
753
755
            case 65307: /* ESCAPE */
754
756
                break;
755
757
            default:
756
758
                calltree_display (current_calls);
757
 
                process_dialing(sflphone_new_call(), keyval, key);
 
759
                process_dialing (sflphone_new_call(), keyval, key);
758
760
                break;
759
761
        }
760
 
    }
761
 
    else if(c)
762
 
    {
763
 
        DEBUG("Call is non-zero");
764
 
        switch(c->_state)
765
 
        {
 
762
    } else if (c) {
 
763
        DEBUG ("Call is non-zero");
 
764
 
 
765
        switch (c->_state) {
766
766
            case CALL_STATE_DIALING: // Currently dialing => edit number
767
 
                DEBUG("Writing a number");
768
 
                process_dialing(c, keyval, key);
 
767
                DEBUG ("Writing a number");
 
768
                process_dialing (c, keyval, key);
769
769
                break;
770
770
            case CALL_STATE_RECORD:
771
771
            case CALL_STATE_CURRENT:
772
 
                switch (keyval)
773
 
                {
 
772
 
 
773
                switch (keyval) {
774
774
                    case 65307: /* ESCAPE */
775
 
                        dbus_hang_up(c);
 
775
                        dbus_hang_up (c);
776
776
                        set_timestamp (&c->_time_stop);
777
 
                        calltree_update_call(history, c, NULL);
 
777
                        calltree_update_call (history, c, NULL);
778
778
                        break;
779
779
                    default:
780
780
                        // To play the dtmf when calling mail box for instance
781
 
                        dbus_play_dtmf(key);
782
 
                        if (keyval < 255 || (keyval >65453 && keyval < 65466))
783
 
                        {
 
781
                        dbus_play_dtmf (key);
 
782
 
 
783
                        if (keyval < 255 || (keyval >65453 && keyval < 65466)) {
784
784
                            //gchar * temp = g_strconcat(call_get_number(c), key, NULL);
785
785
                            //gchar * before = c->from;
786
786
                            //c->from = g_strconcat("\"",call_get_name(c) ,"\" <", temp, ">", NULL);
788
788
                            //g_free(temp);
789
789
                            //update_callable_obj_tree(current_calls,c);
790
790
                        }
 
791
 
791
792
                        break;
792
793
                }
 
794
 
793
795
                break;
794
796
            case CALL_STATE_INCOMING:
795
 
                switch (keyval)
796
 
                {
 
797
 
 
798
                switch (keyval) {
797
799
                    case 65293: /* ENTER */
798
800
                    case 65421: /* ENTER numpad */
799
801
                        c->_history_state = INCOMING;
800
 
                        calltree_update_call(history, c, NULL);
801
 
                        dbus_accept(c);
802
 
                        DEBUG("from sflphone_keypad ( enter ) : "); stop_notification();
 
802
                        calltree_update_call (history, c, NULL);
 
803
                        dbus_accept (c);
 
804
                        DEBUG ("from sflphone_keypad ( enter ) : ");
 
805
                        stop_notification();
803
806
                        break;
804
807
                    case 65307: /* ESCAPE */
805
 
                        dbus_refuse(c);
806
 
                        DEBUG("from sflphone_keypad ( escape ) : "); stop_notification();
 
808
                        dbus_refuse (c);
 
809
                        DEBUG ("from sflphone_keypad ( escape ) : ");
 
810
                        stop_notification();
807
811
                        break;
808
812
                }
 
813
 
809
814
                break;
810
815
            case CALL_STATE_TRANSFERT:
811
 
                switch (keyval)
812
 
                {
 
816
 
 
817
                switch (keyval) {
813
818
                    case 65293: /* ENTER */
814
819
                    case 65421: /* ENTER numpad */
815
 
                        dbus_transfert(c);
 
820
                        dbus_transfert (c);
816
821
                        set_timestamp (&c->_time_stop);
817
822
                        break;
818
823
                    case 65307: /* ESCAPE */
819
 
                        sflphone_unset_transfert(c);
 
824
                        sflphone_unset_transfert (c);
820
825
                        break;
821
826
                    default: // When a call is on transfert, typing new numbers will add it to c->_peer_number
822
 
                        process_dialing(c, keyval, key);
 
827
                        process_dialing (c, keyval, key);
823
828
                        break;
824
829
                }
 
830
 
825
831
                break;
826
832
            case CALL_STATE_HOLD:
827
 
                switch (keyval)
828
 
                {
 
833
 
 
834
                switch (keyval) {
829
835
                    case 65293: /* ENTER */
830
836
                    case 65421: /* ENTER numpad */
831
 
                        dbus_unhold(c);
 
837
                        dbus_unhold (c);
832
838
                        break;
833
839
                    case 65307: /* ESCAPE */
834
 
                        dbus_hang_up(c);
 
840
                        dbus_hang_up (c);
835
841
                        break;
836
842
                    default: // When a call is on hold, typing new numbers will create a new call
837
 
                        process_dialing(sflphone_new_call(), keyval, key);
 
843
                        process_dialing (sflphone_new_call(), keyval, key);
838
844
                        break;
839
845
                }
 
846
 
840
847
                break;
841
848
            case CALL_STATE_RINGING:
842
849
            case CALL_STATE_BUSY:
843
850
            case CALL_STATE_FAILURE:
 
851
 
844
852
                //c->_stop = 0;
845
 
                switch (keyval)
846
 
                {
 
853
                switch (keyval) {
847
854
                    case 65307: /* ESCAPE */
848
 
                        dbus_hang_up(c);
 
855
                        dbus_hang_up (c);
849
856
                        //c->_stop = 0;
850
 
                        calltree_update_call(history, c, NULL);
 
857
                        calltree_update_call (history, c, NULL);
851
858
                        break;
852
859
                }
 
860
 
853
861
                break;
854
862
            default:
855
863
                break;
856
864
        }
857
865
 
858
 
    }
859
 
    else {
 
866
    } else {
860
867
        sflphone_new_call();
861
868
    }
862
869
}
863
870
 
864
 
static int _place_direct_call(const callable_obj_t * c) {
 
871
static int _place_direct_call (const callable_obj_t * c)
 
872
{
865
873
    if (c->_state == CALL_STATE_DIALING) {
866
874
        dbus_place_call (c);
867
875
    } else {
868
876
        return -1;
869
877
    }
 
878
 
870
879
    return 0;
871
880
}
872
881
 
873
 
static int _place_registered_call(callable_obj_t * c) {
 
882
static int _place_registered_call (callable_obj_t * c)
 
883
{
874
884
 
875
885
    account_t * current = NULL;
876
 
  
877
 
    if(c == NULL) {
878
 
        DEBUG("callable_obj_t is NULL in _place_registered_call");
 
886
 
 
887
    if (c == NULL) {
 
888
        DEBUG ("Actions: Callable_obj_t is NULL in _place_registered_call");
879
889
        return -1;
880
890
    }
881
 
    
 
891
 
882
892
    if (c->_state != CALL_STATE_DIALING) {
883
893
        return -1;
884
894
    }
885
 
  
886
 
    if(g_strcasecmp(c->_peer_number, "") == 0) {
 
895
 
 
896
    if (g_strcasecmp (c->_peer_number, "") == 0) {
887
897
        return -1;
888
898
    }
889
 
    
890
 
    if( account_list_get_size() == 0 ) {
 
899
 
 
900
    if (account_list_get_size() == 0) {
891
901
        notify_no_accounts();
892
 
        sflphone_fail(c);
 
902
        sflphone_fail (c);
893
903
        return -1;
894
 
    } 
895
 
    
896
 
    if( account_list_get_by_state( ACCOUNT_STATE_REGISTERED ) == NULL ) {
 
904
    }
 
905
 
 
906
    if (account_list_get_by_state (ACCOUNT_STATE_REGISTERED) == NULL) {
 
907
        DEBUG ("Actions: No registered account, cannot make a call");
897
908
        notify_no_registered_accounts();
898
 
        sflphone_fail(c);
 
909
        sflphone_fail (c);
899
910
        return -1;
900
911
    }
901
 
    
902
 
    if(g_strcasecmp(c->_accountID, "") != 0) {
903
 
        current = account_list_get_by_id(c->_accountID);
 
912
 
 
913
    DEBUG ("Actions: Get account for this call");
 
914
 
 
915
    if (g_strcasecmp (c->_accountID, "") != 0) {
 
916
        DEBUG ("Actions: Account %s already set for this call", c->_accountID);
 
917
        current = account_list_get_by_id (c->_accountID);
904
918
    } else {
 
919
        DEBUG ("Actions: No account set for this call, use first of the list");
905
920
        current = account_list_get_current();
906
921
    }
907
922
 
908
 
    if(current == NULL) { 
909
 
        DEBUG("Unexpected condition: account_t is NULL in %s at %d for accountID %s", __FILE__, __LINE__, c->_accountID);
 
923
    if (current == NULL) {
 
924
        DEBUG ("Actions: Unexpected condition: account_t is NULL in %s at %d for accountID %s", __FILE__, __LINE__, c->_accountID);
910
925
        return -1;
911
 
    }   
912
 
                        
913
 
    if(g_strcasecmp(g_hash_table_lookup( current->properties, "Status"),"REGISTERED")==0) {
 
926
    }
 
927
 
 
928
    if (g_strcasecmp (g_hash_table_lookup (current->properties, "Status"),"REGISTERED") ==0) {
914
929
        /* The call is made with the current account */
915
 
        c->_accountID = current->accountID;
916
 
        dbus_place_call(c);
 
930
        // free memory for previous account id and get a new one
 
931
        g_free (c->_accountID);
 
932
        c->_accountID = g_strdup (current->accountID);
 
933
        dbus_place_call (c);
917
934
    } else {
918
 
       /* Place the call with the first registered account
919
 
        * and switch the current account.
920
 
        * If we are here, we can be sure that there is at least one. 
921
 
        */
922
 
        current = account_list_get_by_state( ACCOUNT_STATE_REGISTERED );
923
 
        c->_accountID = current->accountID;
924
 
        dbus_place_call(c);
925
 
        notify_current_account( current );
926
 
    }        
 
935
        /* Place the call with the first registered account
 
936
         * and switch the current account.
 
937
         * If we are here, we can be sure that there is at least one.
 
938
         */
 
939
        current = account_list_get_by_state (ACCOUNT_STATE_REGISTERED);
 
940
        g_free (c->_accountID);
 
941
        c->_accountID = g_strdup (current->accountID);
 
942
        dbus_place_call (c);
 
943
        notify_current_account (current);
 
944
    }
927
945
 
928
946
    c->_history_state = OUTGOING;
929
 
    calllist_add(history, c);                
 
947
    calllist_add (history, c);
930
948
    return 0;
931
949
}
932
950
 
933
 
    void
934
 
sflphone_place_call ( callable_obj_t * c )
 
951
void
 
952
sflphone_place_call (callable_obj_t * c)
935
953
{
936
 
        gchar *msg = "";
937
 
 
938
 
    DEBUG("Placing call with %s @ %s and accountid %s", c->_peer_name, c->_peer_number, c->_accountID);
939
 
    
940
 
    if(c == NULL) {
941
 
        DEBUG("Unexpected condition: callable_obj_t is null in %s at %d", __FILE__, __LINE__);
 
954
    gchar *msg = "";
 
955
 
 
956
    DEBUG ("Actions: Placing call with %s @ %s and accountid %s", c->_peer_name, c->_peer_number, c->_accountID);
 
957
 
 
958
    if (c == NULL) {
 
959
        DEBUG ("Actions: Unexpected condition: callable_obj_t is null in %s at %d", __FILE__, __LINE__);
942
960
        return;
943
961
    }
944
962
 
945
 
    if(_is_direct_call(c)) {
946
 
                msg = g_markup_printf_escaped (_("Direct SIP call"));
947
 
        statusbar_pop_message(__MSG_ACCOUNT_DEFAULT);
948
 
        statusbar_push_message( msg , __MSG_ACCOUNT_DEFAULT);
949
 
        g_free(msg);
950
 
        if(_place_direct_call(c) < 0) {
951
 
            DEBUG("An error occured while placing direct call in %s at %d", __FILE__, __LINE__);
952
 
            return;
953
 
        }
954
 
    } else {
955
 
        if(_place_registered_call(c) < 0) {
956
 
            DEBUG("An error occured while placing registered call in %s at %d", __FILE__, __LINE__);
957
 
            return;
958
 
        }
959
 
    }
960
 
}
961
 
 
962
 
 
963
 
    void
964
 
sflphone_detach_participant(const gchar* callID)
965
 
{
966
 
    DEBUG("Action: Detach participant from conference");
967
 
 
968
 
    if(callID == NULL) {
969
 
        callable_obj_t * selectedCall = calltab_get_selected_call(current_calls);
970
 
        DEBUG("Action: Detach participant %s", selectedCall->_callID);
971
 
 
972
 
        if(selectedCall->_confID) {
973
 
            g_free(selectedCall->_confID);
974
 
            selectedCall->_confID = NULL;
975
 
        }
976
 
 
977
 
        calltree_remove_call(current_calls, selectedCall, NULL);
978
 
        calltree_add_call(current_calls, selectedCall, NULL);
979
 
        dbus_detach_participant(selectedCall->_callID);
980
 
    }
981
 
    else {
982
 
        callable_obj_t * selectedCall = calllist_get(current_calls, callID);
983
 
        DEBUG("Action: Darticipant %s", callID);
984
 
 
985
 
        if(selectedCall->_confID) {
986
 
            g_free(selectedCall->_confID); 
987
 
            selectedCall->_confID = NULL;
988
 
        }
989
 
 
990
 
        calltree_remove_call(current_calls, selectedCall, NULL);
991
 
        calltree_add_call(current_calls, selectedCall, NULL);
992
 
        dbus_detach_participant(callID);        
993
 
    }
994
 
     
995
 
}
996
 
 
997
 
    void
998
 
sflphone_join_participant(const gchar* sel_callID, const gchar* drag_callID)
999
 
{
1000
 
    DEBUG("sflphone join participants %s and %s", sel_callID, drag_callID);
1001
 
 
1002
 
    
1003
 
    dbus_join_participant(sel_callID, drag_callID);
1004
 
}
1005
 
 
1006
 
 
1007
 
    void
1008
 
sflphone_add_participant(const gchar* callID, const gchar* confID)
1009
 
{
1010
 
    DEBUG("sflphone add participant %s to conference %s", callID, confID);
1011
 
 
1012
 
    dbus_add_participant(callID, confID);
1013
 
}
1014
 
 
1015
 
    void
 
963
    if (_is_direct_call (c)) {
 
964
        msg = g_markup_printf_escaped (_ ("Direct SIP call"));
 
965
        statusbar_pop_message (__MSG_ACCOUNT_DEFAULT);
 
966
        statusbar_push_message (msg , NULL, __MSG_ACCOUNT_DEFAULT);
 
967
        g_free (msg);
 
968
 
 
969
        if (_place_direct_call (c) < 0) {
 
970
            DEBUG ("An error occured while placing direct call in %s at %d", __FILE__, __LINE__);
 
971
            return;
 
972
        }
 
973
    } else {
 
974
        if (_place_registered_call (c) < 0) {
 
975
            DEBUG ("An error occured while placing registered call in %s at %d", __FILE__, __LINE__);
 
976
            return;
 
977
        }
 
978
    }
 
979
}
 
980
 
 
981
 
 
982
void
 
983
sflphone_detach_participant (const gchar* callID)
 
984
{
 
985
    DEBUG ("Action: Detach participant from conference");
 
986
 
 
987
    if (callID == NULL) {
 
988
        callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
 
989
        DEBUG ("Action: Detach participant %s", selectedCall->_callID);
 
990
 
 
991
        if (selectedCall->_confID) {
 
992
            g_free (selectedCall->_confID);
 
993
            selectedCall->_confID = NULL;
 
994
        }
 
995
 
 
996
        // Instant messaging widget should have been deactivated during the conference
 
997
        if (selectedCall->_im_widget)
 
998
            im_widget_update_state (IM_WIDGET (selectedCall->_im_widget), TRUE);
 
999
 
 
1000
        calltree_remove_call (current_calls, selectedCall, NULL);
 
1001
        calltree_add_call (current_calls, selectedCall, NULL);
 
1002
        dbus_detach_participant (selectedCall->_callID);
 
1003
    } else {
 
1004
        callable_obj_t * selectedCall = calllist_get (current_calls, callID);
 
1005
        DEBUG ("Action: Darticipant %s", callID);
 
1006
 
 
1007
        if (selectedCall->_confID) {
 
1008
            g_free (selectedCall->_confID);
 
1009
            selectedCall->_confID = NULL;
 
1010
        }
 
1011
 
 
1012
        // Instant messagin widget should have been deactivated during the conference
 
1013
        if (selectedCall->_im_widget)
 
1014
            im_widget_update_state (IM_WIDGET (selectedCall->_im_widget), TRUE);
 
1015
 
 
1016
        calltree_remove_call (current_calls, selectedCall, NULL);
 
1017
        calltree_add_call (current_calls, selectedCall, NULL);
 
1018
        dbus_detach_participant (callID);
 
1019
    }
 
1020
 
 
1021
}
 
1022
 
 
1023
void
 
1024
sflphone_join_participant (const gchar* sel_callID, const gchar* drag_callID)
 
1025
{
 
1026
    DEBUG ("sflphone join participants %s and %s", sel_callID, drag_callID);
 
1027
 
 
1028
 
 
1029
    dbus_join_participant (sel_callID, drag_callID);
 
1030
}
 
1031
 
 
1032
 
 
1033
void
 
1034
sflphone_add_participant (const gchar* callID, const gchar* confID)
 
1035
{
 
1036
    DEBUG ("sflphone add participant %s to conference %s", callID, confID);
 
1037
 
 
1038
    dbus_add_participant (callID, confID);
 
1039
}
 
1040
 
 
1041
void
1016
1042
sflphone_add_conference()
1017
1043
{
1018
 
    DEBUG("sflphone add a conference to tree view");
 
1044
    DEBUG ("sflphone add a conference to tree view");
1019
1045
    // dbus_join_participant(selected_call, dragged_call);
1020
1046
}
1021
1047
 
1022
 
    void
1023
 
sflphone_join_conference(const gchar* sel_confID, const gchar* drag_confID)
1024
 
{
1025
 
    DEBUG("sflphone join two conference");
1026
 
    dbus_join_conference(sel_confID, drag_confID);
1027
 
}
1028
 
 
1029
 
void
1030
 
sflphone_add_main_participant(const conference_obj_t * c)
1031
 
{
1032
 
    DEBUG("sflphone add main participant");
1033
 
    dbus_add_main_participant(c->_confID);
1034
 
}
1035
 
 
1036
 
void
1037
 
sflphone_conference_on_hold(const conference_obj_t * c)
1038
 
{
1039
 
    DEBUG("sflphone_conference_on_hold");
1040
 
    dbus_hold_conference(c);
1041
 
}
1042
 
 
1043
 
void
1044
 
sflphone_conference_off_hold(const conference_obj_t * c)
1045
 
{
1046
 
    DEBUG("sflphone_conference_off_hold");
1047
 
    dbus_unhold_conference(c);
1048
 
}
1049
 
 
1050
 
 
1051
 
    void
 
1048
void
 
1049
sflphone_join_conference (const gchar* sel_confID, const gchar* drag_confID)
 
1050
{
 
1051
    DEBUG ("sflphone join two conference");
 
1052
    dbus_join_conference (sel_confID, drag_confID);
 
1053
}
 
1054
 
 
1055
void
 
1056
sflphone_add_main_participant (const conference_obj_t * c)
 
1057
{
 
1058
    DEBUG ("sflphone add main participant");
 
1059
    dbus_add_main_participant (c->_confID);
 
1060
}
 
1061
 
 
1062
void
 
1063
sflphone_conference_on_hold (const conference_obj_t * c)
 
1064
{
 
1065
    DEBUG ("sflphone_conference_on_hold");
 
1066
    dbus_hold_conference (c);
 
1067
}
 
1068
 
 
1069
void
 
1070
sflphone_conference_off_hold (const conference_obj_t * c)
 
1071
{
 
1072
    DEBUG ("sflphone_conference_off_hold");
 
1073
    dbus_unhold_conference (c);
 
1074
}
 
1075
 
 
1076
 
 
1077
void
1052
1078
sflphone_rec_call()
1053
1079
{
1054
 
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls);
1055
 
    conference_obj_t * selectedConf = calltab_get_selected_conf(current_calls);
1056
 
 
1057
 
    if(selectedCall)
1058
 
    {
1059
 
        dbus_set_record(selectedCall->_callID);
1060
 
        switch(selectedCall->_state)
1061
 
        {
 
1080
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
 
1081
    conference_obj_t * selectedConf = calltab_get_selected_conf (current_calls);
 
1082
 
 
1083
    if (selectedCall) {
 
1084
        DEBUG ("SFLphone: Set record for selected call");
 
1085
        dbus_set_record (selectedCall->_callID);
 
1086
 
 
1087
        switch (selectedCall->_state) {
1062
1088
            case CALL_STATE_CURRENT:
1063
 
                selectedCall->_state = CALL_STATE_RECORD;
1064
 
                break;
 
1089
                selectedCall->_state = CALL_STATE_RECORD;
 
1090
                break;
1065
1091
            case CALL_STATE_RECORD:
1066
 
                selectedCall->_state = CALL_STATE_CURRENT;
1067
 
                break;
 
1092
                selectedCall->_state = CALL_STATE_CURRENT;
 
1093
                break;
1068
1094
            default:
1069
 
                WARN("Should not happen in sflphone_off_hold ()!");
1070
 
                break;
1071
 
        }
1072
 
    }
1073
 
    else if(selectedConf)
1074
 
    {
1075
 
        dbus_set_record(selectedConf->_confID);
1076
 
        switch(selectedConf->_state)
1077
 
        {
 
1095
                WARN ("Should not happen in sflphone_off_hold ()!");
 
1096
                break;
 
1097
        }
 
1098
    } else if (selectedConf) {
 
1099
        DEBUG ("SFLphone: Set record for selected conf");
 
1100
        dbus_set_record (selectedConf->_confID);
 
1101
 
 
1102
        switch (selectedConf->_state) {
1078
1103
            case CONFERENCE_STATE_ACTIVE_ATACHED:
1079
 
                selectedCall->_state = CONFERENCE_STATE_RECORD;
1080
 
                break;
 
1104
                selectedConf->_state = CONFERENCE_STATE_RECORD;
 
1105
                break;
1081
1106
            case CONFERENCE_STATE_RECORD:
1082
 
                selectedCall->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
1083
 
                break;
 
1107
                selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
 
1108
                break;
1084
1109
            default:
1085
 
                WARN("Should not happen in sflphone_off_hold ()!");
1086
 
                break;
1087
 
        }
 
1110
                WARN ("Should not happen in sflphone_off_hold ()!");
 
1111
                break;
 
1112
        }
1088
1113
    }
1089
 
    calltree_update_call(current_calls, selectedCall, NULL);
 
1114
 
 
1115
    calltree_update_call (current_calls, selectedCall, NULL);
1090
1116
    update_actions();
1091
 
 
1092
 
    // gchar* codname = sflphone_get_current_codec_name();
1093
 
    // DEBUG("sflphone_get_current_codec_name: %s",codname);
1094
 
}
1095
 
 
1096
 
void sflphone_fill_codec_list () {
1097
 
 
1098
 
        guint account_list_size;
1099
 
        guint i;
1100
 
        account_t *current = NULL;
1101
 
        gchar** codecs = NULL;
1102
 
 
1103
 
        DEBUG("SFLphone: Fill codec list");
1104
 
 
1105
 
        account_list_size = account_list_get_size ();
1106
 
 
1107
 
        for (i=0; i<account_list_size; i++)
1108
 
        {
1109
 
                current = account_list_get_nth (i);
1110
 
                if (current) {
1111
 
                        sflphone_fill_codec_list_per_account (&current);
1112
 
                }
1113
 
        }
1114
 
 
1115
 
        /*
1116
 
        if (codec_list_get_size() == 0) {
1117
 
 
1118
 
                // Error message
1119
 
                ERROR ("No audio codecs found");
1120
 
        dbus_unregister(getpid());
1121
 
        exit(0);
1122
 
    }*/
1123
 
}
1124
 
 
1125
 
void sflphone_fill_codec_list_per_account (account_t **account) {
 
1117
}
 
1118
 
 
1119
void sflphone_fill_codec_list ()
 
1120
{
 
1121
 
 
1122
    guint account_list_size;
 
1123
    guint i;
 
1124
    account_t *current = NULL;
 
1125
 
 
1126
    DEBUG ("SFLphone: Fill codec list");
 
1127
 
 
1128
    account_list_size = account_list_get_size ();
 
1129
 
 
1130
    for (i=0; i<account_list_size; i++) {
 
1131
        current = account_list_get_nth (i);
 
1132
 
 
1133
        if (current) {
 
1134
            sflphone_fill_codec_list_per_account (&current);
 
1135
        }
 
1136
    }
 
1137
 
 
1138
}
 
1139
 
 
1140
void sflphone_fill_codec_list_per_account (account_t **account)
 
1141
{
1126
1142
 
1127
1143
    gchar **order;
1128
 
    gchar** details;
1129
1144
    gchar** pl;
1130
 
    gchar *accountID;
1131
1145
    GQueue *codeclist;
1132
1146
    gboolean active = FALSE;
1133
1147
 
1134
 
    order = (gchar**) dbus_get_active_codec_list ((*account)->accountID);
 
1148
    order = (gchar**) dbus_get_active_codec_list ( (*account)->accountID);
1135
1149
 
1136
1150
    codeclist = (*account)->codecs;
1137
1151
 
1138
1152
    // First clean the list
1139
1153
    codec_list_clear (&codeclist);
1140
1154
 
1141
 
    if(!(*order))
1142
 
      ERROR("SFLphone: No codec list provided");
1143
 
 
1144
 
    for (pl=order; *pl; pl++)
1145
 
    {
1146
 
      codec_t * cpy = NULL;
1147
 
                
1148
 
      // Each account will have a copy of the system-wide capabilities
1149
 
      codec_create_new_from_caps (codec_list_get_by_payload ((gconstpointer) (size_t)atoi (*pl), NULL), &cpy);
1150
 
      if (cpy) {
1151
 
          cpy->is_active = TRUE;
1152
 
          codec_list_add (cpy, &codeclist);
1153
 
      }
1154
 
      else
1155
 
        ERROR ("SFLphone: Couldn't find codec");
1156
 
    }
1157
 
 
1158
 
        // Test here if we just added some active codec.
1159
 
        active = (codeclist->length == 0) ? TRUE : FALSE;
1160
 
 
1161
 
        guint caps_size = codec_list_get_size (), i=0;
1162
 
 
1163
 
        for (i=0; i<caps_size; i++) {
1164
 
                        
1165
 
                codec_t * current_cap = capabilities_get_nth (i);
1166
 
                // Check if this codec has already been enabled for this account
1167
 
                if (codec_list_get_by_payload ( (gconstpointer) (size_t)(current_cap->_payload), codeclist) == NULL) {
1168
 
                        // codec_t *cpy;
1169
 
                        // codec_create_new_from_caps (current_cap, &cpy);
1170
 
                        current_cap->is_active = active;
1171
 
                        codec_list_add (current_cap, &codeclist);
1172
 
                }
1173
 
                else {
1174
 
                }
1175
 
 
1176
 
        }
1177
 
        
1178
 
        (*account)->codecs = codeclist; 
1179
 
        
1180
 
        // call dbus function with array of strings
1181
 
        codec_list_update_to_daemon (*account);
1182
 
        
 
1155
    if (! (*order))
 
1156
        ERROR ("SFLphone: No codec list provided");
 
1157
 
 
1158
    for (pl=order; *pl; pl++) {
 
1159
        codec_t * cpy = NULL;
 
1160
 
 
1161
        // Each account will have a copy of the system-wide capabilities
 
1162
        codec_create_new_from_caps (codec_list_get_by_payload ( (gconstpointer) (size_t) atoi (*pl), NULL), &cpy);
 
1163
 
 
1164
        if (cpy) {
 
1165
            cpy->is_active = TRUE;
 
1166
            codec_list_add (cpy, &codeclist);
 
1167
        } else
 
1168
            ERROR ("SFLphone: Couldn't find codec");
 
1169
    }
 
1170
 
 
1171
    // Test here if we just added some active codec.
 
1172
    active = (codeclist->length == 0) ? TRUE : FALSE;
 
1173
 
 
1174
    guint caps_size = codec_list_get_size (), i=0;
 
1175
 
 
1176
    for (i=0; i<caps_size; i++) {
 
1177
 
 
1178
        codec_t * current_cap = capabilities_get_nth (i);
 
1179
 
 
1180
        // Check if this codec has already been enabled for this account
 
1181
        if (codec_list_get_by_payload ( (gconstpointer) (size_t) (current_cap->_payload), codeclist) == NULL) {
 
1182
            // codec_t *cpy;
 
1183
            // codec_create_new_from_caps (current_cap, &cpy);
 
1184
            current_cap->is_active = active;
 
1185
            codec_list_add (current_cap, &codeclist);
 
1186
        } else {
 
1187
        }
 
1188
 
 
1189
    }
 
1190
 
 
1191
    (*account)->codecs = codeclist;
 
1192
 
 
1193
    // call dbus function with array of strings
 
1194
    codec_list_update_to_daemon (*account);
 
1195
 
1183
1196
}
1184
1197
 
1185
1198
void sflphone_fill_call_list (void)
1186
1199
{
1187
1200
 
1188
 
    gchar** calls = (gchar**)dbus_get_call_list();
 
1201
    gchar** calls = (gchar**) dbus_get_call_list();
1189
1202
    gchar** pl;
1190
1203
    GHashTable *call_details;
1191
1204
    callable_obj_t *c;
1192
1205
    gchar *callID;
1193
1206
 
1194
 
    DEBUG("sflphone_fill_call_list");
 
1207
    DEBUG ("sflphone_fill_call_list");
1195
1208
 
1196
 
    if(calls)
1197
 
    {
1198
 
        for(pl=calls; *calls; calls++)
1199
 
        {
1200
 
            c = g_new0(callable_obj_t, 1);
1201
 
            callID = (gchar*)(*calls);
1202
 
            call_details = dbus_get_call_details(callID);
 
1209
    if (calls) {
 
1210
        for (pl=calls; *calls; calls++) {
 
1211
            c = g_new0 (callable_obj_t, 1);
 
1212
            callID = (gchar*) (*calls);
 
1213
            call_details = dbus_get_call_details (callID);
1203
1214
            create_new_call_from_details (callID, call_details, &c);
1204
 
            c->_callID = g_strdup(callID);
 
1215
            c->_callID = g_strdup (callID);
1205
1216
            c->_zrtp_confirmed = FALSE;
1206
1217
            // Add it to the list
1207
1218
            DEBUG ("Add call retrieved from server side: %s\n", c->_callID);
1213
1224
}
1214
1225
 
1215
1226
 
1216
 
void sflphone_fill_conference_list(void)
 
1227
void sflphone_fill_conference_list (void)
1217
1228
{
1218
1229
    // TODO Fetch the active conferences at client startup
1219
1230
 
1223
1234
    gchar* conf_id;
1224
1235
    conference_obj_t* conf;
1225
1236
 
1226
 
    DEBUG("sflphone_fill_conference_list");
 
1237
    DEBUG ("sflphone_fill_conference_list");
1227
1238
 
1228
1239
    conferences = dbus_get_conference_list();
1229
1240
 
1230
 
    if(conferences)
1231
 
    {
1232
 
        for (pl = conferences; *conferences; conferences++)
1233
 
        {
1234
 
            conf = g_new0(conference_obj_t, 1);
1235
 
            conf_id = (gchar*)(*conferences);
1236
 
 
1237
 
            DEBUG("   fetching conference: %s", conf_id);
1238
 
 
1239
 
            conference_details = (GHashTable*) dbus_get_conference_details(conf_id);
1240
 
            
1241
 
            create_new_conference_from_details (conf_id, conference_details, &conf);
1242
 
            
1243
 
            conf->_confID = g_strdup(conf_id);      
1244
 
 
1245
 
            conferencelist_add(conf);
1246
 
            calltree_add_conference (current_calls, conf);
1247
 
        }
 
1241
    if (conferences) {
 
1242
        for (pl = conferences; *conferences; conferences++) {
 
1243
            conf = g_new0 (conference_obj_t, 1);
 
1244
            conf_id = (gchar*) (*conferences);
 
1245
 
 
1246
            DEBUG ("   fetching conference: %s", conf_id);
 
1247
 
 
1248
            conference_details = (GHashTable*) dbus_get_conference_details (conf_id);
 
1249
 
 
1250
            create_new_conference_from_details (conf_id, conference_details, &conf);
 
1251
 
 
1252
            conf->_confID = g_strdup (conf_id);
 
1253
 
 
1254
            conferencelist_add (conf);
 
1255
            calltree_add_conference (current_calls, conf);
 
1256
        }
1248
1257
    }
1249
1258
}
1250
1259
 
1252
1261
{
1253
1262
    GHashTable *entries;
1254
1263
    GHashTableIter iter;
1255
 
    gpointer key, key_to_min, value;
 
1264
    gpointer key, value;
 
1265
    gpointer key_to_min = NULL;
1256
1266
    callable_obj_t *history_entry;
1257
 
 
1258
 
    int timestamp, min_timestamp;
 
1267
    int timestamp = 0;
 
1268
    int min_timestamp = 0;
1259
1269
 
1260
1270
    gboolean is_first;
1261
1271
 
1262
1272
    DEBUG ("Loading history ...");
1263
1273
 
1264
1274
    entries = dbus_get_history ();
 
1275
 
1265
1276
    if (entries) {
1266
1277
 
1267
 
        while(g_hash_table_size (entries)) {
1268
 
 
1269
 
            is_first = TRUE;
1270
 
 
1271
 
            // find lowest timestamp in map
1272
 
            g_hash_table_iter_init (&iter, entries);
1273
 
            while (g_hash_table_iter_next (&iter, &key, &value))  {
1274
 
 
1275
 
                timestamp = atoi((gchar*)key);
1276
 
 
1277
 
                if(is_first) {
1278
 
 
1279
 
                    // first iteration of the loop, init search
1280
 
                    min_timestamp = timestamp;
1281
 
                    key_to_min = key;
1282
 
 
1283
 
                    is_first = FALSE;
1284
 
                }
1285
 
                else {
1286
 
 
1287
 
                    // if lower, replace
1288
 
                    if(timestamp < min_timestamp) {
1289
 
 
1290
 
                        min_timestamp = timestamp;
1291
 
                        key_to_min = key;
1292
 
                    }
1293
 
                }
1294
 
            }
1295
 
 
1296
 
            if(g_hash_table_lookup_extended(entries, key_to_min, &key, &value)) {
1297
 
 
1298
 
                // do something with key and value 
1299
 
                create_history_entry_from_serialized_form ((gchar*)key, (gchar*)value, &history_entry);    
1300
 
                DEBUG("HISTORY ENTRY: %i\n", history_entry->_time_start);
1301
 
                // Add it and update the GUI
1302
 
                calllist_add (history, history_entry);
1303
 
                
1304
 
                // remove entry from map
1305
 
                g_hash_table_remove(entries, key_to_min);
1306
 
            }
1307
 
        }
 
1278
        while (g_hash_table_size (entries)) {
 
1279
 
 
1280
            is_first = TRUE;
 
1281
 
 
1282
            // find lowest timestamp in map
 
1283
            g_hash_table_iter_init (&iter, entries);
 
1284
 
 
1285
            while (g_hash_table_iter_next (&iter, &key, &value))  {
 
1286
 
 
1287
                timestamp = atoi ( (gchar*) key);
 
1288
 
 
1289
                if (is_first) {
 
1290
 
 
1291
                    // first iteration of the loop, init search
 
1292
                    min_timestamp = timestamp;
 
1293
                    key_to_min = key;
 
1294
 
 
1295
                    is_first = FALSE;
 
1296
                } else {
 
1297
 
 
1298
                    // if lower, replace
 
1299
                    if (timestamp < min_timestamp) {
 
1300
 
 
1301
                        min_timestamp = timestamp;
 
1302
                        key_to_min = key;
 
1303
                    }
 
1304
                }
 
1305
            }
 
1306
 
 
1307
            if (g_hash_table_lookup_extended (entries, key_to_min, &key, &value)) {
 
1308
 
 
1309
                // do something with key and value
 
1310
                create_history_entry_from_serialized_form ( (gchar*) key, (gchar*) value, &history_entry);
 
1311
                DEBUG ("HISTORY ENTRY: %i\n", history_entry->_time_start);
 
1312
                // Add it and update the GUI
 
1313
                calllist_add (history, history_entry);
 
1314
 
 
1315
                // remove entry from map
 
1316
                g_hash_table_remove (entries, key_to_min);
 
1317
            }
 
1318
        }
1308
1319
    }
1309
1320
}
1310
1321
 
1319
1330
 
1320
1331
    DEBUG ("Saving history ...");
1321
1332
 
1322
 
    result = g_hash_table_new(NULL, g_str_equal);
 
1333
    result = g_hash_table_new (NULL, g_str_equal);
1323
1334
    items = history->callQueue;
1324
1335
    size = calllist_get_size (history);
1325
1336
 
1326
 
    for (i=0; i<size; i++)
1327
 
    {
 
1337
    for (i=0; i<size; i++) {
1328
1338
        current = g_queue_peek_nth (items, i);
1329
 
        if (current)
1330
 
        {
 
1339
 
 
1340
        if (current) {
1331
1341
            value = serialize_history_entry (current);
1332
1342
            key = convert_timestamp_to_gchar (current->_time_start);
1333
 
            g_hash_table_replace(result, (gpointer) key,
1334
 
                    (gpointer) value);
 
1343
            g_hash_table_replace (result, (gpointer) key,
 
1344
                                  (gpointer) value);
1335
1345
        }
1336
1346
    }
1337
1347
 
1338
1348
    dbus_set_history (result);
1339
1349
 
1340
1350
    // Decrement the reference count
1341
 
    g_hash_table_unref(result);
 
1351
    g_hash_table_unref (result);
1342
1352
}
1343
1353
 
1344
 
   void
1345
 
sflphone_srtp_sdes_on(callable_obj_t * c)
 
1354
void
 
1355
sflphone_srtp_sdes_on (callable_obj_t * c)
1346
1356
{
1347
1357
 
1348
1358
    c->_srtp_state = SRTP_STATE_SDES_SUCCESS;
1349
1359
 
1350
 
    calltree_update_call(current_calls, c, NULL);
 
1360
    calltree_update_call (current_calls, c, NULL);
1351
1361
    update_actions();
1352
1362
}
1353
1363
 
1354
 
   void
1355
 
sflphone_srtp_sdes_off(callable_obj_t * c)
 
1364
void
 
1365
sflphone_srtp_sdes_off (callable_obj_t * c)
1356
1366
{
1357
1367
    c->_srtp_state = SRTP_STATE_UNLOCKED;
1358
1368
 
1359
 
    calltree_update_call(current_calls, c, NULL);
 
1369
    calltree_update_call (current_calls, c, NULL);
1360
1370
    update_actions();
1361
1371
}
1362
1372
 
1363
1373
 
1364
 
   void
1365
 
sflphone_srtp_zrtp_on( callable_obj_t * c)
 
1374
void
 
1375
sflphone_srtp_zrtp_on (callable_obj_t * c)
1366
1376
{
1367
1377
    c->_srtp_state = SRTP_STATE_ZRTP_SAS_UNCONFIRMED;
1368
1378
 
1369
 
    calltree_update_call(current_calls, c, NULL);
 
1379
    calltree_update_call (current_calls, c, NULL);
1370
1380
    update_actions();
1371
1381
}
1372
1382
 
1373
 
    void
1374
 
sflphone_srtp_zrtp_off( callable_obj_t * c )
 
1383
void
 
1384
sflphone_srtp_zrtp_off (callable_obj_t * c)
1375
1385
{
1376
1386
    c->_srtp_state = SRTP_STATE_UNLOCKED;
1377
 
    calltree_update_call(current_calls, c, NULL);
 
1387
    calltree_update_call (current_calls, c, NULL);
1378
1388
    update_actions();
1379
1389
}
1380
1390
 
1381
 
    void
1382
 
sflphone_srtp_zrtp_show_sas( callable_obj_t * c, const gchar* sas, const gboolean verified)
 
1391
void
 
1392
sflphone_srtp_zrtp_show_sas (callable_obj_t * c, const gchar* sas, const gboolean verified)
1383
1393
{
1384
 
    if(c == NULL) {
1385
 
        DEBUG("Panic callable obj is NULL in %s at %d", __FILE__, __LINE__);
 
1394
    if (c == NULL) {
 
1395
        DEBUG ("Panic callable obj is NULL in %s at %d", __FILE__, __LINE__);
1386
1396
    }
1387
 
    c->_sas = g_strdup(sas);
1388
 
    if(verified == TRUE) {
 
1397
 
 
1398
    c->_sas = g_strdup (sas);
 
1399
 
 
1400
    if (verified == TRUE) {
1389
1401
        c->_srtp_state = SRTP_STATE_ZRTP_SAS_CONFIRMED;
1390
1402
    } else {
1391
1403
        c->_srtp_state = SRTP_STATE_ZRTP_SAS_UNCONFIRMED;
1392
1404
    }
1393
 
    calltree_update_call(current_calls, c, NULL);
 
1405
 
 
1406
    calltree_update_call (current_calls, c, NULL);
1394
1407
    update_actions();
1395
1408
}
1396
1409
 
1397
 
    void 
1398
 
sflphone_srtp_zrtp_not_supported( callable_obj_t * c )
 
1410
void
 
1411
sflphone_srtp_zrtp_not_supported (callable_obj_t * c)
1399
1412
{
1400
 
    DEBUG("ZRTP not supported");
1401
 
    main_window_zrtp_not_supported(c);
 
1413
    DEBUG ("ZRTP not supported");
 
1414
    main_window_zrtp_not_supported (c);
1402
1415
}
1403
1416
 
1404
1417
/* Method on sflphoned */
1405
 
    void 
1406
 
sflphone_set_confirm_go_clear( callable_obj_t * c )
 
1418
void
 
1419
sflphone_set_confirm_go_clear (callable_obj_t * c)
1407
1420
{
1408
 
   dbus_set_confirm_go_clear(c);
 
1421
    dbus_set_confirm_go_clear (c);
1409
1422
}
1410
1423
 
1411
 
 void 
1412
 
sflphone_request_go_clear(void)
 
1424
void
 
1425
sflphone_request_go_clear (void)
1413
1426
{
1414
 
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls);
1415
 
    if(selectedCall) {
1416
 
        dbus_request_go_clear(selectedCall);
 
1427
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
 
1428
 
 
1429
    if (selectedCall) {
 
1430
        dbus_request_go_clear (selectedCall);
1417
1431
    }
1418
1432
}
1419
1433
 
1420
1434
/* Signal sent by sflphoned */
1421
 
    void 
1422
 
sflphone_confirm_go_clear( callable_obj_t * c )
 
1435
void
 
1436
sflphone_confirm_go_clear (callable_obj_t * c)
1423
1437
{
1424
 
    main_window_confirm_go_clear(c);
 
1438
    main_window_confirm_go_clear (c);
1425
1439
}
1426
1440
 
1427
1441
 
1428
 
    void 
1429
 
sflphone_call_state_changed( callable_obj_t * c, const gchar * description, const guint code)
 
1442
void
 
1443
sflphone_call_state_changed (callable_obj_t * c, const gchar * description, const guint code)
1430
1444
{
1431
 
        DEBUG("sflphone_call_state_changed");
1432
 
    if(c == NULL) {
1433
 
        DEBUG("Panic callable obj is NULL in %s at %d", __FILE__, __LINE__);
 
1445
    DEBUG ("SFLPhone: sflphone_call_state_changed");
 
1446
 
 
1447
    if (c == NULL) {
 
1448
        DEBUG ("Panic callable obj is NULL in %s at %d", __FILE__, __LINE__);
1434
1449
    } else {
1435
 
        //g_free(c->_state_code_description); 
 
1450
        //g_free(c->_state_code_description);
1436
1451
        //DEBUG("sflphone_call_state_changed");
1437
 
        c->_state_code_description = g_strdup(description);
1438
 
        c->_state_code = code;   
 
1452
        c->_state_code_description = g_strdup (description);
 
1453
        c->_state_code = code;
 
1454
        DEBUG ("SFLPhone: state code %d", c->_state_code);
1439
1455
    }
1440
 
    
1441
 
    calltree_update_call(current_calls, c, NULL);
 
1456
 
 
1457
    calltree_update_call (current_calls, c, NULL);
1442
1458
    update_actions();
1443
1459
}
1444
1460
 
1445
1461
 
1446
 
void sflphone_get_interface_addr_from_name(char *iface_name, char **iface_addr, int size) {
 
1462
void sflphone_get_interface_addr_from_name (char *iface_name, char **iface_addr, int size)
 
1463
{
1447
1464
 
1448
1465
    struct ifreq ifr;
1449
1466
    int fd;
1454
1471
    struct sockaddr_in *saddr_in;
1455
1472
    struct in_addr *addr_in;
1456
1473
 
1457
 
    if((fd = socket (AF_INET, SOCK_DGRAM,0)) < 0)
1458
 
        DEBUG("getInterfaceAddrFromName error could not open socket\n");
 
1474
    if ( (fd = socket (AF_INET, SOCK_DGRAM,0)) < 0)
 
1475
        DEBUG ("getInterfaceAddrFromName error could not open socket\n");
1459
1476
 
1460
1477
    memset (&ifr, 0, sizeof (struct ifreq));
1461
1478
 
1462
1479
    strcpy (ifr.ifr_name, iface_name);
1463
1480
    ifr.ifr_addr.sa_family = AF_INET;
1464
1481
 
1465
 
    if((err = ioctl(fd, SIOCGIFADDR, &ifr)) < 0)
1466
 
        DEBUG("getInterfaceAddrFromName use default interface (0.0.0.0)\n");
1467
 
 
1468
 
    
1469
 
    saddr_in = (struct sockaddr_in *)&ifr.ifr_addr;
1470
 
    addr_in = &(saddr_in->sin_addr);
1471
 
 
1472
 
    tmp_addr = (char *)addr_in;
1473
 
 
1474
 
    snprintf(*iface_addr, size, "%d.%d.%d.%d", 
1475
 
             UC(tmp_addr[0]), UC(tmp_addr[1]), UC(tmp_addr[2]), UC(tmp_addr[3]));
1476
 
 
1477
 
    close(fd);
 
1482
    if ( (err = ioctl (fd, SIOCGIFADDR, &ifr)) < 0)
 
1483
        DEBUG ("getInterfaceAddrFromName use default interface (0.0.0.0)\n");
 
1484
 
 
1485
 
 
1486
    saddr_in = (struct sockaddr_in *) &ifr.ifr_addr;
 
1487
    addr_in = & (saddr_in->sin_addr);
 
1488
 
 
1489
    tmp_addr = (char *) addr_in;
 
1490
 
 
1491
    snprintf (*iface_addr, size, "%d.%d.%d.%d",
 
1492
              UC (tmp_addr[0]), UC (tmp_addr[1]), UC (tmp_addr[2]), UC (tmp_addr[3]));
 
1493
 
 
1494
    close (fd);
1478
1495
 
1479
1496
}