accountconfigdialog.c 42.1 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
/*
Emmanuel Milou's avatar
Emmanuel Milou committed
2
3
 *  Copyright (C) 2007-2008 Savoir-Faire Linux inc.
 *  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
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
7
8
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
10
 *  (at your option) any later version.
11
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
12
13
14
15
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
16
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
17
18
19
20
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
Emmanuel Milou's avatar
Emmanuel Milou committed
21

22
#include <actions.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
23
24
#include <mainwindow.h>
#include <accountlist.h>
25
#include <accountconfigdialog.h>
26
#include <zrtpadvanceddialog.h>
27
#include <tlsadvanceddialog.h>
Emmanuel Milou's avatar
Emmanuel Milou committed
28

29
30
31
// From version 2.16, gtk provides the functionalities libsexy used to provide
#if GTK_CHECK_VERSION(2,16,0)
#else
Emmanuel Milou's avatar
Emmanuel Milou committed
32
#include <libsexy/sexy-icon-entry.h>
33
34
#endif

35
#include <string.h>
36
#include <dbus/dbus.h>
Emmanuel Milou's avatar
Emmanuel Milou committed
37
#include <config.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
38
39
#include <gtk/gtk.h>

40

41
42
43
44
45
46
47
/**
 * TODO: tidy this up
 * by storing these variables
 * in a private structure.
 * Local variables 
 */

48
GtkDialog * dialog;
Emmanuel Milou's avatar
Emmanuel Milou committed
49
GtkWidget * hbox;
50
51
GtkWidget * label;
GtkWidget * entryID;
Emmanuel Milou's avatar
Emmanuel Milou committed
52
GtkWidget * entryAlias;
53
GtkWidget * protocolComboBox;
54
GtkWidget * entryUsername;
Emmanuel Milou's avatar
Emmanuel Milou committed
55
GtkWidget * entryHostname;
56
GtkWidget * entryPassword;
57
GtkWidget * entryMailbox;
58
GtkWidget * entryResolveNameOnlyOnce;
59
GtkWidget * expireSpinBox;
60
61
GtkListStore * credentialStore;
GtkWidget * deleteCredButton;
62
63
GtkWidget * treeViewCredential;
GtkWidget * scrolledWindowCredential;
64
65
GtkWidget * advancedZrtpButton;
GtkWidget * keyExchangeCombo;
pierre-luc's avatar
pierre-luc committed
66
GtkWidget * useSipTlsCheckBox;
67
68
69

GtkWidget * publishedAddressEntry;
GtkWidget * localAddressCombo;
70
71
72
GtkWidget * useStunRadioButton;
GtkWidget * sameAsLocalRadioButton;
GtkWidget * publishedAddrRadioButton;
73
74
GtkWidget * publishedPortSpinBox;
GtkWidget * localPortSpinBox;
75
76
77
78
GtkWidget * publishedAddressLabel;
GtkWidget * publishedPortLabel;
GtkWidget * stunServerLabel;
GtkWidget * stunServerEntry;
79
80

GtkWidget * displayNameEntry;
81
82
83

GtkWidget * security_tab;
GtkWidget * advanced_tab;
pierre-luc's avatar
pierre-luc committed
84
            	
85
86
87
88
89
90
91
92
// Credentials
enum {
    COLUMN_CREDENTIAL_REALM,
    COLUMN_CREDENTIAL_USERNAME,
    COLUMN_CREDENTIAL_PASSWORD,
    COLUMN_CREDENTIAL_DATA,
    COLUMN_CREDENTIAL_COUNT
};
93

94
/* Signal to protocolComboBox 'changed' */
95
	void
96
change_protocol_cb (account_t * currentAccount UNUSED)
97
{
98
99
100
101
102
103
104
105
106
	gchar * protocol = gtk_combo_box_get_active_text(GTK_COMBO_BOX(protocolComboBox));
	
	if (g_strcasecmp(protocol, "IAX") == 0) {
	    gtk_widget_hide(security_tab);
	    gtk_widget_hide(advanced_tab);
	} else {
	    gtk_widget_show(security_tab);
	    gtk_widget_show(advanced_tab);
	}
107
108
}

109
	int
Emmanuel Milou's avatar
Emmanuel Milou committed
110
111
is_iax_enabled(void)
{
112
113
114
115
116
	int res = dbus_is_iax2_enabled();
	if(res == 1)
		return TRUE;
	else
		return FALSE;
Emmanuel Milou's avatar
Emmanuel Milou committed
117
}
118

119
120
121
122
123
124
125
126
static void update_credential_cb(GtkWidget *widget, gpointer data UNUSED)
{
    GtkTreeIter iter;
    gtk_tree_model_get_iter_from_string ((GtkTreeModel *) credentialStore, &iter, "0");
    gint column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "column"));
    gtk_list_store_set (GTK_LIST_STORE (credentialStore), &iter, column, (gchar *) gtk_entry_get_text(GTK_ENTRY(widget)), -1);
}

