~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to .pc/05_glib_includes.patch/gnome/src/config/assistant.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
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
21
 *  If you modify this program, or any covered work, by linking or
 
22
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
23
 *  modified version of that library), containing parts covered by the
 
24
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
25
 *  grants you additional permission to convey the resulting work.
 
26
 *  Corresponding Source for a non-source form of such a combination
 
27
 *  shall include the source code for the parts of OpenSSL used as well
 
28
 *  as that of the covered work.
 
29
 */
 
30
 
 
31
#include <string.h>
 
32
 
 
33
#include "unused.h"
 
34
#include "assistant.h"
 
35
#include "logger.h"
 
36
#include "dbus.h"
 
37
#include "reqaccount.h"
 
38
 
 
39
#define SFLPHONE_ORG_SERVER "sip.sflphone.org"
 
40
 
 
41
struct _wizard *wiz;
 
42
static int account_type;
 
43
static int use_sflphone_org = 1;
 
44
static account_t* current;
 
45
static char message[1024];
 
46
/**
 
47
 * Forward function
 
48
 */
 
49
static gint forward_page_func(gint current_page , gpointer data);
 
50
 
 
51
/**
 
52
 * Page template
 
53
 */
 
54
static GtkWidget* create_vbox(GtkAssistantPageType type, const gchar *title, const gchar *section);
 
55
void prefill_sip(void) ;
 
56
 
 
57
void set_account_type(GtkWidget* widget , gpointer data UNUSED)
 
58
{
 
59
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
 
60
        account_type = _SIP;
 
61
    else
 
62
        account_type = _IAX ;
 
63
}
 
64
 
 
65
static void show_password_cb(GtkWidget *widget UNUSED, gpointer data)
 
66
{
 
67
    gtk_entry_set_visibility(GTK_ENTRY(data), !gtk_entry_get_visibility(GTK_ENTRY(data)));
 
68
}
 
69
 
 
70
 
 
71
/**
 
72
 * Fills string message with the final message of account registration
 
73
 * with alias, server and username specified.
 
74
 */
 
75
void getMessageSummary(const gchar * alias, const gchar * server, const gchar * username, const gboolean zrtp)
 
76
{
 
77
    char var[64];
 
78
    sprintf(message, _("This assistant is now finished."));
 
79
    strcat(message, "\n");
 
80
    strcat(message, _("You can at any time check your registration state or modify your accounts parameters in the Options/Accounts window."));
 
81
    strcat(message, "\n\n");
 
82
 
 
83
    strcat(message, _("Alias"));
 
84
    snprintf(var, sizeof(var), " :   %s\n", alias);
 
85
    strcat(message, var);
 
86
 
 
87
    strcat(message, _("Server"));
 
88
    snprintf(var, sizeof(var), " :   %s\n", server);
 
89
    strcat(message, var);
 
90
 
 
91
    strcat(message, _("Username"));
 
92
    snprintf(var, sizeof(var), " :   %s\n", username);
 
93
    strcat(message, var);
 
94
 
 
95
    strcat(message, _("Security: "));
 
96
 
 
97
    if (zrtp)
 
98
        strcat(message, _("SRTP/ZRTP draft-zimmermann"));
 
99
    else
 
100
        strcat(message, _("None"));
 
101
}
 
102
 
 
103
void set_sflphone_org(GtkWidget* widget , gpointer data UNUSED)
 
104
{
 
105
    use_sflphone_org = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) ?1:0) ;
 
106
}
 
107
 
 
108
 
 
109
 
 
110
/**
 
111
 * Callback when the close button of the dialog is clicked
 
112
 * Action : close the assistant widget and get back to sflphone main window
 
113
 */
 
114
static void close_callback(void)
 
115
{
 
116
    gtk_widget_destroy(wiz->assistant);
 
117
    g_free(wiz);
 
118
    wiz = NULL;
 
119
 
 
120
    status_bar_display_account();
 
121
}
 
