uimanager.c 67 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 *  Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com
 *
 *  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
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  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.
18
19
20
21
22
23
24
25
26
27
28
 *
 *  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.
29
30
31
 */

#include <config.h>
32
#include <preferencesdialog.h>
33
34
35
36
#include <dbus/dbus.h>
#include <mainwindow.h>
#include <assistant.h>
#include <gtk/gtk.h>
37
#include <string.h>
38
39
#include <glib/gprintf.h>
#include <libgnome/gnome-help.h>
40

41
#include <uimanager.h>
42
#include <statusicon.h>
Jonas Fonseca's avatar
im    
Jonas Fonseca committed
43
#include <widget/imwidget.h>
Julien Bonjean's avatar
Julien Bonjean committed
44
#include <eel-gconf-extensions.h>
45
46


Julien Bonjean's avatar
Julien Bonjean committed
47
48
#include "uimanager.h"
#include "statusicon.h"
49
50

#include "contacts/addrbookfactory.h"
51
#include "config/addressbook-config.h"
52

Julien Bonjean's avatar
Julien Bonjean committed
53
54
55
#include "accountlist.h"
#include "config/accountlistconfigdialog.h"

Julien Bonjean's avatar
Julien Bonjean committed
56
void show_edit_number (callable_obj_t *call);
57

58
59
static GtkWidget *toolbar;

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
static guint transfertButtonConnId; //The button toggled signal connection ID
static guint recordButtonConnId; //The button toggled signal connection ID

static GtkAction * pickUpAction;
static GtkWidget * pickUpWidget;
static GtkAction * newCallAction;
static GtkWidget * newCallWidget;
static GtkAction * hangUpAction;
static GtkWidget * hangUpWidget;
static GtkWidget * holdMenu;
static GtkWidget * holdToolbar;
static GtkWidget * offHoldToolbar;
static GtkWidget * transferToolbar;
static GtkAction * copyAction;
static GtkAction * pasteAction;
static GtkAction * recordAction;
static GtkWidget * recordWidget;
static GtkAction * voicemailAction;
static GtkWidget * voicemailToolbar;
static GtkWidget * imToolbar;
static GtkAction * imAction;
81
static GtkWidget * playRecordWidget;
82
static GtkWidget * stopRecordWidget;
83
84
85

static GtkWidget * editable_num;
static GtkDialog * edit_dialog;
86

87
88
enum {
    CALLTREE_CALLS, CALLTREE_HISTORY, CALLTREE_CONTACTS
89
};
90

91
92
static gboolean
is_inserted (GtkWidget* button, GtkWidget *current_toolbar)
93
{
94
    return (GTK_WIDGET (button)->parent == GTK_WIDGET (current_toolbar));
95
96
}

97
void
98
update_actions()
99
{
100

101
    DEBUG ("UIManager: Update action");
Alexandre Savard's avatar
Alexandre Savard committed
102
	
103
104
105
106
107
108
109
110
111
    gtk_action_set_sensitive (GTK_ACTION (newCallAction), TRUE);
    gtk_action_set_sensitive (GTK_ACTION (pickUpAction), FALSE);
    gtk_action_set_sensitive (GTK_ACTION (hangUpAction), FALSE);
    gtk_action_set_sensitive (GTK_ACTION (imAction), FALSE);

    g_object_ref (hangUpWidget);
    g_object_ref (recordWidget);
    g_object_ref (holdToolbar);
    g_object_ref (offHoldToolbar);
112
113
114
    if(abookfactory_is_addressbook_loaded()) {
        g_object_ref (contactButton);
    }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    g_object_ref (historyButton);
    g_object_ref (transferToolbar);
    g_object_ref (voicemailToolbar);
    g_object_ref (imToolbar);

    if (is_inserted (GTK_WIDGET (hangUpWidget), GTK_WIDGET (toolbar))) {
        gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (hangUpWidget));
    }

    if (is_inserted (GTK_WIDGET (recordWidget), GTK_WIDGET (toolbar))) {
        gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (recordWidget));
    }

    if (is_inserted (GTK_WIDGET (transferToolbar), GTK_WIDGET (toolbar))) {
129
        gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (transferToolbar));
130
131
132
133
134
135
    }

    if (is_inserted (GTK_WIDGET (historyButton), GTK_WIDGET (toolbar))) {
        gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (historyButton));
    }

136
137
138
139
    if(abookfactory_is_addressbook_loaded()) {
        if (is_inserted (GTK_WIDGET (contactButton), GTK_WIDGET (toolbar))) {
            gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (contactButton));
        }
