accountconfigdialog.c 55 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 <audioconf.h>
26
#include <accountconfigdialog.h>
27
#include <zrtpadvanceddialog.h>
28
#include <tlsadvanceddialog.h>
Emmanuel Milou's avatar
Emmanuel Milou committed
29

30
31
32
// 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
33
#include <libsexy/sexy-icon-entry.h>
34
35
#endif

36
37
#define PW_HIDDEN		"*****"

38
#include <string.h>
39
#include <dbus/dbus.h>
Emmanuel Milou's avatar
Emmanuel Milou committed
40
#include <config.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
41
42
#include <gtk/gtk.h>

43

44
45
46
47
48
49
/**
 * TODO: tidy this up
 * by storing these variables
 * in a private structure.
 * Local variables 
 */
50
GtkDialog * dialog;
Emmanuel Milou's avatar
Emmanuel Milou committed
51
GtkWidget * hbox;
52
53
GtkWidget * label;
GtkWidget * entryID;
Emmanuel Milou's avatar
Emmanuel Milou committed
54
GtkWidget * entryAlias;
55
GtkWidget * protocolComboBox;
56
GtkWidget * entryUsername;
Emmanuel Milou's avatar
Emmanuel Milou committed
57
GtkWidget * entryHostname;
58
GtkWidget * entryPassword;
59
GtkWidget * entryMailbox;
60
GtkWidget * entryUseragent;
61
GtkWidget * entryResolveNameOnlyOnce;
62
GtkWidget * expireSpinBox;
63
64
GtkListStore * credentialStore;
GtkWidget * deleteCredButton;
65
GtkWidget * treeViewCredential;
66
// GtkWidget * scrolledWindowCredential;
67
68
GtkWidget * advancedZrtpButton;
GtkWidget * keyExchangeCombo;
pierre-luc's avatar
pierre-luc committed
69
GtkWidget * useSipTlsCheckBox;
70

71
GtkWidget * localAddressEntry;
72
GtkWidget * publishedAddressEntry;
73
GtkWidget * localAddressLabel;
74
GtkWidget * localAddressCombo;
75
GtkWidget * useStunCheckBox;
76
77
GtkWidget * sameAsLocalRadioButton;
GtkWidget * publishedAddrRadioButton;
78
79
GtkWidget * sameAsLocalLabel;
GtkWidget * publishedAddrLabel;
80
GtkWidget * publishedPortSpinBox;
81
GtkWidget * localPortLabel;
82
GtkWidget * localPortSpinBox;
83
84
85
86
GtkWidget * publishedAddressLabel;
GtkWidget * publishedPortLabel;
GtkWidget * stunServerLabel;
GtkWidget * stunServerEntry;
87
88

GtkWidget * displayNameEntry;
89
90
91

GtkWidget * security_tab;
GtkWidget * advanced_tab;
92

93
94
GtkWidget * overrtp;

95
96
GHashTable * directIpCallsProperties = NULL;

97
98
// Credentials
enum {
99
100
101
102
103
	COLUMN_CREDENTIAL_REALM,
	COLUMN_CREDENTIAL_USERNAME,
	COLUMN_CREDENTIAL_PASSWORD,
	COLUMN_CREDENTIAL_DATA,
	COLUMN_CREDENTIAL_COUNT
104
};
105

106
107
108
109
110
111
112
113
/*
 * Display / Hide the password
 */
static void show_password_cb (GtkWidget *widget, gpointer data)
{
	gtk_entry_set_visibility (GTK_ENTRY (data), !gtk_entry_get_visibility (GTK_ENTRY (data)));
}

114
/* Signal to protocolComboBox 'changed' */
115
116
117
void change_protocol_cb (account_t *currentAccount UNUSED) {

	gchar *protocol = gtk_combo_box_get_active_text (GTK_COMBO_BOX (protocolComboBox));
118

119
120
121
122
123
124
125
126
127
128
	// Only if tabs are not NULL
	if(security_tab && advanced_tab) {

	    if (g_strcasecmp (protocol, "IAX") == 0) {
		gtk_widget_hide (GTK_WIDGET(security_tab));
		gtk_widget_hide (GTK_WIDGET(advanced_tab));
	    } else {
                gtk_widget_show (GTK_WIDGET(security_tab));
		gtk_widget_show (GTK_WIDGET(advanced_tab));
	    }
129
	}
130
131
}

