~ubuntu-branches/ubuntu/raring/sflphone/raring

« back to all changes in this revision

Viewing changes to gnome/src/config/preferencesdialog.c

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2011-11-25 13:24:12 UTC
  • mfrom: (4.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20111125132412-dc4qvhyosk74cd42
Tags: 1.0.1-4
Don't assume that arch:all packages will get built (closes: #649726)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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>
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
22
 *
 
23
 *  Additional permission under GNU GPL version 3 section 7:
 
24
 *
 
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.
 
33
 */
 
34
 
 
35
#include <gtk/gtk.h>
 
36
#include <stdlib.h>
 
37
#include <stdio.h>
 
38
#include <string.h>
 
39
#include <assert.h>
 
40
 
 
41
#include "eel-gconf-extensions.h"
 
42
#include "dbus.h"
 
43
#include "logger.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"
 
52
#include "unused.h"
 
53
#include "mainwindow.h"
 
54
 
 
55
/**
 
56
 * Local variables
 
57
 */
 
58
static gboolean dialogOpen = FALSE;
 
59
 
 
60
static GtkWidget * history_value;
 
61
 
 
62
static GtkWidget *starthidden;
 
63
static GtkWidget *popupwindow;
 
64
static GtkWidget *neverpopupwindow;
 
65
 
 
66
static GtkWidget *iconview;
 
67
static GtkWidget * notebook;
 
68
 
 
69
 
 
70
enum {
 
71
    PIXBUF_COL,
 
72
    TEXT_COL,
 
73
    PAGE_NUMBER
 
74
};
 
75
 
 
76
// history preference parameters
 
77
static int history_limit;
 
78
static gboolean history_enabled = TRUE;
 
79
 
 
80
// instant messaging preference parameters
 
81
static gboolean instant_messaging_enabled = TRUE;
 
82
 
 
83
static void
 
84
start_hidden(void)
 
85
{
 
86
    gboolean currentstate = eel_gconf_get_integer(START_HIDDEN);
 
87
    eel_gconf_set_integer(START_HIDDEN, !currentstate);
 
88
}
 
89
 
 
90
static void
 
91
set_popup_mode(GtkWidget *widget, gpointer *userdata UNUSED)
 
92
{
 
93
    gboolean currentstate = eel_gconf_get_integer(POPUP_ON_CALL);
 
94
 
 
95
    if (currentstate || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
 
96
        eel_gconf_set_integer(POPUP_ON_CALL, !currentstate);
 
97
}
 
98
 
 
99
void
 
100
set_notif_level()
 
101
{
 
102
    gboolean current_state = eel_gconf_get_integer(NOTIFY_ALL);
 
103
    eel_gconf_set_integer(NOTIFY_ALL, !current_state);
 
104
}
 
105
 
 
106
static void
 
107
history_limit_cb(GtkSpinButton *button UNUSED, void *ptr)
 
108
{
 
109
    history_limit = gtk_spin_button_get_value_as_int((GtkSpinButton *)(ptr));
 
110
}
 
111
 
 
112
static void
 
113
history_enabled_cb(GtkWidget *widget)
 
114
{
 
115
    history_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
 
116
    gtk_widget_set_sensitive(GTK_WIDGET(history_value), history_enabled);
 
117
 
 
118
    // Toggle it through D-Bus
 
119
    eel_gconf_set_integer(HISTORY_ENABLED, !eel_gconf_get_integer(HISTORY_ENABLED));
 
120
}
 
121
 
 
122
static void
 
123
instant_messaging_enabled_cb(GtkWidget *widget)
 
124
{
 
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));
 
127
}
 
128
 
 
129
void
 
130
clean_history(void)
 
131
{
 
132
    calllist_clean_history();
 
133
}
 
134
 
 
135
void showstatusicon_cb(GtkWidget *widget, gpointer data UNUSED)
 
136
{
 
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));
 
139
 
 
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);
 
144
 
 
145
    currentstatus ? show_status_icon() : hide_status_icon();
 
146
 
 
147
    // Update through D-Bus
 
148
    eel_gconf_set_integer(SHOW_STATUSICON, currentstatus);
 
149
}
 
150
 
 
151
 
 
152
GtkWidget*
 
153
create_general_settings()
 
154
{
 
155
    GtkWidget *ret, *notifAll, *frame, *checkBoxWidget, *label, *table, *showstatusicon;
 
156
    gboolean statusicon;
 
157
 
 
158
    // Load history configuration
 
159
    history_load_configuration();
 
160
 
 
161
    // Load instant messaging configuration
 
162
    instant_messaging_load_configuration();
 
163
 
 
164
    // Main widget
 
165
    ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
 
166
    gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
 
167
 
 
168
    // Notifications Frame
 
169
    gnome_main_section_new_with_table(_("Desktop Notifications"), &frame,
 
170
                                      &table, 2, 1);
 
171
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
 
172
 
 
173
    // Notification All
 
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);
 
179
 
 
180
    // System Tray option frame
 
181
    gnome_main_section_new_with_table(_("System Tray Icon"), &frame, &table, 4,
 
182
                                      1);
 
183
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
 
184
 
 
185
    // Whether or not displaying an icon in the system tray
 
186
    statusicon = eel_gconf_get_integer(SHOW_STATUSICON);
 
187
 
 
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);
 
194
 
 
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);
 
200
 
 
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);
 
205
 
 
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),
 
209
        TRUE) :
 
210
    gtk_toggle_button_set_active(
 
211
        GTK_TOGGLE_BUTTON(neverpopupwindow),
 
212
        TRUE);
 
