menus.c 19.5 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
2
/*
 *  Copyright (C) 2007 Savoir-Faire Linux inc.
3
 *  Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
4
5
6
 *                                                                              
 *  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
7
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
8
9
10
11
12
13
14
15
16
17
18
19
20
 *  (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 <menus.h>
21
#include <actions.h>
22
23
24
#include <calllist.h>
#include <calltree.h>
#include <config.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
25
#include <configwindow.h>
26
27
28
29
#include <dbus.h>
#include <mainwindow.h>
#include <screen.h>
#include <gtk/gtk.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
30

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
31
32
#include <string.h> // for strlen

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
33
34
GtkWidget * pickUpMenu;
GtkWidget * hangUpMenu;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
35
GtkWidget * newCallMenu;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
36
GtkWidget * holdMenu;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
37
38
GtkWidget * copyMenu;
GtkWidget * pasteMenu;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
39
guint holdConnId;     //The hold_menu signal connection ID
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
40
41

void update_menus()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
42
43
44
45
{ 
  //Block signals for holdMenu
  gtk_signal_handler_block(GTK_OBJECT(holdMenu), holdConnId);
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
46
47
  gtk_widget_set_sensitive( GTK_WIDGET(pickUpMenu), FALSE);
  gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
48
  gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu),FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
49
  gtk_widget_set_sensitive( GTK_WIDGET(holdMenu),   FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
50
  gtk_widget_set_sensitive( GTK_WIDGET(copyMenu),   FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
51
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(holdMenu), FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
52
53
54
55
	
	call_t * selectedCall = call_get_selected();
	if (selectedCall)
	{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
56
    gtk_widget_set_sensitive( GTK_WIDGET(copyMenu),   TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
57
58
59
60
61
62
63
64
65
    switch(selectedCall->state) 
  	{
  	  case CALL_STATE_INCOMING:
        gtk_widget_set_sensitive( GTK_WIDGET(pickUpMenu), TRUE);
        gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
        break;
      case CALL_STATE_HOLD:
        gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
        gtk_widget_set_sensitive( GTK_WIDGET(holdMenu),   TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
66
67
        gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu),TRUE);
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(holdMenu), TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
68
69
70
71
72
73
74
75
        break;
      case CALL_STATE_RINGING:
        gtk_widget_set_sensitive( GTK_WIDGET(pickUpMenu), TRUE);
        gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
        break;
      case CALL_STATE_DIALING:
        gtk_widget_set_sensitive( GTK_WIDGET(pickUpMenu), TRUE);
        gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
76
        gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu),TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
77
78
79
80
        break;
      case CALL_STATE_CURRENT:
        gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
        gtk_widget_set_sensitive( GTK_WIDGET(holdMenu),   TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
81
        gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu),TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
82
83
84
85
86
87
        break;
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
        gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
        break; 
  	  default:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
88
  	    g_warning("Should not happen in update_menus()!");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
89
90
  	    break;
  	}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
91
92
93
94
  } 
  else
  {
    gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu), TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
95
  }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
96
97
  gtk_signal_handler_unblock(holdMenu, holdConnId);
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
98
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
99
/* ----------------------------------------------------------------- */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
100
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
101
102
103
104
105
106
107
help_about ( void * foo)
{
  gchar *authors[] = {
    "Yan Morin <yan.morin@savoirfairelinux.com>", 
    "Jérôme Oufella <jerome.oufella@savoirfairelinux.com>",
    "Julien Plissonneau Duquene <julien.plissonneau.duquene@savoirfairelinux.com>",
    "Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>",
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
108
    "Pierre-Luc Beaudoin <pierre-luc@squidy.info>", 
Emmanuel Milou's avatar
Emmanuel Milou committed
109
    "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>"
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
110
111
112
113
    "Jean-Philippe Barrette-LaPierre",
    "Laurielle Lea",
    NULL};
  gchar *artists[] = {
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
114
    "Pierre-Luc Beaudoin <pierre-luc@squidy.info>", 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
115
116
117
118
    NULL};
  
  gtk_show_about_dialog( GTK_WINDOW(get_main_window()),
    "name", PACKAGE,
119
    "title", _("About SFLphone"),
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
120
121
122
    "version", VERSION,
    "website", "http://www.sflphone.org",
    "copyright", "Copyright © 2004-2007 Savoir-faire Linux Inc.",
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
123
    "translator-credits", "", 
124
    "comments", _("SFLphone is a VoIP client compatible with SIP and IAX2 protocols."),
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
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
    "artists", artists,
    "authors", authors,
    NULL);
}