132
	int
Emmanuel Milou's avatar
Emmanuel Milou committed
133
134
is_iax_enabled(void)
{
135
136
137
138
139
	int res = dbus_is_iax2_enabled();
	if(res == 1)
		return TRUE;
	else
		return FALSE;
Emmanuel Milou's avatar
Emmanuel Milou committed
140
}
141

142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
        void
select_dtmf_type( void )
{

        DEBUG("DTMF selection changed\n");

        if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(overrtp) ) )
        {
                // dbus_set_audio_manager( ALSA );
                DEBUG("Selected DTMF over RTP");
        }
        else {

                // dbus_set_audio_manager( PULSEAUDIO );
                DEBUG("Selected DTMF over SIP");
        }

}

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
static GPtrArray* getNewCredential (GHashTable * properties) {

	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 ();

	gchar *username;
	gchar *realm;
	gchar *password;
	GHashTable * new_table;   

	gtk_tree_model_get (GTK_TREE_MODEL(credentialStore), &iter,
			COLUMN_CREDENTIAL_REALM, &realm,
			COLUMN_CREDENTIAL_USERNAME, &username,
			COLUMN_CREDENTIAL_PASSWORD, &password,
			-1);

	g_hash_table_insert(properties, g_strdup(ACCOUNT_REALM), realm);
	g_hash_table_insert(properties, g_strdup(ACCOUNT_AUTHENTICATION_USERNAME), username);

	// Do not change the password if nothing has been changed by the user
	if (g_strcasecmp (password, PW_HIDDEN) != 0)
		g_hash_table_insert(properties, g_strdup(ACCOUNT_PASSWORD), password);

	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;
}

216
217
static void update_credential_cb(GtkWidget *widget, gpointer data UNUSED)
{
218
219
220
221
222
	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"));
	// g_print ("set password to %s\n", (gchar *) gtk_entry_get_text(GTK_ENTRY(widget)));
	gtk_list_store_set (GTK_LIST_STORE (credentialStore), &iter, column, (gchar *) gtk_entry_get_text(GTK_ENTRY(widget)), -1);
223
224
}

225
226
static GtkWidget* create_basic_tab (account_t **a)  {

227
228
229
	GtkWidget * frame;
	GtkWidget * table;
	account_t *currentAccount;
230
	GtkWidget * clearTextCheckbox;
231
232
#if GTK_CHECK_VERSION(2,16,0)
#else
233
	GtkWidget *image;
234
#endif
235

236
	// Default settings
237
238
239
240
241
242
243
	gchar *curAccountID = "";
	gchar *curAccountEnabled = "true";
	gchar *curAccountType = "SIP";
	gchar *curAlias = "";
	gchar *curUsername = "";
	gchar *curHostname = "";
	gchar *curPassword = "";
244
	/* TODO: add curProxy, and add boxes for Proxy support */
245
246
	gchar *curMailbox = "";
	gchar *curUseragent = "";
247
248
249
250
251
252
253
254

	currentAccount = *a;

	// Load from SIP/IAX/Unknown ?
	if(currentAccount)
	{
		curAccountID = currentAccount->accountID;
		curAccountType = g_hash_table_lookup(currentAccount->properties, ACCOUNT_TYPE);
255
		DEBUG("CuraccountType %s", curAccountType);
256
257
258
259
260
261
		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);
262
		curUseragent = g_hash_table_lookup(currentAccount->properties, ACCOUNT_USERAGENT);
263
	}
264

265

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

269
	table = gtk_table_new (8, 2  ,  FALSE/* homogeneous */);
270
271
	gtk_table_set_row_spacings( GTK_TABLE(table), 10);
	gtk_table_set_col_spacings( GTK_TABLE(table), 10);
272
	gtk_widget_show (table);
