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

« back to all changes in this revision

Viewing changes to .pc/05_glib_includes.patch/gnome/src/config/accountconfigdialog.c

  • Committer: Package Import Robot
  • Author(s): Whoopie
  • Date: 2012-03-22 10:29:10 UTC
  • mfrom: (4.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120322102910-tb8hugi2su1tguwh
Tags: 1.0.2-1ubuntu1
* Apply some upstream patches to fix FTBFS (LP: #913018):
  - debian/patches/05_glib_includes.patch: fix glib includes.
  - debian/patches/06_use_XkbKeycodeToKeysym.patch: use 
    XkbKeycodeToKeysym instead of (deprecated) XKeycodeToKeysym.

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: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
 
4
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
 
5
 *  Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
 
6
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; either version 3 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program; if not, write to the Free Software
 
20
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 *
 
22
 *  Additional permission under GNU GPL version 3 section 7:
 
23
 *
 
24
 *  If you modify this program, or any covered work, by linking or
 
25
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
26
 *  modified version of that library), containing parts covered by the
 
27
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
28
 *  grants you additional permission to convey the resulting work.
 
29
 *  Corresponding Source for a non-source form of such a combination
 
30
 *  shall include the source code for the parts of OpenSSL used as well
 
31
 *  as that of the covered work.
 
32
 */
 
33
 
 
34
#include <sys/socket.h>
 
35
#include <sys/ioctl.h>
 
36
#include <net/if.h>
 
37
#include <netinet/in.h>
 
38
#include <string.h>
 
39
#include <gtk/gtk.h>
 
40
 
 
41
#include "config.h"
 
42
#include "logger.h"
 
43
#include "actions.h"
 
44
#include "mainwindow.h"
 
45
#include "accountlist.h"
 
46
#include "audioconf.h"
 
47
#include "accountconfigdialog.h"
 
48
#include "zrtpadvanceddialog.h"
 
49
#include "tlsadvanceddialog.h"
 
50
#include "dbus/dbus.h"
 
51
#include "utils.h"
 
52
#include "unused.h"
 
53
 
 
54
/**
 
55
 * TODO: tidy this up
 
56
 * by storing these variables
 
57
 * in a private structure.
 
58
 * Local variables
 
59
 */
 
60
static GtkWidget * entryAlias;
 
61
static GtkWidget * protocolComboBox;
 
62
static GtkWidget * entryUsername;
 
63
static GtkWidget * entryRouteSet;
 
64
static GtkWidget * entryHostname;
 
65
static GtkWidget * entryPassword;
 
66
static GtkWidget * entryMailbox;
 
67
static GtkWidget * entryUseragent;
 
68
static GtkWidget * entryResolveNameOnlyOnce;
 
69
static GtkWidget * expireSpinBox;
 
70
static GtkListStore * credentialStore;
 
71
static GtkWidget * deleteCredButton;
 
72
static GtkWidget * treeViewCredential;
 
73
static GtkWidget * advancedZrtpButton;
 
74
static GtkWidget * keyExchangeCombo;
 
75
static GtkWidget * useSipTlsCheckBox;
 
76
 
 
77
static GtkWidget * localAddressEntry;
 
78
static GtkWidget * publishedAddressEntry;
 
79
static GtkWidget * localAddressCombo;
 
80
static GtkWidget * useStunCheckBox;
 
81
static GtkWidget * sameAsLocalRadioButton;
 
82
static GtkWidget * publishedAddrRadioButton;
 
83
static GtkWidget * publishedPortSpinBox;
 
84
static GtkWidget * localPortSpinBox;
 
85
static GtkWidget * publishedAddressLabel;
 
86
static GtkWidget * publishedPortLabel;
 
87
static GtkWidget * stunServerLabel;
 
88
static GtkWidget * stunServerEntry;
 
89
static GtkWidget * enableTone;
 
90
static GtkWidget * fileChooser;
 
91
 
 
92
static GtkWidget * security_tab;
 
93
static GtkWidget * advanced_tab;
 
94
 
 
95
static GtkWidget * overrtp;
 
96
 
 
97
// Credentials
 
98
enum {
 
99
    COLUMN_CREDENTIAL_REALM,
 
100
    COLUMN_CREDENTIAL_USERNAME,
 
101
    COLUMN_CREDENTIAL_PASSWORD,
 
102
    COLUMN_CREDENTIAL_DATA,
 
103
    COLUMN_CREDENTIAL_COUNT
 
104
};
 
105
 
 
106
/*
 
107
 * The same window is used with different configurations
 
108
 * so we need to reset some data to prevent side-effects
 
109
 */
 
110
static void reset()
 
111
{
 
112
    entryAlias = NULL;
 
113
    protocolComboBox = NULL;
 
114
    entryHostname = NULL;
 
115
    entryUsername = NULL;
 
116
    entryPassword = NULL;
 
117
    entryUseragent = NULL;
 
118
    entryMailbox = NULL;
 
119
}
 
120
 
 
121
/*
 
122
 * Display / Hide the password
 
123
 */
 
124
static void show_password_cb(GtkWidget *widget UNUSED, gpointer data)
 
125
{
 
126
    gtk_entry_set_visibility(GTK_ENTRY(data), !gtk_entry_get_visibility(GTK_ENTRY(data)));
 
127
}
 
128
 
 
129
/* Signal to protocolComboBox 'changed' */
 
130
void change_protocol_cb(account_t *currentAccount UNUSED)
 
131
{
 
132
    gchar *protocol = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(protocolComboBox));
 
133
 
 
134
    // Only if tabs are not NULL
 
135
    if (security_tab && advanced_tab) {
 
136
        if (g_strcasecmp(protocol, "IAX") == 0) {
 
137
            gtk_widget_hide(security_tab);
 
138
            gtk_widget_hide(advanced_tab);
 
139
        } else {
 
140
            gtk_widget_show(security_tab);
 
141
            gtk_widget_show(advanced_tab);
 
142
        }
 
143
    }
 
144
 
 
145
    g_free(protocol);
 
146
}
 
147
 
 
148
void
 
149
select_dtmf_type(void)
 
150
{
 
151
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(overrtp)))
 
152
        DEBUG("Selected DTMF over RTP");
 
153
    else
 
154
        DEBUG("Selected DTMF over SIP");
 
155
}
 
156
 
 
157
static GPtrArray* getNewCredential(void)
 
158
{
 
159
    GtkTreeIter iter;
 
160
    gint row_count = 0;
 
161
    GPtrArray *credential_array = g_ptr_array_new();
 
162
 
 
163
    gboolean valid;
 
164
 
 
165
    for (valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(credentialStore), &iter) ;
 
166
            valid;
 
167
            valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(credentialStore), &iter)) {
 
168
        gchar *username;
 
169
        gchar *realm;
 
170
        gchar *password;
 
171
 
 
172
        gtk_tree_model_get(GTK_TREE_MODEL(credentialStore), &iter,
 
173
                           COLUMN_CREDENTIAL_REALM, &realm,
 
174
                           COLUMN_CREDENTIAL_USERNAME, &username,
 
175
                           COLUMN_CREDENTIAL_PASSWORD, &password,
 
176
                           -1);
 
177
 
 
178
        DEBUG("Row %d: %s %s %s", row_count++, username, password, realm);
 
179
 
 
180
        GHashTable * new_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
 
181
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_REALM), realm);
 
182
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_USERNAME), username);
 
183
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_PASSWORD), password);
 
184
 
 
185
        g_ptr_array_add(credential_array, new_table);
 
186
    }
 
187
 
 
188
    return credential_array;
 
189
}
 
190
 
 
191
static void update_credential_cb(GtkWidget *widget, gpointer data UNUSED)
 
192
{
 
193
    GtkTreeIter iter;
 
194
 
 
195
    if (credentialStore && gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(credentialStore), &iter, "0")) {
 
196
        gint column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "column"));
 
197
        gtk_list_store_set(GTK_LIST_STORE(credentialStore), &iter, column,(gchar *) gtk_entry_get_text(GTK_ENTRY(widget)), -1);
 
198
    }
 
199
}
 
200
 
 
201
static GtkWidget* create_basic_tab(account_t *currentAccount)
 
