mainwindow.c 8.92 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>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
5
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
10
11
12
13
14
15
16
17
18
19
20
21
22
 *  (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>
areversat's avatar
areversat committed
23
#include <calltab.h>
24
#include <calltree.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
25
#include <configwindow.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
26
#include <dialpad.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
27
#include <mainwindow.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
28
#include <menus.h>
29
#include <sliders.h>
areversat's avatar
areversat committed
30
#include <historyfilter.h>
31
#include <assistant.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
32
33
34
35

#include <gtk/gtk.h>

/** Local variables */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
36
GtkAccelGroup * accelGroup = NULL;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
37
38
GtkWidget * window    = NULL;
GtkWidget * subvbox   = NULL;
39
GtkWidget * vbox   = NULL;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
40
GtkWidget * dialpad   = NULL;
41
42
GtkWidget * speaker_control = NULL;
GtkWidget * mic_control = NULL;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
43
GtkWidget * statusBar = NULL;
Emmanuel Milou's avatar
Emmanuel Milou committed
44
GtkWidget * filterEntry = NULL;
45

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
46
/**
Emmanuel Milou's avatar
Emmanuel Milou committed
47
 * Minimize the main window.
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
48
49
 */
static gboolean
50
on_delete (GtkWidget * widget UNUSED, gpointer data UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
51
{
52
#if GTK_CHECK_VERSION(2,10,0)
53
54
  gtk_widget_hide(GTK_WIDGET( get_main_window() ));
  set_minimized( TRUE );
55
#endif
56
  return TRUE;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
57
58
59
60
61
}

/** Ask the user if he wants to hangup current calls */
gboolean 
main_window_ask_quit(){
areversat's avatar
areversat committed
62
  guint count = call_list_get_size(current_calls);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
63
  GtkWidget * dialog;
Emmanuel Milou's avatar
Emmanuel Milou committed
64
  gint response;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
65
66
67
68
  gchar * question;
  
  if(count == 1)
  {
Emmanuel Milou's avatar
Emmanuel Milou committed
69
    question = _("<b>There is one call in progress.</b>\nDo you still want to quit?");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
70
71
72
  }
  else
  {
Emmanuel Milou's avatar
Emmanuel Milou committed
73
    question = _("<b>There are calls in progress.</b>\nDo you still want to quit?");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
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
  }
  
  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;
}

void
create_main_window ()
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
99
  GtkWidget *widget;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
100
101
102
103

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 0);
  gtk_window_set_title (GTK_WINDOW (window), PACKAGE);
104
  gtk_window_set_default_size (GTK_WINDOW (window), 260, 320);
105
  gtk_window_set_default_icon_from_file (ICONS_DIR "/sflphone.png", 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
106
                                          NULL);
107
  gtk_window_set_position( GTK_WINDOW( window ) , GTK_WIN_POS_MOUSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
108
109
110
111
112
113
114
115
116
117
118
119
120

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

  /* 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*/);
121
122
  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
123
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
124
125
  widget = create_menus();
  gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
126
127
128
  
  widget = create_toolbar();
  gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
129
130


areversat's avatar
areversat committed
131
132
  gtk_box_pack_start (GTK_BOX (vbox), current_calls->tree, TRUE /*expand*/, TRUE /*fill*/,  0 /*padding*/);
  gtk_box_pack_start (GTK_BOX (vbox), history->tree, TRUE /*expand*/, TRUE /*fill*/,  0 /*padding*/);
133
134
  
  gtk_box_pack_start (GTK_BOX (vbox), subvbox, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
135
136
137
138
139
140
  
  if( SHOW_SEARCHBAR ){
    filterEntry = create_filter_entry();
    gtk_box_pack_start (GTK_BOX (subvbox), filterEntry, FALSE /*expand*/, TRUE /*fill*/,  0 /*padding*/);
    gtk_widget_show_all ( filterEntry );
  }
141

142
 if( SHOW_VOLUME ){ 
143
    speaker_control = create_slider("speaker");
144
    gtk_box_pack_end (GTK_BOX (subvbox), speaker_control, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
145
146
    gtk_widget_show_all (speaker_control);
    mic_control = create_slider("mic");
147
    gtk_box_pack_end (GTK_BOX (subvbox), mic_control, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
148
149
    gtk_widget_show_all (mic_control);
  }
150

151
152
153
154
155
156
  if( SHOW_DIALPAD ){ 
    dialpad = create_dialpad();
    gtk_box_pack_end (GTK_BOX (subvbox), dialpad, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
    gtk_widget_show_all (dialpad);
  }

157
  /* Status bar */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
158
159
  statusBar = gtk_statusbar_new();
  gtk_box_pack_start (GTK_BOX (vbox), statusBar, FALSE /*expand*/, TRUE /*fill*/,  0 /*padding*/);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
160
161
162
163
  gtk_container_add (GTK_CONTAINER (window), vbox);

  /* make sure that everything, window and label, are visible */
  gtk_widget_show_all (window);
areversat's avatar
areversat committed
164
165
166
167

  /* dont't show the history */
  gtk_widget_hide(history->tree);
  //gtk_widget_show(current_calls->tree);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
168
  
areversat's avatar
areversat committed
169
  gtk_tree_view_set_model(GTK_TREE_VIEW(history->view), GTK_TREE_MODEL(histfilter));
170
  // Configuration wizard 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
171
172
  if (account_list_get_size() == 0)
  {
173
#if GTK_CHECK_VERSION(2,10,0)
174
    build_wizard();
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#else
    GtkWidget * dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(window),
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                  GTK_MESSAGE_INFO,
                                  GTK_BUTTONS_YES_NO,
                                  "<b><big>Welcome to SFLphone!</big></b>\n\nThere are no VoIP accounts configured, would you like to edit the preferences now?");

    int response = gtk_dialog_run (GTK_DIALOG(dialog));

    gtk_widget_destroy (GTK_WIDGET(dialog));

    if (response == GTK_RESPONSE_YES)
    {
      show_config_window();
    }
#endif
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
191
  }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
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
227
228
229
230
231
232
}

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
233
void
234
235
main_window_dialpad( gboolean *state ){
  if( !SHOW_DIALPAD )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
236
237
238
239
  {
    dialpad = create_dialpad();
    gtk_box_pack_end (GTK_BOX (subvbox), dialpad, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
    gtk_widget_show_all (dialpad);
240
    *state = TRUE;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
241
  }
242
  else
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
243
  {
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
244
    gtk_container_remove(GTK_CONTAINER (subvbox), dialpad);
245
    *state = FALSE;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
246
  }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
247
248
}

249
void
250
251
main_window_volume_controls( gboolean *state ){
  if( !SHOW_VOLUME )
252
253
  {
    speaker_control = create_slider("speaker");
254
    gtk_box_pack_end (GTK_BOX (subvbox), speaker_control, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
255
256
    gtk_widget_show_all (speaker_control);
    mic_control = create_slider("mic");
257
    gtk_box_pack_end (GTK_BOX (subvbox), mic_control, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
258
    gtk_widget_show_all (mic_control);
259
    *state = TRUE;
260
  }
261
  else
262
263
264
  {
    gtk_container_remove( GTK_CONTAINER(subvbox) , speaker_control );
    gtk_container_remove( GTK_CONTAINER(subvbox) , mic_control );
265
    *state = FALSE;
266
267
268
  }
}

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
void
main_window_searchbar( gboolean *state ){
  if( !SHOW_SEARCHBAR )
  {
    filterEntry = create_filter_entry();
    gtk_box_pack_start (GTK_BOX (subvbox), filterEntry, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
    gtk_widget_show_all (filterEntry);
    *state = TRUE;
  }
  else
  {
    gtk_container_remove( GTK_CONTAINER(subvbox) , filterEntry );
    *state = FALSE;
  }
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
285
void 
286
statusbar_push_message(const gchar * message, guint id)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
287
{ 
288
  gtk_statusbar_push(GTK_STATUSBAR(statusBar), id, message);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
289
290
}

291
void 
292
statusbar_pop_message(guint id)
293
294
295
296
297
298
{ 
  gtk_statusbar_pop(GTK_STATUSBAR(statusBar), id);
}