uimanager.c 62.3 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 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 45 46 47 48 49 50
#include <eel-gconf-extensions.h>
#include "uimanager.h"
#include "statusicon.h"
#include "contacts/addressbook.h"
#include "accountlist.h"
#include "config/accountlistconfigdialog.h"

Julien Bonjean's avatar
Julien Bonjean committed
51
void show_edit_number (callable_obj_t *call);
52

53
static GtkWidget *toolbar;
54
static GtkWidget *toolbarWindows;
55

56
guint transfertButtonConnId; //The button toggled signal connection ID
57
guint recordButtonConnId; //The button toggled signal connection ID
58

59
GtkAction * pickUpAction;
60
GtkWidget * pickUpWidget;
61
GtkAction * newCallAction;
62
GtkWidget * newCallWidget;
63
GtkAction * hangUpAction;
64
GtkWidget * hangUpWidget;
65
GtkWidget * holdMenu;
66
GtkWidget * holdToolbar;
67
GtkWidget * offHoldToolbar;
68 69 70 71
GtkWidget * transferToolbar;
GtkAction * copyAction;
GtkAction * pasteAction;
GtkAction * recordAction;
72
GtkWidget * recordWidget;
73
GtkAction * voicemailAction;
74
GtkWidget * voicemailToolbar;
75 76
GtkWidget * imToolbar;
GtkAction * imAction;
77 78 79 80

GtkWidget * editable_num;
GtkDialog * edit_dialog;

81 82
enum {
    CALLTREE_CALLS, CALLTREE_HISTORY, CALLTREE_CONTACTS
83
};
84

85 86
static gboolean
is_inserted (GtkWidget* button, GtkWidget *current_toolbar)
87
{
88
    return (GTK_WIDGET (button)->parent == GTK_WIDGET (current_toolbar));
89 90
}

91
void
92
update_actions()
93
{
94

95
    DEBUG ("UIManager: Update action");
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

    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);
    g_object_ref (contactButton);
    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))) {
        gtk_container_remove (GTK_CONTAINER (toolbar),
                              GTK_WIDGET (transferToolbar));
    }

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

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

    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));
    }

    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);
    gtk_widget_set_sensitive (GTK_WIDGET (contactButton), FALSE);
    gtk_widget_set_sensitive (GTK_WIDGET (historyButton), FALSE);
    gtk_widget_set_tooltip_text (GTK_WIDGET (contactButton),
                                 _ ("No address book selected"));

    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);


    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
    if (addressbook_is_enabled() && addressbook_is_ready()) {
        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 (addressbook_is_active()) {
            gtk_widget_set_sensitive (GTK_WIDGET (contactButton), TRUE);
            gtk_widget_set_tooltip_text (GTK_WIDGET (contactButton),
                                         _ ("Address book"));
        }
    }

187 188 189
    // 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);
Julien Bonjean's avatar
Julien Bonjean committed
190

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

194 195 196 197
    gboolean instant_messaging_enabled = TRUE;

    if (eel_gconf_key_exists (INSTANT_MESSAGING_ENABLED))
        instant_messaging_enabled = eel_gconf_get_integer (INSTANT_MESSAGING_ENABLED);
198

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
    if (selectedCall) {
        // update icon in systray
        show_status_hangup_icon();

        gtk_action_set_sensitive (GTK_ACTION (copyAction), TRUE);

        switch (selectedCall->_state) {
            case CALL_STATE_INCOMING:
                // 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:
                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);
223

224
                // Replace the hold button with the off-hold button
225 226
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (offHoldToolbar), 2);
227 228 229 230 231 232

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

233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
                break;
            case CALL_STATE_RINGING:
                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:
                gtk_action_set_sensitive (GTK_ACTION (pickUpAction), TRUE);

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

                //gtk_action_set_sensitive( GTK_ACTION(newCallMenu),TRUE);
                g_object_ref (newCallWidget);
Julien Bonjean's avatar
Julien Bonjean committed
248 249
                gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (newCallWidget));
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (pickUpWidget), 0);
250 251

                if (active_calltree == current_calls)
