mainwindow.c 6.78 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 *  Copyright (C) 2007 Savoir-Faire Linux inc.
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@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 2 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>
#include <actions.h>
#include <calllist.h> 
23
#include <calltree.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
24
25
26
#include <dialpad.h>
#include <menus.h>
#include <screen.h>
27
#include <sliders.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
28
29
30
31

#include <gtk/gtk.h>

/** Local variables */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
32
GtkAccelGroup * accelGroup = NULL;
33
34
35
GtkWidget * window   = NULL;
GtkWidget * subvbox  = NULL;
GtkWidget * dialpad  = NULL;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
36
gboolean showDialpad = FALSE; // true if the dialpad have been showned
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
37

38

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
/**
 * Terminate the main loop.
 */
static gboolean
on_delete (GtkWidget * widget, gpointer data)
{
  /* Must return FALSE to have the window destroyed */
  return !sflphone_quit();
}

/** Ask the user if he wants to hangup current calls */
gboolean 
main_window_ask_quit(){
  guint count = call_list_get_size();
  GtkWidget * dialog;
  guint response;
  gchar * question;
  
  if(count == 1)
  {
    question = "<b>There is one call in progress.</b>\nDo you still want to quit?";
  }
  else
  {
    question = "<b>There are calls in progress.</b>\nDo you still want to quit?";
  }
  
  dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(window) ,
                                  GTK_DIALOG_MODAL,
                                  GTK_MESSAGE_QUESTION,
                                  GTK_BUTTONS_YES_NO,
                                  question);
  
  response = gtk_dialog_run (GTK_DIALOG (dialog));
  
  gtk_widget_destroy (dialog);
  if(response == GTK_RESPONSE_YES)
  { 
    return TRUE;
  }
  else if(response == GTK_RESPONSE_NO)
  {
    return FALSE;
  }
  return TRUE;
}

static gboolean
on_key_released (GtkWidget   *widget,
                GdkEventKey *event,
                gpointer     user_data)  
{
#ifdef DEBUG
  g_print("KEY %s, %d\n", event->string, event->keyval);
#endif 
  // If a modifier key is pressed, it's a shortcut, pass along
  if(event->state & GDK_CONTROL_MASK || 
96
     event->state & GDK_MOD1_MASK    ||
97
98
99
     event->keyval == 60             || // <
     event->keyval == 62             || // >
     event->keyval == 34             || // "
100
     event->keyval == 65361          || // left arrow
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
101
102
     event->keyval == 65363          || // right arrow
     event->keyval == 32                // space
103
     )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
104
105
106
107
108
109
110
111
    return FALSE;
  sflphone_keypad(event->keyval, event->string);
  return TRUE;
}                

void
create_main_window ()
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
112
  GtkWidget *widget;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
113
114
115
116
117
  GtkWidget *vbox;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 0);
  gtk_window_set_title (GTK_WINDOW (window), PACKAGE);
118
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 300);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
119
  gtk_window_set_default_icon_from_file (ICONS_DIR "/sflphone.png", 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
                                          NULL);

  /* Connect the destroy event of the window with our on_destroy function
    * When the window is about to be destroyed we get a notificaiton and
    * stop the main GTK loop
    */
  g_signal_connect (G_OBJECT (window), "delete-event",
                    G_CALLBACK (on_delete), NULL);
  g_signal_connect (G_OBJECT (window), "key-press-event",
                    G_CALLBACK (on_key_released), NULL);

  /* Create an accel group for window's shortcuts */
  accelGroup = gtk_accel_group_new ();
  gtk_window_add_accel_group(GTK_WINDOW(window), accelGroup);

  vbox = gtk_vbox_new ( FALSE /*homogeneous*/, 0 /*spacing*/);
136
137
  subvbox = gtk_vbox_new ( FALSE /*homogeneous*/, 5 /*spacing*/);
  gtk_container_set_border_width (GTK_CONTAINER(subvbox), 5);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
138
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
139
140
  widget = create_menus();
  gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
141
  gtk_box_pack_start (GTK_BOX (vbox), subvbox, TRUE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
142
143
 
  widget = create_screen();
144
145
  // TODO Add the screen when we are decided
  //gtk_box_pack_start (GTK_BOX (subvbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
146
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
147
148
  gtk_box_pack_start (GTK_BOX (subvbox), create_call_tree(), TRUE /*expand*/, TRUE /*fill*/,  0 /*padding*/);
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
149
150
151
152
  widget = create_slider("speaker");
  gtk_box_pack_start (GTK_BOX (subvbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
  widget = create_slider("mic");
  gtk_box_pack_start (GTK_BOX (subvbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
153
  
154
  /* Status bar */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
155
  widget = gtk_statusbar_new();
156
  gtk_box_pack_start (GTK_BOX (vbox), gtk_statusbar_new(), FALSE /*expand*/, TRUE /*fill*/,  0 /*padding*/);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
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
  gtk_container_add (GTK_CONTAINER (window), vbox);

  /* make sure that everything, window and label, are visible */
  gtk_widget_show_all (window);
  
  screen_clear();
}

GtkAccelGroup * 
get_accel_group()
{
  return accelGroup;
}

GtkWidget * 
get_main_window()
{
  return window;
}

void
main_window_message(GtkMessageType type, gchar * markup){
  GtkWidget * dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(get_main_window()),
                                      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                      type,
                                      GTK_BUTTONS_CLOSE,
                                      markup);
  gtk_dialog_run (GTK_DIALOG(dialog));
  
  gtk_widget_destroy (GTK_WIDGET(dialog));
}

void
main_window_error_message(gchar * markup){
  main_window_message(GTK_MESSAGE_ERROR, markup);
}

void
main_window_warning_message(gchar * markup){
  main_window_message(GTK_MESSAGE_WARNING, markup);
}

void
main_window_info_message(gchar * markup){
  main_window_message(GTK_MESSAGE_INFO, markup);
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
204
205
206
207
208
209
210
211
212
213
214
void
main_window_dialpad(gboolean show){
  if(show && !showDialpad)
  {
    dialpad = create_dialpad();
    gtk_box_pack_end (GTK_BOX (subvbox), dialpad, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
    gtk_box_reorder_child(GTK_BOX (subvbox), dialpad, 1);
    gtk_widget_show_all (dialpad);
  }
  else if (!show && showDialpad)
  {
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
215
    gtk_container_remove(GTK_CONTAINER (subvbox), dialpad);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
216
217
218
219
220
  }
  showDialpad = show;
    
}