menus.c 27.4 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1 2
/*
 *  Copyright (C) 2007 Savoir-Faire Linux inc.
Emmanuel Milou's avatar
Emmanuel Milou committed
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
4
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
5
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
6 7
 *  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
8
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
9
 *  (at your option) any later version.
10
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
11 12 13 14
 *  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.
15
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
16 17 18 19
 *  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.
 */
20

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
21
#include <menus.h>
22
#include <actions.h>
23 24 25
#include <calllist.h>
#include <calltree.h>
#include <config.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
26
#include <configwindow.h>
27 28
#include <dbus.h>
#include <mainwindow.h>
areversat's avatar
areversat committed
29
#include <calltab.h>
30
#include <assistant.h>
31
#include <gtk/gtk.h>
32
#include <glib/gprintf.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
33 34
#include <string.h> // for strlen

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
35 36
GtkWidget * pickUpMenu;
GtkWidget * hangUpMenu;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
37
GtkWidget * newCallMenu;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
38
GtkWidget * holdMenu;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
39 40
GtkWidget * copyMenu;
GtkWidget * pasteMenu;
41
GtkWidget * recordMenu;
42

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
43
guint holdConnId;     //The hold_menu signal connection ID
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
44

45 46
GtkWidget * dialpadMenu;
GtkWidget * volumeMenu;
47
GtkWidget * searchbarMenu;
48 49


Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
50
void update_menus()
51
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
52 53
  //Block signals for holdMenu
  gtk_signal_handler_block(GTK_OBJECT(holdMenu), holdConnId);
54

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
55 56
  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
57
  gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu),FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
58
  gtk_widget_set_sensitive( GTK_WIDGET(holdMenu),   FALSE);
59
  gtk_widget_set_sensitive( GTK_WIDGET(recordMenu), FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
60
  gtk_widget_set_sensitive( GTK_WIDGET(copyMenu),   FALSE);
61

62
  call_t * selectedCall = call_get_selected(active_calltree);
63 64
  if (selectedCall)
  {
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
65
    gtk_widget_set_sensitive( GTK_WIDGET(copyMenu),   TRUE);
66
    switch(selectedCall->state)
67 68 69 70 71
    {
      case CALL_STATE_INCOMING:
	gtk_widget_set_sensitive( GTK_WIDGET(pickUpMenu), TRUE);
	gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
72
      case CALL_STATE_HOLD:
73 74 75
	gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
	gtk_widget_set_sensitive( GTK_WIDGET(holdMenu),   TRUE);
	gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu),TRUE);
Emmanuel Milou's avatar
Emmanuel Milou committed
76
        gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( holdMenu ), gtk_image_new_from_file( ICONS_DIR "/icon_unhold.svg"));
77
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
78
      case CALL_STATE_RINGING:
79 80 81
	gtk_widget_set_sensitive( GTK_WIDGET(pickUpMenu), TRUE);
	gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
82
      case CALL_STATE_DIALING:
83 84 85 86
	gtk_widget_set_sensitive( GTK_WIDGET(pickUpMenu), TRUE);
	gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
	gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu),TRUE);
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
87
      case CALL_STATE_CURRENT:
88
      case CALL_STATE_RECORD:
89 90 91
	gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
	gtk_widget_set_sensitive( GTK_WIDGET(holdMenu),   TRUE);
	gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu),TRUE);
92
        gtk_widget_set_sensitive( GTK_WIDGET(recordMenu), TRUE);
Emmanuel Milou's avatar
Emmanuel Milou committed
93
        gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( holdMenu ), gtk_image_new_from_file( ICONS_DIR "/icon_hold.svg"));
94
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
95 96
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
97
	gtk_widget_set_sensitive( GTK_WIDGET(hangUpMenu), TRUE);
98
	break;
99 100 101 102
      default:
	g_warning("Should not happen in update_menus()!");
	break;
    }
103
  }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