140
141
142
143
144
145
146
147
148
149
150
    }

    if (is_inserted (GTK_WIDGET (voicemailToolbar), GTK_WIDGET (toolbar))) {
        gtk_container_remove (GTK_CONTAINER (toolbar),
                              GTK_WIDGET (voicemailToolbar));
    }

    if (is_inserted (GTK_WIDGET (imToolbar), GTK_WIDGET (toolbar))) {
        gtk_container_remove (GTK_CONTAINER (toolbar),
                              GTK_WIDGET (imToolbar));
    }
151
    
152
153
154
155
156
157
    gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), FALSE);
    gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), FALSE);
    gtk_widget_set_sensitive (GTK_WIDGET (offHoldToolbar), FALSE);
    gtk_action_set_sensitive (GTK_ACTION (recordAction), FALSE);
    gtk_widget_set_sensitive (GTK_WIDGET (recordWidget), FALSE);
    gtk_action_set_sensitive (GTK_ACTION (copyAction), FALSE);
Alexandre Savard's avatar
Alexandre Savard committed
158

159
160
161
    if(abookfactory_is_addressbook_loaded()) { 
        gtk_widget_set_sensitive (GTK_WIDGET (contactButton), FALSE);
    }
162
    gtk_widget_set_sensitive (GTK_WIDGET (historyButton), FALSE);
163
164
165
    if(abookfactory_is_addressbook_loaded()) {
        gtk_widget_set_tooltip_text (GTK_WIDGET (contactButton),_("No address book selected"));
    }
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

    if (is_inserted (GTK_WIDGET (holdToolbar), GTK_WIDGET (toolbar)))
        gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (holdToolbar));

    if (is_inserted (GTK_WIDGET (offHoldToolbar), GTK_WIDGET (toolbar)))
        gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (offHoldToolbar));

    if (is_inserted (GTK_WIDGET (newCallWidget), GTK_WIDGET (toolbar)))
        gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (newCallWidget));

    if (is_inserted (GTK_WIDGET (pickUpWidget), GTK_WIDGET (toolbar)))
        gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (pickUpWidget));

    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (newCallWidget), 0);

181
182
183
184
    if(is_inserted(GTK_WIDGET (playRecordWidget), GTK_WIDGET(toolbar)))
	gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(playRecordWidget));
    if(is_inserted(GTK_WIDGET (stopRecordWidget), GTK_WIDGET(toolbar)))
	gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(stopRecordWidget));
185
186
187
188
189
190
191

    if (eel_gconf_get_integer (HISTORY_ENABLED)) {
        gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (historyButton), -1);
        gtk_widget_set_sensitive (GTK_WIDGET (historyButton), TRUE);
    }

    // If addressbook support has been enabled and all addressbooks are loaded, display the icon
192
193
194
   
    if(abookfactory_is_addressbook_loaded()) {
        AddrBookFactory *bookFactory = abookfactory_get_factory();
195
196
197
198
        AddressBook_Config *addressbook_config;
	addressbook_config_load_parameters(&addressbook_config);
 
        if (addressbook_config->enable && bookFactory->addrbook->is_ready()) {
199
200
201
202
203
204
205
            gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (contactButton), -1);

            // Make the icon clickable only if at least one address book is active
            if (bookFactory->addrbook->is_active()) {
                gtk_widget_set_sensitive (GTK_WIDGET (contactButton), TRUE);
                gtk_widget_set_tooltip_text (GTK_WIDGET (contactButton),_ ("Address book"));
            }
206
207
208
209
210
211
        }
    }

    callable_obj_t * selectedCall = calltab_get_selected_call (active_calltree);
    conference_obj_t * selectedConf = calltab_get_selected_conf (active_calltree);

212
    gboolean instant_messaging_enabled = TRUE;
213
    
214
    if (eel_gconf_key_exists (INSTANT_MESSAGING_ENABLED)) {
215
        instant_messaging_enabled = eel_gconf_get_integer (INSTANT_MESSAGING_ENABLED);
216
    }
217

218
    if (selectedCall) {
219

220
        DEBUG("UIManager: Update actions for call %s", selectedCall->_callID); 
221

222
223
224
225
226
227
228
        // update icon in systray
        show_status_hangup_icon();

        gtk_action_set_sensitive (GTK_ACTION (copyAction), TRUE);

        switch (selectedCall->_state) {
            case CALL_STATE_INCOMING:
Alexandre Savard's avatar
Alexandre Savard committed
229
		DEBUG("UIManager: Call State Incoming");
230
231
232
233
234
235
236
237
238
239
240
241
                // Make the button toolbar clickable
                gtk_action_set_sensitive (GTK_ACTION (pickUpAction), TRUE);
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                // Replace the dial button with the hangup button
                g_object_ref (newCallWidget);
                gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (newCallWidget));
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (pickUpWidget),
                                    0);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
                                    1);
                break;
            case CALL_STATE_HOLD:
Alexandre Savard's avatar
Alexandre Savard committed
242
		DEBUG("UIManager: Call State Hold");
243
244
245
246
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (offHoldToolbar), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (newCallWidget), TRUE);
247

248
                // Replace the hold button with the off-hold button
249
250
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (offHoldToolbar), 2);
251
252
253
254
255
256

                if (instant_messaging_enabled) {
                    gtk_action_set_sensitive (GTK_ACTION (imAction), TRUE);
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (imToolbar), 3);
                }

257
258
                break;
            case CALL_STATE_RINGING:
Alexandre Savard's avatar
Alexandre Savard committed
259
		DEBUG("UIManager: Call State Ringing");
260
261
262
263
264
265
                gtk_action_set_sensitive (GTK_ACTION (pickUpAction), TRUE);
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
                                    1);
                break;
            case CALL_STATE_DIALING:
266
                DEBUG("UIManager: Call State Dialing");
267
268
269
270
271
272
                gtk_action_set_sensitive (GTK_ACTION (pickUpAction), TRUE);

                if (active_calltree == current_calls)
                    gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);

                g_object_ref (newCallWidget);
Julien Bonjean's avatar
Julien Bonjean committed
273
274
                gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (newCallWidget));
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (pickUpWidget), 0);
275
276

                if (active_calltree == current_calls)
Julien Bonjean's avatar
Julien Bonjean committed
277
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
278
279
280
281
282
283
284
285
                else if (active_calltree == history) {
                    if (selectedCall->_recordfile && (g_strcmp0(selectedCall->_recordfile, "") != 0)) {
                        if (selectedCall->_record_is_playing)
                            gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM(stopRecordWidget), 3);
                        else
                            gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM(playRecordWidget), 3);
                    }
                }
286
287
                break;
            case CALL_STATE_CURRENT:
288
                DEBUG ("UIManager: Call State Current");
289
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
290
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
291
292
293
294
                gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (transferToolbar), TRUE);
                gtk_action_set_sensitive (GTK_ACTION (recordAction), TRUE);
295
296
297
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), 2);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (transferToolbar), 3);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (recordWidget), 4);
298
                gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId);
299
                gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), FALSE);
300
                gtk_signal_handler_unblock (transferToolbar, transfertButtonConnId);
301
302
303
                g_signal_handler_block (GTK_OBJECT (recordWidget), recordButtonConnId);
                gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (recordWidget), FALSE);
                g_signal_handler_unblock (GTK_OBJECT (recordWidget), recordButtonConnId);
304
305
306
307
308
309

                if (instant_messaging_enabled) {
                    gtk_action_set_sensitive (GTK_ACTION (imAction), TRUE);
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (imToolbar), 5);
                }

310
                break;
311

Julien Bonjean's avatar
Julien Bonjean committed
312
            case CALL_STATE_RECORD:
313
                DEBUG ("UIManager: Call State Record");
Julien Bonjean's avatar
Julien Bonjean committed
314
315
316
317
318
319
320
321
322
323
324
325
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
                gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (transferToolbar), TRUE);
                gtk_action_set_sensitive (GTK_ACTION (recordAction), TRUE);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), 2);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (transferToolbar), 3);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (recordWidget), 4);
                gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId);
                gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), FALSE);
                gtk_signal_handler_unblock (transferToolbar, transfertButtonConnId);
326
327
328
                g_signal_handler_block (GTK_OBJECT (recordWidget), recordButtonConnId);
                gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (recordWidget), TRUE);
                g_signal_handler_unblock (GTK_OBJECT (recordWidget), recordButtonConnId);
329
330
331
332
333
334

                if (instant_messaging_enabled) {
                    gtk_action_set_sensitive (GTK_ACTION (imAction), TRUE);
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (imToolbar), 5);
                }

335
336
337
                break;
            case CALL_STATE_BUSY:
            case CALL_STATE_FAILURE:
Alexandre Savard's avatar
Alexandre Savard committed
338
		DEBUG("UIManager: Call State Busy/Failure"); 
339
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
Julien Bonjean's avatar
Julien Bonjean committed
340
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
341
342
                break;
            case CALL_STATE_TRANSFERT:
Julien Bonjean's avatar
Julien Bonjean committed
343
344
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (transferToolbar), 2);
345
                gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId);
Julien Bonjean's avatar
Julien Bonjean committed
346
                gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), TRUE);
347
348
349
350
351
352
353
                gtk_signal_handler_unblock (transferToolbar, transfertButtonConnId);
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (transferToolbar), TRUE);
                break;
            default:
Alexandre Savard's avatar
Alexandre Savard committed
354
                ERROR ("UIMAnager: Error: Unknown state in action update!");
355
356
357
358
                break;
        }
    } else if (selectedConf) {

359
360
        DEBUG("UIManager: Update actions for conference");

361
362
363
        // update icon in systray
        show_status_hangup_icon();

364

365
366
367
368
        switch (selectedConf->_state) {

            case CONFERENCE_STATE_ACTIVE_ATACHED:
            case CONFERENCE_STATE_ACTIVE_DETACHED:
Alexandre Savard's avatar
Alexandre Savard committed
369
		DEBUG("UIManager: Conference State Active");
370
371
372
373
374
375
376
377
378
379
380
381
		if(active_calltree == current_calls) {
                    gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                    gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE);
                    gtk_action_set_sensitive (GTK_ACTION (recordAction), TRUE);
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), 2);
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (recordWidget), 3);
                    if (instant_messaging_enabled) {
                        gtk_action_set_sensitive (GTK_ACTION (imAction), TRUE);
                        gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (imToolbar), 4);
                    }
		}
382
383
384
385
386
387
388
389
390
		else if(active_calltree == history) {
		    if(selectedConf->_recordfile && (g_strcmp0(selectedConf->_recordfile, "") != 0)) {
                        if(selectedConf->_record_is_playing)
                            gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM(stopRecordWidget), 3);
                        else
                            gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM(playRecordWidget), 3);
                    }

		}
391
                break;
392
            case CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD:
393
            case CONFERENCE_STATE_ACTIVE_DETACHED_RECORD:
Alexandre Savard's avatar
Alexandre Savard committed
394
		DEBUG("UIManager: Conference State Record");
395
396
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE);
Julien Bonjean's avatar
Julien Bonjean committed
397
398
399
400
                gtk_action_set_sensitive (GTK_ACTION (recordAction), TRUE);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), 2);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (recordWidget), 3);
401
402
403
404
                if (instant_messaging_enabled) {
                    gtk_action_set_sensitive (GTK_ACTION (imAction), TRUE);
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (imToolbar), 4);
                }
405
406
                break;
            case CONFERENCE_STATE_HOLD:
407
            case CONFERENCE_STATE_HOLD_RECORD:
Alexandre Savard's avatar
Alexandre Savard committed
408
		DEBUG("UIManager: Conference State Hold");
409
410
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (offHoldToolbar), TRUE);
Julien Bonjean's avatar
Julien Bonjean committed
411
412
413
414
                gtk_action_set_sensitive (GTK_ACTION (recordAction), TRUE);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (offHoldToolbar), 2);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (recordWidget), 3);
415
416
417
418
                if (instant_messaging_enabled) {
                    gtk_action_set_sensitive (GTK_ACTION (imAction), TRUE);
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (imToolbar), 4);
                }
419
420
                break;
            default:
Alexandre Savard's avatar
Alexandre Savard committed
421
                WARN ("UIManager: Error: Should not happen in action update!");
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
                break;
        }
    }

    else {

        // update icon in systray
        hide_status_hangup_icon();

        if (account_list_get_size() > 0 && current_account_has_mailbox()) {
            gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
                                GTK_TOOL_ITEM (voicemailToolbar), -2);
            update_voicemail_status();
        }
    }
437
438
}

439
440
void
update_voicemail_status (void)
441
{
442
443
444
445
446
447
448
449
450
    gchar *messages = "";
    messages = g_markup_printf_escaped (_ ("Voicemail (%i)"),
                                        current_account_get_message_number());
    (current_account_has_new_message()) ? gtk_tool_button_set_icon_name (
        GTK_TOOL_BUTTON (voicemailToolbar), "mail-message-new")
    : gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (voicemailToolbar),
                                     "mail-read");
    gtk_tool_button_set_label (GTK_TOOL_BUTTON (voicemailToolbar), messages);
    g_free (messages);
451
452
}

453
static void
Julien Bonjean's avatar
Julien Bonjean committed
454
volume_bar_cb (GtkToggleAction *togglemenuitem, gpointer user_data UNUSED)
455
{
456
457
458
459
460
461
462
463
464
    gboolean toggled = gtk_toggle_action_get_active (togglemenuitem);

    if (toggled == SHOW_VOLUME)
        return;

    main_window_volume_controls (toggled);

    if (toggled || SHOW_VOLUME)
        eel_gconf_set_integer (SHOW_VOLUME_CONTROLS, toggled);
465
466
}