127
static GtkWidget * create_basic_tab(account_t **a) 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
128
{
129
130
131
	GtkWidget * frame;
	GtkWidget * table;
	account_t *currentAccount;
132
133
#if GTK_CHECK_VERSION(2,16,0)
#else
134
	GtkWidget *image;
135
#endif
136

137
138
	// Default settings
	gchar * curAccountID = "";
139
	gchar * curAccountEnabled = "true";
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
	gchar * curAccountType = "SIP";
	gchar * curAlias = "";
	gchar * curUsername = "";
	gchar * curHostname = "";
	gchar * curPassword = "";
	/* TODO: add curProxy, and add boxes for Proxy support */
	gchar * curMailbox = "";

	currentAccount = *a;

	// Load from SIP/IAX/Unknown ?
	if(currentAccount)
	{
		curAccountID = currentAccount->accountID;
		curAccountType = g_hash_table_lookup(currentAccount->properties, ACCOUNT_TYPE);
155
		DEBUG("CuraccountType %s", curAccountType);
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
		curAccountEnabled = g_hash_table_lookup(currentAccount->properties, ACCOUNT_ENABLED);
		curAlias = g_hash_table_lookup(currentAccount->properties, ACCOUNT_ALIAS);
		curHostname = g_hash_table_lookup(currentAccount->properties, ACCOUNT_HOSTNAME);
		curPassword = g_hash_table_lookup(currentAccount->properties, ACCOUNT_PASSWORD);
		curUsername = g_hash_table_lookup(currentAccount->properties, ACCOUNT_USERNAME);
		curMailbox = g_hash_table_lookup(currentAccount->properties, ACCOUNT_MAILBOX);
	}

	gnome_main_section_new (_("Account Parameters"), &frame);
	gtk_widget_show(frame);

	table = gtk_table_new (9, 2  ,  FALSE/* homogeneous */);
	gtk_table_set_row_spacings( GTK_TABLE(table), 10);
	gtk_table_set_col_spacings( GTK_TABLE(table), 10);
	gtk_widget_show(table);
	gtk_container_add( GTK_CONTAINER( frame) , table );
Emmanuel Milou's avatar
Emmanuel Milou committed
172

173
	label = gtk_label_new_with_mnemonic (_("_Alias"));
174
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
175
176
177
178
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
	entryAlias = gtk_entry_new();
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryAlias);
	gtk_entry_set_text(GTK_ENTRY(entryAlias), curAlias);
179
	gtk_table_attach ( GTK_TABLE( table ), entryAlias, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
180
181

	label = gtk_label_new_with_mnemonic (_("_Protocol"));
182
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
183
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
184
185
186
187
	protocolComboBox = gtk_combo_box_new_text();
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), protocolComboBox);
	gtk_combo_box_append_text(GTK_COMBO_BOX(protocolComboBox), "SIP");
	if( is_iax_enabled() ) gtk_combo_box_append_text(GTK_COMBO_BOX(protocolComboBox), "IAX");
188
189
	if(strcmp(curAccountType, "SIP") == 0)
	{
190
		gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox),0);
191
192
193
	}
	else if(strcmp(curAccountType, "IAX") == 0)
	{
194
		gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox),1);
195
196
197
198
	}
	else
	{
		/* Should never come here, add debug message. */
199
200
		gtk_combo_box_append_text(GTK_COMBO_BOX(protocolComboBox), _("Unknown"));
		gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox),2);
201
	}
202
	gtk_table_attach ( GTK_TABLE( table ), protocolComboBox, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
203
204

	/* Link signal 'changed' */
205
206
	g_signal_connect (G_OBJECT (GTK_COMBO_BOX(protocolComboBox)), "changed",
			G_CALLBACK (change_protocol_cb),
207
208
209
			currentAccount);

	label = gtk_label_new_with_mnemonic (_("_Host name"));
210
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
211
212
213
214
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
	entryHostname = gtk_entry_new();
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryHostname);
	gtk_entry_set_text(GTK_ENTRY(entryHostname), curHostname);
215
	gtk_table_attach ( GTK_TABLE( table ), entryHostname, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
216
217

	label = gtk_label_new_with_mnemonic (_("_User name"));
218
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);	
219
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
220
221
#if GTK_CHECK_VERSION(2,16,0)
	entryUsername = gtk_entry_new();
222
	gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entryUsername), GTK_ENTRY_ICON_PRIMARY, gdk_pixbuf_new_from_file(ICONS_DIR "/stock_person.svg", NULL));
223
#else
224
225
226
	entryUsername = sexy_icon_entry_new();
	image = gtk_image_new_from_file( ICONS_DIR "/stock_person.svg" );
	sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(entryUsername), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) );
227
#endif
228
229
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryUsername);
	gtk_entry_set_text(GTK_ENTRY(entryUsername), curUsername);
230
	gtk_table_attach ( GTK_TABLE( table ), entryUsername, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
231
232
    g_signal_connect(G_OBJECT (entryUsername), "changed", G_CALLBACK (update_credential_cb), NULL);
    g_object_set_data (G_OBJECT (entryUsername), "column", GINT_TO_POINTER (COLUMN_CREDENTIAL_USERNAME));
233

234
	label = gtk_label_new_with_mnemonic (_("_Password"));
235
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
236
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
237
238
#if GTK_CHECK_VERSION(2,16,0)
	entryPassword = gtk_entry_new();
239
240
    GtkSettings *settings = gtk_settings_get_default ();
    g_object_set (G_OBJECT (settings), "gtk-entry-password-hint-timeout", 600, NULL);
241
	gtk_entry_set_icon_from_stock (GTK_ENTRY (entryPassword), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_DIALOG_AUTHENTICATION);
242
#else
243
244
245
	entryPassword = sexy_icon_entry_new();
	image = gtk_image_new_from_stock( GTK_STOCK_DIALOG_AUTHENTICATION , GTK_ICON_SIZE_SMALL_TOOLBAR );
	sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(entryPassword), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) );
246
#endif
247
248
249
	gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryPassword);
	gtk_entry_set_text(GTK_ENTRY(entryPassword), curPassword);
250
	gtk_table_attach ( GTK_TABLE( table ), entryPassword, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
251
252
253
    g_signal_connect(G_OBJECT (entryPassword), "changed", G_CALLBACK (update_credential_cb), NULL);
    g_object_set_data (G_OBJECT (entryPassword), "column", GINT_TO_POINTER (COLUMN_CREDENTIAL_PASSWORD));
    
254
	label = gtk_label_new_with_mnemonic (_("_Voicemail number"));
255
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
256
257
258
259
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
	entryMailbox = gtk_entry_new();
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryMailbox);
	gtk_entry_set_text(GTK_ENTRY(entryMailbox), curMailbox);
260
	gtk_table_attach ( GTK_TABLE( table ), entryMailbox, 1, 2, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
261
262
263
264
265
266

	gtk_widget_show_all( table );
	gtk_container_set_border_width (GTK_CONTAINER(table), 10);

	*a = currentAccount;
	return frame;
267
268
}