GtkWidget * 
create_help_menu()
{
  GtkWidget * menu;
  GtkWidget * root_menu;
  GtkWidget * menu_items;
  
  menu      = gtk_menu_new ();
  
  /*menu_items = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  */
  menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_ABOUT, get_accel_group());
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  g_signal_connect_swapped (G_OBJECT (menu_items), "activate",
                  G_CALLBACK (help_about), 
                  NULL);
  gtk_widget_show (menu_items);
    
150
  root_menu = gtk_menu_item_new_with_mnemonic (_("_Help"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
151
152
153
154
155
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

  return root_menu;
}
/* ----------------------------------------------------------------- */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
156
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
157
call_new_call ( void * foo)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
158
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
159
  sflphone_new_call();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
160
161
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
162
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
163
call_quit ( void * foo)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
164
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
165
  sflphone_quit();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
166
167
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
168
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
169
170
call_hold  (void* foo)
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
171
172
173
  call_t * selectedCall = call_get_selected();
  
  if(selectedCall)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
174
  {
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
175
176
177
178
179
180
181
182
    if(selectedCall->state == CALL_STATE_HOLD)
    {
      sflphone_off_hold();
    }
    else
    {
      sflphone_on_hold();
    } 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
183
184
185
  } 
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
186
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
187
188
189
190
191
call_pick_up ( void * foo)
{
  sflphone_pick_up();
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
192
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
193
194
195
196
197
call_hang_up ( void * foo)
{
  sflphone_hang_up();
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
198
199
200
201
202
203
204
205
GtkWidget * 
create_call_menu()
{
  GtkWidget * menu;
  GtkWidget * root_menu;
  GtkWidget * menu_items;
  
  menu      = gtk_menu_new ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
206
 
207
  newCallMenu = gtk_image_menu_item_new_with_mnemonic(_("_New call"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
208
209
210
211
212
213
214
215
216
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), newCallMenu);
  g_signal_connect_swapped (G_OBJECT (newCallMenu), "activate",
                  G_CALLBACK (call_new_call), 
                  NULL);
  gtk_widget_show (newCallMenu);
  
  menu_items = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  
217
  pickUpMenu = gtk_image_menu_item_new_with_mnemonic(_("_Pick up"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
218
219
220
221
222
223
224
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), pickUpMenu);
  gtk_widget_set_sensitive( GTK_WIDGET(pickUpMenu), FALSE);
  g_signal_connect_swapped (G_OBJECT (pickUpMenu), "activate",
                  G_CALLBACK (call_pick_up), 
                  NULL);
  gtk_widget_show (pickUpMenu);
  
225
  hangUpMenu = gtk_image_menu_item_new_with_mnemonic(_("_Hang up"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
226
227
228
229
230
231
232
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), hangUpMenu);
  gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), FALSE);
  g_signal_connect_swapped (G_OBJECT (hangUpMenu), "activate",
                  G_CALLBACK (call_hang_up), 
                  NULL);
  gtk_widget_show (hangUpMenu);
  
233
  holdMenu = gtk_check_menu_item_new_with_mnemonic (_("On _Hold"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
234
235
236
237
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), holdMenu);
  gtk_widget_set_sensitive( GTK_WIDGET(holdMenu),   FALSE);
  //Here we connect only to activate
  //The toggled state is managed from update_menus()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
238
  holdConnId = g_signal_connect(G_OBJECT (holdMenu), "activate",
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
239
                  G_CALLBACK (call_hold), 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
240
241
242
243
244
245
246
247
248
249
250
251
252
253
                  NULL);
  gtk_widget_show (menu_items);
  
  menu_items = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  
  menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_QUIT, get_accel_group());
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  g_signal_connect_swapped (G_OBJECT (menu_items), "activate",
                  G_CALLBACK (call_quit), 
                  NULL);
  gtk_widget_show (menu_items);
    
  
254
  root_menu = gtk_menu_item_new_with_mnemonic (_("_Call"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
255
256
257
258
259
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

  return root_menu;
}
/* ----------------------------------------------------------------- */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
260

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
261
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
262
263
264
265
266
edit_preferences ( void * foo)
{
  show_config_window();
}

267
268
269
270
271
272
static void 
edit_accounts ( void * foo)
{
  show_accounts_window();
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
273
// The menu Edit/Copy should copy the current selected call's number
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
274
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
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
edit_copy ( void * foo)
{
  GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
  call_t * selectedCall = call_get_selected();
  gchar * no = NULL;
  
  if(selectedCall)
  {
    switch(selectedCall->state)
    {
      case CALL_STATE_TRANSFERT:  
      case CALL_STATE_DIALING:
      case CALL_STATE_RINGING:
        no = selectedCall->to;
        break;
      case CALL_STATE_CURRENT:
      case CALL_STATE_HOLD:
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
      case CALL_STATE_INCOMING:
      default:
        no = call_get_number(selectedCall);
        break;
    }
    
    gtk_clipboard_set_text (clip, no, strlen(no) );
  }
  
}

// The menu Edit/Paste should paste the clipboard into the current selected call
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
306
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
edit_paste ( void * foo)
{
  GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
  call_t * selectedCall = call_get_selected();
  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 = selectedCall->to;
          selectedCall->to = g_strconcat(selectedCall->to, no, NULL);
          g_free(before);
          g_print("TO: %s\n", selectedCall->to);
          
          if(selectedCall->state == CALL_STATE_DIALING)
          {
            g_free(selectedCall->from);
            selectedCall->from = g_strconcat("\"\" <", selectedCall->to, ">", NULL);
          }
          screen_set_call(selectedCall);
          update_call_tree(selectedCall);
        }
        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->to;
          selectedCall->to = g_strconcat(selectedCall->to, no, NULL);
          g_free(before);
          g_print("TO: %s\n", selectedCall->to);
          
          g_free(selectedCall->from);
          selectedCall->from = g_strconcat("\"\" <", selectedCall->to, ">", NULL);
          
          screen_set_call(selectedCall);
          update_call_tree(selectedCall);
        }
        break;
      case CALL_STATE_CURRENT:
      default:
        {
          int i;
          for(i = 0; i < strlen(no); i++)
          {
            gchar * oneNo = g_strndup(&no[i], 1);
            g_print("<%s>\n", oneNo);
            dbus_play_dtmf(oneNo);
             
            gchar * temp = g_strconcat(call_get_number(selectedCall), oneNo, NULL);
            gchar * before = selectedCall->from;
            selectedCall->from = g_strconcat("\"",call_get_name(selectedCall) ,"\" <", temp, ">", NULL);
            g_free(before);
            g_free(temp);
            screen_set_call(selectedCall);
            update_call_tree(selectedCall);
          
          }
        }
        break;
    }
    
  }
  else // There is no current call, create one
  {
    selectedCall = sflphone_new_call();
    
    gchar * before = selectedCall->to;
    selectedCall->to = g_strconcat(selectedCall->to, no, NULL);
    g_free(before);
    g_print("TO: %s\n", selectedCall->to);
    
    g_free(selectedCall->from);
    selectedCall->from = g_strconcat("\"\" <", selectedCall->to, ">", NULL);
    
    screen_set_call(selectedCall);
    update_call_tree(selectedCall);
  }
  
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
397
398
399
400
401
402
403
404
405
GtkWidget * 
create_edit_menu()
{
  GtkWidget * menu;
  GtkWidget * root_menu;
  GtkWidget * menu_items;
  
  menu      = gtk_menu_new ();

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
406
407
408
409
410
411
  copyMenu = gtk_image_menu_item_new_from_stock( GTK_STOCK_COPY, get_accel_group());
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), copyMenu);
  g_signal_connect_swapped (G_OBJECT (copyMenu), "activate",
                  G_CALLBACK (edit_copy), 
                  NULL);
  gtk_widget_show (copyMenu);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
