uimanager.c 46.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 *  Copyright (C) 2009 Savoir-Faire Linux inc.
 *  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.
 */

#include <config.h>
21
#include <preferencesdialog.h>
22
23
24
25
#include <dbus/dbus.h>
#include <mainwindow.h>
#include <assistant.h>
#include <gtk/gtk.h>
26
#include <string.h>
27
28
#include <glib/gprintf.h>
#include <libgnome/gnome-help.h>
29
#include <uimanager.h>
30
#include <statusicon.h>
31

32
static GtkWidget *toolbar;
33
static GtkWidget *toolbarWindows;
34

35
guint transfertButtonConnId; //The button toggled signal connection ID
36
guint recordButtonConnId; //The button toggled signal connection ID
37

38
GtkAction * pickUpAction;
39
GtkWidget * pickUpWidget;
40
GtkAction * newCallAction;
41
GtkWidget * newCallWidget;
42
GtkAction * hangUpAction;
43
GtkWidget * hangUpWidget;
44
GtkWidget * holdMenu;
45
GtkWidget * holdToolbar;
46
GtkWidget * offHoldToolbar;
47
48
49
50
GtkWidget * transferToolbar;
GtkAction * copyAction;
GtkAction * pasteAction;
GtkAction * recordAction;
51
GtkWidget * recordWidget;
52
GtkAction * voicemailAction;
53
GtkWidget * voicemailToolbar;
54
55
56
57

GtkWidget * editable_num;
GtkDialog * edit_dialog;

58
59
60
enum
{
  CALLTREE_CALLS, CALLTREE_HISTORY, CALLTREE_CONTACTS
61
};
62

63
64
static gboolean
is_inserted(GtkWidget* button, GtkWidget *current_toolbar)
65
{
66
  return (GTK_WIDGET (button)->parent == GTK_WIDGET (current_toolbar));
67
68
}

69
70
void
update_actions()
71
{
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  DEBUG("Update action");

  gtk_action_set_sensitive(GTK_ACTION (newCallAction), TRUE);
  gtk_action_set_sensitive(GTK_ACTION (pickUpAction), FALSE);
  gtk_action_set_sensitive(GTK_ACTION (hangUpAction), FALSE);

  g_object_ref(hangUpWidget);
  g_object_ref(recordWidget);
  g_object_ref(holdToolbar);
  g_object_ref(offHoldToolbar);
  g_object_ref(contactButton);
  g_object_ref(transferToolbar);
  g_object_ref(voicemailToolbar);

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

  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);
118
  gtk_widget_set_sensitive(GTK_WIDGET (recordWidget), FALSE);
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
  gtk_action_set_sensitive(GTK_ACTION (copyAction), FALSE);
  gtk_widget_set_sensitive(GTK_WIDGET(contactButton), 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 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"));
        }
    }

149
150
151
  // 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);
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
187
188
189
190
191
192
193
194
195
196
197
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
223
224
225
226

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

  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);
        // Replace the hold button with the off-hold button
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
            1);
        gtk_toolbar_insert(GTK_TOOLBAR(toolbar),
            GTK_TOOL_ITEM (offHoldToolbar), 2);
        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);
        gtk_container_remove(GTK_CONTAINER (toolbar),
            GTK_WIDGET (newCallWidget));
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (pickUpWidget),
            0);
        if (active_calltree == current_calls)
          gtk_toolbar_insert(GTK_TOOLBAR (toolbar),
              GTK_TOOL_ITEM (hangUpWidget), 1);
        break;
      case CALL_STATE_CURRENT:
      case CALL_STATE_RECORD:
        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);