269
270
271
272
273
274
275
static void fill_treeview_with_credential(GtkListStore * credentialStore, account_t * account) 
{
        GtkTreeIter iter;
        gtk_list_store_clear(credentialStore);
        gtk_list_store_append (credentialStore, &iter);

        /* This is the default, undeletable credential */
276
277
278
279
280
281
282
        gchar * authentication_name = g_hash_table_lookup(account->properties, ACCOUNT_AUTHENTICATION_USERNAME);
        gchar * realm = g_hash_table_lookup(account->properties, ACCOUNT_REALM);        
        if (realm == NULL || (g_strcmp0(realm, "") == 0)) {
            realm = g_strdup("*");
        }
        
        if((authentication_name == NULL) || (g_strcmp0(authentication_name, "") == 0)) {
283
            gtk_list_store_set(credentialStore, &iter,
284
                    COLUMN_CREDENTIAL_REALM, realm, 
285
286
287
288
289
290
291
292
293
294
295
296
297
                    COLUMN_CREDENTIAL_USERNAME, gtk_entry_get_text(GTK_ENTRY(entryUsername)),
                    COLUMN_CREDENTIAL_PASSWORD, gtk_entry_get_text(GTK_ENTRY(entryPassword)),    
                    COLUMN_CREDENTIAL_DATA, account, 
                    -1);
        } else {
            gtk_list_store_set(credentialStore, &iter,
                    COLUMN_CREDENTIAL_REALM, g_hash_table_lookup(account->properties, ACCOUNT_REALM), 
                    COLUMN_CREDENTIAL_USERNAME, g_hash_table_lookup(account->properties, ACCOUNT_AUTHENTICATION_USERNAME),
                    COLUMN_CREDENTIAL_PASSWORD, gtk_entry_get_text(GTK_ENTRY(entryPassword)),    
                    COLUMN_CREDENTIAL_DATA, account, 
                    -1);
            g_signal_handlers_disconnect_by_func (G_OBJECT(entryUsername), G_CALLBACK(update_credential_cb), NULL);
        }
298
299
300
301
302
303
304
305
306
        
        if(account->credential_information == NULL) {
            DEBUG("No credential defined");
            return;
        }
        
        unsigned int i;
        for(i = 0; i < account->credential_information->len; i++)
        {	                    
307
            GHashTable * element = g_ptr_array_index(account->credential_information, i);               
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
            gtk_list_store_append (credentialStore, &iter);
            gtk_list_store_set(credentialStore, &iter,
                    COLUMN_CREDENTIAL_REALM, g_hash_table_lookup(element, ACCOUNT_REALM), 
                    COLUMN_CREDENTIAL_USERNAME, g_hash_table_lookup(element, ACCOUNT_USERNAME), 
                    COLUMN_CREDENTIAL_PASSWORD, g_hash_table_lookup(element, ACCOUNT_PASSWORD), 
                    COLUMN_CREDENTIAL_DATA, element, // Pointer
                    -1);
        }
}

static select_credential_cb(GtkTreeSelection *selection, GtkTreeModel *model)
{
    GtkTreeIter iter;
    GtkTreePath *path;
    if(gtk_tree_selection_get_selected (selection, NULL, &iter)) {
        path = gtk_tree_model_get_path (model, &iter);
        if(gtk_tree_path_get_indices (path)[0] == 0) {
            gtk_widget_set_sensitive(GTK_WIDGET(deleteCredButton), FALSE);
        } else {
            gtk_widget_set_sensitive(GTK_WIDGET(deleteCredButton), TRUE);
        }
    }
}

static void add_credential_cb (GtkWidget *button, gpointer data)
{
    GtkTreeIter iter;
    GtkTreeModel *model = (GtkTreeModel *)data;
336
           
337
338
339
340
341
342
343
344
345
346
347
348
349
350
    gtk_list_store_append (GTK_LIST_STORE (model), &iter);
    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                        COLUMN_CREDENTIAL_REALM, "*",
                        COLUMN_CREDENTIAL_USERNAME, _("Authentication"),
                        COLUMN_CREDENTIAL_PASSWORD, _("Secret"),
                        -1);
}

static void delete_credential_cb(GtkWidget *button, gpointer data)
{
    GtkTreeIter iter;
    GtkTreeView *treeview = (GtkTreeView *)data;
    GtkTreeModel *model = gtk_tree_view_get_model (treeview);
    GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
351
          
352
353
354
355
356
357
358
359
    if (gtk_tree_selection_get_selected (selection, NULL, &iter))
    {
        GtkTreePath *path;
        path = gtk_tree_model_get_path (model, &iter);
        gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
        
        gtk_tree_path_free (path);
    }
360

361
362
363
364
365
366
367
}

static void cell_edited_cb(GtkCellRendererText *renderer, gchar *path_desc, gchar *text, gpointer data)
{
    GtkTreeModel *model = (GtkTreeModel *)data;
    GtkTreePath *path = gtk_tree_path_new_from_string (path_desc);
    GtkTreeIter iter;
368
     
369
    gint column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (renderer), "column"));
370
371
372
373
    
    if(g_strcasecmp(path_desc, "0") == 0) {
        if(g_strcasecmp(text, gtk_entry_get_text(GTK_ENTRY(entryUsername))) != 0) {
            g_signal_handlers_disconnect_by_func (G_OBJECT(entryUsername), G_CALLBACK(update_credential_cb), NULL);
374
        }
375
    }  
376
    
377
378
    gtk_tree_model_get_iter (model, &iter, path);
    gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, text, -1);
379
380
    gtk_tree_path_free (path);

381
382
383
384
385
386
387
388
}

static void editing_started_cb (GtkCellRenderer *cell, GtkCellEditable * editable, const gchar * path, gpointer data)
{
    DEBUG("Editing started");
    gtk_entry_set_visibility(GTK_ENTRY(editable), FALSE);
}

389
390
391
392
393
394
static void show_advanced_zrtp_options_cb(GtkWidget *widget UNUSED, gpointer data)
{
    DEBUG("Advanced options for ZRTP");
    show_advanced_zrtp_options((GHashTable *) data);
}