122
 
 
123
/**
 
124
 * Callback when the cancel button of the dialog is clicked
 
125
 * Action : close the assistant widget and get back to sflphone main window
 
126
 */
 
127
static void cancel_callback(void)
 
128
{
 
129
    gtk_widget_destroy(wiz->assistant);
 
130
    g_free(wiz);
 
131
    wiz = NULL;
 
132
 
 
133
    status_bar_display_account();
 
134
}
 
135
 
 
136
/**
 
137
 * Callback when the button apply is clicked
 
138
 * Action : Set the account parameters with the entries values and called dbus_add_account
 
139
 */
 
140
static void sip_apply_callback(void)
 
141
{
 
142
    if (use_sflphone_org) {
 
143
        prefill_sip();
 
144
        account_type = _SIP;
 
145
    }
 
146
 
 
147
    if (account_type == _SIP) {
 
148
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ALIAS), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->sip_alias))));
 
149
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ENABLED), g_strdup("true"));
 
150
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_MAILBOX), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->sip_voicemail))));
 
151
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("SIP"));
 
152
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_HOSTNAME), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->sip_server))));
 
153
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_PASSWORD), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->sip_password))));
 
154
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_USERNAME), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->sip_username))));
 
155
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED), g_strdup((gchar *)(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->enable)) ? "true":"false")));
 
156
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->addr))));
 
157
 
 
158
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->zrtp_enable)) == TRUE) {
 
159
            g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup((gchar *) "true"));
 
160
            g_hash_table_insert(current->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup((gchar *) ZRTP));
 
161
            g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ZRTP_DISPLAY_SAS), g_strdup((gchar *) "true"));
 
162
            g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ZRTP_NOT_SUPP_WARNING), g_strdup((gchar *) "true"));
 
163
            g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ZRTP_HELLO_HASH), g_strdup((gchar *) "true"));
 
164
            g_hash_table_insert(current->properties, g_strdup(ACCOUNT_DISPLAY_SAS_ONCE), g_strdup((gchar *) "false"));
 
165
        }
 
166
 
 
167
 
 
168
        // Add default interface info
 
169
        gchar ** iface_list = NULL;
 
170
        iface_list = (gchar**) dbus_get_all_ip_interface_by_name();
 
171
        gchar ** iface = NULL;
 
172
 
 
173
        // select the first interface available
 
174
        iface = iface_list;
 
175
        DEBUG("Selected interface %s", *iface);
 
176
 
 
177
        g_hash_table_insert(current->properties, g_strdup(LOCAL_INTERFACE), g_strdup((gchar *) *iface));
 
178
 
 
179
        g_hash_table_insert(current->properties, g_strdup(PUBLISHED_ADDRESS), g_strdup((gchar *) *iface));
 
180
 
 
181
        dbus_add_account(current);
 
182
        getMessageSummary(gtk_entry_get_text(GTK_ENTRY(wiz->sip_alias)),
 
183
                          gtk_entry_get_text(GTK_ENTRY(wiz->sip_server)),
 
184
                          gtk_entry_get_text(GTK_ENTRY(wiz->sip_username)),
 
185
                          (gboolean)(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->zrtp_enable)))
 
186
                         );
 
187
 
 
188
        gtk_label_set_text(GTK_LABEL(wiz->label_summary), message);
 
189
    }
 
190
}
 
191
 
 
192
/**
 
193
 * Callback when the button apply is clicked
 
194
 * Action : Set the account parameters with the entries values and called dbus_add_account
 
195
 */
 
196
static void iax_apply_callback(void)
 
197
{
 
198
    if (account_type == _IAX) {
 
199
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ALIAS), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->iax_alias))));
 
200
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ENABLED), g_strdup("true"));
 
201
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_MAILBOX), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->iax_voicemail))));
 
202
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("IAX"));
 
203
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_USERNAME), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->iax_username))));
 