227

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
        break;
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
        gtk_action_set_sensitive(GTK_ACTION(hangUpAction), TRUE);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
            1);
        break;
      case CALL_STATE_TRANSFERT:
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
            1);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar),
            GTK_TOOL_ITEM (transferToolbar), 2);
        gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId);
        gtk_toggle_tool_button_set_active(
            GTK_TOGGLE_TOOL_BUTTON (transferToolbar), TRUE);
        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:
        WARN("Should not happen in update_actions()!")
        ;
        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);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
            1);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar),
            2);
        break;

      case CONFERENCE_STATE_ACTIVE_DETACHED:
        gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE);
        gtk_widget_set_sensitive(GTK_WIDGET (holdToolbar), TRUE);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
            1);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar),
            2);
        break;

      case CONFERENCE_STATE_RECORD:
        gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE);
        gtk_widget_set_sensitive(GTK_WIDGET (holdToolbar), TRUE);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
            1);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar),
            2);
        break;

      case CONFERENCE_STATE_HOLD:
        gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE);
        gtk_widget_set_sensitive(GTK_WIDGET (offHoldToolbar), TRUE);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget),
            1);
        gtk_toolbar_insert(GTK_TOOLBAR (toolbar),
            GTK_TOOL_ITEM (offHoldToolbar), 2);
        break;

      default:
        WARN("Should not happen in update_action()!")
        ;
        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();
        }
    }
321
322
}

323
324
void
update_voicemail_status(void)
325
{
326
327
328
329
330
331
332
333
334
  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);
335
336
}

337
338
static void
volume_bar_cb(GtkToggleAction *togglemenuitem, gpointer user_data)
339
{
340
341
342
343
344
345
  gboolean toggled = gtk_toggle_action_get_active(togglemenuitem);
  if (toggled == SHOW_VOLUME)
    return;
  main_window_volume_controls(toggled);
  if (toggled || SHOW_VOLUME)
    dbus_set_volume_controls(toggled);
346
347
}

348
349
static void
dialpad_bar_cb(GtkToggleAction *togglemenuitem, gpointer user_data)
350
{
351
352
353
354
355
356
  gboolean toggled = gtk_toggle_action_get_active(togglemenuitem);
  if (toggled == SHOW_DIALPAD)
    return;
  main_window_dialpad(toggled);
  if (toggled || SHOW_DIALPAD)
    dbus_set_dialpad(toggled);
357
358
}

359
360
static void
help_contents_cb(GtkAction *action)
361
{
362
363
364
  GError *error = NULL;

  gnome_help_display("sflphone.xml", NULL, &error);
Alexandre Savard's avatar
Alexandre Savard committed
365
  if (error != NULL) {
366
367
      g_warning("%s", error->message);
      g_error_free(error);
Alexandre Savard's avatar
Alexandre Savard committed
368
  }
369
370
}

371
372
static void
help_about(void * foo UNUSED)
373
{
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
  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."),
      "copyright", "Copyright © 2004-2009 Savoir-faire Linux Inc.", "name",
      PACKAGE, "title", _("About SFLphone"), "version", VERSION, "website",
      "http://www.sflphone.org", NULL);
399
400
401
402
403

}

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

404
405
static void
call_new_call(void * foo UNUSED)
406
{
407
  sflphone_new_call();
408
409
}

410
411
static void
call_quit(void * foo UNUSED)
412
{
413
  sflphone_quit();
414
415
}

416
417
static void
call_minimize(void * foo UNUSED)
418
{
419
420
421
422
423
424
425
426

    if (g_strcasecmp (dbus_is_status_icon_enabled (), "true") == 0) {
        gtk_widget_hide(GTK_WIDGET( get_main_window() ));
        set_minimized(TRUE);
    }
    else {
          sflphone_quit ();
    }
427
428
}

429
430
static void
switch_account(GtkWidget* item, gpointer data UNUSED)
431
{
432
433
434
435
  account_t* acc = g_object_get_data(G_OBJECT(item), "account");
  DEBUG("%s" , acc->accountID);
  account_list_set_current(acc);
  status_bar_display_account();
436
437
}