Julien Bonjean's avatar
Julien Bonjean committed
252
                    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
253 254 255

                break;
            case CALL_STATE_CURRENT:
256
                DEBUG ("UIManager: Call State Current");
257
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
258
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
259 260 261 262
                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);
263 264 265
                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);
266
                gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId);
267
                gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), FALSE);
268
                gtk_signal_handler_unblock (transferToolbar, transfertButtonConnId);
269 270 271
                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);
272 273 274 275 276 277

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

278
                break;
279

Julien Bonjean's avatar
Julien Bonjean committed
280
            case CALL_STATE_RECORD:
281
                DEBUG ("UIManager: Call State Record");
Julien Bonjean's avatar
Julien Bonjean committed
282 283 284 285 286 287 288 289 290 291 292 293
                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);
294 295 296
                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);
297 298 299 300 301 302

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

303 304 305 306
                break;
            case CALL_STATE_BUSY:
            case CALL_STATE_FAILURE:
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
Julien Bonjean's avatar
Julien Bonjean committed
307
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
308 309
                break;
            case CALL_STATE_TRANSFERT:
Julien Bonjean's avatar
Julien Bonjean committed
310 311
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1);
                gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (transferToolbar), 2);
312
                gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId);
Julien Bonjean's avatar
Julien Bonjean committed
313
                gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), TRUE);
314 315 316 317 318 319 320
                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:
Julien Bonjean's avatar
Julien Bonjean committed
321
                WARN ("Should not happen in update_actions()!");
322 323 324 325 326 327 328 329 330 331 332 333
                break;
        }
    } else if (selectedConf) {

        // update icon in systray
        show_status_hangup_icon();

        switch (selectedConf->_state) {

            case CONFERENCE_STATE_ACTIVE_ATACHED:
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE);
Julien Bonjean's avatar
Julien Bonjean committed
334 335 336 337
                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);
338 339 340 341 342 343

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

344 345 346 347 348
                break;

            case CONFERENCE_STATE_ACTIVE_DETACHED:
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE);
Julien Bonjean's avatar
Julien Bonjean committed
349 350 351 352
                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);
353 354 355 356 357 358

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

359 360
                break;

361
            case CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD:
362
                DEBUG ("UIManager: Conference state record");
363 364
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE);
Julien Bonjean's avatar
Julien Bonjean committed
365 366 367 368
                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);
369 370 371 372 373 374

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

375 376 377
                break;

            case CONFERENCE_STATE_HOLD:
378
            case CONFERENCE_STATE_HOLD_RECORD:
379 380
                gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE);
                gtk_widget_set_sensitive (GTK_WIDGET (offHoldToolbar), TRUE);
Julien Bonjean's avatar
Julien Bonjean committed
381 382 383 384
                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);
385 386 387 388 389 390

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

391 392 393
                break;

            default:
Julien Bonjean's avatar
Julien Bonjean committed
394
                WARN ("Should not happen in update_action()!");
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
                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();
        }
    }
411 412
}

413 414
void
update_voicemail_status (void)
415
{
416 417 418 419 420 421 422 423 424
    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);
425 426
}

427
static void
Julien Bonjean's avatar
Julien Bonjean committed
428
volume_bar_cb (GtkToggleAction *togglemenuitem, gpointer user_data UNUSED)
429
{
430 431 432 433 434 435 436 437 438
    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);
439 440
}

441
static void
Julien Bonjean's avatar
Julien Bonjean committed
442
dialpad_bar_cb (GtkToggleAction *togglemenuitem, gpointer user_data UNUSED)
443
{
444 445 446 447 448 449 450 451 452 453
    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);
454

455 456
}