204
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_HOSTNAME), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->iax_server))));
 
205
        g_hash_table_insert(current->properties, g_strdup(ACCOUNT_PASSWORD), g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(wiz->iax_password))));
 
206
 
 
207
        dbus_add_account(current);
 
208
        getMessageSummary(gtk_entry_get_text(GTK_ENTRY(wiz->iax_alias)),
 
209
                          gtk_entry_get_text(GTK_ENTRY(wiz->iax_server)),
 
210
                          gtk_entry_get_text(GTK_ENTRY(wiz->iax_username)),
 
211
                          FALSE
 
212
                         ) ;
 
213
 
 
214
        gtk_label_set_text(GTK_LABEL(wiz->label_summary), message);
 
215
    }
 
216
}
 
217
 
 
218
void enable_stun(GtkWidget* widget)
 
219
{
 
220
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->addr), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
 
221
}
 
222
 
 
223
void build_wizard(void)
 
224
{
 
225
    use_sflphone_org = 1;
 
226
 
 
227
    if (wiz)
 
228
        return ;
 
229
 
 
230
    wiz = (struct _wizard*) g_malloc(sizeof(struct _wizard));
 
231
    current = g_new0(account_t, 1);
 
232
    current->properties = NULL;
 
233
    current->properties = dbus_get_account_details(NULL);
 
234
 
 
235
    if (current->properties == NULL) {
 
236
        DEBUG("Failed to get default values. Creating from scratch");
 
237
        current->properties = g_hash_table_new(NULL, g_str_equal);
 
238
    }
 
239
 
 
240
    current->accountID = g_strdup("new");
 
241
 
 
242
    wiz->assistant = gtk_assistant_new();
 
243
 
 
244
    gtk_window_set_title(GTK_WINDOW(wiz->assistant), _("SFLphone account creation wizard"));
 
245
    gtk_window_set_position(GTK_WINDOW(wiz->assistant), GTK_WIN_POS_CENTER);
 
246
    gtk_window_set_default_size(GTK_WINDOW(wiz->assistant), 200 , 200);
 
247
 
 
248
    build_intro();
 
249
    build_sfl_or_account();
 
250
    build_select_account();
 
251
    build_sip_account_configuration();
 
252
    build_nat_settings();
 
253
    build_iax_account_configuration();
 
254
    build_email_configuration();
 
255
    build_summary();
 
256
 
 
257
    g_signal_connect(G_OBJECT(wiz->assistant), "close" , G_CALLBACK(close_callback), NULL);
 
258
 
 
259
    g_signal_connect(G_OBJECT(wiz->assistant), "cancel" , G_CALLBACK(cancel_callback), NULL);
 
260
 
 
261
    gtk_widget_show_all(wiz->assistant);
 
262
 
 
263
    gtk_assistant_set_forward_page_func(GTK_ASSISTANT(wiz->assistant), (GtkAssistantPageFunc) forward_page_func , NULL , NULL);
 
264
    gtk_assistant_update_buttons_state(GTK_ASSISTANT(wiz->assistant));
 
265
}
 
266
 
 
267
GtkWidget* build_intro()
 
268
{
 
269
    GtkWidget *label;
 
270
 
 
271
    wiz->intro = create_vbox(GTK_ASSISTANT_PAGE_INTRO  , "SFLphone GNOME client" , _("Welcome to the Account creation wizard of SFLphone!"));
 
272
    label = gtk_label_new(_("This installation wizard will help you configure an account.")) ;
 
273
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
 
274
    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
 
275
    gtk_widget_set_size_request(GTK_WIDGET(label), 380, -1);
 
276
    gtk_box_pack_start(GTK_BOX(wiz->intro), label, FALSE, TRUE, 0);
 
277
 
 
278
    gtk_assistant_set_page_complete(GTK_ASSISTANT(wiz->assistant),  wiz->intro, TRUE);
 
279
    return wiz->intro;
 
280
}
 