202
{
 
203
    g_assert(currentAccount);
 
204
 
 
205
    // Load from SIP/IAX/Unknown ?
 
206
    gchar *curAccountType = g_hash_table_lookup(currentAccount->properties, ACCOUNT_TYPE);
 
207
    gchar *curAlias = g_hash_table_lookup(currentAccount->properties, ACCOUNT_ALIAS);
 
208
    gchar *curHostname = g_hash_table_lookup(currentAccount->properties, ACCOUNT_HOSTNAME);
 
209
    gchar *curPassword;
 
210
    gchar *curUsername;
 
211
    gchar *curUseragent;
 
212
    gchar *curRouteSet;
 
213
    gchar *curMailbox;
 
214
 
 
215
    if (g_strcmp0(curAccountType, "SIP") == 0) {
 
216
        /* get password from credentials list */
 
217
        if (currentAccount->credential_information) {
 
218
            GHashTable * element = g_ptr_array_index(currentAccount->credential_information, 0);
 
219
            curPassword = g_hash_table_lookup(element, ACCOUNT_PASSWORD);
 
220
        } else
 
221
            curPassword = "";
 
222
    } else
 
223
        curPassword = g_hash_table_lookup(currentAccount->properties, ACCOUNT_PASSWORD);
 
224
 
 
225
    curUsername = g_hash_table_lookup(currentAccount->properties, ACCOUNT_USERNAME);
 
226
    curRouteSet = g_hash_table_lookup(currentAccount->properties, ACCOUNT_ROUTE);
 
227
    curMailbox = g_hash_table_lookup(currentAccount->properties, ACCOUNT_MAILBOX);
 
228
    curMailbox = curMailbox != NULL ? curMailbox : "";
 
229
    curUseragent = g_hash_table_lookup(currentAccount->properties, ACCOUNT_USERAGENT);
 
230
 
 
231
    GtkWidget *frame = gnome_main_section_new(_("Account Parameters"));
 
232
    gtk_widget_show(frame);
 
233
 
 
234
    GtkWidget * table = NULL;
 
235
 
 
236
    if (g_strcmp0(curAccountType, "SIP") == 0)
 
237
        table = gtk_table_new(9, 2,  FALSE/* homogeneous */);
 
238
    else if (g_strcmp0(curAccountType, "IAX") == 0)
 
239
        table = gtk_table_new(8, 2, FALSE);
 
240
    else {
 
241
        ERROR("Unknown account type \"%s\"", curAccountType);
 
242
        return NULL;
 
243
    }
 
244
 
 
245
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
 
246
    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
 
247
    gtk_widget_show(table);
 
248
    gtk_container_add(GTK_CONTAINER(frame) , table);
 
249
 
 
250
    GtkWidget *label = gtk_label_new_with_mnemonic(_("_Alias"));
 
251
    gint row = 0;
 
252
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
253
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
254
    entryAlias = gtk_entry_new();
 
255
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), entryAlias);
 
256
    gtk_entry_set_text(GTK_ENTRY(entryAlias), curAlias);
 
257
    gtk_table_attach(GTK_TABLE(table), entryAlias, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
258
 
 
259
    row++;
 
260
    label = gtk_label_new_with_mnemonic(_("_Protocol"));
 
261
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
262
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
263
    protocolComboBox = gtk_combo_box_text_new();
 
264
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), protocolComboBox);
 
265
    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(protocolComboBox), "SIP");
 
266
 
 
267
    if (dbus_is_iax2_enabled())
 
268
        gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(protocolComboBox), "IAX");
 
269
 
 
270
    if (g_strcmp0(curAccountType, "SIP") == 0)
 
271
        gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox),0);
 
272
    else if (g_strcmp0(curAccountType, "IAX") == 0)
 
273
        gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox),1);
 
274
    else {
 
275
        DEBUG("Config: Error: Account protocol not valid");
 
276
        /* Should never come here, add debug message. */
 
277
        gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(protocolComboBox), _("Unknown"));
 
278
        gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox), 2);
 
279
    }
 
280
 
 
281
    gtk_table_attach(GTK_TABLE(table), protocolComboBox, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
282
 
 
283
    /* Link signal 'changed' */
 
284
    g_signal_connect(G_OBJECT(GTK_COMBO_BOX(protocolComboBox)), "changed",
 
285
                     G_CALLBACK(change_protocol_cb),
 
286
                     currentAccount);
 
287
 
 
288
    row++;
 
289
    label = gtk_label_new_with_mnemonic(_("_Host name"));
 
290
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
291
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
292
    entryHostname = gtk_entry_new();
 
293
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), entryHostname);
 
294
    gtk_entry_set_text(GTK_ENTRY(entryHostname), curHostname);
 
295
    gtk_table_attach(GTK_TABLE(table), entryHostname, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
296
 
 
297
    row++;
 
298
    label = gtk_label_new_with_mnemonic(_("_User name"));
 
299
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
300
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
301
    entryUsername = gtk_entry_new();
 
302
    gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(entryUsername), GTK_ENTRY_ICON_PRIMARY, gdk_pixbuf_new_from_file(ICONS_DIR "/stock_person.svg", NULL));
 
303
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), entryUsername);
 
304
    gtk_entry_set_text(GTK_ENTRY(entryUsername), curUsername);
 
305
    gtk_table_attach(GTK_TABLE(table), entryUsername, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
306
 
 
307
    if (g_strcmp0(curAccountType, "SIP") == 0) {
 
308
        g_signal_connect(G_OBJECT(entryUsername), "changed", G_CALLBACK(update_credential_cb), NULL);
 
309
        g_object_set_data(G_OBJECT(entryUsername), "column", GINT_TO_POINTER(COLUMN_CREDENTIAL_USERNAME));
 
310
    }
 
311
 
 
312
    row++;
 
313
    label = gtk_label_new_with_mnemonic(_("_Password"));
 
314
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
315
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
316
    entryPassword = gtk_entry_new();
 
317
    gtk_entry_set_icon_from_stock(GTK_ENTRY(entryPassword), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_DIALOG_AUTHENTICATION);
 
318
    gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
 
319
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), entryPassword);
 
320
    gtk_entry_set_text(GTK_ENTRY(entryPassword), curPassword);
 
321
    gtk_table_attach(GTK_TABLE(table), entryPassword, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
322
 
 
323
    if (g_strcmp0(curAccountType, "SIP") == 0) {
 
324
        g_signal_connect(G_OBJECT(entryPassword), "changed", G_CALLBACK(update_credential_cb), NULL);
 
325
        g_object_set_data(G_OBJECT(entryPassword), "column", GINT_TO_POINTER(COLUMN_CREDENTIAL_PASSWORD));
 
326
    }
 
327
 
 
328
    row++;
 
329
    GtkWidget *clearTextCheckbox = gtk_check_button_new_with_mnemonic(_("Show password"));
 
330
    g_signal_connect(clearTextCheckbox, "toggled", G_CALLBACK(show_password_cb), entryPassword);
 
331
    gtk_table_attach(GTK_TABLE(table), clearTextCheckbox, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
332
 
 
333
    row++;
 
334
    label = gtk_label_new_with_mnemonic(_("_Proxy"));
 
335
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
336
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
337
    entryRouteSet = gtk_entry_new();
 
338
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), entryRouteSet);
 
339
    gtk_entry_set_text(GTK_ENTRY(entryRouteSet), curRouteSet);
 
340
    gtk_table_attach(GTK_TABLE(table), entryRouteSet, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
341
 
 
342
    row++;
 
343
    label = gtk_label_new_with_mnemonic(_("_Voicemail number"));
 
344
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
345
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
346
    entryMailbox = gtk_entry_new();
 
347
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), entryMailbox);
 
348
    gtk_entry_set_text(GTK_ENTRY(entryMailbox), curMailbox);
 
349
    gtk_table_attach(GTK_TABLE(table), entryMailbox, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
350
 
 
351
    row++;
 
352
    label = gtk_label_new_with_mnemonic(_("_User-agent"));
 
353
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
354
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
355
    entryUseragent = gtk_entry_new();
 
356
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), entryUseragent);
 
357
    gtk_entry_set_text(GTK_ENTRY(entryUseragent), curUseragent);
 
358
    gtk_table_attach(GTK_TABLE(table), entryUseragent, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
359
 
 
360
    gtk_widget_show_all(table);
 
361
    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
 
362
 
 
363
    return frame;
 
364
}
 
365
 
 
366
static void fill_treeview_with_credential(account_t * account)
 
367
{
 
368
    GtkTreeIter iter;
 
369
    gtk_list_store_clear(credentialStore);
 
370
 
 
371
    if (!account->credential_information) {
 
372
        account->credential_information = g_ptr_array_sized_new(1);
 
373
        GHashTable * new_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
 
374
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_REALM), g_strdup("*"));
 
375
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_USERNAME), g_strdup(""));
 
376
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_PASSWORD), g_strdup(""));
 
377
        g_ptr_array_add(account->credential_information, new_table);
 
378
    }
 
379
 
 
380
    for (unsigned i = 0; i < account->credential_information->len; i++) {
 
381
        GHashTable * element = g_ptr_array_index(account->credential_information, i);
 
382
        gtk_list_store_append(credentialStore, &iter);
 
383
        gtk_list_store_set(credentialStore, &iter,
 
384
                           COLUMN_CREDENTIAL_REALM, g_hash_table_lookup(element, ACCOUNT_REALM),
 
385
                           COLUMN_CREDENTIAL_USERNAME, g_hash_table_lookup(element, ACCOUNT_USERNAME),
 
386
                           COLUMN_CREDENTIAL_PASSWORD, g_hash_table_lookup(element, ACCOUNT_PASSWORD),
 
387
                           COLUMN_CREDENTIAL_DATA, element, -1);
 
388
    }
 