438
439
static void
call_hold(void* foo UNUSED)
440
{
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
  callable_obj_t * selectedCall = calltab_get_selected_call(current_calls);
  conference_obj_t * selectedConf = calltab_get_selected_conf();

  if (selectedCall)
    {
      if (selectedCall->_state == CALL_STATE_HOLD)
        {
          sflphone_off_hold();
        }
      else
        {
          sflphone_on_hold();
        }
    }
  else if (selectedConf)
    {

      switch (selectedConf->_state)
        {

      case CONFERENCE_STATE_HOLD:
        {
          selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
          sflphone_conference_off_hold(selectedConf);
        }
        break;

      case CONFERENCE_STATE_ACTIVE_ATACHED:
      case CONFERENCE_STATE_ACTIVE_DETACHED:
        {
          selectedConf->_state = CONFERENCE_STATE_HOLD;
          sflphone_conference_on_hold(selectedConf);
        }
        break;
      default:
        break;
        }

    }
480
481
}

482
483
static void
conference_hold(void* foo UNUSED)
484
{
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
  conference_obj_t * selectedConf = calltab_get_selected_conf();

  switch (selectedConf->_state)
    {
  case CONFERENCE_STATE_HOLD:
    {
      selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
      sflphone_conference_off_hold(selectedConf);
    }
    break;

  case CONFERENCE_STATE_ACTIVE_ATACHED:
  case CONFERENCE_STATE_ACTIVE_DETACHED:
    {
      selectedConf->_state = CONFERENCE_STATE_HOLD;
      sflphone_conference_on_hold(selectedConf);
    }
    break;
  default:
    break;
    }
506
507
}

508
509
static void
call_pick_up(void * foo UNUSED)
510
{
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
  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);
    }
543
544
}