273
	gtk_container_add( GTK_CONTAINER( frame) , table );
Emmanuel Milou's avatar
Emmanuel Milou committed
274

275
	label = gtk_label_new_with_mnemonic (_("_Alias"));
276
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
277
278
279
280
	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);
281
	gtk_table_attach ( GTK_TABLE( table ), entryAlias, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
282
283

	label = gtk_label_new_with_mnemonic (_("_Protocol"));
284
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
285
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
286
287
288
289
	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");
290
291
	if(strcmp(curAccountType, "SIP") == 0)
	{
292
		gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox),0);
293
294
295
	}
	else if(strcmp(curAccountType, "IAX") == 0)
	{
296
		gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox),1);
297
298
299
300
	}
	else
	{
		/* Should never come here, add debug message. */
301
302
		gtk_combo_box_append_text(GTK_COMBO_BOX(protocolComboBox), _("Unknown"));
		gtk_combo_box_set_active(GTK_COMBO_BOX(protocolComboBox),2);
303
	}
304
	gtk_table_attach ( GTK_TABLE( table ), protocolComboBox, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
305
306

	/* Link signal 'changed' */
307
308
	g_signal_connect (G_OBJECT (GTK_COMBO_BOX(protocolComboBox)), "changed",
			G_CALLBACK (change_protocol_cb),
309
310
311
			currentAccount);

	label = gtk_label_new_with_mnemonic (_("_Host name"));
312
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
313
314
315
316
	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);
317
	gtk_table_attach ( GTK_TABLE( table ), entryHostname, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
318
319

	label = gtk_label_new_with_mnemonic (_("_User name"));
320
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);	
321
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
322
323
#if GTK_CHECK_VERSION(2,16,0)
	entryUsername = gtk_entry_new();
324
	gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entryUsername), GTK_ENTRY_ICON_PRIMARY, gdk_pixbuf_new_from_file(ICONS_DIR "/stock_person.svg", NULL));
325
#else
326
327
328
	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) );
329
#endif
330
331
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryUsername);
	gtk_entry_set_text(GTK_ENTRY(entryUsername), curUsername);
332
	gtk_table_attach ( GTK_TABLE( table ), entryUsername, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
333
334
	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));
335

336
	label = gtk_label_new_with_mnemonic (_("_Password"));
337
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
338
	gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
339
340
#if GTK_CHECK_VERSION(2,16,0)
	entryPassword = gtk_entry_new();
341
342
	GtkSettings *settings = gtk_settings_get_default ();
	//g_object_set (G_OBJECT (settings), "gtk-entry-password-hint-timeout", 600, NULL);
343
	gtk_entry_set_icon_from_stock (GTK_ENTRY (entryPassword), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_DIALOG_AUTHENTICATION);
344
#else
345
346
347
	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) );
348
#endif
349
350
351
	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);
352
	gtk_table_attach ( GTK_TABLE( table ), entryPassword, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
353
354
355
	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));

356
	clearTextCheckbox = gtk_check_button_new_with_mnemonic (_("Show password"));
357
358
	g_signal_connect (clearTextCheckbox, "toggled", G_CALLBACK (show_password_cb), entryPassword);
	gtk_table_attach (GTK_TABLE (table), clearTextCheckbox, 1, 2, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
359

360
	label = gtk_label_new_with_mnemonic (_("_Voicemail number"));
361
	gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 6, 7, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
362
363
364
365
	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);
366
	gtk_table_attach ( GTK_TABLE( table ), entryMailbox, 1, 2, 6, 7, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
367

368
369
370
371
372
373
374
375
376
	label = gtk_label_new_with_mnemonic (_("_User-agent"));
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 7, 8, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
	entryUseragent = gtk_entry_new ();
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryUseragent);
	gtk_entry_set_text (GTK_ENTRY (entryUseragent), curUseragent);
	gtk_table_attach ( GTK_TABLE( table ), entryUseragent, 1, 2, 7, 8, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);


377
378
379
380
381
	gtk_widget_show_all( table );
	gtk_container_set_border_width (GTK_CONTAINER(table), 10);

	*a = currentAccount;
	return frame;