389
}
 
390
 
 
391
static void select_credential_cb(GtkTreeSelection *selection, GtkTreeModel *model)
 
392
{
 
393
    GtkTreeIter iter;
 
394
 
 
395
    if (gtk_tree_selection_get_selected(selection, NULL, &iter)) {
 
396
        GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
 
397
 
 
398
        if (gtk_tree_path_get_indices(path)[0] == 0)
 
399
            gtk_widget_set_sensitive(deleteCredButton, FALSE);
 
400
        else
 
401
            gtk_widget_set_sensitive(deleteCredButton, TRUE);
 
402
    }
 
403
}
 
404
 
 
405
static void add_credential_cb(GtkWidget *button UNUSED, gpointer data)
 
406
{
 
407
    GtkTreeIter iter;
 
408
    GtkTreeModel *model =(GtkTreeModel *) data;
 
409
 
 
410
    gtk_list_store_append(GTK_LIST_STORE(model), &iter);
 
411
    gtk_list_store_set(GTK_LIST_STORE(model), &iter,
 
412
                       COLUMN_CREDENTIAL_REALM, "*",
 
413
                       COLUMN_CREDENTIAL_USERNAME, _("Authentication"),
 
414
                       COLUMN_CREDENTIAL_PASSWORD, _("Secret"), -1);
 
415
}
 
416
 
 
417
static void delete_credential_cb(GtkWidget *button UNUSED, gpointer data)
 
418
{
 
419
    GtkTreeIter iter;
 
420
    GtkTreeView *treeview =(GtkTreeView *) data;
 
421
    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
 
422
    GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
 
423
 
 
424
    if (gtk_tree_selection_get_selected(selection, NULL, &iter)) {
 
425
        GtkTreePath *path;
 
426
        path = gtk_tree_model_get_path(model, &iter);
 
427
        gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
 
428
 
 
429
        gtk_tree_path_free(path);
 
430
    }
 
431
 
 
432
}
 
433
 
 
434
static void cell_edited_cb(GtkCellRendererText *renderer, gchar *path_desc, gchar *text, gpointer data)
 
435
{
 
436
    GtkTreeModel *model =(GtkTreeModel *) data;
 
437
    GtkTreePath *path = gtk_tree_path_new_from_string(path_desc);
 
438
 
 
439
    gint column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(renderer), "column"));
 
440
    DEBUG("path desc in cell_edited_cb: %s\n", text);
 
441
 
 
442
    if ((g_strcasecmp(path_desc, "0") == 0) &&
 
443
            g_strcasecmp(text, gtk_entry_get_text(GTK_ENTRY(entryUsername))) != 0)
 
444
        g_signal_handlers_disconnect_by_func(G_OBJECT(entryUsername), G_CALLBACK(update_credential_cb), NULL);
 
445
 
 
446
    GtkTreeIter iter;
 
447
    gtk_tree_model_get_iter(model, &iter, path);
 
448
    gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, text, -1);
 
449
    gtk_tree_path_free(path);
 
450
}
 
451
 
 
452
static void editing_started_cb(GtkCellRenderer *cell UNUSED, GtkCellEditable * editable, const gchar * path, gpointer data UNUSED)
 
453
{
 
454
    DEBUG("Editing started");
 
455
    DEBUG("path desc in editing_started_cb: %s\n", path);
 
456
 
 
457
    // If we are dealing the first row
 
458
    if (g_strcasecmp(path, "0") == 0)
 
459
        gtk_entry_set_text(GTK_ENTRY(editable), gtk_entry_get_text(GTK_ENTRY(entryPassword)));
 
460
}
 
461
 
 
462
static void show_advanced_zrtp_options_cb(GtkWidget *widget UNUSED, gpointer data)
 
463
{
 
464
    gchar *proto = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(keyExchangeCombo));
 
465
 
 
466
    if (g_strcasecmp(proto, "ZRTP") == 0)
 
467
        show_advanced_zrtp_options((GHashTable *) data);
 
468
    else
 
469
        show_advanced_sdes_options((GHashTable *) data);
 
470
 
 
471
    g_free(proto);
 
472
}
 
473
 
 
474
 
 
475
static void show_advanced_tls_options_cb(GtkWidget *widget UNUSED, gpointer data)
 
476
{
 
477
    show_advanced_tls_options((GHashTable *) data);
 
478
}
 
479
 
 
480
static void key_exchange_changed_cb(GtkWidget *widget UNUSED, gpointer data UNUSED)
 
481
{
 
482
    gchar *active_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(keyExchangeCombo));
 
483
    DEBUG("Key exchange changed %s", active_text);
 
484
 
 
485
    gboolean set_sensitive = FALSE;
 
486
    set_sensitive |= g_strcasecmp(active_text, "SDES") == 0;
 
487
    set_sensitive |= g_strcasecmp(active_text, "ZRTP") == 0;
 
488
    g_free(active_text);
 
489
 
 
490
    if (set_sensitive)
 
491
        gtk_widget_set_sensitive(advancedZrtpButton, TRUE);
 
492
    else
 
493
        gtk_widget_set_sensitive(advancedZrtpButton, FALSE);
 
494
}
 
495
 
 
496
 
 
497
static void use_sip_tls_cb(GtkWidget *widget, gpointer data)
 
498
{
 
499
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
 
500
        DEBUG("Using sips");
 
501
        gtk_widget_set_sensitive(data, TRUE);
 
502
        // Uncheck stun
 
503
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useStunCheckBox), FALSE);
 
504
        gtk_widget_set_sensitive(useStunCheckBox, FALSE);
 
505
        gtk_widget_set_sensitive(sameAsLocalRadioButton, TRUE);
 
506
        gtk_widget_set_sensitive(publishedAddrRadioButton, TRUE);
 
507
        gtk_widget_hide(stunServerLabel);
 
508
        gtk_widget_hide(stunServerEntry);
 
509
 
 
510
        if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton))) {
 
511
            gtk_widget_show(publishedAddressEntry);
 
512
            gtk_widget_show(publishedPortSpinBox);
 
513
            gtk_widget_show(publishedAddressLabel);
 
514
            gtk_widget_show(publishedPortLabel);
 
515
        }
 
516
    } else {
 
517
        gtk_widget_set_sensitive(data, FALSE);
 
518
        gtk_widget_set_sensitive(useStunCheckBox, TRUE);
 
519
 
 
520
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useStunCheckBox))) {
 
521
            gtk_widget_set_sensitive(sameAsLocalRadioButton, FALSE);
 
522
            gtk_widget_set_sensitive(publishedAddrRadioButton, FALSE);
 
523
            gtk_widget_show(stunServerLabel);
 
524
            gtk_widget_show(stunServerEntry);
 
525
            gtk_widget_hide(publishedAddressEntry);
 
526
            gtk_widget_hide(publishedPortSpinBox);
 
527
            gtk_widget_hide(publishedAddressLabel);
 
528
            gtk_widget_hide(publishedPortLabel);
 
529
        } else {
 
530
            gtk_widget_set_sensitive(sameAsLocalRadioButton, TRUE);
 
531
            gtk_widget_set_sensitive(publishedAddrRadioButton, TRUE);
 
532
            gtk_widget_hide(stunServerLabel);
 
533
            gtk_widget_hide(stunServerEntry);
 
534
        }
 
535
    }
 
536
}
 
537
 
 
538
static gchar *
 
539
get_interface_addr_from_name(const gchar * const iface_name)
 
540
{
 
541
#define UC(b)   (((int)b)&0xff)
 
542
 
 
543
    int fd;
 
544
 
 
545
    if ((fd = socket(AF_INET, SOCK_DGRAM,0)) < 0)
 
546
        DEBUG("getInterfaceAddrFromName error could not open socket\n");
 
547
 
 
548
    struct ifreq ifr;
 
549
    memset(&ifr, 0, sizeof(struct ifreq));
 
550
 
 
551
    strcpy(ifr.ifr_name, iface_name);
 
552
    ifr.ifr_addr.sa_family = AF_INET;
 
553
 
 
554
    if (ioctl(fd, SIOCGIFADDR, &ifr) < 0)
 
555
        DEBUG("getInterfaceAddrFromName use default interface (0.0.0.0)\n");
 
556
 
 
557
 
 
558
    struct sockaddr_in *saddr_in = (struct sockaddr_in *) &ifr.ifr_addr;
 
559
    struct in_addr *addr_in = &(saddr_in->sin_addr);
 
560
 
 
561
    char *tmp_addr = (char *) addr_in;
 
562
 
 
563
    gchar *iface_addr = g_strdup_printf("%d.%d.%d.%d", UC(tmp_addr[0]),
 
564
                                        UC(tmp_addr[1]), UC(tmp_addr[2]), UC(tmp_addr[3]));
 
565
 
 
566
    close(fd);
 
567
    return iface_addr;
 
568
#undef UC
 
569
}
 