457
static void
Julien Bonjean's avatar
Julien Bonjean committed
458
help_contents_cb (GtkAction *action UNUSED)
459
{
460
    GError *error = NULL;
461

462 463 464 465 466 467
    gnome_help_display ("sflphone.xml", NULL, &error);

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

470 471
static void
help_about (void * foo UNUSED)
472
{
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
    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."),
495
                           "copyright", "Copyright © 2004-2011 Savoir-faire Linux Inc.", "name",
496 497
                           PACKAGE, "title", _ ("About SFLphone"), "version", VERSION, "website",
                           "http://www.sflphone.org", NULL);
498 499 500 501 502

}

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

503 504
static void
call_new_call (void * foo UNUSED)
505
{
506 507
    DEBUG ("UIManager: New call button pressed");

508
    sflphone_new_call();
509 510
}

511 512
static void
call_quit (void * foo UNUSED)
513
{
514
    sflphone_quit();
515 516
}

517 518
static void
call_minimize (void * foo UNUSED)
519
{
520

521 522 523 524 525 526
    if (eel_gconf_get_integer (SHOW_STATUSICON)) {
        gtk_widget_hide (GTK_WIDGET (get_main_window()));
        set_minimized (TRUE);
    } else {
        sflphone_quit ();
    }
527 528
}

529 530
static void
switch_account (GtkWidget* item, gpointer data UNUSED)
531
{
532 533 534 535
    account_t* acc = g_object_get_data (G_OBJECT (item), "account");
    DEBUG ("%s" , acc->accountID);
    account_list_set_current (acc);
    status_bar_display_account();
536 537
}

538 539
static void
call_hold (void* foo UNUSED)
540
{
541 542 543
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
    conference_obj_t * selectedConf = calltab_get_selected_conf();

544
    DEBUG ("UIManager: Hold button pressed");
545

546 547 548 549 550 551 552 553 554 555
    if (selectedCall) {
        if (selectedCall->_state == CALL_STATE_HOLD) {
            sflphone_off_hold();
        } else {
            sflphone_on_hold();
        }
    } else if (selectedConf) {

        switch (selectedConf->_state) {

556
            case CONFERENCE_STATE_HOLD:
557 558
                selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
                sflphone_conference_off_hold (selectedConf);
559 560 561 562 563
                break;
            case CONFERENCE_STATE_HOLD_RECORD:
                selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
                sflphone_conference_off_hold (selectedConf);
                break;
564 565

            case CONFERENCE_STATE_ACTIVE_ATACHED:
566
            case CONFERENCE_STATE_ACTIVE_DETACHED:
567 568
                selectedConf->_state = CONFERENCE_STATE_HOLD;
                sflphone_conference_on_hold (selectedConf);
569 570 571 572 573 574
                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;
575 576 577 578 579
            default:
                break;
        }

    }
580 581
}

582
static void
583
call_im (void* foo UNUSED)
Jonas Fonseca's avatar
im  
Jonas Fonseca committed
584
{
585 586
    callable_obj_t *selectedCall = calltab_get_selected_call (current_calls);
    conference_obj_t *selectedConf = calltab_get_selected_conf();
587

588 589 590
    if (calltab_get_selected_type (current_calls) == A_CALL) {

        if (selectedCall) {
591
            im_widget_display ( (IMWidget **) (&selectedCall->_im_widget), NULL, selectedCall->_callID, NULL);
592
        } else {
593
            WARN ("Sorry. Instant messaging is not allowed outside a call\n");
594
        }
595
    } else {
596
        if (selectedConf) {
597
            im_widget_display ( (IMWidget **) (&selectedConf->_im_widget), NULL, selectedConf->_confID, NULL);
598
        } else {
599
            WARN ("Sorry. Instant messaging is not allowed outside a call\n");
600
        }
601
    }
Jonas Fonseca's avatar
im  
Jonas Fonseca committed
602 603
}