281
 
 
282
GtkWidget* build_select_account()
 
283
{
 
284
    GtkWidget* sip;
 
285
    GtkWidget* iax;
 
286
 
 
287
    wiz->protocols = create_vbox(GTK_ASSISTANT_PAGE_CONTENT , _("VoIP Protocols") , _("Select an account type"));
 
288
 
 
289
    sip = gtk_radio_button_new_with_label(NULL, _("SIP (Session Initiation Protocol)"));
 
290
    gtk_box_pack_start(GTK_BOX(wiz->protocols) , sip , TRUE, TRUE, 0);
 
291
    iax = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(sip), _("IAX2 (InterAsterix Exchange)"));
 
292
    gtk_box_pack_start(GTK_BOX(wiz->protocols) , iax , TRUE, TRUE, 0);
 
293
 
 
294
    g_signal_connect(G_OBJECT(sip) , "clicked" , G_CALLBACK(set_account_type) , NULL);
 
295
 
 
296
    gtk_assistant_set_page_complete(GTK_ASSISTANT(wiz->assistant),  wiz->protocols, TRUE);
 
297
    return wiz->protocols;
 
298
}
 
299
 
 
300
 
 
301
GtkWidget* build_sfl_or_account()
 
302
{
 
303
    GtkWidget* sfl;
 
304
    GtkWidget* cus;
 
305
 
 
306
    wiz->sflphone_org = create_vbox(GTK_ASSISTANT_PAGE_CONTENT , _("Account") , _("Please select one of the following options"));
 
307
 
 
308
    sfl = gtk_radio_button_new_with_label(NULL, _("Create a free SIP/IAX2 account on sflphone.org \n(For testing purpose only)"));
 
309
    gtk_box_pack_start(GTK_BOX(wiz->sflphone_org) , sfl , TRUE, TRUE, 0);
 
310
    cus = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(sfl), _("Register an existing SIP or IAX2 account"));
 
311
    gtk_box_pack_start(GTK_BOX(wiz->sflphone_org) , cus , TRUE, TRUE, 0);
 
312
    g_signal_connect(G_OBJECT(sfl) , "clicked" , G_CALLBACK(set_sflphone_org) , NULL);
 
313
 
 
314
    return wiz->sflphone_org;
 
315
}
 
316
 
 
317
 
 
318
GtkWidget* build_sip_account_configuration(void)
 
319
{
 
320
    GtkWidget* table;
 
321
    GtkWidget* label;
 
322
    GtkWidget * clearTextCheckbox;
 
323
 
 
324
    wiz->sip_account = create_vbox(GTK_ASSISTANT_PAGE_CONTENT , _("SIP account settings") , _("Please fill the following information"));
 
325
    // table
 
326
    table = gtk_table_new(7, 2  ,  FALSE/* homogeneous */);
 
327
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
 
328
    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
 
329
    gtk_box_pack_start(GTK_BOX(wiz->sip_account) , table , TRUE, TRUE, 0);
 
330
 
 
331
    // alias field
 
332
    label = gtk_label_new_with_mnemonic(_("_Alias"));
 
333
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
334
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
335
    wiz->sip_alias = gtk_entry_new();
 
336
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->sip_alias);
 
337
    gtk_table_attach(GTK_TABLE(table), wiz->sip_alias, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
338
 
 
339
    // server field
 
340
    label = gtk_label_new_with_mnemonic(_("_Host name"));
 
341
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
342
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
343
    wiz->sip_server = gtk_entry_new();
 
344
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->sip_server);
 
345
    gtk_table_attach(GTK_TABLE(table), wiz->sip_server, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
346
 
 
347
    // username field
 
348
    label = gtk_label_new_with_mnemonic(_("_User name"));
 
349
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
350
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
351
    wiz->sip_username = gtk_entry_new();
 
352
    gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(wiz->sip_username), GTK_ENTRY_ICON_PRIMARY, gdk_pixbuf_new_from_file(ICONS_DIR "/stock_person.svg", NULL));
 