395
396
397
398
399
400
static void show_advanced_tls_options_cb(GtkWidget *widget UNUSED, gpointer data)
{
    DEBUG("Advanced options for TLS");
    show_advanced_tls_options((GHashTable *) data);
}

401
402
403
404
405
406
407
408
409
410
411
static void key_exchange_changed_cb(GtkWidget *widget, gpointer data)
{
    DEBUG("Key exchange changed");
    if (g_strcasecmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo)), (gchar *) "ZRTP") == 0) {
        gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), TRUE);
    } else {
        gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), FALSE);
        
    }
}

412
413
414
415
416
417
418
static void use_sip_tls_cb(GtkWidget *widget, gpointer data)
{
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
        DEBUG("Using sips");
    	gtk_widget_set_sensitive(GTK_WIDGET(data), TRUE);            
    } else {
        gtk_widget_set_sensitive(GTK_WIDGET(data), FALSE);    
419
    }   
420
421
}

422
GtkWidget * create_security_tab(account_t **a)
423
{
424
425
	GtkWidget * frame;
	GtkWidget * table;
426
	GtkWidget * label;
427
428
429
430
431
432
433
434
435
436
437
	GtkWidget * ret;
	GtkWidget * hbox;
	GtkWidget * editButton;
    GtkWidget * addButton;
	GtkCellRenderer * renderer;
    GtkTreeViewColumn * treeViewColumn;
    GtkTreeSelection * treeSelection;
	
	ret = gtk_vbox_new(FALSE, 10);
    gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
    
438
	account_t * currentAccount;
439
	currentAccount = *a;
440
441
442
	
    gchar * curSRTPEnabled = NULL;
    gchar * curKeyExchange = NULL;
pierre-luc's avatar
pierre-luc committed
443
444
    gchar * curTLSEnabled = NULL;
    
445
	// Load from SIP/IAX/Unknown ?
446
	if(currentAccount) {	
447
448
449
450
451
452
453
        curKeyExchange = g_hash_table_lookup(currentAccount->properties, ACCOUNT_KEY_EXCHANGE);
		if (curKeyExchange == NULL) {
		    curKeyExchange = "none";
		}		
		      		  
        curSRTPEnabled = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SRTP_ENABLED);
        if (curSRTPEnabled == NULL) {
pierre-luc's avatar
pierre-luc committed
454
            curSRTPEnabled = "false";
455
        }
pierre-luc's avatar
pierre-luc committed
456
457
458
459
        
        curTLSEnabled = g_hash_table_lookup(currentAccount->properties, TLS_ENABLE);
        if (curTLSEnabled == NULL) {
            curTLSEnabled = "false";
460
461
462
        } 
        
        DEBUG("TLS is enabled to %s", curTLSEnabled);       
463
	} 
464
  	
465
    /* Credentials tree view */
466
    gnome_main_section_new_with_table (_("Credential"), &frame, &table, 1, 1);
467
	gtk_container_set_border_width (GTK_CONTAINER(table), 10);
468
	gtk_table_set_row_spacings(GTK_TABLE(table), 10);
469
470
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
	
471
472
473
    scrolledWindowCredential = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindowCredential), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledWindowCredential), GTK_SHADOW_IN);
474
    gtk_table_attach_defaults (GTK_TABLE(table), scrolledWindowCredential, 0, 1, 0, 1);
475
476
477
478
479
    
    credentialStore = gtk_list_store_new(COLUMN_CREDENTIAL_COUNT,
            G_TYPE_STRING,  // Realm
            G_TYPE_STRING,  // Username
            G_TYPE_STRING,  // Password
480
            G_TYPE_POINTER  // Pointer to the Objectc
481
482
            );
            
483
484
    treeViewCredential = gtk_tree_view_new_with_model(GTK_TREE_MODEL(credentialStore));
    treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW (treeViewCredential));
485
486
487
488
489
490
491
492
493
494
    g_signal_connect(G_OBJECT (treeSelection), "changed", G_CALLBACK (select_credential_cb), credentialStore);
    
    renderer = gtk_cell_renderer_text_new();
    g_object_set (renderer, "editable", TRUE, "editable-set", TRUE, NULL);
    g_signal_connect(G_OBJECT (renderer), "edited", G_CALLBACK(cell_edited_cb), credentialStore);
    g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_CREDENTIAL_REALM));
    treeViewColumn = gtk_tree_view_column_new_with_attributes ("Realm",
            renderer,
            "markup", COLUMN_CREDENTIAL_REALM,
            NULL);
495
    gtk_tree_view_append_column (GTK_TREE_VIEW(treeViewCredential), treeViewColumn);
496
497
498
499
500
501
502
503
504

    renderer = gtk_cell_renderer_text_new();
    g_object_set (renderer, "editable", TRUE, "editable-set", TRUE, NULL);
    g_signal_connect(G_OBJECT (renderer), "edited", G_CALLBACK(cell_edited_cb), credentialStore);
    g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_CREDENTIAL_USERNAME));
    treeViewColumn = gtk_tree_view_column_new_with_attributes (_("Authentication name"),
            renderer,
            "markup", COLUMN_CREDENTIAL_USERNAME,
            NULL);
505
    gtk_tree_view_append_column (GTK_TREE_VIEW(treeViewCredential), treeViewColumn);
506
507
508
509
510
511
512
513
514
515

    renderer = gtk_cell_renderer_text_new();
    g_object_set (renderer, "editable", TRUE, "editable-set", TRUE, NULL);
    g_signal_connect(G_OBJECT (renderer), "edited", G_CALLBACK(cell_edited_cb), credentialStore);
    g_signal_connect (renderer, "editing-started", G_CALLBACK (editing_started_cb), NULL);
    g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_CREDENTIAL_PASSWORD));
    treeViewColumn = gtk_tree_view_column_new_with_attributes (_("Password"),
            renderer,
            "markup", COLUMN_CREDENTIAL_PASSWORD,
            NULL);