545
546
static void
call_hang_up(void)
547
{
548
549
550
551
552
553
554
555
	/* 
	 * [#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);
  
	sflphone_hang_up();

556
557
}

558
559
static void
conference_hang_up(void)
560
{
561
  sflphone_conference_hang_up();
562
563
}

564
565
static void
call_record(void)
566
{
567
  sflphone_rec_call();
568
569
}

570
571
static void
call_configuration_assistant(void * foo UNUSED)
572
573
{
#if GTK_CHECK_VERSION(2,10,0)
574
  build_wizard();
575
576
577
#endif
}

578
579
static void
remove_from_history(void * foo UNUSED)
580
{
581
582
583
584
585
586
  callable_obj_t* c = calltab_get_selected_call(history);
  if (c)
    {
      DEBUG("Remove the call from the history");
      calllist_remove_from_history(c);
    }
587
588
}

589
590
static void
call_back(void * foo UNUSED)
591
{
592
  callable_obj_t *selected_call, *new_call;
593

594
  selected_call = calltab_get_selected_call(active_calltree);
595

596
597
598
599
  if (selected_call)
    {
      create_new_call(CALL, CALL_STATE_DIALING, "", "",
          selected_call->_peer_name, selected_call->_peer_number, &new_call);
600

601
602
603
604
605
      calllist_add(current_calls, new_call);
      calltree_add_call(current_calls, new_call, NULL);
      sflphone_place_call(new_call);
      calltree_display(current_calls);
    }
606
607
}

608
609
static void
edit_preferences(void * foo UNUSED)
610
{
611
  show_preferences_dialog();
612
613
}

614
615
static void
edit_accounts(void * foo UNUSED)
616
{
617
  show_account_list_config_dialog();
618
619
620
}

// The menu Edit/Copy should copy the current selected call's number
621
622
static void
edit_copy(void * foo UNUSED)
623
{
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
  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;
        }
      DEBUG("Clipboard number: %s\n", no);
      gtk_clipboard_set_text(clip, no, strlen(no));
    }
649
650
651
652

}

// The menu Edit/Paste should paste the clipboard into the current selected call
653
654
static void
edit_paste(void * foo UNUSED)
655
{
656

657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
  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();

          gchar * before = selectedCall->_peer_number;
          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);
      DEBUG("TO: %s", selectedCall->_peer_number);

      g_free(selectedCall->_peer_info);
      selectedCall->_peer_info = g_strconcat("\"\" <",
          selectedCall->_peer_number, ">", NULL);
      calltree_update_call(current_calls, selectedCall, NULL);
    }
739
740
741

}

742
743
static void
clear_history(void)
744
{
745
746
747
748
  if (calllist_get_size(history) != 0)
    {
      calllist_clean_history();
    }
749
750
}

751
752
753
/**
 * Transfert the line
 */
754
755
static void
call_transfer_cb()
756
{
757
758
759
  gboolean active = gtk_toggle_tool_button_get_active(
      GTK_TOGGLE_TOOL_BUTTON (transferToolbar));
  active ? sflphone_set_transfert() : sflphone_unset_transfert();
760
761
}

762
763
static void
call_mailbox_cb(void)
764
{
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
  account_t* current;
  callable_obj_t *mailbox_call;
  gchar *to, *from, *account_id;

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

786
787
static void
toggle_history_cb(GtkToggleAction *action, gpointer user_data)
788
{
789
790
791
  gboolean toggle;
  toggle = gtk_toggle_action_get_active(action);
  (toggle) ? calltree_display(history) : calltree_display(current_calls);
792
793
}

794
795
static void
toggle_addressbook_cb(GtkToggleAction *action, gpointer user_data)
796
{
797
798
799
  gboolean toggle;
  toggle = gtk_toggle_action_get_active(action);
  (toggle) ? calltree_display(contacts) : calltree_display(current_calls);
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
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
static const GtkActionEntry menu_entries[] =
  {

  // Call Menu
        { "Call", NULL, N_("Call") },
        { "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) },
        { "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) },

      // Edit Menu
        { "Edit", NULL, N_("_Edit") },
        { "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) },

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

      // Help menu
        { "Help", NULL, N_("_Help") },
        { "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) }

  };

static const GtkToggleActionEntry toggle_menu_entries[] =
  {

    { "Transfer", GTK_STOCK_TRANSFER, N_("_Transfer"), "<control>T",
        N_("Transfer the call"), NULL }, //G_CALLBACK (call_transfer_cb) },
        { "Record", GTK_STOCK_MEDIA_RECORD, N_("_Record"), "<control>R",
            N_("Record the current conversation"), NULL }, // G_CALLBACK (call_record) },
        { "Toolbar", NULL, N_("_Show toolbar"), "<control>T",
            N_("Show the toolbar"), NULL },
        { "Dialpad", NULL, N_("_Dialpad"), "<control>D",
            N_("Show the dialpad"), G_CALLBACK (dialpad_bar_cb) },
        { "VolumeControls", NULL, N_("_Volume controls"), "<control>V",
            N_("Show the volume controls"), G_CALLBACK (volume_bar_cb) },
        { "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 }

  };

gboolean
uimanager_new(GtkUIManager **_ui_manager)
{
875

876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
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
  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);
      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;
928
929
}

930
931
932
static void
edit_number_cb(GtkWidget *widget UNUSED, gpointer user_data)
{
933

934
  show_edit_number((callable_obj_t*) user_data);
935
936
}

937
938
939
void
add_registered_accounts_to_menu(GtkWidget *menu)
{
940

941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
  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
    }
978

979
}
980

981
982
void
show_popup_menu(GtkWidget *my_widget, GdkEventButton *event)
983
{
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
  // TODO update the selection to make sure the call under the mouse is the call selected

  // call type boolean
  gboolean pickup = FALSE, hangup = FALSE, hold = FALSE, copy = FALSE, record =
      FALSE, detach = FALSE;
  gboolean accounts = FALSE;

  // conference type boolean
  gboolean hangup_conf = FALSE, hold_conf = FALSE;

  callable_obj_t * selectedCall;
  conference_obj_t * selectedConf;

  if (calltab_get_selected_type(current_calls) == A_CALL)
    {
      DEBUG("MENUS: SELECTED A CALL");
      selectedCall = calltab_get_selected_call(current_calls);
For faster browsing, not all history is shown. View entire blame