604 605
static void
conference_hold (void* foo UNUSED)
606
{
607 608
    conference_obj_t * selectedConf = calltab_get_selected_conf();

609 610
    DEBUG ("UIManager: Hold button pressed (conference)");

611
    switch (selectedConf->_state) {
612
        case CONFERENCE_STATE_HOLD:
613 614
            selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
            sflphone_conference_off_hold (selectedConf);
615 616 617 618 619
            break;
        case CONFERENCE_STATE_HOLD_RECORD:
            selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
            sflphone_conference_off_hold (selectedConf);
            break;
620
        case CONFERENCE_STATE_ACTIVE_ATACHED:
621
        case CONFERENCE_STATE_ACTIVE_DETACHED:
622 623
            selectedConf->_state = CONFERENCE_STATE_HOLD;
            sflphone_conference_on_hold (selectedConf);
624 625 626 627 628
            break;
        case CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD:
        case CONFERENCE_STATE_ACTIVE_DETACHED_RECORD:
            selectedConf->_state = CONFERENCE_STATE_HOLD_RECORD;
            sflphone_conference_on_hold(selectedConf);
629 630 631
        default:
            break;
    }
632 633
}

634 635
static void
call_pick_up (void * foo UNUSED)
636
{
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
    DEBUG ("------ call_button -----");
    callable_obj_t * selectedCall;
    callable_obj_t* new_call;

    selectedCall = calltab_get_selected_call (active_calltree);

    if (calllist_get_size (current_calls) > 0)
        sflphone_pick_up();

    else if (calllist_get_size (active_calltree) > 0) {
        if (selectedCall) {
            create_new_call (CALL, CALL_STATE_DIALING, "", "", "",
                             selectedCall->_peer_number, &new_call);

            calllist_add (current_calls, new_call);
            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);
    }
663 664
}

665 666
static void
call_hang_up (void)
667
{
668 669

    DEBUG ("UIManager: Hang up button pressed (call)");
670 671 672 673 674
    /*
     * [#3020]	Restore the record toggle button
     *			We set it to FALSE, as when we hang up a call, the recording is stopped.
     */
    gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (recordWidget), FALSE);
675

676
    sflphone_hang_up();
677

678 679
}

680 681
static void
conference_hang_up (void)
682
{
683 684
    DEBUG ("UIManager: Hang up button pressed (conference)");

685
    sflphone_conference_hang_up();
686 687
}

688 689
static void
call_record (void)
690
{
691 692
    DEBUG ("UIManager: Record button pressed");

693
    sflphone_rec_call();
694 695
}

696 697
static void
call_configuration_assistant (void * foo UNUSED)
698 699
{
#if GTK_CHECK_VERSION(2,10,0)
700
    build_wizard();
701 702 703
#endif
}

704 705
static void
remove_from_history (void * foo UNUSED)
706
{
707 708 709
    callable_obj_t* c = calltab_get_selected_call (history);

    if (c) {
710
        DEBUG ("UIManager: Remove the call from the history");
711 712
        calllist_remove_from_history (c);
    }
713 714
}

715 716
static void
call_back (void * foo UNUSED)
717
{
718
    callable_obj_t *selected_call, *new_call;
719

720
    selected_call = calltab_get_selected_call (active_calltree);
721

722 723 724
    if (selected_call) {
        create_new_call (CALL, CALL_STATE_DIALING, "", "",
                         selected_call->_peer_name, selected_call->_peer_number, &new_call);
725

726 727 728 729 730
        calllist_add (current_calls, new_call);
        calltree_add_call (current_calls, new_call, NULL);
        sflphone_place_call (new_call);
        calltree_display (current_calls);
    }
731 732
}

733 734
static void
edit_preferences (void * foo UNUSED)
735
{
736
    show_preferences_dialog();
737 738
}

739 740
static void
edit_accounts (void * foo UNUSED)
741
{
742
    show_account_list_config_dialog();
743 744 745
}

// The menu Edit/Copy should copy the current selected call's number
746 747
static void
edit_copy (void * foo UNUSED)
748
{
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
    GtkClipboard* clip = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
    callable_obj_t * selectedCall = calltab_get_selected_call (current_calls);
    gchar * no = NULL;

    if (selectedCall) {
        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_HOLD:
            case CALL_STATE_BUSY:
            case CALL_STATE_FAILURE:
            case CALL_STATE_INCOMING:
            default:
                no = selectedCall->_peer_number;
                break;
        }

770
        DEBUG ("UIManager: Clipboard number: %s\n", no);
771 772
        gtk_clipboard_set_text (clip, no, strlen (no));
    }