570
 
 
571
static void local_interface_changed_cb(GtkWidget * widget UNUSED, gpointer data UNUSED)
 
572
{
 
573
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton))) {
 
574
        gchar *local_iface_name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(localAddressCombo));
 
575
        gchar *local_iface_addr = get_interface_addr_from_name(local_iface_name);
 
576
 
 
577
        gtk_entry_set_text(GTK_ENTRY(localAddressEntry), local_iface_addr);
 
578
        gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), local_iface_addr);
 
579
        g_free(local_iface_addr);
 
580
        g_free(local_iface_name);
 
581
    }
 
582
}
 
583
 
 
584
static void set_published_addr_manually_cb(GtkWidget * widget, gpointer data UNUSED)
 
585
{
 
586
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
 
587
        DEBUG("Config: Showing manual publishing options");
 
588
        gtk_widget_show(publishedPortLabel);
 
589
        gtk_widget_show(publishedPortSpinBox);
 
590
        gtk_widget_show(publishedAddressLabel);
 
591
        gtk_widget_show(publishedAddressEntry);
 
592
    } else {
 
593
        DEBUG("Config: Hiding manual publishing options");
 
594
        gtk_widget_hide(publishedPortLabel);
 
595
        gtk_widget_hide(publishedPortSpinBox);
 
596
        gtk_widget_hide(publishedAddressLabel);
 
597
        gtk_widget_hide(publishedAddressEntry);
 
598
    }
 
599
}
 
600
 
 
601
static void use_stun_cb(GtkWidget *widget, gpointer data UNUSED)
 
602
{
 
603
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
 
604
        DEBUG("Config: Showing stun options, hiding Local/Published info");
 
605
        gtk_widget_show(stunServerLabel);
 
606
        gtk_widget_show(stunServerEntry);
 
607
        gtk_widget_set_sensitive(sameAsLocalRadioButton, FALSE);
 
608
        gtk_widget_set_sensitive(publishedAddrRadioButton, FALSE);
 
609
 
 
610
        gtk_widget_hide(publishedAddressLabel);
 
611
        gtk_widget_hide(publishedPortLabel);
 
612
        gtk_widget_hide(publishedAddressEntry);
 
613
        gtk_widget_hide(publishedPortSpinBox);
 
614
    } else {
 
615
        DEBUG("Config: hiding stun options, showing Local/Published info");
 
616
        gtk_widget_hide(stunServerLabel);
 
617
        gtk_widget_hide(stunServerEntry);
 
618
        gtk_widget_set_sensitive(sameAsLocalRadioButton, TRUE);
 
619
        gtk_widget_set_sensitive(publishedAddrRadioButton, TRUE);
 
620
 
 
621
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(publishedAddrRadioButton))) {
 
622
            gtk_widget_show(publishedAddressLabel);
 
623
            gtk_widget_show(publishedPortLabel);
 
624
            gtk_widget_show(publishedAddressEntry);
 
625
            gtk_widget_show(publishedPortSpinBox);
 
626
        }
 
627
    }
 
628
 
 
629
    DEBUG("DONE");
 
630
}
 
631
 
 
632
 
 
633
static void same_as_local_cb(GtkWidget * widget, gpointer data UNUSED)
 
634
{
 
635
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
 
636
        gchar *local_interface = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(localAddressCombo));
 
637
        gchar *local_address = dbus_get_address_from_interface_name(local_interface);
 
638
 
 
639
        gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), local_address);
 
640
 
 
641
        const gchar * local_port = gtk_entry_get_text(GTK_ENTRY(localPortSpinBox));
 
642
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(publishedPortSpinBox), g_ascii_strtod(local_port, NULL));
 
643
        g_free(local_interface);
 
644
    }
 
645
}
 
646
 
 
647
 
 
648
 
 
649
GtkWidget* create_credential_widget(account_t *a)
 
650
{
 
651
 
 
652
    GtkWidget *frame, *table, *scrolledWindowCredential, *addButton;
 
653
    GtkCellRenderer * renderer;
 
654
    GtkTreeViewColumn * treeViewColumn;
 
655
    GtkTreeSelection * treeSelection;
 
656
 
 
657
    /* Credentials tree view */
 
658
    gnome_main_section_new_with_table(_("Credential"), &frame, &table, 1, 1);
 
659
    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
 
660
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
 
661
 
 
662
    scrolledWindowCredential = gtk_scrolled_window_new(NULL, NULL);
 
663
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindowCredential), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
664
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledWindowCredential), GTK_SHADOW_IN);
 
665
    gtk_table_attach_defaults(GTK_TABLE(table), scrolledWindowCredential, 0, 1, 0, 1);
 
666
 
 
667
    credentialStore = gtk_list_store_new(COLUMN_CREDENTIAL_COUNT,
 
668
                                         G_TYPE_STRING,  // Realm
 
669
                                         G_TYPE_STRING,  // Username
 
670
                                         G_TYPE_STRING,  // Password
 
671
                                         G_TYPE_POINTER  // Pointer to the Objectc
 
672
                                        );
 
673
 
 
674
    treeViewCredential = gtk_tree_view_new_with_model(GTK_TREE_MODEL(credentialStore));
 
675
    treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeViewCredential));
 
676
    g_signal_connect(G_OBJECT(treeSelection), "changed", G_CALLBACK(select_credential_cb), credentialStore);
 
677
 
 
678
    renderer = gtk_cell_renderer_text_new();
 
679
    g_object_set(renderer, "editable", TRUE, "editable-set", TRUE, NULL);
 
680
    g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK(cell_edited_cb), credentialStore);
 
681
    g_object_set_data(G_OBJECT(renderer), "column", GINT_TO_POINTER(COLUMN_CREDENTIAL_REALM));
 
682
    treeViewColumn = gtk_tree_view_column_new_with_attributes("Realm",
 
683
                     renderer,
 
684
                     "markup", COLUMN_CREDENTIAL_REALM,
 
685
                     NULL);
 
686
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeViewCredential), treeViewColumn);
 
687
 
 
688
    renderer = gtk_cell_renderer_text_new();
 
689
    g_object_set(renderer, "editable", TRUE, "editable-set", TRUE, NULL);
 
690
    g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK(cell_edited_cb), credentialStore);
 
691
    g_object_set_data(G_OBJECT(renderer), "column", GINT_TO_POINTER(COLUMN_CREDENTIAL_USERNAME));
 
692
    treeViewColumn = gtk_tree_view_column_new_with_attributes(_("Authentication name"),
 
693
                     renderer,
 
694
                     "markup", COLUMN_CREDENTIAL_USERNAME,
 
695
                     NULL);
 
696
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeViewCredential), treeViewColumn);
 
697
 
 
698
    renderer = gtk_cell_renderer_text_new();
 
699
    g_object_set(renderer, "editable", TRUE, "editable-set", TRUE, NULL);
 
700
    g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK(cell_edited_cb), credentialStore);
 
701
    g_signal_connect(renderer, "editing-started", G_CALLBACK(editing_started_cb), NULL);
 
702
    g_object_set_data(G_OBJECT(renderer), "column", GINT_TO_POINTER(COLUMN_CREDENTIAL_PASSWORD));
 
703
    treeViewColumn = gtk_tree_view_column_new_with_attributes(_("Password"),
 
704
                     renderer,
 
705
                     "markup", COLUMN_CREDENTIAL_PASSWORD,
 
706
                     NULL);
 
707
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeViewCredential), treeViewColumn);
 
708
 
 
709
    gtk_container_add(GTK_CONTAINER(scrolledWindowCredential), treeViewCredential);
 
710
 
 
711
    fill_treeview_with_credential(a);
 
712
 
 
713
    /* Credential Buttons */
 
714
    GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
 
715
    gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 3, 1, 2);
 
716
 
 
717
    addButton = gtk_button_new_from_stock(GTK_STOCK_ADD);
 
718
    g_signal_connect(addButton, "clicked", G_CALLBACK(add_credential_cb), credentialStore);
 
719
    gtk_box_pack_start(GTK_BOX(hbox), addButton, FALSE, FALSE, 0);
 
720
 
 
721
    deleteCredButton = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
 
722
    g_signal_connect(deleteCredButton, "clicked", G_CALLBACK(delete_credential_cb), treeViewCredential);
 
723
    gtk_box_pack_start(GTK_BOX(hbox), deleteCredButton, FALSE, FALSE, 0);
 
724
 
 
725
    /* Dynamically resize the window to fit the scrolled window */
 
726
    gtk_widget_set_size_request(scrolledWindowCredential, 400, 120);
 
727
 
 
728
    return frame;
 
729
}
 
730
 
 
731
 
 
732
GtkWidget* create_security_widget(account_t *a)
 
