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-utils.h>
37 #include "empathy-account-widget.h"
38 #include "empathy-ui-utils.h"
40 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
41 #include <libempathy/empathy-debug.h>
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 DEBUG ("Unset %s and restore to %s", param_name, value);
60 gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
63 DEBUG ("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 DEBUG ("Unset %s and restore to %d", param_name, value);
85 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
87 DEBUG ("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 DEBUG ("Unset %s and restore to %d", param_name, default_value);
112 DEBUG ("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 DEBUG ("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 DEBUG ("Unknown type of widget for param %s", param_name);
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 DEBUG ("Unknown signature for param %s: %s",
359 param_name_formatted, param->signature);
363 account_widget_setup_widget (widget, account, param->name);
366 g_free (param_name_formatted);
369 g_slist_free (params);
370 g_object_unref (profile);
371 g_object_unref (protocol);
375 account_widget_handle_params_valist (McAccount *account,
377 const gchar *first_widget_name,
381 const gchar *widget_name;
383 for (widget_name = first_widget_name; widget_name; widget_name = va_arg (args, gchar*)) {
384 const gchar *param_name;
386 param_name = va_arg (args, gchar*);
388 widget = glade_xml_get_widget (gui, widget_name);
391 g_warning ("Glade is missing widget '%s'.", widget_name);
395 account_widget_setup_widget (widget, account, param_name);
400 empathy_account_widget_handle_params (McAccount *account,
402 const gchar *first_widget_name,
407 g_return_if_fail (MC_IS_ACCOUNT (account));
409 va_start (args, first_widget_name);
410 account_widget_handle_params_valist (account, gui,
417 empathy_account_widget_add_forget_button (McAccount *account,
422 GtkWidget *button_forget;
423 GtkWidget *entry_password;
424 gchar *password = NULL;
426 button_forget = glade_xml_get_widget (glade, button);
427 entry_password = glade_xml_get_widget (glade, entry);
429 mc_account_get_param_string (account, "password", &password);
430 gtk_widget_set_sensitive (button_forget, !G_STR_EMPTY (password));
433 g_signal_connect (button_forget, "clicked",
434 G_CALLBACK (account_widget_forget_clicked_cb),
436 g_signal_connect (entry_password, "changed",
437 G_CALLBACK (account_widget_password_changed_cb),
442 empathy_account_widget_generic_new (McAccount *account)
446 GtkWidget *table_common_settings;
447 GtkWidget *table_advanced_settings;
450 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
452 filename = empathy_file_lookup ("empathy-account-widget-generic.glade",
454 glade = empathy_glade_get_file (filename,
455 "vbox_generic_settings",
457 "vbox_generic_settings", &widget,
458 "table_common_settings", &table_common_settings,
459 "table_advanced_settings", &table_advanced_settings,
463 accounts_widget_generic_setup (account, table_common_settings, table_advanced_settings);
465 g_object_unref (glade);
467 gtk_widget_show_all (widget);
473 empathy_account_widget_salut_new (McAccount *account)
479 filename = empathy_file_lookup ("empathy-account-widget-salut.glade",
481 glade = empathy_glade_get_file (filename,
482 "vbox_salut_settings",
484 "vbox_salut_settings", &widget,
488 empathy_account_widget_handle_params (account, glade,
489 "entry_published", "published-name",
490 "entry_nickname", "nickname",
491 "entry_first_name", "first-name",
492 "entry_last_name", "last-name",
493 "entry_email", "email",
497 g_object_unref (glade);
499 gtk_widget_show (widget);
505 empathy_account_widget_msn_new (McAccount *account)
511 filename = empathy_file_lookup ("empathy-account-widget-msn.glade",
513 glade = empathy_glade_get_file (filename,
516 "vbox_msn_settings", &widget,
520 empathy_account_widget_handle_params (account, glade,
521 "entry_id", "account",
522 "entry_password", "password",
523 "entry_server", "server",
524 "spinbutton_port", "port",
527 empathy_account_widget_add_forget_button (account, glade,
531 g_object_unref (glade);
533 gtk_widget_show (widget);
539 empathy_account_widget_jabber_new (McAccount *account)
543 GtkWidget *spinbutton_port;
544 GtkWidget *checkbutton_ssl;
547 filename = empathy_file_lookup ("empathy-account-widget-jabber.glade",
549 glade = empathy_glade_get_file (filename,
550 "vbox_jabber_settings",
552 "vbox_jabber_settings", &widget,
553 "spinbutton_port", &spinbutton_port,
554 "checkbutton_ssl", &checkbutton_ssl,
558 empathy_account_widget_handle_params (account, glade,
559 "entry_id", "account",
560 "entry_password", "password",
561 "entry_resource", "resource",
562 "entry_server", "server",
563 "spinbutton_port", "port",
564 "spinbutton_priority", "priority",
565 "checkbutton_ssl", "old-ssl",
566 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
567 "checkbutton_encryption", "require-encryption",
570 empathy_account_widget_add_forget_button (account, glade,
574 g_signal_connect (checkbutton_ssl, "toggled",
575 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
578 g_object_unref (glade);
580 gtk_widget_show (widget);
586 empathy_account_widget_icq_new (McAccount *account)
590 GtkWidget *spinbutton_port;
593 filename = empathy_file_lookup ("empathy-account-widget-icq.glade",
595 glade = empathy_glade_get_file (filename,
598 "vbox_icq_settings", &widget,
599 "spinbutton_port", &spinbutton_port,
603 empathy_account_widget_handle_params (account, glade,
604 "entry_uin", "account",
605 "entry_password", "password",
606 "entry_server", "server",
607 "spinbutton_port", "port",
608 "entry_charset", "charset",
611 empathy_account_widget_add_forget_button (account, glade,
615 g_object_unref (glade);
617 gtk_widget_show (widget);
623 empathy_account_widget_aim_new (McAccount *account)
627 GtkWidget *spinbutton_port;
630 filename = empathy_file_lookup ("empathy-account-widget-aim.glade",
632 glade = empathy_glade_get_file (filename,
635 "vbox_aim_settings", &widget,
636 "spinbutton_port", &spinbutton_port,
640 empathy_account_widget_handle_params (account, glade,
641 "entry_screenname", "account",
642 "entry_password", "password",
643 "entry_server", "server",
644 "spinbutton_port", "port",
647 empathy_account_widget_add_forget_button (account, glade,
651 g_object_unref (glade);
653 gtk_widget_show (widget);
659 empathy_account_widget_yahoo_new (McAccount *account)
665 filename = empathy_file_lookup ("empathy-account-widget-yahoo.glade",
667 glade = empathy_glade_get_file (filename,
668 "vbox_yahoo_settings",
670 "vbox_yahoo_settings", &widget,
674 empathy_account_widget_handle_params (account, glade,
675 "entry_id", "account",
676 "entry_password", "password",
677 "entry_server", "server",
678 "entry_serverjp", "serverjp",
679 "entry_locale", "room-list-locale",
680 "entry_charset", "charset",
681 "spinbutton_port", "port",
682 "checkbutton_yahoojp", "yahoojp",
683 "checkbutton_ignore_invites", "ignore-invites",
686 empathy_account_widget_add_forget_button (account, glade,
690 g_object_unref (glade);
692 gtk_widget_show (widget);
698 empathy_account_widget_groupwise_new (McAccount *account)
704 filename = empathy_file_lookup ("empathy-account-widget-groupwise.glade",
706 glade = empathy_glade_get_file (filename,
707 "vbox_groupwise_settings",
709 "vbox_groupwise_settings", &widget,
713 empathy_account_widget_handle_params (account, glade,
714 "entry_id", "account",
715 "entry_password", "password",
716 "entry_server", "server",
717 "spinbutton_port", "port",
720 empathy_account_widget_add_forget_button (account, glade,
724 g_object_unref (glade);
726 gtk_widget_show (widget);