773 774 775 776

}

// The menu Edit/Paste should paste the clipboard into the current selected call
777 778
static void
edit_paste (void * foo UNUSED)
779
{
780

781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
    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:
            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);
                    // g_free(temp);
                    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);
849
        DEBUG ("UIManager: TO: %s", selectedCall->_peer_number);
850 851 852 853 854 855

        g_free (selectedCall->_peer_info);
        selectedCall->_peer_info = g_strconcat ("\"\" <",
                                                selectedCall->_peer_number, ">", NULL);
        calltree_update_call (current_calls, selectedCall, NULL);
    }
856 857 858

}

859 860
static void
clear_history (void)
861
{
862 863 864
    if (calllist_get_size (history) != 0) {
        calllist_clean_history();
    }
865 866
}

867 868 869
/**
 * Transfert the line
 */
870
static void
871
call_transfer_cb()
872
{
873 874 875
    gboolean active = gtk_toggle_tool_button_get_active (
                          GTK_TOGGLE_TOOL_BUTTON (transferToolbar));
    active ? sflphone_set_transfert() : sflphone_unset_transfert();
876 877
}

878 879
static void
call_mailbox_cb (void)
880
{
881 882
    account_t* current;
    callable_obj_t *mailbox_call;
Julien Bonjean's avatar
Julien Bonjean committed
883
    gchar *to, *account_id;
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900

    current = account_list_get_current();

    if (current == NULL) // Should not happens
        return;

    to = g_strdup (g_hash_table_lookup (current->properties, ACCOUNT_MAILBOX));
    account_id = g_strdup (current->accountID);

    create_new_call (CALL, CALL_STATE_DIALING, "", account_id, _ ("Voicemail"), to,
                     &mailbox_call);
    DEBUG ("TO : %s" , mailbox_call->_peer_number);
    calllist_add (current_calls, mailbox_call);
    calltree_add_call (current_calls, mailbox_call, NULL);
    update_actions();
    sflphone_place_call (mailbox_call);
    calltree_display (current_calls);
901 902
}

903
static void
Julien Bonjean's avatar
Julien Bonjean committed
904
toggle_history_cb (GtkToggleAction *action, gpointer user_data UNUSED)
905
{
906 907 908
    gboolean toggle;
    toggle = gtk_toggle_action_get_active (action);
    (toggle) ? calltree_display (history) : calltree_display (current_calls);
909 910
}

911
static void
Julien Bonjean's avatar
Julien Bonjean committed
912
toggle_addressbook_cb (GtkToggleAction *action, gpointer user_data UNUSED)
913
{
914 915 916
    gboolean toggle;
    toggle = gtk_toggle_action_get_active (action);
    (toggle) ? calltree_display (contacts) : calltree_display (current_calls);
917 918
}

