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>
36 #include <libempathy/empathy-utils.h>
38 #include "empathy-account-widget.h"
39 #include "empathy-ui-utils.h"
41 #define DEBUG_DOMAIN "AccountWidget"
44 account_widget_entry_focus_cb (GtkWidget *widget,
49 const gchar *param_name;
51 str = gtk_entry_get_text (GTK_ENTRY (widget));
52 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
54 if (G_STR_EMPTY (str)) {
57 mc_account_unset_param (account, param_name);
58 mc_account_get_param_string (account, param_name, &value);
59 empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %s", param_name, value);
60 gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
63 empathy_debug (DEBUG_DOMAIN, "Setting %s to %s", param_name,
64 strstr (param_name, "password") ? "***" : str);
65 mc_account_set_param_string (account, param_name, str);
72 account_widget_int_changed_cb (GtkWidget *widget,
75 const gchar *param_name;
78 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
79 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
82 mc_account_unset_param (account, param_name);
83 mc_account_get_param_int (account, param_name, &value);
84 empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %d", param_name, value);
85 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
87 empathy_debug (DEBUG_DOMAIN, "Setting %s to %d", param_name, value);
88 mc_account_set_param_int (account, param_name, value);
93 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
97 gboolean default_value;
98 const gchar *param_name;
100 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
101 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
103 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
104 * always unset the param and set the value if different from the
106 mc_account_unset_param (account, param_name);
107 mc_account_get_param_boolean (account, param_name, &default_value);
109 if (default_value == value) {
110 empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %d", param_name, default_value);
112 empathy_debug (DEBUG_DOMAIN, "Setting %s to %d", param_name, value);
113 mc_account_set_param_boolean (account, param_name, value);
118 account_widget_forget_clicked_cb (GtkWidget *button,
122 const gchar *param_name;
124 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
125 account = g_object_get_data (G_OBJECT (entry), "account");
127 empathy_debug (DEBUG_DOMAIN, "Unset %s", param_name);
128 mc_account_unset_param (account, param_name);
129 gtk_entry_set_text (GTK_ENTRY (entry), "");
133 account_widget_password_changed_cb (GtkWidget *entry,
138 str = gtk_entry_get_text (GTK_ENTRY (entry));
139 gtk_widget_set_sensitive (button, !G_STR_EMPTY (str));
143 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
144 GtkWidget *spinbutton_port)
150 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
151 account = g_object_get_data (G_OBJECT (spinbutton_port), "account");
152 mc_account_get_param_int (account, "port", &port);
155 if (port == 5222 || port == 0) {
159 if (port == 5223 || port == 0) {
164 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton_port), port);
168 account_widget_setup_widget (GtkWidget *widget,
170 const gchar *param_name)
172 g_object_set_data_full (G_OBJECT (widget), "param_name",
173 g_strdup (param_name), g_free);
174 g_object_set_data_full (G_OBJECT (widget), "account",
175 g_object_ref (account), g_object_unref);
177 if (GTK_IS_SPIN_BUTTON (widget)) {
180 mc_account_get_param_int (account, param_name, &value);
181 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
183 g_signal_connect (widget, "value-changed",
184 G_CALLBACK (account_widget_int_changed_cb),
187 else if (GTK_IS_ENTRY (widget)) {
190 mc_account_get_param_string (account, param_name, &str);
191 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
194 if (strstr (param_name, "password")) {
195 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
198 g_signal_connect (widget, "focus-out-event",
199 G_CALLBACK (account_widget_entry_focus_cb),
202 else if (GTK_IS_TOGGLE_BUTTON (widget)) {
203 gboolean value = FALSE;
205 mc_account_get_param_boolean (account, param_name, &value);
206 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
208 g_signal_connect (widget, "toggled",
209 G_CALLBACK (account_widget_checkbutton_toggled_cb),
212 empathy_debug (DEBUG_DOMAIN,
213 "Unknown type of widget for param %s",
219 account_widget_generic_format_param_name (const gchar *param_name)
224 str = g_strdup (param_name);
226 if (str && g_ascii_isalpha (str[0])) {
227 str[0] = g_ascii_toupper (str[0]);
230 while ((p = strchr (str, '-')) != NULL) {
231 if (p[1] != '\0' && g_ascii_isalpha (p[1])) {
233 p[1] = g_ascii_toupper (p[1]);
243 accounts_widget_generic_setup (McAccount *account,
244 GtkWidget *table_common_settings,
245 GtkWidget *table_advanced_settings)
247 McProtocol *protocol;
251 profile = mc_account_get_profile (account);
252 protocol = mc_profile_get_protocol (profile);
255 /* The CM is not installed, MC shouldn't list them
256 * see SF bug #1688779
257 * FIXME: We should display something asking the user to
260 g_object_unref (profile);
264 params = mc_protocol_get_params (protocol);
266 for (l = params; l; l = l->next) {
267 McProtocolParam *param;
268 GtkWidget *table_settings;
270 GtkWidget *widget = NULL;
271 gchar *param_name_formatted;
274 if (param->flags & MC_PROTOCOL_PARAM_REQUIRED) {
275 table_settings = table_common_settings;
277 table_settings = table_advanced_settings;
279 param_name_formatted = account_widget_generic_format_param_name (param->name);
280 g_object_get (table_settings, "n-rows", &n_rows, NULL);
281 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
283 if (param->signature[0] == 's') {
286 str = g_strdup_printf (_("%s:"), param_name_formatted);
287 widget = gtk_label_new (str);
288 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
291 gtk_table_attach (GTK_TABLE (table_settings),
298 widget = gtk_entry_new ();
299 gtk_table_attach (GTK_TABLE (table_settings),
303 GTK_FILL | GTK_EXPAND, 0,
306 /* int types: ynqiuxt. double type is 'd' */
307 else if (param->signature[0] == 'y' ||
308 param->signature[0] == 'n' ||
309 param->signature[0] == 'q' ||
310 param->signature[0] == 'i' ||
311 param->signature[0] == 'u' ||
312 param->signature[0] == 'x' ||
313 param->signature[0] == 't' ||
314 param->signature[0] == 'd') {
320 switch (param->signature[0]) {
321 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
322 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
323 case 'q': minint = 0; maxint = G_MAXUINT16; break;
324 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
325 case 'u': minint = 0; maxint = G_MAXUINT32; break;
326 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
327 case 't': minint = 0; maxint = G_MAXUINT64; break;
328 case 'd': minint = G_MININT32; maxint = G_MAXINT32; step = 0.1; break;
331 str = g_strdup_printf (_("%s:"), param_name_formatted);
332 widget = gtk_label_new (str);
333 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
336 gtk_table_attach (GTK_TABLE (table_settings),
343 widget = gtk_spin_button_new_with_range (minint, maxint, step);
344 gtk_table_attach (GTK_TABLE (table_settings),
348 GTK_FILL | GTK_EXPAND, 0,
351 else if (param->signature[0] == 'b') {
352 widget = gtk_check_button_new_with_label (param_name_formatted);
353 gtk_table_attach (GTK_TABLE (table_settings),
357 GTK_FILL | GTK_EXPAND, 0,
360 empathy_debug (DEBUG_DOMAIN,
361 "Unknown signature for param %s: %s",
362 param_name_formatted, param->signature);
366 account_widget_setup_widget (widget, account, param->name);
369 g_free (param_name_formatted);
372 g_slist_free (params);
373 g_object_unref (profile);
374 g_object_unref (protocol);
378 account_widget_handle_params_valist (McAccount *account,
380 const gchar *first_widget_name,
384 const gchar *widget_name;
386 for (widget_name = first_widget_name; widget_name; widget_name = va_arg (args, gchar*)) {
387 const gchar *param_name;
389 param_name = va_arg (args, gchar*);
391 widget = glade_xml_get_widget (gui, widget_name);
394 g_warning ("Glade is missing widget '%s'.", widget_name);
398 account_widget_setup_widget (widget, account, param_name);
403 empathy_account_widget_handle_params (McAccount *account,
405 const gchar *first_widget_name,
410 g_return_if_fail (MC_IS_ACCOUNT (account));
412 va_start (args, first_widget_name);
413 account_widget_handle_params_valist (account, gui,
420 empathy_account_widget_add_forget_button (McAccount *account,
425 GtkWidget *button_forget;
426 GtkWidget *entry_password;
427 gchar *password = NULL;
429 button_forget = glade_xml_get_widget (glade, button);
430 entry_password = glade_xml_get_widget (glade, entry);
432 mc_account_get_param_string (account, "password", &password);
433 gtk_widget_set_sensitive (button_forget, !G_STR_EMPTY (password));
436 g_signal_connect (button_forget, "clicked",
437 G_CALLBACK (account_widget_forget_clicked_cb),
439 g_signal_connect (entry_password, "changed",
440 G_CALLBACK (account_widget_password_changed_cb),
445 empathy_account_widget_generic_new (McAccount *account)
449 GtkWidget *table_common_settings;
450 GtkWidget *table_advanced_settings;
453 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
455 filename = empathy_file_lookup ("empathy-account-widget-generic.glade",
457 glade = empathy_glade_get_file (filename,
458 "vbox_generic_settings",
460 "vbox_generic_settings", &widget,
461 "table_common_settings", &table_common_settings,
462 "table_advanced_settings", &table_advanced_settings,
466 accounts_widget_generic_setup (account, table_common_settings, table_advanced_settings);
468 g_object_unref (glade);
470 gtk_widget_show_all (widget);
476 empathy_account_widget_salut_new (McAccount *account)
482 filename = empathy_file_lookup ("empathy-account-widget-salut.glade",
484 glade = empathy_glade_get_file (filename,
485 "vbox_salut_settings",
487 "vbox_salut_settings", &widget,
491 empathy_account_widget_handle_params (account, glade,
492 "entry_published", "published-name",
493 "entry_nickname", "nickname",
494 "entry_first_name", "first-name",
495 "entry_last_name", "last-name",
496 "entry_email", "email",
500 g_object_unref (glade);
502 gtk_widget_show (widget);
508 empathy_account_widget_msn_new (McAccount *account)
514 filename = empathy_file_lookup ("empathy-account-widget-msn.glade",
516 glade = empathy_glade_get_file (filename,
519 "vbox_msn_settings", &widget,
523 empathy_account_widget_handle_params (account, glade,
524 "entry_id", "account",
525 "entry_password", "password",
526 "entry_server", "server",
527 "spinbutton_port", "port",
530 empathy_account_widget_add_forget_button (account, glade,
534 g_object_unref (glade);
536 gtk_widget_show (widget);
542 empathy_account_widget_jabber_new (McAccount *account)
546 GtkWidget *spinbutton_port;
547 GtkWidget *checkbutton_ssl;
550 filename = empathy_file_lookup ("empathy-account-widget-jabber.glade",
552 glade = empathy_glade_get_file (filename,
553 "vbox_jabber_settings",
555 "vbox_jabber_settings", &widget,
556 "spinbutton_port", &spinbutton_port,
557 "checkbutton_ssl", &checkbutton_ssl,
561 empathy_account_widget_handle_params (account, glade,
562 "entry_id", "account",
563 "entry_password", "password",
564 "entry_resource", "resource",
565 "entry_server", "server",
566 "spinbutton_port", "port",
567 "spinbutton_priority", "priority",
568 "checkbutton_ssl", "old-ssl",
569 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
570 "checkbutton_encryption", "require-encryption",
573 empathy_account_widget_add_forget_button (account, glade,
577 g_signal_connect (checkbutton_ssl, "toggled",
578 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
581 g_object_unref (glade);
583 gtk_widget_show (widget);
589 empathy_account_widget_icq_new (McAccount *account)
593 GtkWidget *spinbutton_port;
596 filename = empathy_file_lookup ("empathy-account-widget-icq.glade",
598 glade = empathy_glade_get_file (filename,
601 "vbox_icq_settings", &widget,
602 "spinbutton_port", &spinbutton_port,
606 empathy_account_widget_handle_params (account, glade,
607 "entry_uin", "account",
608 "entry_password", "password",
609 "entry_server", "server",
610 "spinbutton_port", "port",
611 "entry_charset", "charset",
614 empathy_account_widget_add_forget_button (account, glade,
618 g_object_unref (glade);
620 gtk_widget_show (widget);
626 empathy_account_widget_aim_new (McAccount *account)
630 GtkWidget *spinbutton_port;
633 filename = empathy_file_lookup ("empathy-account-widget-aim.glade",
635 glade = empathy_glade_get_file (filename,
638 "vbox_aim_settings", &widget,
639 "spinbutton_port", &spinbutton_port,
643 empathy_account_widget_handle_params (account, glade,
644 "entry_screenname", "account",
645 "entry_password", "password",
646 "entry_server", "server",
647 "spinbutton_port", "port",
650 empathy_account_widget_add_forget_button (account, glade,
654 g_object_unref (glade);
656 gtk_widget_show (widget);
662 empathy_account_widget_yahoo_new (McAccount *account)
668 filename = empathy_file_lookup ("empathy-account-widget-yahoo.glade",
670 glade = empathy_glade_get_file (filename,
671 "vbox_yahoo_settings",
673 "vbox_yahoo_settings", &widget,
677 empathy_account_widget_handle_params (account, glade,
678 "entry_id", "account",
679 "entry_password", "password",
680 "entry_server", "server",
681 "entry_serverjp", "serverjp",
682 "entry_locale", "room-list-locale",
683 "entry_charset", "charset",
684 "spinbutton_port", "port",
685 "checkbutton_yahoojp", "yahoojp",
686 "checkbutton_ignore_invites", "ignore-invites",
689 empathy_account_widget_add_forget_button (account, glade,
693 g_object_unref (glade);
695 gtk_widget_show (widget);
701 empathy_account_widget_groupwise_new (McAccount *account)
707 filename = empathy_file_lookup ("empathy-account-widget-groupwise.glade",
709 glade = empathy_glade_get_file (filename,
710 "vbox_groupwise_settings",
712 "vbox_groupwise_settings", &widget,
716 empathy_account_widget_handle_params (account, glade,
717 "entry_id", "account",
718 "entry_password", "password",
719 "entry_server", "server",
720 "spinbutton_port", "port",
723 empathy_account_widget_add_forget_button (account, glade,
727 g_object_unref (glade);
729 gtk_widget_show (widget);