213
 
 
214
    starthidden = gtk_check_button_new_with_mnemonic(
 
215
                      _("Hide SFLphone window on _startup"));
 
216
 
 
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);
 
222
 
 
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);
 
227
 
 
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);
 
231
 
 
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),
 
235
                                 history_enabled);
 
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);
 
239
 
 
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);
 
247
 
 
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);
 
251
 
 
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);
 
255
 
 
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);
 
263
 
 
264
    gtk_widget_show_all(ret);
 
265
 
 
266
    return ret;
 
267
}
 
268
 
 
269
void
 
270
save_configuration_parameters(void)
 
271
{
 
272
    if (addrbook)
 
273
        addressbook_config_save_parameters();
 
274
 
 
275
    hooks_save_parameters();
 
276
 
 
277
    // History config
 
278
    dbus_set_history_limit(history_limit);
 
279
}
 
280
 
 
281
void
 
282
history_load_configuration()
 
283
{
 
284
    history_limit = dbus_get_history_limit();
 
285
    history_enabled = eel_gconf_get_integer(HISTORY_ENABLED);
 
286
 
 
287
}
 
288
 
 
289
void
 
290
instant_messaging_load_configuration()
 
291
{
 
292
    instant_messaging_enabled = eel_gconf_get_integer(INSTANT_MESSAGING_ENABLED);
 
293
}
 
294
 
 
295
 
 
296
void
 
297
selection_changed_cb(GtkIconView *view, gpointer user_data UNUSED)
 
298
{
 
299
    GtkTreeModel *model;
 
300
    GtkTreeIter iter;
 
301
    GList *list;
 
302
    gint page;
 
303
 
 
304
    model = gtk_icon_view_get_model(view);
 
305
    list = gtk_icon_view_get_selected_items(view);
 
306
 
 
307
    if (list == NULL)
 
308
        return;
 
309
 
 
310
    if (g_list_length(list) > 1)
 
311
        return;
 
312
 
 
313
    gtk_tree_model_get_iter(model, &iter, list->data);
 
314
    gtk_tree_model_get(model, &iter, PAGE_NUMBER, &page, -1);
 
315
 
 
316
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), page);
 
317
    g_list_foreach(list, (GFunc) gtk_tree_path_free, NULL);
 
318
    g_list_free(list);
 
319
}
 
320
 
 
321
/*
 
322
 * Get an 48x48 icon from the default theme or fallback to an application icon.
 
323
 */
 
324
static GdkPixbuf *get_icon(const gchar *name, GtkWidget *widget)
 
325
{
 
326
    GtkIconTheme *theme = gtk_icon_theme_get_default();
 
327
    GdkPixbuf *pixbuf = gtk_icon_theme_load_icon(theme, name, 48, 0, NULL);
 
328
    if (!pixbuf)
 
329
        pixbuf = gtk_widget_render_icon_pixbuf(widget, name, GTK_ICON_SIZE_DIALOG);
 
330
 
 
331
    return pixbuf;
 
332
}
 
333
 
 
334
static GtkTreeModel* create_model(GtkWidget *widget)
 
335
{
 
336
    static const struct {
 
337
        gchar* icon_descr;
 
338
        gchar* icon_name;
 
339
        gint page_number;
 
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},
 
346
    };
 
347
    GdkPixbuf *pixbuf;
 
348
    GtkTreeIter iter;
 
349
    gint i, nb_entries;
 
350
 
 
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]);
 
353
 
 
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,
 
358
                           PIXBUF_COL, pixbuf,
 
359
                           TEXT_COL, _(browser_entries_full[i].icon_descr),
 
360
                           PAGE_NUMBER, browser_entries_full[i].page_number,
 
361
                           -1);
 
362
        if (pixbuf)
 
363
            gdk_pixbuf_unref(pixbuf);
 
364
    }
 
365
 
 
366
    return GTK_TREE_MODEL(store);
 
367
}
 
368
 
 
369
 
 
370
/**
 
371
 * Show configuration window with tabs
 
372
 */
 
373
guint
 
374
show_preferences_dialog()
 
375
{
 
376
    dialogOpen = TRUE;
 
377
    GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new_with_buttons(_("Preferences"),
 
378
                                   GTK_WINDOW(get_main_window()),
 
379
                                   GTK_DIALOG_DESTROY_WITH_PARENT,
 
380
                                   GTK_STOCK_CLOSE,
 
381
                                   GTK_RESPONSE_ACCEPT,
 
382
                                   NULL));
 
383
 
 
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);
 
387
 
 
388
    GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
 
389
 
 
390
    // Create tree view
 
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,
 
396
                  "columns", 1,
 
397
                  "margin", 10,
 
398
                  NULL);
 
399
 
 
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);
 
403
 
 
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);
 
413
 
 
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);
 
418
 
 
419
    // Audio tab
 
420
    tab = create_audio_configuration();
 
421
 
 
422
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Audio")));
 
423
    gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
 
424
 
 
425
    // Hooks 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);
 
429
 
 
430
    // Shortcuts 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);
 
434
 
 
435
    if (addrbook) {
 
436
        // Addressbook 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);
 
440
    }
 
441
 
 
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());
 
446
 
 
447
    guint result = gtk_dialog_run(dialog);
 
448
 
 
449
    save_configuration_parameters();
 
450
    update_actions();
 
451
 
 
452
    dialogOpen = FALSE;
 
453
 
 
454
    gtk_widget_destroy(GTK_WIDGET(dialog));
 
455
    return result;
 
456
}