467
static void
Julien Bonjean's avatar
Julien Bonjean committed
468
dialpad_bar_cb (GtkToggleAction *togglemenuitem, gpointer user_data UNUSED)
469
{
470
471
472
473
474
475
476
477
478
479
    gboolean toggled = gtk_toggle_action_get_active (togglemenuitem);
    gboolean conf_dialpad = eel_gconf_get_boolean (CONF_SHOW_DIALPAD);

    if (toggled == conf_dialpad)
        return;

    main_window_dialpad (toggled);

    if (toggled || conf_dialpad)
        eel_gconf_set_boolean (CONF_SHOW_DIALPAD, toggled); //dbus_set_dialpad (toggled);
480

481
482
}

483
static void
Julien Bonjean's avatar
Julien Bonjean committed
484
help_contents_cb (GtkAction *action UNUSED)
485
{
486
    GError *error = NULL;
487

488
489
490
491
492
493
    gnome_help_display ("sflphone.xml", NULL, &error);

    if (error != NULL) {
        g_warning ("%s", error->message);
        g_error_free (error);
    }
494
495
}

496
497
static void
help_about (void * foo UNUSED)
498
{
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
    gchar
    *authors[] = {
        "Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>",
        "Jean-Philippe Barrette-LaPierre",
        "Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>",
        "Julien Bonjean <julien.bonjean@savoirfairelinux.com>",
        "Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>",
        "Laurielle Lea",
        "Yun Liu <yun.liu@savoirfairelinux.com>",
        "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>",
        "Yan Morin <yan.morin@savoirfairelinux.com>",
        "Jérôme Oufella <jerome.oufella@savoirfairelinux.com>",
        "Julien Plissonneau Duquene <julien.plissonneau.duquene@savoirfairelinux.com>",
        "Alexandre Savard <alexandre.savard@savoirfairelinux.com>", NULL
    };
    gchar *artists[] = { "Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>",
                         "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>", NULL
                       };

    gtk_show_about_dialog (GTK_WINDOW (get_main_window()), "artists", artists,
                           "authors", authors, "comments",
                           _ ("SFLphone is a VoIP client compatible with SIP and IAX2 protocols."),
521
                           "copyright", "Copyright © 2004-2011 Savoir-faire Linux Inc.", "name",
522
523
                           PACKAGE, "title", _ ("About SFLphone"), "version", VERSION, "website",
                           "http://www.sflphone.org", NULL);
524
525
526
527
528

}

/* ----------------------------------------------------------------- */

529
530
static void
call_new_call (void * foo UNUSED)
531
{
532
533
    DEBUG ("UIManager: New call button pressed");

534
    sflphone_new_call();
535
536
}

537
538
static void
call_quit (void * foo UNUSED)
539
{
540
    sflphone_quit();
541
542
}

543
544
static void
call_minimize (void * foo UNUSED)
545
{
546

547
548
549
550
551
552
    if (eel_gconf_get_integer (SHOW_STATUSICON)) {
        gtk_widget_hide (GTK_WIDGET (get_main_window()));
        set_minimized (TRUE);
    } else {
        sflphone_quit ();
    }
553
554
}

555
556
static void
switch_account (GtkWidget* item, gpointer data UNUSED)
557
{
558
559
560
561
    account_t* acc = g_object_get_data (G_OBJECT (item), "account");
    DEBUG ("%s" , acc->accountID);
    account_list_set_current (acc);
    status_bar_display_account();
562
563
}

564
565
static void
call_hold (void* foo UNUSED)
566
{
567
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
568
    conference_obj_t * selectedConf = calltab_get_selected_conf(current_calls);
569

570
    DEBUG ("UIManager: Hold button pressed");
571

572
573
574
575
576
577
578
579
580
581
    if (selectedCall) {
        if (selectedCall->_state == CALL_STATE_HOLD) {
            sflphone_off_hold();
        } else {
            sflphone_on_hold();
        }
    } else if (selectedConf) {

        switch (selectedConf->_state) {

582
            case CONFERENCE_STATE_HOLD:
583
584
                selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
                sflphone_conference_off_hold (selectedConf);
585
586
587
588
589
                break;
            case CONFERENCE_STATE_HOLD_RECORD:
                selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
                sflphone_conference_off_hold (selectedConf);
                break;
590
591

            case CONFERENCE_STATE_ACTIVE_ATACHED:
592
            case CONFERENCE_STATE_ACTIVE_DETACHED:
593
594
                selectedConf->_state = CONFERENCE_STATE_HOLD;
                sflphone_conference_on_hold (selectedConf);
595
596
597
598
599
600
                break;
            case CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD:
            case CONFERENCE_STATE_ACTIVE_DETACHED_RECORD:
              selectedConf->_state = CONFERENCE_STATE_HOLD_RECORD;
              sflphone_conference_on_hold (selectedConf);
              break;
601
602
603
604
605
            default:
                break;
        }

    }
606
607
}