919 920 921 922
static const GtkActionEntry menu_entries[] = {

    // Call Menu
    { "Call", NULL, N_ ("Call") },
Alexandre Savard's avatar
Alexandre Savard committed
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
    {
        "NewCall", GTK_STOCK_DIAL, N_ ("_New call"), "<control>N",
        N_ ("Place a new call"), G_CALLBACK (call_new_call)
    },
    {
        "PickUp", GTK_STOCK_PICKUP, N_ ("_Pick up"), NULL,
        N_ ("Answer the call"), G_CALLBACK (call_pick_up)
    },
    {
        "HangUp", GTK_STOCK_HANGUP, N_ ("_Hang up"), "<control>S",
        N_ ("Finish the call"), G_CALLBACK (call_hang_up)
    },
    {
        "OnHold", GTK_STOCK_ONHOLD, N_ ("O_n hold"), "<control>P",
        N_ ("Place the call on hold"), G_CALLBACK (call_hold)
    },
    {
        "OffHold", GTK_STOCK_OFFHOLD, N_ ("O_ff hold"), "<control>P",
        N_ ("Place the call off hold"), G_CALLBACK (call_hold)
    },
    {
        "InstantMessaging", GTK_STOCK_IM, N_ ("Send _message"), "<control>M",
        N_ ("Send message"), G_CALLBACK (call_im)
    },
    {
        "AccountAssistant", NULL, N_ ("Configuration _Assistant"), NULL,
        N_ ("Run the configuration assistant"),
        G_CALLBACK (call_configuration_assistant)
    },
    {
        "Voicemail", "mail-read", N_ ("Voicemail"), NULL,
        N_ ("Call your voicemail"), G_CALLBACK (call_mailbox_cb)
    },
    {
        "Close", GTK_STOCK_CLOSE, N_ ("_Close"), "<control>W",
        N_ ("Minimize to system tray"), G_CALLBACK (call_minimize)
    },
    {
        "Quit", GTK_STOCK_CLOSE, N_ ("_Quit"), "<control>Q",
        N_ ("Quit the program"), G_CALLBACK (call_quit)
    },
964 965 966

    // Edit Menu
    { "Edit", NULL, N_ ("_Edit") },
Alexandre Savard's avatar
Alexandre Savard committed
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
    {
        "Copy", GTK_STOCK_COPY, N_ ("_Copy"), "<control>C",
        N_ ("Copy the selection"), G_CALLBACK (edit_copy)
    },
    {
        "Paste", GTK_STOCK_PASTE, N_ ("_Paste"), "<control>V",
        N_ ("Paste the clipboard"), G_CALLBACK (edit_paste)
    },
    {
        "ClearHistory", GTK_STOCK_CLEAR, N_ ("Clear _history"), NULL,
        N_ ("Clear the call history"), G_CALLBACK (clear_history)
    },
    {
        "Accounts", NULL, N_ ("_Accounts"), NULL, N_ ("Edit your accounts"),
        G_CALLBACK (edit_accounts)
    },
    {
        "Preferences", GTK_STOCK_PREFERENCES, N_ ("_Preferences"), NULL,
        N_ ("Change your preferences"), G_CALLBACK (edit_preferences)
    },
987 988 989 990 991 992

    // View Menu
    { "View", NULL, N_ ("_View") },

    // Help menu
    { "Help", NULL, N_ ("_Help") },
Alexandre Savard's avatar
Alexandre Savard committed
993 994 995 996 997 998 999 1000
    {
        "HelpContents", GTK_STOCK_HELP, N_ ("Contents"), "F1",
        N_ ("Open the manual"), G_CALLBACK (help_contents_cb)
    },
    {
        "About", GTK_STOCK_ABOUT, NULL, NULL, N_ ("About this application"),
        G_CALLBACK (help_about)
    }
1001 1002

};
1003

1004 1005
static const GtkToggleActionEntry toggle_menu_entries[] = {

Julien Bonjean's avatar
Julien Bonjean committed
1006 1007 1008 1009 1010 1011 1012
    { "Transfer", GTK_STOCK_TRANSFER, N_ ("_Transfer"), "<control>T", N_ ("Transfer the call"), NULL, TRUE },
    { "Record", GTK_STOCK_MEDIA_RECORD, N_ ("_Record"), "<control>R", N_ ("Record the current conversation"), NULL, TRUE },
    { "Toolbar", NULL, N_ ("_Show toolbar"), "<control>T", N_ ("Show the toolbar"), NULL, TRUE },
    { "Dialpad", NULL, N_ ("_Dialpad"), "<control>D", N_ ("Show the dialpad"), G_CALLBACK (dialpad_bar_cb), TRUE },
    { "VolumeControls", NULL, N_ ("_Volume controls"), "<control>V", N_ ("Show the volume controls"), G_CALLBACK (volume_bar_cb), TRUE },
    { "History", "appointment-soon", N_ ("_History"), NULL, N_ ("Calls history"), G_CALLBACK (toggle_history_cb), FALSE },
    { "Addressbook", GTK_STOCK_ADDRESSBOOK, N_ ("_Address book"), NULL, N_ ("Address book"), G_CALLBACK (toggle_addressbook_cb), FALSE }
1013
};
1014