516
    gtk_tree_view_append_column (GTK_TREE_VIEW(treeViewCredential), treeViewColumn);
517
    
518
    gtk_container_add(GTK_CONTAINER(scrolledWindowCredential), treeViewCredential);
519
520
    
    fill_treeview_with_credential(credentialStore, *a);
521
            
522
523
    /* Credential Buttons */    
    hbox = gtk_hbox_new(FALSE, 10);
524
    gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 2, 1, 2);
525
526
527
528
529
530
    
    addButton = gtk_button_new_from_stock (GTK_STOCK_ADD);
    g_signal_connect (addButton, "clicked", G_CALLBACK (add_credential_cb), credentialStore);
    gtk_box_pack_start(GTK_BOX(hbox), addButton, FALSE, FALSE, 0);
        
    deleteCredButton = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
531
    g_signal_connect (deleteCredButton, "clicked", G_CALLBACK (delete_credential_cb), treeViewCredential);
532
    gtk_box_pack_start(GTK_BOX(hbox), deleteCredButton, FALSE, FALSE, 0);
533
534
 
 	 /* SRTP Section */
535
    gnome_main_section_new_with_table (_("Security"), &frame, &table, 2, 3);
536
537
	gtk_container_set_border_width (GTK_CONTAINER(table), 10);
	gtk_table_set_row_spacings (GTK_TABLE(table), 10);
538
    gtk_table_set_col_spacings( GTK_TABLE(table), 10);
539
540
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);

541
542
543
	GtkWidget * sipTlsAdvancedButton;
	sipTlsAdvancedButton = gtk_button_new_from_stock(GTK_STOCK_EDIT);
    gtk_table_attach_defaults(GTK_TABLE(table), sipTlsAdvancedButton, 2, 3, 0, 1);
544
	gtk_widget_set_sensitive(GTK_WIDGET(sipTlsAdvancedButton), FALSE);    
545
    g_signal_connect(G_OBJECT(sipTlsAdvancedButton), "clicked", G_CALLBACK(show_advanced_tls_options_cb), currentAccount->properties);
546
547
548
    
	useSipTlsCheckBox = gtk_check_button_new_with_mnemonic(_("Use TLS transport (sips)"));
	g_signal_connect (useSipTlsCheckBox, "toggled", G_CALLBACK(use_sip_tls_cb), sipTlsAdvancedButton);
549
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useSipTlsCheckBox), (g_strcmp0(curTLSEnabled, "true") == 0) ? TRUE:FALSE);
550
	gtk_table_attach_defaults(GTK_TABLE(table), useSipTlsCheckBox, 0, 2, 0, 1);
551
       	    
552
    label = gtk_label_new_with_mnemonic (_("SRTP key exchange"));
553
 	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
554
555
556
557
558
559
    keyExchangeCombo = gtk_combo_box_new_text();
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), keyExchangeCombo);
    gtk_combo_box_append_text(GTK_COMBO_BOX(keyExchangeCombo), "ZRTP");
    //gtk_combo_box_append_text(GTK_COMBO_BOX(keyExchangeCombo), "SDES");
    gtk_combo_box_append_text(GTK_COMBO_BOX(keyExchangeCombo), _("Disabled"));      
    
560
    advancedZrtpButton = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
561
    g_signal_connect(G_OBJECT(advancedZrtpButton), "clicked", G_CALLBACK(show_advanced_zrtp_options_cb), currentAccount->properties);
562
        
563
    if (g_strcmp0(curSRTPEnabled, "false") == 0)
564
565
566
567
    {
        gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo), 1);
        gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), FALSE);
    } else {
568
        if (strcmp(curKeyExchange, ZRTP) == 0) {
569
570
571
572
573
574
575
576
577
            gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo),0);
        } else {
            gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo), 1);
            gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), FALSE);
        }
    }
    
	g_signal_connect (G_OBJECT (GTK_COMBO_BOX(keyExchangeCombo)), "changed", G_CALLBACK (key_exchange_changed_cb), currentAccount);
    
578
579
580
    gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
    gtk_table_attach_defaults(GTK_TABLE(table), keyExchangeCombo, 1, 2, 1, 2);    
    gtk_table_attach_defaults(GTK_TABLE(table), advancedZrtpButton, 2, 3, 1, 2);
581
582
583
584
585
586
587
588

    gtk_widget_show_all(table);
    
    /* Dynamically resize the window to fit the scrolled window */
    GtkRequisition requisitionTable;
    GtkRequisition requisitionTreeView;
    gtk_widget_size_request(GTK_WIDGET(treeViewCredential), &requisitionTreeView);
    gtk_widget_size_request(GTK_WIDGET(table), &requisitionTable);
589
    gtk_widget_set_size_request(GTK_WIDGET(scrolledWindowCredential), requisitionTable.width, 120);
590
    	
591
    gtk_widget_show_all(ret);
592
    
593
	return ret;
594
595
}

596
597
598
599
600
601
602
603
604
605
606
607
608
static use_stun_cb(GtkWidget * widget, gpointer data UNUSED)
{
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
        DEBUG("Showing stun options");
        gtk_widget_show(stunServerLabel);
        gtk_widget_show(stunServerEntry);
    } else {
        gtk_widget_hide(stunServerLabel);
        gtk_widget_hide(stunServerEntry);
    }
 
}

609
610
611
612
static same_as_local_cb(GtkWidget * widget, gpointer data UNUSED)
{
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
        DEBUG("Same as local");
613
		gchar * ip_address = (gchar *) gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo));
614
615
	    gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), ip_address);
	    
616
        gchar * local_port = (gchar *) gtk_entry_get_text(GTK_ENTRY(localPortSpinBox));
617
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(publishedPortSpinBox), g_ascii_strtod(local_port, NULL));
618
619
620
621
622
623
624
625
626
627
628
    } 
}