353
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->sip_username);
 
354
    gtk_table_attach(GTK_TABLE(table), wiz->sip_username, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
355
 
 
356
    // password field
 
357
 
 
358
    label = gtk_label_new_with_mnemonic(_("_Password"));
 
359
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
360
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
361
    wiz->sip_password = gtk_entry_new();
 
362
    gtk_entry_set_icon_from_stock(GTK_ENTRY(wiz->sip_password), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_DIALOG_AUTHENTICATION);
 
363
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->sip_password);
 
364
    gtk_entry_set_visibility(GTK_ENTRY(wiz->sip_password), FALSE);
 
365
    gtk_table_attach(GTK_TABLE(table), wiz->sip_password, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
366
 
 
367
    clearTextCheckbox = gtk_check_button_new_with_mnemonic(_("Show password"));
 
368
    g_signal_connect(clearTextCheckbox, "toggled", G_CALLBACK(show_password_cb), wiz->sip_password);
 
369
    gtk_table_attach(GTK_TABLE(table), clearTextCheckbox, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
370
 
 
371
    // voicemail number field
 
372
    label = gtk_label_new_with_mnemonic(_("_Voicemail number"));
 
373
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
374
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
375
    wiz->sip_voicemail = gtk_entry_new();
 
376
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->sip_voicemail);
 
377
    gtk_table_attach(GTK_TABLE(table), wiz->sip_voicemail, 1, 2, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
378
 
 
379
    // Security options
 
380
    wiz->zrtp_enable = gtk_check_button_new_with_mnemonic(_("Secure communications with _ZRTP"));
 
381
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wiz->zrtp_enable), FALSE);
 
382
    gtk_table_attach(GTK_TABLE(table), wiz->zrtp_enable, 0, 1, 6, 7, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
383
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->zrtp_enable) , TRUE);
 
384
 
 
385
    //gtk_assistant_set_page_complete(GTK_ASSISTANT(wiz->assistant),  wiz->sip_account, TRUE);
 
386
    return wiz->sip_account;
 
387
}
 
388
 
 
389
GtkWidget* build_email_configuration(void)
 
390
{
 
391
    GtkWidget* label;
 
392
    GtkWidget*  table;
 
393
 
 
394
    wiz->email = create_vbox(GTK_ASSISTANT_PAGE_CONTENT , _("Optional email address") , _("This email address will be used to send your voicemail messages."));
 
395
 
 
396
    table = gtk_table_new(4, 2  ,  FALSE/* homogeneous */);
 
397
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
 
398
    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
 
399
    gtk_box_pack_start(GTK_BOX(wiz->email) , table , TRUE, TRUE, 0);
 
400
 
 
401
    // email field
 
402
    label = gtk_label_new_with_mnemonic(_("_Email address"));
 
403
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
404
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
405
    wiz->mailbox = gtk_entry_new();
 
406
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->mailbox);
 
407
    gtk_table_attach(GTK_TABLE(table), wiz->mailbox, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
408
 
 
409
    // Security options
 
410
    wiz->zrtp_enable = gtk_check_button_new_with_mnemonic(_("Secure communications with _ZRTP"));
 
411
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wiz->zrtp_enable), FALSE);
 
412
    gtk_table_attach(GTK_TABLE(table), wiz->zrtp_enable, 0, 1, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
413
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->zrtp_enable) , TRUE);
 
414
 
 
415
    return wiz->email;
 
416
}
 
417
 
 
418
GtkWidget* build_iax_account_configuration(void)
 