608
static void
609
call_im (void* foo UNUSED)
Jonas Fonseca's avatar
im    
Jonas Fonseca committed
610
{
611
    callable_obj_t *selectedCall = calltab_get_selected_call (current_calls);
612
    conference_obj_t *selectedConf = calltab_get_selected_conf(current_calls);
613

614
615
616
    if (calltab_get_selected_type (current_calls) == A_CALL) {

        if (selectedCall) {
617
            im_widget_display ( (IMWidget **) (&selectedCall->_im_widget), NULL, selectedCall->_callID, NULL);
618
        } else {
619
            WARN ("Sorry. Instant messaging is not allowed outside a call\n");
620
        }
621
    } else {
622
        if (selectedConf) {
623
            im_widget_display ( (IMWidget **) (&selectedConf->_im_widget), NULL, selectedConf->_confID, NULL);
624
        } else {
625
            WARN ("Sorry. Instant messaging is not allowed outside a call\n");
626
        }
627
    }
Jonas Fonseca's avatar
im    
Jonas Fonseca committed
628
629
}

630
631
static void
conference_hold (void* foo UNUSED)
632
{
633
    conference_obj_t * selectedConf = calltab_get_selected_conf(current_calls);
634

635
636
637
638
639
640
    DEBUG ("UIManager: Hold button pressed for conference");

    if(selectedConf == NULL) {
        ERROR("UIManager: No conference selected");
	return;
    }
641

642
    switch (selectedConf->_state) {
643
        case CONFERENCE_STATE_HOLD:
644
645
            selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
            sflphone_conference_off_hold (selectedConf);
646
647
648
649
650
            break;
        case CONFERENCE_STATE_HOLD_RECORD:
            selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
            sflphone_conference_off_hold (selectedConf);
            break;
651
        case CONFERENCE_STATE_ACTIVE_ATACHED:
652
        case CONFERENCE_STATE_ACTIVE_DETACHED:
653
654
            selectedConf->_state = CONFERENCE_STATE_HOLD;
            sflphone_conference_on_hold (selectedConf);
655
656
657
658
659
            break;
        case CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD:
        case CONFERENCE_STATE_ACTIVE_DETACHED_RECORD:
            selectedConf->_state = CONFERENCE_STATE_HOLD_RECORD;
            sflphone_conference_on_hold(selectedConf);
660
661
662
        default:
            break;
    }
663
664
}

665
666
static void
call_pick_up (void * foo UNUSED)
667
{
668
669
    callable_obj_t * selectedCall;
    callable_obj_t* new_call;
670
671
    
    DEBUG ("UIManager: Pick up");
672

673
    if (calllist_get_size (current_calls) > 0) {
674
        sflphone_pick_up();
675
    }
676
677

    else if (calllist_get_size (active_calltree) > 0) {
678
679
	selectedCall = calltab_get_selected_call(active_calltree);

680
        if (selectedCall) {
681
682
            new_call = create_new_call (CALL, CALL_STATE_DIALING, "", "", "",
                             selectedCall->_peer_number);
683

684
            calllist_add_call (current_calls, new_call);
685
686
687
688
689
690
691
692
693
694
695
            calltree_add_call (current_calls, new_call, NULL);
            sflphone_place_call (new_call);
            calltree_display (current_calls);
        } else {
            sflphone_new_call();
            calltree_display (current_calls);
        }
    } else {
        sflphone_new_call();
        calltree_display (current_calls);
    }
696
697
}

698
699
static void
call_hang_up (void)
700
{
701
    DEBUG ("UIManager: Hang up button pressed (call)");
702
703
704
705
    /*
     * [#3020]	Restore the record toggle button
     *			We set it to FALSE, as when we hang up a call, the recording is stopped.
     */
706

707
    sflphone_hang_up();
708

709
710
}

711
712
static void
conference_hang_up (void)
713
{
714
715
    DEBUG ("UIManager: Hang up button pressed (conference)");

716
    sflphone_conference_hang_up();
717
718
}

719
720
static void
call_record (void)
721
{
722
723
    DEBUG ("UIManager: Record button pressed");

724
    sflphone_rec_call();
725
726
}

