2
* Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
* Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
4
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
* Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
6
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
7
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 3 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
* Additional permission under GNU GPL version 3 section 7:
25
* If you modify this program, or any covered work, by linking or
26
* combining it with the OpenSSL project's OpenSSL library (or a
27
* modified version of that library), containing parts covered by the
28
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
29
* grants you additional permission to convey the resulting work.
30
* Corresponding Source for a non-source form of such a combination
31
* shall include the source code for the parts of OpenSSL used as well
32
* as that of the covered work.
41
#include "eel-gconf-extensions.h"
44
#include "statusicon.h"
45
#include "addrbookfactory.h"
46
#include "preferencesdialog.h"
47
#include "addressbook-config.h"
48
#include "shortcuts-config.h"
49
#include "hooks-config.h"
50
#include "audioconf.h"
51
#include "uimanager.h"
53
#include "mainwindow.h"
58
static gboolean dialogOpen = FALSE;
60
static GtkWidget * history_value;
62
static GtkWidget *starthidden;
63
static GtkWidget *popupwindow;
64
static GtkWidget *neverpopupwindow;
66
static GtkWidget *iconview;
67
static GtkWidget * notebook;
76
// history preference parameters
77
static int history_limit;
78
static gboolean history_enabled = TRUE;
80
// instant messaging preference parameters
81
static gboolean instant_messaging_enabled = TRUE;
86
gboolean currentstate = eel_gconf_get_integer(START_HIDDEN);
87
eel_gconf_set_integer(START_HIDDEN, !currentstate);
91
set_popup_mode(GtkWidget *widget, gpointer *userdata UNUSED)
93
gboolean currentstate = eel_gconf_get_integer(POPUP_ON_CALL);
95
if (currentstate || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
96
eel_gconf_set_integer(POPUP_ON_CALL, !currentstate);
102
gboolean current_state = eel_gconf_get_integer(NOTIFY_ALL);
103
eel_gconf_set_integer(NOTIFY_ALL, !current_state);
107
history_limit_cb(GtkSpinButton *button UNUSED, void *ptr)
109
history_limit = gtk_spin_button_get_value_as_int((GtkSpinButton *)(ptr));
113
history_enabled_cb(GtkWidget *widget)
115
history_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
116
gtk_widget_set_sensitive(GTK_WIDGET(history_value), history_enabled);
118
// Toggle it through D-Bus
119
eel_gconf_set_integer(HISTORY_ENABLED, !eel_gconf_get_integer(HISTORY_ENABLED));
123
instant_messaging_enabled_cb(GtkWidget *widget)
125
instant_messaging_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
126
eel_gconf_set_integer(INSTANT_MESSAGING_ENABLED, !eel_gconf_get_integer(INSTANT_MESSAGING_ENABLED));
132
calllist_clean_history();
135
void showstatusicon_cb(GtkWidget *widget, gpointer data UNUSED)
137
// data contains the previous value of dbus_is_status_icon_enabled () - ie before the click.
138
gboolean currentstatus = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
140
// Update the widget states
141
gtk_widget_set_sensitive(GTK_WIDGET(popupwindow), currentstatus);
142
gtk_widget_set_sensitive(GTK_WIDGET(neverpopupwindow), currentstatus);
143
gtk_widget_set_sensitive(GTK_WIDGET(starthidden), currentstatus);
145
currentstatus ? show_status_icon() : hide_status_icon();
147
// Update through D-Bus
148
eel_gconf_set_integer(SHOW_STATUSICON, currentstatus);
153
create_general_settings()
155
GtkWidget *ret, *notifAll, *frame, *checkBoxWidget, *label, *table, *showstatusicon;
158
// Load history configuration
159
history_load_configuration();
161
// Load instant messaging configuration
162
instant_messaging_load_configuration();
165
ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
166
gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
168
// Notifications Frame
169
gnome_main_section_new_with_table(_("Desktop Notifications"), &frame,
171
gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
174
notifAll = gtk_check_button_new_with_mnemonic(_("_Enable notifications"));
175
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(notifAll), eel_gconf_get_integer(NOTIFY_ALL));
176
g_signal_connect(G_OBJECT(notifAll) , "clicked" , G_CALLBACK(set_notif_level) , NULL);
177
gtk_table_attach(GTK_TABLE(table), notifAll, 0, 1, 0, 1, GTK_EXPAND
178
| GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
180
// System Tray option frame
181
gnome_main_section_new_with_table(_("System Tray Icon"), &frame, &table, 4,
183
gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
185
// Whether or not displaying an icon in the system tray
186
statusicon = eel_gconf_get_integer(SHOW_STATUSICON);
188
showstatusicon = gtk_check_button_new_with_mnemonic(
189
_("Show SFLphone in the system tray"));
190
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showstatusicon), statusicon);
191
g_signal_connect(G_OBJECT(showstatusicon) , "clicked" , G_CALLBACK(showstatusicon_cb), NULL);
192
gtk_table_attach(GTK_TABLE(table), showstatusicon, 0, 1, 0, 1, GTK_EXPAND
193
| GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
195
popupwindow = gtk_radio_button_new_with_mnemonic(NULL,
196
_("_Popup main window on incoming call"));
197
g_signal_connect(G_OBJECT(popupwindow), "toggled", G_CALLBACK(set_popup_mode), NULL);
198
gtk_table_attach(GTK_TABLE(table), popupwindow, 0, 1, 1, 2, GTK_EXPAND
199
| GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
201
neverpopupwindow = gtk_radio_button_new_with_mnemonic_from_widget(
202
GTK_RADIO_BUTTON(popupwindow), _("Ne_ver popup main window"));
203
gtk_table_attach(GTK_TABLE(table), neverpopupwindow, 0, 1, 2, 3, GTK_EXPAND
204
| GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
206
// Toggle according to the user configuration
207
eel_gconf_get_integer(POPUP_ON_CALL) ? gtk_toggle_button_set_active(
208
GTK_TOGGLE_BUTTON(popupwindow),
210
gtk_toggle_button_set_active(
211
GTK_TOGGLE_BUTTON(neverpopupwindow),
214
starthidden = gtk_check_button_new_with_mnemonic(
215
_("Hide SFLphone window on _startup"));
217
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(starthidden),
218
eel_gconf_get_integer(START_HIDDEN));
219
g_signal_connect(G_OBJECT(starthidden) , "clicked" , G_CALLBACK(start_hidden) , NULL);
220
gtk_table_attach(GTK_TABLE(table), starthidden, 0, 1, 3, 4, GTK_EXPAND
221
| GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
223
// Update the widget states
224
gtk_widget_set_sensitive(GTK_WIDGET(popupwindow),statusicon);
225
gtk_widget_set_sensitive(GTK_WIDGET(neverpopupwindow),statusicon);
226
gtk_widget_set_sensitive(GTK_WIDGET(starthidden),statusicon);
228
// HISTORY CONFIGURATION
229
gnome_main_section_new_with_table(_("Calls History"), &frame, &table, 3, 1);
230
gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
232
checkBoxWidget = gtk_check_button_new_with_mnemonic(
233
_("_Keep my history for at least"));
234
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkBoxWidget),
236
g_signal_connect(G_OBJECT(checkBoxWidget) , "clicked" , G_CALLBACK(history_enabled_cb) , NULL);
237
gtk_table_attach(GTK_TABLE(table), checkBoxWidget, 0, 1, 0, 1, GTK_EXPAND
238
| GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
240
history_value = gtk_spin_button_new_with_range(1, 99, 1);
241
gtk_spin_button_set_value(GTK_SPIN_BUTTON(history_value), history_limit);
242
g_signal_connect(G_OBJECT(history_value) , "value-changed" , G_CALLBACK(history_limit_cb) , history_value);
243
gtk_widget_set_sensitive(GTK_WIDGET(history_value),
244
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkBoxWidget)));
245
gtk_table_attach(GTK_TABLE(table), history_value, 1, 2, 0, 1, GTK_EXPAND
246
| GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
248
label = gtk_label_new(_("days"));
249
gtk_table_attach(GTK_TABLE(table), label, 2, 3, 0, 1, GTK_EXPAND | GTK_FILL,
250
GTK_EXPAND | GTK_FILL, 0, 5);
252
// INSTANT MESSAGING CONFIGURATION
253
gnome_main_section_new_with_table(_("Instant Messaging"), &frame, &table, 1, 1);
254
gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
256
checkBoxWidget = gtk_check_button_new_with_mnemonic(
257
_("Enable instant messaging"));
258
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkBoxWidget),
259
instant_messaging_enabled);
260
g_signal_connect(G_OBJECT(checkBoxWidget) , "clicked" , G_CALLBACK(instant_messaging_enabled_cb) , NULL);
261
gtk_table_attach(GTK_TABLE(table), checkBoxWidget, 0, 1, 0, 1, GTK_EXPAND
262
| GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
264
gtk_widget_show_all(ret);
270
save_configuration_parameters(void)
273
addressbook_config_save_parameters();
275
hooks_save_parameters();
278
dbus_set_history_limit(history_limit);
282
history_load_configuration()
284
history_limit = dbus_get_history_limit();
285
history_enabled = eel_gconf_get_integer(HISTORY_ENABLED);
290
instant_messaging_load_configuration()
292
instant_messaging_enabled = eel_gconf_get_integer(INSTANT_MESSAGING_ENABLED);
297
selection_changed_cb(GtkIconView *view, gpointer user_data UNUSED)
304
model = gtk_icon_view_get_model(view);
305
list = gtk_icon_view_get_selected_items(view);
310
if (g_list_length(list) > 1)
313
gtk_tree_model_get_iter(model, &iter, list->data);
314
gtk_tree_model_get(model, &iter, PAGE_NUMBER, &page, -1);
316
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), page);
317
g_list_foreach(list, (GFunc) gtk_tree_path_free, NULL);
322
* Get an 48x48 icon from the default theme or fallback to an application icon.
324
static GdkPixbuf *get_icon(const gchar *name, GtkWidget *widget)
326
GtkIconTheme *theme = gtk_icon_theme_get_default();
327
GdkPixbuf *pixbuf = gtk_icon_theme_load_icon(theme, name, 48, 0, NULL);
329
pixbuf = gtk_widget_render_icon_pixbuf(widget, name, GTK_ICON_SIZE_DIALOG);
334
static GtkTreeModel* create_model(GtkWidget *widget)
336
static const struct {
340
} browser_entries_full[] = {
341
{"General", GTK_STOCK_PREFERENCES, 0},
342
{"Audio", GTK_STOCK_AUDIO_CARD, 1},
343
{"Hooks", "applications-development", 2},
344
{"Shortcuts", "preferences-desktop-keyboard", 3},
345
{"Address Book", GTK_STOCK_ADDRESSBOOK, 4},
351
GtkListStore *store = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT);
352
nb_entries = sizeof(browser_entries_full) / sizeof(browser_entries_full[0]);
354
for (i = 0; i < nb_entries; i++) {
355
gtk_list_store_append (store, &iter);
356
pixbuf = get_icon(browser_entries_full[i].icon_name, widget);
357
gtk_list_store_set(store, &iter,
359
TEXT_COL, _(browser_entries_full[i].icon_descr),
360
PAGE_NUMBER, browser_entries_full[i].page_number,
363
gdk_pixbuf_unref(pixbuf);
366
return GTK_TREE_MODEL(store);
371
* Show configuration window with tabs
374
show_preferences_dialog()
377
GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new_with_buttons(_("Preferences"),
378
GTK_WINDOW(get_main_window()),
379
GTK_DIALOG_DESTROY_WITH_PARENT,
384
// Set window properties
385
gtk_window_set_default_size(GTK_WINDOW(dialog), 600, 400);
386
gtk_container_set_border_width(GTK_CONTAINER(dialog), 0);
388
GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
391
iconview = gtk_icon_view_new_with_model(create_model(hbox));
392
g_object_set (iconview,
393
"selection-mode", GTK_SELECTION_BROWSE,
394
"text-column", TEXT_COL,
395
"pixbuf-column", PIXBUF_COL,
400
// Connect the callback when clicking on an item
401
g_signal_connect(G_OBJECT(iconview), "selection-changed", G_CALLBACK(selection_changed_cb), NULL);
402
gtk_box_pack_start(GTK_BOX(hbox), iconview, TRUE, TRUE, 0);
404
// Create tabs container
405
notebook = gtk_notebook_new();
406
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
407
gtk_box_pack_end(GTK_BOX(hbox), notebook, TRUE, TRUE, 0);
408
GtkWidget *box = gtk_dialog_get_content_area(dialog);
409
gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, TRUE, 0);
410
gtk_widget_show_all(box);
411
gtk_container_set_border_width(GTK_CONTAINER(notebook), 10);
412
gtk_widget_show(notebook);
414
// General settings tab
415
GtkWidget *tab = create_general_settings();
416
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("General")));
417
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
420
tab = create_audio_configuration();
422
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Audio")));
423
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
426
tab = create_hooks_settings();
427
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Hooks")));
428
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
431
tab = create_shortcuts_settings();
432
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Shortcuts")));
433
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
437
tab = create_addressbook_settings();
438
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Address Book")));
439
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
442
// By default, general settings
443
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
444
// Highlight the corresponding icon
445
gtk_icon_view_select_path(GTK_ICON_VIEW(iconview), gtk_tree_path_new_first());
447
guint result = gtk_dialog_run(dialog);
449
save_configuration_parameters();
454
gtk_widget_destroy(GTK_WIDGET(dialog));