419
{
 
420
    GtkWidget* label;
 
421
    GtkWidget*  table;
 
422
    GtkWidget * clearTextCheckbox;
 
423
 
 
424
    wiz->iax_account = create_vbox(GTK_ASSISTANT_PAGE_CONFIRM , _("IAX2 account settings") , _("Please fill the following information"));
 
425
 
 
426
    table = gtk_table_new(6, 2  ,  FALSE/* homogeneous */);
 
427
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
 
428
    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
 
429
    gtk_box_pack_start(GTK_BOX(wiz->iax_account) , table , TRUE, TRUE, 0);
 
430
 
 
431
    // alias field
 
432
    label = gtk_label_new_with_mnemonic(_("_Alias"));
 
433
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
434
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
435
    wiz->iax_alias = gtk_entry_new();
 
436
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->iax_alias);
 
437
    gtk_table_attach(GTK_TABLE(table), wiz->iax_alias, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
438
 
 
439
    // server field
 
440
    label = gtk_label_new_with_mnemonic(_("_Host name"));
 
441
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
442
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
443
    wiz->iax_server = gtk_entry_new();
 
444
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->iax_server);
 
445
    gtk_table_attach(GTK_TABLE(table), wiz->iax_server, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
446
 
 
447
    // username field
 
448
    label = gtk_label_new_with_mnemonic(_("_User name"));
 
449
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
450
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
451
    wiz->iax_username = gtk_entry_new();
 
452
    gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(wiz->iax_username), GTK_ENTRY_ICON_PRIMARY, gdk_pixbuf_new_from_file(ICONS_DIR "/stock_person.svg", NULL));
 
453
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->iax_username);
 
454
    gtk_table_attach(GTK_TABLE(table), wiz->iax_username, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
455
 
 
456
    // password field
 
457
    label = gtk_label_new_with_mnemonic(_("_Password"));
 
458
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
459
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
460
    wiz->iax_password = gtk_entry_new();
 
461
    gtk_entry_set_icon_from_stock(GTK_ENTRY(wiz->iax_password), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_DIALOG_AUTHENTICATION);
 
462
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->iax_password);
 
463
    gtk_entry_set_visibility(GTK_ENTRY(wiz->iax_password), FALSE);
 
464
    gtk_table_attach(GTK_TABLE(table), wiz->iax_password, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
465
 
 
466
    clearTextCheckbox = gtk_check_button_new_with_mnemonic(_("Show password"));
 
467
    g_signal_connect(clearTextCheckbox, "toggled", G_CALLBACK(show_password_cb), wiz->iax_password);
 
468
    gtk_table_attach(GTK_TABLE(table), clearTextCheckbox, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
469
 
 
470
    // voicemail number field
 
471
    label = gtk_label_new_with_mnemonic(_("_Voicemail number"));
 
472
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
473
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
474
    wiz->iax_voicemail = gtk_entry_new();
 
475
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->iax_voicemail);
 
476
    gtk_table_attach(GTK_TABLE(table), wiz->iax_voicemail, 1, 2, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
477
 
 
478
    current -> state = ACCOUNT_STATE_UNREGISTERED;
 
479
 
 
480
    g_signal_connect(G_OBJECT(wiz->assistant) , "apply" , G_CALLBACK(iax_apply_callback), NULL);
 
481
 
 
482
    return wiz->iax_account;
 
483
}
 
484
 
 
485
GtkWidget* build_nat_settings(void)
 
486
{
 
487
    GtkWidget* label;
 
488
    GtkWidget* table;
 
489
 
 
490
    wiz->nat = create_vbox(GTK_ASSISTANT_PAGE_CONFIRM , _("Network Address Translation (NAT)") , _("You should probably enable this if you are behind a firewall."));
 
491
 
 
492
    // table
 
493
    table = gtk_table_new(2, 2  ,  FALSE/* homogeneous */);
 
494
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
 
495
    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
 
496
    gtk_box_pack_start(GTK_BOX(wiz->nat), table , TRUE, TRUE, 0);
 
497
 
 
498
    // enable
 
499
    wiz->enable = gtk_check_button_new_with_mnemonic(_("E_nable STUN"));
 
500
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wiz->enable), FALSE);
 