733
{
 
734
 
 
735
    GtkWidget *frame, *table, *sipTlsAdvancedButton, *label;
 
736
    gchar *curSRTPEnabled = NULL, *curKeyExchange = NULL, *curTLSEnabled = NULL;
 
737
 
 
738
    // Load from SIP/IAX/Unknown ?
 
739
    if (a) {
 
740
        curKeyExchange = g_hash_table_lookup(a->properties, ACCOUNT_KEY_EXCHANGE);
 
741
 
 
742
        if (curKeyExchange == NULL)
 
743
            curKeyExchange = "none";
 
744
 
 
745
        curSRTPEnabled = g_hash_table_lookup(a->properties, ACCOUNT_SRTP_ENABLED);
 
746
 
 
747
        if (curSRTPEnabled == NULL)
 
748
            curSRTPEnabled = "false";
 
749
 
 
750
        curTLSEnabled = g_hash_table_lookup(a->properties, TLS_ENABLE);
 
751
 
 
752
        if (curTLSEnabled == NULL)
 
753
            curTLSEnabled = "false";
 
754
    }
 
755
 
 
756
    gnome_main_section_new_with_table(_("Security"), &frame, &table, 2, 3);
 
757
    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
 
758
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
 
759
    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
 
760
 
 
761
    /* TLS subsection */
 
762
    sipTlsAdvancedButton = gtk_button_new_from_stock(GTK_STOCK_EDIT);
 
763
    gtk_table_attach_defaults(GTK_TABLE(table), sipTlsAdvancedButton, 2, 3, 0, 1);
 
764
    gtk_widget_set_sensitive(sipTlsAdvancedButton, FALSE);
 
765
    g_signal_connect(G_OBJECT(sipTlsAdvancedButton), "clicked", G_CALLBACK(show_advanced_tls_options_cb),a->properties);
 
766
 
 
767
    useSipTlsCheckBox = gtk_check_button_new_with_mnemonic(_("Use TLS transport(sips)"));
 
768
    g_signal_connect(useSipTlsCheckBox, "toggled", G_CALLBACK(use_sip_tls_cb), sipTlsAdvancedButton);
 
769
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useSipTlsCheckBox),(g_strcmp0(curTLSEnabled, "true") == 0) ? TRUE:FALSE);
 
770
    gtk_table_attach_defaults(GTK_TABLE(table), useSipTlsCheckBox, 0, 2, 0, 1);
 
771
 
 
772
    /* ZRTP subsection */
 
773
    label = gtk_label_new_with_mnemonic(_("SRTP key exchange"));
 
774
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
775
    keyExchangeCombo = gtk_combo_box_text_new();
 
776
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), keyExchangeCombo);
 
777
    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(keyExchangeCombo), "ZRTP");
 
778
    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(keyExchangeCombo), "SDES");
 
779
    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(keyExchangeCombo), _("Disabled"));
 
780
 
 
781
    advancedZrtpButton = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
 
782
    g_signal_connect(G_OBJECT(advancedZrtpButton), "clicked", G_CALLBACK(show_advanced_zrtp_options_cb),a->properties);
 
783
 
 
784
    if (g_strcmp0(curSRTPEnabled, "false") == 0) {
 
785
        gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo), 2);
 
786
        gtk_widget_set_sensitive(advancedZrtpButton, FALSE);
 
787
    } else {
 
788
        if (g_strcmp0(curKeyExchange, ZRTP) == 0)
 
789
            gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo),0);
 
790
        else if (g_strcmp0(curKeyExchange, SDES) == 0)
 
791
            gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo),1);
 
792
        else {
 
793
            gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo), 2);
 
794
            gtk_widget_set_sensitive(advancedZrtpButton, FALSE);
 
795
        }
 
796
    }
 
797
 
 
798
    g_signal_connect(G_OBJECT(GTK_COMBO_BOX(keyExchangeCombo)), "changed", G_CALLBACK(key_exchange_changed_cb), a);
 
799
 
 
800
    gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
 
801
    gtk_table_attach_defaults(GTK_TABLE(table), keyExchangeCombo, 1, 2, 1, 2);
 
802
    gtk_table_attach_defaults(GTK_TABLE(table), advancedZrtpButton, 2, 3, 1, 2);
 
803
 
 
804
    gtk_widget_show_all(table);
 
805
 
 
806
    return frame;
 
807
}
 
808
 
 
809
 
 
810
GtkWidget * create_security_tab(account_t *a)
 
811
{
 
812
    GtkWidget * frame;
 
813
    GtkWidget * ret;
 
814
 
 
815
    ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
 
816
    gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
 
817
 
 
818
    // Credentials frame
 
819
    frame = create_credential_widget(a);
 
820
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
 
821
 
 
822
    // Security frame
 
823
    frame = create_security_widget(a);
 
824
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
 
825
 
 
826
    gtk_widget_show_all(ret);
 
827
 
 
828
    return ret;
 
829
}
 
830
 
 
831
static GtkWidget* create_registration_expire(account_t *a)
 
832
{
 
833
 
 
834
    GtkWidget *table, *frame, *label;
 
835
 
 
836
    gchar *resolve_once=NULL, *account_expire=NULL;
 
837
 
 
838
    if (a) {
 
839
        resolve_once = g_hash_table_lookup(a->properties, ACCOUNT_RESOLVE_ONCE);
 
840
        account_expire = g_hash_table_lookup(a->properties, ACCOUNT_REGISTRATION_EXPIRE);
 
841
    }
 
842
 
 
843
    gnome_main_section_new_with_table(_("Registration"), &frame, &table, 2, 3);
 
844
    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
 
845
    gtk_table_set_row_spacings(GTK_TABLE(table), 5);
 
846
 
 
847
    label = gtk_label_new_with_mnemonic(_("Registration expire"));
 
848
    gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
 
849
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
850
    expireSpinBox = gtk_spin_button_new_with_range(1, 65535, 1);
 
851
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), expireSpinBox);
 
852
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(expireSpinBox), g_ascii_strtod(account_expire, NULL));
 
853
    gtk_table_attach_defaults(GTK_TABLE(table), expireSpinBox, 1, 2, 0, 1);
 
854
 
 
855
 
 
856
    entryResolveNameOnlyOnce = gtk_check_button_new_with_mnemonic(_("_Comply with RFC 3263"));
 
857
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(entryResolveNameOnlyOnce),
 
858
                                 g_strcasecmp(resolve_once,"false") == 0 ? TRUE: FALSE);
 
859
    gtk_table_attach_defaults(GTK_TABLE(table), entryResolveNameOnlyOnce, 0, 2, 1, 2);
 
860
    gtk_widget_set_sensitive(entryResolveNameOnlyOnce , TRUE);
 
861
 
 
862
    return frame;
 
863
}
 
864
 
 
865
GtkWidget* create_network(account_t *a)
 
866
{
 
867
    GtkWidget *table, *frame, *label;
 
868
    gchar *local_interface = NULL;
 
869
    gchar *local_port = NULL;
 
870
 
 
871
    if (a) {
 
872
        local_interface = g_hash_table_lookup(a->properties, LOCAL_INTERFACE);
 
873
        local_port = g_hash_table_lookup(a->properties, LOCAL_PORT);
 
874
    }
 
875
 
 
876
    gnome_main_section_new_with_table(_("Network Interface"), &frame, &table, 2, 3);
 
877
    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
 
878
    gtk_table_set_row_spacings(GTK_TABLE(table), 5);
 
879
 
 
880
    /**
 
881
     * Retreive the list of IP interface from the
 
882
     * the daemon and build the combo box.
 
883
     */
 
884
    localAddressCombo = gtk_combo_box_text_new();
 
885
 
 
886
 
 
887
    label = gtk_label_new_with_mnemonic(_("Local address"));
 
888
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
889
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
890
 
 
891
    gchar **iface_list = dbus_get_all_ip_interface_by_name();
 
892
 
 
893
    int idx = 0;
 
894
    for (gchar **iface = iface_list; iface && *iface; iface++, idx++) {
 
895
 
 
896
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(localAddressCombo), NULL, *iface);
 
897
        if (g_strcmp0(*iface, local_interface) == 0)
 
898
            gtk_combo_box_set_active(GTK_COMBO_BOX(localAddressCombo), idx);
 
899
    }
 
900
    if (!local_interface)
 
901
        gtk_combo_box_set_active(GTK_COMBO_BOX(localAddressCombo), 0);
 
902
 
 
903
 
 
904
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), localAddressCombo);
 
905
    gtk_table_attach(GTK_TABLE(table), localAddressCombo, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
906
 
 
907
    // Fill the text entry with the ip address of local interface selected
 
908
    localAddressEntry = gtk_entry_new();
 
909
    gchar *local_iface_name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(localAddressCombo));
 
910
    gchar *local_iface_addr = get_interface_addr_from_name(local_iface_name);
 