static set_published_addr_manually_cb(GtkWidget * widget, gpointer data UNUSED)
{
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
        DEBUG("Showing manual options");    
    	gtk_widget_show(publishedPortLabel);            
    	gtk_widget_show(publishedPortSpinBox);
    	gtk_widget_show(publishedAddressLabel);                	
    	gtk_widget_show(publishedAddressEntry);
629
    } else {
630
631
632
633
    	gtk_widget_hide(publishedPortLabel);            
    	gtk_widget_hide(publishedPortSpinBox);
    	gtk_widget_hide(publishedAddressLabel);                	
    	gtk_widget_hide(publishedAddressEntry);
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
    }
}

GtkWidget * create_advanced_tab(account_t **a)
{
	GtkWidget * frame;
	GtkWidget * table;
	GtkWidget * label;
	GtkWidget * ret;
	GtkWidget * hbox;
	
	ret = gtk_vbox_new(FALSE, 10);
    gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
    
	account_t * currentAccount;
	currentAccount = *a;

    gchar * resolve_once = NULL;
    gchar * account_expire = NULL;
653
    gchar * use_tls;
654
655
656
657
    gchar * published_address;
    gchar * published_port;
    gchar * local_address;
    gchar * local_port;
658
659
    gchar * stun_enable;    
    gchar * stun_server;    
660
661
662
663
664
        
	// Load from SIP/IAX/Unknown ?
	if(currentAccount) {
		resolve_once = g_hash_table_lookup(currentAccount->properties, ACCOUNT_RESOLVE_ONCE);
		account_expire = g_hash_table_lookup(currentAccount->properties, ACCOUNT_REGISTRATION_EXPIRE);
665
		use_tls = g_hash_table_lookup(currentAccount->properties,  TLS_ENABLE);
666
667
668
	    local_port = g_hash_table_lookup(currentAccount->properties, LOCAL_PORT);
		local_address = g_hash_table_lookup(currentAccount->properties,  LOCAL_ADDRESS);
		published_address = g_hash_table_lookup(currentAccount->properties,  PUBLISHED_ADDRESS);
669
670
671
		published_port = g_hash_table_lookup(currentAccount->properties,  PUBLISHED_PORT);
		stun_enable = g_hash_table_lookup(currentAccount->properties,  ACCOUNT_SIP_STUN_ENABLED);
		stun_server = g_hash_table_lookup(currentAccount->properties,  ACCOUNT_SIP_STUN_SERVER);				
672
673
674
675
676
	} 

    gnome_main_section_new_with_table (_("Registration"), &frame, &table, 2, 3);
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER(table), 10);
677
	gtk_table_set_row_spacings( GTK_TABLE(table), 5);	
678

679
	label = gtk_label_new_with_mnemonic (_("Registration expire"));
680
681
682
683
684
685
	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
    expireSpinBox = gtk_spin_button_new_with_range(1, 65535, 1);
	gtk_label_set_mnemonic_widget(GTK_LABEL(label), expireSpinBox);
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(expireSpinBox), g_ascii_strtod(account_expire, NULL));
	gtk_table_attach_defaults(GTK_TABLE(table), expireSpinBox, 1, 2, 0, 1);
686
687
688
689
690
691
692
693
694
695

	entryResolveNameOnlyOnce = gtk_check_button_new_with_mnemonic(_("_Comply with RFC 3263"));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(entryResolveNameOnlyOnce),
			g_strcasecmp(resolve_once,"false") == 0 ? TRUE: FALSE);
	gtk_table_attach_defaults( GTK_TABLE( table ), entryResolveNameOnlyOnce, 0, 2, 1, 2);
	gtk_widget_set_sensitive( GTK_WIDGET( entryResolveNameOnlyOnce ) , TRUE );
	
    gnome_main_section_new_with_table (_("Network"), &frame, &table, 2, 3);
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER(table), 10);
696
697
	gtk_table_set_row_spacings( GTK_TABLE(table), 5);
		
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
    /**
     * Retreive the list of IP interface from the 
     * the daemon and build the combo box.
     */
   
    GtkListStore * ipInterfaceListStore; 
    GtkTreeIter iter;
    
    ipInterfaceListStore =  gtk_list_store_new( 1, G_TYPE_STRING );
	label = gtk_label_new_with_mnemonic (_("Local address"));    
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
			
    GtkTreeIter current_local_address_iter = iter;   
    gchar ** iface_list = NULL;
713
    iface_list = (gchar **)dbus_get_all_ip_interface();
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
    gchar ** iface = NULL;
    
    if (iface_list != NULL) {
        for (iface = iface_list; *iface; iface++) {         
            DEBUG("Interface %s", *iface);            
            gtk_list_store_append(ipInterfaceListStore, &iter );
            gtk_list_store_set(ipInterfaceListStore, &iter, 0, *iface, -1 );
            
            current_local_address_iter = iter;
            if (g_strcmp0(*iface, local_address) == 0) {
                DEBUG("Setting active local address combo box");
                current_local_address_iter = iter;
            }
        }
    }
    
    localAddressCombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ipInterfaceListStore));
	gtk_label_set_mnemonic_widget(GTK_LABEL(label), localAddressCombo);
	gtk_table_attach ( GTK_TABLE( table ), localAddressCombo, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
    g_object_unref(G_OBJECT(ipInterfaceListStore));	
    
    GtkCellRenderer * ipInterfaceCellRenderer;
    ipInterfaceCellRenderer = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(localAddressCombo), ipInterfaceCellRenderer, TRUE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(localAddressCombo), ipInterfaceCellRenderer, "text", 0, NULL);
    gtk_combo_box_set_active_iter(GTK_COMBO_BOX(localAddressCombo), &current_local_address_iter);

    /**
     * Local port
     */	    
	label = gtk_label_new_with_mnemonic (_("Local port"));
	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
    localPortSpinBox = gtk_spin_button_new_with_range(1, 65535, 1);
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), localPortSpinBox);
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(localPortSpinBox), g_ascii_strtod(local_port, NULL));
	gtk_table_attach_defaults(GTK_TABLE(table), localPortSpinBox, 1, 2, 1, 2);

752
753
	label = gtk_label_new_with_mnemonic (_("Set published address and port:"));
	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 2, 3);