412
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
413
414
415
416
417
418
  pasteMenu = gtk_image_menu_item_new_from_stock( GTK_STOCK_PASTE, get_accel_group());
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), pasteMenu);
  g_signal_connect_swapped (G_OBJECT (pasteMenu), "activate",
                  G_CALLBACK (edit_paste), 
                  NULL);
  gtk_widget_show (pasteMenu);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
419
420
421
422
  
  menu_items = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  
423
424
425
426
427
428
429
  menu_items = gtk_menu_item_new_with_mnemonic( _("_Accounts") );
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  g_signal_connect_swapped (G_OBJECT (menu_items), "activate",
                  G_CALLBACK (edit_accounts), 
                  NULL);
  gtk_widget_show (menu_items);  

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
430
431
432
433
434
435
436
437
  menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_PREFERENCES, get_accel_group());
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  g_signal_connect_swapped (G_OBJECT (menu_items), "activate",
                  G_CALLBACK (edit_preferences), 
                  NULL);
  gtk_widget_show (menu_items);  
    
  
438
  root_menu = gtk_menu_item_new_with_mnemonic (_("_Edit"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
439
440
441
442
443
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

  return root_menu;
}
/* ----------------------------------------------------------------- */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
444
static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
445
446
447
448
449
450
view_dial_pad  (GtkCheckMenuItem *checkmenuitem,
                void* foo)
{
  main_window_dialpad(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkmenuitem)));
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
451
GtkWidget * 
452
453
454
455
456
create_view_menu()
{
  GtkWidget * menu;
  GtkWidget * root_menu;
  GtkWidget * menu_items;
Emmanuel Milou's avatar
Emmanuel Milou committed
457
458
459
  GtkWidget * submenu;
  GtkWidget * submenu_items;

460
461
  menu      = gtk_menu_new ();

462
  menu_items = gtk_check_menu_item_new_with_mnemonic (_("_Dialpad"));
Emmanuel Milou's avatar
Emmanuel Milou committed
463
464
  gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM ( menu_items ), TRUE);
  main_window_dialpad(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_items)));