104 105 106
  else
  {
    gtk_widget_set_sensitive( GTK_WIDGET(newCallMenu), TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
107
  }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
108
  gtk_signal_handler_unblock(holdMenu, holdConnId);
areversat's avatar
areversat committed
109

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
110
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
111
/* ----------------------------------------------------------------- */
112
  static void
113
help_about ( void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
114 115
{
  gchar *authors[] = {
116
    "Yan Morin <yan.morin@savoirfairelinux.com>",
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
117 118 119
    "Jérôme Oufella <jerome.oufella@savoirfairelinux.com>",
    "Julien Plissonneau Duquene <julien.plissonneau.duquene@savoirfairelinux.com>",
    "Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>",
120
    "Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>",
121 122
    "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>",
    "Yun Liu <yun.liu@savoirfairelinux.com>"
Emmanuel Milou's avatar
Emmanuel Milou committed
123
    "Jean-Philippe Barrette-LaPierre",
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
124 125 126
    "Laurielle Lea",
    NULL};
  gchar *artists[] = {
127
    "Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>",
Emmanuel Milou's avatar
Emmanuel Milou committed
128
    "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>",
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
129
    NULL};
130

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
131
  gtk_show_about_dialog( GTK_WINDOW(get_main_window()),
Emmanuel Milou's avatar
Emmanuel Milou committed
132 133 134
      "artists", artists,
      "authors", authors,
      "comments", _("SFLphone is a VoIP client compatible with SIP and IAX2 protocols."),
135
      "copyright", "Copyright © 2004-2009 Savoir-faire Linux Inc.",
136 137 138 139 140
      "name", PACKAGE,
      "title", _("About SFLphone"),
      "version", VERSION,
      "website", "http://www.sflphone.org",
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
141 142 143
}


144
  GtkWidget *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
145 146 147 148 149
create_help_menu()
{
  GtkWidget * menu;
  GtkWidget * root_menu;
  GtkWidget * menu_items;
150

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
151
  menu      = gtk_menu_new ();
152

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
153 154 155
  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",
156
      G_CALLBACK (help_about),
157
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
158
  gtk_widget_show (menu_items);
159

160
  root_menu = gtk_menu_item_new_with_mnemonic (_("_Help"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
161 162 163 164 165
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

  return root_menu;
}
/* ----------------------------------------------------------------- */
166
  static void
167
call_new_call ( void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
168
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
169
  sflphone_new_call();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
170 171
}

172
  static void
173
call_quit ( void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
174
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
175
  sflphone_quit();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
176 177
}

178
  static void
179
call_minimize ( void * foo UNUSED)
Emmanuel Milou's avatar
test  
Emmanuel Milou committed
180
{
181
#if GTK_CHECK_VERSION(2,10,0)
Emmanuel Milou's avatar
test  
Emmanuel Milou committed
182
  gtk_widget_hide(GTK_WIDGET( get_main_window() ));
183
  set_minimized( TRUE );
184
#endif
Emmanuel Milou's avatar
test  
Emmanuel Milou committed
185 186
}

187
  static void
188
switch_account(  GtkWidget* item , gpointer data UNUSED)
189 190 191
{
  account_t* acc = g_object_get_data( G_OBJECT(item) , "account" );
  g_print("%s\n" , acc->accountID);
192
  account_list_set_current_id( acc->accountID );
193 194
}

195
  static void
196
call_hold  (void* foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
197
{
areversat's avatar
areversat committed
198
  call_t * selectedCall = call_get_selected(current_calls);
199

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
200
  if(selectedCall)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
201
  {
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
202 203
    if(selectedCall->state == CALL_STATE_HOLD)
    {
204
      gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( holdMenu ), gtk_image_new_from_file( ICONS_DIR "/icon_unhold.svg"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
205 206 207 208
      sflphone_off_hold();
    }
    else
    {
209
      gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( holdMenu ), gtk_image_new_from_file( ICONS_DIR "/icon_hold.svg"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
210
      sflphone_on_hold();
211 212
    }
  }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
213 214
}

215
  static void
216
call_pick_up ( void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
217 218 219 220
{
  sflphone_pick_up();
}

221
  static void
222
call_hang_up ( void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
223 224 225 226
{
  sflphone_hang_up();
}

227
static void
228 229 230 231 232
call_record ( void * foo UNUSED)
{
  sflphone_rec_call();
}

233
  static void
234
call_wizard ( void * foo UNUSED)
235
{
236
#if GTK_CHECK_VERSION(2,10,0)
237
  build_wizard();
238
#endif
239 240
}

241
static void
242
remove_from_history( void * foo UNUSED)
243 244 245 246 247 248 249 250 251
{
  call_t* c = call_get_selected( history );
  if(c){
    g_print("Remove the call from the history\n");
    call_list_remove_from_history( c );
  }
}

static void
252
call_back( void * foo UNUSED)
253
{
Julien Bonjean's avatar
Julien Bonjean committed
254
  call_t* selectedCall = call_get_selected( active_calltree );
255 256
  call_t* newCall =  g_new0 (call_t, 1);
  if( selectedCall )
257
  {
258 259 260 261
    newCall->to = g_strdup(call_get_number(selectedCall));
    newCall->from = g_strconcat("\"\" <", call_get_number(selectedCall), ">",NULL);
    newCall->state = CALL_STATE_DIALING;
    newCall->callID = g_new0(gchar, 30);
262
    g_sprintf(newCall->callID, "%d", rand());
263 264 265 266 267
    newCall->_start = 0;
    newCall->_stop = 0;
    call_list_add(current_calls, newCall);
    update_call_tree_add(current_calls, newCall);
    sflphone_place_call(newCall);
268
    display_calltree (current_calls);
269
  }
270
}
271 272

  GtkWidget *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
273 274 275 276 277
create_call_menu()
{
  GtkWidget * menu;
  GtkWidget * root_menu;
  GtkWidget * menu_items;
278
  GtkWidget * image;
279

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
280
  menu      = gtk_menu_new ();
281

282
  image = gtk_image_new_from_file( ICONS_DIR "/icon_call.svg");
283
  newCallMenu = gtk_image_menu_item_new_with_mnemonic(_("_New call"));
284
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( newCallMenu ), image );
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
285 286
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), newCallMenu);
  g_signal_connect_swapped (G_OBJECT (newCallMenu), "activate",
287
      G_CALLBACK (call_new_call),
288
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
289
  gtk_widget_show (newCallMenu);
290

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
291 292
  menu_items = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
293

294
  image = gtk_image_new_from_file( ICONS_DIR "/icon_accept.svg");
295
  pickUpMenu = gtk_image_menu_item_new_with_mnemonic(_("_Pick up"));
296
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( pickUpMenu ), image );
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
297 298 299
  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",
300
      G_CALLBACK (call_pick_up),
301
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
302
  gtk_widget_show (pickUpMenu);
303

304
  image = gtk_image_new_from_file( ICONS_DIR "/icon_hangup.svg");
305
  hangUpMenu = gtk_image_menu_item_new_with_mnemonic(_("_Hang up"));
306
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( hangUpMenu ), image );
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
307 308 309
  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",
310
      G_CALLBACK (call_hang_up),
311
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
312
  gtk_widget_show (hangUpMenu);
313

314 315 316
  image = gtk_image_new_from_file( ICONS_DIR "/icon_hold.svg");
  holdMenu = gtk_image_menu_item_new_with_mnemonic (_("On _Hold"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( holdMenu ), image );
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
317 318 319 320
  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
321
  holdConnId = g_signal_connect(G_OBJECT (holdMenu), "activate",
322
      G_CALLBACK (call_hold),
323
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
324
  gtk_widget_show (menu_items);
325

326
  recordMenu = gtk_image_menu_item_new_from_stock (GTK_STOCK_MEDIA_RECORD, get_accel_group());
327 328 329
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), recordMenu);
  gtk_widget_set_sensitive( GTK_WIDGET(recordMenu), FALSE);
  g_signal_connect_swapped (G_OBJECT (recordMenu), "activate",
330
      G_CALLBACK (call_record),
331 332 333
      NULL);
  gtk_widget_show (recordMenu);

Emmanuel Milou's avatar
test  
Emmanuel Milou committed
334
  // Separator
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
335
  menu_items = gtk_separator_menu_item_new ();
336 337
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);

338
#if GTK_CHECK_VERSION(2,10,0)
339 340 341 342 343 344
  menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Account Assistant"));
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  g_signal_connect_swapped( G_OBJECT( menu_items ) , "activate" , G_CALLBACK( call_wizard  ) , NULL );
  gtk_widget_show (menu_items);
  // Separator
  menu_items = gtk_separator_menu_item_new ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
345
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
346
#endif
347

Emmanuel Milou's avatar
test  
Emmanuel Milou committed
348 349 350 351
  // Close menu to minimize the main window to the system tray
  menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_CLOSE, get_accel_group());
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
  g_signal_connect_swapped (G_OBJECT (menu_items), "activate",
352
      G_CALLBACK (call_minimize),
353
      NULL);
Emmanuel Milou's avatar
test  
Emmanuel Milou committed
354 355 356 357 358 359 360
  gtk_widget_show (menu_items);

  // Separator
  menu_items = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);

  // Quit Menu - quit SFLphone
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
361 362 363
  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",
364
      G_CALLBACK (call_quit),
365
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
366
  gtk_widget_show (menu_items);
367 368


369
  root_menu = gtk_menu_item_new_with_mnemonic (_("_Call"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
370 371 372 373 374
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

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

376
  static void
377
edit_preferences ( void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
378 379 380 381
{
  show_config_window();
}

382
  static void
383
edit_accounts ( void * foo UNUSED)
384 385 386 387
{
  show_accounts_window();
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
388
// The menu Edit/Copy should copy the current selected call's number
389
  static void
390
edit_copy ( void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
391 392
{
  GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
areversat's avatar
areversat committed
393
  call_t * selectedCall = call_get_selected(current_calls);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
394
  gchar * no = NULL;
395

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
396 397 398 399
  if(selectedCall)
  {
    switch(selectedCall->state)
    {
400
      case CALL_STATE_TRANSFERT:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
401 402
      case CALL_STATE_DIALING:
      case CALL_STATE_RINGING:
403 404
	no = selectedCall->to;
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
405 406 407 408 409 410
      case CALL_STATE_CURRENT:
      case CALL_STATE_HOLD:
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
      case CALL_STATE_INCOMING:
      default:
411 412
	no = call_get_number(selectedCall);
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
413
    }
414

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
415 416
    gtk_clipboard_set_text (clip, no, strlen(no) );
  }
417

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
418 419 420
}

// The menu Edit/Paste should paste the clipboard into the current selected call
421
  static void
422
edit_paste ( void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
423 424
{
  GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
areversat's avatar
areversat committed
425
  call_t * selectedCall = call_get_selected(current_calls);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
426
  gchar * no = gtk_clipboard_wait_for_text (clip);
427

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
428 429 430 431
  if(no && selectedCall)
  {
    switch(selectedCall->state)
    {
432
      case CALL_STATE_TRANSFERT:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
433
      case CALL_STATE_DIALING:
434
	// Add the text to the number
435
	{
436 437 438 439 440 441 442 443 444 445
	  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);
	  }
446
	  update_call_tree(current_calls, selectedCall);
447 448
	}
	break;
449
      case CALL_STATE_RINGING:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
450 451 452 453
      case CALL_STATE_INCOMING:
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
      case CALL_STATE_HOLD:
454 455 456 457 458 459 460 461 462 463 464
	{ // 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);

465
	  update_call_tree(current_calls, selectedCall);
466 467
	}
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
468 469
      case CALL_STATE_CURRENT:
      default:
470
	{
Emmanuel Milou's avatar
Emmanuel Milou committed
471
	  unsigned int i;
472 473 474 475 476 477 478 479 480 481 482
	  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);
483
	    update_call_tree(current_calls, selectedCall);
484 485 486 487

	  }
	}
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
488
    }
489

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
490 491 492 493
  }
  else // There is no current call, create one
  {
    selectedCall = sflphone_new_call();
494

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
495 496 497 498
    gchar * before = selectedCall->to;
    selectedCall->to = g_strconcat(selectedCall->to, no, NULL);
    g_free(before);
    g_print("TO: %s\n", selectedCall->to);
499

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
500 501
    g_free(selectedCall->from);
    selectedCall->from = g_strconcat("\"\" <", selectedCall->to, ">", NULL);
502
    update_call_tree(current_calls,selectedCall);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
503
  }
504

505 506 507
}

  static void
508
clear_history (void)
509
{
510
  if( call_list_get_size( history ) != 0 ){
511
      call_list_clean_history();
512
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
513 514
}

515
  GtkWidget *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
516 517 518
create_edit_menu()
{
  GtkWidget * menu;
519
  GtkWidget * image;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
520 521
  GtkWidget * root_menu;
  GtkWidget * menu_items;
522

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
523 524
  menu      = gtk_menu_new ();

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
525 526 527
  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",
528
      G_CALLBACK (edit_copy),
529
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
530
  gtk_widget_show (copyMenu);
531

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
532 533 534
  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",
535
      G_CALLBACK (edit_paste),
536
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
537
  gtk_widget_show (pasteMenu);
538

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
539 540
  menu_items = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
541

542 543 544 545 546
  menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Clear history"));
  image = gtk_image_new_from_stock( GTK_STOCK_CLEAR , GTK_ICON_SIZE_MENU );
  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_swapped (G_OBJECT (menu_items), "activate",
547
      G_CALLBACK (clear_history),
548
      NULL);
549
  gtk_widget_show (menu_items);
550 551 552 553

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

554 555 556
  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",
557
      G_CALLBACK (edit_accounts),
558
      NULL);
559
  gtk_widget_show (menu_items);
560

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
561 562 563
  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",
564
      G_CALLBACK (edit_preferences),
565
      NULL);
566
  gtk_widget_show (menu_items);
567 568


569
  root_menu = gtk_menu_item_new_with_mnemonic (_("_Edit"));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
570 571 572 573 574
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

  return root_menu;
}
/* ----------------------------------------------------------------- */
575
  static void
576 577
view_dialpad  (GtkImageMenuItem *imagemenuitem UNUSED,
    void* foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
578
{
579 580 581 582 583
  gboolean state;
  main_window_dialpad( &state );
  if( state )
    gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( dialpadMenu ),
				  gtk_image_new_from_file( ICONS_DIR "/icon_dialpad_off.svg"));
584 585
  else
    gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( dialpadMenu ),
586 587
				  gtk_image_new_from_file( ICONS_DIR "/icon_dialpad.svg"));
  dbus_set_dialpad( state );
588

589

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
590 591
}

592
  static void
593 594
view_volume_controls  (GtkImageMenuItem *imagemenuitem UNUSED,
    void* foo UNUSED)
595
{
596 597 598 599 600
  gboolean state;
  main_window_volume_controls( &state );
  if( state )
    gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( volumeMenu ),
				  gtk_image_new_from_file( ICONS_DIR "/icon_volume_off.svg"));
601 602
  else
    gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( volumeMenu ),
603 604
				  gtk_image_new_from_file( ICONS_DIR "/icon_volume.svg"));
  dbus_set_volume_controls( state );
605 606
}

607
  static void
608 609
view_searchbar  (GtkImageMenuItem *imagemenuitem UNUSED,
    void* foo UNUSED)
610 611 612 613 614 615
{
  gboolean state;
  main_window_searchbar( &state );
  dbus_set_searchbar( state );
}

616
  GtkWidget *
617 618 619 620
create_view_menu()
{
  GtkWidget * menu;
  GtkWidget * root_menu;
621
  GtkWidget * image;
Emmanuel Milou's avatar
Emmanuel Milou committed
622

623 624
  menu      = gtk_menu_new ();

625 626 627 628 629 630 631 632
  if( SHOW_DIALPAD )
    image = gtk_image_new_from_file( ICONS_DIR "/icon_dialpad_off.svg");
  else
    image = gtk_image_new_from_file( ICONS_DIR "/icon_dialpad.svg");
  dialpadMenu = gtk_image_menu_item_new_with_mnemonic (_("_Dialpad"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( dialpadMenu ), image );
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), dialpadMenu);
  g_signal_connect(G_OBJECT ( dialpadMenu ), "activate",
633
      G_CALLBACK (view_dialpad),
634
      NULL);
635
  gtk_widget_show (dialpadMenu);
636

637 638 639 640 641 642 643 644
  if( SHOW_VOLUME )
    image = gtk_image_new_from_file( ICONS_DIR "/icon_volume.svg");
  else
    image = gtk_image_new_from_file( ICONS_DIR "/icon_volume.svg");
  volumeMenu = gtk_image_menu_item_new_with_mnemonic (_("_Volume controls"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( volumeMenu ), image );
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), volumeMenu);
  g_signal_connect(G_OBJECT (volumeMenu), "activate",
645
      G_CALLBACK (view_volume_controls),
646
      NULL);
647
  gtk_widget_show (volumeMenu);
Emmanuel Milou's avatar
Emmanuel Milou committed
648

649 650 651 652 653
  image = gtk_image_new_from_stock( GTK_STOCK_FIND , GTK_ICON_SIZE_MENU );
  searchbarMenu = gtk_image_menu_item_new_with_mnemonic (_("_Search history"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( searchbarMenu ), image );
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), searchbarMenu);
  g_signal_connect(G_OBJECT (searchbarMenu), "activate",
654
      G_CALLBACK (view_searchbar),
655 656 657
      NULL);
  gtk_widget_show (searchbarMenu);