754
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
755
756
757
758

	useStunRadioButton = gtk_radio_button_new_with_mnemonic(NULL,_("Using STUN "));
	gtk_table_attach_defaults(GTK_TABLE(table), useStunRadioButton, 0, 2, 3, 4);
	gtk_widget_set_sensitive(GTK_TOGGLE_BUTTON(useStunRadioButton),
759
			g_strcasecmp(use_tls,"true") == 0 ? FALSE: TRUE);
760
761
762
763
764
765
766
767
768
769
770
771
	
	sameAsLocalRadioButton = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(useStunRadioButton), _("Same as local parameters"));
	gtk_table_attach_defaults(GTK_TABLE(table), sameAsLocalRadioButton, 0, 2, 4, 5);

	publishedAddrRadioButton = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(useStunRadioButton), _("Manually"));
	gtk_table_attach_defaults(GTK_TABLE(table), publishedAddrRadioButton, 0, 2, 5, 6);

    gtk_widget_show_all(ret);
    		
	publishedAddressLabel = gtk_label_new_with_mnemonic (_("Published address"));
	gtk_table_attach_defaults( GTK_TABLE(table), publishedAddressLabel, 0, 1, 6, 7);
	gtk_misc_set_alignment(GTK_MISC (publishedAddressLabel), 0, 0.5);
772
	publishedAddressEntry = gtk_entry_new();
773
	gtk_label_set_mnemonic_widget (GTK_LABEL (publishedAddressLabel), publishedAddressEntry);
774
	gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), published_address);
775
	gtk_table_attach_defaults( GTK_TABLE(table), publishedAddressEntry, 1, 2, 6, 7);
776
		
777
778
779
	publishedPortLabel = gtk_label_new_with_mnemonic(_("Published port"));
	gtk_table_attach_defaults(GTK_TABLE(table), publishedPortLabel, 0, 1, 7, 8);
	gtk_misc_set_alignment(GTK_MISC(publishedPortLabel), 0, 0.5);
780
    publishedPortSpinBox = gtk_spin_button_new_with_range(1, 65535, 1);
781
	gtk_label_set_mnemonic_widget(GTK_LABEL (publishedPortLabel), publishedPortSpinBox);
782
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(publishedPortSpinBox), g_ascii_strtod(published_port, NULL));
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
	gtk_table_attach_defaults(GTK_TABLE(table), publishedPortSpinBox, 1, 2, 7, 8);

	stunServerLabel = gtk_label_new_with_mnemonic (_("STUN server URL"));
	gtk_table_attach_defaults(GTK_TABLE(table), stunServerLabel, 0, 1, 8, 9);
	gtk_misc_set_alignment(GTK_MISC(stunServerLabel), 0, 0.5);
	stunServerEntry = gtk_entry_new();
	gtk_label_set_mnemonic_widget(GTK_LABEL(stunServerLabel), stunServerEntry);
	gtk_entry_set_text(GTK_ENTRY(stunServerEntry), stun_server);
	gtk_table_attach_defaults(GTK_TABLE(table), stunServerEntry, 1, 2, 8, 9);
	 
    // This will trigger a signal, and the above two
    // widgets need to be instanciated before that.
	g_signal_connect(useStunRadioButton, "toggled", G_CALLBACK(use_stun_cb), useStunRadioButton);		    		
	g_signal_connect(sameAsLocalRadioButton, "toggled", G_CALLBACK(same_as_local_cb), sameAsLocalRadioButton);   
	g_signal_connect(publishedAddrRadioButton, "toggled", G_CALLBACK(set_published_addr_manually_cb), publishedAddrRadioButton);		
	
    if (g_strcasecmp(stun_enable,"true") == 0)	{
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useStunRadioButton), TRUE);
    } else if ((g_strcasecmp(published_address, local_address) == 0) 
            && (g_strcasecmp(published_port, local_port) == 0)) {
        	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton), TRUE);	    
    } else {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(publishedAddrRadioButton), TRUE);
    }
	
808
809
810
	return ret;
}

811
static GPtrArray * getNewCredential(GHashTable * properties)
812
{
813
814
815
816
817
818
819
820
    GtkTreeIter iter;
    gboolean valid;
    gint row_count = 0;

    valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(credentialStore), &iter);

    GPtrArray * credential_array = g_ptr_array_new ();
        
821
822
823
    gchar *username;
    gchar *realm;
    gchar *password;
824
825
    GHashTable * new_table;   
     
826
827
828
829
830
831
    gtk_tree_model_get (GTK_TREE_MODEL(credentialStore), &iter,
                        COLUMN_CREDENTIAL_REALM, &realm,
                        COLUMN_CREDENTIAL_USERNAME, &username,
                        COLUMN_CREDENTIAL_PASSWORD, &password,
                        -1);

832
833
834
    g_hash_table_insert(properties, g_strdup(ACCOUNT_REALM), realm);
    g_hash_table_insert(properties, g_strdup(ACCOUNT_AUTHENTICATION_USERNAME), username);
    g_hash_table_insert(properties, g_strdup(ACCOUNT_PASSWORD), password);
835
  
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
    valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(credentialStore), &iter);
                                     
    while (valid) {        
        gtk_tree_model_get (GTK_TREE_MODEL(credentialStore), &iter,
                            COLUMN_CREDENTIAL_REALM, &realm,
                            COLUMN_CREDENTIAL_USERNAME, &username,
                            COLUMN_CREDENTIAL_PASSWORD, &password,
                            -1);

        DEBUG ("Row %d: %s %s %s", row_count, username, password, realm);

        new_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_REALM), realm);
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_USERNAME), username);
        g_hash_table_insert(new_table, g_strdup(ACCOUNT_PASSWORD), password);

        g_ptr_array_add (credential_array, new_table);

        row_count ++;

        valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(credentialStore), &iter);
    }

    return credential_array;
860
861
}

862
	void