501
    gtk_table_attach(GTK_TABLE(table), wiz->enable, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
502
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->enable) , TRUE);
 
503
    g_signal_connect(G_OBJECT(GTK_TOGGLE_BUTTON(wiz->enable)) , "toggled" , G_CALLBACK(enable_stun), NULL);
 
504
 
 
505
    // server address
 
506
    label = gtk_label_new_with_mnemonic(_("_STUN server"));
 
507
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
508
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
509
    wiz->addr = gtk_entry_new();
 
510
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), wiz->addr);
 
511
    gtk_table_attach(GTK_TABLE(table), wiz->addr, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
512
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->addr), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->enable)));
 
513
 
 
514
    g_signal_connect(G_OBJECT(wiz->assistant) , "apply" , G_CALLBACK(sip_apply_callback), NULL);
 
515
 
 
516
    return wiz->nat;
 
517
}
 
518
 
 
519
GtkWidget* build_summary()
 
520
{
 
521
    wiz->summary = create_vbox(GTK_ASSISTANT_PAGE_SUMMARY  , _("Account Registration") , _("Congratulations!"));
 
522
 
 
523
    strcpy(message,"");
 
524
    wiz->label_summary = gtk_label_new(message) ;
 
525
    gtk_label_set_selectable(GTK_LABEL(wiz->label_summary), TRUE);
 
526
    gtk_misc_set_alignment(GTK_MISC(wiz->label_summary), 0, 0);
 
527
    gtk_label_set_line_wrap(GTK_LABEL(wiz->label_summary), TRUE);
 
528
    //gtk_widget_set_size_request(GTK_WIDGET(wiz->label_summary), 380, -1);
 
529
    gtk_box_pack_start(GTK_BOX(wiz->summary), wiz->label_summary, FALSE, TRUE, 0);
 
530
 
 
531
    return wiz->summary;
 
532
}
 
533
 
 
534
GtkWidget* build_registration_error()
 
535
{
 
536
    GtkWidget *label;
 
537
    wiz->reg_failed = create_vbox(GTK_ASSISTANT_PAGE_SUMMARY  , "Account Registration" , "Registration error");
 
538
 
 
539
    label = gtk_label_new(" Please correct the information.") ;
 
540
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
 
541
    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
 
542
    gtk_widget_set_size_request(GTK_WIDGET(label), 380, -1);
 
543
    gtk_box_pack_start(GTK_BOX(wiz->reg_failed), label, FALSE, TRUE, 0);
 
544
 
 
545
    return wiz->reg_failed;
 
546
}
 
547
 
 
548
void set_sip_infos_sentivite(gboolean b)
 
549
{
 
550
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->sip_alias), b);
 
551
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->sip_server), b);
 
552
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->sip_username), b);
 
553
    gtk_widget_set_sensitive(GTK_WIDGET(wiz->sip_password), b);
 
554
}
 
555
 
 
556
void prefill_sip(void)
 
557
{
 
558
    if (use_sflphone_org == 1) {
 
559
        char alias[300];
 
560
        char *email;
 
561
        email = (char *) gtk_entry_get_text(GTK_ENTRY(wiz->mailbox));
 
562
        rest_account ra = get_rest_account(SFLPHONE_ORG_SERVER,email);
 
563
 
 
564
        if (ra.success) {
 
565
            set_sip_infos_sentivite(FALSE);
 
566
            strcpy(alias,ra.user);
 
567
            strcat(alias,"@");
 
568
            strcat(alias,"sip.sflphone.org");
 
569
            gtk_entry_set_text(GTK_ENTRY(wiz->sip_alias),alias);
 
570
            gtk_entry_set_text(GTK_ENTRY(wiz->sip_server), SFLPHONE_ORG_SERVER);
 
571
            gtk_entry_set_text(GTK_ENTRY(wiz->sip_username), ra.user);
 
572
            gtk_entry_set_text(GTK_ENTRY(wiz->sip_password), ra.passwd);
 
573
        }
 
574
    }
 
575
}
 