911
    g_free(local_iface_name);
 
912
    gtk_entry_set_text(GTK_ENTRY(localAddressEntry), local_iface_addr);
 
913
    g_free(local_iface_addr);
 
914
    gtk_widget_set_sensitive(localAddressEntry, FALSE);
 
915
    gtk_table_attach(GTK_TABLE(table), localAddressEntry, 2, 3, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
916
 
 
917
    // Local port widget
 
918
    label = gtk_label_new_with_mnemonic(_("Local port"));
 
919
    gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
 
920
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
921
    localPortSpinBox = gtk_spin_button_new_with_range(1, 65535, 1);
 
922
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), localPortSpinBox);
 
923
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(localPortSpinBox), g_ascii_strtod(local_port, NULL));
 
924
 
 
925
    gtk_table_attach_defaults(GTK_TABLE(table), localPortSpinBox, 1, 2, 1, 2);
 
926
 
 
927
    return frame;
 
928
}
 
929
 
 
930
GtkWidget* create_published_address(account_t *a)
 
931
{
 
932
 
 
933
    GtkWidget *table, *frame;
 
934
    gchar *use_tls =NULL;
 
935
    gchar *published_address = NULL;
 
936
    gchar *published_port = NULL;
 
937
    gchar *stun_enable = NULL;
 
938
    gchar *stun_server = NULL;
 
939
    gchar *published_sameas_local = NULL;
 
940
 
 
941
    // Get the user configuration
 
942
    if (a) {
 
943
 
 
944
        use_tls = g_hash_table_lookup(a->properties, TLS_ENABLE);
 
945
        published_sameas_local = g_hash_table_lookup(a->properties, PUBLISHED_SAMEAS_LOCAL);
 
946
 
 
947
        if (g_strcasecmp(published_sameas_local, "true") == 0) {
 
948
            published_address = dbus_get_address_from_interface_name(g_hash_table_lookup(a->properties, LOCAL_INTERFACE));
 
949
            published_port = g_hash_table_lookup(a->properties, LOCAL_PORT);
 
950
        } else {
 
951
            published_address = g_hash_table_lookup(a->properties, PUBLISHED_ADDRESS);
 
952
            published_port = g_hash_table_lookup(a->properties, PUBLISHED_PORT);
 
953
        }
 
954
 
 
955
        stun_enable = g_hash_table_lookup(a->properties, ACCOUNT_SIP_STUN_ENABLED);
 
956
        stun_server = g_hash_table_lookup(a->properties, ACCOUNT_SIP_STUN_SERVER);
 
957
        published_sameas_local = g_hash_table_lookup(a->properties, PUBLISHED_SAMEAS_LOCAL);
 
958
    }
 
959
 
 
960
    gnome_main_section_new_with_table(_("Published address"), &frame, &table, 2, 3);
 
961
    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
 
962
    gtk_table_set_row_spacings(GTK_TABLE(table), 5);
 
963
 
 
964
    useStunCheckBox = gtk_check_button_new_with_mnemonic(_("Using STUN"));
 
965
    gtk_table_attach_defaults(GTK_TABLE(table), useStunCheckBox, 0, 1, 0, 1);
 
966
    g_signal_connect(useStunCheckBox, "toggled", G_CALLBACK(use_stun_cb), a);
 
967
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useStunCheckBox),
 
968
                                 g_strcasecmp(stun_enable, "true") == 0 ? TRUE: FALSE);
 
969
    gtk_widget_set_sensitive(useStunCheckBox,
 
970
                             g_strcasecmp(use_tls, "true") == 0 ? FALSE: TRUE);
 
971
 
 
972
    stunServerLabel = gtk_label_new_with_mnemonic(_("STUN server URL"));
 
973
    gtk_table_attach_defaults(GTK_TABLE(table), stunServerLabel, 0, 1, 1, 2);
 
974
    gtk_misc_set_alignment(GTK_MISC(stunServerLabel), 0, 0.5);
 
975
    stunServerEntry = gtk_entry_new();
 
976
    gtk_label_set_mnemonic_widget(GTK_LABEL(stunServerLabel), stunServerEntry);
 
977
    gtk_entry_set_text(GTK_ENTRY(stunServerEntry), stun_server);
 
978
    gtk_table_attach_defaults(GTK_TABLE(table), stunServerEntry, 1, 2, 1, 2);
 
979
 
 
980
    sameAsLocalRadioButton = gtk_radio_button_new_with_mnemonic_from_widget(NULL, _("Same as local parameters"));
 
981
    gtk_table_attach_defaults(GTK_TABLE(table), sameAsLocalRadioButton, 0, 2, 3, 4);
 
982
 
 
983
    publishedAddrRadioButton = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(sameAsLocalRadioButton), _("Set published address and port:"));
 
984
    gtk_table_attach_defaults(GTK_TABLE(table), publishedAddrRadioButton, 0, 2, 4, 5);
 
985
 
 
986
    if (g_strcasecmp(published_sameas_local, "true") == 0) {
 
987
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton), TRUE);
 
988
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(publishedAddrRadioButton), FALSE);
 
989
    } else {
 
990
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton), FALSE);
 
991
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(publishedAddrRadioButton), TRUE);
 
992
    }
 
993
 
 
994
    publishedAddressLabel = gtk_label_new_with_mnemonic(_("Published address"));
 
995
    gtk_table_attach_defaults(GTK_TABLE(table), publishedAddressLabel, 0, 1, 5, 6);
 
996
    gtk_misc_set_alignment(GTK_MISC(publishedAddressLabel), 0, 0.5);
 
997
    publishedAddressEntry = gtk_entry_new();
 
998
    gtk_label_set_mnemonic_widget(GTK_LABEL(publishedAddressLabel), publishedAddressEntry);
 
999
 
 
1000
    gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), published_address);
 
1001
    gtk_table_attach_defaults(GTK_TABLE(table), publishedAddressEntry, 1, 2, 5, 6);
 
1002
 
 
1003
    publishedPortLabel = gtk_label_new_with_mnemonic(_("Published port"));
 
1004
    gtk_table_attach_defaults(GTK_TABLE(table), publishedPortLabel, 0, 1, 6, 7);
 
1005
    gtk_misc_set_alignment(GTK_MISC(publishedPortLabel), 0, 0.5);
 
1006
    publishedPortSpinBox = gtk_spin_button_new_with_range(1, 65535, 1);
 
1007
    gtk_label_set_mnemonic_widget(GTK_LABEL(publishedPortLabel), publishedPortSpinBox);
 
1008
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(publishedPortSpinBox), g_ascii_strtod(published_port, NULL));
 
1009
 
 
1010
    gtk_table_attach_defaults(GTK_TABLE(table), publishedPortSpinBox, 1, 2, 6, 7);
 
1011
 
 
1012
    // This will trigger a signal, and the above two
 
1013
    // widgets need to be instanciated before that.
 
1014
    g_signal_connect(localAddressCombo, "changed", G_CALLBACK(local_interface_changed_cb), localAddressCombo);
 
1015
 
 
1016
 
 
1017
    g_signal_connect(sameAsLocalRadioButton, "toggled", G_CALLBACK(same_as_local_cb), sameAsLocalRadioButton);
 
1018
    g_signal_connect(publishedAddrRadioButton, "toggled", G_CALLBACK(set_published_addr_manually_cb), publishedAddrRadioButton);
 
1019
 
 
1020
    set_published_addr_manually_cb(publishedAddrRadioButton, NULL);
 
1021
 
 
1022
    return frame;
 
1023
}
 
1024
 
 
1025
GtkWidget* create_advanced_tab(account_t *a)
 
1026
{
 
1027
 
 
1028
    // Build the advanced tab, to appear on the account configuration panel
 
1029
    DEBUG("Config: Build advanced tab");
 
1030
 
 
1031
    GtkWidget *vbox, *frame;
 
1032
 
 
1033
    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
 
1034
 
 
1035
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
 
1036
 
 
1037
    frame = create_registration_expire(a);
 
1038
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
 
1039
 
 
1040
    frame = create_network(a);
 
1041
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
 
1042
 
 
1043
    frame = create_published_address(a);
 
1044
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
 
1045
 
 
1046
    gtk_widget_show_all(vbox);
 
1047
 
 
1048
    use_stun_cb(useStunCheckBox, NULL);
 
1049
 
 
1050
    set_published_addr_manually_cb(publishedAddrRadioButton, NULL);
 
1051
 
 
1052
    return vbox;
 
1053
}
 
1054
 
 
1055
void ringtone_enabled(GtkWidget *widget UNUSED, gpointer data, const gchar *accountID UNUSED)
 
1056
{
 
1057
    /* toggle sensitivity */
 
1058
    gtk_widget_set_sensitive(data, !gtk_widget_is_sensitive(data));
 
1059
}
 
1060
 
 
1061
 
 
1062
static GtkWidget* create_audiocodecs_configuration(account_t *currentAccount)
 