1015 1016
gboolean
uimanager_new (GtkUIManager **_ui_manager)
1017 1018
{

1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
    GtkUIManager *ui_manager;
    GtkActionGroup *action_group;
    GtkWidget *window;
    gchar *path;
    GError *error = NULL;

    window = get_main_window();
    ui_manager = gtk_ui_manager_new();

    /* Create an accel group for window's shortcuts */
    path = g_build_filename (SFLPHONE_UIDIR_UNINSTALLED, "./ui.xml", NULL);

    if (g_file_test (path, G_FILE_TEST_EXISTS)) {
        gtk_ui_manager_add_ui_from_file (ui_manager, path, &error);

        if (error != NULL) {
            g_error_free (error);
            return FALSE;
        }

        g_free (path);
    } else {
        path = g_build_filename (SFLPHONE_UIDIR, "./ui.xml", NULL);
1042

1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
        if (g_file_test (path, G_FILE_TEST_EXISTS)) {
            gtk_ui_manager_add_ui_from_file (ui_manager, path, &error);

            if (error != NULL) {
                g_error_free (error);
                return FALSE;
            }

            g_free (path);
        } else
            return FALSE;
    }

    action_group = gtk_action_group_new ("SFLphoneWindowActions");
    // To translate label and tooltip entries
    gtk_action_group_set_translation_domain (action_group, "sflphone-client-gnome");
    gtk_action_group_add_actions (action_group, menu_entries,
                                  G_N_ELEMENTS (menu_entries), window);
    gtk_action_group_add_toggle_actions (action_group, toggle_menu_entries,
                                         G_N_ELEMENTS (toggle_menu_entries), window);
    //gtk_action_group_add_radio_actions (action_group, radio_menu_entries, G_N_ELEMENTS (radio_menu_entries), CALLTREE_CALLS, G_CALLBACK (calltree_switch_cb), window);
    gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);

    *_ui_manager = ui_manager;

    return TRUE;
1069 1070
}

1071 1072
static void
edit_number_cb (GtkWidget *widget UNUSED, gpointer user_data)
1073
{
1074

1075
    show_edit_number ( (callable_obj_t*) user_data);
1076 1077
}

1078 1079
void
add_registered_accounts_to_menu (GtkWidget *menu)
1080
{
1081

1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
    GtkWidget *menu_items;
    unsigned int i;
    account_t* acc, *current;
    gchar* alias;

    menu_items = gtk_separator_menu_item_new();
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
    gtk_widget_show (menu_items);

    for (i = 0; i < account_list_get_size(); i++) {
        acc = account_list_get_nth (i);

        // Display only the registered accounts
        if (g_strcasecmp (account_state_name (acc->state), account_state_name (
                              ACCOUNT_STATE_REGISTERED)) == 0) {
            alias = g_strconcat (g_hash_table_lookup (acc->properties,
                                 ACCOUNT_ALIAS), " - ", g_hash_table_lookup (acc->properties,
                                         ACCOUNT_TYPE), NULL);
            menu_items = gtk_check_menu_item_new_with_mnemonic (alias);
            gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
            g_object_set_data (G_OBJECT (menu_items), "account", acc);
            g_free (alias);
            current = account_list_get_current();

            if (current) {
                gtk_check_menu_item_set_active (
                    GTK_CHECK_MENU_ITEM (menu_items),
                    (g_strcasecmp (acc->accountID, current->accountID) == 0) ? TRUE
                    : FALSE);
            }

            g_signal_connect (G_OBJECT (menu_items), "activate",
                              G_CALLBACK (switch_account),
                              NULL);
            gtk_widget_show (menu_items);
        } // fi
    }
1119

1120
}
1121

1122 1123
void
show_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
Emmanuel Milou's avatar