576
 
 
577
typedef enum {
 
578
    PAGE_INTRO,
 
579
    PAGE_SFL,
 
580
    PAGE_TYPE,
 
581
    PAGE_SIP,
 
582
    PAGE_STUN,
 
583
    PAGE_IAX,
 
584
    PAGE_EMAIL,
 
585
    PAGE_SUMMARY
 
586
} assistant_state;
 
587
 
 
588
static gint forward_page_func(gint current_page , gpointer data UNUSED)
 
589
{
 
590
    gint next_page = 0;
 
591
 
 
592
    switch (current_page) {
 
593
        case PAGE_INTRO:
 
594
            next_page = PAGE_SFL;
 
595
            break;
 
596
        case PAGE_SFL:
 
597
 
 
598
            if (use_sflphone_org) {
 
599
                next_page = PAGE_EMAIL;
 
600
            } else
 
601
                next_page = PAGE_TYPE;
 
602
 
 
603
            break;
 
604
        case PAGE_TYPE:
 
605
 
 
606
            if (account_type == _SIP) {
 
607
                set_sip_infos_sentivite(TRUE);
 
608
                next_page = PAGE_SIP;
 
609
            } else
 
610
                next_page = PAGE_IAX;
 
611
 
 
612
            break;
 
613
        case PAGE_SIP:
 
614
            next_page = PAGE_STUN;
 
615
            break;
 
616
        case PAGE_EMAIL:
 
617
            next_page = PAGE_STUN;
 
618
            break;
 
619
        case PAGE_STUN:
 
620
            next_page = PAGE_SUMMARY;
 
621
            break;
 
622
        case PAGE_IAX:
 
623
            next_page = PAGE_SUMMARY;
 
624
            break;
 
625
        case PAGE_SUMMARY:
 
626
            next_page = PAGE_SUMMARY;
 
627
            break;
 
628
        default:
 
629
            next_page = -1;
 
630
    }
 
631
 
 
632
    return next_page;
 
633
}
 
634
 
 
635
 
 
636
static GtkWidget* create_vbox(GtkAssistantPageType type, const gchar *title, const gchar *section)
 
637
{
 
638
    GtkWidget *vbox;
 
639
    GtkWidget *label;
 
640
    gchar *str;
 
641
 
 
642
    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
 
643
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 24);
 
644
 
 
645
    gtk_assistant_append_page(GTK_ASSISTANT(wiz->assistant), vbox);
 
646
    gtk_assistant_set_page_type(GTK_ASSISTANT(wiz->assistant), vbox, type);
 
647
    str = g_strdup_printf(" %s", title);
 
648
    gtk_assistant_set_page_title(GTK_ASSISTANT(wiz->assistant), vbox, str);
 
649
 
 
650
    g_free(str);
 
651
 
 
652
    gtk_assistant_set_page_complete(GTK_ASSISTANT(wiz->assistant), vbox, TRUE);
 
653
 
 
654
#if 0
 
655
    /* FIXME */
 
656
    http://developer.gnome.org/gtk3/stable/GtkAssistant.html#gtk-assistant-set-page-header-image
 
657
    wiz->logo = gdk_pixbuf_new_from_file(LOGO, NULL);
 
658
    gtk_assistant_set_page_header_image(GTK_ASSISTANT(wiz->assistant),vbox, wiz->logo);
 
659
    g_object_unref(wiz->logo);
 
660
#endif
 
661
 
 
662
    if (section) {
 
663
        label = gtk_label_new(NULL);
 
664
        str = g_strdup_printf("<b>%s</b>\n", section);
 
665
        gtk_label_set_markup(GTK_LABEL(label), str);
 
666
        g_free(str);
 
667
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
 
668
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
 
669
    }
 
670
 
 
671
    return vbox;
 
672
}