1063
{
 
1064
    GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
 
1065
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
 
1066
 
 
1067
    GtkWidget *box = audiocodecs_box(currentAccount);
 
1068
 
 
1069
    // Box for the audiocodecs
 
1070
    GtkWidget *audiocodecs = gnome_main_section_new(_("Audio"));
 
1071
    gtk_box_pack_start(GTK_BOX(vbox), audiocodecs, FALSE, FALSE, 0);
 
1072
    gtk_widget_set_size_request(audiocodecs, -1, 200);
 
1073
    gtk_widget_show(audiocodecs);
 
1074
    gtk_container_add(GTK_CONTAINER(audiocodecs), box);
 
1075
 
 
1076
    // Add DTMF type selection for SIP account only
 
1077
    gpointer p = g_hash_table_lookup(currentAccount->properties, ACCOUNT_TYPE);
 
1078
 
 
1079
    GtkWidget *table;
 
1080
 
 
1081
    if (g_strcmp0(p, "SIP") == 0) {
 
1082
        // Box for dtmf
 
1083
        GtkWidget *dtmf;
 
1084
        gnome_main_section_new_with_table(_("DTMF"), &dtmf, &table, 1, 2);
 
1085
        gtk_box_pack_start(GTK_BOX(vbox), dtmf, FALSE, FALSE, 0);
 
1086
        gtk_widget_show(dtmf);
 
1087
 
 
1088
        const gchar * const currentDtmfType = g_hash_table_lookup(currentAccount->properties, ACCOUNT_DTMF_TYPE);
 
1089
 
 
1090
        gboolean dtmf_are_rtp = TRUE;
 
1091
 
 
1092
        if (g_strcasecmp(currentDtmfType, OVERRTP) != 0)
 
1093
            dtmf_are_rtp = FALSE;
 
1094
 
 
1095
        overrtp = gtk_radio_button_new_with_label(NULL, _("RTP"));
 
1096
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(overrtp), dtmf_are_rtp);
 
1097
        gtk_table_attach(GTK_TABLE(table), overrtp, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1098
 
 
1099
        GtkWidget *sipinfo = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(overrtp),  _("SIP"));
 
1100
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sipinfo), !dtmf_are_rtp);
 
1101
        g_signal_connect(G_OBJECT(sipinfo), "clicked", G_CALLBACK(select_dtmf_type), NULL);
 
1102
        gtk_table_attach(GTK_TABLE(table), sipinfo, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1103
    }
 
1104
 
 
1105
    // Box for the ringtones
 
1106
    GtkWidget *frame;
 
1107
    gnome_main_section_new_with_table(_("Ringtones"), &frame, &table, 1, 2);
 
1108
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
 
1109
 
 
1110
    fileChooser = gtk_file_chooser_button_new(_("Choose a ringtone"), GTK_FILE_CHOOSER_ACTION_OPEN);
 
1111
 
 
1112
    p = g_hash_table_lookup(currentAccount->properties, CONFIG_RINGTONE_ENABLED);
 
1113
    gboolean ringtoneEnabled =(g_strcmp0(p, "true") == 0) ? TRUE : FALSE;
 
1114
 
 
1115
    enableTone = gtk_check_button_new_with_mnemonic(_("_Enable ringtones"));
 
1116
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enableTone), ringtoneEnabled);
 
1117
    g_signal_connect(G_OBJECT(enableTone) , "clicked" , G_CALLBACK(ringtone_enabled), fileChooser);
 
1118
    gtk_table_attach(GTK_TABLE(table), enableTone, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1119
 
 
1120
    // file chooser button
 
1121
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fileChooser) , g_get_home_dir());
 
1122
    p = g_hash_table_lookup(currentAccount->properties, CONFIG_RINGTONE_PATH);
 
1123
    gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(fileChooser) , p);
 
1124
    gtk_widget_set_sensitive(fileChooser, ringtoneEnabled);
 
1125
 
 
1126
    GtkFileFilter *filter = gtk_file_filter_new();
 
1127
    gtk_file_filter_set_name(filter, _("Audio Files"));
 
1128
    gtk_file_filter_add_pattern(filter, "*.wav");
 
1129
    gtk_file_filter_add_pattern(filter, "*.ul");
 
1130
    gtk_file_filter_add_pattern(filter, "*.au");
 
1131
 
 
1132
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser) , filter);
 
1133
    gtk_table_attach(GTK_TABLE(table), fileChooser, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1134
 
 
1135
    gtk_widget_show_all(vbox);
 
1136
 
 
1137
    return vbox;
 
1138
}
 
1139
 
 
1140
GtkWidget* create_direct_ip_calls_tab(account_t *a)
 
1141
{
 
1142
    GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
 
1143
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
 
1144
 
 
1145
    gchar *description = g_markup_printf_escaped(_("This profile is used when "
 
1146
                         "you want to reach a remote peer simply by typing a sip URI "
 
1147
                         "such as <b>sip:remotepeer</b>. The settings you define here "
 
1148
                         "will also be used if no account can be matched to an incoming"
 
1149
                         " or outgoing call."));
 
1150
    GtkWidget *label = gtk_label_new(NULL);
 
1151
    gtk_label_set_markup(GTK_LABEL(label), description);
 
1152
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
1153
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
 
1154
 
 
1155
    gtk_widget_set_size_request(label, 350, -1);
 
1156
    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
 
1157
 
 
1158
    GtkWidget *frame = create_network(a);
 
1159
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
 
1160
 
 
1161
    frame = create_security_widget(a);
 
1162
    gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
 
1163
 
 
1164
    gtk_widget_show_all(vbox);
 
1165
    return vbox;
 
1166
}
 
1167
 
 
1168
void show_account_window(account_t * currentAccount)
 
1169
{
 
1170
    // Firstly we reset
 
1171
    reset();
 
1172
 
 
1173
    if (currentAccount == NULL) {
 
1174
        DEBUG("Config: Fetching default values for new account");
 
1175
        currentAccount = g_new0(account_t, 1);
 
1176
        currentAccount->properties = dbus_get_account_details(NULL);
 
1177
        currentAccount->accountID = g_strdup("new"); //FIXME : replace with NULL for new accounts
 
1178
        currentAccount->credential_information = NULL;
 
1179
        sflphone_fill_codec_list_per_account(currentAccount);
 
1180
    }
 
1181
 
 
1182
    GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Account settings"),
 
1183
                        GTK_WINDOW(get_main_window()),
 
1184
                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
1185
                        GTK_STOCK_CANCEL,
 
1186
                        GTK_RESPONSE_CANCEL,
 
1187
                        GTK_STOCK_APPLY,
 
1188
                        GTK_RESPONSE_ACCEPT,
 
1189
                        NULL);
 
1190
 
 
1191
    gtk_container_set_border_width(GTK_CONTAINER(dialog), 0);
 
1192
 
 
1193
    GtkWidget *notebook = gtk_notebook_new();
 
1194
    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), notebook, TRUE, TRUE, 0);
 
1195
    gtk_container_set_border_width(GTK_CONTAINER(notebook), 10);
 
1196
    gtk_widget_show(notebook);
 
1197
 
 
1198
    // We do not need the global settings for the IP2IP account
 
1199
    if (g_strcasecmp(currentAccount->accountID, IP2IP) != 0) {
 
1200
        /* General Settings */
 
1201
        GtkWidget *basic_tab = create_basic_tab(currentAccount);
 
1202
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), basic_tab, gtk_label_new(_("Basic")));
 
1203
        gtk_notebook_page_num(GTK_NOTEBOOK(notebook), basic_tab);
 
1204
    }
 
1205
 
 
1206
    /* Audio Codecs */
 
1207
    GtkWidget *audiocodecs_tab = create_audiocodecs_configuration(currentAccount);
 
1208
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), audiocodecs_tab, gtk_label_new(_("Audio")));
 
1209
    gtk_notebook_page_num(GTK_NOTEBOOK(notebook), audiocodecs_tab);
 
1210
 
 
1211
    // Get current protocol for this account protocol
 
1212
    gchar *currentProtocol;
 
1213
 
 
1214
    if (protocolComboBox)
 
1215
        currentProtocol = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(protocolComboBox));
 
1216
    else
 
1217
        currentProtocol = g_strdup("SIP");
 
1218
 
 
1219
    // Do not need advanced or security one for the IP2IP account
 
1220
    if (g_strcasecmp(currentAccount->accountID, IP2IP) != 0) {
 
1221
 
 
1222
        /* Advanced */
 
1223
        advanced_tab = create_advanced_tab(currentAccount);
 
1224
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), advanced_tab, gtk_label_new(_("Advanced")));
 
1225
        gtk_notebook_page_num(GTK_NOTEBOOK(notebook), advanced_tab);
 
1226
 
 
1227
        /* Security */
 
1228
        security_tab = create_security_tab(currentAccount);
 