727
static void
728
start_playback_record_cb(void)
729
{
730
731
732
    gboolean result;

    DEBUG("UIManager: Start playback button pressed");
733
734
735
736
737
738
739
740
741

    callable_obj_t *selectedCall = calltab_get_selected_call (history);
    conference_obj_t *selectedConf = calltab_get_selected_conf (history);

    if((selectedCall == NULL) && (selectedConf == NULL)) {
        ERROR("UIManager: Error: No selected object in playback record callback");
	return;
    }

Alexandre Savard's avatar
Alexandre Savard committed
742
743
744
745
746
    if(selectedCall && selectedConf) {
	ERROR("UIManager: Error: Two selected object in playback record callback");
	return;
    }

747
    if(selectedCall) {
Alexandre Savard's avatar
Alexandre Savard committed
748
	DEBUG("UIManager: Start selected call file playback %s", selectedCall->_recordfile);
749
750
751
752
        result = dbus_start_recorded_file_playback(selectedCall->_recordfile);
	selectedCall->_record_is_playing = result;
    }
    else if(selectedConf) {
Alexandre Savard's avatar
Alexandre Savard committed
753
	DEBUG("UIMAnager: Start selected conf file playback %s", selectedConf->_recordfile);
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
	result = dbus_start_recorded_file_playback(selectedConf->_recordfile);
	selectedConf->_record_is_playing = result;
    } 

    update_actions();
}

static void
stop_playback_record_cb(void)
{
    DEBUG("UIManager: Stop playback button pressed");

    callable_obj_t *selectedCall = calltab_get_selected_call (history);
    conference_obj_t *selectedConf = calltab_get_selected_conf(history);

    if(selectedCall && selectedConf) {
        ERROR("UIManager: Error: Two selected object in history treeview");
	return;
    }

    if((selectedCall == NULL) && (selectedConf == NULL)) {
        ERROR("UIManager: Error: No selected object in history treeview");
	return;
    }

    if(selectedCall) {
Alexandre Savard's avatar
Alexandre Savard committed
780
781
782
783
        if(selectedCall->_recordfile == NULL) {
            ERROR("UIManager: Error: Record file is NULL");
	    return;
        }
784
	dbus_stop_recorded_file_playback(selectedCall->_recordfile);
Alexandre Savard's avatar
Alexandre Savard committed
785
	DEBUG("UIManager: Stop selected call file playback %s", selectedCall->_recordfile);
786
787
788
	selectedCall->_record_is_playing = FALSE;
    } 
    else if(selectedConf) {
Alexandre Savard's avatar
Alexandre Savard committed
789
790
791
792
        if(selectedConf->_recordfile == NULL) {
            ERROR("UIManager: Error: Record file is NULL");
	    return;
	}
793
        dbus_stop_recorded_file_playback(selectedConf->_recordfile);
Alexandre Savard's avatar
Alexandre Savard committed
794
	DEBUG("UIMAnager: Start selected call file playback: %s", selectedConf->_recordfile);
795
796
797
798
	selectedConf->_record_is_playing = FALSE;
    }

    update_actions();
799
800
}

801
802
static void
call_configuration_assistant (void * foo UNUSED)
803
804
{
#if GTK_CHECK_VERSION(2,10,0)
805
    build_wizard();
806
807
808
#endif
}

809
810
static void
remove_from_history (void * foo UNUSED)
811
{
812
    callable_obj_t* call = calltab_get_selected_call (history);
813

814
815
816
817
818
    DEBUG ("UIManager: Remove the call from the history");

    if(call == NULL) {
	ERROR("UIManager: Error: Call is NULL");
    	return;
819
    }
820
821

    calllist_remove_from_history (call);
822
823
}

824
825
static void
call_back (void * foo UNUSED)
826
{
827
    callable_obj_t *selected_call, *new_call;
828

829
    selected_call = calltab_get_selected_call (active_calltree);
830

831
    DEBUG("UIManager: Call back");
832

833
834
835
    if(selected_call == NULL) {
	ERROR("UIManager: Error: No selected call");
	return;
836
    }
837

838
839
    new_call = create_new_call (CALL, CALL_STATE_DIALING, "", "",
                         selected_call->_peer_name, selected_call->_peer_number);
840

841
    calllist_add_call (current_calls, new_call);
842
843
844
    calltree_add_call (current_calls, new_call, NULL);
    sflphone_place_call (new_call);
    calltree_display (current_calls);
845
846
}

847
848
static void
edit_preferences (void * foo UNUSED)
849
{
850
    show_preferences_dialog();
851
852
}

853
854
static void
edit_accounts (void * foo UNUSED)
855
{
856
    show_account_list_config_dialog();
857
858
859
}