465
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
466
467
  g_signal_connect(G_OBJECT (menu_items), "toggled",
                  G_CALLBACK (view_dial_pad), 
468
469
470
                  NULL);
  gtk_widget_show (menu_items);
  
471
  menu_items = gtk_check_menu_item_new_with_mnemonic (_("_Volume controls"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
472
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
473
474
475
476
477
  gtk_widget_set_sensitive( GTK_WIDGET(menu_items),   FALSE);
  g_signal_connect(G_OBJECT (menu_items), "toggled",
                  G_CALLBACK (view_dial_pad), 
                  NULL);
  gtk_widget_show (menu_items);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
478
  
Emmanuel Milou's avatar
Emmanuel Milou committed
479
  menu_items = gtk_menu_item_new_with_mnemonic(_("_Toolbar"));
480
  gtk_widget_set_sensitive( GTK_WIDGET(menu_items) , FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
481
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
Emmanuel Milou's avatar
Emmanuel Milou committed
482

483
  root_menu = gtk_menu_item_new_with_mnemonic (_("_View"));
484
485
486
487
488
489
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

  return root_menu;
}
/* ----------------------------------------------------------------- */
GtkWidget * 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
490
491
492
493
494
495
496
497
498
499
create_menus ( )
{

  GtkWidget * menu_bar;
  GtkWidget * root_menu;

  menu_bar  = gtk_menu_bar_new ();
  
  root_menu = create_call_menu();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);
500
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
501
502
503
  root_menu = create_edit_menu();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);
  
504
505
  root_menu = create_view_menu();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
506
507
508
509
510
511
512
513
514
515

  root_menu = create_help_menu();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);

  gtk_widget_show (menu_bar);
  
  
  return menu_bar;
}