382
383
}

384
static void fill_treeview_with_credential (GtkListStore * credentialStore, account_t * account) 
385
{
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
	GtkTreeIter iter;
	gtk_list_store_clear(credentialStore);
	gtk_list_store_append (credentialStore, &iter);

	/* This is the default, undeletable credential */
	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)) {
		gtk_list_store_set(credentialStore, &iter,
				COLUMN_CREDENTIAL_REALM, realm, 
				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_PASSWORD, PW_HIDDEN,    
				COLUMN_CREDENTIAL_DATA, account, 
				-1);
		g_signal_handlers_disconnect_by_func (G_OBJECT(entryUsername), G_CALLBACK(update_credential_cb), NULL);
	}

	if(account->credential_information == NULL) {
		DEBUG("No credential defined");
		return;
	}

	unsigned int i;
	for(i = 0; i < account->credential_information->len; i++)
	{	                    
		GHashTable * element = g_ptr_array_index(account->credential_information, i);               
		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);
	}
432
433
434
435
}

static select_credential_cb(GtkTreeSelection *selection, GtkTreeModel *model)
{
436
437
438
439
440
441
442
443
444
445
	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);
		}
	}
446
447
448
449
}

static void add_credential_cb (GtkWidget *button, gpointer data)
{
450
451
452
453
454
455
456
457
458
	GtkTreeIter iter;
	GtkTreeModel *model = (GtkTreeModel *)data;

	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);
459
460
461
462
}

static void delete_credential_cb(GtkWidget *button, gpointer data)
{
463
464
465
466
467
468
469
470
471
472
473
474
475
	GtkTreeIter iter;
	GtkTreeView *treeview = (GtkTreeView *)data;
	GtkTreeModel *model = gtk_tree_view_get_model (treeview);
	GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);

	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);
	}
476

477
478
479
480
}

static void cell_edited_cb(GtkCellRendererText *renderer, gchar *path_desc, gchar *text, gpointer data)
{
481
482
483
	GtkTreeModel *model = (GtkTreeModel *)data;
	GtkTreePath *path = gtk_tree_path_new_from_string (path_desc);
	GtkTreeIter iter;
484

485
	gint column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (renderer), "column"));
486
	DEBUG("path desc in cell_edited_cb: %s\n", text);
487

488
489
490
491
492
493
	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);
		}

		if (column == COLUMN_CREDENTIAL_PASSWORD) { 
494
495
496
			gtk_entry_set_text (GTK_ENTRY (entryPassword), text);
			text = PW_HIDDEN;	
		}
497
498
499
500
501
	}  

	gtk_tree_model_get_iter (model, &iter, path);
	gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, text, -1);
	gtk_tree_path_free (path);
502

503
504
}

505
506
507
static void editing_started_cb (GtkCellRenderer *cell, GtkCellEditable * editable, const gchar * path, gpointer data) {

	DEBUG("Editing started");
508
	DEBUG("path desc in editing_started_cb: %s\n", path);
509
510
511
512
513
514

	// If we are dealing the first row
	if (g_strcasecmp (path, "0") == 0)
	{
		gtk_entry_set_text (GTK_ENTRY (editable), gtk_entry_get_text (GTK_ENTRY (entryPassword)));
	}
515
516
}

517
518
static void show_advanced_zrtp_options_cb(GtkWidget *widget UNUSED, gpointer data)
{
519

520
521
522
523
524
525
526
    DEBUG("Advanced options for SRTP");
    if (g_strcasecmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo)), (gchar *) "ZRTP") == 0) {
        show_advanced_zrtp_options((GHashTable *) data);
    }
    else {
        show_advanced_sdes_options((GHashTable *) data);
    }
527
528
}

529

530
531
static void show_advanced_tls_options_cb(GtkWidget *widget UNUSED, gpointer data)
{
532
533
	DEBUG("Advanced options for TLS");
	show_advanced_tls_options((GHashTable *) data);
534
535
}

536
537
static void key_exchange_changed_cb(GtkWidget *widget, gpointer data)
{
538

539
    DEBUG("Key exchange changed %s", gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo)));