// The menu Edit/Copy should copy the current selected call's number
860
861
static void
edit_copy (void * foo UNUSED)
862
{
863
864
865
866
    GtkClipboard* clip = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
    gchar * no = NULL;

867
    DEBUG("UIManager: Edit/Copy");
868

869
870
871
    if(selectedCall == NULL) {
        ERROR("UIManager: Error: No selected call", selectedCall);
    	return;
872
    }
873

874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
    switch (selectedCall->_state) {
        case CALL_STATE_TRANSFERT:
        case CALL_STATE_DIALING:
        case CALL_STATE_RINGING:
            no = selectedCall->_peer_number;
            break;
        case CALL_STATE_CURRENT:
        case CALL_STATE_RECORD:
        case CALL_STATE_HOLD:
        case CALL_STATE_BUSY:
        case CALL_STATE_FAILURE:
        case CALL_STATE_INCOMING:
        default:
            no = selectedCall->_peer_number;
            break;
    }

    DEBUG ("UIManager: Clipboard number: %s\n", no);
    gtk_clipboard_set_text (clip, no, strlen (no));

894
895
896
}

// The menu Edit/Paste should paste the clipboard into the current selected call
897
898
static void
edit_paste (void * foo UNUSED)
899
{
900

901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
    GtkClipboard* clip = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
    gchar * no = gtk_clipboard_wait_for_text (clip);

    if (no && selectedCall) {
        switch (selectedCall->_state) {
            case CALL_STATE_TRANSFERT:
            case CALL_STATE_DIALING:
                // Add the text to the number
            {
                gchar * before;
                before = selectedCall->_peer_number;
                DEBUG ("TO: %s\n", before);
                selectedCall->_peer_number = g_strconcat (before, no, NULL);

                if (selectedCall->_state == CALL_STATE_DIALING) {
                    selectedCall->_peer_info = g_strconcat ("\"\" <",
                                                            selectedCall->_peer_number, ">", NULL);
                }

                calltree_update_call (current_calls, selectedCall, NULL);
            }
            break;
            case CALL_STATE_RINGING:
            case CALL_STATE_INCOMING:
            case CALL_STATE_BUSY:
            case CALL_STATE_FAILURE:
            case CALL_STATE_HOLD: { // Create a new call to hold the new text
                selectedCall = sflphone_new_call();

                selectedCall->_peer_number = g_strconcat (selectedCall->_peer_number,
                                             no, NULL);
                DEBUG ("TO: %s", selectedCall->_peer_number);

                selectedCall->_peer_info = g_strconcat ("\"\" <",
                                                        selectedCall->_peer_number, ">", NULL);

                calltree_update_call (current_calls, selectedCall, NULL);
            }
            break;
            case CALL_STATE_CURRENT:
942
            case CALL_STATE_RECORD:
943
944
945
946
947
948
949
950
951
952
953
954
            default: {
                unsigned int i;

                for (i = 0; i < strlen (no); i++) {
                    gchar * oneNo = g_strndup (&no[i], 1);
                    DEBUG ("<%s>", oneNo);
                    dbus_play_dtmf (oneNo);

                    gchar * temp = g_strconcat (selectedCall->_peer_number, oneNo,
                                                NULL);
                    selectedCall->_peer_info = get_peer_info (temp,
                                               selectedCall->_peer_name);
955
                    g_free(temp);
956
957
958
959
960
961
962
963
964
965
966
967
968
969
                    calltree_update_call (current_calls, selectedCall, NULL);

                }
            }
            break;
        }

    } else { // There is no current call, create one
        selectedCall = sflphone_new_call();

        gchar * before = selectedCall->_peer_number;
        selectedCall->_peer_number = g_strconcat (selectedCall->_peer_number, no,
                                     NULL);
        g_free (before);
970
        DEBUG ("UIManager: TO: %s", selectedCall->_peer_number);
971
972
973
974
975
976

        g_free (selectedCall->_peer_info);
        selectedCall->_peer_info = g_strconcat ("\"\" <",
                                                selectedCall->_peer_number, ">", NULL);
        calltree_update_call (current_calls, selectedCall, NULL);
    }
977
978
979

}

980
981
static void
clear_history (void)
982
{
Alexandre Savard's avatar
Alexandre Savard committed
983
984
985
986
    if(conferencelist_get_size(history) != 0) {
	conferencelist_clean_history();
    }

987
988
989
    if (calllist_get_size (history) != 0) {
        calllist_clean_history();
    }
990
991
}

992
/**
Alexandre Savard's avatar
Alexandre Savard committed
993
 * Transfer the line
994
 */
995
static void
996
call_transfer_cb()
997
{
998
999
1000
    gboolean active = gtk_toggle_tool_button_get_active (
                          GTK_TOGGLE_TOOL_BUTTON (transferToolbar));
    active ? sflphone_set_transfert() : sflphone_unset_transfert();
For faster browsing, not all history is shown. View entire blame