From 91c325aabdb286f44729cb5ee7f69afd717dcca6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 27 Aug 2009 16:56:42 +0100 Subject: Base the selected widget both on the CM and the protocol Previously Empathy would select the custom account widget purely based on the protocol, the problem here is that these widgets assume one specific connection manager and its set of parameters. Which triggered bugs if the intended cm for a protocol isn't installed, but haze is and provides the protocol. --- libempathy-gtk/empathy-account-widget.c | 103 ++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 38 deletions(-) (limited to 'libempathy-gtk/empathy-account-widget.c') diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 5863d4980..801510043 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -738,6 +738,24 @@ account_widget_build_salut (EmpathyAccountWidget *self, self->ui_details->default_focus = g_strdup ("entry_nickname"); } +static void +account_widget_build_irc (EmpathyAccountWidget *self, + const char *filename) +{ + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + empathy_account_widget_irc_build (self, filename, + &priv->table_common_settings); +} + +static void +account_widget_build_sip (EmpathyAccountWidget *self, + const char *filename) +{ + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + empathy_account_widget_sip_build (self, filename, + &priv->table_common_settings); +} + static void account_widget_build_msn (EmpathyAccountWidget *self, const char *filename) @@ -1088,52 +1106,63 @@ do_get_property (GObject *object, } } +#define WIDGET(cm, proto) \ + { #cm, #proto, "empathy-account-widget-"#proto".ui", \ + account_widget_build_##proto } + static void do_constructed (GObject *obj) { EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); EmpathyAccountWidgetPriv *priv = GET_PRIV (self); EmpathyAccount *account; - char *uiname, *filename; - - uiname = g_strconcat ("empathy-account-widget-", priv->protocol, - ".ui", NULL); - filename = empathy_file_lookup (uiname, "libempathy-gtk"); - - if (!tp_strdiff (priv->protocol, "local-xmpp")) - account_widget_build_salut (self, filename); - else if (!tp_strdiff (priv->protocol, "msn")) - account_widget_build_msn (self, filename); - else if (!tp_strdiff (priv->protocol, "jabber")) - account_widget_build_jabber (self, filename); - else if (!tp_strdiff (priv->protocol, "icq")) - account_widget_build_icq (self, filename); - else if (!tp_strdiff (priv->protocol, "aim")) - account_widget_build_aim (self, filename); - else if (!tp_strdiff (priv->protocol, "yahoo")) - account_widget_build_yahoo (self, filename); - else if (!tp_strdiff (priv->protocol, "groupwise")) - account_widget_build_groupwise (self, filename); - else if (!tp_strdiff (priv->protocol, "irc")) - empathy_account_widget_irc_build (self, filename, - &priv->table_common_settings); - else if (!tp_strdiff (priv->protocol, "sip")) - empathy_account_widget_sip_build (self, filename, - &priv->table_common_settings); - else if (!tp_strdiff (priv->protocol, "generic")) - account_widget_build_generic (self, filename); - else + const gchar *protocol, *cm_name; + int i = 0; + struct { + const gchar *cm_name; + const gchar *protocol; + const char *file; + void (*func)(EmpathyAccountWidget *self, const gchar *filename); + } widgets [] = { + { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui", + account_widget_build_salut }, + WIDGET (gabble, jabber), + WIDGET (butterfly, msn), + WIDGET (haze, icq), + WIDGET (haze, aim), + WIDGET (haze, yahoo), + WIDGET (haze, groupwise), + WIDGET (idle, irc), + WIDGET (sofiasip, sip), + }; + + cm_name = empathy_account_settings_get_cm (priv->settings); + protocol = empathy_account_settings_get_protocol (priv->settings); + + for (i = 0 ; i < G_N_ELEMENTS (widgets); i++) { - g_free (filename); + if (!tp_strdiff (widgets[i].cm_name, cm_name) && + !tp_strdiff (widgets[i].protocol, protocol)) + { + gchar *filename; + + filename = empathy_file_lookup (widgets[i].file, + "libempathy-gtk"); + widgets[i].func (self, filename); + g_free (filename); + + break; + } + } - filename = empathy_file_lookup ( + if (i == G_N_ELEMENTS (widgets)) + { + gchar *filename = empathy_file_lookup ( "empathy-account-widget-generic.ui", "libempathy-gtk"); account_widget_build_generic (self, filename); + g_free (filename); } - g_free (uiname); - g_free (filename); - /* handle default focus */ if (self->ui_details->default_focus != NULL) { @@ -1383,17 +1412,15 @@ empathy_account_widget_get_widget (EmpathyAccountWidget *widget) } EmpathyAccountWidget * -empathy_account_widget_new_for_protocol (const char *protocol, - EmpathyAccountSettings *settings, +empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings, gboolean simple) { EmpathyAccountWidget *self; g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL); - g_return_val_if_fail (protocol != NULL, NULL); self = g_object_new - (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol, + (EMPATHY_TYPE_ACCOUNT_WIDGET, "settings", settings, "simple", simple, "creating-account", empathy_account_settings_get_account (settings) == NULL, -- cgit v1.2.3