1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2006-2007 Imendio AB
4
* Copyright (C) 2007-2008 Collabora Ltd.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of the
9
* License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public
17
* License along with this program; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
21
* Authors: Xavier Claessens <xclaesse@gmail.com>
22
* Martyn Russell <martyn@imendio.com>
30
#include <glib/gi18n.h>
32
#include <libmissioncontrol/mc-account.h>
33
#include <libmissioncontrol/mc-protocol.h>
35
#include <libempathy/empathy-debug.h>
37
#include "empathy-account-widget.h"
38
#include "empathy-ui-utils.h"
40
#define DEBUG_DOMAIN "AccountWidget"
43
account_widget_entry_focus_cb (GtkWidget *widget,
48
const gchar *param_name;
50
str = gtk_entry_get_text (GTK_ENTRY (widget));
51
param_name = g_object_get_data (G_OBJECT (widget), "param_name");
53
if (G_STR_EMPTY (str)) {
56
mc_account_unset_param (account, param_name);
57
mc_account_get_param_string (account, param_name, &value);
58
empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %s", param_name, value);
59
gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
62
empathy_debug (DEBUG_DOMAIN, "Setting %s to %s", param_name, str);
63
mc_account_set_param_string (account, param_name, str);
70
account_widget_int_changed_cb (GtkWidget *widget,
73
const gchar *param_name;
76
value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
77
param_name = g_object_get_data (G_OBJECT (widget), "param_name");
80
mc_account_unset_param (account, param_name);
81
mc_account_get_param_int (account, param_name, &value);
82
empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %d", param_name, value);
83
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
85
empathy_debug (DEBUG_DOMAIN, "Setting %s to %d", param_name, value);
86
mc_account_set_param_int (account, param_name, value);
91
account_widget_checkbutton_toggled_cb (GtkWidget *widget,
95
gboolean default_value;
96
const gchar *param_name;
98
value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
99
param_name = g_object_get_data (G_OBJECT (widget), "param_name");
101
/* FIXME: This is ugly! checkbox don't have a "not-set" value so we
102
* always unset the param and set the value if different from the
104
mc_account_unset_param (account, param_name);
105
mc_account_get_param_boolean (account, param_name, &default_value);
107
if (default_value == value) {
108
empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %d", param_name, default_value);
110
empathy_debug (DEBUG_DOMAIN, "Setting %s to %d", param_name, value);
111
mc_account_set_param_boolean (account, param_name, value);
116
account_widget_forget_clicked_cb (GtkWidget *button,
120
const gchar *param_name;
122
param_name = g_object_get_data (G_OBJECT (entry), "param_name");
123
account = g_object_get_data (G_OBJECT (entry), "account");
125
empathy_debug (DEBUG_DOMAIN, "Unset %s", param_name);
126
mc_account_unset_param (account, param_name);
127
gtk_entry_set_text (GTK_ENTRY (entry), "");
131
account_widget_password_changed_cb (GtkWidget *entry,
136
str = gtk_entry_get_text (GTK_ENTRY (entry));
137
gtk_widget_set_sensitive (button, !G_STR_EMPTY (str));
141
account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
142
GtkWidget *spinbutton_port)
148
value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
149
account = g_object_get_data (G_OBJECT (spinbutton_port), "account");
150
mc_account_get_param_int (account, "port", &port);
153
if (port == 5222 || port == 0) {
157
if (port == 5223 || port == 0) {
162
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton_port), port);
166
account_widget_setup_widget (GtkWidget *widget,
168
const gchar *param_name)
170
g_object_set_data_full (G_OBJECT (widget), "param_name",
171
g_strdup (param_name), g_free);
172
g_object_set_data_full (G_OBJECT (widget), "account",
173
g_object_ref (account), g_object_unref);
175
if (GTK_IS_SPIN_BUTTON (widget)) {
178
mc_account_get_param_int (account, param_name, &value);
179
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
181
g_signal_connect (widget, "value-changed",
182
G_CALLBACK (account_widget_int_changed_cb),
185
else if (GTK_IS_ENTRY (widget)) {
188
mc_account_get_param_string (account, param_name, &str);
189
gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
192
if (strstr (param_name, "password")) {
193
gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
196
g_signal_connect (widget, "focus-out-event",
197
G_CALLBACK (account_widget_entry_focus_cb),
200
else if (GTK_IS_TOGGLE_BUTTON (widget)) {
201
gboolean value = FALSE;
203
mc_account_get_param_boolean (account, param_name, &value);
204
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
206
g_signal_connect (widget, "toggled",
207
G_CALLBACK (account_widget_checkbutton_toggled_cb),
210
empathy_debug (DEBUG_DOMAIN,
211
"Unknown type of widget for param %s",
217
account_widget_generic_format_param_name (const gchar *param_name)
222
str = g_strdup (param_name);
224
if (str && g_ascii_isalpha (str[0])) {
225
str[0] = g_ascii_toupper (str[0]);
228
while ((p = strchr (str, '-')) != NULL) {
229
if (p[1] != '\0' && g_ascii_isalpha (p[1])) {
231
p[1] = g_ascii_toupper (p[1]);
241
accounts_widget_generic_setup (McAccount *account,
242
GtkWidget *table_common_settings,
243
GtkWidget *table_advanced_settings)
245
McProtocol *protocol;
249
profile = mc_account_get_profile (account);
250
protocol = mc_profile_get_protocol (profile);
253
/* The CM is not installed, MC shouldn't list them
254
* see SF bug #1688779
255
* FIXME: We should display something asking the user to
258
g_object_unref (profile);
262
params = mc_protocol_get_params (protocol);
264
for (l = params; l; l = l->next) {
265
McProtocolParam *param;
266
GtkWidget *table_settings;
268
GtkWidget *widget = NULL;
269
gchar *param_name_formatted;
272
if (param->flags & MC_PROTOCOL_PARAM_REQUIRED) {
273
table_settings = table_common_settings;
275
table_settings = table_advanced_settings;
277
param_name_formatted = account_widget_generic_format_param_name (param->name);
278
g_object_get (table_settings, "n-rows", &n_rows, NULL);
279
gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
281
if (param->signature[0] == 's') {
284
str = g_strdup_printf (_("%s:"), param_name_formatted);
285
widget = gtk_label_new (str);
286
gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
289
gtk_table_attach (GTK_TABLE (table_settings),
296
widget = gtk_entry_new ();
297
gtk_table_attach (GTK_TABLE (table_settings),
301
GTK_FILL | GTK_EXPAND, 0,
304
/* int types: ynqiuxt. double type is 'd' */
305
else if (param->signature[0] == 'y' ||
306
param->signature[0] == 'n' ||
307
param->signature[0] == 'q' ||
308
param->signature[0] == 'i' ||
309
param->signature[0] == 'u' ||
310
param->signature[0] == 'x' ||
311
param->signature[0] == 't' ||
312
param->signature[0] == 'd') {
318
switch (param->signature[0]) {
319
case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
320
case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
321
case 'q': minint = 0; maxint = G_MAXUINT16; break;
322
case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
323
case 'u': minint = 0; maxint = G_MAXUINT32; break;
324
case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
325
case 't': minint = 0; maxint = G_MAXUINT64; break;
326
case 'd': minint = G_MININT32; maxint = G_MAXINT32; step = 0.1; break;
329
str = g_strdup_printf (_("%s:"), param_name_formatted);
330
widget = gtk_label_new (str);
331
gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
334
gtk_table_attach (GTK_TABLE (table_settings),
341
widget = gtk_spin_button_new_with_range (minint, maxint, step);
342
gtk_table_attach (GTK_TABLE (table_settings),
346
GTK_FILL | GTK_EXPAND, 0,
349
else if (param->signature[0] == 'b') {
350
widget = gtk_check_button_new_with_label (param_name_formatted);
351
gtk_table_attach (GTK_TABLE (table_settings),
355
GTK_FILL | GTK_EXPAND, 0,
358
empathy_debug (DEBUG_DOMAIN,
359
"Unknown signature for param %s: %s",
360
param_name_formatted, param->signature);
364
account_widget_setup_widget (widget, account, param->name);
367
g_free (param_name_formatted);
370
g_slist_free (params);
371
g_object_unref (profile);
372
g_object_unref (protocol);
376
account_widget_handle_params_valist (McAccount *account,
378
const gchar *first_widget_name,
382
const gchar *widget_name;
384
for (widget_name = first_widget_name; widget_name; widget_name = va_arg (args, gchar*)) {
385
const gchar *param_name;
387
param_name = va_arg (args, gchar*);
389
widget = glade_xml_get_widget (gui, widget_name);
392
g_warning ("Glade is missing widget '%s'.", widget_name);
396
account_widget_setup_widget (widget, account, param_name);
401
empathy_account_widget_handle_params (McAccount *account,
403
const gchar *first_widget_name,
408
g_return_if_fail (MC_IS_ACCOUNT (account));
410
va_start (args, first_widget_name);
411
account_widget_handle_params_valist (account, gui,
418
empathy_account_widget_add_forget_button (McAccount *account,
423
GtkWidget *button_forget;
424
GtkWidget *entry_password;
425
gchar *password = NULL;
427
button_forget = glade_xml_get_widget (glade, button);
428
entry_password = glade_xml_get_widget (glade, entry);
430
mc_account_get_param_string (account, "password", &password);
431
gtk_widget_set_sensitive (button_forget, !G_STR_EMPTY (password));
434
g_signal_connect (button_forget, "clicked",
435
G_CALLBACK (account_widget_forget_clicked_cb),
437
g_signal_connect (entry_password, "changed",
438
G_CALLBACK (account_widget_password_changed_cb),
443
empathy_account_widget_generic_new (McAccount *account)
447
GtkWidget *table_common_settings;
448
GtkWidget *table_advanced_settings;
450
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
452
glade = empathy_glade_get_file ("empathy-account-widget-generic.glade",
453
"vbox_generic_settings",
455
"vbox_generic_settings", &widget,
456
"table_common_settings", &table_common_settings,
457
"table_advanced_settings", &table_advanced_settings,
460
accounts_widget_generic_setup (account, table_common_settings, table_advanced_settings);
462
g_object_unref (glade);
464
gtk_widget_show_all (widget);
470
empathy_account_widget_salut_new (McAccount *account)
475
glade = empathy_glade_get_file ("empathy-account-widget-salut.glade",
476
"vbox_salut_settings",
478
"vbox_salut_settings", &widget,
481
empathy_account_widget_handle_params (account, glade,
482
"entry_published", "published-name",
483
"entry_nickname", "nickname",
484
"entry_first_name", "first-name",
485
"entry_last_name", "last-name",
486
"entry_email", "email",
490
g_object_unref (glade);
492
gtk_widget_show (widget);
498
empathy_account_widget_msn_new (McAccount *account)
503
glade = empathy_glade_get_file ("empathy-account-widget-msn.glade",
506
"vbox_msn_settings", &widget,
509
empathy_account_widget_handle_params (account, glade,
510
"entry_id", "account",
511
"entry_password", "password",
512
"entry_server", "server",
513
"spinbutton_port", "port",
516
empathy_account_widget_add_forget_button (account, glade,
520
g_object_unref (glade);
522
gtk_widget_show (widget);
528
empathy_account_widget_jabber_new (McAccount *account)
532
GtkWidget *spinbutton_port;
533
GtkWidget *checkbutton_ssl;
535
glade = empathy_glade_get_file ("empathy-account-widget-jabber.glade",
536
"vbox_jabber_settings",
538
"vbox_jabber_settings", &widget,
539
"spinbutton_port", &spinbutton_port,
540
"checkbutton_ssl", &checkbutton_ssl,
543
empathy_account_widget_handle_params (account, glade,
544
"entry_id", "account",
545
"entry_password", "password",
546
"entry_resource", "resource",
547
"entry_server", "server",
548
"spinbutton_port", "port",
549
"spinbutton_priority", "priority",
550
"checkbutton_ssl", "old-ssl",
551
"checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
552
"checkbutton_encryption", "require-encryption",
555
empathy_account_widget_add_forget_button (account, glade,
559
g_signal_connect (checkbutton_ssl, "toggled",
560
G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
563
g_object_unref (glade);
565
gtk_widget_show (widget);
571
empathy_account_widget_icq_new (McAccount *account)
575
GtkWidget *spinbutton_port;
577
glade = empathy_glade_get_file ("empathy-account-widget-icq.glade",
580
"vbox_icq_settings", &widget,
581
"spinbutton_port", &spinbutton_port,
584
empathy_account_widget_handle_params (account, glade,
585
"entry_uin", "account",
586
"entry_password", "password",
587
"entry_server", "server",
588
"spinbutton_port", "port",
589
"entry_charset", "charset",
592
empathy_account_widget_add_forget_button (account, glade,
596
g_object_unref (glade);
598
gtk_widget_show (widget);
604
empathy_account_widget_yahoo_new (McAccount *account)
609
glade = empathy_glade_get_file ("empathy-account-widget-yahoo.glade",
610
"vbox_yahoo_settings",
612
"vbox_yahoo_settings", &widget,
615
empathy_account_widget_handle_params (account, glade,
616
"entry_id", "account",
617
"entry_password", "password",
618
"entry_server", "server",
619
"entry_serverjp", "serverjp",
620
"entry_locale", "room-list-locale",
621
"entry_charset", "charset",
622
"spinbutton_port", "port",
623
"checkbutton_yahoojp", "yahoojp",
624
"checkbutton_ignore_invites", "ignore-invites",
627
empathy_account_widget_add_forget_button (account, glade,
631
g_object_unref (glade);
633
gtk_widget_show (widget);