516
517
518
519
520
/* ----------------------------------------------------------------- */

void
show_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
  // TODO update the selection to make sure the call under the mouse is the call selected
  
  gboolean pickup = FALSE, hangup = FALSE, hold = FALSE, copy = FALSE;
  
	call_t * selectedCall = call_get_selected();
	if (selectedCall)
	{
    copy = TRUE;
    switch(selectedCall->state) 
  	{
  	  case CALL_STATE_INCOMING:
        pickup = TRUE;
        hangup = TRUE;
        break;
      case CALL_STATE_HOLD:
        hangup = TRUE;
        hold   = TRUE;
        break;
      case CALL_STATE_RINGING:
        hangup = TRUE;
        break;
      case CALL_STATE_DIALING:
        pickup = TRUE;
        hangup = TRUE;
        break;
      case CALL_STATE_CURRENT:
        hangup = TRUE;
        hold   = TRUE;
        break;
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
        hangup = TRUE;
        break; 
  	  default:
  	    g_warning("Should not happen in show_popup_menu!");
  	    break;
  	}
  } 
  
560
  GtkWidget *menu;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
561
  //GtkWidget *image;
562
563
564
565
  int button, event_time;
  GtkWidget * menu_items;

  menu = gtk_menu_new ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
566
567
  //g_signal_connect (menu, "deactivate", 
  //       G_CALLBACK (gtk_widget_destroy), NULL);
568

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
569
570
571
572
573
574
575
576
577
  if(copy)
  {
    menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_COPY, get_accel_group());
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
    g_signal_connect (G_OBJECT (menu_items), "activate",
                    G_CALLBACK (edit_copy), 
                    NULL);
    gtk_widget_show (menu_items);
  }
578
579
580
  
  menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_PASTE, get_accel_group());
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
581
  g_signal_connect (G_OBJECT (menu_items), "activate",
582
583
                  G_CALLBACK (edit_paste), 
                  NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
584
585
586
587
588
589
590
591
592
593
594
595
  gtk_widget_show (menu_items);
  
  if(pickup || hangup || hold)
  {
    menu_items = gtk_separator_menu_item_new ();
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
    gtk_widget_show (menu_items);
  }
  
  if(pickup)
  {
    
596
    menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Pick up"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
597
598
599
600
601
602
603
604
605
606
607
	  //image = gtk_image_new_from_file( ICONS_DIR "/accept.svg");
    //gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
    g_signal_connect (G_OBJECT (menu_items), "activate",
                    G_CALLBACK (call_pick_up), 
                    NULL);
    gtk_widget_show (menu_items);
  }
  
  if(hangup)
  {
608
    menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Hang up"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
609
610
611
612
613
614
615
616
617
618
619
	  //image = gtk_image_new_from_file( ICONS_DIR "/hang_up.svg");
    //gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
    g_signal_connect (G_OBJECT (menu_items), "activate",
                    G_CALLBACK (call_hang_up), 
                    NULL);
    gtk_widget_show (menu_items);
  }
  
  if(hold)
  {
620
    menu_items = gtk_check_menu_item_new_with_mnemonic (_("On _Hold"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
621
622
623
624
625
626
627
628
629
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_items), 
      (selectedCall->state == CALL_STATE_HOLD ? TRUE : FALSE));
    g_signal_connect(G_OBJECT (menu_items), "activate",
                    G_CALLBACK (call_hold), 
                    NULL);
    gtk_widget_show (menu_items);
  }  
  
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
  if (event)
  {
    button = event->button;
    event_time = event->time;
  }
  else
  {
    button = 0;
    event_time = gtk_get_current_event_time ();
  }

  gtk_menu_attach_to_widget (GTK_MENU (menu), my_widget, NULL);
  gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 
                  button, event_time);
}