From 2d517a8bf5f8048a83d753fb0977d4949cbdeb7a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 5 Jul 2009 13:08:11 +0100 Subject: [PATCH] Remove usage of McProfiles --- libempathy-gtk/empathy-account-widget.c | 140 +++++++++++++----------- libempathy-gtk/empathy-theme-adium.c | 5 +- src/empathy-accounts-dialog.c | 95 +++++++--------- src/empathy-new-chatroom-dialog.c | 5 +- 4 files changed, 117 insertions(+), 128 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index f602cd8b..8b71e3ff 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -29,11 +29,11 @@ #include #include -#include - #include #include +#include + #include "empathy-account-widget.h" #include "empathy-ui-utils.h" @@ -60,27 +60,9 @@ account_widget_entry_focus_cb (GtkWidget *widget, gtk_entry_set_text (GTK_ENTRY (widget), value ? value : ""); g_free (value); } else { - McProfile *profile; - const gchar *domain = NULL; - gchar *dup_str = NULL; - - profile = empathy_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); empathy_account_set_param_string (account, param_name, str); - g_free (dup_str); - g_object_unref (profile); } return FALSE; @@ -257,37 +239,19 @@ account_widget_generic_format_param_name (const gchar *param_name) static void accounts_widget_generic_setup (EmpathyAccount *account, + TpConnectionManagerParam *params, GtkWidget *table_common_settings, GtkWidget *table_advanced_settings) { - McProtocol *protocol; - McProfile *profile; - GSList *params, *l; - - profile = empathy_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; - } + TpConnectionManagerParam *param; - params = mc_protocol_get_params (protocol); - - for (l = params; l; l = l->next) { - McProtocolParam *param; + for (param = params; param != NULL; 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) { + if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED) { table_settings = table_common_settings; } else { table_settings = table_advanced_settings; @@ -296,7 +260,7 @@ accounts_widget_generic_setup (EmpathyAccount *account, 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') { + if (param->dbus_signature[0] == 's') { gchar *str; str = g_strdup_printf (_("%s:"), param_name_formatted); @@ -327,20 +291,20 @@ accounts_widget_generic_setup (EmpathyAccount *account, 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') { + else if (param->dbus_signature[0] == 'y' || + param->dbus_signature[0] == 'n' || + param->dbus_signature[0] == 'q' || + param->dbus_signature[0] == 'i' || + param->dbus_signature[0] == 'u' || + param->dbus_signature[0] == 'x' || + param->dbus_signature[0] == 't' || + param->dbus_signature[0] == 'd') { gchar *str = NULL; gdouble minint = 0; gdouble maxint = 0; gdouble step = 1; - switch (param->signature[0]) { + switch (param->dbus_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; @@ -373,7 +337,7 @@ accounts_widget_generic_setup (EmpathyAccount *account, 0, 0); gtk_widget_show (widget); } - else if (param->signature[0] == 'b') { + else if (param->dbus_signature[0] == 'b') { widget = gtk_check_button_new_with_label (param_name_formatted); gtk_table_attach (GTK_TABLE (table_settings), widget, @@ -384,7 +348,7 @@ accounts_widget_generic_setup (EmpathyAccount *account, gtk_widget_show (widget); } else { DEBUG ("Unknown signature for param %s: %s", - param_name_formatted, param->signature); + param_name_formatted, param->dbus_signature); } if (widget) { @@ -393,10 +357,6 @@ accounts_widget_generic_setup (EmpathyAccount *account, g_free (param_name_formatted); } - - g_slist_free (params); - g_object_unref (profile); - g_object_unref (protocol); } static void @@ -475,27 +435,77 @@ empathy_account_widget_set_default_focus (GtkBuilder *gui, NULL); } +static void +account_widget_tp_cm_ready_cb (TpConnectionManager *cm, const GError *error, + gpointer user_data, GObject *weak_object) +{ + GtkBuilder *builder; + EmpathyAccount *account; + GtkWidget *table_common_settings; + GtkWidget *table_advanced_settings; + const TpConnectionManagerProtocol *protocol; + + if (error != NULL) { + DEBUG ("CM wasn't happy: %s", error->message); + return; + } + + account = EMPATHY_ACCOUNT (user_data); + builder = GTK_BUILDER (weak_object); + + table_common_settings = GTK_WIDGET (gtk_builder_get_object (builder, + "table_common_settings")); + table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (builder, + "table_advanced_settings")); + + protocol = tp_connection_manager_get_protocol (cm, + empathy_account_get_protocol (account)); + + accounts_widget_generic_setup (account, protocol->params, + table_common_settings, table_advanced_settings); +} + GtkWidget * empathy_account_widget_generic_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; - GtkWidget *table_common_settings; - GtkWidget *table_advanced_settings; gchar *filename; filename = empathy_file_lookup ("empathy-account-widget-generic.ui", "libempathy-gtk"); gui = empathy_builder_get_file (filename, "vbox_generic_settings", &widget, - "table_common_settings", &table_common_settings, - "table_advanced_settings", &table_advanced_settings, NULL); - g_free (filename); - accounts_widget_generic_setup (account, table_common_settings, table_advanced_settings); + /* If the profile isn't installed get_protocol will return NULL with MC4 */ + if (empathy_account_get_protocol (account) != NULL) { + TpDBusDaemon *dbus; + TpConnectionManager *cm; + GError *error; - return empathy_builder_unref_and_keep_widget (gui, widget); + dbus = tp_dbus_daemon_dup (NULL); + + cm = tp_connection_manager_new (dbus, + empathy_account_get_connection_manager (account), NULL, &error); + + if (cm == NULL) { + DEBUG ("failed to get the cm: %s", error->message); + g_error_free (error); + g_object_unref (gui); + return NULL; + } + + tp_connection_manager_call_when_ready (cm, account_widget_tp_cm_ready_cb, + account, g_object_unref, G_OBJECT (gui)); + + g_object_unref (dbus); + } else { + /* no protocol information available :(( */ + return empathy_builder_unref_and_keep_widget (gui, widget); + } + + return g_object_ref (widget); } GtkWidget * diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 1f1b3b06..ca0599e0 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -348,7 +348,6 @@ theme_adium_append_html (EmpathyThemeAdium *theme, } else if (theme_adium_match (&cur, "%time")) { gchar *format = NULL; gchar *end; - /* Time can be in 2 formats: * %time% or %time{strftime format}% * Extract the time format if provided. */ @@ -393,7 +392,6 @@ theme_adium_append_message (EmpathyChatView *view, EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); EmpathyContact *sender; EmpathyAccount *account; - McProfile *account_profile; gchar *dup_body = NULL; const gchar *body; const gchar *name; @@ -416,8 +414,7 @@ theme_adium_append_message (EmpathyChatView *view, /* Get information */ sender = empathy_message_get_sender (msg); account = empathy_contact_get_account (sender); - account_profile = empathy_account_get_profile (account); - service_name = mc_profile_get_display_name (account_profile); + service_name = empathy_account_get_protocol (account); timestamp = empathy_message_get_timestamp (msg); body = empathy_message_get_body (msg); dup_body = theme_adium_parse_body (theme, body); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index f427b999..1b48c148 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -164,13 +164,45 @@ accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, g_free (text); } +typedef GtkWidget *CreateWidget (EmpathyAccount *); + +static GtkWidget * +get_account_setup_widget (EmpathyAccount *account) +{ + const gchar *cm = empathy_account_get_connection_manager (account); + const gchar *proto = empathy_account_get_protocol (account); + struct { + const gchar *cm; + const gchar *proto; + CreateWidget *cb; + } dialogs[] = { + { "gabble", "jabber", empathy_account_widget_jabber_new}, + { "butterfly", "msn", empathy_account_widget_msn_new}, + { "salut", "local-xmpp", empathy_account_widget_salut_new}, + { "idle", "irc", empathy_account_widget_irc_new}, + { "haze", "icq", empathy_account_widget_icq_new}, + { "haze", "aim", empathy_account_widget_aim_new}, + { "haze", "yahoo", empathy_account_widget_yahoo_new}, + { "haze", "groupwise", empathy_account_widget_groupwise_new}, + { "sofiasip", "sip", empathy_account_widget_sip_new}, + { NULL, NULL, NULL } + }; + int i; + + for (i = 0; dialogs[i].cm != NULL; i++) { + if (!tp_strdiff (cm, dialogs[i].cm) + && !tp_strdiff (proto, dialogs[i].proto)) + return dialogs[i].cb(account); + } + + return empathy_account_widget_generic_new (account); +} + + static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog, EmpathyAccount *account) { - McProfile *profile; - const gchar *config_ui; - if (!account) { GtkTreeView *view; GtkTreeModel *model; @@ -215,48 +247,7 @@ accounts_dialog_update_account (EmpathyAccountsDialog *dialog, dialog->settings_widget = NULL; } - profile = empathy_account_get_profile (account); - config_ui = mc_profile_get_configuration_ui (profile); - if (!tp_strdiff (config_ui, "jabber")) { - dialog->settings_widget = - empathy_account_widget_jabber_new (account); - } - else if (!tp_strdiff (config_ui, "msn")) { - dialog ->settings_widget = - empathy_account_widget_msn_new (account); - } - else if (!tp_strdiff (config_ui, "local-xmpp")) { - dialog->settings_widget = - empathy_account_widget_salut_new (account); - } - else if (!tp_strdiff (config_ui, "irc")) { - dialog->settings_widget = - empathy_account_widget_irc_new (account); - } - else if (!tp_strdiff (config_ui, "icq")) { - dialog->settings_widget = - empathy_account_widget_icq_new (account); - } - else if (!tp_strdiff (config_ui, "aim")) { - dialog->settings_widget = - empathy_account_widget_aim_new (account); - } - else if (!tp_strdiff (config_ui, "yahoo")) { - dialog->settings_widget = - empathy_account_widget_yahoo_new (account); - } - else if (!tp_strdiff (config_ui, "sofiasip")) { - dialog->settings_widget = - empathy_account_widget_sip_new (account); - } - else if (!tp_strdiff (config_ui, "groupwise")) { - dialog->settings_widget = - empathy_account_widget_groupwise_new (account); - } - else { - dialog->settings_widget = - empathy_account_widget_generic_new (account); - } + dialog->settings_widget = get_account_setup_widget (account); gtk_container_add (GTK_CONTAINER (dialog->alignment_settings), dialog->settings_widget); @@ -264,14 +255,12 @@ accounts_dialog_update_account (EmpathyAccountsDialog *dialog, gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type), - mc_profile_get_icon_name (profile), + empathy_account_get_icon_name (account), GTK_ICON_SIZE_DIALOG); gtk_widget_set_tooltip_text (dialog->image_type, - mc_profile_get_display_name (profile)); + empathy_account_get_protocol (account)); accounts_dialog_update_name_label (dialog, account); - - g_object_unref (profile); } static void @@ -661,13 +650,10 @@ accounts_dialog_account_added_cb (EmpathyAccountManager *manager, current_name = empathy_account_get_display_name (account); account_param = empathy_account_get_param_string (account, "account"); if (!EMP_STR_EMPTY (account_param)) { - McProfile *profile; - const gchar *profile_name; gchar *new_name; - profile = empathy_account_get_profile (account); - profile_name = mc_profile_get_display_name (profile); - new_name = g_strdup_printf ("%s (%s)", profile_name, + new_name = g_strdup_printf ("%s (%s)", + empathy_account_get_protocol (account), account_param); DEBUG ("Setting new display name for account %s: '%s'", @@ -675,7 +661,6 @@ accounts_dialog_account_added_cb (EmpathyAccountManager *manager, empathy_account_set_display_name (account, new_name); g_free (new_name); - g_object_unref (profile); } else { /* FIXME: This CM has no account parameter, what can be done? */ } diff --git a/src/empathy-new-chatroom-dialog.c b/src/empathy-new-chatroom-dialog.c index e16da91a..7313fd1e 100644 --- a/src/empathy-new-chatroom-dialog.c +++ b/src/empathy-new-chatroom-dialog.c @@ -358,14 +358,12 @@ new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog) { EmpathyAccountChooser *account_chooser; EmpathyAccount *account; - McProfile *profile; const gchar *protocol; const gchar *room; account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser); account = empathy_account_chooser_dup_account (account_chooser); - profile = empathy_account_get_profile (account); - protocol = mc_profile_get_protocol_name (profile); + protocol = empathy_account_get_protocol (account); gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), ""); @@ -390,7 +388,6 @@ new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog) gtk_widget_grab_focus (dialog->entry_room); g_object_unref (account); - g_object_unref (profile); } static void -- 2.39.2