1229
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), security_tab, gtk_label_new(_("Security")));
 
1230
        gtk_notebook_page_num(GTK_NOTEBOOK(notebook),security_tab);
 
1231
 
 
1232
    } else {
 
1233
        /* Custom tab for the IP to IP profile */
 
1234
        GtkWidget *ip_tab = create_direct_ip_calls_tab(currentAccount);
 
1235
        gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook), ip_tab, gtk_label_new(_("Network")));
 
1236
        gtk_notebook_page_num(GTK_NOTEBOOK(notebook), ip_tab);
 
1237
    }
 
1238
 
 
1239
    // Emit signal to hide advanced and security tabs in case of IAX
 
1240
    if (protocolComboBox)
 
1241
        g_signal_emit_by_name(protocolComboBox, "changed", NULL);
 
1242
 
 
1243
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook) ,  0);
 
1244
 
 
1245
    /**************/
 
1246
    /* Run dialog */
 
1247
    /**************/
 
1248
    gint response = gtk_dialog_run(GTK_DIALOG(dialog));
 
1249
 
 
1250
    // Update protocol in case it changed
 
1251
    gchar *proto;
 
1252
 
 
1253
    if (protocolComboBox)
 
1254
        proto = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(protocolComboBox));
 
1255
    else
 
1256
        proto = g_strdup("SIP");
 
1257
 
 
1258
    // If cancel button is pressed
 
1259
    if (response == GTK_RESPONSE_CANCEL) {
 
1260
        gtk_widget_destroy(dialog);
 
1261
        g_free(proto);
 
1262
        return;
 
1263
    }
 
1264
 
 
1265
    // If accept button is
 
1266
    if (g_strcasecmp(currentAccount->accountID, IP2IP) != 0) {
 
1267
 
 
1268
        g_hash_table_replace(currentAccount->properties,
 
1269
                             g_strdup(ACCOUNT_ALIAS),
 
1270
                             g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(entryAlias))));
 
1271
        g_hash_table_replace(currentAccount->properties,
 
1272
                             g_strdup(ACCOUNT_TYPE),
 
1273
                             g_strdup(proto));
 
1274
        g_hash_table_replace(currentAccount->properties,
 
1275
                             g_strdup(ACCOUNT_HOSTNAME),
 
1276
                             g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(entryHostname))));
 
1277
        g_hash_table_replace(currentAccount->properties,
 
1278
                             g_strdup(ACCOUNT_USERNAME),
 
1279
                             g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(entryUsername))));
 
1280
        g_hash_table_replace(currentAccount->properties,
 
1281
                             g_strdup(ACCOUNT_PASSWORD),
 
1282
                             g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(entryPassword))));
 
1283
        g_hash_table_replace(currentAccount->properties,
 
1284
                             g_strdup(ACCOUNT_MAILBOX),
 
1285
                             g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(entryMailbox))));
 
1286
    }
 
1287
 
 
1288
    if (g_strcmp0(proto, "SIP") == 0) {
 
1289
        if (g_strcasecmp(currentAccount->accountID, IP2IP) != 0) {
 
1290
 
 
1291
            g_hash_table_replace(currentAccount->properties,
 
1292
                                 g_strdup(ACCOUNT_RESOLVE_ONCE),
 
1293
                                 g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(entryResolveNameOnlyOnce)) ? "false": "true"));
 
1294
 
 
1295
            g_hash_table_replace(currentAccount->properties,
 
1296
                                 g_strdup(ACCOUNT_REGISTRATION_EXPIRE),
 
1297
                                 g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(expireSpinBox))));
 
1298
 
 
1299
 
 
1300
            // TODO: uncomment this code and implement route
 
1301
            g_hash_table_replace(currentAccount->properties,
 
1302
                                 g_strdup(ACCOUNT_ROUTE),
 
1303
                                 g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryRouteSet))));
 
1304
 
 
1305
 
 
1306
            g_hash_table_replace(currentAccount->properties,
 
1307
                                 g_strdup(ACCOUNT_USERAGENT),
 
1308
                                 g_strdup(gtk_entry_get_text(GTK_ENTRY(entryUseragent))));
 
1309
 
 
1310
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED),
 
1311
                                 g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useStunCheckBox)) ? "true":"false"));
 
1312
 
 
1313
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER),
 
1314
                                 g_strdup(gtk_entry_get_text(GTK_ENTRY(stunServerEntry))));
 
1315
 
 
1316
            g_hash_table_replace(currentAccount->properties, g_strdup(PUBLISHED_SAMEAS_LOCAL), g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton)) ? "true":"false"));
 
1317
 
 
1318
            if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton))) {
 
1319
                g_hash_table_replace(currentAccount->properties,
 
1320
                                     g_strdup(PUBLISHED_PORT),
 
1321
                                     g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(publishedPortSpinBox))));
 
1322
 
 
1323
                g_hash_table_replace(currentAccount->properties,
 
1324
                                     g_strdup(PUBLISHED_ADDRESS),
 
1325
                                     g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(publishedAddressEntry))));
 
1326
            } else {
 
1327
                g_hash_table_replace(currentAccount->properties,
 
1328
                                     g_strdup(PUBLISHED_PORT),
 
1329
                                     g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));
 
1330
                gchar *local_interface = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(localAddressCombo));
 
1331
 
 
1332
                gchar *published_address = dbus_get_address_from_interface_name(local_interface);
 
1333
                g_free(local_interface);
 
1334
 
 
1335
                g_hash_table_replace(currentAccount->properties,
 
1336
                                     g_strdup(PUBLISHED_ADDRESS),
 
1337
                                     published_address);
 
1338
            }
 
1339
        }
 
1340
 
 
1341
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(overrtp))) {
 
1342
            DEBUG("Config: Set dtmf over rtp");
 
1343
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_DTMF_TYPE), g_strdup(OVERRTP));
 
1344
        } else {
 
1345
            DEBUG("Config: Set dtmf over sip");
 
1346
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_DTMF_TYPE), g_strdup(SIPINFO));
 
1347
        }
 
1348
 
 
1349
        gchar* keyExchange = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(keyExchangeCombo));
 
1350
 
 
1351
        if (g_strcasecmp(keyExchange, "ZRTP") == 0) {
 
1352
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true"));
 
1353
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(ZRTP));
 
1354
        } else if (g_strcasecmp(keyExchange, "SDES") == 0) {
 
1355
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true"));
 
1356
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(SDES));
 
1357
        } else {
 
1358
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("false"));
 
1359
            g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(""));
 
1360
        }
 
1361
 
 
1362
        g_free(keyExchange);
 
1363
 
 
1364
        g_hash_table_replace(currentAccount->properties, g_strdup(TLS_ENABLE),
 
1365
                             g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useSipTlsCheckBox)) ? "true":"false"));
 
1366
 
 
1367
        gboolean toneEnabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(enableTone));
 
1368
        g_hash_table_replace(currentAccount->properties,
 
1369
                             g_strdup(CONFIG_RINGTONE_ENABLED),
 
1370
                             g_strdup(toneEnabled ? "true" : "false"));
 
1371
 
 
1372
        g_hash_table_replace(currentAccount->properties,
 
1373
                             g_strdup(CONFIG_RINGTONE_PATH),
 
1374
                             g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fileChooser))));
 
1375
 
 
1376
        g_hash_table_replace(currentAccount->properties,
 
1377
                             g_strdup(LOCAL_INTERFACE),
 
1378
                             gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(localAddressCombo)));
 
1379
 
 
1380
        g_hash_table_replace(currentAccount->properties,
 
1381
                             g_strdup(LOCAL_PORT),
 
1382
                             g_strdup(gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));
 
1383
 
 
1384
    }
 
1385
 
 
1386
    /** @todo Verify if it's the best condition to check */
 
1387
    if (g_strcasecmp(currentAccount->accountID, "new") == 0)
 
1388
        dbus_add_account(currentAccount);
 
1389
    else
 
1390
        dbus_set_account_details(currentAccount);
 
1391
 
 
1392
    if (g_strcmp0(currentProtocol, "SIP") == 0) {
 
1393
        /* Set new credentials if any */
 
1394
        DEBUG("Config: Setting credentials");
 
1395
 
 
1396
        if (g_strcasecmp(currentAccount->accountID, IP2IP) != 0) {
 
1397
            DEBUG("Config: Get new credentials");
 
1398
            currentAccount->credential_information = getNewCredential();
 
1399
 
 
1400
            if (currentAccount->credential_information)
 
1401
                dbus_set_credentials(currentAccount);
 
1402
        }
 
1403
    }
 
1404
 
 
1405
    // propagate changes to the daemon
 
1406
    codec_list_update_to_daemon(currentAccount);
 
1407
 
 
1408
    gtk_widget_destroy(dialog);
 
1409
    g_free(currentProtocol);
 
1410
    g_free(proto);
 
1411
}
 
1412