863
864
865
show_account_window (account_t * a)
{

866
867
868
869
870
871
	GtkWidget * notebook;
	GtkWidget * tab; 
	gint response;
	account_t *currentAccount;

	currentAccount = a;   
872
873
874
875
876
877
878
879
	
    if (currentAccount == NULL) {
		currentAccount = g_new0(account_t, 1);
		currentAccount->properties = dbus_account_details(NULL);
		currentAccount->accountID = "new";    
        DEBUG("Account is NULL. Will fetch default values\n");      
    }
    
880
881
882
	dialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Account settings"),
				GTK_WINDOW(get_main_window()),
				GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
883
	    		GTK_STOCK_CANCEL,
884
				GTK_RESPONSE_CANCEL,
885
886
				GTK_STOCK_APPLY,				
				GTK_RESPONSE_ACCEPT,
887
888
				NULL));

889
	gtk_dialog_set_has_separator(dialog, FALSE);
890
891
892
893
894
895
896
897
	gtk_container_set_border_width (GTK_CONTAINER(dialog), 0);

	notebook = gtk_notebook_new();
	gtk_box_pack_start(GTK_BOX (dialog->vbox), notebook, TRUE, TRUE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(notebook), 10);
	gtk_widget_show(notebook);

	/* General Settings */
898
	tab = create_basic_tab(&currentAccount);
899
900
	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Basic")));
	gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
901

902
	/* Advanced */
903
904
905
	advanced_tab = create_advanced_tab(&currentAccount);
	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), advanced_tab, gtk_label_new(_("Advanced")));
	gtk_notebook_page_num(GTK_NOTEBOOK(notebook), advanced_tab);
906
907
		
    /* Security */
908
909
910
    security_tab = create_security_tab(&currentAccount);
	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), security_tab, gtk_label_new(_("Security")));
	gtk_notebook_page_num(GTK_NOTEBOOK(notebook),security_tab);
911
		    	
912
913
	gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook) ,  0);

914
915
    g_signal_emit_by_name(protocolComboBox, "changed", NULL);
    
916
917
918
919
	response = gtk_dialog_run (GTK_DIALOG (dialog));

	if(response == GTK_RESPONSE_ACCEPT)
	{
920
		gchar* proto = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(protocolComboBox));
921
922
923

		g_hash_table_replace(currentAccount->properties,
				g_strdup(ACCOUNT_RESOLVE_ONCE),
924
				g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(entryResolveNameOnlyOnce)) ? "false": "true"));
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
		g_hash_table_replace(currentAccount->properties,
				g_strdup(ACCOUNT_ALIAS),
				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryAlias))));
		g_hash_table_replace(currentAccount->properties,
				g_strdup(ACCOUNT_TYPE),
				g_strdup(proto));
		g_hash_table_replace(currentAccount->properties,
				g_strdup(ACCOUNT_HOSTNAME),
				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryHostname))));
		g_hash_table_replace(currentAccount->properties,
				g_strdup(ACCOUNT_USERNAME),
				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryUsername))));
		g_hash_table_replace(currentAccount->properties,
				g_strdup(ACCOUNT_PASSWORD),
				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryPassword))));
		g_hash_table_replace(currentAccount->properties,
				g_strdup(ACCOUNT_MAILBOX),
				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryMailbox))));
		g_hash_table_replace(currentAccount->properties,
				g_strdup(ACCOUNT_REGISTRATION_EXPIRE),
945
				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(expireSpinBox))));				
946
        
947
		if (strcmp(proto, "SIP") == 0) {
948
			
949
950
951
952
953
954
			g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED), 
					            g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useStunRadioButton)) ? "true":"false"));

			g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER), 
					            g_strdup(gtk_entry_get_text(GTK_ENTRY(stunServerEntry))));

955
			gchar* keyExchange = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo));
pierre-luc's avatar
pierre-luc committed
956
            if (g_strcasecmp(keyExchange, "ZRTP") == 0) {
957
958
                g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true"));
                g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(ZRTP));
959
            } else {
960
                g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("false"));
961
962
            }
    		
pierre-luc's avatar
pierre-luc committed
963
964
965
    		g_hash_table_replace(currentAccount->properties, g_strdup(TLS_ENABLE), 
    		g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useSipTlsCheckBox)) ? "true":"false"));

966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
    		g_hash_table_replace(currentAccount->properties,
    				g_strdup(LOCAL_PORT),
    				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));	

    		g_hash_table_replace(currentAccount->properties,
    				g_strdup(LOCAL_ADDRESS),
			        g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo))));

    		g_hash_table_replace(currentAccount->properties,
    				g_strdup(PUBLISHED_PORT),
    				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(publishedPortSpinBox))));	

    		g_hash_table_replace(currentAccount->properties,
    				g_strdup(PUBLISHED_ADDRESS),
    				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(publishedAddressEntry))));	    
981
982
		}

983
	    /* Set new credentials if any */
984
985
986
987
988
989
990
991
992
993
	    
        DEBUG("Setting credentials"); 

        /* This hack is necessary because of the way the 
        * configuration file is made (.ini at that time).
        * and deleting account per account is too much 
        * of a trouble. 
        */
        dbus_delete_all_credential(currentAccount);
        
994
        GPtrArray * credential = getNewCredential(currentAccount->properties);         
995
996
        currentAccount->credential_information = credential;
        if(currentAccount->credential_information != NULL) {
997
998
999
1000
            int i;
            for(i = 0; i < currentAccount->credential_information->len; i++) {
                dbus_set_credential(currentAccount, i);
            }
1001
            dbus_set_number_of_credential(currentAccount, currentAccount->credential_information->len);
1002
        }
1003
1004
        
		/** @todo Verify if it's the best condition to check */
1005
		if (g_strcasecmp(currentAccount->accountID, "new") == 0) {
1006
1007
1008
1009
1010
1011
1012
			dbus_add_account(currentAccount);
		}
		else {
			dbus_set_account_details(currentAccount);
		}
		

1013
1014
	} 
	
1015
	gtk_widget_destroy (GTK_WIDGET(dialog));
Emmanuel Milou's avatar
Emmanuel Milou committed
1016

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1017
}