540
541
542
543
544

    int isSdes = g_strcasecmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo)), (gchar *) "SDES");
    int isZrtp = g_strcasecmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo)), (gchar *) "ZRTP");

    if ((isSdes == 0) || (isZrtp == 0)) {
545
546
547
548
549
550
551
        gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), TRUE);
    } else {
        gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), FALSE);
        
    }
}

552

553
554
static void use_sip_tls_cb(GtkWidget *widget, gpointer data)
{
555

556
557
558
559
560
561
562
563
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
		DEBUG("Using sips");
		gtk_widget_set_sensitive(GTK_WIDGET(data), TRUE);
		// Uncheck stun
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useStunCheckBox), FALSE);
		gtk_widget_set_sensitive(GTK_WIDGET(useStunCheckBox), FALSE);
		gtk_widget_set_sensitive(GTK_WIDGET(sameAsLocalRadioButton), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(publishedAddrRadioButton), TRUE);
564
565
		gtk_widget_hide (stunServerLabel);
		gtk_widget_hide (stunServerEntry);
566
567
568
569
570
571
572
573
574



		if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton))) {
			gtk_widget_show(publishedAddressEntry);
			gtk_widget_show(publishedPortSpinBox);
			gtk_widget_show(publishedAddressLabel);
			gtk_widget_show(publishedPortLabel);
		}
575

576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
	} else {
		gtk_widget_set_sensitive(GTK_WIDGET(data), FALSE);
		gtk_widget_set_sensitive(GTK_WIDGET(useStunCheckBox), TRUE);

		if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useStunCheckBox))) {
			gtk_widget_set_sensitive(GTK_WIDGET(sameAsLocalRadioButton), FALSE);
			gtk_widget_set_sensitive(GTK_WIDGET(publishedAddrRadioButton), FALSE);
			gtk_widget_show(stunServerLabel);
			gtk_widget_show(stunServerEntry);
			gtk_widget_hide(publishedAddressEntry);
			gtk_widget_hide(publishedPortSpinBox);
			gtk_widget_hide(publishedAddressLabel);
			gtk_widget_hide(publishedPortLabel);
		}
		else {
			gtk_widget_set_sensitive(GTK_WIDGET(sameAsLocalRadioButton), TRUE);
			gtk_widget_set_sensitive(GTK_WIDGET(publishedAddrRadioButton), TRUE);
			gtk_widget_hide(stunServerLabel);
			gtk_widget_hide(stunServerEntry);
		}

	}   
598
599
}

600
static local_interface_changed_cb(GtkWidget * widget, gpointer data UNUSED) {
601

602
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sameAsLocalRadioButton))) {
603

604
605
606
		gchar *local_iface_name;
		gchar *local_iface_addr;
		local_iface_addr = g_malloc(36);
607

608
		local_iface_name = (gchar *) gtk_combo_box_get_active_text (GTK_COMBO_BOX (localAddressCombo));
609
		// sflphone_get_interface_addr_from_name((char *)local_interface);
610
		sflphone_get_interface_addr_from_name(local_iface_name, &local_iface_addr);
611

612
613
		gtk_entry_set_text(GTK_ENTRY(localAddressEntry), local_iface_addr);
		gtk_entry_set_text (GTK_ENTRY(publishedAddressEntry), local_iface_addr);
614
615
616

		// gchar * local_port = (gchar *) gtk_entry_get_text(GTK_ENTRY(localPortSpinBox));
		// gtk_spin_button_set_value(GTK_SPIN_BUTTON(publishedPortSpinBox), g_ascii_strtod(local_port, NULL));
617
		g_free(local_iface_addr);
618
	}
619
620
621

}

622
623
static set_published_addr_manually_cb(GtkWidget * widget, gpointer data UNUSED)
{
624
625
626
627
628
629
630
631
632
633
634
635
636
637

	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);
	} else {
		DEBUG("Hiding manual options");   
		gtk_widget_hide(publishedPortLabel);            
		gtk_widget_hide(publishedPortSpinBox);
		gtk_widget_hide(publishedAddressLabel);                	
		gtk_widget_hide(publishedAddressEntry);
	}