658
  root_menu = gtk_menu_item_new_with_mnemonic (_("_View"));
659 660 661 662 663
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

  return root_menu;
}
/* ----------------------------------------------------------------- */
664
  GtkWidget *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
665 666 667 668 669 670 671
create_menus ( )
{

  GtkWidget * menu_bar;
  GtkWidget * root_menu;

  menu_bar  = gtk_menu_bar_new ();
672

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
673 674
  root_menu = create_call_menu();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);
675

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
676 677
  root_menu = create_edit_menu();
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);
678

679 680
  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
681 682 683 684 685

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

  gtk_widget_show (menu_bar);
686 687


Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
688 689 690
  return menu_bar;
}

691 692
/* ----------------------------------------------------------------- */

693
  void
694 695
show_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
696
  // TODO update the selection to make sure the call under the mouse is the call selected
697

698
  gboolean pickup = FALSE, hangup = FALSE, hold = FALSE, copy = FALSE, record = FALSE;
699 700
  gboolean accounts = FALSE;

701
  call_t * selectedCall = call_get_selected(current_calls);
702 703
  if (selectedCall)
  {
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
704
    copy = TRUE;
705
    switch(selectedCall->state)
706 707 708 709 710
    {
      case CALL_STATE_INCOMING:
	pickup = TRUE;
	hangup = TRUE;
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
711
      case CALL_STATE_HOLD:
712 713 714
	hangup = TRUE;
	hold   = TRUE;
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
715
      case CALL_STATE_RINGING:
716 717
	hangup = TRUE;
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
718
      case CALL_STATE_DIALING:
719 720 721 722
	pickup = TRUE;
	hangup = TRUE;
	accounts = TRUE;
	break;
723
      case CALL_STATE_RECORD:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
724
      case CALL_STATE_CURRENT:
725 726
	hangup = TRUE;
	hold   = TRUE;
727
        record = TRUE;
728
	break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
729 730
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
731
	hangup = TRUE;
732
	break;
733 734 735 736
      default:
	g_warning("Should not happen in show_popup_menu!");
	break;
    }
737
  }
738

739
  GtkWidget *menu;
740
  GtkWidget *image;
741 742 743 744
  int button, event_time;
  GtkWidget * menu_items;

  menu = gtk_menu_new ();
745
  //g_signal_connect (menu, "deactivate",
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
746
  //       G_CALLBACK (gtk_widget_destroy), NULL);
747

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
748 749 750 751 752
  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",
753
	G_CALLBACK (edit_copy),
754
	NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
755 756
    gtk_widget_show (menu_items);
  }
757

758 759
  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
760
  g_signal_connect (G_OBJECT (menu_items), "activate",
761
      G_CALLBACK (edit_paste),
762
      NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
763
  gtk_widget_show (menu_items);
764

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
765 766 767 768 769 770
  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);
  }
771

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
772 773
  if(pickup)
  {
Emmanuel Milou's avatar