static gboolean
account_widget_entry_focus_cb (GtkWidget     *widget,
			       GdkEventFocus *event,
			       McAccount     *account)
{
	const gchar *str;
	const gchar *param_name;

	str = gtk_entry_get_text (GTK_ENTRY (widget));
	param_name = g_object_get_data (G_OBJECT (widget), "param_name");

	if (EMP_STR_EMPTY (str)) {
		gchar *value = NULL;

		mc_account_unset_param (account, param_name);
		mc_account_get_param_string (account, param_name, &value);
		DEBUG ("Unset %s and restore to %s", param_name, value);
		gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
		g_free (value);
	} else {
		McProfile   *profile;
		const gchar *domain = NULL;
		gchar       *dup_str = NULL;

		profile = mc_account_get_profile (account);
		if (mc_profile_get_capabilities (profile) &
		    MC_PROFILE_CAPABILITY_SPLIT_ACCOUNT) {
			domain = mc_profile_get_default_account_domain (profile);
		}

		if (domain && !strstr (str, "@") &&
		    strcmp (param_name, "account") == 0) {
			DEBUG ("Adding @%s suffix to account", domain);
			str = dup_str = g_strconcat (str, "@", domain, NULL);
			gtk_entry_set_text (GTK_ENTRY (widget), str);
		}
		DEBUG ("Setting %s to %s", param_name,
			strstr (param_name, "password") ? "***" : str);
		mc_account_set_param_string (account, param_name, str);
		g_free (dup_str);
		g_object_unref (profile);
	}

	return FALSE;
}
static void
new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
{
	EmpathyAccountChooser *account_chooser;
	McAccount             *account;
	McProfile             *profile;
	const gchar           *protocol;
	const gchar           *room;
	
	account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
	account = empathy_account_chooser_get_account (account_chooser);
	profile = mc_account_get_profile (account);
	protocol = mc_profile_get_protocol_name (profile);

	gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), "");

	/* hardcode here known protocols */
	if (strcmp (protocol, "jabber") == 0) {
		gtk_widget_set_sensitive (dialog->entry_server, TRUE);
		gtk_widget_show (dialog->vbox_browse);

	}
	else if (strcmp (protocol, "local-xmpp") == 0) {
		gtk_widget_set_sensitive (dialog->entry_server, FALSE);
		gtk_widget_show (dialog->vbox_browse);		
	}
	else if (strcmp (protocol, "irc") == 0) {
		gtk_widget_set_sensitive (dialog->entry_server, FALSE);
		gtk_widget_show (dialog->vbox_browse);		
	} else {
		gtk_widget_set_sensitive (dialog->entry_server, TRUE);
		gtk_widget_show (dialog->vbox_browse);
	}

	room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
	gtk_widget_set_sensitive (dialog->button_join, !EMP_STR_EMPTY (room));

	/* Final set up of the dialog */
	gtk_widget_grab_focus (dialog->entry_room);

	g_object_unref (account);
	g_object_unref (profile);
}
static void
accounts_widget_generic_setup (McAccount *account,
			       GtkWidget *table_common_settings,
			       GtkWidget *table_advanced_settings)
{
	McProtocol *protocol;
	McProfile  *profile;
	GSList     *params, *l;

	profile = mc_account_get_profile (account);
	protocol = mc_profile_get_protocol (profile);

	if (!protocol) {
		/* The CM is not installed, MC shouldn't list them
		 * see SF bug #1688779
		 * FIXME: We should display something asking the user to
		 * install the CM
		 */
		g_object_unref (profile);
		return;
	}

	params = mc_protocol_get_params (protocol);

	for (l = params; l; l = l->next) {
		McProtocolParam *param;
		GtkWidget       *table_settings;
		guint            n_rows = 0;
		GtkWidget       *widget = NULL;
		gchar           *param_name_formatted;

		param = l->data;
		if (param->flags & MC_PROTOCOL_PARAM_REQUIRED) {
			table_settings = table_common_settings;
		} else {
			table_settings = table_advanced_settings;
		}
		param_name_formatted = account_widget_generic_format_param_name (param->name);
		g_object_get (table_settings, "n-rows", &n_rows, NULL);
		gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);

		if (param->signature[0] == 's') {
			gchar *str;

			str = g_strdup_printf (_("%s:"), param_name_formatted);
			widget = gtk_label_new (str);
			gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
			g_free (str);

			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  0, 1,
					  n_rows - 1, n_rows,
					  GTK_FILL, 0,
					  0, 0);
			gtk_widget_show (widget);

			widget = gtk_entry_new ();
			if (strcmp (param->name, "account") == 0) {
				g_signal_connect (widget, "realize",
						  G_CALLBACK (account_widget_default_entry_realized_cb),
						  NULL);
			}
			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  1, 2,
					  n_rows - 1, n_rows,
					  GTK_FILL | GTK_EXPAND, 0,
					  0, 0);
			gtk_widget_show (widget);
		}
		/* int types: ynqiuxt. double type is 'd' */
		else if (param->signature[0] == 'y' ||
			 param->signature[0] == 'n' ||
			 param->signature[0] == 'q' ||
			 param->signature[0] == 'i' ||
			 param->signature[0] == 'u' ||
			 param->signature[0] == 'x' ||
			 param->signature[0] == 't' ||
			 param->signature[0] == 'd') {
			gchar   *str = NULL;
			gdouble  minint = 0;
			gdouble  maxint = 0;
			gdouble  step = 1;

			switch (param->signature[0]) {
			case 'y': minint = G_MININT8;  maxint = G_MAXINT8;   break;
			case 'n': minint = G_MININT16; maxint = G_MAXINT16;  break;
			case 'q': minint = 0;          maxint = G_MAXUINT16; break;
			case 'i': minint = G_MININT32; maxint = G_MAXINT32;  break;
			case 'u': minint = 0;          maxint = G_MAXUINT32; break;
			case 'x': minint = G_MININT64; maxint = G_MAXINT64;  break;
			case 't': minint = 0;          maxint = G_MAXUINT64; break;
			case 'd': minint = G_MININT32; maxint = G_MAXINT32; step = 0.1; break;
			}

			str = g_strdup_printf (_("%s:"), param_name_formatted);
			widget = gtk_label_new (str);
			gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
			g_free (str);

			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  0, 1,
					  n_rows - 1, n_rows,
					  GTK_FILL, 0,
					  0, 0);
			gtk_widget_show (widget);

			widget = gtk_spin_button_new_with_range (minint, maxint, step);
			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  1, 2,
					  n_rows - 1, n_rows,
					  GTK_FILL | GTK_EXPAND, 0,
					  0, 0);
			gtk_widget_show (widget);
		}
		else if (param->signature[0] == 'b') {
			widget = gtk_check_button_new_with_label (param_name_formatted);
			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  0, 2,
					  n_rows - 1, n_rows,
					  GTK_FILL | GTK_EXPAND, 0,
					  0, 0);
			gtk_widget_show (widget);
		} else {
			DEBUG ("Unknown signature for param %s: %s",
				param_name_formatted, param->signature);
		}

		if (widget) {
			account_widget_setup_widget (widget, account, param->name);
		}

		g_free (param_name_formatted);
	}

	g_slist_free (params);
	g_object_unref (profile);
	g_object_unref (protocol);
}