638
639
}

640
static use_stun_cb(GtkWidget *widget, gpointer data UNUSED)
641
{
642
643
644
645
	gchar *local_interface;
	gchar *local_address;

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
646
647

		DEBUG("Showing stun options, hiding Local/Published info");
648
649
650
651
		gtk_widget_show (stunServerLabel);
		gtk_widget_show (stunServerEntry);
		gtk_widget_set_sensitive (sameAsLocalRadioButton, FALSE);
		gtk_widget_set_sensitive (publishedAddrRadioButton, FALSE);
652

653
654
655
656
657
		gtk_widget_hide (publishedAddressLabel);
		gtk_widget_hide (publishedPortLabel);
		gtk_widget_hide (publishedAddressEntry);
		gtk_widget_hide (publishedPortSpinBox);

658
	} else {
659
660
661
662
663
664

		gtk_widget_hide (stunServerLabel);
		gtk_widget_hide (stunServerEntry);
		gtk_widget_set_sensitive (sameAsLocalRadioButton, TRUE);
		gtk_widget_set_sensitive (publishedAddrRadioButton, TRUE);

665
		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (publishedAddrRadioButton))) {
666
667
668
669
			gtk_widget_show (publishedAddressLabel);
			gtk_widget_show (publishedPortLabel);
			gtk_widget_show (publishedAddressEntry);
			gtk_widget_show (publishedPortSpinBox);
670
671
672
673
674
675
676
677
678

			// Since stun callback is called at initialization, we cannot reinit published address
			// TODO: find a way so that if stun is unchecked, reinit published address entry 
			//       in case local address changedd

			// local_interface = (gchar *) gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo));
			// local_address = dbus_get_address_from_interface_name(local_interface);
			// gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), local_address);
		}
679
	}
680
681
}

682

683
684
static same_as_local_cb(GtkWidget * widget, gpointer data UNUSED)
{
685

686
687
688
689
690
691
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
		DEBUG("Same as local");
		gchar * local_interface;
		gchar * local_address;

		local_interface = (gchar *) gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo));
692
		// sflphone_get_interface_addr_from_name((char *)local_interface);
693
		local_address = dbus_get_address_from_interface_name(local_interface);
694

695
		gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), local_address);
696

697
698
699
		gchar * local_port = (gchar *) gtk_entry_get_text(GTK_ENTRY(localPortSpinBox));
		gtk_spin_button_set_value(GTK_SPIN_BUTTON(publishedPortSpinBox), g_ascii_strtod(local_port, NULL));
	} 
700

701
702
703
704
}



705
GtkWidget* create_credential_widget (account_t **a) {
706

707
708
709
710
711
712
713
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
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
808
809
810
811
812
813
814
	GtkWidget *frame, *table, *scrolledWindowCredential, *addButton;
	GtkCellRenderer * renderer;
	GtkTreeViewColumn * treeViewColumn;
	GtkTreeSelection * treeSelection;

	/* Credentials tree view */
	gnome_main_section_new_with_table (_("Credential"), &frame, &table, 1, 1);
	gtk_container_set_border_width (GTK_CONTAINER(table), 10);
	gtk_table_set_row_spacings(GTK_TABLE(table), 10);

	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);
	gtk_table_attach_defaults (GTK_TABLE (table), scrolledWindowCredential, 0, 1, 0, 1);

	credentialStore = gtk_list_store_new(COLUMN_CREDENTIAL_COUNT,
			G_TYPE_STRING,  // Realm
			G_TYPE_STRING,  // Username
			G_TYPE_STRING,  // Password
			G_TYPE_POINTER  // Pointer to the Objectc
			);

	treeViewCredential = gtk_tree_view_new_with_model(GTK_TREE_MODEL(credentialStore));
	treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW (treeViewCredential));
	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);
	gtk_tree_view_append_column (GTK_TREE_VIEW(treeViewCredential), treeViewColumn);

	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);
	gtk_tree_view_append_column (GTK_TREE_VIEW(treeViewCredential), treeViewColumn);

	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);
	gtk_tree_view_append_column (GTK_TREE_VIEW(treeViewCredential), treeViewColumn);

	gtk_container_add(GTK_CONTAINER(scrolledWindowCredential), treeViewCredential);

	fill_treeview_with_credential(credentialStore, *a);

	/* Credential Buttons */    
	hbox = gtk_hbox_new(FALSE, 10);
	gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 3, 1, 2);

	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);
	g_signal_connect (deleteCredButton, "clicked", G_CALLBACK (delete_credential_cb), treeViewCredential);
	gtk_box_pack_start(GTK_BOX(hbox), deleteCredButton, FALSE, FALSE, 0);

	/* 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);
	gtk_widget_set_size_request (GTK_WIDGET(scrolledWindowCredential), 400, /*requisitionTable.width,*/ 120);
	// same_as_local_cb (sameAsLocalRadioButton, NULL);
	// set_published_addr_manually_cb (publishedAddrRadioButton, NULL);


	return frame;
}


GtkWidget* create_security_widget (account_t **a) {

	GtkWidget *frame, *table, *sipTlsAdvancedButton, *label;
	gchar *curSRTPEnabled = NULL, *curKeyExchange = NULL, *curTLSEnabled = NULL;

	// Load from SIP/IAX/Unknown ?
	if((*a)) {	
		curKeyExchange = g_hash_table_lookup ((*a)->properties, ACCOUNT_KEY_EXCHANGE);
		if (curKeyExchange == NULL) {
			curKeyExchange = "none";
		}		

		curSRTPEnabled = g_hash_table_lookup ((*a)->properties, ACCOUNT_SRTP_ENABLED);
		if (curSRTPEnabled == NULL) {
			curSRTPEnabled = "false";
		}

		curTLSEnabled = g_hash_table_lookup ((*a)->properties, TLS_ENABLE);
		if (curTLSEnabled == NULL) {
			curTLSEnabled = "false";
		}
815
	}
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
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
860
861
862
863
864
865
866
867
868
869
870

	gnome_main_section_new_with_table (_("Security"), &frame, &table, 2, 3);
	gtk_container_set_border_width (GTK_CONTAINER(table), 10);
	gtk_table_set_row_spacings (GTK_TABLE(table), 10);
	gtk_table_set_col_spacings (GTK_TABLE(table), 10);

	/* TLS subsection */
	sipTlsAdvancedButton = gtk_button_new_from_stock (GTK_STOCK_EDIT);
	gtk_table_attach_defaults (GTK_TABLE (table), sipTlsAdvancedButton, 2, 3, 0, 1);
	gtk_widget_set_sensitive (GTK_WIDGET (sipTlsAdvancedButton), FALSE);    
	g_signal_connect (G_OBJECT (sipTlsAdvancedButton), "clicked", G_CALLBACK (show_advanced_tls_options_cb), (*a)->properties);

	useSipTlsCheckBox = gtk_check_button_new_with_mnemonic(_("Use TLS transport (sips)"));
	g_signal_connect (useSipTlsCheckBox, "toggled", G_CALLBACK(use_sip_tls_cb), sipTlsAdvancedButton);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useSipTlsCheckBox), (g_strcmp0(curTLSEnabled, "true") == 0) ? TRUE:FALSE);
	gtk_table_attach_defaults(GTK_TABLE(table), useSipTlsCheckBox, 0, 2, 0, 1);

	/* ZRTP subsection */
	label = gtk_label_new_with_mnemonic (_("SRTP key exchange"));
	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
	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"));      

	advancedZrtpButton = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
	g_signal_connect(G_OBJECT(advancedZrtpButton), "clicked", G_CALLBACK(show_advanced_zrtp_options_cb), (*a)->properties);

	if (g_strcmp0(curSRTPEnabled, "false") == 0)
	{
		gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo), 2);
		gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), FALSE);
	} else {
		if (strcmp(curKeyExchange, ZRTP) == 0) {
			gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo),0);
		} 
		else if (strcmp(curKeyExchange, SDES) == 0) {
			gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo),1);
		}
		else {
			gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo), 2);
			gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), FALSE);
		}
	}

	g_signal_connect (G_OBJECT (GTK_COMBO_BOX(keyExchangeCombo)), "changed", G_CALLBACK (key_exchange_changed_cb), *a);

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

	gtk_widget_show_all(table);

	return frame;
871
872
}

873

874
GtkWidget * create_security_tab (account_t **a)
875
876
877
878
{
	GtkWidget * frame;
	GtkWidget * ret;
	GtkWidget * hbox;
879

880
	ret = gtk_vbox_new(FALSE, 10);
881
	gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
882

883
884
	/*
	   published_address = g_hash_table_lookup(currentAccount->properties,  PUBLISHED_ADDRESS);
885

886
	   published_port = g_hash_table_lookup(currentAccount->properties,  PUBLISHED_PORT);
887

888
889
	   DEBUG("TLS is enabled to %s", curTLSEnabled);       
	   } */
890

891
892
893
	// Credentials frame
	frame = create_credential_widget (a);
	gtk_box_pack_start (GTK_BOX (ret), frame, FALSE, FALSE, 0);
894

895
896
897
	// Security frame
	frame = create_security_widget (a);
	gtk_box_pack_start (GTK_BOX (ret), frame, FALSE, FALSE, 0);
898

899
	gtk_widget_show_all(ret);
900

901
	return ret;
902
	}
903

904
GtkWidget* create_registration_expire (account_t **a) {
905

906
    GtkWidget *table, *frame, *label;
907

908
    gchar *resolve_once=NULL, *account_expire=NULL;
909

910
911
912
913
    if (*a) {
        resolve_once = g_hash_table_lookup ((*a)->properties, ACCOUNT_RESOLVE_ONCE);
	account_expire = g_hash_table_lookup ((*a)->properties, ACCOUNT_REGISTRATION_EXPIRE);
    }
914

915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
    gnome_main_section_new_with_table (_("Registration"), &frame, &table, 2, 3);
    gtk_container_set_border_width (GTK_CONTAINER(table), 10);
    gtk_table_set_row_spacings (GTK_TABLE (table), 5);	
    
    label = gtk_label_new_with_mnemonic (_("Registration expire"));
    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);
	

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

    return frame;
935
936
937
}

GtkWidget* create_network (account_t **a) {
938
939
940
  
    GtkWidget *table, *frame, *label;
    gchar *local_interface, *local_port;
941

942
943
944
945
    if (*a) {
        local_interface = g_hash_table_lookup ((*a)->properties, LOCAL_INTERFACE);
	local_port = g_hash_table_lookup ((*a)->properties, LOCAL_PORT);
    }
946

947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
    gnome_main_section_new_with_table (_("Network Interface"), &frame, &table, 2, 3);
    gtk_container_set_border_width (GTK_CONTAINER(table), 10);
    gtk_table_set_row_spacings( GTK_TABLE(table), 5);

    /**
     * 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_iface_iter = iter;   
    gchar ** iface_list = NULL;
    // iface_list = (gchar**) dbus_get_all_ip_interface();
    iface_list = (gchar**) dbus_get_all_ip_interface_by_name();
    gchar ** iface = NULL;

    // flag to determine if local_address is found 
    gboolean iface_found = FALSE;

    gchar *local_iface_addr;
    gchar *local_iface_name; 

    local_iface_addr= g_malloc(18);
    
    if (iface_list != NULL) {

        // fill the iterface combo box
        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 );

	    // set the current local address
	    if (!iface_found && (g_strcmp0(*iface, local_interface) == 0)) {
	        DEBUG("Setting active local address combo box");
		current_local_iface_iter = iter;
		iface_found = TRUE;
	  }
992
	}
993
994
995
996
	    
	if(!iface_found) {
	  DEBUG("Did not find local ip address, take fisrt in the list");
	  gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ipInterfaceListStore), &current_local_iface_iter);
997
	}
998
999
1000
	
    }
  
For faster browsing, not all history is shown. View entire blame