From adef4b7fed1d3555723b7e223781f6caa1a8e015 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 5 Jul 2009 10:28:04 +0100 Subject: Add API to get the protocol and cm name from a account --- libempathy/empathy-account.c | 55 ++++++++++++++++++++++++++++++++++++++------ libempathy/empathy-account.h | 7 +++--- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index e0a8e756b..3bae8f5b5 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -73,6 +73,10 @@ struct _EmpathyAccountPriv glong connect_time; McAccount *mc_account; + McProfile *mc_profile; + + gchar *cm_name; + gchar *proto_name; }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount) @@ -236,6 +240,10 @@ empathy_account_dispose (GObject *object) g_object_unref (priv->connection); priv->connection = NULL; + if (priv->mc_profile != NULL) + g_object_unref (priv->mc_profile); + priv->mc_profile = NULL; + /* release any references held by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL) G_OBJECT_CLASS (empathy_account_parent_class)->dispose (object); @@ -244,6 +252,11 @@ empathy_account_dispose (GObject *object) void empathy_account_finalize (GObject *object) { + EmpathyAccountPriv *priv = GET_PRIV (object); + + g_free (priv->cm_name); + g_free (priv->proto_name); + /* free any data held directly by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL) G_OBJECT_CLASS (empathy_account_parent_class)->finalize (object); @@ -320,6 +333,22 @@ empathy_account_is_valid (EmpathyAccount *account) return mc_account_is_complete (priv->mc_account); } +const gchar * +empathy_account_get_connection_manager (EmpathyAccount *account) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + return priv->cm_name; +} + +const gchar * +empathy_account_get_protocol (EmpathyAccount *account) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + return priv->proto_name; +} + void empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) { @@ -409,23 +438,34 @@ empathy_account_set_display_name (EmpathyAccount *account, mc_account_set_display_name (priv->mc_account, display_name); } -McProfile * -empathy_account_get_profile (EmpathyAccount *account) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - return mc_account_get_profile (priv->mc_account); -} - EmpathyAccount * _empathy_account_new (McAccount *mc_account) { EmpathyAccount *account; EmpathyAccountPriv *priv; + McProfile *profile; + McProtocol *protocol; + account = g_object_new (EMPATHY_TYPE_ACCOUNT, NULL); priv = GET_PRIV (account); priv->mc_account = mc_account; + profile = mc_account_get_profile (mc_account); + protocol = mc_profile_get_protocol (profile); + + if (protocol != NULL) + { + McManager *manager = mc_protocol_get_manager (protocol); + + priv->proto_name = g_strdup (mc_protocol_get_name (protocol)); + priv->cm_name = g_strdup (mc_manager_get_unique_name (manager)); + + g_object_unref (protocol); + g_object_unref (manager); + } + g_object_unref (profile); + return account; } @@ -571,5 +611,6 @@ McAccount * _empathy_account_get_mc_account (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); + return priv->mc_account; } diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 75babd826..66141ae9b 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -61,6 +61,9 @@ TpConnection *empathy_account_get_connection (EmpathyAccount *account); const gchar *empathy_account_get_unique_name (EmpathyAccount *account); const gchar *empathy_account_get_display_name (EmpathyAccount *account); +const gchar *empathy_account_get_connection_manager (EmpathyAccount *account); +const gchar *empathy_account_get_protocol (EmpathyAccount *account); + void empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled); gboolean empathy_account_is_enabled (EmpathyAccount *account); @@ -85,10 +88,6 @@ gboolean empathy_account_is_valid (EmpathyAccount *account); void empathy_account_set_display_name (EmpathyAccount *account, const gchar *display_name); - -/* TODO remove McProfile */ -McProfile *empathy_account_get_profile (EmpathyAccount *account); - G_END_DECLS #endif /* #ifndef __EMPATHY_ACCOUNT_H__*/ -- cgit v1.2.3 From 6294f9870191ddc0f8a357907d17ac776ef511ca Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 5 Jul 2009 10:31:15 +0100 Subject: Add missing newline --- libempathy-gtk/empathy-ui-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index baa6d21de..3c8c52746 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -1539,4 +1539,4 @@ empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler) G_CALLBACK (file_manager_receive_file_response_cb), handler); gtk_widget_show (widget); -} \ No newline at end of file +} -- cgit v1.2.3 From ddcb104dfa874375ea17cac4de2f273af7327fc4 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 5 Jul 2009 10:43:50 +0100 Subject: Get the icon name from the account object directly --- libempathy-gtk/empathy-account-chooser.c | 2 +- libempathy-gtk/empathy-log-window.c | 2 +- libempathy-gtk/empathy-ui-utils.c | 10 ---------- libempathy-gtk/empathy-ui-utils.h | 1 - libempathy/empathy-account.c | 11 +++++++++++ libempathy/empathy-account.h | 1 + src/empathy-accounts-dialog.c | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c index 7dccb2179..719cc76c2 100644 --- a/libempathy-gtk/empathy-account-chooser.c +++ b/libempathy-gtk/empathy-account-chooser.c @@ -610,7 +610,7 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser, COL_ACCOUNT_POINTER, &account, -1); - icon_name = empathy_icon_name_from_account (account); + icon_name = empathy_account_get_icon_name (account); if (priv->filter) { is_enabled = priv->filter (account, priv->filter_data); } diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index f05017c9c..7add30136 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -419,7 +419,7 @@ log_window_find_populate (EmpathyLogWindow *window, date_readable = empathy_log_manager_get_date_readable (hit->date); account_name = empathy_account_get_display_name (hit->account); - account_icon = empathy_icon_name_from_account (hit->account); + account_icon = empathy_account_get_icon_name (hit->account); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index 3c8c52746..00e6a0cb2 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -182,16 +182,6 @@ empathy_builder_unref_and_keep_widget (GtkBuilder *gui, return widget; } -const gchar * -empathy_icon_name_from_account (EmpathyAccount *account) -{ - McProfile *profile; - - profile = empathy_account_get_profile (account); - - return mc_profile_get_icon_name (profile); -} - const gchar * empathy_icon_name_for_presence (TpConnectionPresenceType presence) { diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 10f889b0c..fe676b135 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -59,7 +59,6 @@ GtkWidget *empathy_builder_unref_and_keep_widget (GtkBuilder *gui, GtkWidget *root); /* Pixbufs */ -const gchar * empathy_icon_name_from_account (EmpathyAccount *account); const gchar * empathy_icon_name_for_presence (TpConnectionPresenceType presence); const gchar * empathy_icon_name_for_contact (EmpathyContact *contact); GdkPixbuf * empathy_pixbuf_from_data (gchar *data, diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 3bae8f5b5..c6a2184f9 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -77,6 +77,7 @@ struct _EmpathyAccountPriv gchar *cm_name; gchar *proto_name; + gchar *icon_name; }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount) @@ -256,6 +257,7 @@ empathy_account_finalize (GObject *object) g_free (priv->cm_name); g_free (priv->proto_name); + g_free (priv->icon_name); /* free any data held directly by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL) @@ -349,6 +351,14 @@ empathy_account_get_protocol (EmpathyAccount *account) return priv->proto_name; } +const gchar * +empathy_account_get_icon_name (EmpathyAccount *account) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + return priv->icon_name; +} + void empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) { @@ -460,6 +470,7 @@ _empathy_account_new (McAccount *mc_account) priv->proto_name = g_strdup (mc_protocol_get_name (protocol)); priv->cm_name = g_strdup (mc_manager_get_unique_name (manager)); + priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name); g_object_unref (protocol); g_object_unref (manager); diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 66141ae9b..95879215c 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -63,6 +63,7 @@ const gchar *empathy_account_get_display_name (EmpathyAccount *account); const gchar *empathy_account_get_connection_manager (EmpathyAccount *account); const gchar *empathy_account_get_protocol (EmpathyAccount *account); +const gchar *empathy_account_get_icon_name (EmpathyAccount *account); void empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 98e848566..f427b9994 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -466,7 +466,7 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, COL_ACCOUNT_POINTER, &account, -1); - icon_name = empathy_icon_name_from_account (account); + icon_name = empathy_account_get_icon_name (account); pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); if (pixbuf) { -- cgit v1.2.3 From 2d517a8bf5f8048a83d753fb0977d4949cbdeb7a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 5 Jul 2009 13:08:11 +0100 Subject: 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 f602cd8bd..8b71e3fff 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 1f1b3b06d..ca0599e0e 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 f427b9994..1b48c1488 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 e16da91a7..7313fd1e6 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 -- cgit v1.2.3 From 7445fd6d08294399972dd0c2c808d9aabfc11b20 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 5 Jul 2009 16:19:59 +0100 Subject: Add api to create accounts, by cm and proto name --- libempathy/empathy-account-manager.c | 42 +++++++++++++++++++++++++++++++++++- libempathy/empathy-account-manager.h | 8 ++++++- tests/check-empathy-helpers.c | 3 ++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index fd8a21b1d..0d09ec5f0 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -22,6 +22,7 @@ #include "config.h" #include +#include #include "empathy-account-manager.h" #include "empathy-account-priv.h" @@ -582,7 +583,7 @@ empathy_account_manager_dup_singleton (void) } EmpathyAccount * -empathy_account_manager_create (EmpathyAccountManager *manager, +empathy_account_manager_create_by_profile (EmpathyAccountManager *manager, McProfile *profile) { McAccount *mc_account = mc_account_create (profile); @@ -591,6 +592,45 @@ empathy_account_manager_create (EmpathyAccountManager *manager, mc_account)); } +EmpathyAccount * +empathy_account_manager_create (EmpathyAccountManager *manager, + const gchar *connection_manager, + const gchar *protocol, + const gchar *display_name) +{ + McProfile *profile; + gboolean found; + GList *profiles, *l; + EmpathyAccount *result = NULL; + + profiles = mc_profiles_list_by_protocol (protocol); + + for (l = profiles; l != NULL; l = g_list_next (l)) { + McProtocol *protocol; + McManager *cm; + + profile = MC_PROFILE (l->data); + + protocol = mc_profile_get_protocol (profile); + cm = mc_protocol_get_manager (protocol); + found = !tp_strdiff (mc_manager_get_unique_name (cm), + connection_manager); + + g_object_unref (protocol); + g_object_unref (manager); + + if (found) { + result = empathy_account_manager_create_by_profile (manager, profile); + empathy_account_set_display_name (result, display_name); + break; + } + } + + mc_profiles_free_list (profiles); + + return result; +} + int empathy_account_manager_get_connected_accounts (EmpathyAccountManager *manager) { diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index b04571ff8..2d77610fb 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -52,7 +52,13 @@ GType empathy_account_manager_get_type (void); /* public methods */ EmpathyAccountManager * empathy_account_manager_dup_singleton (void); -EmpathyAccount * empathy_account_manager_create +EmpathyAccount * empathy_account_manager_create ( + EmpathyAccountManager *manager, + const gchar *connection_manager, + const gchar *protocol, + const gchar *display_name); + +EmpathyAccount * empathy_account_manager_create_by_profile (EmpathyAccountManager *manager, McProfile *profile); int empathy_account_manager_get_connected_accounts diff --git a/tests/check-empathy-helpers.c b/tests/check-empathy-helpers.c index c77cf9b75..fc6f04439 100644 --- a/tests/check-empathy-helpers.c +++ b/tests/check-empathy-helpers.c @@ -79,7 +79,8 @@ get_test_account (void) if (g_list_length (accounts) == 0) { /* need to create a test account */ - account = empathy_account_manager_create (account_manager, profile); + account = empathy_account_manager_create_by_profile (account_manager, + profile); } else { -- cgit v1.2.3 From da5b54cd7fb15a4388d494348b94f96787896155 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 6 Jul 2009 10:51:05 +0100 Subject: use newly deprecated API --- src/empathy-import-dialog.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c index 1e135892d..1d0854dd0 100644 --- a/src/empathy-import-dialog.c +++ b/src/empathy-import-dialog.c @@ -99,7 +99,9 @@ import_dialog_add_account (EmpathyImportAccountData *data) GValue *username; account_manager = empathy_account_manager_dup_singleton (); - account = empathy_account_manager_create (account_manager, data->profile); + account = empathy_account_manager_create_by_profile (account_manager, + data->profile); + g_object_unref (account_manager); if (account == NULL) { -- cgit v1.2.3 From eb9dc0cc2b90d53b87b52e13122f760d291d211e Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 6 Jul 2009 10:55:03 +0100 Subject: Rework creating a salut account so it doesn't need profiles --- src/empathy.c | 128 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 85 insertions(+), 43 deletions(-) diff --git a/src/empathy.c b/src/empathy.c index 40626b532..4b754c472 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -220,15 +221,40 @@ use_nm_notify_cb (EmpathyConf *conf, } } +static gboolean +should_create_salut_account (void) +{ + EmpathyAccountManager *manager; + gboolean salut_created = FALSE; + GList *accounts, *l; + + /* Check if we already created a salut account */ + empathy_conf_get_bool (empathy_conf_get (), + EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, + &salut_created); + + manager = empathy_account_manager_dup_singleton (); + accounts = empathy_account_manager_dup_accounts (manager); + + for (l = accounts; l != NULL; l = g_list_next (l)) { + EmpathyAccount *account = EMPATHY_ACCOUNT (l->data); + + if (!tp_strdiff (empathy_account_get_protocol (account), "local-xmpp")) + salut_created = TRUE; + + g_object_unref (account); + } + + g_object_unref (manager); + + return !salut_created; +} + static void -create_salut_account (void) +create_salut_account_if_needed (void) { - McProfile *profile; - McProtocol *protocol; - gboolean salut_created = FALSE; EmpathyAccount *account; EmpathyAccountManager *account_manager; - GList *accounts; EBook *book; EContact *contact; gchar *nickname = NULL; @@ -238,56 +264,25 @@ create_salut_account (void) gchar *jid = NULL; GError *error = NULL; - /* Check if we already created a salut account */ - empathy_conf_get_bool (empathy_conf_get (), - EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, - &salut_created); - if (salut_created) { - return; - } - - DEBUG ("Try to add a salut account..."); - /* Check if the salut CM is installed */ - profile = mc_profile_lookup ("salut"); - if (!profile) { - DEBUG ("No salut profile"); + if (!should_create_salut_account()) return; - } - protocol = mc_profile_get_protocol (profile); - if (!protocol) { - DEBUG ("Salut not installed"); - g_object_unref (profile); - return; - } - g_object_unref (protocol); + + DEBUG ("Trying to add a salut account..."); /* Get self EContact from EDS */ if (!e_book_get_self (&contact, &book, &error)) { DEBUG ("Failed to get self econtact: %s", error ? error->message : "No error given"); g_clear_error (&error); - g_object_unref (profile); - return; - } - - empathy_conf_set_bool (empathy_conf_get (), - EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, - TRUE); - - /* Check if there is already a salut account */ - accounts = mc_accounts_list_by_profile (profile); - if (accounts) { - DEBUG ("There is already a salut account"); - mc_accounts_list_free (accounts); - g_object_unref (profile); return; } account_manager = empathy_account_manager_dup_singleton (); - account = empathy_account_manager_create (account_manager, profile); - empathy_account_set_display_name (account, _("People nearby")); + account = empathy_account_manager_create (account_manager, + "salut", "local-xmpp", _("People nearby")); g_object_unref (account_manager); + empathy_account_set_enabled (account, TRUE); nickname = e_contact_get (contact, E_CONTACT_NICKNAME); first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME); @@ -316,9 +311,51 @@ create_salut_account (void) g_free (email); g_free (jid); g_object_unref (account); - g_object_unref (profile); g_object_unref (contact); g_object_unref (book); + + empathy_conf_set_bool (empathy_conf_get (), + EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, + TRUE); + +} + +static void +connection_manager_listed (TpConnectionManager * const * cms, + gsize n_cms, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + int i; + if (error != NULL) { + DEBUG ("Couldn't get the connection manager list: %s", error->message); + return; + } + + for (i = 0; i < n_cms; i++) { + if (!tp_strdiff (tp_connection_manager_get_name (cms[i]), "salut")) { + /* salut installed, see if we need to create a new account */ + create_salut_account_if_needed (); + return; + } + } +} + +static void +create_salut_account (void) +{ + TpDBusDaemon *d; + + if (!should_create_salut_account()) + return; + + d = tp_dbus_daemon_dup (NULL); + + tp_list_connection_managers (d, connection_manager_listed, NULL, + NULL, NULL); + + g_object_unref (d); } /* The code that handles single-instance and startup notification is @@ -487,6 +524,7 @@ main (int argc, char *argv[]) #endif EmpathyStatusIcon *icon; EmpathyDispatcher *dispatcher; + EmpathyAccountManager *account_manager; EmpathyLogManager *log_manager; EmpathyChatroomManager *chatroom_manager; EmpathyCallFactory *call_factory; @@ -637,6 +675,9 @@ main (int argc, char *argv[]) empathy_idle_set_state (idle, MC_PRESENCE_AVAILABLE); } + /* account management */ + account_manager = empathy_account_manager_dup_singleton (); + create_salut_account (); /* Setting up UI */ @@ -685,6 +726,7 @@ main (int argc, char *argv[]) g_object_unref (mc); g_object_unref (idle); g_object_unref (icon); + g_object_unref (account_manager); g_object_unref (log_manager); g_object_unref (dispatcher); g_object_unref (chatroom_manager); -- cgit v1.2.3 From 0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 6 Jul 2009 11:29:55 +0100 Subject: Transform profile chooser into a protocol chooser --- libempathy-gtk/Makefile.am | 4 +- libempathy-gtk/empathy-profile-chooser.c | 324 ---------------------------- libempathy-gtk/empathy-profile-chooser.h | 69 ------ libempathy-gtk/empathy-protocol-chooser.c | 339 ++++++++++++++++++++++++++++++ libempathy-gtk/empathy-protocol-chooser.h | 70 ++++++ src/empathy-accounts-dialog.c | 81 ++++--- src/empathy-accounts-dialog.ui | 2 +- tests/Makefile.am | 4 +- tests/test-empathy-profile-chooser.c | 31 --- tests/test-empathy-protocol-chooser.c | 31 +++ 10 files changed, 484 insertions(+), 471 deletions(-) delete mode 100644 libempathy-gtk/empathy-profile-chooser.c delete mode 100644 libempathy-gtk/empathy-profile-chooser.h create mode 100644 libempathy-gtk/empathy-protocol-chooser.c create mode 100644 libempathy-gtk/empathy-protocol-chooser.h delete mode 100644 tests/test-empathy-profile-chooser.c create mode 100644 tests/test-empathy-protocol-chooser.c diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 10931012a..94cc4ee15 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -52,7 +52,7 @@ libempathy_gtk_handwritten_source = \ empathy-log-window.c \ empathy-new-message-dialog.c \ empathy-presence-chooser.c \ - empathy-profile-chooser.c \ + empathy-protocol-chooser.c \ empathy-smiley-manager.c \ empathy-sound.c \ empathy-spell.c \ @@ -112,7 +112,7 @@ libempathy_gtk_headers = \ empathy-log-window.h \ empathy-new-message-dialog.h \ empathy-presence-chooser.h \ - empathy-profile-chooser.h \ + empathy-protocol-chooser.h \ empathy-smiley-manager.h \ empathy-sound.h \ empathy-spell.h \ diff --git a/libempathy-gtk/empathy-profile-chooser.c b/libempathy-gtk/empathy-profile-chooser.c deleted file mode 100644 index b3cbf90d0..000000000 --- a/libempathy-gtk/empathy-profile-chooser.c +++ /dev/null @@ -1,324 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* - * Copyright (C) 2007-2009 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens - * Jonny Lamb - */ - -#include - -#include - -#include -#include -#include - -#include - -#include "empathy-profile-chooser.h" -#include "empathy-ui-utils.h" - -/** - * SECTION:empathy-profile-chooser - * @title: EmpathyProfileChooser - * @short_description: A widget used to choose from a list of profiles - * @include: libempathy-gtk/empathy-profile-chooser.h - * - * #EmpathyProfileChooser is a widget which extends #GtkComboBox to provides a - * chooser of available profiles. - */ - -/** - * EmpathyProfileChooser: - * @parent: parent object - * - * Widget which extends #GtkComboBox to provide a chooser of available - * profiles. - */ - -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyProfileChooser) -typedef struct -{ - GtkListStore *store; - gboolean dispose_run; -} EmpathyProfileChooserPriv; - -enum -{ - COL_ICON, - COL_LABEL, - COL_PROFILE, - COL_COUNT -}; - -G_DEFINE_TYPE (EmpathyProfileChooser, empathy_profile_chooser, - GTK_TYPE_COMBO_BOX); - -static gint -profile_chooser_sort_profile_value (McProfile *profile) -{ - guint i; - const gchar *profile_name; - const gchar *names[] = { - "jabber", - "salut", - "gtalk", - NULL - }; - - profile_name = mc_profile_get_unique_name (profile); - - for (i = 0 ; names[i]; i++) - { - if (strcmp (profile_name, names[i]) == 0) - return i; - } - - return i; -} - -static gint -profile_chooser_sort_func (GtkTreeModel *model, - GtkTreeIter *iter_a, - GtkTreeIter *iter_b, - gpointer user_data) -{ - McProfile *profile_a; - McProfile *profile_b; - gint cmp; - - gtk_tree_model_get (model, iter_a, - COL_PROFILE, &profile_a, - -1); - gtk_tree_model_get (model, iter_b, - COL_PROFILE, &profile_b, - -1); - - cmp = profile_chooser_sort_profile_value (profile_a); - cmp -= profile_chooser_sort_profile_value (profile_b); - if (cmp == 0) - { - cmp = strcmp (mc_profile_get_display_name (profile_a), - mc_profile_get_display_name (profile_b)); - } - - g_object_unref (profile_a); - g_object_unref (profile_b); - - return cmp; -} - -static void -profile_chooser_constructed (GObject *object) -{ - EmpathyProfileChooser *profile_chooser; - EmpathyProfileChooserPriv *priv; - - GList *profiles, *l, *seen; - GtkCellRenderer *renderer; - GtkTreeIter iter; - gboolean iter_set = FALSE; - McManager *btf_cm; - - priv = GET_PRIV (object); - profile_chooser = EMPATHY_PROFILE_CHOOSER (object); - - /* set up combo box with new store */ - priv->store = gtk_list_store_new (COL_COUNT, - G_TYPE_STRING, /* Icon name */ - G_TYPE_STRING, /* Label */ - MC_TYPE_PROFILE); /* Profile */ - - gtk_combo_box_set_model (GTK_COMBO_BOX (object), - GTK_TREE_MODEL (priv->store)); - - renderer = gtk_cell_renderer_pixbuf_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, FALSE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer, - "icon-name", COL_ICON, - NULL); - g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer, - "text", COL_LABEL, - NULL); - - btf_cm = mc_manager_lookup ("butterfly"); - profiles = mc_profiles_list (); - seen = NULL; - for (l = profiles; l; l = g_list_next (l)) - { - McProfile *profile; - McProtocol *protocol; - const gchar *unique_name; - - profile = l->data; - - /* Check if the CM is installed, otherwise skip that profile. - * Workaround SF bug #1688779 */ - protocol = mc_profile_get_protocol (profile); - if (!protocol) - continue; - - g_object_unref (protocol); - - /* Skip MSN-Haze if we have butterfly */ - unique_name = mc_profile_get_unique_name (profile); - if (btf_cm && strcmp (unique_name, "msn-haze") == 0) - continue; - - if (g_list_find_custom (seen, unique_name, (GCompareFunc) strcmp)) - continue; - - seen = g_list_append (seen, (char *) unique_name); - - gtk_list_store_insert_with_values (priv->store, &iter, 0, - COL_ICON, mc_profile_get_icon_name (profile), - COL_LABEL, mc_profile_get_display_name (profile), - COL_PROFILE, profile, - -1); - iter_set = TRUE; - } - - g_list_free (seen); - - if (btf_cm) - g_object_unref (btf_cm); - - /* Set the profile sort function */ - gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store), - COL_PROFILE, - profile_chooser_sort_func, - NULL, NULL); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store), - COL_PROFILE, - GTK_SORT_ASCENDING); - - if (iter_set) - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (object), &iter); - - mc_profiles_free_list (profiles); - - if (G_OBJECT_CLASS (empathy_profile_chooser_parent_class)->constructed) - G_OBJECT_CLASS (empathy_profile_chooser_parent_class)->constructed (object); -} - -static void -empathy_profile_chooser_init (EmpathyProfileChooser *profile_chooser) -{ - EmpathyProfileChooserPriv *priv = - G_TYPE_INSTANCE_GET_PRIVATE (profile_chooser, - EMPATHY_TYPE_PROFILE_CHOOSER, EmpathyProfileChooserPriv); - - priv->dispose_run = FALSE; - - profile_chooser->priv = priv; -} - -static void -profile_chooser_dispose (GObject *object) -{ - EmpathyProfileChooser *profile_chooser = EMPATHY_PROFILE_CHOOSER (object); - EmpathyProfileChooserPriv *priv = GET_PRIV (profile_chooser); - - if (priv->dispose_run) - return; - - priv->dispose_run = TRUE; - - if (priv->store) - { - g_object_unref (priv->store); - priv->store = NULL; - } - - (G_OBJECT_CLASS (empathy_profile_chooser_parent_class)->dispose) (object); -} - -static void -empathy_profile_chooser_class_init (EmpathyProfileChooserClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->constructed = profile_chooser_constructed; - object_class->dispose = profile_chooser_dispose; - - g_type_class_add_private (object_class, sizeof (EmpathyProfileChooserPriv)); -} - -/** - * empathy_profile_chooser_dup_selected: - * @profile_chooser: an #EmpathyProfileChooser - * - * Returns a new reference to the selected #McProfile in @profile_chooser. The - * returned #McProfile should be unrefed with g_object_unref() when finished - * with. - * - * Return value: a new reference to the selected #McProfile - */ -McProfile * -empathy_profile_chooser_dup_selected (EmpathyProfileChooser *profile_chooser) -{ - EmpathyProfileChooserPriv *priv = GET_PRIV (profile_chooser); - GtkTreeIter iter; - McProfile *profile = NULL; - - g_return_val_if_fail (EMPATHY_IS_PROFILE_CHOOSER (profile_chooser), NULL); - - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (profile_chooser), &iter)) - { - gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, - COL_PROFILE, &profile, - -1); - } - - return profile; -} - -/** - * empathy_profile_chooser_n_profiles: - * @profile_chooser: an #EmpathyProfileChooser - * - * Returns the number of profiles in @profile_chooser. - * - * Return value: the number of profiles in @profile_chooser - */ -gint -empathy_profile_chooser_n_profiles (EmpathyProfileChooser *profile_chooser) -{ - EmpathyProfileChooserPriv *priv = GET_PRIV (profile_chooser); - - g_return_val_if_fail (EMPATHY_IS_PROFILE_CHOOSER (profile_chooser), 0); - - return gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), NULL); -} - -/** - * empathy_profile_chooser_new: - * - * Creates a new #EmpathyProfileChooser widget. - * - * Return value: a new #EmpathyProfileChooser widget - */ -GtkWidget * -empathy_profile_chooser_new (void) -{ - return GTK_WIDGET (g_object_new (EMPATHY_TYPE_PROFILE_CHOOSER, NULL)); -} diff --git a/libempathy-gtk/empathy-profile-chooser.h b/libempathy-gtk/empathy-profile-chooser.h deleted file mode 100644 index 37d7241a9..000000000 --- a/libempathy-gtk/empathy-profile-chooser.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* - * Copyright (C) 2007-2009 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens - * Jonny Lamb -#include - -#include - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_PROFILE_CHOOSER (empathy_profile_chooser_get_type ()) -#define EMPATHY_PROFILE_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ - EMPATHY_TYPE_PROFILE_CHOOSER, EmpathyProfileChooser)) -#define EMPATHY_PROFILE_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ - EMPATHY_TYPE_PROFILE_CHOOSER, EmpathyProfileChooserClass)) -#define EMPATHY_IS_PROFILE_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ - EMPATHY_TYPE_PROFILE_CHOOSER)) -#define EMPATHY_IS_PROFILE_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ - EMPATHY_TYPE_PROFILE_CHOOSER)) -#define EMPATHY_PROFILE_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \ - EMPATHY_TYPE_PROFILE_CHOOSER, EmpathyProfileChooserClass)) - -typedef struct _EmpathyProfileChooser EmpathyProfileChooser; -typedef struct _EmpathyProfileChooserClass EmpathyProfileChooserClass; - -struct _EmpathyProfileChooser -{ - GtkComboBox parent; - - /**/ - gpointer priv; -}; - -struct _EmpathyProfileChooserClass -{ - GtkComboBoxClass parent_class; -}; - -GType empathy_profile_chooser_get_type (void) G_GNUC_CONST; -GtkWidget * empathy_profile_chooser_new (void); -McProfile * empathy_profile_chooser_dup_selected ( - EmpathyProfileChooser *profile_chooser); -gint empathy_profile_chooser_n_profiles ( - EmpathyProfileChooser *profile_chooser); - -G_END_DECLS -#endif /* __EMPATHY_PROFILE_CHOOSER_H__ */ diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c new file mode 100644 index 000000000..45442156e --- /dev/null +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -0,0 +1,339 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* + * Copyright (C) 2007-2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + * Jonny Lamb + */ + +#include + +#include + +#include + +#include + +#include + +#include "empathy-protocol-chooser.h" +#include "empathy-ui-utils.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT +#include + +/** + * SECTION:empathy-protocol-chooser + * @title: EmpathyProtocolChooser + * @short_description: A widget used to choose from a list of protocols + * @include: libempathy-gtk/empathy-protocol-chooser.h + * + * #EmpathyProtocolChooser is a widget which extends #GtkComboBox to provides a + * chooser of available protocols. + */ + +/** + * EmpathyProtocolChooser: + * @parent: parent object + * + * Widget which extends #GtkComboBox to provide a chooser of available + * protocols. + */ + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyProtocolChooser) +typedef struct +{ + GtkListStore *store; + gboolean dispose_run; + +} EmpathyProtocolChooserPriv; + +enum +{ + COL_ICON, + COL_LABEL, + COL_CM, + COL_PROTOCOL, + COL_COUNT +}; + +G_DEFINE_TYPE (EmpathyProtocolChooser, empathy_protocol_chooser, + GTK_TYPE_COMBO_BOX); + +static gint +protocol_chooser_sort_protocol_value (TpConnectionManagerProtocol *protocol) +{ + guint i; + const gchar *names[] = { + "jabber", + "salut", + "gtalk", + NULL + }; + + for (i = 0 ; names[i]; i++) + { + if (strcmp (protocol->name, names[i]) == 0) + return i; + } + + return i; +} + +static gint +protocol_chooser_sort_func (GtkTreeModel *model, + GtkTreeIter *iter_a, + GtkTreeIter *iter_b, + gpointer user_data) +{ + TpConnectionManagerProtocol *protocol_a; + TpConnectionManagerProtocol *protocol_b; + gint cmp; + + gtk_tree_model_get (model, iter_a, + COL_PROTOCOL, &protocol_a, + -1); + gtk_tree_model_get (model, iter_b, + COL_PROTOCOL, &protocol_b, + -1); + + cmp = protocol_chooser_sort_protocol_value (protocol_a); + cmp -= protocol_chooser_sort_protocol_value (protocol_b); + if (cmp == 0) + { + cmp = strcmp (protocol_a->name, protocol_b->name); + } + + return cmp; +} + +static void +protocol_choosers_add_cm (EmpathyProtocolChooser *chooser, + TpConnectionManager *cm) +{ + EmpathyProtocolChooserPriv *priv = GET_PRIV (chooser); + const TpConnectionManagerProtocol * const *iter; + + for (iter = cm->protocols; iter != NULL && *iter != NULL; iter++) + { + const TpConnectionManagerProtocol *proto = *iter; + gchar *icon_name; + gchar *display_name; + + + icon_name = g_strdup_printf ("im-%s", proto->name); + + if (!tp_strdiff (cm->name, "haze") && !tp_strdiff (proto->name, "msn")) + display_name = g_strdup_printf ("msn (Haze)"); + else + display_name = g_strdup (proto->name); + + gtk_list_store_insert_with_values (priv->store, NULL, 0, + COL_ICON, icon_name, + COL_LABEL, display_name, + COL_CM, cm, + COL_PROTOCOL, proto, + -1); + + g_free (display_name); + g_free (icon_name); + } +} + + +static void +protocol_choosers_cms_listed (TpConnectionManager * const *cms, + gsize n_cms, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + TpConnectionManager * const *iter; + + if (error !=NULL) + { + DEBUG ("Failed to get connection managers: %s", error->message); + return; + } + + for (iter = cms ; iter != NULL && *iter != NULL; iter++) + protocol_choosers_add_cm (EMPATHY_PROTOCOL_CHOOSER (weak_object), + *iter); + + gtk_combo_box_set_active (GTK_COMBO_BOX (weak_object), 0); +} + +static void +protocol_chooser_constructed (GObject *object) +{ + EmpathyProtocolChooser *protocol_chooser; + EmpathyProtocolChooserPriv *priv; + + GtkCellRenderer *renderer; + TpDBusDaemon *dbus; + + priv = GET_PRIV (object); + protocol_chooser = EMPATHY_PROTOCOL_CHOOSER (object); + + /* set up combo box with new store */ + priv->store = gtk_list_store_new (COL_COUNT, + G_TYPE_STRING, /* Icon name */ + G_TYPE_STRING, /* Label */ + G_TYPE_OBJECT, /* CM */ + G_TYPE_POINTER); /* protocol */ + + gtk_combo_box_set_model (GTK_COMBO_BOX (object), + GTK_TREE_MODEL (priv->store)); + + renderer = gtk_cell_renderer_pixbuf_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, FALSE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer, + "icon-name", COL_ICON, + NULL); + g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer, + "text", COL_LABEL, + NULL); + + dbus = tp_dbus_daemon_dup (NULL); + tp_list_connection_managers (dbus, protocol_choosers_cms_listed, + NULL, NULL, object); + g_object_unref (dbus); + + /* Set the protocol sort function */ + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store), + COL_PROTOCOL, + protocol_chooser_sort_func, + NULL, NULL); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store), + COL_PROTOCOL, + GTK_SORT_ASCENDING); + + if (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed) + G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed (object); +} + +static void +empathy_protocol_chooser_init (EmpathyProtocolChooser *protocol_chooser) +{ + EmpathyProtocolChooserPriv *priv = + G_TYPE_INSTANCE_GET_PRIVATE (protocol_chooser, + EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserPriv); + + priv->dispose_run = FALSE; + + protocol_chooser->priv = priv; +} + +static void +protocol_chooser_dispose (GObject *object) +{ + EmpathyProtocolChooser *protocol_chooser = EMPATHY_PROTOCOL_CHOOSER (object); + EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); + + if (priv->dispose_run) + return; + + priv->dispose_run = TRUE; + + if (priv->store) + { + g_object_unref (priv->store); + priv->store = NULL; + } + + (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->dispose) (object); +} + +static void +empathy_protocol_chooser_class_init (EmpathyProtocolChooserClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = protocol_chooser_constructed; + object_class->dispose = protocol_chooser_dispose; + + g_type_class_add_private (object_class, sizeof (EmpathyProtocolChooserPriv)); +} + +/** + * empathy_protocol_chooser_get_selected_protocol: + * @protocol_chooser: an #EmpathyProtocolChooser + * + * Returns a pointer to the selected #TpConnectionManagerProtocol in + * @protocol_chooser. + * + * Return value: a pointer to the selected #TpConnectionManagerProtocol + */ +TpConnectionManager *empathy_protocol_chooser_dup_selected ( + EmpathyProtocolChooser *protocol_chooser, + TpConnectionManagerProtocol **protocol) +{ + EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); + GtkTreeIter iter; + TpConnectionManager *cm = NULL; + + g_return_val_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser), NULL); + + if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (protocol_chooser), &iter)) + { + gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, + COL_CM, &cm, + -1); + + if (protocol != NULL) + gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, + COL_PROTOCOL, protocol, + -1); + } + + return cm; +} + +/** + * empathy_protocol_chooser_n_protocols: + * @protocol_chooser: an #EmpathyProtocolChooser + * + * Returns the number of protocols in @protocol_chooser. + * + * Return value: the number of protocols in @protocol_chooser + */ +gint +empathy_protocol_chooser_n_protocols (EmpathyProtocolChooser *protocol_chooser) +{ + EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); + + g_return_val_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser), 0); + + return gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), NULL); +} + +/** + * empathy_protocol_chooser_new: + * + * Creates a new #EmpathyProtocolChooser widget. + * + * Return value: a new #EmpathyProtocolChooser widget + */ +GtkWidget * +empathy_protocol_chooser_new (void) +{ + return GTK_WIDGET (g_object_new (EMPATHY_TYPE_PROTOCOL_CHOOSER, NULL)); +} diff --git a/libempathy-gtk/empathy-protocol-chooser.h b/libempathy-gtk/empathy-protocol-chooser.h new file mode 100644 index 000000000..75f9343cc --- /dev/null +++ b/libempathy-gtk/empathy-protocol-chooser.h @@ -0,0 +1,70 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* + * Copyright (C) 2007-2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + * Jonny Lamb +#include + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_PROTOCOL_CHOOSER (empathy_protocol_chooser_get_type ()) +#define EMPATHY_PROTOCOL_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooser)) +#define EMPATHY_PROTOCOL_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserClass)) +#define EMPATHY_IS_PROTOCOL_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER)) +#define EMPATHY_IS_PROTOCOL_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER)) +#define EMPATHY_PROTOCOL_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserClass)) + +typedef struct _EmpathyProtocolChooser EmpathyProtocolChooser; +typedef struct _EmpathyProtocolChooserClass EmpathyProtocolChooserClass; + +struct _EmpathyProtocolChooser +{ + GtkComboBox parent; + + /**/ + gpointer priv; +}; + +struct _EmpathyProtocolChooserClass +{ + GtkComboBoxClass parent_class; +}; + +GType empathy_protocol_chooser_get_type (void) G_GNUC_CONST; +GtkWidget * empathy_protocol_chooser_new (void); +TpConnectionManager *empathy_protocol_chooser_dup_selected ( + EmpathyProtocolChooser *protocol_chooser, + TpConnectionManagerProtocol **protocol); +gint empathy_protocol_chooser_n_protocols ( + EmpathyProtocolChooser *protocol_chooser); + +G_END_DECLS +#endif /* __EMPATHY_PROTOCOL_CHOOSER_H__ */ diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 1b48c1488..c523a2138 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -31,13 +31,12 @@ #include #include -#include #include #include #include #include -#include +#include #include #include #include @@ -58,7 +57,7 @@ typedef struct { GtkWidget *alignment_settings; GtkWidget *vbox_details; - GtkWidget *frame_no_profile; + GtkWidget *frame_no_protocol; GtkWidget *treeview; @@ -67,7 +66,7 @@ typedef struct { GtkWidget *button_import; GtkWidget *frame_new_account; - GtkWidget *combobox_profile; + GtkWidget *combobox_protocol; GtkWidget *hbox_type; GtkWidget *button_create; GtkWidget *button_back; @@ -215,8 +214,8 @@ accounts_dialog_update_account (EmpathyAccountsDialog *dialog, accounts_dialog_model_select_first (dialog); return; } - if (empathy_profile_chooser_n_profiles ( - EMPATHY_PROFILE_CHOOSER (dialog->combobox_profile)) > 0) { + if (empathy_protocol_chooser_n_protocols ( + EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol)) > 0) { /* We have no account configured but we have some * profiles instsalled. The user obviously wants to add * an account. Click on the Add button for him. */ @@ -228,7 +227,7 @@ accounts_dialog_update_account (EmpathyAccountsDialog *dialog, /* No account and no profile, warn the user */ gtk_widget_hide (dialog->vbox_details); gtk_widget_hide (dialog->frame_new_account); - gtk_widget_show (dialog->frame_no_profile); + gtk_widget_show (dialog->frame_no_protocol); gtk_widget_set_sensitive (dialog->button_add, FALSE); gtk_widget_set_sensitive (dialog->button_remove, FALSE); return; @@ -237,7 +236,7 @@ accounts_dialog_update_account (EmpathyAccountsDialog *dialog, /* We have an account selected, destroy old settings and create a new * one for the account selected */ gtk_widget_hide (dialog->frame_new_account); - gtk_widget_hide (dialog->frame_no_profile); + gtk_widget_hide (dialog->frame_no_protocol); gtk_widget_show (dialog->vbox_details); gtk_widget_set_sensitive (dialog->button_add, TRUE); gtk_widget_set_sensitive (dialog->button_remove, TRUE); @@ -801,31 +800,30 @@ static void accounts_dialog_button_create_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { - McProfile *profile; EmpathyAccount *account; gchar *str; - McProfileCapabilityFlags cap; + TpConnectionManager *cm; + TpConnectionManagerProtocol *proto; - profile = empathy_profile_chooser_dup_selected ( - EMPATHY_PROFILE_CHOOSER (dialog->combobox_profile)); + cm = empathy_protocol_chooser_dup_selected ( + EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto); /* Create account */ - account = empathy_account_manager_create (dialog->account_manager, profile); + /* To translator: %s is the protocol name */ + str = g_strdup_printf (_("New %s account"), proto->name); + + account = empathy_account_manager_create (dialog->account_manager, + cm->name, proto->name, str); + + g_free (str); + if (account == NULL) { /* We can't display an error to the user as MC doesn't give us * any clue about the reason of the failure... */ - g_object_unref (profile); return; } - /* To translator: %s is the protocol name */ - str = g_strdup_printf (_("New %s account"), - mc_profile_get_display_name (profile)); - empathy_account_set_display_name (account, str); - g_free (str); - - cap = mc_profile_get_capabilities (profile); - if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) { + if (tp_connection_manager_protocol_can_register (proto)) { gboolean active; active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register)); @@ -838,7 +836,7 @@ accounts_dialog_button_create_clicked_cb (GtkWidget *button, accounts_dialog_model_set_selected (dialog, account); g_object_unref (account); - g_object_unref (profile); + g_object_unref (cm); } static void @@ -852,24 +850,23 @@ accounts_dialog_button_back_clicked_cb (GtkWidget *button, } static void -accounts_dialog_profile_changed_cb (GtkWidget *widget, +accounts_dialog_protocol_changed_cb (GtkWidget *widget, EmpathyAccountsDialog *dialog) { - McProfile *profile; - McProfileCapabilityFlags cap; + TpConnectionManager *cm; + TpConnectionManagerProtocol *proto; - profile = empathy_profile_chooser_dup_selected ( - EMPATHY_PROFILE_CHOOSER (dialog->combobox_profile)); - cap = mc_profile_get_capabilities (profile); + cm = empathy_protocol_chooser_dup_selected ( + EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto); - if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) { + if (tp_connection_manager_protocol_can_register (proto)) { gtk_widget_show (dialog->radiobutton_register); gtk_widget_show (dialog->radiobutton_reuse); } else { gtk_widget_hide (dialog->radiobutton_register); gtk_widget_hide (dialog->radiobutton_reuse); } - g_object_unref (profile); + g_object_unref (cm); } static void @@ -888,7 +885,7 @@ accounts_dialog_button_add_clicked_cb (GtkWidget *button, gtk_widget_set_sensitive (dialog->button_add, FALSE); gtk_widget_set_sensitive (dialog->button_remove, FALSE); gtk_widget_hide (dialog->vbox_details); - gtk_widget_hide (dialog->frame_no_profile); + gtk_widget_hide (dialog->frame_no_protocol); gtk_widget_show (dialog->frame_new_account); /* If we have no account, no need of a back button */ @@ -898,11 +895,11 @@ accounts_dialog_button_add_clicked_cb (GtkWidget *button, gtk_widget_hide (dialog->button_back); } - accounts_dialog_profile_changed_cb (dialog->radiobutton_register, dialog); + accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse), TRUE); - gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0); - gtk_widget_grab_focus (dialog->combobox_profile); + gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0); + gtk_widget_grab_focus (dialog->combobox_protocol); } static void @@ -1052,7 +1049,7 @@ empathy_accounts_dialog_show (GtkWindow *parent, gui = empathy_builder_get_file (filename, "accounts_dialog", &dialog->window, "vbox_details", &dialog->vbox_details, - "frame_no_profile", &dialog->frame_no_profile, + "frame_no_protocol", &dialog->frame_no_protocol, "alignment_settings", &dialog->alignment_settings, "treeview", &dialog->treeview, "frame_new_account", &dialog->frame_new_account, @@ -1084,14 +1081,14 @@ empathy_accounts_dialog_show (GtkWindow *parent, g_object_unref (gui); - /* Create profile chooser */ - dialog->combobox_profile = empathy_profile_chooser_new (); + /* Create protocol chooser */ + dialog->combobox_protocol = empathy_protocol_chooser_new (); gtk_box_pack_end (GTK_BOX (dialog->hbox_type), - dialog->combobox_profile, + dialog->combobox_protocol, TRUE, TRUE, 0); - gtk_widget_show (dialog->combobox_profile); - g_signal_connect (dialog->combobox_profile, "changed", - G_CALLBACK (accounts_dialog_profile_changed_cb), + gtk_widget_show (dialog->combobox_protocol); + g_signal_connect (dialog->combobox_protocol, "changed", + G_CALLBACK (accounts_dialog_protocol_changed_cb), dialog); /* Set up signalling */ diff --git a/src/empathy-accounts-dialog.ui b/src/empathy-accounts-dialog.ui index cf1b23ef4..a76b4ae7f 100644 --- a/src/empathy-accounts-dialog.ui +++ b/src/empathy-accounts-dialog.ui @@ -391,7 +391,7 @@ - + 0 none diff --git a/tests/Makefile.am b/tests/Makefile.am index f96650e79..7f99eaf36 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -27,13 +27,13 @@ noinst_PROGRAMS = \ empetit \ test-empathy-presence-chooser \ test-empathy-status-preset-dialog \ - test-empathy-profile-chooser + test-empathy-protocol-chooser contact_manager_SOURCES = contact-manager.c empetit_SOURCES = empetit.c test_empathy_presence_chooser_SOURCES = test-empathy-presence-chooser.c test_empathy_status_preset_dialog_SOURCES = test-empathy-status-preset-dialog.c -test_empathy_profile_chooser_SOURCES = test-empathy-profile-chooser.c +test_empathy_protocol_chooser_SOURCES = test-empathy-protocol-chooser.c check_PROGRAMS = check-main TESTS = check-main diff --git a/tests/test-empathy-profile-chooser.c b/tests/test-empathy-profile-chooser.c deleted file mode 100644 index 9078bbde4..000000000 --- a/tests/test-empathy-profile-chooser.c +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#include - -#include -#include - -int -main (int argc, - char **argv) -{ - GtkWidget *window; - GtkWidget *chooser; - - gtk_init (&argc, &argv); - empathy_gtk_init (); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - chooser = empathy_profile_chooser_new (); - gtk_container_add (GTK_CONTAINER (window), chooser); - - /* gtk_window_set_default_size (GTK_WINDOW (window), 150, -1);*/ - gtk_widget_show_all (window); - - g_signal_connect_swapped (window, "destroy", - G_CALLBACK (gtk_main_quit), NULL); - - gtk_main (); - - return 0; -} diff --git a/tests/test-empathy-protocol-chooser.c b/tests/test-empathy-protocol-chooser.c new file mode 100644 index 000000000..07b1c70e1 --- /dev/null +++ b/tests/test-empathy-protocol-chooser.c @@ -0,0 +1,31 @@ +#include + +#include + +#include +#include + +int +main (int argc, + char **argv) +{ + GtkWidget *window; + GtkWidget *chooser; + + gtk_init (&argc, &argv); + empathy_gtk_init (); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + chooser = empathy_protocol_chooser_new (); + gtk_container_add (GTK_CONTAINER (window), chooser); + + /* gtk_window_set_default_size (GTK_WINDOW (window), 150, -1);*/ + gtk_widget_show_all (window); + + g_signal_connect_swapped (window, "destroy", + G_CALLBACK (gtk_main_quit), NULL); + + gtk_main (); + + return 0; +} -- cgit v1.2.3 From e4c5612c5e28f5c1afcf212602da3c531fe28909 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 6 Jul 2009 11:31:00 +0100 Subject: Update python bindings --- python/pyempathy/pyempathy.defs | 11 ++++ python/pyempathygtk/pyempathygtk.defs | 86 +++++++------------------------ python/pyempathygtk/pyempathygtk.override | 2 +- python/update-binding.sh | 2 +- 4 files changed, 31 insertions(+), 70 deletions(-) diff --git a/python/pyempathy/pyempathy.defs b/python/pyempathy/pyempathy.defs index 6b6f7dfd3..003564bc5 100644 --- a/python/pyempathy/pyempathy.defs +++ b/python/pyempathy/pyempathy.defs @@ -281,6 +281,17 @@ (of-object "EmpathyAccountManager") (c-name "empathy_account_manager_create") (return-type "EmpathyAccount*") + (parameters + '("const-gchar*" "connection_manager") + '("const-gchar*" "protocol") + '("const-gchar*" "display_name") + ) +) + +(define-method create_by_profile + (of-object "EmpathyAccountManager") + (c-name "empathy_account_manager_create_by_profile") + (return-type "EmpathyAccount*") (parameters '("McProfile*" "profile") ) diff --git a/python/pyempathygtk/pyempathygtk.defs b/python/pyempathygtk/pyempathygtk.defs index 377eea43a..1eb50c30f 100644 --- a/python/pyempathygtk/pyempathygtk.defs +++ b/python/pyempathygtk/pyempathygtk.defs @@ -118,11 +118,11 @@ (gtype-id "EMPATHY_TYPE_PRESENCE_CHOOSER") ) -(define-object ProfileChooser +(define-object ProtocolChooser (in-module "Empathy") (parent "GtkComboBox") - (c-name "EmpathyProfileChooser") - (gtype-id "EMPATHY_TYPE_PROFILE_CHOOSER") + (c-name "EmpathyProtocolChooser") + (gtype-id "EMPATHY_TYPE_PROTOCOL_CHOOSER") ) (define-object SmileyManager @@ -254,25 +254,6 @@ ) ) -(define-enum Sound - (in-module "Empathy") - (c-name "EmpathySound") - (gtype-id "EMPATHY_TYPE_SOUND") - (values - '("empathy-sound-message-incoming" "EMPATHY_SOUND_MESSAGE_INCOMING") - '("empathy-sound-message-outgoing" "EMPATHY_SOUND_MESSAGE_OUTGOING") - '("empathy-sound-conversation-new" "EMPATHY_SOUND_CONVERSATION_NEW") - '("empathy-sound-contact-connected" "EMPATHY_SOUND_CONTACT_CONNECTED") - '("empathy-sound-contact-disconnected" "EMPATHY_SOUND_CONTACT_DISCONNECTED") - '("empathy-sound-account-connected" "EMPATHY_SOUND_ACCOUNT_CONNECTED") - '("empathy-sound-account-disconnected" "EMPATHY_SOUND_ACCOUNT_DISCONNECTED") - '("empathy-sound-phone-incoming" "EMPATHY_SOUND_PHONE_INCOMING") - '("empathy-sound-phone-outgoing" "EMPATHY_SOUND_PHONE_OUTGOING") - '("empathy-sound-phone-hangup" "EMPATHY_SOUND_PHONE_HANGUP") - '("last-empathy-sound" "LAST_EMPATHY_SOUND") - ) -) - ;; From empathy-account-chooser.h @@ -1541,28 +1522,31 @@ -;; From empathy-profile-chooser.h +;; From empathy-protocol-chooser.h -(define-function profile_chooser_get_type - (c-name "empathy_profile_chooser_get_type") +(define-function protocol_chooser_get_type + (c-name "empathy_protocol_chooser_get_type") (return-type "GType") ) -(define-function profile_chooser_new - (c-name "empathy_profile_chooser_new") - (is-constructor-of "EmpathyProfileChooser") +(define-function protocol_chooser_new + (c-name "empathy_protocol_chooser_new") + (is-constructor-of "EmpathyProtocolChooser") (return-type "GtkWidget*") ) (define-method dup_selected - (of-object "EmpathyProfileChooser") - (c-name "empathy_profile_chooser_dup_selected") - (return-type "McProfile*") + (of-object "EmpathyProtocolChooser") + (c-name "empathy_protocol_chooser_dup_selected") + (return-type "TpConnectionManager*") + (parameters + '("TpConnectionManagerProtocol**" "protocol") + ) ) -(define-method n_profiles - (of-object "EmpathyProfileChooser") - (c-name "empathy_profile_chooser_n_profiles") +(define-method n_protocols + (of-object "EmpathyProtocolChooser") + (c-name "empathy_protocol_chooser_n_protocols") (return-type "gint") ) @@ -1782,14 +1766,6 @@ ) ) -(define-function icon_name_from_account - (c-name "empathy_icon_name_from_account") - (return-type "const-gchar*") - (parameters - '("EmpathyAccount*" "account") - ) -) - (define-function icon_name_for_presence (c-name "empathy_icon_name_for_presence") (return-type "const-gchar*") @@ -1985,30 +1961,4 @@ ) ) -(define-function sound_play - (c-name "empathy_sound_play") - (return-type "none") - (parameters - '("GtkWidget*" "widget") - '("EmpathySound" "sound_id") - ) -) - -(define-function sound_play_full - (c-name "empathy_sound_play_full") - (return-type "gboolean") - (parameters - '("GtkWidget*" "widget") - '("EmpathySound" "sound_id") - '("ca_finish_callback_t" "callback") - '("gpointer" "user_data") - ) -) - -(define-method stop - (of-object "EmpathySound") - (c-name "empathy_sound_stop") - (return-type "none") -) - diff --git a/python/pyempathygtk/pyempathygtk.override b/python/pyempathygtk/pyempathygtk.override index 3229cbac2..035ef1344 100644 --- a/python/pyempathygtk/pyempathygtk.override +++ b/python/pyempathygtk/pyempathygtk.override @@ -27,7 +27,7 @@ headers #include "empathy-log-window.h" #include "empathy-new-message-dialog.h" #include "empathy-presence-chooser.h" -#include "empathy-profile-chooser.h" +#include "empathy-protocol-chooser.h" #include "empathy-smiley-manager.h" #include "empathy-spell.h" #include "empathy-theme-boxes.h" diff --git a/python/update-binding.sh b/python/update-binding.sh index 854c33159..3636b6341 100755 --- a/python/update-binding.sh +++ b/python/update-binding.sh @@ -74,7 +74,7 @@ python /usr/share/pygobject/2.0/codegen/h2def.py \ empathy-log-window.h \ empathy-new-message-dialog.h \ empathy-presence-chooser.h \ - empathy-profile-chooser.h \ + empathy-protocol-chooser.h \ empathy-smiley-manager.h \ empathy-spell.h \ empathy-theme-boxes.h \ -- cgit v1.2.3 From 13f92652db89b2c15c3302b4af7560a4e4ee22c9 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 6 Jul 2009 11:56:14 +0100 Subject: Remove useless mission-control includes --- libempathy-gtk/empathy-account-chooser.c | 2 -- libempathy-gtk/empathy-account-widget-irc.c | 2 -- libempathy-gtk/empathy-account-widget-sip.c | 2 -- libempathy-gtk/empathy-contact-dialogs.c | 2 -- libempathy-gtk/empathy-irc-network-dialog.c | 2 -- libempathy-gtk/empathy-new-message-dialog.c | 2 -- libempathy-gtk/empathy-theme-adium.c | 1 - libempathy-gtk/empathy-ui-utils.c | 2 -- libempathy-gtk/empathy-ui-utils.h | 2 -- libempathy/empathy-dispatcher.c | 2 -- libempathy/empathy-idle.h | 2 +- libempathy/empathy-log-manager.h | 2 -- megaphone/src/megaphone-applet.c | 2 -- nothere/src/nothere-applet.c | 1 - src/empathy-chat-window.c | 1 - src/empathy-main-window.c | 2 -- src/empathy-new-chatroom-dialog.c | 3 --- src/empathy.c | 1 - 18 files changed, 1 insertion(+), 32 deletions(-) diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c index 719cc76c2..ec2c2b18a 100644 --- a/libempathy-gtk/empathy-account-chooser.c +++ b/libempathy-gtk/empathy-account-chooser.c @@ -29,8 +29,6 @@ #include #include -#include - #include #include diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c index 688a3e0e6..7e0fb89ed 100644 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ b/libempathy-gtk/empathy-account-widget-irc.c @@ -27,8 +27,6 @@ #include #include -#include - #include #include diff --git a/libempathy-gtk/empathy-account-widget-sip.c b/libempathy-gtk/empathy-account-widget-sip.c index 05e917e53..ad8cd7d8e 100644 --- a/libempathy-gtk/empathy-account-widget-sip.c +++ b/libempathy-gtk/empathy-account-widget-sip.c @@ -28,8 +28,6 @@ #include #include -#include - #include #include "empathy-account-widget.h" diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index c1cca3e2b..5b11ddc2e 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -27,8 +27,6 @@ #include #include -#include - #include #include #include diff --git a/libempathy-gtk/empathy-irc-network-dialog.c b/libempathy-gtk/empathy-irc-network-dialog.c index e6b4a6f7f..8d4676417 100644 --- a/libempathy-gtk/empathy-irc-network-dialog.c +++ b/libempathy-gtk/empathy-irc-network-dialog.c @@ -27,8 +27,6 @@ #include #include -#include - #include #include diff --git a/libempathy-gtk/empathy-new-message-dialog.c b/libempathy-gtk/empathy-new-message-dialog.c index 77b368bd9..66b2adb2d 100644 --- a/libempathy-gtk/empathy-new-message-dialog.c +++ b/libempathy-gtk/empathy-new-message-dialog.c @@ -27,8 +27,6 @@ #include #include -#include - #include #include #include diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index ca0599e0e..0cc2c034d 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -31,7 +31,6 @@ #include #include -#include #include "empathy-theme-adium.h" #include "empathy-smiley-manager.h" diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index 00e6a0cb2..7b4cc1d43 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -38,8 +38,6 @@ #include #include -#include - #include "empathy-ui-utils.h" #include "empathy-images.h" #include "empathy-conf.h" diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index fe676b135..312835f0c 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -34,8 +34,6 @@ #include -#include - #include #include #include diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index b51df95fa..8618be6e0 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -32,8 +32,6 @@ #include #include -#include - #include #include "empathy-dispatcher.h" diff --git a/libempathy/empathy-idle.h b/libempathy/empathy-idle.h index 0f7f23deb..d2a802335 100644 --- a/libempathy/empathy-idle.h +++ b/libempathy/empathy-idle.h @@ -24,7 +24,7 @@ #include -#include +#include G_BEGIN_DECLS diff --git a/libempathy/empathy-log-manager.h b/libempathy/empathy-log-manager.h index 6907e2ede..a67f6e8dd 100644 --- a/libempathy/empathy-log-manager.h +++ b/libempathy/empathy-log-manager.h @@ -26,8 +26,6 @@ #include -#include - #include "empathy-message.h" #include "empathy-dispatcher.h" diff --git a/megaphone/src/megaphone-applet.c b/megaphone/src/megaphone-applet.c index 2e4fb1e72..7350c1873 100644 --- a/megaphone/src/megaphone-applet.c +++ b/megaphone/src/megaphone-applet.c @@ -31,8 +31,6 @@ #include #include -#include - #include #include #include diff --git a/nothere/src/nothere-applet.c b/nothere/src/nothere-applet.c index 243272e67..8cdde3e97 100644 --- a/nothere/src/nothere-applet.c +++ b/nothere/src/nothere-applet.c @@ -27,7 +27,6 @@ #include #include -#include #include #include diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index f9d0b924a..937e68aff 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -35,7 +35,6 @@ #include #include -#include #include #include diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index c7816d7fd..0d04153a3 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -49,8 +49,6 @@ #include #include -#include - #include "empathy-accounts-dialog.h" #include "empathy-main-window.h" #include "ephy-spinner.h" diff --git a/src/empathy-new-chatroom-dialog.c b/src/empathy-new-chatroom-dialog.c index 7313fd1e6..b36d0d4f5 100644 --- a/src/empathy-new-chatroom-dialog.c +++ b/src/empathy-new-chatroom-dialog.c @@ -32,9 +32,6 @@ #include #include -#include -#include - #include #include #include diff --git a/src/empathy.c b/src/empathy.c index 4b754c472..6439eecfa 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include -- cgit v1.2.3 From e98ae9bde97e290c0f54593af1cb30905bb9055e Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 8 Jul 2009 11:35:02 +0100 Subject: Add an GType of ao --- libempathy/empathy-utils.c | 10 ++++++++++ libempathy/empathy-utils.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index fd54c9a98..69779d99f 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -378,3 +378,13 @@ empathy_uint_compare (gconstpointer a, return *(guint *) a - *(guint *) b; } +GType +empathy_type_dbus_ao (void) +{ + static GType t = 0; + + if (G_UNLIKELY (t == 0)) + t = dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH); + + return t; +} diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 42acbc8e3..735946b92 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -80,6 +80,9 @@ gboolean empathy_check_available_state (void); gint empathy_uint_compare (gconstpointer a, gconstpointer b); +#define EMPATHY_ARRAY_TYPE_OBJECT (empathy_type_dbus_ao ()) +GType empathy_type_dbus_ao (void); + G_END_DECLS #endif /* __EMPATHY_UTILS_H__ */ -- cgit v1.2.3 From 96fad6a1159582a3e8792dd3308ce1fbeb178234 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 8 Jul 2009 11:35:43 +0100 Subject: Initial port of Account and AccountManager to MC5 --- libempathy-gtk/empathy-account-widget-irc.c | 13 +- libempathy-gtk/empathy-account-widget.c | 9 +- libempathy/Makefile.am | 1 - libempathy/empathy-account-manager.c | 185 ++++++++++---- libempathy/empathy-account-priv.h | 44 ---- libempathy/empathy-account.c | 368 +++++++++++++++++++++++----- libempathy/empathy-account.h | 6 +- src/empathy-accounts-dialog.c | 3 +- 8 files changed, 457 insertions(+), 172 deletions(-) delete mode 100644 libempathy/empathy-account-priv.h diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c index 7e0fb89ed..b2383a02a 100644 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ b/libempathy-gtk/empathy-account-widget-irc.c @@ -321,11 +321,11 @@ fill_networks_model (EmpathyAccountWidgetIrc *settings, static void account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) { - gchar *nick = NULL; - gchar *fullname = NULL; - gchar *server = NULL; + const gchar *nick = NULL; + const gchar *fullname = NULL; + const gchar *server = NULL; gint port = 6667; - gchar *charset; + const gchar *charset; gboolean ssl = FALSE; EmpathyIrcNetwork *network = NULL; @@ -402,11 +402,6 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) fill_networks_model (settings, network); - - g_free (nick); - g_free (fullname); - g_free (server); - g_free (charset); } /** diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 8b71e3fff..783a48a0a 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -52,13 +52,12 @@ account_widget_entry_focus_cb (GtkWidget *widget, param_name = g_object_get_data (G_OBJECT (widget), "param_name"); if (EMP_STR_EMPTY (str)) { - gchar *value = NULL; + const gchar *value = NULL; empathy_account_unset_param (account, param_name); value = empathy_account_get_param_string (account, param_name); DEBUG ("Unset %s and restore to %s", param_name, value); gtk_entry_set_text (GTK_ENTRY (widget), value ? value : ""); - g_free (value); } else { DEBUG ("Setting %s to %s", param_name, strstr (param_name, "password") ? "***" : str); @@ -185,11 +184,10 @@ account_widget_setup_widget (GtkWidget *widget, account); } else if (GTK_IS_ENTRY (widget)) { - gchar *str = NULL; + const gchar *str = NULL; str = empathy_account_get_param_string (account, param_name); gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); - g_free (str); if (strstr (param_name, "password")) { gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE); @@ -406,14 +404,13 @@ empathy_account_widget_add_forget_button (EmpathyAccount *account, { GtkWidget *button_forget; GtkWidget *entry_password; - gchar *password = NULL; + const gchar *password = NULL; button_forget = GTK_WIDGET (gtk_builder_get_object (gui, button)); entry_password = GTK_WIDGET (gtk_builder_get_object (gui, entry)); password = empathy_account_get_param_string (account, "password"); gtk_widget_set_sensitive (button_forget, !EMP_STR_EMPTY (password)); - g_free (password); g_signal_connect (button_forget, "clicked", G_CALLBACK (account_widget_forget_clicked_cb), diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 27671543a..545074aed 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -25,7 +25,6 @@ lib_LTLIBRARIES = libempathy.la libempathy_la_SOURCES = \ empathy-account.c \ - empathy-account-priv.h \ empathy-account-manager.c \ empathy-chatroom.c \ empathy-chatroom-manager.c \ diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 0d09ec5f0..c31ac0159 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -23,6 +23,9 @@ #include #include +#include +#include +#include #include "empathy-account-manager.h" #include "empathy-account-priv.h" @@ -34,15 +37,18 @@ #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountManager) +#define MC5_BUS_NAME "org.freedesktop.Telepathy.MissionControl5" + typedef struct { - McAccountMonitor *monitor; - MissionControl *mc; /* (owned) unique name -> (reffed) EmpathyAccount */ GHashTable *accounts; int connected; int connecting; gboolean dispose_run; + TpProxySignalConnection *proxy_signal; + TpAccountManager *tp_manager; + TpDBusDaemon *dbus; } EmpathyAccountManagerPriv; enum { @@ -62,6 +68,7 @@ static EmpathyAccountManager *manager_singleton = NULL; G_DEFINE_TYPE (EmpathyAccountManager, empathy_account_manager, G_TYPE_OBJECT); +#if 0 static TpConnectionPresenceType mc_presence_to_tp_presence (McPresence presence) { @@ -83,6 +90,7 @@ mc_presence_to_tp_presence (McPresence presence) return TP_CONNECTION_PRESENCE_TYPE_UNSET; } } +#endif static void emp_account_connection_cb (EmpathyAccount *account, @@ -98,6 +106,17 @@ emp_account_connection_cb (EmpathyAccount *account, g_signal_emit (manager, signals[NEW_CONNECTION], 0, connection); } +static void +emp_account_enabled_cb (EmpathyAccount *account, + GParamSpec *spec, + gpointer manager) +{ + if (empathy_account_is_enabled (account)) + g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account); + else + g_signal_emit (manager, signals[ACCOUNT_DISABLED], 0, account); +} + static void emp_account_status_changed_cb (EmpathyAccount *account, TpConnectionStatus old, @@ -147,11 +166,39 @@ emp_account_presence_changed_cb (EmpathyAccount *account, account, new, old); } +static void +emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) +{ + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); + EmpathyAccount *account = EMPATHY_ACCOUNT (obj); + gboolean ready; + + g_object_get (account, "ready", &ready, NULL); + + if (!ready) + return; + + g_signal_emit (manager, signals[ACCOUNT_CREATED], 0, account); + + g_signal_connect (account, "notify::connection", + G_CALLBACK (emp_account_connection_cb), manager); + + g_signal_connect (account, "notify::enabled", + G_CALLBACK (emp_account_enabled_cb), manager); + + g_signal_connect (account, "status-changed", + G_CALLBACK (emp_account_status_changed_cb), manager); + + g_signal_connect (account, "presence-changed", + G_CALLBACK (emp_account_presence_changed_cb), manager); +} + static EmpathyAccount * create_account (EmpathyAccountManager *manager, const gchar *account_name, McAccount *mc_account) { +#if 0 EmpathyAccountManagerPriv *priv = GET_PRIV (manager); EmpathyAccount *account; TpConnectionStatus status; @@ -210,8 +257,11 @@ create_account (EmpathyAccountManager *manager, presence); return account; +#endif + return NULL; } +#if 0 static void account_created_cb (McAccountMonitor *mon, gchar *account_name, @@ -254,39 +304,6 @@ account_changed_cb (McAccountMonitor *mon, g_signal_emit (manager, signals[ACCOUNT_CHANGED], 0, account); } -static void -account_disabled_cb (McAccountMonitor *mon, - gchar *account_name, - EmpathyAccountManager *manager) -{ - EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - EmpathyAccount *account; - - account = g_hash_table_lookup (priv->accounts, account_name); - - if (account) - { - _empathy_account_set_enabled (account, FALSE); - g_signal_emit (manager, signals[ACCOUNT_DISABLED], 0, account); - } -} - -static void -account_enabled_cb (McAccountMonitor *mon, - gchar *account_name, - EmpathyAccountManager *manager) -{ - EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - EmpathyAccount *account; - - account = g_hash_table_lookup (priv->accounts, account_name); - - if (account) - { - _empathy_account_set_enabled (account, TRUE); - g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account); - } -} typedef struct { TpConnectionStatus status; @@ -335,7 +352,9 @@ account_status_changed_idle_cb (ChangedSignalData *signal_data) return FALSE; } +#endif +#if 0 static void account_status_changed_cb (MissionControl *mc, TpConnectionStatus status, @@ -360,27 +379,104 @@ account_status_changed_cb (MissionControl *mc, g_idle_add ((GSourceFunc) account_status_changed_idle_cb, data); } +#endif + +static void +account_manager_got_all_cb (TpProxy *proxy, + GHashTable *properties, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + GPtrArray *accounts; + int i; + + if (error != NULL) + { + DEBUG ("Failed to get account manager properties: %s", error->message); + return; + } + + accounts = tp_asv_get_boxed (properties, "ValidAccounts", + EMPATHY_ARRAY_TYPE_OBJECT); + + + for (i = 0; i < accounts->len; i++) + { + EmpathyAccount *account; + gchar *name = g_ptr_array_index (accounts, i); + + account = empathy_account_new (priv->dbus, name); + g_hash_table_insert (priv->accounts, g_strdup (name), account); + + g_signal_connect (account, "notify::ready", + G_CALLBACK (emp_account_ready_cb), manager); + } +} + +static void +account_manager_name_owner_changed_cb (TpDBusDaemon *proxy, + const gchar *arg0, + const gchar *arg1, + const gchar *arg2, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + + tp_proxy_signal_connection_disconnect (priv->proxy_signal); + priv->proxy_signal = NULL; + + priv->tp_manager = tp_account_manager_new (priv->dbus); + tp_cli_dbus_properties_call_get_all (priv->tp_manager, -1, + TP_IFACE_ACCOUNT_MANAGER, + account_manager_got_all_cb, + NULL, + NULL, + G_OBJECT (manager)); +} static void empathy_account_manager_init (EmpathyAccountManager *manager) { EmpathyAccountManagerPriv *priv; - GList *mc_accounts, *l; + TpProxy *mc5_proxy; priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManagerPriv); manager->priv = priv; - priv->monitor = mc_account_monitor_new (); - priv->mc = empathy_mission_control_dup_singleton (); priv->connected = priv->connecting = 0; - priv->dispose_run = FALSE; priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); - mc_accounts = mc_accounts_list (); + priv->dbus = tp_dbus_daemon_dup (NULL); + priv->proxy_signal = tp_cli_dbus_daemon_connect_to_name_owner_changed ( + priv->dbus, + account_manager_name_owner_changed_cb, + TP_ACCOUNT_MANAGER_BUS_NAME, + NULL, + G_OBJECT (manager), + NULL); + + /* trigger MC5 starting */ + mc5_proxy = g_object_new (TP_TYPE_PROXY, + "dbus-daemon", priv->dbus, + "dbus-connection", tp_proxy_get_dbus_connection (TP_PROXY (priv->dbus)), + "bus-name", MC5_BUS_NAME, + "object-path", "/", + NULL); + + tp_cli_dbus_peer_call_ping (mc5_proxy, -1, NULL, NULL, NULL, NULL); + + g_object_unref (mc5_proxy); + +#if 0 for (l = mc_accounts; l; l = l->next) account_created_cb (priv->monitor, (char *) mc_account_get_unique_name (l->data), manager); @@ -401,6 +497,7 @@ empathy_account_manager_init (EmpathyAccountManager *manager) manager, NULL); mc_accounts_list_free (mc_accounts); +#endif } static void @@ -425,6 +522,11 @@ do_dispose (GObject *obj) priv->dispose_run = TRUE; + if (priv->dbus == NULL) + g_object_unref (priv->dbus); + priv->dbus = NULL; + +#if 0 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged", G_CALLBACK (account_status_changed_cb), @@ -450,6 +552,7 @@ do_dispose (GObject *obj) g_object_unref (priv->mc); g_hash_table_remove_all (priv->accounts); +#endif G_OBJECT_CLASS (empathy_account_manager_parent_class)->dispose (obj); } @@ -769,5 +872,5 @@ void empathy_account_manager_remove (EmpathyAccountManager *manager, EmpathyAccount *account) { - mc_account_delete (_empathy_account_get_mc_account (account)); + /* FIXME */ } diff --git a/libempathy/empathy-account-priv.h b/libempathy/empathy-account-priv.h deleted file mode 100644 index 8b656b4d8..000000000 --- a/libempathy/empathy-account-priv.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * empathy-account-priv.h - Private Header for EmpathyAccount - * Copyright (C) 2009 Collabora Ltd. - * @author Sjoerd Simons - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __EMPATHY_ACCOUNT_PRIV_H__ -#define __EMPATHY_ACCOUNT_PRIV_H__ - -#include - -#include -#include "empathy-account.h" - -G_BEGIN_DECLS - -EmpathyAccount *_empathy_account_new (McAccount *account); -void _empathy_account_set_status (EmpathyAccount *account, - TpConnectionStatus status, - TpConnectionStatusReason reason, - TpConnectionPresenceType presence); -void _empathy_account_set_connection (EmpathyAccount *account, - TpConnection *connection); -void _empathy_account_set_enabled (EmpathyAccount *account, - gboolean enabled); -McAccount *_empathy_account_get_mc_account (EmpathyAccount *account); - -G_END_DECLS - -#endif /* #ifndef __EMPATHY_ACCOUNT_PRIV_H__*/ diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index c6a2184f9..010990d7a 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -18,20 +18,25 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - #include #include +#include #include +#include +#include +#include +#include #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include #include "empathy-account.h" -#include "empathy-account-priv.h" #include "empathy-utils.h" #include "empathy-marshal.h" +#define UNIQUE_NAME_PREFIX "/org/freedesktop/Telepathy/Account/" + /* signals */ enum { STATUS_CHANGED, @@ -45,10 +50,12 @@ static guint signals[LAST_SIGNAL]; enum { PROP_ENABLED = 1, PROP_PRESENCE, + PROP_READY, PROP_CONNECTION_STATUS, PROP_CONNECTION_STATUS_REASON, PROP_CONNECTION, PROP_UNIQUE_NAME, + PROP_DBUS_DAEMON, PROP_DISPLAY_NAME }; @@ -69,19 +76,28 @@ struct _EmpathyAccountPriv TpConnectionPresenceType presence; gboolean enabled; + gboolean valid; + gboolean ready; /* Timestamp when the connection got connected in seconds since the epoch */ glong connect_time; - McAccount *mc_account; - McProfile *mc_profile; - gchar *cm_name; gchar *proto_name; gchar *icon_name; + + gchar *unique_name; + gchar *display_name; + TpDBusDaemon *dbus; + + TpAccount *account; + GHashTable *parameters; }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount) +static void _empathy_account_set_connection (EmpathyAccount *account, + TpConnection *connection); + static void empathy_account_init (EmpathyAccount *obj) { @@ -95,6 +111,32 @@ empathy_account_init (EmpathyAccount *obj) priv->status = TP_CONNECTION_STATUS_DISCONNECTED; } +static void +empathy_account_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + switch (prop_id) + { + case PROP_ENABLED: + empathy_account_set_enabled (account, g_value_get_boolean (value)); + break; + case PROP_UNIQUE_NAME: + priv->unique_name = g_value_dup_string (value); + break; + case PROP_DBUS_DAEMON: + priv->dbus = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void empathy_account_get_property (GObject *object, guint prop_id, @@ -109,6 +151,9 @@ empathy_account_get_property (GObject *object, case PROP_ENABLED: g_value_set_boolean (value, priv->enabled); break; + case PROP_READY: + g_value_set_boolean (value, priv->enabled); + break; case PROP_PRESENCE: g_value_set_uint (value, priv->presence); break; @@ -130,12 +175,208 @@ empathy_account_get_property (GObject *object, g_value_set_string (value, empathy_account_get_display_name (account)); break; + case PROP_DBUS_DAEMON: + g_value_set_string (value, + empathy_account_get_display_name (account)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } +static void +empathy_account_update (EmpathyAccount *account, GHashTable *properties) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + const gchar *conn_path; + GValueArray *arr; + TpConnectionStatus old_s = priv->status; + TpConnectionPresenceType old_p = priv->presence; + + if (g_hash_table_lookup (properties, "ConnectionStatus") != NULL) + priv->status = tp_asv_get_int32 (properties, "ConnectionStatus", NULL); + + if (g_hash_table_lookup (properties, "ConnectionStatusReason") != NULL) + priv->reason = tp_asv_get_int32 (properties, + "ConnectionStatusReason", NULL); + + if (g_hash_table_lookup (properties, "CurrentPresence") != NULL) + { + arr = tp_asv_get_boxed (properties, "CurrentPresence", + TP_STRUCT_TYPE_SIMPLE_PRESENCE); + priv->presence = g_value_get_uint (g_value_array_get_nth (arr, 0)); + } + + if (g_hash_table_lookup (properties, "DisplayName") != NULL) + priv->display_name = + g_strdup (tp_asv_get_string (properties, "DisplayName")); + + if (g_hash_table_lookup (properties, "Enabled") != NULL) + empathy_account_set_enabled (account, + tp_asv_get_boolean (properties, "Enabled", NULL)); + + if (g_hash_table_lookup (properties, "Valid") != NULL) + priv->valid = tp_asv_get_boolean (properties, "Valid", NULL); + + if (g_hash_table_lookup (properties, "Parameters") != NULL) + { + GHashTable *parameters; + + parameters = tp_asv_get_boxed (properties, "Parameters", + TP_HASH_TYPE_STRING_VARIANT_MAP); + + priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP, + parameters); + } + + if (!priv->ready) + { + priv->ready = TRUE; + g_object_notify (G_OBJECT (account), "ready"); + } + + if (priv->status != old_s) + { + if (priv->status == TP_CONNECTION_STATUS_CONNECTED) + { + GTimeVal val; + g_get_current_time (&val); + + priv->connect_time = val.tv_sec; + } + + g_signal_emit (account, signals[STATUS_CHANGED], 0, + old_s, priv->status, priv->reason); + + g_object_notify (G_OBJECT (account), "status"); + } + + if (priv->presence != old_p) + { + g_signal_emit (account, signals[PRESENCE_CHANGED], 0, + old_p, priv->presence); + g_object_notify (G_OBJECT (account), "presence"); + } + + if (g_hash_table_lookup (properties, "Connection") != NULL) + { + conn_path = tp_asv_get_object_path (properties, "Connection"); + + if (tp_strdiff (conn_path, "/") && priv->connection == NULL) + { + TpConnection *conn; + GError *error = NULL; + conn = tp_connection_new (priv->dbus, NULL, conn_path, &error); + + if (conn == NULL) + { + DEBUG ("Failed to create a new TpConnection: %s", + error->message); + g_error_free (error); + } + + _empathy_account_set_connection (account, conn); + } + } +} + +static void +empathy_account_properties_changed (TpAccount *proxy, + GHashTable *properties, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (!priv->ready) + return; + + empathy_account_update (account, properties); +} + +static void +empathy_account_got_all_cb (TpProxy *proxy, + GHashTable *properties, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + + if (error != NULL) + { + printf ("Unhappy\n"); + return; + } + + empathy_account_update (account, properties); +} + +static gboolean +empathy_account_parse_unique_name (const gchar *bus_name, + gchar **protocol, gchar **manager) +{ + const gchar *proto, *proto_end; + const gchar *cm, *cm_end; + + g_return_val_if_fail ( + g_str_has_prefix (bus_name, UNIQUE_NAME_PREFIX), FALSE); + + cm = bus_name + strlen (UNIQUE_NAME_PREFIX); + + for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++) + /* pass */; + + if (*cm_end == '\0') + return FALSE; + + if (cm_end == '\0') + return FALSE; + + proto = cm_end + 1; + + for (proto_end = proto; *proto_end != '/' && *proto_end != '\0'; proto_end++) + /* pass */; + + if (*proto_end == '\0') + return FALSE; + + if (protocol != NULL) + *protocol = g_strndup (proto, proto_end - proto); + + if (manager != NULL) + *manager = g_strndup (cm, cm_end - cm); + + return TRUE; +} + +static void +empathy_account_constructed (GObject *object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL); + + empathy_account_parse_unique_name (priv->unique_name, + &(priv->proto_name), &(priv->cm_name)); + + priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name); + + tp_cli_account_connect_to_account_property_changed (priv->account, + empathy_account_properties_changed, + NULL, NULL, object, NULL); + + tp_cli_dbus_properties_call_get_all (priv->account, -1, + TP_IFACE_ACCOUNT, + empathy_account_got_all_cb, + NULL, + NULL, + G_OBJECT (account)); +} + static void empathy_account_dispose (GObject *object); static void empathy_account_finalize (GObject *object); @@ -147,15 +388,24 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) g_type_class_add_private (empathy_account_class, sizeof (EmpathyAccountPriv)); + object_class->set_property = empathy_account_set_property; object_class->get_property = empathy_account_get_property; object_class->dispose = empathy_account_dispose; object_class->finalize = empathy_account_finalize; + object_class->constructed = empathy_account_constructed; g_object_class_install_property (object_class, PROP_ENABLED, g_param_spec_boolean ("enabled", "Enabled", "Whether this account is enabled or not", FALSE, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_READY, + g_param_spec_boolean ("ready", + "Ready", + "Whether this account is ready to be used", + FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_PRESENCE, @@ -197,7 +447,14 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) "UniqueName", "The accounts unique name", NULL, - G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_DBUS_DAEMON, + g_param_spec_object ("dbus-daemon", + "dbus-daemon", + "The Tp Dbus daemon on which this account exists", + TP_TYPE_DBUS_DAEMON, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_DISPLAY_NAME, g_param_spec_string ("display-name", @@ -241,10 +498,6 @@ empathy_account_dispose (GObject *object) g_object_unref (priv->connection); priv->connection = NULL; - if (priv->mc_profile != NULL) - g_object_unref (priv->mc_profile); - priv->mc_profile = NULL; - /* release any references held by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL) G_OBJECT_CLASS (empathy_account_parent_class)->dispose (object); @@ -258,6 +511,7 @@ empathy_account_finalize (GObject *object) g_free (priv->cm_name); g_free (priv->proto_name); g_free (priv->icon_name); + g_free (priv->display_name); /* free any data held directly by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL) @@ -310,7 +564,7 @@ empathy_account_get_unique_name (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return mc_account_get_unique_name (priv->mc_account); + return priv->unique_name; } /** @@ -324,15 +578,16 @@ empathy_account_get_display_name (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return mc_account_get_display_name (priv->mc_account); + return priv->display_name; } gboolean empathy_account_is_valid (EmpathyAccount *account) { - EmpathyAccountPriv *priv = GET_PRIV (account); + //EmpathyAccountPriv *priv = GET_PRIV (account); - return mc_account_is_complete (priv->mc_account); + /* FIXME */ + return FALSE; } const gchar * @@ -359,14 +614,6 @@ empathy_account_get_icon_name (EmpathyAccount *account) return priv->icon_name; } -void -empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - - mc_account_set_enabled (priv->mc_account, enabled); -} - gboolean empathy_account_is_enabled (EmpathyAccount *account) { @@ -378,39 +625,33 @@ empathy_account_is_enabled (EmpathyAccount *account) void empathy_account_unset_param (EmpathyAccount *account, const gchar *param) { - EmpathyAccountPriv *priv = GET_PRIV (account); + //EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_unset_param (priv->mc_account, param); + //mc_account_unset_param (priv->mc_account, param); } -gchar * +const gchar * empathy_account_get_param_string (EmpathyAccount *account, const gchar *param) { EmpathyAccountPriv *priv = GET_PRIV (account); - gchar *value = NULL; - mc_account_get_param_string (priv->mc_account, param, &value); - return value; + return tp_asv_get_string (priv->parameters, param); } gint empathy_account_get_param_int (EmpathyAccount *account, const gchar *param) { EmpathyAccountPriv *priv = GET_PRIV (account); - int value; - mc_account_get_param_int (priv->mc_account, param, &value); - return value; + return tp_asv_get_int32 (priv->parameters, param, NULL); } gboolean empathy_account_get_param_boolean (EmpathyAccount *account, const gchar *param) { EmpathyAccountPriv *priv = GET_PRIV (account); - gboolean value; - mc_account_get_param_boolean (priv->mc_account, param, &value); - return value; + return tp_asv_get_boolean (priv->parameters, param, NULL); } void @@ -418,8 +659,8 @@ empathy_account_set_param_string (EmpathyAccount *account, const gchar *param, const gchar *value) { - EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_set_param_string (priv->mc_account, param, value); + //EmpathyAccountPriv *priv = GET_PRIV (account); + //mc_account_set_param_string (priv->mc_account, param, value); } void @@ -427,8 +668,8 @@ empathy_account_set_param_int (EmpathyAccount *account, const gchar *param, gint value) { - EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_set_param_int (priv->mc_account, param, value); + //EmpathyAccountPriv *priv = GET_PRIV (account); + //mc_account_set_param_int (priv->mc_account, param, value); } void @@ -436,18 +677,29 @@ empathy_account_set_param_boolean (EmpathyAccount *account, const gchar *param, gboolean value) { - EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_set_param_boolean (priv->mc_account, param, value); + //EmpathyAccountPriv *priv = GET_PRIV (account); + //mc_account_set_param_boolean (priv->mc_account, param, value); } void empathy_account_set_display_name (EmpathyAccount *account, const gchar *display_name) { - EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_set_display_name (priv->mc_account, display_name); + //EmpathyAccountPriv *priv = GET_PRIV (account); + //mc_account_set_display_name (priv->mc_account, display_name); } + +EmpathyAccount * +empathy_account_new (TpDBusDaemon *dbus, const gchar *unique_name) +{ + return EMPATHY_ACCOUNT (g_object_new (EMPATHY_TYPE_ACCOUNT, + "dbus-daemon", dbus, + "unique-name", unique_name, + NULL)); +} + +#if 0 EmpathyAccount * _empathy_account_new (McAccount *mc_account) { @@ -470,7 +722,6 @@ _empathy_account_new (McAccount *mc_account) priv->proto_name = g_strdup (mc_protocol_get_name (protocol)); priv->cm_name = g_strdup (mc_manager_get_unique_name (manager)); - priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name); g_object_unref (protocol); g_object_unref (manager); @@ -493,30 +744,8 @@ _empathy_account_set_status (EmpathyAccount *account, priv->status = status; priv->presence = presence; - if (priv->status != old_s) - { - if (priv->status == TP_CONNECTION_STATUS_CONNECTED) - { - GTimeVal val; - g_get_current_time (&val); - - priv->connect_time = val.tv_sec; - } - - priv->reason = reason; - g_signal_emit (account, signals[STATUS_CHANGED], 0, - old_s, priv->status, reason); - - g_object_notify (G_OBJECT (account), "status"); - } - - if (priv->presence != old_p) - { - g_signal_emit (account, signals[PRESENCE_CHANGED], 0, - old_p, priv->presence); - g_object_notify (G_OBJECT (account), "presence"); - } } +#endif static void empathy_account_connection_ready_cb (TpConnection *connection, @@ -568,7 +797,7 @@ _empathy_account_connection_invalidated_cb (TpProxy *self, g_object_notify (G_OBJECT (account), "connection"); } -void +static void _empathy_account_set_connection (EmpathyAccount *account, TpConnection *connection) { @@ -599,6 +828,7 @@ _empathy_account_set_connection (EmpathyAccount *account, G_CALLBACK (_empathy_account_connection_invalidated_cb), account); + DEBUG ("Readying connection for %s", priv->unique_name); /* notify a change in the connection property when it's ready */ tp_connection_call_when_ready (priv->connection, empathy_account_connection_ready_cb, account); @@ -606,7 +836,7 @@ _empathy_account_set_connection (EmpathyAccount *account, } void -_empathy_account_set_enabled (EmpathyAccount *account, +empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) { EmpathyAccountPriv *priv = GET_PRIV (account); @@ -618,6 +848,7 @@ _empathy_account_set_enabled (EmpathyAccount *account, g_object_notify (G_OBJECT (account), "enabled"); } +#if 0 McAccount * _empathy_account_get_mc_account (EmpathyAccount *account) { @@ -625,3 +856,4 @@ _empathy_account_get_mc_account (EmpathyAccount *account) return priv->mc_account; } +#endif diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 95879215c..ab09e52f2 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -70,7 +70,7 @@ void empathy_account_set_enabled (EmpathyAccount *account, gboolean empathy_account_is_enabled (EmpathyAccount *account); void empathy_account_unset_param (EmpathyAccount *account, const gchar *param); -gchar *empathy_account_get_param_string (EmpathyAccount *account, +const gchar *empathy_account_get_param_string (EmpathyAccount *account, const gchar *param); gint empathy_account_get_param_int (EmpathyAccount *account, const gchar *param); @@ -85,10 +85,14 @@ void empathy_account_set_param_boolean (EmpathyAccount *account, const gchar *param, gboolean value); gboolean empathy_account_is_valid (EmpathyAccount *account); +gboolean empathy_account_is_ready (EmpathyAccount *account); void empathy_account_set_display_name (EmpathyAccount *account, const gchar *display_name); +EmpathyAccount *empathy_account_new (TpDBusDaemon *bus_daemon, + const gchar *unique_name); + G_END_DECLS #endif /* #ifndef __EMPATHY_ACCOUNT_H__*/ diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index c523a2138..47e2887b0 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -637,7 +637,7 @@ accounts_dialog_account_added_cb (EmpathyAccountManager *manager, EmpathyAccountsDialog *dialog) { const gchar *current_name; - gchar *account_param = NULL; + const gchar *account_param = NULL; accounts_dialog_add_or_update_account (dialog, account); @@ -663,7 +663,6 @@ accounts_dialog_account_added_cb (EmpathyAccountManager *manager, } else { /* FIXME: This CM has no account parameter, what can be done? */ } - g_free (account_param); } static void -- cgit v1.2.3 From 6389342273e991e9b4c17d15fe82b709801a6983 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 8 Jul 2009 16:18:56 +0100 Subject: Add api to set the requested presence --- libempathy/empathy-account.c | 43 +++++++++++++++++++++++++++++++++++++++++++ libempathy/empathy-account.h | 4 ++++ 2 files changed, 47 insertions(+) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 010990d7a..d965fac62 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -848,6 +848,49 @@ empathy_account_set_enabled (EmpathyAccount *account, g_object_notify (G_OBJECT (account), "enabled"); } +static void +empathy_account_requested_presence_cb (TpProxy *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + if (error) + DEBUG (":( : %s", error->message); +} + + +void +empathy_account_request_presence (EmpathyAccount *account, + TpConnectionPresenceType type, + const gchar *status, + const gchar *message) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + GValue value = {0, }; + GValueArray *arr; + + g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE); + g_value_take_boxed (&value, dbus_g_type_specialized_construct + (TP_STRUCT_TYPE_SIMPLE_PRESENCE)); + arr = (GValueArray *) g_value_get_boxed (&value); + + g_value_set_uint (arr->values, type); + g_value_set_static_string (arr->values + 1, status); + g_value_set_static_string (arr->values + 2, message); + + tp_cli_dbus_properties_call_set (TP_PROXY (priv->account), + -1, + TP_IFACE_ACCOUNT, + "RequestedPresence", + &value, + empathy_account_requested_presence_cb, + NULL, + NULL, + G_OBJECT (account)); + + g_value_unset (&value); +} + #if 0 McAccount * _empathy_account_get_mc_account (EmpathyAccount *account) diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index ab09e52f2..4be35a919 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -93,6 +93,10 @@ void empathy_account_set_display_name (EmpathyAccount *account, EmpathyAccount *empathy_account_new (TpDBusDaemon *bus_daemon, const gchar *unique_name); +void empathy_account_request_presence (EmpathyAccount *account, + TpConnectionPresenceType type, const gchar *status, const gchar *message); + + G_END_DECLS #endif /* #ifndef __EMPATHY_ACCOUNT_H__*/ -- cgit v1.2.3 From 5182ada04ef43baabccfcc46b1ff0ea754f572b0 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 8 Jul 2009 16:19:18 +0100 Subject: Add a utility to set the presence on all requested accounts --- libempathy/empathy-account-manager.c | 29 ++++++++++++++++++++++++++++- libempathy/empathy-account-manager.h | 6 ++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index c31ac0159..b443c2cd0 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -40,7 +40,6 @@ #define MC5_BUS_NAME "org.freedesktop.Telepathy.MissionControl5" typedef struct { - /* (owned) unique name -> (reffed) EmpathyAccount */ GHashTable *accounts; int connected; @@ -874,3 +873,31 @@ empathy_account_manager_remove (EmpathyAccountManager *manager, { /* FIXME */ } + + +void +empathy_account_manager_request_global_presence ( + EmpathyAccountManager *manager, + TpConnectionPresenceType type, + const gchar *status, + const gchar *message) +{ + /* FIXME should remember requested presence and set it on new accounts + as well */ + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + GHashTableIter iter; + gpointer value; + + g_hash_table_iter_init (&iter, priv->accounts); + while (g_hash_table_iter_next (&iter, NULL, &value)) + { + EmpathyAccount *account = EMPATHY_ACCOUNT (value); + gboolean ready; + + g_object_get (account, "ready", &ready, NULL); + + if (ready) + empathy_account_request_presence (account, type, status, message); + } +} + diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index 2d77610fb..5d794bd83 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -81,6 +81,12 @@ void empathy_account_manager_remove ( EmpathyAccountManager *manager, EmpathyAccount *account); +void empathy_account_manager_request_global_presence ( + EmpathyAccountManager *manager, + TpConnectionPresenceType type, + const gchar *status, + const gchar *message); + G_END_DECLS #endif /* __EMPATHY_ACCOUNT_MANAGER_H__ */ -- cgit v1.2.3 From 8022c4d5692acc7406f3fa3cb8cacb443c2b96d4 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 8 Jul 2009 16:19:48 +0100 Subject: Use the account manager to set the presence --- libempathy/empathy-idle.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 5d2fa2bdc..9b34fc7f1 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -33,6 +33,7 @@ #include #include +#include "empathy-account-manager.h" #include "empathy-idle.h" #include "empathy-utils.h" @@ -63,6 +64,8 @@ typedef struct { gboolean is_idle; gboolean nm_connected; guint ext_away_timeout; + + EmpathyAccountManager *manager; } EmpathyIdlePriv; typedef enum { @@ -296,6 +299,9 @@ idle_finalize (GObject *object) g_object_unref (priv->gs_proxy); } + if (priv->manager != NULL) + g_object_unref (priv->manager); + #ifdef HAVE_NM if (priv->nm_client) { g_object_unref (priv->nm_client); @@ -482,6 +488,8 @@ empathy_idle_init (EmpathyIdle *idle) idle->priv = priv; priv->is_idle = FALSE; priv->mc = empathy_mission_control_dup_singleton (); + + priv->manager = empathy_account_manager_dup_singleton (); priv->state = empathy_idle_get_actual_presence (idle, &error); if (error) { DEBUG ("Error getting actual presence: %s", error->message); @@ -617,33 +625,12 @@ empathy_idle_do_set_presence (EmpathyIdle *idle, TpConnectionPresenceType state, const gchar *status) { - McPresence mc_state = MC_PRESENCE_UNSET; EmpathyIdlePriv *priv = GET_PRIV (idle); - switch (state) { - case TP_CONNECTION_PRESENCE_TYPE_OFFLINE: - mc_state = MC_PRESENCE_OFFLINE; - break; - case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE: - mc_state = MC_PRESENCE_AVAILABLE; - break; - case TP_CONNECTION_PRESENCE_TYPE_AWAY: - mc_state = MC_PRESENCE_AWAY; - break; - case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY: - mc_state = MC_PRESENCE_EXTENDED_AWAY; - break; - case TP_CONNECTION_PRESENCE_TYPE_HIDDEN: - mc_state = MC_PRESENCE_HIDDEN; - break; - case TP_CONNECTION_PRESENCE_TYPE_BUSY: - mc_state = MC_PRESENCE_DO_NOT_DISTURB; - break; - default: - g_assert_not_reached (); - } - mission_control_set_presence (priv->mc, mc_state, status, NULL, NULL); + /* FIXME */ + empathy_account_manager_request_global_presence (priv->manager, + state, "available", status); } void -- cgit v1.2.3 From db59070855af10bc2ac8ac7355f80a27f6f91d3d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 10 Jul 2009 11:51:39 +0100 Subject: Implement a first minimal version of a Client.Handler --- libempathy/empathy-dispatcher.c | 290 ++++++++++++++++++++++++---------------- libempathy/empathy-dispatcher.h | 2 + 2 files changed, 176 insertions(+), 116 deletions(-) diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 8618be6e0..721d398d9 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -19,6 +19,9 @@ * Cosimo Cecchi */ +#define DISPATCHER_BUS_NAME TP_CLIENT_BUS_NAME_BASE "Empathy" +#define DISPATCHER_OBJECT_PATH TP_CLIENT_OBJECT_PATH_BASE "Empathy" + #include #include @@ -31,6 +34,9 @@ #include #include #include +#include +#include +#include #include @@ -62,7 +68,29 @@ typedef struct GHashTable *request_channel_class_async_ids; } EmpathyDispatcherPriv; -G_DEFINE_TYPE (EmpathyDispatcher, empathy_dispatcher, G_TYPE_OBJECT); +static void empathy_dispatcher_client_handler_iface_init (gpointer g_iface, + gpointer g_iface_data); + +G_DEFINE_TYPE_WITH_CODE (EmpathyDispatcher, + empathy_dispatcher, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, + tp_dbus_properties_mixin_iface_init); + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CLIENT, NULL); + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CLIENT_HANDLER, + empathy_dispatcher_client_handler_iface_init); + ); + +static const gchar *empathy_displatcher_interfaces[] = { + TP_IFACE_CLIENT_HANDLER, + NULL +}; + +enum +{ + PROP_INTERFACES = 1, + PROP_CHANNEL_FILTER, +}; enum { @@ -636,30 +664,11 @@ dispatcher_connection_new_channel (EmpathyDispatcher *dispatcher, } static void -dispatcher_connection_new_channel_cb (TpConnection *connection, - const gchar *object_path, - const gchar *channel_type, - guint handle_type, - guint handle, - gboolean suppress_handler, - gpointer user_data, - GObject *object) -{ - EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object); - - /* Empathy heavily abuses surpress handler (don't try this at home), if - * surpress handler is true then it is an outgoing channel, which is - * requested either by us or some other party (like the megaphone applet). - * Otherwise it's an incoming channel */ - dispatcher_connection_new_channel (dispatcher, connection, - object_path, channel_type, handle_type, handle, NULL, !suppress_handler); -} - -static void -dispatcher_connection_new_channel_with_properties (EmpathyDispatcher *dispatcher, - TpConnection *connection, - const gchar *object_path, - GHashTable *properties) +dispatcher_connection_new_channel_with_properties ( + EmpathyDispatcher *dispatcher, + TpConnection *connection, + const gchar *object_path, + GHashTable *properties) { const gchar *channel_type; guint handle_type; @@ -706,29 +715,6 @@ dispatcher_connection_new_channel_with_properties (EmpathyDispatcher *dispatcher object_path, channel_type, handle_type, handle, properties, !requested); } -static void -dispatcher_connection_new_channels_cb (TpConnection *connection, - const GPtrArray *channels, - gpointer user_data, - GObject *object) -{ - EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object); - int i; - - for (i = 0; i < channels->len ; i++) - { - GValueArray *arr = g_ptr_array_index (channels, i); - const gchar *object_path; - GHashTable *properties; - - object_path = g_value_get_boxed (g_value_array_get_nth (arr, 0)); - properties = g_value_get_boxed (g_value_array_get_nth (arr, 1)); - - dispatcher_connection_new_channel_with_properties (dispatcher, - connection, object_path, properties); - } -} - static void dispatcher_connection_got_all (TpProxy *proxy, GHashTable *properties, @@ -738,7 +724,6 @@ dispatcher_connection_got_all (TpProxy *proxy, { EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object); EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); - GPtrArray *channels; GPtrArray *requestable_channels; if (error) { @@ -746,15 +731,6 @@ dispatcher_connection_got_all (TpProxy *proxy, return; } - channels = tp_asv_get_boxed (properties, "Channels", - TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST); - - if (channels == NULL) - DEBUG ("No Channels property !?! on connection"); - else - dispatcher_connection_new_channels_cb (TP_CONNECTION (proxy), - channels, NULL, object); - requestable_channels = tp_asv_get_boxed (properties, "RequestableChannelClasses", TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST); @@ -795,38 +771,6 @@ dispatcher_connection_got_all (TpProxy *proxy, } } -static void -dispatcher_connection_list_channels_cb (TpConnection *connection, - const GPtrArray *channels, - const GError *error, - gpointer user_data, - GObject *dispatcher) -{ - int i; - - if (error) - { - DEBUG ("Error: %s", error->message); - return; - } - - for (i = 0; i < channels->len; i++) - { - GValueArray *values; - - values = g_ptr_array_index (channels, i); - /* We don't have any extra info, so assume already existing channels are - * incoming... */ - dispatcher_connection_new_channel (EMPATHY_DISPATCHER (dispatcher), - connection, - g_value_get_boxed (g_value_array_get_nth (values, 0)), - g_value_get_string (g_value_array_get_nth (values, 1)), - g_value_get_uint (g_value_array_get_nth (values, 2)), - g_value_get_uint (g_value_array_get_nth (values, 3)), - NULL, TRUE); - } -} - static void dispatcher_connection_advertise_capabilities_cb (TpConnection *connection, const GPtrArray *capabilities, @@ -861,26 +805,11 @@ dispatcher_new_connection_cb (EmpathyAccountManager *manager, if (tp_proxy_has_interface_by_id (TP_PROXY (connection), TP_IFACE_QUARK_CONNECTION_INTERFACE_REQUESTS)) { - tp_cli_connection_interface_requests_connect_to_new_channels (connection, - dispatcher_connection_new_channels_cb, - NULL, NULL, G_OBJECT (dispatcher), NULL); - tp_cli_dbus_properties_call_get_all (connection, -1, TP_IFACE_CONNECTION_INTERFACE_REQUESTS, dispatcher_connection_got_all, NULL, NULL, G_OBJECT (dispatcher)); } - else - { - tp_cli_connection_connect_to_new_channel (connection, - dispatcher_connection_new_channel_cb, - NULL, NULL, G_OBJECT (dispatcher), NULL); - - tp_cli_connection_call_list_channels (connection, -1, - dispatcher_connection_list_channels_cb, NULL, NULL, - G_OBJECT (dispatcher)); - - } /* Advertise VoIP capabilities */ capabilities = g_ptr_array_sized_new (1); @@ -922,19 +851,25 @@ dispatcher_constructor (GType type, GObjectConstructParam *construct_params) { GObject *retval; + TpDBusDaemon *dbus; - if (dispatcher == NULL) - { - retval = G_OBJECT_CLASS (empathy_dispatcher_parent_class)->constructor - (type, n_construct_params, construct_params); + if (dispatcher != NULL) + return g_object_ref (dispatcher); - dispatcher = EMPATHY_DISPATCHER (retval); - g_object_add_weak_pointer (retval, (gpointer) &dispatcher); - } - else - { - retval = g_object_ref (dispatcher); - } + retval = G_OBJECT_CLASS (empathy_dispatcher_parent_class)->constructor + (type, n_construct_params, construct_params); + + dispatcher = EMPATHY_DISPATCHER (retval); + g_object_add_weak_pointer (retval, (gpointer) &dispatcher); + + dbus = tp_dbus_daemon_dup (NULL); + + g_assert (tp_dbus_daemon_request_name (dbus, + DISPATCHER_BUS_NAME, TRUE, NULL)); + dbus_g_connection_register_g_object (tp_get_bus (), + DISPATCHER_OBJECT_PATH, retval); + + DEBUG ("Registering at '%s'", DISPATCHER_OBJECT_PATH); return retval; } @@ -987,14 +922,79 @@ dispatcher_finalize (GObject *object) g_hash_table_destroy (priv->outstanding_classes_requests); } +static void +dispatcher_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) + { + case PROP_INTERFACES: + g_value_set_boxed (value, empathy_displatcher_interfaces); + break; + case PROP_CHANNEL_FILTER: + { + GPtrArray *filters = g_ptr_array_new (); + GHashTable *filter = g_hash_table_new (NULL, NULL); + + g_ptr_array_add (filters, filter); + + g_value_set_boxed (value, filters); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + static void empathy_dispatcher_class_init (EmpathyDispatcherClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + static TpDBusPropertiesMixinPropImpl client_props[] = { + { "Interfaces", "interfaces", NULL }, + { NULL } + }; + static TpDBusPropertiesMixinPropImpl client_handler_props[] = { + { "HandlerChannelFilter", "channel-filter", NULL }, + { NULL } + }; + static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { + { TP_IFACE_CLIENT, + tp_dbus_properties_mixin_getter_gobject_properties, + NULL, + client_props + }, + { TP_IFACE_CLIENT_HANDLER, + tp_dbus_properties_mixin_getter_gobject_properties, + NULL, + client_handler_props + }, + { NULL } + }; object_class->finalize = dispatcher_finalize; object_class->constructor = dispatcher_constructor; + object_class->get_property = dispatcher_get_property; + + param_spec = g_param_spec_boxed ("interfaces", "interfaces", + "Available D-Bus interfaces", + G_TYPE_STRV, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_INTERFACES, param_spec); + + param_spec = g_param_spec_boxed ("channel-filter", "channel-filter", + "Filter for channels this handles", + TP_ARRAY_TYPE_CHANNEL_CLASS_LIST, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, + PROP_CHANNEL_FILTER, param_spec); + signals[OBSERVE] = g_signal_new ("observe", G_TYPE_FROM_CLASS (klass), @@ -1025,8 +1025,13 @@ empathy_dispatcher_class_init (EmpathyDispatcherClass *klass) G_TYPE_NONE, 1, EMPATHY_TYPE_DISPATCH_OPERATION); + g_type_class_add_private (object_class, sizeof (EmpathyDispatcherPriv)); + + klass->dbus_props_class.interfaces = prop_interfaces; + tp_dbus_properties_mixin_class_init (object_class, + G_STRUCT_OFFSET (EmpathyDispatcherClass, dbus_props_class)); } static void @@ -1751,3 +1756,56 @@ empathy_dispatcher_find_requestable_channel_classes_async g_hash_table_insert (priv->request_channel_class_async_ids, request, GUINT_TO_POINTER (source_id)); } + +static void +empathy_dispatcher_handle_channels (TpSvcClientHandler *self, + const gchar *account_path, + const gchar *connection_path, + const GPtrArray *channels, + const GPtrArray *requests_satisfied, + guint64 timestamp, + GHashTable *handler_info, + DBusGMethodInvocation *context) +{ + EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (self); + EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); + int i; + EmpathyAccount *account; + TpConnection *connection; + + account = empathy_account_manager_lookup (priv->account_manager, + account_path); + /* FIXME */ + g_assert (account != NULL); + + connection = empathy_account_get_connection (account); + /* FIXME */ + g_assert (connection != NULL); + + for (i = 0; i < channels->len ; i++) + { + GValueArray *arr = g_ptr_array_index (channels, i); + const gchar *object_path; + GHashTable *properties; + + object_path = g_value_get_boxed (g_value_array_get_nth (arr, 0)); + properties = g_value_get_boxed (g_value_array_get_nth (arr, 1)); + + dispatcher_connection_new_channel_with_properties (dispatcher, + connection, object_path, properties); + } + + tp_svc_client_handler_return_from_handle_channels (context); + + g_object_unref (account); +} + +static void +empathy_dispatcher_client_handler_iface_init (gpointer g_iface, + gpointer g_iface_data) +{ + TpSvcClientHandlerClass *klass = (TpSvcClientHandlerClass *) g_iface; + + tp_svc_client_handler_implement_handle_channels (klass, + empathy_dispatcher_handle_channels); +} diff --git a/libempathy/empathy-dispatcher.h b/libempathy/empathy-dispatcher.h index d6c83f6c1..41a1430fb 100644 --- a/libempathy/empathy-dispatcher.h +++ b/libempathy/empathy-dispatcher.h @@ -26,6 +26,7 @@ #include #include +#include #include "empathy-contact.h" #include "empathy-dispatch-operation.h" @@ -51,6 +52,7 @@ struct _EmpathyDispatcher struct _EmpathyDispatcherClass { GObjectClass parent_class; + TpDBusPropertiesMixinClass dbus_props_class; }; /* Will be called when the channel is ready for dispatching. The requestor -- cgit v1.2.3 From 2e6c79d649630038440d47da78fc6905aea4d36c Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 10 Jul 2009 13:33:52 +0100 Subject: empathy-account-manager.c: remove obsolte empathy-account-priv.h include --- libempathy/empathy-account-manager.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index b443c2cd0..7711c2cc2 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -28,7 +28,6 @@ #include #include "empathy-account-manager.h" -#include "empathy-account-priv.h" #include "empathy-marshal.h" #include "empathy-utils.h" -- cgit v1.2.3 From 41ad88801dbd0efbfe82bd5c5ba3cb595c9151ab Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 10 Jul 2009 16:07:10 +0100 Subject: Implement HandledChannels D-Bus property --- libempathy/empathy-dispatcher.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 721d398d9..55fa668ca 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -90,6 +90,7 @@ enum { PROP_INTERFACES = 1, PROP_CHANNEL_FILTER, + PROP_CHANNELS }; enum @@ -928,6 +929,9 @@ dispatcher_get_property (GObject *object, GValue *value, GParamSpec *pspec) { + EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object); + EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); + switch (property_id) { case PROP_INTERFACES: @@ -943,6 +947,24 @@ dispatcher_get_property (GObject *object, g_value_set_boxed (value, filters); break; } + case PROP_CHANNELS: + { + GPtrArray *accounts; + GList *l; + + accounts = g_ptr_array_new (); + + for (l = priv->channels; l != NULL; l = g_list_next (l)) + { + TpProxy *channel = TP_PROXY (l->data); + + g_ptr_array_add (accounts, + g_strdup (tp_proxy_get_object_path (channel))); + } + + g_value_set_boxed (value, accounts); + break; + } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -961,6 +983,7 @@ empathy_dispatcher_class_init (EmpathyDispatcherClass *klass) }; static TpDBusPropertiesMixinPropImpl client_handler_props[] = { { "HandlerChannelFilter", "channel-filter", NULL }, + { "HandledChannels", "channels", NULL }, { NULL } }; static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { @@ -995,6 +1018,13 @@ empathy_dispatcher_class_init (EmpathyDispatcherClass *klass) g_object_class_install_property (object_class, PROP_CHANNEL_FILTER, param_spec); + param_spec = g_param_spec_boxed ("channels", "channels", + "List of channels we're handling", + EMPATHY_ARRAY_TYPE_OBJECT, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, + PROP_CHANNELS, param_spec); + signals[OBSERVE] = g_signal_new ("observe", G_TYPE_FROM_CLASS (klass), -- cgit v1.2.3 From c004e520157141ca939e32ac5ef18390304e1d9e Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 14:44:10 +0100 Subject: Remove dead code --- libempathy/empathy-account-manager.c | 118 +---------------------------------- libempathy/empathy-account-manager.h | 3 - 2 files changed, 2 insertions(+), 119 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 7711c2cc2..0795f3ad5 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -66,30 +66,6 @@ static EmpathyAccountManager *manager_singleton = NULL; G_DEFINE_TYPE (EmpathyAccountManager, empathy_account_manager, G_TYPE_OBJECT); -#if 0 -static TpConnectionPresenceType -mc_presence_to_tp_presence (McPresence presence) -{ - switch (presence) - { - case MC_PRESENCE_OFFLINE: - return TP_CONNECTION_PRESENCE_TYPE_OFFLINE; - case MC_PRESENCE_AVAILABLE: - return TP_CONNECTION_PRESENCE_TYPE_AVAILABLE; - case MC_PRESENCE_AWAY: - return TP_CONNECTION_PRESENCE_TYPE_AWAY; - case MC_PRESENCE_EXTENDED_AWAY: - return TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY; - case MC_PRESENCE_HIDDEN: - return TP_CONNECTION_PRESENCE_TYPE_HIDDEN; - case MC_PRESENCE_DO_NOT_DISTURB: - return TP_CONNECTION_PRESENCE_TYPE_BUSY; - default: - return TP_CONNECTION_PRESENCE_TYPE_UNSET; - } -} -#endif - static void emp_account_connection_cb (EmpathyAccount *account, GParamSpec *spec, @@ -473,29 +449,6 @@ empathy_account_manager_init (EmpathyAccountManager *manager) tp_cli_dbus_peer_call_ping (mc5_proxy, -1, NULL, NULL, NULL, NULL); g_object_unref (mc5_proxy); - -#if 0 - for (l = mc_accounts; l; l = l->next) - account_created_cb (priv->monitor, - (char *) mc_account_get_unique_name (l->data), manager); - - g_signal_connect (priv->monitor, "account-created", - G_CALLBACK (account_created_cb), manager); - g_signal_connect (priv->monitor, "account-deleted", - G_CALLBACK (account_deleted_cb), manager); - g_signal_connect (priv->monitor, "account-disabled", - G_CALLBACK (account_disabled_cb), manager); - g_signal_connect (priv->monitor, "account-enabled", - G_CALLBACK (account_enabled_cb), manager); - g_signal_connect (priv->monitor, "account-changed", - G_CALLBACK (account_changed_cb), manager); - - dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged", - G_CALLBACK (account_status_changed_cb), - manager, NULL); - - mc_accounts_list_free (mc_accounts); -#endif } static void @@ -524,34 +477,6 @@ do_dispose (GObject *obj) g_object_unref (priv->dbus); priv->dbus = NULL; -#if 0 - dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc), - "AccountStatusChanged", - G_CALLBACK (account_status_changed_cb), - obj); - - if (priv->monitor) - { - g_signal_handlers_disconnect_by_func (priv->monitor, - account_created_cb, obj); - g_signal_handlers_disconnect_by_func (priv->monitor, - account_deleted_cb, obj); - g_signal_handlers_disconnect_by_func (priv->monitor, - account_disabled_cb, obj); - g_signal_handlers_disconnect_by_func (priv->monitor, - account_enabled_cb, obj); - g_signal_handlers_disconnect_by_func (priv->monitor, - account_changed_cb, obj); - g_object_unref (priv->monitor); - priv->monitor = NULL; - } - - if (priv->mc) - g_object_unref (priv->mc); - - g_hash_table_remove_all (priv->accounts); -#endif - G_OBJECT_CLASS (empathy_account_manager_parent_class)->dispose (obj); } @@ -683,53 +608,14 @@ empathy_account_manager_dup_singleton (void) return g_object_new (EMPATHY_TYPE_ACCOUNT_MANAGER, NULL); } -EmpathyAccount * -empathy_account_manager_create_by_profile (EmpathyAccountManager *manager, - McProfile *profile) -{ - McAccount *mc_account = mc_account_create (profile); - return g_object_ref (create_account (manager, - mc_account_get_unique_name (mc_account), - mc_account)); -} - EmpathyAccount * empathy_account_manager_create (EmpathyAccountManager *manager, const gchar *connection_manager, const gchar *protocol, const gchar *display_name) { - McProfile *profile; - gboolean found; - GList *profiles, *l; - EmpathyAccount *result = NULL; - - profiles = mc_profiles_list_by_protocol (protocol); - - for (l = profiles; l != NULL; l = g_list_next (l)) { - McProtocol *protocol; - McManager *cm; - - profile = MC_PROFILE (l->data); - - protocol = mc_profile_get_protocol (profile); - cm = mc_protocol_get_manager (protocol); - found = !tp_strdiff (mc_manager_get_unique_name (cm), - connection_manager); - - g_object_unref (protocol); - g_object_unref (manager); - - if (found) { - result = empathy_account_manager_create_by_profile (manager, profile); - empathy_account_set_display_name (result, display_name); - break; - } - } - - mc_profiles_free_list (profiles); - - return result; + /* FIXME */ + return NULL; } int diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index 5d794bd83..d940e6b89 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -58,9 +58,6 @@ EmpathyAccount * empathy_account_manager_create ( const gchar *protocol, const gchar *display_name); -EmpathyAccount * empathy_account_manager_create_by_profile - (EmpathyAccountManager *manager, - McProfile *profile); int empathy_account_manager_get_connected_accounts (EmpathyAccountManager *manager); int empathy_account_manager_get_connecting_accounts -- cgit v1.2.3 From aafc27b739884d4c9e5fe0d9cabee52445eaa4ba Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 14:53:29 +0100 Subject: Keep track of ``global'' presence of all accounts --- libempathy/empathy-account-manager.c | 304 ++++++++++++----------------------- libempathy/empathy-account-manager.h | 5 + libempathy/empathy-account.c | 69 ++++++-- libempathy/empathy-account.h | 1 - 4 files changed, 163 insertions(+), 216 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 0795f3ad5..dc15651cb 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -21,11 +21,11 @@ #include "config.h" -#include #include #include #include #include +#include #include "empathy-account-manager.h" #include "empathy-marshal.h" @@ -47,6 +47,13 @@ typedef struct { TpProxySignalConnection *proxy_signal; TpAccountManager *tp_manager; TpDBusDaemon *dbus; + + /* global presence */ + EmpathyAccount *global_account; + + TpConnectionPresenceType global_presence; + gchar *global_status; + gchar *global_status_message; } EmpathyAccountManagerPriv; enum { @@ -56,7 +63,7 @@ enum { ACCOUNT_DISABLED, ACCOUNT_CHANGED, ACCOUNT_CONNECTION_CHANGED, - ACCOUNT_PRESENCE_CHANGED, + GLOBAL_PRESENCE_CHANGED, NEW_CONNECTION, LAST_SIGNAL }; @@ -130,230 +137,110 @@ emp_account_status_changed_cb (EmpathyAccount *account, } static void -emp_account_presence_changed_cb (EmpathyAccount *account, - TpConnectionPresenceType old, - TpConnectionPresenceType new, - gpointer user_data) +emp_account_manager_update_global_presence (EmpathyAccountManager *manager) { - EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); - g_signal_emit (manager, signals[ACCOUNT_PRESENCE_CHANGED], 0, - account, new, old); -} - -static void -emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) -{ - EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); - EmpathyAccount *account = EMPATHY_ACCOUNT (obj); - gboolean ready; - - g_object_get (account, "ready", &ready, NULL); - - if (!ready) - return; - - g_signal_emit (manager, signals[ACCOUNT_CREATED], 0, account); - - g_signal_connect (account, "notify::connection", - G_CALLBACK (emp_account_connection_cb), manager); - - g_signal_connect (account, "notify::enabled", - G_CALLBACK (emp_account_enabled_cb), manager); - - g_signal_connect (account, "status-changed", - G_CALLBACK (emp_account_status_changed_cb), manager); - - g_signal_connect (account, "presence-changed", - G_CALLBACK (emp_account_presence_changed_cb), manager); -} - -static EmpathyAccount * -create_account (EmpathyAccountManager *manager, - const gchar *account_name, - McAccount *mc_account) -{ -#if 0 EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - EmpathyAccount *account; - TpConnectionStatus status; - TpConnectionPresenceType presence; - McPresence mc_presence; - TpConnection *connection; - GError *error = NULL; - - if ((account = g_hash_table_lookup (priv->accounts, account_name)) != NULL) - return account; - - account = _empathy_account_new (mc_account); - g_hash_table_insert (priv->accounts, g_strdup (account_name), - account); - - _empathy_account_set_enabled (account, - mc_account_is_enabled (mc_account)); - - g_signal_emit (manager, signals[ACCOUNT_CREATED], 0, account); - - g_signal_connect (account, "notify::connection", - G_CALLBACK (emp_account_connection_cb), manager); + TpConnectionPresenceType presence = TP_CONNECTION_PRESENCE_TYPE_UNSET; + EmpathyAccount *account = NULL; + GHashTableIter iter; + gpointer value; - connection = mission_control_get_tpconnection (priv->mc, - mc_account, NULL); - _empathy_account_set_connection (account, connection); + g_hash_table_iter_init (&iter, priv->accounts); + while (g_hash_table_iter_next (&iter, NULL, &value)) + { + EmpathyAccount *a = EMPATHY_ACCOUNT (value); + TpConnectionPresenceType p; - status = mission_control_get_connection_status (priv->mc, - mc_account, &error); + g_object_get (a, "presence", &p, NULL); - if (error != NULL) - { - status = TP_CONNECTION_STATUS_DISCONNECTED; - g_clear_error (&error); + if (tp_connection_presence_type_cmp_availability (p, presence) > 0) + { + account = a; + presence = p; + } } - mc_presence = mission_control_get_presence_actual (priv->mc, &error); - if (error != NULL) - { - presence = TP_CONNECTION_PRESENCE_TYPE_UNSET; - g_clear_error (&error); - } - else + priv->global_account = account; + g_free (priv->global_status); + g_free (priv->global_status_message); + + if (account == NULL) { - presence = mc_presence_to_tp_presence (mc_presence); + priv->global_status = NULL; + priv->global_status_message = NULL; + return; } - g_signal_connect (account, "status-changed", - G_CALLBACK (emp_account_status_changed_cb), manager); - - g_signal_connect (account, "presence-changed", - G_CALLBACK (emp_account_presence_changed_cb), manager); - - _empathy_account_set_status (account, status, - TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED, - presence); - - return account; -#endif - return NULL; -} - -#if 0 -static void -account_created_cb (McAccountMonitor *mon, - gchar *account_name, - EmpathyAccountManager *manager) -{ - McAccount *mc_account = mc_account_lookup (account_name); - - if (mc_account != NULL) - create_account (manager, account_name, mc_account); + g_object_get (account, + "presence", &priv->global_presence, + "status", &priv->global_status, + "status-message", &priv->global_status_message, + NULL); } static void -account_deleted_cb (McAccountMonitor *mon, - gchar *account_name, - EmpathyAccountManager *manager) +emp_account_presence_changed_cb (EmpathyAccount *account, + TpConnectionPresenceType presence, + const gchar *status, + const gchar *status_message, + gpointer user_data) { + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - EmpathyAccount *account; - account = g_hash_table_lookup (priv->accounts, account_name); - - if (account) + if (tp_connection_presence_type_cmp_availability (presence, + priv->global_presence) > 0) { - g_signal_emit (manager, signals[ACCOUNT_DELETED], 0, account); - g_hash_table_remove (priv->accounts, account_name); - } -} - -static void -account_changed_cb (McAccountMonitor *mon, - gchar *account_name, - EmpathyAccountManager *manager) -{ - EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - EmpathyAccount *account; - - account = g_hash_table_lookup (priv->accounts, account_name); - - if (account != NULL) - g_signal_emit (manager, signals[ACCOUNT_CHANGED], 0, account); -} + priv->global_account = account; + priv->global_presence = presence; -typedef struct { - TpConnectionStatus status; - TpConnectionPresenceType presence; - TpConnectionStatusReason reason; - gchar *unique_name; - EmpathyAccountManager *manager; - McAccount *mc_account; -} ChangedSignalData; - -static gboolean -account_status_changed_idle_cb (ChangedSignalData *signal_data) -{ - EmpathyAccount *account; - EmpathyAccountManager *manager = signal_data->manager; - EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + g_free (priv->global_status); + priv->global_status = g_strdup (status); - account = g_hash_table_lookup (priv->accounts, - signal_data->unique_name); + g_free (priv->global_status_message); + priv->global_status_message = g_strdup (status_message); - if (account) + goto signal; + } + else if (priv->global_account == account) { - if (empathy_account_get_connection (account) == NULL) - { - TpConnection *connection; - - connection = mission_control_get_tpconnection (priv->mc, - signal_data->mc_account, NULL); - - if (connection != NULL) - { - _empathy_account_set_connection (account, connection); - g_object_unref (connection); - } - } - - _empathy_account_set_status (account, signal_data->status, - signal_data->reason, - signal_data->presence); + emp_account_manager_update_global_presence (manager); + goto signal; } - g_object_unref (signal_data->manager); - g_object_unref (signal_data->mc_account); - g_free (signal_data->unique_name); - g_slice_free (ChangedSignalData, signal_data); - - return FALSE; + return; +signal: + g_signal_emit (manager, signals[GLOBAL_PRESENCE_CHANGED], 0, + priv->global_presence, priv->global_status, priv->global_status_message); } -#endif -#if 0 static void -account_status_changed_cb (MissionControl *mc, - TpConnectionStatus status, - McPresence presence, - TpConnectionStatusReason reason, - const gchar *unique_name, - EmpathyAccountManager *manager) +emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) { - ChangedSignalData *data; + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); + EmpathyAccount *account = EMPATHY_ACCOUNT (obj); + gboolean ready; + + g_object_get (account, "ready", &ready, NULL); + + if (!ready) + return; + + g_signal_emit (manager, signals[ACCOUNT_CREATED], 0, account); - DEBUG ("Status of account %s became " - "status: %d presence: %d reason: %d", unique_name, status, - presence, reason); + g_signal_connect (account, "notify::connection", + G_CALLBACK (emp_account_connection_cb), manager); + + g_signal_connect (account, "notify::enabled", + G_CALLBACK (emp_account_enabled_cb), manager); - data = g_slice_new0 (ChangedSignalData); - data->status = status; - data->presence = mc_presence_to_tp_presence (presence); - data->reason = reason; - data->unique_name = g_strdup (unique_name); - data->manager = g_object_ref (manager); - data->mc_account = mc_account_lookup (unique_name); + g_signal_connect (account, "status-changed", + G_CALLBACK (emp_account_status_changed_cb), manager); - g_idle_add ((GSourceFunc) account_status_changed_idle_cb, data); + g_signal_connect (account, "presence-changed", + G_CALLBACK (emp_account_presence_changed_cb), manager); } -#endif static void account_manager_got_all_cb (TpProxy *proxy, @@ -424,6 +311,7 @@ empathy_account_manager_init (EmpathyAccountManager *manager) manager->priv = priv; priv->connected = priv->connecting = 0; + priv->global_presence = TP_CONNECTION_PRESENCE_TYPE_UNSET; priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); @@ -575,17 +463,17 @@ empathy_account_manager_class_init (EmpathyAccountManagerClass *klass) G_TYPE_UINT, /* actual connection */ G_TYPE_UINT); /* previous connection */ - signals[ACCOUNT_PRESENCE_CHANGED] = - g_signal_new ("account-presence-changed", + signals[GLOBAL_PRESENCE_CHANGED] = + g_signal_new ("global-presence-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - _empathy_marshal_VOID__OBJECT_INT_INT, + _empathy_marshal_VOID__UINT_STRING_STRING, G_TYPE_NONE, - 3, EMPATHY_TYPE_ACCOUNT, - G_TYPE_INT, /* actual presence */ - G_TYPE_INT); /* previous presence */ + 3, G_TYPE_UINT, /* Presence type */ + G_TYPE_STRING, /* status */ + G_TYPE_STRING); /* stauts message*/ signals[NEW_CONNECTION] = g_signal_new ("new-connection", @@ -786,3 +674,19 @@ empathy_account_manager_request_global_presence ( } } +TpConnectionPresenceType +empathy_account_manager_get_global_presence ( + EmpathyAccountManager *manager, + gchar **status, + gchar **message) +{ + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + + if (status != NULL) + *status = g_strdup (priv->global_status); + if (message != NULL) + *message = g_strdup (priv->global_status_message); + + return priv->global_presence; +} + diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index d940e6b89..bbf091997 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -84,6 +84,11 @@ void empathy_account_manager_request_global_presence ( const gchar *status, const gchar *message); +TpConnectionPresenceType empathy_account_manager_get_global_presence ( + EmpathyAccountManager *manager, + gchar **status, + gchar **message); + G_END_DECLS #endif /* __EMPATHY_ACCOUNT_MANAGER_H__ */ diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index d965fac62..5bfa38765 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -27,6 +27,7 @@ #include #include #include +#include #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include @@ -50,6 +51,8 @@ static guint signals[LAST_SIGNAL]; enum { PROP_ENABLED = 1, PROP_PRESENCE, + PROP_STATUS, + PROP_STATUS_MESSAGE, PROP_READY, PROP_CONNECTION_STATUS, PROP_CONNECTION_STATUS_REASON, @@ -71,9 +74,12 @@ struct _EmpathyAccountPriv TpConnection *connection; guint connection_invalidated_id; - TpConnectionStatus status; + TpConnectionStatus connection_status; TpConnectionStatusReason reason; + TpConnectionPresenceType presence; + gchar *status; + gchar *message; gboolean enabled; gboolean valid; @@ -108,7 +114,7 @@ empathy_account_init (EmpathyAccount *obj) obj->priv = priv; - priv->status = TP_CONNECTION_STATUS_DISCONNECTED; + priv->connection_status = TP_CONNECTION_STATUS_DISCONNECTED; } static void @@ -157,8 +163,14 @@ empathy_account_get_property (GObject *object, case PROP_PRESENCE: g_value_set_uint (value, priv->presence); break; + case PROP_STATUS: + g_value_set_string (value, priv->status); + break; + case PROP_STATUS_MESSAGE: + g_value_set_string (value, priv->message); + break; case PROP_CONNECTION_STATUS: - g_value_set_uint (value, priv->status); + g_value_set_uint (value, priv->connection_status); break; case PROP_CONNECTION_STATUS_REASON: g_value_set_uint (value, priv->reason); @@ -191,11 +203,12 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) EmpathyAccountPriv *priv = GET_PRIV (account); const gchar *conn_path; GValueArray *arr; - TpConnectionStatus old_s = priv->status; - TpConnectionPresenceType old_p = priv->presence; + TpConnectionStatus old_s = priv->connection_status; + gboolean presence_changed = FALSE; if (g_hash_table_lookup (properties, "ConnectionStatus") != NULL) - priv->status = tp_asv_get_int32 (properties, "ConnectionStatus", NULL); + priv->connection_status = + tp_asv_get_int32 (properties, "ConnectionStatus", NULL); if (g_hash_table_lookup (properties, "ConnectionStatusReason") != NULL) priv->reason = tp_asv_get_int32 (properties, @@ -203,9 +216,16 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) if (g_hash_table_lookup (properties, "CurrentPresence") != NULL) { + presence_changed = TRUE; arr = tp_asv_get_boxed (properties, "CurrentPresence", TP_STRUCT_TYPE_SIMPLE_PRESENCE); priv->presence = g_value_get_uint (g_value_array_get_nth (arr, 0)); + + g_free (priv->status); + priv->status = g_value_dup_string (g_value_array_get_nth (arr, 1)); + + g_free (priv->message); + priv->message = g_value_dup_string (g_value_array_get_nth (arr, 2)); } if (g_hash_table_lookup (properties, "DisplayName") != NULL) @@ -236,9 +256,9 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) g_object_notify (G_OBJECT (account), "ready"); } - if (priv->status != old_s) + if (priv->connection_status != old_s) { - if (priv->status == TP_CONNECTION_STATUS_CONNECTED) + if (priv->connection_status == TP_CONNECTION_STATUS_CONNECTED) { GTimeVal val; g_get_current_time (&val); @@ -247,16 +267,18 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) } g_signal_emit (account, signals[STATUS_CHANGED], 0, - old_s, priv->status, priv->reason); + old_s, priv->connection_status, priv->reason); g_object_notify (G_OBJECT (account), "status"); } - if (priv->presence != old_p) + if (presence_changed) { g_signal_emit (account, signals[PRESENCE_CHANGED], 0, - old_p, priv->presence); + priv->presence, priv->status, priv->message); g_object_notify (G_OBJECT (account), "presence"); + g_object_notify (G_OBJECT (account), "status"); + g_object_notify (G_OBJECT (account), "status-message"); } if (g_hash_table_lookup (properties, "Connection") != NULL) @@ -417,8 +439,22 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) TP_CONNECTION_PRESENCE_TYPE_UNSET, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + g_object_class_install_property (object_class, PROP_STATUS, + g_param_spec_string ("status", + "Status", + "The Status string of the account", + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + + g_object_class_install_property (object_class, PROP_STATUS_MESSAGE, + g_param_spec_string ("status-message", + "status-message", + "The Status message string of the account", + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + g_object_class_install_property (object_class, PROP_CONNECTION_STATUS, - g_param_spec_uint ("status", + g_param_spec_uint ("connection-status", "ConnectionStatus", "The accounts connections status type", 0, @@ -474,8 +510,8 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - _empathy_marshal_VOID__UINT_UINT, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); + _empathy_marshal_VOID__UINT_STRING_STRING, + G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); } void @@ -508,6 +544,9 @@ empathy_account_finalize (GObject *object) { EmpathyAccountPriv *priv = GET_PRIV (object); + g_free (priv->status); + g_free (priv->message); + g_free (priv->cm_name); g_free (priv->proto_name); g_free (priv->icon_name); @@ -524,7 +563,7 @@ empathy_account_is_just_connected (EmpathyAccount *account) EmpathyAccountPriv *priv = GET_PRIV (account); GTimeVal val; - if (priv->status != TP_CONNECTION_STATUS_CONNECTED) + if (priv->connection_status != TP_CONNECTION_STATUS_CONNECTED) return FALSE; g_get_current_time (&val); diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 4be35a919..252c959d2 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -24,7 +24,6 @@ #include #include -#include G_BEGIN_DECLS -- cgit v1.2.3 From 7c4c3fb9a2de1711a7a76abc48d6ac540b70d4d0 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 14:58:26 +0100 Subject: Get the presence from the AccountManager instead of MC4 --- libempathy/empathy-idle.c | 59 ++++++----------------------------------------- 1 file changed, 7 insertions(+), 52 deletions(-) diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 9b34fc7f1..e1cccf1e7 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -90,9 +90,10 @@ G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT); static EmpathyIdle * idle_singleton = NULL; static void -idle_presence_changed_cb (MissionControl *mc, +idle_presence_changed_cb (EmpathyAccountManager *manager, TpConnectionPresenceType state, gchar *status, + gchar *status_message, EmpathyIdle *idle) { EmpathyIdlePriv *priv; @@ -452,36 +453,9 @@ empathy_idle_class_init (EmpathyIdleClass *klass) g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv)); } -static TpConnectionPresenceType -empathy_idle_get_actual_presence (EmpathyIdle *idle, GError **error) -{ - McPresence presence; - EmpathyIdlePriv *priv = GET_PRIV (idle); - - presence = mission_control_get_presence_actual (priv->mc, error); - - switch (presence) { - case MC_PRESENCE_OFFLINE: - return TP_CONNECTION_PRESENCE_TYPE_OFFLINE; - case MC_PRESENCE_AVAILABLE: - return TP_CONNECTION_PRESENCE_TYPE_AVAILABLE; - case MC_PRESENCE_AWAY: - return TP_CONNECTION_PRESENCE_TYPE_AWAY; - case MC_PRESENCE_EXTENDED_AWAY: - return TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY; - case MC_PRESENCE_HIDDEN: - return TP_CONNECTION_PRESENCE_TYPE_HIDDEN; - case MC_PRESENCE_DO_NOT_DISTURB: - return TP_CONNECTION_PRESENCE_TYPE_BUSY; - default: - return TP_CONNECTION_PRESENCE_TYPE_OFFLINE; - } -} - static void empathy_idle_init (EmpathyIdle *idle) { - GError *error = NULL; EmpathyIdlePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (idle, EMPATHY_TYPE_IDLE, EmpathyIdlePriv); @@ -490,31 +464,12 @@ empathy_idle_init (EmpathyIdle *idle) priv->mc = empathy_mission_control_dup_singleton (); priv->manager = empathy_account_manager_dup_singleton (); - priv->state = empathy_idle_get_actual_presence (idle, &error); - if (error) { - DEBUG ("Error getting actual presence: %s", error->message); - - /* Fallback to OFFLINE as that's what mission_control_get_presence_actual - does. This also ensure to always display the status icon (there is no - unset presence icon). */ - priv->state = TP_CONNECTION_PRESENCE_TYPE_OFFLINE; - g_clear_error (&error); - } - priv->status = mission_control_get_presence_message_actual (priv->mc, &error); - if (error || EMP_STR_EMPTY (priv->status)) { - g_free (priv->status); - priv->status = NULL; - - if (error) { - DEBUG ("Error getting actual presence message: %s", error->message); - g_clear_error (&error); - } - } + priv->state = empathy_account_manager_get_global_presence (priv->manager, + NULL, &priv->status); + - dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), - "PresenceChanged", - G_CALLBACK (idle_presence_changed_cb), - idle, NULL); + g_signal_connect (priv->manager, "global-presence-changed", + G_CALLBACK (idle_presence_changed_cb), idle); priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (), "org.gnome.SessionManager", -- cgit v1.2.3 From 565bab5296d9114543318ff453c6c2a878da417e Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 15:00:26 +0100 Subject: Use default status identifiers when setting the presence --- libempathy/empathy-idle.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index e1cccf1e7..9250359f0 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -577,15 +577,31 @@ empathy_idle_set_flash_state (EmpathyIdle *idle, static void empathy_idle_do_set_presence (EmpathyIdle *idle, - TpConnectionPresenceType state, - const gchar *status) + TpConnectionPresenceType status_type, + const gchar *status_message) { EmpathyIdlePriv *priv = GET_PRIV (idle); + const gchar *statusses[NUM_TP_CONNECTION_PRESENCE_TYPES] = { + NULL, + "offline", + "available", + "away", + "xa", + "hidden", + "busy", + NULL, + NULL, + }; + const gchar *status; + + g_assert (status_type > 0 && status_type < NUM_TP_CONNECTION_PRESENCE_TYPES); + + status = statusses[status_type]; + g_return_if_fail (status != NULL); - /* FIXME */ empathy_account_manager_request_global_presence (priv->manager, - state, "available", status); + status_type, status, status_message); } void -- cgit v1.2.3 From 5dc89d6d5a3f5e47ea7b65fdfdbd84ff178625c5 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 15:14:17 +0100 Subject: Temporarily disable account importing as it still depends on profiles --- src/Makefile.am | 2 -- src/empathy-accounts-dialog.c | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 42485b7d1..50d317fbb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,8 +39,6 @@ empathy_handwritten_source = \ empathy-chat-window.c empathy-chat-window.h \ empathy-event-manager.c empathy-event-manager.h \ empathy-ft-manager.c empathy-ft-manager.h \ - empathy-import-dialog.c empathy-import-dialog.h \ - empathy-import-pidgin.c empathy-import-pidgin.h \ empathy-main-window.c empathy-main-window.h \ empathy-misc.c empathy-misc.h \ empathy-new-chatroom-dialog.c empathy-new-chatroom-dialog.h \ diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 47e2887b0..bfb92af37 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -43,7 +43,10 @@ #include #include "empathy-accounts-dialog.h" +#if 0 +/* FIXME MC-5 */ #include "empathy-import-dialog.h" +#endif #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include @@ -142,8 +145,11 @@ static void accounts_dialog_button_help_clicked_cb (GtkWidget EmpathyAccountsDialog *dialog); static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog); +#if 0 +/* FIXME MC-5 */ static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog); +#endif static void accounts_dialog_response_cb (GtkWidget *widget, gint response, EmpathyAccountsDialog *dialog); @@ -957,12 +963,15 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button, gtk_widget_destroy (message_dialog); } +#if 0 +/* FIXME MC-5 */ static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE); } +#endif static void accounts_dialog_response_cb (GtkWidget *widget, @@ -1072,7 +1081,10 @@ empathy_accounts_dialog_show (GtkWindow *parent, "button_back", "clicked", accounts_dialog_button_back_clicked_cb, "button_add", "clicked", accounts_dialog_button_add_clicked_cb, "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb, +#if 0 +/* FIXME MC-5 */ "button_import", "clicked", accounts_dialog_button_import_clicked_cb, +#endif "button_help", "clicked", accounts_dialog_button_help_clicked_cb, NULL); @@ -1140,6 +1152,8 @@ empathy_accounts_dialog_show (GtkWindow *parent, EMPATHY_PREFS_IMPORT_ASKED, &import_asked); +#if 0 +/* FIXME MC-5 */ if (empathy_import_dialog_accounts_to_import ()) { if (!import_asked) { @@ -1151,6 +1165,7 @@ empathy_accounts_dialog_show (GtkWindow *parent, } else { gtk_widget_set_sensitive (dialog->button_import, FALSE); } +#endif return dialog->window; } -- cgit v1.2.3 From ec439e852438565122a2d5a5dc322db8567d6c7d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 15:24:16 +0100 Subject: Remove profiles, they're not used anymore --- data/Makefile.am | 21 --------------------- data/aim.profile | 10 ---------- data/ekiga.profile | 14 -------------- data/fwd.profile | 15 --------------- data/gadugadu.profile | 11 ----------- data/groupwise.profile | 11 ----------- data/gtalk.profile | 16 ---------------- data/icq.profile | 11 ----------- data/irc.profile | 9 --------- data/jabber.profile | 12 ------------ data/msn-haze.profile | 13 ------------- data/msn.profile | 13 ------------- data/qq.profile | 11 ----------- data/salut.profile | 9 --------- data/sametime.profile | 11 ----------- data/sipphone.profile | 16 ---------------- data/sofiasip.profile | 10 ---------- data/yahoo.profile | 11 ----------- 18 files changed, 224 deletions(-) delete mode 100644 data/aim.profile delete mode 100644 data/ekiga.profile delete mode 100644 data/fwd.profile delete mode 100644 data/gadugadu.profile delete mode 100644 data/groupwise.profile delete mode 100644 data/gtalk.profile delete mode 100644 data/icq.profile delete mode 100644 data/irc.profile delete mode 100644 data/jabber.profile delete mode 100644 data/msn-haze.profile delete mode 100644 data/msn.profile delete mode 100644 data/qq.profile delete mode 100644 data/salut.profile delete mode 100644 data/sametime.profile delete mode 100644 data/sipphone.profile delete mode 100644 data/sofiasip.profile delete mode 100644 data/yahoo.profile diff --git a/data/Makefile.am b/data/Makefile.am index 52108fbe7..2182ed0f5 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,25 +1,5 @@ SUBDIRS = icons -profiledir = $(datadir)/mission-control/profiles -profile_DATA = \ - aim.profile \ - icq.profile \ - jabber.profile \ - salut.profile \ - yahoo.profile \ - gtalk.profile \ - irc.profile \ - msn.profile \ - msn-haze.profile \ - sofiasip.profile \ - ekiga.profile \ - fwd.profile \ - sipphone.profile \ - groupwise.profile \ - gadugadu.profile \ - qq.profile \ - sametime.profile - desktopdir = $(datadir)/applications desktop_in_files = empathy.desktop.in desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) @@ -45,7 +25,6 @@ htmldir = $(datadir)/empathy html_DATA = Template.html EXTRA_DIST = \ - $(profile_DATA) \ $(desktop_in_files) \ $(desktop_DATA) \ $(schemas_in_files) \ diff --git a/data/aim.profile b/data/aim.profile deleted file mode 100644 index ae7dbaecc..000000000 --- a/data/aim.profile +++ /dev/null @@ -1,10 +0,0 @@ -[Profile] -Manager=haze -Protocol=aim -IconName = im-aim -DisplayName=AIM -ConfigurationUI = aim -Capabilities = chat-p2p, supports-alias, supports-avatars, supports-roster -VCardDefault = 1 -VCardField = X-AIM -SupportedPresences = away,hidden,do-not-disturb diff --git a/data/ekiga.profile b/data/ekiga.profile deleted file mode 100644 index 1acc71044..000000000 --- a/data/ekiga.profile +++ /dev/null @@ -1,14 +0,0 @@ -[Profile] -Manager = sofiasip -Protocol = sip -DisplayName = Ekiga.net (SIP) -IconName = im-ekiga -ConfigurationUI = sofiasip -VCardDefault = 1 -VCardField = X-SIP -Capabilities = chat-p2p, voice-p2p, split-account, video-p2p -DefaultAccountDomain = ekiga.net -Default-priority = 1 -Default-stun-server = stun.ekiga.net -Default-discover-stun = false - diff --git a/data/fwd.profile b/data/fwd.profile deleted file mode 100644 index af05b2cc3..000000000 --- a/data/fwd.profile +++ /dev/null @@ -1,15 +0,0 @@ -[Profile] -Manager = sofiasip -Protocol = sip -DisplayName = FreeWorldDialup (SIP) -IconName = im-sip -ConfigurationUI = sofiasip -VCardDefault = 1 -VCardField = X-SIP -Capabilities = chav-p2p, voice-p2p, split-account, video-p2p -DefaultAccountDomain = fwd.pulver.com -Default-priority = 1 -Default-proxy-address = fwd.pulver.com -Default-stun-server = stun.fwdnet.net -Default-discover-stun = false - diff --git a/data/gadugadu.profile b/data/gadugadu.profile deleted file mode 100644 index ca2f5b7a9..000000000 --- a/data/gadugadu.profile +++ /dev/null @@ -1,11 +0,0 @@ -[Profile] -Manager=haze -Protocol=gadugadu -DisplayName=Gadu Gadu -IconName = im-gadugadu -ConfigurationUI = gadugadu -Capabilities = chat-p2p, contact-search, supports-alias, supports-roster -VCardDefault = 1 -VCardField = X-GADUGADU -SupportedPresences = offline,available,away,hidden - diff --git a/data/groupwise.profile b/data/groupwise.profile deleted file mode 100644 index 3e47ec2fb..000000000 --- a/data/groupwise.profile +++ /dev/null @@ -1,11 +0,0 @@ -[Profile] -Manager=haze -Protocol=groupwise -IconName = im-nov -DisplayName=GroupWise -ConfigurationUI = groupwise -Capabilities = chat-p2p, supports-alias, supports-roster -VCardDefault = 1 -VCardField = X-Groupwise -SupportedPresences = away,hidden,do-not-disturb - diff --git a/data/gtalk.profile b/data/gtalk.profile deleted file mode 100644 index 21eadc031..000000000 --- a/data/gtalk.profile +++ /dev/null @@ -1,16 +0,0 @@ -[Profile] -Manager = gabble -Protocol = jabber -DisplayName = Google Talk -IconName = im-google-talk -ConfigurationUI = jabber -VCardDefault = 0 -VCardField = X-JABBER -Capabilities = chat-p2p, voice-p2p, split-account, chat-room, chat-room-list, supports-avatars, supports-alias, supports-roster -DefaultAccountDomain = gmail.com -Default-server = talk.google.com -Default-port = 5223 -Default-old-ssl = 1 -Default-ignore-ssl-errors = 1 -Default-fallback-conference-server = conference.jabber.org -SupportedPresences = away,extended-away,do-not-disturb diff --git a/data/icq.profile b/data/icq.profile deleted file mode 100644 index 0f4622e75..000000000 --- a/data/icq.profile +++ /dev/null @@ -1,11 +0,0 @@ -[Profile] -Manager=haze -Protocol=icq -IconName = im-icq -DisplayName=ICQ -ConfigurationUI = icq -Capabilities = chat-p2p, supports-alias, supports-avatars, supports-roster -VCardDefault = 1 -VCardField = X-ICQ -SupportedPresences = away,hidden,do-not-disturb - diff --git a/data/irc.profile b/data/irc.profile deleted file mode 100644 index 05bf5ed5a..000000000 --- a/data/irc.profile +++ /dev/null @@ -1,9 +0,0 @@ -[Profile] -Manager = idle -Protocol = irc -DisplayName = IRC -IconName = im-irc -ConfigurationUI = irc -VCardField = X-IRC -Capabilities = chat-p2p, chat-room, chat-room-list -SupportedPresences = away diff --git a/data/jabber.profile b/data/jabber.profile deleted file mode 100644 index c3cb57aff..000000000 --- a/data/jabber.profile +++ /dev/null @@ -1,12 +0,0 @@ -[Profile] -Manager = gabble -Protocol = jabber -DisplayName = Jabber -IconName = im-xmpp -ConfigurationUI = jabber -VCardDefault = 1 -VCardField = X-JABBER -Capabilities = chat-p2p, chat-room, chat-room-list, voice-p2p, contact-search, split-account, registration-ui, supports-avatars, supports-alias, supports-roster -DefaultAccountDomain = jabber.org -Default-fallback-conference-server = conference.jabber.org -SupportedPresences = away,extended-away,hidden,do-not-disturb diff --git a/data/msn-haze.profile b/data/msn-haze.profile deleted file mode 100644 index 196825202..000000000 --- a/data/msn-haze.profile +++ /dev/null @@ -1,13 +0,0 @@ -[Profile] -Manager=haze -Protocol=msn -DisplayName=MSN (Haze) -IconName = im-msn -ConfigurationUI = haze -SupportsInvisible = 0 -Capabilities = chat-p2p, split-account, supports-alias, supports-avatars, supports-roster -DefaultAccountDomain = hotmail.com -VCardDefault = 1 -VCardField = X-MSN -SupportedPresences = away,hidden,do-not-disturb - diff --git a/data/msn.profile b/data/msn.profile deleted file mode 100644 index 9bdd051ea..000000000 --- a/data/msn.profile +++ /dev/null @@ -1,13 +0,0 @@ -[Profile] -Manager=butterfly -Protocol=msn -DisplayName=MSN -IconName = im-msn -ConfigurationUI = msn -SupportsInvisible = 1 -Capabilities = chat-p2p, split-account, supports-avatars, supports-alias -DefaultAccountDomain = hotmail.com -VCardDefault = 1 -VCardField = X-MSN -SupportedPresences = offline,available,away,extended-away,hidden,do-not-disturb - diff --git a/data/qq.profile b/data/qq.profile deleted file mode 100644 index 9a52d2441..000000000 --- a/data/qq.profile +++ /dev/null @@ -1,11 +0,0 @@ -[Profile] -Manager=haze -Protocol=qq -DisplayName=QQ -IconName = im-qq -ConfigurationUI = qq -Capabilities = chat-p2p, chat-room, contact-search, supports-alias, supports-roster -VCardDefault = 1 -VCardField = X-QQ -SupportedPresences = offline,available,away,hidden - diff --git a/data/salut.profile b/data/salut.profile deleted file mode 100644 index acd483ccc..000000000 --- a/data/salut.profile +++ /dev/null @@ -1,9 +0,0 @@ -[Profile] -Manager = salut -Protocol = local-xmpp -DisplayName = Salut -IconName = im-local-xmpp -ConfigurationUI = local-xmpp -VCardField = X-LOCAL-XMPP -Capabilities = chat-p2p, contact-search, supports-alias, supports-roster -SupportedPresences = away,extended-away,hidden,do-not-disturb diff --git a/data/sametime.profile b/data/sametime.profile deleted file mode 100644 index aec798925..000000000 --- a/data/sametime.profile +++ /dev/null @@ -1,11 +0,0 @@ -[Profile] -Manager=haze -Protocol=sametime -IconName = im-meanwhile -DisplayName = Sametime -ConfigurationUI = sametime -Capabilities = chat-p2p, supports-alias, supports-roster -VCardDefault = 1 -VCardField = X-Sametime -SupportedPresences = away,hidden,do-not-disturb - diff --git a/data/sipphone.profile b/data/sipphone.profile deleted file mode 100644 index 4904a7481..000000000 --- a/data/sipphone.profile +++ /dev/null @@ -1,16 +0,0 @@ -[Profile] -Manager = sofiasip -Protocol = sip -DisplayName = Sipphone.com (SIP) -IconName = im-sip -ConfigurationUI = sofiasip -VCardDefault = 1 -VCardField = X-SIP -Capabilities = voice-p2p, split-account, video-p2p -DefaultAccountDomain = proxy01.sipphone.com -Default-priority = 1 -Default-stun-server = stun01.sipphone.com -Default-proxy = 198.65.166.131 -Default-discover-stun = false -Default-transport = udp - diff --git a/data/sofiasip.profile b/data/sofiasip.profile deleted file mode 100644 index e49f9a09d..000000000 --- a/data/sofiasip.profile +++ /dev/null @@ -1,10 +0,0 @@ -[Profile] -Manager = sofiasip -Protocol = sip -DisplayName = SIP -IconName = im-sip -ConfigurationUI = sofiasip -VCardDefault = 1 -VCardField = X-SIP -Capabilities = chat-p2p, voice-p2p, split-account - diff --git a/data/yahoo.profile b/data/yahoo.profile deleted file mode 100644 index f4173d1af..000000000 --- a/data/yahoo.profile +++ /dev/null @@ -1,11 +0,0 @@ -[Profile] -Manager=haze -Protocol=yahoo -DisplayName=Yahoo -IconName = im-yahoo -ConfigurationUI = yahoo -Capabilities = chat-p2p, supports-alias, supports-avatars, supports-roster -VCardDefault = 1 -VCardField = X-YAHOO -SupportedPresences = away,hidden,do-not-disturb - -- cgit v1.2.3 From 3546af6b2b14fa640c1a86e6a975eef6fcb37a00 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 15:24:48 +0100 Subject: Remove last references to mission-control 4 --- configure.ac | 9 +--- libempathy/empathy-call-handler.c | 1 + libempathy/empathy-chatroom-manager.c | 2 + libempathy/empathy-dispatcher.c | 4 +- libempathy/empathy-ft-handler.c | 1 + libempathy/empathy-idle.c | 4 -- libempathy/empathy-log-manager.c | 1 + libempathy/empathy-tp-chat.c | 1 + libempathy/empathy-tp-contact-factory.c | 2 + libempathy/empathy-tp-contact-list.c | 1 + libempathy/empathy-tp-file.c | 1 + libempathy/empathy-tp-roomlist.c | 1 + libempathy/empathy-utils.c | 15 ------- libempathy/empathy-utils.h | 3 -- src/empathy-accounts-dialog.c | 3 -- src/empathy-debug-dialog.c | 4 -- src/empathy-event-manager.c | 1 + src/empathy-main-window.c | 3 -- src/empathy-tube-dispatch.c | 1 + src/empathy.c | 76 +-------------------------------- 20 files changed, 18 insertions(+), 116 deletions(-) diff --git a/configure.ac b/configure.ac index 0dab5e4fc..ce7decf66 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,6 @@ GTK_REQUIRED=2.16.0 GCONF_REQUIRED=1.2.0 LIBPANELAPPLET_REQUIRED=2.10.0 TELEPATHY_GLIB_REQUIRED=0.7.31 -MISSION_CONTROL_REQUIRED=4.61 ENCHANT_REQUIRED=1.2.0 ISO_CODES_REQUIRED=0.35 LIBNOTIFY_REQUIRED=0.4.4 @@ -95,7 +94,6 @@ PKG_CHECK_MODULES(LIBEMPATHY, gio-unix-2.0 >= $GLIB_REQUIRED libxml-2.0 telepathy-glib >= $TELEPATHY_GLIB_REQUIRED - libmissioncontrol >= $MISSION_CONTROL_REQUIRED telepathy-farsight farsight2-0.10 gstreamer-0.10 @@ -111,7 +109,6 @@ PKG_CHECK_MODULES(LIBEMPATHYGTK, gtk+-2.0 >= $GTK_REQUIRED libcanberra-gtk >= $LIBCANBERRA_GTK_REQUIRED telepathy-glib >= $TELEPATHY_GLIB_REQUIRED - libmissioncontrol >= $MISSION_CONTROL_REQUIRED farsight2-0.10 gstreamer-0.10 gstreamer-interfaces-0.10 @@ -127,7 +124,6 @@ PKG_CHECK_MODULES(EMPATHY, libebook-1.2 dbus-glib-1 telepathy-glib >= $TELEPATHY_GLIB_REQUIRED - libmissioncontrol >= $MISSION_CONTROL_REQUIRED telepathy-farsight gstreamer-0.10 ]) @@ -319,7 +315,7 @@ if test "x$enable_megaphone" != "xno"; then glib-2.0 >= $GLIB_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gconf-2.0 >= $GCONF_REQUIRED - libmissioncontrol >= $MISSION_CONTROL_REQUIRED + telepathy-glib >= $TELEPATHY_GLIB_REQUIRED ], have_megaphone="yes", have_megaphone="no") else have_megaphone=no @@ -346,7 +342,7 @@ if test "x$enable_nothere" != "xno"; then glib-2.0 >= $GLIB_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gconf-2.0 >= $GCONF_REQUIRED - libmissioncontrol >= $MISSION_CONTROL_REQUIRED + telepathy-glib >= $TELEPATHY_GLIB_REQUIRED ], have_nothere="yes", have_nothere="no") else have_nothere=no @@ -397,7 +393,6 @@ if test "x$enable_python" != "xno"; then gobject-2.0 gconf-2.0 >= $GCONF_REQUIRED libxml-2.0 - libmissioncontrol >= $MISSION_CONTROL_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gstreamer-0.10 gstreamer-interfaces-0.10 diff --git a/libempathy/empathy-call-handler.c b/libempathy/empathy-call-handler.c index f73c41e2e..39f950f86 100644 --- a/libempathy/empathy-call-handler.c +++ b/libempathy/empathy-call-handler.c @@ -23,6 +23,7 @@ #include #include +#include #include #include diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c index 1ce7a6e5d..a512f5b25 100644 --- a/libempathy/empathy-chatroom-manager.c +++ b/libempathy/empathy-chatroom-manager.c @@ -30,6 +30,8 @@ #include #include +#include + #include "empathy-tp-chat.h" #include "empathy-chatroom-manager.h" #include "empathy-account-manager.h" diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 55fa668ca..bce9f7610 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -55,7 +56,6 @@ typedef struct { EmpathyAccountManager *account_manager; - MissionControl *mc; /* connection to connection data mapping */ GHashTable *connections; GHashTable *outstanding_classes_requests; @@ -917,7 +917,6 @@ dispatcher_finalize (GObject *object) } g_object_unref (priv->account_manager); - g_object_unref (priv->mc); g_hash_table_destroy (priv->connections); g_hash_table_destroy (priv->outstanding_classes_requests); @@ -1072,7 +1071,6 @@ empathy_dispatcher_init (EmpathyDispatcher *dispatcher) EMPATHY_TYPE_DISPATCHER, EmpathyDispatcherPriv); dispatcher->priv = priv; - priv->mc = empathy_mission_control_dup_singleton (); priv->account_manager = empathy_account_manager_dup_singleton (); g_signal_connect (priv->account_manager, "new-connection", diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c index d24467b24..b05da94aa 100644 --- a/libempathy/empathy-ft-handler.c +++ b/libempathy/empathy-ft-handler.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "empathy-ft-handler.h" #include "empathy-tp-contact-factory.h" diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 9250359f0..f60fc0f85 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -31,7 +31,6 @@ #include #include -#include #include "empathy-account-manager.h" #include "empathy-idle.h" @@ -45,7 +44,6 @@ #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIdle) typedef struct { - MissionControl *mc; DBusGProxy *gs_proxy; #ifdef HAVE_NM NMClient *nm_client; @@ -294,7 +292,6 @@ idle_finalize (GObject *object) priv = GET_PRIV (object); g_free (priv->status); - g_object_unref (priv->mc); if (priv->gs_proxy) { g_object_unref (priv->gs_proxy); @@ -461,7 +458,6 @@ empathy_idle_init (EmpathyIdle *idle) idle->priv = priv; priv->is_idle = FALSE; - priv->mc = empathy_mission_control_dup_singleton (); priv->manager = empathy_account_manager_dup_singleton (); priv->state = empathy_account_manager_get_global_presence (priv->manager, diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c index c1e20f487..309b3b60f 100644 --- a/libempathy/empathy-log-manager.c +++ b/libempathy/empathy-log-manager.c @@ -29,6 +29,7 @@ #include #include +#include #include "empathy-log-manager.h" #include "empathy-log-store-empathy.h" diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index ac61392e0..091871034 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "empathy-tp-chat.h" #include "empathy-tp-contact-factory.h" diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c index 27160a445..29148feec 100644 --- a/libempathy/empathy-tp-contact-factory.c +++ b/libempathy/empathy-tp-contact-factory.c @@ -26,6 +26,8 @@ #include #include #include +#include + #if HAVE_GEOCLUE #include #endif diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c index cdb0431c4..6564deb2b 100644 --- a/libempathy/empathy-tp-contact-list.c +++ b/libempathy/empathy-tp-contact-list.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "empathy-tp-contact-list.h" #include "empathy-tp-contact-factory.h" diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c index e60b2999d..c43fa0be7 100644 --- a/libempathy/empathy-tp-file.c +++ b/libempathy/empathy-tp-file.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "empathy-tp-file.h" #include "empathy-marshal.h" diff --git a/libempathy/empathy-tp-roomlist.c b/libempathy/empathy-tp-roomlist.c index b3d955ee4..e369373f8 100644 --- a/libempathy/empathy-tp-roomlist.c +++ b/libempathy/empathy-tp-roomlist.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "empathy-account.h" diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 69779d99f..525f2fe06 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -242,21 +242,6 @@ empathy_account_equal (gconstpointer a, return a == b; } -MissionControl * -empathy_mission_control_dup_singleton (void) -{ - static MissionControl *mc = NULL; - - if (!mc) { - mc = mission_control_new (tp_get_bus ()); - g_object_add_weak_pointer (G_OBJECT (mc), (gpointer) &mc); - } else { - g_object_ref (mc); - } - - return mc; -} - const gchar * empathy_presence_get_default_message (TpConnectionPresenceType presence) { diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 735946b92..3de6047f4 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -32,8 +32,6 @@ #include #include -#include - #include "empathy-contact.h" #define EMPATHY_GET_PRIV(obj,type) ((type##Priv *) ((type *) obj)->priv) @@ -67,7 +65,6 @@ xmlNodePtr empathy_xml_node_find_child_prop_value (xmlNodePtr node, guint empathy_account_hash (gconstpointer key); gboolean empathy_account_equal (gconstpointer a, gconstpointer b); -MissionControl *empathy_mission_control_dup_singleton (void); const gchar * empathy_presence_get_default_message (TpConnectionPresenceType presence); const gchar * empathy_presence_to_str (TpConnectionPresenceType presence); TpConnectionPresenceType empathy_presence_from_str (const gchar *str); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index bfb92af37..080a6cae3 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -85,7 +85,6 @@ typedef struct { guint connecting_id; EmpathyAccountManager *account_manager; - MissionControl *mc; } EmpathyAccountsDialog; enum { @@ -1030,7 +1029,6 @@ accounts_dialog_destroy_cb (GtkWidget *widget, } g_object_unref (dialog->account_manager); - g_object_unref (dialog->mc); g_free (dialog); } @@ -1104,7 +1102,6 @@ empathy_accounts_dialog_show (GtkWindow *parent, /* Set up signalling */ dialog->account_manager = empathy_account_manager_dup_singleton (); - dialog->mc = empathy_mission_control_dup_singleton (); g_signal_connect (dialog->account_manager, "account-created", G_CALLBACK (accounts_dialog_account_added_cb), diff --git a/src/empathy-debug-dialog.c b/src/empathy-debug-dialog.c index cd0d925f9..9b420fd02 100644 --- a/src/empathy-debug-dialog.c +++ b/src/empathy-debug-dialog.c @@ -284,7 +284,6 @@ debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser, EmpathyDebugDialog *debug_dialog) { EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog); - MissionControl *mc; TpDBusDaemon *dbus; GError *error = NULL; gchar *bus_name; @@ -302,13 +301,11 @@ debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser, return; } - mc = empathy_mission_control_dup_singleton (); dbus = tp_dbus_daemon_dup (&error); if (error != NULL) { DEBUG ("Failed at duping the dbus daemon: %s", error->message); - g_object_unref (mc); } gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter, @@ -344,7 +341,6 @@ debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser, debug_dialog_get_messages_cb, debug_dialog, NULL, NULL); g_object_unref (dbus); - g_object_unref (mc); } typedef struct diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c index 1a7ec09cb..1be3ff7ce 100644 --- a/src/empathy-event-manager.c +++ b/src/empathy-event-manager.c @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 0d04153a3..05eb0774e 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -79,7 +79,6 @@ typedef struct { EmpathyContactListView *list_view; EmpathyContactListStore *list_store; - MissionControl *mc; EmpathyAccountManager *account_manager; EmpathyChatroomManager *chatroom_manager; EmpathyEventManager *event_manager; @@ -646,7 +645,6 @@ main_window_destroy_cb (GtkWidget *widget, g_list_free (window->actions_connected); - g_object_unref (window->mc); g_object_unref (window->account_manager); g_object_unref (window->list_store); g_hash_table_destroy (window->errors); @@ -1175,7 +1173,6 @@ empathy_main_window_show (void) gtk_action_set_visible (show_map_widget, FALSE); #endif - window->mc = empathy_mission_control_dup_singleton (); window->account_manager = empathy_account_manager_dup_singleton (); g_signal_connect (window->account_manager, diff --git a/src/empathy-tube-dispatch.c b/src/empathy-tube-dispatch.c index 67db5a3a3..66efa217d 100644 --- a/src/empathy-tube-dispatch.c +++ b/src/empathy-tube-dispatch.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include diff --git a/src/empathy.c b/src/empathy.c index 6439eecfa..5e3d983aa 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -145,68 +146,6 @@ dispatch_cb (EmpathyDispatcher *dispatcher, } } -static void -service_ended_cb (MissionControl *mc, - gpointer user_data) -{ - DEBUG ("Mission Control stopped"); -} - -static void -operation_error_cb (MissionControl *mc, - guint operation_id, - guint error_code, - gpointer user_data) -{ - const gchar *message; - - switch (error_code) { - case MC_DISCONNECTED_ERROR: - message = "Disconnected"; - break; - case MC_INVALID_HANDLE_ERROR: - message = "Invalid handle"; - break; - case MC_NO_MATCHING_CONNECTION_ERROR: - message = "No matching connection"; - break; - case MC_INVALID_ACCOUNT_ERROR: - message = "Invalid account"; - break; - case MC_PRESENCE_FAILURE_ERROR: - message = "Presence failure"; - break; - case MC_NO_ACCOUNTS_ERROR: - message = "No accounts"; - break; - case MC_NETWORK_ERROR: - message = "Network error"; - break; - case MC_CONTACT_DOES_NOT_SUPPORT_VOICE_ERROR: - message = "Contact does not support voice"; - break; - case MC_LOWMEM_ERROR: - message = "Lowmem"; - break; - case MC_CHANNEL_REQUEST_GENERIC_ERROR: - message = "Channel request generic error"; - break; - case MC_CHANNEL_BANNED_ERROR: - message = "Channel banned"; - break; - case MC_CHANNEL_FULL_ERROR: - message = "Channel full"; - break; - case MC_CHANNEL_INVITE_ONLY_ERROR: - message = "Channel invite only"; - break; - default: - message = "Unknown error code"; - } - - DEBUG ("Error during operation %d: %s", operation_id, message); -} - static void use_nm_notify_cb (EmpathyConf *conf, const gchar *key, @@ -529,7 +468,6 @@ main (int argc, char *argv[]) EmpathyCallFactory *call_factory; EmpathyFTFactory *ft_factory; GtkWidget *window; - MissionControl *mc; EmpathyIdle *idle; gboolean autoconnect = TRUE; gboolean no_connect = FALSE; @@ -636,15 +574,6 @@ main (int argc, char *argv[]) g_clear_error (&error); } - /* Setting up MC */ - mc = empathy_mission_control_dup_singleton (); - g_signal_connect (mc, "ServiceEnded", - G_CALLBACK (service_ended_cb), - NULL); - g_signal_connect (mc, "Error", - G_CALLBACK (operation_error_cb), - NULL); - if (accounts_dialog) { GtkWidget *dialog; @@ -671,7 +600,7 @@ main (int argc, char *argv[]) if (autoconnect && ! no_connect && tp_connection_presence_type_cmp_availability (empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0) { - empathy_idle_set_state (idle, MC_PRESENCE_AVAILABLE); + empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE); } /* account management */ @@ -722,7 +651,6 @@ main (int argc, char *argv[]) empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE); - g_object_unref (mc); g_object_unref (idle); g_object_unref (icon); g_object_unref (account_manager); -- cgit v1.2.3 From 17b571acbdbe5219c9b7c468006dda616cb7bb0a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 18:18:27 +0100 Subject: Check the right variable for setting the ready property --- libempathy/empathy-account.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5bfa38765..a93d548e3 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -158,7 +158,7 @@ empathy_account_get_property (GObject *object, g_value_set_boolean (value, priv->enabled); break; case PROP_READY: - g_value_set_boolean (value, priv->enabled); + g_value_set_boolean (value, priv->ready); break; case PROP_PRESENCE: g_value_set_uint (value, priv->presence); -- cgit v1.2.3 From 7cded0b0190dac119d3e7bb6882b2a2a93293db8 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 18:19:31 +0100 Subject: Add a concept of ready to the account manager --- libempathy/empathy-account-manager.c | 74 +++++++++++++++++++++++++++++++++++- libempathy/empathy-account-manager.h | 2 + 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index dc15651cb..ed24e0623 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -44,6 +44,7 @@ typedef struct { int connected; int connecting; gboolean dispose_run; + gboolean ready; TpProxySignalConnection *proxy_signal; TpAccountManager *tp_manager; TpDBusDaemon *dbus; @@ -68,6 +69,10 @@ enum { LAST_SIGNAL }; +enum { + PROP_READY = 1, +}; + static guint signals[LAST_SIGNAL]; static EmpathyAccountManager *manager_singleton = NULL; @@ -215,6 +220,32 @@ signal: priv->global_presence, priv->global_status, priv->global_status_message); } +static void +empathy_account_manager_check_ready (EmpathyAccountManager *manager) +{ + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + GHashTableIter iter; + gpointer value; + + if (priv->ready) + return; + + g_hash_table_iter_init (&iter, priv->accounts); + while (g_hash_table_iter_next (&iter, NULL, &value)) + { + EmpathyAccount *account = EMPATHY_ACCOUNT (value); + gboolean ready; + + g_object_get (account, "ready", &ready, NULL); + + if (!ready) + return; + } + + priv->ready = TRUE; + g_object_notify (G_OBJECT (manager), "ready"); +} + static void emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) { @@ -240,6 +271,8 @@ emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) g_signal_connect (account, "presence-changed", G_CALLBACK (emp_account_presence_changed_cb), manager); + + empathy_account_manager_check_ready (manager); } static void @@ -263,7 +296,6 @@ account_manager_got_all_cb (TpProxy *proxy, accounts = tp_asv_get_boxed (properties, "ValidAccounts", EMPATHY_ARRAY_TYPE_OBJECT); - for (i = 0; i < accounts->len; i++) { EmpathyAccount *account; @@ -275,6 +307,8 @@ account_manager_got_all_cb (TpProxy *proxy, g_signal_connect (account, "notify::ready", G_CALLBACK (emp_account_ready_cb), manager); } + + empathy_account_manager_check_ready (manager); } static void @@ -391,6 +425,26 @@ do_constructor (GType type, return retval; } +static void +do_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (object); + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + + switch (prop_id) + { + case PROP_READY: + g_value_set_boolean (value, priv->ready); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void empathy_account_manager_class_init (EmpathyAccountManagerClass *klass) { @@ -399,6 +453,14 @@ empathy_account_manager_class_init (EmpathyAccountManagerClass *klass) oclass->finalize = do_finalize; oclass->dispose = do_dispose; oclass->constructor = do_constructor; + oclass->get_property = do_get_property; + + g_object_class_install_property (oclass, PROP_READY, + g_param_spec_boolean ("ready", + "Ready", + "Whether the initial state dump from the account manager is finished", + FALSE, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); signals[ACCOUNT_CREATED] = g_signal_new ("account-created", @@ -506,6 +568,15 @@ empathy_account_manager_create (EmpathyAccountManager *manager, return NULL; } + +gboolean +empathy_account_manager_is_ready (EmpathyAccountManager *manager) +{ + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + + return priv->ready; +} + int empathy_account_manager_get_connected_accounts (EmpathyAccountManager *manager) { @@ -689,4 +760,3 @@ empathy_account_manager_get_global_presence ( return priv->global_presence; } - diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index bbf091997..e77f5017e 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -58,6 +58,8 @@ EmpathyAccount * empathy_account_manager_create ( const gchar *protocol, const gchar *display_name); +gboolean empathy_account_manager_is_ready (EmpathyAccountManager *manager); + int empathy_account_manager_get_connected_accounts (EmpathyAccountManager *manager); int empathy_account_manager_get_connecting_accounts -- cgit v1.2.3 From 1c95c220ca3830e83ed436d840528126e9ba9d15 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 16 Jul 2009 11:41:15 +0100 Subject: Move the responsibility of popping up the empathy accounts dialog out of the status icon --- src/empathy-status-icon.c | 17 ----------------- src/empathy.c | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c index f6c63c537..aca2d85c2 100644 --- a/src/empathy-status-icon.c +++ b/src/empathy-status-icon.c @@ -305,24 +305,7 @@ status_icon_set_visibility (EmpathyStatusIcon *icon, if (!visible) { empathy_window_iconify (priv->window, priv->icon); } else { - GList *accounts; - GList *l; - gboolean one_enabled = FALSE; - empathy_window_present (GTK_WINDOW (priv->window), TRUE); - - /* Show the accounts dialog if there is no enabled accounts */ - accounts = empathy_account_manager_dup_accounts (priv->account_manager); - for (l = accounts ; l != NULL ; l = g_list_next (l)) { - one_enabled = empathy_account_is_enabled (EMPATHY_ACCOUNT (l->data)) - || one_enabled; - g_object_unref (l->data); - } - g_list_free (accounts); - if (!one_enabled) { - DEBUG ("No enabled account, Showing account dialog"); - empathy_accounts_dialog_show (GTK_WINDOW (priv->window), NULL); - } } } diff --git a/src/empathy.c b/src/empathy.c index 5e3d983aa..1fa7f5a12 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -453,6 +453,22 @@ default_log_handler (const gchar *log_domain, } #endif /* ENABLE_DEBUG */ +static void +account_manager_ready_cb (EmpathyAccountManager *manager, + GParamSpec *spec, + gpointer user_data) +{ + if (!empathy_account_manager_is_ready (manager)) + return; + + if (empathy_account_manager_get_count (manager) != 0) + { + empathy_accounts_dialog_show (GTK_WINDOW (empathy_main_window_get ()), + NULL); + } + create_salut_account (); +} + int main (int argc, char *argv[]) { @@ -605,8 +621,8 @@ main (int argc, char *argv[]) /* account management */ account_manager = empathy_account_manager_dup_singleton (); - - create_salut_account (); + g_signal_connect (account_manager, "notify::ready", + G_CALLBACK (account_manager_ready_cb), NULL); /* Setting up UI */ window = empathy_main_window_show (); @@ -666,4 +682,3 @@ main (int argc, char *argv[]) return EXIT_SUCCESS; } - -- cgit v1.2.3 From 758bc33318e81709f4a64ea99c0629e9c522258a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 16 Jul 2009 12:41:26 +0100 Subject: Escape the unique account name --- libempathy/empathy-log-store-empathy.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 7e50cb12f..abfb276e1 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -98,8 +98,8 @@ empathy_log_store_empathy_init (EmpathyLogStoreEmpathy *self) self->priv = priv; - priv->basedir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), - ".gnome2", PACKAGE_NAME, "logs", NULL); + priv->basedir = g_build_path (G_DIR_SEPERATOR_S, g_get_user_data_dir (), + PACKAGE_NAME, "logs", NULL); priv->name = g_strdup ("Empathy"); priv->account_manager = empathy_account_manager_dup_singleton (); @@ -117,7 +117,8 @@ log_store_empathy_get_dir (EmpathyLogStore *self, priv = GET_PRIV (self); - account_id = empathy_account_get_unique_name (account); + account_id = tp_escape_as_identifier ( + empathy_account_get_unique_name (account)); if (chatroom) basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, account_id, @@ -126,6 +127,8 @@ log_store_empathy_get_dir (EmpathyLogStore *self, basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, account_id, chat_id, NULL); + g_free (account_id); + return basedir; } -- cgit v1.2.3 From f8043f3f6ebdd8acee896f0b50f78f62b35d0fdf Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 16 Jul 2009 14:53:18 +0100 Subject: Default to OFFLINE instead of UNSET for the global presence --- libempathy/empathy-account-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index ed24e0623..ebeb90d72 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -145,7 +145,7 @@ static void emp_account_manager_update_global_presence (EmpathyAccountManager *manager) { EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - TpConnectionPresenceType presence = TP_CONNECTION_PRESENCE_TYPE_UNSET; + TpConnectionPresenceType presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE; EmpathyAccount *account = NULL; GHashTableIter iter; gpointer value; -- cgit v1.2.3 From e700d8f398b27a98ef24476e3909570aa91c329a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 16 Jul 2009 14:54:45 +0100 Subject: Put the logs in XDG_DATA_HOME instead of ~/.gnome2 --- libempathy/empathy-log-store-empathy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index abfb276e1..6fedf121a 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -29,6 +29,8 @@ #include #include +#include + #include "empathy-log-store.h" #include "empathy-log-store-empathy.h" #include "empathy-log-manager.h" @@ -98,7 +100,7 @@ empathy_log_store_empathy_init (EmpathyLogStoreEmpathy *self) self->priv = priv; - priv->basedir = g_build_path (G_DIR_SEPERATOR_S, g_get_user_data_dir (), + priv->basedir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), PACKAGE_NAME, "logs", NULL); priv->name = g_strdup ("Empathy"); @@ -111,7 +113,7 @@ log_store_empathy_get_dir (EmpathyLogStore *self, const gchar *chat_id, gboolean chatroom) { - const gchar *account_id; + gchar *account_id; gchar *basedir; EmpathyLogStoreEmpathyPriv *priv; -- cgit v1.2.3 From 9309c89a6ce064223dc2879d5b61baf69472a334 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 16 Jul 2009 15:38:46 +0100 Subject: Ignore a log when the account it isn't found --- libempathy/empathy-log-store-empathy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 6fedf121a..56dc70fa4 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -426,9 +426,15 @@ log_store_empathy_get_messages_for_file (EmpathyLogStore *self, /* Get the account from the filename */ hit = log_store_empathy_search_hit_new (self, filename); - account = g_object_ref (hit->account); + + if (hit->account != NULL) + account = g_object_ref (hit->account); + empathy_log_manager_search_hit_free (hit); + if (hit->account == NULL) + return NULL; + /* Create parser. */ ctxt = xmlNewParserCtxt (); -- cgit v1.2.3 From e8f72606c7fc3ff48916c27a3e8d776618fe6f93 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 16 Jul 2009 15:39:25 +0100 Subject: Escape unique names by replacing / by % --- libempathy/empathy-log-store-empathy.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 56dc70fa4..189bf0036 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -113,23 +113,26 @@ log_store_empathy_get_dir (EmpathyLogStore *self, const gchar *chat_id, gboolean chatroom) { - gchar *account_id; gchar *basedir; + gchar *escaped; EmpathyLogStoreEmpathyPriv *priv; priv = GET_PRIV (self); - account_id = tp_escape_as_identifier ( - empathy_account_get_unique_name (account)); + /* unique name is an object path, ignore the initial / and replace the others + * by % */ + escaped = g_strdup (empathy_account_get_unique_name (account) + 1); + + g_strdelimit(escaped, "/", '%'); if (chatroom) - basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, account_id, + basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, escaped, LOG_DIR_CHATROOMS, chat_id, NULL); else basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, - account_id, chat_id, NULL); + escaped, chat_id, NULL); - g_free (account_id); + g_free (escaped); return basedir; } @@ -369,7 +372,8 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self, { EmpathyLogStoreEmpathyPriv *priv = GET_PRIV (self); EmpathyLogSearchHit *hit; - const gchar *account_name; + gchar *unescaped; + gchar *account_name; const gchar *end; gchar **strv; guint len; @@ -392,10 +396,13 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self, else account_name = strv[len-3]; + unescaped = g_strdup_printf ("/%s", g_strdelimit (account_name, "%", '/')); + hit->account = empathy_account_manager_lookup (priv->account_manager, - account_name); + unescaped); hit->filename = g_strdup (filename); + g_free (unescaped); g_strfreev (strv); return hit; -- cgit v1.2.3 From e4c629b216459740a76cb51b329be445c6a86a3e Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 19 Jul 2009 14:45:31 +0100 Subject: remove dead code --- libempathy/empathy-account.c | 58 -------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index a93d548e3..ef377427d 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -738,54 +738,6 @@ empathy_account_new (TpDBusDaemon *dbus, const gchar *unique_name) NULL)); } -#if 0 -EmpathyAccount * -_empathy_account_new (McAccount *mc_account) -{ - EmpathyAccount *account; - EmpathyAccountPriv *priv; - McProfile *profile; - McProtocol *protocol; - - - account = g_object_new (EMPATHY_TYPE_ACCOUNT, NULL); - priv = GET_PRIV (account); - priv->mc_account = mc_account; - - profile = mc_account_get_profile (mc_account); - protocol = mc_profile_get_protocol (profile); - - if (protocol != NULL) - { - McManager *manager = mc_protocol_get_manager (protocol); - - priv->proto_name = g_strdup (mc_protocol_get_name (protocol)); - priv->cm_name = g_strdup (mc_manager_get_unique_name (manager)); - - g_object_unref (protocol); - g_object_unref (manager); - } - g_object_unref (profile); - - return account; -} - -void -_empathy_account_set_status (EmpathyAccount *account, - TpConnectionStatus status, - TpConnectionStatusReason reason, - TpConnectionPresenceType presence) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - TpConnectionStatus old_s = priv->status; - TpConnectionPresenceType old_p = priv->presence; - - priv->status = status; - priv->presence = presence; - -} -#endif - static void empathy_account_connection_ready_cb (TpConnection *connection, const GError *error, @@ -929,13 +881,3 @@ empathy_account_request_presence (EmpathyAccount *account, g_value_unset (&value); } - -#if 0 -McAccount * -_empathy_account_get_mc_account (EmpathyAccount *account) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - - return priv->mc_account; -} -#endif -- cgit v1.2.3 From cd822950695cd4d0589559924703badf9d4771df Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 20 Jul 2009 11:30:54 +0100 Subject: Add singleton to cache TpConnectionManagers --- libempathy/Makefile.am | 2 + libempathy/empathy-connection-managers.c | 296 +++++++++++++++++++++++++++++++ libempathy/empathy-connection-managers.h | 75 ++++++++ 3 files changed, 373 insertions(+) create mode 100644 libempathy/empathy-connection-managers.c create mode 100644 libempathy/empathy-connection-managers.h diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 545074aed..ae1687f55 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -35,6 +35,7 @@ libempathy_la_SOURCES = \ empathy-contact-list.c \ empathy-contact-manager.c \ empathy-contact-monitor.c \ + empathy-connection-managers.c \ empathy-debug.c \ empathy-debugger.c \ empathy-dispatcher.c \ @@ -86,6 +87,7 @@ libempathy_headers = \ empathy-contact-list.h \ empathy-contact-manager.h \ empathy-contact-monitor.h \ + empathy-connection-managers.h \ empathy-debug.h \ empathy-debugger.h \ empathy-dispatcher.h \ diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c new file mode 100644 index 000000000..2ccfb9052 --- /dev/null +++ b/libempathy/empathy-connection-managers.c @@ -0,0 +1,296 @@ +/* + * empathy-connection-managers.c - Source for EmpathyConnectionManagers + * Copyright (C) 2009 Collabora Ltd. + * @author Sjoerd Simons + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include +#include + +#include +#include + +#include "empathy-connection-managers.h" +#include "empathy-utils.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include + +static GObject *managers = NULL; + +G_DEFINE_TYPE(EmpathyConnectionManagers, empathy_connection_managers, + G_TYPE_OBJECT) + +/* signal enum */ +enum +{ + UPDATED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = {0}; + +/* properties */ +enum { + PROP_READY = 1 +}; + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyConnectionManagers) + + +/* private structure */ +typedef struct _EmpathyConnectionManagersPriv + EmpathyConnectionManagersPriv; + +struct _EmpathyConnectionManagersPriv +{ + gboolean dispose_has_run; + gboolean ready; + + GList *cms; + + TpDBusDaemon *dbus; +}; + +#define EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + EMPATHY_TYPE_CONNECTION_MANAGERS, EmpathyConnectionManagersPriv)) + +static void +empathy_connection_managers_init (EmpathyConnectionManagers *obj) +{ + EmpathyConnectionManagersPriv *priv = + EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (obj); + + priv->dbus = tp_dbus_daemon_dup (NULL); + g_assert (priv->dbus != NULL); + + empathy_connection_managers_update (obj); + + /* allocate any data required by the object here */ +} + +static void empathy_connection_managers_dispose (GObject *object); +static void empathy_connection_managers_finalize (GObject *object); + +static GObject * +empathy_connection_managers_constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + if (managers != NULL) + return g_object_ref (managers); + + managers = + G_OBJECT_CLASS (empathy_connection_managers_parent_class)->constructor + (type, n_construct_params, construct_params); + + g_object_add_weak_pointer (managers, (gpointer) &managers); + + return managers; +} + + + +static void +empathy_connection_managers_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyConnectionManagers *managers = EMPATHY_CONNECTION_MANAGERS (object); + EmpathyConnectionManagersPriv *priv = GET_PRIV (managers); + + switch (prop_id) + { + case PROP_READY: + g_value_set_boolean (value, priv->ready); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +empathy_connection_managers_class_init ( + EmpathyConnectionManagersClass *empathy_connection_managers_class) +{ + GObjectClass *object_class = + G_OBJECT_CLASS (empathy_connection_managers_class); + + g_type_class_add_private (empathy_connection_managers_class, sizeof + (EmpathyConnectionManagersPriv)); + + object_class->constructor = empathy_connection_managers_constructor; + object_class->dispose = empathy_connection_managers_dispose; + object_class->finalize = empathy_connection_managers_finalize; + object_class->get_property = empathy_connection_managers_get_property; + + g_object_class_install_property (object_class, PROP_READY, + g_param_spec_boolean ("ready", + "Ready", + "Whether the connection manager information is ready to be used", + FALSE, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + + signals[UPDATED] = g_signal_new ("updated", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +static void +empathy_connection_managers_free_cm_list (EmpathyConnectionManagers *self) +{ + EmpathyConnectionManagersPriv *priv = GET_PRIV (self); + GList *l; + + for (l = priv->cms ; l != NULL ; l = g_list_next (l)) + { + g_object_unref (l->data); + } + g_list_free (priv->cms); + + priv->cms = NULL; +} + +static void +empathy_connection_managers_dispose (GObject *object) +{ + EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object); + EmpathyConnectionManagersPriv *priv = GET_PRIV (self); + + if (priv->dispose_has_run) + return; + + priv->dispose_has_run = TRUE; + + if (priv->dbus != NULL) + g_object_unref (priv->dbus); + priv->dbus = NULL; + + empathy_connection_managers_free_cm_list (self); + + /* release any references held by the object here */ + + if (G_OBJECT_CLASS (empathy_connection_managers_parent_class)->dispose) + G_OBJECT_CLASS (empathy_connection_managers_parent_class)->dispose (object); +} + +void +empathy_connection_managers_finalize (GObject *object) +{ +#if 0 + EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object); + EmpathyConnectionManagersPriv *priv = + EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (self); + + /* free any data held directly by the object here */ + + G_OBJECT_CLASS (empathy_connection_managers_parent_class)->finalize (object); +#endif +} + +EmpathyConnectionManagers * +empathy_connection_managers_dup_singleton (void) +{ + return EMPATHY_CONNECTION_MANAGERS ( + g_object_new (EMPATHY_TYPE_CONNECTION_MANAGERS, NULL)); +} + +gboolean +empathy_connection_managers_is_ready (EmpathyConnectionManagers *managers) +{ + EmpathyConnectionManagersPriv *priv = GET_PRIV (managers); + return priv->ready; +} + +static void +empathy_connection_managers_listed_cb (TpConnectionManager * const *cms, + gsize n_cms, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + EmpathyConnectionManagers *self = + EMPATHY_CONNECTION_MANAGERS (weak_object); + EmpathyConnectionManagersPriv *priv = GET_PRIV (self); + TpConnectionManager * const *iter; + + empathy_connection_managers_free_cm_list (self); + + if (error != NULL) + { + DEBUG ("Failed to get connection managers: %s", error->message); + goto out; + } + + for (iter = cms ; iter != NULL && *iter != NULL; iter++) + { + /* only list cms that didn't hit errors */ + if (tp_connection_manager_is_ready(*iter)) + priv->cms = g_list_prepend (priv->cms, g_object_ref (*iter)); + } + +out: + if (!priv->ready) + { + priv->ready = TRUE; + g_object_notify (weak_object, "ready"); + } + g_signal_emit (weak_object, signals[UPDATED], 0); +} + +void +empathy_connection_managers_update (EmpathyConnectionManagers *managers) +{ + EmpathyConnectionManagersPriv *priv = GET_PRIV (managers); + + tp_list_connection_managers (priv->dbus, + empathy_connection_managers_listed_cb, + NULL, NULL, G_OBJECT (managers)); +} + +GList * +empathy_connection_managers_get_cms (EmpathyConnectionManagers *managers) +{ + EmpathyConnectionManagersPriv *priv = GET_PRIV (managers); + + return priv->cms; +} + +TpConnectionManager * +empathy_connection_managers_get_cm (EmpathyConnectionManagers *managers, + const gchar *cm) +{ + EmpathyConnectionManagersPriv *priv = GET_PRIV (managers); + GList *l; + + for (l = priv->cms ; l != NULL; l = g_list_next (l)) + { + TpConnectionManager *c = TP_CONNECTION_MANAGER (l->data); + + if (!tp_strdiff (c->name, cm)) + return c; + } + + return NULL; +} diff --git a/libempathy/empathy-connection-managers.h b/libempathy/empathy-connection-managers.h new file mode 100644 index 000000000..661075614 --- /dev/null +++ b/libempathy/empathy-connection-managers.h @@ -0,0 +1,75 @@ +/* + * empathy-connection-managers.h - Header for EmpathyConnectionManagers + * Copyright (C) 2009 Collabora Ltd. + * @author Sjoerd Simons + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __EMPATHY_CONNECTION_MANAGERS_H__ +#define __EMPATHY_CONNECTION_MANAGERS_H__ + +#include + +#include + +G_BEGIN_DECLS + +typedef struct _EmpathyConnectionManagers EmpathyConnectionManagers; +typedef struct _EmpathyConnectionManagersClass EmpathyConnectionManagersClass; + +struct _EmpathyConnectionManagersClass { + GObjectClass parent_class; +}; + +struct _EmpathyConnectionManagers { + GObject parent; + gpointer priv; +}; + +GType empathy_connection_managers_get_type(void); + +/* TYPE MACROS */ +#define EMPATHY_TYPE_CONNECTION_MANAGERS \ + (empathy_connection_managers_get_type()) +#define EMPATHY_CONNECTION_MANAGERS(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), EMPATHY_TYPE_CONNECTION_MANAGERS, \ + EmpathyConnectionManagers)) +#define EMPATHY_CONNECTION_MANAGERS_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), EMPATHY_TYPE_CONNECTION_MANAGERS, \ + EmpathyConnectionManagersClass)) +#define EMPATHY_IS_CONNECTION_MANAGERS(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), EMPATHY_TYPE_CONNECTION_MANAGERS)) +#define EMPATHY_IS_CONNECTION_MANAGERS_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), EMPATHY_TYPE_CONNECTION_MANAGERS)) +#define EMPATHY_CONNECTION_MANAGERS_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_CONNECTION_MANAGERS, \ + EmpathyConnectionManagersClass)) + +EmpathyConnectionManagers *empathy_connection_managers_dup_singleton (void); +gboolean empathy_connection_managers_is_ready ( + EmpathyConnectionManagers *managers); + +void empathy_connection_managers_update (EmpathyConnectionManagers *managers); + +GList * empathy_connection_managers_get_cms ( + EmpathyConnectionManagers *managers); + +TpConnectionManager *empathy_connection_managers_get_cm ( + EmpathyConnectionManagers *managers, const gchar *cm); + +G_END_DECLS + +#endif /* #ifndef __EMPATHY_CONNECTION_MANAGERS_H__*/ -- cgit v1.2.3 From 4bdda84105d2e83a551b6c1caa919df221fc2244 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:25:36 +0100 Subject: reformat macros a bit --- libempathy/empathy-account-manager.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index e77f5017e..490fb09c2 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -28,12 +28,17 @@ G_BEGIN_DECLS -#define EMPATHY_TYPE_ACCOUNT_MANAGER (empathy_account_manager_get_type ()) -#define EMPATHY_ACCOUNT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManager)) -#define EMPATHY_ACCOUNT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManagerClass)) -#define EMPATHY_IS_ACCOUNT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_ACCOUNT_MANAGER)) -#define EMPATHY_IS_ACCOUNT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_ACCOUNT_MANAGER)) -#define EMPATHY_ACCOUNT_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManagerClass)) +#define EMPATHY_TYPE_ACCOUNT_MANAGER (empathy_account_manager_get_type ()) +#define EMPATHY_ACCOUNT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ + EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManager)) +#define EMPATHY_ACCOUNT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ + EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManagerClass)) +#define EMPATHY_IS_ACCOUNT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ + EMPATHY_TYPE_ACCOUNT_MANAGER)) +#define EMPATHY_IS_ACCOUNT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ + EMPATHY_TYPE_ACCOUNT_MANAGER)) +#define EMPATHY_ACCOUNT_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \ + EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManagerClass)) typedef struct _EmpathyAccountManager EmpathyAccountManager; typedef struct _EmpathyAccountManagerClass EmpathyAccountManagerClass; -- cgit v1.2.3 From b53f011fbab2a1efbb2ba229195da8ec8e1fc7dc Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:27:22 +0100 Subject: Add API to add accounts --- libempathy/empathy-account-manager.c | 115 +++++++++++++++++++++++++++++------ libempathy/empathy-account-manager.h | 14 +++-- 2 files changed, 106 insertions(+), 23 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index ebeb90d72..eeac5c130 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -275,6 +275,22 @@ emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) empathy_account_manager_check_ready (manager); } +static EmpathyAccount * +account_manager_add_account (EmpathyAccountManager *manager, + const gchar *path) +{ + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + EmpathyAccount *account; + + account = empathy_account_new (priv->dbus, path); + g_hash_table_insert (priv->accounts, g_strdup (path), account); + + g_signal_connect (account, "notify::ready", + G_CALLBACK (emp_account_ready_cb), manager); + + return account; +} + static void account_manager_got_all_cb (TpProxy *proxy, GHashTable *properties, @@ -283,7 +299,6 @@ account_manager_got_all_cb (TpProxy *proxy, GObject *weak_object) { EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); - EmpathyAccountManagerPriv *priv = GET_PRIV (manager); GPtrArray *accounts; int i; @@ -298,14 +313,9 @@ account_manager_got_all_cb (TpProxy *proxy, for (i = 0; i < accounts->len; i++) { - EmpathyAccount *account; gchar *name = g_ptr_array_index (accounts, i); - account = empathy_account_new (priv->dbus, name); - g_hash_table_insert (priv->accounts, g_strdup (name), account); - - g_signal_connect (account, "notify::ready", - G_CALLBACK (emp_account_ready_cb), manager); + account_manager_add_account (manager, name); } empathy_account_manager_check_ready (manager); @@ -558,17 +568,6 @@ empathy_account_manager_dup_singleton (void) return g_object_new (EMPATHY_TYPE_ACCOUNT_MANAGER, NULL); } -EmpathyAccount * -empathy_account_manager_create (EmpathyAccountManager *manager, - const gchar *connection_manager, - const gchar *protocol, - const gchar *display_name) -{ - /* FIXME */ - return NULL; -} - - gboolean empathy_account_manager_is_ready (EmpathyAccountManager *manager) { @@ -760,3 +759,83 @@ empathy_account_manager_get_global_presence ( return priv->global_presence; } + +static void +empathy_account_manager_created_ready_cb (EmpathyAccount *account, + GParamSpec *spec, gpointer user_data) +{ + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + + if (!empathy_account_is_ready (account)) + return; + + g_simple_async_result_set_op_res_gpointer ( + G_SIMPLE_ASYNC_RESULT (result), account, NULL); + + g_simple_async_result_complete (result); + g_object_unref (G_OBJECT (result)); +} + +static void +empathy_account_manager_created_cb (TpAccountManager *proxy, + const gchar *account_path, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + EmpathyAccount *account; + + if (error != NULL) + { + g_simple_async_result_set_from_error (result, (GError *)error); + g_simple_async_result_complete (result); + g_object_unref (G_OBJECT (result)); + return; + } + + account = account_manager_add_account (manager, account_path); + g_signal_connect (account, "notify::ready", + G_CALLBACK (empathy_account_manager_created_ready_cb), result); +} + +void +empathy_account_manager_create_account_async (EmpathyAccountManager *manager, + const gchar *connection_manager, + const gchar *protocol, const gchar *display_name, + GHashTable *parameters, GHashTable *properties, + GAsyncReadyCallback callback, gpointer user_data) +{ + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (manager), + callback, user_data, empathy_account_manager_create_account_finish); + + tp_cli_account_manager_call_create_account (priv->tp_manager, + -1, + connection_manager, + protocol, + display_name, + parameters, + properties, + empathy_account_manager_created_cb, + result, + NULL, + G_OBJECT (manager)); +} + +EmpathyAccount * +empathy_account_manager_create_account_finish ( + EmpathyAccountManager *manager, GAsyncResult *result, GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return NULL; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (manager), empathy_account_manager_create_account_finish), NULL); + + return EMPATHY_ACCOUNT (g_simple_async_result_get_op_res_gpointer ( + G_SIMPLE_ASYNC_RESULT (result))); +} + diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index 490fb09c2..953d8bc75 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -57,11 +57,6 @@ GType empathy_account_manager_get_type (void); /* public methods */ EmpathyAccountManager * empathy_account_manager_dup_singleton (void); -EmpathyAccount * empathy_account_manager_create ( - EmpathyAccountManager *manager, - const gchar *connection_manager, - const gchar *protocol, - const gchar *display_name); gboolean empathy_account_manager_is_ready (EmpathyAccountManager *manager); @@ -96,6 +91,15 @@ TpConnectionPresenceType empathy_account_manager_get_global_presence ( gchar **status, gchar **message); +void empathy_account_manager_create_account_async ( + EmpathyAccountManager *manager, const gchar *connection_manager, + const gchar *protocol, const gchar *display_name, + GHashTable *parameters, GHashTable *properties, + GAsyncReadyCallback callback, gpointer user_data); + +EmpathyAccount * empathy_account_manager_create_account_finish ( + EmpathyAccountManager *settings, GAsyncResult *result, GError **error); + G_END_DECLS #endif /* __EMPATHY_ACCOUNT_MANAGER_H__ */ -- cgit v1.2.3 From 96445f9768c9dee5e375522aa3bb3a9a01df7280 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:32:44 +0100 Subject: Put (Haze) behind all protocols coming from haze --- libempathy-gtk/empathy-protocol-chooser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index 45442156e..ebb198455 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -137,8 +137,8 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser, icon_name = g_strdup_printf ("im-%s", proto->name); - if (!tp_strdiff (cm->name, "haze") && !tp_strdiff (proto->name, "msn")) - display_name = g_strdup_printf ("msn (Haze)"); + if (!tp_strdiff (cm->name, "haze")) + display_name = g_strdup_printf ("%s (Haze)", proto->name); else display_name = g_strdup (proto->name); -- cgit v1.2.3 From 0d4c1f6c049f0f08f7f323b7d8924783e0b1f608 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:33:26 +0100 Subject: Correct usage of priv --- libempathy/empathy-connection-managers.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c index 2ccfb9052..6a87a3fa5 100644 --- a/libempathy/empathy-connection-managers.c +++ b/libempathy/empathy-connection-managers.c @@ -67,15 +67,14 @@ struct _EmpathyConnectionManagersPriv TpDBusDaemon *dbus; }; -#define EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - EMPATHY_TYPE_CONNECTION_MANAGERS, EmpathyConnectionManagersPriv)) - static void empathy_connection_managers_init (EmpathyConnectionManagers *obj) { EmpathyConnectionManagersPriv *priv = - EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (obj); + G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ + EMPATHY_TYPE_CONNECTION_MANAGERS, EmpathyConnectionManagersPriv); + + obj->priv = priv; priv->dbus = tp_dbus_daemon_dup (NULL); g_assert (priv->dbus != NULL); -- cgit v1.2.3 From f8d5873483b65c9d3d6577b3490d0ed21e7f4a21 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:43:31 +0100 Subject: Add an abstraction to buffer up changes to an account --- libempathy/Makefile.am | 2 + libempathy/empathy-account-settings.c | 964 ++++++++++++++++++++++++++++++++++ libempathy/empathy-account-settings.h | 156 ++++++ 3 files changed, 1122 insertions(+) create mode 100644 libempathy/empathy-account-settings.c create mode 100644 libempathy/empathy-account-settings.h diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index ae1687f55..cdaa144fc 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -25,6 +25,7 @@ lib_LTLIBRARIES = libempathy.la libempathy_la_SOURCES = \ empathy-account.c \ + empathy-account-settings.c \ empathy-account-manager.c \ empathy-chatroom.c \ empathy-chatroom-manager.c \ @@ -76,6 +77,7 @@ libempathy_la_LDFLAGS = \ -export-symbols-regex ^empathy_ libempathy_headers = \ + empathy-account-settings.h \ empathy-account.h \ empathy-account-manager.h \ empathy-chatroom.h \ diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c new file mode 100644 index 000000000..2763f0702 --- /dev/null +++ b/libempathy/empathy-account-settings.c @@ -0,0 +1,964 @@ +/* + * empathy-account-settings.c - Source for EmpathyAccountSettings + * Copyright (C) 2009 Collabora Ltd. + * @author Sjoerd Simons + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include +#include + +#include + +#include "empathy-account-settings.h" +#include "empathy-account-manager.h" +#include "empathy-connection-managers.h" +#include "empathy-utils.h" + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountSettings) + +G_DEFINE_TYPE(EmpathyAccountSettings, empathy_account_settings, G_TYPE_OBJECT) + +/* signal enum */ +#if 0 +enum +{ + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = {0}; +#endif + +enum { + PROP_ACCOUNT = 1, + PROP_CM_NAME, + PROP_PROTOCOL, + PROP_DISPLAY_NAME, + PROP_READY +}; + +/* private structure */ +typedef struct _EmpathyAccountSettingsPriv EmpathyAccountSettingsPriv; + +struct _EmpathyAccountSettingsPriv +{ + gboolean dispose_has_run; + EmpathyConnectionManagers *managers; + EmpathyAccountManager *account_manager; + gulong account_manager_ready_id; + + TpConnectionManager *manager; + const TpConnectionManagerProtocol *tp_protocol; + + EmpathyAccount *account; + gchar *cm_name; + gchar *protocol; + gchar *display_name; + gboolean ready; + + GHashTable *parameters; + GArray *unset_parameters; + + gulong managers_ready_id; + gulong account_ready_id; + + GSimpleAsyncResult *apply_result; +}; + +static void +empathy_account_settings_init (EmpathyAccountSettings *obj) +{ + EmpathyAccountSettingsPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE ((obj), + EMPATHY_TYPE_ACCOUNT_SETTINGS, EmpathyAccountSettingsPriv); + + obj->priv = priv; + + /* allocate any data required by the object here */ + priv->managers = empathy_connection_managers_dup_singleton (); + priv->account_manager = empathy_account_manager_dup_singleton (); + + priv->parameters = tp_asv_new (NULL, NULL); + priv->unset_parameters = g_array_new (TRUE, FALSE, sizeof (gchar *)); +} + +static void empathy_account_settings_dispose (GObject *object); +static void empathy_account_settings_finalize (GObject *object); +static void empathy_account_settings_ready_cb (GObject *obj, + GParamSpec *spec, gpointer user_data); +static void empathy_account_settings_check_readyness ( + EmpathyAccountSettings *self); + +static void +empathy_account_settings_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (object); + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + switch (prop_id) + { + case PROP_ACCOUNT: + priv->account = g_value_dup_object (value); + break; + case PROP_CM_NAME: + priv->cm_name = g_value_dup_string (value); + break; + case PROP_PROTOCOL: + priv->protocol = g_value_dup_string (value); + break; + case PROP_DISPLAY_NAME: + priv->display_name = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +empathy_account_settings_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (object); + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + switch (prop_id) + { + case PROP_ACCOUNT: + g_value_set_object (value, priv->account); + break; + case PROP_CM_NAME: + g_value_set_string (value, priv->cm_name); + break; + case PROP_PROTOCOL: + g_value_set_string (value, priv->protocol); + break; + case PROP_DISPLAY_NAME: + g_value_set_string (value, priv->display_name); + break; + case PROP_READY: + g_value_set_boolean (value, priv->ready); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +empathy_account_settings_constructed (GObject *object) +{ + EmpathyAccountSettings *self = EMPATHY_ACCOUNT_SETTINGS (object); + EmpathyAccountSettingsPriv *priv = GET_PRIV (self); + + if (priv->account != NULL) + { + g_free (priv->cm_name); + g_free (priv->protocol); + g_free (priv->display_name); + + priv->cm_name = + g_strdup (empathy_account_get_connection_manager (priv->account)); + priv->protocol = + g_strdup (empathy_account_get_protocol (priv->account)); + priv->display_name = + g_strdup (empathy_account_get_display_name (priv->account)); + } + + g_assert (priv->cm_name != NULL && priv->protocol != NULL + && priv->display_name != NULL); + + empathy_account_settings_check_readyness (self); + + if (!priv->ready) + { + g_signal_connect (priv->account, "notify::ready", + G_CALLBACK (empathy_account_settings_ready_cb), self); + g_signal_connect (priv->managers, "notify::ready", + G_CALLBACK (empathy_account_settings_ready_cb), self); + } + + if (G_OBJECT_CLASS ( + empathy_account_settings_parent_class)->constructed != NULL) + G_OBJECT_CLASS ( + empathy_account_settings_parent_class)->constructed (object); +} + + +static void +empathy_account_settings_class_init ( + EmpathyAccountSettingsClass *empathy_account_settings_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (empathy_account_settings_class); + + g_type_class_add_private (empathy_account_settings_class, sizeof + (EmpathyAccountSettingsPriv)); + + object_class->dispose = empathy_account_settings_dispose; + object_class->finalize = empathy_account_settings_finalize; + object_class->set_property = empathy_account_settings_set_property; + object_class->get_property = empathy_account_settings_get_property; + object_class->constructed = empathy_account_settings_constructed; + + g_object_class_install_property (object_class, PROP_ACCOUNT, + g_param_spec_object ("account", + "Account", + "The EmpathyAccount backing these settings", + EMPATHY_TYPE_ACCOUNT, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_CM_NAME, + g_param_spec_string ("connection-manager", + "connection-manager", + "The name of the connection manager this account uses", + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_PROTOCOL, + g_param_spec_string ("protocol", + "Protocol", + "The name of the protocol this account uses", + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_DISPLAY_NAME, + g_param_spec_string ("display-name", + "display-name", + "The display name account these settings belong to", + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_READY, + g_param_spec_boolean ("ready", + "Ready", + "Whether this account is ready to be used", + FALSE, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); +} + +static void +empathy_account_settings_dispose (GObject *object) +{ + EmpathyAccountSettings *self = EMPATHY_ACCOUNT_SETTINGS (object); + EmpathyAccountSettingsPriv *priv = GET_PRIV (self); + + if (priv->dispose_has_run) + return; + + priv->dispose_has_run = TRUE; + + if (priv->managers_ready_id != 0) + g_signal_handler_disconnect (priv->managers, priv->managers_ready_id); + priv->managers_ready_id = 0; + + if (priv->managers != NULL) + g_object_unref (priv->managers); + priv->managers = NULL; + + if (priv->manager != NULL) + g_object_unref (priv->manager); + priv->manager = NULL; + + if (priv->account_manager_ready_id != 0) + g_signal_handler_disconnect (priv->account_manager, + priv->account_manager_ready_id); + priv->account_manager_ready_id = 0; + + if (priv->account_manager != NULL) + g_object_unref (priv->account_manager); + priv->account_manager = NULL; + + if (priv->account_ready_id != 0) + g_signal_handler_disconnect (priv->account, priv->account_ready_id); + priv->account_ready_id = 0; + + if (priv->account != NULL) + g_object_unref (priv->account); + priv->account = NULL; + + /* release any references held by the object here */ + if (G_OBJECT_CLASS (empathy_account_settings_parent_class)->dispose) + G_OBJECT_CLASS (empathy_account_settings_parent_class)->dispose (object); +} + +static void +empathy_account_settings_free_unset_parameters ( + EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + int i; + + for (i = 0 ; i < priv->unset_parameters->len; i++) + g_free (g_array_index (priv->unset_parameters, gchar *, i)); + + g_array_set_size (priv->unset_parameters, 0); +} + +static void +empathy_account_settings_finalize (GObject *object) +{ + EmpathyAccountSettings *self = EMPATHY_ACCOUNT_SETTINGS (object); + EmpathyAccountSettingsPriv *priv = GET_PRIV (self); + + /* free any data held directly by the object here */ + g_free (priv->cm_name); + g_free (priv->protocol); + g_free (priv->display_name); + + g_hash_table_destroy (priv->parameters); + + empathy_account_settings_free_unset_parameters (self); + g_array_free (priv->unset_parameters, TRUE); + + G_OBJECT_CLASS (empathy_account_settings_parent_class)->finalize (object); +} + +static void +empathy_account_settings_check_readyness (EmpathyAccountSettings *self) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (self); + + if (priv->ready) + return; + + if (priv->account != NULL && !empathy_account_is_ready (priv->account)) + return; + + if (!empathy_connection_managers_is_ready (priv->managers)) + return; + + priv->manager = empathy_connection_managers_get_cm ( + priv->managers, priv->cm_name); + + if (priv->manager == NULL) + return; + + priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager, + priv->protocol); + + if (priv->tp_protocol == NULL) + { + priv->manager = NULL; + return; + } + + g_object_ref (priv->manager); + + priv->ready = TRUE; + g_object_notify (G_OBJECT (self), "ready"); +} + +static void +empathy_account_settings_ready_cb (GObject *obj, + GParamSpec *spec, gpointer user_data) +{ + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data); + + empathy_account_settings_check_readyness (settings); +} + +EmpathyAccountSettings * +empathy_account_settings_new (const gchar *connection_manager, + const gchar *protocol, + const char *display_name) +{ + return g_object_new (EMPATHY_TYPE_ACCOUNT_SETTINGS, + "connection-manager", connection_manager, + "protocol", protocol, + "display-name", display_name, + NULL); +} + +EmpathyAccountSettings * +empathy_account_settings_new_for_account (EmpathyAccount *account) +{ + return g_object_new (EMPATHY_TYPE_ACCOUNT_SETTINGS, + "account", account, + NULL); +} + +TpConnectionManagerParam * +empathy_account_settings_get_tp_params (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + g_return_val_if_fail (priv->tp_protocol != NULL, NULL); + + return priv->tp_protocol->params; +} + +gboolean +empathy_account_settings_is_ready (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + return priv->ready; +} + +const gchar * +empathy_account_settings_get_cm (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + return priv->cm_name; +} + +const gchar * +empathy_account_settings_get_protocol (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + return priv->protocol; +} + +const gchar * +empathy_account_settings_get_icon_name (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + if (priv->account != NULL) + return empathy_account_get_icon_name (priv->account); + + return NULL; +} + +const gchar * +empathy_account_settings_get_display_name (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + return priv->display_name; +} + +EmpathyAccount * +empathy_account_settings_get_account (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + return priv->account; +} + +static gboolean +empathy_account_settings_is_unset (EmpathyAccountSettings *settings, + const gchar *param) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + GArray *a; + int i; + + a = priv->unset_parameters; + + for (i = 0; i < a->len; i++) + { + if (!tp_strdiff (g_array_index (a, gchar *, i), param)) + return TRUE; + } + + return FALSE; +} + +static TpConnectionManagerParam * +empathy_account_settings_get_tp_param (EmpathyAccountSettings *settings, + const gchar *param) +{ + TpConnectionManagerParam *tp_params = + empathy_account_settings_get_tp_params (settings); + TpConnectionManagerParam *p; + + for (p = tp_params; p != NULL && p->name != NULL; p++) + { + if (tp_strdiff (p->name, param)) + continue; + + return p; + } + + return NULL; +} + +const GValue * +empathy_account_settings_get_default (EmpathyAccountSettings *settings, + const gchar *param) +{ + TpConnectionManagerParam *p; + + p = empathy_account_settings_get_tp_param (settings, param); + + if (p == NULL || !(p->flags & TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT)) + return NULL; + + return &(p->default_value); +} + +const gchar * +empathy_settings_get_dbus_signature (EmpathyAccountSettings *settings, + const gchar *param) +{ + TpConnectionManagerParam *p; + + p = empathy_account_settings_get_tp_param (settings, param); + + if (p == NULL) + return NULL; + + return p->dbus_signature; +} + +const GValue * +empathy_account_settings_get (EmpathyAccountSettings *settings, + const gchar *param) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + const GValue *result = NULL; + + /* Lookup the update parameters we set */ + result = tp_asv_lookup (priv->parameters, param); + if (result != NULL) + return result; + + /* If the parameters isn't unset use the accounts setting if any */ + if (priv->account != NULL + && !empathy_account_settings_is_unset (settings, param)) + { + const GHashTable *parameters; + + parameters = empathy_account_get_parameters (priv->account); + result = tp_asv_lookup (parameters, param); + + if (result != NULL) + return result; + } + + /* fallback to the default */ + return empathy_account_settings_get_default (settings, param); +} + + +void +empathy_account_settings_unset (EmpathyAccountSettings *settings, + const gchar *param) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + gchar *v; + if (empathy_account_settings_is_unset (settings, param)) + return; + + v = g_strdup (param); + + g_array_append_val (priv->unset_parameters, v); + g_hash_table_remove (priv->parameters, param); +} + +const gchar * +empathy_account_settings_get_string (EmpathyAccountSettings *settings, + const gchar *param) +{ + const GValue *v; + + v = empathy_account_settings_get (settings, param); + + if (v == NULL || !G_VALUE_HOLDS_STRING (v)) + return NULL; + + return g_value_get_string (v); +} + +gint32 +empathy_account_settings_get_int32 (EmpathyAccountSettings *settings, + const gchar *param) +{ + const GValue *v; + gint32 ret = 0; + + v = empathy_account_settings_get (settings, param); + + if (v == NULL) + return 0; + + switch G_VALUE_TYPE (v) + { + case G_TYPE_UCHAR: + ret = g_value_get_uchar (v); + break; + case G_TYPE_INT: + ret = g_value_get_int (v); + break; + case G_TYPE_UINT: + ret = CLAMP (G_MININT32, g_value_get_uint (v), G_MAXINT32); + break; + case G_TYPE_INT64: + ret = CLAMP (G_MININT32, g_value_get_int64 (v), G_MAXINT32); + break; + case G_TYPE_UINT64: + ret = CLAMP (G_MININT32, g_value_get_uint64 (v), G_MAXINT32); + break; + default: + ret = 0; + break; + } + + return ret; +} + +gint64 +empathy_account_settings_get_int64 (EmpathyAccountSettings *settings, + const gchar *param) +{ + const GValue *v; + gint64 ret = 0; + + v = empathy_account_settings_get (settings, param); + if (v == NULL) + return 0; + + switch G_VALUE_TYPE (v) + { + case G_TYPE_UCHAR: + ret = g_value_get_uchar (v); + break; + case G_TYPE_INT: + ret = g_value_get_int (v); + break; + case G_TYPE_UINT: + ret = g_value_get_uint (v); + break; + case G_TYPE_INT64: + ret = g_value_get_int64 (v); + break; + case G_TYPE_UINT64: + ret = CLAMP (G_MININT64, g_value_get_uint64 (v), G_MAXINT64); + break; + default: + ret = 0; + break; + } + + return ret; +} + +guint32 +empathy_account_settings_get_uint32 (EmpathyAccountSettings *settings, + const gchar *param) +{ + const GValue *v; + guint32 ret; + + v = empathy_account_settings_get (settings, param); + + switch G_VALUE_TYPE (v) + { + case G_TYPE_UCHAR: + ret = g_value_get_uchar (v); + break; + case G_TYPE_INT: + ret = MAX (0, g_value_get_int (v)); + break; + case G_TYPE_UINT: + ret = g_value_get_uint (v); + break; + case G_TYPE_INT64: + ret = CLAMP (0, g_value_get_int64 (v), G_MAXUINT32); + break; + case G_TYPE_UINT64: + ret = CLAMP (0, g_value_get_uint64 (v), G_MAXUINT32); + break; + default: + ret = 0; + break; + } + + return ret; +} + +guint64 +empathy_account_settings_get_uint64 (EmpathyAccountSettings *settings, + const gchar *param) +{ + const GValue *v; + guint64 ret = 0; + + v = empathy_account_settings_get (settings, param); + + if (v == NULL || !G_VALUE_HOLDS_INT (v)) + return 0; + + switch G_VALUE_TYPE (v) + { + case G_TYPE_UCHAR: + ret = g_value_get_uchar (v); + break; + case G_TYPE_INT: + ret = MAX (0, g_value_get_int (v)); + break; + case G_TYPE_UINT: + ret = g_value_get_uint (v); + break; + case G_TYPE_INT64: + ret = MAX (0, g_value_get_int64 (v)); + break; + case G_TYPE_UINT64: + ret = CLAMP (0, g_value_get_uint64 (v), G_MAXUINT64); + break; + default: + ret = 0; + break; + } + + return ret; +} + +gboolean +empathy_account_settings_get_boolean (EmpathyAccountSettings *settings, + const gchar *param) +{ + const GValue *v; + + v = empathy_account_settings_get (settings, param); + + if (v == NULL || !G_VALUE_HOLDS_BOOLEAN (v)) + return FALSE; + + return g_value_get_boolean (v); +} + +void +empathy_account_settings_set_string (EmpathyAccountSettings *settings, + const gchar *param, + const gchar *value) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + tp_asv_set_string (priv->parameters, param, value); +} + +void +empathy_account_settings_set_int32 (EmpathyAccountSettings *settings, + const gchar *param, + gint32 value) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + tp_asv_set_int32 (priv->parameters, param, value); +} + +void +empathy_account_settings_set_int64 (EmpathyAccountSettings *settings, + const gchar *param, + gint64 value) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + tp_asv_set_int64 (priv->parameters, param, value); +} + +void +empathy_account_settings_set_uint32 (EmpathyAccountSettings *settings, + const gchar *param, + guint32 value) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + tp_asv_set_uint32 (priv->parameters, param, value); +} + +void +empathy_account_settings_set_uint64 (EmpathyAccountSettings *settings, + const gchar *param, + guint64 value) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + tp_asv_set_uint64 (priv->parameters, param, value); +} + +void +empathy_account_settings_set_boolean (EmpathyAccountSettings *settings, + const gchar *param, + gboolean value) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + tp_asv_set_boolean (priv->parameters, param, value); +} + + +void +empathy_account_settings_set_display_name_async ( + EmpathyAccountSettings *settings, + const gchar *name, + GAsyncReadyCallback callback, + gpointer user_data) +{ +} + +gboolean +empathy_account_settings_set_display_name_finish ( + EmpathyAccountSettings *settings, + GAsyncResult *result, + GError **error) +{ + + return TRUE; +} + +static void +empathy_account_settings_account_updated (GObject *source, + GAsyncResult *result, gpointer user_data) +{ + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data); + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + GSimpleAsyncResult *r; + GError *error = NULL; + + if (!empathy_account_update_settings_finish (EMPATHY_ACCOUNT (source), + result, &error)) + { + g_simple_async_result_set_from_error (priv->apply_result, error); + g_error_free (error); + } + + r = priv->apply_result; + priv->apply_result = NULL; + + g_simple_async_result_complete (r); + g_object_unref (r); +} + +static void +empathy_account_settings_created_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data); + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + EmpathyAccount *account; + GError *error = NULL; + GSimpleAsyncResult *r; + + account = empathy_account_manager_create_account_finish ( + EMPATHY_ACCOUNT_MANAGER (source), result, &error); + + if (account == NULL) + { + g_simple_async_result_set_from_error (priv->apply_result, error); + } + else + { + priv->account = g_object_ref (account); + } + + r = priv->apply_result; + priv->apply_result = NULL; + + g_simple_async_result_complete (r); + g_object_unref (r); +} + + +static void +empathy_account_settings_do_create_account (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + GHashTable *properties; + + properties = g_hash_table_new (NULL, NULL); + + empathy_account_manager_create_account_async (priv->account_manager, + priv->cm_name, priv->protocol, priv->display_name, + priv->parameters, properties, + empathy_account_settings_created_cb, + settings); + + g_hash_table_unref (properties); +} + +static void +empathy_account_settings_manager_ready_cb (EmpathyAccountManager *manager, + GParamSpec *spec, gpointer user_data) +{ + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data); + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + if (empathy_account_manager_is_ready (manager)) + { + g_assert (priv->apply_result != NULL && priv->account == NULL); + g_signal_handler_disconnect (priv->account_manager, + priv->account_manager_ready_id); + priv->account_manager_ready_id = 0; + + empathy_account_settings_do_create_account (settings); + } +} + +void +empathy_account_settings_apply_async (EmpathyAccountSettings *settings, + GAsyncReadyCallback callback, + gpointer user_data) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + if (priv->apply_result != NULL) + { + g_simple_async_report_error_in_idle (G_OBJECT (settings), + callback, user_data, + G_IO_ERROR, G_IO_ERROR_PENDING, "Applying already in progress"); + return; + } + + priv->apply_result = g_simple_async_result_new (G_OBJECT (settings), + callback, user_data, empathy_account_settings_apply_finish); + + if (priv->account == NULL) + { + if (empathy_account_manager_is_ready (priv->account_manager)) + empathy_account_settings_do_create_account (settings); + else + priv->account_manager_ready_id = g_signal_connect ( + priv->account_manager, + "notify::ready", + G_CALLBACK (empathy_account_settings_manager_ready_cb), + settings); + } + else + { + empathy_account_update_settings_async (priv->account, + priv->parameters, (const gchar **)priv->unset_parameters->data, + empathy_account_settings_account_updated, settings); + + g_hash_table_remove_all (priv->parameters); + empathy_account_settings_free_unset_parameters (settings); + } +} + +gboolean +empathy_account_settings_apply_finish (EmpathyAccountSettings *settings, + GAsyncResult *result, + GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (settings), empathy_account_settings_apply_finish), FALSE); + + return TRUE; +} diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h new file mode 100644 index 000000000..c0f21a31c --- /dev/null +++ b/libempathy/empathy-account-settings.h @@ -0,0 +1,156 @@ +/* + * empathy-account-settings.h - Header for EmpathyAccountSettings + * Copyright (C) 2009 Collabora Ltd. + * @author Sjoerd Simons + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __EMPATHY_ACCOUNT_SETTINGS_H__ +#define __EMPATHY_ACCOUNT_SETTINGS_H__ + +#include +#include + +#include +#include + +G_BEGIN_DECLS + +typedef struct _EmpathyAccountSettings EmpathyAccountSettings; +typedef struct _EmpathyAccountSettingsClass EmpathyAccountSettingsClass; + +struct _EmpathyAccountSettingsClass { + GObjectClass parent_class; +}; + +struct _EmpathyAccountSettings { + GObject parent; + gpointer priv; +}; + +GType empathy_account_settings_get_type(void); + +/* TYPE MACROS */ +#define EMPATHY_TYPE_ACCOUNT_SETTINGS \ + (empathy_account_settings_get_type()) +#define EMPATHY_ACCOUNT_SETTINGS(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + EMPATHY_TYPE_ACCOUNT_SETTINGS, EmpathyAccountSettings)) +#define EMPATHY_ACCOUNT_SETTINGS_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), EMPATHY_TYPE_ACCOUNT_SETTINGS, \ + EmpathyAccountSettingsClass)) +#define EMPATHY_IS_ACCOUNT_SETTINGS(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), EMPATHY_TYPE_ACCOUNT_SETTINGS)) +#define EMPATHY_IS_ACCOUNT_SETTINGS_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), EMPATHY_TYPE_ACCOUNT_SETTINGS)) +#define EMPATHY_ACCOUNT_SETTINGS_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_SETTINGS, \ + EmpathyAccountSettingsClass)) + +EmpathyAccountSettings * empathy_account_settings_new ( + const gchar *connection_manager, + const gchar *protocol, + const char *display_name); + +EmpathyAccountSettings * empathy_account_settings_new_for_account ( + EmpathyAccount *account); + +gboolean empathy_account_settings_is_ready (EmpathyAccountSettings *settings); + +const gchar *empathy_account_settings_get_cm (EmpathyAccountSettings *settings); +const gchar *empathy_account_settings_get_protocol ( + EmpathyAccountSettings *settings); + +EmpathyAccount *empathy_account_settings_get_account ( + EmpathyAccountSettings *settings); + +TpConnectionManagerParam *empathy_account_settings_get_tp_params ( + EmpathyAccountSettings *settings); + +void empathy_account_settings_unset (EmpathyAccountSettings *settings, + const gchar *param); + +const GValue *empathy_account_settings_get (EmpathyAccountSettings *settings, + const gchar *param); + +const gchar * +empathy_settings_get_dbus_signature (EmpathyAccountSettings *setting, + const gchar *param); + +const GValue * +empathy_account_settings_get_default (EmpathyAccountSettings *settings, + const gchar *param); + +const gchar *empathy_account_settings_get_string ( + EmpathyAccountSettings *settings, + const gchar *param); + +gint32 empathy_account_settings_get_int32 (EmpathyAccountSettings *settings, + const gchar *param); +gint64 empathy_account_settings_get_int64 (EmpathyAccountSettings *settings, + const gchar *param); +guint32 empathy_account_settings_get_uint32 (EmpathyAccountSettings *settings, + const gchar *param); +guint64 empathy_account_settings_get_uint64 (EmpathyAccountSettings *settings, + const gchar *param); +gboolean empathy_account_settings_get_boolean (EmpathyAccountSettings *settings, + const gchar *param); + +void empathy_account_settings_set_string (EmpathyAccountSettings *settings, + const gchar *param, const gchar *value); + +void empathy_account_settings_set_int32 (EmpathyAccountSettings *settings, + const gchar *param, gint32 value); +void empathy_account_settings_set_int64 (EmpathyAccountSettings *settings, + const gchar *param, gint64 value); +void empathy_account_settings_set_uint32 (EmpathyAccountSettings *settings, + const gchar *param, guint32 value); +void empathy_account_settings_set_uint64 (EmpathyAccountSettings *settings, + const gchar *param, guint64 value); + +void empathy_account_settings_set_boolean (EmpathyAccountSettings *settings, + const gchar *param, gboolean value); + +const gchar *empathy_account_settings_get_icon_name ( + EmpathyAccountSettings *settings); + +const gchar *empathy_account_settings_get_display_name ( + EmpathyAccountSettings *settings); + +void empathy_account_settings_set_display_name_async ( + EmpathyAccountSettings *settings, + const gchar *name, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean empathy_account_settings_set_display_name_finish ( + EmpathyAccountSettings *settings, + GAsyncResult *result, + GError **error); + +void empathy_account_settings_apply_async (EmpathyAccountSettings *settings, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean empathy_account_settings_apply_finish ( + EmpathyAccountSettings *settings, + GAsyncResult *result, + GError **error); + + +G_END_DECLS + +#endif /* #ifndef __EMPATHY_ACCOUNT_SETTINGS_H__*/ -- cgit v1.2.3 From b81f5d599018df2378b489f080b5a2a64a8f9c9a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:48:58 +0100 Subject: Remove the API to change the account parameters one by one --- libempathy/empathy-account.c | 67 ++++++-------------------------------------- libempathy/empathy-account.h | 17 ++--------- 2 files changed, 10 insertions(+), 74 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index ef377427d..91edaed66 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -653,79 +653,28 @@ empathy_account_get_icon_name (EmpathyAccount *account) return priv->icon_name; } -gboolean -empathy_account_is_enabled (EmpathyAccount *account) +const GHashTable * +empathy_account_get_parameters (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return priv->enabled; -} - -void -empathy_account_unset_param (EmpathyAccount *account, const gchar *param) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - - //mc_account_unset_param (priv->mc_account, param); + return priv->parameters; } -const gchar * -empathy_account_get_param_string (EmpathyAccount *account, const gchar *param) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - - return tp_asv_get_string (priv->parameters, param); -} - -gint -empathy_account_get_param_int (EmpathyAccount *account, const gchar *param) +gboolean +empathy_account_is_enabled (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return tp_asv_get_int32 (priv->parameters, param, NULL); + return priv->enabled; } gboolean -empathy_account_get_param_boolean (EmpathyAccount *account, const gchar *param) +empathy_account_is_ready (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return tp_asv_get_boolean (priv->parameters, param, NULL); -} - -void -empathy_account_set_param_string (EmpathyAccount *account, - const gchar *param, - const gchar *value) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - //mc_account_set_param_string (priv->mc_account, param, value); -} - -void -empathy_account_set_param_int (EmpathyAccount *account, - const gchar *param, - gint value) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - //mc_account_set_param_int (priv->mc_account, param, value); -} - -void -empathy_account_set_param_boolean (EmpathyAccount *account, - const gchar *param, - gboolean value) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - //mc_account_set_param_boolean (priv->mc_account, param, value); -} - -void -empathy_account_set_display_name (EmpathyAccount *account, - const gchar *display_name) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - //mc_account_set_display_name (priv->mc_account, display_name); + return priv->ready; } diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 252c959d2..efc8df713 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -68,21 +68,6 @@ void empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled); gboolean empathy_account_is_enabled (EmpathyAccount *account); -void empathy_account_unset_param (EmpathyAccount *account, const gchar *param); -const gchar *empathy_account_get_param_string (EmpathyAccount *account, - const gchar *param); -gint empathy_account_get_param_int (EmpathyAccount *account, - const gchar *param); -gboolean empathy_account_get_param_boolean (EmpathyAccount *account, - const gchar *param); - -void empathy_account_set_param_string (EmpathyAccount *account, - const gchar *param, const gchar *value); -void empathy_account_set_param_int (EmpathyAccount *account, - const gchar *param, gint value); -void empathy_account_set_param_boolean (EmpathyAccount *account, - const gchar *param, gboolean value); - gboolean empathy_account_is_valid (EmpathyAccount *account); gboolean empathy_account_is_ready (EmpathyAccount *account); @@ -95,6 +80,8 @@ EmpathyAccount *empathy_account_new (TpDBusDaemon *bus_daemon, void empathy_account_request_presence (EmpathyAccount *account, TpConnectionPresenceType type, const gchar *status, const gchar *message); +const GHashTable *empathy_account_get_parameters (EmpathyAccount *account); + G_END_DECLS -- cgit v1.2.3 From 10b85cf1e8161c7f3392f50dc329c89f3bb87512 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:50:43 +0100 Subject: Add API to Update an accounts parameters --- libempathy/empathy-account.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ libempathy/empathy-account.h | 8 +++++++ 2 files changed, 59 insertions(+) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 91edaed66..5ad3ef464 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -830,3 +830,54 @@ empathy_account_request_presence (EmpathyAccount *account, g_value_unset (&value); } + +static void +empathy_account_updated_cb (TpAccount *proxy, + const gchar **reconnect_required, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + + if (error != NULL) + { + g_simple_async_result_set_from_error (result, (GError *)error); + } + + g_simple_async_result_complete (result); + g_object_unref (G_OBJECT (result)); +} + +void +empathy_account_update_settings_async (EmpathyAccount *account, + const GHashTable *parameters, const gchar **unset_parameters, + GAsyncReadyCallback callback, gpointer user_data) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account), + callback, user_data, empathy_account_update_settings_finish); + + tp_cli_account_call_update_parameters (priv->account, + -1, + (GHashTable *)parameters, + unset_parameters, + empathy_account_updated_cb, + result, + NULL, + G_OBJECT (account)); +} + +gboolean +empathy_account_update_settings_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (account), empathy_account_update_settings_finish), FALSE); + + return TRUE; +} diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index efc8df713..f498e11e3 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -22,6 +22,7 @@ #define __EMPATHY_ACCOUNT_H__ #include +#include #include @@ -71,6 +72,13 @@ gboolean empathy_account_is_enabled (EmpathyAccount *account); gboolean empathy_account_is_valid (EmpathyAccount *account); gboolean empathy_account_is_ready (EmpathyAccount *account); +void empathy_account_update_settings_async (EmpathyAccount *account, + const GHashTable *parameters, const gchar **unset_parameters, + GAsyncReadyCallback callback, gpointer user_data); + +gboolean empathy_account_update_settings_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error); + void empathy_account_set_display_name (EmpathyAccount *account, const gchar *display_name); -- cgit v1.2.3 From aeb06b95274c6c22501c752b9fb8864af6f1bc29 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:54:05 +0100 Subject: Make empathy_account_set_enable call out over d-bus --- libempathy/empathy-account.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5ad3ef464..21ece6f0d 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -233,8 +233,14 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) g_strdup (tp_asv_get_string (properties, "DisplayName")); if (g_hash_table_lookup (properties, "Enabled") != NULL) - empathy_account_set_enabled (account, - tp_asv_get_boolean (properties, "Enabled", NULL)); + { + gboolean enabled = tp_asv_get_boolean (properties, "Enabled", NULL); + if (priv->enabled != enabled) + { + priv->enabled = enabled; + g_object_notify (G_OBJECT (account), "enabled"); + } + } if (g_hash_table_lookup (properties, "Valid") != NULL) priv->valid = tp_asv_get_boolean (properties, "Valid", NULL); @@ -327,6 +333,9 @@ empathy_account_got_all_cb (TpProxy *proxy, { EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + DEBUG ("Got initial set of properties for %s", + empathy_account_get_unique_name (account)); + if (error != NULL) { printf ("Unhappy\n"); @@ -780,12 +789,25 @@ empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) { EmpathyAccountPriv *priv = GET_PRIV (account); + GValue value = {0, }; if (priv->enabled == enabled) return; - priv->enabled = enabled; - g_object_notify (G_OBJECT (account), "enabled"); + g_value_init (&value, G_TYPE_BOOLEAN); + g_value_set_boolean (&value, enabled); + + tp_cli_dbus_properties_call_set (TP_PROXY (priv->account), + -1, + TP_IFACE_ACCOUNT, + "Enabled", + &value, + NULL, + NULL, + NULL, + NULL); + + g_value_unset (&value); } static void -- cgit v1.2.3 From 9c3db97dcf9bd237784d401ae3215326a1d77ae2 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:56:22 +0100 Subject: Port to using EmpathyAccountSettings --- libempathy-gtk/empathy-account-widget-irc.c | 61 +++-- libempathy-gtk/empathy-account-widget-irc.h | 4 +- libempathy-gtk/empathy-account-widget-sip.c | 22 +- libempathy-gtk/empathy-account-widget-sip.h | 4 +- libempathy-gtk/empathy-account-widget.c | 264 +++++++++++--------- libempathy-gtk/empathy-account-widget.h | 25 +- src/empathy-accounts-dialog.c | 363 +++++++++++++++++++--------- 7 files changed, 475 insertions(+), 268 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c index b2383a02a..ae41f1e39 100644 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ b/libempathy-gtk/empathy-account-widget-irc.c @@ -41,7 +41,7 @@ #define IRC_NETWORKS_FILENAME "irc-networks.xml" typedef struct { - EmpathyAccount *account; + EmpathyAccountSettings *settings; EmpathyIrcNetworkManager *network_manager; GtkWidget *vbox_settings; @@ -59,7 +59,7 @@ account_widget_irc_destroy_cb (GtkWidget *widget, EmpathyAccountWidgetIrc *settings) { g_object_unref (settings->network_manager); - g_object_unref (settings->account); + g_object_unref (settings->settings); g_slice_free (EmpathyAccountWidgetIrc, settings); } @@ -67,9 +67,9 @@ static void unset_server_params (EmpathyAccountWidgetIrc *settings) { DEBUG ("Unset server, port and use-ssl"); - empathy_account_unset_param (settings->account, "server"); - empathy_account_unset_param (settings->account, "port"); - empathy_account_unset_param (settings->account, "use-ssl"); + empathy_account_settings_unset (settings->settings, "server"); + empathy_account_settings_unset (settings->settings, "port"); + empathy_account_settings_unset (settings->settings, "use-ssl"); } static void @@ -95,7 +95,7 @@ update_server_params (EmpathyAccountWidgetIrc *settings) g_object_get (network, "charset", &charset, NULL); DEBUG ("Setting charset to %s", charset); - empathy_account_set_param_string (settings->account, "charset", charset); + empathy_account_settings_set_string (settings->settings, "charset", charset); g_free (charset); servers = empathy_irc_network_get_servers (network); @@ -114,11 +114,13 @@ update_server_params (EmpathyAccountWidgetIrc *settings) NULL); DEBUG ("Setting server to %s", address); - empathy_account_set_param_string (settings->account, "server", address); + empathy_account_settings_set_string (settings->settings, + "server", address); DEBUG ("Setting port to %u", port); - empathy_account_set_param_int (settings->account, "port", port); + empathy_account_settings_set_uint32 (settings->settings, "port", port); DEBUG ("Setting use-ssl to %s", ssl ? "TRUE": "FALSE" ); - empathy_account_set_param_boolean (settings->account, "use-ssl", ssl); + empathy_account_settings_set_boolean (settings->settings, + "use-ssl", ssl); g_free (address); } @@ -329,17 +331,19 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) gboolean ssl = FALSE; EmpathyIrcNetwork *network = NULL; - nick = empathy_account_get_param_string (settings->account, "account"); - fullname = empathy_account_get_param_string (settings->account, "fullname"); - server = empathy_account_get_param_string (settings->account, "server"); - charset = empathy_account_get_param_string (settings->account, "charset"); - port = empathy_account_get_param_int (settings->account, "port"); - ssl = empathy_account_get_param_boolean (settings->account, "use-ssl"); + nick = empathy_account_settings_get_string (settings->settings, "account"); + fullname = empathy_account_settings_get_string (settings->settings, + "fullname"); + server = empathy_account_settings_get_string (settings->settings, "server"); + charset = empathy_account_settings_get_string (settings->settings, "charset"); + port = empathy_account_settings_get_uint32 (settings->settings, "port"); + ssl = empathy_account_settings_get_boolean (settings->settings, "use-ssl"); if (!nick) { nick = g_strdup (g_get_user_name ()); - empathy_account_set_param_string (settings->account, "account", nick); + empathy_account_settings_set_string (settings->settings, + "account", nick); } if (!fullname) @@ -349,7 +353,8 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) { fullname = g_strdup (nick); } - empathy_account_set_param_string (settings->account, "fullname", fullname); + empathy_account_settings_set_string (settings->settings, + "fullname", fullname); } if (server != NULL) @@ -406,14 +411,14 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) /** * empathy_account_widget_irc_new: - * @account: the #EmpathyAccount to configure + * @settings: the #EmpathyAccountSettings to configure * * Creates a new IRC account widget to configure a given #EmpathyAccount * * Returns: The toplevel container of the configuration widget */ GtkWidget * -empathy_account_widget_irc_new (EmpathyAccount *account) +empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) { EmpathyAccountWidgetIrc *settings; gchar *dir, *user_file_with_path, *global_file_with_path; @@ -423,7 +428,7 @@ empathy_account_widget_irc_new (EmpathyAccount *account) gchar *filename; settings = g_slice_new0 (EmpathyAccountWidgetIrc); - settings->account = g_object_ref (account); + settings->settings = g_object_ref (settings); dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); @@ -476,7 +481,7 @@ empathy_account_widget_irc_new (EmpathyAccount *account) account_widget_irc_setup (settings); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (account_settings, gui, "entry_nick", "account", "entry_fullname", "fullname", "entry_password", "password", @@ -485,13 +490,19 @@ empathy_account_widget_irc_new (EmpathyAccount *account) empathy_builder_connect (gui, settings, "vbox_irc_settings", "destroy", account_widget_irc_destroy_cb, - "button_network", "clicked", account_widget_irc_button_edit_network_clicked_cb, - "button_add_network", "clicked", account_widget_irc_button_add_network_clicked_cb, - "button_remove_network", "clicked", account_widget_irc_button_remove_clicked_cb, - "combobox_network", "changed", account_widget_irc_combobox_network_changed_cb, + "button_network", "clicked", + account_widget_irc_button_edit_network_clicked_cb, + "button_add_network", "clicked", + account_widget_irc_button_add_network_clicked_cb, + "button_remove_network", "clicked", + account_widget_irc_button_remove_clicked_cb, + "combobox_network", "changed", + account_widget_irc_combobox_network_changed_cb, NULL); empathy_account_widget_set_default_focus (gui, "entry_nick"); + empathy_account_widget_add_apply_button (account_settings, + settings->vbox_settings); return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings); } diff --git a/libempathy-gtk/empathy-account-widget-irc.h b/libempathy-gtk/empathy-account-widget-irc.h index 40e58bbc3..0373238ed 100644 --- a/libempathy-gtk/empathy-account-widget-irc.h +++ b/libempathy-gtk/empathy-account-widget-irc.h @@ -22,11 +22,11 @@ #define __EMPATHY_ACCOUNT_WIDGET_IRC_H__ #include -#include +#include G_BEGIN_DECLS -GtkWidget * empathy_account_widget_irc_new (EmpathyAccount *account); +GtkWidget * empathy_account_widget_irc_new (EmpathyAccountSettings *settings); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget-sip.c b/libempathy-gtk/empathy-account-widget-sip.c index ad8cd7d8e..9f08046b7 100644 --- a/libempathy-gtk/empathy-account-widget-sip.c +++ b/libempathy-gtk/empathy-account-widget-sip.c @@ -35,7 +35,7 @@ #include "empathy-ui-utils.h" typedef struct { - EmpathyAccount *account; + EmpathyAccountSettings *settings; GtkWidget *vbox_settings; @@ -48,7 +48,7 @@ static void account_widget_sip_destroy_cb (GtkWidget *widget, EmpathyAccountWidgetSip *settings) { - g_object_unref (settings->account); + g_object_unref (settings->settings); g_slice_free (EmpathyAccountWidgetSip, settings); } @@ -73,14 +73,14 @@ account_widget_sip_discover_stun_toggled_cb ( * Returns: The toplevel container of the configuration widget */ GtkWidget * -empathy_account_widget_sip_new (EmpathyAccount *account) +empathy_account_widget_sip_new (EmpathyAccountSettings *account_settings) { EmpathyAccountWidgetSip *settings; GtkBuilder *gui; gchar *filename; settings = g_slice_new0 (EmpathyAccountWidgetSip); - settings->account = g_object_ref (account); + settings->settings = g_object_ref (account_settings); filename = empathy_file_lookup ("empathy-account-widget-sip.ui", "libempathy-gtk"); @@ -92,7 +92,7 @@ empathy_account_widget_sip_new (EmpathyAccount *account) NULL); g_free (filename); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (account_settings, gui, "entry_userid", "account", "entry_password", "password", "checkbutton_discover-stun", "discover-stun", @@ -100,19 +100,23 @@ empathy_account_widget_sip_new (EmpathyAccount *account) "spinbutton_stun-port", "stun-port", NULL); - empathy_account_widget_add_forget_button (account, gui, + empathy_account_widget_add_forget_button (account_settings, gui, "button_forget", "entry_password"); - account_widget_sip_discover_stun_toggled_cb (settings->checkbutton_discover_stun, - settings); + account_widget_sip_discover_stun_toggled_cb ( + settings->checkbutton_discover_stun, + settings); empathy_builder_connect (gui, settings, "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb, - "checkbutton_discover-stun", "toggled", account_widget_sip_discover_stun_toggled_cb, + "checkbutton_discover-stun", "toggled", + account_widget_sip_discover_stun_toggled_cb, NULL); empathy_account_widget_set_default_focus (gui, "entry_userid"); + empathy_account_widget_add_apply_button (account_settings, + settings->vbox_settings); return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings); } diff --git a/libempathy-gtk/empathy-account-widget-sip.h b/libempathy-gtk/empathy-account-widget-sip.h index 69f60aacc..15dd7244a 100644 --- a/libempathy-gtk/empathy-account-widget-sip.h +++ b/libempathy-gtk/empathy-account-widget-sip.h @@ -22,11 +22,11 @@ #define __EMPATHY_ACCOUNT_WIDGET_SIP_H__ #include -#include +#include G_BEGIN_DECLS -GtkWidget * empathy_account_widget_sip_new (EmpathyAccount *account); +GtkWidget * empathy_account_widget_sip_new (EmpathyAccountSettings *settings); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 783a48a0a..ea0a05b35 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -33,6 +33,7 @@ #include #include +#include #include "empathy-account-widget.h" #include "empathy-ui-utils.h" @@ -43,7 +44,7 @@ static gboolean account_widget_entry_focus_cb (GtkWidget *widget, GdkEventFocus *event, - EmpathyAccount *account) + EmpathyAccountSettings *settings) { const gchar *str; const gchar *param_name; @@ -54,14 +55,14 @@ account_widget_entry_focus_cb (GtkWidget *widget, if (EMP_STR_EMPTY (str)) { const gchar *value = NULL; - empathy_account_unset_param (account, param_name); - value = empathy_account_get_param_string (account, param_name); + empathy_account_settings_unset (settings, param_name); + value = empathy_account_settings_get_string (settings, param_name); DEBUG ("Unset %s and restore to %s", param_name, value); gtk_entry_set_text (GTK_ENTRY (widget), value ? value : ""); } else { DEBUG ("Setting %s to %s", param_name, strstr (param_name, "password") ? "***" : str); - empathy_account_set_param_string (account, param_name, str); + empathy_account_settings_set_string (settings, param_name, str); } return FALSE; @@ -69,28 +70,44 @@ account_widget_entry_focus_cb (GtkWidget *widget, static void account_widget_int_changed_cb (GtkWidget *widget, - EmpathyAccount *account) + EmpathyAccountSettings *settings) { const gchar *param_name; gint value; + const gchar *signature; value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - if (value == 0) { - empathy_account_unset_param (account, param_name); - value = empathy_account_get_param_int (account, param_name); - DEBUG ("Unset %s and restore to %d", param_name, value); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); - } else { - DEBUG ("Setting %s to %d", param_name, value); - empathy_account_set_param_int (account, param_name, value); - } + signature = empathy_settings_get_dbus_signature (settings, param_name); + g_return_if_fail (signature != NULL); + + DEBUG ("Setting %s to %d", param_name, value); + + switch ((int)*signature) + { + case DBUS_TYPE_INT16: + case DBUS_TYPE_INT32: + empathy_account_settings_set_int32 (settings, param_name, value); + break; + case DBUS_TYPE_INT64: + empathy_account_settings_set_int64 (settings, param_name, value); + break; + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + empathy_account_settings_set_uint32 (settings, param_name, value); + break; + case DBUS_TYPE_UINT64: + empathy_account_settings_set_uint64 (settings, param_name, value); + break; + default: + g_return_if_reached (); + } } static void account_widget_checkbutton_toggled_cb (GtkWidget *widget, - EmpathyAccount *account) + EmpathyAccountSettings *settings) { gboolean value; gboolean default_value; @@ -102,14 +119,14 @@ account_widget_checkbutton_toggled_cb (GtkWidget *widget, /* FIXME: This is ugly! checkbox don't have a "not-set" value so we * always unset the param and set the value if different from the * default value. */ - empathy_account_unset_param (account, param_name); - default_value = empathy_account_get_param_boolean (account, param_name); + empathy_account_settings_unset (settings, param_name); + default_value = empathy_account_settings_get_boolean (settings, param_name); if (default_value == value) { DEBUG ("Unset %s and restore to %d", param_name, default_value); } else { DEBUG ("Setting %s to %d", param_name, value); - empathy_account_set_param_boolean (account, param_name, value); + empathy_account_settings_set_boolean (settings, param_name, value); } } @@ -117,14 +134,14 @@ static void account_widget_forget_clicked_cb (GtkWidget *button, GtkWidget *entry) { - EmpathyAccount *account; + EmpathyAccountSettings *settings; const gchar *param_name; param_name = g_object_get_data (G_OBJECT (entry), "param_name"); - account = g_object_get_data (G_OBJECT (entry), "account"); + settings = g_object_get_data (G_OBJECT (entry), "settings"); DEBUG ("Unset %s", param_name); - empathy_account_unset_param (account, param_name); + empathy_account_settings_unset (settings, param_name); gtk_entry_set_text (GTK_ENTRY (entry), ""); } @@ -142,13 +159,13 @@ static void account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, GtkWidget *spinbutton_port) { - EmpathyAccount *account; + EmpathyAccountSettings *settings; gboolean value; - gint port = 0; + gint32 port = 0; value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl)); - account = g_object_get_data (G_OBJECT (spinbutton_port), "account"); - port = empathy_account_get_param_int (account, "port"); + settings = g_object_get_data (G_OBJECT (spinbutton_port), "settings"); + port = empathy_account_settings_get_uint32 (settings, "port"); if (value) { if (port == 5222 || port == 0) { @@ -165,28 +182,51 @@ account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, static void account_widget_setup_widget (GtkWidget *widget, - EmpathyAccount *account, + EmpathyAccountSettings *settings, const gchar *param_name) { g_object_set_data_full (G_OBJECT (widget), "param_name", g_strdup (param_name), g_free); - g_object_set_data_full (G_OBJECT (widget), "account", - g_object_ref (account), g_object_unref); + g_object_set_data_full (G_OBJECT (widget), "settings", + g_object_ref (settings), g_object_unref); if (GTK_IS_SPIN_BUTTON (widget)) { gint value = 0; + const gchar *signature; + + signature = empathy_settings_get_dbus_signature (settings, param_name); + g_return_if_fail (signature != NULL); + + switch ((int)*signature) + { + case DBUS_TYPE_INT16: + case DBUS_TYPE_INT32: + value = empathy_account_settings_get_int32 (settings, param_name); + break; + case DBUS_TYPE_INT64: + value = empathy_account_settings_get_int64 (settings, param_name); + break; + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + value = empathy_account_settings_get_uint32 (settings, param_name); + break; + case DBUS_TYPE_UINT64: + value = empathy_account_settings_get_uint64 (settings, param_name); + break; + default: + g_return_if_reached (); + } - value = empathy_account_get_param_int (account, param_name); gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); g_signal_connect (widget, "value-changed", G_CALLBACK (account_widget_int_changed_cb), - account); + settings); } else if (GTK_IS_ENTRY (widget)) { const gchar *str = NULL; - str = empathy_account_get_param_string (account, param_name); + str = empathy_account_settings_get_string (settings, param_name); gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); if (strstr (param_name, "password")) { @@ -195,17 +235,17 @@ account_widget_setup_widget (GtkWidget *widget, g_signal_connect (widget, "focus-out-event", G_CALLBACK (account_widget_entry_focus_cb), - account); + settings); } else if (GTK_IS_TOGGLE_BUTTON (widget)) { gboolean value = FALSE; - value = empathy_account_get_param_boolean (account, param_name); + value = empathy_account_settings_get_boolean (settings, param_name); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); g_signal_connect (widget, "toggled", G_CALLBACK (account_widget_checkbutton_toggled_cb), - account); + settings); } else { DEBUG ("Unknown type of widget for param %s", param_name); } @@ -236,14 +276,15 @@ account_widget_generic_format_param_name (const gchar *param_name) } static void -accounts_widget_generic_setup (EmpathyAccount *account, - TpConnectionManagerParam *params, +accounts_widget_generic_setup (EmpathyAccountSettings *settings, GtkWidget *table_common_settings, GtkWidget *table_advanced_settings) { - TpConnectionManagerParam *param; + TpConnectionManagerParam *params, *param; + + params = empathy_account_settings_get_tp_params (settings); - for (param = params; param != NULL; param++) { + for (param = params; param != NULL && param->name != NULL; param++) { GtkWidget *table_settings; guint n_rows = 0; GtkWidget *widget = NULL; @@ -350,7 +391,7 @@ accounts_widget_generic_setup (EmpathyAccount *account, } if (widget) { - account_widget_setup_widget (widget, account, param->name); + account_widget_setup_widget (widget, settings, param->name); } g_free (param_name_formatted); @@ -358,7 +399,7 @@ accounts_widget_generic_setup (EmpathyAccount *account, } static void -account_widget_handle_params_valist (EmpathyAccount *account, +account_widget_handle_params_valist (EmpathyAccountSettings *settings, GtkBuilder *gui, const gchar *first_widget, va_list args) @@ -377,12 +418,12 @@ account_widget_handle_params_valist (EmpathyAccount *account, continue; } - account_widget_setup_widget (GTK_WIDGET (object), account, param_name); + account_widget_setup_widget (GTK_WIDGET (object), settings, param_name); } } void -empathy_account_widget_handle_params (EmpathyAccount *account, +empathy_account_widget_handle_params (EmpathyAccountSettings *settings, GtkBuilder *gui, const gchar *first_widget, ...) @@ -392,12 +433,35 @@ empathy_account_widget_handle_params (EmpathyAccount *account, g_return_if_fail (GTK_IS_BUILDER (gui)); va_start (args, first_widget); - account_widget_handle_params_valist (account, gui, first_widget, args); + account_widget_handle_params_valist (settings, gui, first_widget, args); va_end (args); } +static void +account_widget_apply_clicked_cb (GtkWidget *button, + EmpathyAccountSettings *settings) +{ + empathy_account_settings_apply_async (settings, NULL, NULL); +} + +void +empathy_account_widget_add_apply_button (EmpathyAccountSettings *settings, + GtkWidget *vbox) +{ + GtkWidget *button; + + button = gtk_button_new_from_stock (GTK_STOCK_APPLY); + + gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 3); + + g_signal_connect (button, "clicked", + G_CALLBACK (account_widget_apply_clicked_cb), + settings); + gtk_widget_show (button); +} + void -empathy_account_widget_add_forget_button (EmpathyAccount *account, +empathy_account_widget_add_forget_button (EmpathyAccountSettings *settings, GtkBuilder *gui, const gchar *button, const gchar *entry) @@ -409,7 +473,7 @@ empathy_account_widget_add_forget_button (EmpathyAccount *account, button_forget = GTK_WIDGET (gtk_builder_get_object (gui, button)); entry_password = GTK_WIDGET (gtk_builder_get_object (gui, entry)); - password = empathy_account_get_param_string (account, "password"); + password = empathy_account_settings_get_string (settings, "password"); gtk_widget_set_sensitive (button_forget, !EMP_STR_EMPTY (password)); g_signal_connect (button_forget, "clicked", @@ -433,37 +497,33 @@ empathy_account_widget_set_default_focus (GtkBuilder *gui, } static void -account_widget_tp_cm_ready_cb (TpConnectionManager *cm, const GError *error, - gpointer user_data, GObject *weak_object) +account_widget_setup_generic (EmpathyAccountSettings *settings, + GtkBuilder *builder) { - 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 (settings, table_common_settings, + table_advanced_settings); +} - accounts_widget_generic_setup (account, protocol->params, - table_common_settings, table_advanced_settings); +static void +account_widget_settings_ready_cb (EmpathyAccountSettings *settings, + GParamSpec *pspec, gpointer user_data) +{ + GtkBuilder *builder = GTK_BUILDER (user_data); + + if (empathy_account_settings_is_ready (settings)) + account_widget_setup_generic (settings, builder); } GtkWidget * -empathy_account_widget_generic_new (EmpathyAccount *account) +empathy_account_widget_generic_new (EmpathyAccountSettings *settings) { GtkBuilder *gui; GtkWidget *widget; @@ -475,38 +535,19 @@ empathy_account_widget_generic_new (EmpathyAccount *account) "vbox_generic_settings", &widget, NULL); - /* 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; - - dbus = tp_dbus_daemon_dup (NULL); + if (empathy_account_settings_is_ready (settings)) + account_widget_setup_generic (settings, gui); + else + g_signal_connect (settings, "notify::ready", + G_CALLBACK (account_widget_settings_ready_cb), gui); - 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); - } + empathy_account_widget_add_apply_button (settings, widget); return g_object_ref (widget); } GtkWidget * -empathy_account_widget_salut_new (EmpathyAccount *account) +empathy_account_widget_salut_new (EmpathyAccountSettings *settings) { GtkBuilder *gui; GtkWidget *widget; @@ -519,7 +560,7 @@ empathy_account_widget_salut_new (EmpathyAccount *account) NULL); g_free (filename); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (settings, gui, "entry_published", "published-name", "entry_nickname", "nickname", "entry_first_name", "first-name", @@ -534,7 +575,7 @@ empathy_account_widget_salut_new (EmpathyAccount *account) } GtkWidget * -empathy_account_widget_msn_new (EmpathyAccount *account) +empathy_account_widget_msn_new (EmpathyAccountSettings *settings) { GtkBuilder *gui; GtkWidget *widget; @@ -547,14 +588,14 @@ empathy_account_widget_msn_new (EmpathyAccount *account) NULL); g_free (filename); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (settings, gui, "entry_id", "account", "entry_password", "password", "entry_server", "server", "spinbutton_port", "port", NULL); - empathy_account_widget_add_forget_button (account, gui, + empathy_account_widget_add_forget_button (settings, gui, "button_forget", "entry_password"); @@ -564,7 +605,7 @@ empathy_account_widget_msn_new (EmpathyAccount *account) } GtkWidget * -empathy_account_widget_jabber_new (EmpathyAccount *account) +empathy_account_widget_jabber_new (EmpathyAccountSettings *settings) { GtkBuilder *gui; GtkWidget *widget; @@ -581,7 +622,7 @@ empathy_account_widget_jabber_new (EmpathyAccount *account) NULL); g_free (filename); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (settings, gui, "entry_id", "account", "entry_password", "password", "entry_resource", "resource", @@ -593,7 +634,7 @@ empathy_account_widget_jabber_new (EmpathyAccount *account) "checkbutton_encryption", "require-encryption", NULL); - empathy_account_widget_add_forget_button (account, gui, + empathy_account_widget_add_forget_button (settings, gui, "button_forget", "entry_password"); @@ -603,11 +644,13 @@ empathy_account_widget_jabber_new (EmpathyAccount *account) G_CALLBACK (account_widget_jabber_ssl_toggled_cb), spinbutton_port); + empathy_account_widget_add_apply_button (settings, widget); + return empathy_builder_unref_and_keep_widget (gui, widget); } GtkWidget * -empathy_account_widget_icq_new (EmpathyAccount *account) +empathy_account_widget_icq_new (EmpathyAccountSettings *settings) { GtkBuilder *gui; GtkWidget *widget; @@ -622,7 +665,7 @@ empathy_account_widget_icq_new (EmpathyAccount *account) NULL); g_free (filename); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (settings, gui, "entry_uin", "account", "entry_password", "password", "entry_server", "server", @@ -630,17 +673,19 @@ empathy_account_widget_icq_new (EmpathyAccount *account) "entry_charset", "charset", NULL); - empathy_account_widget_add_forget_button (account, gui, + empathy_account_widget_add_forget_button (settings, gui, "button_forget", "entry_password"); empathy_account_widget_set_default_focus (gui, "entry_uin"); + empathy_account_widget_add_apply_button (settings, widget); + return empathy_builder_unref_and_keep_widget (gui, widget); } GtkWidget * -empathy_account_widget_aim_new (EmpathyAccount *account) +empathy_account_widget_aim_new (EmpathyAccountSettings *settings) { GtkBuilder *gui; GtkWidget *widget; @@ -655,24 +700,25 @@ empathy_account_widget_aim_new (EmpathyAccount *account) NULL); g_free (filename); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (settings, gui, "entry_screenname", "account", "entry_password", "password", "entry_server", "server", "spinbutton_port", "port", NULL); - empathy_account_widget_add_forget_button (account, gui, + empathy_account_widget_add_forget_button (settings, gui, "button_forget", "entry_password"); empathy_account_widget_set_default_focus (gui, "entry_screenname"); + empathy_account_widget_add_apply_button (settings, widget); return empathy_builder_unref_and_keep_widget (gui, widget); } GtkWidget * -empathy_account_widget_yahoo_new (EmpathyAccount *account) +empathy_account_widget_yahoo_new (EmpathyAccountSettings *settings) { GtkBuilder *gui; GtkWidget *widget; @@ -685,7 +731,7 @@ empathy_account_widget_yahoo_new (EmpathyAccount *account) NULL); g_free (filename); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (settings, gui, "entry_id", "account", "entry_password", "password", "entry_server", "server", @@ -696,17 +742,18 @@ empathy_account_widget_yahoo_new (EmpathyAccount *account) "checkbutton_ignore_invites", "ignore-invites", NULL); - empathy_account_widget_add_forget_button (account, gui, + empathy_account_widget_add_forget_button (settings, gui, "button_forget", "entry_password"); empathy_account_widget_set_default_focus (gui, "entry_id"); + empathy_account_widget_add_apply_button (settings, widget); return empathy_builder_unref_and_keep_widget (gui, widget); } GtkWidget * -empathy_account_widget_groupwise_new (EmpathyAccount *account) +empathy_account_widget_groupwise_new (EmpathyAccountSettings *settings) { GtkBuilder *gui; GtkWidget *widget; @@ -719,18 +766,19 @@ empathy_account_widget_groupwise_new (EmpathyAccount *account) NULL); g_free (filename); - empathy_account_widget_handle_params (account, gui, + empathy_account_widget_handle_params (settings, gui, "entry_id", "account", "entry_password", "password", "entry_server", "server", "spinbutton_port", "port", NULL); - empathy_account_widget_add_forget_button (account, gui, + empathy_account_widget_add_forget_button (settings, gui, "button_forget", "entry_password"); empathy_account_widget_set_default_focus (gui, "entry_id"); + empathy_account_widget_add_apply_button (settings, widget); return empathy_builder_unref_and_keep_widget (gui, widget); } diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h index 7a76db9e0..f05c66012 100644 --- a/libempathy-gtk/empathy-account-widget.h +++ b/libempathy-gtk/empathy-account-widget.h @@ -27,28 +27,31 @@ #include -#include +#include G_BEGIN_DECLS -void empathy_account_widget_handle_params (EmpathyAccount *account, +void empathy_account_widget_handle_params (EmpathyAccountSettings *settings, GtkBuilder *gui, const gchar *first_widget, ...); -void empathy_account_widget_add_forget_button (EmpathyAccount *account, +void empathy_account_widget_add_forget_button (EmpathyAccountSettings *settings, GtkBuilder *gui, const gchar *button, const gchar *entry); +void empathy_account_widget_add_apply_button (EmpathyAccountSettings *settings, + GtkWidget *vbox); + void empathy_account_widget_set_default_focus (GtkBuilder *gui, const gchar *entry); -GtkWidget *empathy_account_widget_generic_new (EmpathyAccount *account); -GtkWidget *empathy_account_widget_salut_new (EmpathyAccount *account); -GtkWidget *empathy_account_widget_msn_new (EmpathyAccount *account); -GtkWidget *empathy_account_widget_jabber_new (EmpathyAccount *account); -GtkWidget *empathy_account_widget_icq_new (EmpathyAccount *account); -GtkWidget *empathy_account_widget_aim_new (EmpathyAccount *account); -GtkWidget *empathy_account_widget_yahoo_new (EmpathyAccount *account); -GtkWidget *empathy_account_widget_groupwise_new (EmpathyAccount *account); +GtkWidget *empathy_account_widget_generic_new (EmpathyAccountSettings *settings); +GtkWidget *empathy_account_widget_salut_new (EmpathyAccountSettings *settings); +GtkWidget *empathy_account_widget_msn_new (EmpathyAccountSettings *settings); +GtkWidget *empathy_account_widget_jabber_new (EmpathyAccountSettings *settings); +GtkWidget *empathy_account_widget_icq_new (EmpathyAccountSettings *settings); +GtkWidget *empathy_account_widget_aim_new (EmpathyAccountSettings *settings); +GtkWidget *empathy_account_widget_yahoo_new (EmpathyAccountSettings *settings); +GtkWidget *empathy_account_widget_groupwise_new (EmpathyAccountSettings *settings); G_END_DECLS diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 080a6cae3..d6a29ea63 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -84,6 +84,9 @@ typedef struct { gboolean connecting_show; guint connecting_id; + gulong settings_ready_id; + EmpathyAccountSettings *settings_ready; + EmpathyAccountManager *account_manager; } EmpathyAccountsDialog; @@ -92,11 +95,12 @@ enum { COL_NAME, COL_STATUS, COL_ACCOUNT_POINTER, + COL_ACCOUNT_SETTINGS_POINTER, COL_COUNT }; -static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account); +static void accounts_dialog_update (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings); static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog); static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog); static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer, @@ -109,14 +113,11 @@ static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn GtkTreeModel *model, GtkTreeIter *iter, EmpathyAccountsDialog *dialog); -static EmpathyAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog); static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog, - EmpathyAccount *account); + EmpathyAccountSettings *settings); static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog); static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection, EmpathyAccountsDialog *dialog); -static void accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account); static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager, EmpathyAccount *account, EmpathyAccountsDialog *dialog); @@ -157,24 +158,24 @@ static void accounts_dialog_destroy_cb (GtkWidget static void accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, - EmpathyAccount *account) + EmpathyAccountSettings *settings) { gchar *text; text = g_markup_printf_escaped ("%s", - empathy_account_get_display_name (account)); + empathy_account_settings_get_display_name (settings)); gtk_label_set_markup (GTK_LABEL (dialog->label_name), text); g_free (text); } -typedef GtkWidget *CreateWidget (EmpathyAccount *); +typedef GtkWidget *CreateWidget (EmpathyAccountSettings *); static GtkWidget * -get_account_setup_widget (EmpathyAccount *account) +get_account_setup_widget (EmpathyAccountSettings *settings) { - const gchar *cm = empathy_account_get_connection_manager (account); - const gchar *proto = empathy_account_get_protocol (account); + const gchar *cm = empathy_account_settings_get_cm (settings); + const gchar *proto = empathy_account_settings_get_protocol (settings); struct { const gchar *cm; const gchar *proto; @@ -196,18 +197,53 @@ get_account_setup_widget (EmpathyAccount *account) 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 dialogs[i].cb (settings); } - return empathy_account_widget_generic_new (account); + return empathy_account_widget_generic_new (settings); } static void -accounts_dialog_update_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account) +account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings) +{ + dialog->settings_widget = get_account_setup_widget (settings); + + gtk_container_add (GTK_CONTAINER (dialog->alignment_settings), + dialog->settings_widget); + gtk_widget_show (dialog->settings_widget); + + + gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type), + empathy_account_settings_get_icon_name (settings), + GTK_ICON_SIZE_DIALOG); + gtk_widget_set_tooltip_text (dialog->image_type, + empathy_account_settings_get_protocol (settings)); + + accounts_dialog_update_name_label (dialog, settings); +} + +static void +account_dialog_settings_ready_cb (EmpathyAccountSettings *settings, + GParamSpec *spec, EmpathyAccountsDialog *dialog) +{ + if (empathy_account_settings_is_ready (settings)) + account_dialog_create_settings_widget (dialog, settings); +} + +static void +accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings) { - if (!account) { + if (dialog->settings_ready != NULL) { + g_signal_handler_disconnect (dialog->settings_ready, + dialog->settings_ready_id); + dialog->settings_ready = NULL; + dialog->settings_ready_id = 0; + } + + if (!settings) { GtkTreeView *view; GtkTreeModel *model; @@ -251,20 +287,18 @@ accounts_dialog_update_account (EmpathyAccountsDialog *dialog, dialog->settings_widget = NULL; } - dialog->settings_widget = get_account_setup_widget (account); - - gtk_container_add (GTK_CONTAINER (dialog->alignment_settings), - dialog->settings_widget); - gtk_widget_show (dialog->settings_widget); - - - gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type), - empathy_account_get_icon_name (account), - GTK_ICON_SIZE_DIALOG); - gtk_widget_set_tooltip_text (dialog->image_type, - empathy_account_get_protocol (account)); + if (empathy_account_settings_is_ready (settings)) + { + account_dialog_create_settings_widget (dialog, settings); + } + else + { + dialog->settings_ready = settings; + dialog->settings_ready_id = + g_signal_connect (settings, "notify::ready", + G_CALLBACK (account_dialog_settings_ready_cb), dialog); + } - accounts_dialog_update_name_label (dialog, account); } static void @@ -277,7 +311,8 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog) G_TYPE_BOOLEAN, /* enabled */ G_TYPE_STRING, /* name */ G_TYPE_UINT, /* status */ - EMPATHY_TYPE_ACCOUNT); /* account */ + EMPATHY_TYPE_ACCOUNT, /* account */ + EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */ gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview), GTK_TREE_MODEL (store)); @@ -303,7 +338,7 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer, gchar *new_text, EmpathyAccountsDialog *dialog) { - EmpathyAccount *account; + EmpathyAccountSettings *settings; GtkTreeModel *model; GtkTreePath *treepath; GtkTreeIter iter; @@ -318,15 +353,16 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer, treepath = gtk_tree_path_new_from_string (path); gtk_tree_model_get_iter (model, &iter, treepath); gtk_tree_model_get (model, &iter, - COL_ACCOUNT_POINTER, &account, + COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); gtk_list_store_set (GTK_LIST_STORE (model), &iter, COL_NAME, new_text, -1); gtk_tree_path_free (treepath); - empathy_account_set_display_name (account, new_text); - g_object_unref (account); + empathy_account_settings_set_display_name_async (settings, new_text, + NULL, NULL); + g_object_unref (settings); } static void @@ -348,6 +384,9 @@ accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer, -1); gtk_tree_path_free (treepath); + if (account == NULL) + return; + enabled = empathy_account_is_enabled (account); empathy_account_set_enabled (account, !enabled); @@ -438,7 +477,7 @@ accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog) selection = gtk_tree_view_get_selection (view); gtk_tree_selection_select_iter (selection, &iter); } else { - accounts_dialog_update_account (dialog, NULL); + accounts_dialog_update_settings (dialog, NULL); } } @@ -449,17 +488,17 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, GtkTreeIter *iter, EmpathyAccountsDialog *dialog) { - EmpathyAccount *account; + EmpathyAccountSettings *settings; const gchar *icon_name; GdkPixbuf *pixbuf; TpConnectionStatus status; gtk_tree_model_get (model, iter, COL_STATUS, &status, - COL_ACCOUNT_POINTER, &account, + COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); - icon_name = empathy_account_get_icon_name (account); + icon_name = empathy_account_settings_get_icon_name (settings); pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); if (pixbuf) { @@ -488,15 +527,15 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, "pixbuf", pixbuf, NULL); - g_object_unref (account); + g_object_unref (settings); if (pixbuf) { g_object_unref (pixbuf); } } static gboolean -accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, - EmpathyAccount *account, +accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings, GtkTreeIter *iter) { GtkTreeView *view; @@ -509,6 +548,42 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, selection = gtk_tree_view_get_selection (view); model = gtk_tree_view_get_model (view); + for (ok = gtk_tree_model_get_iter_first (model, iter); + ok; + ok = gtk_tree_model_iter_next (model, iter)) { + EmpathyAccountSettings *this_settings; + gboolean equal; + + gtk_tree_model_get (model, iter, + COL_ACCOUNT_SETTINGS_POINTER, &this_settings, + -1); + + equal = (this_settings == settings); + g_object_unref (this_settings); + + if (equal) { + return TRUE; + } + } + + return FALSE; +} + +static gboolean +accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, + EmpathyAccount *account, + GtkTreeIter *iter) +{ + GtkTreeView *view; + GtkTreeSelection *selection; + GtkTreeModel *model; + gboolean ok; + + /* Update the status in the model */ + view = GTK_TREE_VIEW (dialog->treeview); + selection = gtk_tree_view_get_selection (view); + model = gtk_tree_view_get_model (view); + for (ok = gtk_tree_model_get_iter_first (model, iter); ok; ok = gtk_tree_model_iter_next (model, iter)) { @@ -519,7 +594,7 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, COL_ACCOUNT_POINTER, &this_account, -1); - equal = empathy_account_equal (this_account, account); + equal = (this_account == account); g_object_unref (this_account); if (equal) { @@ -530,8 +605,31 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, return FALSE; } +static EmpathyAccountSettings * +accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog) +{ + GtkTreeView *view; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccountSettings *settings; + + view = GTK_TREE_VIEW (dialog->treeview); + selection = gtk_tree_view_get_selection (view); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { + return NULL; + } + + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); + + return settings; +} + + static EmpathyAccount * -accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog) +accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog) { GtkTreeView *view; GtkTreeModel *model; @@ -553,13 +651,13 @@ accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog) static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog, - EmpathyAccount *account) + EmpathyAccountSettings *settings) { GtkTreeSelection *selection; GtkTreeIter iter; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview)); - if (accounts_dialog_get_account_iter (dialog, account, &iter)) { + if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) { gtk_tree_selection_select_iter (selection, &iter); } } @@ -586,25 +684,48 @@ static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection, EmpathyAccountsDialog *dialog) { - EmpathyAccount *account; + EmpathyAccountSettings *settings; GtkTreeModel *model; GtkTreeIter iter; gboolean is_selection; is_selection = gtk_tree_selection_get_selected (selection, &model, &iter); - account = accounts_dialog_model_get_selected (dialog); - accounts_dialog_update_account (dialog, account); + settings = accounts_dialog_model_get_selected_settings (dialog); + accounts_dialog_update_settings (dialog, settings); - if (account) { - g_object_unref (account); + if (settings) { + g_object_unref (settings); } } static void -accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog, +accounts_dialog_add (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings) +{ + GtkTreeModel *model; + GtkTreeIter iter; + const gchar *name; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + name = empathy_account_settings_get_display_name (settings); + + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_ENABLED, FALSE, + COL_NAME, name, + COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED, + COL_ACCOUNT_SETTINGS_POINTER, settings, + -1); +} + + +static void +accounts_dialog_add_account (EmpathyAccountsDialog *dialog, EmpathyAccount *account) { + EmpathyAccountSettings *settings; GtkTreeModel *model; GtkTreeIter iter; TpConnectionStatus status; @@ -616,16 +737,16 @@ accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog, name = empathy_account_get_display_name (account); enabled = empathy_account_is_enabled (account); - if (!accounts_dialog_get_account_iter (dialog, account, &iter)) { - DEBUG ("Adding new account"); - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - } + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + + settings = empathy_account_settings_new_for_account (account); gtk_list_store_set (GTK_LIST_STORE (model), &iter, COL_ENABLED, enabled, COL_NAME, name, COL_STATUS, status, COL_ACCOUNT_POINTER, account, + COL_ACCOUNT_SETTINGS_POINTER, settings, -1); accounts_dialog_connection_changed_cb (dialog->account_manager, @@ -634,6 +755,39 @@ accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog, status, TP_CONNECTION_STATUS_DISCONNECTED, dialog); + + g_object_unref (settings); +} + +static void +accounts_dialog_update (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings) +{ + GtkTreeModel *model; + GtkTreeIter iter; + TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED; + const gchar *name; + gboolean enabled = FALSE; + EmpathyAccount *account; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + name = empathy_account_settings_get_display_name (settings); + + account = empathy_account_settings_get_account (settings); + if (account != NULL) + { + enabled = empathy_account_is_enabled (account); + g_object_get (account, "connection-status", &status, NULL); + } + + accounts_dialog_get_settings_iter (dialog, settings, &iter); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_ENABLED, enabled, + COL_NAME, name, + COL_STATUS, status, + COL_ACCOUNT_POINTER, account, + COL_ACCOUNT_SETTINGS_POINTER, settings, + -1); } static void @@ -641,43 +795,20 @@ accounts_dialog_account_added_cb (EmpathyAccountManager *manager, EmpathyAccount *account, EmpathyAccountsDialog *dialog) { - const gchar *current_name; - const gchar *account_param = NULL; - - accounts_dialog_add_or_update_account (dialog, account); - - /* Change the display name to "%s (%s)" % (protocol, account). - * - The protocol is the display name of the profile. - * - The account should be the normalized name of the EmpathyAccount but - * it's not set until first connection, so we get the "account" - * parameter for CM that have it. */ - current_name = empathy_account_get_display_name (account); - account_param = empathy_account_get_param_string (account, "account"); - if (!EMP_STR_EMPTY (account_param)) { - gchar *new_name; - - new_name = g_strdup_printf ("%s (%s)", - empathy_account_get_protocol (account), - account_param); - - DEBUG ("Setting new display name for account %s: '%s'", - empathy_account_get_unique_name (account), new_name); - - empathy_account_set_display_name (account, new_name); - g_free (new_name); - } else { - /* FIXME: This CM has no account parameter, what can be done? */ - } + accounts_dialog_add_account (dialog, account); } + static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager, EmpathyAccount *account, EmpathyAccountsDialog *dialog) { + GtkTreeIter iter; - accounts_dialog_model_set_selected (dialog, account); - accounts_dialog_model_remove_selected (dialog); + if (accounts_dialog_get_account_iter (dialog, account, &iter)) + gtk_list_store_remove (GTK_LIST_STORE ( + gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview))), &iter); } static gboolean @@ -791,20 +922,31 @@ accounts_dialog_account_changed_cb (EmpathyAccountManager *manager, EmpathyAccount *account, EmpathyAccountsDialog *dialog) { - EmpathyAccount *selected_account; + EmpathyAccountSettings *settings, *selected_settings; + GtkTreeModel *model; + GtkTreeIter iter; - accounts_dialog_add_or_update_account (dialog, account); - selected_account = accounts_dialog_model_get_selected (dialog); - if (empathy_account_equal (account, selected_account)) { - accounts_dialog_update_name_label (dialog, account); - } + model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + + if (!accounts_dialog_get_account_iter (dialog, account, &iter)) + return; + + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_SETTINGS_POINTER, &settings, + -1); + + accounts_dialog_update (dialog, settings); + selected_settings = accounts_dialog_model_get_selected_settings (dialog); + + if (settings == selected_settings) + accounts_dialog_update_name_label (dialog, settings); } static void accounts_dialog_button_create_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { - EmpathyAccount *account; + EmpathyAccountSettings *settings; gchar *str; TpConnectionManager *cm; TpConnectionManagerProtocol *proto; @@ -816,30 +958,23 @@ accounts_dialog_button_create_clicked_cb (GtkWidget *button, /* To translator: %s is the protocol name */ str = g_strdup_printf (_("New %s account"), proto->name); - account = empathy_account_manager_create (dialog->account_manager, - cm->name, proto->name, str); + settings = empathy_account_settings_new (cm->name, proto->name, str); g_free (str); - if (account == NULL) { - /* We can't display an error to the user as MC doesn't give us - * any clue about the reason of the failure... */ - return; - } - if (tp_connection_manager_protocol_can_register (proto)) { gboolean active; active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register)); if (active) { - empathy_account_set_param_boolean (account, "register", TRUE); + empathy_account_settings_set_boolean (settings, "register", TRUE); } } - accounts_dialog_add_or_update_account (dialog, account); - accounts_dialog_model_set_selected (dialog, account); + accounts_dialog_add (dialog, settings); + accounts_dialog_model_set_selected (dialog, settings); - g_object_unref (account); + g_object_unref (settings); g_object_unref (cm); } @@ -847,10 +982,10 @@ static void accounts_dialog_button_back_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { - EmpathyAccount *account; + EmpathyAccountSettings *settings; - account = accounts_dialog_model_get_selected (dialog); - accounts_dialog_update_account (dialog, account); + settings = accounts_dialog_model_get_selected_settings (dialog); + accounts_dialog_update (dialog, settings); } static void @@ -921,9 +1056,9 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button, GtkWidget *message_dialog; gint res; - account = accounts_dialog_model_get_selected (dialog); + account = accounts_dialog_model_get_selected_account (dialog); - if (!empathy_account_is_valid (account)) { + if (account == NULL || !empathy_account_is_valid (account)) { accounts_dialog_model_remove_selected (dialog); accounts_dialog_model_select_first (dialog); return; @@ -1127,13 +1262,19 @@ empathy_accounts_dialog_show (GtkWindow *parent, /* Add existing accounts */ accounts = empathy_account_manager_dup_accounts (dialog->account_manager); for (l = accounts; l; l = l->next) { - accounts_dialog_add_or_update_account (dialog, l->data); + accounts_dialog_add_account (dialog, l->data); g_object_unref (l->data); } g_list_free (accounts); if (selected_account) { - accounts_dialog_model_set_selected (dialog, selected_account); + GtkTreeSelection *selection; + GtkTreeIter iter; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview)); + if (accounts_dialog_get_account_iter (dialog, selected_account, &iter)) { + gtk_tree_selection_select_iter (selection, &iter); + } } else { accounts_dialog_model_select_first (dialog); } -- cgit v1.2.3 From e24b064cc562a89abf8facba5b9085d4aee862ed Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 18:02:21 +0100 Subject: Port creating of of a salut account to then new apis --- src/empathy.c | 134 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 44 deletions(-) diff --git a/src/empathy.c b/src/empathy.c index 1fa7f5a12..13230d1a0 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -47,7 +47,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -159,6 +161,7 @@ use_nm_notify_cb (EmpathyConf *conf, } } +/* Salut account creation */ static gboolean should_create_salut_account (void) { @@ -171,6 +174,12 @@ should_create_salut_account (void) EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, &salut_created); + if (salut_created) + { + DEBUG ("Gconf says we already created a salut account once"); + return FALSE; + } + manager = empathy_account_manager_dup_singleton (); accounts = empathy_account_manager_dup_accounts (manager); @@ -185,14 +194,46 @@ should_create_salut_account (void) g_object_unref (manager); + if (salut_created) + { + DEBUG ("Existing salut account already exists, flagging so in gconf"); + empathy_conf_set_bool (empathy_conf_get (), + EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, + TRUE); + } + return !salut_created; } static void -create_salut_account_if_needed (void) +salut_account_created (GObject *source, + GAsyncResult *result, gpointer user_data) { - EmpathyAccount *account; - EmpathyAccountManager *account_manager; + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source); + EmpathyAccount *account; + GError *error = NULL; + + if (!empathy_account_settings_apply_finish (settings, result, &error)) + { + DEBUG ("Failed to create salut account: %s", error->message); + g_error_free (error); + return; + } + + account = empathy_account_settings_get_account (settings); + + empathy_account_set_enabled (account, TRUE); + empathy_conf_set_bool (empathy_conf_get (), + EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, + TRUE); +} + +static void +create_salut_account_if_needed (EmpathyConnectionManagers *managers) +{ + EmpathyAccountSettings *settings; + TpConnectionManager *manager; + const TpConnectionManagerProtocol *protocol; EBook *book; EContact *contact; gchar *nickname = NULL; @@ -205,6 +246,20 @@ create_salut_account_if_needed (void) if (!should_create_salut_account()) return; + + manager = empathy_connection_managers_get_cm (managers, "salut"); + if (manager == NULL) + { + DEBUG ("Salut not installed, not making a salut account"); + return; + } + + protocol = tp_connection_manager_get_protocol (manager, "local-xmpp"); + if (protocol == NULL) + { + DEBUG ("Salut doesn't support local-xmpp!!"); + return; + } DEBUG ("Trying to add a salut account..."); @@ -216,11 +271,8 @@ create_salut_account_if_needed (void) return; } - account_manager = empathy_account_manager_dup_singleton (); - account = empathy_account_manager_create (account_manager, - "salut", "local-xmpp", _("People nearby")); - g_object_unref (account_manager); - empathy_account_set_enabled (account, TRUE); + settings = empathy_account_settings_new ("salut", "local-xmpp", + _("People nearby")); nickname = e_contact_get (contact, E_CONTACT_NICKNAME); first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME); @@ -237,63 +289,57 @@ create_salut_account_if_needed (void) "last-name=%s\nemail=%s\njid=%s\n", nickname, first_name, last_name, email, jid); - empathy_account_set_param_string (account, "nickname", nickname ? nickname : ""); - empathy_account_set_param_string (account, "first-name", first_name ? first_name : ""); - empathy_account_set_param_string (account, "last-name", last_name ? last_name : ""); - empathy_account_set_param_string (account, "email", email ? email : ""); - empathy_account_set_param_string (account, "jid", jid ? jid : ""); + empathy_account_settings_set_string (settings, "nickname", nickname ? nickname : ""); + empathy_account_settings_set_string (settings, "first-name", first_name ? first_name : ""); + empathy_account_settings_set_string (settings, "last-name", last_name ? last_name : ""); + empathy_account_settings_set_string (settings, "email", email ? email : ""); + empathy_account_settings_set_string (settings, "jid", jid ? jid : ""); + + empathy_account_settings_apply_async (settings, + salut_account_created, NULL); g_free (nickname); g_free (first_name); g_free (last_name); g_free (email); g_free (jid); - g_object_unref (account); + g_object_unref (settings); g_object_unref (contact); g_object_unref (book); - - empathy_conf_set_bool (empathy_conf_get (), - EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, - TRUE); - } static void -connection_manager_listed (TpConnectionManager * const * cms, - gsize n_cms, - const GError *error, - gpointer user_data, - GObject *weak_object) +connection_managers_ready_cb (EmpathyConnectionManagers *managers, + GParamSpec *spec, gpointer user_data) { - int i; - if (error != NULL) { - DEBUG ("Couldn't get the connection manager list: %s", error->message); - return; - } - - for (i = 0; i < n_cms; i++) { - if (!tp_strdiff (tp_connection_manager_get_name (cms[i]), "salut")) { - /* salut installed, see if we need to create a new account */ - create_salut_account_if_needed (); - return; - } - } + if (empathy_connection_managers_is_ready (managers)) + { + create_salut_account_if_needed (managers); + g_object_unref (managers); + managers = NULL; + } } static void create_salut_account (void) { - TpDBusDaemon *d; + EmpathyConnectionManagers *managers; if (!should_create_salut_account()) return; - d = tp_dbus_daemon_dup (NULL); + managers = empathy_connection_managers_dup_singleton (); - tp_list_connection_managers (d, connection_manager_listed, NULL, - NULL, NULL); - - g_object_unref (d); + if (empathy_connection_managers_is_ready (managers)) + { + create_salut_account_if_needed (managers); + g_object_unref (managers); + } + else + { + g_signal_connect (managers, "notify::ready", + G_CALLBACK (connection_managers_ready_cb), NULL); + } } /* The code that handles single-instance and startup notification is @@ -461,7 +507,7 @@ account_manager_ready_cb (EmpathyAccountManager *manager, if (!empathy_account_manager_is_ready (manager)) return; - if (empathy_account_manager_get_count (manager) != 0) + if (empathy_account_manager_get_count (manager) == 0) { empathy_accounts_dialog_show (GTK_WINDOW (empathy_main_window_get ()), NULL); -- cgit v1.2.3 From 7ba6375cdfa00bc0871e4958076398e82f92c2b5 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 18:02:47 +0100 Subject: Unescape _ and _2d in the protocol from mission-control --- libempathy/empathy-account.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 21ece6f0d..4cd96e393 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -345,6 +345,41 @@ empathy_account_got_all_cb (TpProxy *proxy, empathy_account_update (account, properties); } +static gchar * +empathy_account_unescape_protocol (const gchar *protocol, gssize len) +{ + gchar *result, *escape; + /* Bad implementation might accidentally use tp_escape_as_identifier, + * which escapes - in the wrong way... */ + if ((escape = g_strstr_len (protocol, len, "_2d")) != NULL) + { + GString *str; + const gchar *input; + + str = g_string_new (""); + input = protocol; + do { + g_string_append_len (str, input, escape - input); + g_string_append_c (str, '-'); + + len -= escape - input + 3; + input = escape + 3; + } while ((escape = g_strstr_len (input, len, "_2d")) != NULL); + + g_string_append_len (str, input, len); + + result = g_string_free (str, FALSE); + } + else + { + result = g_strndup (protocol, len); + } + + g_strdelimit (result, "_", '-'); + + return result; +} + static gboolean empathy_account_parse_unique_name (const gchar *bus_name, gchar **protocol, gchar **manager) @@ -375,7 +410,9 @@ empathy_account_parse_unique_name (const gchar *bus_name, return FALSE; if (protocol != NULL) - *protocol = g_strndup (proto, proto_end - proto); + { + *protocol = empathy_account_unescape_protocol (proto, proto_end - proto); + } if (manager != NULL) *manager = g_strndup (cm, cm_end - cm); -- cgit v1.2.3 From 183bea15838e2ad9dc16f6d86eedb820831a8d7f Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 18:06:47 +0100 Subject: Coding style fixes --- libempathy/empathy-account-manager.c | 2 +- libempathy/empathy-account-settings.h | 4 ++-- libempathy/empathy-account.c | 6 +++--- libempathy/empathy-account.h | 2 +- libempathy/empathy-connection-managers.c | 2 +- libempathy/empathy-connection-managers.h | 4 ++-- libempathy/empathy-log-store-empathy.c | 2 +- src/empathy.c | 8 ++++---- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index eeac5c130..692b4f05a 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -789,7 +789,7 @@ empathy_account_manager_created_cb (TpAccountManager *proxy, if (error != NULL) { - g_simple_async_result_set_from_error (result, (GError *)error); + g_simple_async_result_set_from_error (result, (GError *) error); g_simple_async_result_complete (result); g_object_unref (G_OBJECT (result)); return; diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h index c0f21a31c..d9231a50a 100644 --- a/libempathy/empathy-account-settings.h +++ b/libempathy/empathy-account-settings.h @@ -41,11 +41,11 @@ struct _EmpathyAccountSettings { gpointer priv; }; -GType empathy_account_settings_get_type(void); +GType empathy_account_settings_get_type (void); /* TYPE MACROS */ #define EMPATHY_TYPE_ACCOUNT_SETTINGS \ - (empathy_account_settings_get_type()) + (empathy_account_settings_get_type ()) #define EMPATHY_ACCOUNT_SETTINGS(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), \ EMPATHY_TYPE_ACCOUNT_SETTINGS, EmpathyAccountSettings)) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 4cd96e393..5727a8a25 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -901,7 +901,7 @@ empathy_account_updated_cb (TpAccount *proxy, if (error != NULL) { - g_simple_async_result_set_from_error (result, (GError *)error); + g_simple_async_result_set_from_error (result, (GError *) error); } g_simple_async_result_complete (result); @@ -910,7 +910,7 @@ empathy_account_updated_cb (TpAccount *proxy, void empathy_account_update_settings_async (EmpathyAccount *account, - const GHashTable *parameters, const gchar **unset_parameters, + GHashTable *parameters, const gchar **unset_parameters, GAsyncReadyCallback callback, gpointer user_data) { EmpathyAccountPriv *priv = GET_PRIV (account); @@ -919,7 +919,7 @@ empathy_account_update_settings_async (EmpathyAccount *account, tp_cli_account_call_update_parameters (priv->account, -1, - (GHashTable *)parameters, + parameters, unset_parameters, empathy_account_updated_cb, result, diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index f498e11e3..58f174eaa 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -73,7 +73,7 @@ gboolean empathy_account_is_valid (EmpathyAccount *account); gboolean empathy_account_is_ready (EmpathyAccount *account); void empathy_account_update_settings_async (EmpathyAccount *account, - const GHashTable *parameters, const gchar **unset_parameters, + GHashTable *parameters, const gchar **unset_parameters, GAsyncReadyCallback callback, gpointer user_data); gboolean empathy_account_update_settings_finish (EmpathyAccount *account, diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c index 6a87a3fa5..150d6a43c 100644 --- a/libempathy/empathy-connection-managers.c +++ b/libempathy/empathy-connection-managers.c @@ -245,7 +245,7 @@ empathy_connection_managers_listed_cb (TpConnectionManager * const *cms, for (iter = cms ; iter != NULL && *iter != NULL; iter++) { /* only list cms that didn't hit errors */ - if (tp_connection_manager_is_ready(*iter)) + if (tp_connection_manager_is_ready (*iter)) priv->cms = g_list_prepend (priv->cms, g_object_ref (*iter)); } diff --git a/libempathy/empathy-connection-managers.h b/libempathy/empathy-connection-managers.h index 661075614..0c4147951 100644 --- a/libempathy/empathy-connection-managers.h +++ b/libempathy/empathy-connection-managers.h @@ -39,11 +39,11 @@ struct _EmpathyConnectionManagers { gpointer priv; }; -GType empathy_connection_managers_get_type(void); +GType empathy_connection_managers_get_type (void); /* TYPE MACROS */ #define EMPATHY_TYPE_CONNECTION_MANAGERS \ - (empathy_connection_managers_get_type()) + (empathy_connection_managers_get_type ()) #define EMPATHY_CONNECTION_MANAGERS(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), EMPATHY_TYPE_CONNECTION_MANAGERS, \ EmpathyConnectionManagers)) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 189bf0036..d0487e761 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -123,7 +123,7 @@ log_store_empathy_get_dir (EmpathyLogStore *self, * by % */ escaped = g_strdup (empathy_account_get_unique_name (account) + 1); - g_strdelimit(escaped, "/", '%'); + g_strdelimit (escaped, "/", '%'); if (chatroom) basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, escaped, diff --git a/src/empathy.c b/src/empathy.c index 13230d1a0..3d8fe6e12 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -244,7 +244,7 @@ create_salut_account_if_needed (EmpathyConnectionManagers *managers) GError *error = NULL; - if (!should_create_salut_account()) + if (!should_create_salut_account ()) return; manager = empathy_connection_managers_get_cm (managers, "salut"); @@ -253,14 +253,14 @@ create_salut_account_if_needed (EmpathyConnectionManagers *managers) DEBUG ("Salut not installed, not making a salut account"); return; } - + protocol = tp_connection_manager_get_protocol (manager, "local-xmpp"); if (protocol == NULL) { DEBUG ("Salut doesn't support local-xmpp!!"); return; } - + DEBUG ("Trying to add a salut account..."); /* Get self EContact from EDS */ @@ -325,7 +325,7 @@ create_salut_account (void) { EmpathyConnectionManagers *managers; - if (!should_create_salut_account()) + if (!should_create_salut_account ()) return; managers = empathy_connection_managers_dup_singleton (); -- cgit v1.2.3 From e9266689e7b55d9be53afc46c5b3d131ba9837cd Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 18:14:51 +0100 Subject: Disable tests that try to use MC4 related code --- tests/check-empathy-chatroom-manager.c | 4 ++++ tests/check-empathy-chatroom.c | 4 ++++ tests/check-empathy-helpers.c | 2 ++ 3 files changed, 10 insertions(+) diff --git a/tests/check-empathy-chatroom-manager.c b/tests/check-empathy-chatroom-manager.c index 1c0f924a2..5a3384fe4 100644 --- a/tests/check-empathy-chatroom-manager.c +++ b/tests/check-empathy-chatroom-manager.c @@ -18,6 +18,7 @@ #define CHATROOM_SAMPLE "chatrooms-sample.xml" #define CHATROOM_FILE "chatrooms.xml" +#if 0 static void check_chatroom (EmpathyChatroom *chatroom, const gchar *name, @@ -384,15 +385,18 @@ START_TEST (test_empathy_chatroom_manager_change_chatroom) g_object_unref (account_manager); } END_TEST +#endif TCase * make_empathy_chatroom_manager_tcase (void) { TCase *tc = tcase_create ("empathy-chatroom-manager"); + /* tcase_add_test (tc, test_empathy_chatroom_manager_dup_singleton); tcase_add_test (tc, test_empathy_chatroom_manager_add); tcase_add_test (tc, test_empathy_chatroom_manager_remove); tcase_add_test (tc, test_empathy_chatroom_manager_change_favorite); tcase_add_test (tc, test_empathy_chatroom_manager_change_chatroom); + */ return tc; } diff --git a/tests/check-empathy-chatroom.c b/tests/check-empathy-chatroom.c index f2110a8f8..4d0b7e1ee 100644 --- a/tests/check-empathy-chatroom.c +++ b/tests/check-empathy-chatroom.c @@ -9,6 +9,7 @@ #include +#if 0 static EmpathyChatroom * create_chatroom (void) { @@ -143,13 +144,16 @@ START_TEST (test_change_favorite) fail_if (!changed); } END_TEST +#endif TCase * make_empathy_chatroom_tcase (void) { TCase *tc = tcase_create ("empathy-chatroom"); + /* tcase_add_test (tc, test_empathy_chatroom_new); tcase_add_test (tc, test_favorite_and_auto_connect); tcase_add_test (tc, test_change_favorite); + */ return tc; } diff --git a/tests/check-empathy-helpers.c b/tests/check-empathy-helpers.c index fc6f04439..5fb8b4a35 100644 --- a/tests/check-empathy-helpers.c +++ b/tests/check-empathy-helpers.c @@ -65,6 +65,7 @@ copy_xml_file (const gchar *orig, g_free (buffer); } +#if 0 EmpathyAccount * get_test_account (void) { @@ -166,3 +167,4 @@ destroy_test_account (EmpathyAccount *account) g_object_unref (account); g_object_unref (manager); } +#endif -- cgit v1.2.3 From 68dcc8dcce232a4e8c803bd6cc71052c473f9203 Mon Sep 17 00:00:00 2001 From: Marco Barisione Date: Mon, 20 Jul 2009 13:25:23 +0100 Subject: Use the account manager when the service is running, not when we receive NameOwnerChanged --- libempathy/empathy-account-manager.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 692b4f05a..7df1a80b7 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "empathy-account-manager.h" @@ -45,7 +46,6 @@ typedef struct { int connecting; gboolean dispose_run; gboolean ready; - TpProxySignalConnection *proxy_signal; TpAccountManager *tp_manager; TpDBusDaemon *dbus; @@ -322,18 +322,16 @@ account_manager_got_all_cb (TpProxy *proxy, } static void -account_manager_name_owner_changed_cb (TpDBusDaemon *proxy, - const gchar *arg0, - const gchar *arg1, - const gchar *arg2, - gpointer user_data, - GObject *weak_object) +account_manager_name_owner_cb (TpDBusDaemon *proxy, + const gchar *name, + const gchar *new_owner, + gpointer user_data) { - EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - tp_proxy_signal_connection_disconnect (priv->proxy_signal); - priv->proxy_signal = NULL; + tp_dbus_daemon_cancel_name_owner_watch (proxy, name, + account_manager_name_owner_cb, user_data); priv->tp_manager = tp_account_manager_new (priv->dbus); tp_cli_dbus_properties_call_get_all (priv->tp_manager, -1, @@ -362,12 +360,10 @@ empathy_account_manager_init (EmpathyAccountManager *manager) priv->dbus = tp_dbus_daemon_dup (NULL); - priv->proxy_signal = tp_cli_dbus_daemon_connect_to_name_owner_changed ( - priv->dbus, - account_manager_name_owner_changed_cb, + tp_dbus_daemon_watch_name_owner (priv->dbus, TP_ACCOUNT_MANAGER_BUS_NAME, - NULL, - G_OBJECT (manager), + account_manager_name_owner_cb, + manager, NULL); /* trigger MC5 starting */ @@ -405,6 +401,9 @@ do_dispose (GObject *obj) priv->dispose_run = TRUE; + tp_dbus_daemon_cancel_name_owner_watch (priv->dbus, + TP_ACCOUNT_MANAGER_BUS_NAME, account_manager_name_owner_cb, manager); + if (priv->dbus == NULL) g_object_unref (priv->dbus); priv->dbus = NULL; -- cgit v1.2.3 From 08c068fc1b90777c3a2b9c313e282f93f24b3f71 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 18:45:20 +0100 Subject: Make the account manager listen to AccountValidityChanged --- libempathy/empathy-account-manager.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 7df1a80b7..5d1363fce 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -282,6 +282,10 @@ account_manager_add_account (EmpathyAccountManager *manager, EmpathyAccountManagerPriv *priv = GET_PRIV (manager); EmpathyAccount *account; + account = g_hash_table_lookup (priv->accounts, path); + if (account != NULL) + return account; + account = empathy_account_new (priv->dbus, path); g_hash_table_insert (priv->accounts, g_strdup (path), account); @@ -321,6 +325,21 @@ account_manager_got_all_cb (TpProxy *proxy, empathy_account_manager_check_ready (manager); } +static void +account_validity_changed_cb (TpAccountManager *proxy, + const gchar *path, + gboolean valid, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); + + if (!valid) + return; + + account_manager_add_account (manager, path); +} + static void account_manager_name_owner_cb (TpDBusDaemon *proxy, const gchar *name, @@ -334,6 +353,15 @@ account_manager_name_owner_cb (TpDBusDaemon *proxy, account_manager_name_owner_cb, user_data); priv->tp_manager = tp_account_manager_new (priv->dbus); + + tp_cli_account_manager_connect_to_account_validity_changed ( + priv->tp_manager, + account_validity_changed_cb, + NULL, + NULL, + G_OBJECT (manager), + NULL); + tp_cli_dbus_properties_call_get_all (priv->tp_manager, -1, TP_IFACE_ACCOUNT_MANAGER, account_manager_got_all_cb, @@ -795,8 +823,11 @@ empathy_account_manager_created_cb (TpAccountManager *proxy, } account = account_manager_add_account (manager, account_path); - g_signal_connect (account, "notify::ready", - G_CALLBACK (empathy_account_manager_created_ready_cb), result); + if (empathy_account_is_ready (account)) + empathy_account_manager_created_ready_cb (account, NULL, result); + else + g_signal_connect (account, "notify::ready", + G_CALLBACK (empathy_account_manager_created_ready_cb), result); } void -- cgit v1.2.3 From 067e77dceb1e0c01f33ce4c743e88c7214403b8a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:02:37 +0100 Subject: Add removed signal on EmpathyAccount --- libempathy/empathy-account-manager.c | 17 +++++++++++++ libempathy/empathy-account.c | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 5d1363fce..7339acb9f 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -220,6 +220,20 @@ signal: priv->global_presence, priv->global_status, priv->global_status_message); } +static void +emp_account_removed_cb (EmpathyAccount *account, gpointer user_data) +{ + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + + g_object_ref (account); + g_hash_table_remove (priv->accounts, + empathy_account_get_unique_name (account)); + + g_signal_emit (manager, signals[ACCOUNT_DELETED], 0, account); + g_object_unref (account); +} + static void empathy_account_manager_check_ready (EmpathyAccountManager *manager) { @@ -272,6 +286,9 @@ emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) g_signal_connect (account, "presence-changed", G_CALLBACK (emp_account_presence_changed_cb), manager); + g_signal_connect (account, "removed", + G_CALLBACK (emp_account_removed_cb), manager); + empathy_account_manager_check_ready (manager); } diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5727a8a25..51dd26316 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -42,6 +42,7 @@ enum { STATUS_CHANGED, PRESENCE_CHANGED, + REMOVED, LAST_SIGNAL }; @@ -84,6 +85,7 @@ struct _EmpathyAccountPriv gboolean enabled; gboolean valid; gboolean ready; + gboolean removed; /* Timestamp when the connection got connected in seconds since the epoch */ glong connect_time; @@ -324,6 +326,22 @@ empathy_account_properties_changed (TpAccount *proxy, empathy_account_update (account, properties); } +static void +empathy_account_removed_cb (TpAccount *proxy, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (priv->removed) + return; + + priv->removed = TRUE; + + g_signal_emit (account, signals[REMOVED], 0); +} + static void empathy_account_got_all_cb (TpProxy *proxy, GHashTable *properties, @@ -420,6 +438,21 @@ empathy_account_parse_unique_name (const gchar *bus_name, return TRUE; } +static void +account_invalidated_cb (TpProxy *proxy, guint domain, gint code, + gchar *message, gpointer user_data) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (user_data); + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (priv->removed) + return; + + priv->removed = TRUE; + + g_signal_emit (account, signals[REMOVED], 0); +} + static void empathy_account_constructed (GObject *object) { @@ -428,6 +461,9 @@ empathy_account_constructed (GObject *object) priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL); + g_signal_connect (priv->account, "invalidated", + G_CALLBACK (account_invalidated_cb), object); + empathy_account_parse_unique_name (priv->unique_name, &(priv->proto_name), &(priv->cm_name)); @@ -437,6 +473,10 @@ empathy_account_constructed (GObject *object) empathy_account_properties_changed, NULL, NULL, object, NULL); + tp_cli_account_connect_to_removed (priv->account, + empathy_account_removed_cb, + NULL, NULL, object, NULL); + tp_cli_dbus_properties_call_get_all (priv->account, -1, TP_IFACE_ACCOUNT, empathy_account_got_all_cb, @@ -558,6 +598,13 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) 0, NULL, NULL, _empathy_marshal_VOID__UINT_STRING_STRING, G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); + + signals[REMOVED] = g_signal_new ("removed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } void -- cgit v1.2.3 From 2e87bc47e7c03fa0d2145b2c3904df545b941a76 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:11:50 +0100 Subject: Add api to remove accounts --- libempathy/empathy-account.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ libempathy/empathy-account.h | 5 +++++ 2 files changed, 53 insertions(+) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 51dd26316..8d4909586 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -987,3 +987,51 @@ empathy_account_update_settings_finish (EmpathyAccount *account, return TRUE; } + +static void +empathy_account_remove_cb (TpAccount *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + + if (error != NULL) + { + g_simple_async_result_set_from_error (result, (GError *) error); + } + + g_simple_async_result_complete (result); + g_object_unref (G_OBJECT (result)); +} + +void +empathy_account_remove_async (EmpathyAccount *account, + GAsyncReadyCallback callback, gpointer user_data) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account), + callback, user_data, empathy_account_remove_finish); + + tp_cli_account_call_remove (priv->account, + -1, + empathy_account_remove_cb, + result, + NULL, + G_OBJECT (account)); +} + +gboolean +empathy_account_remove_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (account), empathy_account_update_settings_finish), FALSE); + + return TRUE; +} + diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 58f174eaa..00daa46ee 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -79,6 +79,11 @@ void empathy_account_update_settings_async (EmpathyAccount *account, gboolean empathy_account_update_settings_finish (EmpathyAccount *account, GAsyncResult *result, GError **error); +void empathy_account_remove_async (EmpathyAccount *account, + GAsyncReadyCallback callback, gpointer user_data); +gboolean empathy_account_remove_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error); + void empathy_account_set_display_name (EmpathyAccount *account, const gchar *display_name); -- cgit v1.2.3 From d46b6d50cedf6babe686d8a13dea36d5cbc4394f Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:12:01 +0100 Subject: Hook up removing accounts in the accounts dialog --- src/empathy-accounts-dialog.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index d6a29ea63..010493ff2 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -669,6 +669,7 @@ accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog) GtkTreeModel *model; GtkTreeSelection *selection; GtkTreeIter iter; + EmpathyAccount *account; view = GTK_TREE_VIEW (dialog->treeview); selection = gtk_tree_view_get_selection (view); @@ -677,6 +678,13 @@ accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog) return FALSE; } + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_POINTER, &account, + -1); + + if (account != NULL) + empathy_account_remove_async (account, NULL, NULL); + return gtk_list_store_remove (GTK_LIST_STORE (model), &iter); } -- cgit v1.2.3 From 6d2d940c7946eafb807e325af4c87a03570ef383 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:27:43 +0100 Subject: Correctly implement empathy_account_is_valid --- libempathy/empathy-account.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 8d4909586..cc982aea7 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -716,10 +716,9 @@ empathy_account_get_display_name (EmpathyAccount *account) gboolean empathy_account_is_valid (EmpathyAccount *account) { - //EmpathyAccountPriv *priv = GET_PRIV (account); + EmpathyAccountPriv *priv = GET_PRIV (account); - /* FIXME */ - return FALSE; + return priv->valid; } const gchar * -- cgit v1.2.3 From 80e9b255ca7f39d17034475f52479e5199ce5f93 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:28:08 +0100 Subject: Add apply button for salut accounts --- libempathy-gtk/empathy-account-widget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index ea0a05b35..21e3d3ee3 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -570,6 +570,7 @@ empathy_account_widget_salut_new (EmpathyAccountSettings *settings) NULL); empathy_account_widget_set_default_focus (gui, "entry_nickname"); + empathy_account_widget_add_apply_button (settings, widget); return empathy_builder_unref_and_keep_widget (gui, widget); } -- cgit v1.2.3 From 36bfa50660b97ad74678e3cde0f6195154135fef Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:42:40 +0100 Subject: Add the Apply widget to the IRC account settings dialog --- libempathy-gtk/empathy-account-widget-irc.c | 13 +- libempathy-gtk/empathy-account-widget-irc.ui | 339 ++++++++++++++------------- 2 files changed, 181 insertions(+), 171 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c index ae41f1e39..4bca91073 100644 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ b/libempathy-gtk/empathy-account-widget-irc.c @@ -423,12 +423,13 @@ empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) EmpathyAccountWidgetIrc *settings; gchar *dir, *user_file_with_path, *global_file_with_path; GtkBuilder *gui; + GtkWidget *widget; GtkListStore *store; GtkCellRenderer *renderer; gchar *filename; settings = g_slice_new0 (EmpathyAccountWidgetIrc); - settings->settings = g_object_ref (settings); + settings->settings = g_object_ref (account_settings); dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); @@ -454,7 +455,8 @@ empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) filename = empathy_file_lookup ("empathy-account-widget-irc.ui", "libempathy-gtk"); gui = empathy_builder_get_file (filename, - "vbox_irc_settings", &settings->vbox_settings, + "vbox_irc", &widget, + "table_irc_settings", &settings->vbox_settings, "combobox_network", &settings->combobox_network, NULL); g_free (filename); @@ -489,7 +491,7 @@ empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) NULL); empathy_builder_connect (gui, settings, - "vbox_irc_settings", "destroy", account_widget_irc_destroy_cb, + "table_irc_settings", "destroy", account_widget_irc_destroy_cb, "button_network", "clicked", account_widget_irc_button_edit_network_clicked_cb, "button_add_network", "clicked", @@ -501,8 +503,7 @@ empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) NULL); empathy_account_widget_set_default_focus (gui, "entry_nick"); - empathy_account_widget_add_apply_button (account_settings, - settings->vbox_settings); + empathy_account_widget_add_apply_button (account_settings, widget); - return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings); + return empathy_builder_unref_and_keep_widget (gui, widget); } diff --git a/libempathy-gtk/empathy-account-widget-irc.ui b/libempathy-gtk/empathy-account-widget-irc.ui index abb1c9362..a4f7faa7f 100644 --- a/libempathy-gtk/empathy-account-widget-irc.ui +++ b/libempathy-gtk/empathy-account-widget-irc.ui @@ -255,207 +255,216 @@ button_close - + True - 5 - 2 - 12 - 6 + vertical - + True - True - - - - 1 - 2 - 4 - 5 - - - - - - True - 0 - Quit message: - - - 4 - 5 - GTK_FILL - - - - - - True - True - - - - 1 - 2 - 3 - 4 - - - - - - True - True - False - - - - 1 - 2 - 2 - 3 - - - - - - True - 0 - Password: - - - 2 - 3 - GTK_FILL - - - - - - True - 0 - Real name: - - - 3 - 4 - GTK_FILL - - - - - - True - True - - - - 1 - 2 - 1 - 2 - - - - - - True - 0 - Nickname: - True - entry_nick - - - 1 - 2 - GTK_FILL - - - - - - True - 2 + 5 + 2 + 12 + 6 - + True + True + - 0 + 1 + 2 + 4 + 5 + - + + True + 0 + Quit message: + + + 4 + 5 + GTK_FILL + + + + + True True - True - - - True - gtk-add - - + - False - False - 1 + 1 + 2 + 3 + 4 + - + True True - True - - - True - gtk-edit - - + False + - False - False - 2 + 1 + 2 + 2 + 3 + + + + + + True + 0 + Password: + + + 2 + 3 + GTK_FILL + + + + + + True + 0 + Real name: + + + 3 + 4 + GTK_FILL + - + True True - True + + + + 1 + 2 + 1 + 2 + + + + + + True + 0 + Nickname: + True + entry_nick + + + 1 + 2 + GTK_FILL + + + + + + True + 2 + + + True + + + 0 + + + + + True + True + True + + + True + gtk-add + + + + + False + False + 1 + + - + True - gtk-remove + True + True + + + True + gtk-edit + + + + False + False + 2 + + + + + True + True + True + + + True + gtk-remove + + + + + False + False + 3 + - False - False - 3 + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + 0 + Network: + True + + + GTK_FILL + - 1 - 2 - GTK_FILL - GTK_FILL - - - - - True - 0 - Network: - True - - - GTK_FILL - + 0 -- cgit v1.2.3 From 5fcaf2ec834ebd542ee6f434705acdfaf8a05368 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 22 Jul 2009 00:00:33 +0100 Subject: If the requested property is missing, assume we didn't request it MC5 tries to handle channels only signalled by the old NewChannel signal, but the Requested property isn't set in that case. Assume that we didn't request it in that case --- libempathy/empathy-dispatcher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index bce9f7610..0b2a74a2e 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -709,7 +709,7 @@ dispatcher_connection_new_channel_with_properties ( if (!valid) { g_message ("%s had an invalid Requested property", object_path); - return; + requested = FALSE; } dispatcher_connection_new_channel (dispatcher, connection, -- cgit v1.2.3 From 0b269dddf9534936735567c8f23519f0f88c949d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 22 Jul 2009 00:06:14 +0100 Subject: Get the connection status, not the presence status string --- libempathy-gtk/empathy-account-chooser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c index ec2c2b18a..fa05bbcc9 100644 --- a/libempathy-gtk/empathy-account-chooser.c +++ b/libempathy-gtk/empathy-account-chooser.c @@ -769,7 +769,7 @@ empathy_account_chooser_filter_is_connected (EmpathyAccount *account, { TpConnectionStatus status; - g_object_get (account, "status", &status, NULL); + g_object_get (account, "connection-status", &status, NULL); return status == TP_CONNECTION_STATUS_CONNECTED; } -- cgit v1.2.3 From df1cf218c8a219caa68fc2f95aed1df84a95382e Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 22 Jul 2009 00:07:03 +0100 Subject: Don't try to update the widgets if no account was selected --- src/empathy-new-chatroom-dialog.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/empathy-new-chatroom-dialog.c b/src/empathy-new-chatroom-dialog.c index b36d0d4f5..219be371d 100644 --- a/src/empathy-new-chatroom-dialog.c +++ b/src/empathy-new-chatroom-dialog.c @@ -360,6 +360,10 @@ new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog) account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser); account = empathy_account_chooser_dup_account (account_chooser); + + if (account == NULL) + return; + protocol = empathy_account_get_protocol (account); gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), ""); -- cgit v1.2.3 From f3e15cee01791e3e6a4b624450fea6167aa02c31 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 22 Jul 2009 00:16:23 +0100 Subject: Allow stop to be called if there isn't a backing channel --- libempathy/empathy-tp-roomlist.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libempathy/empathy-tp-roomlist.c b/libempathy/empathy-tp-roomlist.c index e369373f8..54d232339 100644 --- a/libempathy/empathy-tp-roomlist.c +++ b/libempathy/empathy-tp-roomlist.c @@ -518,6 +518,10 @@ empathy_tp_roomlist_stop (EmpathyTpRoomlist *list) EmpathyTpRoomlistPriv *priv = GET_PRIV (list); g_return_if_fail (EMPATHY_IS_TP_ROOMLIST (list)); + + if (priv->channel == NULL) + return; + g_return_if_fail (TP_IS_CHANNEL (priv->channel)); tp_cli_channel_type_room_list_call_stop_listing (priv->channel, -1, -- cgit v1.2.3 From b50b7039d3b52f33df94e5a3526d9f43a51401ad Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 22 Jul 2009 19:28:28 +0100 Subject: Ensure EmpathyConnectionManagers stays alive when still emitting signals --- libempathy/empathy-connection-managers.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c index 150d6a43c..587a463a8 100644 --- a/libempathy/empathy-connection-managers.c +++ b/libempathy/empathy-connection-managers.c @@ -250,12 +250,14 @@ empathy_connection_managers_listed_cb (TpConnectionManager * const *cms, } out: + g_object_ref (weak_object); if (!priv->ready) { priv->ready = TRUE; g_object_notify (weak_object, "ready"); } g_signal_emit (weak_object, signals[UPDATED], 0); + g_object_unref (weak_object); } void -- cgit v1.2.3 From a410e0a8e2d745a94ebb96c98d63651a3f06a6dc Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 24 Jul 2009 14:34:44 +0200 Subject: Add missing includes in empathy-share-my-desktop.c --- libempathy-gtk/empathy-share-my-desktop.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libempathy-gtk/empathy-share-my-desktop.c b/libempathy-gtk/empathy-share-my-desktop.c index 4a5fce916..4c60e435f 100644 --- a/libempathy-gtk/empathy-share-my-desktop.c +++ b/libempathy-gtk/empathy-share-my-desktop.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #define DEBUG_FLAG EMPATHY_DEBUG_SHARE_DESKTOP #include -- cgit v1.2.3 From e5a8856fbc12280af273c8329ee08ba4e6e3a044 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 24 Jul 2009 14:38:13 +0200 Subject: Update gitignore --- tests/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/.gitignore b/tests/.gitignore index eac793465..2165c52d6 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -6,4 +6,4 @@ contact-run-until-ready-2 empetit test-empathy-presence-chooser test-empathy-status-preset-dialog -test-empathy-profile-chooser +test-empathy-protocol-chooser -- cgit v1.2.3 From 1bcccdbc977cc35af2edccc9b222d53a63a8c0b6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 16:46:24 +0200 Subject: Add a utility function to may protocols to their icons --- libempathy-gtk/empathy-protocol-chooser.c | 3 +-- libempathy/empathy-account.c | 2 +- libempathy/empathy-utils.c | 6 ++++++ libempathy/empathy-utils.h | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index ebb198455..c17dfc526 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -134,8 +134,7 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser, gchar *icon_name; gchar *display_name; - - icon_name = g_strdup_printf ("im-%s", proto->name); + icon_name = empathy_protocol_icon_name (proto->name); if (!tp_strdiff (cm->name, "haze")) display_name = g_strdup_printf ("%s (Haze)", proto->name); diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index cc982aea7..db2ca1f56 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -467,7 +467,7 @@ empathy_account_constructed (GObject *object) empathy_account_parse_unique_name (priv->unique_name, &(priv->proto_name), &(priv->cm_name)); - priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name); + priv->icon_name = empathy_protocol_icon_name (priv->proto_name); tp_cli_account_connect_to_account_property_changed (priv->account, empathy_account_properties_changed, diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 525f2fe06..fe54ce85a 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -363,6 +363,12 @@ empathy_uint_compare (gconstpointer a, return *(guint *) a - *(guint *) b; } +gchar * +empathy_protocol_icon_name (const gchar *protocol) +{ + return g_strdup_printf ("im-%s", protocol); +} + GType empathy_type_dbus_ao (void) { diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 3de6047f4..59ea15403 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -77,6 +77,8 @@ gboolean empathy_check_available_state (void); gint empathy_uint_compare (gconstpointer a, gconstpointer b); +gchar *empathy_protocol_icon_name (const gchar *protocol); + #define EMPATHY_ARRAY_TYPE_OBJECT (empathy_type_dbus_ao ()) GType empathy_type_dbus_ao (void); -- cgit v1.2.3 From 4c97b5730fd6c27376c6e2079262038e87fdc6c9 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 16:48:08 +0200 Subject: Fix some leaks --- libempathy-gtk/empathy-account-widget.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 21e3d3ee3..391125a5f 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -510,6 +510,8 @@ account_widget_setup_generic (EmpathyAccountSettings *settings, accounts_widget_generic_setup (settings, table_common_settings, table_advanced_settings); + + g_object_unref (builder); } static void @@ -543,7 +545,11 @@ empathy_account_widget_generic_new (EmpathyAccountSettings *settings) empathy_account_widget_add_apply_button (settings, widget); - return g_object_ref (widget); + g_free (filename); + + g_object_ref (widget); + g_object_force_floating (G_OBJECT (widget)); + return widget; } GtkWidget * -- cgit v1.2.3 From 68cf4c663ae37ef031adfbe4afaecc218df235e6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 16:50:17 +0200 Subject: Fix some coding style issues --- libempathy-gtk/empathy-protocol-chooser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index c17dfc526..65f778ac4 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -163,7 +163,7 @@ protocol_choosers_cms_listed (TpConnectionManager * const *cms, { TpConnectionManager * const *iter; - if (error !=NULL) + if (error != NULL) { DEBUG ("Failed to get connection managers: %s", error->message); return; @@ -181,7 +181,6 @@ protocol_chooser_constructed (GObject *object) { EmpathyProtocolChooser *protocol_chooser; EmpathyProtocolChooserPriv *priv; - GtkCellRenderer *renderer; TpDBusDaemon *dbus; @@ -281,7 +280,8 @@ empathy_protocol_chooser_class_init (EmpathyProtocolChooserClass *klass) * * Return value: a pointer to the selected #TpConnectionManagerProtocol */ -TpConnectionManager *empathy_protocol_chooser_dup_selected ( +TpConnectionManager * +empathy_protocol_chooser_dup_selected ( EmpathyProtocolChooser *protocol_chooser, TpConnectionManagerProtocol **protocol) { -- cgit v1.2.3 From bb2d63c7d3964a3cd68e6667a19907aa72bb686b Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 19:28:56 +0200 Subject: Unref the connection if it fails to become ready or is invalidated --- libempathy/empathy-account.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index db2ca1f56..5cf489769 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -607,6 +607,21 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) G_TYPE_NONE, 0); } +static void +empathy_account_free_connection (EmpathyAccount *account) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (priv->connection_invalidated_id != 0) + g_signal_handler_disconnect (priv->connection, + priv->connection_invalidated_id); + priv->connection_invalidated_id = 0; + + if (priv->connection != NULL) + g_object_unref (priv->connection); + priv->connection = NULL; +} + void empathy_account_dispose (GObject *object) { @@ -618,14 +633,7 @@ empathy_account_dispose (GObject *object) priv->dispose_has_run = TRUE; - if (priv->connection_invalidated_id != 0) - g_signal_handler_disconnect (priv->connection, - priv->connection_invalidated_id); - priv->connection_invalidated_id = 0; - - if (priv->connection != NULL) - g_object_unref (priv->connection); - priv->connection = NULL; + empathy_account_free_connection (self); /* release any references held by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL) @@ -785,13 +793,12 @@ empathy_account_connection_ready_cb (TpConnection *connection, gpointer user_data) { EmpathyAccount *account = EMPATHY_ACCOUNT (user_data); - EmpathyAccountPriv *priv = GET_PRIV (account); if (error != NULL) { DEBUG ("(%s) Connection failed to become ready: %s", empathy_account_get_unique_name (account), error->message); - priv->connection = NULL; + empathy_account_free_connection (account); } else { -- cgit v1.2.3 From a5a46b1dc612eb29b86f4bdfa3b3d80cb35f8893 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 20:20:57 +0200 Subject: Remove empathy_account_hash --- libempathy/empathy-utils.c | 8 -------- libempathy/empathy-utils.h | 1 - src/empathy-main-window.c | 4 ++-- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index fe54ce85a..1e1377a8d 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -227,14 +227,6 @@ empathy_xml_node_find_child_prop_value (xmlNodePtr node, return found; } -guint -empathy_account_hash (gconstpointer key) -{ - g_return_val_if_fail (EMPATHY_IS_ACCOUNT (key), 0); - - return g_str_hash (empathy_account_get_unique_name (EMPATHY_ACCOUNT (key))); -} - gboolean empathy_account_equal (gconstpointer a, gconstpointer b) diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 59ea15403..3ab4077f5 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -62,7 +62,6 @@ xmlNodePtr empathy_xml_node_find_child_prop_value (xmlNodePtr node, const gchar *prop_value); /* Others */ -guint empathy_account_hash (gconstpointer key); gboolean empathy_account_equal (gconstpointer a, gconstpointer b); const gchar * empathy_presence_get_default_message (TpConnectionPresenceType presence); diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 4a9f80f76..f8e22d91d 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -1254,8 +1254,8 @@ empathy_main_window_show (void) "account-connection-changed", G_CALLBACK (main_window_connection_changed_cb), window); - window->errors = g_hash_table_new_full (empathy_account_hash, - empathy_account_equal, + window->errors = g_hash_table_new_full (g_direct_hash, + g_direct_equal, g_object_unref, NULL); -- cgit v1.2.3 From 97d122d36a2e387ccdba9689052b0397bbe42a76 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 20:38:13 +0200 Subject: remove usage of empathy_account_equal --- libempathy-gtk/empathy-account-chooser.c | 8 +++----- libempathy-gtk/empathy-chat.c | 2 +- libempathy-gtk/empathy-log-window.c | 2 +- libempathy/empathy-chatroom-manager.c | 11 ++++------- libempathy/empathy-chatroom.c | 3 +-- libempathy/empathy-utils.c | 7 ------- libempathy/empathy-utils.h | 2 -- megaphone/src/megaphone-applet.c | 2 +- src/empathy-chat-window.c | 2 +- src/empathy-chatrooms-window.c | 2 +- 10 files changed, 13 insertions(+), 28 deletions(-) diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c index 7c6f52fa5..a91b0eb29 100644 --- a/libempathy-gtk/empathy-account-chooser.c +++ b/libempathy-gtk/empathy-account-chooser.c @@ -545,7 +545,7 @@ account_chooser_find_account_foreach (GtkTreeModel *model, gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1); - if (empathy_account_equal (account, data->account)) { + if (account == data->account) { data->found = TRUE; *(data->iter) = *iter; g_object_unref (account); @@ -688,10 +688,8 @@ account_chooser_set_account_foreach (GtkTreeModel *model, if ((data->account == NULL) != (account == NULL)) { equal = FALSE; } - else if (data->account == account) { - equal = TRUE; - } else { - equal = empathy_account_equal (data->account, account); + else { + equal = (data->account == account); } if (account) { diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index a8ca745e2..0358b0ada 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -204,7 +204,7 @@ chat_new_connection_cb (EmpathyAccountManager *manager, EmpathyAccount *account; account = empathy_account_manager_get_account (manager, connection); - if (!priv->tp_chat && empathy_account_equal (account, priv->account) && + if (!priv->tp_chat && account == priv->account && priv->handle_type != TP_HANDLE_TYPE_NONE && !EMP_STR_EMPTY (priv->id)) { diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index 7add30136..11ddca74b 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -774,7 +774,7 @@ log_window_chats_set_selected (EmpathyLogWindow *window, COL_CHAT_IS_CHATROOM, &this_is_chatroom, -1); - if (empathy_account_equal (this_account, account) && + if (this_account == account && strcmp (this_chat_id, chat_id) == 0 && this_is_chatroom == is_chatroom) { gtk_tree_selection_select_iter (selection, &iter); diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c index 649dcc9cf..c5f9864a1 100644 --- a/libempathy/empathy-chatroom-manager.c +++ b/libempathy/empathy-chatroom-manager.c @@ -580,9 +580,8 @@ empathy_chatroom_manager_find (EmpathyChatroomManager *manager, this_account = empathy_chatroom_get_account (chatroom); this_room = empathy_chatroom_get_room (chatroom); - if (this_account && this_room && - empathy_account_equal (account, this_account) && - strcmp (this_room, room) == 0) { + if (this_account && this_room && account == this_account + && strcmp (this_room, room) == 0) { return chatroom; } } @@ -611,8 +610,7 @@ empathy_chatroom_manager_get_chatrooms (EmpathyChatroomManager *manager, chatroom = l->data; - if (empathy_account_equal (account, - empathy_chatroom_get_account (chatroom))) { + if (account == empathy_chatroom_get_account (chatroom)) { chatrooms = g_list_append (chatrooms, chatroom); } } @@ -641,8 +639,7 @@ empathy_chatroom_manager_get_count (EmpathyChatroomManager *manager, chatroom = l->data; - if (empathy_account_equal (account, - empathy_chatroom_get_account (chatroom))) { + if (account == empathy_chatroom_get_account (chatroom)) { count++; } } diff --git a/libempathy/empathy-chatroom.c b/libempathy/empathy-chatroom.c index b62d6ad77..33df9a3d6 100644 --- a/libempathy/empathy-chatroom.c +++ b/libempathy/empathy-chatroom.c @@ -480,8 +480,7 @@ empathy_chatroom_equal (gconstpointer v1, room_a = empathy_chatroom_get_room (EMPATHY_CHATROOM (v1)); room_b = empathy_chatroom_get_room (EMPATHY_CHATROOM (v2)); - return empathy_account_equal (account_a, account_b) && - !tp_strdiff (room_a, room_b); + return account_a == account_b && !tp_strdiff (room_a, room_b); } EmpathyTpChat * diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 1e1377a8d..db35e94dd 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -227,13 +227,6 @@ empathy_xml_node_find_child_prop_value (xmlNodePtr node, return found; } -gboolean -empathy_account_equal (gconstpointer a, - gconstpointer b) -{ - return a == b; -} - const gchar * empathy_presence_get_default_message (TpConnectionPresenceType presence) { diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 3ab4077f5..c6aebb4f2 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -62,8 +62,6 @@ xmlNodePtr empathy_xml_node_find_child_prop_value (xmlNodePtr node, const gchar *prop_value); /* Others */ -gboolean empathy_account_equal (gconstpointer a, - gconstpointer b); const gchar * empathy_presence_get_default_message (TpConnectionPresenceType presence); const gchar * empathy_presence_to_str (TpConnectionPresenceType presence); TpConnectionPresenceType empathy_presence_from_str (const gchar *str); diff --git a/megaphone/src/megaphone-applet.c b/megaphone/src/megaphone-applet.c index 8d70d6241..1ef88ebc1 100644 --- a/megaphone/src/megaphone-applet.c +++ b/megaphone/src/megaphone-applet.c @@ -197,7 +197,7 @@ megaphone_applet_new_connection_cb (EmpathyAccountManager *manager, { MegaphoneAppletPriv *priv = GET_PRIV (applet); - if (priv->contact || !empathy_account_equal (account, priv->account)) { + if (priv->contact || account != priv->account) { return; } diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index 03644026b..9694a653c 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -1778,7 +1778,7 @@ empathy_chat_window_find_chat (EmpathyAccount *account, chat = ll->data; - if (empathy_account_equal (account, empathy_chat_get_account (chat)) && + if (account == empathy_chat_get_account (chat) && !tp_strdiff (id, empathy_chat_get_id (chat))) { return chat; } diff --git a/src/empathy-chatrooms-window.c b/src/empathy-chatrooms-window.c index 3b5dd1f77..4ec71ec49 100644 --- a/src/empathy-chatrooms-window.c +++ b/src/empathy-chatrooms-window.c @@ -514,7 +514,7 @@ chatrooms_window_chatroom_added_cb (EmpathyChatroomManager *manager, if (!account) { chatrooms_window_model_add (window, chatroom, FALSE); } else { - if (empathy_account_equal (account, empathy_chatroom_get_account (chatroom))) { + if (account == empathy_chatroom_get_account (chatroom)) { chatrooms_window_model_add (window, chatroom, FALSE); } -- cgit v1.2.3 From ac4f16973341bb7b0d9af0e668bf1c9c13a49431 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 20:38:38 +0200 Subject: Update python bindings --- python/pyempathy/pyempathy.defs | 158 +++++++++++++++++++++++++--------- python/pyempathygtk/pyempathygtk.defs | 120 ++++++++++++++++++++------ 2 files changed, 212 insertions(+), 66 deletions(-) diff --git a/python/pyempathy/pyempathy.defs b/python/pyempathy/pyempathy.defs index 003564bc5..2b8719254 100644 --- a/python/pyempathy/pyempathy.defs +++ b/python/pyempathy/pyempathy.defs @@ -206,6 +206,18 @@ ) ) +(define-flags ContactListFlags + (in-module "Empathy") + (c-name "EmpathyContactListFlags") + (gtype-id "EMPATHY_TYPE_CONTACT_LIST_FLAGS") + (values + '("add" "EMPATHY_CONTACT_LIST_CAN_ADD") + '("remove" "EMPATHY_CONTACT_LIST_CAN_REMOVE") + '("alias" "EMPATHY_CONTACT_LIST_CAN_ALIAS") + '("group" "EMPATHY_CONTACT_LIST_CAN_GROUP") + ) +) + (define-flags DebugFlags (in-module "Empathy") (c-name "EmpathyDebugFlags") @@ -220,6 +232,7 @@ '("ft" "EMPATHY_DEBUG_FT") '("location" "EMPATHY_DEBUG_LOCATION") '("other" "EMPATHY_DEBUG_OTHER") + '("share-desktop" "EMPATHY_DEBUG_SHARE_DESKTOP") ) ) @@ -277,24 +290,10 @@ (return-type "EmpathyAccountManager*") ) -(define-method create - (of-object "EmpathyAccountManager") - (c-name "empathy_account_manager_create") - (return-type "EmpathyAccount*") - (parameters - '("const-gchar*" "connection_manager") - '("const-gchar*" "protocol") - '("const-gchar*" "display_name") - ) -) - -(define-method create_by_profile +(define-method is_ready (of-object "EmpathyAccountManager") - (c-name "empathy_account_manager_create_by_profile") - (return-type "EmpathyAccount*") - (parameters - '("McProfile*" "profile") - ) + (c-name "empathy_account_manager_is_ready") + (return-type "gboolean") ) (define-method get_connected_accounts @@ -354,6 +353,52 @@ ) ) +(define-method request_global_presence + (of-object "EmpathyAccountManager") + (c-name "empathy_account_manager_request_global_presence") + (return-type "none") + (parameters + '("TpConnectionPresenceType" "type") + '("const-gchar*" "status") + '("const-gchar*" "message") + ) +) + +(define-method get_global_presence + (of-object "EmpathyAccountManager") + (c-name "empathy_account_manager_get_global_presence") + (return-type "TpConnectionPresenceType") + (parameters + '("gchar**" "status") + '("gchar**" "message") + ) +) + +(define-method create_account_async + (of-object "EmpathyAccountManager") + (c-name "empathy_account_manager_create_account_async") + (return-type "none") + (parameters + '("const-gchar*" "connection_manager") + '("const-gchar*" "protocol") + '("const-gchar*" "display_name") + '("GHashTable*" "parameters") + '("GHashTable*" "properties") + '("GAsyncReadyCallback" "callback") + '("gpointer" "user_data") + ) +) + +(define-method create_account_finish + (of-object "EmpathyAccountManager") + (c-name "empathy_account_manager_create_account_finish") + (return-type "EmpathyAccount*") + (parameters + '("GAsyncResult*" "result") + '("GError**" "error") + ) +) + ;; From empathy-chatroom.h @@ -910,6 +955,18 @@ (return-type "gboolean") ) +(define-method can_voip_audio + (of-object "EmpathyContact") + (c-name "empathy_contact_can_voip_audio") + (return-type "gboolean") +) + +(define-method can_voip_video + (of-object "EmpathyContact") + (c-name "empathy_contact_can_voip_video") + (return-type "gboolean") +) + (define-method can_send_files (of-object "EmpathyContact") (c-name "empathy_contact_can_send_files") @@ -1142,6 +1199,12 @@ (return-type "EmpathyContactMonitor*") ) +(define-method get_flags + (of-object "EmpathyContactList") + (c-name "empathy_contact_list_get_flags") + (return-type "EmpathyContactListFlags") +) + ;; From empathy-contact-manager.h @@ -1151,6 +1214,11 @@ (return-type "GType") ) +(define-function contact_manager_initialized + (c-name "empathy_contact_manager_initialized") + (return-type "gboolean") +) + (define-function contact_manager_dup_singleton (c-name "empathy_contact_manager_dup_singleton") (return-type "EmpathyContactManager*") @@ -1165,10 +1233,10 @@ ) ) -(define-method can_add +(define-method get_flags_for_connection (of-object "EmpathyContactManager") - (c-name "empathy_contact_manager_can_add") - (return-type "gboolean") + (c-name "empathy_contact_manager_get_flags_for_connection") + (return-type "EmpathyContactListFlags") (parameters '("TpConnection*" "connection") ) @@ -2153,6 +2221,21 @@ ) ) +(define-method is_backlog + (of-object "EmpathyMessage") + (c-name "empathy_message_is_backlog") + (return-type "gboolean") +) + +(define-method set_is_backlog + (of-object "EmpathyMessage") + (c-name "empathy_message_set_is_backlog") + (return-type "none") + (parameters + '("gboolean" "is_backlog") + ) +) + (define-method should_highlight (of-object "EmpathyMessage") (c-name "empathy_message_should_highlight") @@ -2867,28 +2950,6 @@ ) ) -(define-function account_hash - (c-name "empathy_account_hash") - (return-type "guint") - (parameters - '("gconstpointer" "key") - ) -) - -(define-function account_equal - (c-name "empathy_account_equal") - (return-type "gboolean") - (parameters - '("gconstpointer" "a") - '("gconstpointer" "b") - ) -) - -(define-function mission_control_dup_singleton - (c-name "empathy_mission_control_dup_singleton") - (return-type "MissionControl*") -) - (define-function presence_get_default_message (c-name "empathy_presence_get_default_message") (return-type "const-gchar*") @@ -2953,4 +3014,17 @@ ) ) +(define-function protocol_icon_name + (c-name "empathy_protocol_icon_name") + (return-type "gchar*") + (parameters + '("const-gchar*" "protocol") + ) +) + +(define-function type_dbus_ao + (c-name "empathy_type_dbus_ao") + (return-type "GType") +) + diff --git a/python/pyempathygtk/pyempathygtk.defs b/python/pyempathygtk/pyempathygtk.defs index 1eb50c30f..5b23def9a 100644 --- a/python/pyempathygtk/pyempathygtk.defs +++ b/python/pyempathygtk/pyempathygtk.defs @@ -190,6 +190,7 @@ '("is-separator" "EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR") '("can-audio-call" "EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL") '("can-video-call" "EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL") + '("flags" "EMPATHY_CONTACT_LIST_STORE_COL_FLAGS") '("count" "EMPATHY_CONTACT_LIST_STORE_COL_COUNT") ) ) @@ -327,28 +328,37 @@ ;; From empathy-account-widget.h -(define-method widget_handle_params - (of-object "EmpathyAccount") +(define-function account_widget_handle_params (c-name "empathy_account_widget_handle_params") (return-type "none") (parameters + '("EmpathyAccountSettings*" "settings") '("GtkBuilder*" "gui") '("const-gchar*" "first_widget") ) (varargs #t) ) -(define-method widget_add_forget_button - (of-object "EmpathyAccount") +(define-function account_widget_add_forget_button (c-name "empathy_account_widget_add_forget_button") (return-type "none") (parameters + '("EmpathyAccountSettings*" "settings") '("GtkBuilder*" "gui") '("const-gchar*" "button") '("const-gchar*" "entry") ) ) +(define-function account_widget_add_apply_button + (c-name "empathy_account_widget_add_apply_button") + (return-type "none") + (parameters + '("EmpathyAccountSettings*" "settings") + '("GtkWidget*" "vbox") + ) +) + (define-function account_widget_set_default_focus (c-name "empathy_account_widget_set_default_focus") (return-type "none") @@ -358,72 +368,102 @@ ) ) -(define-method widget_generic_new - (of-object "EmpathyAccount") +(define-function account_widget_generic_new (c-name "empathy_account_widget_generic_new") + (is-constructor-of "EmpathyAccountWidgetGeneric") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) -(define-method widget_salut_new - (of-object "EmpathyAccount") +(define-function account_widget_salut_new (c-name "empathy_account_widget_salut_new") + (is-constructor-of "EmpathyAccountWidgetSalut") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) -(define-method widget_msn_new - (of-object "EmpathyAccount") +(define-function account_widget_msn_new (c-name "empathy_account_widget_msn_new") + (is-constructor-of "EmpathyAccountWidgetMsn") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) -(define-method widget_jabber_new - (of-object "EmpathyAccount") +(define-function account_widget_jabber_new (c-name "empathy_account_widget_jabber_new") + (is-constructor-of "EmpathyAccountWidgetJabber") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) -(define-method widget_icq_new - (of-object "EmpathyAccount") +(define-function account_widget_icq_new (c-name "empathy_account_widget_icq_new") + (is-constructor-of "EmpathyAccountWidgetIcq") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) -(define-method widget_aim_new - (of-object "EmpathyAccount") +(define-function account_widget_aim_new (c-name "empathy_account_widget_aim_new") + (is-constructor-of "EmpathyAccountWidgetAim") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) -(define-method widget_yahoo_new - (of-object "EmpathyAccount") +(define-function account_widget_yahoo_new (c-name "empathy_account_widget_yahoo_new") + (is-constructor-of "EmpathyAccountWidgetYahoo") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) -(define-method widget_groupwise_new - (of-object "EmpathyAccount") +(define-function account_widget_groupwise_new (c-name "empathy_account_widget_groupwise_new") + (is-constructor-of "EmpathyAccountWidgetGroupwise") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) ;; From empathy-account-widget-irc.h -(define-method widget_irc_new - (of-object "EmpathyAccount") +(define-function account_widget_irc_new (c-name "empathy_account_widget_irc_new") + (is-constructor-of "EmpathyAccountWidgetIrc") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) ;; From empathy-account-widget-sip.h -(define-method widget_sip_new - (of-object "EmpathyAccount") +(define-function account_widget_sip_new (c-name "empathy_account_widget_sip_new") + (is-constructor-of "EmpathyAccountWidgetSip") (return-type "GtkWidget*") + (parameters + '("EmpathyAccountSettings*" "settings") + ) ) @@ -972,6 +1012,15 @@ ) ) +(define-function new_contact_dialog_show_with_contact + (c-name "empathy_new_contact_dialog_show_with_contact") + (return-type "none") + (parameters + '("GtkWindow*" "parent") + '("EmpathyContact*" "contact") + ) +) + ;; From empathy-contact-list-store.h @@ -1129,6 +1178,12 @@ (return-type "EmpathyContact*") ) +(define-method get_flags + (of-object "EmpathyContactListView") + (c-name "empathy_contact_list_view_get_flags") + (return-type "EmpathyContactListFlags") +) + (define-method get_selected_group (of-object "EmpathyContactListView") (c-name "empathy_contact_list_view_get_selected_group") @@ -1160,6 +1215,12 @@ ) ) +(define-method add_menu_item_new + (of-object "EmpathyContact") + (c-name "empathy_contact_add_menu_item_new") + (return-type "GtkWidget*") +) + (define-method chat_menu_item_new (of-object "EmpathyContact") (c-name "empathy_contact_chat_menu_item_new") @@ -1208,6 +1269,12 @@ (return-type "GtkWidget*") ) +(define-method share_my_desktop_menu_item_new + (of-object "EmpathyContact") + (c-name "empathy_contact_share_my_desktop_menu_item_new") + (return-type "GtkWidget*") +) + ;; From empathy-contact-selector.h @@ -1716,6 +1783,11 @@ (return-type "const-gchar**") ) +(define-function theme_manager_get_adium_themes + (c-name "empathy_theme_manager_get_adium_themes") + (return-type "GList*") +) + (define-method create_view (of-object "EmpathyThemeManager") (c-name "empathy_theme_manager_create_view") -- cgit v1.2.3 From 4b6db27ff05428dda571c5e60bc7229a4dd91d5f Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 22 Jul 2009 14:15:01 +0200 Subject: Synchronize EmpathyProtocolChooser and EmpathyAccountsDialog Synchronize the two objects with the help of EmpathyConnectionManagers, so that we can get a consistent list of the CMs when using the chooser. --- libempathy-gtk/empathy-protocol-chooser.c | 77 ++++++++++++++----------------- libempathy-gtk/empathy-protocol-chooser.h | 6 ++- tests/test-empathy-protocol-chooser.c | 8 ++-- 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index ebb198455..462979843 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -29,6 +29,7 @@ #include #include +#include #include "empathy-protocol-chooser.h" #include "empathy-ui-utils.h" @@ -59,6 +60,7 @@ typedef struct { GtkListStore *store; gboolean dispose_run; + EmpathyConnectionManagers *cms; } EmpathyProtocolChooserPriv; @@ -154,27 +156,26 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser, } } - static void -protocol_choosers_cms_listed (TpConnectionManager * const *cms, - gsize n_cms, - const GError *error, - gpointer user_data, - GObject *weak_object) +protocol_chooser_add_cms_list (EmpathyProtocolChooser *protocol_chooser, + GList *cms) { - TpConnectionManager * const *iter; + GList *l; - if (error !=NULL) - { - DEBUG ("Failed to get connection managers: %s", error->message); - return; - } + for (l = cms; l != NULL; l = l->next) + protocol_choosers_add_cm (protocol_chooser, l->data); - for (iter = cms ; iter != NULL && *iter != NULL; iter++) - protocol_choosers_add_cm (EMPATHY_PROTOCOL_CHOOSER (weak_object), - *iter); + gtk_combo_box_set_active (GTK_COMBO_BOX (protocol_chooser), 0); +} - gtk_combo_box_set_active (GTK_COMBO_BOX (weak_object), 0); +static void +protocol_chooser_cms_ready_cb (EmpathyConnectionManagers *cms, + GParamSpec *pspec, + EmpathyProtocolChooser *protocol_chooser) +{ + if (empathy_connection_managers_is_ready (cms)) + protocol_chooser_add_cms_list + (protocol_chooser, empathy_connection_managers_get_cms (cms)); } static void @@ -182,9 +183,7 @@ protocol_chooser_constructed (GObject *object) { EmpathyProtocolChooser *protocol_chooser; EmpathyProtocolChooserPriv *priv; - GtkCellRenderer *renderer; - TpDBusDaemon *dbus; priv = GET_PRIV (object); protocol_chooser = EMPATHY_PROTOCOL_CHOOSER (object); @@ -212,11 +211,6 @@ protocol_chooser_constructed (GObject *object) "text", COL_LABEL, NULL); - dbus = tp_dbus_daemon_dup (NULL); - tp_list_connection_managers (dbus, protocol_choosers_cms_listed, - NULL, NULL, object); - g_object_unref (dbus); - /* Set the protocol sort function */ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store), COL_PROTOCOL, @@ -226,6 +220,13 @@ protocol_chooser_constructed (GObject *object) COL_PROTOCOL, GTK_SORT_ASCENDING); + if (empathy_connection_managers_is_ready (priv->cms)) + protocol_chooser_add_cms_list (protocol_chooser, + empathy_connection_managers_get_cms (priv->cms)); + else + g_signal_connect (priv->cms, "notify::ready", + G_CALLBACK (protocol_chooser_cms_ready_cb), protocol_chooser); + if (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed) G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed (object); } @@ -238,6 +239,7 @@ empathy_protocol_chooser_init (EmpathyProtocolChooser *protocol_chooser) EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserPriv); priv->dispose_run = FALSE; + priv->cms = empathy_connection_managers_dup_singleton (); protocol_chooser->priv = priv; } @@ -259,6 +261,12 @@ protocol_chooser_dispose (GObject *object) priv->store = NULL; } + if (priv->cms) + { + g_object_unref (priv->cms); + priv->cms = NULL; + } + (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->dispose) (object); } @@ -273,6 +281,8 @@ empathy_protocol_chooser_class_init (EmpathyProtocolChooserClass *klass) g_type_class_add_private (object_class, sizeof (EmpathyProtocolChooserPriv)); } +/* public methods */ + /** * empathy_protocol_chooser_get_selected_protocol: * @protocol_chooser: an #EmpathyProtocolChooser @@ -307,31 +317,14 @@ TpConnectionManager *empathy_protocol_chooser_dup_selected ( return cm; } -/** - * empathy_protocol_chooser_n_protocols: - * @protocol_chooser: an #EmpathyProtocolChooser - * - * Returns the number of protocols in @protocol_chooser. - * - * Return value: the number of protocols in @protocol_chooser - */ -gint -empathy_protocol_chooser_n_protocols (EmpathyProtocolChooser *protocol_chooser) -{ - EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); - - g_return_val_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser), 0); - - return gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), NULL); -} - /** * empathy_protocol_chooser_new: * - * Creates a new #EmpathyProtocolChooser widget. + * Triggers the creation of a new #EmpathyProtocolChooser. * * Return value: a new #EmpathyProtocolChooser widget */ + GtkWidget * empathy_protocol_chooser_new (void) { diff --git a/libempathy-gtk/empathy-protocol-chooser.h b/libempathy-gtk/empathy-protocol-chooser.h index 75f9343cc..9d881958d 100644 --- a/libempathy-gtk/empathy-protocol-chooser.h +++ b/libempathy-gtk/empathy-protocol-chooser.h @@ -58,13 +58,15 @@ struct _EmpathyProtocolChooserClass GtkComboBoxClass parent_class; }; +typedef void (* EmpathyProtocolChooserReadyCb) (GtkWidget *chooser, + GError *error, + gpointer user_data); + GType empathy_protocol_chooser_get_type (void) G_GNUC_CONST; GtkWidget * empathy_protocol_chooser_new (void); TpConnectionManager *empathy_protocol_chooser_dup_selected ( EmpathyProtocolChooser *protocol_chooser, TpConnectionManagerProtocol **protocol); -gint empathy_protocol_chooser_n_protocols ( - EmpathyProtocolChooser *protocol_chooser); G_END_DECLS #endif /* __EMPATHY_PROTOCOL_CHOOSER_H__ */ diff --git a/tests/test-empathy-protocol-chooser.c b/tests/test-empathy-protocol-chooser.c index 07b1c70e1..90b1797a3 100644 --- a/tests/test-empathy-protocol-chooser.c +++ b/tests/test-empathy-protocol-chooser.c @@ -9,15 +9,15 @@ int main (int argc, char **argv) { - GtkWidget *window; - GtkWidget *chooser; + GtkWidget *window, *c; gtk_init (&argc, &argv); empathy_gtk_init (); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - chooser = empathy_protocol_chooser_new (); - gtk_container_add (GTK_CONTAINER (window), chooser); + c = empathy_protocol_chooser_new (); + + gtk_container_add (GTK_CONTAINER (window), c); /* gtk_window_set_default_size (GTK_WINDOW (window), 150, -1);*/ gtk_widget_show_all (window); -- cgit v1.2.3 From 9dfae3e6a3b7ca4751c2249590eca8317768e9b9 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 23 Jul 2009 12:31:27 +0200 Subject: Add an API to get the num of CMs --- libempathy/empathy-connection-managers.c | 12 ++++++++++++ libempathy/empathy-connection-managers.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c index 587a463a8..82699d3d6 100644 --- a/libempathy/empathy-connection-managers.c +++ b/libempathy/empathy-connection-managers.c @@ -295,3 +295,15 @@ empathy_connection_managers_get_cm (EmpathyConnectionManagers *managers, return NULL; } + +guint +empathy_connection_managers_get_cms_num (EmpathyConnectionManagers *managers) +{ + EmpathyConnectionManagersPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONNECTION_MANAGERS (managers), 0); + + priv = GET_PRIV (managers); + + return g_list_length (priv->cms); +} diff --git a/libempathy/empathy-connection-managers.h b/libempathy/empathy-connection-managers.h index 0c4147951..17289d36d 100644 --- a/libempathy/empathy-connection-managers.h +++ b/libempathy/empathy-connection-managers.h @@ -66,6 +66,8 @@ void empathy_connection_managers_update (EmpathyConnectionManagers *managers); GList * empathy_connection_managers_get_cms ( EmpathyConnectionManagers *managers); +guint empathy_connection_managers_get_cms_num + (EmpathyConnectionManagers *managers); TpConnectionManager *empathy_connection_managers_get_cm ( EmpathyConnectionManagers *managers, const gchar *cm); -- cgit v1.2.3 From 010828ac98b604438cd0edace9263cd120f4ad10 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 23 Jul 2009 12:32:23 +0200 Subject: GObject-ify and clean-up the code; still WIP --- src/empathy-accounts-dialog.c | 545 ++++++++++++++++++++++++++++-------------- src/empathy-accounts-dialog.h | 27 ++- 2 files changed, 387 insertions(+), 185 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 010493ff2..bad15b974 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -54,6 +55,11 @@ /* Flashing delay for icons (milliseconds). */ #define FLASH_TIMEOUT 500 +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog) +G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT); + +static EmpathyAccountsDialog *dialog_singleton = NULL; + typedef struct { GtkWidget *window; @@ -88,7 +94,11 @@ typedef struct { EmpathyAccountSettings *settings_ready; EmpathyAccountManager *account_manager; -} EmpathyAccountsDialog; + EmpathyConnectionManagers *cms; + + EmpathyAccount *selected_account; + GtkWindow *parent_window; +} EmpathyAccountsDialogPriv; enum { COL_ENABLED, @@ -99,6 +109,11 @@ enum { COL_COUNT }; +enum { + PROP_SELECTED_ACCOUNT = 1, + PROP_PARENT +}; + static void accounts_dialog_update (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings); static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog); @@ -153,18 +168,17 @@ static void accounts_dialog_button_import_clicked_cb (GtkWidget static void accounts_dialog_response_cb (GtkWidget *widget, gint response, EmpathyAccountsDialog *dialog); -static void accounts_dialog_destroy_cb (GtkWidget *widget, - EmpathyAccountsDialog *dialog); static void accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings) { gchar *text; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); text = g_markup_printf_escaped ("%s", empathy_account_settings_get_display_name (settings)); - gtk_label_set_markup (GTK_LABEL (dialog->label_name), text); + gtk_label_set_markup (GTK_LABEL (priv->label_name), text); g_free (text); } @@ -208,17 +222,19 @@ static void account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings) { - dialog->settings_widget = get_account_setup_widget (settings); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + priv->settings_widget = get_account_setup_widget (settings); - gtk_container_add (GTK_CONTAINER (dialog->alignment_settings), - dialog->settings_widget); - gtk_widget_show (dialog->settings_widget); + gtk_container_add (GTK_CONTAINER (priv->alignment_settings), + priv->settings_widget); + gtk_widget_show (priv->settings_widget); - gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type), + gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type), empathy_account_settings_get_icon_name (settings), GTK_ICON_SIZE_DIALOG); - gtk_widget_set_tooltip_text (dialog->image_type, + gtk_widget_set_tooltip_text (priv->image_type, empathy_account_settings_get_protocol (settings)); accounts_dialog_update_name_label (dialog, settings); @@ -236,18 +252,20 @@ static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings) { - if (dialog->settings_ready != NULL) { - g_signal_handler_disconnect (dialog->settings_ready, - dialog->settings_ready_id); - dialog->settings_ready = NULL; - dialog->settings_ready_id = 0; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + if (priv->settings_ready != NULL) { + g_signal_handler_disconnect (priv->settings_ready, + priv->settings_ready_id); + priv->settings_ready = NULL; + priv->settings_ready_id = 0; } if (!settings) { GtkTreeView *view; GtkTreeModel *model; - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); model = gtk_tree_view_get_model (view); if (gtk_tree_model_iter_n_children (model, NULL) > 0) { @@ -255,36 +273,35 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, accounts_dialog_model_select_first (dialog); return; } - if (empathy_protocol_chooser_n_protocols ( - EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol)) > 0) { + if (empathy_connection_managers_get_cms_num (priv->cms) > 0) { /* We have no account configured but we have some * profiles instsalled. The user obviously wants to add * an account. Click on the Add button for him. */ - accounts_dialog_button_add_clicked_cb (dialog->button_add, + accounts_dialog_button_add_clicked_cb (priv->button_add, dialog); return; } /* No account and no profile, warn the user */ - gtk_widget_hide (dialog->vbox_details); - gtk_widget_hide (dialog->frame_new_account); - gtk_widget_show (dialog->frame_no_protocol); - gtk_widget_set_sensitive (dialog->button_add, FALSE); - gtk_widget_set_sensitive (dialog->button_remove, FALSE); + gtk_widget_hide (priv->vbox_details); + gtk_widget_hide (priv->frame_new_account); + gtk_widget_show (priv->frame_no_protocol); + gtk_widget_set_sensitive (priv->button_add, FALSE); + gtk_widget_set_sensitive (priv->button_remove, FALSE); return; } /* We have an account selected, destroy old settings and create a new * one for the account selected */ - gtk_widget_hide (dialog->frame_new_account); - gtk_widget_hide (dialog->frame_no_protocol); - gtk_widget_show (dialog->vbox_details); - gtk_widget_set_sensitive (dialog->button_add, TRUE); - gtk_widget_set_sensitive (dialog->button_remove, TRUE); - - if (dialog->settings_widget) { - gtk_widget_destroy (dialog->settings_widget); - dialog->settings_widget = NULL; + gtk_widget_hide (priv->frame_new_account); + gtk_widget_hide (priv->frame_no_protocol); + gtk_widget_show (priv->vbox_details); + gtk_widget_set_sensitive (priv->button_add, TRUE); + gtk_widget_set_sensitive (priv->button_remove, TRUE); + + if (priv->settings_widget) { + gtk_widget_destroy (priv->settings_widget); + priv->settings_widget = NULL; } if (empathy_account_settings_is_ready (settings)) @@ -293,8 +310,8 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, } else { - dialog->settings_ready = settings; - dialog->settings_ready_id = + priv->settings_ready = settings; + priv->settings_ready_id = g_signal_connect (settings, "notify::ready", G_CALLBACK (account_dialog_settings_ready_cb), dialog); } @@ -306,6 +323,7 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog) { GtkListStore *store; GtkTreeSelection *selection; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); store = gtk_list_store_new (COL_COUNT, G_TYPE_BOOLEAN, /* enabled */ @@ -314,10 +332,10 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog) EMPATHY_TYPE_ACCOUNT, /* account */ EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */ - gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview), + gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), GTK_TREE_MODEL (store)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); g_signal_connect (selection, "changed", @@ -342,14 +360,15 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer, GtkTreeModel *model; GtkTreePath *treepath; GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) { - dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT, + if (empathy_account_manager_get_connecting_accounts (priv->account_manager) > 0) { + priv->connecting_id = g_timeout_add (FLASH_TIMEOUT, (GSourceFunc) accounts_dialog_flash_connecting_cb, dialog); } - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); treepath = gtk_tree_path_new_from_string (path); gtk_tree_model_get_iter (model, &iter, treepath); gtk_tree_model_get (model, &iter, @@ -375,8 +394,9 @@ accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer, GtkTreePath *treepath; GtkTreeIter iter; gboolean enabled; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); treepath = gtk_tree_path_new_from_string (path); gtk_tree_model_get_iter (model, &iter, treepath); gtk_tree_model_get (model, &iter, @@ -402,8 +422,10 @@ accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer, gchar *path, EmpathyAccountsDialog *dialog) { - if (dialog->connecting_id) { - g_source_remove (dialog->connecting_id); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + if (priv->connecting_id) { + g_source_remove (priv->connecting_id); } DEBUG ("Editing account name started; stopping flashing"); } @@ -414,8 +436,9 @@ accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog) GtkTreeView *view; GtkTreeViewColumn *column; GtkCellRenderer *cell; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); gtk_tree_view_set_headers_visible (view, TRUE); /* Enabled column */ @@ -468,9 +491,10 @@ accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog) GtkTreeModel *model; GtkTreeSelection *selection; GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); /* select first */ - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); model = gtk_tree_view_get_model (view); if (gtk_tree_model_get_iter_first (model, &iter)) { @@ -492,6 +516,7 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, const gchar *icon_name; GdkPixbuf *pixbuf; TpConnectionStatus status; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); gtk_tree_model_get (model, iter, COL_STATUS, &status, @@ -504,7 +529,7 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, if (pixbuf) { if (status == TP_CONNECTION_STATUS_DISCONNECTED || (status == TP_CONNECTION_STATUS_CONNECTING && - !dialog->connecting_show)) { + !priv->connecting_show)) { GdkPixbuf *modded_pixbuf; modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, @@ -542,9 +567,10 @@ accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog, GtkTreeSelection *selection; GtkTreeModel *model; gboolean ok; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); /* Update the status in the model */ - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); selection = gtk_tree_view_get_selection (view); model = gtk_tree_view_get_model (view); @@ -578,9 +604,10 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, GtkTreeSelection *selection; GtkTreeModel *model; gboolean ok; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); /* Update the status in the model */ - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); selection = gtk_tree_view_get_selection (view); model = gtk_tree_view_get_model (view); @@ -613,8 +640,9 @@ accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog) GtkTreeSelection *selection; GtkTreeIter iter; EmpathyAccountSettings *settings; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); selection = gtk_tree_view_get_selection (view); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { @@ -636,8 +664,9 @@ accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog) GtkTreeSelection *selection; GtkTreeIter iter; EmpathyAccount *account; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); selection = gtk_tree_view_get_selection (view); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { @@ -655,8 +684,9 @@ accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog, { GtkTreeSelection *selection; GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) { gtk_tree_selection_select_iter (selection, &iter); } @@ -670,8 +700,9 @@ accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog) GtkTreeSelection *selection; GtkTreeIter iter; EmpathyAccount *account; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); selection = gtk_tree_view_get_selection (view); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { @@ -714,8 +745,9 @@ accounts_dialog_add (EmpathyAccountsDialog *dialog, GtkTreeModel *model; GtkTreeIter iter; const gchar *name; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); name = empathy_account_settings_get_display_name (settings); gtk_list_store_append (GTK_LIST_STORE (model), &iter); @@ -739,8 +771,9 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, TpConnectionStatus status; const gchar *name; gboolean enabled; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); g_object_get (account, "status", &status, NULL); name = empathy_account_get_display_name (account); enabled = empathy_account_is_enabled (account); @@ -757,7 +790,7 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, COL_ACCOUNT_SETTINGS_POINTER, settings, -1); - accounts_dialog_connection_changed_cb (dialog->account_manager, + accounts_dialog_connection_changed_cb (priv->account_manager, account, TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED, status, @@ -777,8 +810,9 @@ accounts_dialog_update (EmpathyAccountsDialog *dialog, const gchar *name; gboolean enabled = FALSE; EmpathyAccount *account; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); name = empathy_account_settings_get_display_name (settings); account = empathy_account_settings_get_account (settings); @@ -813,10 +847,11 @@ accounts_dialog_account_removed_cb (EmpathyAccountManager *manager, EmpathyAccountsDialog *dialog) { GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); if (accounts_dialog_get_account_iter (dialog, account, &iter)) gtk_list_store_remove (GTK_LIST_STORE ( - gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview))), &iter); + gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter); } static gboolean @@ -835,10 +870,11 @@ accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog) { GtkTreeView *view; GtkTreeModel *model; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - dialog->connecting_show = !dialog->connecting_show; + priv->connecting_show = !priv->connecting_show; - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); model = gtk_tree_view_get_model (view); gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL); @@ -857,9 +893,10 @@ accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, GtkTreeModel *model; GtkTreeIter iter; gboolean found; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); /* Update the status in the model */ - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); if (accounts_dialog_get_account_iter (dialog, account, &iter)) { GtkTreePath *path; @@ -875,13 +912,13 @@ accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, found = (empathy_account_manager_get_connecting_accounts (manager) > 0); - if (!found && dialog->connecting_id) { - g_source_remove (dialog->connecting_id); - dialog->connecting_id = 0; + if (!found && priv->connecting_id) { + g_source_remove (priv->connecting_id); + priv->connecting_id = 0; } - if (found && !dialog->connecting_id) { - dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT, + if (found && !priv->connecting_id) { + priv->connecting_id = g_timeout_add (FLASH_TIMEOUT, (GSourceFunc) accounts_dialog_flash_connecting_cb, dialog); } @@ -894,9 +931,10 @@ enable_or_disable_account (EmpathyAccountsDialog *dialog, { GtkTreeModel *model; GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); /* Update the status in the model */ - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); DEBUG ("Account %s is now %s", empathy_account_get_display_name (account), @@ -933,8 +971,9 @@ accounts_dialog_account_changed_cb (EmpathyAccountManager *manager, EmpathyAccountSettings *settings, *selected_settings; GtkTreeModel *model; GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); if (!accounts_dialog_get_account_iter (dialog, account, &iter)) return; @@ -958,9 +997,10 @@ accounts_dialog_button_create_clicked_cb (GtkWidget *button, gchar *str; TpConnectionManager *cm; TpConnectionManagerProtocol *proto; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); cm = empathy_protocol_chooser_dup_selected ( - EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto); + EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto); /* Create account */ /* To translator: %s is the protocol name */ @@ -973,7 +1013,7 @@ accounts_dialog_button_create_clicked_cb (GtkWidget *button, if (tp_connection_manager_protocol_can_register (proto)) { gboolean active; - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register)); + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->radiobutton_register)); if (active) { empathy_account_settings_set_boolean (settings, "register", TRUE); } @@ -1002,16 +1042,17 @@ accounts_dialog_protocol_changed_cb (GtkWidget *widget, { TpConnectionManager *cm; TpConnectionManagerProtocol *proto; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); cm = empathy_protocol_chooser_dup_selected ( - EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto); + EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto); if (tp_connection_manager_protocol_can_register (proto)) { - gtk_widget_show (dialog->radiobutton_register); - gtk_widget_show (dialog->radiobutton_reuse); + gtk_widget_show (priv->radiobutton_register); + gtk_widget_show (priv->radiobutton_reuse); } else { - gtk_widget_hide (dialog->radiobutton_register); - gtk_widget_hide (dialog->radiobutton_reuse); + gtk_widget_hide (priv->radiobutton_register); + gtk_widget_hide (priv->radiobutton_reuse); } g_object_unref (cm); } @@ -1023,30 +1064,31 @@ accounts_dialog_button_add_clicked_cb (GtkWidget *button, GtkTreeView *view; GtkTreeSelection *selection; GtkTreeModel *model; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - view = GTK_TREE_VIEW (dialog->treeview); + view = GTK_TREE_VIEW (priv->treeview); model = gtk_tree_view_get_model (view); selection = gtk_tree_view_get_selection (view); gtk_tree_selection_unselect_all (selection); - gtk_widget_set_sensitive (dialog->button_add, FALSE); - gtk_widget_set_sensitive (dialog->button_remove, FALSE); - gtk_widget_hide (dialog->vbox_details); - gtk_widget_hide (dialog->frame_no_protocol); - gtk_widget_show (dialog->frame_new_account); + gtk_widget_set_sensitive (priv->button_add, FALSE); + gtk_widget_set_sensitive (priv->button_remove, FALSE); + gtk_widget_hide (priv->vbox_details); + gtk_widget_hide (priv->frame_no_protocol); + gtk_widget_show (priv->frame_new_account); /* If we have no account, no need of a back button */ if (gtk_tree_model_iter_n_children (model, NULL) > 0) { - gtk_widget_show (dialog->button_back); + gtk_widget_show (priv->button_back); } else { - gtk_widget_hide (dialog->button_back); + gtk_widget_hide (priv->button_back); } - accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse), + accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse), TRUE); - gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0); - gtk_widget_grab_focus (dialog->combobox_protocol); + gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0); + gtk_widget_grab_focus (priv->combobox_protocol); } static void @@ -1063,6 +1105,7 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button, EmpathyAccount *account; GtkWidget *message_dialog; gint res; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); account = accounts_dialog_model_get_selected_account (dialog); @@ -1072,7 +1115,7 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button, return; } message_dialog = gtk_message_dialog_new - (GTK_WINDOW (dialog->window), + (GTK_WINDOW (priv->window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, @@ -1099,7 +1142,7 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button, res = gtk_dialog_run (GTK_DIALOG (message_dialog)); if (res == GTK_RESPONSE_YES) { - empathy_account_manager_remove (dialog->account_manager, account); + empathy_account_manager_remove (priv->account_manager, account); accounts_dialog_model_select_first (dialog); } gtk_widget_destroy (message_dialog); @@ -1111,7 +1154,9 @@ static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { - empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + empathy_import_dialog_show (GTK_WINDOW (priv->window), TRUE); } #endif @@ -1126,33 +1171,109 @@ accounts_dialog_response_cb (GtkWidget *widget, } static void -accounts_dialog_destroy_cb (GtkWidget *widget, - EmpathyAccountsDialog *dialog) +accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms, + GParamSpec *pspec, + EmpathyAccountsDialog *dialog) +{ + if (empathy_connection_managers_is_ready (cms)) { + accounts_dialog_update_settings (dialog, NULL); + } +} + +static void +accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) +{ + GtkBuilder *gui; + gchar *filename; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src"); + + gui = empathy_builder_get_file (filename, + "accounts_dialog", &priv->window, + "vbox_details", &priv->vbox_details, + "frame_no_protocol", &priv->frame_no_protocol, + "alignment_settings", &priv->alignment_settings, + "treeview", &priv->treeview, + "frame_new_account", &priv->frame_new_account, + "hbox_type", &priv->hbox_type, + "button_create", &priv->button_create, + "button_back", &priv->button_back, + "radiobutton_reuse", &priv->radiobutton_reuse, + "radiobutton_register", &priv->radiobutton_register, + "image_type", &priv->image_type, + "label_name", &priv->label_name, + "button_add", &priv->button_add, + "button_remove", &priv->button_remove, + "button_import", &priv->button_import, + NULL); + g_free (filename); + + empathy_builder_connect (gui, dialog, + "accounts_dialog", "response", accounts_dialog_response_cb, + "button_create", "clicked", accounts_dialog_button_create_clicked_cb, + "button_back", "clicked", accounts_dialog_button_back_clicked_cb, + "button_add", "clicked", accounts_dialog_button_add_clicked_cb, + "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb, +#if 0 +/* FIXME MC-5 */ + "button_import", "clicked", accounts_dialog_button_import_clicked_cb, +#endif + "button_help", "clicked", accounts_dialog_button_help_clicked_cb, + NULL); + + g_object_unref (gui); + + priv->combobox_protocol = empathy_protocol_chooser_new (); + gtk_box_pack_end (GTK_BOX (priv->hbox_type), + priv->combobox_protocol, + TRUE, TRUE, 0); + gtk_widget_show (priv->combobox_protocol); + g_signal_connect (priv->combobox_protocol, "changed", + G_CALLBACK (accounts_dialog_protocol_changed_cb), + dialog); + + if (priv->parent_window) { + gtk_window_set_transient_for (GTK_WINDOW (priv->window), + priv->parent_window); + } +} + +static void +do_finalize (GObject *obj) +{ + +} + +static void +do_dispose (GObject *obj) { + EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); GList *accounts, *l; /* Disconnect signals */ - g_signal_handlers_disconnect_by_func (dialog->account_manager, + g_signal_handlers_disconnect_by_func (priv->account_manager, accounts_dialog_account_added_cb, dialog); - g_signal_handlers_disconnect_by_func (dialog->account_manager, + g_signal_handlers_disconnect_by_func (priv->account_manager, accounts_dialog_account_removed_cb, dialog); - g_signal_handlers_disconnect_by_func (dialog->account_manager, + g_signal_handlers_disconnect_by_func (priv->account_manager, accounts_dialog_account_enabled_cb, dialog); - g_signal_handlers_disconnect_by_func (dialog->account_manager, + g_signal_handlers_disconnect_by_func (priv->account_manager, accounts_dialog_account_disabled_cb, dialog); - g_signal_handlers_disconnect_by_func (dialog->account_manager, + g_signal_handlers_disconnect_by_func (priv->account_manager, accounts_dialog_account_changed_cb, dialog); - g_signal_handlers_disconnect_by_func (dialog->account_manager, + g_signal_handlers_disconnect_by_func (priv->account_manager, accounts_dialog_connection_changed_cb, dialog); /* Delete incomplete accounts */ - accounts = empathy_account_manager_dup_accounts (dialog->account_manager); + accounts = empathy_account_manager_dup_accounts (priv->account_manager); for (l = accounts; l; l = l->next) { EmpathyAccount *account; @@ -1160,140 +1281,142 @@ accounts_dialog_destroy_cb (GtkWidget *widget, if (!empathy_account_is_valid (account)) { /* FIXME: Warn the user the account is not complete * and is going to be removed. */ - empathy_account_manager_remove (dialog->account_manager, account); + empathy_account_manager_remove (priv->account_manager, account); } g_object_unref (account); } g_list_free (accounts); - if (dialog->connecting_id) { - g_source_remove (dialog->connecting_id); + if (priv->connecting_id) { + g_source_remove (priv->connecting_id); } - g_object_unref (dialog->account_manager); - - g_free (dialog); + g_object_unref (priv->account_manager); } -GtkWidget * -empathy_accounts_dialog_show (GtkWindow *parent, - EmpathyAccount *selected_account) +static GObject * +do_constructor (GType type, + guint n_props, + GObjectConstructParam *props) { - static EmpathyAccountsDialog *dialog = NULL; - GtkBuilder *gui; - gchar *filename; - GList *accounts, *l; - gboolean import_asked; + GObject *retval; - if (dialog) { - gtk_window_present (GTK_WINDOW (dialog->window)); - return dialog->window; - } + if (dialog_singleton) { + retval = G_OBJECT (dialog_singleton); + } else { + retval = G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor + (type, n_props, props); - dialog = g_new0 (EmpathyAccountsDialog, 1); + dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval); + g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton); + } - filename = empathy_file_lookup ("empathy-accounts-dialog.ui", - "src"); - gui = empathy_builder_get_file (filename, - "accounts_dialog", &dialog->window, - "vbox_details", &dialog->vbox_details, - "frame_no_protocol", &dialog->frame_no_protocol, - "alignment_settings", &dialog->alignment_settings, - "treeview", &dialog->treeview, - "frame_new_account", &dialog->frame_new_account, - "hbox_type", &dialog->hbox_type, - "button_create", &dialog->button_create, - "button_back", &dialog->button_back, - "radiobutton_reuse", &dialog->radiobutton_reuse, - "radiobutton_register", &dialog->radiobutton_register, - "image_type", &dialog->image_type, - "label_name", &dialog->label_name, - "button_add", &dialog->button_add, - "button_remove", &dialog->button_remove, - "button_import", &dialog->button_import, - NULL); - g_free (filename); + return retval; +} - empathy_builder_connect (gui, dialog, - "accounts_dialog", "destroy", accounts_dialog_destroy_cb, - "accounts_dialog", "response", accounts_dialog_response_cb, - "button_create", "clicked", accounts_dialog_button_create_clicked_cb, - "button_back", "clicked", accounts_dialog_button_back_clicked_cb, - "button_add", "clicked", accounts_dialog_button_add_clicked_cb, - "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb, -#if 0 -/* FIXME MC-5 */ - "button_import", "clicked", accounts_dialog_button_import_clicked_cb, -#endif - "button_help", "clicked", accounts_dialog_button_help_clicked_cb, - NULL); +static void +do_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountsDialogPriv *priv = GET_PRIV (object); + + switch (property_id) { + case PROP_PARENT: + g_value_set_object (value, priv->parent_window); + break; + case PROP_SELECTED_ACCOUNT: + g_value_set_object (value, priv->selected_account); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} - g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog); +static void +do_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountsDialogPriv *priv = GET_PRIV (object); + + switch (property_id) { + case PROP_PARENT: + priv->parent_window = g_value_get_object (value); + break; + case PROP_SELECTED_ACCOUNT: + priv->selected_account = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} - g_object_unref (gui); +static void +do_constructed (GObject *object) +{ + EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + GList *accounts, *l; + gboolean import_asked; - /* Create protocol chooser */ - dialog->combobox_protocol = empathy_protocol_chooser_new (); - gtk_box_pack_end (GTK_BOX (dialog->hbox_type), - dialog->combobox_protocol, - TRUE, TRUE, 0); - gtk_widget_show (dialog->combobox_protocol); - g_signal_connect (dialog->combobox_protocol, "changed", - G_CALLBACK (accounts_dialog_protocol_changed_cb), - dialog); + accounts_dialog_build_ui (dialog); /* Set up signalling */ - dialog->account_manager = empathy_account_manager_dup_singleton (); + priv->account_manager = empathy_account_manager_dup_singleton (); - g_signal_connect (dialog->account_manager, "account-created", + g_signal_connect (priv->account_manager, "account-created", G_CALLBACK (accounts_dialog_account_added_cb), dialog); - g_signal_connect (dialog->account_manager, "account-deleted", + g_signal_connect (priv->account_manager, "account-deleted", G_CALLBACK (accounts_dialog_account_removed_cb), dialog); - g_signal_connect (dialog->account_manager, "account-enabled", + g_signal_connect (priv->account_manager, "account-enabled", G_CALLBACK (accounts_dialog_account_enabled_cb), dialog); - g_signal_connect (dialog->account_manager, "account-disabled", + g_signal_connect (priv->account_manager, "account-disabled", G_CALLBACK (accounts_dialog_account_disabled_cb), dialog); - g_signal_connect (dialog->account_manager, "account-changed", + g_signal_connect (priv->account_manager, "account-changed", G_CALLBACK (accounts_dialog_account_changed_cb), dialog); - g_signal_connect (dialog->account_manager, "account-connection-changed", + g_signal_connect (priv->account_manager, "account-connection-changed", G_CALLBACK (accounts_dialog_connection_changed_cb), dialog); accounts_dialog_model_setup (dialog); /* Add existing accounts */ - accounts = empathy_account_manager_dup_accounts (dialog->account_manager); + accounts = empathy_account_manager_dup_accounts (priv->account_manager); for (l = accounts; l; l = l->next) { accounts_dialog_add_account (dialog, l->data); g_object_unref (l->data); } g_list_free (accounts); - if (selected_account) { + priv->cms = empathy_connection_managers_dup_singleton (); + if (!empathy_connection_managers_is_ready (priv->cms)) { + g_signal_connect (priv->cms, "notify::ready", + G_CALLBACK (accounts_dialog_cms_ready_cb), dialog); + } + + if (priv->selected_account) { GtkTreeSelection *selection; GtkTreeIter iter; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview)); - if (accounts_dialog_get_account_iter (dialog, selected_account, &iter)) { + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + if (accounts_dialog_get_account_iter (dialog, priv->selected_account, &iter)) { gtk_tree_selection_select_iter (selection, &iter); } + + priv->selected_account = NULL; } else { accounts_dialog_model_select_first (dialog); } - if (parent) { - gtk_window_set_transient_for (GTK_WINDOW (dialog->window), - GTK_WINDOW (parent)); - } - - gtk_widget_show (dialog->window); - empathy_conf_get_bool (empathy_conf_get (), EMPATHY_PREFS_IMPORT_ASKED, &import_asked); @@ -1305,14 +1428,70 @@ empathy_accounts_dialog_show (GtkWindow *parent, if (!import_asked) { empathy_conf_set_bool (empathy_conf_get (), EMPATHY_PREFS_IMPORT_ASKED, TRUE); - empathy_import_dialog_show (GTK_WINDOW (dialog->window), + empathy_import_dialog_show (GTK_WINDOW (priv->window), FALSE); } } else { - gtk_widget_set_sensitive (dialog->button_import, FALSE); + gtk_widget_set_sensitive (priv->button_import, FALSE); } #endif +} - return dialog->window; +static void +empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + oclass->constructor = do_constructor; + oclass->finalize = do_finalize; + oclass->dispose = do_dispose; + oclass->constructed = do_constructed; + oclass->set_property = do_set_property; + oclass->get_property = do_get_property; + + param_spec = g_param_spec_object ("parent", + "parent", "The parent window", + GTK_TYPE_WINDOW, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_PARENT, param_spec); + + param_spec = g_param_spec_object ("selected-account", + "selected-account", "The account selected by default", + EMPATHY_TYPE_ACCOUNT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_SELECTED_ACCOUNT, param_spec); + + + g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv)); } +static void +empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog) +{ + EmpathyAccountsDialogPriv *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog), + EMPATHY_TYPE_ACCOUNTS_DIALOG, + EmpathyAccountsDialogPriv); + dialog->priv = priv; +} + +/* public methods */ + +GtkWidget * +empathy_accounts_dialog_show (GtkWindow *parent, + EmpathyAccount *selected_account) +{ + EmpathyAccountsDialog *dialog; + EmpathyAccountsDialogPriv *priv; + + dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG, + "parent", parent, "selected-account", selected_account, NULL); + + priv = GET_PRIV (dialog); + + gtk_window_present (GTK_WINDOW (priv->window)); + + return priv->window; +} diff --git a/src/empathy-accounts-dialog.h b/src/empathy-accounts-dialog.h index 11e237c8f..aa8f7c06b 100644 --- a/src/empathy-accounts-dialog.h +++ b/src/empathy-accounts-dialog.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2005-2007 Imendio AB * Copyright (C) 2007-2008 Collabora Ltd. @@ -31,8 +30,32 @@ G_BEGIN_DECLS +#define EMPATHY_TYPE_ACCOUNTS_DIALOG empathy_accounts_dialog_get_type() +#define EMPATHY_ACCOUNTS_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNTS_DIALOG, EmpathyAccountsDialog)) +#define EMPATHY_ACCOUNTS_DIALOG_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNTS_DIALOG, EmpathyAccountsDialogClass)) +#define EMPATHY_IS_ACCOUNTS_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNTS_DIALOG)) +#define EMPATHY_IS_ACCOUNTS_DIALOG_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNTS_DIALOG)) +#define EMPATHY_ACCOUNTS_DIALOG_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNTS_DIALOG, EmpathyAccountsDialogClass)) + +typedef struct { + GObject parent; + + /* private */ + gpointer priv; +} EmpathyAccountsDialog; + +typedef struct { + GObjectClass parent_class; +} EmpathyAccountsDialogClass; + +GType empathy_accounts_dialog_get_type (void); GtkWidget *empathy_accounts_dialog_show (GtkWindow *parent, - EmpathyAccount *selected_account); + EmpathyAccount *selected_account); G_END_DECLS -- cgit v1.2.3 From 43208e2ee8fe2371d0562f37d817173857a91268 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 23 Jul 2009 16:21:12 +0200 Subject: Move some code off dispose --- src/empathy-accounts-dialog.c | 49 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index bad15b974..f2b433618 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1165,7 +1165,29 @@ accounts_dialog_response_cb (GtkWidget *widget, gint response, EmpathyAccountsDialog *dialog) { + GList *accounts, *l; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + if (response == GTK_RESPONSE_CLOSE) { + /* Delete incomplete accounts */ + accounts = empathy_account_manager_dup_accounts + (priv->account_manager); + for (l = accounts; l; l = l->next) { + EmpathyAccount *account; + + account = l->data; + if (!empathy_account_is_valid (account)) { + /* FIXME: Warn the user the account is not + * complete and is going to be removed. + */ + empathy_account_manager_remove + (priv->account_manager, account); + } + + g_object_unref (account); + } + g_list_free (accounts); + gtk_widget_destroy (widget); } } @@ -1250,7 +1272,6 @@ do_dispose (GObject *obj) { EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj); EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - GList *accounts, *l; /* Disconnect signals */ g_signal_handlers_disconnect_by_func (priv->account_manager, @@ -1272,27 +1293,19 @@ do_dispose (GObject *obj) accounts_dialog_connection_changed_cb, dialog); - /* Delete incomplete accounts */ - accounts = empathy_account_manager_dup_accounts (priv->account_manager); - for (l = accounts; l; l = l->next) { - EmpathyAccount *account; - - account = l->data; - if (!empathy_account_is_valid (account)) { - /* FIXME: Warn the user the account is not complete - * and is going to be removed. */ - empathy_account_manager_remove (priv->account_manager, account); - } - - g_object_unref (account); - } - g_list_free (accounts); - if (priv->connecting_id) { g_source_remove (priv->connecting_id); } - g_object_unref (priv->account_manager); + if (priv->account_manager != NULL) { + g_object_unref (priv->account_manager); + priv->account_manager = NULL; + } + + if (priv->cms != NULL) { + g_object_unref (priv->cms); + priv->cms = NULL; + } } static GObject * -- cgit v1.2.3 From 5a729c2ae7018c491216eedc93129fa483cab181 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 23 Jul 2009 16:22:38 +0200 Subject: Chain up dispose and remove useless finalize --- src/empathy-accounts-dialog.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index f2b433618..68f140ff5 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1261,12 +1261,6 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) } } -static void -do_finalize (GObject *obj) -{ - -} - static void do_dispose (GObject *obj) { @@ -1306,6 +1300,8 @@ do_dispose (GObject *obj) g_object_unref (priv->cms); priv->cms = NULL; } + + G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj); } static GObject * @@ -1457,7 +1453,6 @@ empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass) GParamSpec *param_spec; oclass->constructor = do_constructor; - oclass->finalize = do_finalize; oclass->dispose = do_dispose; oclass->constructed = do_constructed; oclass->set_property = do_set_property; -- cgit v1.2.3 From d5c41662829057e80268b6771fbe7452aa36a814 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 23 Jul 2009 16:27:36 +0200 Subject: Unref the dialog when destroying --- src/empathy-accounts-dialog.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 68f140ff5..6ac9eb352 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1192,6 +1192,15 @@ accounts_dialog_response_cb (GtkWidget *widget, } } +static void +accounts_dialog_destroy_cb (GtkObject *obj, + EmpathyAccountsDialog *dialog) +{ + DEBUG ("%p", obj); + + g_object_unref (dialog); +} + static void accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms, GParamSpec *pspec, @@ -1233,6 +1242,7 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) empathy_builder_connect (gui, dialog, "accounts_dialog", "response", accounts_dialog_response_cb, + "accounts_dialog", "destroy", accounts_dialog_destroy_cb, "button_create", "clicked", accounts_dialog_button_create_clicked_cb, "button_back", "clicked", accounts_dialog_button_back_clicked_cb, "button_add", "clicked", accounts_dialog_button_add_clicked_cb, -- cgit v1.2.3 From 68d69476f586e377ce45af014f7e4eeb8acd3b8d Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 23 Jul 2009 19:22:30 +0200 Subject: Respect the global presence when enabling an account --- libempathy/empathy-account-manager.c | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 7339acb9f..09bb68126 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -55,6 +55,13 @@ typedef struct { TpConnectionPresenceType global_presence; gchar *global_status; gchar *global_status_message; + + /* desired global presence, could be different + * from the actual global one. + */ + TpConnectionPresenceType desired_presence; + gchar *desired_status; + gchar *desired_status_message; } EmpathyAccountManagerPriv; enum { @@ -769,8 +776,6 @@ empathy_account_manager_request_global_presence ( const gchar *status, const gchar *message) { - /* FIXME should remember requested presence and set it on new accounts - as well */ EmpathyAccountManagerPriv *priv = GET_PRIV (manager); GHashTableIter iter; gpointer value; @@ -786,6 +791,23 @@ empathy_account_manager_request_global_presence ( if (ready) empathy_account_request_presence (account, type, status, message); } + + /* save the requested global presence, to use it in case we create + * new accounts. + */ + priv->desired_presence = type; + + if (tp_strdiff (priv->desired_status, status)) + { + g_free (priv->desired_status); + priv->desired_status = g_strdup (status); + } + + if (tp_strdiff (priv->desired_status_message, message)) + { + g_free (priv->desired_status_message); + priv->desired_status_message = g_strdup (message); + } } TpConnectionPresenceType @@ -875,6 +897,9 @@ EmpathyAccount * empathy_account_manager_create_account_finish ( EmpathyAccountManager *manager, GAsyncResult *result, GError **error) { + EmpathyAccount *retval; + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) return NULL; @@ -882,7 +907,15 @@ empathy_account_manager_create_account_finish ( g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), empathy_account_manager_create_account_finish), NULL); - return EMPATHY_ACCOUNT (g_simple_async_result_get_op_res_gpointer ( + retval = EMPATHY_ACCOUNT (g_simple_async_result_get_op_res_gpointer ( G_SIMPLE_ASYNC_RESULT (result))); + + /* if we have an account, it's ready, as we waited for it. + * request the global presence now. + */ + empathy_account_request_presence (retval, priv->desired_presence, + priv->desired_status, priv->desired_status_message); + + return retval; } -- cgit v1.2.3 From 9b7a3c09518ca7fee43c0c8941a0c1d49261871e Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 23 Jul 2009 19:23:04 +0200 Subject: Plug some leaks --- libempathy/empathy-account-manager.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 09bb68126..96e2e538f 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -439,6 +439,12 @@ do_finalize (GObject *obj) g_hash_table_destroy (priv->accounts); + g_free (priv->global_status); + g_free (priv->global_status_message); + + g_free (priv->desired_status); + g_free (priv->desired_status_message); + G_OBJECT_CLASS (empathy_account_manager_parent_class)->finalize (obj); } -- cgit v1.2.3 From 113d262b56effb7927d310ca90db3da5840e2dc9 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 23 Jul 2009 19:23:27 +0200 Subject: Make remove work --- src/empathy-accounts-dialog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 6ac9eb352..3b5386606 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1142,7 +1142,7 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button, res = gtk_dialog_run (GTK_DIALOG (message_dialog)); if (res == GTK_RESPONSE_YES) { - empathy_account_manager_remove (priv->account_manager, account); + accounts_dialog_model_remove_selected (dialog); accounts_dialog_model_select_first (dialog); } gtk_widget_destroy (message_dialog); -- cgit v1.2.3 From 45c7f5469ed08aeda3d54bf375d129cab5194cde Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 24 Jul 2009 01:45:59 +0200 Subject: When an account is enabled, always align it to the global presence. Before, this was only done for newly created accounts, and not every time any account was enabled. --- libempathy/empathy-account-manager.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 96e2e538f..55f9da837 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -104,8 +104,16 @@ emp_account_enabled_cb (EmpathyAccount *account, GParamSpec *spec, gpointer manager) { + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + if (empathy_account_is_enabled (account)) - g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account); + { + g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account); + + /* set the desired global presence on the account */ + empathy_account_request_presence (account, priv->desired_presence, + priv->desired_status, priv->desired_status_message); + } else g_signal_emit (manager, signals[ACCOUNT_DISABLED], 0, account); } @@ -904,7 +912,6 @@ empathy_account_manager_create_account_finish ( EmpathyAccountManager *manager, GAsyncResult *result, GError **error) { EmpathyAccount *retval; - EmpathyAccountManagerPriv *priv = GET_PRIV (manager); if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) @@ -916,12 +923,6 @@ empathy_account_manager_create_account_finish ( retval = EMPATHY_ACCOUNT (g_simple_async_result_get_op_res_gpointer ( G_SIMPLE_ASYNC_RESULT (result))); - /* if we have an account, it's ready, as we waited for it. - * request the global presence now. - */ - empathy_account_request_presence (retval, priv->desired_presence, - priv->desired_status, priv->desired_status_message); - return retval; } -- cgit v1.2.3 From e3ed5ba84d20da177070d4708bca4bdb9d0ee149 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 24 Jul 2009 15:52:29 +0200 Subject: Implement _set_display_name --- libempathy/empathy-account-settings.c | 46 +++++++++++++++++++++++++++ libempathy/empathy-account.c | 59 +++++++++++++++++++++++++++++++++++ libempathy/empathy-account.h | 7 +++-- 3 files changed, 110 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 2763f0702..989d2d355 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -799,6 +799,26 @@ empathy_account_settings_set_boolean (EmpathyAccountSettings *settings, tp_asv_set_boolean (priv->parameters, param, value); } +static void +account_settings_display_name_set_cb (GObject *src, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + EmpathyAccount *account = EMPATHY_ACCOUNT (src); + GSimpleAsyncResult *set_result = user_data; + + empathy_account_set_display_name_finish (account, res, &error); + + if (error != NULL) + { + g_simple_async_result_set_from_error (set_result, error); + g_error_free (error); + } + + g_simple_async_result_complete (set_result); + g_object_unref (set_result); +} void empathy_account_settings_set_display_name_async ( @@ -807,6 +827,26 @@ empathy_account_settings_set_display_name_async ( GAsyncReadyCallback callback, gpointer user_data) { + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + GSimpleAsyncResult *result; + + result = g_simple_async_result_new (G_OBJECT (settings), + callback, user_data, empathy_account_settings_set_display_name_finish); + + if (priv->account == NULL) + { + if (priv->display_name != NULL) + g_free (priv->display_name); + + priv->display_name = g_strdup (name); + + g_simple_async_result_complete_in_idle (result); + + return; + } + + empathy_account_set_display_name_async (priv->account, name, + account_settings_display_name_set_cb, result); } gboolean @@ -815,6 +855,12 @@ empathy_account_settings_set_display_name_finish ( GAsyncResult *result, GError **error) { + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (settings), empathy_account_settings_set_display_name_finish), FALSE); return TRUE; } diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index cc982aea7..bb55abed7 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -32,6 +32,8 @@ #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include +#include + #include "empathy-account.h" #include "empathy-utils.h" #include "empathy-marshal.h" @@ -987,6 +989,63 @@ empathy_account_update_settings_finish (EmpathyAccount *account, return TRUE; } +static void +account_display_name_set_cb (TpProxy *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) + g_simple_async_result_set_from_error (result, (GError *) error); + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +void +empathy_account_set_display_name_async (EmpathyAccount *account, + const char *display_name, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + GValue value = {0, }; + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (display_name == NULL) + { + g_simple_async_report_error_in_idle (G_OBJECT (account), + callback, user_data, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, + _("Can't set an empty display name")); + return; + } + + result = g_simple_async_result_new (G_OBJECT (account), callback, + user_data, empathy_account_set_display_name_finish); + + g_value_init (&value, G_TYPE_STRING); + g_value_set_string (&value, display_name); + + tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT, + "DisplayName", &value, account_display_name_set_cb, result, NULL, + G_OBJECT (account)); +} + +gboolean +empathy_account_set_display_name_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error) || + !g_simple_async_result_is_valid (result, G_OBJECT (account), + empathy_account_set_display_name_finish)) + return FALSE; + + return TRUE; +} + static void empathy_account_remove_cb (TpAccount *proxy, const GError *error, diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 00daa46ee..67939d748 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -84,8 +84,11 @@ void empathy_account_remove_async (EmpathyAccount *account, gboolean empathy_account_remove_finish (EmpathyAccount *account, GAsyncResult *result, GError **error); -void empathy_account_set_display_name (EmpathyAccount *account, - const gchar *display_name); +void empathy_account_set_display_name_async (EmpathyAccount *account, + const gchar *display_name, GAsyncReadyCallback callback, + gpointer user_data); +gboolean empathy_account_set_display_name_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error); EmpathyAccount *empathy_account_new (TpDBusDaemon *bus_daemon, const gchar *unique_name); -- cgit v1.2.3 From 6d59456848be4257df0724a610ef224d8c1d2e84 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 24 Jul 2009 21:24:38 +0200 Subject: Make sure the account dialog respects the initial selection --- src/empathy-accounts-dialog.c | 64 +++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 3b5386606..a9a5e7f63 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -96,8 +96,8 @@ typedef struct { EmpathyAccountManager *account_manager; EmpathyConnectionManagers *cms; - EmpathyAccount *selected_account; GtkWindow *parent_window; + EmpathyAccount *initial_selection; } EmpathyAccountsDialogPriv; enum { @@ -110,8 +110,7 @@ enum { }; enum { - PROP_SELECTED_ACCOUNT = 1, - PROP_PARENT + PROP_PARENT = 1 }; static void accounts_dialog_update (EmpathyAccountsDialog *dialog, @@ -1201,13 +1200,34 @@ accounts_dialog_destroy_cb (GtkObject *obj, g_object_unref (dialog); } +static void +accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog, + EmpathyAccount *account) +{ + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + if (accounts_dialog_get_account_iter (dialog, account, &iter)) { + gtk_tree_selection_select_iter (selection, &iter); + } +} + static void accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms, GParamSpec *pspec, EmpathyAccountsDialog *dialog) { + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + if (empathy_connection_managers_is_ready (cms)) { accounts_dialog_update_settings (dialog, NULL); + + if (priv->initial_selection != NULL) { + accounts_dialog_set_selected_account (dialog, priv->initial_selection); + priv->initial_selection = NULL; + } } } @@ -1346,9 +1366,6 @@ do_get_property (GObject *object, case PROP_PARENT: g_value_set_object (value, priv->parent_window); break; - case PROP_SELECTED_ACCOUNT: - g_value_set_object (value, priv->selected_account); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -1366,9 +1383,6 @@ do_set_property (GObject *object, case PROP_PARENT: priv->parent_window = g_value_get_object (value); break; - case PROP_SELECTED_ACCOUNT: - priv->selected_account = g_value_get_object (value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -1422,19 +1436,7 @@ do_constructed (GObject *object) G_CALLBACK (accounts_dialog_cms_ready_cb), dialog); } - if (priv->selected_account) { - GtkTreeSelection *selection; - GtkTreeIter iter; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); - if (accounts_dialog_get_account_iter (dialog, priv->selected_account, &iter)) { - gtk_tree_selection_select_iter (selection, &iter); - } - - priv->selected_account = NULL; - } else { - accounts_dialog_model_select_first (dialog); - } + accounts_dialog_model_select_first (dialog); empathy_conf_get_bool (empathy_conf_get (), EMPATHY_PREFS_IMPORT_ASKED, &import_asked); @@ -1474,13 +1476,6 @@ empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (oclass, PROP_PARENT, param_spec); - param_spec = g_param_spec_object ("selected-account", - "selected-account", "The account selected by default", - EMPATHY_TYPE_ACCOUNT, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (oclass, PROP_SELECTED_ACCOUNT, param_spec); - - g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv)); } @@ -1505,10 +1500,19 @@ empathy_accounts_dialog_show (GtkWindow *parent, EmpathyAccountsDialogPriv *priv; dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG, - "parent", parent, "selected-account", selected_account, NULL); + "parent", parent, NULL); priv = GET_PRIV (dialog); + if (selected_account && empathy_connection_managers_is_ready (priv->cms)) { + accounts_dialog_set_selected_account (dialog, selected_account); + } else { + /* save the selection to set it later when the cms + * becomes ready. + */ + priv->initial_selection = selected_account; + } + gtk_window_present (GTK_WINDOW (priv->window)); return priv->window; -- cgit v1.2.3 From 7f8d4b20123d1f3f48ddaf404b022bdeeba5d99a Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 25 Jul 2009 16:44:14 +0200 Subject: Add empathy_account_settings_owns_account() --- libempathy/empathy-account-settings.c | 14 ++++++++++++++ libempathy/empathy-account-settings.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 989d2d355..4e32dfcfa 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -1008,3 +1008,17 @@ empathy_account_settings_apply_finish (EmpathyAccountSettings *settings, return TRUE; } + +gboolean +empathy_account_settings_owns_account (EmpathyAccountSettings *settings, + EmpathyAccount *account) +{ + EmpathyAccountSettingsPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE); + g_return_val_if_fail (EMPATHY_IS_ACCOUNT (account), FALSE); + + priv = GET_PRIV (settings); + + return (account == priv->account); +} diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h index d9231a50a..8119879cc 100644 --- a/libempathy/empathy-account-settings.h +++ b/libempathy/empathy-account-settings.h @@ -77,6 +77,9 @@ const gchar *empathy_account_settings_get_protocol ( EmpathyAccount *empathy_account_settings_get_account ( EmpathyAccountSettings *settings); +gboolean empathy_account_settings_owns_account ( + EmpathyAccountSettings *settings, EmpathyAccount *account); + TpConnectionManagerParam *empathy_account_settings_get_tp_params ( EmpathyAccountSettings *settings); -- cgit v1.2.3 From 7823b045d9b6a00102a44b40943d7d2188412521 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 25 Jul 2009 16:45:01 +0200 Subject: Use the new API when getting the account iter. --- src/empathy-accounts-dialog.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index a9a5e7f63..f358be8b4 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -613,15 +613,16 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, for (ok = gtk_tree_model_get_iter_first (model, iter); ok; ok = gtk_tree_model_iter_next (model, iter)) { - EmpathyAccount *this_account; + EmpathyAccountSettings *settings; gboolean equal; gtk_tree_model_get (model, iter, - COL_ACCOUNT_POINTER, &this_account, + COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); - equal = (this_account == account); - g_object_unref (this_account); + equal = empathy_account_settings_owns_account + (settings, account); + g_object_unref (settings); if (equal) { return TRUE; @@ -777,7 +778,9 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, name = empathy_account_get_display_name (account); enabled = empathy_account_is_enabled (account); - gtk_list_store_append (GTK_LIST_STORE (model), &iter); + if (!accounts_dialog_get_account_iter (dialog, account, &iter)) { + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + } settings = empathy_account_settings_new_for_account (account); -- cgit v1.2.3 From b3970ee62ba17348a793cc2d2e617f403216f728 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 25 Jul 2009 16:46:32 +0200 Subject: Emit the ACCOUNT_CREATED signal at the right time I.e. emit it only after the account has been added to the relevant EmpathyAccountSettings object. --- libempathy/empathy-account-manager.c | 67 +++++++++++++++++------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 55f9da837..b9694a95b 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -62,6 +62,8 @@ typedef struct { TpConnectionPresenceType desired_presence; gchar *desired_status; gchar *desired_status_message; + + GSimpleAsyncResult *create_result; } EmpathyAccountManagerPriv; enum { @@ -276,9 +278,12 @@ empathy_account_manager_check_ready (EmpathyAccountManager *manager) } static void -emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) +account_manager_account_ready_cb (GObject *obj, + GParamSpec *spec, + gpointer user_data) { EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); EmpathyAccount *account = EMPATHY_ACCOUNT (obj); gboolean ready; @@ -287,6 +292,15 @@ emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) if (!ready) return; + if (priv->create_result) + { + g_simple_async_result_set_op_res_gpointer ( + G_SIMPLE_ASYNC_RESULT (priv->create_result), account, NULL); + + g_simple_async_result_complete (priv->create_result); + g_object_unref (priv->create_result); + } + g_signal_emit (manager, signals[ACCOUNT_CREATED], 0, account); g_signal_connect (account, "notify::connection", @@ -307,7 +321,7 @@ emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) empathy_account_manager_check_ready (manager); } -static EmpathyAccount * +static void account_manager_add_account (EmpathyAccountManager *manager, const gchar *path) { @@ -316,15 +330,13 @@ account_manager_add_account (EmpathyAccountManager *manager, account = g_hash_table_lookup (priv->accounts, path); if (account != NULL) - return account; + return; account = empathy_account_new (priv->dbus, path); g_hash_table_insert (priv->accounts, g_strdup (path), account); g_signal_connect (account, "notify::ready", - G_CALLBACK (emp_account_ready_cb), manager); - - return account; + G_CALLBACK (account_manager_account_ready_cb), manager); } static void @@ -840,22 +852,6 @@ empathy_account_manager_get_global_presence ( return priv->global_presence; } -static void -empathy_account_manager_created_ready_cb (EmpathyAccount *account, - GParamSpec *spec, gpointer user_data) -{ - GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); - - if (!empathy_account_is_ready (account)) - return; - - g_simple_async_result_set_op_res_gpointer ( - G_SIMPLE_ASYNC_RESULT (result), account, NULL); - - g_simple_async_result_complete (result); - g_object_unref (G_OBJECT (result)); -} - static void empathy_account_manager_created_cb (TpAccountManager *proxy, const gchar *account_path, @@ -864,23 +860,20 @@ empathy_account_manager_created_cb (TpAccountManager *proxy, GObject *weak_object) { EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); - GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); - EmpathyAccount *account; + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); if (error != NULL) { - g_simple_async_result_set_from_error (result, (GError *) error); - g_simple_async_result_complete (result); - g_object_unref (G_OBJECT (result)); + g_simple_async_result_set_from_error (priv->create_result, + (GError *) error); + g_simple_async_result_complete (priv->create_result); + g_object_unref (priv->create_result); + priv->create_result = NULL; + return; } - account = account_manager_add_account (manager, account_path); - if (empathy_account_is_ready (account)) - empathy_account_manager_created_ready_cb (account, NULL, result); - else - g_signal_connect (account, "notify::ready", - G_CALLBACK (empathy_account_manager_created_ready_cb), result); + account_manager_add_account (manager, account_path); } void @@ -891,8 +884,10 @@ empathy_account_manager_create_account_async (EmpathyAccountManager *manager, GAsyncReadyCallback callback, gpointer user_data) { EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (manager), - callback, user_data, empathy_account_manager_create_account_finish); + + priv->create_result = g_simple_async_result_new + (G_OBJECT (manager), callback, user_data, + empathy_account_manager_create_account_finish); tp_cli_account_manager_call_create_account (priv->tp_manager, -1, @@ -902,7 +897,7 @@ empathy_account_manager_create_account_async (EmpathyAccountManager *manager, parameters, properties, empathy_account_manager_created_cb, - result, + NULL, NULL, G_OBJECT (manager)); } -- cgit v1.2.3 From 8159c9cf091d3474702df58b04dcd11783109ab7 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 25 Jul 2009 17:01:33 +0200 Subject: Cancel the creation thread in dispose() --- libempathy/empathy-account-manager.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index b9694a95b..2d6977d3c 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -299,6 +299,7 @@ account_manager_account_ready_cb (GObject *obj, g_simple_async_result_complete (priv->create_result); g_object_unref (priv->create_result); + priv->create_result = NULL; } g_signal_emit (manager, signals[ACCOUNT_CREATED], 0, account); @@ -479,6 +480,16 @@ do_dispose (GObject *obj) priv->dispose_run = TRUE; + if (priv->create_result != NULL) + { + g_simple_async_result_set_error (priv->create_result, G_IO_ERROR, + G_IO_ERROR_CANCELLED, "The account manager was disposed while " + "creating the account"); + g_simple_async_result_complete (priv->create_result); + g_object_unref (priv->create_result); + priv->create_result = NULL; + } + tp_dbus_daemon_cancel_name_owner_watch (priv->dbus, TP_ACCOUNT_MANAGER_BUS_NAME, account_manager_name_owner_cb, manager); -- cgit v1.2.3 From 604cd696cf2af3995a3bba6317b3684255a08fc2 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 25 Jul 2009 17:02:20 +0200 Subject: Fix a typo in dispose() --- libempathy/empathy-account-manager.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 2d6977d3c..71cf34fb9 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -493,9 +493,11 @@ do_dispose (GObject *obj) tp_dbus_daemon_cancel_name_owner_watch (priv->dbus, TP_ACCOUNT_MANAGER_BUS_NAME, account_manager_name_owner_cb, manager); - if (priv->dbus == NULL) - g_object_unref (priv->dbus); - priv->dbus = NULL; + if (priv->dbus != NULL) + { + g_object_unref (priv->dbus); + priv->dbus = NULL; + } G_OBJECT_CLASS (empathy_account_manager_parent_class)->dispose (obj); } -- cgit v1.2.3 From ab51e3524e667dce95c9b792a9cd051f4070d668 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 25 Jul 2009 17:23:38 +0200 Subject: Use the right property name when getting the connection status. --- src/empathy-accounts-dialog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index f358be8b4..35acf69e8 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -774,7 +774,7 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - g_object_get (account, "status", &status, NULL); + g_object_get (account, "connection-status", &status, NULL); name = empathy_account_get_display_name (account); enabled = empathy_account_is_enabled (account); -- cgit v1.2.3 From 0613221d61c564e4931cf3f62cc95109e71f4c6c Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 25 Jul 2009 18:20:40 +0200 Subject: Adapt to the current telepathy style --- src/empathy-accounts-dialog.c | 2318 ++++++++++++++++++++--------------------- 1 file changed, 1146 insertions(+), 1172 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 35acf69e8..339c53b96 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -37,6 +37,7 @@ #include #include #include + #include #include #include @@ -61,125 +62,79 @@ G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT); static EmpathyAccountsDialog *dialog_singleton = NULL; typedef struct { - GtkWidget *window; + GtkWidget *window; - GtkWidget *alignment_settings; + GtkWidget *alignment_settings; - GtkWidget *vbox_details; - GtkWidget *frame_no_protocol; + GtkWidget *vbox_details; + GtkWidget *frame_no_protocol; - GtkWidget *treeview; + GtkWidget *treeview; - GtkWidget *button_add; - GtkWidget *button_remove; - GtkWidget *button_import; + GtkWidget *button_add; + GtkWidget *button_remove; + GtkWidget *button_import; - GtkWidget *frame_new_account; - GtkWidget *combobox_protocol; - GtkWidget *hbox_type; - GtkWidget *button_create; - GtkWidget *button_back; - GtkWidget *radiobutton_reuse; - GtkWidget *radiobutton_register; + GtkWidget *frame_new_account; + GtkWidget *combobox_protocol; + GtkWidget *hbox_type; + GtkWidget *button_create; + GtkWidget *button_back; + GtkWidget *radiobutton_reuse; + GtkWidget *radiobutton_register; - GtkWidget *image_type; - GtkWidget *label_name; - GtkWidget *label_type; - GtkWidget *settings_widget; + GtkWidget *image_type; + GtkWidget *label_name; + GtkWidget *label_type; + GtkWidget *settings_widget; - gboolean connecting_show; - guint connecting_id; + gboolean connecting_show; + guint connecting_id; - gulong settings_ready_id; - EmpathyAccountSettings *settings_ready; + gulong settings_ready_id; + EmpathyAccountSettings *settings_ready; - EmpathyAccountManager *account_manager; - EmpathyConnectionManagers *cms; + EmpathyAccountManager *account_manager; + EmpathyConnectionManagers *cms; - GtkWindow *parent_window; - EmpathyAccount *initial_selection; + GtkWindow *parent_window; + EmpathyAccount *initial_selection; } EmpathyAccountsDialogPriv; enum { - COL_ENABLED, - COL_NAME, - COL_STATUS, - COL_ACCOUNT_POINTER, - COL_ACCOUNT_SETTINGS_POINTER, - COL_COUNT + COL_ENABLED, + COL_NAME, + COL_STATUS, + COL_ACCOUNT_POINTER, + COL_ACCOUNT_SETTINGS_POINTER, + COL_COUNT }; enum { - PROP_PARENT = 1 + PROP_PARENT = 1 }; -static void accounts_dialog_update (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings); -static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog); -static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog); -static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer, - GtkCellEditable *editable, - gchar *path, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog); -static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings); -static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog); -static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountsDialog *dialog); -static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer user_data); -static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog); -static void accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - TpConnectionStatusReason reason, - TpConnectionStatus current, - TpConnectionStatus previous, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_button_create_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_button_back_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_button_add_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_button_help_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog); -static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog); +static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings); + #if 0 /* FIXME MC-5 */ static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog); + EmpathyAccountsDialog *dialog); #endif -static void accounts_dialog_response_cb (GtkWidget *widget, - gint response, - EmpathyAccountsDialog *dialog); static void accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings) + EmpathyAccountSettings *settings) { - gchar *text; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + gchar *text; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - text = g_markup_printf_escaped ("%s", - empathy_account_settings_get_display_name (settings)); - gtk_label_set_markup (GTK_LABEL (priv->label_name), text); + text = g_markup_printf_escaped ("%s", + empathy_account_settings_get_display_name (settings)); + gtk_label_set_markup (GTK_LABEL (priv->label_name), text); - g_free (text); + g_free (text); } typedef GtkWidget *CreateWidget (EmpathyAccountSettings *); @@ -187,1336 +142,1355 @@ typedef GtkWidget *CreateWidget (EmpathyAccountSettings *); static GtkWidget * get_account_setup_widget (EmpathyAccountSettings *settings) { - const gchar *cm = empathy_account_settings_get_cm (settings); - const gchar *proto = empathy_account_settings_get_protocol (settings); - 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 (settings); - } - - return empathy_account_widget_generic_new (settings); + const gchar *cm = empathy_account_settings_get_cm (settings); + const gchar *proto = empathy_account_settings_get_protocol (settings); + 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 (settings); + } + + return empathy_account_widget_generic_new (settings); } static void account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings) + EmpathyAccountSettings *settings) { - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - priv->settings_widget = get_account_setup_widget (settings); + priv->settings_widget = get_account_setup_widget (settings); - gtk_container_add (GTK_CONTAINER (priv->alignment_settings), - priv->settings_widget); - gtk_widget_show (priv->settings_widget); + gtk_container_add (GTK_CONTAINER (priv->alignment_settings), + priv->settings_widget); + gtk_widget_show (priv->settings_widget); - gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type), - empathy_account_settings_get_icon_name (settings), - GTK_ICON_SIZE_DIALOG); - gtk_widget_set_tooltip_text (priv->image_type, - empathy_account_settings_get_protocol (settings)); + gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type), + empathy_account_settings_get_icon_name (settings), + GTK_ICON_SIZE_DIALOG); + gtk_widget_set_tooltip_text (priv->image_type, + empathy_account_settings_get_protocol (settings)); - accounts_dialog_update_name_label (dialog, settings); + accounts_dialog_update_name_label (dialog, settings); } static void account_dialog_settings_ready_cb (EmpathyAccountSettings *settings, - GParamSpec *spec, EmpathyAccountsDialog *dialog) + GParamSpec *spec, + EmpathyAccountsDialog *dialog) { - if (empathy_account_settings_is_ready (settings)) - account_dialog_create_settings_widget (dialog, settings); + if (empathy_account_settings_is_ready (settings)) + account_dialog_create_settings_widget (dialog, settings); } static void -accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings) +accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog) { - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - if (priv->settings_ready != NULL) { - g_signal_handler_disconnect (priv->settings_ready, - priv->settings_ready_id); - priv->settings_ready = NULL; - priv->settings_ready_id = 0; - } - - if (!settings) { - GtkTreeView *view; - GtkTreeModel *model; - - view = GTK_TREE_VIEW (priv->treeview); - model = gtk_tree_view_get_model (view); - - if (gtk_tree_model_iter_n_children (model, NULL) > 0) { - /* We have configured accounts, select the first one */ - accounts_dialog_model_select_first (dialog); - return; - } - if (empathy_connection_managers_get_cms_num (priv->cms) > 0) { - /* We have no account configured but we have some - * profiles instsalled. The user obviously wants to add - * an account. Click on the Add button for him. */ - accounts_dialog_button_add_clicked_cb (priv->button_add, - dialog); - return; - } - - /* No account and no profile, warn the user */ - gtk_widget_hide (priv->vbox_details); - gtk_widget_hide (priv->frame_new_account); - gtk_widget_show (priv->frame_no_protocol); - gtk_widget_set_sensitive (priv->button_add, FALSE); - gtk_widget_set_sensitive (priv->button_remove, FALSE); - return; - } - - /* We have an account selected, destroy old settings and create a new - * one for the account selected */ - gtk_widget_hide (priv->frame_new_account); - gtk_widget_hide (priv->frame_no_protocol); - gtk_widget_show (priv->vbox_details); - gtk_widget_set_sensitive (priv->button_add, TRUE); - gtk_widget_set_sensitive (priv->button_remove, TRUE); - - if (priv->settings_widget) { - gtk_widget_destroy (priv->settings_widget); - priv->settings_widget = NULL; - } - - if (empathy_account_settings_is_ready (settings)) - { - account_dialog_create_settings_widget (dialog, settings); - } - else - { - priv->settings_ready = settings; - priv->settings_ready_id = - g_signal_connect (settings, "notify::ready", - G_CALLBACK (account_dialog_settings_ready_cb), dialog); - } - + GtkTreeView *view; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + /* select first */ + view = GTK_TREE_VIEW (priv->treeview); + model = gtk_tree_view_get_model (view); + + if (gtk_tree_model_get_iter_first (model, &iter)) + { + selection = gtk_tree_view_get_selection (view); + gtk_tree_selection_select_iter (selection, &iter); + } + else + { + accounts_dialog_update_settings (dialog, NULL); + } } static void -accounts_dialog_model_setup (EmpathyAccountsDialog *dialog) +accounts_dialog_protocol_changed_cb (GtkWidget *widget, + EmpathyAccountsDialog *dialog) { - GtkListStore *store; - GtkTreeSelection *selection; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - store = gtk_list_store_new (COL_COUNT, - G_TYPE_BOOLEAN, /* enabled */ - G_TYPE_STRING, /* name */ - G_TYPE_UINT, /* status */ - EMPATHY_TYPE_ACCOUNT, /* account */ - EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */ - - gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), - GTK_TREE_MODEL (store)); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - - g_signal_connect (selection, "changed", - G_CALLBACK (accounts_dialog_model_selection_changed), - dialog); - - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), - COL_NAME, GTK_SORT_ASCENDING); - - accounts_dialog_model_add_columns (dialog); - - g_object_unref (store); + TpConnectionManager *cm; + TpConnectionManagerProtocol *proto; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + cm = empathy_protocol_chooser_dup_selected ( + EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto); + + if (tp_connection_manager_protocol_can_register (proto)) + { + gtk_widget_show (priv->radiobutton_register); + gtk_widget_show (priv->radiobutton_reuse); + } + else + { + gtk_widget_hide (priv->radiobutton_register); + gtk_widget_hide (priv->radiobutton_reuse); + } + g_object_unref (cm); } static void -accounts_dialog_name_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - EmpathyAccountsDialog *dialog) +accounts_dialog_button_add_clicked_cb (GtkWidget *button, + EmpathyAccountsDialog *dialog) { - EmpathyAccountSettings *settings; - GtkTreeModel *model; - GtkTreePath *treepath; - GtkTreeIter iter; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - if (empathy_account_manager_get_connecting_accounts (priv->account_manager) > 0) { - priv->connecting_id = g_timeout_add (FLASH_TIMEOUT, - (GSourceFunc) accounts_dialog_flash_connecting_cb, - dialog); - } - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - treepath = gtk_tree_path_new_from_string (path); - gtk_tree_model_get_iter (model, &iter, treepath); - gtk_tree_model_get (model, &iter, - COL_ACCOUNT_SETTINGS_POINTER, &settings, - -1); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_NAME, new_text, - -1); - gtk_tree_path_free (treepath); - - empathy_account_settings_set_display_name_async (settings, new_text, - NULL, NULL); - g_object_unref (settings); + GtkTreeView *view; + GtkTreeSelection *selection; + GtkTreeModel *model; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + view = GTK_TREE_VIEW (priv->treeview); + model = gtk_tree_view_get_model (view); + selection = gtk_tree_view_get_selection (view); + gtk_tree_selection_unselect_all (selection); + + gtk_widget_set_sensitive (priv->button_add, FALSE); + gtk_widget_set_sensitive (priv->button_remove, FALSE); + gtk_widget_hide (priv->vbox_details); + gtk_widget_hide (priv->frame_no_protocol); + gtk_widget_show (priv->frame_new_account); + + /* If we have no account, no need of a back button */ + if (gtk_tree_model_iter_n_children (model, NULL) > 0) + gtk_widget_show (priv->button_back); + else + gtk_widget_hide (priv->button_back); + + accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse), + TRUE); + gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0); + gtk_widget_grab_focus (priv->combobox_protocol); } static void -accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer, - gchar *path, - EmpathyAccountsDialog *dialog) +accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings) { - EmpathyAccount *account; - GtkTreeModel *model; - GtkTreePath *treepath; - GtkTreeIter iter; - gboolean enabled; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - treepath = gtk_tree_path_new_from_string (path); - gtk_tree_model_get_iter (model, &iter, treepath); - gtk_tree_model_get (model, &iter, - COL_ACCOUNT_POINTER, &account, - -1); - gtk_tree_path_free (treepath); - - if (account == NULL) - return; - - enabled = empathy_account_is_enabled (account); - empathy_account_set_enabled (account, !enabled); - - DEBUG ("%s account %s", enabled ? "Disabled" : "Enable", - empathy_account_get_display_name (account)); - - g_object_unref (account); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + if (priv->settings_ready != NULL) + { + g_signal_handler_disconnect (priv->settings_ready, + priv->settings_ready_id); + priv->settings_ready = NULL; + priv->settings_ready_id = 0; + } + + if (!settings) + { + GtkTreeView *view; + GtkTreeModel *model; + + view = GTK_TREE_VIEW (priv->treeview); + model = gtk_tree_view_get_model (view); + + if (gtk_tree_model_iter_n_children (model, NULL) > 0) + { + /* We have configured accounts, select the first one */ + accounts_dialog_model_select_first (dialog); + return; + } + if (empathy_connection_managers_get_cms_num (priv->cms) > 0) + { + /* We have no account configured but we have some + * profiles instsalled. The user obviously wants to add + * an account. Click on the Add button for him. */ + accounts_dialog_button_add_clicked_cb (priv->button_add, + dialog); + return; + } + + /* No account and no profile, warn the user */ + gtk_widget_hide (priv->vbox_details); + gtk_widget_hide (priv->frame_new_account); + gtk_widget_show (priv->frame_no_protocol); + gtk_widget_set_sensitive (priv->button_add, FALSE); + gtk_widget_set_sensitive (priv->button_remove, FALSE); + return; + } + + /* We have an account selected, destroy old settings and create a new + * one for the account selected */ + gtk_widget_hide (priv->frame_new_account); + gtk_widget_hide (priv->frame_no_protocol); + gtk_widget_show (priv->vbox_details); + gtk_widget_set_sensitive (priv->button_add, TRUE); + gtk_widget_set_sensitive (priv->button_remove, TRUE); + + if (priv->settings_widget) + { + gtk_widget_destroy (priv->settings_widget); + priv->settings_widget = NULL; + } + + if (empathy_account_settings_is_ready (settings)) + { + account_dialog_create_settings_widget (dialog, settings); + } + else + { + priv->settings_ready = settings; + priv->settings_ready_id = + g_signal_connect (settings, "notify::ready", + G_CALLBACK (account_dialog_settings_ready_cb), dialog); + } + } static void -accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer, - GtkCellEditable *editable, - gchar *path, - EmpathyAccountsDialog *dialog) +accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer, + GtkCellEditable *editable, + gchar *path, + EmpathyAccountsDialog *dialog) { - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - if (priv->connecting_id) { - g_source_remove (priv->connecting_id); - } - DEBUG ("Editing account name started; stopping flashing"); + if (priv->connecting_id) + g_source_remove (priv->connecting_id); + + DEBUG ("Editing account name started; stopping flashing"); } static void -accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog) +accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + EmpathyAccountsDialog *dialog) { - GtkTreeView *view; - GtkTreeViewColumn *column; - GtkCellRenderer *cell; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - view = GTK_TREE_VIEW (priv->treeview); - gtk_tree_view_set_headers_visible (view, TRUE); - - /* Enabled column */ - cell = gtk_cell_renderer_toggle_new (); - gtk_tree_view_insert_column_with_attributes (view, -1, - _("Enabled"), - cell, - "active", COL_ENABLED, - NULL); - g_signal_connect (cell, "toggled", - G_CALLBACK (accounts_dialog_enable_toggled_cb), - dialog); - - /* Account column */ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Accounts")); - gtk_tree_view_column_set_expand (column, TRUE); - gtk_tree_view_append_column (view, column); - - /* Icon renderer */ - cell = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (column, cell, FALSE); - gtk_tree_view_column_set_cell_data_func (column, cell, - (GtkTreeCellDataFunc) - accounts_dialog_model_pixbuf_data_func, - dialog, - NULL); - - /* Name renderer */ - cell = gtk_cell_renderer_text_new (); - g_object_set (cell, - "ellipsize", PANGO_ELLIPSIZE_END, - "width-chars", 25, - "editable", TRUE, - NULL); - gtk_tree_view_column_pack_start (column, cell, TRUE); - gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME); - g_signal_connect (cell, "edited", - G_CALLBACK (accounts_dialog_name_edited_cb), - dialog); - g_signal_connect (cell, "editing-started", - G_CALLBACK (accounts_dialog_name_editing_started_cb), - dialog); + EmpathyAccountSettings *settings; + const gchar *icon_name; + GdkPixbuf *pixbuf; + TpConnectionStatus status; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + gtk_tree_model_get (model, iter, + COL_STATUS, &status, + COL_ACCOUNT_SETTINGS_POINTER, &settings, + -1); + + icon_name = empathy_account_settings_get_icon_name (settings); + pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); + + if (pixbuf) + { + if (status == TP_CONNECTION_STATUS_DISCONNECTED || + (status == TP_CONNECTION_STATUS_CONNECTING && + !priv->connecting_show)) + { + GdkPixbuf *modded_pixbuf; + + modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, + TRUE, + 8, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf)); + + gdk_pixbuf_saturate_and_pixelate (pixbuf, + modded_pixbuf, + 1.0, + TRUE); + g_object_unref (pixbuf); + pixbuf = modded_pixbuf; + } + } + + g_object_set (cell, + "visible", TRUE, + "pixbuf", pixbuf, + NULL); + + g_object_unref (settings); + + if (pixbuf) + g_object_unref (pixbuf); } static void -accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog) +accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer, + gchar *path, + EmpathyAccountsDialog *dialog) { - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - /* select first */ - view = GTK_TREE_VIEW (priv->treeview); - model = gtk_tree_view_get_model (view); - - if (gtk_tree_model_get_iter_first (model, &iter)) { - selection = gtk_tree_view_get_selection (view); - gtk_tree_selection_select_iter (selection, &iter); - } else { - accounts_dialog_update_settings (dialog, NULL); - } + EmpathyAccount *account; + GtkTreeModel *model; + GtkTreePath *treepath; + GtkTreeIter iter; + gboolean enabled; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + treepath = gtk_tree_path_new_from_string (path); + gtk_tree_model_get_iter (model, &iter, treepath); + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_POINTER, &account, + -1); + gtk_tree_path_free (treepath); + + if (account == NULL) + return; + + enabled = empathy_account_is_enabled (account); + empathy_account_set_enabled (account, !enabled); + + DEBUG ("%s account %s", enabled ? "Disabled" : "Enable", + empathy_account_get_display_name (account)); + + g_object_unref (account); } -static void -accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyAccountsDialog *dialog) +static gboolean +accounts_dialog_row_changed_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer user_data) { - EmpathyAccountSettings *settings; - const gchar *icon_name; - GdkPixbuf *pixbuf; - TpConnectionStatus status; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - gtk_tree_model_get (model, iter, - COL_STATUS, &status, - COL_ACCOUNT_SETTINGS_POINTER, &settings, - -1); - - icon_name = empathy_account_settings_get_icon_name (settings); - pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); - - if (pixbuf) { - if (status == TP_CONNECTION_STATUS_DISCONNECTED || - (status == TP_CONNECTION_STATUS_CONNECTING && - !priv->connecting_show)) { - GdkPixbuf *modded_pixbuf; - - modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, - TRUE, - 8, - gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf)); - - gdk_pixbuf_saturate_and_pixelate (pixbuf, - modded_pixbuf, - 1.0, - TRUE); - g_object_unref (pixbuf); - pixbuf = modded_pixbuf; - } - } - - g_object_set (cell, - "visible", TRUE, - "pixbuf", pixbuf, - NULL); - - g_object_unref (settings); - if (pixbuf) { - g_object_unref (pixbuf); - } + gtk_tree_model_row_changed (model, path, iter); + + return FALSE; } static gboolean -accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings, - GtkTreeIter *iter) +accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog) { - GtkTreeView *view; - GtkTreeSelection *selection; - GtkTreeModel *model; - gboolean ok; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - /* Update the status in the model */ - view = GTK_TREE_VIEW (priv->treeview); - selection = gtk_tree_view_get_selection (view); - model = gtk_tree_view_get_model (view); - - for (ok = gtk_tree_model_get_iter_first (model, iter); - ok; - ok = gtk_tree_model_iter_next (model, iter)) { - EmpathyAccountSettings *this_settings; - gboolean equal; - - gtk_tree_model_get (model, iter, - COL_ACCOUNT_SETTINGS_POINTER, &this_settings, - -1); - - equal = (this_settings == settings); - g_object_unref (this_settings); - - if (equal) { - return TRUE; - } - } - - return FALSE; + GtkTreeView *view; + GtkTreeModel *model; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + priv->connecting_show = !priv->connecting_show; + + view = GTK_TREE_VIEW (priv->treeview); + model = gtk_tree_view_get_model (view); + + gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL); + + return TRUE; } -static gboolean -accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, - EmpathyAccount *account, - GtkTreeIter *iter) +static void +accounts_dialog_name_edited_cb (GtkCellRendererText *renderer, + gchar *path, + gchar *new_text, + EmpathyAccountsDialog *dialog) { - GtkTreeView *view; - GtkTreeSelection *selection; - GtkTreeModel *model; - gboolean ok; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - /* Update the status in the model */ - view = GTK_TREE_VIEW (priv->treeview); - selection = gtk_tree_view_get_selection (view); - model = gtk_tree_view_get_model (view); - - for (ok = gtk_tree_model_get_iter_first (model, iter); - ok; - ok = gtk_tree_model_iter_next (model, iter)) { - EmpathyAccountSettings *settings; - gboolean equal; - - gtk_tree_model_get (model, iter, - COL_ACCOUNT_SETTINGS_POINTER, &settings, - -1); - - equal = empathy_account_settings_owns_account - (settings, account); - g_object_unref (settings); - - if (equal) { - return TRUE; - } - } - - return FALSE; + EmpathyAccountSettings *settings; + GtkTreeModel *model; + GtkTreePath *treepath; + GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + if (empathy_account_manager_get_connecting_accounts (priv->account_manager) > 0) + { + priv->connecting_id = g_timeout_add (FLASH_TIMEOUT, + (GSourceFunc) accounts_dialog_flash_connecting_cb, + dialog); + } + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + treepath = gtk_tree_path_new_from_string (path); + gtk_tree_model_get_iter (model, &iter, treepath); + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_SETTINGS_POINTER, &settings, + -1); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_NAME, new_text, + -1); + gtk_tree_path_free (treepath); + + empathy_account_settings_set_display_name_async (settings, new_text, + NULL, NULL); + g_object_unref (settings); +} + +static void +accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog) +{ + GtkTreeView *view; + GtkTreeViewColumn *column; + GtkCellRenderer *cell; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + view = GTK_TREE_VIEW (priv->treeview); + gtk_tree_view_set_headers_visible (view, TRUE); + + /* Enabled column */ + cell = gtk_cell_renderer_toggle_new (); + gtk_tree_view_insert_column_with_attributes (view, -1, + _("Enabled"), + cell, + "active", COL_ENABLED, + NULL); + g_signal_connect (cell, "toggled", + G_CALLBACK (accounts_dialog_enable_toggled_cb), + dialog); + + /* Account column */ + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_title (column, _("Accounts")); + gtk_tree_view_column_set_expand (column, TRUE); + gtk_tree_view_append_column (view, column); + + /* Icon renderer */ + cell = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (column, cell, FALSE); + gtk_tree_view_column_set_cell_data_func (column, cell, + (GtkTreeCellDataFunc) + accounts_dialog_model_pixbuf_data_func, + dialog, + NULL); + + /* Name renderer */ + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, + "ellipsize", PANGO_ELLIPSIZE_END, + "width-chars", 25, + "editable", TRUE, + NULL); + gtk_tree_view_column_pack_start (column, cell, TRUE); + gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME); + g_signal_connect (cell, "edited", + G_CALLBACK (accounts_dialog_name_edited_cb), + dialog); + g_signal_connect (cell, "editing-started", + G_CALLBACK (accounts_dialog_name_editing_started_cb), + dialog); } static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog) { - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - EmpathyAccountSettings *settings; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + GtkTreeView *view; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccountSettings *settings; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + view = GTK_TREE_VIEW (priv->treeview); + selection = gtk_tree_view_get_selection (view); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return NULL; + + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); + + return settings; +} - view = GTK_TREE_VIEW (priv->treeview); - selection = gtk_tree_view_get_selection (view); +static void +accounts_dialog_model_selection_changed (GtkTreeSelection *selection, + EmpathyAccountsDialog *dialog) +{ + EmpathyAccountSettings *settings; + GtkTreeModel *model; + GtkTreeIter iter; + gboolean is_selection; - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { - return NULL; - } + is_selection = gtk_tree_selection_get_selected (selection, &model, &iter); - gtk_tree_model_get (model, &iter, - COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); + settings = accounts_dialog_model_get_selected_settings (dialog); + accounts_dialog_update_settings (dialog, settings); - return settings; + if (settings) + g_object_unref (settings); } - -static EmpathyAccount * -accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog) +static void +accounts_dialog_model_setup (EmpathyAccountsDialog *dialog) { - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - EmpathyAccount *account; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + GtkListStore *store; + GtkTreeSelection *selection; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + store = gtk_list_store_new (COL_COUNT, + G_TYPE_BOOLEAN, /* enabled */ + G_TYPE_STRING, /* name */ + G_TYPE_UINT, /* status */ + EMPATHY_TYPE_ACCOUNT, /* account */ + EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */ + + gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), + GTK_TREE_MODEL (store)); - view = GTK_TREE_VIEW (priv->treeview); - selection = gtk_tree_view_get_selection (view); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { - return NULL; - } + g_signal_connect (selection, "changed", + G_CALLBACK (accounts_dialog_model_selection_changed), + dialog); - gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), + COL_NAME, GTK_SORT_ASCENDING); - return account; + accounts_dialog_model_add_columns (dialog); + + g_object_unref (store); } -static void -accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings) +static gboolean +accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings, + GtkTreeIter *iter) { - GtkTreeSelection *selection; - GtkTreeIter iter; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); - if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) { - gtk_tree_selection_select_iter (selection, &iter); - } + GtkTreeView *view; + GtkTreeSelection *selection; + GtkTreeModel *model; + gboolean ok; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + /* Update the status in the model */ + view = GTK_TREE_VIEW (priv->treeview); + selection = gtk_tree_view_get_selection (view); + model = gtk_tree_view_get_model (view); + + for (ok = gtk_tree_model_get_iter_first (model, iter); + ok; + ok = gtk_tree_model_iter_next (model, iter)) + { + EmpathyAccountSettings *this_settings; + gboolean equal; + + gtk_tree_model_get (model, iter, + COL_ACCOUNT_SETTINGS_POINTER, &this_settings, + -1); + + equal = (this_settings == settings); + g_object_unref (this_settings); + + if (equal) + return TRUE; + } + + return FALSE; } static gboolean -accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog) +accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, + EmpathyAccount *account, + GtkTreeIter *iter) { - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - EmpathyAccount *account; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - view = GTK_TREE_VIEW (priv->treeview); - selection = gtk_tree_view_get_selection (view); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { - return FALSE; - } - - gtk_tree_model_get (model, &iter, - COL_ACCOUNT_POINTER, &account, - -1); - - if (account != NULL) - empathy_account_remove_async (account, NULL, NULL); + GtkTreeView *view; + GtkTreeSelection *selection; + GtkTreeModel *model; + gboolean ok; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + /* Update the status in the model */ + view = GTK_TREE_VIEW (priv->treeview); + selection = gtk_tree_view_get_selection (view); + model = gtk_tree_view_get_model (view); + + for (ok = gtk_tree_model_get_iter_first (model, iter); + ok; + ok = gtk_tree_model_iter_next (model, iter)) + { + EmpathyAccountSettings *settings; + gboolean equal; + + gtk_tree_model_get (model, iter, + COL_ACCOUNT_SETTINGS_POINTER, &settings, + -1); + + equal = empathy_account_settings_owns_account + (settings, account); + g_object_unref (settings); + + if (equal) + return TRUE; + } + + return FALSE; +} - return gtk_list_store_remove (GTK_LIST_STORE (model), &iter); +static EmpathyAccount * +accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog) +{ + GtkTreeView *view; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccount *account; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + view = GTK_TREE_VIEW (priv->treeview); + selection = gtk_tree_view_get_selection (view); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return NULL; + + gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1); + + return account; } static void -accounts_dialog_model_selection_changed (GtkTreeSelection *selection, - EmpathyAccountsDialog *dialog) +accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings) { - EmpathyAccountSettings *settings; - GtkTreeModel *model; - GtkTreeIter iter; - gboolean is_selection; - - is_selection = gtk_tree_selection_get_selected (selection, &model, &iter); + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - settings = accounts_dialog_model_get_selected_settings (dialog); - accounts_dialog_update_settings (dialog, settings); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) + gtk_tree_selection_select_iter (selection, &iter); +} - if (settings) { - g_object_unref (settings); - } +static gboolean +accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog) +{ + GtkTreeView *view; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccount *account; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + view = GTK_TREE_VIEW (priv->treeview); + selection = gtk_tree_view_get_selection (view); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return FALSE; + + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_POINTER, &account, + -1); + + if (account != NULL) + empathy_account_remove_async (account, NULL, NULL); + + return gtk_list_store_remove (GTK_LIST_STORE (model), &iter); } static void accounts_dialog_add (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings) + EmpathyAccountSettings *settings) { - GtkTreeModel *model; - GtkTreeIter iter; - const gchar *name; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - name = empathy_account_settings_get_display_name (settings); - - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ENABLED, FALSE, - COL_NAME, name, - COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED, - COL_ACCOUNT_SETTINGS_POINTER, settings, - -1); + GtkTreeModel *model; + GtkTreeIter iter; + const gchar *name; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + name = empathy_account_settings_get_display_name (settings); + + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_ENABLED, FALSE, + COL_NAME, name, + COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED, + COL_ACCOUNT_SETTINGS_POINTER, settings, + -1); } +static void +accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, + EmpathyAccount *account, + TpConnectionStatusReason reason, + TpConnectionStatus current, + TpConnectionStatus previous, + EmpathyAccountsDialog *dialog) +{ + GtkTreeModel *model; + GtkTreeIter iter; + gboolean found; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + /* Update the status in the model */ + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + + if (accounts_dialog_get_account_iter (dialog, account, &iter)) + { + GtkTreePath *path; + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_STATUS, current, + -1); + + path = gtk_tree_model_get_path (model, &iter); + gtk_tree_model_row_changed (model, path, &iter); + gtk_tree_path_free (path); + } + + found = (empathy_account_manager_get_connecting_accounts (manager) > 0); + + if (!found && priv->connecting_id) + { + g_source_remove (priv->connecting_id); + priv->connecting_id = 0; + } + + if (found && !priv->connecting_id) + priv->connecting_id = g_timeout_add (FLASH_TIMEOUT, + (GSourceFunc) accounts_dialog_flash_connecting_cb, + dialog); +} static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account) + EmpathyAccount *account) { - EmpathyAccountSettings *settings; - GtkTreeModel *model; - GtkTreeIter iter; - TpConnectionStatus status; - const gchar *name; - gboolean enabled; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - g_object_get (account, "connection-status", &status, NULL); - name = empathy_account_get_display_name (account); - enabled = empathy_account_is_enabled (account); - - if (!accounts_dialog_get_account_iter (dialog, account, &iter)) { - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - } - - settings = empathy_account_settings_new_for_account (account); - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ENABLED, enabled, - COL_NAME, name, - COL_STATUS, status, - COL_ACCOUNT_POINTER, account, - COL_ACCOUNT_SETTINGS_POINTER, settings, - -1); - - accounts_dialog_connection_changed_cb (priv->account_manager, - account, - TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED, - status, - TP_CONNECTION_STATUS_DISCONNECTED, - dialog); - - g_object_unref (settings); + EmpathyAccountSettings *settings; + GtkTreeModel *model; + GtkTreeIter iter; + TpConnectionStatus status; + const gchar *name; + gboolean enabled; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + g_object_get (account, "connection-status", &status, NULL); + name = empathy_account_get_display_name (account); + enabled = empathy_account_is_enabled (account); + + if (!accounts_dialog_get_account_iter (dialog, account, &iter)) + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + + settings = empathy_account_settings_new_for_account (account); + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_ENABLED, enabled, + COL_NAME, name, + COL_STATUS, status, + COL_ACCOUNT_POINTER, account, + COL_ACCOUNT_SETTINGS_POINTER, settings, + -1); + + accounts_dialog_connection_changed_cb (priv->account_manager, + account, + TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED, + status, + TP_CONNECTION_STATUS_DISCONNECTED, + dialog); + + g_object_unref (settings); } static void accounts_dialog_update (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings) + EmpathyAccountSettings *settings) { - GtkTreeModel *model; - GtkTreeIter iter; - TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED; - const gchar *name; - gboolean enabled = FALSE; - EmpathyAccount *account; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - name = empathy_account_settings_get_display_name (settings); - - account = empathy_account_settings_get_account (settings); - if (account != NULL) - { - enabled = empathy_account_is_enabled (account); - g_object_get (account, "connection-status", &status, NULL); - } - - accounts_dialog_get_settings_iter (dialog, settings, &iter); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ENABLED, enabled, - COL_NAME, name, - COL_STATUS, status, - COL_ACCOUNT_POINTER, account, - COL_ACCOUNT_SETTINGS_POINTER, settings, - -1); + GtkTreeModel *model; + GtkTreeIter iter; + TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED; + const gchar *name; + gboolean enabled = FALSE; + EmpathyAccount *account; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + name = empathy_account_settings_get_display_name (settings); + + account = empathy_account_settings_get_account (settings); + if (account != NULL) + { + enabled = empathy_account_is_enabled (account); + g_object_get (account, "connection-status", &status, NULL); + } + + accounts_dialog_get_settings_iter (dialog, settings, &iter); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_ENABLED, enabled, + COL_NAME, name, + COL_STATUS, status, + COL_ACCOUNT_POINTER, account, + COL_ACCOUNT_SETTINGS_POINTER, settings, + -1); } static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountsDialog *dialog) + EmpathyAccount *account, + EmpathyAccountsDialog *dialog) { - accounts_dialog_add_account (dialog, account); + accounts_dialog_add_account (dialog, account); } static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountsDialog *dialog) + EmpathyAccount *account, + EmpathyAccountsDialog *dialog) { - GtkTreeIter iter; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - if (accounts_dialog_get_account_iter (dialog, account, &iter)) - gtk_list_store_remove (GTK_LIST_STORE ( - gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter); + if (accounts_dialog_get_account_iter (dialog, account, &iter)) + gtk_list_store_remove (GTK_LIST_STORE ( + gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter); } -static gboolean -accounts_dialog_row_changed_foreach (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer user_data) -{ - gtk_tree_model_row_changed (model, path, iter); - - return FALSE; -} - -static gboolean -accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog) +static void +enable_or_disable_account (EmpathyAccountsDialog *dialog, + EmpathyAccount *account, + gboolean enabled) { - GtkTreeView *view; - GtkTreeModel *model; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - priv->connecting_show = !priv->connecting_show; + GtkTreeModel *model; + GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - view = GTK_TREE_VIEW (priv->treeview); - model = gtk_tree_view_get_model (view); + /* Update the status in the model */ + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL); + DEBUG ("Account %s is now %s", + empathy_account_get_display_name (account), + enabled ? "enabled" : "disabled"); - return TRUE; -} - -static void -accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - TpConnectionStatusReason reason, - TpConnectionStatus current, - TpConnectionStatus previous, - EmpathyAccountsDialog *dialog) -{ - GtkTreeModel *model; - GtkTreeIter iter; - gboolean found; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - /* Update the status in the model */ - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - - if (accounts_dialog_get_account_iter (dialog, account, &iter)) { - GtkTreePath *path; - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_STATUS, current, - -1); - - path = gtk_tree_model_get_path (model, &iter); - gtk_tree_model_row_changed (model, path, &iter); - gtk_tree_path_free (path); - } - - found = (empathy_account_manager_get_connecting_accounts (manager) > 0); - - if (!found && priv->connecting_id) { - g_source_remove (priv->connecting_id); - priv->connecting_id = 0; - } - - if (found && !priv->connecting_id) { - priv->connecting_id = g_timeout_add (FLASH_TIMEOUT, - (GSourceFunc) accounts_dialog_flash_connecting_cb, - dialog); - } -} - -static void -enable_or_disable_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account, - gboolean enabled) -{ - GtkTreeModel *model; - GtkTreeIter iter; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - /* Update the status in the model */ - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - - DEBUG ("Account %s is now %s", - empathy_account_get_display_name (account), - enabled ? "enabled" : "disabled"); - - if (accounts_dialog_get_account_iter (dialog, account, &iter)) { - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ENABLED, enabled, - -1); - } + if (accounts_dialog_get_account_iter (dialog, account, &iter)) + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_ENABLED, enabled, + -1); } static void accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountsDialog *dialog) + EmpathyAccount *account, + EmpathyAccountsDialog *dialog) { - enable_or_disable_account (dialog, account, FALSE); + enable_or_disable_account (dialog, account, FALSE); } static void accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountsDialog *dialog) + EmpathyAccount *account, + EmpathyAccountsDialog *dialog) { - enable_or_disable_account (dialog, account, TRUE); + enable_or_disable_account (dialog, account, TRUE); } static void accounts_dialog_account_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountsDialog *dialog) + EmpathyAccount *account, + EmpathyAccountsDialog *dialog) { - EmpathyAccountSettings *settings, *selected_settings; - GtkTreeModel *model; - GtkTreeIter iter; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + EmpathyAccountSettings *settings, *selected_settings; + GtkTreeModel *model; + GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - if (!accounts_dialog_get_account_iter (dialog, account, &iter)) - return; + if (!accounts_dialog_get_account_iter (dialog, account, &iter)) + return; - gtk_tree_model_get (model, &iter, - COL_ACCOUNT_SETTINGS_POINTER, &settings, - -1); + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_SETTINGS_POINTER, &settings, + -1); - accounts_dialog_update (dialog, settings); - selected_settings = accounts_dialog_model_get_selected_settings (dialog); + accounts_dialog_update (dialog, settings); + selected_settings = accounts_dialog_model_get_selected_settings (dialog); - if (settings == selected_settings) - accounts_dialog_update_name_label (dialog, settings); + if (settings == selected_settings) + accounts_dialog_update_name_label (dialog, settings); } static void -accounts_dialog_button_create_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog) +accounts_dialog_button_create_clicked_cb (GtkWidget *button, + EmpathyAccountsDialog *dialog) { - EmpathyAccountSettings *settings; - gchar *str; - TpConnectionManager *cm; - TpConnectionManagerProtocol *proto; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - cm = empathy_protocol_chooser_dup_selected ( - EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto); - - /* Create account */ - /* To translator: %s is the protocol name */ - str = g_strdup_printf (_("New %s account"), proto->name); + EmpathyAccountSettings *settings; + gchar *str; + TpConnectionManager *cm; + TpConnectionManagerProtocol *proto; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - settings = empathy_account_settings_new (cm->name, proto->name, str); + cm = empathy_protocol_chooser_dup_selected ( + EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto); - g_free (str); + /* Create account */ + /* To translator: %s is the protocol name */ + str = g_strdup_printf (_("New %s account"), proto->name); - if (tp_connection_manager_protocol_can_register (proto)) { - gboolean active; + settings = empathy_account_settings_new (cm->name, proto->name, str); - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->radiobutton_register)); - if (active) { - empathy_account_settings_set_boolean (settings, "register", TRUE); - } - } + g_free (str); - accounts_dialog_add (dialog, settings); - accounts_dialog_model_set_selected (dialog, settings); + if (tp_connection_manager_protocol_can_register (proto)) + { + gboolean active; - g_object_unref (settings); - g_object_unref (cm); -} + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->radiobutton_register)); + if (active) + empathy_account_settings_set_boolean (settings, "register", TRUE); + } -static void -accounts_dialog_button_back_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog) -{ - EmpathyAccountSettings *settings; + accounts_dialog_add (dialog, settings); + accounts_dialog_model_set_selected (dialog, settings); - settings = accounts_dialog_model_get_selected_settings (dialog); - accounts_dialog_update (dialog, settings); + g_object_unref (settings); + g_object_unref (cm); } static void -accounts_dialog_protocol_changed_cb (GtkWidget *widget, - EmpathyAccountsDialog *dialog) +accounts_dialog_button_back_clicked_cb (GtkWidget *button, + EmpathyAccountsDialog *dialog) { - TpConnectionManager *cm; - TpConnectionManagerProtocol *proto; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - cm = empathy_protocol_chooser_dup_selected ( - EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto); - - if (tp_connection_manager_protocol_can_register (proto)) { - gtk_widget_show (priv->radiobutton_register); - gtk_widget_show (priv->radiobutton_reuse); - } else { - gtk_widget_hide (priv->radiobutton_register); - gtk_widget_hide (priv->radiobutton_reuse); - } - g_object_unref (cm); -} + EmpathyAccountSettings *settings; -static void -accounts_dialog_button_add_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog) -{ - GtkTreeView *view; - GtkTreeSelection *selection; - GtkTreeModel *model; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - view = GTK_TREE_VIEW (priv->treeview); - model = gtk_tree_view_get_model (view); - selection = gtk_tree_view_get_selection (view); - gtk_tree_selection_unselect_all (selection); - - gtk_widget_set_sensitive (priv->button_add, FALSE); - gtk_widget_set_sensitive (priv->button_remove, FALSE); - gtk_widget_hide (priv->vbox_details); - gtk_widget_hide (priv->frame_no_protocol); - gtk_widget_show (priv->frame_new_account); - - /* If we have no account, no need of a back button */ - if (gtk_tree_model_iter_n_children (model, NULL) > 0) { - gtk_widget_show (priv->button_back); - } else { - gtk_widget_hide (priv->button_back); - } - - accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse), - TRUE); - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0); - gtk_widget_grab_focus (priv->combobox_protocol); + settings = accounts_dialog_model_get_selected_settings (dialog); + accounts_dialog_update (dialog, settings); } static void -accounts_dialog_button_help_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog) +accounts_dialog_button_help_clicked_cb (GtkWidget *button, + EmpathyAccountsDialog *dialog) { - empathy_url_show (button, "ghelp:empathy?empathy-create-account"); + empathy_url_show (button, "ghelp:empathy?empathy-create-account"); } static void -accounts_dialog_button_remove_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog) +accounts_dialog_button_remove_clicked_cb (GtkWidget *button, + EmpathyAccountsDialog *dialog) { - EmpathyAccount *account; - GtkWidget *message_dialog; - gint res; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - account = accounts_dialog_model_get_selected_account (dialog); - - if (account == NULL || !empathy_account_is_valid (account)) { - accounts_dialog_model_remove_selected (dialog); - accounts_dialog_model_select_first (dialog); - return; - } - message_dialog = gtk_message_dialog_new - (GTK_WINDOW (priv->window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - _("You are about to remove your %s account!\n" - "Are you sure you want to proceed?"), - empathy_account_get_display_name (account)); - - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (message_dialog), - _("Any associated conversations and chat rooms will NOT be " - "removed if you decide to proceed.\n" - "\n" - "Should you decide to add the account back at a later time, " - "they will still be available.")); - - gtk_dialog_add_button (GTK_DIALOG (message_dialog), - GTK_STOCK_CANCEL, - GTK_RESPONSE_NO); - gtk_dialog_add_button (GTK_DIALOG (message_dialog), - GTK_STOCK_REMOVE, - GTK_RESPONSE_YES); - - gtk_widget_show (message_dialog); - res = gtk_dialog_run (GTK_DIALOG (message_dialog)); - - if (res == GTK_RESPONSE_YES) { - accounts_dialog_model_remove_selected (dialog); - accounts_dialog_model_select_first (dialog); - } - gtk_widget_destroy (message_dialog); + EmpathyAccount *account; + GtkWidget *message_dialog; + gint res; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + account = accounts_dialog_model_get_selected_account (dialog); + + if (account == NULL || !empathy_account_is_valid (account)) + { + accounts_dialog_model_remove_selected (dialog); + accounts_dialog_model_select_first (dialog); + return; + } + message_dialog = gtk_message_dialog_new + (GTK_WINDOW (priv->window), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("You are about to remove your %s account!\n" + "Are you sure you want to proceed?"), + empathy_account_get_display_name (account)); + + gtk_message_dialog_format_secondary_text + (GTK_MESSAGE_DIALOG (message_dialog), + _("Any associated conversations and chat rooms will NOT be " + "removed if you decide to proceed.\n" + "\n" + "Should you decide to add the account back at a later time, " + "they will still be available.")); + + gtk_dialog_add_button (GTK_DIALOG (message_dialog), + GTK_STOCK_CANCEL, + GTK_RESPONSE_NO); + gtk_dialog_add_button (GTK_DIALOG (message_dialog), + GTK_STOCK_REMOVE, + GTK_RESPONSE_YES); + + gtk_widget_show (message_dialog); + res = gtk_dialog_run (GTK_DIALOG (message_dialog)); + + if (res == GTK_RESPONSE_YES) + { + accounts_dialog_model_remove_selected (dialog); + accounts_dialog_model_select_first (dialog); + } + gtk_widget_destroy (message_dialog); } #if 0 /* FIXME MC-5 */ static void -accounts_dialog_button_import_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog) +accounts_dialog_button_import_clicked_cb (GtkWidget *button, + EmpathyAccountsDialog *dialog) { - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - empathy_import_dialog_show (GTK_WINDOW (priv->window), TRUE); + empathy_import_dialog_show (GTK_WINDOW (priv->window), TRUE); } #endif static void -accounts_dialog_response_cb (GtkWidget *widget, - gint response, - EmpathyAccountsDialog *dialog) +accounts_dialog_response_cb (GtkWidget *widget, + gint response, + EmpathyAccountsDialog *dialog) { - GList *accounts, *l; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - if (response == GTK_RESPONSE_CLOSE) { - /* Delete incomplete accounts */ - accounts = empathy_account_manager_dup_accounts - (priv->account_manager); - for (l = accounts; l; l = l->next) { - EmpathyAccount *account; - - account = l->data; - if (!empathy_account_is_valid (account)) { - /* FIXME: Warn the user the account is not - * complete and is going to be removed. - */ - empathy_account_manager_remove - (priv->account_manager, account); - } - - g_object_unref (account); - } - g_list_free (accounts); - - gtk_widget_destroy (widget); - } + GList *accounts, *l; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + if (response == GTK_RESPONSE_CLOSE) + { + /* Delete incomplete accounts */ + accounts = empathy_account_manager_dup_accounts + (priv->account_manager); + for (l = accounts; l; l = l->next) + { + EmpathyAccount *account; + + account = l->data; + if (!empathy_account_is_valid (account)) + /* FIXME: Warn the user the account is not + * complete and is going to be removed. + */ + empathy_account_manager_remove + (priv->account_manager, account); + + g_object_unref (account); + } + g_list_free (accounts); + + gtk_widget_destroy (widget); + } } static void accounts_dialog_destroy_cb (GtkObject *obj, - EmpathyAccountsDialog *dialog) + EmpathyAccountsDialog *dialog) { - DEBUG ("%p", obj); + DEBUG ("%p", obj); - g_object_unref (dialog); + g_object_unref (dialog); } static void accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account) + EmpathyAccount *account) { - GtkTreeSelection *selection; - GtkTreeIter iter; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); - if (accounts_dialog_get_account_iter (dialog, account, &iter)) { - gtk_tree_selection_select_iter (selection, &iter); - } + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + if (accounts_dialog_get_account_iter (dialog, account, &iter)) + gtk_tree_selection_select_iter (selection, &iter); } static void accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms, - GParamSpec *pspec, - EmpathyAccountsDialog *dialog) + GParamSpec *pspec, + EmpathyAccountsDialog *dialog) { - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - if (empathy_connection_managers_is_ready (cms)) { - accounts_dialog_update_settings (dialog, NULL); - - if (priv->initial_selection != NULL) { - accounts_dialog_set_selected_account (dialog, priv->initial_selection); - priv->initial_selection = NULL; - } - } + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + if (empathy_connection_managers_is_ready (cms)) + { + accounts_dialog_update_settings (dialog, NULL); + + if (priv->initial_selection != NULL) + { + accounts_dialog_set_selected_account (dialog, priv->initial_selection); + priv->initial_selection = NULL; + } + } } static void accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) { - GtkBuilder *gui; - gchar *filename; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src"); - - gui = empathy_builder_get_file (filename, - "accounts_dialog", &priv->window, - "vbox_details", &priv->vbox_details, - "frame_no_protocol", &priv->frame_no_protocol, - "alignment_settings", &priv->alignment_settings, - "treeview", &priv->treeview, - "frame_new_account", &priv->frame_new_account, - "hbox_type", &priv->hbox_type, - "button_create", &priv->button_create, - "button_back", &priv->button_back, - "radiobutton_reuse", &priv->radiobutton_reuse, - "radiobutton_register", &priv->radiobutton_register, - "image_type", &priv->image_type, - "label_name", &priv->label_name, - "button_add", &priv->button_add, - "button_remove", &priv->button_remove, - "button_import", &priv->button_import, - NULL); - g_free (filename); - - empathy_builder_connect (gui, dialog, - "accounts_dialog", "response", accounts_dialog_response_cb, - "accounts_dialog", "destroy", accounts_dialog_destroy_cb, - "button_create", "clicked", accounts_dialog_button_create_clicked_cb, - "button_back", "clicked", accounts_dialog_button_back_clicked_cb, - "button_add", "clicked", accounts_dialog_button_add_clicked_cb, - "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb, + GtkBuilder *gui; + gchar *filename; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src"); + + gui = empathy_builder_get_file (filename, + "accounts_dialog", &priv->window, + "vbox_details", &priv->vbox_details, + "frame_no_protocol", &priv->frame_no_protocol, + "alignment_settings", &priv->alignment_settings, + "treeview", &priv->treeview, + "frame_new_account", &priv->frame_new_account, + "hbox_type", &priv->hbox_type, + "button_create", &priv->button_create, + "button_back", &priv->button_back, + "radiobutton_reuse", &priv->radiobutton_reuse, + "radiobutton_register", &priv->radiobutton_register, + "image_type", &priv->image_type, + "label_name", &priv->label_name, + "button_add", &priv->button_add, + "button_remove", &priv->button_remove, + "button_import", &priv->button_import, + NULL); + g_free (filename); + + empathy_builder_connect (gui, dialog, + "accounts_dialog", "response", accounts_dialog_response_cb, + "accounts_dialog", "destroy", accounts_dialog_destroy_cb, + "button_create", "clicked", accounts_dialog_button_create_clicked_cb, + "button_back", "clicked", accounts_dialog_button_back_clicked_cb, + "button_add", "clicked", accounts_dialog_button_add_clicked_cb, + "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb, #if 0 -/* FIXME MC-5 */ - "button_import", "clicked", accounts_dialog_button_import_clicked_cb, + /* FIXME MC-5 */ + "button_import", "clicked", accounts_dialog_button_import_clicked_cb, #endif - "button_help", "clicked", accounts_dialog_button_help_clicked_cb, - NULL); - - g_object_unref (gui); - - priv->combobox_protocol = empathy_protocol_chooser_new (); - gtk_box_pack_end (GTK_BOX (priv->hbox_type), - priv->combobox_protocol, - TRUE, TRUE, 0); - gtk_widget_show (priv->combobox_protocol); - g_signal_connect (priv->combobox_protocol, "changed", - G_CALLBACK (accounts_dialog_protocol_changed_cb), - dialog); - - if (priv->parent_window) { - gtk_window_set_transient_for (GTK_WINDOW (priv->window), - priv->parent_window); - } + "button_help", "clicked", accounts_dialog_button_help_clicked_cb, + NULL); + + g_object_unref (gui); + + priv->combobox_protocol = empathy_protocol_chooser_new (); + gtk_box_pack_end (GTK_BOX (priv->hbox_type), + priv->combobox_protocol, + TRUE, TRUE, 0); + gtk_widget_show (priv->combobox_protocol); + g_signal_connect (priv->combobox_protocol, "changed", + G_CALLBACK (accounts_dialog_protocol_changed_cb), + dialog); + + if (priv->parent_window) + gtk_window_set_transient_for (GTK_WINDOW (priv->window), + priv->parent_window); } static void do_dispose (GObject *obj) { - EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj); - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - /* Disconnect signals */ - g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_account_added_cb, - dialog); - g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_account_removed_cb, - dialog); - g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_account_enabled_cb, - dialog); - g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_account_disabled_cb, - dialog); - g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_account_changed_cb, - dialog); - g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_connection_changed_cb, - dialog); - - if (priv->connecting_id) { - g_source_remove (priv->connecting_id); - } - - if (priv->account_manager != NULL) { - g_object_unref (priv->account_manager); - priv->account_manager = NULL; - } - - if (priv->cms != NULL) { - g_object_unref (priv->cms); - priv->cms = NULL; - } - - G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj); + EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + /* Disconnect signals */ + g_signal_handlers_disconnect_by_func (priv->account_manager, + accounts_dialog_account_added_cb, + dialog); + g_signal_handlers_disconnect_by_func (priv->account_manager, + accounts_dialog_account_removed_cb, + dialog); + g_signal_handlers_disconnect_by_func (priv->account_manager, + accounts_dialog_account_enabled_cb, + dialog); + g_signal_handlers_disconnect_by_func (priv->account_manager, + accounts_dialog_account_disabled_cb, + dialog); + g_signal_handlers_disconnect_by_func (priv->account_manager, + accounts_dialog_account_changed_cb, + dialog); + g_signal_handlers_disconnect_by_func (priv->account_manager, + accounts_dialog_connection_changed_cb, + dialog); + + if (priv->connecting_id) + g_source_remove (priv->connecting_id); + + if (priv->account_manager != NULL) + { + g_object_unref (priv->account_manager); + priv->account_manager = NULL; + } + + if (priv->cms != NULL) + { + g_object_unref (priv->cms); + priv->cms = NULL; + } + + G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj); } static GObject * do_constructor (GType type, - guint n_props, - GObjectConstructParam *props) + guint n_props, + GObjectConstructParam *props) { - GObject *retval; - - if (dialog_singleton) { - retval = G_OBJECT (dialog_singleton); - } else { - retval = G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor - (type, n_props, props); - - dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval); - g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton); - } - - return retval; + GObject *retval; + + if (dialog_singleton) + { + retval = G_OBJECT (dialog_singleton); + } + else + { + retval = G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor + (type, n_props, props); + + dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval); + g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton); + } + + return retval; } static void do_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) + guint property_id, + GValue *value, + GParamSpec *pspec) { - EmpathyAccountsDialogPriv *priv = GET_PRIV (object); - - switch (property_id) { - case PROP_PARENT: - g_value_set_object (value, priv->parent_window); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + EmpathyAccountsDialogPriv *priv = GET_PRIV (object); + + switch (property_id) + { + case PROP_PARENT: + g_value_set_object (value, priv->parent_window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void do_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) + guint property_id, + const GValue *value, + GParamSpec *pspec) { - EmpathyAccountsDialogPriv *priv = GET_PRIV (object); - - switch (property_id) { - case PROP_PARENT: - priv->parent_window = g_value_get_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } + EmpathyAccountsDialogPriv *priv = GET_PRIV (object); + + switch (property_id) + { + case PROP_PARENT: + priv->parent_window = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } } static void do_constructed (GObject *object) { - EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object); - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - GList *accounts, *l; - gboolean import_asked; - - accounts_dialog_build_ui (dialog); - - /* Set up signalling */ - priv->account_manager = empathy_account_manager_dup_singleton (); - - g_signal_connect (priv->account_manager, "account-created", - G_CALLBACK (accounts_dialog_account_added_cb), - dialog); - g_signal_connect (priv->account_manager, "account-deleted", - G_CALLBACK (accounts_dialog_account_removed_cb), - dialog); - g_signal_connect (priv->account_manager, "account-enabled", - G_CALLBACK (accounts_dialog_account_enabled_cb), - dialog); - g_signal_connect (priv->account_manager, "account-disabled", - G_CALLBACK (accounts_dialog_account_disabled_cb), - dialog); - g_signal_connect (priv->account_manager, "account-changed", - G_CALLBACK (accounts_dialog_account_changed_cb), - dialog); - g_signal_connect (priv->account_manager, "account-connection-changed", - G_CALLBACK (accounts_dialog_connection_changed_cb), - dialog); - - accounts_dialog_model_setup (dialog); - - /* Add existing accounts */ - accounts = empathy_account_manager_dup_accounts (priv->account_manager); - for (l = accounts; l; l = l->next) { - accounts_dialog_add_account (dialog, l->data); - g_object_unref (l->data); - } - g_list_free (accounts); - - priv->cms = empathy_connection_managers_dup_singleton (); - if (!empathy_connection_managers_is_ready (priv->cms)) { - g_signal_connect (priv->cms, "notify::ready", - G_CALLBACK (accounts_dialog_cms_ready_cb), dialog); - } - - accounts_dialog_model_select_first (dialog); - - empathy_conf_get_bool (empathy_conf_get (), - EMPATHY_PREFS_IMPORT_ASKED, &import_asked); + EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + GList *accounts, *l; + gboolean import_asked; + + accounts_dialog_build_ui (dialog); + + /* Set up signalling */ + priv->account_manager = empathy_account_manager_dup_singleton (); + + g_signal_connect (priv->account_manager, "account-created", + G_CALLBACK (accounts_dialog_account_added_cb), + dialog); + g_signal_connect (priv->account_manager, "account-deleted", + G_CALLBACK (accounts_dialog_account_removed_cb), + dialog); + g_signal_connect (priv->account_manager, "account-enabled", + G_CALLBACK (accounts_dialog_account_enabled_cb), + dialog); + g_signal_connect (priv->account_manager, "account-disabled", + G_CALLBACK (accounts_dialog_account_disabled_cb), + dialog); + g_signal_connect (priv->account_manager, "account-changed", + G_CALLBACK (accounts_dialog_account_changed_cb), + dialog); + g_signal_connect (priv->account_manager, "account-connection-changed", + G_CALLBACK (accounts_dialog_connection_changed_cb), + dialog); + + accounts_dialog_model_setup (dialog); + + /* Add existing accounts */ + accounts = empathy_account_manager_dup_accounts (priv->account_manager); + for (l = accounts; l; l = l->next) + { + accounts_dialog_add_account (dialog, l->data); + g_object_unref (l->data); + } + g_list_free (accounts); + + priv->cms = empathy_connection_managers_dup_singleton (); + if (!empathy_connection_managers_is_ready (priv->cms)) + g_signal_connect (priv->cms, "notify::ready", + G_CALLBACK (accounts_dialog_cms_ready_cb), dialog); + + accounts_dialog_model_select_first (dialog); + + empathy_conf_get_bool (empathy_conf_get (), + EMPATHY_PREFS_IMPORT_ASKED, &import_asked); #if 0 -/* FIXME MC-5 */ - if (empathy_import_dialog_accounts_to_import ()) { - - if (!import_asked) { - empathy_conf_set_bool (empathy_conf_get (), - EMPATHY_PREFS_IMPORT_ASKED, TRUE); - empathy_import_dialog_show (GTK_WINDOW (priv->window), - FALSE); - } - } else { - gtk_widget_set_sensitive (priv->button_import, FALSE); - } + /* FIXME MC-5 */ + if (empathy_import_dialog_accounts_to_import ()) + { + + if (!import_asked) + { + empathy_conf_set_bool (empathy_conf_get (), + EMPATHY_PREFS_IMPORT_ASKED, TRUE); + empathy_import_dialog_show (GTK_WINDOW (priv->window), + FALSE); + } + } + else + { + gtk_widget_set_sensitive (priv->button_import, FALSE); + } #endif } static void empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass) { - GObjectClass *oclass = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - oclass->constructor = do_constructor; - oclass->dispose = do_dispose; - oclass->constructed = do_constructed; - oclass->set_property = do_set_property; - oclass->get_property = do_get_property; - - param_spec = g_param_spec_object ("parent", - "parent", "The parent window", - GTK_TYPE_WINDOW, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (oclass, PROP_PARENT, param_spec); - - g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv)); + GObjectClass *oclass = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + oclass->constructor = do_constructor; + oclass->dispose = do_dispose; + oclass->constructed = do_constructed; + oclass->set_property = do_set_property; + oclass->get_property = do_get_property; + + param_spec = g_param_spec_object ("parent", + "parent", "The parent window", + GTK_TYPE_WINDOW, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_PARENT, param_spec); + + g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv)); } static void empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog) { - EmpathyAccountsDialogPriv *priv; + EmpathyAccountsDialogPriv *priv; - priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog), - EMPATHY_TYPE_ACCOUNTS_DIALOG, - EmpathyAccountsDialogPriv); - dialog->priv = priv; + priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog), + EMPATHY_TYPE_ACCOUNTS_DIALOG, + EmpathyAccountsDialogPriv); + dialog->priv = priv; } /* public methods */ GtkWidget * empathy_accounts_dialog_show (GtkWindow *parent, - EmpathyAccount *selected_account) + EmpathyAccount *selected_account) { - EmpathyAccountsDialog *dialog; - EmpathyAccountsDialogPriv *priv; + EmpathyAccountsDialog *dialog; + EmpathyAccountsDialogPriv *priv; - dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG, - "parent", parent, NULL); + dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG, + "parent", parent, NULL); - priv = GET_PRIV (dialog); + priv = GET_PRIV (dialog); - if (selected_account && empathy_connection_managers_is_ready (priv->cms)) { - accounts_dialog_set_selected_account (dialog, selected_account); - } else { - /* save the selection to set it later when the cms - * becomes ready. - */ - priv->initial_selection = selected_account; - } + if (selected_account && empathy_connection_managers_is_ready (priv->cms)) + accounts_dialog_set_selected_account (dialog, selected_account); + else + /* save the selection to set it later when the cms + * becomes ready. + */ + priv->initial_selection = selected_account; - gtk_window_present (GTK_WINDOW (priv->window)); + gtk_window_present (GTK_WINDOW (priv->window)); - return priv->window; + return priv->window; } -- cgit v1.2.3 From 88723038185c9f7b1402153f0a3009ea883fc250 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 25 Jul 2009 18:24:54 +0200 Subject: Even more cleanup + update header --- src/empathy-accounts-dialog.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 339c53b96..78ef4fe75 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1,7 +1,6 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2005-2007 Imendio AB - * Copyright (C) 2007-2008 Collabora Ltd. + * Copyright (C) 2007-2009 Collabora Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,6 +19,7 @@ * * Authors: Martyn Russell * Xavier Claessens + * Cosimo Cecchi */ #include @@ -119,8 +119,8 @@ static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, #if 0 /* FIXME MC-5 */ -static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog); +static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, + EmpathyAccountsDialog *dialog); #endif static void @@ -172,7 +172,6 @@ get_account_setup_widget (EmpathyAccountSettings *settings) return empathy_account_widget_generic_new (settings); } - static void account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings) @@ -501,7 +500,8 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer, GtkTreeIter iter; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - if (empathy_account_manager_get_connecting_accounts (priv->account_manager) > 0) + if (empathy_account_manager_get_connecting_accounts + (priv->account_manager) > 0) { priv->connecting_id = g_timeout_add (FLASH_TIMEOUT, (GSourceFunc) accounts_dialog_flash_connecting_cb, @@ -1033,7 +1033,8 @@ accounts_dialog_button_create_clicked_cb (GtkWidget *button, { gboolean active; - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->radiobutton_register)); + active = gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (priv->radiobutton_register)); if (active) empathy_account_settings_set_boolean (settings, "register", TRUE); } @@ -1194,7 +1195,8 @@ accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms, if (priv->initial_selection != NULL) { - accounts_dialog_set_selected_account (dialog, priv->initial_selection); + accounts_dialog_set_selected_account + (dialog, priv->initial_selection); priv->initial_selection = NULL; } } @@ -1316,8 +1318,9 @@ do_constructor (GType type, } else { - retval = G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor - (type, n_props, props); + retval = + G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor + (type, n_props, props); dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval); g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton); -- cgit v1.2.3 From 72ae76e34c0c57b326be53f860bbc12cadf1ceb8 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 26 Jul 2009 17:08:47 +0200 Subject: Fix a typo. --- libempathy-gtk/empathy-account-widget.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h index f05c66012..d3bd171fc 100644 --- a/libempathy-gtk/empathy-account-widget.h +++ b/libempathy-gtk/empathy-account-widget.h @@ -22,8 +22,8 @@ * Martyn Russell */ -#ifndef __EMPATHY_ACCOUNT_WIDGET_GENERIC_H__ -#define __EMPATHY_ACCOUNT_WIDGET_GENERIC_H__ +#ifndef __EMPATHY_ACCOUNT_WIDGET_H__ +#define __EMPATHY_ACCOUNT_WIDGET_H__ #include @@ -55,4 +55,4 @@ GtkWidget *empathy_account_widget_groupwise_new (EmpathyAccountSettings *s G_END_DECLS -#endif /* __EMPATHY_ACCOUNT_WIDGET_GENERIC_H__ */ +#endif /* __EMPATHY_ACCOUNT_WIDGET_H__ */ -- cgit v1.2.3 From a84e75c56b59533a551a411ff7a2aa7d88659cd4 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 26 Jul 2009 17:09:06 +0200 Subject: Add empathy_account_settings_is_valid () --- libempathy/empathy-account-settings.c | 60 +++++++++++++++++++++++++++++++++++ libempathy/empathy-account-settings.h | 1 + 2 files changed, 61 insertions(+) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 4e32dfcfa..59cfcc525 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -72,6 +72,7 @@ struct _EmpathyAccountSettingsPriv GHashTable *parameters; GArray *unset_parameters; + GArray *required_params; gulong managers_ready_id; gulong account_ready_id; @@ -360,6 +361,23 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self) return; } + if (priv->required_params == NULL) + { + TpConnectionManagerParam *cur; + char *val; + + priv->required_params = g_array_new (TRUE, FALSE, sizeof (gchar *)); + + for (cur = priv->tp_protocol->params; cur->name != NULL; cur++) + { + if (tp_connection_manager_param_is_required (cur)) + { + val = g_strdup (cur->name); + g_array_append_val (priv->required_params, val); + } + } + } + g_object_ref (priv->manager); priv->ready = TRUE; @@ -1022,3 +1040,45 @@ empathy_account_settings_owns_account (EmpathyAccountSettings *settings, return (account == priv->account); } + +gboolean +empathy_account_settings_is_valid (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv; + int idx; + gchar *current; + gboolean missed = FALSE; + + g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE); + + priv = GET_PRIV (settings); + + for (idx = 0; idx < priv->required_params->len; idx++) + { + current = g_array_index (priv->required_params, gchar *, idx); + + /* first, look if it's set in our own parameters */ + if (tp_asv_lookup (priv->parameters, current)) + continue; + + /* if we did not unset the parameter, look if it's in the account */ + if (priv->account != NULL && + !empathy_account_settings_is_unset (settings, current)) + { + const GHashTable *account_params; + + account_params = empathy_account_get_parameters (priv->account); + if (tp_asv_lookup (account_params, current)) + continue; + } + + /* see if there's a default value */ + if (empathy_account_settings_get_default (settings, current)) + continue; + + missed = TRUE; + break; + } + + return !missed; +} diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h index 8119879cc..b660addd0 100644 --- a/libempathy/empathy-account-settings.h +++ b/libempathy/empathy-account-settings.h @@ -153,6 +153,7 @@ gboolean empathy_account_settings_apply_finish ( GAsyncResult *result, GError **error); +gboolean empathy_account_settings_is_valid (EmpathyAccountSettings *settings); G_END_DECLS -- cgit v1.2.3 From 000a7c0ca4dc343b42e628323ddd1ca0f2a08e3f Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 27 Jul 2009 00:54:23 +0200 Subject: First cut at GObject-ifying EmpathyAccountWidget --- libempathy-gtk/Makefile.am | 3 +- libempathy-gtk/empathy-account-widget-irc.c | 79 ++- libempathy-gtk/empathy-account-widget-irc.h | 5 +- .../empathy-account-widget-local-xmpp.ui | 219 +++++++ libempathy-gtk/empathy-account-widget-private.h | 47 ++ libempathy-gtk/empathy-account-widget-salut.ui | 219 ------- libempathy-gtk/empathy-account-widget-sip.c | 42 +- libempathy-gtk/empathy-account-widget-sip.h | 5 +- libempathy-gtk/empathy-account-widget.c | 642 ++++++++++++--------- libempathy-gtk/empathy-account-widget.h | 52 +- src/empathy-accounts-dialog.c | 29 +- 11 files changed, 732 insertions(+), 610 deletions(-) create mode 100644 libempathy-gtk/empathy-account-widget-local-xmpp.ui create mode 100644 libempathy-gtk/empathy-account-widget-private.h delete mode 100644 libempathy-gtk/empathy-account-widget-salut.ui diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 94cc4ee15..4a97761b9 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -68,6 +68,7 @@ libempathy_gtk_la_SOURCES = \ # do not distribute generated files nodist_libempathy_gtk_la_SOURCES =\ + empathy-account-widget-private.h \ $(BUILT_SOURCES) libempathy_gtk_la_LIBADD = \ @@ -141,7 +142,7 @@ ui_DATA = \ empathy-account-widget-jabber.ui \ empathy-account-widget-msn.ui \ empathy-account-widget-sip.ui \ - empathy-account-widget-salut.ui \ + empathy-account-widget-local-xmpp.ui \ empathy-account-widget-irc.ui \ empathy-account-widget-icq.ui \ empathy-account-widget-yahoo.ui \ diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c index 4bca91073..425adbcb5 100644 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ b/libempathy-gtk/empathy-account-widget-irc.c @@ -32,6 +32,7 @@ #include "empathy-irc-network-dialog.h" #include "empathy-account-widget.h" +#include "empathy-account-widget-private.h" #include "empathy-account-widget-irc.h" #include "empathy-ui-utils.h" @@ -41,7 +42,7 @@ #define IRC_NETWORKS_FILENAME "irc-networks.xml" typedef struct { - EmpathyAccountSettings *settings; + EmpathyAccountWidget *self; EmpathyIrcNetworkManager *network_manager; GtkWidget *vbox_settings; @@ -59,17 +60,19 @@ account_widget_irc_destroy_cb (GtkWidget *widget, EmpathyAccountWidgetIrc *settings) { g_object_unref (settings->network_manager); - g_object_unref (settings->settings); g_slice_free (EmpathyAccountWidgetIrc, settings); } static void unset_server_params (EmpathyAccountWidgetIrc *settings) { + EmpathyAccountSettings *ac_settings; + + g_object_get (settings->self, "settings", &ac_settings, NULL); DEBUG ("Unset server, port and use-ssl"); - empathy_account_settings_unset (settings->settings, "server"); - empathy_account_settings_unset (settings->settings, "port"); - empathy_account_settings_unset (settings->settings, "use-ssl"); + empathy_account_settings_unset (ac_settings, "server"); + empathy_account_settings_unset (ac_settings, "port"); + empathy_account_settings_unset (ac_settings, "use-ssl"); } static void @@ -80,6 +83,9 @@ update_server_params (EmpathyAccountWidgetIrc *settings) EmpathyIrcNetwork *network; GSList *servers; gchar *charset; + EmpathyAccountSettings *ac_settings; + + g_object_get (settings->self, "settings", &ac_settings, NULL); if (!gtk_combo_box_get_active_iter ( GTK_COMBO_BOX (settings->combobox_network), &iter)) @@ -95,7 +101,7 @@ update_server_params (EmpathyAccountWidgetIrc *settings) g_object_get (network, "charset", &charset, NULL); DEBUG ("Setting charset to %s", charset); - empathy_account_settings_set_string (settings->settings, "charset", charset); + empathy_account_settings_set_string (ac_settings, "charset", charset); g_free (charset); servers = empathy_irc_network_get_servers (network); @@ -114,13 +120,11 @@ update_server_params (EmpathyAccountWidgetIrc *settings) NULL); DEBUG ("Setting server to %s", address); - empathy_account_settings_set_string (settings->settings, - "server", address); + empathy_account_settings_set_string (ac_settings, "server", address); DEBUG ("Setting port to %u", port); - empathy_account_settings_set_uint32 (settings->settings, "port", port); + empathy_account_settings_set_uint32 (ac_settings, "port", port); DEBUG ("Setting use-ssl to %s", ssl ? "TRUE": "FALSE" ); - empathy_account_settings_set_boolean (settings->settings, - "use-ssl", ssl); + empathy_account_settings_set_boolean (ac_settings, "use-ssl", ssl); g_free (address); } @@ -330,19 +334,22 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) const gchar *charset; gboolean ssl = FALSE; EmpathyIrcNetwork *network = NULL; + EmpathyAccountSettings *ac_settings; - nick = empathy_account_settings_get_string (settings->settings, "account"); - fullname = empathy_account_settings_get_string (settings->settings, + g_object_get (settings->self, "settings", &ac_settings, NULL); + + nick = empathy_account_settings_get_string (ac_settings, "account"); + fullname = empathy_account_settings_get_string (ac_settings, "fullname"); - server = empathy_account_settings_get_string (settings->settings, "server"); - charset = empathy_account_settings_get_string (settings->settings, "charset"); - port = empathy_account_settings_get_uint32 (settings->settings, "port"); - ssl = empathy_account_settings_get_boolean (settings->settings, "use-ssl"); + server = empathy_account_settings_get_string (ac_settings, "server"); + charset = empathy_account_settings_get_string (ac_settings, "charset"); + port = empathy_account_settings_get_uint32 (ac_settings, "port"); + ssl = empathy_account_settings_get_boolean (ac_settings, "use-ssl"); if (!nick) { nick = g_strdup (g_get_user_name ()); - empathy_account_settings_set_string (settings->settings, + empathy_account_settings_set_string (ac_settings, "account", nick); } @@ -353,7 +360,7 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) { fullname = g_strdup (nick); } - empathy_account_settings_set_string (settings->settings, + empathy_account_settings_set_string (ac_settings, "fullname", fullname); } @@ -409,27 +416,17 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) fill_networks_model (settings, network); } -/** - * empathy_account_widget_irc_new: - * @settings: the #EmpathyAccountSettings to configure - * - * Creates a new IRC account widget to configure a given #EmpathyAccount - * - * Returns: The toplevel container of the configuration widget - */ -GtkWidget * -empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) +void +empathy_account_widget_irc_build (EmpathyAccountWidget *self, + const char *filename) { EmpathyAccountWidgetIrc *settings; gchar *dir, *user_file_with_path, *global_file_with_path; - GtkBuilder *gui; - GtkWidget *widget; GtkListStore *store; GtkCellRenderer *renderer; - gchar *filename; settings = g_slice_new0 (EmpathyAccountWidgetIrc); - settings->settings = g_object_ref (account_settings); + settings->self = self; dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); @@ -452,14 +449,11 @@ empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) g_free (global_file_with_path); g_free (user_file_with_path); - filename = empathy_file_lookup ("empathy-account-widget-irc.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_irc", &widget, + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_irc", &self->ui_details->widget, "table_irc_settings", &settings->vbox_settings, "combobox_network", &settings->combobox_network, NULL); - g_free (filename); /* Fill the networks combobox */ store = gtk_list_store_new (2, G_TYPE_OBJECT, G_TYPE_STRING); @@ -483,14 +477,14 @@ empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) account_widget_irc_setup (settings); - empathy_account_widget_handle_params (account_settings, gui, + empathy_account_widget_handle_params (self, "entry_nick", "account", "entry_fullname", "fullname", "entry_password", "password", "entry_quit_message", "quit-message", NULL); - empathy_builder_connect (gui, settings, + empathy_builder_connect (self->ui_details->gui, settings, "table_irc_settings", "destroy", account_widget_irc_destroy_cb, "button_network", "clicked", account_widget_irc_button_edit_network_clicked_cb, @@ -502,8 +496,5 @@ empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings) account_widget_irc_combobox_network_changed_cb, NULL); - empathy_account_widget_set_default_focus (gui, "entry_nick"); - empathy_account_widget_add_apply_button (account_settings, widget); - - return empathy_builder_unref_and_keep_widget (gui, widget); + self->ui_details->default_focus = g_strdup ("entry_nick"); } diff --git a/libempathy-gtk/empathy-account-widget-irc.h b/libempathy-gtk/empathy-account-widget-irc.h index 0373238ed..a76787120 100644 --- a/libempathy-gtk/empathy-account-widget-irc.h +++ b/libempathy-gtk/empathy-account-widget-irc.h @@ -22,11 +22,12 @@ #define __EMPATHY_ACCOUNT_WIDGET_IRC_H__ #include -#include +#include G_BEGIN_DECLS -GtkWidget * empathy_account_widget_irc_new (EmpathyAccountSettings *settings); +void empathy_account_widget_irc_build (EmpathyAccountWidget *self, + const char *filename); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget-local-xmpp.ui b/libempathy-gtk/empathy-account-widget-local-xmpp.ui new file mode 100644 index 000000000..ca633309d --- /dev/null +++ b/libempathy-gtk/empathy-account-widget-local-xmpp.ui @@ -0,0 +1,219 @@ + + + + + + True + vertical + 6 + + + True + 3 + 3 + 12 + 6 + + + True + True + + + + 1 + 3 + 2 + 3 + + + + + + True + True + + + + 1 + 3 + 1 + 2 + + + + + + True + True + + + + 1 + 3 + + + + + + True + 0 + _Nickname: + True + entry_nickname + + + 2 + 3 + GTK_FILL + + + + + + True + 0 + _Last Name: + True + entry_last_name + + + 1 + 2 + GTK_FILL + + + + + + True + 0 + _First Name: + True + entry_first_name + + + GTK_FILL + + + + + + False + False + 0 + + + + + True + True + + + True + 3 + 3 + 12 + 6 + + + True + True + + + + 1 + 3 + + + + + + True + 0 + _Published Name: + True + entry_published + + + GTK_FILL + + + + + + True + True + + + + 1 + 3 + 2 + 3 + + + + + + True + True + + + + 1 + 3 + 1 + 2 + + + + + + True + 0 + _Jabber ID: + True + entry_jid + + + 2 + 3 + GTK_FILL + + + + + + True + 0 + _Email: + True + entry_email + + + 1 + 2 + GTK_FILL + + + + + + + + True + Advanced + + + + + + + + False + False + 1 + + + + diff --git a/libempathy-gtk/empathy-account-widget-private.h b/libempathy-gtk/empathy-account-widget-private.h new file mode 100644 index 000000000..aaa24e58f --- /dev/null +++ b/libempathy-gtk/empathy-account-widget-private.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Cosimo Cecchi + */ + +#ifndef __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ +#define __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ + +#include +#include +#include + +G_BEGIN_DECLS + +struct _EmpathyAccountWidgetUIDetails { + GtkWidget *widget; + + GtkBuilder *gui; + + char *default_focus; + gboolean add_forget; +}; + + +void empathy_account_widget_handle_params (EmpathyAccountWidget *self, + const gchar *first_widget, + ...); + +G_END_DECLS + +#endif /* __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ */ \ No newline at end of file diff --git a/libempathy-gtk/empathy-account-widget-salut.ui b/libempathy-gtk/empathy-account-widget-salut.ui deleted file mode 100644 index ca633309d..000000000 --- a/libempathy-gtk/empathy-account-widget-salut.ui +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - True - vertical - 6 - - - True - 3 - 3 - 12 - 6 - - - True - True - - - - 1 - 3 - 2 - 3 - - - - - - True - True - - - - 1 - 3 - 1 - 2 - - - - - - True - True - - - - 1 - 3 - - - - - - True - 0 - _Nickname: - True - entry_nickname - - - 2 - 3 - GTK_FILL - - - - - - True - 0 - _Last Name: - True - entry_last_name - - - 1 - 2 - GTK_FILL - - - - - - True - 0 - _First Name: - True - entry_first_name - - - GTK_FILL - - - - - - False - False - 0 - - - - - True - True - - - True - 3 - 3 - 12 - 6 - - - True - True - - - - 1 - 3 - - - - - - True - 0 - _Published Name: - True - entry_published - - - GTK_FILL - - - - - - True - True - - - - 1 - 3 - 2 - 3 - - - - - - True - True - - - - 1 - 3 - 1 - 2 - - - - - - True - 0 - _Jabber ID: - True - entry_jid - - - 2 - 3 - GTK_FILL - - - - - - True - 0 - _Email: - True - entry_email - - - 1 - 2 - GTK_FILL - - - - - - - - True - Advanced - - - - - - - - False - False - 1 - - - - diff --git a/libempathy-gtk/empathy-account-widget-sip.c b/libempathy-gtk/empathy-account-widget-sip.c index 9f08046b7..fedbf2aa6 100644 --- a/libempathy-gtk/empathy-account-widget-sip.c +++ b/libempathy-gtk/empathy-account-widget-sip.c @@ -31,12 +31,12 @@ #include #include "empathy-account-widget.h" +#include "empathy-account-widget-private.h" #include "empathy-account-widget-sip.h" #include "empathy-ui-utils.h" typedef struct { - EmpathyAccountSettings *settings; - + EmpathyAccountWidget *self; GtkWidget *vbox_settings; GtkWidget *entry_stun_server; @@ -48,7 +48,6 @@ static void account_widget_sip_destroy_cb (GtkWidget *widget, EmpathyAccountWidgetSip *settings) { - g_object_unref (settings->settings); g_slice_free (EmpathyAccountWidgetSip, settings); } @@ -64,35 +63,23 @@ account_widget_sip_discover_stun_toggled_cb ( gtk_widget_set_sensitive (settings->spinbutton_stun_part, !active); } -/** - * empathy_account_widget_sip_new: - * @account: the #EmpathyAccount to configure - * - * Creates a new SIP account widget to configure a given #EmpathyAccount - * - * Returns: The toplevel container of the configuration widget - */ -GtkWidget * -empathy_account_widget_sip_new (EmpathyAccountSettings *account_settings) +void +empathy_account_widget_sip_build (EmpathyAccountWidget *self, + const char *filename) { EmpathyAccountWidgetSip *settings; - GtkBuilder *gui; - gchar *filename; settings = g_slice_new0 (EmpathyAccountWidgetSip); - settings->settings = g_object_ref (account_settings); + settings->self = self; - filename = empathy_file_lookup ("empathy-account-widget-sip.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_sip_settings", &settings->vbox_settings, "entry_stun-server", &settings->entry_stun_server, "spinbutton_stun-port", &settings->spinbutton_stun_part, "checkbutton_discover-stun", &settings->checkbutton_discover_stun, NULL); - g_free (filename); - empathy_account_widget_handle_params (account_settings, gui, + empathy_account_widget_handle_params (self, "entry_userid", "account", "entry_password", "password", "checkbutton_discover-stun", "discover-stun", @@ -100,23 +87,18 @@ empathy_account_widget_sip_new (EmpathyAccountSettings *account_settings) "spinbutton_stun-port", "stun-port", NULL); - empathy_account_widget_add_forget_button (account_settings, gui, - "button_forget", - "entry_password"); - account_widget_sip_discover_stun_toggled_cb ( settings->checkbutton_discover_stun, settings); - empathy_builder_connect (gui, settings, + empathy_builder_connect (self->ui_details->gui, settings, "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb, "checkbutton_discover-stun", "toggled", account_widget_sip_discover_stun_toggled_cb, NULL); - empathy_account_widget_set_default_focus (gui, "entry_userid"); - empathy_account_widget_add_apply_button (account_settings, - settings->vbox_settings); + self->ui_details->add_forget = TRUE; + self->ui_details->default_focus = g_strdup ("entry_userid"); - return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings); + self->ui_details->widget = settings->vbox_settings; } diff --git a/libempathy-gtk/empathy-account-widget-sip.h b/libempathy-gtk/empathy-account-widget-sip.h index 15dd7244a..435ad6ea1 100644 --- a/libempathy-gtk/empathy-account-widget-sip.h +++ b/libempathy-gtk/empathy-account-widget-sip.h @@ -22,11 +22,12 @@ #define __EMPATHY_ACCOUNT_WIDGET_SIP_H__ #include -#include +#include G_BEGIN_DECLS -GtkWidget * empathy_account_widget_sip_new (EmpathyAccountSettings *settings); +void empathy_account_widget_sip_build (EmpathyAccountWidget *self, + const char *filename); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 21e3d3ee3..76145c483 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -33,21 +33,60 @@ #include #include +#include #include #include "empathy-account-widget.h" +#include "empathy-account-widget-private.h" +#include "empathy-account-widget-sip.h" +#include "empathy-account-widget-irc.h" #include "empathy-ui-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include +G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT) + +typedef struct { + GtkWidget *widget; + + char *protocol; + EmpathyAccountSettings *settings; + + GtkWidget *apply_button; + GtkWidget *entry_password; + GtkWidget *button_forget; + GtkWidget *spinbutton_port; + + GtkBuilder *gui; + char *default_focus; + gboolean add_forget; +} EmpathyAccountWidgetPriv; + +enum { + PROP_PROTOCOL = 1, + PROP_SETTINGS +}; + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget) + +static void +account_widget_handle_apply_sensitivity (EmpathyAccountWidget *self) +{ + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + gtk_widget_set_sensitive (priv->apply_button, + empathy_account_settings_is_valid (priv->settings)); +} + static gboolean account_widget_entry_focus_cb (GtkWidget *widget, GdkEventFocus *event, - EmpathyAccountSettings *settings) + EmpathyAccountWidget *self) { const gchar *str; const gchar *param_name; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); str = gtk_entry_get_text (GTK_ENTRY (widget)); param_name = g_object_get_data (G_OBJECT (widget), "param_name"); @@ -55,31 +94,34 @@ account_widget_entry_focus_cb (GtkWidget *widget, if (EMP_STR_EMPTY (str)) { const gchar *value = NULL; - empathy_account_settings_unset (settings, param_name); - value = empathy_account_settings_get_string (settings, param_name); + empathy_account_settings_unset (priv->settings, param_name); + value = empathy_account_settings_get_string (priv->settings, param_name); DEBUG ("Unset %s and restore to %s", param_name, value); gtk_entry_set_text (GTK_ENTRY (widget), value ? value : ""); } else { DEBUG ("Setting %s to %s", param_name, strstr (param_name, "password") ? "***" : str); - empathy_account_settings_set_string (settings, param_name, str); + empathy_account_settings_set_string (priv->settings, param_name, str); } + account_widget_handle_apply_sensitivity (self); + return FALSE; } static void account_widget_int_changed_cb (GtkWidget *widget, - EmpathyAccountSettings *settings) + EmpathyAccountWidget *self) { const gchar *param_name; - gint value; + gint value; const gchar *signature; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - signature = empathy_settings_get_dbus_signature (settings, param_name); + signature = empathy_settings_get_dbus_signature (priv->settings, param_name); g_return_if_fail (signature != NULL); DEBUG ("Setting %s to %d", param_name, value); @@ -88,30 +130,33 @@ account_widget_int_changed_cb (GtkWidget *widget, { case DBUS_TYPE_INT16: case DBUS_TYPE_INT32: - empathy_account_settings_set_int32 (settings, param_name, value); + empathy_account_settings_set_int32 (priv->settings, param_name, value); break; case DBUS_TYPE_INT64: - empathy_account_settings_set_int64 (settings, param_name, value); + empathy_account_settings_set_int64 (priv->settings, param_name, value); break; case DBUS_TYPE_UINT16: case DBUS_TYPE_UINT32: - empathy_account_settings_set_uint32 (settings, param_name, value); + empathy_account_settings_set_uint32 (priv->settings, param_name, value); break; case DBUS_TYPE_UINT64: - empathy_account_settings_set_uint64 (settings, param_name, value); + empathy_account_settings_set_uint64 (priv->settings, param_name, value); break; default: g_return_if_reached (); - } + } + + account_widget_handle_apply_sensitivity (self); } static void account_widget_checkbutton_toggled_cb (GtkWidget *widget, - EmpathyAccountSettings *settings) + EmpathyAccountWidget *self) { gboolean value; gboolean default_value; const gchar *param_name; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); param_name = g_object_get_data (G_OBJECT (widget), "param_name"); @@ -119,30 +164,33 @@ account_widget_checkbutton_toggled_cb (GtkWidget *widget, /* FIXME: This is ugly! checkbox don't have a "not-set" value so we * always unset the param and set the value if different from the * default value. */ - empathy_account_settings_unset (settings, param_name); - default_value = empathy_account_settings_get_boolean (settings, param_name); + empathy_account_settings_unset (priv->settings, param_name); + default_value = empathy_account_settings_get_boolean (priv->settings, param_name); if (default_value == value) { DEBUG ("Unset %s and restore to %d", param_name, default_value); } else { DEBUG ("Setting %s to %d", param_name, value); - empathy_account_settings_set_boolean (settings, param_name, value); + empathy_account_settings_set_boolean (priv->settings, param_name, value); } + + account_widget_handle_apply_sensitivity (self); } static void account_widget_forget_clicked_cb (GtkWidget *button, - GtkWidget *entry) + EmpathyAccountWidget *self) { - EmpathyAccountSettings *settings; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); const gchar *param_name; - param_name = g_object_get_data (G_OBJECT (entry), "param_name"); - settings = g_object_get_data (G_OBJECT (entry), "settings"); + param_name = g_object_get_data (G_OBJECT (priv->entry_password), "param_name"); DEBUG ("Unset %s", param_name); - empathy_account_settings_unset (settings, param_name); - gtk_entry_set_text (GTK_ENTRY (entry), ""); + empathy_account_settings_unset (priv->settings, param_name); + gtk_entry_set_text (GTK_ENTRY (priv->entry_password), ""); + + account_widget_handle_apply_sensitivity (self); } static void @@ -157,15 +205,14 @@ account_widget_password_changed_cb (GtkWidget *entry, static void account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, - GtkWidget *spinbutton_port) + EmpathyAccountWidget *self) { - EmpathyAccountSettings *settings; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); gboolean value; gint32 port = 0; value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl)); - settings = g_object_get_data (G_OBJECT (spinbutton_port), "settings"); - port = empathy_account_settings_get_uint32 (settings, "port"); + port = empathy_account_settings_get_uint32 (priv->settings, "port"); if (value) { if (port == 5222 || port == 0) { @@ -177,41 +224,41 @@ account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, } } - gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton_port), port); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port); } static void -account_widget_setup_widget (GtkWidget *widget, - EmpathyAccountSettings *settings, +account_widget_setup_widget (EmpathyAccountWidget *self, + GtkWidget *widget, const gchar *param_name) { + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + g_object_set_data_full (G_OBJECT (widget), "param_name", g_strdup (param_name), g_free); - g_object_set_data_full (G_OBJECT (widget), "settings", - g_object_ref (settings), g_object_unref); if (GTK_IS_SPIN_BUTTON (widget)) { gint value = 0; const gchar *signature; - signature = empathy_settings_get_dbus_signature (settings, param_name); + signature = empathy_settings_get_dbus_signature (priv->settings, param_name); g_return_if_fail (signature != NULL); switch ((int)*signature) { case DBUS_TYPE_INT16: case DBUS_TYPE_INT32: - value = empathy_account_settings_get_int32 (settings, param_name); + value = empathy_account_settings_get_int32 (priv->settings, param_name); break; case DBUS_TYPE_INT64: - value = empathy_account_settings_get_int64 (settings, param_name); + value = empathy_account_settings_get_int64 (priv->settings, param_name); break; case DBUS_TYPE_UINT16: case DBUS_TYPE_UINT32: - value = empathy_account_settings_get_uint32 (settings, param_name); + value = empathy_account_settings_get_uint32 (priv->settings, param_name); break; case DBUS_TYPE_UINT64: - value = empathy_account_settings_get_uint64 (settings, param_name); + value = empathy_account_settings_get_uint64 (priv->settings, param_name); break; default: g_return_if_reached (); @@ -221,12 +268,12 @@ account_widget_setup_widget (GtkWidget *widget, g_signal_connect (widget, "value-changed", G_CALLBACK (account_widget_int_changed_cb), - settings); + self); } else if (GTK_IS_ENTRY (widget)) { const gchar *str = NULL; - str = empathy_account_settings_get_string (settings, param_name); + str = empathy_account_settings_get_string (priv->settings, param_name); gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); if (strstr (param_name, "password")) { @@ -235,17 +282,17 @@ account_widget_setup_widget (GtkWidget *widget, g_signal_connect (widget, "focus-out-event", G_CALLBACK (account_widget_entry_focus_cb), - settings); + self); } else if (GTK_IS_TOGGLE_BUTTON (widget)) { gboolean value = FALSE; - value = empathy_account_settings_get_boolean (settings, param_name); + value = empathy_account_settings_get_boolean (priv->settings, param_name); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); g_signal_connect (widget, "toggled", G_CALLBACK (account_widget_checkbutton_toggled_cb), - settings); + self); } else { DEBUG ("Unknown type of widget for param %s", param_name); } @@ -276,13 +323,14 @@ account_widget_generic_format_param_name (const gchar *param_name) } static void -accounts_widget_generic_setup (EmpathyAccountSettings *settings, +accounts_widget_generic_setup (EmpathyAccountWidget *self, GtkWidget *table_common_settings, GtkWidget *table_advanced_settings) { TpConnectionManagerParam *params, *param; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - params = empathy_account_settings_get_tp_params (settings); + params = empathy_account_settings_get_tp_params (priv->settings); for (param = params; param != NULL && param->name != NULL; param++) { GtkWidget *table_settings; @@ -391,7 +439,7 @@ accounts_widget_generic_setup (EmpathyAccountSettings *settings, } if (widget) { - account_widget_setup_widget (widget, settings, param->name); + account_widget_setup_widget (self, widget, param->name); } g_free (param_name_formatted); @@ -399,168 +447,93 @@ accounts_widget_generic_setup (EmpathyAccountSettings *settings, } static void -account_widget_handle_params_valist (EmpathyAccountSettings *settings, - GtkBuilder *gui, +account_widget_handle_params_valist (EmpathyAccountWidget *self, const gchar *first_widget, va_list args) { GObject *object; const gchar *name; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); for (name = first_widget; name; name = va_arg (args, const gchar *)) { const gchar *param_name; param_name = va_arg (args, const gchar *); - object = gtk_builder_get_object (gui, name); + object = gtk_builder_get_object (priv->gui, name); if (!object) { g_warning ("Builder is missing object '%s'.", name); continue; } - account_widget_setup_widget (GTK_WIDGET (object), settings, param_name); + account_widget_setup_widget (self, GTK_WIDGET (object), param_name); } } -void -empathy_account_widget_handle_params (EmpathyAccountSettings *settings, - GtkBuilder *gui, - const gchar *first_widget, - ...) -{ - va_list args; - - g_return_if_fail (GTK_IS_BUILDER (gui)); - - va_start (args, first_widget); - account_widget_handle_params_valist (settings, gui, first_widget, args); - va_end (args); -} - static void account_widget_apply_clicked_cb (GtkWidget *button, - EmpathyAccountSettings *settings) + EmpathyAccountWidget *self) { - empathy_account_settings_apply_async (settings, NULL, NULL); -} - -void -empathy_account_widget_add_apply_button (EmpathyAccountSettings *settings, - GtkWidget *vbox) -{ - GtkWidget *button; - - button = gtk_button_new_from_stock (GTK_STOCK_APPLY); - - gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 3); - - g_signal_connect (button, "clicked", - G_CALLBACK (account_widget_apply_clicked_cb), - settings); - gtk_widget_show (button); -} - -void -empathy_account_widget_add_forget_button (EmpathyAccountSettings *settings, - GtkBuilder *gui, - const gchar *button, - const gchar *entry) -{ - GtkWidget *button_forget; - GtkWidget *entry_password; - const gchar *password = NULL; - - button_forget = GTK_WIDGET (gtk_builder_get_object (gui, button)); - entry_password = GTK_WIDGET (gtk_builder_get_object (gui, entry)); - - password = empathy_account_settings_get_string (settings, "password"); - gtk_widget_set_sensitive (button_forget, !EMP_STR_EMPTY (password)); - - g_signal_connect (button_forget, "clicked", - G_CALLBACK (account_widget_forget_clicked_cb), - entry_password); - g_signal_connect (entry_password, "changed", - G_CALLBACK (account_widget_password_changed_cb), - button_forget); -} - -void -empathy_account_widget_set_default_focus (GtkBuilder *gui, - const gchar *entry) -{ - GObject *default_focus_entry; - - default_focus_entry = gtk_builder_get_object (gui, entry); - g_signal_connect (default_focus_entry, "realize", - G_CALLBACK (gtk_widget_grab_focus), - NULL); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + empathy_account_settings_apply_async (priv->settings, NULL, NULL); } static void -account_widget_setup_generic (EmpathyAccountSettings *settings, - GtkBuilder *builder) +account_widget_setup_generic (EmpathyAccountWidget *self) { GtkWidget *table_common_settings; GtkWidget *table_advanced_settings; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - table_common_settings = GTK_WIDGET (gtk_builder_get_object (builder, + table_common_settings = GTK_WIDGET (gtk_builder_get_object (priv->gui, "table_common_settings")); - table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (builder, + table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (priv->gui, "table_advanced_settings")); - accounts_widget_generic_setup (settings, table_common_settings, + accounts_widget_generic_setup (self, table_common_settings, table_advanced_settings); } static void account_widget_settings_ready_cb (EmpathyAccountSettings *settings, - GParamSpec *pspec, gpointer user_data) + GParamSpec *pspec, + gpointer user_data) { - GtkBuilder *builder = GTK_BUILDER (user_data); + EmpathyAccountWidget *self = user_data; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - if (empathy_account_settings_is_ready (settings)) - account_widget_setup_generic (settings, builder); + if (empathy_account_settings_is_ready (priv->settings)) + account_widget_setup_generic (self); } -GtkWidget * -empathy_account_widget_generic_new (EmpathyAccountSettings *settings) +static void +account_widget_build_generic (EmpathyAccountWidget *self, + const char *filename) { - GtkBuilder *gui; - GtkWidget *widget; - gchar *filename; - - filename = empathy_file_lookup ("empathy-account-widget-generic.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_generic_settings", &widget, + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + priv->gui = empathy_builder_get_file (filename, + "vbox_generic_settings", &self->ui_details->widget, NULL); - if (empathy_account_settings_is_ready (settings)) - account_widget_setup_generic (settings, gui); + if (empathy_account_settings_is_ready (priv->settings)) + account_widget_setup_generic (self); else - g_signal_connect (settings, "notify::ready", - G_CALLBACK (account_widget_settings_ready_cb), gui); - - empathy_account_widget_add_apply_button (settings, widget); - - return g_object_ref (widget); + g_signal_connect (priv->settings, "notify::ready", + G_CALLBACK (account_widget_settings_ready_cb), self); } -GtkWidget * -empathy_account_widget_salut_new (EmpathyAccountSettings *settings) +static void +account_widget_build_salut (EmpathyAccountWidget *self, + const char *filename) { - GtkBuilder *gui; - GtkWidget *widget; - gchar *filename; - - filename = empathy_file_lookup ("empathy-account-widget-salut.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_salut_settings", &widget, + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + priv->gui = empathy_builder_get_file (filename, + "vbox_salut_settings", &self->ui_details->widget, NULL); - g_free (filename); - empathy_account_widget_handle_params (settings, gui, + empathy_account_widget_handle_params (self, "entry_published", "published-name", "entry_nickname", "nickname", "entry_first_name", "first-name", @@ -569,61 +542,44 @@ empathy_account_widget_salut_new (EmpathyAccountSettings *settings) "entry_jid", "jid", NULL); - empathy_account_widget_set_default_focus (gui, "entry_nickname"); - empathy_account_widget_add_apply_button (settings, widget); - - return empathy_builder_unref_and_keep_widget (gui, widget); + self->ui_details->default_focus = g_strdup ("entry_nickname"); } -GtkWidget * -empathy_account_widget_msn_new (EmpathyAccountSettings *settings) +static void +account_widget_build_msn (EmpathyAccountWidget *self, + const char *filename) { - GtkBuilder *gui; - GtkWidget *widget; - gchar *filename; - - filename = empathy_file_lookup ("empathy-account-widget-msn.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_msn_settings", &widget, + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + priv->gui = empathy_builder_get_file (filename, + "vbox_msn_settings", &self->ui_details->widget, NULL); - g_free (filename); - empathy_account_widget_handle_params (settings, gui, + empathy_account_widget_handle_params (self, "entry_id", "account", "entry_password", "password", "entry_server", "server", "spinbutton_port", "port", NULL); - empathy_account_widget_add_forget_button (settings, gui, - "button_forget", - "entry_password"); - - empathy_account_widget_set_default_focus (gui, "entry_id"); - - return empathy_builder_unref_and_keep_widget (gui, widget); + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; } -GtkWidget * -empathy_account_widget_jabber_new (EmpathyAccountSettings *settings) +static void +account_widget_build_jabber (EmpathyAccountWidget *self, + const char *filename) { - GtkBuilder *gui; - GtkWidget *widget; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); GtkWidget *spinbutton_port; GtkWidget *checkbutton_ssl; - gchar *filename; - filename = empathy_file_lookup ("empathy-account-widget-jabber.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_jabber_settings", &widget, + priv->gui = empathy_builder_get_file (filename, + "vbox_jabber_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, "checkbutton_ssl", &checkbutton_ssl, NULL); - g_free (filename); - empathy_account_widget_handle_params (settings, gui, + empathy_account_widget_handle_params (self, "entry_id", "account", "entry_password", "password", "entry_resource", "resource", @@ -635,38 +591,28 @@ empathy_account_widget_jabber_new (EmpathyAccountSettings *settings) "checkbutton_encryption", "require-encryption", NULL); - empathy_account_widget_add_forget_button (settings, gui, - "button_forget", - "entry_password"); - - empathy_account_widget_set_default_focus (gui, "entry_id"); + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; + priv->spinbutton_port = spinbutton_port; g_signal_connect (checkbutton_ssl, "toggled", G_CALLBACK (account_widget_jabber_ssl_toggled_cb), - spinbutton_port); - - empathy_account_widget_add_apply_button (settings, widget); - - return empathy_builder_unref_and_keep_widget (gui, widget); + self); } -GtkWidget * -empathy_account_widget_icq_new (EmpathyAccountSettings *settings) +static void +account_widget_build_icq (EmpathyAccountWidget *self, + const char *filename) { - GtkBuilder *gui; - GtkWidget *widget; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); GtkWidget *spinbutton_port; - gchar *filename; - filename = empathy_file_lookup ("empathy-account-widget-icq.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_icq_settings", &widget, + priv->gui = empathy_builder_get_file (filename, + "vbox_icq_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, NULL); - g_free (filename); - empathy_account_widget_handle_params (settings, gui, + empathy_account_widget_handle_params (self, "entry_uin", "account", "entry_password", "password", "entry_server", "server", @@ -674,65 +620,44 @@ empathy_account_widget_icq_new (EmpathyAccountSettings *settings) "entry_charset", "charset", NULL); - empathy_account_widget_add_forget_button (settings, gui, - "button_forget", - "entry_password"); - - empathy_account_widget_set_default_focus (gui, "entry_uin"); - - empathy_account_widget_add_apply_button (settings, widget); - - return empathy_builder_unref_and_keep_widget (gui, widget); + self->ui_details->default_focus = g_strdup ("entry_uin"); + self->ui_details->add_forget = TRUE; } -GtkWidget * -empathy_account_widget_aim_new (EmpathyAccountSettings *settings) +static void +account_widget_build_aim (EmpathyAccountWidget *self, + const char *filename) { - GtkBuilder *gui; - GtkWidget *widget; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); GtkWidget *spinbutton_port; - gchar *filename; - filename = empathy_file_lookup ("empathy-account-widget-aim.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_aim_settings", &widget, + priv->gui = empathy_builder_get_file (filename, + "vbox_aim_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, NULL); - g_free (filename); - empathy_account_widget_handle_params (settings, gui, + empathy_account_widget_handle_params (self, "entry_screenname", "account", "entry_password", "password", "entry_server", "server", "spinbutton_port", "port", NULL); - empathy_account_widget_add_forget_button (settings, gui, - "button_forget", - "entry_password"); - - empathy_account_widget_set_default_focus (gui, "entry_screenname"); - empathy_account_widget_add_apply_button (settings, widget); - - return empathy_builder_unref_and_keep_widget (gui, widget); + self->ui_details->default_focus = g_strdup ("entry_screenname"); + self->ui_details->add_forget = TRUE; } -GtkWidget * -empathy_account_widget_yahoo_new (EmpathyAccountSettings *settings) +static void +account_widget_build_yahoo (EmpathyAccountWidget *self, + const char *filename) { - GtkBuilder *gui; - GtkWidget *widget; - gchar *filename; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - filename = empathy_file_lookup ("empathy-account-widget-yahoo.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_yahoo_settings", &widget, + priv->gui = empathy_builder_get_file (filename, + "vbox_yahoo_settings", &self->ui_details->widget, NULL); - g_free (filename); - empathy_account_widget_handle_params (settings, gui, + empathy_account_widget_handle_params (self, "entry_id", "account", "entry_password", "password", "entry_server", "server", @@ -743,44 +668,209 @@ empathy_account_widget_yahoo_new (EmpathyAccountSettings *settings) "checkbutton_ignore_invites", "ignore-invites", NULL); - empathy_account_widget_add_forget_button (settings, gui, - "button_forget", - "entry_password"); - - empathy_account_widget_set_default_focus (gui, "entry_id"); - empathy_account_widget_add_apply_button (settings, widget); - - return empathy_builder_unref_and_keep_widget (gui, widget); + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; } -GtkWidget * -empathy_account_widget_groupwise_new (EmpathyAccountSettings *settings) +static void +account_widget_build_groupwise (EmpathyAccountWidget *self, + const char *filename) { - GtkBuilder *gui; - GtkWidget *widget; - gchar *filename; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - filename = empathy_file_lookup ("empathy-account-widget-groupwise.ui", - "libempathy-gtk"); - gui = empathy_builder_get_file (filename, - "vbox_groupwise_settings", &widget, - NULL); - g_free (filename); + priv->gui = empathy_builder_get_file (filename, + "vbox_groupwise_settings", &self->ui_details->widget, + NULL); - empathy_account_widget_handle_params (settings, gui, + empathy_account_widget_handle_params (self, "entry_id", "account", "entry_password", "password", "entry_server", "server", "spinbutton_port", "port", NULL); - empathy_account_widget_add_forget_button (settings, gui, - "button_forget", - "entry_password"); + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; +} - empathy_account_widget_set_default_focus (gui, "entry_id"); - empathy_account_widget_add_apply_button (settings, widget); +static void +do_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountWidgetPriv *priv = GET_PRIV (object); + + switch (prop_id) { + case PROP_PROTOCOL: + priv->protocol = g_value_dup_string (value); + break; + case PROP_SETTINGS: + priv->settings = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +do_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountWidgetPriv *priv = GET_PRIV (object); + + switch (prop_id) { + case PROP_PROTOCOL: + g_value_set_string (value, priv->protocol); + break; + case PROP_SETTINGS: + g_value_set_object (value, priv->settings); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +do_constructed (GObject *obj) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + 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); + else if (!tp_strdiff (priv->protocol, "sip")) + empathy_account_widget_sip_build (self, filename); + else + account_widget_build_generic (self, filename); + + g_free (uiname); + g_free (filename); + + /* handle default focus */ + if (self->ui_details->default_focus != NULL) + { + GObject *default_focus_entry; + + default_focus_entry = gtk_builder_get_object + (priv->gui, self->ui_details->default_focus); + g_signal_connect (default_focus_entry, "realize", + G_CALLBACK (gtk_widget_grab_focus), + NULL); + } + + /* handle forget button */ + if (self->ui_details->add_forget) + { + const gchar *password = NULL; + + priv->button_forget = GTK_WIDGET (gtk_builder_get_object (priv->gui, "button_forget")); + priv->entry_password = GTK_WIDGET (gtk_builder_get_object (priv->gui, "entry_password")); + + password = empathy_account_settings_get_string (priv->settings, "password"); + gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (password)); + + g_signal_connect (priv->button_forget, "clicked", + G_CALLBACK (account_widget_forget_clicked_cb), + self); + g_signal_connect (priv->entry_password, "changed", + G_CALLBACK (account_widget_password_changed_cb), + self); + } + + /* handle apply button */ + priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY); + gtk_box_pack_end (GTK_BOX (self->ui_details->widget), priv->apply_button, FALSE, FALSE, 3); + + g_signal_connect (priv->apply_button, "clicked", + G_CALLBACK (account_widget_apply_clicked_cb), + self); + gtk_widget_show (priv->apply_button); +} + +static void +empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + oclass->get_property = do_get_property; + oclass->set_property = do_set_property; + oclass->constructed = do_constructed; + + param_spec = g_param_spec_string ("protocol", + "protocol", "The protocol of the account", + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec); + + param_spec = g_param_spec_object ("settings", + "settings", "The settings of the account", + EMPATHY_TYPE_ACCOUNT_SETTINGS, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_SETTINGS, param_spec); + + g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); +} - return empathy_builder_unref_and_keep_widget (gui, widget); +static void +empathy_account_widget_init (EmpathyAccountWidget *self) +{ + EmpathyAccountWidgetPriv *priv = + G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET, + EmpathyAccountWidgetPriv); + + self->priv = priv; + self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails); } +void +empathy_account_widget_handle_params (EmpathyAccountWidget *self, + const gchar *first_widget, + ...) +{ + va_list args; + + va_start (args, first_widget); + account_widget_handle_params_valist (self, first_widget, args); + va_end (args); +} + +GtkWidget * +empathy_account_widget_new_for_protocol (const char *protocol, + EmpathyAccountSettings *settings) +{ + EmpathyAccountWidget *self; + EmpathyAccountWidgetPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL); + g_return_val_if_fail (settings != NULL, NULL); + + self = g_object_new + (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol, + "settings", settings, NULL); + priv = GET_PRIV (self); + + return self->ui_details->widget; +} \ No newline at end of file diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h index d3bd171fc..8a5f0f2c2 100644 --- a/libempathy-gtk/empathy-account-widget.h +++ b/libempathy-gtk/empathy-account-widget.h @@ -31,27 +31,37 @@ G_BEGIN_DECLS -void empathy_account_widget_handle_params (EmpathyAccountSettings *settings, - GtkBuilder *gui, - const gchar *first_widget, - ...); -void empathy_account_widget_add_forget_button (EmpathyAccountSettings *settings, - GtkBuilder *gui, - const gchar *button, - const gchar *entry); -void empathy_account_widget_add_apply_button (EmpathyAccountSettings *settings, - GtkWidget *vbox); - -void empathy_account_widget_set_default_focus (GtkBuilder *gui, - const gchar *entry); -GtkWidget *empathy_account_widget_generic_new (EmpathyAccountSettings *settings); -GtkWidget *empathy_account_widget_salut_new (EmpathyAccountSettings *settings); -GtkWidget *empathy_account_widget_msn_new (EmpathyAccountSettings *settings); -GtkWidget *empathy_account_widget_jabber_new (EmpathyAccountSettings *settings); -GtkWidget *empathy_account_widget_icq_new (EmpathyAccountSettings *settings); -GtkWidget *empathy_account_widget_aim_new (EmpathyAccountSettings *settings); -GtkWidget *empathy_account_widget_yahoo_new (EmpathyAccountSettings *settings); -GtkWidget *empathy_account_widget_groupwise_new (EmpathyAccountSettings *settings); +#define EMPATHY_TYPE_ACCOUNT_WIDGET empathy_account_widget_get_type() +#define EMPATHY_ACCOUNT_WIDGET(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidget)) +#define EMPATHY_ACCOUNT_WIDGET_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidgetClass)) +#define EMPATHY_IS_ACCOUNT_WIDGET(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET)) +#define EMPATHY_IS_ACCOUNT_WIDGET_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_WIDGET)) +#define EMPATHY_ACCOUNT_WIDGET_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidgetClass)) + +typedef struct _EmpathyAccountWidgetUIDetails EmpathyAccountWidgetUIDetails; + +typedef struct { + GObject parent; + + EmpathyAccountWidgetUIDetails *ui_details; + + /* private */ + gpointer priv; +} EmpathyAccountWidget; + +typedef struct { + GObjectClass parent_class; +} EmpathyAccountWidgetClass; + +GType empathy_account_widget_get_type (void); + +GtkWidget *empathy_account_widget_new_for_protocol (const char *protocol, + EmpathyAccountSettings *settings); G_END_DECLS diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 78ef4fe75..bfdae5c4c 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -137,28 +137,27 @@ accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, g_free (text); } -typedef GtkWidget *CreateWidget (EmpathyAccountSettings *); - static GtkWidget * get_account_setup_widget (EmpathyAccountSettings *settings) { const gchar *cm = empathy_account_settings_get_cm (settings); const gchar *proto = empathy_account_settings_get_protocol (settings); + + g_print ("cm : %s, proto %s\n", cm, proto); 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 } + { "gabble", "jabber" }, + { "butterfly", "msn" }, + { "salut", "local-xmpp" }, + { "idle", "irc" }, + { "haze", "icq" }, + { "haze", "aim" }, + { "haze", "yahoo" }, + { "haze", "groupwise" }, + { "sofiasip", "sip" }, + { NULL, NULL } }; int i; @@ -166,10 +165,10 @@ get_account_setup_widget (EmpathyAccountSettings *settings) { if (!tp_strdiff (cm, dialogs[i].cm) && !tp_strdiff (proto, dialogs[i].proto)) - return dialogs[i].cb (settings); + return empathy_account_widget_new_for_protocol (dialogs[i].proto, settings); } - return empathy_account_widget_generic_new (settings); + return empathy_account_widget_new_for_protocol ("generic", settings); } static void -- cgit v1.2.3 From 9e9bc5b2eebee732b8012cbcd649ebba1c320b65 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 27 Jul 2009 01:17:14 +0200 Subject: Update copyright and author --- libempathy-gtk/empathy-account-widget.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 76145c483..901fc68d9 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -1,7 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2006-2007 Imendio AB - * Copyright (C) 2007-2008 Collabora Ltd. + * Copyright (C) 2007-2009 Collabora Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,6 +20,7 @@ * * Authors: Xavier Claessens * Martyn Russell + * Cosimo Cecchi */ #include -- cgit v1.2.3 From c6e40cfec95a7f0bef133a96b74220a9bd295c72 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 27 Jul 2009 01:17:25 +0200 Subject: Use telepathy style --- libempathy-gtk/empathy-account-widget.c | 1289 ++++++++++++++++--------------- 1 file changed, 657 insertions(+), 632 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 901fc68d9..1a5c4f643 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -49,24 +49,24 @@ G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT) typedef struct { - GtkWidget *widget; + GtkWidget *widget; - char *protocol; - EmpathyAccountSettings *settings; + char *protocol; + EmpathyAccountSettings *settings; - GtkWidget *apply_button; - GtkWidget *entry_password; - GtkWidget *button_forget; - GtkWidget *spinbutton_port; - - GtkBuilder *gui; - char *default_focus; - gboolean add_forget; + GtkWidget *apply_button; + GtkWidget *entry_password; + GtkWidget *button_forget; + GtkWidget *spinbutton_port; + + GtkBuilder *gui; + char *default_focus; + gboolean add_forget; } EmpathyAccountWidgetPriv; enum { - PROP_PROTOCOL = 1, - PROP_SETTINGS + PROP_PROTOCOL = 1, + PROP_SETTINGS }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget) @@ -74,408 +74,431 @@ enum { static void account_widget_handle_apply_sensitivity (EmpathyAccountWidget *self) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - gtk_widget_set_sensitive (priv->apply_button, - empathy_account_settings_is_valid (priv->settings)); + gtk_widget_set_sensitive (priv->apply_button, + empathy_account_settings_is_valid (priv->settings)); } static gboolean -account_widget_entry_focus_cb (GtkWidget *widget, - GdkEventFocus *event, - EmpathyAccountWidget *self) +account_widget_entry_focus_cb (GtkWidget *widget, + GdkEventFocus *event, + EmpathyAccountWidget *self) { - const gchar *str; - const gchar *param_name; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - - str = gtk_entry_get_text (GTK_ENTRY (widget)); - param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - - if (EMP_STR_EMPTY (str)) { - const gchar *value = NULL; - - empathy_account_settings_unset (priv->settings, param_name); - value = empathy_account_settings_get_string (priv->settings, param_name); - DEBUG ("Unset %s and restore to %s", param_name, value); - gtk_entry_set_text (GTK_ENTRY (widget), value ? value : ""); - } else { - DEBUG ("Setting %s to %s", param_name, - strstr (param_name, "password") ? "***" : str); - empathy_account_settings_set_string (priv->settings, param_name, str); - } - - account_widget_handle_apply_sensitivity (self); - - return FALSE; + const gchar *str; + const gchar *param_name; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + str = gtk_entry_get_text (GTK_ENTRY (widget)); + param_name = g_object_get_data (G_OBJECT (widget), "param_name"); + + if (EMP_STR_EMPTY (str)) + { + const gchar *value = NULL; + + empathy_account_settings_unset (priv->settings, param_name); + value = empathy_account_settings_get_string (priv->settings, param_name); + DEBUG ("Unset %s and restore to %s", param_name, value); + gtk_entry_set_text (GTK_ENTRY (widget), value ? value : ""); + } + else + { + DEBUG ("Setting %s to %s", param_name, + strstr (param_name, "password") ? "***" : str); + empathy_account_settings_set_string (priv->settings, param_name, str); + } + + account_widget_handle_apply_sensitivity (self); + + return FALSE; } static void account_widget_int_changed_cb (GtkWidget *widget, - EmpathyAccountWidget *self) + EmpathyAccountWidget *self) { - const gchar *param_name; - gint value; - const gchar *signature; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - - value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); - param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - - signature = empathy_settings_get_dbus_signature (priv->settings, param_name); - g_return_if_fail (signature != NULL); - - DEBUG ("Setting %s to %d", param_name, value); - - switch ((int)*signature) - { - case DBUS_TYPE_INT16: - case DBUS_TYPE_INT32: - empathy_account_settings_set_int32 (priv->settings, param_name, value); - break; - case DBUS_TYPE_INT64: - empathy_account_settings_set_int64 (priv->settings, param_name, value); - break; - case DBUS_TYPE_UINT16: - case DBUS_TYPE_UINT32: - empathy_account_settings_set_uint32 (priv->settings, param_name, value); - break; - case DBUS_TYPE_UINT64: - empathy_account_settings_set_uint64 (priv->settings, param_name, value); - break; - default: - g_return_if_reached (); - } + const gchar *param_name; + gint value; + const gchar *signature; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); + param_name = g_object_get_data (G_OBJECT (widget), "param_name"); + + signature = empathy_settings_get_dbus_signature (priv->settings, param_name); + g_return_if_fail (signature != NULL); + + DEBUG ("Setting %s to %d", param_name, value); + + switch ((int)*signature) + { + case DBUS_TYPE_INT16: + case DBUS_TYPE_INT32: + empathy_account_settings_set_int32 (priv->settings, param_name, value); + break; + case DBUS_TYPE_INT64: + empathy_account_settings_set_int64 (priv->settings, param_name, value); + break; + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + empathy_account_settings_set_uint32 (priv->settings, param_name, value); + break; + case DBUS_TYPE_UINT64: + empathy_account_settings_set_uint64 (priv->settings, param_name, value); + break; + default: + g_return_if_reached (); + } - account_widget_handle_apply_sensitivity (self); + account_widget_handle_apply_sensitivity (self); } static void account_widget_checkbutton_toggled_cb (GtkWidget *widget, - EmpathyAccountWidget *self) + EmpathyAccountWidget *self) { - gboolean value; - gboolean default_value; - const gchar *param_name; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - - value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); - param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - - /* FIXME: This is ugly! checkbox don't have a "not-set" value so we - * always unset the param and set the value if different from the - * default value. */ - empathy_account_settings_unset (priv->settings, param_name); - default_value = empathy_account_settings_get_boolean (priv->settings, param_name); - - if (default_value == value) { - DEBUG ("Unset %s and restore to %d", param_name, default_value); - } else { - DEBUG ("Setting %s to %d", param_name, value); - empathy_account_settings_set_boolean (priv->settings, param_name, value); - } + gboolean value; + gboolean default_value; + const gchar *param_name; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + param_name = g_object_get_data (G_OBJECT (widget), "param_name"); + + /* FIXME: This is ugly! checkbox don't have a "not-set" value so we + * always unset the param and set the value if different from the + * default value. */ + empathy_account_settings_unset (priv->settings, param_name); + default_value = empathy_account_settings_get_boolean (priv->settings, param_name); + + if (default_value == value) + { + DEBUG ("Unset %s and restore to %d", param_name, default_value); + } + else + { + DEBUG ("Setting %s to %d", param_name, value); + empathy_account_settings_set_boolean (priv->settings, param_name, value); + } - account_widget_handle_apply_sensitivity (self); + account_widget_handle_apply_sensitivity (self); } static void account_widget_forget_clicked_cb (GtkWidget *button, - EmpathyAccountWidget *self) + EmpathyAccountWidget *self) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - const gchar *param_name; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + const gchar *param_name; - param_name = g_object_get_data (G_OBJECT (priv->entry_password), "param_name"); + param_name = g_object_get_data (G_OBJECT (priv->entry_password), "param_name"); - DEBUG ("Unset %s", param_name); - empathy_account_settings_unset (priv->settings, param_name); - gtk_entry_set_text (GTK_ENTRY (priv->entry_password), ""); + DEBUG ("Unset %s", param_name); + empathy_account_settings_unset (priv->settings, param_name); + gtk_entry_set_text (GTK_ENTRY (priv->entry_password), ""); - account_widget_handle_apply_sensitivity (self); + account_widget_handle_apply_sensitivity (self); } static void account_widget_password_changed_cb (GtkWidget *entry, - GtkWidget *button) + GtkWidget *button) { - const gchar *str; + const gchar *str; - str = gtk_entry_get_text (GTK_ENTRY (entry)); - gtk_widget_set_sensitive (button, !EMP_STR_EMPTY (str)); + str = gtk_entry_get_text (GTK_ENTRY (entry)); + gtk_widget_set_sensitive (button, !EMP_STR_EMPTY (str)); } static void account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, - EmpathyAccountWidget *self) + EmpathyAccountWidget *self) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - gboolean value; - gint32 port = 0; - - value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl)); - port = empathy_account_settings_get_uint32 (priv->settings, "port"); - - if (value) { - if (port == 5222 || port == 0) { - port = 5223; - } - } else { - if (port == 5223 || port == 0) { - port = 5222; - } - } - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + gboolean value; + gint32 port = 0; + + value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl)); + port = empathy_account_settings_get_uint32 (priv->settings, "port"); + + if (value) + { + if (port == 5222 || port == 0) + port = 5223; + } + else + { + if (port == 5223 || port == 0) + port = 5222; + } + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port); } static void account_widget_setup_widget (EmpathyAccountWidget *self, - GtkWidget *widget, - const gchar *param_name) + GtkWidget *widget, + const gchar *param_name) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - g_object_set_data_full (G_OBJECT (widget), "param_name", - g_strdup (param_name), g_free); - - if (GTK_IS_SPIN_BUTTON (widget)) { - gint value = 0; - const gchar *signature; - - signature = empathy_settings_get_dbus_signature (priv->settings, param_name); - g_return_if_fail (signature != NULL); - - switch ((int)*signature) - { - case DBUS_TYPE_INT16: - case DBUS_TYPE_INT32: - value = empathy_account_settings_get_int32 (priv->settings, param_name); - break; - case DBUS_TYPE_INT64: - value = empathy_account_settings_get_int64 (priv->settings, param_name); - break; - case DBUS_TYPE_UINT16: - case DBUS_TYPE_UINT32: - value = empathy_account_settings_get_uint32 (priv->settings, param_name); - break; - case DBUS_TYPE_UINT64: - value = empathy_account_settings_get_uint64 (priv->settings, param_name); - break; - default: - g_return_if_reached (); - } - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); - - g_signal_connect (widget, "value-changed", - G_CALLBACK (account_widget_int_changed_cb), - self); - } - else if (GTK_IS_ENTRY (widget)) { - const gchar *str = NULL; - - str = empathy_account_settings_get_string (priv->settings, param_name); - gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); - - if (strstr (param_name, "password")) { - gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE); - } - - g_signal_connect (widget, "focus-out-event", - G_CALLBACK (account_widget_entry_focus_cb), - self); - } - else if (GTK_IS_TOGGLE_BUTTON (widget)) { - gboolean value = FALSE; - - value = empathy_account_settings_get_boolean (priv->settings, param_name); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); - - g_signal_connect (widget, "toggled", - G_CALLBACK (account_widget_checkbutton_toggled_cb), - self); - } else { - DEBUG ("Unknown type of widget for param %s", param_name); - } + g_object_set_data_full (G_OBJECT (widget), "param_name", + g_strdup (param_name), g_free); + + if (GTK_IS_SPIN_BUTTON (widget)) + { + gint value = 0; + const gchar *signature; + + signature = empathy_settings_get_dbus_signature (priv->settings, param_name); + g_return_if_fail (signature != NULL); + + switch ((int)*signature) + { + case DBUS_TYPE_INT16: + case DBUS_TYPE_INT32: + value = empathy_account_settings_get_int32 (priv->settings, param_name); + break; + case DBUS_TYPE_INT64: + value = empathy_account_settings_get_int64 (priv->settings, param_name); + break; + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + value = empathy_account_settings_get_uint32 (priv->settings, param_name); + break; + case DBUS_TYPE_UINT64: + value = empathy_account_settings_get_uint64 (priv->settings, param_name); + break; + default: + g_return_if_reached (); + } + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); + + g_signal_connect (widget, "value-changed", + G_CALLBACK (account_widget_int_changed_cb), + self); + } + else if (GTK_IS_ENTRY (widget)) + { + const gchar *str = NULL; + + str = empathy_account_settings_get_string (priv->settings, param_name); + gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); + + if (strstr (param_name, "password")) + { + gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE); + } + + g_signal_connect (widget, "focus-out-event", + G_CALLBACK (account_widget_entry_focus_cb), + self); + } + else if (GTK_IS_TOGGLE_BUTTON (widget)) + { + gboolean value = FALSE; + + value = empathy_account_settings_get_boolean (priv->settings, param_name); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); + + g_signal_connect (widget, "toggled", + G_CALLBACK (account_widget_checkbutton_toggled_cb), + self); + } + else + { + DEBUG ("Unknown type of widget for param %s", param_name); + } } static gchar * account_widget_generic_format_param_name (const gchar *param_name) { - gchar *str; - gchar *p; + gchar *str; + gchar *p; - str = g_strdup (param_name); + str = g_strdup (param_name); - if (str && g_ascii_isalpha (str[0])) { - str[0] = g_ascii_toupper (str[0]); - } + if (str && g_ascii_isalpha (str[0])) + str[0] = g_ascii_toupper (str[0]); - while ((p = strchr (str, '-')) != NULL) { - if (p[1] != '\0' && g_ascii_isalpha (p[1])) { - p[0] = ' '; - p[1] = g_ascii_toupper (p[1]); - } + while ((p = strchr (str, '-')) != NULL) + { + if (p[1] != '\0' && g_ascii_isalpha (p[1])) + { + p[0] = ' '; + p[1] = g_ascii_toupper (p[1]); + } - p++; - } + p++; + } - return str; + return str; } static void accounts_widget_generic_setup (EmpathyAccountWidget *self, - GtkWidget *table_common_settings, - GtkWidget *table_advanced_settings) + GtkWidget *table_common_settings, + GtkWidget *table_advanced_settings) { - TpConnectionManagerParam *params, *param; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - - params = empathy_account_settings_get_tp_params (priv->settings); - - for (param = params; param != NULL && param->name != NULL; param++) { - GtkWidget *table_settings; - guint n_rows = 0; - GtkWidget *widget = NULL; - gchar *param_name_formatted; - - if (param->flags & TP_CONN_MGR_PARAM_FLAG_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->dbus_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 (gtk_widget_grab_focus), - 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->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->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; - 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->dbus_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->dbus_signature); - } - - if (widget) { - account_widget_setup_widget (self, widget, param->name); - } - - g_free (param_name_formatted); - } + TpConnectionManagerParam *params, *param; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + params = empathy_account_settings_get_tp_params (priv->settings); + + for (param = params; param != NULL && param->name != NULL; param++) + { + GtkWidget *table_settings; + guint n_rows = 0; + GtkWidget *widget = NULL; + gchar *param_name_formatted; + + if (param->flags & TP_CONN_MGR_PARAM_FLAG_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->dbus_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 (gtk_widget_grab_focus), + 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->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->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; + 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->dbus_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->dbus_signature); + } + + if (widget) + account_widget_setup_widget (self, widget, param->name); + + g_free (param_name_formatted); + } } static void account_widget_handle_params_valist (EmpathyAccountWidget *self, - const gchar *first_widget, - va_list args) + const gchar *first_widget, + va_list args) { - GObject *object; - const gchar *name; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + GObject *object; + const gchar *name; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - for (name = first_widget; name; name = va_arg (args, const gchar *)) { - const gchar *param_name; + for (name = first_widget; name; name = va_arg (args, const gchar *)) + { + const gchar *param_name; - param_name = va_arg (args, const gchar *); - object = gtk_builder_get_object (priv->gui, name); + param_name = va_arg (args, const gchar *); + object = gtk_builder_get_object (priv->gui, name); - if (!object) { - g_warning ("Builder is missing object '%s'.", name); - continue; - } + if (!object) + { + g_warning ("Builder is missing object '%s'.", name); + continue; + } - account_widget_setup_widget (self, GTK_WIDGET (object), param_name); - } + account_widget_setup_widget (self, GTK_WIDGET (object), param_name); + } } static void account_widget_apply_clicked_cb (GtkWidget *button, - EmpathyAccountWidget *self) + EmpathyAccountWidget *self) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); empathy_account_settings_apply_async (priv->settings, NULL, NULL); } @@ -483,395 +506,397 @@ account_widget_apply_clicked_cb (GtkWidget *button, static void account_widget_setup_generic (EmpathyAccountWidget *self) { - GtkWidget *table_common_settings; - GtkWidget *table_advanced_settings; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + GtkWidget *table_common_settings; + GtkWidget *table_advanced_settings; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - table_common_settings = GTK_WIDGET (gtk_builder_get_object (priv->gui, - "table_common_settings")); - table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (priv->gui, - "table_advanced_settings")); + table_common_settings = GTK_WIDGET (gtk_builder_get_object (priv->gui, + "table_common_settings")); + table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (priv->gui, + "table_advanced_settings")); - accounts_widget_generic_setup (self, table_common_settings, - table_advanced_settings); + accounts_widget_generic_setup (self, table_common_settings, + table_advanced_settings); } static void account_widget_settings_ready_cb (EmpathyAccountSettings *settings, - GParamSpec *pspec, - gpointer user_data) + GParamSpec *pspec, + gpointer user_data) { - EmpathyAccountWidget *self = user_data; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + EmpathyAccountWidget *self = user_data; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - if (empathy_account_settings_is_ready (priv->settings)) - account_widget_setup_generic (self); + if (empathy_account_settings_is_ready (priv->settings)) + account_widget_setup_generic (self); } static void account_widget_build_generic (EmpathyAccountWidget *self, - const char *filename) + const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - priv->gui = empathy_builder_get_file (filename, - "vbox_generic_settings", &self->ui_details->widget, - NULL); - - if (empathy_account_settings_is_ready (priv->settings)) - account_widget_setup_generic (self); - else - g_signal_connect (priv->settings, "notify::ready", - G_CALLBACK (account_widget_settings_ready_cb), self); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + priv->gui = empathy_builder_get_file (filename, + "vbox_generic_settings", &self->ui_details->widget, + NULL); + + if (empathy_account_settings_is_ready (priv->settings)) + account_widget_setup_generic (self); + else + g_signal_connect (priv->settings, "notify::ready", + G_CALLBACK (account_widget_settings_ready_cb), self); } static void account_widget_build_salut (EmpathyAccountWidget *self, - const char *filename) + const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - priv->gui = empathy_builder_get_file (filename, - "vbox_salut_settings", &self->ui_details->widget, - NULL); - - empathy_account_widget_handle_params (self, - "entry_published", "published-name", - "entry_nickname", "nickname", - "entry_first_name", "first-name", - "entry_last_name", "last-name", - "entry_email", "email", - "entry_jid", "jid", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_nickname"); + priv->gui = empathy_builder_get_file (filename, + "vbox_salut_settings", &self->ui_details->widget, + NULL); + + empathy_account_widget_handle_params (self, + "entry_published", "published-name", + "entry_nickname", "nickname", + "entry_first_name", "first-name", + "entry_last_name", "last-name", + "entry_email", "email", + "entry_jid", "jid", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_nickname"); } static void account_widget_build_msn (EmpathyAccountWidget *self, - const char *filename) + const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - priv->gui = empathy_builder_get_file (filename, - "vbox_msn_settings", &self->ui_details->widget, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id"); - self->ui_details->add_forget = TRUE; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + priv->gui = empathy_builder_get_file (filename, + "vbox_msn_settings", &self->ui_details->widget, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; } static void account_widget_build_jabber (EmpathyAccountWidget *self, - const char *filename) + const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - GtkWidget *spinbutton_port; - GtkWidget *checkbutton_ssl; - - priv->gui = empathy_builder_get_file (filename, - "vbox_jabber_settings", &self->ui_details->widget, - "spinbutton_port", &spinbutton_port, - "checkbutton_ssl", &checkbutton_ssl, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_resource", "resource", - "entry_server", "server", - "spinbutton_port", "port", - "spinbutton_priority", "priority", - "checkbutton_ssl", "old-ssl", - "checkbutton_ignore_ssl_errors", "ignore-ssl-errors", - "checkbutton_encryption", "require-encryption", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id"); - self->ui_details->add_forget = TRUE; - priv->spinbutton_port = spinbutton_port; - - g_signal_connect (checkbutton_ssl, "toggled", - G_CALLBACK (account_widget_jabber_ssl_toggled_cb), - self); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + GtkWidget *spinbutton_port; + GtkWidget *checkbutton_ssl; + + priv->gui = empathy_builder_get_file (filename, + "vbox_jabber_settings", &self->ui_details->widget, + "spinbutton_port", &spinbutton_port, + "checkbutton_ssl", &checkbutton_ssl, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_resource", "resource", + "entry_server", "server", + "spinbutton_port", "port", + "spinbutton_priority", "priority", + "checkbutton_ssl", "old-ssl", + "checkbutton_ignore_ssl_errors", "ignore-ssl-errors", + "checkbutton_encryption", "require-encryption", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; + priv->spinbutton_port = spinbutton_port; + + g_signal_connect (checkbutton_ssl, "toggled", + G_CALLBACK (account_widget_jabber_ssl_toggled_cb), + self); } static void account_widget_build_icq (EmpathyAccountWidget *self, - const char *filename) + const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - GtkWidget *spinbutton_port; - - priv->gui = empathy_builder_get_file (filename, - "vbox_icq_settings", &self->ui_details->widget, - "spinbutton_port", &spinbutton_port, - NULL); - - empathy_account_widget_handle_params (self, - "entry_uin", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - "entry_charset", "charset", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_uin"); - self->ui_details->add_forget = TRUE; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + GtkWidget *spinbutton_port; + + priv->gui = empathy_builder_get_file (filename, + "vbox_icq_settings", &self->ui_details->widget, + "spinbutton_port", &spinbutton_port, + NULL); + + empathy_account_widget_handle_params (self, + "entry_uin", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + "entry_charset", "charset", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_uin"); + self->ui_details->add_forget = TRUE; } static void account_widget_build_aim (EmpathyAccountWidget *self, - const char *filename) + const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - GtkWidget *spinbutton_port; - - priv->gui = empathy_builder_get_file (filename, - "vbox_aim_settings", &self->ui_details->widget, - "spinbutton_port", &spinbutton_port, - NULL); - - empathy_account_widget_handle_params (self, - "entry_screenname", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_screenname"); - self->ui_details->add_forget = TRUE; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + GtkWidget *spinbutton_port; + + priv->gui = empathy_builder_get_file (filename, + "vbox_aim_settings", &self->ui_details->widget, + "spinbutton_port", &spinbutton_port, + NULL); + + empathy_account_widget_handle_params (self, + "entry_screenname", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_screenname"); + self->ui_details->add_forget = TRUE; } static void account_widget_build_yahoo (EmpathyAccountWidget *self, - const char *filename) + const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - - priv->gui = empathy_builder_get_file (filename, - "vbox_yahoo_settings", &self->ui_details->widget, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_server", "server", - "entry_locale", "room-list-locale", - "entry_charset", "charset", - "spinbutton_port", "port", - "checkbutton_yahoojp", "yahoojp", - "checkbutton_ignore_invites", "ignore-invites", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id"); - self->ui_details->add_forget = TRUE; + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + priv->gui = empathy_builder_get_file (filename, + "vbox_yahoo_settings", &self->ui_details->widget, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_server", "server", + "entry_locale", "room-list-locale", + "entry_charset", "charset", + "spinbutton_port", "port", + "checkbutton_yahoojp", "yahoojp", + "checkbutton_ignore_invites", "ignore-invites", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; } static void account_widget_build_groupwise (EmpathyAccountWidget *self, - const char *filename) + const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - priv->gui = empathy_builder_get_file (filename, - "vbox_groupwise_settings", &self->ui_details->widget, - NULL); + priv->gui = empathy_builder_get_file (filename, + "vbox_groupwise_settings", &self->ui_details->widget, + NULL); - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); - self->ui_details->default_focus = g_strdup ("entry_id"); - self->ui_details->add_forget = TRUE; + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; } static void do_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (object); - - switch (prop_id) { - case PROP_PROTOCOL: - priv->protocol = g_value_dup_string (value); - break; - case PROP_SETTINGS: - priv->settings = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } + EmpathyAccountWidgetPriv *priv = GET_PRIV (object); + + switch (prop_id) + { + case PROP_PROTOCOL: + priv->protocol = g_value_dup_string (value); + break; + case PROP_SETTINGS: + priv->settings = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } } static void do_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (object); - - switch (prop_id) { - case PROP_PROTOCOL: - g_value_set_string (value, priv->protocol); - break; - case PROP_SETTINGS: - g_value_set_object (value, priv->settings); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } + EmpathyAccountWidgetPriv *priv = GET_PRIV (object); + + switch (prop_id) + { + case PROP_PROTOCOL: + g_value_set_string (value, priv->protocol); + break; + case PROP_SETTINGS: + g_value_set_object (value, priv->settings); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } } static void do_constructed (GObject *obj) { - EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - 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); - else if (!tp_strdiff (priv->protocol, "sip")) - empathy_account_widget_sip_build (self, filename); - else - account_widget_build_generic (self, filename); - - g_free (uiname); - g_free (filename); - - /* handle default focus */ - if (self->ui_details->default_focus != NULL) - { - GObject *default_focus_entry; - - default_focus_entry = gtk_builder_get_object - (priv->gui, self->ui_details->default_focus); - g_signal_connect (default_focus_entry, "realize", - G_CALLBACK (gtk_widget_grab_focus), - NULL); - } - - /* handle forget button */ - if (self->ui_details->add_forget) - { - const gchar *password = NULL; - - priv->button_forget = GTK_WIDGET (gtk_builder_get_object (priv->gui, "button_forget")); - priv->entry_password = GTK_WIDGET (gtk_builder_get_object (priv->gui, "entry_password")); - - password = empathy_account_settings_get_string (priv->settings, "password"); - gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (password)); - - g_signal_connect (priv->button_forget, "clicked", - G_CALLBACK (account_widget_forget_clicked_cb), - self); - g_signal_connect (priv->entry_password, "changed", - G_CALLBACK (account_widget_password_changed_cb), - self); - } - - /* handle apply button */ - priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY); - gtk_box_pack_end (GTK_BOX (self->ui_details->widget), priv->apply_button, FALSE, FALSE, 3); - - g_signal_connect (priv->apply_button, "clicked", - G_CALLBACK (account_widget_apply_clicked_cb), - self); - gtk_widget_show (priv->apply_button); + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + 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); + else if (!tp_strdiff (priv->protocol, "sip")) + empathy_account_widget_sip_build (self, filename); + else + account_widget_build_generic (self, filename); + + g_free (uiname); + g_free (filename); + + /* handle default focus */ + if (self->ui_details->default_focus != NULL) + { + GObject *default_focus_entry; + + default_focus_entry = gtk_builder_get_object + (priv->gui, self->ui_details->default_focus); + g_signal_connect (default_focus_entry, "realize", + G_CALLBACK (gtk_widget_grab_focus), + NULL); + } + + /* handle forget button */ + if (self->ui_details->add_forget) + { + const gchar *password = NULL; + + priv->button_forget = GTK_WIDGET (gtk_builder_get_object (priv->gui, "button_forget")); + priv->entry_password = GTK_WIDGET (gtk_builder_get_object (priv->gui, "entry_password")); + + password = empathy_account_settings_get_string (priv->settings, "password"); + gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (password)); + + g_signal_connect (priv->button_forget, "clicked", + G_CALLBACK (account_widget_forget_clicked_cb), + self); + g_signal_connect (priv->entry_password, "changed", + G_CALLBACK (account_widget_password_changed_cb), + self); + } + + /* handle apply button */ + priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY); + gtk_box_pack_end (GTK_BOX (self->ui_details->widget), priv->apply_button, FALSE, FALSE, 3); + + g_signal_connect (priv->apply_button, "clicked", + G_CALLBACK (account_widget_apply_clicked_cb), + self); + gtk_widget_show (priv->apply_button); } static void empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) { - GObjectClass *oclass = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; + GObjectClass *oclass = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; - oclass->get_property = do_get_property; - oclass->set_property = do_set_property; - oclass->constructed = do_constructed; + oclass->get_property = do_get_property; + oclass->set_property = do_set_property; + oclass->constructed = do_constructed; - param_spec = g_param_spec_string ("protocol", + param_spec = g_param_spec_string ("protocol", "protocol", "The protocol of the account", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec); - param_spec = g_param_spec_object ("settings", + param_spec = g_param_spec_object ("settings", "settings", "The settings of the account", EMPATHY_TYPE_ACCOUNT_SETTINGS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (oclass, PROP_SETTINGS, param_spec); - g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); + g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); } static void empathy_account_widget_init (EmpathyAccountWidget *self) { - EmpathyAccountWidgetPriv *priv = - G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET, - EmpathyAccountWidgetPriv); + EmpathyAccountWidgetPriv *priv = + G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET, + EmpathyAccountWidgetPriv); - self->priv = priv; - self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails); + self->priv = priv; + self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails); } void empathy_account_widget_handle_params (EmpathyAccountWidget *self, - const gchar *first_widget, - ...) + const gchar *first_widget, + ...) { - va_list args; + va_list args; - va_start (args, first_widget); - account_widget_handle_params_valist (self, first_widget, args); - va_end (args); + va_start (args, first_widget); + account_widget_handle_params_valist (self, first_widget, args); + va_end (args); } GtkWidget * empathy_account_widget_new_for_protocol (const char *protocol, - EmpathyAccountSettings *settings) + EmpathyAccountSettings *settings) { - EmpathyAccountWidget *self; - EmpathyAccountWidgetPriv *priv; + EmpathyAccountWidget *self; + EmpathyAccountWidgetPriv *priv; - g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL); - g_return_val_if_fail (settings != NULL, NULL); + g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL); + g_return_val_if_fail (settings != NULL, NULL); - self = g_object_new - (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol, - "settings", settings, NULL); - priv = GET_PRIV (self); + self = g_object_new + (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol, + "settings", settings, NULL); + priv = GET_PRIV (self); - return self->ui_details->widget; -} \ No newline at end of file + return self->ui_details->widget; +} -- cgit v1.2.3 From 68f828614636f87c93af780960954c923cf2faf6 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 27 Jul 2009 01:18:31 +0200 Subject: Add a cosmetic comment to separate public and non-public methods. --- libempathy-gtk/empathy-account-widget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 1a5c4f643..0695e95a6 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -871,6 +871,8 @@ empathy_account_widget_init (EmpathyAccountWidget *self) self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails); } +/* public methods */ + void empathy_account_widget_handle_params (EmpathyAccountWidget *self, const gchar *first_widget, -- cgit v1.2.3 From 207d7ac4384915a0fd3a65f609a04eeb59cb98e0 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 27 Jul 2009 01:24:42 +0200 Subject: Remove debug output --- src/empathy-accounts-dialog.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index bfdae5c4c..0cfcd7c48 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -143,7 +143,6 @@ get_account_setup_widget (EmpathyAccountSettings *settings) const gchar *cm = empathy_account_settings_get_cm (settings); const gchar *proto = empathy_account_settings_get_protocol (settings); - g_print ("cm : %s, proto %s\n", cm, proto); struct { const gchar *cm; const gchar *proto; -- cgit v1.2.3 From 7f58866b6d20c71e21af8d90dc714f32de077af5 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 27 Jul 2009 01:24:53 +0200 Subject: Set apply button sensitivity on creation --- libempathy-gtk/empathy-account-widget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 0695e95a6..c171a6549 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -832,6 +832,7 @@ do_constructed (GObject *obj) g_signal_connect (priv->apply_button, "clicked", G_CALLBACK (account_widget_apply_clicked_cb), self); + account_widget_handle_apply_sensitivity (self); gtk_widget_show (priv->apply_button); } -- cgit v1.2.3 From 9980b694fec4e3d205555a88040571365416455b Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 27 Jul 2009 11:52:06 +0200 Subject: Implement dispose and finalize --- libempathy-gtk/empathy-account-widget.c | 106 ++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 31 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index c171a6549..0361b957c 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -49,8 +49,6 @@ G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT) typedef struct { - GtkWidget *widget; - char *protocol; EmpathyAccountSettings *settings; @@ -59,9 +57,7 @@ typedef struct { GtkWidget *button_forget; GtkWidget *spinbutton_port; - GtkBuilder *gui; - char *default_focus; - gboolean add_forget; + gboolean dispose_run; } EmpathyAccountWidgetPriv; enum { @@ -475,14 +471,13 @@ account_widget_handle_params_valist (EmpathyAccountWidget *self, { GObject *object; const gchar *name; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); for (name = first_widget; name; name = va_arg (args, const gchar *)) { const gchar *param_name; param_name = va_arg (args, const gchar *); - object = gtk_builder_get_object (priv->gui, name); + object = gtk_builder_get_object (self->ui_details->gui, name); if (!object) { @@ -508,15 +503,16 @@ account_widget_setup_generic (EmpathyAccountWidget *self) { GtkWidget *table_common_settings; GtkWidget *table_advanced_settings; - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - table_common_settings = GTK_WIDGET (gtk_builder_get_object (priv->gui, + table_common_settings = GTK_WIDGET (gtk_builder_get_object (self->ui_details->gui, "table_common_settings")); - table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (priv->gui, + table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (self->ui_details->gui, "table_advanced_settings")); accounts_widget_generic_setup (self, table_common_settings, table_advanced_settings); + + g_object_unref (self->ui_details->gui); } static void @@ -536,10 +532,12 @@ account_widget_build_generic (EmpathyAccountWidget *self, const char *filename) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - priv->gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_generic_settings", &self->ui_details->widget, NULL); + g_object_ref (self->ui_details->gui); + if (empathy_account_settings_is_ready (priv->settings)) account_widget_setup_generic (self); else @@ -551,9 +549,7 @@ static void account_widget_build_salut (EmpathyAccountWidget *self, const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - - priv->gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_salut_settings", &self->ui_details->widget, NULL); @@ -573,8 +569,7 @@ static void account_widget_build_msn (EmpathyAccountWidget *self, const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - priv->gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_msn_settings", &self->ui_details->widget, NULL); @@ -597,7 +592,7 @@ account_widget_build_jabber (EmpathyAccountWidget *self, GtkWidget *spinbutton_port; GtkWidget *checkbutton_ssl; - priv->gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_jabber_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, "checkbutton_ssl", &checkbutton_ssl, @@ -628,10 +623,9 @@ static void account_widget_build_icq (EmpathyAccountWidget *self, const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); GtkWidget *spinbutton_port; - priv->gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_icq_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, NULL); @@ -652,10 +646,9 @@ static void account_widget_build_aim (EmpathyAccountWidget *self, const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); GtkWidget *spinbutton_port; - priv->gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_aim_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, NULL); @@ -675,9 +668,7 @@ static void account_widget_build_yahoo (EmpathyAccountWidget *self, const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - - priv->gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_yahoo_settings", &self->ui_details->widget, NULL); @@ -700,9 +691,7 @@ static void account_widget_build_groupwise (EmpathyAccountWidget *self, const char *filename) { - EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - - priv->gui = empathy_builder_get_file (filename, + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_groupwise_settings", &self->ui_details->widget, NULL); @@ -788,8 +777,15 @@ do_constructed (GObject *obj) empathy_account_widget_irc_build (self, filename); else if (!tp_strdiff (priv->protocol, "sip")) empathy_account_widget_sip_build (self, filename); - else + else if (!tp_strdiff (priv->protocol, "generic")) account_widget_build_generic (self, filename); + else + { + g_free (uiname); + g_free (filename); + g_critical ("Unknown protocol, can't build the account widget"); + return; + } g_free (uiname); g_free (filename); @@ -800,7 +796,7 @@ do_constructed (GObject *obj) GObject *default_focus_entry; default_focus_entry = gtk_builder_get_object - (priv->gui, self->ui_details->default_focus); + (self->ui_details->gui, self->ui_details->default_focus); g_signal_connect (default_focus_entry, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL); @@ -811,8 +807,8 @@ do_constructed (GObject *obj) { const gchar *password = NULL; - priv->button_forget = GTK_WIDGET (gtk_builder_get_object (priv->gui, "button_forget")); - priv->entry_password = GTK_WIDGET (gtk_builder_get_object (priv->gui, "entry_password")); + priv->button_forget = GTK_WIDGET (gtk_builder_get_object (self->ui_details->gui, "button_forget")); + priv->entry_password = GTK_WIDGET (gtk_builder_get_object (self->ui_details->gui, "entry_password")); password = empathy_account_settings_get_string (priv->settings, "password"); gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (password)); @@ -834,6 +830,50 @@ do_constructed (GObject *obj) self); account_widget_handle_apply_sensitivity (self); gtk_widget_show (priv->apply_button); + + empathy_builder_unref_and_keep_widget (self->ui_details->gui, self->ui_details->widget); +} + +static void +do_dispose (GObject *obj) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + if (priv->dispose_run) + return; + + priv->dispose_run = TRUE; + + if (self->ui_details->gui != NULL) + { + g_object_unref (self->ui_details->gui); + self->ui_details->gui = NULL; + } + + if (priv->settings != NULL) + { + g_object_unref (priv->settings); + priv->settings = NULL; + } + + if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL) + G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj); +} + +static void +do_finalize (GObject *obj) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + g_free (self->ui_details->default_focus); + g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details); + + g_free (priv->protocol); + + if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL) + G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj); } static void @@ -845,6 +885,8 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) oclass->get_property = do_get_property; oclass->set_property = do_set_property; oclass->constructed = do_constructed; + oclass->dispose = do_dispose; + oclass->finalize = do_finalize; param_spec = g_param_spec_string ("protocol", "protocol", "The protocol of the account", @@ -869,6 +911,8 @@ empathy_account_widget_init (EmpathyAccountWidget *self) EmpathyAccountWidgetPriv); self->priv = priv; + priv->dispose_run = FALSE; + self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails); } -- cgit v1.2.3 From 10439722fe6985ff89c61e8c7488113e1a52806e Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 29 Jul 2009 22:44:22 +0200 Subject: Rename empathy_account_settings_owns_account() Call it empathy_account_settings_has_account() instead --- libempathy/empathy-account-settings.c | 2 +- libempathy/empathy-account-settings.h | 2 +- src/empathy-accounts-dialog.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 59cfcc525..21109d261 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -1028,7 +1028,7 @@ empathy_account_settings_apply_finish (EmpathyAccountSettings *settings, } gboolean -empathy_account_settings_owns_account (EmpathyAccountSettings *settings, +empathy_account_settings_has_account (EmpathyAccountSettings *settings, EmpathyAccount *account) { EmpathyAccountSettingsPriv *priv; diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h index b660addd0..06e5e69e3 100644 --- a/libempathy/empathy-account-settings.h +++ b/libempathy/empathy-account-settings.h @@ -77,7 +77,7 @@ const gchar *empathy_account_settings_get_protocol ( EmpathyAccount *empathy_account_settings_get_account ( EmpathyAccountSettings *settings); -gboolean empathy_account_settings_owns_account ( +gboolean empathy_account_settings_has_account ( EmpathyAccountSettings *settings, EmpathyAccount *account); TpConnectionManagerParam *empathy_account_settings_get_tp_params ( diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 0cfcd7c48..95c3ac146 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -712,7 +712,7 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); - equal = empathy_account_settings_owns_account + equal = empathy_account_settings_has_account (settings, account); g_object_unref (settings); -- cgit v1.2.3 From 3c966e213e602fc6bb289a30b62f12122dcbdee9 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 29 Jul 2009 23:06:35 +0200 Subject: Make account creation non-exclusive As it's valid to create more than an account at the same time, we should permit it with subsequent calls to EmpathyAccountManager. --- libempathy/empathy-account-manager.c | 68 ++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 71cf34fb9..cb86e0881 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -63,7 +63,7 @@ typedef struct { gchar *desired_status; gchar *desired_status_message; - GSimpleAsyncResult *create_result; + GHashTable *create_results; } EmpathyAccountManagerPriv; enum { @@ -285,6 +285,7 @@ account_manager_account_ready_cb (GObject *obj, EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); EmpathyAccountManagerPriv *priv = GET_PRIV (manager); EmpathyAccount *account = EMPATHY_ACCOUNT (obj); + GSimpleAsyncResult *result; gboolean ready; g_object_get (account, "ready", &ready, NULL); @@ -292,14 +293,17 @@ account_manager_account_ready_cb (GObject *obj, if (!ready) return; - if (priv->create_result) + /* see if there's any pending callbacks for this account */ + result = g_hash_table_lookup (priv->create_results, account); + if (result != NULL) { g_simple_async_result_set_op_res_gpointer ( - G_SIMPLE_ASYNC_RESULT (priv->create_result), account, NULL); + G_SIMPLE_ASYNC_RESULT (result), account, NULL); - g_simple_async_result_complete (priv->create_result); - g_object_unref (priv->create_result); - priv->create_result = NULL; + g_simple_async_result_complete (result); + + g_hash_table_remove (priv->create_results, account); + g_object_unref (result); } g_signal_emit (manager, signals[ACCOUNT_CREATED], 0, account); @@ -322,7 +326,7 @@ account_manager_account_ready_cb (GObject *obj, empathy_account_manager_check_ready (manager); } -static void +static EmpathyAccount * account_manager_add_account (EmpathyAccountManager *manager, const gchar *path) { @@ -331,13 +335,15 @@ account_manager_add_account (EmpathyAccountManager *manager, account = g_hash_table_lookup (priv->accounts, path); if (account != NULL) - return; + return account; account = empathy_account_new (priv->dbus, path); g_hash_table_insert (priv->accounts, g_strdup (path), account); g_signal_connect (account, "notify::ready", G_CALLBACK (account_manager_account_ready_cb), manager); + + return account; } static void @@ -430,6 +436,8 @@ empathy_account_manager_init (EmpathyAccountManager *manager) priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); + + priv->create_results = g_hash_table_new (g_direct_hash, g_direct_equal); priv->dbus = tp_dbus_daemon_dup (NULL); @@ -458,6 +466,7 @@ do_finalize (GObject *obj) EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (obj); EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + g_hash_table_destroy (priv->create_results); g_hash_table_destroy (priv->accounts); g_free (priv->global_status); @@ -480,14 +489,25 @@ do_dispose (GObject *obj) priv->dispose_run = TRUE; - if (priv->create_result != NULL) + if (priv->create_results != NULL && + g_hash_table_size (priv->create_results) > 0) { - g_simple_async_result_set_error (priv->create_result, G_IO_ERROR, - G_IO_ERROR_CANCELLED, "The account manager was disposed while " - "creating the account"); - g_simple_async_result_complete (priv->create_result); - g_object_unref (priv->create_result); - priv->create_result = NULL; + /* the manager is being destroyed while there are account creation + * processes pending; this should not happen, but emit the callbacks + * with an error anyway. + */ + GHashTableIter iter; + GSimpleAsyncResult *result; + + g_hash_table_iter_init (&iter, priv->create_results); + while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &result)) + { + g_simple_async_result_set_error (result, G_IO_ERROR, + G_IO_ERROR_CANCELLED, "The account manager was disposed while " + "creating the account"); + g_simple_async_result_complete (result); + g_object_unref (result); + } } tp_dbus_daemon_cancel_name_owner_watch (priv->dbus, @@ -874,19 +894,22 @@ empathy_account_manager_created_cb (TpAccountManager *proxy, { EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + GSimpleAsyncResult *my_res = user_data; + EmpathyAccount *account; if (error != NULL) { - g_simple_async_result_set_from_error (priv->create_result, + g_simple_async_result_set_from_error (my_res, (GError *) error); - g_simple_async_result_complete (priv->create_result); - g_object_unref (priv->create_result); - priv->create_result = NULL; + g_simple_async_result_complete (my_res); + g_object_unref (my_res); return; } - account_manager_add_account (manager, account_path); + account = account_manager_add_account (manager, account_path); + + g_hash_table_insert (priv->create_results, account, my_res); } void @@ -897,8 +920,9 @@ empathy_account_manager_create_account_async (EmpathyAccountManager *manager, GAsyncReadyCallback callback, gpointer user_data) { EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + GSimpleAsyncResult *res; - priv->create_result = g_simple_async_result_new + res = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, empathy_account_manager_create_account_finish); @@ -910,7 +934,7 @@ empathy_account_manager_create_account_async (EmpathyAccountManager *manager, parameters, properties, empathy_account_manager_created_cb, - NULL, + res, NULL, G_OBJECT (manager)); } -- cgit v1.2.3 From 6bd8c2d7d8589d3d0019599c75de05b20ae18f44 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 29 Jul 2009 23:11:07 +0200 Subject: Ignore default value for required params Parameters should never have both the default and the required flags set, as required means the user has to fill in a value. When this happens anyway, the default dlag should be ignored, so we can avoid looking up the default value when checking for an account settings' validity. --- libempathy/empathy-account-settings.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 21109d261..1c5bc719a 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -1072,10 +1072,6 @@ empathy_account_settings_is_valid (EmpathyAccountSettings *settings) continue; } - /* see if there's a default value */ - if (empathy_account_settings_get_default (settings, current)) - continue; - missed = TRUE; break; } -- cgit v1.2.3 From 25ee209b2d033ca91f23a818636926285030945d Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 29 Jul 2009 23:21:40 +0200 Subject: Set the sensitivity to the forget button --- libempathy-gtk/empathy-account-widget.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 0361b957c..5cfff21d9 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -198,12 +198,13 @@ account_widget_forget_clicked_cb (GtkWidget *button, static void account_widget_password_changed_cb (GtkWidget *entry, - GtkWidget *button) + EmpathyAccountWidget *self) { + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); const gchar *str; str = gtk_entry_get_text (GTK_ENTRY (entry)); - gtk_widget_set_sensitive (button, !EMP_STR_EMPTY (str)); + gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str)); } static void -- cgit v1.2.3 From c8fc859d6d2bda4110e0dcb5fa4e213162d1c1c4 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 29 Jul 2009 23:38:00 +0200 Subject: Hook up to the destroy signal in EmpathyAccountWidget --- libempathy-gtk/empathy-account-widget.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 5cfff21d9..2b6439f1d 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -707,6 +707,13 @@ account_widget_build_groupwise (EmpathyAccountWidget *self, self->ui_details->add_forget = TRUE; } +static void +account_widget_destroy_cb (GtkWidget *widget, + EmpathyAccountWidget *self) +{ + g_object_unref (self); +} + static void do_set_property (GObject *object, guint prop_id, @@ -832,6 +839,10 @@ do_constructed (GObject *obj) account_widget_handle_apply_sensitivity (self); gtk_widget_show (priv->apply_button); + /* hook up to widget destruction to unref ourselves */ + g_signal_connect (self->ui_details->widget, "destroy", + G_CALLBACK (account_widget_destroy_cb), self); + empathy_builder_unref_and_keep_widget (self->ui_details->gui, self->ui_details->widget); } -- cgit v1.2.3 From 20438b5175f16e9b78b68a89b5da3fdd3aadad45 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 29 Jul 2009 23:38:19 +0200 Subject: Don't try to unref the GtkBuilder object in _dispose We take care of unreffing it before getting to dispose, as the object can have a variable lifecycle --- libempathy-gtk/empathy-account-widget.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 2b6439f1d..a9edc1b1c 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -857,12 +857,6 @@ do_dispose (GObject *obj) priv->dispose_run = TRUE; - if (self->ui_details->gui != NULL) - { - g_object_unref (self->ui_details->gui); - self->ui_details->gui = NULL; - } - if (priv->settings != NULL) { g_object_unref (priv->settings); -- cgit v1.2.3 From 6d753b4f94a7fd35a727f5a2359087379e8288b1 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 30 Jul 2009 00:44:27 +0200 Subject: Update POTFILES.in --- po/POTFILES.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index cfd921533..d7aa74d61 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,6 +4,7 @@ data/empathy.desktop.in.in data/empathy.schemas.in +libempathy/empathy-account.c libempathy/empathy-ft-handler.c libempathy/empathy-tp-contact-list.c libempathy/empathy-tp-file.c @@ -20,7 +21,7 @@ libempathy-gtk/empathy-account-widget-irc.c [type: gettext/glade]libempathy-gtk/empathy-account-widget-irc.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-jabber.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-msn.ui -[type: gettext/glade]libempathy-gtk/empathy-account-widget-salut.ui +[type: gettext/glade]libempathy-gtk/empathy-account-widget-local-xmpp.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-sip.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-yahoo.ui libempathy-gtk/empathy-avatar-chooser.c -- cgit v1.2.3 From bf6b5979152190e78ca913c6cfd0b91e204c60fd Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 30 Jul 2009 00:44:36 +0200 Subject: Fix trailing whitespace --- libempathy-gtk/empathy-account-widget.c | 18 +++++++++--------- libempathy/empathy-account-manager.c | 6 +++--- src/empathy-accounts-dialog.c | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index a9edc1b1c..6d5b2b279 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -51,7 +51,7 @@ G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT) typedef struct { char *protocol; EmpathyAccountSettings *settings; - + GtkWidget *apply_button; GtkWidget *entry_password; GtkWidget *button_forget; @@ -145,7 +145,7 @@ account_widget_int_changed_cb (GtkWidget *widget, default: g_return_if_reached (); } - + account_widget_handle_apply_sensitivity (self); } @@ -176,7 +176,7 @@ account_widget_checkbutton_toggled_cb (GtkWidget *widget, DEBUG ("Setting %s to %d", param_name, value); empathy_account_settings_set_boolean (priv->settings, param_name, value); } - + account_widget_handle_apply_sensitivity (self); } @@ -238,7 +238,7 @@ account_widget_setup_widget (EmpathyAccountWidget *self, const gchar *param_name) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - + g_object_set_data_full (G_OBJECT (widget), "param_name", g_strdup (param_name), g_free); @@ -495,7 +495,7 @@ account_widget_apply_clicked_cb (GtkWidget *button, EmpathyAccountWidget *self) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - + empathy_account_settings_apply_async (priv->settings, NULL, NULL); } @@ -758,7 +758,7 @@ do_get_property (GObject *object, static void do_constructed (GObject *obj) -{ +{ EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); EmpathyAccountWidgetPriv *priv = GET_PRIV (self); char *uiname, *filename; @@ -826,7 +826,7 @@ do_constructed (GObject *obj) self); g_signal_connect (priv->entry_password, "changed", G_CALLBACK (account_widget_password_changed_cb), - self); + self); } /* handle apply button */ @@ -904,7 +904,7 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) "settings", "The settings of the account", EMPATHY_TYPE_ACCOUNT_SETTINGS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (oclass, PROP_SETTINGS, param_spec); + g_object_class_install_property (oclass, PROP_SETTINGS, param_spec); g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); } @@ -912,7 +912,7 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) static void empathy_account_widget_init (EmpathyAccountWidget *self) { - EmpathyAccountWidgetPriv *priv = + EmpathyAccountWidgetPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidgetPriv); diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index cb86e0881..b037f5d30 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -107,7 +107,7 @@ emp_account_enabled_cb (EmpathyAccount *account, gpointer manager) { EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - + if (empathy_account_is_enabled (account)) { g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account); @@ -279,7 +279,7 @@ empathy_account_manager_check_ready (EmpathyAccountManager *manager) static void account_manager_account_ready_cb (GObject *obj, - GParamSpec *spec, + GParamSpec *spec, gpointer user_data) { EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); @@ -436,7 +436,7 @@ empathy_account_manager_init (EmpathyAccountManager *manager) priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); - + priv->create_results = g_hash_table_new (g_direct_hash, g_direct_equal); priv->dbus = tp_dbus_daemon_dup (NULL); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 95c3ac146..7a9dffb79 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -367,7 +367,7 @@ accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer, if (priv->connecting_id) g_source_remove (priv->connecting_id); - + DEBUG ("Editing account name started; stopping flashing"); } @@ -591,7 +591,7 @@ accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog) if (!gtk_tree_selection_get_selected (selection, &model, &iter)) return NULL; - + gtk_tree_model_get (model, &iter, COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); @@ -738,7 +738,7 @@ accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog) if (!gtk_tree_selection_get_selected (selection, &model, &iter)) return NULL; - + gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1); return account; @@ -772,7 +772,7 @@ accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog) if (!gtk_tree_selection_get_selected (selection, &model, &iter)) return FALSE; - + gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1); @@ -867,7 +867,7 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, if (!accounts_dialog_get_account_iter (dialog, account, &iter)) gtk_list_store_append (GTK_LIST_STORE (model), &iter); - + settings = empathy_account_settings_new_for_account (account); gtk_list_store_set (GTK_LIST_STORE (model), &iter, @@ -1202,7 +1202,7 @@ accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms, static void accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) -{ +{ GtkBuilder *gui; gchar *filename; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); -- cgit v1.2.3 From 237c4ac2d8d1b008a0c34aa24fc63eb3a1c0c91d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 17:18:30 +0200 Subject: explicitely include libempathy/empathy-enum-types.h --- python/pyempathygtk/pyempathygtk.override | 1 + 1 file changed, 1 insertion(+) diff --git a/python/pyempathygtk/pyempathygtk.override b/python/pyempathygtk/pyempathygtk.override index 035ef1344..d758afbf8 100644 --- a/python/pyempathygtk/pyempathygtk.override +++ b/python/pyempathygtk/pyempathygtk.override @@ -2,6 +2,7 @@ headers #include #include +#include #include "empathy-account-chooser.h" #include "empathy-account-widget.h" #include "empathy-account-widget-irc.h" -- cgit v1.2.3 From c9ef23052d2e5007e6120dcc881d6c382fcf48d3 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 17:35:38 +0200 Subject: Chang the API of AccountManager to have the get lookup the account by name EmpathyAccountManager used to have a _lookup function that looked up accounts by name and a _get function that lookup up accounts by connection. This is confusing, as looking up an account for a connection is less common rename have the _get_account be the same _lookup (but without returning a ref) and add a _get_account_for_connection function lookup by account --- libempathy-gtk/empathy-chat.c | 6 ++++-- libempathy-gtk/empathy-contact-list-view.c | 2 +- libempathy/empathy-account-manager.c | 15 +++++---------- libempathy/empathy-account-manager.h | 4 ++-- libempathy/empathy-chatroom-manager.c | 8 ++++---- libempathy/empathy-contact.c | 3 ++- libempathy/empathy-dispatcher.c | 4 +--- libempathy/empathy-log-store-empathy.c | 4 +++- megaphone/src/megaphone-applet.c | 3 ++- src/empathy-chat-window.c | 4 +--- src/empathy.c | 2 +- 11 files changed, 26 insertions(+), 29 deletions(-) diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 0358b0ada..d52d7af93 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -203,7 +203,8 @@ chat_new_connection_cb (EmpathyAccountManager *manager, EmpathyChatPriv *priv = GET_PRIV (chat); EmpathyAccount *account; - account = empathy_account_manager_get_account (manager, connection); + account = empathy_account_manager_get_account_for_connection (manager, + connection); if (!priv->tp_chat && account == priv->account && priv->handle_type != TP_HANDLE_TYPE_NONE && !EMP_STR_EMPTY (priv->id)) { @@ -1766,7 +1767,8 @@ empathy_chat_set_tp_chat (EmpathyChat *chat, priv->tp_chat = g_object_ref (tp_chat); connection = empathy_tp_chat_get_connection (priv->tp_chat); - priv->account = empathy_account_manager_get_account (priv->account_manager, + priv->account = empathy_account_manager_get_account_for_connection ( + priv->account_manager, connection); g_object_ref (priv->account); diff --git a/libempathy-gtk/empathy-contact-list-view.c b/libempathy-gtk/empathy-contact-list-view.c index 783d986d0..2ff27b130 100644 --- a/libempathy-gtk/empathy-contact-list-view.c +++ b/libempathy-gtk/empathy-contact-list-view.c @@ -302,7 +302,7 @@ contact_list_view_drag_data_received (GtkWidget *view, account_id = strv[0]; contact_id = strv[1]; account_manager = empathy_account_manager_dup_singleton (); - account = empathy_account_manager_lookup (account_manager, account_id); + account = empathy_account_manager_get_account (account_manager, account_id); if (account) { TpConnection *connection; diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 7339acb9f..c199e1d3e 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -665,8 +665,9 @@ empathy_account_manager_get_count (EmpathyAccountManager *manager) } EmpathyAccount * -empathy_account_manager_get_account (EmpathyAccountManager *manager, - TpConnection *connection) +empathy_account_manager_get_account_for_connection ( + EmpathyAccountManager *manager, + TpConnection *connection) { EmpathyAccountManagerPriv *priv; GHashTableIter iter; @@ -689,18 +690,12 @@ empathy_account_manager_get_account (EmpathyAccountManager *manager, } EmpathyAccount * -empathy_account_manager_lookup (EmpathyAccountManager *manager, +empathy_account_manager_get_account (EmpathyAccountManager *manager, const gchar *unique_name) { EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - EmpathyAccount *account; - - account = g_hash_table_lookup (priv->accounts, unique_name); - if (account != NULL) - g_object_ref (account); - - return account; + return g_hash_table_lookup (priv->accounts, unique_name); } GList * diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index 953d8bc75..1f73f635e 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -66,10 +66,10 @@ int empathy_account_manager_get_connecting_accounts (EmpathyAccountManager *manager); int empathy_account_manager_get_count (EmpathyAccountManager *manager); -EmpathyAccount * empathy_account_manager_get_account +EmpathyAccount * empathy_account_manager_get_account_for_connection (EmpathyAccountManager *manager, TpConnection *connection); -EmpathyAccount * empathy_account_manager_lookup +EmpathyAccount * empathy_account_manager_get_account (EmpathyAccountManager *manager, const gchar *unique_name); GList * empathy_account_manager_dup_accounts diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c index c5f9864a1..7c3559e2f 100644 --- a/libempathy/empathy-chatroom-manager.c +++ b/libempathy/empathy-chatroom-manager.c @@ -223,7 +223,8 @@ chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager, xmlFree (str); } - account = empathy_account_manager_lookup (priv->account_manager, account_id); + account = empathy_account_manager_get_account (priv->account_manager, + account_id); if (!account) { g_free (name); g_free (room); @@ -236,7 +237,6 @@ chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager, add_chatroom (manager, chatroom); g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); - g_object_unref (account); g_free (name); g_free (room); g_free (account_id); @@ -704,8 +704,8 @@ chatroom_manager_observe_channel_cb (EmpathyDispatcher *dispatcher, chat = EMPATHY_TP_CHAT ( empathy_dispatch_operation_get_channel_wrapper (operation)); connection = empathy_tp_chat_get_connection (chat); - account = empathy_account_manager_get_account (priv->account_manager, - connection); + account = empathy_account_manager_get_account_for_connection ( + priv->account_manager, connection); roomname = empathy_tp_chat_get_id (chat); diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index c82ecd467..bbce927b7 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -570,7 +570,8 @@ empathy_contact_get_account (EmpathyContact *contact) /* FIXME: This assume the account manager already exists */ manager = empathy_account_manager_dup_singleton (); connection = tp_contact_get_connection (priv->tp_contact); - priv->account = empathy_account_manager_get_account (manager, connection); + priv->account = empathy_account_manager_get_account_for_connection ( + manager, connection); g_object_ref (priv->account); g_object_unref (manager); } diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 0b2a74a2e..fe330256d 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -1801,7 +1801,7 @@ empathy_dispatcher_handle_channels (TpSvcClientHandler *self, EmpathyAccount *account; TpConnection *connection; - account = empathy_account_manager_lookup (priv->account_manager, + account = empathy_account_manager_get_account (priv->account_manager, account_path); /* FIXME */ g_assert (account != NULL); @@ -1824,8 +1824,6 @@ empathy_dispatcher_handle_channels (TpSvcClientHandler *self, } tp_svc_client_handler_return_from_handle_channels (context); - - g_object_unref (account); } static void diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 4bb17e428..81cbcade7 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -405,8 +405,10 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self, unescaped = g_strdup_printf ("/%s", g_strdelimit (account_name, "%", '/')); - hit->account = empathy_account_manager_lookup (priv->account_manager, + hit->account = empathy_account_manager_get_account (priv->account_manager, unescaped); + if (hit->account != NULL) + g_object_ref (hit->account); hit->filename = g_strdup (filename); g_free (unescaped); diff --git a/megaphone/src/megaphone-applet.c b/megaphone/src/megaphone-applet.c index 1ef88ebc1..c269c7c7d 100644 --- a/megaphone/src/megaphone-applet.c +++ b/megaphone/src/megaphone-applet.c @@ -443,7 +443,7 @@ megaphone_applet_set_contact (MegaphoneApplet *applet, /* Lookup the new contact */ if (str) { strv = g_strsplit (str, "/", 2); - priv->account = empathy_account_manager_lookup (priv->account_manager, + priv->account = empathy_account_manager_get_account (priv->account_manager, strv[0]); priv->id = strv[1]; g_free (strv[0]); @@ -451,6 +451,7 @@ megaphone_applet_set_contact (MegaphoneApplet *applet, } if (priv->account) { + g_object_ref (priv->account); connection = empathy_account_get_connection (priv->account); if (connection) { megaphone_applet_new_connection_cb (priv->account_manager, diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index 9694a653c..47ef37c42 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -1269,7 +1269,7 @@ chat_window_drag_data_received (GtkWidget *widget, strv = g_strsplit (id, "/", 2); account_id = strv[0]; contact_id = strv[1]; - account = empathy_account_manager_lookup (account_manager, account_id); + account = empathy_account_manager_get_account (account_manager, account_id); chat = empathy_chat_window_find_chat (account, contact_id); if (!chat) { @@ -1282,11 +1282,9 @@ chat_window_drag_data_received (GtkWidget *widget, connection, contact_id, NULL, NULL); } - g_object_unref (account); g_strfreev (strv); return; } - g_object_unref (account); g_object_unref (account_manager); g_strfreev (strv); diff --git a/src/empathy.c b/src/empathy.c index 4e824bcb4..956b05e5f 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -113,7 +113,7 @@ dispatch_cb (EmpathyDispatcher *dispatcher, manager = empathy_account_manager_dup_singleton (); connection = empathy_tp_chat_get_connection (tp_chat); - account = empathy_account_manager_get_account (manager, + account = empathy_account_manager_get_account_for_connection (manager, connection); chat = empathy_chat_window_find_chat (account, id); g_object_unref (manager); -- cgit v1.2.3 From 586a307e56f2bce203e80de9f9f9d5a15e34bec6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 17:37:45 +0200 Subject: Update python bindings --- python/pyempathy/pyempathy.defs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/pyempathy/pyempathy.defs b/python/pyempathy/pyempathy.defs index 2b8719254..669c09013 100644 --- a/python/pyempathy/pyempathy.defs +++ b/python/pyempathy/pyempathy.defs @@ -314,18 +314,18 @@ (return-type "int") ) -(define-method get_account +(define-method get_account_for_connection (of-object "EmpathyAccountManager") - (c-name "empathy_account_manager_get_account") + (c-name "empathy_account_manager_get_account_for_connection") (return-type "EmpathyAccount*") (parameters '("TpConnection*" "connection") ) ) -(define-method lookup +(define-method get_account (of-object "EmpathyAccountManager") - (c-name "empathy_account_manager_lookup") + (c-name "empathy_account_manager_get_account") (return-type "EmpathyAccount*") (parameters '("const-gchar*" "unique_name") -- cgit v1.2.3 From ef19c477deba879906da074361527c7885db35ee Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 19:25:24 +0200 Subject: Fix typo --- libempathy/empathy-idle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index f60fc0f85..b77dd0732 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -577,7 +577,7 @@ empathy_idle_do_set_presence (EmpathyIdle *idle, const gchar *status_message) { EmpathyIdlePriv *priv = GET_PRIV (idle); - const gchar *statusses[NUM_TP_CONNECTION_PRESENCE_TYPES] = { + const gchar *statuses[NUM_TP_CONNECTION_PRESENCE_TYPES] = { NULL, "offline", "available", @@ -592,7 +592,7 @@ empathy_idle_do_set_presence (EmpathyIdle *idle, g_assert (status_type > 0 && status_type < NUM_TP_CONNECTION_PRESENCE_TYPES); - status = statusses[status_type]; + status = statuses[status_type]; g_return_if_fail (status != NULL); -- cgit v1.2.3 From 4e38b2c3eab6a2a19906db5c4933870beb6ce626 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 19:29:35 +0200 Subject: Add a small comment about emp_account_manager_update_global_presence --- libempathy/empathy-account-manager.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index c199e1d3e..2057581d4 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -150,6 +150,9 @@ emp_account_manager_update_global_presence (EmpathyAccountManager *manager) GHashTableIter iter; gpointer value; + /* Make the global presence is equal to the presence of the account with the + * highest availability */ + g_hash_table_iter_init (&iter, priv->accounts); while (g_hash_table_iter_next (&iter, NULL, &value)) { -- cgit v1.2.3 From f54c1834d7a8dc0de0f6f4c1ae60910a38944d05 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 19:30:25 +0200 Subject: add some slightly nicer debug messages --- libempathy/empathy-account.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5cf489769..4585d33cf 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -356,7 +356,8 @@ empathy_account_got_all_cb (TpProxy *proxy, if (error != NULL) { - printf ("Unhappy\n"); + DEBUG ("Failed to get the initial set of account properties: %s", + error->message); return; } @@ -907,7 +908,7 @@ empathy_account_requested_presence_cb (TpProxy *proxy, GObject *weak_object) { if (error) - DEBUG (":( : %s", error->message); + DEBUG ("Failed to set the requested presence: %s", error->message); } -- cgit v1.2.3 From 87070d25c5f2d9a0ecba73e8ce913eca7f183c79 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 19:35:03 +0200 Subject: Fix some coding style issues --- libempathy/empathy-account-manager.c | 11 +++++++---- libempathy/empathy-account-settings.c | 33 ++++++++++++++++++--------------- libempathy/empathy-account.c | 8 +++++--- libempathy/empathy-dispatcher.c | 1 - 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 2057581d4..727eb7eaf 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -847,10 +847,13 @@ empathy_account_manager_created_cb (TpAccountManager *proxy, void empathy_account_manager_create_account_async (EmpathyAccountManager *manager, - const gchar *connection_manager, - const gchar *protocol, const gchar *display_name, - GHashTable *parameters, GHashTable *properties, - GAsyncReadyCallback callback, gpointer user_data) + const gchar *connection_manager, + const gchar *protocol, + const gchar *display_name, + GHashTable *parameters, + GHashTable *properties, + GAsyncReadyCallback callback, + gpointer user_data) { EmpathyAccountManagerPriv *priv = GET_PRIV (manager); GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (manager), diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 2763f0702..0b92ec1b1 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -301,7 +301,7 @@ empathy_account_settings_dispose (GObject *object) static void empathy_account_settings_free_unset_parameters ( - EmpathyAccountSettings *settings) + EmpathyAccountSettings *settings) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); int i; @@ -368,7 +368,8 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self) static void empathy_account_settings_ready_cb (GObject *obj, - GParamSpec *spec, gpointer user_data) + GParamSpec *spec, + gpointer user_data) { EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data); @@ -458,7 +459,7 @@ empathy_account_settings_get_account (EmpathyAccountSettings *settings) static gboolean empathy_account_settings_is_unset (EmpathyAccountSettings *settings, - const gchar *param) + const gchar *param) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); GArray *a; @@ -477,7 +478,7 @@ empathy_account_settings_is_unset (EmpathyAccountSettings *settings, static TpConnectionManagerParam * empathy_account_settings_get_tp_param (EmpathyAccountSettings *settings, - const gchar *param) + const gchar *param) { TpConnectionManagerParam *tp_params = empathy_account_settings_get_tp_params (settings); @@ -496,7 +497,7 @@ empathy_account_settings_get_tp_param (EmpathyAccountSettings *settings, const GValue * empathy_account_settings_get_default (EmpathyAccountSettings *settings, - const gchar *param) + const gchar *param) { TpConnectionManagerParam *p; @@ -510,7 +511,7 @@ empathy_account_settings_get_default (EmpathyAccountSettings *settings, const gchar * empathy_settings_get_dbus_signature (EmpathyAccountSettings *settings, - const gchar *param) + const gchar *param) { TpConnectionManagerParam *p; @@ -524,7 +525,7 @@ empathy_settings_get_dbus_signature (EmpathyAccountSettings *settings, const GValue * empathy_account_settings_get (EmpathyAccountSettings *settings, - const gchar *param) + const gchar *param) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); const GValue *result = NULL; @@ -821,7 +822,8 @@ empathy_account_settings_set_display_name_finish ( static void empathy_account_settings_account_updated (GObject *source, - GAsyncResult *result, gpointer user_data) + GAsyncResult *result, + gpointer user_data) { EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data); EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); @@ -844,8 +846,8 @@ empathy_account_settings_account_updated (GObject *source, static void empathy_account_settings_created_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) + GAsyncResult *result, + gpointer user_data) { EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data); EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); @@ -892,7 +894,8 @@ empathy_account_settings_do_create_account (EmpathyAccountSettings *settings) static void empathy_account_settings_manager_ready_cb (EmpathyAccountManager *manager, - GParamSpec *spec, gpointer user_data) + GParamSpec *spec, + gpointer user_data) { EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data); EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); @@ -910,8 +913,8 @@ empathy_account_settings_manager_ready_cb (EmpathyAccountManager *manager, void empathy_account_settings_apply_async (EmpathyAccountSettings *settings, - GAsyncReadyCallback callback, - gpointer user_data) + GAsyncReadyCallback callback, + gpointer user_data) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); @@ -950,8 +953,8 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings, gboolean empathy_account_settings_apply_finish (EmpathyAccountSettings *settings, - GAsyncResult *result, - GError **error) + GAsyncResult *result, + GError **error) { if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 4585d33cf..df948b69c 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -200,7 +200,8 @@ empathy_account_get_property (GObject *object, } static void -empathy_account_update (EmpathyAccount *account, GHashTable *properties) +empathy_account_update (EmpathyAccount *account, + GHashTable *properties) { EmpathyAccountPriv *priv = GET_PRIV (account); const gchar *conn_path; @@ -401,7 +402,7 @@ empathy_account_unescape_protocol (const gchar *protocol, gssize len) static gboolean empathy_account_parse_unique_name (const gchar *bus_name, - gchar **protocol, gchar **manager) + gchar **protocol, gchar **manager) { const gchar *proto, *proto_end; const gchar *cm, *cm_end; @@ -780,7 +781,8 @@ empathy_account_is_ready (EmpathyAccount *account) EmpathyAccount * -empathy_account_new (TpDBusDaemon *dbus, const gchar *unique_name) +empathy_account_new (TpDBusDaemon *dbus, + const gchar *unique_name) { return EMPATHY_ACCOUNT (g_object_new (EMPATHY_TYPE_ACCOUNT, "dbus-daemon", dbus, diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index fe330256d..03f5fc1b8 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -1057,7 +1057,6 @@ empathy_dispatcher_class_init (EmpathyDispatcherClass *klass) g_type_class_add_private (object_class, sizeof (EmpathyDispatcherPriv)); - klass->dbus_props_class.interfaces = prop_interfaces; tp_dbus_properties_mixin_class_init (object_class, G_STRUCT_OFFSET (EmpathyDispatcherClass, dbus_props_class)); -- cgit v1.2.3 From 8d2d494e21dd76251ce3fff3301bf007eb514f53 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 31 Jul 2009 11:44:12 +0200 Subject: Don't try to lookup NULL connections --- libempathy-gtk/empathy-contact-dialogs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 5b11ddc2e..4252ae019 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -335,6 +335,10 @@ can_add_contact_to_account (EmpathyAccount *account, connection = empathy_account_get_connection (account); + if (connection == NULL) { + return FALSE; + } + contact_manager = empathy_contact_manager_dup_singleton (); result = empathy_contact_manager_can_add (contact_manager, connection); g_object_unref (contact_manager); -- cgit v1.2.3 From 0279ad1b9504f81dbe6773eab9fdbd6ffdbfca3d Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 31 Jul 2009 11:44:35 +0200 Subject: Make protocol icons work also with account == NULL --- libempathy/empathy-account-settings.c | 7 +++++-- libempathy/empathy-account-settings.h | 2 +- src/empathy-accounts-dialog.c | 11 ++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 1c5bc719a..256d05ba4 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -447,13 +447,16 @@ empathy_account_settings_get_protocol (EmpathyAccountSettings *settings) return priv->protocol; } -const gchar * +gchar * empathy_account_settings_get_icon_name (EmpathyAccountSettings *settings) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); if (priv->account != NULL) - return empathy_account_get_icon_name (priv->account); + return g_strdup (empathy_account_get_icon_name (priv->account)); + + if (priv->tp_protocol != NULL) + return g_strdup_printf ("im-%s", priv->tp_protocol->name); return NULL; } diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h index 06e5e69e3..8ae692212 100644 --- a/libempathy/empathy-account-settings.h +++ b/libempathy/empathy-account-settings.h @@ -127,7 +127,7 @@ void empathy_account_settings_set_uint64 (EmpathyAccountSettings *settings, void empathy_account_settings_set_boolean (EmpathyAccountSettings *settings, const gchar *param, gboolean value); -const gchar *empathy_account_settings_get_icon_name ( +gchar *empathy_account_settings_get_icon_name ( EmpathyAccountSettings *settings); const gchar *empathy_account_settings_get_display_name ( diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 7a9dffb79..974b6dcc4 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -175,6 +175,7 @@ account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings) { EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + gchar *icon_name; priv->settings_widget = get_account_setup_widget (settings); @@ -182,14 +183,16 @@ account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, priv->settings_widget); gtk_widget_show (priv->settings_widget); + icon_name = empathy_account_settings_get_icon_name (settings); gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type), - empathy_account_settings_get_icon_name (settings), - GTK_ICON_SIZE_DIALOG); + icon_name, GTK_ICON_SIZE_DIALOG); gtk_widget_set_tooltip_text (priv->image_type, empathy_account_settings_get_protocol (settings)); accounts_dialog_update_name_label (dialog, settings); + + g_free (icon_name); } static void @@ -379,7 +382,7 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, EmpathyAccountsDialog *dialog) { EmpathyAccountSettings *settings; - const gchar *icon_name; + gchar *icon_name; GdkPixbuf *pixbuf; TpConnectionStatus status; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); @@ -392,6 +395,8 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, icon_name = empathy_account_settings_get_icon_name (settings); pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); + g_free (icon_name); + if (pixbuf) { if (status == TP_CONNECTION_STATUS_DISCONNECTED || -- cgit v1.2.3 From 41e5b31c1918f40c3ba47bff2dc9ab682fe0391f Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 31 Jul 2009 12:11:58 +0200 Subject: Use proper display names in the chooser --- libempathy-gtk/empathy-protocol-chooser.c | 46 +++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index 462979843..79adbac9f 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -123,6 +123,36 @@ protocol_chooser_sort_func (GtkTreeModel *model, return cmp; } +static const char * +protocol_chooser_proto_name_to_display_name (const gchar *proto_name) +{ + int i; + + static struct { + const gchar *proto; + const gchar *display; + } names[] = { + { "jabber", "XMPP" }, + { "msn", "MSN" }, + { "local-xmpp", "Salut" }, + { "irc", "IRC" }, + { "icq", "ICQ" }, + { "aim", "AIM" }, + { "yahoo", "Yahoo" }, + { "groupwise", "GroupWise" }, + { "sip", "SIP" }, + { NULL, NULL } + }; + + for (i = 0; names[i].proto != NULL; i++) + { + if (!tp_strdiff (proto_name, names[i].proto)) + return names[i].display; + } + + return NULL; +} + static void protocol_choosers_add_cm (EmpathyProtocolChooser *chooser, TpConnectionManager *cm) @@ -134,24 +164,28 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser, { const TpConnectionManagerProtocol *proto = *iter; gchar *icon_name; - gchar *display_name; - + const gchar *display_name; + gchar *display_name_set; icon_name = g_strdup_printf ("im-%s", proto->name); + display_name = protocol_chooser_proto_name_to_display_name (proto->name); + + if (display_name == NULL) + display_name = proto->name; if (!tp_strdiff (cm->name, "haze")) - display_name = g_strdup_printf ("%s (Haze)", proto->name); + display_name_set = g_strdup_printf ("%s (Haze)", display_name); else - display_name = g_strdup (proto->name); + display_name_set = g_strdup (display_name); gtk_list_store_insert_with_values (priv->store, NULL, 0, COL_ICON, icon_name, - COL_LABEL, display_name, + COL_LABEL, display_name_set, COL_CM, cm, COL_PROTOCOL, proto, -1); - g_free (display_name); + g_free (display_name_set); g_free (icon_name); } } -- cgit v1.2.3 From af5cee20d84c3ef3ebf31f7e19b4108f9607aa14 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 13:24:42 +0200 Subject: Make sure we always show the main window --- src/empathy-main-window.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index f8e22d91d..d61a05c27 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -1404,6 +1404,8 @@ empathy_main_window_show (void) main_window_update_status (window, window->account_manager); + gtk_widget_show (window->window); + return window->window; } -- cgit v1.2.3 From 9f9890593181c881b09773d7f8e68a402d8ce7fa Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 15:12:42 +0200 Subject: Port to libunique --- configure.ac | 1 + src/Makefile.am | 1 - src/bacon-message-connection.c | 412 ----------------------------------------- src/bacon-message-connection.h | 51 ----- src/empathy.c | 151 ++++----------- 5 files changed, 38 insertions(+), 578 deletions(-) delete mode 100644 src/bacon-message-connection.c delete mode 100644 src/bacon-message-connection.h diff --git a/configure.ac b/configure.ac index 62e08f0a4..0e11a66d8 100644 --- a/configure.ac +++ b/configure.ac @@ -126,6 +126,7 @@ PKG_CHECK_MODULES(EMPATHY, telepathy-glib >= $TELEPATHY_GLIB_REQUIRED telepathy-farsight gstreamer-0.10 + unique-1.0 ]) PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED) diff --git a/src/Makefile.am b/src/Makefile.am index 50d317fbb..01f47d2bb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,7 +49,6 @@ empathy_handwritten_source = \ empathy_SOURCES = \ $(empathy_handwritten_source) \ - bacon-message-connection.c bacon-message-connection.h \ ephy-spinner.c ephy-spinner.h nodist_empathy_SOURCES = $(BUILT_SOURCES) diff --git a/src/bacon-message-connection.c b/src/bacon-message-connection.c deleted file mode 100644 index c9fda4aeb..000000000 --- a/src/bacon-message-connection.c +++ /dev/null @@ -1,412 +0,0 @@ -/* - * Copyright (C) 2003 Bastien Nocera - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Totem project hereby grant permission for non-gpl compatible GStreamer - * plugins to be used and distributed together with GStreamer and Totem. This - * permission are above and beyond the permissions granted by the GPL license - * Totem is covered by. - * - * Monday 7th February 2005: Christian Schaller: Add excemption clause. - * See license_change file for details. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bacon-message-connection.h" - -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 -#endif - -struct BaconMessageConnection { - /* A server accepts connections */ - gboolean is_server; - - /* The socket path itself */ - char *path; - - /* File descriptor of the socket */ - int fd; - /* Channel to watch */ - GIOChannel *chan; - /* Event id returned by g_io_add_watch() */ - int conn_id; - - /* Connections accepted by this connection */ - GSList *accepted_connections; - - /* callback */ - void (*func) (const char *message, gpointer user_data); - gpointer data; -}; - -static gboolean -test_is_socket (const char *path) -{ - struct stat s; - - if (stat (path, &s) == -1) - return FALSE; - - if (S_ISSOCK (s.st_mode)) - return TRUE; - - return FALSE; -} - -static gboolean -is_owned_by_user_and_socket (const char *path) -{ - struct stat s; - - if (stat (path, &s) == -1) - return FALSE; - - if (s.st_uid != geteuid ()) - return FALSE; - - if ((s.st_mode & S_IFSOCK) != S_IFSOCK) - return FALSE; - - return TRUE; -} - -static gboolean server_cb (GIOChannel *source, - GIOCondition condition, gpointer data); - -static gboolean -setup_connection (BaconMessageConnection *conn) -{ - int fdflags; - - g_return_val_if_fail (conn->chan == NULL, FALSE); - - /* Add CLOEXEC flag on the fd to make sure the socket get closed - * if exec is called. */ - fdflags = fcntl (conn->fd, F_GETFD, 0); - if (fdflags >= 0) { - fdflags |= FD_CLOEXEC; - fcntl (conn->fd, F_SETFD, fdflags); - } - - conn->chan = g_io_channel_unix_new (conn->fd); - if (!conn->chan) { - return FALSE; - } - g_io_channel_set_line_term (conn->chan, "\n", 1); - conn->conn_id = g_io_add_watch (conn->chan, G_IO_IN, server_cb, conn); - - return TRUE; -} - -static void -accept_new_connection (BaconMessageConnection *server_conn) -{ - BaconMessageConnection *conn; - int alen; - - g_return_if_fail (server_conn->is_server); - - conn = g_new0 (BaconMessageConnection, 1); - conn->is_server = FALSE; - conn->func = server_conn->func; - conn->data = server_conn->data; - - conn->fd = accept (server_conn->fd, NULL, (guint *)&alen); - - server_conn->accepted_connections = - g_slist_prepend (server_conn->accepted_connections, conn); - - setup_connection (conn); -} - -static gboolean -server_cb (GIOChannel *source, GIOCondition condition, gpointer data) -{ - BaconMessageConnection *conn = (BaconMessageConnection *)data; - char *message, *subs, buf; - int cd, rc, offset; - gboolean finished; - - offset = 0; - if (conn->is_server && conn->fd == g_io_channel_unix_get_fd (source)) { - accept_new_connection (conn); - return TRUE; - } - message = g_malloc (1); - cd = conn->fd; - rc = read (cd, &buf, 1); - while (rc > 0 && buf != '\n') - { - message = g_realloc (message, rc + offset + 1); - message[offset] = buf; - offset = offset + rc; - rc = read (cd, &buf, 1); - } - if (rc <= 0) { - g_io_channel_shutdown (conn->chan, FALSE, NULL); - g_io_channel_unref (conn->chan); - conn->chan = NULL; - close (conn->fd); - conn->fd = -1; - g_free (message); - conn->conn_id = 0; - - return FALSE; - } - message[offset] = '\0'; - - subs = message; - finished = FALSE; - - while (finished == FALSE && *subs != '\0') - { - if (conn->func != NULL) - (*conn->func) (subs, conn->data); - - subs += strlen (subs) + 1; - if (subs - message >= offset) - finished = TRUE; - } - - g_free (message); - - return TRUE; -} - -static char * -find_file_with_pattern (const char *dir, const char *pattern) -{ - GDir *filedir; - char *found_filename; - const char *filename; - GPatternSpec *pat; - - filedir = g_dir_open (dir, 0, NULL); - if (filedir == NULL) - return NULL; - - pat = g_pattern_spec_new (pattern); - if (pat == NULL) - { - g_dir_close (filedir); - return NULL; - } - - found_filename = NULL; - - while ((filename = g_dir_read_name (filedir))) - { - if (g_pattern_match_string (pat, filename)) - { - char *tmp = g_build_filename (dir, filename, NULL); - if (is_owned_by_user_and_socket (tmp)) - found_filename = g_strdup (filename); - g_free (tmp); - } - - if (found_filename != NULL) - break; - } - - g_pattern_spec_free (pat); - g_dir_close (filedir); - - return found_filename; -} - -static char * -socket_filename (const char *prefix) -{ - char *pattern, *newfile, *path, *filename; - const char *tmpdir; - - pattern = g_strdup_printf ("%s.%s.*", prefix, g_get_user_name ()); - tmpdir = g_get_tmp_dir (); - filename = find_file_with_pattern (tmpdir, pattern); - if (filename == NULL) - { - newfile = g_strdup_printf ("%s.%s.%u", prefix, - g_get_user_name (), g_random_int ()); - path = g_build_filename (tmpdir, newfile, NULL); - g_free (newfile); - } else { - path = g_build_filename (tmpdir, filename, NULL); - g_free (filename); - } - - g_free (pattern); - return path; -} - -static gboolean -try_server (BaconMessageConnection *conn) -{ - struct sockaddr_un uaddr; - - uaddr.sun_family = AF_UNIX; - strncpy (uaddr.sun_path, conn->path, - MIN (strlen(conn->path)+1, UNIX_PATH_MAX)); - conn->fd = socket (PF_UNIX, SOCK_STREAM, 0); - if (bind (conn->fd, (struct sockaddr *) &uaddr, sizeof (uaddr)) == -1) - { - conn->fd = -1; - return FALSE; - } - listen (conn->fd, 5); - - return setup_connection (conn); -} - -static gboolean -try_client (BaconMessageConnection *conn) -{ - struct sockaddr_un uaddr; - - uaddr.sun_family = AF_UNIX; - strncpy (uaddr.sun_path, conn->path, - MIN(strlen(conn->path)+1, UNIX_PATH_MAX)); - conn->fd = socket (PF_UNIX, SOCK_STREAM, 0); - if (connect (conn->fd, (struct sockaddr *) &uaddr, - sizeof (uaddr)) == -1) - { - conn->fd = -1; - return FALSE; - } - - return setup_connection (conn); -} - -BaconMessageConnection * -bacon_message_connection_new (const char *prefix) -{ - BaconMessageConnection *conn; - - g_return_val_if_fail (prefix != NULL, NULL); - - conn = g_new0 (BaconMessageConnection, 1); - conn->path = socket_filename (prefix); - - if (test_is_socket (conn->path) == FALSE) - { - if (!try_server (conn)) - { - bacon_message_connection_free (conn); - return NULL; - } - - conn->is_server = TRUE; - return conn; - } - - if (try_client (conn) == FALSE) - { - unlink (conn->path); - try_server (conn); - if (conn->fd == -1) - { - bacon_message_connection_free (conn); - return NULL; - } - - conn->is_server = TRUE; - return conn; - } - - conn->is_server = FALSE; - return conn; -} - -void -bacon_message_connection_free (BaconMessageConnection *conn) -{ - GSList *child_conn; - - g_return_if_fail (conn != NULL); - /* Only servers can accept other connections */ - g_return_if_fail (conn->is_server != FALSE || - conn->accepted_connections == NULL); - - child_conn = conn->accepted_connections; - while (child_conn != NULL) { - bacon_message_connection_free (child_conn->data); - child_conn = g_slist_next (child_conn); - } - g_slist_free (conn->accepted_connections); - - if (conn->conn_id) { - g_source_remove (conn->conn_id); - conn->conn_id = 0; - } - if (conn->chan) { - g_io_channel_shutdown (conn->chan, FALSE, NULL); - g_io_channel_unref (conn->chan); - } - - if (conn->is_server != FALSE) { - unlink (conn->path); - } - if (conn->fd != -1) { - close (conn->fd); - } - - g_free (conn->path); - g_free (conn); -} - -void -bacon_message_connection_set_callback (BaconMessageConnection *conn, - BaconMessageReceivedFunc func, - gpointer user_data) -{ - g_return_if_fail (conn != NULL); - - conn->func = func; - conn->data = user_data; -} - -void -bacon_message_connection_send (BaconMessageConnection *conn, - const char *message) -{ - g_return_if_fail (conn != NULL); - g_return_if_fail (message != NULL); - - g_io_channel_write_chars (conn->chan, message, strlen (message), - NULL, NULL); - g_io_channel_write_chars (conn->chan, "\n", 1, NULL, NULL); - g_io_channel_flush (conn->chan, NULL); -} - -gboolean -bacon_message_connection_get_is_server (BaconMessageConnection *conn) -{ - g_return_val_if_fail (conn != NULL, FALSE); - - return conn->is_server; -} - diff --git a/src/bacon-message-connection.h b/src/bacon-message-connection.h deleted file mode 100644 index db4a91262..000000000 --- a/src/bacon-message-connection.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2003 Bastien Nocera - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Totem project hereby grant permission for non-gpl compatible GStreamer - * plugins to be used and distributed together with GStreamer and Totem. This - * permission are above and beyond the permissions granted by the GPL license - * Totem is covered by. - * - * Monday 7th February 2005: Christian Schaller: Add excemption clause. - * See license_change file for details. - * - */ - -#ifndef BACON_MESSAGE_CONNECTION_H -#define BACON_MESSAGE_CONNECTION_H - -#include - -G_BEGIN_DECLS - -typedef void (*BaconMessageReceivedFunc) (const char *message, - gpointer user_data); - -typedef struct BaconMessageConnection BaconMessageConnection; - -BaconMessageConnection *bacon_message_connection_new (const char *prefix); -void bacon_message_connection_free (BaconMessageConnection *conn); -void bacon_message_connection_set_callback (BaconMessageConnection *conn, - BaconMessageReceivedFunc func, - gpointer user_data); -void bacon_message_connection_send (BaconMessageConnection *conn, - const char *message); -gboolean bacon_message_connection_get_is_server (BaconMessageConnection *conn); - -G_END_DECLS - -#endif /* BACON_MESSAGE_CONNECTION_H */ diff --git a/src/empathy.c b/src/empathy.c index 637470773..3cc494a94 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -30,6 +30,7 @@ #include #include #include +#include #if HAVE_LIBCHAMPLAIN #include @@ -68,7 +69,6 @@ #include "empathy-call-window.h" #include "empathy-chat-window.h" #include "empathy-ft-manager.h" -#include "bacon-message-connection.h" #include "extensions/extensions.h" @@ -77,7 +77,7 @@ #include -static BaconMessageConnection *connection = NULL; +#define COMMAND_ACCOUNTS_DIALOG 1 static void dispatch_cb (EmpathyDispatcher *dispatcher, @@ -403,85 +403,29 @@ migrate_config_to_xdg_dir (void) g_free (old_dir); } -/* The code that handles single-instance and startup notification is - * copied from gedit. - * - * Copyright (C) 2005 - Paolo Maggi - */ -static void -on_bacon_message_received (const char *message, - gpointer data) +static UniqueResponse +unique_app_message_cb (UniqueApp *unique_app, + gint command, + UniqueMessageData *data, + guint timestamp, + gpointer user_data) { - GtkWidget *window = data; - guint32 startup_timestamp; - - g_return_if_fail (message != NULL); + GtkWidget *window = user_data; - DEBUG ("Other instance launched, presenting the main window. message='%s'", - message); + DEBUG ("Other instance launched, presenting the main window. " + "Command=%d, timestamp %u", command, timestamp); - if (strcmp (message, "accounts") == 0) { - /* accounts dialog requested */ + if (command == COMMAND_ACCOUNTS_DIALOG) { empathy_accounts_dialog_show (GTK_WINDOW (window), NULL); } else { - startup_timestamp = atoi (message); - - /* Set the proper interaction time on the window. - * Fall back to roundtripping to the X server when we - * don't have the timestamp, e.g. when launched from - * terminal. We also need to make sure that the window - * has been realized otherwise it will not work. lame. */ - if (startup_timestamp == 0) { - /* Work if launched from the terminal */ - DEBUG ("Using X server timestamp as a fallback"); - - if (!GTK_WIDGET_REALIZED (window)) { - gtk_widget_realize (GTK_WIDGET (window)); - } - - startup_timestamp = gdk_x11_get_server_time (gtk_widget_get_window (window)); - } - - gtk_window_present_with_time (GTK_WINDOW (window), startup_timestamp); + gtk_window_set_screen (GTK_WINDOW (window), + unique_message_data_get_screen (data)); + gtk_window_set_startup_id (GTK_WINDOW (window), + unique_message_data_get_startup_id (data)); + gtk_window_present_with_time (GTK_WINDOW (window), timestamp); } -} - -static guint32 -get_startup_timestamp () -{ - const gchar *startup_id_env; - gchar *startup_id = NULL; - gchar *time_str; - gchar *end; - gulong retval = 0; - - /* we don't unset the env, since startup-notification - * may still need it */ - startup_id_env = g_getenv ("DESKTOP_STARTUP_ID"); - if (startup_id_env == NULL) { - goto out; - } - - startup_id = g_strdup (startup_id_env); - - time_str = g_strrstr (startup_id, "_TIME"); - if (time_str == NULL) { - goto out; - } - - errno = 0; - /* Skip past the "_TIME" part */ - time_str += 5; - - retval = strtoul (time_str, &end, 0); - if (end == time_str || errno != 0) - retval = 0; - - out: - g_free (startup_id); - - return (retval > 0) ? retval : 0; + return UNIQUE_RESPONSE_OK; } static gboolean @@ -579,7 +523,6 @@ account_manager_ready_cb (EmpathyAccountManager *manager, int main (int argc, char *argv[]) { - guint32 startup_timestamp; #if HAVE_GEOCLUE EmpathyLocationManager *location_manager = NULL; #endif @@ -598,6 +541,7 @@ main (int argc, char *argv[]) gboolean accounts_dialog = FALSE; GError *error = NULL; TpDBusDaemon *dbus_daemon; + UniqueApp *unique_app; GOptionEntry options[] = { { "no-connect", 'n', 0, G_OPTION_ARG_NONE, &no_connect, @@ -645,39 +589,20 @@ main (int argc, char *argv[]) g_log_set_default_handler (default_log_handler, NULL); #endif - /* Setting up the bacon connection */ - startup_timestamp = get_startup_timestamp (); - connection = bacon_message_connection_new ("empathy"); - if (connection != NULL) { - if (!bacon_message_connection_get_is_server (connection)) { - gchar *message; - - if (accounts_dialog) { - DEBUG ("Showing accounts dialog from existing Empathy instance"); - - message = g_strdup ("accounts"); - - } else { - - DEBUG ("Activating existing instance"); - - message = g_strdup_printf ("%" G_GUINT32_FORMAT, - startup_timestamp); - } - - bacon_message_connection_send (connection, message); - - /* We never popup a window, so tell startup-notification - * that we are done. */ - gdk_notify_startup_complete (); - - g_free (message); - bacon_message_connection_free (connection); - - return EXIT_SUCCESS; - } - } else { - g_warning ("Cannot create the 'empathy' bacon connection."); + unique_app = unique_app_new_with_commands ("org.gnome.Empathy", + NULL, + "accounts_dialog", + COMMAND_ACCOUNTS_DIALOG, + NULL); + + if (unique_app_is_running (unique_app)) { + unique_app_send_message (unique_app, + accounts_dialog ? + COMMAND_ACCOUNTS_DIALOG : + UNIQUE_ACTIVATE, + NULL); + g_object_unref (unique_app); + return EXIT_SUCCESS; } /* Take well-known name */ @@ -737,12 +662,9 @@ main (int argc, char *argv[]) window = empathy_main_window_show (); icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list); - if (connection) { - /* We se the callback here because we need window */ - bacon_message_connection_set_callback (connection, - on_bacon_message_received, - window); - } + g_signal_connect (unique_app, "message-received", + G_CALLBACK (unique_app_message_cb), + window); /* Handle channels */ dispatcher = empathy_dispatcher_dup_singleton (); @@ -786,6 +708,7 @@ main (int argc, char *argv[]) g_object_unref (location_manager); #endif g_object_unref (ft_factory); + g_object_unref (unique_app); notify_uninit (); -- cgit v1.2.3 From d72ca1549ebfe0648060f12416a44530566c066b Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 16:23:17 +0200 Subject: Set presence on accounts when they become ready --- libempathy/empathy-account-manager.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 18eff355f..45d906889 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -327,6 +327,10 @@ account_manager_account_ready_cb (GObject *obj, G_CALLBACK (emp_account_removed_cb), manager); empathy_account_manager_check_ready (manager); + + /* update the account to the desired global presence */ + empathy_account_request_presence (account, priv->desired_presence, + priv->desired_status, priv->desired_status_message); } static EmpathyAccount * @@ -837,6 +841,9 @@ empathy_account_manager_request_global_presence ( GHashTableIter iter; gpointer value; + DEBUG ("request global presence, type: %d, status: %s, message: %s", + type, status, message); + g_hash_table_iter_init (&iter, priv->accounts); while (g_hash_table_iter_next (&iter, NULL, &value)) { @@ -850,7 +857,7 @@ empathy_account_manager_request_global_presence ( } /* save the requested global presence, to use it in case we create - * new accounts. + * new accounts or some accounts become ready. */ priv->desired_presence = type; -- cgit v1.2.3 From 8b24044e2bdeec4e282339c78d4eff9050cf964c Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 13:11:20 +0100 Subject: If there is a failure in recognizing the protocol name, fallback to the generic UI --- libempathy-gtk/empathy-account-widget.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 6d5b2b279..feb5b6d84 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -785,15 +785,8 @@ do_constructed (GObject *obj) empathy_account_widget_irc_build (self, filename); else if (!tp_strdiff (priv->protocol, "sip")) empathy_account_widget_sip_build (self, filename); - else if (!tp_strdiff (priv->protocol, "generic")) - account_widget_build_generic (self, filename); else - { - g_free (uiname); - g_free (filename); - g_critical ("Unknown protocol, can't build the account widget"); - return; - } + account_widget_build_generic (self, filename); g_free (uiname); g_free (filename); -- cgit v1.2.3 From 9b497ff832bbffab66eb193ebae190161db55757 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 13:11:46 +0100 Subject: Remove double check for connection == NULL --- libempathy-gtk/empathy-contact-dialogs.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index ad466da50..5c77a787e 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -337,10 +337,6 @@ can_add_contact_to_account (EmpathyAccount *account, if (connection == NULL) return FALSE; - if (connection == NULL) { - return FALSE; - } - contact_manager = empathy_contact_manager_dup_singleton (); result = empathy_contact_manager_get_flags_for_connection ( contact_manager, connection) & EMPATHY_CONTACT_LIST_CAN_ADD; -- cgit v1.2.3 From b7bc2ba10f00bf35fb6615e9565e69618b1528d3 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 13:18:03 +0100 Subject: no need to check for the size of the hash table --- libempathy/empathy-account-manager.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 45d906889..0bc0fe6f1 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -496,8 +496,7 @@ do_dispose (GObject *obj) priv->dispose_run = TRUE; - if (priv->create_results != NULL && - g_hash_table_size (priv->create_results) > 0) + if (priv->create_results != NULL) { /* the manager is being destroyed while there are account creation * processes pending; this should not happen, but emit the callbacks -- cgit v1.2.3 From af5442e540b7913f382e7691053c91472b867254 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 13:18:18 +0100 Subject: Fix coding style (tabs vs. spaces --- libempathy/empathy-account-manager.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 0bc0fe6f1..bc5d6e37d 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -507,13 +507,13 @@ do_dispose (GObject *obj) g_hash_table_iter_init (&iter, priv->create_results); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &result)) - { - g_simple_async_result_set_error (result, G_IO_ERROR, + { + g_simple_async_result_set_error (result, G_IO_ERROR, G_IO_ERROR_CANCELLED, "The account manager was disposed while " "creating the account"); - g_simple_async_result_complete (result); - g_object_unref (result); - } + g_simple_async_result_complete (result); + g_object_unref (result); + } } tp_dbus_daemon_cancel_name_owner_watch (priv->dbus, -- cgit v1.2.3 From 0c3cd08bfeadc61d4f679e9f36732e49d6500418 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 13:19:25 +0100 Subject: Only cancel the name owner watch if the dbus proxy still exists --- libempathy/empathy-account-manager.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index bc5d6e37d..00c5cb14f 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -516,11 +516,12 @@ do_dispose (GObject *obj) } } - tp_dbus_daemon_cancel_name_owner_watch (priv->dbus, - TP_ACCOUNT_MANAGER_BUS_NAME, account_manager_name_owner_cb, manager); if (priv->dbus != NULL) { + tp_dbus_daemon_cancel_name_owner_watch (priv->dbus, + TP_ACCOUNT_MANAGER_BUS_NAME, account_manager_name_owner_cb, manager); + g_object_unref (priv->dbus); priv->dbus = NULL; } -- cgit v1.2.3 From 665ec36c0690f5247e4803d7f5513097b2cf2bb4 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 16:36:20 +0100 Subject: Removed dead code --- libempathy/empathy-account-settings.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index df99ea1c5..bdf8024e8 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -33,16 +33,6 @@ G_DEFINE_TYPE(EmpathyAccountSettings, empathy_account_settings, G_TYPE_OBJECT) -/* signal enum */ -#if 0 -enum -{ - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; -#endif - enum { PROP_ACCOUNT = 1, PROP_CM_NAME, -- cgit v1.2.3 From ad9ed2451356457afaceddc7d0dc6b8b74a83bf6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 16:36:51 +0100 Subject: Plug some leaks --- libempathy/empathy-account.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index ffb6e6786..ae17f8d6a 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -234,8 +234,11 @@ empathy_account_update (EmpathyAccount *account, } if (g_hash_table_lookup (properties, "DisplayName") != NULL) - priv->display_name = - g_strdup (tp_asv_get_string (properties, "DisplayName")); + { + g_free (priv->display_name); + priv->display_name = + g_strdup (tp_asv_get_string (properties, "DisplayName")); + } if (g_hash_table_lookup (properties, "Enabled") != NULL) { @@ -257,6 +260,9 @@ empathy_account_update (EmpathyAccount *account, parameters = tp_asv_get_boxed (properties, "Parameters", TP_HASH_TYPE_STRING_VARIANT_MAP); + if (priv->parameters != NULL) + g_hash_table_unref (priv->parameters); + priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP, parameters); } -- cgit v1.2.3 From 65e338cadaca67c77e418903d6887ee0f0196827 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 16:37:28 +0100 Subject: No need to check if create_results exists in dispose --- libempathy/empathy-account-manager.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 00c5cb14f..12ecff1aa 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -490,32 +490,28 @@ do_dispose (GObject *obj) { EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (obj); EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + GHashTableIter iter; + GSimpleAsyncResult *result; if (priv->dispose_run) return; priv->dispose_run = TRUE; - if (priv->create_results != NULL) + /* the manager is being destroyed while there are account creation + * processes pending; this should not happen, but emit the callbacks + * with an error anyway. + */ + g_hash_table_iter_init (&iter, priv->create_results); + while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &result)) { - /* the manager is being destroyed while there are account creation - * processes pending; this should not happen, but emit the callbacks - * with an error anyway. - */ - GHashTableIter iter; - GSimpleAsyncResult *result; - - g_hash_table_iter_init (&iter, priv->create_results); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &result)) - { - g_simple_async_result_set_error (result, G_IO_ERROR, - G_IO_ERROR_CANCELLED, "The account manager was disposed while " - "creating the account"); - g_simple_async_result_complete (result); - g_object_unref (result); - } + g_simple_async_result_set_error (result, G_IO_ERROR, + G_IO_ERROR_CANCELLED, "The account manager was disposed while " + "creating the account"); + g_simple_async_result_complete (result); + g_object_unref (result); } - + g_hash_table_remove_all (priv->create_results); if (priv->dbus != NULL) { -- cgit v1.2.3 From cc4b0254397717079f7d53391560952a8b1992a5 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 16:40:24 +0100 Subject: Notify when display-name is updated --- libempathy/empathy-account.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index ae17f8d6a..b82080ee0 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -238,6 +238,7 @@ empathy_account_update (EmpathyAccount *account, g_free (priv->display_name); priv->display_name = g_strdup (tp_asv_get_string (properties, "DisplayName")); + g_object_notify (G_OBJECT (account), "display-name"); } if (g_hash_table_lookup (properties, "Enabled") != NULL) -- cgit v1.2.3 From 40ee5f34184be738a4f9f31456480c62a9ad3bb9 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 17:12:23 +0100 Subject: Fix identation --- src/empathy-accounts-dialog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 974b6dcc4..682104d76 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -164,7 +164,8 @@ get_account_setup_widget (EmpathyAccountSettings *settings) { if (!tp_strdiff (cm, dialogs[i].cm) && !tp_strdiff (proto, dialogs[i].proto)) - return empathy_account_widget_new_for_protocol (dialogs[i].proto, settings); + return empathy_account_widget_new_for_protocol (dialogs[i].proto, + settings); } return empathy_account_widget_new_for_protocol ("generic", settings); @@ -717,8 +718,7 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, COL_ACCOUNT_SETTINGS_POINTER, &settings, -1); - equal = empathy_account_settings_has_account - (settings, account); + equal = empathy_account_settings_has_account (settings, account); g_object_unref (settings); if (equal) -- cgit v1.2.3 From d7ad9a427fa8c11bcee8628a0bb5f56602fc84b3 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 17:12:55 +0100 Subject: _new for a signleton needs to return a ref --- src/empathy-accounts-dialog.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 682104d76..87d93c5ae 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1318,6 +1318,7 @@ do_constructor (GType type, if (dialog_singleton) { retval = G_OBJECT (dialog_singleton); + g_object_ref (retval); } else { -- cgit v1.2.3 From 31ef7d012ce3fe7ab4872f4864deaf4230feede1 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 17:54:25 +0100 Subject: Use the remove function account --- src/empathy-accounts-dialog.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 87d93c5ae..98d31b3b9 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1152,8 +1152,7 @@ accounts_dialog_response_cb (GtkWidget *widget, /* FIXME: Warn the user the account is not * complete and is going to be removed. */ - empathy_account_manager_remove - (priv->account_manager, account); + empathy_account_remove_async (account, NULL, NULL); g_object_unref (account); } -- cgit v1.2.3 From 955e5f31d9cf3056777ceaf321b8ed4dc33b06cd Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 17:55:33 +0100 Subject: rename status-reason to connection-status-reason and notify connection-status{-reason,} when changes happen --- libempathy/empathy-account.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index b82080ee0..7d89f20fc 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -287,7 +287,8 @@ empathy_account_update (EmpathyAccount *account, g_signal_emit (account, signals[STATUS_CHANGED], 0, old_s, priv->connection_status, priv->reason); - g_object_notify (G_OBJECT (account), "status"); + g_object_notify (G_OBJECT (account), "connection-status"); + g_object_notify (G_OBJECT (account), "connection-status-reason"); } if (presence_changed) @@ -560,7 +561,7 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON, - g_param_spec_uint ("status-reason", + g_param_spec_uint ("connection-status-reason", "ConnectionStatusReason", "The account connections status reason", 0, -- cgit v1.2.3 From acd0172ff0bcc511ec646f8859742542c0cd5393 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 17:56:05 +0100 Subject: Remove dead code --- libempathy/empathy-account-manager.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 12ecff1aa..9089e5f43 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -818,14 +818,6 @@ empathy_account_manager_dup_connections (EmpathyAccountManager *manager) return ret; } -void -empathy_account_manager_remove (EmpathyAccountManager *manager, - EmpathyAccount *account) -{ - /* FIXME */ -} - - void empathy_account_manager_request_global_presence ( EmpathyAccountManager *manager, -- cgit v1.2.3 From 6c2a10287ca173821152889963efdd6bc66e7a26 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 17:56:32 +0100 Subject: Rename desired presence to requested presence --- libempathy/empathy-account-manager.c | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 9089e5f43..9a76fdafe 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -56,12 +56,12 @@ typedef struct { gchar *global_status; gchar *global_status_message; - /* desired global presence, could be different + /* requested global presence, could be different * from the actual global one. */ - TpConnectionPresenceType desired_presence; - gchar *desired_status; - gchar *desired_status_message; + TpConnectionPresenceType requested_presence; + gchar *requested_status; + gchar *requested_status_message; GHashTable *create_results; } EmpathyAccountManagerPriv; @@ -112,9 +112,9 @@ emp_account_enabled_cb (EmpathyAccount *account, { g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account); - /* set the desired global presence on the account */ - empathy_account_request_presence (account, priv->desired_presence, - priv->desired_status, priv->desired_status_message); + /* set the requested global presence on the account */ + empathy_account_request_presence (account, priv->requested_presence, + priv->requested_status, priv->requested_status_message); } else g_signal_emit (manager, signals[ACCOUNT_DISABLED], 0, account); @@ -328,9 +328,9 @@ account_manager_account_ready_cb (GObject *obj, empathy_account_manager_check_ready (manager); - /* update the account to the desired global presence */ - empathy_account_request_presence (account, priv->desired_presence, - priv->desired_status, priv->desired_status_message); + /* update the account to the requested global presence */ + empathy_account_request_presence (account, priv->requested_presence, + priv->requested_status, priv->requested_status_message); } static EmpathyAccount * @@ -479,8 +479,8 @@ do_finalize (GObject *obj) g_free (priv->global_status); g_free (priv->global_status_message); - g_free (priv->desired_status); - g_free (priv->desired_status_message); + g_free (priv->requested_status); + g_free (priv->requested_status_message); G_OBJECT_CLASS (empathy_account_manager_parent_class)->finalize (obj); } @@ -847,18 +847,18 @@ empathy_account_manager_request_global_presence ( /* save the requested global presence, to use it in case we create * new accounts or some accounts become ready. */ - priv->desired_presence = type; + priv->requested_presence = type; - if (tp_strdiff (priv->desired_status, status)) + if (tp_strdiff (priv->requested_status, status)) { - g_free (priv->desired_status); - priv->desired_status = g_strdup (status); + g_free (priv->requested_status); + priv->requested_status = g_strdup (status); } - if (tp_strdiff (priv->desired_status_message, message)) + if (tp_strdiff (priv->requested_status_message, message)) { - g_free (priv->desired_status_message); - priv->desired_status_message = g_strdup (message); + g_free (priv->requested_status_message); + priv->requested_status_message = g_strdup (message); } } -- cgit v1.2.3 From 07a2794768ee8fbfb2d7b5a71ea22a9ea17d7b43 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 17:56:53 +0100 Subject: Set gui to NULL after unreffing it --- libempathy-gtk/empathy-account-widget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index feb5b6d84..2ba38d66b 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -837,6 +837,7 @@ do_constructed (GObject *obj) G_CALLBACK (account_widget_destroy_cb), self); empathy_builder_unref_and_keep_widget (self->ui_details->gui, self->ui_details->widget); + self->ui_details->gui = NULL; } static void -- cgit v1.2.3 From 72d258b32eddaae77992e30a127882cbaaab0be0 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 18 Aug 2009 10:58:59 +0100 Subject: keep a ref on the selected account --- src/empathy-accounts-dialog.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 98d31b3b9..f027eccc0 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1199,6 +1199,7 @@ accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms, { accounts_dialog_set_selected_account (dialog, priv->initial_selection); + g_object_unref (priv->initial_selection); priv->initial_selection = NULL; } } @@ -1304,6 +1305,10 @@ do_dispose (GObject *obj) priv->cms = NULL; } + if (priv->initial_selection != NULL) + g_object_unref (priv->initial_selection); + priv->initial_selection = NULL; + G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj); } @@ -1488,13 +1493,16 @@ empathy_accounts_dialog_show (GtkWindow *parent, priv = GET_PRIV (dialog); - if (selected_account && empathy_connection_managers_is_ready (priv->cms)) - accounts_dialog_set_selected_account (dialog, selected_account); - else - /* save the selection to set it later when the cms - * becomes ready. - */ - priv->initial_selection = selected_account; + if (selected_account) + { + if (empathy_connection_managers_is_ready (priv->cms)) + accounts_dialog_set_selected_account (dialog, selected_account); + else + /* save the selection to set it later when the cms + * becomes ready. + */ + priv->initial_selection = g_object_ref (selected_account); + } gtk_window_present (GTK_WINDOW (priv->window)); -- cgit v1.2.3 From 58da89ed39904ba96f085fbc18b3a7cdad54ac57 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 18 Aug 2009 16:32:27 +0100 Subject: Rename empathy_settings_get_dbus_signature to empathy_account_settings_get_dbus_signature --- libempathy-gtk/empathy-account-widget.c | 3 ++- libempathy/empathy-account-settings.c | 2 +- libempathy/empathy-account-settings.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 2ba38d66b..9d9d47dbd 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -121,7 +121,8 @@ account_widget_int_changed_cb (GtkWidget *widget, value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - signature = empathy_settings_get_dbus_signature (priv->settings, param_name); + signature = empathy_account_settings_get_dbus_signature (priv->settings, + param_name); g_return_if_fail (signature != NULL); DEBUG ("Setting %s to %d", param_name, value); diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index bdf8024e8..fbd0724d1 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -521,7 +521,7 @@ empathy_account_settings_get_default (EmpathyAccountSettings *settings, } const gchar * -empathy_settings_get_dbus_signature (EmpathyAccountSettings *settings, +empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings, const gchar *param) { TpConnectionManagerParam *p; diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h index 8ae692212..9bb6657e2 100644 --- a/libempathy/empathy-account-settings.h +++ b/libempathy/empathy-account-settings.h @@ -90,7 +90,7 @@ const GValue *empathy_account_settings_get (EmpathyAccountSettings *settings, const gchar *param); const gchar * -empathy_settings_get_dbus_signature (EmpathyAccountSettings *setting, +empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *setting, const gchar *param); const GValue * -- cgit v1.2.3 From ac3c718ca603a8261dfd02536e5a75bc60edfb4a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 18 Aug 2009 16:32:38 +0100 Subject: Fix indentation --- libempathy-gtk/empathy-account-widget.c | 39 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 9d9d47dbd..5444ffda2 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -248,27 +248,32 @@ account_widget_setup_widget (EmpathyAccountWidget *self, gint value = 0; const gchar *signature; - signature = empathy_settings_get_dbus_signature (priv->settings, param_name); + signature = empathy_account_settings_get_dbus_signature (priv->settings, + param_name); g_return_if_fail (signature != NULL); switch ((int)*signature) { - case DBUS_TYPE_INT16: - case DBUS_TYPE_INT32: - value = empathy_account_settings_get_int32 (priv->settings, param_name); - break; - case DBUS_TYPE_INT64: - value = empathy_account_settings_get_int64 (priv->settings, param_name); - break; - case DBUS_TYPE_UINT16: - case DBUS_TYPE_UINT32: - value = empathy_account_settings_get_uint32 (priv->settings, param_name); - break; - case DBUS_TYPE_UINT64: - value = empathy_account_settings_get_uint64 (priv->settings, param_name); - break; - default: - g_return_if_reached (); + case DBUS_TYPE_INT16: + case DBUS_TYPE_INT32: + value = empathy_account_settings_get_int32 (priv->settings, + param_name); + break; + case DBUS_TYPE_INT64: + value = empathy_account_settings_get_int64 (priv->settings, + param_name); + break; + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + value = empathy_account_settings_get_uint32 (priv->settings, + param_name); + break; + case DBUS_TYPE_UINT64: + value = empathy_account_settings_get_uint64 (priv->settings, + param_name); + break; + default: + g_return_if_reached (); } gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); -- cgit v1.2.3 From 266a064e053e0e5795167e47d3c1bb026e303284 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 18 Aug 2009 16:47:04 +0100 Subject: Get the DisplayName when the account is ready --- libempathy/empathy-account-settings.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index fbd0724d1..209f017b9 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -164,18 +164,14 @@ empathy_account_settings_constructed (GObject *object) { g_free (priv->cm_name); g_free (priv->protocol); - g_free (priv->display_name); priv->cm_name = g_strdup (empathy_account_get_connection_manager (priv->account)); priv->protocol = g_strdup (empathy_account_get_protocol (priv->account)); - priv->display_name = - g_strdup (empathy_account_get_display_name (priv->account)); } - g_assert (priv->cm_name != NULL && priv->protocol != NULL - && priv->display_name != NULL); + g_assert (priv->cm_name != NULL && priv->protocol != NULL); empathy_account_settings_check_readyness (self); @@ -342,6 +338,13 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self) if (priv->manager == NULL) return; + if (priv->account != NULL) + { + g_free (priv->display_name); + priv->display_name = + g_strdup (empathy_account_get_display_name (priv->account)); + } + priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager, priv->protocol); -- cgit v1.2.3 From 37dd3c3001f54daf3b2f41c2360bc2f46dcf00e8 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Fri, 31 Jul 2009 14:29:23 +1000 Subject: displatcher -> dispatcher --- libempathy/empathy-dispatcher.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 03f5fc1b8..47e214c8d 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -81,7 +81,7 @@ G_DEFINE_TYPE_WITH_CODE (EmpathyDispatcher, empathy_dispatcher_client_handler_iface_init); ); -static const gchar *empathy_displatcher_interfaces[] = { +static const gchar *empathy_dispatcher_interfaces[] = { TP_IFACE_CLIENT_HANDLER, NULL }; @@ -934,7 +934,7 @@ dispatcher_get_property (GObject *object, switch (property_id) { case PROP_INTERFACES: - g_value_set_boxed (value, empathy_displatcher_interfaces); + g_value_set_boxed (value, empathy_dispatcher_interfaces); break; case PROP_CHANNEL_FILTER: { -- cgit v1.2.3 From 84a60506e5b1cf6cdbf0e2838c0c37eeb3b4a480 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 18 Aug 2009 19:12:12 +0100 Subject: Add a debug message for tracking global status --- libempathy/empathy-account-manager.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 9a76fdafe..9f0c71003 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -201,6 +201,9 @@ emp_account_manager_update_global_presence (EmpathyAccountManager *manager) "status", &priv->global_status, "status-message", &priv->global_status_message, NULL); + + DEBUG ("Updated global presence to: %s (%d) \"%s\"", + priv->global_status, priv->global_presence, priv->global_status_message); } static void -- cgit v1.2.3 From eafc0f2bb66f45dbc2d79482c9c0caaf9c6f0c00 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 18 Aug 2009 19:13:14 +0100 Subject: the status in EmpathyIdle is the status_message not the status string --- libempathy/empathy-idle.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index b77dd0732..94764f420 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -102,14 +102,15 @@ idle_presence_changed_cb (EmpathyAccountManager *manager, /* Assume our presence is offline if MC reports UNSET */ state = TP_CONNECTION_PRESENCE_TYPE_OFFLINE; - DEBUG ("Presence changed to '%s' (%d)", status, state); + DEBUG ("Presence changed to '%s' (%d) \"%s\"", status, state, + status_message); g_free (priv->status); priv->state = state; - priv->status = NULL; - if (!EMP_STR_EMPTY (status)) { - priv->status = g_strdup (status); - } + if (EMP_STR_EMPTY (status_message)) + priv->status = NULL; + else + priv->status = g_strdup (status_message); g_object_notify (G_OBJECT (idle), "state"); g_object_notify (G_OBJECT (idle), "status"); -- cgit v1.2.3 From 27e11ea6e41c5b2498307d581caa751936de30f1 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 18 Aug 2009 19:33:10 +0100 Subject: replace UNIQUE_NAME_PREFIX by TP_ACCOUNT_OBJECT_PATH_BASE --- libempathy/empathy-account.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 7d89f20fc..623a324e8 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -28,6 +28,7 @@ #include #include #include +#include #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include @@ -38,8 +39,6 @@ #include "empathy-utils.h" #include "empathy-marshal.h" -#define UNIQUE_NAME_PREFIX "/org/freedesktop/Telepathy/Account/" - /* signals */ enum { STATUS_CHANGED, @@ -418,9 +417,9 @@ empathy_account_parse_unique_name (const gchar *bus_name, const gchar *cm, *cm_end; g_return_val_if_fail ( - g_str_has_prefix (bus_name, UNIQUE_NAME_PREFIX), FALSE); + g_str_has_prefix (bus_name, TP_ACCOUNT_OBJECT_PATH_BASE), FALSE); - cm = bus_name + strlen (UNIQUE_NAME_PREFIX); + cm = bus_name + strlen (TP_ACCOUNT_OBJECT_PATH_BASE); for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++) /* pass */; -- cgit v1.2.3 From eaac8d0b0724b90e6891ae69c3c8937861b8cdc9 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 19 Aug 2009 12:22:58 +0100 Subject: Don't automagically remove invalid accounts Automagic removal is slightly terrifying, if the user succeeded in creating the account it must have been valid at some point. So leave it there, the UI should indicate that there is a problem with the account so that the user can fix it instead. --- src/empathy-accounts-dialog.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index f027eccc0..f74de13a9 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1135,31 +1135,8 @@ accounts_dialog_response_cb (GtkWidget *widget, gint response, EmpathyAccountsDialog *dialog) { - GList *accounts, *l; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - if (response == GTK_RESPONSE_CLOSE) - { - /* Delete incomplete accounts */ - accounts = empathy_account_manager_dup_accounts - (priv->account_manager); - for (l = accounts; l; l = l->next) - { - EmpathyAccount *account; - - account = l->data; - if (!empathy_account_is_valid (account)) - /* FIXME: Warn the user the account is not - * complete and is going to be removed. - */ - empathy_account_remove_async (account, NULL, NULL); - - g_object_unref (account); - } - g_list_free (accounts); - - gtk_widget_destroy (widget); - } + gtk_widget_destroy (widget); } static void -- cgit v1.2.3 From 6f47d10791dac97495b73200e05122b6406ea74b Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 19 Aug 2009 12:59:06 +0100 Subject: Cache the icon inside EmpathyAccountSettings At some point we should set the Icon property in the account manager, for now just cache it in the settings so we can pass it by reference instead of needing to dup it as that's the API we want to have in the future --- libempathy/empathy-account-settings.c | 16 +++++++++------- src/empathy-accounts-dialog.c | 4 ---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 209f017b9..4bafac2c9 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -58,6 +58,7 @@ struct _EmpathyAccountSettingsPriv gchar *cm_name; gchar *protocol; gchar *display_name; + gchar *icon_name; gboolean ready; GHashTable *parameters; @@ -171,6 +172,8 @@ empathy_account_settings_constructed (GObject *object) g_strdup (empathy_account_get_protocol (priv->account)); } + priv->icon_name = g_strdup_printf ("im-%s", priv->protocol); + g_assert (priv->cm_name != NULL && priv->protocol != NULL); empathy_account_settings_check_readyness (self); @@ -309,6 +312,7 @@ empathy_account_settings_finalize (GObject *object) g_free (priv->cm_name); g_free (priv->protocol); g_free (priv->display_name); + g_free (priv->icon_name); g_hash_table_destroy (priv->parameters); @@ -343,6 +347,10 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self) g_free (priv->display_name); priv->display_name = g_strdup (empathy_account_get_display_name (priv->account)); + + g_free (priv->icon_name); + priv->icon_name = + (gchar *) empathy_account_get_icon_name (priv->account); } priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager, @@ -446,13 +454,7 @@ empathy_account_settings_get_icon_name (EmpathyAccountSettings *settings) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); - if (priv->account != NULL) - return g_strdup (empathy_account_get_icon_name (priv->account)); - - if (priv->tp_protocol != NULL) - return g_strdup_printf ("im-%s", priv->tp_protocol->name); - - return NULL; + return priv->icon_name; } const gchar * diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index f74de13a9..913239589 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -192,8 +192,6 @@ account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, empathy_account_settings_get_protocol (settings)); accounts_dialog_update_name_label (dialog, settings); - - g_free (icon_name); } static void @@ -396,8 +394,6 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, icon_name = empathy_account_settings_get_icon_name (settings); pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); - g_free (icon_name); - if (pixbuf) { if (status == TP_CONNECTION_STATUS_DISCONNECTED || -- cgit v1.2.3 From 6a6c9006908cb43e0cacca34cc22862582aadba6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 20 Aug 2009 17:57:17 +0100 Subject: Add a function to get the requested global presence from the account manager --- libempathy/empathy-account-manager.c | 16 ++++++++++++++++ libempathy/empathy-account-manager.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 9f0c71003..7624122d8 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -865,6 +865,22 @@ empathy_account_manager_request_global_presence ( } } +TpConnectionPresenceType +empathy_account_manager_get_requested_global_presence ( + EmpathyAccountManager *manager, + gchar **status, + gchar **message) +{ + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + + if (status != NULL) + *status = g_strdup (priv->requested_status); + if (message != NULL) + *message = g_strdup (priv->requested_status_message); + + return priv->requested_presence; +} + TpConnectionPresenceType empathy_account_manager_get_global_presence ( EmpathyAccountManager *manager, diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index 1f73f635e..e0ec93761 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -86,6 +86,11 @@ void empathy_account_manager_request_global_presence ( const gchar *status, const gchar *message); +TpConnectionPresenceType empathy_account_manager_get_requested_global_presence ( + EmpathyAccountManager *manager, + gchar **status, + gchar **message); + TpConnectionPresenceType empathy_account_manager_get_global_presence ( EmpathyAccountManager *manager, gchar **status, -- cgit v1.2.3 From dcb2ab438c8b9d02e6eef6a53d93242836db2ae7 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 20 Aug 2009 17:58:48 +0100 Subject: Only set the current global requested on the initial set of accounts Stop setting the presence automagically when an account gets enabled or becomes ready, in both cases this account might be created or be enabled by some other UI and that UI should make the decisions about it's requested presence. --- libempathy/empathy-account-manager.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 7624122d8..bd27fae54 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -106,16 +106,8 @@ emp_account_enabled_cb (EmpathyAccount *account, GParamSpec *spec, gpointer manager) { - EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - if (empathy_account_is_enabled (account)) - { - g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account); - - /* set the requested global presence on the account */ - empathy_account_request_presence (account, priv->requested_presence, - priv->requested_status, priv->requested_status_message); - } + g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account); else g_signal_emit (manager, signals[ACCOUNT_DISABLED], 0, account); } @@ -279,6 +271,14 @@ empathy_account_manager_check_ready (EmpathyAccountManager *manager) return; } + /* Rerequest global presence on the initial set of accounts for cases where a + * global presence was requested before the manager was ready */ + if (priv->requested_presence != TP_CONNECTION_PRESENCE_TYPE_UNSET) + empathy_account_manager_request_global_presence (manager, + priv->requested_presence, + priv->requested_status, + priv->requested_status_message); + priv->ready = TRUE; g_object_notify (G_OBJECT (manager), "ready"); } @@ -330,10 +330,6 @@ account_manager_account_ready_cb (GObject *obj, G_CALLBACK (emp_account_removed_cb), manager); empathy_account_manager_check_ready (manager); - - /* update the account to the requested global presence */ - empathy_account_request_presence (account, priv->requested_presence, - priv->requested_status, priv->requested_status_message); } static EmpathyAccount * -- cgit v1.2.3 From baa418e11bf914a99a5ce40d12c964cb394e0e63 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 20 Aug 2009 18:04:49 +0100 Subject: Set the RequestedPresence when creating a new command When we create a new account set the initial value of RequestedPresence to the global requested presence, but don't enable it by default. This will cause its requested presence to always be in sync with the rest of empathy. --- libempathy/empathy-account-settings.c | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 4bafac2c9..6d43c4788 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -23,6 +23,8 @@ #include #include +#include +#include #include "empathy-account-settings.h" #include "empathy-account-manager.h" @@ -942,8 +944,41 @@ empathy_account_settings_do_create_account (EmpathyAccountSettings *settings) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); GHashTable *properties; + TpConnectionPresenceType type; + gchar *status; + gchar *message; - properties = g_hash_table_new (NULL, NULL); + properties = tp_asv_new (NULL, NULL); + + type = empathy_account_manager_get_requested_global_presence + (priv->account_manager, &status, &message); + + if (type != TP_CONNECTION_PRESENCE_TYPE_UNSET) + { + /* Create the account with the requested presence the same as the current + * global requested presence, but don't enable it */ + GValueArray *presence; + GValue vtype = { 0, }; + GValue vstatus = { 0, }; + GValue vmessage = { 0, }; + + presence = g_value_array_new (3); + + g_value_init (&vtype, G_TYPE_UINT); + g_value_set_uint (&vtype, type); + g_value_array_append (presence, &vtype); + + g_value_init (&vstatus, G_TYPE_STRING); + g_value_take_string (&vstatus, status); + g_value_array_append (presence, &vstatus); + + g_value_init (&vmessage, G_TYPE_STRING); + g_value_take_string (&vmessage, message); + g_value_array_append (presence, &vmessage); + + tp_asv_take_boxed (properties, TP_IFACE_ACCOUNT ".RequestedPresence", + TP_STRUCT_TYPE_SIMPLE_PRESENCE, presence); + } empathy_account_manager_create_account_async (priv->account_manager, priv->cm_name, priv->protocol, priv->display_name, -- cgit v1.2.3 From 15dda78fbc8c5fa6e942b8e6098689678914b7c5 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 20 Aug 2009 19:49:12 +0100 Subject: When getting an account for an unknown path automagically create the new account object --- libempathy/empathy-account-manager.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index bd27fae54..83de26c67 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -332,8 +332,8 @@ account_manager_account_ready_cb (GObject *obj, empathy_account_manager_check_ready (manager); } -static EmpathyAccount * -account_manager_add_account (EmpathyAccountManager *manager, +EmpathyAccount * +empathy_account_manager_get_account (EmpathyAccountManager *manager, const gchar *path) { EmpathyAccountManagerPriv *priv = GET_PRIV (manager); @@ -376,7 +376,7 @@ account_manager_got_all_cb (TpProxy *proxy, { gchar *name = g_ptr_array_index (accounts, i); - account_manager_add_account (manager, name); + empathy_account_manager_get_account (manager, name); } empathy_account_manager_check_ready (manager); @@ -394,7 +394,7 @@ account_validity_changed_cb (TpAccountManager *proxy, if (!valid) return; - account_manager_add_account (manager, path); + empathy_account_manager_get_account (manager, path); } static void @@ -757,15 +757,6 @@ empathy_account_manager_get_account_for_connection ( return NULL; } -EmpathyAccount * -empathy_account_manager_get_account (EmpathyAccountManager *manager, - const gchar *unique_name) -{ - EmpathyAccountManagerPriv *priv = GET_PRIV (manager); - - return g_hash_table_lookup (priv->accounts, unique_name); -} - GList * empathy_account_manager_dup_accounts (EmpathyAccountManager *manager) { @@ -915,7 +906,7 @@ empathy_account_manager_created_cb (TpAccountManager *proxy, return; } - account = account_manager_add_account (manager, account_path); + account = empathy_account_manager_get_account (manager, account_path); g_hash_table_insert (priv->create_results, account, my_res); } -- cgit v1.2.3 From 8bd008f556dcab022cceb2eaceb3080cb7198efc Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 20 Aug 2009 20:29:26 +0100 Subject: Add API to get teh TpConnection for an account on a certain path --- libempathy/empathy-account.c | 90 +++++++++++++++++++++++++++++--------------- libempathy/empathy-account.h | 2 + 2 files changed, 61 insertions(+), 31 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 623a324e8..445576b63 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -105,7 +105,7 @@ struct _EmpathyAccountPriv #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount) static void _empathy_account_set_connection (EmpathyAccount *account, - TpConnection *connection); + const gchar *path); static void empathy_account_init (EmpathyAccount *obj) @@ -205,7 +205,6 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) { EmpathyAccountPriv *priv = GET_PRIV (account); - const gchar *conn_path; GValueArray *arr; TpConnectionStatus old_s = priv->connection_status; gboolean presence_changed = FALSE; @@ -301,23 +300,10 @@ empathy_account_update (EmpathyAccount *account, if (g_hash_table_lookup (properties, "Connection") != NULL) { - conn_path = tp_asv_get_object_path (properties, "Connection"); + const gchar *conn_path = + tp_asv_get_object_path (properties, "Connection"); - if (tp_strdiff (conn_path, "/") && priv->connection == NULL) - { - TpConnection *conn; - GError *error = NULL; - conn = tp_connection_new (priv->dbus, NULL, conn_path, &error); - - if (conn == NULL) - { - DEBUG ("Failed to create a new TpConnection: %s", - error->message); - g_error_free (error); - } - - _empathy_account_set_connection (account, conn); - } + _empathy_account_set_connection (account, conn_path); } } @@ -704,6 +690,35 @@ empathy_account_get_connection (EmpathyAccount *account) return NULL; } +/** + * empathy_account_get_connection_for: + * @account: a #EmpathyAccount + * @patch: the path to connection object for #EmpathyAccount + * + * Get the connection of the account on path. This function does not return a + * new ref. It is not guaranteed that the returned connection object is ready + * + * Returns: the connection of the account. + **/ +TpConnection * +empathy_account_get_connection_for (EmpathyAccount *account, + const gchar *path) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + /* double-check that the object path is valid */ + if (!tp_dbus_check_valid_object_path (path, NULL)) + return NULL; + + /* Should be a full object path, not the special "/" value */ + if (strlen (path) == 1) + return NULL; + + _empathy_account_set_connection (account, path); + + return priv->connection; +} + /** * empathy_account_get_unique_name: * @account: a #EmpathyAccount @@ -850,18 +865,20 @@ _empathy_account_connection_invalidated_cb (TpProxy *self, static void _empathy_account_set_connection (EmpathyAccount *account, - TpConnection *connection) + const gchar *path) { EmpathyAccountPriv *priv = GET_PRIV (account); - if (priv->connection == connection) - return; + if (priv->connection != NULL) + { + const gchar *current; - /* Connection already set, don't set the new one */ - if (connection != NULL && priv->connection != NULL) - return; + current = tp_proxy_get_object_path (priv->connection); + if (!tp_strdiff (current, path)) + return; + } - if (connection == NULL) + if (priv->connection != NULL) { g_signal_handler_disconnect (priv->connection, priv->connection_invalidated_id); @@ -869,21 +886,32 @@ _empathy_account_set_connection (EmpathyAccount *account, g_object_unref (priv->connection); priv->connection = NULL; - g_object_notify (G_OBJECT (account), "connection"); } - else + + if (tp_strdiff ("/", path)) { - priv->connection = g_object_ref (connection); + GError *error = NULL; + priv->connection = tp_connection_new (priv->dbus, NULL, path, &error); + + if (priv->connection == NULL) + { + DEBUG ("Failed to create a new TpConnection: %s", + error->message); + g_error_free (error); + } + priv->connection_invalidated_id = g_signal_connect (priv->connection, "invalidated", - G_CALLBACK (_empathy_account_connection_invalidated_cb), - account); + G_CALLBACK (_empathy_account_connection_invalidated_cb), + account); DEBUG ("Readying connection for %s", priv->unique_name); /* notify a change in the connection property when it's ready */ tp_connection_call_when_ready (priv->connection, - empathy_account_connection_ready_cb, account); + empathy_account_connection_ready_cb, account); } + + g_object_notify (G_OBJECT (account), "connection"); } void diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 67939d748..d1961b932 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -58,6 +58,8 @@ GType empathy_account_get_type (void); gboolean empathy_account_is_just_connected (EmpathyAccount *account); TpConnection *empathy_account_get_connection (EmpathyAccount *account); +TpConnection *empathy_account_get_connection_for (EmpathyAccount *account, + const gchar *path); const gchar *empathy_account_get_unique_name (EmpathyAccount *account); const gchar *empathy_account_get_display_name (EmpathyAccount *account); -- cgit v1.2.3 From d458f689738ad5a94b3355fe73c167e469bce2dc Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 20 Aug 2009 20:29:41 +0100 Subject: Use new api to get connections --- libempathy/empathy-dispatcher.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 47e214c8d..927cd5c3e 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -1802,12 +1802,16 @@ empathy_dispatcher_handle_channels (TpSvcClientHandler *self, account = empathy_account_manager_get_account (priv->account_manager, account_path); - /* FIXME */ g_assert (account != NULL); - connection = empathy_account_get_connection (account); - /* FIXME */ - g_assert (connection != NULL); + connection = empathy_account_get_connection_for (account, connection_path); + if (connection == NULL) + { + GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, + "Invalid connection argument" }; + dbus_g_method_return_error (context, &error); + return; + } for (i = 0; i < channels->len ; i++) { -- cgit v1.2.3 From a1f79e1c8bb3613005f5fe158e23d22290d27403 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 21 Aug 2009 15:40:09 +0200 Subject: Use g_strdup instead of casting a const gchar* to a gchar*. --- libempathy/empathy-account-settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 6d43c4788..cede5fd9b 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -352,7 +352,7 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self) g_free (priv->icon_name); priv->icon_name = - (gchar *) empathy_account_get_icon_name (priv->account); + g_strdup (empathy_account_get_icon_name (priv->account)); } priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager, -- cgit v1.2.3 From 0f736265600a180423b1640841923f560fba70c2 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 16:11:17 +0100 Subject: Let the cached parameters asv own the key strings --- libempathy/empathy-account-settings.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index cede5fd9b..5c4644d5a 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -85,7 +85,9 @@ empathy_account_settings_init (EmpathyAccountSettings *obj) priv->managers = empathy_connection_managers_dup_singleton (); priv->account_manager = empathy_account_manager_dup_singleton (); - priv->parameters = tp_asv_new (NULL, NULL); + priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify) tp_g_value_slice_free); + priv->unset_parameters = g_array_new (TRUE, FALSE, sizeof (gchar *)); } @@ -765,7 +767,7 @@ empathy_account_settings_set_string (EmpathyAccountSettings *settings, { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); - tp_asv_set_string (priv->parameters, param, value); + tp_asv_set_string (priv->parameters, g_strdup (param), value); } void @@ -775,7 +777,7 @@ empathy_account_settings_set_int32 (EmpathyAccountSettings *settings, { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); - tp_asv_set_int32 (priv->parameters, param, value); + tp_asv_set_int32 (priv->parameters, g_strdup (param), value); } void @@ -785,7 +787,7 @@ empathy_account_settings_set_int64 (EmpathyAccountSettings *settings, { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); - tp_asv_set_int64 (priv->parameters, param, value); + tp_asv_set_int64 (priv->parameters, g_strdup (param), value); } void @@ -795,7 +797,7 @@ empathy_account_settings_set_uint32 (EmpathyAccountSettings *settings, { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); - tp_asv_set_uint32 (priv->parameters, param, value); + tp_asv_set_uint32 (priv->parameters, g_strdup (param), value); } void @@ -805,7 +807,7 @@ empathy_account_settings_set_uint64 (EmpathyAccountSettings *settings, { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); - tp_asv_set_uint64 (priv->parameters, param, value); + tp_asv_set_uint64 (priv->parameters, g_strdup (param), value); } void @@ -815,7 +817,7 @@ empathy_account_settings_set_boolean (EmpathyAccountSettings *settings, { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); - tp_asv_set_boolean (priv->parameters, param, value); + tp_asv_set_boolean (priv->parameters, g_strdup (param), value); } static void -- cgit v1.2.3 From 4b3de48f8648402437053f01296ff596cfdbf38a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 17:14:55 +0100 Subject: Don't hook up to invalidated when creating the connection failed --- libempathy/empathy-account.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 445576b63..914ae6141 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -899,16 +899,17 @@ _empathy_account_set_connection (EmpathyAccount *account, error->message); g_error_free (error); } - - priv->connection_invalidated_id = g_signal_connect (priv->connection, - "invalidated", - G_CALLBACK (_empathy_account_connection_invalidated_cb), - account); - - DEBUG ("Readying connection for %s", priv->unique_name); - /* notify a change in the connection property when it's ready */ - tp_connection_call_when_ready (priv->connection, - empathy_account_connection_ready_cb, account); + else + { + priv->connection_invalidated_id = g_signal_connect (priv->connection, + "invalidated", + G_CALLBACK (_empathy_account_connection_invalidated_cb), account); + + DEBUG ("Readying connection for %s", priv->unique_name); + /* notify a change in the connection property when it's ready */ + tp_connection_call_when_ready (priv->connection, + empathy_account_connection_ready_cb, account); + } } g_object_notify (G_OBJECT (account), "connection"); -- cgit v1.2.3 From fd8e9c5dc2584055177c7a79021cdd53ca431c22 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 17:23:48 +0100 Subject: Rename empathy_account_get_connection_for to empathy_account_get_connection_for_path --- libempathy/empathy-account.c | 4 ++-- libempathy/empathy-account.h | 2 +- libempathy/empathy-dispatcher.c | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 914ae6141..5a6b31f0a 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -691,7 +691,7 @@ empathy_account_get_connection (EmpathyAccount *account) } /** - * empathy_account_get_connection_for: + * empathy_account_get_connection_for_path: * @account: a #EmpathyAccount * @patch: the path to connection object for #EmpathyAccount * @@ -701,7 +701,7 @@ empathy_account_get_connection (EmpathyAccount *account) * Returns: the connection of the account. **/ TpConnection * -empathy_account_get_connection_for (EmpathyAccount *account, +empathy_account_get_connection_for_path (EmpathyAccount *account, const gchar *path) { EmpathyAccountPriv *priv = GET_PRIV (account); diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index d1961b932..6351c9316 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -58,7 +58,7 @@ GType empathy_account_get_type (void); gboolean empathy_account_is_just_connected (EmpathyAccount *account); TpConnection *empathy_account_get_connection (EmpathyAccount *account); -TpConnection *empathy_account_get_connection_for (EmpathyAccount *account, +TpConnection *empathy_account_get_connection_for_path (EmpathyAccount *account, const gchar *path); const gchar *empathy_account_get_unique_name (EmpathyAccount *account); const gchar *empathy_account_get_display_name (EmpathyAccount *account); diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 927cd5c3e..7e1492de8 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -1804,7 +1804,8 @@ empathy_dispatcher_handle_channels (TpSvcClientHandler *self, account_path); g_assert (account != NULL); - connection = empathy_account_get_connection_for (account, connection_path); + connection = empathy_account_get_connection_for_path (account, + connection_path); if (connection == NULL) { GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, -- cgit v1.2.3 From 10d2be90115f126fbc0a31050ee8555bf822ef89 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 18:01:34 +0100 Subject: Add new files to the POTFILES --- po/POTFILES.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/po/POTFILES.in b/po/POTFILES.in index ec6aea64f..d2759b5a0 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -22,6 +22,7 @@ libempathy-gtk/empathy-account-widget-irc.c [type: gettext/glade]libempathy-gtk/empathy-account-widget-jabber.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-msn.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-local-xmpp.ui +[type: gettext/glade]libempathy-gtk/empathy-account-widget-salut.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-sip.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-yahoo.ui libempathy-gtk/empathy-avatar-chooser.c @@ -62,6 +63,7 @@ nothere/src/nothere-applet.c src/empathy.c src/empathy-about-dialog.c +src/empathy-account-assistant.c src/empathy-accounts-dialog.c [type: gettext/glade]src/empathy-accounts-dialog.ui src/empathy-call-window.c @@ -75,6 +77,7 @@ src/empathy-ft-manager.c [type: gettext/glade]src/empathy-ft-manager.ui src/empathy-import-dialog.c [type: gettext/glade]src/empathy-import-dialog.ui +src/empathy-import-widget.c src/empathy-main-window.c [type: gettext/glade]src/empathy-main-window.ui src/empathy-new-chatroom-dialog.c -- cgit v1.2.3 From fee38f8b6bb302fafb9e506cf7522c6071f76a55 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 18:03:10 +0100 Subject: Fix trailing spaces --- libempathy-gtk/empathy-protocol-chooser.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index ecd26d8ff..d85997fb2 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -127,7 +127,6 @@ static const char * protocol_chooser_proto_name_to_display_name (const gchar *proto_name) { int i; - static struct { const gchar *proto; const gchar *display; -- cgit v1.2.3 From 0ccf92f2b7b27dd85e722188cab07041f1083314 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 18:03:23 +0100 Subject: Update python bindings --- python/pyempathy/pyempathy.defs | 10 +++ python/pyempathygtk/pyempathygtk.defs | 143 ++++++---------------------------- 2 files changed, 33 insertions(+), 120 deletions(-) diff --git a/python/pyempathy/pyempathy.defs b/python/pyempathy/pyempathy.defs index b8f0b40aa..ee8aab8d0 100644 --- a/python/pyempathy/pyempathy.defs +++ b/python/pyempathy/pyempathy.defs @@ -365,6 +365,16 @@ ) ) +(define-method get_requested_global_presence + (of-object "EmpathyAccountManager") + (c-name "empathy_account_manager_get_requested_global_presence") + (return-type "TpConnectionPresenceType") + (parameters + '("gchar**" "status") + '("gchar**" "message") + ) +) + (define-method get_global_presence (of-object "EmpathyAccountManager") (c-name "empathy_account_manager_get_global_presence") diff --git a/python/pyempathygtk/pyempathygtk.defs b/python/pyempathygtk/pyempathygtk.defs index 51d32709e..dd906cddd 100644 --- a/python/pyempathygtk/pyempathygtk.defs +++ b/python/pyempathygtk/pyempathygtk.defs @@ -7,6 +7,13 @@ (gtype-id "EMPATHY_TYPE_ACCOUNT_CHOOSER") ) +(define-object AccountWidget + (in-module "Empathy") + (parent "GObject") + (c-name "EmpathyAccountWidget") + (gtype-id "EMPATHY_TYPE_ACCOUNT_WIDGET") +) + (define-object AvatarChooser (in-module "Empathy") (parent "GtkButton") @@ -328,114 +335,16 @@ ;; From empathy-account-widget.h -(define-function account_widget_handle_params - (c-name "empathy_account_widget_handle_params") - (return-type "none") - (parameters - '("EmpathyAccountSettings*" "settings") - '("GtkBuilder*" "gui") - '("const-gchar*" "first_widget") - ) - (varargs #t) -) - -(define-function account_widget_add_forget_button - (c-name "empathy_account_widget_add_forget_button") - (return-type "none") - (parameters - '("EmpathyAccountSettings*" "settings") - '("GtkBuilder*" "gui") - '("const-gchar*" "button") - '("const-gchar*" "entry") - ) -) - -(define-function account_widget_add_apply_button - (c-name "empathy_account_widget_add_apply_button") - (return-type "none") - (parameters - '("EmpathyAccountSettings*" "settings") - '("GtkWidget*" "vbox") - ) -) - -(define-function account_widget_set_default_focus - (c-name "empathy_account_widget_set_default_focus") - (return-type "none") - (parameters - '("GtkBuilder*" "gui") - '("const-gchar*" "entry") - ) -) - -(define-function account_widget_generic_new - (c-name "empathy_account_widget_generic_new") - (is-constructor-of "EmpathyAccountWidgetGeneric") - (return-type "GtkWidget*") - (parameters - '("EmpathyAccountSettings*" "settings") - ) -) - -(define-function account_widget_salut_new - (c-name "empathy_account_widget_salut_new") - (is-constructor-of "EmpathyAccountWidgetSalut") - (return-type "GtkWidget*") - (parameters - '("EmpathyAccountSettings*" "settings") - ) -) - -(define-function account_widget_msn_new - (c-name "empathy_account_widget_msn_new") - (is-constructor-of "EmpathyAccountWidgetMsn") - (return-type "GtkWidget*") - (parameters - '("EmpathyAccountSettings*" "settings") - ) -) - -(define-function account_widget_jabber_new - (c-name "empathy_account_widget_jabber_new") - (is-constructor-of "EmpathyAccountWidgetJabber") - (return-type "GtkWidget*") - (parameters - '("EmpathyAccountSettings*" "settings") - ) -) - -(define-function account_widget_icq_new - (c-name "empathy_account_widget_icq_new") - (is-constructor-of "EmpathyAccountWidgetIcq") - (return-type "GtkWidget*") - (parameters - '("EmpathyAccountSettings*" "settings") - ) -) - -(define-function account_widget_aim_new - (c-name "empathy_account_widget_aim_new") - (is-constructor-of "EmpathyAccountWidgetAim") - (return-type "GtkWidget*") - (parameters - '("EmpathyAccountSettings*" "settings") - ) -) - -(define-function account_widget_yahoo_new - (c-name "empathy_account_widget_yahoo_new") - (is-constructor-of "EmpathyAccountWidgetYahoo") - (return-type "GtkWidget*") - (parameters - '("EmpathyAccountSettings*" "settings") - ) +(define-function account_widget_get_type + (c-name "empathy_account_widget_get_type") + (return-type "GType") ) -(define-function account_widget_groupwise_new - (c-name "empathy_account_widget_groupwise_new") - (is-constructor-of "EmpathyAccountWidgetGroupwise") +(define-function account_widget_new_for_protocol + (c-name "empathy_account_widget_new_for_protocol") (return-type "GtkWidget*") (parameters + '("const-char*" "protocol") '("EmpathyAccountSettings*" "settings") ) ) @@ -444,12 +353,12 @@ ;; From empathy-account-widget-irc.h -(define-function account_widget_irc_new - (c-name "empathy_account_widget_irc_new") - (is-constructor-of "EmpathyAccountWidgetIrc") - (return-type "GtkWidget*") +(define-method irc_build + (of-object "EmpathyAccountWidget") + (c-name "empathy_account_widget_irc_build") + (return-type "none") (parameters - '("EmpathyAccountSettings*" "settings") + '("const-char*" "filename") ) ) @@ -457,12 +366,12 @@ ;; From empathy-account-widget-sip.h -(define-function account_widget_sip_new - (c-name "empathy_account_widget_sip_new") - (is-constructor-of "EmpathyAccountWidgetSip") - (return-type "GtkWidget*") +(define-method sip_build + (of-object "EmpathyAccountWidget") + (c-name "empathy_account_widget_sip_build") + (return-type "none") (parameters - '("EmpathyAccountSettings*" "settings") + '("const-char*" "filename") ) ) @@ -1611,12 +1520,6 @@ ) ) -(define-method n_protocols - (of-object "EmpathyProtocolChooser") - (c-name "empathy_protocol_chooser_n_protocols") - (return-type "gint") -) - ;; From empathy-smiley-manager.h -- cgit v1.2.3 From f1394c92c71040e26bf6ec204c3eb9d8bb11ba25 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 18:08:30 +0100 Subject: fix critical errors in the .hr translation --- po/hr.po | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/po/hr.po b/po/hr.po index da1b5692c..854950b60 100644 --- a/po/hr.po +++ b/po/hr.po @@ -9,6 +9,7 @@ msgstr "" "PO-Revision-Date: 2007-08-25 20:40+CET\n" "Last-Translator: Senko Rasic \n" "MIME-Version: 1.0\n" +"Language-Team: Croatian\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%" @@ -535,7 +536,7 @@ msgstr "Soba za razgovor" #, c-format msgid "Conversation" msgid_plural "Conversations (%d)" -msgstr[0] "Razgovor" +msgstr[0] "Razgovor (%d)" msgstr[1] "Razgovora (%d)" msgstr[2] "Razgovora (%d)" -- cgit v1.2.3 From 735481c7e2d0d2180d5970b83722452f8aa99ae9 Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Tue, 28 Jul 2009 14:49:26 +0200 Subject: Port empathy-import-dialog to mc5 --- src/empathy-import-dialog.c | 143 +++++++++++++++++++++++++++----------------- src/empathy-import-dialog.h | 7 ++- 2 files changed, 93 insertions(+), 57 deletions(-) diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c index 1d0854dd0..a70a6eedd 100644 --- a/src/empathy-import-dialog.c +++ b/src/empathy-import-dialog.c @@ -36,7 +36,7 @@ #include #include #include - +#include #include typedef struct @@ -69,6 +69,8 @@ empathy_import_account_data_new (const gchar *source) data->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); data->source = g_strdup (source); + data->protocol = NULL; + data->connection_manager = NULL; return data; } @@ -78,8 +80,10 @@ empathy_import_account_data_free (EmpathyImportAccountData *data) { if (data == NULL) return; - if (data->profile != NULL) - g_object_unref (data->profile); + if (data->protocol != NULL) + g_free (data->protocol); + if (data->connection_manager != NULL) + g_free (data->connection_manager); if (data->settings != NULL) g_hash_table_destroy (data->settings); if (data->source != NULL) @@ -89,66 +93,60 @@ empathy_import_account_data_free (EmpathyImportAccountData *data) } static void -import_dialog_add_account (EmpathyImportAccountData *data) +import_dialog_create_account_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) { - EmpathyAccountManager *account_manager; + EmpathyImportAccountData *data = (EmpathyImportAccountData *) user_data; EmpathyAccount *account; - GHashTableIter iter; - gpointer key, value; - gchar *display_name; - GValue *username; + GError *error = NULL; - account_manager = empathy_account_manager_dup_singleton (); - account = empathy_account_manager_create_by_profile (account_manager, - data->profile); + account = empathy_account_manager_create_account_finish ( + EMPATHY_ACCOUNT_MANAGER (source), result, &error); - g_object_unref (account_manager); if (account == NULL) { - DEBUG ("Failed to create account"); + DEBUG ("Failed to create account: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + empathy_import_account_data_free (data); return; } - g_hash_table_iter_init (&iter, data->settings); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - const gchar *param = key; - GValue *gvalue = value; + DEBUG ("account created\n"); - switch (G_VALUE_TYPE (gvalue)) - { - case G_TYPE_STRING: - DEBUG ("Set param '%s' to '%s' (string)", - param, g_value_get_string (gvalue)); - empathy_account_set_param_string (account, - param, g_value_get_string (gvalue)); - break; - - case G_TYPE_BOOLEAN: - DEBUG ("Set param '%s' to %s (boolean)", - param, g_value_get_boolean (gvalue) ? "TRUE" : "FALSE"); - empathy_account_set_param_boolean (account, - param, g_value_get_boolean (gvalue)); - break; - - case G_TYPE_INT: - DEBUG ("Set param '%s' to '%i' (integer)", - param, g_value_get_int (gvalue)); - empathy_account_set_param_int (account, - param, g_value_get_int (gvalue)); - break; - } - } + g_object_unref (account); +} + +static void +import_dialog_add_account (EmpathyImportAccountData *data) +{ + EmpathyAccountManager *account_manager; + gchar *display_name; + GHashTable *properties; + GValue *username; + + account_manager = empathy_account_manager_dup_singleton (); + + DEBUG ("connection_manager: %s\n", data->connection_manager); /* Set the display name of the account */ username = g_hash_table_lookup (data->settings, "account"); display_name = g_strdup_printf ("%s (%s)", - mc_profile_get_display_name (data->profile), + data->protocol, g_value_get_string (username)); - empathy_account_set_display_name (account, display_name); + DEBUG ("display name: %s\n", display_name); + + properties = g_hash_table_new (NULL, NULL); + + empathy_account_manager_create_account_async (account_manager, + (const gchar*) data->connection_manager, data->protocol, display_name, + data->settings, properties, import_dialog_create_account_cb, NULL); + + g_hash_table_unref (properties); g_free (display_name); - g_object_unref (account); + g_object_unref (account_manager); } static gboolean @@ -159,18 +157,22 @@ import_dialog_account_id_in_list (GList *accounts, for (l = accounts; l; l = l->next) { - McAccount *account = l->data; - gchar *value = NULL; + EmpathyAccount *account = l->data; + const gchar *account_string; + GValue *value; gboolean result; + const GHashTable *parameters; + + parameters = empathy_account_get_parameters (account); - mc_account_get_param_string (account, "account", &value); + value = g_hash_table_lookup ((GHashTable *) parameters, "account"); if (value == NULL) continue; - result = tp_strdiff (value, account_id); + account_string = g_value_get_string (value); - g_free (value); + result = tp_strdiff (account_string, account_id); if (!result) return TRUE; @@ -179,12 +181,39 @@ import_dialog_account_id_in_list (GList *accounts, return FALSE; } +static gboolean protocol_is_supported (EmpathyImportAccountData *data) +{ + EmpathyConnectionManagers *cm = + empathy_connection_managers_dup_singleton (); + GList *cms = empathy_connection_managers_get_cms (cm); + GList *l; + gboolean proto_is_supported = FALSE; + + for (l = cms; l; l = l->next) + { + TpConnectionManager *tp_cm = l->data; + const gchar *cm_name = tp_connection_manager_get_name (tp_cm); + if (tp_connection_manager_has_protocol (tp_cm, + (const gchar*)data->protocol)) + { + data->connection_manager = g_strdup (cm_name); + proto_is_supported = TRUE; + break; + } + } + + g_object_unref (cm); + + return proto_is_supported; +} + static void import_dialog_add_accounts_to_model (EmpathyImportDialog *dialog) { GtkTreeModel *model; GtkTreeIter iter; GList *l; + EmpathyAccountManager *manager = empathy_account_manager_dup_singleton (); model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); @@ -195,27 +224,33 @@ import_dialog_add_accounts_to_model (EmpathyImportDialog *dialog) gboolean import; GList *accounts; + if (!protocol_is_supported (data)) + continue; + value = g_hash_table_lookup (data->settings, "account"); - accounts = mc_accounts_list_by_profile (data->profile); + accounts = empathy_account_manager_dup_accounts (manager); /* Only set the "Import" cell to be active if there isn't already an * account set up with the same account id. */ import = !import_dialog_account_id_in_list (accounts, g_value_get_string (value)); - mc_accounts_list_free (accounts); + g_list_foreach (accounts, (GFunc) g_object_unref, NULL); + g_list_free (accounts); gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, COL_IMPORT, import, - COL_PROTOCOL, mc_profile_get_display_name (data->profile), + COL_PROTOCOL, data->protocol, COL_NAME, g_value_get_string (value), COL_SOURCE, data->source, COL_ACCOUNT_DATA, data, -1); } + + g_object_unref (manager); } static void diff --git a/src/empathy-import-dialog.h b/src/empathy-import-dialog.h index 0e3fd148f..bdd0de732 100644 --- a/src/empathy-import-dialog.h +++ b/src/empathy-import-dialog.h @@ -20,7 +20,6 @@ */ #include -#include #ifndef __EMPATHY_IMPORT_DIALOG_H__ #define __EMPATHY_IMPORT_DIALOG_H__ @@ -31,8 +30,10 @@ typedef struct { /* Table mapping CM param string to a GValue */ GHashTable *settings; - /* The profile to use for this account */ - McProfile *profile; + /* Protocol name */ + gchar *protocol; + /* Connection manager name */ + gchar *connection_manager; /* The name of the account import source */ gchar *source; } EmpathyImportAccountData; -- cgit v1.2.3 From 5e48d35061335282d7cf64e00dcf932dffcdfb54 Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Tue, 28 Jul 2009 14:49:53 +0200 Subject: Port empathy-import-pidgin to mc5 --- src/empathy-import-pidgin.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/empathy-import-pidgin.c b/src/empathy-import-pidgin.c index 935c022ea..5c8221ce7 100644 --- a/src/empathy-import-pidgin.c +++ b/src/empathy-import-pidgin.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -114,8 +115,7 @@ import_dialog_pidgin_parse_setting (EmpathyImportAccountData *data, /* Search for the map corresponding to setting we are parsing */ for (i = 0; i < G_N_ELEMENTS (pidgin_cm_map); i++) { - if (!tp_strdiff (mc_profile_get_protocol_name (data->profile), - pidgin_cm_map[i].protocol) && + if (!tp_strdiff (data->protocol, pidgin_cm_map[i].protocol) && !tp_strdiff (tag_name, pidgin_cm_map[i].pidgin_name)) { item = pidgin_cm_map + i; @@ -199,23 +199,26 @@ empathy_import_pidgin_load (void) if (!tp_strdiff ((gchar *) child->name, PIDGIN_ACCOUNT_TAG_PROTOCOL)) { - gchar *content; + xmlChar *content; const gchar *protocol; - protocol = content = (gchar *) xmlNodeGetContent (child); + content = xmlNodeGetContent (child); + + protocol = (const gchar *) content; if (g_str_has_prefix (protocol, "prpl-")) protocol += 5; - if (!tp_strdiff (protocol, PIDGIN_PROTOCOL_BONJOUR)) - protocol = "salut"; - else if (!tp_strdiff (protocol, PIDGIN_PROTOCOL_NOVELL)) - protocol = "groupwise"; + data->protocol = g_strdup (protocol); + + if (!tp_strdiff (data->protocol, PIDGIN_PROTOCOL_BONJOUR)) + data->protocol = "salut"; + else if (!tp_strdiff (data->protocol, PIDGIN_PROTOCOL_NOVELL)) + data->protocol = "groupwise"; - data->profile = mc_profile_lookup (protocol); - g_free (content); + xmlFree (content); - if (data->profile == NULL) + if (data->protocol == NULL) break; } @@ -240,8 +243,7 @@ empathy_import_pidgin_load (void) username = name; /* Split "username@server" if it is an IRC account */ - if (strstr (name, "@") && !tp_strdiff ( - mc_profile_get_protocol_name (data->profile), "irc")) + if (strstr (name, "@") && !tp_strdiff (data->protocol, "irc")) { nick_server = g_strsplit (name, "@", 2); username = nick_server[0]; @@ -287,12 +289,11 @@ empathy_import_pidgin_load (void) /* If we have the needed settings, add the account data to the list, * otherwise free the data */ - if (data->profile != NULL && g_hash_table_size (data->settings) > 0) + if (data->protocol != NULL && g_hash_table_size (data->settings) > 0) { /* Special-case XMPP: * http://bugzilla.gnome.org/show_bug.cgi?id=579992 */ - if (!tp_strdiff ( - mc_profile_get_protocol_name (data->profile), "jabber")) + if (!tp_strdiff (data->protocol, "jabber")) { if (EMP_STR_EMPTY (tp_asv_get_string (data->settings, "server"))) { -- cgit v1.2.3 From 6da962b47b8a9b6bba3aecf8fda82d1e58d547cf Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Tue, 28 Jul 2009 15:55:28 +0200 Subject: Add empathy-import-dialog and empathy-import-pidgin to the makefile --- src/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 01f47d2bb..d0b86edfc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,6 +39,8 @@ empathy_handwritten_source = \ empathy-chat-window.c empathy-chat-window.h \ empathy-event-manager.c empathy-event-manager.h \ empathy-ft-manager.c empathy-ft-manager.h \ + empathy-import-dialog.c empathy-import-dialog.h \ + empathy-import-pidgin.c empathy-import-pidgin.h \ empathy-main-window.c empathy-main-window.h \ empathy-misc.c empathy-misc.h \ empathy-new-chatroom-dialog.c empathy-new-chatroom-dialog.h \ -- cgit v1.2.3 From f51d76329d1f2994c450aa0c8bf3a37412512581 Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Tue, 28 Jul 2009 15:57:41 +0200 Subject: Instantiate mc5 pidgin account importer in empathy-accounts-dialog --- src/empathy-accounts-dialog.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 913239589..8b896676d 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -45,10 +45,7 @@ #include #include "empathy-accounts-dialog.h" -#if 0 -/* FIXME MC-5 */ #include "empathy-import-dialog.h" -#endif #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include @@ -117,11 +114,8 @@ enum { static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings); -#if 0 -/* FIXME MC-5 */ static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog); -#endif static void accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, @@ -1114,8 +1108,6 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button, gtk_widget_destroy (message_dialog); } -#if 0 -/* FIXME MC-5 */ static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) @@ -1124,7 +1116,6 @@ accounts_dialog_button_import_clicked_cb (GtkWidget *button, empathy_import_dialog_show (GTK_WINDOW (priv->window), TRUE); } -#endif static void accounts_dialog_response_cb (GtkWidget *widget, @@ -1214,10 +1205,7 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) "button_back", "clicked", accounts_dialog_button_back_clicked_cb, "button_add", "clicked", accounts_dialog_button_add_clicked_cb, "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb, -#if 0 - /* FIXME MC-5 */ "button_import", "clicked", accounts_dialog_button_import_clicked_cb, -#endif "button_help", "clicked", accounts_dialog_button_help_clicked_cb, NULL); @@ -1400,8 +1388,6 @@ do_constructed (GObject *object) EMPATHY_PREFS_IMPORT_ASKED, &import_asked); -#if 0 - /* FIXME MC-5 */ if (empathy_import_dialog_accounts_to_import ()) { @@ -1417,7 +1403,6 @@ do_constructed (GObject *object) { gtk_widget_set_sensitive (priv->button_import, FALSE); } -#endif } static void -- cgit v1.2.3 From 3245c197d95c326372323addde9f62ca96167a33 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 18:51:24 +0100 Subject: Fix a small memory leak --- src/empathy-import-pidgin.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/empathy-import-pidgin.c b/src/empathy-import-pidgin.c index 5c8221ce7..6a145ff93 100644 --- a/src/empathy-import-pidgin.c +++ b/src/empathy-import-pidgin.c @@ -209,12 +209,12 @@ empathy_import_pidgin_load (void) if (g_str_has_prefix (protocol, "prpl-")) protocol += 5; - data->protocol = g_strdup (protocol); - - if (!tp_strdiff (data->protocol, PIDGIN_PROTOCOL_BONJOUR)) - data->protocol = "salut"; - else if (!tp_strdiff (data->protocol, PIDGIN_PROTOCOL_NOVELL)) - data->protocol = "groupwise"; + if (!tp_strdiff (protocol, PIDGIN_PROTOCOL_BONJOUR)) + data->protocol = g_strdup ("salut"); + else if (!tp_strdiff (protocol, PIDGIN_PROTOCOL_NOVELL)) + data->protocol = g_strdup ("groupwise"); + else + data->protocol = g_strdup (protocol); xmlFree (content); -- cgit v1.2.3 From 74209eb1b8b0cf9df87e66e2e028cae885b39a5f Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 16:54:23 +0200 Subject: Port empathy.c to telepathy-style --- src/empathy.c | 1072 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 546 insertions(+), 526 deletions(-) diff --git a/src/empathy.c b/src/empathy.c index 718fe70bf..b80b64be7 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -1,6 +1,5 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2007-2008 Collabora Ltd. + * Copyright (C) 2007-2009 Collabora Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -82,402 +81,424 @@ static void dispatch_cb (EmpathyDispatcher *dispatcher, - EmpathyDispatchOperation *operation, - gpointer user_data) + EmpathyDispatchOperation *operation, + gpointer user_data) { - GQuark channel_type; - - channel_type = empathy_dispatch_operation_get_channel_type_id (operation); - - if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) { - EmpathyTpChat *tp_chat; - EmpathyChat *chat = NULL; - const gchar *id; - - tp_chat = EMPATHY_TP_CHAT ( - empathy_dispatch_operation_get_channel_wrapper (operation)); - - id = empathy_tp_chat_get_id (tp_chat); - if (!id) { - EmpathyContact *contact; - - contact = empathy_tp_chat_get_remote_contact (tp_chat); - if (contact) { - id = empathy_contact_get_id (contact); - } - } - - if (id) { - EmpathyAccountManager *manager; - TpConnection *connection; - EmpathyAccount *account; - - manager = empathy_account_manager_dup_singleton (); - connection = empathy_tp_chat_get_connection (tp_chat); - account = empathy_account_manager_get_account_for_connection (manager, - connection); - chat = empathy_chat_window_find_chat (account, id); - g_object_unref (manager); - } - - if (chat) { - empathy_chat_set_tp_chat (chat, tp_chat); - } else { - chat = empathy_chat_new (tp_chat); - } - - empathy_chat_window_present_chat (chat); - - empathy_dispatch_operation_claim (operation); - } else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA) { - EmpathyCallFactory *factory; - - factory = empathy_call_factory_get (); - empathy_call_factory_claim_channel (factory, operation); - } else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) { - EmpathyFTFactory *factory; - - factory = empathy_ft_factory_dup_singleton (); - - /* if the operation is not incoming, don't claim it, - * as it might have been triggered by another client, and - * we are observing it. - */ - if (empathy_dispatch_operation_is_incoming (operation)) { - empathy_ft_factory_claim_channel (factory, operation); - } - } + GQuark channel_type; + + channel_type = empathy_dispatch_operation_get_channel_type_id (operation); + + if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) + { + EmpathyTpChat *tp_chat; + EmpathyChat *chat = NULL; + const gchar *id; + + tp_chat = EMPATHY_TP_CHAT + (empathy_dispatch_operation_get_channel_wrapper (operation)); + + id = empathy_tp_chat_get_id (tp_chat); + if (!id) + { + EmpathyContact *contact; + + contact = empathy_tp_chat_get_remote_contact (tp_chat); + if (contact) + id = empathy_contact_get_id (contact); + } + + if (id) + { + EmpathyAccountManager *manager; + TpConnection *connection; + EmpathyAccount *account; + + manager = empathy_account_manager_dup_singleton (); + connection = empathy_tp_chat_get_connection (tp_chat); + account = empathy_account_manager_get_account_for_connection (manager, + connection); + chat = empathy_chat_window_find_chat (account, id); + g_object_unref (manager); + } + + if (chat) + empathy_chat_set_tp_chat (chat, tp_chat); + else + chat = empathy_chat_new (tp_chat); + + empathy_chat_window_present_chat (chat); + + empathy_dispatch_operation_claim (operation); + } + else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA) + { + EmpathyCallFactory *factory; + + factory = empathy_call_factory_get (); + empathy_call_factory_claim_channel (factory, operation); + } + else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) + { + EmpathyFTFactory *factory; + + factory = empathy_ft_factory_dup_singleton (); + + /* if the operation is not incoming, don't claim it, + * as it might have been triggered by another client, and + * we are observing it. + */ + if (empathy_dispatch_operation_is_incoming (operation)) + empathy_ft_factory_claim_channel (factory, operation); + } } /* Salut account creation */ static gboolean should_create_salut_account (void) { - EmpathyAccountManager *manager; - gboolean salut_created = FALSE; - GList *accounts, *l; + EmpathyAccountManager *manager; + gboolean salut_created = FALSE; + GList *accounts, *l; - /* Check if we already created a salut account */ - empathy_conf_get_bool (empathy_conf_get (), - EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, - &salut_created); + /* Check if we already created a salut account */ + empathy_conf_get_bool (empathy_conf_get (), + EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, + &salut_created); - if (salut_created) - { - DEBUG ("Gconf says we already created a salut account once"); - return FALSE; - } + if (salut_created) + { + DEBUG ("Gconf says we already created a salut account once"); + return FALSE; + } - manager = empathy_account_manager_dup_singleton (); - accounts = empathy_account_manager_dup_accounts (manager); + manager = empathy_account_manager_dup_singleton (); + accounts = empathy_account_manager_dup_accounts (manager); - for (l = accounts; l != NULL; l = g_list_next (l)) { - EmpathyAccount *account = EMPATHY_ACCOUNT (l->data); + for (l = accounts; l != NULL; l = g_list_next (l)) + { + EmpathyAccount *account = EMPATHY_ACCOUNT (l->data); - if (!tp_strdiff (empathy_account_get_protocol (account), "local-xmpp")) - salut_created = TRUE; + if (!tp_strdiff (empathy_account_get_protocol (account), "local-xmpp")) + salut_created = TRUE; - g_object_unref (account); - } + g_object_unref (account); + } - g_object_unref (manager); + g_object_unref (manager); - if (salut_created) - { - DEBUG ("Existing salut account already exists, flagging so in gconf"); - empathy_conf_set_bool (empathy_conf_get (), - EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, - TRUE); - } + if (salut_created) + { + DEBUG ("Existing salut account already exists, flagging so in gconf"); + empathy_conf_set_bool (empathy_conf_get (), + EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, + TRUE); + } - return !salut_created; + return !salut_created; } static void salut_account_created (GObject *source, - GAsyncResult *result, gpointer user_data) + GAsyncResult *result, + gpointer user_data) { - EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source); - EmpathyAccount *account; - GError *error = NULL; - - if (!empathy_account_settings_apply_finish (settings, result, &error)) - { - DEBUG ("Failed to create salut account: %s", error->message); - g_error_free (error); - return; - } - - account = empathy_account_settings_get_account (settings); - - empathy_account_set_enabled (account, TRUE); - empathy_conf_set_bool (empathy_conf_get (), - EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, - TRUE); + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source); + EmpathyAccount *account; + GError *error = NULL; + + if (!empathy_account_settings_apply_finish (settings, result, &error)) + { + DEBUG ("Failed to create salut account: %s", error->message); + g_error_free (error); + return; + } + + account = empathy_account_settings_get_account (settings); + + empathy_account_set_enabled (account, TRUE); + empathy_conf_set_bool (empathy_conf_get (), + EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, + TRUE); } static void use_conn_notify_cb (EmpathyConf *conf, - const gchar *key, - gpointer user_data) + const gchar *key, + gpointer user_data) { - EmpathyConnectivity *connectivity = user_data; - gboolean use_conn; + EmpathyConnectivity *connectivity = user_data; + gboolean use_conn; - if (empathy_conf_get_bool (conf, key, &use_conn)) { - empathy_connectivity_set_use_conn (connectivity, use_conn); - } + if (empathy_conf_get_bool (conf, key, &use_conn)) + { + empathy_connectivity_set_use_conn (connectivity, use_conn); + } } static void create_salut_account_if_needed (EmpathyConnectionManagers *managers) { - EmpathyAccountSettings *settings; - TpConnectionManager *manager; - const TpConnectionManagerProtocol *protocol; - EBook *book; - EContact *contact; - gchar *nickname = NULL; - gchar *first_name = NULL; - gchar *last_name = NULL; - gchar *email = NULL; - gchar *jid = NULL; - GError *error = NULL; - - - if (!should_create_salut_account ()) - return; - - manager = empathy_connection_managers_get_cm (managers, "salut"); - if (manager == NULL) - { - DEBUG ("Salut not installed, not making a salut account"); - return; - } - - protocol = tp_connection_manager_get_protocol (manager, "local-xmpp"); - if (protocol == NULL) - { - DEBUG ("Salut doesn't support local-xmpp!!"); - return; - } - - DEBUG ("Trying to add a salut account..."); - - /* Get self EContact from EDS */ - if (!e_book_get_self (&contact, &book, &error)) { - DEBUG ("Failed to get self econtact: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - return; - } - - settings = empathy_account_settings_new ("salut", "local-xmpp", - _("People nearby")); - - nickname = e_contact_get (contact, E_CONTACT_NICKNAME); - first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME); - last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME); - email = e_contact_get (contact, E_CONTACT_EMAIL_1); - jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1); - - if (!tp_strdiff (nickname, "nickname")) { - g_free (nickname); - nickname = NULL; - } - - DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n" - "last-name=%s\nemail=%s\njid=%s\n", - nickname, first_name, last_name, email, jid); - - empathy_account_settings_set_string (settings, "nickname", nickname ? nickname : ""); - empathy_account_settings_set_string (settings, "first-name", first_name ? first_name : ""); - empathy_account_settings_set_string (settings, "last-name", last_name ? last_name : ""); - empathy_account_settings_set_string (settings, "email", email ? email : ""); - empathy_account_settings_set_string (settings, "jid", jid ? jid : ""); - - empathy_account_settings_apply_async (settings, - salut_account_created, NULL); - - g_free (nickname); - g_free (first_name); - g_free (last_name); - g_free (email); - g_free (jid); - g_object_unref (settings); - g_object_unref (contact); - g_object_unref (book); + EmpathyAccountSettings *settings; + TpConnectionManager *manager; + const TpConnectionManagerProtocol *protocol; + EBook *book; + EContact *contact; + gchar *nickname = NULL; + gchar *first_name = NULL; + gchar *last_name = NULL; + gchar *email = NULL; + gchar *jid = NULL; + GError *error = NULL; + + + if (!should_create_salut_account ()) + return; + + manager = empathy_connection_managers_get_cm (managers, "salut"); + if (manager == NULL) + { + DEBUG ("Salut not installed, not making a salut account"); + return; + } + + protocol = tp_connection_manager_get_protocol (manager, "local-xmpp"); + if (protocol == NULL) + { + DEBUG ("Salut doesn't support local-xmpp!!"); + return; + } + + DEBUG ("Trying to add a salut account..."); + + /* Get self EContact from EDS */ + if (!e_book_get_self (&contact, &book, &error)) + { + DEBUG ("Failed to get self econtact: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + return; + } + + settings = empathy_account_settings_new ("salut", "local-xmpp", + _("People nearby")); + + nickname = e_contact_get (contact, E_CONTACT_NICKNAME); + first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME); + last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME); + email = e_contact_get (contact, E_CONTACT_EMAIL_1); + jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1); + + if (!tp_strdiff (nickname, "nickname")) + { + g_free (nickname); + nickname = NULL; + } + + DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n" + "last-name=%s\nemail=%s\njid=%s\n", + nickname, first_name, last_name, email, jid); + + empathy_account_settings_set_string (settings, + "nickname", nickname ? nickname : ""); + empathy_account_settings_set_string (settings, + "first-name", first_name ? first_name : ""); + empathy_account_settings_set_string (settings, + "last-name", last_name ? last_name : ""); + empathy_account_settings_set_string (settings, "email", email ? email : ""); + empathy_account_settings_set_string (settings, "jid", jid ? jid : ""); + + empathy_account_settings_apply_async (settings, + salut_account_created, NULL); + + g_free (nickname); + g_free (first_name); + g_free (last_name); + g_free (email); + g_free (jid); + g_object_unref (settings); + g_object_unref (contact); + g_object_unref (book); } static void connection_managers_ready_cb (EmpathyConnectionManagers *managers, - GParamSpec *spec, gpointer user_data) + GParamSpec *spec, + gpointer user_data) { - if (empathy_connection_managers_is_ready (managers)) - { - create_salut_account_if_needed (managers); - g_object_unref (managers); - managers = NULL; - } + if (empathy_connection_managers_is_ready (managers)) + { + create_salut_account_if_needed (managers); + g_object_unref (managers); + managers = NULL; + } } static void create_salut_account (void) { - EmpathyConnectionManagers *managers; - - if (!should_create_salut_account ()) - return; - - managers = empathy_connection_managers_dup_singleton (); - - if (empathy_connection_managers_is_ready (managers)) - { - create_salut_account_if_needed (managers); - g_object_unref (managers); - } - else - { - g_signal_connect (managers, "notify::ready", - G_CALLBACK (connection_managers_ready_cb), NULL); - } + EmpathyConnectionManagers *managers; + + if (!should_create_salut_account ()) + return; + + managers = empathy_connection_managers_dup_singleton (); + + if (empathy_connection_managers_is_ready (managers)) + { + create_salut_account_if_needed (managers); + g_object_unref (managers); + } + else + { + g_signal_connect (managers, "notify::ready", + G_CALLBACK (connection_managers_ready_cb), NULL); + } } static void migrate_config_to_xdg_dir (void) { - gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename; - int i; - GFile *xdg_file, *old_file; - static const gchar* filenames[] = { - "geometry.ini", - "irc-networks.xml", - "chatrooms.xml", - "contact-groups.xml", - "status-presets.xml", - "accels.txt", - NULL - }; - - xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL); - if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { - /* xdg config dir already exists */ - g_free (xdg_dir); - return; - } - - old_dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); - if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { - /* old config dir didn't exist */ - g_free (xdg_dir); - g_free (old_dir); - return; - } - - if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1) { - DEBUG ("Failed to create configuration directory; aborting migration"); - g_free (xdg_dir); - g_free (old_dir); - return; - } - - for (i = 0; filenames[i]; i++) { - old_filename = g_build_filename (old_dir, filenames[i], NULL); - if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) { - g_free (old_filename); - continue; - } - xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL); - old_file = g_file_new_for_path (old_filename); - xdg_file = g_file_new_for_path (xdg_filename); - if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE, - NULL, NULL, NULL, NULL)) { - DEBUG ("Failed to migrate %s", filenames[i]); - } - g_free (old_filename); - g_free (xdg_filename); - g_object_unref (old_file); - g_object_unref (xdg_file); - } - - g_free (xdg_dir); - g_free (old_dir); + gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename; + int i; + GFile *xdg_file, *old_file; + static const gchar* filenames[] = { + "geometry.ini", + "irc-networks.xml", + "chatrooms.xml", + "contact-groups.xml", + "status-presets.xml", + "accels.txt", + NULL + }; + + xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL); + if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) + { + /* xdg config dir already exists */ + g_free (xdg_dir); + return; + } + + old_dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) + { + /* old config dir didn't exist */ + g_free (xdg_dir); + g_free (old_dir); + return; + } + + if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1) + { + DEBUG ("Failed to create configuration directory; aborting migration"); + g_free (xdg_dir); + g_free (old_dir); + return; + } + + for (i = 0; filenames[i]; i++) + { + old_filename = g_build_filename (old_dir, filenames[i], NULL); + if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) + { + g_free (old_filename); + continue; + } + xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL); + old_file = g_file_new_for_path (old_filename); + xdg_file = g_file_new_for_path (xdg_filename); + + if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE, + NULL, NULL, NULL, NULL)) + DEBUG ("Failed to migrate %s", filenames[i]); + + g_free (old_filename); + g_free (xdg_filename); + g_object_unref (old_file); + g_object_unref (xdg_file); + } + + g_free (xdg_dir); + g_free (old_dir); } static UniqueResponse unique_app_message_cb (UniqueApp *unique_app, - gint command, - UniqueMessageData *data, - guint timestamp, - gpointer user_data) + gint command, + UniqueMessageData *data, + guint timestamp, + gpointer user_data) { - GtkWidget *window = user_data; - - DEBUG ("Other instance launched, presenting the main window. " - "Command=%d, timestamp %u", command, timestamp); - - if (command == COMMAND_ACCOUNTS_DIALOG) { - empathy_accounts_dialog_show (GTK_WINDOW (window), NULL); - } else { - gtk_window_set_screen (GTK_WINDOW (window), - unique_message_data_get_screen (data)); - gtk_window_set_startup_id (GTK_WINDOW (window), - unique_message_data_get_startup_id (data)); - gtk_window_present_with_time (GTK_WINDOW (window), timestamp); - } - - return UNIQUE_RESPONSE_OK; + GtkWidget *window = user_data; + + DEBUG ("Other instance launched, presenting the main window. " + "Command=%d, timestamp %u", command, timestamp); + + if (command == COMMAND_ACCOUNTS_DIALOG) + { + empathy_accounts_dialog_show (GTK_WINDOW (window), NULL); + } + else + { + gtk_window_set_screen (GTK_WINDOW (window), + unique_message_data_get_screen (data)); + gtk_window_set_startup_id (GTK_WINDOW (window), + unique_message_data_get_startup_id (data)); + gtk_window_present_with_time (GTK_WINDOW (window), timestamp); + } + + return UNIQUE_RESPONSE_OK; } static gboolean show_version_cb (const char *option_name, - const char *value, - gpointer data, - GError **error) + const char *value, + gpointer data, + GError **error) { - g_print ("%s\n", PACKAGE_STRING); + g_print ("%s\n", PACKAGE_STRING); - exit (EXIT_SUCCESS); + exit (EXIT_SUCCESS); - return FALSE; + return FALSE; } static void new_incoming_transfer_cb (EmpathyFTFactory *factory, - EmpathyFTHandler *handler, - GError *error, - gpointer user_data) + EmpathyFTHandler *handler, + GError *error, + gpointer user_data) { - if (error) { - empathy_ft_manager_display_error (handler, error); - } else { - empathy_receive_file_with_file_chooser (handler); - } + if (error) + empathy_ft_manager_display_error (handler, error); + else + empathy_receive_file_with_file_chooser (handler); } static void new_ft_handler_cb (EmpathyFTFactory *factory, - EmpathyFTHandler *handler, - GError *error, - gpointer user_data) + EmpathyFTHandler *handler, + GError *error, + gpointer user_data) { - if (error) { - empathy_ft_manager_display_error (handler, error); - } else { - empathy_ft_manager_add_handler (handler); - } + if (error) + empathy_ft_manager_display_error (handler, error); + else + empathy_ft_manager_add_handler (handler); - g_object_unref (handler); + g_object_unref (handler); } static void -new_call_handler_cb (EmpathyCallFactory *factory, EmpathyCallHandler *handler, - gboolean outgoing, gpointer user_data) +new_call_handler_cb (EmpathyCallFactory *factory, + EmpathyCallHandler *handler, + gboolean outgoing, + gpointer user_data) { - EmpathyCallWindow *window; + EmpathyCallWindow *window; - window = empathy_call_window_new (handler); - gtk_widget_show (GTK_WIDGET (window)); + window = empathy_call_window_new (handler); + gtk_widget_show (GTK_WIDGET (window)); } #ifdef ENABLE_DEBUG @@ -487,237 +508,236 @@ default_log_handler (const gchar *log_domain, const gchar *message, gpointer user_data) { - g_log_default_handler (log_domain, log_level, message, NULL); - - /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the - * debugger as they already have in empathy_debug. */ - if (log_level != G_LOG_LEVEL_DEBUG - || tp_strdiff (log_domain, G_LOG_DOMAIN)) { - EmpathyDebugger *dbg; - GTimeVal now; - - dbg = empathy_debugger_get_singleton (); - g_get_current_time (&now); - - empathy_debugger_add_message (dbg, &now, log_domain, - log_level, message); - } + g_log_default_handler (log_domain, log_level, message, NULL); + + /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the + * debugger as they already have in empathy_debug. */ + if (log_level != G_LOG_LEVEL_DEBUG + || tp_strdiff (log_domain, G_LOG_DOMAIN)) + { + EmpathyDebugger *dbg; + GTimeVal now; + + dbg = empathy_debugger_get_singleton (); + g_get_current_time (&now); + + empathy_debugger_add_message (dbg, &now, log_domain, + log_level, message); + } } #endif /* ENABLE_DEBUG */ static void account_manager_ready_cb (EmpathyAccountManager *manager, - GParamSpec *spec, - gpointer user_data) + GParamSpec *spec, + gpointer user_data) { - if (!empathy_account_manager_is_ready (manager)) - return; - - if (empathy_account_manager_get_count (manager) == 0) - { - empathy_accounts_dialog_show (GTK_WINDOW (empathy_main_window_get ()), - NULL); - } - create_salut_account (); + if (!empathy_account_manager_is_ready (manager)) + return; + + if (empathy_account_manager_get_count (manager) == 0) + empathy_accounts_dialog_show (GTK_WINDOW (empathy_main_window_get ()), + NULL); + + create_salut_account (); } int main (int argc, char *argv[]) { #if HAVE_GEOCLUE - EmpathyLocationManager *location_manager = NULL; + EmpathyLocationManager *location_manager = NULL; #endif - EmpathyStatusIcon *icon; - EmpathyDispatcher *dispatcher; - EmpathyAccountManager *account_manager; - EmpathyLogManager *log_manager; - EmpathyChatroomManager *chatroom_manager; - EmpathyCallFactory *call_factory; - EmpathyFTFactory *ft_factory; - GtkWidget *window; - EmpathyIdle *idle; - EmpathyConnectivity *connectivity; - gboolean autoconnect = TRUE; - gboolean no_connect = FALSE; - gboolean hide_contact_list = FALSE; - gboolean accounts_dialog = FALSE; - GError *error = NULL; - TpDBusDaemon *dbus_daemon; - UniqueApp *unique_app; - GOptionEntry options[] = { - { "no-connect", 'n', - 0, G_OPTION_ARG_NONE, &no_connect, - N_("Don't connect on startup"), - NULL }, - { "hide-contact-list", 'h', - 0, G_OPTION_ARG_NONE, &hide_contact_list, - N_("Don't show the contact list on startup"), - NULL }, - { "accounts", 'a', - 0, G_OPTION_ARG_NONE, &accounts_dialog, - N_("Show the accounts dialog"), - NULL }, - { "version", 'v', - G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb, NULL, NULL }, - { NULL } - }; - - /* Init */ - g_thread_init (NULL); - empathy_init (); - - if (!gtk_init_with_args (&argc, &argv, - N_("- Empathy IM Client"), - options, GETTEXT_PACKAGE, &error)) { - g_warning ("Error in empathy init: %s", error->message); - return EXIT_FAILURE; - } - - empathy_gtk_init (); - g_set_application_name (_(PACKAGE_NAME)); - g_setenv ("PULSE_PROP_media.role", "phone", TRUE); - - gst_init (&argc, &argv); + EmpathyStatusIcon *icon; + EmpathyDispatcher *dispatcher; + EmpathyAccountManager *account_manager; + EmpathyLogManager *log_manager; + EmpathyChatroomManager *chatroom_manager; + EmpathyCallFactory *call_factory; + EmpathyFTFactory *ft_factory; + GtkWidget *window; + EmpathyIdle *idle; + EmpathyConnectivity *connectivity; + gboolean autoconnect = TRUE; + gboolean no_connect = FALSE; + gboolean hide_contact_list = FALSE; + gboolean accounts_dialog = FALSE; + GError *error = NULL; + TpDBusDaemon *dbus_daemon; + UniqueApp *unique_app; + + GOptionEntry options[] = { + { "no-connect", 'n', + 0, G_OPTION_ARG_NONE, &no_connect, + N_("Don't connect on startup"), + NULL }, + { "hide-contact-list", 'h', + 0, G_OPTION_ARG_NONE, &hide_contact_list, + N_("Don't show the contact list on startup"), + NULL }, + { "accounts", 'a', + 0, G_OPTION_ARG_NONE, &accounts_dialog, + N_("Show the accounts dialog"), + NULL }, + { "version", 'v', + G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb, + NULL, NULL }, + { NULL } + }; + + /* Init */ + g_thread_init (NULL); + empathy_init (); + + if (!gtk_init_with_args (&argc, &argv, N_("- Empathy IM Client"), + options, GETTEXT_PACKAGE, &error)) + { + g_warning ("Error in empathy init: %s", error->message); + return EXIT_FAILURE; + } + + empathy_gtk_init (); + g_set_application_name (_(PACKAGE_NAME)); + g_setenv ("PULSE_PROP_media.role", "phone", TRUE); + + gst_init (&argc, &argv); #if HAVE_LIBCHAMPLAIN - gtk_clutter_init (&argc, &argv); + gtk_clutter_init (&argc, &argv); #endif - gtk_window_set_default_icon_name ("empathy"); - textdomain (GETTEXT_PACKAGE); + gtk_window_set_default_icon_name ("empathy"); + textdomain (GETTEXT_PACKAGE); #ifdef ENABLE_DEBUG - /* Set up debugger */ - g_log_set_default_handler (default_log_handler, NULL); + /* Set up debugger */ + g_log_set_default_handler (default_log_handler, NULL); #endif - unique_app = unique_app_new_with_commands ("org.gnome.Empathy", - NULL, - "accounts_dialog", - COMMAND_ACCOUNTS_DIALOG, - NULL); - - if (unique_app_is_running (unique_app)) { - unique_app_send_message (unique_app, - accounts_dialog ? - COMMAND_ACCOUNTS_DIALOG : - UNIQUE_ACTIVATE, - NULL); - g_object_unref (unique_app); - return EXIT_SUCCESS; - } - - /* Take well-known name */ - dbus_daemon = tp_dbus_daemon_dup (&error); - if (error == NULL) { - if (!tp_dbus_daemon_request_name (dbus_daemon, - "org.gnome.Empathy", - TRUE, &error)) { - DEBUG ("Failed to request well-known name: %s", - error ? error->message : "no message"); - g_clear_error (&error); - } - g_object_unref (dbus_daemon); - } else { - DEBUG ("Failed to dup dbus daemon: %s", - error ? error->message : "no message"); - g_clear_error (&error); - } - - if (accounts_dialog) { - GtkWidget *dialog; - - dialog = empathy_accounts_dialog_show (NULL, NULL); - g_signal_connect (dialog, "destroy", - G_CALLBACK (gtk_main_quit), - NULL); - - gtk_main (); - return 0; - } - - /* Setting up Idle */ - idle = empathy_idle_dup_singleton (); - empathy_idle_set_auto_away (idle, TRUE); - - /* Setting up Connectivity */ - connectivity = empathy_connectivity_dup_singleton (); - use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN, - connectivity); - empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN, - use_conn_notify_cb, connectivity); - - /* Autoconnect */ - empathy_conf_get_bool (empathy_conf_get (), - EMPATHY_PREFS_AUTOCONNECT, - &autoconnect); - if (autoconnect && ! no_connect && - tp_connection_presence_type_cmp_availability (empathy_idle_get_state - (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0) { - empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE); - } - - /* account management */ - account_manager = empathy_account_manager_dup_singleton (); - g_signal_connect (account_manager, "notify::ready", - G_CALLBACK (account_manager_ready_cb), NULL); - - migrate_config_to_xdg_dir (); - - /* Setting up UI */ - window = empathy_main_window_show (); - icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list); - - g_signal_connect (unique_app, "message-received", - G_CALLBACK (unique_app_message_cb), - window); - - /* Handle channels */ - dispatcher = empathy_dispatcher_dup_singleton (); - g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL); - - /* Logging */ - log_manager = empathy_log_manager_dup_singleton (); - empathy_log_manager_observe (log_manager, dispatcher); - - chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL); - empathy_chatroom_manager_observe (chatroom_manager, dispatcher); - - notify_init (_(PACKAGE_NAME)); - /* Create the call factory */ - call_factory = empathy_call_factory_initialise (); - g_signal_connect (G_OBJECT (call_factory), "new-call-handler", - G_CALLBACK (new_call_handler_cb), NULL); - /* Create the FT factory */ - ft_factory = empathy_ft_factory_dup_singleton (); - g_signal_connect (ft_factory, "new-ft-handler", - G_CALLBACK (new_ft_handler_cb), NULL); - g_signal_connect (ft_factory, "new-incoming-transfer", - G_CALLBACK (new_incoming_transfer_cb), NULL); - - /* Location mananger */ + unique_app = unique_app_new_with_commands ("org.gnome.Empathy", + NULL, "accounts_dialog", COMMAND_ACCOUNTS_DIALOG, NULL); + + if (unique_app_is_running (unique_app)) + { + unique_app_send_message (unique_app, accounts_dialog ? + COMMAND_ACCOUNTS_DIALOG : UNIQUE_ACTIVATE, NULL); + + g_object_unref (unique_app); + return EXIT_SUCCESS; + } + + /* Take well-known name */ + dbus_daemon = tp_dbus_daemon_dup (&error); + if (error == NULL) + { + if (!tp_dbus_daemon_request_name (dbus_daemon, + "org.gnome.Empathy", TRUE, &error)) + { + DEBUG ("Failed to request well-known name: %s", + error ? error->message : "no message"); + g_clear_error (&error); + } + g_object_unref (dbus_daemon); + } + else + { + DEBUG ("Failed to dup dbus daemon: %s", + error ? error->message : "no message"); + g_clear_error (&error); + } + + if (accounts_dialog) + { + GtkWidget *dialog; + + dialog = empathy_accounts_dialog_show (NULL, NULL); + g_signal_connect (dialog, "destroy", + G_CALLBACK (gtk_main_quit), NULL); + + gtk_main (); + return 0; + } + + /* Setting up Idle */ + idle = empathy_idle_dup_singleton (); + empathy_idle_set_auto_away (idle, TRUE); + + /* Setting up Connectivity */ + connectivity = empathy_connectivity_dup_singleton (); + use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN, + connectivity); + empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN, + use_conn_notify_cb, connectivity); + + /* Autoconnect */ + empathy_conf_get_bool (empathy_conf_get (), + EMPATHY_PREFS_AUTOCONNECT, &autoconnect); + if (autoconnect && !no_connect && + tp_connection_presence_type_cmp_availability + (empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE) + <= 0) + empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE); + + /* account management */ + account_manager = empathy_account_manager_dup_singleton (); + g_signal_connect (account_manager, "notify::ready", + G_CALLBACK (account_manager_ready_cb), NULL); + + migrate_config_to_xdg_dir (); + + /* Setting up UI */ + window = empathy_main_window_show (); + icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list); + + g_signal_connect (unique_app, "message-received", + G_CALLBACK (unique_app_message_cb), window); + + /* Handle channels */ + dispatcher = empathy_dispatcher_dup_singleton (); + g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL); + + /* Logging */ + log_manager = empathy_log_manager_dup_singleton (); + empathy_log_manager_observe (log_manager, dispatcher); + + chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL); + empathy_chatroom_manager_observe (chatroom_manager, dispatcher); + + notify_init (_(PACKAGE_NAME)); + /* Create the call factory */ + call_factory = empathy_call_factory_initialise (); + g_signal_connect (G_OBJECT (call_factory), "new-call-handler", + G_CALLBACK (new_call_handler_cb), NULL); + /* Create the FT factory */ + ft_factory = empathy_ft_factory_dup_singleton (); + g_signal_connect (ft_factory, "new-ft-handler", + G_CALLBACK (new_ft_handler_cb), NULL); + g_signal_connect (ft_factory, "new-incoming-transfer", + G_CALLBACK (new_incoming_transfer_cb), NULL); + + /* Location mananger */ #if HAVE_GEOCLUE - location_manager = empathy_location_manager_dup_singleton (); + location_manager = empathy_location_manager_dup_singleton (); #endif - gtk_main (); + gtk_main (); - empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE); + empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE); - g_object_unref (idle); - g_object_unref (connectivity); - g_object_unref (icon); - g_object_unref (account_manager); - g_object_unref (log_manager); - g_object_unref (dispatcher); - g_object_unref (chatroom_manager); + g_object_unref (idle); + g_object_unref (connectivity); + g_object_unref (icon); + g_object_unref (account_manager); + g_object_unref (log_manager); + g_object_unref (dispatcher); + g_object_unref (chatroom_manager); #if HAVE_GEOCLUE - g_object_unref (location_manager); + g_object_unref (location_manager); #endif - g_object_unref (ft_factory); - g_object_unref (unique_app); + g_object_unref (ft_factory); + g_object_unref (unique_app); - notify_uninit (); + notify_uninit (); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } -- cgit v1.2.3 From 8bccbdc3d107c019ef858d0ad15c769c31028731 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 17:00:30 +0200 Subject: Skeleton of EmpathyAccountAssistant --- src/empathy-account-assistant.c | 43 ++++++++++++++++++++++++++++++ src/empathy-account-assistant.h | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 src/empathy-account-assistant.c create mode 100644 src/empathy-account-assistant.h diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c new file mode 100644 index 000000000..d264df367 --- /dev/null +++ b/src/empathy-account-assistant.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Cosimo Cecchi + */ + +/* empathy-account-assistant.c */ + +#include "empathy-account-assistant.h" + +G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant, + GTK_TYPE_ASSISTANT) + + +static void +empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) +{ +} + +static void +empathy_account_assistant_init (EmpathyAccountAssistant *self) +{ +} + +EmpathyAccountAssistant* +empathy_account_assistant_new (void) +{ + return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, NULL); +} diff --git a/src/empathy-account-assistant.h b/src/empathy-account-assistant.h new file mode 100644 index 000000000..03e99e265 --- /dev/null +++ b/src/empathy-account-assistant.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Cosimo Cecchi + */ + +/* empathy-account-assistant.h */ + +#ifndef __EMPATHY_ACCOUNT_ASSISTANT_H__ +#define __EMPATHY_ACCOUNT_ASSISTANT_H__ + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_ACCOUNT_ASSISTANT empathy_account_assistant_get_type() +#define EMPATHY_ACCOUNT_ASSISTANT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistant)) +#define EMPATHY_ACCOUNT_ASSISTANT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) +#define EMPATHY_IS_ACCOUNT_ASSISTANT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) +#define EMPATHY_IS_ACCOUNT_ASSISTANT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) +#define EMPATHY_ACCOUNT_ASSISTANT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) + +typedef struct { + GtkAssistant parent; + + /* private */ + gpointer priv; +} EmpathyAccountAssistant; + +typedef struct { + GtkAssistantClass parent_class; +} EmpathyAccountAssistantClass; + +GType empathy_account_assistant_get_type (void); + +EmpathyAccountAssistant* empathy_account_assistant_new (void); + +G_END_DECLS + +#endif /* __EMPATHY_ACCOUNT_ASSISTANT_H__ */ -- cgit v1.2.3 From 1b1ba53e2b64a4e5b3f9e27a54b3b863f5be0d4a Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 17:33:21 +0200 Subject: Add a test for the assistant --- tests/Makefile.am | 2 ++ tests/test-empathy-account-assistant.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/test-empathy-account-assistant.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 7f99eaf36..eb5dba529 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,6 +25,7 @@ LDADD = \ noinst_PROGRAMS = \ contact-manager \ empetit \ + test-empathy-account-assistant \ test-empathy-presence-chooser \ test-empathy-status-preset-dialog \ test-empathy-protocol-chooser @@ -34,6 +35,7 @@ empetit_SOURCES = empetit.c test_empathy_presence_chooser_SOURCES = test-empathy-presence-chooser.c test_empathy_status_preset_dialog_SOURCES = test-empathy-status-preset-dialog.c test_empathy_protocol_chooser_SOURCES = test-empathy-protocol-chooser.c +test_empathy_account_assistant_SOURCES = test-empathy-account-assistant.c check_PROGRAMS = check-main TESTS = check-main diff --git a/tests/test-empathy-account-assistant.c b/tests/test-empathy-account-assistant.c new file mode 100644 index 000000000..bdcbe6c69 --- /dev/null +++ b/tests/test-empathy-account-assistant.c @@ -0,0 +1,25 @@ +#include + +#include + +#include +#include + +int main (int argc, char *argv) +{ + GtkWidget *assistant; + + gtk_init (&argc, &argv); + empathy_gtk_init (); + + assistant = empathy_account_assistant_new (); + + gtk_widget_show_all (assistant); + + g_signal_connect_swapped (assistant, "destroy", + G_CALLBACK (gtk_main_quit), NULL); + + gtk_main (); + + return 0; +} -- cgit v1.2.3 From a1382ef236e65efb2443268d3ed406229e747381 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 17:33:32 +0200 Subject: Add a first page to the assistant --- src/Makefile.am | 1 + src/empathy-account-assistant.c | 32 ++++++++++++++++++++++++++++++++ src/empathy-account-assistant.h | 1 + 3 files changed, 34 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index d0b86edfc..9ac6b9bb3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,7 @@ BUILT_SOURCES= \ empathy_handwritten_source = \ empathy.c \ empathy-about-dialog.c empathy-about-dialog.h \ + empathy-account-assistant.c empathy-account-assistant.h \ empathy-accounts-dialog.c empathy-accounts-dialog.h \ empathy-call-window.c empathy-call-window.h \ empathy-call-window-fullscreen.c empathy-call-window-fullscreen.h \ diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index d264df367..461949892 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -20,20 +20,52 @@ /* empathy-account-assistant.c */ +#include + #include "empathy-account-assistant.h" G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant, GTK_TYPE_ASSISTANT) +static GtkWidget * +account_assistant_build_introduction_page (void) +{ + GtkWidget *main_vbox, *hbox_1, *w; + + main_vbox = gtk_vbox_new (FALSE, 12); + gtk_widget_show (main_vbox); + + hbox_1 = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 6); + gtk_widget_show (hbox_1); + + w = gtk_label_new (_("With Empathy you can chat with people online nearby " + "and with friends and colleagues who use Google Talk, AIM, " + "Windows Live and many other chat programs. With a microphone " + "or a webcam you can also have audio or video calls.")); + gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); + gtk_widget_show (w); + + w = gtk_image_new_from_icon_name ("empathy", GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); + gtk_widget_show (w); + + return main_vbox; +} static void empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) { + } static void empathy_account_assistant_init (EmpathyAccountAssistant *self) { + GtkWidget *page; + + page = account_assistant_build_introduction_page (); + gtk_assistant_append_page (GTK_ASSISTANT (self), page); } EmpathyAccountAssistant* diff --git a/src/empathy-account-assistant.h b/src/empathy-account-assistant.h index 03e99e265..64711e72f 100644 --- a/src/empathy-account-assistant.h +++ b/src/empathy-account-assistant.h @@ -24,6 +24,7 @@ #define __EMPATHY_ACCOUNT_ASSISTANT_H__ #include +#include G_BEGIN_DECLS -- cgit v1.2.3 From 73a995007e5a417b0e1e0ebf13bdcfdf4dae7c7c Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 19:02:52 +0200 Subject: Implement first page in the assistant --- libempathy-gtk/Makefile.am | 2 + libempathy-gtk/empathy-account-assistant.c | 116 +++++++++++++++++++++++++++++ libempathy-gtk/empathy-account-assistant.h | 60 +++++++++++++++ src/Makefile.am | 1 - src/empathy-account-assistant.c | 75 ------------------- src/empathy-account-assistant.h | 60 --------------- tests/test-empathy-account-assistant.c | 2 +- 7 files changed, 179 insertions(+), 137 deletions(-) create mode 100644 libempathy-gtk/empathy-account-assistant.c create mode 100644 libempathy-gtk/empathy-account-assistant.h delete mode 100644 src/empathy-account-assistant.c delete mode 100644 src/empathy-account-assistant.h diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 70e11e412..aeada220b 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -24,6 +24,7 @@ BUILT_SOURCES = \ lib_LTLIBRARIES = libempathy-gtk.la libempathy_gtk_handwritten_source = \ + empathy-account-assistant.c \ empathy-account-chooser.c \ empathy-account-widget.c \ empathy-account-widget-irc.c \ @@ -86,6 +87,7 @@ libempathy_gtk_la_LDFLAGS = \ -export-symbols-regex ^empathy_ libempathy_gtk_headers = \ + empathy-account-assistant.h \ empathy-account-chooser.h \ empathy-account-widget.h \ empathy-account-widget-irc.h \ diff --git a/libempathy-gtk/empathy-account-assistant.c b/libempathy-gtk/empathy-account-assistant.c new file mode 100644 index 000000000..2efe0f086 --- /dev/null +++ b/libempathy-gtk/empathy-account-assistant.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Cosimo Cecchi + */ + +/* empathy-account-assistant.c */ + +#include + +#include "empathy-account-assistant.h" +#include "empathy-ui-utils.h" + +G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant, + GTK_TYPE_ASSISTANT) + +static GtkWidget * +account_assistant_build_introduction_page (void) +{ + GtkWidget *main_vbox, *hbox_1, *w, *radio, *vbox_1; + GdkPixbuf *pix; + + main_vbox = gtk_vbox_new (FALSE, 12); + gtk_widget_show (main_vbox); + gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); + + hbox_1 = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0); + gtk_widget_show (hbox_1); + + w = gtk_label_new (_("With Empathy you can chat with people \nonline nearby " + "and with friends and colleagues \nwho use Google Talk, AIM, " + "Windows Live \nand many other chat programs. With a microphone \n" + "or a webcam you can also have audio or video calls.")); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); + gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + pix = empathy_pixbuf_from_icon_name_sized ("empathy", 96); + w = gtk_image_new_from_pixbuf (pix); + gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); + gtk_widget_show (w); + + g_object_unref (pix); + + w = gtk_label_new (_("Do you have an account you've been using with another " + "chat program?")); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + w = gtk_alignment_new (0, 0, 0, 0); + gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + vbox_1 = gtk_vbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (w), vbox_1); + gtk_widget_show (vbox_1); + + radio = gtk_radio_button_new_with_label (NULL, _("Yes, import my account details from ")); + gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0); + gtk_widget_show (radio); + + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("Yes, I'll enter my account details now")); + gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I want a new account")); + gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I just want to see people online nearby for now")); + gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + return main_vbox; +} + +static void +empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) +{ + +} + +static void +empathy_account_assistant_init (EmpathyAccountAssistant *self) +{ + GtkWidget *page; + + page = account_assistant_build_introduction_page (); + gtk_assistant_append_page (GTK_ASSISTANT (self), page); + gtk_assistant_set_page_title (GTK_ASSISTANT (self), page, _("Welcome to Empathy")); + gtk_assistant_set_page_type (GTK_ASSISTANT (self), page, GTK_ASSISTANT_PAGE_INTRO); + gtk_assistant_set_page_complete (GTK_ASSISTANT (self), page, TRUE); +} + +GtkWidget * +empathy_account_assistant_new (void) +{ + return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, NULL); +} diff --git a/libempathy-gtk/empathy-account-assistant.h b/libempathy-gtk/empathy-account-assistant.h new file mode 100644 index 000000000..38a96f8f0 --- /dev/null +++ b/libempathy-gtk/empathy-account-assistant.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Cosimo Cecchi + */ + +/* empathy-account-assistant.h */ + +#ifndef __EMPATHY_ACCOUNT_ASSISTANT_H__ +#define __EMPATHY_ACCOUNT_ASSISTANT_H__ + +#include +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_ACCOUNT_ASSISTANT empathy_account_assistant_get_type() +#define EMPATHY_ACCOUNT_ASSISTANT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistant)) +#define EMPATHY_ACCOUNT_ASSISTANT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) +#define EMPATHY_IS_ACCOUNT_ASSISTANT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) +#define EMPATHY_IS_ACCOUNT_ASSISTANT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) +#define EMPATHY_ACCOUNT_ASSISTANT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) + +typedef struct { + GtkAssistant parent; + + /* private */ + gpointer priv; +} EmpathyAccountAssistant; + +typedef struct { + GtkAssistantClass parent_class; +} EmpathyAccountAssistantClass; + +GType empathy_account_assistant_get_type (void); + +GtkWidget *empathy_account_assistant_new (void); + +G_END_DECLS + +#endif /* __EMPATHY_ACCOUNT_ASSISTANT_H__ */ diff --git a/src/Makefile.am b/src/Makefile.am index 9ac6b9bb3..d0b86edfc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,7 +31,6 @@ BUILT_SOURCES= \ empathy_handwritten_source = \ empathy.c \ empathy-about-dialog.c empathy-about-dialog.h \ - empathy-account-assistant.c empathy-account-assistant.h \ empathy-accounts-dialog.c empathy-accounts-dialog.h \ empathy-call-window.c empathy-call-window.h \ empathy-call-window-fullscreen.c empathy-call-window-fullscreen.h \ diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c deleted file mode 100644 index 461949892..000000000 --- a/src/empathy-account-assistant.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2009 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Cosimo Cecchi - */ - -/* empathy-account-assistant.c */ - -#include - -#include "empathy-account-assistant.h" - -G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant, - GTK_TYPE_ASSISTANT) - -static GtkWidget * -account_assistant_build_introduction_page (void) -{ - GtkWidget *main_vbox, *hbox_1, *w; - - main_vbox = gtk_vbox_new (FALSE, 12); - gtk_widget_show (main_vbox); - - hbox_1 = gtk_hbox_new (FALSE, 12); - gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 6); - gtk_widget_show (hbox_1); - - w = gtk_label_new (_("With Empathy you can chat with people online nearby " - "and with friends and colleagues who use Google Talk, AIM, " - "Windows Live and many other chat programs. With a microphone " - "or a webcam you can also have audio or video calls.")); - gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); - gtk_widget_show (w); - - w = gtk_image_new_from_icon_name ("empathy", GTK_ICON_SIZE_DIALOG); - gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); - gtk_widget_show (w); - - return main_vbox; -} - -static void -empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) -{ - -} - -static void -empathy_account_assistant_init (EmpathyAccountAssistant *self) -{ - GtkWidget *page; - - page = account_assistant_build_introduction_page (); - gtk_assistant_append_page (GTK_ASSISTANT (self), page); -} - -EmpathyAccountAssistant* -empathy_account_assistant_new (void) -{ - return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, NULL); -} diff --git a/src/empathy-account-assistant.h b/src/empathy-account-assistant.h deleted file mode 100644 index 64711e72f..000000000 --- a/src/empathy-account-assistant.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2009 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Cosimo Cecchi - */ - -/* empathy-account-assistant.h */ - -#ifndef __EMPATHY_ACCOUNT_ASSISTANT_H__ -#define __EMPATHY_ACCOUNT_ASSISTANT_H__ - -#include -#include - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_ACCOUNT_ASSISTANT empathy_account_assistant_get_type() -#define EMPATHY_ACCOUNT_ASSISTANT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistant)) -#define EMPATHY_ACCOUNT_ASSISTANT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) -#define EMPATHY_IS_ACCOUNT_ASSISTANT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) -#define EMPATHY_IS_ACCOUNT_ASSISTANT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) -#define EMPATHY_ACCOUNT_ASSISTANT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) - -typedef struct { - GtkAssistant parent; - - /* private */ - gpointer priv; -} EmpathyAccountAssistant; - -typedef struct { - GtkAssistantClass parent_class; -} EmpathyAccountAssistantClass; - -GType empathy_account_assistant_get_type (void); - -EmpathyAccountAssistant* empathy_account_assistant_new (void); - -G_END_DECLS - -#endif /* __EMPATHY_ACCOUNT_ASSISTANT_H__ */ diff --git a/tests/test-empathy-account-assistant.c b/tests/test-empathy-account-assistant.c index bdcbe6c69..5add95881 100644 --- a/tests/test-empathy-account-assistant.c +++ b/tests/test-empathy-account-assistant.c @@ -5,7 +5,7 @@ #include #include -int main (int argc, char *argv) +int main (int argc, char **argv) { GtkWidget *assistant; -- cgit v1.2.3 From 3ac8eb4e2f6909d6c54718d6910b156359e10b42 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Aug 2009 19:11:33 +0200 Subject: Move back the account assistant to src/ --- libempathy-gtk/Makefile.am | 2 - libempathy-gtk/empathy-account-assistant.c | 116 ----------------------------- libempathy-gtk/empathy-account-assistant.h | 60 --------------- src/Makefile.am | 1 + src/empathy-account-assistant.c | 116 +++++++++++++++++++++++++++++ src/empathy-account-assistant.h | 60 +++++++++++++++ tests/Makefile.am | 5 ++ tests/test-empathy-account-assistant.c | 2 +- 8 files changed, 183 insertions(+), 179 deletions(-) delete mode 100644 libempathy-gtk/empathy-account-assistant.c delete mode 100644 libempathy-gtk/empathy-account-assistant.h create mode 100644 src/empathy-account-assistant.c create mode 100644 src/empathy-account-assistant.h diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index aeada220b..70e11e412 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -24,7 +24,6 @@ BUILT_SOURCES = \ lib_LTLIBRARIES = libempathy-gtk.la libempathy_gtk_handwritten_source = \ - empathy-account-assistant.c \ empathy-account-chooser.c \ empathy-account-widget.c \ empathy-account-widget-irc.c \ @@ -87,7 +86,6 @@ libempathy_gtk_la_LDFLAGS = \ -export-symbols-regex ^empathy_ libempathy_gtk_headers = \ - empathy-account-assistant.h \ empathy-account-chooser.h \ empathy-account-widget.h \ empathy-account-widget-irc.h \ diff --git a/libempathy-gtk/empathy-account-assistant.c b/libempathy-gtk/empathy-account-assistant.c deleted file mode 100644 index 2efe0f086..000000000 --- a/libempathy-gtk/empathy-account-assistant.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2009 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Cosimo Cecchi - */ - -/* empathy-account-assistant.c */ - -#include - -#include "empathy-account-assistant.h" -#include "empathy-ui-utils.h" - -G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant, - GTK_TYPE_ASSISTANT) - -static GtkWidget * -account_assistant_build_introduction_page (void) -{ - GtkWidget *main_vbox, *hbox_1, *w, *radio, *vbox_1; - GdkPixbuf *pix; - - main_vbox = gtk_vbox_new (FALSE, 12); - gtk_widget_show (main_vbox); - gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); - - hbox_1 = gtk_hbox_new (FALSE, 12); - gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0); - gtk_widget_show (hbox_1); - - w = gtk_label_new (_("With Empathy you can chat with people \nonline nearby " - "and with friends and colleagues \nwho use Google Talk, AIM, " - "Windows Live \nand many other chat programs. With a microphone \n" - "or a webcam you can also have audio or video calls.")); - gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); - gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - pix = empathy_pixbuf_from_icon_name_sized ("empathy", 96); - w = gtk_image_new_from_pixbuf (pix); - gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); - gtk_widget_show (w); - - g_object_unref (pix); - - w = gtk_label_new (_("Do you have an account you've been using with another " - "chat program?")); - gtk_misc_set_alignment (GTK_MISC (w), 0, 0); - gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - w = gtk_alignment_new (0, 0, 0, 0); - gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0); - gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - vbox_1 = gtk_vbox_new (FALSE, 6); - gtk_container_add (GTK_CONTAINER (w), vbox_1); - gtk_widget_show (vbox_1); - - radio = gtk_radio_button_new_with_label (NULL, _("Yes, import my account details from ")); - gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0); - gtk_widget_show (radio); - - w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("Yes, I'll enter my account details now")); - gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I want a new account")); - gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I just want to see people online nearby for now")); - gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - return main_vbox; -} - -static void -empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) -{ - -} - -static void -empathy_account_assistant_init (EmpathyAccountAssistant *self) -{ - GtkWidget *page; - - page = account_assistant_build_introduction_page (); - gtk_assistant_append_page (GTK_ASSISTANT (self), page); - gtk_assistant_set_page_title (GTK_ASSISTANT (self), page, _("Welcome to Empathy")); - gtk_assistant_set_page_type (GTK_ASSISTANT (self), page, GTK_ASSISTANT_PAGE_INTRO); - gtk_assistant_set_page_complete (GTK_ASSISTANT (self), page, TRUE); -} - -GtkWidget * -empathy_account_assistant_new (void) -{ - return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, NULL); -} diff --git a/libempathy-gtk/empathy-account-assistant.h b/libempathy-gtk/empathy-account-assistant.h deleted file mode 100644 index 38a96f8f0..000000000 --- a/libempathy-gtk/empathy-account-assistant.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2009 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Cosimo Cecchi - */ - -/* empathy-account-assistant.h */ - -#ifndef __EMPATHY_ACCOUNT_ASSISTANT_H__ -#define __EMPATHY_ACCOUNT_ASSISTANT_H__ - -#include -#include - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_ACCOUNT_ASSISTANT empathy_account_assistant_get_type() -#define EMPATHY_ACCOUNT_ASSISTANT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistant)) -#define EMPATHY_ACCOUNT_ASSISTANT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) -#define EMPATHY_IS_ACCOUNT_ASSISTANT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) -#define EMPATHY_IS_ACCOUNT_ASSISTANT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) -#define EMPATHY_ACCOUNT_ASSISTANT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) - -typedef struct { - GtkAssistant parent; - - /* private */ - gpointer priv; -} EmpathyAccountAssistant; - -typedef struct { - GtkAssistantClass parent_class; -} EmpathyAccountAssistantClass; - -GType empathy_account_assistant_get_type (void); - -GtkWidget *empathy_account_assistant_new (void); - -G_END_DECLS - -#endif /* __EMPATHY_ACCOUNT_ASSISTANT_H__ */ diff --git a/src/Makefile.am b/src/Makefile.am index d0b86edfc..9ac6b9bb3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,7 @@ BUILT_SOURCES= \ empathy_handwritten_source = \ empathy.c \ empathy-about-dialog.c empathy-about-dialog.h \ + empathy-account-assistant.c empathy-account-assistant.h \ empathy-accounts-dialog.c empathy-accounts-dialog.h \ empathy-call-window.c empathy-call-window.h \ empathy-call-window-fullscreen.c empathy-call-window-fullscreen.h \ diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c new file mode 100644 index 000000000..6d3c27aa2 --- /dev/null +++ b/src/empathy-account-assistant.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Cosimo Cecchi + */ + +/* empathy-account-assistant.c */ + +#include + +#include "empathy-account-assistant.h" +#include + +G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant, + GTK_TYPE_ASSISTANT) + +static GtkWidget * +account_assistant_build_introduction_page (void) +{ + GtkWidget *main_vbox, *hbox_1, *w, *radio, *vbox_1; + GdkPixbuf *pix; + + main_vbox = gtk_vbox_new (FALSE, 12); + gtk_widget_show (main_vbox); + gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); + + hbox_1 = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0); + gtk_widget_show (hbox_1); + + w = gtk_label_new (_("With Empathy you can chat with people \nonline nearby " + "and with friends and colleagues \nwho use Google Talk, AIM, " + "Windows Live \nand many other chat programs. With a microphone \n" + "or a webcam you can also have audio or video calls.")); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); + gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + pix = empathy_pixbuf_from_icon_name_sized ("empathy", 96); + w = gtk_image_new_from_pixbuf (pix); + gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); + gtk_widget_show (w); + + g_object_unref (pix); + + w = gtk_label_new (_("Do you have an account you've been using with another " + "chat program?")); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + w = gtk_alignment_new (0, 0, 0, 0); + gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + vbox_1 = gtk_vbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (w), vbox_1); + gtk_widget_show (vbox_1); + + radio = gtk_radio_button_new_with_label (NULL, _("Yes, import my account details from ")); + gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0); + gtk_widget_show (radio); + + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("Yes, I'll enter my account details now")); + gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I want a new account")); + gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I just want to see people online nearby for now")); + gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + gtk_widget_show (w); + + return main_vbox; +} + +static void +empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) +{ + +} + +static void +empathy_account_assistant_init (EmpathyAccountAssistant *self) +{ + GtkWidget *page; + + page = account_assistant_build_introduction_page (); + gtk_assistant_append_page (GTK_ASSISTANT (self), page); + gtk_assistant_set_page_title (GTK_ASSISTANT (self), page, _("Welcome to Empathy")); + gtk_assistant_set_page_type (GTK_ASSISTANT (self), page, GTK_ASSISTANT_PAGE_INTRO); + gtk_assistant_set_page_complete (GTK_ASSISTANT (self), page, TRUE); +} + +GtkWidget * +empathy_account_assistant_new (void) +{ + return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, NULL); +} diff --git a/src/empathy-account-assistant.h b/src/empathy-account-assistant.h new file mode 100644 index 000000000..38a96f8f0 --- /dev/null +++ b/src/empathy-account-assistant.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Cosimo Cecchi + */ + +/* empathy-account-assistant.h */ + +#ifndef __EMPATHY_ACCOUNT_ASSISTANT_H__ +#define __EMPATHY_ACCOUNT_ASSISTANT_H__ + +#include +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_ACCOUNT_ASSISTANT empathy_account_assistant_get_type() +#define EMPATHY_ACCOUNT_ASSISTANT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistant)) +#define EMPATHY_ACCOUNT_ASSISTANT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) +#define EMPATHY_IS_ACCOUNT_ASSISTANT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) +#define EMPATHY_IS_ACCOUNT_ASSISTANT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) +#define EMPATHY_ACCOUNT_ASSISTANT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) + +typedef struct { + GtkAssistant parent; + + /* private */ + gpointer priv; +} EmpathyAccountAssistant; + +typedef struct { + GtkAssistantClass parent_class; +} EmpathyAccountAssistantClass; + +GType empathy_account_assistant_get_type (void); + +GtkWidget *empathy_account_assistant_new (void); + +G_END_DECLS + +#endif /* __EMPATHY_ACCOUNT_ASSISTANT_H__ */ diff --git a/tests/Makefile.am b/tests/Makefile.am index eb5dba529..8ffdae723 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -37,6 +37,11 @@ test_empathy_status_preset_dialog_SOURCES = test-empathy-status-preset-dialog.c test_empathy_protocol_chooser_SOURCES = test-empathy-protocol-chooser.c test_empathy_account_assistant_SOURCES = test-empathy-account-assistant.c +test_empathy_account_assistant_CFLAGS = -I$(top_srcdir)/src +test_empathy_account_assistant_LDADD = \ + $(top_builddir)/src/empathy-account-assistant.o \ + $(LDADD) + check_PROGRAMS = check-main TESTS = check-main check_main_SOURCES = \ diff --git a/tests/test-empathy-account-assistant.c b/tests/test-empathy-account-assistant.c index 5add95881..f1f519d77 100644 --- a/tests/test-empathy-account-assistant.c +++ b/tests/test-empathy-account-assistant.c @@ -3,7 +3,7 @@ #include #include -#include +#include "empathy-account-assistant.h" int main (int argc, char **argv) { -- cgit v1.2.3 From 01e526b8b694869c81996f9e817cc3e3a559c161 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 3 Aug 2009 10:34:48 +0200 Subject: Fix style --- src/empathy-account-assistant.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 6d3c27aa2..4c23ca8b0 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -72,19 +72,23 @@ account_assistant_build_introduction_page (void) gtk_container_add (GTK_CONTAINER (w), vbox_1); gtk_widget_show (vbox_1); - radio = gtk_radio_button_new_with_label (NULL, _("Yes, import my account details from ")); + radio = gtk_radio_button_new_with_label (NULL, + _("Yes, import my account details from ")); gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0); gtk_widget_show (radio); - w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("Yes, I'll enter my account details now")); + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), + _("Yes, I'll enter my account details now")); gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); gtk_widget_show (w); - w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I want a new account")); + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), + _("No, I want a new account")); gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); gtk_widget_show (w); - w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I just want to see people online nearby for now")); + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), + _("No, I just want to see people online nearby for now")); gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); gtk_widget_show (w); @@ -102,10 +106,13 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) { GtkWidget *page; + /* first page */ page = account_assistant_build_introduction_page (); gtk_assistant_append_page (GTK_ASSISTANT (self), page); - gtk_assistant_set_page_title (GTK_ASSISTANT (self), page, _("Welcome to Empathy")); - gtk_assistant_set_page_type (GTK_ASSISTANT (self), page, GTK_ASSISTANT_PAGE_INTRO); + gtk_assistant_set_page_title (GTK_ASSISTANT (self), page, + _("Welcome to Empathy")); + gtk_assistant_set_page_type (GTK_ASSISTANT (self), page, + GTK_ASSISTANT_PAGE_INTRO); gtk_assistant_set_page_complete (GTK_ASSISTANT (self), page, TRUE); } -- cgit v1.2.3 From 91feedc5c6b02468fc029f83157445a9c6d8b7d4 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 3 Aug 2009 11:32:05 +0200 Subject: Style fixes --- src/empathy-account-assistant.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/empathy-account-assistant.h b/src/empathy-account-assistant.h index 38a96f8f0..82b14e312 100644 --- a/src/empathy-account-assistant.h +++ b/src/empathy-account-assistant.h @@ -30,15 +30,18 @@ G_BEGIN_DECLS #define EMPATHY_TYPE_ACCOUNT_ASSISTANT empathy_account_assistant_get_type() #define EMPATHY_ACCOUNT_ASSISTANT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistant)) + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT,\ + EmpathyAccountAssistant)) #define EMPATHY_ACCOUNT_ASSISTANT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT,\ + EmpathyAccountAssistantClass)) #define EMPATHY_IS_ACCOUNT_ASSISTANT(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) #define EMPATHY_IS_ACCOUNT_ASSISTANT_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_ASSISTANT)) #define EMPATHY_ACCOUNT_ASSISTANT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantClass)) + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_ASSISTANT,\ + EmpathyAccountAssistantClass)) typedef struct { GtkAssistant parent; -- cgit v1.2.3 From 63b3a10e4b442ef9865885f590f3d251ac006f04 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 3 Aug 2009 11:32:19 +0200 Subject: Add private struct and responses to first page --- src/empathy-account-assistant.c | 62 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 4c23ca8b0..5b7535bd3 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -23,13 +23,43 @@ #include #include "empathy-account-assistant.h" + +#include + #include G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant, GTK_TYPE_ASSISTANT) +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountAssistant) + +typedef enum { + RESPONSE_IMPORT = 1, + RESPONSE_ENTER_ACCOUNT = 2, + RESPONSE_CREATE_ACCOUNT = 3, + RESPONSE_SALUT_ONLY = 4 +} FirstPageResponse; + +typedef struct { + FirstPageResponse first_resp; +} EmpathyAccountAssistantPriv; + +static void +account_assistant_radio_choice_toggled_cb (GtkToggleButton *button, + EmpathyAccountAssistant *self) +{ + FirstPageResponse response; + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + + response = GPOINTER_TO_INT (g_object_get_data + (G_OBJECT (button), "response")); + + g_print ("choice %d toggled\n", response); + priv->first_resp = response; +} + static GtkWidget * -account_assistant_build_introduction_page (void) +account_assistant_build_introduction_page (EmpathyAccountAssistant *self) { GtkWidget *main_vbox, *hbox_1, *w, *radio, *vbox_1; GdkPixbuf *pix; @@ -72,42 +102,68 @@ account_assistant_build_introduction_page (void) gtk_container_add (GTK_CONTAINER (w), vbox_1); gtk_widget_show (vbox_1); + /* TODO: this will have to be updated when kutio's branch have landed */ radio = gtk_radio_button_new_with_label (NULL, _("Yes, import my account details from ")); gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (radio), "response", + GINT_TO_POINTER (RESPONSE_IMPORT)); gtk_widget_show (radio); + g_signal_connect (radio, "clicked", + G_CALLBACK (account_assistant_radio_choice_toggled_cb), self); + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("Yes, I'll enter my account details now")); gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (w), "response", + GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT)); gtk_widget_show (w); + g_signal_connect (w, "clicked", + G_CALLBACK (account_assistant_radio_choice_toggled_cb), self); + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I want a new account")); gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (w), "response", + GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT)); gtk_widget_show (w); + g_signal_connect (w, "clicked", + G_CALLBACK (account_assistant_radio_choice_toggled_cb), self); + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("No, I just want to see people online nearby for now")); gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (w), "response", + GINT_TO_POINTER (RESPONSE_SALUT_ONLY)); gtk_widget_show (w); + g_signal_connect (w, "clicked", + G_CALLBACK (account_assistant_radio_choice_toggled_cb), self); + return main_vbox; } static void empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) { - + g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv)); } static void empathy_account_assistant_init (EmpathyAccountAssistant *self) { + EmpathyAccountAssistantPriv *priv; GtkWidget *page; + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT, + EmpathyAccountAssistantPriv); + self->priv = priv; + /* first page */ - page = account_assistant_build_introduction_page (); + page = account_assistant_build_introduction_page (self); gtk_assistant_append_page (GTK_ASSISTANT (self), page); gtk_assistant_set_page_title (GTK_ASSISTANT (self), page, _("Welcome to Empathy")); -- cgit v1.2.3 From 7ec689852cca3280e48f1d6cba3f5c358575844c Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 3 Aug 2009 18:00:41 +0200 Subject: Remove dead code --- libempathy-gtk/empathy-protocol-chooser.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.h b/libempathy-gtk/empathy-protocol-chooser.h index 9d881958d..d6b944a2f 100644 --- a/libempathy-gtk/empathy-protocol-chooser.h +++ b/libempathy-gtk/empathy-protocol-chooser.h @@ -58,10 +58,6 @@ struct _EmpathyProtocolChooserClass GtkComboBoxClass parent_class; }; -typedef void (* EmpathyProtocolChooserReadyCb) (GtkWidget *chooser, - GError *error, - gpointer user_data); - GType empathy_protocol_chooser_get_type (void) G_GNUC_CONST; GtkWidget * empathy_protocol_chooser_new (void); TpConnectionManager *empathy_protocol_chooser_dup_selected ( -- cgit v1.2.3 From f36945737307c6de7d5c8c66fb117dbdc170a758 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 3 Aug 2009 18:01:48 +0200 Subject: Fix long lines --- libempathy-gtk/empathy-account-widget.c | 35 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 5444ffda2..76f4d72a3 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -166,7 +166,8 @@ account_widget_checkbutton_toggled_cb (GtkWidget *widget, * always unset the param and set the value if different from the * default value. */ empathy_account_settings_unset (priv->settings, param_name); - default_value = empathy_account_settings_get_boolean (priv->settings, param_name); + default_value = empathy_account_settings_get_boolean (priv->settings, + param_name); if (default_value == value) { @@ -188,7 +189,8 @@ account_widget_forget_clicked_cb (GtkWidget *button, EmpathyAccountWidgetPriv *priv = GET_PRIV (self); const gchar *param_name; - param_name = g_object_get_data (G_OBJECT (priv->entry_password), "param_name"); + param_name = g_object_get_data (G_OBJECT (priv->entry_password), + "param_name"); DEBUG ("Unset %s", param_name); empathy_account_settings_unset (priv->settings, param_name); @@ -302,7 +304,8 @@ account_widget_setup_widget (EmpathyAccountWidget *self, { gboolean value = FALSE; - value = empathy_account_settings_get_boolean (priv->settings, param_name); + value = empathy_account_settings_get_boolean (priv->settings, + param_name); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); g_signal_connect (widget, "toggled", @@ -362,7 +365,8 @@ accounts_widget_generic_setup (EmpathyAccountWidget *self, else table_settings = table_advanced_settings; - param_name_formatted = account_widget_generic_format_param_name (param->name); + 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); @@ -422,7 +426,8 @@ accounts_widget_generic_setup (EmpathyAccountWidget *self, 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; + case 'd': minint = G_MININT32; maxint = G_MAXINT32; + step = 0.1; break; } str = g_strdup_printf (_("%s:"), param_name_formatted); @@ -511,10 +516,10 @@ account_widget_setup_generic (EmpathyAccountWidget *self) GtkWidget *table_common_settings; GtkWidget *table_advanced_settings; - table_common_settings = GTK_WIDGET (gtk_builder_get_object (self->ui_details->gui, - "table_common_settings")); - table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (self->ui_details->gui, - "table_advanced_settings")); + table_common_settings = GTK_WIDGET (gtk_builder_get_object + (self->ui_details->gui, "table_common_settings")); + table_advanced_settings = GTK_WIDGET (gtk_builder_get_object + (self->ui_details->gui, "table_advanced_settings")); accounts_widget_generic_setup (self, table_common_settings, table_advanced_settings); @@ -814,11 +819,15 @@ do_constructed (GObject *obj) { const gchar *password = NULL; - priv->button_forget = GTK_WIDGET (gtk_builder_get_object (self->ui_details->gui, "button_forget")); - priv->entry_password = GTK_WIDGET (gtk_builder_get_object (self->ui_details->gui, "entry_password")); + priv->button_forget = GTK_WIDGET (gtk_builder_get_object + (self->ui_details->gui, "button_forget")); + priv->entry_password = GTK_WIDGET (gtk_builder_get_object + (self->ui_details->gui, "entry_password")); - password = empathy_account_settings_get_string (priv->settings, "password"); - gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (password)); + password = empathy_account_settings_get_string (priv->settings, + "password"); + gtk_widget_set_sensitive (priv->button_forget, + !EMP_STR_EMPTY (password)); g_signal_connect (priv->button_forget, "clicked", G_CALLBACK (account_widget_forget_clicked_cb), -- cgit v1.2.3 From f6a4501ee0965a8353b9ed638d37367f7068b34a Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 02:39:25 +0200 Subject: Add the concept of simple account widget --- libempathy-gtk/empathy-account-widget.c | 113 +++++++++++++++++++++++--------- libempathy-gtk/empathy-account-widget.h | 3 + 2 files changed, 85 insertions(+), 31 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 76f4d72a3..99b450910 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -57,12 +57,15 @@ typedef struct { GtkWidget *button_forget; GtkWidget *spinbutton_port; + gboolean simple; + gboolean dispose_run; } EmpathyAccountWidgetPriv; enum { PROP_PROTOCOL = 1, - PROP_SETTINGS + PROP_SETTINGS, + PROP_SIMPLE }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget) @@ -604,31 +607,47 @@ account_widget_build_jabber (EmpathyAccountWidget *self, GtkWidget *spinbutton_port; GtkWidget *checkbutton_ssl; - self->ui_details->gui = empathy_builder_get_file (filename, - "vbox_jabber_settings", &self->ui_details->widget, - "spinbutton_port", &spinbutton_port, - "checkbutton_ssl", &checkbutton_ssl, - NULL); + if (priv->simple) + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_jabber_simple", &self->ui_details->widget, + NULL); + + empathy_account_widget_handle_params (self, + "entry_simple_id", "account", + "entry_simple_password", "password", + NULL); - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_resource", "resource", - "entry_server", "server", - "spinbutton_port", "port", - "spinbutton_priority", "priority", - "checkbutton_ssl", "old-ssl", - "checkbutton_ignore_ssl_errors", "ignore-ssl-errors", - "checkbutton_encryption", "require-encryption", - NULL); + self->ui_details->default_focus = g_strdup ("entry_simple_id"); + } + else + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_jabber_settings", &self->ui_details->widget, + "spinbutton_port", &spinbutton_port, + "checkbutton_ssl", &checkbutton_ssl, + NULL); - self->ui_details->default_focus = g_strdup ("entry_id"); - self->ui_details->add_forget = TRUE; - priv->spinbutton_port = spinbutton_port; + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_resource", "resource", + "entry_server", "server", + "spinbutton_port", "port", + "spinbutton_priority", "priority", + "checkbutton_ssl", "old-ssl", + "checkbutton_ignore_ssl_errors", "ignore-ssl-errors", + "checkbutton_encryption", "require-encryption", + NULL); - g_signal_connect (checkbutton_ssl, "toggled", - G_CALLBACK (account_widget_jabber_ssl_toggled_cb), - self); + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; + priv->spinbutton_port = spinbutton_port; + + g_signal_connect (checkbutton_ssl, "toggled", + G_CALLBACK (account_widget_jabber_ssl_toggled_cb), + self); + } } static void @@ -741,6 +760,9 @@ do_set_property (GObject *object, case PROP_SETTINGS: priv->settings = g_value_dup_object (value); break; + case PROP_SIMPLE: + priv->simple = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -762,6 +784,8 @@ do_get_property (GObject *object, case PROP_SETTINGS: g_value_set_object (value, priv->settings); break; + case PROP_SIMPLE: + g_value_set_boolean (value, priv->simple); default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -838,20 +862,25 @@ do_constructed (GObject *obj) } /* handle apply button */ - priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY); - gtk_box_pack_end (GTK_BOX (self->ui_details->widget), priv->apply_button, FALSE, FALSE, 3); + if (!priv->simple) + { + priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY); + gtk_box_pack_end (GTK_BOX (self->ui_details->widget), priv->apply_button, + FALSE, FALSE, 3); - g_signal_connect (priv->apply_button, "clicked", - G_CALLBACK (account_widget_apply_clicked_cb), - self); - account_widget_handle_apply_sensitivity (self); - gtk_widget_show (priv->apply_button); + g_signal_connect (priv->apply_button, "clicked", + G_CALLBACK (account_widget_apply_clicked_cb), + self); + account_widget_handle_apply_sensitivity (self); + gtk_widget_show (priv->apply_button); + } /* hook up to widget destruction to unref ourselves */ g_signal_connect (self->ui_details->widget, "destroy", G_CALLBACK (account_widget_destroy_cb), self); - empathy_builder_unref_and_keep_widget (self->ui_details->gui, self->ui_details->widget); + empathy_builder_unref_and_keep_widget (self->ui_details->gui, + self->ui_details->widget); self->ui_details->gui = NULL; } @@ -915,6 +944,12 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (oclass, PROP_SETTINGS, param_spec); + param_spec = g_param_spec_boolean ("simple", + "simple", "Whether the account widget is a simple or an advanced one", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_SIMPLE, param_spec); + g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); } @@ -962,3 +997,19 @@ empathy_account_widget_new_for_protocol (const char *protocol, return self->ui_details->widget; } + +GtkWidget * +empathy_account_widget_simple_new_for_protocol (const char *protocol, + EmpathyAccountSettings *settings) +{ + 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, + "settings", settings, "simple", TRUE, NULL); + + return self->ui_details->widget; +} diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h index 8a5f0f2c2..7e6c331d1 100644 --- a/libempathy-gtk/empathy-account-widget.h +++ b/libempathy-gtk/empathy-account-widget.h @@ -62,6 +62,9 @@ GType empathy_account_widget_get_type (void); GtkWidget *empathy_account_widget_new_for_protocol (const char *protocol, EmpathyAccountSettings *settings); +GtkWidget * empathy_account_widget_simple_new_for_protocol + (const char *protocol, + EmpathyAccountSettings *settings); G_END_DECLS -- cgit v1.2.3 From 008fe6aa33bcc251a83b4670ead7eff5f552c268 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 02:39:47 +0200 Subject: Add an API to filter protocols --- libempathy-gtk/empathy-protocol-chooser.c | 81 ++++++++++++++++++++++++++----- libempathy-gtk/empathy-protocol-chooser.h | 11 ++++- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index d85997fb2..9ba28baf6 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -59,9 +59,12 @@ typedef struct { GtkListStore *store; + GtkTreeModel *filter_model; gboolean dispose_run; EmpathyConnectionManagers *cms; + EmpathyProtocolChooserFilterFunc filter_func; + gpointer filter_user_data; } EmpathyProtocolChooserPriv; enum @@ -177,7 +180,8 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser, else display_name_set = g_strdup (display_name); - gtk_list_store_insert_with_values (priv->store, NULL, 0, + gtk_list_store_insert_with_values (priv->store, + NULL, 0, COL_ICON, icon_name, COL_LABEL, display_name_set, COL_CM, cm, @@ -228,8 +232,20 @@ protocol_chooser_constructed (GObject *object) G_TYPE_OBJECT, /* CM */ G_TYPE_POINTER); /* protocol */ + priv->filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (priv->store), + NULL); + + /* Set the protocol sort function */ + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store), + COL_PROTOCOL, + protocol_chooser_sort_func, + NULL, NULL); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store), + COL_PROTOCOL, + GTK_SORT_ASCENDING); + gtk_combo_box_set_model (GTK_COMBO_BOX (object), - GTK_TREE_MODEL (priv->store)); + GTK_TREE_MODEL (priv->filter_model)); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, FALSE); @@ -244,15 +260,6 @@ protocol_chooser_constructed (GObject *object) "text", COL_LABEL, NULL); - /* Set the protocol sort function */ - gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store), - COL_PROTOCOL, - protocol_chooser_sort_func, - NULL, NULL); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store), - COL_PROTOCOL, - GTK_SORT_ASCENDING); - if (empathy_connection_managers_is_ready (priv->cms)) protocol_chooser_add_cms_list (protocol_chooser, empathy_connection_managers_get_cms (priv->cms)); @@ -288,6 +295,12 @@ protocol_chooser_dispose (GObject *object) priv->dispose_run = TRUE; + if (priv->filter_model) + { + g_object_unref (priv->filter_model); + priv->filter_model = NULL; + } + if (priv->store) { g_object_unref (priv->store); @@ -314,6 +327,28 @@ empathy_protocol_chooser_class_init (EmpathyProtocolChooserClass *klass) g_type_class_add_private (object_class, sizeof (EmpathyProtocolChooserPriv)); } +static gboolean +protocol_chooser_filter_visible_func (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer user_data) +{ + EmpathyProtocolChooser *protocol_chooser = user_data; + EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); + TpConnectionManager *cm = NULL; + TpConnectionManagerProtocol *protocol = NULL; + gboolean visible = FALSE; + + gtk_tree_model_get (model, iter, COL_CM, &cm, COL_PROTOCOL, &protocol, -1); + + if (cm != NULL && protocol != NULL) + { + visible = priv->filter_func (cm, protocol, priv->filter_user_data); + g_object_unref (cm); + } + + return visible; +} + /* public methods */ /** @@ -338,12 +373,12 @@ empathy_protocol_chooser_dup_selected ( if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (protocol_chooser), &iter)) { - gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, + gtk_tree_model_get (GTK_TREE_MODEL (priv->filter_model), &iter, COL_CM, &cm, -1); if (protocol != NULL) - gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, + gtk_tree_model_get (GTK_TREE_MODEL (priv->filter_model), &iter, COL_PROTOCOL, protocol, -1); } @@ -364,3 +399,23 @@ empathy_protocol_chooser_new (void) { return GTK_WIDGET (g_object_new (EMPATHY_TYPE_PROTOCOL_CHOOSER, NULL)); } + +void +empathy_protocol_chooser_set_visible (EmpathyProtocolChooser *protocol_chooser, + EmpathyProtocolChooserFilterFunc func, + gpointer user_data) +{ + EmpathyProtocolChooserPriv *priv; + + g_return_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser)); + + priv = GET_PRIV (protocol_chooser); + priv->filter_func = func; + priv->filter_user_data = user_data; + + gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER + (priv->filter_model), protocol_chooser_filter_visible_func, + protocol_chooser, NULL); + + gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model)); +} diff --git a/libempathy-gtk/empathy-protocol-chooser.h b/libempathy-gtk/empathy-protocol-chooser.h index d6b944a2f..55e8e355e 100644 --- a/libempathy-gtk/empathy-protocol-chooser.h +++ b/libempathy-gtk/empathy-protocol-chooser.h @@ -39,7 +39,7 @@ G_BEGIN_DECLS EMPATHY_TYPE_PROTOCOL_CHOOSER)) #define EMPATHY_IS_PROTOCOL_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ EMPATHY_TYPE_PROTOCOL_CHOOSER)) -#define EMPATHY_PROTOCOL_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \ +#define EMPATHY_PROTOCOL_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),\ EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserClass)) typedef struct _EmpathyProtocolChooser EmpathyProtocolChooser; @@ -58,11 +58,20 @@ struct _EmpathyProtocolChooserClass GtkComboBoxClass parent_class; }; +typedef gboolean (*EmpathyProtocolChooserFilterFunc) (TpConnectionManager *cm, + TpConnectionManagerProtocol *protocol, gpointer user_data); + GType empathy_protocol_chooser_get_type (void) G_GNUC_CONST; GtkWidget * empathy_protocol_chooser_new (void); TpConnectionManager *empathy_protocol_chooser_dup_selected ( EmpathyProtocolChooser *protocol_chooser, TpConnectionManagerProtocol **protocol); +void empathy_protocol_chooser_set_visible ( + EmpathyProtocolChooser *protocol_chooser, + EmpathyProtocolChooserFilterFunc func, + gpointer user_data); + + G_END_DECLS #endif /* __EMPATHY_PROTOCOL_CHOOSER_H__ */ -- cgit v1.2.3 From 7f784aadcfcadc05128b783a4e8d5f8499887b9d Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 02:40:04 +0200 Subject: Add the details page to the assistant Also, add a sketched version of the other pages --- src/empathy-account-assistant.c | 170 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 165 insertions(+), 5 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 5b7535bd3..0586daaf0 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -24,8 +24,11 @@ #include "empathy-account-assistant.h" +#include #include +#include +#include #include G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant, @@ -42,8 +45,27 @@ typedef enum { typedef struct { FirstPageResponse first_resp; + + GtkWidget *add_existing_page; } EmpathyAccountAssistantPriv; +static gint +account_assistant_page_forward_func (gint current_page, + gpointer user_data) +{ + EmpathyAccountAssistant *self = user_data; + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + gint retval; + + retval = current_page; + + if (current_page == 0) + retval = priv->first_resp; + + g_print ("retval = %d\n", retval); + return retval; +} + static void account_assistant_radio_choice_toggled_cb (GtkToggleButton *button, EmpathyAccountAssistant *self) @@ -146,6 +168,117 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self) return main_vbox; } +static GtkWidget * +account_assistant_build_import_page (EmpathyAccountAssistant *self) +{ + /* TODO: import page */ + GtkWidget *main_vbox, *w; + + main_vbox = gtk_vbox_new (FALSE, 12); + w = gtk_label_new ("Import your accounts!"); + gtk_widget_show (w); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6); + + gtk_widget_show (main_vbox); + + return main_vbox; +} + +static gboolean +account_assistant_chooser_enter_details_filter_func ( + TpConnectionManager *cm, + TpConnectionManagerProtocol *protocol, + gpointer user_data) +{ + /* TODO */ + return TRUE; +} + +static void +account_assistant_protocol_changed_cb (GtkComboBox *chooser, + EmpathyAccountAssistant *self) +{ + TpConnectionManager *cm; + TpConnectionManagerProtocol *proto; + EmpathyAccountSettings *settings; + EmpathyAccountAssistantPriv *priv; + char *str; + GtkWidget *account_widget; + + priv = GET_PRIV (self); + + cm = empathy_protocol_chooser_dup_selected ( + EMPATHY_PROTOCOL_CHOOSER (chooser), &proto); + + if (cm == NULL || proto == NULL) + /* we are not ready yet */ + return; + + /* Create account */ + /* To translator: %s is the protocol name */ + str = g_strdup_printf (_("New %s account"), proto->name); + + settings = empathy_account_settings_new (cm->name, proto->name, str); + account_widget = empathy_account_widget_simple_new_for_protocol + (proto->name, settings); + + gtk_box_pack_start (GTK_BOX (priv->add_existing_page), account_widget, FALSE, + FALSE, 0); + gtk_widget_show (account_widget); + + g_free (str); +} + +static GtkWidget * +account_assistant_build_enter_details_page (EmpathyAccountAssistant *self) +{ + GtkWidget *main_vbox, *w, *chooser; + + main_vbox = gtk_vbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); + gtk_widget_show (main_vbox); + + w = gtk_label_new (_("What kind of chat account do you have?")); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); + + w = gtk_alignment_new (0, 0, 0, 0); + gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + chooser = empathy_protocol_chooser_new (); + empathy_protocol_chooser_set_visible (EMPATHY_PROTOCOL_CHOOSER (chooser), + account_assistant_chooser_enter_details_filter_func, self); + gtk_container_add (GTK_CONTAINER (w), chooser); + gtk_widget_show (chooser); + + g_signal_connect (chooser, "changed", + G_CALLBACK (account_assistant_protocol_changed_cb), self); + + /* trigger show the first account widget */ + account_assistant_protocol_changed_cb (GTK_COMBO_BOX (chooser), self); + + return main_vbox; +} + +static GtkWidget * +account_assistant_build_create_account_page (EmpathyAccountAssistant *self) +{ + GtkWidget *main_vbox, *w; + + main_vbox = gtk_vbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); + gtk_widget_show (main_vbox); + + w = gtk_label_new (_("What kind of chat account do you want to create?")); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + return main_vbox; +} + static void empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) { @@ -156,20 +289,47 @@ static void empathy_account_assistant_init (EmpathyAccountAssistant *self) { EmpathyAccountAssistantPriv *priv; + GtkAssistant *assistant = GTK_ASSISTANT (self); GtkWidget *page; priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT, EmpathyAccountAssistantPriv); self->priv = priv; - /* first page */ + gtk_assistant_set_forward_page_func (assistant, + account_assistant_page_forward_func, self, NULL); + + /* first page (introduction) */ page = account_assistant_build_introduction_page (self); - gtk_assistant_append_page (GTK_ASSISTANT (self), page); - gtk_assistant_set_page_title (GTK_ASSISTANT (self), page, + gtk_assistant_append_page (assistant, page); + gtk_assistant_set_page_title (assistant, page, _("Welcome to Empathy")); - gtk_assistant_set_page_type (GTK_ASSISTANT (self), page, + gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_INTRO); - gtk_assistant_set_page_complete (GTK_ASSISTANT (self), page, TRUE); + gtk_assistant_set_page_complete (assistant, page, TRUE); + + /* set a default answer */ + priv->first_resp = RESPONSE_IMPORT; + + /* second page (import accounts) */ + page = account_assistant_build_import_page (self); + gtk_assistant_append_page (assistant, page); + gtk_assistant_set_page_title (assistant, page, + _("Import your existing accounts")); + gtk_assistant_set_page_complete (assistant, page, TRUE); + + /* third page (enter account details) */ + page = account_assistant_build_enter_details_page (self); + gtk_assistant_append_page (assistant, page); + gtk_assistant_set_page_title (assistant, page, + _("Enter your account details")); + priv->add_existing_page = page; + + /* fourth page (create a new account) */ + page = account_assistant_build_create_account_page (self); + gtk_assistant_append_page (assistant, page); + gtk_assistant_set_page_title (assistant, page, + _("Enter the details of the new account")); } GtkWidget * -- cgit v1.2.3 From f274e990d552235090b689071f5d464007948d52 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 11:45:42 +0200 Subject: Add a way to hook up to the apply sensitivity --- libempathy-gtk/empathy-account-widget.c | 27 ++++++++++++++++++++++++--- libempathy-gtk/empathy-account-widget.h | 3 ++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 99b450910..4a6b8f21d 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -68,15 +68,27 @@ enum { PROP_SIMPLE }; +enum { + HANDLE_APPLY, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget) static void account_widget_handle_apply_sensitivity (EmpathyAccountWidget *self) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + gboolean is_valid; + + is_valid = empathy_account_settings_is_valid (priv->settings); - gtk_widget_set_sensitive (priv->apply_button, - empathy_account_settings_is_valid (priv->settings)); + if (!priv->simple) + gtk_widget_set_sensitive (priv->apply_button, is_valid); + + g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid); } static gboolean @@ -950,6 +962,13 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (oclass, PROP_SIMPLE, param_spec); + signals[HANDLE_APPLY] = + g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, + 1, G_TYPE_BOOLEAN); + g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); } @@ -1000,7 +1019,7 @@ empathy_account_widget_new_for_protocol (const char *protocol, GtkWidget * empathy_account_widget_simple_new_for_protocol (const char *protocol, - EmpathyAccountSettings *settings) + EmpathyAccountSettings *settings, EmpathyAccountWidget **object) { EmpathyAccountWidget *self; @@ -1011,5 +1030,7 @@ empathy_account_widget_simple_new_for_protocol (const char *protocol, (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol, "settings", settings, "simple", TRUE, NULL); + *object = self; + return self->ui_details->widget; } diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h index 7e6c331d1..ab4e62b45 100644 --- a/libempathy-gtk/empathy-account-widget.h +++ b/libempathy-gtk/empathy-account-widget.h @@ -64,7 +64,8 @@ GtkWidget *empathy_account_widget_new_for_protocol (const char *protocol, EmpathyAccountSettings *settings); GtkWidget * empathy_account_widget_simple_new_for_protocol (const char *protocol, - EmpathyAccountSettings *settings); + EmpathyAccountSettings *settings, + EmpathyAccountWidget **object); G_END_DECLS -- cgit v1.2.3 From b69cd1fb3e9c4f2ffe87e1be5e165cc168cc60c9 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 11:46:24 +0200 Subject: Update label layout and add an "apply" logic --- src/empathy-account-assistant.c | 66 +++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 0586daaf0..7a5f176cd 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -47,6 +47,8 @@ typedef struct { FirstPageResponse first_resp; GtkWidget *add_existing_page; + GtkWidget *current_account_widget; + EmpathyAccountWidget *current_widget_object; } EmpathyAccountAssistantPriv; static gint @@ -94,23 +96,25 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self) gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0); gtk_widget_show (hbox_1); - w = gtk_label_new (_("With Empathy you can chat with people \nonline nearby " - "and with friends and colleagues \nwho use Google Talk, AIM, " - "Windows Live \nand many other chat programs. With a microphone \n" - "or a webcam you can also have audio or video calls.")); + w = gtk_label_new ( + _("With Empathy you can chat with people\n" + "online nearby and with friends and colleagues\n" + "who use Google Talk, AIM, Windows Live\n" + "and many other chat programs. With a microphone\n" + "or a webcam you can also have audio or video calls.")); gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0); gtk_widget_show (w); - pix = empathy_pixbuf_from_icon_name_sized ("empathy", 96); + pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80); w = gtk_image_new_from_pixbuf (pix); gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); gtk_widget_show (w); g_object_unref (pix); - w = gtk_label_new (_("Do you have an account you've been using with another " - "chat program?")); + w = gtk_label_new (_("Do you have an account you've been using " + "with another\nchat program?")); gtk_misc_set_alignment (GTK_MISC (w), 0, 0); gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); gtk_widget_show (w); @@ -194,6 +198,17 @@ account_assistant_chooser_enter_details_filter_func ( return TRUE; } +static void +account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object, + gboolean is_valid, + EmpathyAccountAssistant *self) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + + gtk_assistant_set_page_complete (GTK_ASSISTANT (self), + priv->add_existing_page, is_valid); +} + static void account_assistant_protocol_changed_cb (GtkComboBox *chooser, EmpathyAccountAssistant *self) @@ -204,6 +219,7 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser, EmpathyAccountAssistantPriv *priv; char *str; GtkWidget *account_widget; + EmpathyAccountWidget *widget_object = NULL; priv = GET_PRIV (self); @@ -220,7 +236,20 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser, settings = empathy_account_settings_new (cm->name, proto->name, str); account_widget = empathy_account_widget_simple_new_for_protocol - (proto->name, settings); + (proto->name, settings, &widget_object); + + if (priv->current_account_widget != NULL) + { + g_signal_handlers_disconnect_by_func (priv->current_widget_object, + account_assistant_handle_apply_cb, self); + gtk_widget_destroy (priv->current_account_widget); + } + + priv->current_account_widget = account_widget; + priv->current_widget_object = widget_object; + + g_signal_connect (priv->current_widget_object, "handle-apply", + G_CALLBACK (account_assistant_handle_apply_cb), self); gtk_box_pack_start (GTK_BOX (priv->add_existing_page), account_widget, FALSE, FALSE, 0); @@ -232,7 +261,8 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser, static GtkWidget * account_assistant_build_enter_details_page (EmpathyAccountAssistant *self) { - GtkWidget *main_vbox, *w, *chooser; + GtkWidget *main_vbox, *w, *chooser, *hbox; + PangoAttrList *list; main_vbox = gtk_vbox_new (FALSE, 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); @@ -259,6 +289,23 @@ account_assistant_build_enter_details_page (EmpathyAccountAssistant *self) /* trigger show the first account widget */ account_assistant_protocol_changed_cb (GTK_COMBO_BOX (chooser), self); + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_end (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + w = gtk_image_new_from_icon_name ("gtk-dialog-info", GTK_ICON_SIZE_BUTTON); + gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + w = gtk_label_new (_("If you have other accounts to set up, you can do " + "that at any time\nfrom the Edit menu.")); + gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); + list = pango_attr_list_new (); + pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_SMALL)); + gtk_label_set_attributes (GTK_LABEL (w), list); + gtk_widget_show (w); + pango_attr_list_unref (list); + return main_vbox; } @@ -323,6 +370,7 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) gtk_assistant_append_page (assistant, page); gtk_assistant_set_page_title (assistant, page, _("Enter your account details")); + gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); priv->add_existing_page = page; /* fourth page (create a new account) */ -- cgit v1.2.3 From 712f5f9f45105ce66f0f8d4fff40857924943ae8 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 13:20:52 +0200 Subject: Add simple implementations for many widgets --- libempathy-gtk/empathy-account-widget-aim.ui | 66 +++++++ libempathy-gtk/empathy-account-widget-groupwise.ui | 66 +++++++ libempathy-gtk/empathy-account-widget-icq.ui | 66 +++++++ libempathy-gtk/empathy-account-widget-jabber.ui | 66 +++++++ libempathy-gtk/empathy-account-widget-msn.ui | 66 +++++++ libempathy-gtk/empathy-account-widget-sip.ui | 66 +++++++ libempathy-gtk/empathy-account-widget-yahoo.ui | 66 +++++++ libempathy-gtk/empathy-account-widget.c | 218 +++++++++++++++------ 8 files changed, 615 insertions(+), 65 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-aim.ui b/libempathy-gtk/empathy-account-widget-aim.ui index 7f7ac3a60..d6696f583 100644 --- a/libempathy-gtk/empathy-account-widget-aim.ui +++ b/libempathy-gtk/empathy-account-widget-aim.ui @@ -190,4 +190,70 @@ + + True + vertical + 6 + + + True + 0 + What is your AIM screen name? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + + + + + + 1 + + + + + True + 0 + What is your AIM password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + + 3 + + + diff --git a/libempathy-gtk/empathy-account-widget-groupwise.ui b/libempathy-gtk/empathy-account-widget-groupwise.ui index 84157527d..f5ddf8d9f 100644 --- a/libempathy-gtk/empathy-account-widget-groupwise.ui +++ b/libempathy-gtk/empathy-account-widget-groupwise.ui @@ -194,4 +194,70 @@ + + True + vertical + 6 + + + True + 0 + What is your GroupWise User ID? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + + + + + + 1 + + + + + True + 0 + What is your GroupWise password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + + 3 + + + diff --git a/libempathy-gtk/empathy-account-widget-icq.ui b/libempathy-gtk/empathy-account-widget-icq.ui index 5eab0b75b..b2a62c215 100644 --- a/libempathy-gtk/empathy-account-widget-icq.ui +++ b/libempathy-gtk/empathy-account-widget-icq.ui @@ -219,4 +219,70 @@ + + True + vertical + 6 + + + True + 0 + What is your ICQ UIN? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + + + + + + 1 + + + + + True + 0 + What is your ICQ password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + + 3 + + + diff --git a/libempathy-gtk/empathy-account-widget-jabber.ui b/libempathy-gtk/empathy-account-widget-jabber.ui index 4b0aa15ad..a2165393c 100644 --- a/libempathy-gtk/empathy-account-widget-jabber.ui +++ b/libempathy-gtk/empathy-account-widget-jabber.ui @@ -348,4 +348,70 @@ + + True + vertical + 6 + + + True + 0 + What is your Jabber ID? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + + + + + + 1 + + + + + True + 0 + What is your Jabber password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.5 + 12 + + + True + True + False + + + + + + 3 + + + diff --git a/libempathy-gtk/empathy-account-widget-msn.ui b/libempathy-gtk/empathy-account-widget-msn.ui index 1d7bde038..2f06d88e7 100644 --- a/libempathy-gtk/empathy-account-widget-msn.ui +++ b/libempathy-gtk/empathy-account-widget-msn.ui @@ -194,4 +194,70 @@ + + True + vertical + 6 + + + True + 0 + What is your Windows Live user name? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + + + + + + 1 + + + + + True + 0 + What is your Windows Live password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + + 3 + + + diff --git a/libempathy-gtk/empathy-account-widget-sip.ui b/libempathy-gtk/empathy-account-widget-sip.ui index 406f22c94..edb70e426 100644 --- a/libempathy-gtk/empathy-account-widget-sip.ui +++ b/libempathy-gtk/empathy-account-widget-sip.ui @@ -212,4 +212,70 @@ + + True + vertical + 6 + + + True + 0 + What is your SIP login ID? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + + + + + + 1 + + + + + True + 0 + What is your SIP account password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + + 3 + + + diff --git a/libempathy-gtk/empathy-account-widget-yahoo.ui b/libempathy-gtk/empathy-account-widget-yahoo.ui index 31e932674..75c27f15c 100644 --- a/libempathy-gtk/empathy-account-widget-yahoo.ui +++ b/libempathy-gtk/empathy-account-widget-yahoo.ui @@ -294,4 +294,70 @@ + + True + vertical + 6 + + + True + 0 + What is your Yahoo! ID? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + + + + + + 1 + + + + + True + 0 + What is your Yahoo! password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + + 3 + + + diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 4a6b8f21d..3bd8309fa 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -596,19 +596,37 @@ static void account_widget_build_msn (EmpathyAccountWidget *self, const char *filename) { - self->ui_details->gui = empathy_builder_get_file (filename, - "vbox_msn_settings", &self->ui_details->widget, - NULL); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); + if (priv->simple) + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_msn_simple", &self->ui_details->widget, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id_simple"); + } + else + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_msn_settings", &self->ui_details->widget, + NULL); - self->ui_details->default_focus = g_strdup ("entry_id"); - self->ui_details->add_forget = TRUE; + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; + } } static void @@ -626,11 +644,11 @@ account_widget_build_jabber (EmpathyAccountWidget *self, NULL); empathy_account_widget_handle_params (self, - "entry_simple_id", "account", - "entry_simple_password", "password", + "entry_id_simple", "account", + "entry_password_simple", "password", NULL); - self->ui_details->default_focus = g_strdup ("entry_simple_id"); + self->ui_details->default_focus = g_strdup ("entry_id_simple"); } else { @@ -666,87 +684,157 @@ static void account_widget_build_icq (EmpathyAccountWidget *self, const char *filename) { + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); GtkWidget *spinbutton_port; - self->ui_details->gui = empathy_builder_get_file (filename, - "vbox_icq_settings", &self->ui_details->widget, - "spinbutton_port", &spinbutton_port, - NULL); + if (priv->simple) + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_icq_simple", &self->ui_details->widget, + NULL); - empathy_account_widget_handle_params (self, - "entry_uin", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - "entry_charset", "charset", - NULL); + empathy_account_widget_handle_params (self, + "entry_uin_simple", "account", + "entry_password_simple", "password", + NULL); - self->ui_details->default_focus = g_strdup ("entry_uin"); - self->ui_details->add_forget = TRUE; + self->ui_details->default_focus = g_strdup ("entry_uin_simple"); + } + else + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_icq_settings", &self->ui_details->widget, + "spinbutton_port", &spinbutton_port, + NULL); + + empathy_account_widget_handle_params (self, + "entry_uin", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + "entry_charset", "charset", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_uin"); + self->ui_details->add_forget = TRUE; + } } static void account_widget_build_aim (EmpathyAccountWidget *self, const char *filename) { + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); GtkWidget *spinbutton_port; - self->ui_details->gui = empathy_builder_get_file (filename, - "vbox_aim_settings", &self->ui_details->widget, - "spinbutton_port", &spinbutton_port, - NULL); + if (priv->simple) + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_aim_simple", &self->ui_details->widget, + NULL); - empathy_account_widget_handle_params (self, - "entry_screenname", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); + empathy_account_widget_handle_params (self, + "entry_screenname_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_screenname_simple"); + } + else + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_aim_settings", &self->ui_details->widget, + "spinbutton_port", &spinbutton_port, + NULL); - self->ui_details->default_focus = g_strdup ("entry_screenname"); - self->ui_details->add_forget = TRUE; + empathy_account_widget_handle_params (self, + "entry_screenname", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_screenname"); + self->ui_details->add_forget = TRUE; + } } static void account_widget_build_yahoo (EmpathyAccountWidget *self, const char *filename) { - self->ui_details->gui = empathy_builder_get_file (filename, - "vbox_yahoo_settings", &self->ui_details->widget, - NULL); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + if (priv->simple) + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_yahoo_simple", &self->ui_details->widget, + NULL); - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_server", "server", - "entry_locale", "room-list-locale", - "entry_charset", "charset", - "spinbutton_port", "port", - "checkbutton_yahoojp", "yahoojp", - "checkbutton_ignore_invites", "ignore-invites", - NULL); + empathy_account_widget_handle_params (self, + "entry_id_simple", "account", + "entry_password_simple", "password", + NULL); - self->ui_details->default_focus = g_strdup ("entry_id"); - self->ui_details->add_forget = TRUE; + self->ui_details->default_focus = g_strdup ("entry_id_simple"); + } + else + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_yahoo_settings", &self->ui_details->widget, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_server", "server", + "entry_locale", "room-list-locale", + "entry_charset", "charset", + "spinbutton_port", "port", + "checkbutton_yahoojp", "yahoojp", + "checkbutton_ignore_invites", "ignore-invites", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; + } } static void account_widget_build_groupwise (EmpathyAccountWidget *self, const char *filename) { - self->ui_details->gui = empathy_builder_get_file (filename, - "vbox_groupwise_settings", &self->ui_details->widget, - NULL); + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + if (priv->simple) + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_groupwise_simple", &self->ui_details->widget, + NULL); - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); + empathy_account_widget_handle_params (self, + "entry_id_simple", "account", + "entry_password_simple", "password", + NULL); - self->ui_details->default_focus = g_strdup ("entry_id"); - self->ui_details->add_forget = TRUE; + self->ui_details->default_focus = g_strdup ("entry_id_simple"); + } + else + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_groupwise_settings", &self->ui_details->widget, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + self->ui_details->add_forget = TRUE; + } } static void -- cgit v1.2.3 From f75d35f22aa745688f9fd932a5de6a6903b3db04 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 15:21:46 +0200 Subject: Implement a simple SIP widget --- libempathy-gtk/empathy-account-widget-sip.c | 81 ++++++++++++++++++----------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-sip.c b/libempathy-gtk/empathy-account-widget-sip.c index fedbf2aa6..afc20fecb 100644 --- a/libempathy-gtk/empathy-account-widget-sip.c +++ b/libempathy-gtk/empathy-account-widget-sip.c @@ -68,37 +68,58 @@ empathy_account_widget_sip_build (EmpathyAccountWidget *self, const char *filename) { EmpathyAccountWidgetSip *settings; - - settings = g_slice_new0 (EmpathyAccountWidgetSip); - settings->self = self; - - self->ui_details->gui = empathy_builder_get_file (filename, - "vbox_sip_settings", &settings->vbox_settings, - "entry_stun-server", &settings->entry_stun_server, - "spinbutton_stun-port", &settings->spinbutton_stun_part, - "checkbutton_discover-stun", &settings->checkbutton_discover_stun, - NULL); - - empathy_account_widget_handle_params (self, - "entry_userid", "account", - "entry_password", "password", - "checkbutton_discover-stun", "discover-stun", - "entry_stun-server", "stun-server", - "spinbutton_stun-port", "stun-port", - NULL); - - account_widget_sip_discover_stun_toggled_cb ( - settings->checkbutton_discover_stun, - settings); - - empathy_builder_connect (self->ui_details->gui, settings, - "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb, - "checkbutton_discover-stun", "toggled", + GtkWidget *vbox_settings; + gboolean is_simple; + + g_object_get (self, "simple", &is_simple, NULL); + + if (is_simple) + { + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_sip_simple", &vbox_settings, + NULL); + + empathy_account_widget_handle_params (self, + "entry_userid_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_userid_simple"); + } + else + { + settings = g_slice_new0 (EmpathyAccountWidgetSip); + settings->self = self; + + self->ui_details->gui = empathy_builder_get_file (filename, + "vbox_sip_settings", &vbox_settings, + "entry_stun-server", &settings->entry_stun_server, + "spinbutton_stun-port", &settings->spinbutton_stun_part, + "checkbutton_discover-stun", &settings->checkbutton_discover_stun, + NULL); + settings->vbox_settings = vbox_settings; + + empathy_account_widget_handle_params (self, + "entry_userid", "account", + "entry_password", "password", + "checkbutton_discover-stun", "discover-stun", + "entry_stun-server", "stun-server", + "spinbutton_stun-port", "stun-port", + NULL); + + account_widget_sip_discover_stun_toggled_cb ( + settings->checkbutton_discover_stun, + settings); + + empathy_builder_connect (self->ui_details->gui, settings, + "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb, + "checkbutton_discover-stun", "toggled", account_widget_sip_discover_stun_toggled_cb, - NULL); + NULL); - self->ui_details->add_forget = TRUE; - self->ui_details->default_focus = g_strdup ("entry_userid"); + self->ui_details->add_forget = TRUE; + self->ui_details->default_focus = g_strdup ("entry_userid"); + } - self->ui_details->widget = settings->vbox_settings; + self->ui_details->widget = vbox_settings; } -- cgit v1.2.3 From 3f21eaf356b78cd1e0a8c7d43818e85c7bc12e4a Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 15:22:29 +0200 Subject: Implement a generic simple widget --- libempathy-gtk/empathy-account-widget-generic.ui | 2 +- libempathy-gtk/empathy-account-widget.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-generic.ui b/libempathy-gtk/empathy-account-widget-generic.ui index 649307e06..ae97f3c98 100644 --- a/libempathy-gtk/empathy-account-widget-generic.ui +++ b/libempathy-gtk/empathy-account-widget-generic.ui @@ -29,7 +29,7 @@ - + True True diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 3bd8309fa..916de9502 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -377,6 +377,8 @@ accounts_widget_generic_setup (EmpathyAccountWidget *self, if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED) table_settings = table_common_settings; + else if (priv->simple) + return; else table_settings = table_advanced_settings; @@ -559,10 +561,16 @@ account_widget_build_generic (EmpathyAccountWidget *self, const char *filename) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + GtkWidget *expander_advanced; + self->ui_details->gui = empathy_builder_get_file (filename, "vbox_generic_settings", &self->ui_details->widget, + "expander_advanced_settings", &expander_advanced, NULL); + if (priv->simple) + gtk_widget_hide (expander_advanced); + g_object_ref (self->ui_details->gui); if (empathy_account_settings_is_ready (priv->settings)) @@ -805,7 +813,7 @@ account_widget_build_groupwise (EmpathyAccountWidget *self, const char *filename) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - + if (priv->simple) { self->ui_details->gui = empathy_builder_get_file (filename, @@ -886,6 +894,7 @@ do_get_property (GObject *object, break; case PROP_SIMPLE: g_value_set_boolean (value, priv->simple); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -921,7 +930,13 @@ do_constructed (GObject *obj) else if (!tp_strdiff (priv->protocol, "sip")) empathy_account_widget_sip_build (self, filename); else - account_widget_build_generic (self, filename); + { + g_free (filename); + + filename = empathy_file_lookup ( + "empathy-account-widget-generic.ui", "libempathy-gtk"); + account_widget_build_generic (self, filename); + } g_free (uiname); g_free (filename); -- cgit v1.2.3 From c037c417937a5a77a8c8bc168103cb3c5a19a659 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 15:22:36 +0200 Subject: Filter out IRC and local-xmpp in the wizard --- src/empathy-account-assistant.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 7a5f176cd..b7c5b28ed 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -21,6 +21,7 @@ /* empathy-account-assistant.c */ #include +#include #include "empathy-account-assistant.h" @@ -194,7 +195,10 @@ account_assistant_chooser_enter_details_filter_func ( TpConnectionManagerProtocol *protocol, gpointer user_data) { - /* TODO */ + if (!tp_strdiff (protocol->name, "local-xmpp") || + !tp_strdiff (protocol->name, "irc")) + return FALSE; + return TRUE; } -- cgit v1.2.3 From fa77756bd1db1c0b657fc784508890330bd5bfb3 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 18:21:47 +0200 Subject: Remove the parameters from the unset pool when we set them again --- libempathy/empathy-account-settings.c | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 5c4644d5a..ad7874d6c 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -515,6 +515,29 @@ empathy_account_settings_get_tp_param (EmpathyAccountSettings *settings, return NULL; } +static void +account_settings_remove_from_unset (EmpathyAccountSettings *settings, + const gchar *param) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + int idx; + gchar *val; + + for (idx = 0; idx < priv->unset_parameters->len; idx++) + { + val = g_array_index (priv->unset_parameters, gchar *, idx); + + if (!tp_strdiff (val, param)) + { + priv->unset_parameters = + g_array_remove_index (priv->unset_parameters, idx); + g_free (val); + + break; + } + } +} + const GValue * empathy_account_settings_get_default (EmpathyAccountSettings *settings, const gchar *param) @@ -572,7 +595,6 @@ empathy_account_settings_get (EmpathyAccountSettings *settings, return empathy_account_settings_get_default (settings, param); } - void empathy_account_settings_unset (EmpathyAccountSettings *settings, const gchar *param) @@ -768,6 +790,8 @@ empathy_account_settings_set_string (EmpathyAccountSettings *settings, EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); tp_asv_set_string (priv->parameters, g_strdup (param), value); + + account_settings_remove_from_unset (settings, param); } void @@ -778,6 +802,8 @@ empathy_account_settings_set_int32 (EmpathyAccountSettings *settings, EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); tp_asv_set_int32 (priv->parameters, g_strdup (param), value); + + account_settings_remove_from_unset (settings, param); } void @@ -788,6 +814,8 @@ empathy_account_settings_set_int64 (EmpathyAccountSettings *settings, EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); tp_asv_set_int64 (priv->parameters, g_strdup (param), value); + + account_settings_remove_from_unset (settings, param); } void @@ -798,6 +826,8 @@ empathy_account_settings_set_uint32 (EmpathyAccountSettings *settings, EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); tp_asv_set_uint32 (priv->parameters, g_strdup (param), value); + + account_settings_remove_from_unset (settings, param); } void @@ -808,6 +838,8 @@ empathy_account_settings_set_uint64 (EmpathyAccountSettings *settings, EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); tp_asv_set_uint64 (priv->parameters, g_strdup (param), value); + + account_settings_remove_from_unset (settings, param); } void @@ -818,6 +850,8 @@ empathy_account_settings_set_boolean (EmpathyAccountSettings *settings, EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); tp_asv_set_boolean (priv->parameters, g_strdup (param), value); + + account_settings_remove_from_unset (settings, param); } static void -- cgit v1.2.3 From caa57e8e5e3fbbad790e3825597a5b3ddd2f3175 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 18:22:32 +0200 Subject: React to entry changes immediately --- libempathy-gtk/empathy-account-widget.c | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 916de9502..27120c51a 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -76,6 +76,7 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget) +#define CHANGED_TIMEOUT 300 static void account_widget_handle_apply_sensitivity (EmpathyAccountWidget *self) @@ -91,26 +92,30 @@ account_widget_handle_apply_sensitivity (EmpathyAccountWidget *self) g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid); } -static gboolean -account_widget_entry_focus_cb (GtkWidget *widget, - GdkEventFocus *event, - EmpathyAccountWidget *self) +static void +account_widget_entry_changed_common (EmpathyAccountWidget *self, + GtkEntry *entry, gboolean focus) { const gchar *str; const gchar *param_name; EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - str = gtk_entry_get_text (GTK_ENTRY (widget)); - param_name = g_object_get_data (G_OBJECT (widget), "param_name"); + str = gtk_entry_get_text (entry); + param_name = g_object_get_data (G_OBJECT (entry), "param_name"); if (EMP_STR_EMPTY (str)) { const gchar *value = NULL; empathy_account_settings_unset (priv->settings, param_name); - value = empathy_account_settings_get_string (priv->settings, param_name); - DEBUG ("Unset %s and restore to %s", param_name, value); - gtk_entry_set_text (GTK_ENTRY (widget), value ? value : ""); + + if (focus) + { + value = empathy_account_settings_get_string (priv->settings, + param_name); + DEBUG ("Unset %s and restore to %s", param_name, value); + gtk_entry_set_text (entry, value ? value : ""); + } } else { @@ -120,10 +125,25 @@ account_widget_entry_focus_cb (GtkWidget *widget, } account_widget_handle_apply_sensitivity (self); +} + +static gboolean +account_widget_entry_focus_cb (GtkWidget *widget, + GdkEventFocus *event, + EmpathyAccountWidget *self) +{ + account_widget_entry_changed_common (self, GTK_ENTRY (widget), TRUE); return FALSE; } +static void +account_widget_entry_changed_cb (GtkEditable *entry, + EmpathyAccountWidget *self) +{ + account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE); +} + static void account_widget_int_changed_cb (GtkWidget *widget, EmpathyAccountWidget *self) @@ -314,6 +334,8 @@ account_widget_setup_widget (EmpathyAccountWidget *self, g_signal_connect (widget, "focus-out-event", G_CALLBACK (account_widget_entry_focus_cb), self); + g_signal_connect (widget, "changed", + G_CALLBACK (account_widget_entry_changed_cb), self); } else if (GTK_IS_TOGGLE_BUTTON (widget)) { -- cgit v1.2.3 From bc7cb0959c31644d271fc9945d17cd961dece03d Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 20:00:54 +0200 Subject: Support changing the filter func on the fly --- libempathy-gtk/empathy-protocol-chooser.c | 36 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index 9ba28baf6..70ba60b06 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -59,7 +59,7 @@ typedef struct { GtkListStore *store; - GtkTreeModel *filter_model; + gboolean dispose_run; EmpathyConnectionManagers *cms; @@ -232,9 +232,6 @@ protocol_chooser_constructed (GObject *object) G_TYPE_OBJECT, /* CM */ G_TYPE_POINTER); /* protocol */ - priv->filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (priv->store), - NULL); - /* Set the protocol sort function */ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store), COL_PROTOCOL, @@ -245,7 +242,7 @@ protocol_chooser_constructed (GObject *object) GTK_SORT_ASCENDING); gtk_combo_box_set_model (GTK_COMBO_BOX (object), - GTK_TREE_MODEL (priv->filter_model)); + GTK_TREE_MODEL (priv->store)); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, FALSE); @@ -295,12 +292,6 @@ protocol_chooser_dispose (GObject *object) priv->dispose_run = TRUE; - if (priv->filter_model) - { - g_object_unref (priv->filter_model); - priv->filter_model = NULL; - } - if (priv->store) { g_object_unref (priv->store); @@ -365,20 +356,25 @@ empathy_protocol_chooser_dup_selected ( EmpathyProtocolChooser *protocol_chooser, TpConnectionManagerProtocol **protocol) { - EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); GtkTreeIter iter; TpConnectionManager *cm = NULL; + GtkTreeModel *cur_model; g_return_val_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser), NULL); + /* get the current model from the chooser, as we could either be filtering + * or not. + */ + cur_model = gtk_combo_box_get_model (GTK_COMBO_BOX (protocol_chooser)); + if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (protocol_chooser), &iter)) { - gtk_tree_model_get (GTK_TREE_MODEL (priv->filter_model), &iter, + gtk_tree_model_get (GTK_TREE_MODEL (cur_model), &iter, COL_CM, &cm, -1); if (protocol != NULL) - gtk_tree_model_get (GTK_TREE_MODEL (priv->filter_model), &iter, + gtk_tree_model_get (GTK_TREE_MODEL (cur_model), &iter, COL_PROTOCOL, protocol, -1); } @@ -406,6 +402,7 @@ empathy_protocol_chooser_set_visible (EmpathyProtocolChooser *protocol_chooser, gpointer user_data) { EmpathyProtocolChooserPriv *priv; + GtkTreeModel *filter_model; g_return_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser)); @@ -413,9 +410,16 @@ empathy_protocol_chooser_set_visible (EmpathyProtocolChooser *protocol_chooser, priv->filter_func = func; priv->filter_user_data = user_data; + filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (priv->store), + NULL); + gtk_combo_box_set_model (GTK_COMBO_BOX (protocol_chooser), filter_model); + g_object_unref (filter_model); + gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER - (priv->filter_model), protocol_chooser_filter_visible_func, + (filter_model), protocol_chooser_filter_visible_func, protocol_chooser, NULL); - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model)); + gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model)); + + gtk_combo_box_set_active (GTK_COMBO_BOX (protocol_chooser), 0); } -- cgit v1.2.3 From 877ca07d5b79400863997df5c31180feec7103db Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 4 Aug 2009 20:01:30 +0200 Subject: Unify the enter and create page. Refactor a lot the surrounding code. Missing piece: adapting labels for the EmpathyAccountWidget in case of creation vs. entering details. --- src/empathy-account-assistant.c | 319 ++++++++++++++++++++++++++-------------- 1 file changed, 205 insertions(+), 114 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index b7c5b28ed..5fd125816 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -44,14 +44,197 @@ typedef enum { RESPONSE_SALUT_ONLY = 4 } FirstPageResponse; +enum { + PAGE_INTRO = 0, + PAGE_IMPORT = 1, + PAGE_ENTER_CREATE = 2, + PAGE_SALUT_ONLY = 3 +}; + typedef struct { FirstPageResponse first_resp; - GtkWidget *add_existing_page; + /* enter or create page */ + GtkWidget *enter_or_create_page; GtkWidget *current_account_widget; EmpathyAccountWidget *current_widget_object; + GtkWidget *first_label; + GtkWidget *second_label; + GtkWidget *chooser; + EmpathyAccountSettings *settings; } EmpathyAccountAssistantPriv; +static void +account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + + if (priv->settings == NULL) + return; + + empathy_account_settings_apply_async (priv->settings, NULL, NULL); +} + +static void +account_assistant_apply_cb (GtkAssistant *assistant, + gpointer user_data) +{ + EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant); + gint current_page; + + current_page = gtk_assistant_get_current_page (assistant); + + if (current_page == RESPONSE_ENTER_ACCOUNT) + account_assistant_apply_account_and_finish (self); +} + +static void +account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object, + gboolean is_valid, + EmpathyAccountAssistant *self) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + + gtk_assistant_set_page_complete (GTK_ASSISTANT (self), + priv->enter_or_create_page, is_valid); +} + +static void +account_assistant_protocol_changed_cb (GtkComboBox *chooser, + EmpathyAccountAssistant *self) +{ + TpConnectionManager *cm; + TpConnectionManagerProtocol *proto; + EmpathyAccountSettings *settings; + EmpathyAccountAssistantPriv *priv; + char *str; + GtkWidget *account_widget; + EmpathyAccountWidget *widget_object = NULL; + + priv = GET_PRIV (self); + + cm = empathy_protocol_chooser_dup_selected ( + EMPATHY_PROTOCOL_CHOOSER (chooser), &proto); + + if (cm == NULL || proto == NULL) + /* we are not ready yet */ + return; + + /* Create account */ + /* To translator: %s is the protocol name */ + str = g_strdup_printf (_("New %s account"), proto->name); + + settings = empathy_account_settings_new (cm->name, proto->name, str); + account_widget = empathy_account_widget_simple_new_for_protocol + (proto->name, settings, &widget_object); + + if (priv->current_account_widget != NULL) + { + g_signal_handlers_disconnect_by_func (priv->current_widget_object, + account_assistant_handle_apply_cb, self); + gtk_widget_destroy (priv->current_account_widget); + } + + priv->current_account_widget = account_widget; + priv->current_widget_object = widget_object; + priv->settings = settings; + + g_signal_connect (priv->current_widget_object, "handle-apply", + G_CALLBACK (account_assistant_handle_apply_cb), self); + + gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget, + FALSE, FALSE, 0); + gtk_widget_show (account_widget); + + g_free (str); +} + +static gboolean +account_assistant_chooser_enter_details_filter_func ( + TpConnectionManager *cm, + TpConnectionManagerProtocol *protocol, + gpointer user_data) +{ + if (!tp_strdiff (protocol->name, "local-xmpp") || + !tp_strdiff (protocol->name, "irc")) + return FALSE; + + return TRUE; +} + +static gboolean +account_assistant_chooser_create_account_filter_func ( + TpConnectionManager *cm, + TpConnectionManagerProtocol *protocol, + gpointer user_data) +{ + return tp_connection_manager_protocol_can_register (protocol); +} + +static void +account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self, + gboolean is_enter) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + + if (is_enter) + { + gtk_label_set_label (GTK_LABEL (priv->first_label), + _("What kind of chat account do you have?")); + gtk_label_set_label (GTK_LABEL (priv->second_label), + _("If you have other accounts to set up, you can do " + "that at any time\nfrom the Edit menu.")); + empathy_protocol_chooser_set_visible ( + EMPATHY_PROTOCOL_CHOOSER (priv->chooser), + account_assistant_chooser_enter_details_filter_func, self); + + gtk_assistant_set_page_title (GTK_ASSISTANT (self), + priv->enter_or_create_page, _("Enter your account details")); + } + else + { + gtk_label_set_label (GTK_LABEL (priv->first_label), + _("What kind of chat account do you want to create?")); + gtk_label_set_label (GTK_LABEL (priv->second_label), + _("You can register other accounts, or setup\n" + "an existing one at any time from the Edit menu.")); + empathy_protocol_chooser_set_visible ( + EMPATHY_PROTOCOL_CHOOSER (priv->chooser), + account_assistant_chooser_create_account_filter_func, self); + + gtk_assistant_set_page_title (GTK_ASSISTANT (self), + priv->enter_or_create_page, + _("Enter the details for the new account")); + } + + g_signal_connect (priv->chooser, "changed", + G_CALLBACK (account_assistant_protocol_changed_cb), self); + + /* trigger show the first account widget */ + account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self); +} + +static void +account_assistant_prepare_cb (GtkAssistant *assistant, + GtkWidget *current_page, + gpointer user_data) +{ + EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant); + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + gint current_idx; + + current_idx = gtk_assistant_get_current_page (assistant); + + g_print ("prepare, current idx = %d\n", current_idx); + + if (current_idx == PAGE_ENTER_CREATE) + { + account_assistant_finish_enter_or_create_page (self, + priv->first_resp == RESPONSE_ENTER_ACCOUNT ? + TRUE : FALSE); + } +} + static gint account_assistant_page_forward_func (gint current_page, gpointer user_data) @@ -63,7 +246,11 @@ account_assistant_page_forward_func (gint current_page, retval = current_page; if (current_page == 0) - retval = priv->first_resp; + { + if (priv->first_resp == RESPONSE_ENTER_ACCOUNT || + priv->first_resp == RESPONSE_CREATE_ACCOUNT) + retval = PAGE_ENTER_CREATE; + } g_print ("retval = %d\n", retval); return retval; @@ -189,82 +376,11 @@ account_assistant_build_import_page (EmpathyAccountAssistant *self) return main_vbox; } -static gboolean -account_assistant_chooser_enter_details_filter_func ( - TpConnectionManager *cm, - TpConnectionManagerProtocol *protocol, - gpointer user_data) -{ - if (!tp_strdiff (protocol->name, "local-xmpp") || - !tp_strdiff (protocol->name, "irc")) - return FALSE; - - return TRUE; -} - -static void -account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object, - gboolean is_valid, - EmpathyAccountAssistant *self) -{ - EmpathyAccountAssistantPriv *priv = GET_PRIV (self); - - gtk_assistant_set_page_complete (GTK_ASSISTANT (self), - priv->add_existing_page, is_valid); -} - -static void -account_assistant_protocol_changed_cb (GtkComboBox *chooser, - EmpathyAccountAssistant *self) -{ - TpConnectionManager *cm; - TpConnectionManagerProtocol *proto; - EmpathyAccountSettings *settings; - EmpathyAccountAssistantPriv *priv; - char *str; - GtkWidget *account_widget; - EmpathyAccountWidget *widget_object = NULL; - - priv = GET_PRIV (self); - - cm = empathy_protocol_chooser_dup_selected ( - EMPATHY_PROTOCOL_CHOOSER (chooser), &proto); - - if (cm == NULL || proto == NULL) - /* we are not ready yet */ - return; - - /* Create account */ - /* To translator: %s is the protocol name */ - str = g_strdup_printf (_("New %s account"), proto->name); - - settings = empathy_account_settings_new (cm->name, proto->name, str); - account_widget = empathy_account_widget_simple_new_for_protocol - (proto->name, settings, &widget_object); - - if (priv->current_account_widget != NULL) - { - g_signal_handlers_disconnect_by_func (priv->current_widget_object, - account_assistant_handle_apply_cb, self); - gtk_widget_destroy (priv->current_account_widget); - } - - priv->current_account_widget = account_widget; - priv->current_widget_object = widget_object; - - g_signal_connect (priv->current_widget_object, "handle-apply", - G_CALLBACK (account_assistant_handle_apply_cb), self); - - gtk_box_pack_start (GTK_BOX (priv->add_existing_page), account_widget, FALSE, - FALSE, 0); - gtk_widget_show (account_widget); - - g_free (str); -} - static GtkWidget * -account_assistant_build_enter_details_page (EmpathyAccountAssistant *self) +account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self, + gboolean is_enter) { + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); GtkWidget *main_vbox, *w, *chooser, *hbox; PangoAttrList *list; @@ -272,9 +388,11 @@ account_assistant_build_enter_details_page (EmpathyAccountAssistant *self) gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); gtk_widget_show (main_vbox); - w = gtk_label_new (_("What kind of chat account do you have?")); + w = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (w), 0, 0); gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + priv->first_label = w; w = gtk_alignment_new (0, 0, 0, 0); gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0); @@ -282,16 +400,9 @@ account_assistant_build_enter_details_page (EmpathyAccountAssistant *self) gtk_widget_show (w); chooser = empathy_protocol_chooser_new (); - empathy_protocol_chooser_set_visible (EMPATHY_PROTOCOL_CHOOSER (chooser), - account_assistant_chooser_enter_details_filter_func, self); gtk_container_add (GTK_CONTAINER (w), chooser); gtk_widget_show (chooser); - - g_signal_connect (chooser, "changed", - G_CALLBACK (account_assistant_protocol_changed_cb), self); - - /* trigger show the first account widget */ - account_assistant_protocol_changed_cb (GTK_COMBO_BOX (chooser), self); + priv->chooser = chooser; hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_end (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); @@ -301,35 +412,18 @@ account_assistant_build_enter_details_page (EmpathyAccountAssistant *self) gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); gtk_widget_show (w); - w = gtk_label_new (_("If you have other accounts to set up, you can do " - "that at any time\nfrom the Edit menu.")); + w = gtk_label_new (NULL); gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); list = pango_attr_list_new (); pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_SMALL)); gtk_label_set_attributes (GTK_LABEL (w), list); gtk_widget_show (w); + priv->second_label = w; pango_attr_list_unref (list); return main_vbox; } -static GtkWidget * -account_assistant_build_create_account_page (EmpathyAccountAssistant *self) -{ - GtkWidget *main_vbox, *w; - - main_vbox = gtk_vbox_new (FALSE, 12); - gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); - gtk_widget_show (main_vbox); - - w = gtk_label_new (_("What kind of chat account do you want to create?")); - gtk_misc_set_alignment (GTK_MISC (w), 0, 0); - gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - return main_vbox; -} - static void empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) { @@ -350,6 +444,11 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) gtk_assistant_set_forward_page_func (assistant, account_assistant_page_forward_func, self, NULL); + g_signal_connect (self, "apply", + G_CALLBACK (account_assistant_apply_cb), NULL); + g_signal_connect (self, "prepare", + G_CALLBACK (account_assistant_prepare_cb), NULL); + /* first page (introduction) */ page = account_assistant_build_introduction_page (self); gtk_assistant_append_page (assistant, page); @@ -370,18 +469,10 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) gtk_assistant_set_page_complete (assistant, page, TRUE); /* third page (enter account details) */ - page = account_assistant_build_enter_details_page (self); + page = account_assistant_build_enter_or_create_page (self, TRUE); gtk_assistant_append_page (assistant, page); - gtk_assistant_set_page_title (assistant, page, - _("Enter your account details")); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); - priv->add_existing_page = page; - - /* fourth page (create a new account) */ - page = account_assistant_build_create_account_page (self); - gtk_assistant_append_page (assistant, page); - gtk_assistant_set_page_title (assistant, page, - _("Enter the details of the new account")); + priv->enter_or_create_page = page; } GtkWidget * -- cgit v1.2.3 From 3962f6f8d1680b6a304577dbc1ed366c33f6b206 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 5 Aug 2009 12:02:39 +0200 Subject: Change labels when creating an account --- libempathy-gtk/empathy-account-widget-jabber.ui | 28 +++++++++++++++++++++---- libempathy-gtk/empathy-account-widget.c | 14 +++++++++++++ src/empathy-account-assistant.c | 4 ++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-jabber.ui b/libempathy-gtk/empathy-account-widget-jabber.ui index a2165393c..164bbcdf9 100644 --- a/libempathy-gtk/empathy-account-widget-jabber.ui +++ b/libempathy-gtk/empathy-account-widget-jabber.ui @@ -351,7 +351,6 @@ True vertical - 6 True @@ -362,6 +361,15 @@ 0 + + + 0 + What is your desired Jabber ID? + + + 1 + + True @@ -369,6 +377,7 @@ 0 0.34999999403953552 0.34999999403953552 + 6 12 @@ -379,17 +388,28 @@ - 1 + 2 True 0 + 6 What is your Jabber password? - 2 + 3 + + + + + 0 + 6 + What is your desired Jabber password? + + + 4 @@ -410,7 +430,7 @@ - 3 + 5 diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 27120c51a..713f50048 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -666,12 +666,26 @@ account_widget_build_jabber (EmpathyAccountWidget *self, EmpathyAccountWidgetPriv *priv = GET_PRIV (self); GtkWidget *spinbutton_port; GtkWidget *checkbutton_ssl; + GtkWidget *label_id, *label_password; + GtkWidget *label_id_create, *label_password_create; if (priv->simple) { self->ui_details->gui = empathy_builder_get_file (filename, "vbox_jabber_simple", &self->ui_details->widget, + "label_id_simple", &label_id, + "label_id_create", &label_id_create, + "label_password_simple", &label_password, + "label_password_create", &label_password_create, NULL); + + if (empathy_account_settings_get_boolean (priv->settings, "register")) + { + gtk_widget_hide (label_id); + gtk_widget_hide (label_password); + gtk_widget_show (label_id_create); + gtk_widget_show (label_password_create); + } empathy_account_widget_handle_params (self, "entry_id_simple", "account", diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 5fd125816..91ba26b68 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -125,6 +125,10 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser, str = g_strdup_printf (_("New %s account"), proto->name); settings = empathy_account_settings_new (cm->name, proto->name, str); + + if (priv->first_resp == RESPONSE_CREATE_ACCOUNT) + empathy_account_settings_set_boolean (settings, "register", TRUE); + account_widget = empathy_account_widget_simple_new_for_protocol (proto->name, settings, &widget_object); -- cgit v1.2.3 From 06c242f4125d7a48667b069ac53902894cbcdf10 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 5 Aug 2009 12:06:29 +0200 Subject: Unref settings when changing the protocol --- src/empathy-account-assistant.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 91ba26b68..852ea4534 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -141,6 +141,10 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser, priv->current_account_widget = account_widget; priv->current_widget_object = widget_object; + + if (priv->settings != NULL) + g_object_unref (priv->settings); + priv->settings = settings; g_signal_connect (priv->current_widget_object, "handle-apply", -- cgit v1.2.3 From 665eea7db24e59db641803d5d778f0fbc58eebe7 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 5 Aug 2009 12:08:17 +0200 Subject: Fix long line --- libempathy/empathy-account-settings.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index ad7874d6c..ce0ba1bfa 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -915,7 +915,8 @@ empathy_account_settings_set_display_name_finish ( return FALSE; g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (settings), empathy_account_settings_set_display_name_finish), FALSE); + G_OBJECT (settings), empathy_account_settings_set_display_name_finish), + FALSE); return TRUE; } -- cgit v1.2.3 From bca9fa60a556e96dbad090afcfd407dab7a4532d Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 5 Aug 2009 16:38:55 +0200 Subject: Add a parent window property to the assistant --- src/empathy-account-assistant.c | 71 +++++++++++++++++++++++++++++++++- src/empathy-account-assistant.h | 2 +- src/empathy.c | 10 ++++- tests/test-empathy-account-assistant.c | 2 +- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 852ea4534..e92826688 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -51,6 +51,10 @@ enum { PAGE_SALUT_ONLY = 3 }; +enum { + PROP_PARENT = 1 +}; + typedef struct { FirstPageResponse first_resp; @@ -432,9 +436,71 @@ account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self, return main_vbox; } +static void +do_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (object); + + switch (property_id) + { + case PROP_PARENT: + g_value_set_object (value, priv->parent_window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +do_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (object); + + switch (property_id) + { + case PROP_PARENT: + priv->parent_window = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +do_constructed (GObject *object) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (object); + + /* set us as transient for the parent window if any */ + if (priv->parent_window) + gtk_window_set_transient_for (GTK_WINDOW (object), + priv->parent_window); + + gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG); +} + static void empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) { + GObjectClass *oclass = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + oclass->get_property = do_get_property; + oclass->set_property = do_set_property; + oclass->constructed = do_constructed; + + param_spec = g_param_spec_object ("parent-window", + "parent-window", "The parent window", + GTK_TYPE_WINDOW, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_PARENT, param_spec); + g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv)); } @@ -484,7 +550,8 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) } GtkWidget * -empathy_account_assistant_new (void) +empathy_account_assistant_new (GtkWindow *window) { - return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, NULL); + return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, "parent-window", + window, NULL); } diff --git a/src/empathy-account-assistant.h b/src/empathy-account-assistant.h index 82b14e312..857460201 100644 --- a/src/empathy-account-assistant.h +++ b/src/empathy-account-assistant.h @@ -56,7 +56,7 @@ typedef struct { GType empathy_account_assistant_get_type (void); -GtkWidget *empathy_account_assistant_new (void); +GtkWidget *empathy_account_assistant_new (GtkWindow *parent); G_END_DECLS diff --git a/src/empathy.c b/src/empathy.c index b80b64be7..acfdcb13e 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -63,6 +63,7 @@ #include #include +#include "empathy-account-assistant.h" #include "empathy-accounts-dialog.h" #include "empathy-main-window.h" #include "empathy-status-icon.h" @@ -532,12 +533,17 @@ account_manager_ready_cb (EmpathyAccountManager *manager, GParamSpec *spec, gpointer user_data) { + GtkWidget *assistant; + if (!empathy_account_manager_is_ready (manager)) return; if (empathy_account_manager_get_count (manager) == 0) - empathy_accounts_dialog_show (GTK_WINDOW (empathy_main_window_get ()), - NULL); + { + assistant = empathy_account_assistant_new ( + GTK_WINDOW (empathy_main_window_get ())); + gtk_window_present (GTK_WINDOW (assistant)); + } create_salut_account (); } diff --git a/tests/test-empathy-account-assistant.c b/tests/test-empathy-account-assistant.c index f1f519d77..6d1330eeb 100644 --- a/tests/test-empathy-account-assistant.c +++ b/tests/test-empathy-account-assistant.c @@ -12,7 +12,7 @@ int main (int argc, char **argv) gtk_init (&argc, &argv); empathy_gtk_init (); - assistant = empathy_account_assistant_new (); + assistant = empathy_account_assistant_new (NULL); gtk_widget_show_all (assistant); -- cgit v1.2.3 From ce3eb60be50a9571bde936eccecc800ee54080f1 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 5 Aug 2009 16:39:20 +0200 Subject: Report back errors (right now just on stdout) --- src/empathy-account-assistant.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index e92826688..567ddc67b 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -66,8 +66,24 @@ typedef struct { GtkWidget *second_label; GtkWidget *chooser; EmpathyAccountSettings *settings; + + GtkWindow *parent_window; } EmpathyAccountAssistantPriv; +static void +account_assistant_apply_account_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + + empathy_account_settings_apply_finish (EMPATHY_ACCOUNT_SETTINGS (source), + result, &error); + + if (error != NULL) + g_print ("error applying %s\n", error->message); +} + static void account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self) { @@ -76,7 +92,8 @@ account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self) if (priv->settings == NULL) return; - empathy_account_settings_apply_async (priv->settings, NULL, NULL); + empathy_account_settings_apply_async (priv->settings, + account_assistant_apply_account_cb, self); } static void -- cgit v1.2.3 From 84fbdb813bbb7f29aceedbd7293dcb10c499d660 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 5 Aug 2009 16:39:47 +0200 Subject: Don't forward anymore after the end --- src/empathy-account-assistant.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 567ddc67b..4c7062b9d 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -281,6 +281,12 @@ account_assistant_page_forward_func (gint current_page, retval = PAGE_ENTER_CREATE; } + if (current_page == PAGE_ENTER_CREATE) + { + /* don't forward anymore */ + retval = -1; + } + g_print ("retval = %d\n", retval); return retval; } -- cgit v1.2.3 From 9aafbf8e9f92b270036f61622ece41461342a279 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 5 Aug 2009 16:39:57 +0200 Subject: Fix long lines --- src/empathy.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/empathy.c b/src/empathy.c index acfdcb13e..15672c8df 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -116,8 +116,8 @@ dispatch_cb (EmpathyDispatcher *dispatcher, manager = empathy_account_manager_dup_singleton (); connection = empathy_tp_chat_get_connection (tp_chat); - account = empathy_account_manager_get_account_for_connection (manager, - connection); + account = empathy_account_manager_get_account_for_connection ( + manager, connection); chat = empathy_chat_window_find_chat (account, id); g_object_unref (manager); } @@ -380,7 +380,8 @@ migrate_config_to_xdg_dir (void) return; } - old_dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + old_dir = g_build_filename (g_get_home_dir (), ".gnome2", + PACKAGE_NAME, NULL); if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { /* old config dir didn't exist */ -- cgit v1.2.3 From b264035637b60c6fc09839f2a58f2bc16f573113 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 15:39:00 +0200 Subject: Report errors during creation --- src/empathy-account-assistant.c | 118 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 4c7062b9d..dc83330a0 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -70,18 +70,134 @@ typedef struct { GtkWindow *parent_window; } EmpathyAccountAssistantPriv; +static GtkWidget * +account_assistant_build_error_page (EmpathyAccountAssistant *self, + GError *error, gint page_num) +{ + GtkWidget *main_vbox, *w, *hbox; + GString *str; + char *message; + PangoAttrList *list; + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + + main_vbox = gtk_vbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); + gtk_widget_show (main_vbox); + + hbox = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, + GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + /* translators: this is followed by the "while ..." strings some lines + * down this file. + */ + str = g_string_new (_("There has been an error\n")); + + if (page_num == PAGE_IMPORT) + /* translators: this follows the "There has been an error " string */ + str = g_string_append (str, _("while importing the accounts.")); + else if (page_num == PAGE_ENTER_CREATE && + priv->first_resp == RESPONSE_ENTER_ACCOUNT) + /* translators: this follows the "There has been an error " string */ + str = g_string_append (str, _("while parsing the account details.")); + else if (page_num == PAGE_ENTER_CREATE && + priv->first_resp == RESPONSE_CREATE_ACCOUNT) + /* translators: this follows the "There has been an error " string */ + str = g_string_append (str, _("while creating the account.")); + + message = g_string_free (str, FALSE); + + w = gtk_label_new (message); + gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); + list = pango_attr_list_new (); + pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_LARGE)); + pango_attr_list_insert (list, pango_attr_weight_new (PANGO_WEIGHT_BOLD)); + gtk_label_set_attributes (GTK_LABEL (w), list); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); + gtk_widget_show (w); + + g_free (message); + pango_attr_list_unref (list); + + message = g_markup_printf_escaped + (_("The error message was: %s"), + error->message); + w = gtk_label_new (message); + gtk_label_set_use_markup (GTK_LABEL (w), TRUE); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); + gtk_widget_show (w); + + w = gtk_label_new (_("You can either go back and try to enter your " + "accounts' details\nagain or quit this wizard and add accounts " + "later from the Edit menu.")); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6); + gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); + gtk_widget_show (w); + + return main_vbox; +} + +static void +account_assistant_back_button_clicked_cb (GtkButton *button, + EmpathyAccountAssistant *self) +{ + gint page_num; + + page_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), + "page-num")); + gtk_assistant_remove_action_widget (GTK_ASSISTANT (self), + GTK_WIDGET (button)); + gtk_assistant_set_current_page (GTK_ASSISTANT (self), page_num); +} + +static void +account_assistant_present_error_page (EmpathyAccountAssistant *self, + GError *error, gint page_num) +{ + GtkWidget *error_page, *back_button; + gint num; + + error_page = account_assistant_build_error_page (self, error, + page_num); + num = gtk_assistant_append_page (GTK_ASSISTANT (self), error_page); + gtk_assistant_set_page_title (GTK_ASSISTANT (self), error_page, + _("An error occurred")); + gtk_assistant_set_page_type (GTK_ASSISTANT (self), error_page, + GTK_ASSISTANT_PAGE_SUMMARY); + + back_button = gtk_button_new_from_stock (GTK_STOCK_GO_BACK); + gtk_assistant_add_action_widget (GTK_ASSISTANT (self), back_button); + g_object_set_data (G_OBJECT (back_button), + "page-num", GINT_TO_POINTER (page_num)); + g_signal_connect (back_button, "clicked", + G_CALLBACK (account_assistant_back_button_clicked_cb), self); + gtk_widget_show (back_button); + + gtk_assistant_set_current_page (GTK_ASSISTANT (self), num); +} + static void account_assistant_apply_account_cb (GObject *source, GAsyncResult *result, gpointer user_data) { GError *error = NULL; + EmpathyAccountAssistant *self = user_data; empathy_account_settings_apply_finish (EMPATHY_ACCOUNT_SETTINGS (source), result, &error); if (error != NULL) - g_print ("error applying %s\n", error->message); + { + account_assistant_present_error_page (self, error, PAGE_ENTER_CREATE); + g_error_free (error); + } } static void -- cgit v1.2.3 From f9cbc778a336d3a891d67914d289841222fb679b Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 19:19:49 +0200 Subject: Implement dispose --- src/empathy-account-assistant.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index dc83330a0..5bcd602e7 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -68,6 +68,8 @@ typedef struct { EmpathyAccountSettings *settings; GtkWindow *parent_window; + + gboolean dispose_run; } EmpathyAccountAssistantPriv; static GtkWidget * @@ -624,6 +626,26 @@ do_constructed (GObject *object) gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG); } +static void +do_dispose (GObject *obj) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (obj); + + if (priv->dispose_run) + return; + + priv->dispose_run = TRUE; + + if (priv->settings != NULL) + { + g_object_unref (priv->settings); + priv->settings = NULL; + } + + if (G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose != NULL) + G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose (obj); +} + static void empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) { @@ -633,6 +655,7 @@ empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) oclass->get_property = do_get_property; oclass->set_property = do_set_property; oclass->constructed = do_constructed; + oclass->dispose = do_dispose; param_spec = g_param_spec_object ("parent-window", "parent-window", "The parent window", -- cgit v1.2.3 From 1d0f90da95786ef6143460ed7234156ec9c46936 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 19:19:56 +0200 Subject: Enable newly created accounts --- src/empathy-account-assistant.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 5bcd602e7..9291cd30c 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -191,15 +191,21 @@ account_assistant_apply_account_cb (GObject *source, { GError *error = NULL; EmpathyAccountAssistant *self = user_data; + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source); + EmpathyAccount *account; - empathy_account_settings_apply_finish (EMPATHY_ACCOUNT_SETTINGS (source), - result, &error); + empathy_account_settings_apply_finish (settings, result, &error); if (error != NULL) { account_assistant_present_error_page (self, error, PAGE_ENTER_CREATE); g_error_free (error); + return; } + + /* enable the newly created account */ + account = empathy_account_settings_get_account (settings); + empathy_account_set_enabled (account, TRUE); } static void -- cgit v1.2.3 From 2cfd3d52a13089bd00c863a2ff2a721ec04190b5 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 19:20:28 +0200 Subject: Add a comment over the window type hint --- src/empathy-account-assistant.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 9291cd30c..91d90c83c 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -629,6 +629,7 @@ do_constructed (GObject *object) gtk_window_set_transient_for (GTK_WINDOW (object), priv->parent_window); + /* set the dialog hint, so this will be centered over the parent window */ gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG); } -- cgit v1.2.3 From a4f73e80b9f3015356fd0ee7d33fc0c7a8a21c8c Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 19:55:36 +0200 Subject: Implement close and cancel; Also, move to implementing GTK+ signals rather than connecting --- src/empathy-account-assistant.c | 101 ++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 91d90c83c..4e9044fdf 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -220,19 +220,6 @@ account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self) account_assistant_apply_account_cb, self); } -static void -account_assistant_apply_cb (GtkAssistant *assistant, - gpointer user_data) -{ - EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant); - gint current_page; - - current_page = gtk_assistant_get_current_page (assistant); - - if (current_page == RESPONSE_ENTER_ACCOUNT) - account_assistant_apply_account_and_finish (self); -} - static void account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object, gboolean is_valid, @@ -367,27 +354,6 @@ account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self, account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self); } -static void -account_assistant_prepare_cb (GtkAssistant *assistant, - GtkWidget *current_page, - gpointer user_data) -{ - EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant); - EmpathyAccountAssistantPriv *priv = GET_PRIV (self); - gint current_idx; - - current_idx = gtk_assistant_get_current_page (assistant); - - g_print ("prepare, current idx = %d\n", current_idx); - - if (current_idx == PAGE_ENTER_CREATE) - { - account_assistant_finish_enter_or_create_page (self, - priv->first_resp == RESPONSE_ENTER_ACCOUNT ? - TRUE : FALSE); - } -} - static gint account_assistant_page_forward_func (gint current_page, gpointer user_data) @@ -421,12 +387,22 @@ account_assistant_radio_choice_toggled_cb (GtkToggleButton *button, { FirstPageResponse response; EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + GtkWidget *intro_page; response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "response")); - g_print ("choice %d toggled\n", response); priv->first_resp = response; + + intro_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (self), + PAGE_INTRO); + + if (response == RESPONSE_SALUT_ONLY) + gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page, + GTK_ASSISTANT_PAGE_SUMMARY); + else + gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page, + GTK_ASSISTANT_PAGE_INTRO); } static GtkWidget * @@ -583,6 +559,50 @@ account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self, return main_vbox; } +static void +impl_signal_apply (GtkAssistant *assistant) +{ + EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant); + gint current_page; + + current_page = gtk_assistant_get_current_page (assistant); + + if (current_page == RESPONSE_ENTER_ACCOUNT) + account_assistant_apply_account_and_finish (self); +} + +static void +impl_signal_close (GtkAssistant *assistant) +{ + gtk_widget_destroy (GTK_WIDGET (assistant)); +} + +static void +impl_signal_cancel (GtkAssistant *assistant) +{ + gtk_widget_destroy (GTK_WIDGET (assistant)); +} + +static void +impl_signal_prepare (GtkAssistant *assistant, + GtkWidget *current_page) +{ + EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant); + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + gint current_idx; + + current_idx = gtk_assistant_get_current_page (assistant); + + g_print ("prepare, current idx = %d\n", current_idx); + + if (current_idx == PAGE_ENTER_CREATE) + { + account_assistant_finish_enter_or_create_page (self, + priv->first_resp == RESPONSE_ENTER_ACCOUNT ? + TRUE : FALSE); + } +} + static void do_get_property (GObject *object, guint property_id, @@ -657,6 +677,7 @@ static void empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) { GObjectClass *oclass = G_OBJECT_CLASS (klass); + GtkAssistantClass *gtkclass = GTK_ASSISTANT_CLASS (klass); GParamSpec *param_spec; oclass->get_property = do_get_property; @@ -664,6 +685,11 @@ empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) oclass->constructed = do_constructed; oclass->dispose = do_dispose; + gtkclass->apply = impl_signal_apply; + gtkclass->prepare = impl_signal_prepare; + gtkclass->close = impl_signal_close; + gtkclass->cancel = impl_signal_cancel; + param_spec = g_param_spec_object ("parent-window", "parent-window", "The parent window", GTK_TYPE_WINDOW, @@ -687,11 +713,6 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) gtk_assistant_set_forward_page_func (assistant, account_assistant_page_forward_func, self, NULL); - g_signal_connect (self, "apply", - G_CALLBACK (account_assistant_apply_cb), NULL); - g_signal_connect (self, "prepare", - G_CALLBACK (account_assistant_prepare_cb), NULL); - /* first page (introduction) */ page = account_assistant_build_introduction_page (self); gtk_assistant_append_page (assistant, page); -- cgit v1.2.3 From 23d4544855656cfdc9cf65ed94801191002e86ce Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 21:13:09 +0200 Subject: Make the set_enabled API async --- libempathy/empathy-account.c | 57 +++++++++++++++++++++++++++++++++----------- libempathy/empathy-account.h | 7 ++++-- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5a6b31f0a..2dd662874 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -132,7 +132,8 @@ empathy_account_set_property (GObject *object, switch (prop_id) { case PROP_ENABLED: - empathy_account_set_enabled (account, g_value_get_boolean (value)); + empathy_account_set_enabled_async (account, + g_value_get_boolean (value), NULL, NULL); break; case PROP_UNIQUE_NAME: priv->unique_name = g_value_dup_string (value); @@ -915,30 +916,58 @@ _empathy_account_set_connection (EmpathyAccount *account, g_object_notify (G_OBJECT (account), "connection"); } +static void +account_enabled_set_cb (TpProxy *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) + g_simple_async_result_set_from_error (result, (GError *) error); + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +gboolean +empathy_account_set_enabled_finish (EmpathyAccount *account, + GAsyncResult *result, + GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error) || + !g_simple_async_result_is_valid (result, G_OBJECT (account), + empathy_account_set_enabled_finish)) + return FALSE; + + return TRUE; +} + void -empathy_account_set_enabled (EmpathyAccount *account, - gboolean enabled) +empathy_account_set_enabled_async (EmpathyAccount *account, + gboolean enabled, + GAsyncReadyCallback callback, + gpointer user_data) { EmpathyAccountPriv *priv = GET_PRIV (account); GValue value = {0, }; + GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account), + callback, user_data, empathy_account_set_enabled_finish); if (priv->enabled == enabled) - return; + { + g_simple_async_result_complete_in_idle (result); + return; + } g_value_init (&value, G_TYPE_BOOLEAN); g_value_set_boolean (&value, enabled); tp_cli_dbus_properties_call_set (TP_PROXY (priv->account), - -1, - TP_IFACE_ACCOUNT, - "Enabled", - &value, - NULL, - NULL, - NULL, - NULL); - - g_value_unset (&value); + -1, TP_IFACE_ACCOUNT, "Enabled", &value, + account_enabled_set_cb, result, NULL, G_OBJECT (account)); } static void diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index 6351c9316..f88ac43e4 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -67,8 +67,11 @@ const gchar *empathy_account_get_connection_manager (EmpathyAccount *account); const gchar *empathy_account_get_protocol (EmpathyAccount *account); const gchar *empathy_account_get_icon_name (EmpathyAccount *account); -void empathy_account_set_enabled (EmpathyAccount *account, - gboolean enabled); +void empathy_account_set_enabled_async (EmpathyAccount *account, + gboolean enabled, GAsyncReadyCallback callback, gpointer user_data); +gboolean empathy_account_set_enabled_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error); + gboolean empathy_account_is_enabled (EmpathyAccount *account); gboolean empathy_account_is_valid (EmpathyAccount *account); -- cgit v1.2.3 From 85883a63be4daae817ed194ba6fa014266d27c09 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 21:13:31 +0200 Subject: Port to new API --- src/empathy-accounts-dialog.c | 2 +- src/empathy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 8b896676d..391c42b6d 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -446,7 +446,7 @@ accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer, return; enabled = empathy_account_is_enabled (account); - empathy_account_set_enabled (account, !enabled); + empathy_account_set_enabled_async (account, !enabled, NULL, NULL); DEBUG ("%s account %s", enabled ? "Disabled" : "Enable", empathy_account_get_display_name (account)); diff --git a/src/empathy.c b/src/empathy.c index 15672c8df..650129ebb 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -216,7 +216,7 @@ salut_account_created (GObject *source, account = empathy_account_settings_get_account (settings); - empathy_account_set_enabled (account, TRUE); + empathy_account_set_enabled_async (account, TRUE, NULL, NULL); empathy_conf_set_bool (empathy_conf_get (), EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, TRUE); -- cgit v1.2.3 From b047c404615a4137ced83c40d214f1092fbc733b Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 21:17:16 +0200 Subject: Emit the close signal only after we are done with the async machinery. --- src/empathy-account-assistant.c | 53 ++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 4e9044fdf..f5ef3c7f5 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -66,6 +66,7 @@ typedef struct { GtkWidget *second_label; GtkWidget *chooser; EmpathyAccountSettings *settings; + gboolean is_creating; GtkWindow *parent_window; @@ -184,6 +185,26 @@ account_assistant_present_error_page (EmpathyAccountAssistant *self, gtk_assistant_set_current_page (GTK_ASSISTANT (self), num); } +static void +account_assistant_account_enabled_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + EmpathyAccountAssistant *self = user_data; + + empathy_account_set_enabled_finish (EMPATHY_ACCOUNT (source), + result, &error); + + if (error) + { + g_warning ("Error enabling an account: %s", error->message); + g_error_free (error); + } + + g_signal_emit_by_name (self, "close"); +} + static void account_assistant_apply_account_cb (GObject *source, GAsyncResult *result, @@ -191,11 +212,14 @@ account_assistant_apply_account_cb (GObject *source, { GError *error = NULL; EmpathyAccountAssistant *self = user_data; + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source); EmpathyAccount *account; empathy_account_settings_apply_finish (settings, result, &error); + priv->is_creating = FALSE; + if (error != NULL) { account_assistant_present_error_page (self, error, PAGE_ENTER_CREATE); @@ -205,7 +229,8 @@ account_assistant_apply_account_cb (GObject *source, /* enable the newly created account */ account = empathy_account_settings_get_account (settings); - empathy_account_set_enabled (account, TRUE); + empathy_account_set_enabled_async (account, TRUE, + account_assistant_account_enabled_cb, self); } static void @@ -216,6 +241,8 @@ account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self) if (priv->settings == NULL) return; + priv->is_creating = TRUE; + empathy_account_settings_apply_async (priv->settings, account_assistant_apply_account_cb, self); } @@ -559,24 +586,32 @@ account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self, return main_vbox; } +static void +account_assistant_close_cb (GtkAssistant *assistant, + gpointer user_data) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (assistant); + + if (priv->is_creating) + return; + + gtk_widget_destroy (GTK_WIDGET (assistant)); +} + static void impl_signal_apply (GtkAssistant *assistant) { EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant); + // EmpathyAccountAssistantPriv *priv = GET_PRIV (self); gint current_page; + g_print ("apply!!\n"); current_page = gtk_assistant_get_current_page (assistant); if (current_page == RESPONSE_ENTER_ACCOUNT) account_assistant_apply_account_and_finish (self); } -static void -impl_signal_close (GtkAssistant *assistant) -{ - gtk_widget_destroy (GTK_WIDGET (assistant)); -} - static void impl_signal_cancel (GtkAssistant *assistant) { @@ -687,7 +722,6 @@ empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass) gtkclass->apply = impl_signal_apply; gtkclass->prepare = impl_signal_prepare; - gtkclass->close = impl_signal_close; gtkclass->cancel = impl_signal_cancel; param_spec = g_param_spec_object ("parent-window", @@ -710,6 +744,9 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) EmpathyAccountAssistantPriv); self->priv = priv; + g_signal_connect (self, "close", + G_CALLBACK (account_assistant_close_cb), NULL); + gtk_assistant_set_forward_page_func (assistant, account_assistant_page_forward_func, self, NULL); -- cgit v1.2.3 From 1ca4a9ee58260df26a03bc6565867b7958333f4c Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Tue, 28 Jul 2009 15:07:53 +0200 Subject: Remove the hardcode --- src/empathy-accounts-dialog.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 391c42b6d..3532e97f4 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -134,34 +134,24 @@ accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, static GtkWidget * get_account_setup_widget (EmpathyAccountSettings *settings) { - const gchar *cm = empathy_account_settings_get_cm (settings); const gchar *proto = empathy_account_settings_get_protocol (settings); + EmpathyConnectionManagers *cm = + empathy_connection_managers_dup_singleton (); + GList *cms = empathy_connection_managers_get_cms (cm); + GList *l; - struct { - const gchar *cm; - const gchar *proto; - } dialogs[] = { - { "gabble", "jabber" }, - { "butterfly", "msn" }, - { "salut", "local-xmpp" }, - { "idle", "irc" }, - { "haze", "icq" }, - { "haze", "aim" }, - { "haze", "yahoo" }, - { "haze", "groupwise" }, - { "sofiasip", "sip" }, - { NULL, NULL } - }; - int i; - - for (i = 0; dialogs[i].cm != NULL; i++) + for (l = cms; l; l = l->next) { - if (!tp_strdiff (cm, dialogs[i].cm) - && !tp_strdiff (proto, dialogs[i].proto)) - return empathy_account_widget_new_for_protocol (dialogs[i].proto, - settings); + TpConnectionManager *tp_cm = l->data; + if (tp_connection_manager_has_protocol (tp_cm, proto)) + { + g_object_unref (cm); + return empathy_account_widget_new_for_protocol + (proto, settings); + } } + g_object_unref (cm); return empathy_account_widget_new_for_protocol ("generic", settings); } -- cgit v1.2.3 From 2f019885754917e5130b35d167cadb4c5ca966d5 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 7 Aug 2009 17:21:56 +0200 Subject: Split EmpathyImportDialog and EmpathyImportWidget Also, take this as a chance to GObject-ify everything. --- src/empathy-import-dialog.c | 493 ++++++++++++++----------------------------- src/empathy-import-dialog.h | 39 +++- src/empathy-import-dialog.ui | 78 ++----- src/empathy-import-widget.c | 464 ++++++++++++++++++++++++++++++++++++++++ src/empathy-import-widget.h | 68 ++++++ 5 files changed, 739 insertions(+), 403 deletions(-) create mode 100644 src/empathy-import-widget.c create mode 100644 src/empathy-import-widget.h diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c index a70a6eedd..4866b81c5 100644 --- a/src/empathy-import-dialog.c +++ b/src/empathy-import-dialog.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2008-2009 Collabora Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -17,7 +17,8 @@ * Boston, MA 02110-1301 USA * * Authors: Jonny Lamb - * */ + * Cosimo Cecchi + */ #include @@ -31,6 +32,7 @@ #include "empathy-import-dialog.h" #include "empathy-import-pidgin.h" +#include "empathy-import-widget.h" #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include @@ -39,25 +41,22 @@ #include #include -typedef struct -{ - GtkWidget *window; - GtkWidget *treeview; - GtkWidget *button_ok; - GtkWidget *button_cancel; - GList *accounts; -} EmpathyImportDialog; - -enum -{ - COL_IMPORT = 0, - COL_PROTOCOL, - COL_NAME, - COL_SOURCE, - COL_ACCOUNT_DATA, - COL_COUNT +enum { + PROP_PARENT = 1, + PROP_SHOW_WARNING }; +typedef struct { + GtkWindow *parent_window; + + EmpathyImportWidget *iw; + + gboolean show_warning; +} EmpathyImportDialogPriv; + +G_DEFINE_TYPE (EmpathyImportDialog, empathy_import_dialog, GTK_TYPE_DIALOG) +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyImportDialog) + EmpathyImportAccountData * empathy_import_account_data_new (const gchar *source) { @@ -92,377 +91,193 @@ empathy_import_account_data_free (EmpathyImportAccountData *data) g_slice_free (EmpathyImportAccountData, data); } -static void -import_dialog_create_account_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) +gboolean +empathy_import_dialog_accounts_to_import (void) { - EmpathyImportAccountData *data = (EmpathyImportAccountData *) user_data; - EmpathyAccount *account; - GError *error = NULL; - - account = empathy_account_manager_create_account_finish ( - EMPATHY_ACCOUNT_MANAGER (source), result, &error); - - if (account == NULL) - { - DEBUG ("Failed to create account: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - empathy_import_account_data_free (data); - return; - } - - DEBUG ("account created\n"); - - g_object_unref (account); + return empathy_import_pidgin_accounts_to_import (); } static void -import_dialog_add_account (EmpathyImportAccountData *data) +import_dialog_add_import_widget (EmpathyImportDialog *self) { - EmpathyAccountManager *account_manager; - gchar *display_name; - GHashTable *properties; - GValue *username; - - account_manager = empathy_account_manager_dup_singleton (); - - DEBUG ("connection_manager: %s\n", data->connection_manager); - - /* Set the display name of the account */ - username = g_hash_table_lookup (data->settings, "account"); - display_name = g_strdup_printf ("%s (%s)", - data->protocol, - g_value_get_string (username)); - - DEBUG ("display name: %s\n", display_name); - - properties = g_hash_table_new (NULL, NULL); - - empathy_account_manager_create_account_async (account_manager, - (const gchar*) data->connection_manager, data->protocol, display_name, - data->settings, properties, import_dialog_create_account_cb, NULL); - - g_hash_table_unref (properties); - g_free (display_name); - g_object_unref (account_manager); + EmpathyImportWidget *iw; + EmpathyImportDialogPriv *priv = GET_PRIV (self); + GtkWidget *widget, *area; + + area = gtk_dialog_get_content_area (GTK_DIALOG (self)); + + iw = empathy_import_widget_new (); + widget = empathy_import_widget_get_widget (iw); + gtk_box_pack_start (GTK_BOX (area), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + priv->iw = iw; + + gtk_dialog_add_buttons (GTK_DIALOG (self), GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); } -static gboolean -import_dialog_account_id_in_list (GList *accounts, - const gchar *account_id) +static void +import_dialog_show_warning_message (EmpathyImportDialog *self) { - GList *l; + GtkWidget *hbox, *vbox, *w; - for (l = accounts; l; l = l->next) - { - EmpathyAccount *account = l->data; - const gchar *account_string; - GValue *value; - gboolean result; - const GHashTable *parameters; + vbox = gtk_vbox_new (FALSE, 12); + hbox = gtk_hbox_new (FALSE, 12); - parameters = empathy_account_get_parameters (account); + w = gtk_label_new (_("No accounts to import could be found. Empathy " + "currently only supports importing accounts from Pidgin.")); + gtk_label_set_line_wrap (GTK_LABEL (w), TRUE); + gtk_label_set_selectable (GTK_LABEL (w), TRUE); + gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.0); + gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - value = g_hash_table_lookup ((GHashTable *) parameters, "account"); + w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, + GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment (GTK_MISC (w), 0.5, 0.0); + gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - if (value == NULL) - continue; + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - account_string = g_value_get_string (value); + w = gtk_dialog_get_content_area (GTK_DIALOG (self)); + gtk_box_pack_start (GTK_BOX (w), hbox, FALSE, FALSE, 0); - result = tp_strdiff (account_string, account_id); + gtk_box_set_spacing (GTK_BOX (w), 14); /* 14 + 2 * 5 = 24 */ - if (!result) - return TRUE; - } + gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CLOSE, + GTK_RESPONSE_CLOSE); - return FALSE; + gtk_widget_show_all (w); } -static gboolean protocol_is_supported (EmpathyImportAccountData *data) +static void +impl_signal_response (GtkDialog *dialog, + gint response_id) { - EmpathyConnectionManagers *cm = - empathy_connection_managers_dup_singleton (); - GList *cms = empathy_connection_managers_get_cms (cm); - GList *l; - gboolean proto_is_supported = FALSE; + EmpathyImportDialogPriv *priv = GET_PRIV (dialog); - for (l = cms; l; l = l->next) - { - TpConnectionManager *tp_cm = l->data; - const gchar *cm_name = tp_connection_manager_get_name (tp_cm); - if (tp_connection_manager_has_protocol (tp_cm, - (const gchar*)data->protocol)) - { - data->connection_manager = g_strdup (cm_name); - proto_is_supported = TRUE; - break; - } - } - - g_object_unref (cm); + if (response_id == GTK_RESPONSE_OK) + empathy_import_widget_add_selected_accounts (priv->iw); - return proto_is_supported; + gtk_widget_destroy (GTK_WIDGET (dialog)); } static void -import_dialog_add_accounts_to_model (EmpathyImportDialog *dialog) +do_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - GtkTreeModel *model; - GtkTreeIter iter; - GList *l; - EmpathyAccountManager *manager = empathy_account_manager_dup_singleton (); + EmpathyImportDialogPriv *priv = GET_PRIV (object); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); - - for (l = dialog->accounts; l; l = l->next) + switch (property_id) { - GValue *value; - EmpathyImportAccountData *data = l->data; - gboolean import; - GList *accounts; - - if (!protocol_is_supported (data)) - continue; - - value = g_hash_table_lookup (data->settings, "account"); - - accounts = empathy_account_manager_dup_accounts (manager); - - /* Only set the "Import" cell to be active if there isn't already an - * account set up with the same account id. */ - import = !import_dialog_account_id_in_list (accounts, - g_value_get_string (value)); - - g_list_foreach (accounts, (GFunc) g_object_unref, NULL); - g_list_free (accounts); - - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_IMPORT, import, - COL_PROTOCOL, data->protocol, - COL_NAME, g_value_get_string (value), - COL_SOURCE, data->source, - COL_ACCOUNT_DATA, data, - -1); + case PROP_PARENT: + g_value_set_object (value, priv->parent_window); + break; + case PROP_SHOW_WARNING: + g_value_set_boolean (value, priv->show_warning); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } - - g_object_unref (manager); -} - -static void -import_dialog_cell_toggled_cb (GtkCellRendererToggle *cell_renderer, - const gchar *path_str, - EmpathyImportDialog *dialog) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GtkTreePath *path; - - path = gtk_tree_path_new_from_string (path_str); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); - - gtk_tree_model_get_iter (model, &iter, path); - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_IMPORT, !gtk_cell_renderer_toggle_get_active (cell_renderer), - -1); - - gtk_tree_path_free (path); } static void -import_dialog_set_up_account_list (EmpathyImportDialog *dialog) -{ - GtkListStore *store; - GtkTreeView *view; - GtkTreeViewColumn *column; - GtkCellRenderer *cell; - - store = gtk_list_store_new (COL_COUNT, G_TYPE_BOOLEAN, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); - - gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview), - GTK_TREE_MODEL (store)); - - g_object_unref (store); - - view = GTK_TREE_VIEW (dialog->treeview); - gtk_tree_view_set_headers_visible (view, TRUE); - - /* Import column */ - cell = gtk_cell_renderer_toggle_new (); - gtk_tree_view_insert_column_with_attributes (view, -1, - /* Translators: this is the header of a treeview column */ - _("Import"), cell, - "active", COL_IMPORT, - NULL); - - g_signal_connect (cell, "toggled", - G_CALLBACK (import_dialog_cell_toggled_cb), dialog); - - /* Protocol column */ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Protocol")); - gtk_tree_view_column_set_expand (column, TRUE); - gtk_tree_view_append_column (view, column); - - cell = gtk_cell_renderer_text_new (); - g_object_set (cell, - "editable", FALSE, - NULL); - gtk_tree_view_column_pack_start (column, cell, TRUE); - gtk_tree_view_column_add_attribute (column, cell, "text", COL_PROTOCOL); - - /* Account column */ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Account")); - gtk_tree_view_column_set_expand (column, TRUE); - gtk_tree_view_append_column (view, column); - - cell = gtk_cell_renderer_text_new (); - g_object_set (cell, - "editable", FALSE, - NULL); - gtk_tree_view_column_pack_start (column, cell, TRUE); - gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME); - - /* Source column */ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Source")); - gtk_tree_view_column_set_expand (column, TRUE); - gtk_tree_view_append_column (view, column); - - cell = gtk_cell_renderer_text_new (); - g_object_set (cell, - "editable", FALSE, - NULL); - gtk_tree_view_column_pack_start (column, cell, TRUE); - gtk_tree_view_column_add_attribute (column, cell, "text", COL_SOURCE); - - import_dialog_add_accounts_to_model (dialog); -} - -static gboolean -import_dialog_tree_model_foreach (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer user_data) +do_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { - gboolean to_import; - EmpathyImportAccountData *data; - - gtk_tree_model_get (model, iter, - COL_IMPORT, &to_import, - COL_ACCOUNT_DATA, &data, - -1); - - if (to_import) - import_dialog_add_account (data); - - return FALSE; -} + EmpathyImportDialogPriv *priv = GET_PRIV (object); -static void -import_dialog_response_cb (GtkWidget *widget, - gint response, - EmpathyImportDialog *dialog) -{ - if (response == GTK_RESPONSE_OK) + switch (property_id) { - GtkTreeModel *model; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); - gtk_tree_model_foreach (model, import_dialog_tree_model_foreach, dialog); + case PROP_PARENT: + priv->parent_window = g_value_get_object (value); + break; + case PROP_SHOW_WARNING: + priv->show_warning = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } - - gtk_widget_destroy (dialog->window); } static void -import_dialog_destroy_cb (GtkWidget *widget, - EmpathyImportDialog *dialog) +do_constructed (GObject *obj) { - g_list_foreach (dialog->accounts, (GFunc) empathy_import_account_data_free, - NULL); - g_list_free (dialog->accounts); - g_slice_free (EmpathyImportDialog, dialog); -} + EmpathyImportDialog *self = EMPATHY_IMPORT_DIALOG (obj); + EmpathyImportDialogPriv *priv = GET_PRIV (self); + gboolean have_accounts; -gboolean -empathy_import_dialog_accounts_to_import (void) -{ - return empathy_import_pidgin_accounts_to_import (); -} + have_accounts = empathy_import_dialog_accounts_to_import (); -void -empathy_import_dialog_show (GtkWindow *parent, - gboolean warning) -{ - static EmpathyImportDialog *dialog = NULL; - GtkBuilder *gui; - gchar *filename; - GList *accounts = NULL; - - /* This window is a singleton. If it already exist, present it */ - if (dialog) - { - gtk_window_present (GTK_WINDOW (dialog->window)); - return; - } - - /* Load all accounts from all supported applications */ - accounts = g_list_concat (accounts, empathy_import_pidgin_load ()); - - /* Check if we have accounts to import before creating the window */ - if (!accounts) + if (!have_accounts) { - GtkWidget *message; - - if (warning) + if (priv->show_warning) { - message = gtk_message_dialog_new (parent, - GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, - _("No accounts to import could be found. Empathy currently only " - "supports importing accounts from Pidgin.")); - - gtk_dialog_run (GTK_DIALOG (message)); - gtk_widget_destroy (message); + import_dialog_show_warning_message (self); } else DEBUG ("No accounts to import; closing dialog silently."); - - return; + } + else + { + import_dialog_add_import_widget (self); } - /* We have accounts, let's display the window with them */ - dialog = g_slice_new0 (EmpathyImportDialog); - dialog->accounts = accounts; - - filename = empathy_file_lookup ("empathy-import-dialog.ui", "src"); - gui = empathy_builder_get_file (filename, - "import_dialog", &dialog->window, - "treeview", &dialog->treeview, - NULL); - - empathy_builder_connect (gui, dialog, - "import_dialog", "destroy", import_dialog_destroy_cb, - "import_dialog", "response", import_dialog_response_cb, - NULL); - - g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog); + if (priv->parent_window) + gtk_window_set_transient_for (GTK_WINDOW (self), priv->parent_window); +} - g_free (filename); - g_object_unref (gui); +static void +empathy_import_dialog_init (EmpathyImportDialog *self) +{ + EmpathyImportDialogPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_IMPORT_DIALOG, EmpathyImportDialogPriv); - if (parent) - gtk_window_set_transient_for (GTK_WINDOW (dialog->window), parent); + self->priv = priv; - import_dialog_set_up_account_list (dialog); + gtk_container_set_border_width (GTK_CONTAINER (self), 5); + gtk_window_set_title (GTK_WINDOW (self), _("Import Accounts")); + gtk_window_set_modal (GTK_WINDOW (self), TRUE); + gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE); +} - gtk_widget_show (dialog->window); +static void +empathy_import_dialog_class_init (EmpathyImportDialogClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + GtkDialogClass *gtkclass = GTK_DIALOG_CLASS (klass); + GParamSpec *param_spec; + + oclass->constructed = do_constructed; + oclass->get_property = do_get_property; + oclass->set_property = do_set_property; + + gtkclass->response = impl_signal_response; + + param_spec = g_param_spec_object ("parent-window", + "parent-window", "The parent window", + GTK_TYPE_WINDOW, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_PARENT, param_spec); + + param_spec = g_param_spec_boolean ("show-warning", + "show-warning", "Whether a warning should be shown when there are no " + "sources for importing accounts.", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_SHOW_WARNING, param_spec); + + g_type_class_add_private (klass, sizeof (EmpathyImportDialogPriv)); } +GtkWidget * +empathy_import_dialog_new (GtkWindow *parent, + gboolean warning) +{ + return g_object_new (EMPATHY_TYPE_IMPORT_DIALOG, "parent-window", + parent, "show-warning", warning, NULL); +} diff --git a/src/empathy-import-dialog.h b/src/empathy-import-dialog.h index bdd0de732..14ab33b47 100644 --- a/src/empathy-import-dialog.h +++ b/src/empathy-import-dialog.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2008-2009 Collabora Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -17,6 +17,7 @@ * Boston, MA 02110-1301 USA * * Authors: Jonny Lamb + * Cosimo Cecchi */ #include @@ -26,6 +27,21 @@ G_BEGIN_DECLS +#define EMPATHY_TYPE_IMPORT_DIALOG empathy_import_dialog_get_type() +#define EMPATHY_IMPORT_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_IMPORT_DIALOG,\ + EmpathyImportDialog)) +#define EMPATHY_IMPORT_DIALOG_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_IMPORT_DIALOG,\ + EmpathyImportDialogClass)) +#define EMPATHY_IS_IMPORT_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_IMPORT_DIALOG)) +#define EMPATHY_IS_IMPORT_DIALOG_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_IMPORT_DIALOG)) +#define EMPATHY_IMPORT_DIALOG_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_IMPORT_DIALOG,\ + EmpathyImportDialogClass)) + typedef struct { /* Table mapping CM param string to a GValue */ @@ -38,10 +54,27 @@ typedef struct gchar *source; } EmpathyImportAccountData; -EmpathyImportAccountData *empathy_import_account_data_new (const gchar *source); +typedef struct { + GtkDialog parent; + + /* private */ + gpointer priv; +} EmpathyImportDialog; + +typedef struct { + GtkDialogClass parent_class; +} EmpathyImportDialogClass; + +GType empathy_import_dialog_get_type (void); + +GtkWidget* empathy_import_dialog_new (GtkWindow *parent_window, + gboolean show_warning); + +EmpathyImportAccountData *empathy_import_account_data_new ( + const gchar *source); void empathy_import_account_data_free (EmpathyImportAccountData *data); + gboolean empathy_import_dialog_accounts_to_import (void); -void empathy_import_dialog_show (GtkWindow *parent, gboolean warning); G_END_DECLS diff --git a/src/empathy-import-dialog.ui b/src/empathy-import-dialog.ui index 38ba434e4..ce7a56a74 100644 --- a/src/empathy-import-dialog.ui +++ b/src/empathy-import-dialog.ui @@ -1,73 +1,29 @@ - - - 5 - Import Accounts - True - GTK_WIN_POS_CENTER_ON_PARENT - GDK_WINDOW_TYPE_HINT_DIALOG - False - - + + + + True + 2 + + True - 2 + True + never + automatic + in - + + 200 True True - GTK_POLICY_NEVER - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - - - 200 - True - True - False - - + False - - 1 - - - - - True - GTK_BUTTONBOX_END - - - True - True - True - gtk-cancel - True - - - - - True - True - True - gtk-ok - True - - - 1 - - - - - False - GTK_PACK_END - + + 1 + - - button_cancel - button_ok - diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c new file mode 100644 index 000000000..d276c03e5 --- /dev/null +++ b/src/empathy-import-widget.c @@ -0,0 +1,464 @@ +/* + * Copyright (C) 2008-2009 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Jonny Lamb + * Cosimo Cecchi + */ + +/* empathy-import-widget.c */ + +#include "empathy-import-dialog.h" +#include "empathy-import-widget.h" +#include "empathy-import-pidgin.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include +#include +#include +#include +#include + +#include + +#include + +#include + +G_DEFINE_TYPE (EmpathyImportWidget, empathy_import_widget, G_TYPE_OBJECT) + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyImportWidget) + +enum +{ + COL_IMPORT = 0, + COL_PROTOCOL, + COL_NAME, + COL_SOURCE, + COL_ACCOUNT_DATA, + COL_COUNT +}; + +typedef struct { + GtkWidget *vbox; + GtkWidget *treeview; + + GList *accounts; + + EmpathyConnectionManagers *cms; + + gboolean dispose_run; +} EmpathyImportWidgetPriv; + +static gboolean +import_widget_account_id_in_list (GList *accounts, + const gchar *account_id) +{ + GList *l; + + for (l = accounts; l; l = l->next) + { + EmpathyAccount *account = l->data; + const gchar *account_string; + GValue *value; + gboolean result; + const GHashTable *parameters; + + parameters = empathy_account_get_parameters (account); + + value = g_hash_table_lookup ((GHashTable *)parameters, "account"); + + if (value == NULL) + continue; + + account_string = g_value_get_string (value); + + result = tp_strdiff (account_string, account_id); + + if (!result) + return TRUE; + } + + return FALSE; +} + +static gboolean +protocol_is_supported (EmpathyImportWidget *self, + EmpathyImportAccountData *data) +{ + EmpathyImportWidgetPriv *priv = GET_PRIV (self); + GList *cms = empathy_connection_managers_get_cms (priv->cms); + GList *l; + gboolean proto_is_supported = FALSE; + + for (l = cms; l; l = l->next) + { + TpConnectionManager *tp_cm = l->data; + const gchar *cm_name = tp_connection_manager_get_name (tp_cm); + if (tp_connection_manager_has_protocol (tp_cm, + (const gchar*) data->protocol)) + { + data->connection_manager = g_strdup (cm_name); + proto_is_supported = TRUE; + break; + } + } + + return proto_is_supported; +} + +static void +import_widget_add_accounts_to_model (EmpathyImportWidget *self) +{ + GtkTreeModel *model; + GtkTreeIter iter; + GList *l; + EmpathyImportWidgetPriv *priv = GET_PRIV (self); + EmpathyAccountManager *manager = empathy_account_manager_dup_singleton (); + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + + for (l = priv->accounts; l; l = l->next) + { + GValue *value; + EmpathyImportAccountData *data = l->data; + gboolean import; + GList *accounts; + + if (!protocol_is_supported (self, data)) + continue; + + value = g_hash_table_lookup (data->settings, "account"); + + accounts = empathy_account_manager_dup_accounts (manager); + + /* Only set the "Import" cell to be active if there isn't already an + * account set up with the same account id. */ + import = !import_widget_account_id_in_list (accounts, + g_value_get_string (value)); + + g_list_foreach (accounts, (GFunc) g_object_unref, NULL); + g_list_free (accounts); + + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_IMPORT, import, + COL_PROTOCOL, data->protocol, + COL_NAME, g_value_get_string (value), + COL_SOURCE, data->source, + COL_ACCOUNT_DATA, data, + -1); + } + + g_object_unref (manager); +} + +static void +import_widget_create_account_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyAccount *account; + GError *error = NULL; + EmpathyImportWidget *self = user_data; + + account = empathy_account_manager_create_account_finish ( + EMPATHY_ACCOUNT_MANAGER (source), result, &error); + + if (account == NULL) + { + DEBUG ("Failed to create account: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + return; + } + + DEBUG ("account created\n"); + + g_object_unref (self); +} + +static void +import_widget_add_account (EmpathyImportWidget *self, + EmpathyImportAccountData *data) +{ + EmpathyAccountManager *account_manager; + gchar *display_name; + GHashTable *properties; + GValue *username; + + account_manager = empathy_account_manager_dup_singleton (); + + DEBUG ("connection_manager: %s\n", data->connection_manager); + + /* Set the display name of the account */ + username = g_hash_table_lookup (data->settings, "account"); + display_name = g_strdup_printf ("%s (%s)", + data->protocol, + g_value_get_string (username)); + + DEBUG ("display name: %s\n", display_name); + + properties = g_hash_table_new (NULL, NULL); + + empathy_account_manager_create_account_async (account_manager, + (const gchar*) data->connection_manager, data->protocol, display_name, + data->settings, properties, import_widget_create_account_cb, + g_object_ref (self)); + + g_hash_table_unref (properties); + g_free (display_name); + g_object_unref (account_manager); +} + +static gboolean +import_widget_tree_model_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer user_data) +{ + gboolean to_import; + EmpathyImportAccountData *data; + EmpathyImportWidget *self = user_data; + + gtk_tree_model_get (model, iter, + COL_IMPORT, &to_import, + COL_ACCOUNT_DATA, &data, + -1); + + if (to_import) + import_widget_add_account (self, data); + + return FALSE; +} + +static void +import_widget_cell_toggled_cb (GtkCellRendererToggle *cell_renderer, + const gchar *path_str, + EmpathyImportWidget *self) +{ + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; + EmpathyImportWidgetPriv *priv = GET_PRIV (self); + + path = gtk_tree_path_new_from_string (path_str); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + + gtk_tree_model_get_iter (model, &iter, path); + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_IMPORT, !gtk_cell_renderer_toggle_get_active (cell_renderer), + -1); + + gtk_tree_path_free (path); +} + +static void +import_widget_set_up_account_list (EmpathyImportWidget *self) +{ + EmpathyImportWidgetPriv *priv = GET_PRIV (self); + GtkListStore *store; + GtkTreeView *view; + GtkTreeViewColumn *column; + GtkCellRenderer *cell; + + store = gtk_list_store_new (COL_COUNT, G_TYPE_BOOLEAN, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); + + gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), + GTK_TREE_MODEL (store)); + + g_object_unref (store); + + view = GTK_TREE_VIEW (priv->treeview); + gtk_tree_view_set_headers_visible (view, TRUE); + + /* Import column */ + cell = gtk_cell_renderer_toggle_new (); + gtk_tree_view_insert_column_with_attributes (view, -1, + /* Translators: this is the header of a treeview column */ + _("Import"), cell, + "active", COL_IMPORT, + NULL); + + g_signal_connect (cell, "toggled", + G_CALLBACK (import_widget_cell_toggled_cb), self); + + /* Protocol column */ + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_title (column, _("Protocol")); + gtk_tree_view_column_set_expand (column, TRUE); + gtk_tree_view_append_column (view, column); + + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, "editable", FALSE, NULL); + gtk_tree_view_column_pack_start (column, cell, TRUE); + gtk_tree_view_column_add_attribute (column, cell, "text", COL_PROTOCOL); + + /* Account column */ + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_title (column, _("Account")); + gtk_tree_view_column_set_expand (column, TRUE); + gtk_tree_view_append_column (view, column); + + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, "editable", FALSE, NULL); + gtk_tree_view_column_pack_start (column, cell, TRUE); + gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME); + + /* Source column */ + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_title (column, _("Source")); + gtk_tree_view_column_set_expand (column, TRUE); + gtk_tree_view_append_column (view, column); + + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, "editable", FALSE, NULL); + gtk_tree_view_column_pack_start (column, cell, TRUE); + gtk_tree_view_column_add_attribute (column, cell, "text", COL_SOURCE); + + import_widget_add_accounts_to_model (self); +} + +static void +import_widget_cms_ready_cb (EmpathyConnectionManagers *cms, + GParamSpec *pspec, + EmpathyImportWidget *self) +{ + if (empathy_connection_managers_is_ready (cms)) + import_widget_set_up_account_list (self); +} + +static void +import_widget_destroy_cb (GtkWidget *w, + EmpathyImportWidget *self) +{ + g_object_unref (self); +} + +static void +do_finalize (GObject *obj) +{ + EmpathyImportWidgetPriv *priv = GET_PRIV (obj); + + g_list_foreach (priv->accounts, (GFunc) empathy_import_account_data_free, + NULL); + g_list_free (priv->accounts); + + if (G_OBJECT_CLASS (empathy_import_widget_parent_class)->finalize != NULL) + G_OBJECT_CLASS (empathy_import_widget_parent_class)->finalize (obj); +} + +static void +do_dispose (GObject *obj) +{ + EmpathyImportWidgetPriv *priv = GET_PRIV (obj); + + if (priv->dispose_run) + return; + + priv->dispose_run = TRUE; + + if (priv->cms != NULL) + { + g_object_unref (priv->cms); + priv->cms = NULL; + } + + if (G_OBJECT_CLASS (empathy_import_widget_parent_class)->dispose != NULL) + G_OBJECT_CLASS (empathy_import_widget_parent_class)->dispose (obj); +} + +static void +do_constructed (GObject *obj) +{ + EmpathyImportWidget *self = EMPATHY_IMPORT_WIDGET (obj); + EmpathyImportWidgetPriv *priv = GET_PRIV (self); + GtkBuilder *gui; + gchar *filename; + + filename = empathy_file_lookup ("empathy-import-dialog.ui", "src"); + gui = empathy_builder_get_file (filename, + "widget_vbox", &priv->vbox, + "treeview", &priv->treeview, + NULL); + + g_free (filename); + empathy_builder_unref_and_keep_widget (gui, priv->vbox); + + g_signal_connect (priv->vbox, "destroy", + G_CALLBACK (import_widget_destroy_cb), self); + + if (empathy_connection_managers_is_ready (priv->cms)) + import_widget_set_up_account_list (self); + else + g_signal_connect (priv->cms, "notify::ready", + G_CALLBACK (import_widget_cms_ready_cb), self); +} + +static void +empathy_import_widget_class_init (EmpathyImportWidgetClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + + oclass->constructed = do_constructed; + oclass->finalize = do_finalize; + oclass->dispose = do_dispose; + + g_type_class_add_private (klass, sizeof (EmpathyImportWidgetPriv)); +} + +static void +empathy_import_widget_init (EmpathyImportWidget *self) +{ + EmpathyImportWidgetPriv *priv = + G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_IMPORT_WIDGET, + EmpathyImportWidgetPriv); + + self->priv = priv; + + /* Load all accounts from all supported applications */ + priv->accounts = empathy_import_pidgin_load (); + + priv->cms = empathy_connection_managers_dup_singleton (); +} + +EmpathyImportWidget * +empathy_import_widget_new (void) +{ + return g_object_new (EMPATHY_TYPE_IMPORT_WIDGET, NULL); +} + +GtkWidget * +empathy_import_widget_get_widget (EmpathyImportWidget *self) +{ + EmpathyImportWidgetPriv *priv = GET_PRIV (self); + + return priv->vbox; +} + +void +empathy_import_widget_add_selected_accounts (EmpathyImportWidget *self) +{ + GtkTreeModel *model; + EmpathyImportWidgetPriv *priv = GET_PRIV (self); + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + gtk_tree_model_foreach (model, import_widget_tree_model_foreach, self); +} diff --git a/src/empathy-import-widget.h b/src/empathy-import-widget.h new file mode 100644 index 000000000..8af953d79 --- /dev/null +++ b/src/empathy-import-widget.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008-2009 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Jonny Lamb + * Cosimo Cecchi + */ + +/* empathy-import-widget.h */ + +#ifndef __EMPATHY_IMPORT_WIDGET_H__ +#define __EMPATHY_IMPORT_WIDGET_H__ + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_IMPORT_WIDGET empathy_import_widget_get_type() +#define EMPATHY_IMPORT_WIDGET(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_IMPORT_WIDGET,\ + EmpathyImportWidget)) +#define EMPATHY_IMPORT_WIDGET_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_IMPORT_WIDGET,\ + EmpathyImportWidgetClass)) +#define EMPATHY_IS_IMPORT_WIDGET(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_IMPORT_WIDGET)) +#define EMPATHY_IS_IMPORT_WIDGET_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_IMPORT_WIDGET)) +#define EMPATHY_IMPORT_WIDGET_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_IMPORT_WIDGET,\ + EmpathyImportWidgetClass)) + +typedef struct { + GObject parent; + + /* private */ + gpointer priv; +} EmpathyImportWidget; + +typedef struct { + GObjectClass parent_class; +} EmpathyImportWidgetClass; + +GType empathy_import_widget_get_type (void); + +EmpathyImportWidget* empathy_import_widget_new (void); + +GtkWidget * empathy_import_widget_get_widget (EmpathyImportWidget *self); + +void empathy_import_widget_add_selected_accounts (EmpathyImportWidget *self); + +G_END_DECLS + +#endif /* __EMPATHY_IMPORT_WIDGET_H__ */ -- cgit v1.2.3 From a7e5be33b8ff0bf0cdeaf4672d967e14f80c54eb Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 7 Aug 2009 17:22:55 +0200 Subject: Add the new files to the Makefile.am --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.am b/src/Makefile.am index 9ac6b9bb3..5d3bee501 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,7 @@ empathy_handwritten_source = \ empathy-event-manager.c empathy-event-manager.h \ empathy-ft-manager.c empathy-ft-manager.h \ empathy-import-dialog.c empathy-import-dialog.h \ + empathy-import-widget.c empathy-import-widget.h \ empathy-import-pidgin.c empathy-import-pidgin.h \ empathy-main-window.c empathy-main-window.h \ empathy-misc.c empathy-misc.h \ -- cgit v1.2.3 From 72ade92677b8c069b2933b76c64e340222a31254 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 7 Aug 2009 17:23:24 +0200 Subject: Adapt to the new API --- src/empathy-accounts-dialog.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 3532e97f4..785d20ae0 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1103,8 +1103,10 @@ accounts_dialog_button_import_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + GtkWidget *import_dialog; - empathy_import_dialog_show (GTK_WINDOW (priv->window), TRUE); + import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window), TRUE); + gtk_widget_show (import_dialog); } static void @@ -1383,10 +1385,13 @@ do_constructed (GObject *object) if (!import_asked) { + GtkWidget *import_dialog; + empathy_conf_set_bool (empathy_conf_get (), EMPATHY_PREFS_IMPORT_ASKED, TRUE); - empathy_import_dialog_show (GTK_WINDOW (priv->window), + import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window), FALSE); + gtk_widget_show (import_dialog); } } else -- cgit v1.2.3 From 5f31f7e68a4d8e132aa9c1d0c6305e1546368666 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 7 Aug 2009 17:24:06 +0200 Subject: Hook the import UI in the assistant --- src/empathy-account-assistant.c | 92 +++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index f5ef3c7f5..0b30bb807 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -24,6 +24,8 @@ #include #include "empathy-account-assistant.h" +#include "empathy-import-dialog.h" +#include "empathy-import-widget.h" #include #include @@ -68,6 +70,9 @@ typedef struct { EmpathyAccountSettings *settings; gboolean is_creating; + /* import page */ + EmpathyImportWidget *iw; + GtkWindow *parent_window; gboolean dispose_run; @@ -396,15 +401,17 @@ account_assistant_page_forward_func (gint current_page, if (priv->first_resp == RESPONSE_ENTER_ACCOUNT || priv->first_resp == RESPONSE_CREATE_ACCOUNT) retval = PAGE_ENTER_CREATE; + if (priv->first_resp == RESPONSE_IMPORT) + retval = PAGE_IMPORT; } - if (current_page == PAGE_ENTER_CREATE) + if (current_page == PAGE_ENTER_CREATE || + current_page == PAGE_IMPORT) { /* don't forward anymore */ retval = -1; } - g_print ("retval = %d\n", retval); return retval; } @@ -435,8 +442,10 @@ account_assistant_radio_choice_toggled_cb (GtkToggleButton *button, static GtkWidget * account_assistant_build_introduction_page (EmpathyAccountAssistant *self) { - GtkWidget *main_vbox, *hbox_1, *w, *radio, *vbox_1; + GtkWidget *main_vbox, *hbox_1, *w, *vbox_1; + GtkWidget *radio = NULL; GdkPixbuf *pix; + const gchar *str; main_vbox = gtk_vbox_new (FALSE, 12); gtk_widget_show (main_vbox); @@ -474,23 +483,46 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self) gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0); gtk_widget_show (w); - vbox_1 = gtk_vbox_new (FALSE, 6); + vbox_1 = gtk_vbox_new (TRUE, 0); gtk_container_add (GTK_CONTAINER (w), vbox_1); gtk_widget_show (vbox_1); - /* TODO: this will have to be updated when kutio's branch have landed */ - radio = gtk_radio_button_new_with_label (NULL, - _("Yes, import my account details from ")); - gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0); - g_object_set_data (G_OBJECT (radio), "response", - GINT_TO_POINTER (RESPONSE_IMPORT)); - gtk_widget_show (radio); + if (empathy_import_dialog_accounts_to_import ()) + { + hbox_1 = gtk_hbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox_1), hbox_1, TRUE, TRUE, 0); + gtk_widget_show (hbox_1); + + radio = gtk_radio_button_new_with_label (NULL, + _("Yes, import my account details from ")); + gtk_box_pack_start (GTK_BOX (hbox_1), radio, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (radio), "response", + GINT_TO_POINTER (RESPONSE_IMPORT)); + gtk_widget_show (radio); + + w = gtk_combo_box_new_text (); + gtk_combo_box_append_text (GTK_COMBO_BOX (w), "Pidgin"); + gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (w), 0); + gtk_widget_show (w); + + g_signal_connect (radio, "clicked", + G_CALLBACK (account_assistant_radio_choice_toggled_cb), self); + } - g_signal_connect (radio, "clicked", - G_CALLBACK (account_assistant_radio_choice_toggled_cb), self); + str = _("Yes, I'll enter my account details now"); + + if (radio == NULL) + { + radio = gtk_radio_button_new_with_label (NULL, str); + w = radio; + } + else + { + w = gtk_radio_button_new_with_label_from_widget ( + GTK_RADIO_BUTTON (radio), str); + } - w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), - _("Yes, I'll enter my account details now")); gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0); g_object_set_data (G_OBJECT (w), "response", GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT)); @@ -525,14 +557,29 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self) static GtkWidget * account_assistant_build_import_page (EmpathyAccountAssistant *self) { - /* TODO: import page */ - GtkWidget *main_vbox, *w; + GtkWidget *main_vbox, *w, *import; + EmpathyImportWidget *iw; + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); main_vbox = gtk_vbox_new (FALSE, 12); - w = gtk_label_new ("Import your accounts!"); + gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); + w = gtk_label_new (_("Select the accounts you want to import:")); + gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); gtk_widget_show (w); gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6); + w = gtk_alignment_new (0, 0, 0, 0); + gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + iw = empathy_import_widget_new (); + import = empathy_import_widget_get_widget (iw); + gtk_container_add (GTK_CONTAINER (w), import); + gtk_widget_show (import); + + priv->iw = iw; + gtk_widget_show (main_vbox); return main_vbox; @@ -602,14 +649,16 @@ static void impl_signal_apply (GtkAssistant *assistant) { EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant); - // EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); gint current_page; - g_print ("apply!!\n"); current_page = gtk_assistant_get_current_page (assistant); if (current_page == RESPONSE_ENTER_ACCOUNT) account_assistant_apply_account_and_finish (self); + + if (current_page == RESPONSE_IMPORT) + empathy_import_widget_add_selected_accounts (priv->iw); } static void @@ -628,8 +677,6 @@ impl_signal_prepare (GtkAssistant *assistant, current_idx = gtk_assistant_get_current_page (assistant); - g_print ("prepare, current idx = %d\n", current_idx); - if (current_idx == PAGE_ENTER_CREATE) { account_assistant_finish_enter_or_create_page (self, @@ -768,6 +815,7 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) gtk_assistant_set_page_title (assistant, page, _("Import your existing accounts")); gtk_assistant_set_page_complete (assistant, page, TRUE); + gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); /* third page (enter account details) */ page = account_assistant_build_enter_or_create_page (self, TRUE); -- cgit v1.2.3 From fdb4edb101b73e0860c37570e877f8c2a57b3b76 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 7 Aug 2009 17:24:42 +0200 Subject: Update the test --- tests/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ffdae723..1e0a59e8e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -40,6 +40,9 @@ test_empathy_account_assistant_SOURCES = test-empathy-account-assistant.c test_empathy_account_assistant_CFLAGS = -I$(top_srcdir)/src test_empathy_account_assistant_LDADD = \ $(top_builddir)/src/empathy-account-assistant.o \ + $(top_builddir)/src/empathy-import-dialog.o \ + $(top_builddir)/src/empathy-import-pidgin.o \ + $(top_builddir)/src/empathy-import-widget.o \ $(LDADD) check_PROGRAMS = check-main -- cgit v1.2.3 From 34f824dd1b1642afab7474d32b53e65074a5495c Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 7 Aug 2009 21:06:49 +0200 Subject: Don't hardcode new lines --- src/empathy-account-assistant.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 0b30bb807..0b32b3a94 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -104,7 +104,7 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self, /* translators: this is followed by the "while ..." strings some lines * down this file. */ - str = g_string_new (_("There has been an error\n")); + str = g_string_new (_("There has been an error ")); if (page_num == PAGE_IMPORT) /* translators: this follows the "There has been an error " string */ @@ -127,6 +127,7 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self, pango_attr_list_insert (list, pango_attr_weight_new (PANGO_WEIGHT_BOLD)); gtk_label_set_attributes (GTK_LABEL (w), list); gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); + gtk_label_set_line_wrap (GTK_LABEL (w), TRUE); gtk_widget_show (w); g_free (message); @@ -142,10 +143,11 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self, gtk_widget_show (w); w = gtk_label_new (_("You can either go back and try to enter your " - "accounts' details\nagain or quit this wizard and add accounts " + "accounts' details again or quit this wizard and add accounts " "later from the Edit menu.")); gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6); gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); + gtk_label_set_line_wrap (GTK_LABEL (w), TRUE); gtk_widget_show (w); return main_vbox; @@ -355,7 +357,7 @@ account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self, _("What kind of chat account do you have?")); gtk_label_set_label (GTK_LABEL (priv->second_label), _("If you have other accounts to set up, you can do " - "that at any time\nfrom the Edit menu.")); + "that at any time from the Edit menu.")); empathy_protocol_chooser_set_visible ( EMPATHY_PROTOCOL_CHOOSER (priv->chooser), account_assistant_chooser_enter_details_filter_func, self); @@ -368,7 +370,7 @@ account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self, gtk_label_set_label (GTK_LABEL (priv->first_label), _("What kind of chat account do you want to create?")); gtk_label_set_label (GTK_LABEL (priv->second_label), - _("You can register other accounts, or setup\n" + _("You can register other accounts, or setup " "an existing one at any time from the Edit menu.")); empathy_protocol_chooser_set_visible ( EMPATHY_PROTOCOL_CHOOSER (priv->chooser), @@ -456,25 +458,27 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self) gtk_widget_show (hbox_1); w = gtk_label_new ( - _("With Empathy you can chat with people\n" - "online nearby and with friends and colleagues\n" - "who use Google Talk, AIM, Windows Live\n" - "and many other chat programs. With a microphone\n" + _("With Empathy you can chat with people " + "online nearby and with friends and colleagues " + "who use Google Talk, AIM, Windows Live " + "and many other chat programs. With a microphone " "or a webcam you can also have audio or video calls.")); gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5); - gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0); + gtk_label_set_line_wrap (GTK_LABEL (w), TRUE); + gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0); gtk_widget_show (w); pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80); w = gtk_image_new_from_pixbuf (pix); - gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6); + gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6); gtk_widget_show (w); g_object_unref (pix); w = gtk_label_new (_("Do you have an account you've been using " - "with another\nchat program?")); + "with another chat program?")); gtk_misc_set_alignment (GTK_MISC (w), 0, 0); + gtk_label_set_line_wrap (GTK_LABEL (w), TRUE); gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); gtk_widget_show (w); @@ -626,6 +630,8 @@ account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self, list = pango_attr_list_new (); pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_SMALL)); gtk_label_set_attributes (GTK_LABEL (w), list); + gtk_label_set_line_wrap (GTK_LABEL (w), TRUE); + gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); gtk_widget_show (w); priv->second_label = w; pango_attr_list_unref (list); -- cgit v1.2.3 From 7bbf2dfc7a29041ab5efeb1683fab7d213d480df Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 7 Aug 2009 21:08:12 +0200 Subject: The assistant should not be resizable --- src/empathy-account-assistant.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 0b32b3a94..34c505613 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -828,6 +828,8 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) gtk_assistant_append_page (assistant, page); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); priv->enter_or_create_page = page; + + gtk_window_set_resizable (GTK_WINDOW (self), FALSE); } GtkWidget * -- cgit v1.2.3 From 350ed3dbdba49253b6a94c8066c45ae81e95bed1 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 9 Aug 2009 17:15:51 +0200 Subject: Remove useless includes --- src/empathy-account-assistant.c | 1 + src/empathy-import-dialog.c | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 34c505613..55a322e24 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -22,6 +22,7 @@ #include #include +#include #include "empathy-account-assistant.h" #include "empathy-import-dialog.h" diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c index 4866b81c5..1a5f0a25c 100644 --- a/src/empathy-import-dialog.c +++ b/src/empathy-import-dialog.c @@ -22,8 +22,6 @@ #include -#include - #include #include #include @@ -37,8 +35,6 @@ #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include #include -#include -#include #include enum { -- cgit v1.2.3 From 0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 9 Aug 2009 17:48:57 +0200 Subject: Make the import system more future-proof Split the utilities from the widget and the dialog; we now have an enum for supported applications, with a special value which means "all applications", which is the only one which triggers showing the "Source" column in EmpathyImportWidget. We need this to avoid being redundant in the EmpathyAccountAssistant, as we already choose there the application from which to import. --- src/Makefile.am | 1 + src/empathy-account-assistant.c | 7 ++-- src/empathy-accounts-dialog.c | 3 +- src/empathy-import-dialog.c | 44 +--------------------- src/empathy-import-dialog.h | 18 --------- src/empathy-import-pidgin.c | 2 +- src/empathy-import-utils.c | 76 ++++++++++++++++++++++++++++++++++++++ src/empathy-import-utils.h | 56 ++++++++++++++++++++++++++++ src/empathy-import-widget.c | 82 +++++++++++++++++++++++++++++++++-------- src/empathy-import-widget.h | 4 +- tests/Makefile.am | 2 +- 11 files changed, 213 insertions(+), 82 deletions(-) create mode 100644 src/empathy-import-utils.c create mode 100644 src/empathy-import-utils.h diff --git a/src/Makefile.am b/src/Makefile.am index 5d3bee501..3641835f7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -43,6 +43,7 @@ empathy_handwritten_source = \ empathy-import-dialog.c empathy-import-dialog.h \ empathy-import-widget.c empathy-import-widget.h \ empathy-import-pidgin.c empathy-import-pidgin.h \ + empathy-import-utils.c empathy-import-utils.h \ empathy-main-window.c empathy-main-window.h \ empathy-misc.c empathy-misc.h \ empathy-new-chatroom-dialog.c empathy-new-chatroom-dialog.h \ diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 55a322e24..ab42bbd4f 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -25,8 +25,8 @@ #include #include "empathy-account-assistant.h" -#include "empathy-import-dialog.h" #include "empathy-import-widget.h" +#include "empathy-import-utils.h" #include #include @@ -492,7 +492,7 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self) gtk_container_add (GTK_CONTAINER (w), vbox_1); gtk_widget_show (vbox_1); - if (empathy_import_dialog_accounts_to_import ()) + if (empathy_import_accounts_to_import ()) { hbox_1 = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox_1), hbox_1, TRUE, TRUE, 0); @@ -578,7 +578,8 @@ account_assistant_build_import_page (EmpathyAccountAssistant *self) gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0); gtk_widget_show (w); - iw = empathy_import_widget_new (); + /* NOTE: this is hardcoded as we support pidgin only */ + iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN); import = empathy_import_widget_get_widget (iw); gtk_container_add (GTK_CONTAINER (w), import); gtk_widget_show (import); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 785d20ae0..e985befc8 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -46,6 +46,7 @@ #include "empathy-accounts-dialog.h" #include "empathy-import-dialog.h" +#include "empathy-import-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include @@ -1380,7 +1381,7 @@ do_constructed (GObject *object) EMPATHY_PREFS_IMPORT_ASKED, &import_asked); - if (empathy_import_dialog_accounts_to_import ()) + if (empathy_import_accounts_to_import ()) { if (!import_asked) diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c index 1a5f0a25c..7ca0285b1 100644 --- a/src/empathy-import-dialog.c +++ b/src/empathy-import-dialog.c @@ -53,46 +53,6 @@ typedef struct { G_DEFINE_TYPE (EmpathyImportDialog, empathy_import_dialog, GTK_TYPE_DIALOG) #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyImportDialog) -EmpathyImportAccountData * -empathy_import_account_data_new (const gchar *source) -{ - EmpathyImportAccountData *data; - - g_return_val_if_fail (!EMP_STR_EMPTY (source), NULL); - - data = g_slice_new0 (EmpathyImportAccountData); - data->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, - (GDestroyNotify) tp_g_value_slice_free); - data->source = g_strdup (source); - data->protocol = NULL; - data->connection_manager = NULL; - - return data; -} - -void -empathy_import_account_data_free (EmpathyImportAccountData *data) -{ - if (data == NULL) - return; - if (data->protocol != NULL) - g_free (data->protocol); - if (data->connection_manager != NULL) - g_free (data->connection_manager); - if (data->settings != NULL) - g_hash_table_destroy (data->settings); - if (data->source != NULL) - g_free (data->source); - - g_slice_free (EmpathyImportAccountData, data); -} - -gboolean -empathy_import_dialog_accounts_to_import (void) -{ - return empathy_import_pidgin_accounts_to_import (); -} - static void import_dialog_add_import_widget (EmpathyImportDialog *self) { @@ -102,7 +62,7 @@ import_dialog_add_import_widget (EmpathyImportDialog *self) area = gtk_dialog_get_content_area (GTK_DIALOG (self)); - iw = empathy_import_widget_new (); + iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_ALL); widget = empathy_import_widget_get_widget (iw); gtk_box_pack_start (GTK_BOX (area), widget, FALSE, FALSE, 0); gtk_widget_show (widget); @@ -207,7 +167,7 @@ do_constructed (GObject *obj) EmpathyImportDialogPriv *priv = GET_PRIV (self); gboolean have_accounts; - have_accounts = empathy_import_dialog_accounts_to_import (); + have_accounts = empathy_import_accounts_to_import (); if (!have_accounts) { diff --git a/src/empathy-import-dialog.h b/src/empathy-import-dialog.h index 14ab33b47..0e9d225c4 100644 --- a/src/empathy-import-dialog.h +++ b/src/empathy-import-dialog.h @@ -42,18 +42,6 @@ G_BEGIN_DECLS (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_IMPORT_DIALOG,\ EmpathyImportDialogClass)) -typedef struct -{ - /* Table mapping CM param string to a GValue */ - GHashTable *settings; - /* Protocol name */ - gchar *protocol; - /* Connection manager name */ - gchar *connection_manager; - /* The name of the account import source */ - gchar *source; -} EmpathyImportAccountData; - typedef struct { GtkDialog parent; @@ -70,12 +58,6 @@ GType empathy_import_dialog_get_type (void); GtkWidget* empathy_import_dialog_new (GtkWindow *parent_window, gboolean show_warning); -EmpathyImportAccountData *empathy_import_account_data_new ( - const gchar *source); -void empathy_import_account_data_free (EmpathyImportAccountData *data); - -gboolean empathy_import_dialog_accounts_to_import (void); - G_END_DECLS #endif /* __EMPATHY_IMPORT_DIALOG_H__ */ diff --git a/src/empathy-import-pidgin.c b/src/empathy-import-pidgin.c index 6a145ff93..23b1d84f5 100644 --- a/src/empathy-import-pidgin.c +++ b/src/empathy-import-pidgin.c @@ -32,7 +32,7 @@ #include #include -#include "empathy-import-dialog.h" +#include "empathy-import-utils.h" #include "empathy-import-pidgin.h" #define DEBUG_FLAG EMPATHY_DEBUG_OTHER diff --git a/src/empathy-import-utils.c b/src/empathy-import-utils.c new file mode 100644 index 000000000..f84b20609 --- /dev/null +++ b/src/empathy-import-utils.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Jonny Lamb + * Cosimo Cecchi + */ + +#include + +#include + +#include "empathy-import-utils.h" +#include "empathy-import-pidgin.h" + +EmpathyImportAccountData * +empathy_import_account_data_new (const gchar *source) +{ + EmpathyImportAccountData *data; + + g_return_val_if_fail (!EMP_STR_EMPTY (source), NULL); + + data = g_slice_new0 (EmpathyImportAccountData); + data->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, + (GDestroyNotify) tp_g_value_slice_free); + data->source = g_strdup (source); + data->protocol = NULL; + data->connection_manager = NULL; + + return data; +} + +void +empathy_import_account_data_free (EmpathyImportAccountData *data) +{ + if (data == NULL) + return; + if (data->protocol != NULL) + g_free (data->protocol); + if (data->connection_manager != NULL) + g_free (data->connection_manager); + if (data->settings != NULL) + g_hash_table_destroy (data->settings); + if (data->source != NULL) + g_free (data->source); + + g_slice_free (EmpathyImportAccountData, data); +} + +gboolean +empathy_import_accounts_to_import (void) +{ + return empathy_import_pidgin_accounts_to_import (); +} + +GList * +empathy_import_accounts_load (EmpathyImportApplication id) +{ + if (id == EMPATHY_IMPORT_APPLICATION_PIDGIN) + return empathy_import_pidgin_load (); + + return empathy_import_pidgin_load (); +} diff --git a/src/empathy-import-utils.h b/src/empathy-import-utils.h new file mode 100644 index 000000000..8c971a04d --- /dev/null +++ b/src/empathy-import-utils.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Jonny Lamb + * Cosimo Cecchi + */ + +#ifndef __EMPATHY_IMPORT_UTILS_H__ +#define __EMPATHY_IMPORT_UTILS_H__ + +#include + +G_BEGIN_DECLS + +typedef struct +{ + /* Table mapping CM param string to a GValue */ + GHashTable *settings; + /* Protocol name */ + gchar *protocol; + /* Connection manager name */ + gchar *connection_manager; + /* The name of the account import source */ + gchar *source; +} EmpathyImportAccountData; + +typedef enum { + EMPATHY_IMPORT_APPLICATION_ALL = 0, + EMPATHY_IMPORT_APPLICATION_PIDGIN, + EMPATHY_IMPORT_APPLICATION_INVALID +} EmpathyImportApplication; + +EmpathyImportAccountData *empathy_import_account_data_new ( + const gchar *source); +void empathy_import_account_data_free (EmpathyImportAccountData *data); + +gboolean empathy_import_accounts_to_import (void); +GList *empathy_import_accounts_load (EmpathyImportApplication id); + +G_END_DECLS + +#endif /* __EMPATHY_IMPORT_UTILS_H__ */ diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c index d276c03e5..03117350c 100644 --- a/src/empathy-import-widget.c +++ b/src/empathy-import-widget.c @@ -53,11 +53,16 @@ enum COL_COUNT }; +enum { + PROP_APPLICATION_ID = 1 +}; + typedef struct { GtkWidget *vbox; GtkWidget *treeview; GList *accounts; + EmpathyImportApplication app_id; EmpathyConnectionManagers *cms; @@ -322,16 +327,19 @@ import_widget_set_up_account_list (EmpathyImportWidget *self) gtk_tree_view_column_pack_start (column, cell, TRUE); gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME); - /* Source column */ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Source")); - gtk_tree_view_column_set_expand (column, TRUE); - gtk_tree_view_append_column (view, column); - - cell = gtk_cell_renderer_text_new (); - g_object_set (cell, "editable", FALSE, NULL); - gtk_tree_view_column_pack_start (column, cell, TRUE); - gtk_tree_view_column_add_attribute (column, cell, "text", COL_SOURCE); + if (priv->app_id == EMPATHY_IMPORT_APPLICATION_ALL) + { + /* Source column */ + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_title (column, _("Source")); + gtk_tree_view_column_set_expand (column, TRUE); + gtk_tree_view_append_column (view, column); + + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, "editable", FALSE, NULL); + gtk_tree_view_column_pack_start (column, cell, TRUE); + gtk_tree_view_column_add_attribute (column, cell, "text", COL_SOURCE); + } import_widget_add_accounts_to_model (self); } @@ -352,6 +360,42 @@ import_widget_destroy_cb (GtkWidget *w, g_object_unref (self); } +static void +do_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyImportWidgetPriv *priv = GET_PRIV (object); + + switch (property_id) + { + case PROP_APPLICATION_ID: + g_value_set_int (value, priv->app_id); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +do_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyImportWidgetPriv *priv = GET_PRIV (object); + + switch (property_id) + { + case PROP_APPLICATION_ID: + priv->app_id = g_value_get_int (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + static void do_finalize (GObject *obj) { @@ -393,6 +437,8 @@ do_constructed (GObject *obj) GtkBuilder *gui; gchar *filename; + priv->accounts = empathy_import_accounts_load (priv->app_id); + filename = empathy_file_lookup ("empathy-import-dialog.ui", "src"); gui = empathy_builder_get_file (filename, "widget_vbox", &priv->vbox, @@ -416,10 +462,19 @@ static void empathy_import_widget_class_init (EmpathyImportWidgetClass *klass) { GObjectClass *oclass = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; oclass->constructed = do_constructed; oclass->finalize = do_finalize; oclass->dispose = do_dispose; + oclass->set_property = do_set_property; + oclass->get_property = do_get_property; + + param_spec = g_param_spec_int ("application-id", + "application-id", "The application id to import from", + 0, EMPATHY_IMPORT_APPLICATION_INVALID, EMPATHY_IMPORT_APPLICATION_ALL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_APPLICATION_ID, param_spec); g_type_class_add_private (klass, sizeof (EmpathyImportWidgetPriv)); } @@ -433,16 +488,13 @@ empathy_import_widget_init (EmpathyImportWidget *self) self->priv = priv; - /* Load all accounts from all supported applications */ - priv->accounts = empathy_import_pidgin_load (); - priv->cms = empathy_connection_managers_dup_singleton (); } EmpathyImportWidget * -empathy_import_widget_new (void) +empathy_import_widget_new (EmpathyImportApplication id) { - return g_object_new (EMPATHY_TYPE_IMPORT_WIDGET, NULL); + return g_object_new (EMPATHY_TYPE_IMPORT_WIDGET, "application-id", id, NULL); } GtkWidget * diff --git a/src/empathy-import-widget.h b/src/empathy-import-widget.h index 8af953d79..48f2e1d48 100644 --- a/src/empathy-import-widget.h +++ b/src/empathy-import-widget.h @@ -27,6 +27,8 @@ #include +#include "empathy-import-utils.h" + G_BEGIN_DECLS #define EMPATHY_TYPE_IMPORT_WIDGET empathy_import_widget_get_type() @@ -57,7 +59,7 @@ typedef struct { GType empathy_import_widget_get_type (void); -EmpathyImportWidget* empathy_import_widget_new (void); +EmpathyImportWidget* empathy_import_widget_new (EmpathyImportApplication id); GtkWidget * empathy_import_widget_get_widget (EmpathyImportWidget *self); diff --git a/tests/Makefile.am b/tests/Makefile.am index 1e0a59e8e..8832181dd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -40,7 +40,7 @@ test_empathy_account_assistant_SOURCES = test-empathy-account-assistant.c test_empathy_account_assistant_CFLAGS = -I$(top_srcdir)/src test_empathy_account_assistant_LDADD = \ $(top_builddir)/src/empathy-account-assistant.o \ - $(top_builddir)/src/empathy-import-dialog.o \ + $(top_builddir)/src/empathy-import-utils.o \ $(top_builddir)/src/empathy-import-pidgin.o \ $(top_builddir)/src/empathy-import-widget.o \ $(LDADD) -- cgit v1.2.3 From f77948f72bf1863ed85d903c9a6f28353f36b175 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 10 Aug 2009 17:20:17 +0200 Subject: Add example labels to the simple widgets --- libempathy-gtk/empathy-account-widget-aim.ui | 28 +++++++++++++++++++--- libempathy-gtk/empathy-account-widget-groupwise.ui | 28 +++++++++++++++++++--- libempathy-gtk/empathy-account-widget-icq.ui | 28 +++++++++++++++++++--- libempathy-gtk/empathy-account-widget-jabber.ui | 28 +++++++++++++++++++--- libempathy-gtk/empathy-account-widget-msn.ui | 28 +++++++++++++++++++--- libempathy-gtk/empathy-account-widget-sip.ui | 28 +++++++++++++++++++--- libempathy-gtk/empathy-account-widget-yahoo.ui | 28 +++++++++++++++++++--- 7 files changed, 175 insertions(+), 21 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-aim.ui b/libempathy-gtk/empathy-account-widget-aim.ui index d6696f583..05c942d9c 100644 --- a/libempathy-gtk/empathy-account-widget-aim.ui +++ b/libempathy-gtk/empathy-account-widget-aim.ui @@ -211,12 +211,34 @@ 0 0.34999999403953552 0.34999999403953552 + 3 12 - + True - True - + vertical + 4 + + + True + True + + + + 0 + + + + + True + 0.10000000149011612 + <span size="small"><b>Example:</b> MyScreenName</span> + True + + + 1 + + diff --git a/libempathy-gtk/empathy-account-widget-groupwise.ui b/libempathy-gtk/empathy-account-widget-groupwise.ui index f5ddf8d9f..c0a717e5e 100644 --- a/libempathy-gtk/empathy-account-widget-groupwise.ui +++ b/libempathy-gtk/empathy-account-widget-groupwise.ui @@ -215,12 +215,34 @@ 0 0.34999999403953552 0.34999999403953552 + 3 12 - + True - True - + vertical + 4 + + + True + True + + + + 0 + + + + + True + 0.10000000149011612 + <span size="small"><b>Example:</b> username</span> + True + + + 1 + + diff --git a/libempathy-gtk/empathy-account-widget-icq.ui b/libempathy-gtk/empathy-account-widget-icq.ui index b2a62c215..1a19500b5 100644 --- a/libempathy-gtk/empathy-account-widget-icq.ui +++ b/libempathy-gtk/empathy-account-widget-icq.ui @@ -240,12 +240,34 @@ 0 0.34999999403953552 0.34999999403953552 + 3 12 - + True - True - + vertical + 4 + + + True + True + + + + 0 + + + + + True + 0.10000000149011612 + <span size="small"><b>Example:</b> 123456789</span> + True + + + 1 + + diff --git a/libempathy-gtk/empathy-account-widget-jabber.ui b/libempathy-gtk/empathy-account-widget-jabber.ui index 164bbcdf9..d1c28774b 100644 --- a/libempathy-gtk/empathy-account-widget-jabber.ui +++ b/libempathy-gtk/empathy-account-widget-jabber.ui @@ -378,12 +378,34 @@ 0.34999999403953552 0.34999999403953552 6 + 3 12 - + True - True - + vertical + 4 + + + True + True + + + + 0 + + + + + True + 0.10000000149011612 + <span size="small"><b>Example:</b> user@jabber.org</span> + True + + + 1 + + diff --git a/libempathy-gtk/empathy-account-widget-msn.ui b/libempathy-gtk/empathy-account-widget-msn.ui index 2f06d88e7..dbca5fc7e 100644 --- a/libempathy-gtk/empathy-account-widget-msn.ui +++ b/libempathy-gtk/empathy-account-widget-msn.ui @@ -215,12 +215,34 @@ 0 0.34999999403953552 0.34999999403953552 + 3 12 - + True - True - + vertical + 4 + + + True + True + + + + 0 + + + + + True + 0.10000000149011612 + <span size="small"><b>Example:</b> user@hotmail.com</span> + True + + + 1 + + diff --git a/libempathy-gtk/empathy-account-widget-sip.ui b/libempathy-gtk/empathy-account-widget-sip.ui index edb70e426..84e68b01f 100644 --- a/libempathy-gtk/empathy-account-widget-sip.ui +++ b/libempathy-gtk/empathy-account-widget-sip.ui @@ -233,12 +233,34 @@ 0 0.34999999403953552 0.34999999403953552 + 3 12 - + True - True - + vertical + 4 + + + True + True + + + + 0 + + + + + True + 0.10000000149011612 + <span size="small"><b>Example:</b> user@my.sip.server</span> + True + + + 1 + + diff --git a/libempathy-gtk/empathy-account-widget-yahoo.ui b/libempathy-gtk/empathy-account-widget-yahoo.ui index 75c27f15c..0800ac1dc 100644 --- a/libempathy-gtk/empathy-account-widget-yahoo.ui +++ b/libempathy-gtk/empathy-account-widget-yahoo.ui @@ -315,12 +315,34 @@ 0 0.34999999403953552 0.34999999403953552 + 3 12 - + True - True - + vertical + 4 + + + True + True + + + + 0 + + + + + True + 0.10000000149011612 + <span size="small"><b>Example:</b> username</span> + True + + + 1 + + -- cgit v1.2.3 From 165945e35293556ba6d133f5f90a7251de8d8e4b Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 11 Aug 2009 17:48:59 +0200 Subject: Enable entering more than an account from the wizard. --- src/empathy-account-assistant.c | 167 +++++++++++++++++++++++++++++++--------- 1 file changed, 131 insertions(+), 36 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index ab42bbd4f..613ba4b8c 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -47,11 +47,15 @@ typedef enum { RESPONSE_SALUT_ONLY = 4 } FirstPageResponse; +typedef enum { + RESPONSE_CREATE_AGAIN = 1, + RESPONSE_CREATE_STOP = 2 +} CreateEnterPageResponse; + enum { PAGE_INTRO = 0, PAGE_IMPORT = 1, PAGE_ENTER_CREATE = 2, - PAGE_SALUT_ONLY = 3 }; enum { @@ -60,6 +64,8 @@ enum { typedef struct { FirstPageResponse first_resp; + CreateEnterPageResponse create_enter_resp; + gboolean enter_create_forward; /* enter or create page */ GtkWidget *enter_or_create_page; @@ -68,6 +74,7 @@ typedef struct { GtkWidget *first_label; GtkWidget *second_label; GtkWidget *chooser; + GtkWidget *create_again_radio; EmpathyAccountSettings *settings; gboolean is_creating; @@ -79,6 +86,12 @@ typedef struct { gboolean dispose_run; } EmpathyAccountAssistantPriv; +static GtkWidget * account_assistant_build_enter_or_create_page ( + EmpathyAccountAssistant *self); +static void account_assistant_finish_enter_or_create_page ( + EmpathyAccountAssistant *self, + gboolean is_enter); + static GtkWidget * account_assistant_build_error_page (EmpathyAccountAssistant *self, GError *error, gint page_num) @@ -110,11 +123,11 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self, if (page_num == PAGE_IMPORT) /* translators: this follows the "There has been an error " string */ str = g_string_append (str, _("while importing the accounts.")); - else if (page_num == PAGE_ENTER_CREATE && + else if (page_num >= PAGE_ENTER_CREATE && priv->first_resp == RESPONSE_ENTER_ACCOUNT) /* translators: this follows the "There has been an error " string */ str = g_string_append (str, _("while parsing the account details.")); - else if (page_num == PAGE_ENTER_CREATE && + else if (page_num >= PAGE_ENTER_CREATE && priv->first_resp == RESPONSE_CREATE_ACCOUNT) /* translators: this follows the "There has been an error " string */ str = g_string_append (str, _("while creating the account.")); @@ -193,6 +206,26 @@ account_assistant_present_error_page (EmpathyAccountAssistant *self, gtk_assistant_set_current_page (GTK_ASSISTANT (self), num); } +static void +account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self) +{ + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + GtkWidget *page; + gint idx; + + page = account_assistant_build_enter_or_create_page (self); + idx = gtk_assistant_append_page (GTK_ASSISTANT (self), page); + gtk_assistant_set_page_type (GTK_ASSISTANT (self), page, + GTK_ASSISTANT_PAGE_CONFIRM); + priv->enter_or_create_page = page; + + gtk_assistant_set_current_page (GTK_ASSISTANT (self), idx); + + account_assistant_finish_enter_or_create_page (self, + priv->first_resp == RESPONSE_ENTER_ACCOUNT ? + TRUE : FALSE); +} + static void account_assistant_account_enabled_cb (GObject *source, GAsyncResult *result, @@ -200,6 +233,7 @@ account_assistant_account_enabled_cb (GObject *source, { GError *error = NULL; EmpathyAccountAssistant *self = user_data; + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); empathy_account_set_enabled_finish (EMPATHY_ACCOUNT (source), result, &error); @@ -210,7 +244,10 @@ account_assistant_account_enabled_cb (GObject *source, g_error_free (error); } - g_signal_emit_by_name (self, "close"); + if (priv->create_enter_resp == RESPONSE_CREATE_STOP) + g_signal_emit_by_name (self, "close"); + else + account_assistant_reset_enter_create_page (self); } static void @@ -230,7 +267,8 @@ account_assistant_apply_account_cb (GObject *source, if (error != NULL) { - account_assistant_present_error_page (self, error, PAGE_ENTER_CREATE); + account_assistant_present_error_page (self, error, + gtk_assistant_get_current_page (GTK_ASSISTANT (self))); g_error_free (error); return; } @@ -356,9 +394,12 @@ account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self, { gtk_label_set_label (GTK_LABEL (priv->first_label), _("What kind of chat account do you have?")); - gtk_label_set_label (GTK_LABEL (priv->second_label), + /* gtk_label_set_label (GTK_LABEL (priv->second_label), _("If you have other accounts to set up, you can do " "that at any time from the Edit menu.")); + */ + gtk_label_set_label (GTK_LABEL (priv->second_label), + _("Do you have any other chat accounts you want to set up?")); empathy_protocol_chooser_set_visible ( EMPATHY_PROTOCOL_CHOOSER (priv->chooser), account_assistant_chooser_enter_details_filter_func, self); @@ -370,9 +411,12 @@ account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self, { gtk_label_set_label (GTK_LABEL (priv->first_label), _("What kind of chat account do you want to create?")); - gtk_label_set_label (GTK_LABEL (priv->second_label), + /* gtk_label_set_label (GTK_LABEL (priv->second_label), _("You can register other accounts, or setup " "an existing one at any time from the Edit menu.")); + */ + gtk_label_set_label (GTK_LABEL (priv->second_label), + _("Do you want to create other chat accounts?")); empathy_protocol_chooser_set_visible ( EMPATHY_PROTOCOL_CHOOSER (priv->chooser), account_assistant_chooser_create_account_filter_func, self); @@ -399,7 +443,7 @@ account_assistant_page_forward_func (gint current_page, retval = current_page; - if (current_page == 0) + if (current_page == PAGE_INTRO) { if (priv->first_resp == RESPONSE_ENTER_ACCOUNT || priv->first_resp == RESPONSE_CREATE_ACCOUNT) @@ -408,11 +452,16 @@ account_assistant_page_forward_func (gint current_page, retval = PAGE_IMPORT; } - if (current_page == PAGE_ENTER_CREATE || - current_page == PAGE_IMPORT) + if (current_page == PAGE_IMPORT || + current_page >= PAGE_ENTER_CREATE) + /* don't forward anymore */ + retval = -1; + + if (current_page >= PAGE_ENTER_CREATE && + priv->create_enter_resp == RESPONSE_CREATE_AGAIN) { - /* don't forward anymore */ - retval = -1; + priv->enter_create_forward = TRUE; + retval = current_page; } return retval; @@ -591,13 +640,29 @@ account_assistant_build_import_page (EmpathyAccountAssistant *self) return main_vbox; } +static void +account_assistant_radio_create_again_clicked_cb (GtkButton *button, + EmpathyAccountAssistant *self) +{ + CreateEnterPageResponse response; + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); + + response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), + "response")); + + priv->create_enter_resp = response; + + gtk_assistant_set_page_type (GTK_ASSISTANT (self), + priv->enter_or_create_page, + (response == RESPONSE_CREATE_AGAIN) ? + GTK_ASSISTANT_PAGE_CONTENT : GTK_ASSISTANT_PAGE_CONFIRM); +} + static GtkWidget * -account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self, - gboolean is_enter) +account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self) { EmpathyAccountAssistantPriv *priv = GET_PRIV (self); - GtkWidget *main_vbox, *w, *chooser, *hbox; - PangoAttrList *list; + GtkWidget *main_vbox, *w, *chooser, *vbox, *hbox, *radio; main_vbox = gtk_vbox_new (FALSE, 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); @@ -619,24 +684,46 @@ account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self, gtk_widget_show (chooser); priv->chooser = chooser; - hbox = gtk_hbox_new (FALSE, 6); - gtk_box_pack_end (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - w = gtk_image_new_from_icon_name ("gtk-dialog-info", GTK_ICON_SIZE_BUTTON); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); + vbox = gtk_vbox_new (FALSE, 6); + gtk_box_pack_end (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0); + gtk_widget_show (vbox); w = gtk_label_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - list = pango_attr_list_new (); - pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_SMALL)); - gtk_label_set_attributes (GTK_LABEL (w), list); + gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); gtk_label_set_line_wrap (GTK_LABEL (w), TRUE); gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); gtk_widget_show (w); priv->second_label = w; - pango_attr_list_unref (list); + + w = gtk_alignment_new (0, 0, 0, 0); + gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0); + gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + hbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (w), hbox); + gtk_widget_show (hbox); + + radio = gtk_radio_button_new_with_label (NULL, _("Yes")); + gtk_box_pack_start (GTK_BOX (hbox), radio, FALSE, FALSE, 0); + g_object_set_data (G_OBJECT (radio), "response", + GINT_TO_POINTER (RESPONSE_CREATE_AGAIN)); + gtk_widget_show (radio); + + w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), + _("No, that's all for now")); + gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); + g_object_set_data (G_OBJECT (w), "response", + GINT_TO_POINTER (RESPONSE_CREATE_STOP)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE); + priv->create_enter_resp = RESPONSE_CREATE_STOP; + priv->create_again_radio = w; + gtk_widget_show (w); + + g_signal_connect (w, "clicked", + G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self); + g_signal_connect (radio, "clicked", + G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self); return main_vbox; } @@ -662,10 +749,10 @@ impl_signal_apply (GtkAssistant *assistant) current_page = gtk_assistant_get_current_page (assistant); - if (current_page == RESPONSE_ENTER_ACCOUNT) + if (current_page >= PAGE_ENTER_CREATE) account_assistant_apply_account_and_finish (self); - if (current_page == RESPONSE_IMPORT) + if (current_page == PAGE_IMPORT) empathy_import_widget_add_selected_accounts (priv->iw); } @@ -684,12 +771,20 @@ impl_signal_prepare (GtkAssistant *assistant, gint current_idx; current_idx = gtk_assistant_get_current_page (assistant); - - if (current_idx == PAGE_ENTER_CREATE) + + if (current_idx >= PAGE_ENTER_CREATE) { - account_assistant_finish_enter_or_create_page (self, - priv->first_resp == RESPONSE_ENTER_ACCOUNT ? - TRUE : FALSE); + if (!priv->enter_create_forward) + { + account_assistant_finish_enter_or_create_page (self, + priv->first_resp == RESPONSE_ENTER_ACCOUNT ? + TRUE : FALSE); + } + else + { + priv->enter_create_forward = FALSE; + account_assistant_apply_account_and_finish (self); + } } } @@ -826,7 +921,7 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); /* third page (enter account details) */ - page = account_assistant_build_enter_or_create_page (self, TRUE); + page = account_assistant_build_enter_or_create_page (self); gtk_assistant_append_page (assistant, page); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); priv->enter_or_create_page = page; -- cgit v1.2.3 From adc79c5d0574f548cfe2b89cb0e04d74a5d1e40e Mon Sep 17 00:00:00 2001 From: Jonathan Tellier Date: Thu, 13 Aug 2009 08:56:02 -0400 Subject: First part of an overhaul of the accounts dialog --- libempathy-gtk/empathy-account-widget-jabber.ui | 53 ++- libempathy-gtk/empathy-account-widget.c | 302 ++++++++++++++--- libempathy-gtk/empathy-account-widget.h | 16 +- libempathy/empathy-account-manager.c | 9 +- libempathy/empathy-account-settings.c | 49 ++- libempathy/empathy-account-settings.h | 3 + src/empathy-account-assistant.c | 5 +- src/empathy-accounts-dialog.c | 416 ++++++++++++------------ src/empathy-accounts-dialog.ui | 137 +++----- 9 files changed, 628 insertions(+), 362 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-jabber.ui b/libempathy-gtk/empathy-account-widget-jabber.ui index d1c28774b..5fddcb7b8 100644 --- a/libempathy-gtk/empathy-account-widget-jabber.ui +++ b/libempathy-gtk/empathy-account-widget-jabber.ui @@ -21,7 +21,7 @@ True - 2 + 3 3 12 6 @@ -35,8 +35,8 @@ 1 2 - 1 - 2 + 2 + 3 @@ -55,7 +55,7 @@ True - 0 + 1 Login I_D: True entry_id @@ -81,8 +81,8 @@ 2 3 - 1 - 2 + 2 + 3 GTK_FILL @@ -90,18 +90,47 @@ True - 0 + 1 Pass_word: True entry_password - 1 - 2 + 2 + 3 GTK_FILL + + + True + 1 + <span size="small">Example:</span> + True + + + 1 + 2 + + + + + True + 0 + <span size="small">test@jabber.org</span> + True + + + 1 + 2 + 1 + 2 + + + + + False @@ -114,7 +143,7 @@ True True - + True vertical @@ -227,7 +256,7 @@ 0 none - + True 12 @@ -371,7 +400,7 @@ - + True 0 0 diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 713f50048..2f6537aeb 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2006-2007 Imendio AB * Copyright (C) 2007-2009 Collabora Ltd. @@ -21,6 +20,7 @@ * Authors: Xavier Claessens * Martyn Russell * Cosimo Cecchi + * Jonathan Tellier */ #include @@ -52,24 +52,41 @@ typedef struct { char *protocol; EmpathyAccountSettings *settings; + GtkWidget *table_common_settings; GtkWidget *apply_button; + GtkWidget *cancel_button; GtkWidget *entry_password; GtkWidget *button_forget; GtkWidget *spinbutton_port; + GtkWidget *enabled_checkbox; gboolean simple; + /* An EmpathyAccountWidget can be used to either create an account or + * modify it. When we are creating an account, this member is set to TRUE */ + gboolean creating_account; + + /* After having applied changes to a user account, we automatically + * disconnect him. Once he's disconnected, he will be reconnected, + * depending on the value of this member which should be set to the checked + * state of the "Enabled" checkbox. This is done so the new information + * entered by the user is validated on the server. */ + gboolean re_enable_accound; + gboolean dispose_run; } EmpathyAccountWidgetPriv; enum { PROP_PROTOCOL = 1, PROP_SETTINGS, - PROP_SIMPLE + PROP_SIMPLE, + PROP_CREATING_ACCOUNT }; enum { HANDLE_APPLY, + ACCOUNT_CREATED, + CANCELLED, LAST_SIGNAL }; @@ -79,7 +96,20 @@ static guint signals[LAST_SIGNAL] = { 0 }; #define CHANGED_TIMEOUT 300 static void -account_widget_handle_apply_sensitivity (EmpathyAccountWidget *self) +account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self, + gboolean sensitive) +{ + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + + if (!priv->simple) + { + gtk_widget_set_sensitive (priv->apply_button, sensitive); + gtk_widget_set_sensitive (priv->cancel_button, sensitive); + } +} + +static void +account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); gboolean is_valid; @@ -87,7 +117,10 @@ account_widget_handle_apply_sensitivity (EmpathyAccountWidget *self) is_valid = empathy_account_settings_is_valid (priv->settings); if (!priv->simple) - gtk_widget_set_sensitive (priv->apply_button, is_valid); + { + gtk_widget_set_sensitive (priv->apply_button, is_valid); + gtk_widget_set_sensitive (priv->cancel_button, is_valid); + } g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid); } @@ -120,11 +153,9 @@ account_widget_entry_changed_common (EmpathyAccountWidget *self, else { DEBUG ("Setting %s to %s", param_name, - strstr (param_name, "password") ? "***" : str); + tp_strdiff (param_name, "password") ? str : "***"); empathy_account_settings_set_string (priv->settings, param_name, str); } - - account_widget_handle_apply_sensitivity (self); } static gboolean @@ -142,6 +173,7 @@ account_widget_entry_changed_cb (GtkEditable *entry, EmpathyAccountWidget *self) { account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE); + account_widget_handle_control_buttons_sensitivity (self); } static void @@ -182,7 +214,7 @@ account_widget_int_changed_cb (GtkWidget *widget, g_return_if_reached (); } - account_widget_handle_apply_sensitivity (self); + account_widget_handle_control_buttons_sensitivity (self); } static void @@ -214,7 +246,7 @@ account_widget_checkbutton_toggled_cb (GtkWidget *widget, empathy_account_settings_set_boolean (priv->settings, param_name, value); } - account_widget_handle_apply_sensitivity (self); + account_widget_handle_control_buttons_sensitivity (self); } static void @@ -231,7 +263,7 @@ account_widget_forget_clicked_cb (GtkWidget *button, empathy_account_settings_unset (priv->settings, param_name); gtk_entry_set_text (GTK_ENTRY (priv->entry_password), ""); - account_widget_handle_apply_sensitivity (self); + account_widget_handle_control_buttons_sensitivity (self); } static void @@ -540,13 +572,97 @@ account_widget_handle_params_valist (EmpathyAccountWidget *self, } } +static void +account_widget_cancel_clicked_cb (GtkWidget *button, + EmpathyAccountWidget *self) +{ + g_signal_emit (self, signals[CANCELLED], 0); +} + +static void +account_widget_account_enabled_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + EmpathyAccount *account = EMPATHY_ACCOUNT (source_object); + EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data); + + empathy_account_set_enabled_finish (account, res, &error); + + if (error != NULL) + { + DEBUG ("Could not automatically enable new account: %s", error->message); + g_error_free (error); + } + else + { + g_signal_emit (widget, signals[ACCOUNT_CREATED], 0); + } +} + +static void +account_widget_applied_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + EmpathyAccount *account; + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object); + EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data); + EmpathyAccountWidgetPriv *priv = GET_PRIV (widget); + + empathy_account_settings_apply_finish (settings, res, &error); + + if (error != NULL) + { + DEBUG ("Could not apply changes to account: %s", error->message); + g_error_free (error); + return; + } + + account = empathy_account_settings_get_account (priv->settings); + + if (priv->creating_account) + { + /* By default, when an account is created, we enable it. */ + empathy_account_set_enabled_async (account, TRUE, + account_widget_account_enabled_cb, widget); + } + else if (account != NULL && priv->enabled_checkbox != NULL) + { + gboolean enabled_checked; + + enabled_checked = gtk_toggle_button_get_active ( + GTK_TOGGLE_BUTTON (priv->enabled_checkbox)); + + if (empathy_account_is_enabled (account)) + { + /* We want to disable the account (and possibly re-enable it) to make + * sure that the new settings are effective */ + priv->re_enable_accound = enabled_checked; + empathy_account_set_enabled_async (account, FALSE, NULL, NULL); + } + else + { + /* The account is already disable so we just enable it according + * to the value of the "Enabled" checkbox */ + empathy_account_set_enabled_async (account, enabled_checked, + NULL, NULL); + } + } + + account_widget_set_control_buttons_sensitivity (widget, FALSE); +} + static void account_widget_apply_clicked_cb (GtkWidget *button, EmpathyAccountWidget *self) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - empathy_account_settings_apply_async (priv->settings, NULL, NULL); + empathy_account_settings_apply_async (priv->settings, + account_widget_applied_cb, self); } static void @@ -686,7 +802,7 @@ account_widget_build_jabber (EmpathyAccountWidget *self, gtk_widget_show (label_id_create); gtk_widget_show (label_password_create); } - + empathy_account_widget_handle_params (self, "entry_id_simple", "account", "entry_password_simple", "password", @@ -697,6 +813,7 @@ account_widget_build_jabber (EmpathyAccountWidget *self, else { self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_settings", &priv->table_common_settings, "vbox_jabber_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, "checkbutton_ssl", &checkbutton_ssl, @@ -808,7 +925,7 @@ account_widget_build_yahoo (EmpathyAccountWidget *self, const char *filename) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - + if (priv->simple) { self->ui_details->gui = empathy_builder_get_file (filename, @@ -888,6 +1005,37 @@ account_widget_destroy_cb (GtkWidget *widget, g_object_unref (self); } +static void +empathy_account_widget_enabled_cb (EmpathyAccount *account, + GParamSpec *spec, + gpointer user_data) +{ + EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data); + EmpathyAccountWidgetPriv *priv = GET_PRIV (widget); + gboolean enabled = empathy_account_is_enabled (account); + + if (!enabled && priv->re_enable_accound) + { + /* The account has been disabled because we were applying changes. + * However, the user wants the account to be enabled so let's re-enable + * it */ + empathy_account_set_enabled_async (account, TRUE, NULL, NULL); + } + else if (priv->enabled_checkbox != NULL) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox), + enabled); + } +} + +static void +account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button, + gpointer user_data) +{ + account_widget_handle_control_buttons_sensitivity ( + EMPATHY_ACCOUNT_WIDGET (user_data)); +} + static void do_set_property (GObject *object, guint prop_id, @@ -907,6 +1055,9 @@ do_set_property (GObject *object, case PROP_SIMPLE: priv->simple = g_value_get_boolean (value); break; + case PROP_CREATING_ACCOUNT: + priv->creating_account = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -931,6 +1082,9 @@ do_get_property (GObject *object, case PROP_SIMPLE: g_value_set_boolean (value, priv->simple); break; + case PROP_CREATING_ACCOUNT: + g_value_set_boolean (value, priv->creating_account); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -941,6 +1095,7 @@ 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, @@ -1012,18 +1167,64 @@ do_constructed (GObject *obj) self); } - /* handle apply button */ + /* handle apply and cancel button */ if (!priv->simple) { + GtkWidget *hbox = gtk_hbox_new (TRUE, 3); + + priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY); - gtk_box_pack_end (GTK_BOX (self->ui_details->widget), priv->apply_button, - FALSE, FALSE, 3); + gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE, + TRUE, 3); + gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE, + TRUE, 3); + + gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE, + FALSE, 3); + + g_signal_connect (priv->cancel_button, "clicked", + G_CALLBACK (account_widget_cancel_clicked_cb), + self); g_signal_connect (priv->apply_button, "clicked", G_CALLBACK (account_widget_apply_clicked_cb), self); - account_widget_handle_apply_sensitivity (self); - gtk_widget_show (priv->apply_button); + gtk_widget_show_all (hbox); + account_widget_set_control_buttons_sensitivity(self, FALSE); + } + + account = empathy_account_settings_get_account (priv->settings); + + if (account != NULL) + { + g_signal_connect (account, "notify::enabled", + G_CALLBACK (empathy_account_widget_enabled_cb), self); + } + + /* handle the "Enabled" checkbox. We only add it when modifying an account */ + if (!priv->creating_account && priv->table_common_settings != NULL) + { + guint nb_rows, nb_columns; + + priv->enabled_checkbox = + gtk_check_button_new_with_label (_("Enabled")); + gtk_toggle_button_set_active ( + GTK_TOGGLE_BUTTON (priv->enabled_checkbox), + empathy_account_is_enabled (account)); + + g_object_get (priv->table_common_settings, "n-rows", &nb_rows, + "n-columns", &nb_columns, NULL); + + gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows, + nb_columns); + + gtk_table_attach_defaults (GTK_TABLE (priv->table_common_settings), + priv->enabled_checkbox, 0, nb_columns, nb_rows - 1, nb_rows); + + gtk_widget_show (priv->enabled_checkbox); + + g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled", + G_CALLBACK (account_widget_enabled_toggled_cb), self); } /* hook up to widget destruction to unref ourselves */ @@ -1046,8 +1247,19 @@ do_dispose (GObject *obj) priv->dispose_run = TRUE; + empathy_account_settings_is_ready (priv->settings); + if (priv->settings != NULL) { + EmpathyAccount *account; + account = empathy_account_settings_get_account (priv->settings); + + if (account != NULL) + { + g_signal_handlers_disconnect_by_func (account, + empathy_account_widget_enabled_cb, self); + } + g_object_unref (priv->settings); priv->settings = NULL; } @@ -1101,6 +1313,13 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (oclass, PROP_SIMPLE, param_spec); + param_spec = g_param_spec_boolean ("creating-account", + "creating-account", + "TRUE if we're creating an account, FALSE if we're modifying it", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec); + signals[HANDLE_APPLY] = g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, @@ -1108,6 +1327,21 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + /* This signal is emitted when an account has been created and enabled. */ + signals[ACCOUNT_CREATED] = + g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + signals[CANCELLED] = + g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); } @@ -1139,26 +1373,15 @@ empathy_account_widget_handle_params (EmpathyAccountWidget *self, } GtkWidget * -empathy_account_widget_new_for_protocol (const char *protocol, - EmpathyAccountSettings *settings) +empathy_account_widget_get_widget (EmpathyAccountWidget *widget) { - EmpathyAccountWidget *self; - EmpathyAccountWidgetPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL); - g_return_val_if_fail (settings != NULL, NULL); - - self = g_object_new - (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol, - "settings", settings, NULL); - priv = GET_PRIV (self); - - return self->ui_details->widget; + return widget->ui_details->widget; } -GtkWidget * -empathy_account_widget_simple_new_for_protocol (const char *protocol, - EmpathyAccountSettings *settings, EmpathyAccountWidget **object) +EmpathyAccountWidget * +empathy_account_widget_new_for_protocol (const char *protocol, + EmpathyAccountSettings *settings, + gboolean simple) { EmpathyAccountWidget *self; @@ -1167,9 +1390,10 @@ empathy_account_widget_simple_new_for_protocol (const char *protocol, self = g_object_new (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol, - "settings", settings, "simple", TRUE, NULL); - - *object = self; + "settings", settings, "simple", simple, + "creating-account", + empathy_account_settings_get_account (settings) == NULL, + NULL); - return self->ui_details->widget; + return self; } diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h index ab4e62b45..f44edcc6a 100644 --- a/libempathy-gtk/empathy-account-widget.h +++ b/libempathy-gtk/empathy-account-widget.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2006-2007 Imendio AB * Copyright (C) 2007-2008 Collabora Ltd. @@ -60,12 +59,15 @@ typedef struct { GType empathy_account_widget_get_type (void); -GtkWidget *empathy_account_widget_new_for_protocol (const char *protocol, - EmpathyAccountSettings *settings); -GtkWidget * empathy_account_widget_simple_new_for_protocol - (const char *protocol, - EmpathyAccountSettings *settings, - EmpathyAccountWidget **object); +GtkWidget *empathy_account_widget_get_widget (EmpathyAccountWidget *widget); + +//EmpathyAccountWidget *empathy_account_widget_new_for_protocol ( +// const char *protocol, +// EmpathyAccountSettings *settings); +EmpathyAccountWidget * empathy_account_widget_new_for_protocol ( + const char *protocol, + EmpathyAccountSettings *settings, + gboolean simple); G_END_DECLS diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 83de26c67..2f0f13415 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -372,11 +372,14 @@ account_manager_got_all_cb (TpProxy *proxy, accounts = tp_asv_get_boxed (properties, "ValidAccounts", EMPATHY_ARRAY_TYPE_OBJECT); - for (i = 0; i < accounts->len; i++) + if (accounts != NULL) { - gchar *name = g_ptr_array_index (accounts, i); + for (i = 0; i < accounts->len; i++) + { + gchar *name = g_ptr_array_index (accounts, i); - empathy_account_manager_get_account (manager, name); + empathy_account_manager_get_account (manager, name); + } } empathy_account_manager_check_ready (manager); diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index ce0ba1bfa..6129570c2 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -40,6 +40,7 @@ enum { PROP_CM_NAME, PROP_PROTOCOL, PROP_DISPLAY_NAME, + PROP_DISPLAY_NAME_OVERRIDDEN, PROP_READY }; @@ -61,6 +62,7 @@ struct _EmpathyAccountSettingsPriv gchar *protocol; gchar *display_name; gchar *icon_name; + gboolean display_name_overridden; gboolean ready; GHashTable *parameters; @@ -86,7 +88,7 @@ empathy_account_settings_init (EmpathyAccountSettings *obj) priv->account_manager = empathy_account_manager_dup_singleton (); priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify) tp_g_value_slice_free); + g_free, (GDestroyNotify) tp_g_value_slice_free); priv->unset_parameters = g_array_new (TRUE, FALSE, sizeof (gchar *)); } @@ -121,6 +123,9 @@ empathy_account_settings_set_property (GObject *object, case PROP_DISPLAY_NAME: priv->display_name = g_value_dup_string (value); break; + case PROP_DISPLAY_NAME_OVERRIDDEN: + priv->display_name_overridden = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -150,6 +155,9 @@ empathy_account_settings_get_property (GObject *object, case PROP_DISPLAY_NAME: g_value_set_string (value, priv->display_name); break; + case PROP_DISPLAY_NAME_OVERRIDDEN: + g_value_set_boolean (value, priv->display_name_overridden); + break; case PROP_READY: g_value_set_boolean (value, priv->ready); break; @@ -240,6 +248,13 @@ empathy_account_settings_class_init ( NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_DISPLAY_NAME_OVERRIDDEN, + g_param_spec_boolean ("display-name-overridden", + "display-name-overridden", + "Whether the display name for this account has been manually overridden", + FALSE, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_READY, g_param_spec_boolean ("ready", "Ready", @@ -560,9 +575,6 @@ empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings, p = empathy_account_settings_get_tp_param (settings, param); - if (p == NULL) - return NULL; - return p->dbus_signature; } @@ -610,6 +622,21 @@ empathy_account_settings_unset (EmpathyAccountSettings *settings, g_hash_table_remove (priv->parameters, param); } +void +empathy_account_settings_discard_changes (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + + if (g_hash_table_size (priv->parameters) > 0) + g_hash_table_remove_all (priv->parameters); + + if (priv->unset_parameters->len > 0) + { + g_array_remove_range (priv->unset_parameters, 0, + priv->unset_parameters->len); + } +} + const gchar * empathy_account_settings_get_string (EmpathyAccountSettings *settings, const gchar *param) @@ -960,13 +987,9 @@ empathy_account_settings_created_cb (GObject *source, EMPATHY_ACCOUNT_MANAGER (source), result, &error); if (account == NULL) - { - g_simple_async_result_set_from_error (priv->apply_result, error); - } + g_simple_async_result_set_from_error (priv->apply_result, error); else - { - priv->account = g_object_ref (account); - } + priv->account = g_object_ref (account); r = priv->apply_result; priv->apply_result = NULL; @@ -1065,6 +1088,12 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings, if (priv->account == NULL) { + const gchar *default_display_name; + default_display_name = empathy_account_settings_get_string (settings, + "account"); + empathy_account_settings_set_display_name_async (settings, + default_display_name, NULL, NULL); + if (empathy_account_manager_is_ready (priv->account_manager)) empathy_account_settings_do_create_account (settings); else diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h index 9bb6657e2..476bfb397 100644 --- a/libempathy/empathy-account-settings.h +++ b/libempathy/empathy-account-settings.h @@ -86,6 +86,9 @@ TpConnectionManagerParam *empathy_account_settings_get_tp_params ( void empathy_account_settings_unset (EmpathyAccountSettings *settings, const gchar *param); +void empathy_account_settings_discard_changes ( + EmpathyAccountSettings *settings); + const GValue *empathy_account_settings_get (EmpathyAccountSettings *settings, const gchar *param); diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 613ba4b8c..8b803a9b6 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -334,8 +334,9 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser, if (priv->first_resp == RESPONSE_CREATE_ACCOUNT) empathy_account_settings_set_boolean (settings, "register", TRUE); - account_widget = empathy_account_widget_simple_new_for_protocol - (proto->name, settings, &widget_object); + widget_object = empathy_account_widget_new_for_protocol (proto->name, + settings, TRUE); + account_widget = empathy_account_widget_get_widget (widget_object); if (priv->current_account_widget != NULL) { diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index e985befc8..30a7f72a8 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -20,6 +20,7 @@ * Authors: Martyn Russell * Xavier Claessens * Cosimo Cecchi + * Jonathan Tellier */ #include @@ -42,7 +43,9 @@ #include #include #include +#include #include +#include #include "empathy-accounts-dialog.h" #include "empathy-import-dialog.h" @@ -70,8 +73,6 @@ typedef struct { GtkWidget *treeview; GtkWidget *button_add; - GtkWidget *button_remove; - GtkWidget *button_import; GtkWidget *frame_new_account; GtkWidget *combobox_protocol; @@ -100,7 +101,6 @@ typedef struct { } EmpathyAccountsDialogPriv; enum { - COL_ENABLED, COL_NAME, COL_STATUS, COL_ACCOUNT_POINTER, @@ -112,28 +112,86 @@ enum { PROP_PARENT = 1 }; -static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, +static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings ( + EmpathyAccountsDialog *dialog); + +static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog); + +static void accounts_dialog_update (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings); -static void accounts_dialog_button_import_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog); +static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, + EmpathyAccountSettings *settings); static void accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings) + const gchar *display_name) { gchar *text; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - text = g_markup_printf_escaped ("%s", - empathy_account_settings_get_display_name (settings)); + text = g_markup_printf_escaped ("%s", display_name); gtk_label_set_markup (GTK_LABEL (priv->label_name), text); g_free (text); } +static void +empathy_account_dialog_widget_cancelled_cb (EmpathyAccountWidget *widget_object, + EmpathyAccountsDialog *dialog) +{ + GtkTreeView *view; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; + EmpathyAccountSettings *settings; + EmpathyAccount *account; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + view = GTK_TREE_VIEW (priv->treeview); + selection = gtk_tree_view_get_selection (view); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return; + + gtk_tree_model_get (model, &iter, + COL_ACCOUNT_SETTINGS_POINTER, &settings, + COL_ACCOUNT_POINTER, &account, -1); + + empathy_account_settings_discard_changes (settings); + + if (account == NULL) + { + /* We were creating an account. We remove the selected row */ + gtk_list_store_remove (GTK_LIST_STORE (model), &iter); + } + else + { + /* We were modifying an account. We discard the changes by reloading the + * settings and the UI. */ + accounts_dialog_update_settings (dialog, settings); + g_object_unref (account); + } + + if (settings != NULL) + g_object_unref (settings); +} + +static void +empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object, + EmpathyAccountsDialog *dialog) +{ + EmpathyAccountSettings *settings = + accounts_dialog_model_get_selected_settings (dialog); + accounts_dialog_update_settings (dialog, settings); + + if (settings) + g_object_unref (settings); +} + static GtkWidget * -get_account_setup_widget (EmpathyAccountSettings *settings) +get_account_setup_widget (EmpathyAccountSettings *settings, + EmpathyAccountWidget **widget_object) { const gchar *proto = empathy_account_settings_get_protocol (settings); EmpathyConnectionManagers *cm = @@ -147,23 +205,31 @@ get_account_setup_widget (EmpathyAccountSettings *settings) if (tp_connection_manager_has_protocol (tp_cm, proto)) { g_object_unref (cm); - return empathy_account_widget_new_for_protocol - (proto, settings); + *widget_object = empathy_account_widget_new_for_protocol (proto, + settings, FALSE); + return empathy_account_widget_get_widget (*widget_object); } } g_object_unref (cm); - return empathy_account_widget_new_for_protocol ("generic", settings); + *widget_object = empathy_account_widget_new_for_protocol ("generic", settings, + FALSE); + return empathy_account_widget_get_widget (*widget_object); } static void account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings) { + EmpathyAccountWidget *widget_object = NULL; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); gchar *icon_name; - priv->settings_widget = get_account_setup_widget (settings); + priv->settings_widget = get_account_setup_widget (settings, &widget_object); + g_signal_connect (widget_object, "account-created", + G_CALLBACK (empathy_account_dialog_account_created_cb), dialog); + g_signal_connect (widget_object, "cancelled", + G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog); gtk_container_add (GTK_CONTAINER (priv->alignment_settings), priv->settings_widget); @@ -176,7 +242,10 @@ account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, gtk_widget_set_tooltip_text (priv->image_type, empathy_account_settings_get_protocol (settings)); - accounts_dialog_update_name_label (dialog, settings); + accounts_dialog_update_name_label (dialog, + empathy_account_settings_get_display_name(settings)); + + g_free (icon_name); } static void @@ -241,17 +310,13 @@ accounts_dialog_button_add_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { GtkTreeView *view; - GtkTreeSelection *selection; GtkTreeModel *model; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); view = GTK_TREE_VIEW (priv->treeview); model = gtk_tree_view_get_model (view); - selection = gtk_tree_view_get_selection (view); - gtk_tree_selection_unselect_all (selection); gtk_widget_set_sensitive (priv->button_add, FALSE); - gtk_widget_set_sensitive (priv->button_remove, FALSE); gtk_widget_hide (priv->vbox_details); gtk_widget_hide (priv->frame_no_protocol); gtk_widget_show (priv->frame_new_account); @@ -300,7 +365,7 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, if (empathy_connection_managers_get_cms_num (priv->cms) > 0) { /* We have no account configured but we have some - * profiles instsalled. The user obviously wants to add + * profiles installed. The user obviously wants to add * an account. Click on the Add button for him. */ accounts_dialog_button_add_clicked_cb (priv->button_add, dialog); @@ -312,7 +377,6 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, gtk_widget_hide (priv->frame_new_account); gtk_widget_show (priv->frame_no_protocol); gtk_widget_set_sensitive (priv->button_add, FALSE); - gtk_widget_set_sensitive (priv->button_remove, FALSE); return; } @@ -322,7 +386,6 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, gtk_widget_hide (priv->frame_no_protocol); gtk_widget_show (priv->vbox_details); gtk_widget_set_sensitive (priv->button_add, TRUE); - gtk_widget_set_sensitive (priv->button_remove, TRUE); if (priv->settings_widget) { @@ -413,38 +476,6 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column, g_object_unref (pixbuf); } -static void -accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer, - gchar *path, - EmpathyAccountsDialog *dialog) -{ - EmpathyAccount *account; - GtkTreeModel *model; - GtkTreePath *treepath; - GtkTreeIter iter; - gboolean enabled; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - treepath = gtk_tree_path_new_from_string (path); - gtk_tree_model_get_iter (model, &iter, treepath); - gtk_tree_model_get (model, &iter, - COL_ACCOUNT_POINTER, &account, - -1); - gtk_tree_path_free (treepath); - - if (account == NULL) - return; - - enabled = empathy_account_is_enabled (account); - empathy_account_set_enabled_async (account, !enabled, NULL, NULL); - - DEBUG ("%s account %s", enabled ? "Disabled" : "Enable", - empathy_account_get_display_name (account)); - - g_object_unref (account); -} - static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model, GtkTreePath *path, @@ -506,9 +537,102 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer, empathy_account_settings_set_display_name_async (settings, new_text, NULL, NULL); + g_object_set (settings, "display-name-overridden", TRUE, NULL); g_object_unref (settings); } +static void +accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog, + gint response_id, + gpointer user_data) +{ + EmpathyAccount *account; + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreeSelection *selection; + EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data); + EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog); + + if (response_id == GTK_RESPONSE_YES) + { + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return; + + gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1); + + if (account != NULL) + { + empathy_account_remove_async (account, NULL, NULL); + g_object_unref (account); + } + + gtk_list_store_remove (GTK_LIST_STORE (model), &iter); + accounts_dialog_model_select_first (account_dialog); + } + + gtk_widget_destroy (GTK_WIDGET (message_dialog)); +} + +static void +accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell, + const gchar *path_string, + EmpathyAccountsDialog *dialog) +{ + EmpathyAccount *account; + GtkTreeModel *model; + GtkTreeIter iter; + GtkWidget *message_dialog; + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + + if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string)) + return; + + gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1); + + if (account == NULL || !empathy_account_is_valid (account)) + { + gtk_list_store_remove (GTK_LIST_STORE (model), &iter); + accounts_dialog_model_select_first (dialog); + return; + } + + message_dialog = gtk_message_dialog_new + (GTK_WINDOW (priv->window), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("You are about to remove your %s account!\n" + "Are you sure you want to proceed?"), + empathy_account_get_display_name (account)); + + gtk_message_dialog_format_secondary_text + (GTK_MESSAGE_DIALOG (message_dialog), + _("Any associated conversations and chat rooms will NOT be " + "removed if you decide to proceed.\n" + "\n" + "Should you decide to add the account back at a later time, " + "they will still be available.")); + + gtk_dialog_add_button (GTK_DIALOG (message_dialog), + GTK_STOCK_CANCEL, + GTK_RESPONSE_NO); + gtk_dialog_add_button (GTK_DIALOG (message_dialog), + GTK_STOCK_REMOVE, + GTK_RESPONSE_YES); + + g_signal_connect (message_dialog, "response", + G_CALLBACK (accounts_dialog_delete_account_response_cb), dialog); + + gtk_widget_show (message_dialog); + + if (account != NULL) + g_object_unref (account); +} + static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog) { @@ -518,22 +642,11 @@ accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog) EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); view = GTK_TREE_VIEW (priv->treeview); - gtk_tree_view_set_headers_visible (view, TRUE); - - /* Enabled column */ - cell = gtk_cell_renderer_toggle_new (); - gtk_tree_view_insert_column_with_attributes (view, -1, - _("Enabled"), - cell, - "active", COL_ENABLED, - NULL); - g_signal_connect (cell, "toggled", - G_CALLBACK (accounts_dialog_enable_toggled_cb), - dialog); + gtk_tree_view_set_headers_visible (view, FALSE); /* Account column */ column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Accounts")); + //gtk_tree_view_column_set_title (column, _("Accounts")); gtk_tree_view_column_set_expand (column, TRUE); gtk_tree_view_append_column (view, column); @@ -561,6 +674,17 @@ accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog) g_signal_connect (cell, "editing-started", G_CALLBACK (accounts_dialog_name_editing_started_cb), dialog); + + /* Delete column */ + cell = empathy_cell_renderer_activatable_new (); + gtk_tree_view_column_pack_start (column, cell, FALSE); + g_object_set (cell, + "icon-name", GTK_STOCK_DELETE, + NULL); + + g_signal_connect (cell, "path-activated", + G_CALLBACK (accounts_dialog_view_delete_activated_cb), + dialog); } static EmpathyAccountSettings * @@ -589,6 +713,7 @@ static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection, EmpathyAccountsDialog *dialog) { +// EmpathyAccountsDialogPriv priv = GET_PRIV (dialog); EmpathyAccountSettings *settings; GtkTreeModel *model; GtkTreeIter iter; @@ -597,6 +722,10 @@ accounts_dialog_model_selection_changed (GtkTreeSelection *selection, is_selection = gtk_tree_selection_get_selected (selection, &model, &iter); settings = accounts_dialog_model_get_selected_settings (dialog); + + if (settings != NULL) + empathy_account_settings_discard_changes (settings); + accounts_dialog_update_settings (dialog, settings); if (settings) @@ -611,7 +740,6 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog) EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); store = gtk_list_store_new (COL_COUNT, - G_TYPE_BOOLEAN, /* enabled */ G_TYPE_STRING, /* name */ G_TYPE_UINT, /* status */ EMPATHY_TYPE_ACCOUNT, /* account */ @@ -709,27 +837,6 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, return FALSE; } -static EmpathyAccount * -accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog) -{ - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - EmpathyAccount *account; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - view = GTK_TREE_VIEW (priv->treeview); - selection = gtk_tree_view_get_selection (view); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return NULL; - - gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1); - - return account; -} - static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings) @@ -742,33 +849,6 @@ accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog, if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) gtk_tree_selection_select_iter (selection, &iter); } - -static gboolean -accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog) -{ - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - EmpathyAccount *account; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - view = GTK_TREE_VIEW (priv->treeview); - selection = gtk_tree_view_get_selection (view); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return FALSE; - - gtk_tree_model_get (model, &iter, - COL_ACCOUNT_POINTER, &account, - -1); - - if (account != NULL) - empathy_account_remove_async (account, NULL, NULL); - - return gtk_list_store_remove (GTK_LIST_STORE (model), &iter); -} - static void accounts_dialog_add (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings) @@ -784,7 +864,6 @@ accounts_dialog_add (EmpathyAccountsDialog *dialog, gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ENABLED, FALSE, COL_NAME, name, COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED, COL_ACCOUNT_SETTINGS_POINTER, settings, @@ -857,7 +936,6 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, settings = empathy_account_settings_new_for_account (account); gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ENABLED, enabled, COL_NAME, name, COL_STATUS, status, COL_ACCOUNT_POINTER, account, @@ -871,7 +949,7 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, TP_CONNECTION_STATUS_DISCONNECTED, dialog); - g_object_unref (settings); + //g_object_unref (settings); } static void @@ -898,7 +976,6 @@ accounts_dialog_update (EmpathyAccountsDialog *dialog, accounts_dialog_get_settings_iter (dialog, settings, &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ENABLED, enabled, COL_NAME, name, COL_STATUS, status, COL_ACCOUNT_POINTER, account, @@ -934,7 +1011,6 @@ enable_or_disable_account (EmpathyAccountsDialog *dialog, gboolean enabled) { GtkTreeModel *model; - GtkTreeIter iter; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); /* Update the status in the model */ @@ -943,11 +1019,6 @@ enable_or_disable_account (EmpathyAccountsDialog *dialog, DEBUG ("Account %s is now %s", empathy_account_get_display_name (account), enabled ? "enabled" : "disabled"); - - if (accounts_dialog_get_account_iter (dialog, account, &iter)) - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ENABLED, enabled, - -1); } static void @@ -989,7 +1060,14 @@ accounts_dialog_account_changed_cb (EmpathyAccountManager *manager, selected_settings = accounts_dialog_model_get_selected_settings (dialog); if (settings == selected_settings) - accounts_dialog_update_name_label (dialog, settings); + accounts_dialog_update_name_label (dialog, + empathy_account_settings_get_display_name(settings)); + + if (settings) + g_object_unref (settings); + + if (selected_settings) + g_object_unref (selected_settings); } static void @@ -1037,7 +1115,10 @@ accounts_dialog_button_back_clicked_cb (GtkWidget *button, EmpathyAccountSettings *settings; settings = accounts_dialog_model_get_selected_settings (dialog); - accounts_dialog_update (dialog, settings); + accounts_dialog_update_settings (dialog, settings); + + if (settings) + g_object_unref (settings); } static void @@ -1047,69 +1128,6 @@ accounts_dialog_button_help_clicked_cb (GtkWidget *button, empathy_url_show (button, "ghelp:empathy?empathy-create-account"); } -static void -accounts_dialog_button_remove_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog) -{ - EmpathyAccount *account; - GtkWidget *message_dialog; - gint res; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - account = accounts_dialog_model_get_selected_account (dialog); - - if (account == NULL || !empathy_account_is_valid (account)) - { - accounts_dialog_model_remove_selected (dialog); - accounts_dialog_model_select_first (dialog); - return; - } - message_dialog = gtk_message_dialog_new - (GTK_WINDOW (priv->window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - _("You are about to remove your %s account!\n" - "Are you sure you want to proceed?"), - empathy_account_get_display_name (account)); - - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (message_dialog), - _("Any associated conversations and chat rooms will NOT be " - "removed if you decide to proceed.\n" - "\n" - "Should you decide to add the account back at a later time, " - "they will still be available.")); - - gtk_dialog_add_button (GTK_DIALOG (message_dialog), - GTK_STOCK_CANCEL, - GTK_RESPONSE_NO); - gtk_dialog_add_button (GTK_DIALOG (message_dialog), - GTK_STOCK_REMOVE, - GTK_RESPONSE_YES); - - gtk_widget_show (message_dialog); - res = gtk_dialog_run (GTK_DIALOG (message_dialog)); - - if (res == GTK_RESPONSE_YES) - { - accounts_dialog_model_remove_selected (dialog); - accounts_dialog_model_select_first (dialog); - } - gtk_widget_destroy (message_dialog); -} - -static void -accounts_dialog_button_import_clicked_cb (GtkWidget *button, - EmpathyAccountsDialog *dialog) -{ - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - GtkWidget *import_dialog; - - import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window), TRUE); - gtk_widget_show (import_dialog); -} - static void accounts_dialog_response_cb (GtkWidget *widget, gint response, @@ -1186,8 +1204,6 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) "image_type", &priv->image_type, "label_name", &priv->label_name, "button_add", &priv->button_add, - "button_remove", &priv->button_remove, - "button_import", &priv->button_import, NULL); g_free (filename); @@ -1197,15 +1213,13 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) "button_create", "clicked", accounts_dialog_button_create_clicked_cb, "button_back", "clicked", accounts_dialog_button_back_clicked_cb, "button_add", "clicked", accounts_dialog_button_add_clicked_cb, - "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb, - "button_import", "clicked", accounts_dialog_button_import_clicked_cb, "button_help", "clicked", accounts_dialog_button_help_clicked_cb, NULL); g_object_unref (gui); priv->combobox_protocol = empathy_protocol_chooser_new (); - gtk_box_pack_end (GTK_BOX (priv->hbox_type), + gtk_box_pack_start (GTK_BOX (priv->hbox_type), priv->combobox_protocol, TRUE, TRUE, 0); gtk_widget_show (priv->combobox_protocol); @@ -1386,19 +1400,15 @@ do_constructed (GObject *object) if (!import_asked) { - GtkWidget *import_dialog; - + GtkWidget *import_dialog; + empathy_conf_set_bool (empathy_conf_get (), EMPATHY_PREFS_IMPORT_ASKED, TRUE); import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window), FALSE); - gtk_widget_show (import_dialog); + gtk_widget_show (import_dialog); } } - else - { - gtk_widget_set_sensitive (priv->button_import, FALSE); - } } static void diff --git a/src/empathy-accounts-dialog.ui b/src/empathy-accounts-dialog.ui index 7c899a3cb..edd8f20a4 100644 --- a/src/empathy-accounts-dialog.ui +++ b/src/empathy-accounts-dialog.ui @@ -2,10 +2,6 @@ - - gtk-add - 4 - 5 Accounts @@ -46,62 +42,18 @@ - + + _Add... True - 6 - True - - - True - 6 - True - - - True - True - False - add_image - _Add... - True - - - 0 - - - - - gtk-remove - True - True - False - True - - - 1 - - - - - False - False - 0 - - - - - Import Accounts... - True - True - False - - - 1 - - + True + True + add_image + True False - 1 + False + 2 @@ -128,11 +80,11 @@ True True Gmail + True - + - True 0 @@ -205,29 +157,6 @@ True 12 - - - True - 6 - - - True - Type: - - - False - False - 0 - - - - - - - - 0 - - True @@ -347,12 +276,45 @@ - + True - Add Account - - - + + + True + Add new + + + + + + 5 + 0 + + + + + True + 6 + + + + + + True + account + + + False + False + end + 0 + + + + + 1 + + @@ -454,4 +416,7 @@ button_close + + gtk-add + -- cgit v1.2.3 From 17ae7af66b0baa2b898445dee8e79a670e588891 Mon Sep 17 00:00:00 2001 From: Jonathan Tellier Date: Fri, 21 Aug 2009 15:11:32 -0400 Subject: Fix errors revealed by make check - Added missing files in po/POTFILES.in - Fixed style --- libempathy-gtk/empathy-account-widget.c | 2 +- libempathy-gtk/empathy-protocol-chooser.c | 2 +- po/POTFILES.in | 1 + src/empathy-account-assistant.c | 10 +++++----- src/empathy-accounts-dialog.c | 4 ++-- src/empathy-import-dialog.c | 4 ++-- src/empathy-import-widget.c | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 2f6537aeb..7a72deb36 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -1190,7 +1190,7 @@ do_constructed (GObject *obj) G_CALLBACK (account_widget_apply_clicked_cb), self); gtk_widget_show_all (hbox); - account_widget_set_control_buttons_sensitivity(self, FALSE); + account_widget_set_control_buttons_sensitivity (self, FALSE); } account = empathy_account_settings_get_account (priv->settings); diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index 70ba60b06..f148edb99 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -59,7 +59,7 @@ typedef struct { GtkListStore *store; - + gboolean dispose_run; EmpathyConnectionManagers *cms; diff --git a/po/POTFILES.in b/po/POTFILES.in index d2759b5a0..a140f16c4 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -76,6 +76,7 @@ src/empathy-event-manager.c src/empathy-ft-manager.c [type: gettext/glade]src/empathy-ft-manager.ui src/empathy-import-dialog.c +src/empathy-import-widget.c [type: gettext/glade]src/empathy-import-dialog.ui src/empathy-import-widget.c src/empathy-main-window.c diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index 8b803a9b6..e375aa72e 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -390,7 +390,7 @@ account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self, gboolean is_enter) { EmpathyAccountAssistantPriv *priv = GET_PRIV (self); - + if (is_enter) { gtk_label_set_label (GTK_LABEL (priv->first_label), @@ -426,10 +426,10 @@ account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self, priv->enter_or_create_page, _("Enter the details for the new account")); } - + g_signal_connect (priv->chooser, "changed", G_CALLBACK (account_assistant_protocol_changed_cb), self); - + /* trigger show the first account widget */ account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self); } @@ -568,7 +568,7 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self) str = _("Yes, I'll enter my account details now"); if (radio == NULL) - { + { radio = gtk_radio_button_new_with_label (NULL, str); w = radio; } @@ -772,7 +772,7 @@ impl_signal_prepare (GtkAssistant *assistant, gint current_idx; current_idx = gtk_assistant_get_current_page (assistant); - + if (current_idx >= PAGE_ENTER_CREATE) { if (!priv->enter_create_forward) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 30a7f72a8..43acfbcf9 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -243,7 +243,7 @@ account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, empathy_account_settings_get_protocol (settings)); accounts_dialog_update_name_label (dialog, - empathy_account_settings_get_display_name(settings)); + empathy_account_settings_get_display_name (settings)); g_free (icon_name); } @@ -1061,7 +1061,7 @@ accounts_dialog_account_changed_cb (EmpathyAccountManager *manager, if (settings == selected_settings) accounts_dialog_update_name_label (dialog, - empathy_account_settings_get_display_name(settings)); + empathy_account_settings_get_display_name (settings)); if (settings) g_object_unref (settings); diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c index 7ca0285b1..94c6fd765 100644 --- a/src/empathy-import-dialog.c +++ b/src/empathy-import-dialog.c @@ -61,14 +61,14 @@ import_dialog_add_import_widget (EmpathyImportDialog *self) GtkWidget *widget, *area; area = gtk_dialog_get_content_area (GTK_DIALOG (self)); - + iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_ALL); widget = empathy_import_widget_get_widget (iw); gtk_box_pack_start (GTK_BOX (area), widget, FALSE, FALSE, 0); gtk_widget_show (widget); priv->iw = iw; - + gtk_dialog_add_buttons (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); } diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c index 03117350c..17f196229 100644 --- a/src/empathy-import-widget.c +++ b/src/empathy-import-widget.c @@ -85,7 +85,7 @@ import_widget_account_id_in_list (GList *accounts, parameters = empathy_account_get_parameters (account); - value = g_hash_table_lookup ((GHashTable *)parameters, "account"); + value = g_hash_table_lookup ((GHashTable *) parameters, "account"); if (value == NULL) continue; @@ -438,7 +438,7 @@ do_constructed (GObject *obj) gchar *filename; priv->accounts = empathy_import_accounts_load (priv->app_id); - + filename = empathy_file_lookup ("empathy-import-dialog.ui", "src"); gui = empathy_builder_get_file (filename, "widget_vbox", &priv->vbox, -- cgit v1.2.3 From d047670385b7dcc65ccdb89969f0e43deea7c93e Mon Sep 17 00:00:00 2001 From: Jonathan Tellier Date: Fri, 21 Aug 2009 16:08:29 -0400 Subject: Every protocols should now have an "Enabled" checkbox in "edit" mode. --- libempathy-gtk/empathy-account-widget-irc.c | 4 +++- libempathy-gtk/empathy-account-widget-irc.h | 3 ++- libempathy-gtk/empathy-account-widget-sip.c | 4 +++- libempathy-gtk/empathy-account-widget-sip.h | 3 ++- libempathy-gtk/empathy-account-widget-sip.ui | 2 +- libempathy-gtk/empathy-account-widget.c | 17 +++++++++++++++-- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c index 932e2f81d..e462aa611 100644 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ b/libempathy-gtk/empathy-account-widget-irc.c @@ -418,7 +418,8 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) void empathy_account_widget_irc_build (EmpathyAccountWidget *self, - const char *filename) + const char *filename, + GtkWidget **table_common_settings) { EmpathyAccountWidgetIrc *settings; gchar *dir, *user_file_with_path, *global_file_with_path; @@ -450,6 +451,7 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self, g_free (user_file_with_path); self->ui_details->gui = empathy_builder_get_file (filename, + "table_irc_settings", table_common_settings, "vbox_irc", &self->ui_details->widget, "table_irc_settings", &settings->vbox_settings, "combobox_network", &settings->combobox_network, diff --git a/libempathy-gtk/empathy-account-widget-irc.h b/libempathy-gtk/empathy-account-widget-irc.h index a76787120..022158529 100644 --- a/libempathy-gtk/empathy-account-widget-irc.h +++ b/libempathy-gtk/empathy-account-widget-irc.h @@ -27,7 +27,8 @@ G_BEGIN_DECLS void empathy_account_widget_irc_build (EmpathyAccountWidget *self, - const char *filename); + const char *filename, + GtkWidget **table_common_settings); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget-sip.c b/libempathy-gtk/empathy-account-widget-sip.c index afc20fecb..db39ddae4 100644 --- a/libempathy-gtk/empathy-account-widget-sip.c +++ b/libempathy-gtk/empathy-account-widget-sip.c @@ -65,7 +65,8 @@ account_widget_sip_discover_stun_toggled_cb ( void empathy_account_widget_sip_build (EmpathyAccountWidget *self, - const char *filename) + const char *filename, + GtkWidget **table_common_settings) { EmpathyAccountWidgetSip *settings; GtkWidget *vbox_settings; @@ -92,6 +93,7 @@ empathy_account_widget_sip_build (EmpathyAccountWidget *self, settings->self = self; self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_settings", table_common_settings, "vbox_sip_settings", &vbox_settings, "entry_stun-server", &settings->entry_stun_server, "spinbutton_stun-port", &settings->spinbutton_stun_part, diff --git a/libempathy-gtk/empathy-account-widget-sip.h b/libempathy-gtk/empathy-account-widget-sip.h index 435ad6ea1..6334a745b 100644 --- a/libempathy-gtk/empathy-account-widget-sip.h +++ b/libempathy-gtk/empathy-account-widget-sip.h @@ -27,7 +27,8 @@ G_BEGIN_DECLS void empathy_account_widget_sip_build (EmpathyAccountWidget *self, - const char *filename); + const char *filename, + GtkWidget **table_common_settings); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget-sip.ui b/libempathy-gtk/empathy-account-widget-sip.ui index 84e68b01f..65e16473d 100644 --- a/libempathy-gtk/empathy-account-widget-sip.ui +++ b/libempathy-gtk/empathy-account-widget-sip.ui @@ -11,7 +11,7 @@ True vertical - + True 2 2 diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 7a72deb36..aa1c6724e 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -702,6 +702,7 @@ account_widget_build_generic (EmpathyAccountWidget *self, GtkWidget *expander_advanced; self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_settings", &priv->table_common_settings, "vbox_generic_settings", &self->ui_details->widget, "expander_advanced_settings", &expander_advanced, NULL); @@ -722,7 +723,10 @@ static void account_widget_build_salut (EmpathyAccountWidget *self, const char *filename) { + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_settings", &priv->table_common_settings, "vbox_salut_settings", &self->ui_details->widget, NULL); @@ -760,6 +764,7 @@ account_widget_build_msn (EmpathyAccountWidget *self, else { self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_msn_settings", &priv->table_common_settings, "vbox_msn_settings", &self->ui_details->widget, NULL); @@ -864,6 +869,7 @@ account_widget_build_icq (EmpathyAccountWidget *self, else { self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_settings", &priv->table_common_settings, "vbox_icq_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, NULL); @@ -904,6 +910,7 @@ account_widget_build_aim (EmpathyAccountWidget *self, else { self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_settings", &priv->table_common_settings, "vbox_aim_settings", &self->ui_details->widget, "spinbutton_port", &spinbutton_port, NULL); @@ -942,6 +949,7 @@ account_widget_build_yahoo (EmpathyAccountWidget *self, else { self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_settings", &priv->table_common_settings, "vbox_yahoo_settings", &self->ui_details->widget, NULL); @@ -983,6 +991,7 @@ account_widget_build_groupwise (EmpathyAccountWidget *self, else { self->ui_details->gui = empathy_builder_get_file (filename, + "table_common_groupwise_settings", &priv->table_common_settings, "vbox_groupwise_settings", &self->ui_details->widget, NULL); @@ -1117,9 +1126,13 @@ do_constructed (GObject *obj) 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); + 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); + 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 { g_free (filename); -- cgit v1.2.3 From f454a43c73519864fde157ce1ba5e61139c98ee6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 15:53:07 +0100 Subject: Update python bindings --- python/pyempathygtk/pyempathygtk.defs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/python/pyempathygtk/pyempathygtk.defs b/python/pyempathygtk/pyempathygtk.defs index dd906cddd..82fe5daca 100644 --- a/python/pyempathygtk/pyempathygtk.defs +++ b/python/pyempathygtk/pyempathygtk.defs @@ -340,12 +340,19 @@ (return-type "GType") ) +(define-method get_widget + (of-object "EmpathyAccountWidget") + (c-name "empathy_account_widget_get_widget") + (return-type "GtkWidget*") +) + (define-function account_widget_new_for_protocol (c-name "empathy_account_widget_new_for_protocol") - (return-type "GtkWidget*") + (return-type "EmpathyAccountWidget*") (parameters '("const-char*" "protocol") '("EmpathyAccountSettings*" "settings") + '("gboolean" "simple") ) ) @@ -359,6 +366,7 @@ (return-type "none") (parameters '("const-char*" "filename") + '("GtkWidget**" "table_common_settings") ) ) @@ -372,6 +380,7 @@ (return-type "none") (parameters '("const-char*" "filename") + '("GtkWidget**" "table_common_settings") ) ) @@ -1520,6 +1529,16 @@ ) ) +(define-method set_visible + (of-object "EmpathyProtocolChooser") + (c-name "empathy_protocol_chooser_set_visible") + (return-type "none") + (parameters + '("EmpathyProtocolChooserFilterFunc" "func") + '("gpointer" "user_data") + ) +) + ;; From empathy-smiley-manager.h -- cgit v1.2.3 From d2b306d115c9c7b46da2e2018e061aa38e6397bf Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 16:04:26 +0100 Subject: Don't free the icon name that we don't own --- src/empathy-accounts-dialog.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 43acfbcf9..408feaad3 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -244,8 +244,6 @@ account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog, accounts_dialog_update_name_label (dialog, empathy_account_settings_get_display_name (settings)); - - g_free (icon_name); } static void -- cgit v1.2.3 From 0888975ccb8c6ead5761659677d18991c53fe23a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 16:14:20 +0100 Subject: Make the alignment names in the sip.ui file unique --- libempathy-gtk/empathy-account-widget-sip.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libempathy-gtk/empathy-account-widget-sip.ui b/libempathy-gtk/empathy-account-widget-sip.ui index 65e16473d..45e0f7d31 100644 --- a/libempathy-gtk/empathy-account-widget-sip.ui +++ b/libempathy-gtk/empathy-account-widget-sip.ui @@ -109,7 +109,7 @@ True True - + True 0 12 -- cgit v1.2.3 From bd062af39b10bb87d86b9561001f4ab9184e037d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 17:21:09 +0100 Subject: Don't leak a ref to EmpathyAccountSettings --- src/empathy-accounts-dialog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 408feaad3..ad96ba921 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -947,7 +947,7 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, TP_CONNECTION_STATUS_DISCONNECTED, dialog); - //g_object_unref (settings); + g_object_unref (settings); } static void -- cgit v1.2.3 From b72ead7076cd2ba308d32f0ae42fc50efc82bd51 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 17:22:23 +0100 Subject: Remove dead code and fix some coding style issues --- libempathy-gtk/empathy-account-widget.h | 3 --- src/empathy-accounts-dialog.c | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h index f44edcc6a..415934a2d 100644 --- a/libempathy-gtk/empathy-account-widget.h +++ b/libempathy-gtk/empathy-account-widget.h @@ -61,9 +61,6 @@ GType empathy_account_widget_get_type (void); GtkWidget *empathy_account_widget_get_widget (EmpathyAccountWidget *widget); -//EmpathyAccountWidget *empathy_account_widget_new_for_protocol ( -// const char *protocol, -// EmpathyAccountSettings *settings); EmpathyAccountWidget * empathy_account_widget_new_for_protocol ( const char *protocol, EmpathyAccountSettings *settings, diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index ad96ba921..40f46e49e 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -644,7 +644,6 @@ accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog) /* Account column */ column = gtk_tree_view_column_new (); - //gtk_tree_view_column_set_title (column, _("Accounts")); gtk_tree_view_column_set_expand (column, TRUE); gtk_tree_view_append_column (view, column); @@ -711,7 +710,6 @@ static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection, EmpathyAccountsDialog *dialog) { -// EmpathyAccountsDialogPriv priv = GET_PRIV (dialog); EmpathyAccountSettings *settings; GtkTreeModel *model; GtkTreeIter iter; @@ -726,7 +724,7 @@ accounts_dialog_model_selection_changed (GtkTreeSelection *selection, accounts_dialog_update_settings (dialog, settings); - if (settings) + if (settings != NULL) g_object_unref (settings); } -- cgit v1.2.3 From 4174547fb3fcc5d9447b20728a3fb086cf90b9e0 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 17:31:15 +0100 Subject: If the parameter wasn't known return NULL for the dbus signature --- libempathy/empathy-account-settings.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 6129570c2..f6c1af42c 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -575,6 +575,9 @@ empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings, p = empathy_account_settings_get_tp_param (settings, param); + if (p == NULL) + return NULL; + return p->dbus_signature; } -- cgit v1.2.3 From c10e3fbca90c684a3f0988a119cfad3d14def218 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 17:44:14 +0100 Subject: Fix some leaks in _settings_discard Prevent leaking the unset parameter names when unsetting the array. Also use it as a general utility function in other parts of the code --- libempathy/empathy-account-settings.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index f6c1af42c..efcbb2d8e 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -630,14 +630,8 @@ empathy_account_settings_discard_changes (EmpathyAccountSettings *settings) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); - if (g_hash_table_size (priv->parameters) > 0) - g_hash_table_remove_all (priv->parameters); - - if (priv->unset_parameters->len > 0) - { - g_array_remove_range (priv->unset_parameters, 0, - priv->unset_parameters->len); - } + g_hash_table_remove_all (priv->parameters); + empathy_account_settings_free_unset_parameters (settings); } const gchar * @@ -967,6 +961,10 @@ empathy_account_settings_account_updated (GObject *source, g_simple_async_result_set_from_error (priv->apply_result, error); g_error_free (error); } + else + { + empathy_account_settings_discard_changes (settings); + } r = priv->apply_result; priv->apply_result = NULL; @@ -990,9 +988,14 @@ empathy_account_settings_created_cb (GObject *source, EMPATHY_ACCOUNT_MANAGER (source), result, &error); if (account == NULL) - g_simple_async_result_set_from_error (priv->apply_result, error); + { + g_simple_async_result_set_from_error (priv->apply_result, error); + } else - priv->account = g_object_ref (account); + { + priv->account = g_object_ref (account); + empathy_account_settings_discard_changes (settings); + } r = priv->apply_result; priv->apply_result = NULL; @@ -1111,9 +1114,6 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings, empathy_account_update_settings_async (priv->account, priv->parameters, (const gchar **)priv->unset_parameters->data, empathy_account_settings_account_updated, settings); - - g_hash_table_remove_all (priv->parameters); - empathy_account_settings_free_unset_parameters (settings); } } -- cgit v1.2.3 From 1eda75c91abf01bc7fe25d4eb41465a21f042596 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 18:20:32 +0100 Subject: Make the layout more consistent with the other widgets --- libempathy-gtk/empathy-account-widget-jabber.ui | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-jabber.ui b/libempathy-gtk/empathy-account-widget-jabber.ui index 5fddcb7b8..2d602cb7f 100644 --- a/libempathy-gtk/empathy-account-widget-jabber.ui +++ b/libempathy-gtk/empathy-account-widget-jabber.ui @@ -55,7 +55,7 @@ True - 1 + 0 Login I_D: True entry_id @@ -90,9 +90,10 @@ True - 1 + 0 Pass_word: True + right entry_password @@ -102,23 +103,11 @@ - - - True - 1 - <span size="small">Example:</span> - True - - - 1 - 2 - - True 0 - <span size="small">test@jabber.org</span> + Example: <span size="small">test@jabber.org</span> True @@ -131,6 +120,9 @@ + + + False -- cgit v1.2.3 From fe39c811b7ef600c0262b905683f3a8966311129 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 18:20:53 +0100 Subject: Clean up the dialog a bit --- src/empathy-accounts-dialog.ui | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/empathy-accounts-dialog.ui b/src/empathy-accounts-dialog.ui index edd8f20a4..cd98415d7 100644 --- a/src/empathy-accounts-dialog.ui +++ b/src/empathy-accounts-dialog.ui @@ -6,6 +6,7 @@ 5 Accounts accounts + 640 dialog False @@ -111,28 +112,12 @@ - + True - 0 - none + 6 + 20 - - True - 6 - 20 - - - - - - - - True - Settings - - - - + -- cgit v1.2.3 From f984475cb967427790466d21b42b6e703fa55a26 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 18:33:58 +0100 Subject: When creating an account use a connect button instead of an apply button --- libempathy-gtk/empathy-account-widget.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index aa1c6724e..9712ae984 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -1186,7 +1186,8 @@ do_constructed (GObject *obj) GtkWidget *hbox = gtk_hbox_new (TRUE, 3); priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); - priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY); + priv->apply_button = gtk_button_new_from_stock ( + priv->creating_account ? GTK_STOCK_CONNECT : GTK_STOCK_APPLY); gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE, TRUE, 3); -- cgit v1.2.3 From 45a6ac022bc86f649bb49f909f95b9311eec57c9 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 22 Aug 2009 19:43:38 +0100 Subject: Use the right default answer if we're not importing accounts --- src/empathy-account-assistant.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index e375aa72e..d8aa46f1d 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -495,6 +495,7 @@ account_assistant_radio_choice_toggled_cb (GtkToggleButton *button, static GtkWidget * account_assistant_build_introduction_page (EmpathyAccountAssistant *self) { + EmpathyAccountAssistantPriv *priv = GET_PRIV (self); GtkWidget *main_vbox, *hbox_1, *w, *vbox_1; GtkWidget *radio = NULL; GdkPixbuf *pix; @@ -563,6 +564,11 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self) g_signal_connect (radio, "clicked", G_CALLBACK (account_assistant_radio_choice_toggled_cb), self); + priv->first_resp = RESPONSE_IMPORT; + } + else + { + priv->first_resp = RESPONSE_ENTER_ACCOUNT; } str = _("Yes, I'll enter my account details now"); @@ -910,9 +916,6 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self) GTK_ASSISTANT_PAGE_INTRO); gtk_assistant_set_page_complete (assistant, page, TRUE); - /* set a default answer */ - priv->first_resp = RESPONSE_IMPORT; - /* second page (import accounts) */ page = account_assistant_build_import_page (self); gtk_assistant_append_page (assistant, page); -- cgit v1.2.3 From 69587b5167623c9c73a06ab9c86695019c2146c6 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sun, 23 Aug 2009 20:55:18 +0200 Subject: Use better avatar location: ~/.cache/// --- libempathy/empathy-contact.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index bbce927b7..44d9dbeed 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -858,27 +858,23 @@ contact_get_avatar_filename (EmpathyContact *contact, gchar *avatar_path; gchar *avatar_file; gchar *token_escaped; - gchar *contact_escaped; if (EMP_STR_EMPTY (empathy_contact_get_id (contact))) return NULL; - contact_escaped = tp_escape_as_identifier (empathy_contact_get_id (contact)); token_escaped = tp_escape_as_identifier (token); account = empathy_contact_get_account (contact); - /* FIXME: Do not use the account, but proto/cm instead */ avatar_path = g_build_filename (g_get_user_cache_dir (), - PACKAGE_NAME, + "telepathy", "avatars", - empathy_account_get_unique_name (account), - contact_escaped, + empathy_account_get_connection_manager (account), + empathy_account_get_protocol (account), NULL); g_mkdir_with_parents (avatar_path, 0700); avatar_file = g_build_filename (avatar_path, token_escaped, NULL); - g_free (contact_escaped); g_free (token_escaped); g_free (avatar_path); -- cgit v1.2.3 From 9a0b883ee43536dfd302526f60e5396ff9e7fa72 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sun, 23 Aug 2009 20:58:24 +0200 Subject: Ignore tests/test-empathy-account-assistant --- tests/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/.gitignore b/tests/.gitignore index 2165c52d6..a522514bd 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -4,6 +4,7 @@ contact-run-until-ready contact-run-until-ready-2 *.log empetit +test-empathy-account-assistant test-empathy-presence-chooser test-empathy-status-preset-dialog test-empathy-protocol-chooser -- cgit v1.2.3 From 1173e9d086df6304f2436edf0d8cc6c1540414f9 Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Sat, 22 Aug 2009 14:52:15 +0200 Subject: Add empathy-import-mc4-accounts files --- src/empathy-import-mc4-accounts.c | 555 ++++++++++++++++++++++++++++++++++++++ src/empathy-import-mc4-accounts.h | 31 +++ 2 files changed, 586 insertions(+) create mode 100644 src/empathy-import-mc4-accounts.c create mode 100644 src/empathy-import-mc4-accounts.h diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c new file mode 100644 index 000000000..0dbadd6ee --- /dev/null +++ b/src/empathy-import-mc4-accounts.c @@ -0,0 +1,555 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Arnaud Maillet + */ + +#include +#include +#include +#include +#include +#include + +#include "empathy-import-mc4-accounts.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_IMPORT_MC4_ACCOUNTS +#include + +#define MC_ACCOUNTS_GCONF_BASE "/apps/telepathy/mc/accounts" +#define IMPORT_MC4_ACCOUNTS "/apps/empathy/accounts/import_mc4_accounts" + +typedef struct +{ + gchar *profile; + gchar *protocol; +} ProfileProtocolMapItem; + +static ProfileProtocolMapItem profile_protocol_map[] = +{ + { "aim", "aim" }, + { "ekiga", "sip" }, + { "fwd", "sip" }, + { "gadugadu", "gadugadu" }, + { "groupwise", "groupwise" }, + { "gtalk", "jabber" }, + { "icq", "icq" }, + { "irc", "irc" }, + { "jabber", "jabber" }, + { "msn-haze", "msn" }, + { "msn", "msn" }, + { "qq", "qq" }, + { "salut", "local-xmpp" }, + { "sametime", "sametime" }, + { "sipphone", "sip" }, + { "sofiasip", "sip" }, + { "yahoo", "yahoo" }, +}; + +typedef struct +{ + gchar *connection_manager; + gchar *protocol; + gchar *display_name; + gchar *param_account; + gchar *param_server; + gboolean enabled; + GHashTable *parameters; +} AccountData; + +static void +_account_data_free (AccountData *account) +{ + if (account->connection_manager != NULL) + { + g_free (account->connection_manager); + account->connection_manager = NULL; + } + + if (account->protocol != NULL) + { + g_free (account->protocol); + account->protocol = NULL; + } + + if (account->display_name != NULL) + { + g_free (account->display_name); + account->display_name = NULL; + } + + if (account->param_account != NULL) + { + g_free (account->param_account); + account->param_account = NULL; + } + + if (account->param_server != NULL) + { + g_free (account->param_server); + account->param_server = NULL; + } + + if (account->parameters != NULL) + { + g_hash_table_destroy (account->parameters); + account->parameters = NULL; + } + + g_slice_free (AccountData, account); +} + +static gchar * +_account_name_from_key (const gchar *key) +{ + guint base_len = strlen (MC_ACCOUNTS_GCONF_BASE); + const gchar *base, *slash; + + g_assert (key == strstr (key, MC_ACCOUNTS_GCONF_BASE)); + g_assert (strlen (key) > base_len + 1); + + base = key + base_len + 1; + slash = strchr (base, '/'); + + if (slash == NULL) + return g_strdup (base); + else + return g_strndup (base, slash - base); +} + +static gchar * +_param_name_from_key (const gchar *key) +{ + const gchar *base, *slash; + gchar *account_name; + + account_name = _account_name_from_key (key); + base = strstr (key, account_name); + slash = strchr (base, '/'); + g_free (account_name); + + return g_strdup (slash+1); +} + +static void +_normalize_display_name (AccountData *account) +{ + + if (account->display_name != NULL) + return; + + if (!tp_strdiff (account->protocol, "local-xmpp")) + { + account->display_name = g_strdup ("Nearby People"); + } + + else if (!tp_strdiff (account->protocol, "irc")) + { + + if (account->display_name != NULL) + { + g_free (account->display_name); + account->display_name = NULL; + } + + account->display_name = g_strdup_printf + ("%s on %s", account->param_account, account->param_server); + + } + + else if (account->display_name == NULL) + { + + if (account->param_account != NULL) + account->display_name = g_strdup + ((const gchar *) account->param_account); + else + account->display_name = g_strdup + ("No display name"); + + } +} + +static gboolean +_protocol_is_supported (AccountData *data) +{ + EmpathyConnectionManagers *cm = + empathy_connection_managers_dup_singleton (); + GList *cms = empathy_connection_managers_get_cms (cm); + GList *l; + gboolean proto_is_supported = FALSE; + + for (l = cms; l; l = l->next) + { + TpConnectionManager *tp_cm = l->data; + const gchar *cm_name = tp_connection_manager_get_name (tp_cm); + if (tp_connection_manager_has_protocol (tp_cm, + (const gchar*)data->protocol)) + { + data->connection_manager = g_strdup (cm_name); + proto_is_supported = TRUE; + break; + } + } + + g_object_unref (cm); + + return proto_is_supported; +} + +static void +_create_account_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + AccountData *data = (AccountData*) user_data; + EmpathyAccount *account; + GError *error = NULL; + + account = empathy_account_manager_create_account_finish ( + EMPATHY_ACCOUNT_MANAGER (source), result, &error); + + if (account == NULL) + { + DEBUG ("Failed to create account: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + _account_data_free (data); + return; + } + + DEBUG ("account created\n"); + empathy_account_set_enabled (account, data->enabled); + + g_object_unref (account); + _account_data_free (data); +} + +static void +_recurse_account (GSList *entries, AccountData *account) +{ + GSList *tmp; + + for (tmp = entries; tmp != NULL; tmp = tmp->next) + { + + GConfEntry *entry; + gchar *param; + GConfValue *value; + + entry = (GConfEntry*) tmp->data; + param = _param_name_from_key (gconf_entry_get_key (entry)); + + if (!tp_strdiff (param, "profile")) + { + const gchar *profile; + gint i; + value = gconf_entry_get_value (entry); + profile = gconf_value_get_string (value); + + DEBUG ("profile: %s\n", profile); + + for (i = 0; i < G_N_ELEMENTS (profile_protocol_map); i++) + { + if (!tp_strdiff (profile, profile_protocol_map[i].profile)) + { + account->protocol = g_strdup + (profile_protocol_map[i].protocol); + break; + } + } + } + + else if (!tp_strdiff (param, "enabled")) + { + value = gconf_entry_get_value (entry); + account->enabled = gconf_value_get_bool (value); + } + + else if (!tp_strdiff (param, "display_name")) + { + value = gconf_entry_get_value (entry); + account->display_name = g_strdup (gconf_value_get_string (value)); + } + + else if (!tp_strdiff (param, "param-account")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + account->param_account = g_strdup (gconf_value_get_string (value)); + + my_g_value = tp_g_value_slice_new (G_TYPE_STRING); + g_value_set_string (my_g_value, account->param_account); + g_hash_table_insert (account->parameters, "account", my_g_value); + + } + + else if (!tp_strdiff (param, "param-server")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + account->param_account = g_strdup (gconf_value_get_string (value)); + + my_g_value = tp_g_value_slice_new (G_TYPE_STRING); + g_value_set_string (my_g_value, account->param_account); + g_hash_table_insert (account->parameters, "server", my_g_value); + + } + + else if (!tp_strdiff (param, "param-port")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_UINT); + g_value_set_uint (my_g_value, gconf_value_get_int (value)); + g_hash_table_insert (account->parameters, "password", my_g_value);; + + } + + + else if (!tp_strdiff (param, "param-password")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_STRING); + g_value_set_string (my_g_value, gconf_value_get_string (value)); + g_hash_table_insert (account->parameters, "password", my_g_value); + + } + + else if (!tp_strdiff (param, "param-require-encryption")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_BOOLEAN); + g_value_set_boolean (my_g_value, gconf_value_get_bool (value)); + g_hash_table_insert (account->parameters, "require-encryption", my_g_value); + + } + + else if (!tp_strdiff (param, "param-register")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_BOOLEAN); + g_value_set_boolean (my_g_value, gconf_value_get_bool (value)); + g_hash_table_insert (account->parameters, "require-register", my_g_value); + + } + + else if (!tp_strdiff (param, "param-ident")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_STRING); + g_value_set_string (my_g_value, gconf_value_get_string (value)); + g_hash_table_insert (account->parameters, "ident", my_g_value); + + } + + else if (!tp_strdiff (param, "param-fullname")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_STRING); + g_value_set_string (my_g_value, gconf_value_get_string (value)); + g_hash_table_insert (account->parameters, "fullname", my_g_value); + + } + + else if (!tp_strdiff (param, "param-stun-server")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_STRING); + g_value_set_string (my_g_value, gconf_value_get_string (value)); + g_hash_table_insert (account->parameters, "stun-server", my_g_value); + + } + + else if (!tp_strdiff (param, "param-stun-port")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_UINT); + g_value_set_uint (my_g_value, gconf_value_get_int (value)); + g_hash_table_insert (account->parameters, "stun-port", my_g_value);; + + } + + else if (!tp_strdiff (param, "param-keepalive-interval")) + { + + GValue *my_g_value; + + value = gconf_entry_get_value (entry); + my_g_value = tp_g_value_slice_new (G_TYPE_UINT); + g_value_set_uint (my_g_value, gconf_value_get_int (value)); + g_hash_table_insert (account->parameters, "keepalive-interval", my_g_value);; + + } + + g_free (param); + gconf_entry_unref (entry); + + } + + _normalize_display_name (account); +} + +void empathy_import_mc4_accounts (void) +{ + GConfClient *client; + GError *error = NULL; + GSList *dir, *dirs, *entries; + gboolean import_mc4_accounts; + + client = gconf_client_get_default (); + + import_mc4_accounts = gconf_client_get_bool (client, + IMPORT_MC4_ACCOUNTS, &error); + + if (error != NULL) + { + DEBUG ("Failed to get import_mc4_accounts key: %s\n", error->message); + g_clear_error (&error); + g_object_unref (client); + return; + } + + if (!import_mc4_accounts) + { + g_object_unref (client); + return; + } + + DEBUG ("MC 4 accounts are going to be imported\n"); + + dirs = gconf_client_all_dirs (client, MC_ACCOUNTS_GCONF_BASE, &error); + + if (error != NULL) + { + DEBUG ("Failed to get mc_accounts_gconf_base dirs: %s\n", + error->message); + g_clear_error (&error); + g_object_unref (client); + return; + } + + for (dir = dirs; NULL != dir; dir = dir->next) + { + gchar *account_name = _account_name_from_key (dir->data); + AccountData *account; + + account = g_slice_new0 (AccountData); + + account->connection_manager = NULL; + account->protocol = NULL; + account->enabled = FALSE; + account->display_name = NULL; + account->param_account = NULL; + account->param_server = NULL; + account->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, + NULL, (GDestroyNotify) tp_g_value_slice_free); + + DEBUG ("name : %s\n", account_name); + + entries = gconf_client_all_entries (client, dir->data, &error); + + if (error != NULL) + { + + DEBUG ("Failed to get all entries: %s\n", error->message); + g_clear_error (&error); + + } + else + { + _recurse_account (entries, account); + } + + if (_protocol_is_supported (account)) + { + EmpathyAccountManager *account_manager; + GHashTable *properties; + + account_manager = empathy_account_manager_dup_singleton (); + + properties = g_hash_table_new (NULL, NULL); + + DEBUG ("account cm: %s", account->connection_manager); + DEBUG ("account protocol: %s", account->protocol); + DEBUG ("account display_name: %s", account->display_name); + DEBUG ("account param_account: %s", account->param_account); + DEBUG ("account param_server: %s", account->param_server); + DEBUG ("enabled: %d", account->enabled); + tp_asv_dump (account->parameters); + + empathy_account_manager_create_account_async (account_manager, + (const gchar*) account->connection_manager, + (const gchar*) account->protocol, account->display_name, + account->parameters, properties, + _create_account_cb, account); + + g_hash_table_unref (properties); + g_object_unref (account_manager); + } + else + { + DEBUG ("protocol of this account is not supported\n"); + _account_data_free (account); + } + + g_slist_free (entries); + g_free (account_name); + g_free (dir->data); + + } + + gconf_client_set_bool (client, + IMPORT_MC4_ACCOUNTS, FALSE, &error); + + if (error != NULL) + { + DEBUG ("Failed to set import_mc4_accounts key: %s\n", error->message); + g_clear_error (&error); + } + + g_slist_free (dirs); + g_object_unref (client); +} \ No newline at end of file diff --git a/src/empathy-import-mc4-accounts.h b/src/empathy-import-mc4-accounts.h new file mode 100644 index 000000000..fcc5118cf --- /dev/null +++ b/src/empathy-import-mc4-accounts.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Arnaud Maillet + */ + +#ifndef __EMPATHY_IMPORT_MC4_ACCOUNTS_H__ +#define __EMPATHY_IMPORT_MC4_ACCOUNTS_H__ + +G_BEGIN_DECLS + +void empathy_import_mc4_accounts (void); + +G_END_DECLS + +#endif /* __EMPATHY_IMPORT_MC4_ACCOUNTS_H__ */ \ No newline at end of file -- cgit v1.2.3 From 4e9b2251c70bd47c52806963a7cd9f6389240798 Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Sat, 22 Aug 2009 14:53:34 +0200 Subject: Add a new gconf value to know if mc4 accounts have to be imported --- data/empathy.schemas.in | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/data/empathy.schemas.in b/data/empathy.schemas.in index bb9068725..7c0f8af20 100644 --- a/data/empathy.schemas.in +++ b/data/empathy.schemas.in @@ -481,6 +481,23 @@ /schemas/apps/empathy/use_conn /apps/empathy/use_conn + /schemas/apps/empathy/accounts/import_mc4_accounts + /apps/empathy/accounts/import_mc4_accounts + empathy + bool + true + + MC 4 accounts have to be imported + + MC 4 accounts have to be importedd on the first + Empathy run. + + + + + + /schemas/apps/empathy/use_nm + /apps/empathy/use_nm empathy bool true -- cgit v1.2.3 From cd4e69ec454107edd7e6ef4b36d75a28e7588c77 Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Sat, 22 Aug 2009 14:54:06 +0200 Subject: Add a new DEBUG domain for the mc4 account importer --- libempathy/empathy-debug.c | 1 + libempathy/empathy-debug.h | 1 + 2 files changed, 2 insertions(+) diff --git a/libempathy/empathy-debug.c b/libempathy/empathy-debug.c index 9d69b801c..141340024 100644 --- a/libempathy/empathy-debug.c +++ b/libempathy/empathy-debug.c @@ -50,6 +50,7 @@ static GDebugKey keys[] = { { "Location", EMPATHY_DEBUG_LOCATION }, { "Other", EMPATHY_DEBUG_OTHER }, { "Connectivity", EMPATHY_DEBUG_CONNECTIVITY }, + { "ImportMc4Accounts", EMPATHY_DEBUG_IMPORT_MC4_ACCOUNTS }, { 0, } }; diff --git a/libempathy/empathy-debug.h b/libempathy/empathy-debug.h index edfa05d95..cc8eca0a3 100644 --- a/libempathy/empathy-debug.h +++ b/libempathy/empathy-debug.h @@ -43,6 +43,7 @@ typedef enum EMPATHY_DEBUG_OTHER = 1 << 9, EMPATHY_DEBUG_SHARE_DESKTOP = 1 << 10, EMPATHY_DEBUG_CONNECTIVITY = 1 << 11, + EMPATHY_DEBUG_IMPORT_MC4_ACCOUNTS = 1 << 11, } EmpathyDebugFlags; gboolean empathy_debug_flag_is_set (EmpathyDebugFlags flag); -- cgit v1.2.3 From 5b34b46eb22ab9b178144959a23ca99d5b20f3ac Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Sat, 22 Aug 2009 14:54:49 +0200 Subject: Add the mc4 account importer files in the makefile --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.am b/src/Makefile.am index 3641835f7..6896c03f3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,6 +39,7 @@ empathy_handwritten_source = \ empathy-debug-dialog.c empathy-debug-dialog.h \ empathy-chat-window.c empathy-chat-window.h \ empathy-event-manager.c empathy-event-manager.h \ + empathy-import-mc4-accounts.c empathy-import-mc4-accounts.h \ empathy-ft-manager.c empathy-ft-manager.h \ empathy-import-dialog.c empathy-import-dialog.h \ empathy-import-widget.c empathy-import-widget.h \ -- cgit v1.2.3 From 53077973f94837e583296a2d4c93db84317e1913 Mon Sep 17 00:00:00 2001 From: Arnaud Maillet Date: Sat, 22 Aug 2009 14:55:49 +0200 Subject: Instantiate the mc4 account importer in empathy.c --- src/empathy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/empathy.c b/src/empathy.c index 650129ebb..a80d39684 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -70,6 +70,7 @@ #include "empathy-call-window.h" #include "empathy-chat-window.h" #include "empathy-ft-manager.h" +#include "empathy-import-mc4-accounts.h" #include "extensions/extensions.h" @@ -328,6 +329,7 @@ connection_managers_ready_cb (EmpathyConnectionManagers *managers, { if (empathy_connection_managers_is_ready (managers)) { + empathy_import_mc4_accounts (); create_salut_account_if_needed (managers); g_object_unref (managers); managers = NULL; -- cgit v1.2.3 From 047eaa1027bc50f98f0980f0169b3ccbdda34238 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 14:31:46 +0100 Subject: Remove unused finalize --- libempathy/empathy-connection-managers.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c index 82699d3d6..bd6f315e2 100644 --- a/libempathy/empathy-connection-managers.c +++ b/libempathy/empathy-connection-managers.c @@ -85,7 +85,6 @@ empathy_connection_managers_init (EmpathyConnectionManagers *obj) } static void empathy_connection_managers_dispose (GObject *object); -static void empathy_connection_managers_finalize (GObject *object); static GObject * empathy_connection_managers_constructor (GType type, @@ -138,7 +137,6 @@ empathy_connection_managers_class_init ( object_class->constructor = empathy_connection_managers_constructor; object_class->dispose = empathy_connection_managers_dispose; - object_class->finalize = empathy_connection_managers_finalize; object_class->get_property = empathy_connection_managers_get_property; g_object_class_install_property (object_class, PROP_READY, @@ -194,20 +192,6 @@ empathy_connection_managers_dispose (GObject *object) G_OBJECT_CLASS (empathy_connection_managers_parent_class)->dispose (object); } -void -empathy_connection_managers_finalize (GObject *object) -{ -#if 0 - EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object); - EmpathyConnectionManagersPriv *priv = - EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (self); - - /* free any data held directly by the object here */ - - G_OBJECT_CLASS (empathy_connection_managers_parent_class)->finalize (object); -#endif -} - EmpathyConnectionManagers * empathy_connection_managers_dup_singleton (void) { -- cgit v1.2.3 From 50a7def3f5ba311a0e5f8725d6ccaa1215742db6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 14:51:18 +0100 Subject: Return the correct object when querying the dbus-daemon property --- libempathy/empathy-account.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 2dd662874..091950880 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -192,8 +192,7 @@ empathy_account_get_property (GObject *object, empathy_account_get_display_name (account)); break; case PROP_DBUS_DAEMON: - g_value_set_string (value, - empathy_account_get_display_name (account)); + g_value_set_object (value, priv->dbus); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); -- cgit v1.2.3 From b466c826795481a46c47f74773689633d9bb0b6c Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 14:55:17 +0100 Subject: Use new async enable api --- src/empathy-import-mc4-accounts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 0dbadd6ee..13f81e4e2 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -234,7 +234,7 @@ _create_account_cb (GObject *source, } DEBUG ("account created\n"); - empathy_account_set_enabled (account, data->enabled); + empathy_account_set_enabled_async (account, data->enabled, NULL, NULL); g_object_unref (account); _account_data_free (data); -- cgit v1.2.3 From 8781e7c615d1f233a530cff66cfe47aa54fddd2f Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 14:55:53 +0100 Subject: Don't unref the account object as we don't own it --- src/empathy-import-mc4-accounts.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 13f81e4e2..86e2b1a3b 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -236,7 +236,6 @@ _create_account_cb (GObject *source, DEBUG ("account created\n"); empathy_account_set_enabled_async (account, data->enabled, NULL, NULL); - g_object_unref (account); _account_data_free (data); } -- cgit v1.2.3 From 4b5fa08436333e571186c991496549be520f21eb Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 14:57:32 +0100 Subject: Make the gconf entry be false by default --- data/empathy.schemas.in | 17 +++++++---------- src/empathy-import-mc4-accounts.c | 15 ++++++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/data/empathy.schemas.in b/data/empathy.schemas.in index 7c0f8af20..3c752ad12 100644 --- a/data/empathy.schemas.in +++ b/data/empathy.schemas.in @@ -479,25 +479,22 @@ - /schemas/apps/empathy/use_conn - /apps/empathy/use_conn - /schemas/apps/empathy/accounts/import_mc4_accounts - /apps/empathy/accounts/import_mc4_accounts + /schemas/apps/empathy/accounts/imported_mc4_accounts + /apps/empathy/accounts/imported_mc4_accounts empathy bool - true + false - MC 4 accounts have to be imported + MC 4 accounts were imported - MC 4 accounts have to be importedd on the first - Empathy run. + MC 4 accounts were to be imported. - /schemas/apps/empathy/use_nm - /apps/empathy/use_nm + /schemas/apps/empathy/use_conn + /apps/empathy/use_conn empathy bool true diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 86e2b1a3b..4ce8d4e80 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -32,7 +32,7 @@ #include #define MC_ACCOUNTS_GCONF_BASE "/apps/telepathy/mc/accounts" -#define IMPORT_MC4_ACCOUNTS "/apps/empathy/accounts/import_mc4_accounts" +#define IMPORTED_MC4_ACCOUNTS "/apps/empathy/accounts/imported_mc4_accounts" typedef struct { @@ -436,12 +436,12 @@ void empathy_import_mc4_accounts (void) GConfClient *client; GError *error = NULL; GSList *dir, *dirs, *entries; - gboolean import_mc4_accounts; + gboolean imported_mc4_accounts; client = gconf_client_get_default (); - import_mc4_accounts = gconf_client_get_bool (client, - IMPORT_MC4_ACCOUNTS, &error); + imported_mc4_accounts = gconf_client_get_bool (client, + IMPORTED_MC4_ACCOUNTS, &error); if (error != NULL) { @@ -451,8 +451,9 @@ void empathy_import_mc4_accounts (void) return; } - if (!import_mc4_accounts) + if (imported_mc4_accounts) { + DEBUG ("Mc4 accounts already imported"); g_object_unref (client); return; } @@ -541,7 +542,7 @@ void empathy_import_mc4_accounts (void) } gconf_client_set_bool (client, - IMPORT_MC4_ACCOUNTS, FALSE, &error); + IMPORTED_MC4_ACCOUNTS, TRUE, &error); if (error != NULL) { @@ -551,4 +552,4 @@ void empathy_import_mc4_accounts (void) g_slist_free (dirs); g_object_unref (client); -} \ No newline at end of file +} -- cgit v1.2.3 From 9498d6a67a0085d0bab3e49cd11288daa6474771 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 15:00:28 +0100 Subject: Use g_str_has_prefix convenience function for clarity --- src/empathy-import-mc4-accounts.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 4ce8d4e80..8fa8d5845 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -19,6 +19,7 @@ * Authors: Arnaud Maillet */ +#include #include #include #include @@ -120,7 +121,7 @@ _account_name_from_key (const gchar *key) guint base_len = strlen (MC_ACCOUNTS_GCONF_BASE); const gchar *base, *slash; - g_assert (key == strstr (key, MC_ACCOUNTS_GCONF_BASE)); + g_assert (g_str_has_prefix (key, MC_ACCOUNTS_GCONF_BASE)); g_assert (strlen (key) > base_len + 1); base = key + base_len + 1; -- cgit v1.2.3 From 6e879827478efe7a4cb8d03101840cbff32188b1 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 17:37:25 +0100 Subject: Don't override the display_name when creating the account --- libempathy/empathy-account-settings.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index efcbb2d8e..81a7a948e 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -1094,12 +1094,6 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings, if (priv->account == NULL) { - const gchar *default_display_name; - default_display_name = empathy_account_settings_get_string (settings, - "account"); - empathy_account_settings_set_display_name_async (settings, - default_display_name, NULL, NULL); - if (empathy_account_manager_is_ready (priv->account_manager)) empathy_account_settings_do_create_account (settings); else -- cgit v1.2.3 From 95cddd4f98544e4526a08cc25e5dd3fce0ed2a33 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 17:51:58 +0100 Subject: Overhaul the importer slightly --- src/empathy-import-mc4-accounts.c | 516 +++++++++++++------------------------- src/empathy-import-mc4-accounts.h | 6 +- 2 files changed, 179 insertions(+), 343 deletions(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 8fa8d5845..eea3b7f18 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -22,9 +22,12 @@ #include #include #include +#include #include #include +#include #include +#include #include #include "empathy-import-mc4-accounts.h" @@ -43,78 +46,15 @@ typedef struct static ProfileProtocolMapItem profile_protocol_map[] = { - { "aim", "aim" }, { "ekiga", "sip" }, { "fwd", "sip" }, - { "gadugadu", "gadugadu" }, - { "groupwise", "groupwise" }, { "gtalk", "jabber" }, - { "icq", "icq" }, - { "irc", "irc" }, - { "jabber", "jabber" }, { "msn-haze", "msn" }, - { "msn", "msn" }, - { "qq", "qq" }, { "salut", "local-xmpp" }, - { "sametime", "sametime" }, { "sipphone", "sip" }, { "sofiasip", "sip" }, - { "yahoo", "yahoo" }, }; -typedef struct -{ - gchar *connection_manager; - gchar *protocol; - gchar *display_name; - gchar *param_account; - gchar *param_server; - gboolean enabled; - GHashTable *parameters; -} AccountData; - -static void -_account_data_free (AccountData *account) -{ - if (account->connection_manager != NULL) - { - g_free (account->connection_manager); - account->connection_manager = NULL; - } - - if (account->protocol != NULL) - { - g_free (account->protocol); - account->protocol = NULL; - } - - if (account->display_name != NULL) - { - g_free (account->display_name); - account->display_name = NULL; - } - - if (account->param_account != NULL) - { - g_free (account->param_account); - account->param_account = NULL; - } - - if (account->param_server != NULL) - { - g_free (account->param_server); - account->param_server = NULL; - } - - if (account->parameters != NULL) - { - g_hash_table_destroy (account->parameters); - account->parameters = NULL; - } - - g_slice_free (AccountData, account); -} - static gchar * _account_name_from_key (const gchar *key) { @@ -147,70 +87,47 @@ _param_name_from_key (const gchar *key) return g_strdup (slash+1); } -static void -_normalize_display_name (AccountData *account) +static gchar * +_create_default_display_name (const gchar *protocol) { + if (!tp_strdiff (protocol, "local-xmpp")) + return g_strdup (_("People Nearby")); - if (account->display_name != NULL) - return; - - if (!tp_strdiff (account->protocol, "local-xmpp")) - { - account->display_name = g_strdup ("Nearby People"); - } - - else if (!tp_strdiff (account->protocol, "irc")) - { - - if (account->display_name != NULL) - { - g_free (account->display_name); - account->display_name = NULL; - } - - account->display_name = g_strdup_printf - ("%s on %s", account->param_account, account->param_server); - - } - - else if (account->display_name == NULL) - { - - if (account->param_account != NULL) - account->display_name = g_strdup - ((const gchar *) account->param_account); - else - account->display_name = g_strdup - ("No display name"); - - } + return g_strdup_printf ("%s account", protocol); } -static gboolean -_protocol_is_supported (AccountData *data) +static const gchar * +_get_manager_for_protocol (EmpathyConnectionManagers *managers, + const gchar *protocol) { - EmpathyConnectionManagers *cm = - empathy_connection_managers_dup_singleton (); - GList *cms = empathy_connection_managers_get_cms (cm); + GList *cms = empathy_connection_managers_get_cms (managers); GList *l; - gboolean proto_is_supported = FALSE; + TpConnectionManager *haze = NULL; + TpConnectionManager *cm = NULL; for (l = cms; l; l = l->next) { TpConnectionManager *tp_cm = l->data; - const gchar *cm_name = tp_connection_manager_get_name (tp_cm); - if (tp_connection_manager_has_protocol (tp_cm, - (const gchar*)data->protocol)) + + /* Only use haze if no other cm provides this account */ + if (!tp_strdiff (tp_connection_manager_get_name (tp_cm), "haze")) { - data->connection_manager = g_strdup (cm_name); - proto_is_supported = TRUE; - break; + haze = tp_cm; + continue; + } + + if (tp_connection_manager_has_protocol (tp_cm, protocol)) + { + cm = tp_cm; + goto out; } } - g_object_unref (cm); + if (haze != NULL && tp_connection_manager_has_protocol (haze, protocol)) + return tp_connection_manager_get_name (haze); - return proto_is_supported; +out: + return cm != NULL ? tp_connection_manager_get_name (cm) : NULL; } static void @@ -218,227 +135,208 @@ _create_account_cb (GObject *source, GAsyncResult *result, gpointer user_data) { - AccountData *data = (AccountData*) user_data; EmpathyAccount *account; GError *error = NULL; - account = empathy_account_manager_create_account_finish ( - EMPATHY_ACCOUNT_MANAGER (source), result, &error); - - if (account == NULL) + if (!empathy_account_settings_apply_finish ( + EMPATHY_ACCOUNT_SETTINGS (source), result, &error)) { DEBUG ("Failed to create account: %s", error ? error->message : "No error given"); - g_clear_error (&error); - _account_data_free (data); - return; + g_error_free (error); + goto out; } DEBUG ("account created\n"); - empathy_account_set_enabled_async (account, data->enabled, NULL, NULL); + account = empathy_account_settings_get_account ( + EMPATHY_ACCOUNT_SETTINGS (source)); + empathy_account_set_enabled_async (account, + GPOINTER_TO_INT (user_data), NULL, NULL); - _account_data_free (data); +out: + g_object_unref (source); } -static void -_recurse_account (GSList *entries, AccountData *account) +static gchar * +_get_protocol_from_profile (const gchar *profile) { - GSList *tmp; + gint i; - for (tmp = entries; tmp != NULL; tmp = tmp->next) - { + DEBUG ("profile: %s\n", profile); - GConfEntry *entry; - gchar *param; - GConfValue *value; + for (i = 0; i < G_N_ELEMENTS (profile_protocol_map); i++) + if (!tp_strdiff (profile, profile_protocol_map[i].profile)) + return g_strdup (profile_protocol_map[i].protocol); - entry = (GConfEntry*) tmp->data; - param = _param_name_from_key (gconf_entry_get_key (entry)); - - if (!tp_strdiff (param, "profile")) - { - const gchar *profile; - gint i; - value = gconf_entry_get_value (entry); - profile = gconf_value_get_string (value); - - DEBUG ("profile: %s\n", profile); - - for (i = 0; i < G_N_ELEMENTS (profile_protocol_map); i++) - { - if (!tp_strdiff (profile, profile_protocol_map[i].profile)) - { - account->protocol = g_strdup - (profile_protocol_map[i].protocol); - break; - } - } - } - - else if (!tp_strdiff (param, "enabled")) - { - value = gconf_entry_get_value (entry); - account->enabled = gconf_value_get_bool (value); - } - - else if (!tp_strdiff (param, "display_name")) - { - value = gconf_entry_get_value (entry); - account->display_name = g_strdup (gconf_value_get_string (value)); - } - - else if (!tp_strdiff (param, "param-account")) - { - - GValue *my_g_value; - - value = gconf_entry_get_value (entry); - account->param_account = g_strdup (gconf_value_get_string (value)); - - my_g_value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (my_g_value, account->param_account); - g_hash_table_insert (account->parameters, "account", my_g_value); - - } - - else if (!tp_strdiff (param, "param-server")) - { - - GValue *my_g_value; - - value = gconf_entry_get_value (entry); - account->param_account = g_strdup (gconf_value_get_string (value)); + return g_strdup (profile); +} - my_g_value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (my_g_value, account->param_account); - g_hash_table_insert (account->parameters, "server", my_g_value); +static void +_handle_entry (EmpathyAccountSettings *settings, + const gchar *key, + GConfEntry *entry) +{ + const gchar *signature; - } + signature = empathy_account_settings_get_dbus_signature (settings, key); + if (signature == NULL) + { + DEBUG ("Parameter %s is unknown", signature); + return; + } - else if (!tp_strdiff (param, "param-port")) + switch ((int)*signature) + { + case DBUS_TYPE_INT16: + case DBUS_TYPE_INT32: { - - GValue *my_g_value; - - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_UINT); - g_value_set_uint (my_g_value, gconf_value_get_int (value)); - g_hash_table_insert (account->parameters, "password", my_g_value);; - + gint v = gconf_value_get_int (gconf_entry_get_value (entry)); + empathy_account_settings_set_int32 (settings, key, v); + break; } - - - else if (!tp_strdiff (param, "param-password")) + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: { - - GValue *my_g_value; - - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (my_g_value, gconf_value_get_string (value)); - g_hash_table_insert (account->parameters, "password", my_g_value); - + gint v = gconf_value_get_int (gconf_entry_get_value (entry)); + empathy_account_settings_set_uint32 (settings, key, v); + break; } - - else if (!tp_strdiff (param, "param-require-encryption")) + case DBUS_TYPE_STRING: { + const gchar *v = gconf_value_get_string ( + gconf_entry_get_value (entry)); - GValue *my_g_value; - - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_BOOLEAN); - g_value_set_boolean (my_g_value, gconf_value_get_bool (value)); - g_hash_table_insert (account->parameters, "require-encryption", my_g_value); - + empathy_account_settings_set_string (settings, key, v); + break; } - - else if (!tp_strdiff (param, "param-register")) + case DBUS_TYPE_BOOLEAN: { + gboolean v = gconf_value_get_bool ( + gconf_entry_get_value (entry)); - GValue *my_g_value; - - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_BOOLEAN); - g_value_set_boolean (my_g_value, gconf_value_get_bool (value)); - g_hash_table_insert (account->parameters, "require-register", my_g_value); - + empathy_account_settings_set_boolean (settings, key, v); + break; } + default: + DEBUG ("Unsupported type in signature: %s", signature); + } +} - else if (!tp_strdiff (param, "param-ident")) - { +static void +_recurse_account (GSList *entries, EmpathyAccountSettings *settings) +{ + GSList *tmp; - GValue *my_g_value; + for (tmp = entries; tmp != NULL; tmp = tmp->next) + { - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (my_g_value, gconf_value_get_string (value)); - g_hash_table_insert (account->parameters, "ident", my_g_value); + GConfEntry *entry; + gchar *param; - } + entry = (GConfEntry*) tmp->data; + param = _param_name_from_key (gconf_entry_get_key (entry)); - else if (!tp_strdiff (param, "param-fullname")) + if (g_str_has_prefix (param, "param-")) { - - GValue *my_g_value; - - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (my_g_value, gconf_value_get_string (value)); - g_hash_table_insert (account->parameters, "fullname", my_g_value); - + _handle_entry (settings, param + strlen ("param-"), entry); } - else if (!tp_strdiff (param, "param-stun-server")) - { - - GValue *my_g_value; + g_free (param); + gconf_entry_unref (entry); + } +} - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (my_g_value, gconf_value_get_string (value)); - g_hash_table_insert (account->parameters, "stun-server", my_g_value); +static void +import_one_account (const char *path, + EmpathyConnectionManagers *managers, + GConfClient *client) +{ + gchar *account_name = _account_name_from_key (path); + EmpathyAccountSettings *settings; + GError *error = NULL; + GSList *entries = NULL; + gchar *profile = NULL; + gchar *protocol = NULL; + const gchar *manager; + gchar *display_name; + gchar *key; + gboolean enabled = FALSE; - } + DEBUG ("Starting import of %s (%s)", path, account_name); - else if (!tp_strdiff (param, "param-stun-port")) - { + key = g_strdup_printf ("%s/profile", path); + profile = gconf_client_get_string (client, key, NULL); + g_free (key); - GValue *my_g_value; + if (profile == NULL) + { + DEBUG ("Account is missing a profile entry\n"); + goto failed; + } - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_UINT); - g_value_set_uint (my_g_value, gconf_value_get_int (value)); - g_hash_table_insert (account->parameters, "stun-port", my_g_value);; + protocol = _get_protocol_from_profile (profile); + manager = _get_manager_for_protocol (managers, protocol); + if (manager == NULL) + { + DEBUG ("No manager available for this protocol %s", protocol); + goto failed; + } - } + key = g_strdup_printf ("%s/display_name", path); + display_name = gconf_client_get_string (client, key, NULL); + g_free (key); - else if (!tp_strdiff (param, "param-keepalive-interval")) - { + if (display_name == NULL) + display_name = _create_default_display_name (protocol); - GValue *my_g_value; + settings = empathy_account_settings_new (manager, protocol, display_name); + g_free (display_name); - value = gconf_entry_get_value (entry); - my_g_value = tp_g_value_slice_new (G_TYPE_UINT); - g_value_set_uint (my_g_value, gconf_value_get_int (value)); - g_hash_table_insert (account->parameters, "keepalive-interval", my_g_value);; + /* Bit of a hack, as we know EmpathyConnectionManagers is ready the + * EmpathyAccountSettings should be ready right away as well */ + g_assert (empathy_account_settings_is_ready (settings)); - } + entries = gconf_client_all_entries (client, path, &error); - g_free (param); - gconf_entry_unref (entry); + if (entries == NULL) + { + DEBUG ("Failed to get all entries: %s\n", error->message); + g_error_free (error); + goto failed; } - _normalize_display_name (account); + _recurse_account (entries, settings); + + key = g_strdup_printf ("%s/enabled", path); + enabled = gconf_client_get_bool (client, key, NULL); + g_free (key); + empathy_account_settings_apply_async (settings, + _create_account_cb, GINT_TO_POINTER (enabled)); +out: + g_free (protocol); + g_free (profile); + g_slist_free (entries); + g_free (account_name); + return; + +failed: + DEBUG ("Failed to import %s", path); + if (settings != NULL) + g_object_unref (settings); + goto out; } -void empathy_import_mc4_accounts (void) +void +empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) { GConfClient *client; GError *error = NULL; - GSList *dir, *dirs, *entries; + GSList *dir, *dirs; gboolean imported_mc4_accounts; + g_return_if_fail (empathy_connection_managers_is_ready (managers)); + client = gconf_client_get_default (); imported_mc4_accounts = gconf_client_get_bool (client, @@ -474,73 +372,10 @@ void empathy_import_mc4_accounts (void) for (dir = dirs; NULL != dir; dir = dir->next) { - gchar *account_name = _account_name_from_key (dir->data); - AccountData *account; - - account = g_slice_new0 (AccountData); - - account->connection_manager = NULL; - account->protocol = NULL; - account->enabled = FALSE; - account->display_name = NULL; - account->param_account = NULL; - account->param_server = NULL; - account->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, (GDestroyNotify) tp_g_value_slice_free); - - DEBUG ("name : %s\n", account_name); - - entries = gconf_client_all_entries (client, dir->data, &error); - - if (error != NULL) - { - - DEBUG ("Failed to get all entries: %s\n", error->message); - g_clear_error (&error); - - } - else - { - _recurse_account (entries, account); - } - - if (_protocol_is_supported (account)) - { - EmpathyAccountManager *account_manager; - GHashTable *properties; - - account_manager = empathy_account_manager_dup_singleton (); - - properties = g_hash_table_new (NULL, NULL); - - DEBUG ("account cm: %s", account->connection_manager); - DEBUG ("account protocol: %s", account->protocol); - DEBUG ("account display_name: %s", account->display_name); - DEBUG ("account param_account: %s", account->param_account); - DEBUG ("account param_server: %s", account->param_server); - DEBUG ("enabled: %d", account->enabled); - tp_asv_dump (account->parameters); - - empathy_account_manager_create_account_async (account_manager, - (const gchar*) account->connection_manager, - (const gchar*) account->protocol, account->display_name, - account->parameters, properties, - _create_account_cb, account); - - g_hash_table_unref (properties); - g_object_unref (account_manager); - } - else - { - DEBUG ("protocol of this account is not supported\n"); - _account_data_free (account); - } - - g_slist_free (entries); - g_free (account_name); + import_one_account ((gchar *)dir->data, managers, client); g_free (dir->data); - } + g_slist_free (dirs); gconf_client_set_bool (client, IMPORTED_MC4_ACCOUNTS, TRUE, &error); @@ -551,6 +386,5 @@ void empathy_import_mc4_accounts (void) g_clear_error (&error); } - g_slist_free (dirs); g_object_unref (client); } diff --git a/src/empathy-import-mc4-accounts.h b/src/empathy-import-mc4-accounts.h index fcc5118cf..e5392db67 100644 --- a/src/empathy-import-mc4-accounts.h +++ b/src/empathy-import-mc4-accounts.h @@ -24,8 +24,10 @@ G_BEGIN_DECLS -void empathy_import_mc4_accounts (void); +#include + +void empathy_import_mc4_accounts (EmpathyConnectionManagers *managers); G_END_DECLS -#endif /* __EMPATHY_IMPORT_MC4_ACCOUNTS_H__ */ \ No newline at end of file +#endif /* __EMPATHY_IMPORT_MC4_ACCOUNTS_H__ */ -- cgit v1.2.3 From f4cd87f5aba95e2c20cb4af10f9de8e1d62b3702 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 18:16:24 +0100 Subject: Grab passwords from the keyring if needed --- configure.ac | 2 ++ src/empathy-import-mc4-accounts.c | 47 ++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 7576c8e9d..080fdffd4 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,7 @@ LIBCHAMPLAIN_GTK_REQUIRED=0.3.6 CLUTTER_GTK_REQUIRED=0.10 GEOCLUE_REQUIRED=0.11 WEBKIT_REQUIRED=1.1.7 +KEYRING_REQUIRED=2.22 NETWORK_MANAGER_REQUIRED=0.7.0 # Use --enable-maintainer-mode to disabled deprecated symbols @@ -127,6 +128,7 @@ PKG_CHECK_MODULES(EMPATHY, telepathy-farsight gstreamer-0.10 unique-1.0 + gnome-keyring-1 >= $KEYRING_REQUIRED ]) PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index eea3b7f18..614c5cbe3 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -172,7 +173,35 @@ _get_protocol_from_profile (const gchar *profile) } static void -_handle_entry (EmpathyAccountSettings *settings, +_set_password_from_keyring (EmpathyAccountSettings *settings, + const gchar *account_name, const gchar *key) +{ + GnomeKeyringResult res; + gchar *password; + GnomeKeyringPasswordSchema keyring_schema = { + GNOME_KEYRING_ITEM_GENERIC_SECRET, + { + { "account", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, + { "param", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, + { NULL, 0 } + } + }; + + res = gnome_keyring_find_password_sync (&keyring_schema, + &password, + "account", account_name, + "param", key, + NULL); + + if (res == GNOME_KEYRING_RESULT_OK) + { + empathy_account_settings_set_string (settings, key, password); + gnome_keyring_free_password (password); + } +} + +static void +_handle_entry (EmpathyAccountSettings *settings, const gchar *account_name, const gchar *key, GConfEntry *entry) { @@ -206,7 +235,13 @@ _handle_entry (EmpathyAccountSettings *settings, const gchar *v = gconf_value_get_string ( gconf_entry_get_value (entry)); - empathy_account_settings_set_string (settings, key, v); + /* MC 4 would put password in the keyring and leave the password in + * gconf keyring */ + + if (!tp_strdiff (key, "password") && !tp_strdiff (v, "keyring")) + _set_password_from_keyring (settings, account_name, key); + else + empathy_account_settings_set_string (settings, key, v); break; } case DBUS_TYPE_BOOLEAN: @@ -223,7 +258,8 @@ _handle_entry (EmpathyAccountSettings *settings, } static void -_recurse_account (GSList *entries, EmpathyAccountSettings *settings) +_recurse_account (GSList *entries, EmpathyAccountSettings *settings, + const gchar *account_name) { GSList *tmp; @@ -238,7 +274,8 @@ _recurse_account (GSList *entries, EmpathyAccountSettings *settings) if (g_str_has_prefix (param, "param-")) { - _handle_entry (settings, param + strlen ("param-"), entry); + _handle_entry (settings, account_name, param + strlen ("param-"), + entry); } g_free (param); @@ -306,7 +343,7 @@ import_one_account (const char *path, goto failed; } - _recurse_account (entries, settings); + _recurse_account (entries, settings, account_name); key = g_strdup_printf ("%s/enabled", path); enabled = gconf_client_get_bool (client, key, NULL); -- cgit v1.2.3 From afd7de0052654752aa60edc8dddfd628eaa49ce6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 18:24:46 +0100 Subject: Return TRUE if we imported any mc4 accounts --- src/empathy-import-mc4-accounts.c | 30 +++++++++++++++++++----------- src/empathy-import-mc4-accounts.h | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 614c5cbe3..5425b35cd 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -283,7 +283,7 @@ _recurse_account (GSList *entries, EmpathyAccountSettings *settings, } } -static void +static gboolean import_one_account (const char *path, EmpathyConnectionManagers *managers, GConfClient *client) @@ -298,6 +298,7 @@ import_one_account (const char *path, gchar *display_name; gchar *key; gboolean enabled = FALSE; + gboolean ret = FALSE; DEBUG ("Starting import of %s (%s)", path, account_name); @@ -350,12 +351,15 @@ import_one_account (const char *path, g_free (key); empathy_account_settings_apply_async (settings, _create_account_cb, GINT_TO_POINTER (enabled)); + ret = TRUE; + out: g_free (protocol); g_free (profile); g_slist_free (entries); g_free (account_name); - return; + + return ret; failed: DEBUG ("Failed to import %s", path); @@ -364,15 +368,17 @@ failed: goto out; } -void +gboolean empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) { GConfClient *client; GError *error = NULL; - GSList *dir, *dirs; + GSList *dir, *dirs = NULL; gboolean imported_mc4_accounts; + gboolean imported = FALSE; - g_return_if_fail (empathy_connection_managers_is_ready (managers)); + g_return_val_if_fail (empathy_connection_managers_is_ready (managers), + FALSE); client = gconf_client_get_default (); @@ -384,14 +390,13 @@ empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) DEBUG ("Failed to get import_mc4_accounts key: %s\n", error->message); g_clear_error (&error); g_object_unref (client); - return; + goto out; } if (imported_mc4_accounts) { DEBUG ("Mc4 accounts already imported"); - g_object_unref (client); - return; + goto out; } DEBUG ("MC 4 accounts are going to be imported\n"); @@ -404,15 +409,15 @@ empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) error->message); g_clear_error (&error); g_object_unref (client); - return; + goto out; } for (dir = dirs; NULL != dir; dir = dir->next) { - import_one_account ((gchar *)dir->data, managers, client); + if (import_one_account ((gchar *)dir->data, managers, client)) + imported = TRUE; g_free (dir->data); } - g_slist_free (dirs); gconf_client_set_bool (client, IMPORTED_MC4_ACCOUNTS, TRUE, &error); @@ -423,5 +428,8 @@ empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) g_clear_error (&error); } +out: + g_slist_free (dirs); g_object_unref (client); + return imported; } diff --git a/src/empathy-import-mc4-accounts.h b/src/empathy-import-mc4-accounts.h index e5392db67..c30b4e505 100644 --- a/src/empathy-import-mc4-accounts.h +++ b/src/empathy-import-mc4-accounts.h @@ -26,7 +26,7 @@ G_BEGIN_DECLS #include -void empathy_import_mc4_accounts (EmpathyConnectionManagers *managers); +gboolean empathy_import_mc4_accounts (EmpathyConnectionManagers *managers); G_END_DECLS -- cgit v1.2.3 From 9d3432812718541748315d119b22960c190a2ffd Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 18:45:13 +0100 Subject: Add api to ask if we have importer our mc4 accounts --- src/empathy-import-mc4-accounts.c | 14 ++++++++++++++ src/empathy-import-mc4-accounts.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 5425b35cd..27dd94956 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -368,6 +368,20 @@ failed: goto out; } +gboolean +empathy_import_mc4_has_imported (void) +{ + GConfClient *client; + gboolean ret; + + client = gconf_client_get_default (); + + ret = gconf_client_get_bool (client, IMPORTED_MC4_ACCOUNTS, NULL); + g_object_unref (client); + + return ret; +} + gboolean empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) { diff --git a/src/empathy-import-mc4-accounts.h b/src/empathy-import-mc4-accounts.h index c30b4e505..98fb86916 100644 --- a/src/empathy-import-mc4-accounts.h +++ b/src/empathy-import-mc4-accounts.h @@ -27,6 +27,7 @@ G_BEGIN_DECLS #include gboolean empathy_import_mc4_accounts (EmpathyConnectionManagers *managers); +gboolean empathy_import_mc4_has_imported (void); G_END_DECLS -- cgit v1.2.3 From 3cdcb21a13d11a2026d242c242704b0581a7b475 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 18:52:17 +0100 Subject: Fix debug strings, don't unref the gconf client twice --- src/empathy-import-mc4-accounts.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 27dd94956..312b5a2fc 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -402,14 +402,13 @@ empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) if (error != NULL) { DEBUG ("Failed to get import_mc4_accounts key: %s\n", error->message); - g_clear_error (&error); - g_object_unref (client); + g_error_free (error); goto out; } if (imported_mc4_accounts) { - DEBUG ("Mc4 accounts already imported"); + DEBUG ("Mc4 accounts previously imported"); goto out; } @@ -419,7 +418,7 @@ empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) if (error != NULL) { - DEBUG ("Failed to get mc_accounts_gconf_base dirs: %s\n", + DEBUG ("Failed to get MC4 account dirs: %s\n", error->message); g_clear_error (&error); g_object_unref (client); -- cgit v1.2.3 From 97ce0c3a078943c1c25ad8e2411482ffc9edc8c8 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 18:53:33 +0100 Subject: Always set the mc4 imported gconf key --- src/empathy-import-mc4-accounts.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 312b5a2fc..6f2a02c83 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -432,16 +432,9 @@ empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) g_free (dir->data); } - gconf_client_set_bool (client, - IMPORTED_MC4_ACCOUNTS, TRUE, &error); - - if (error != NULL) - { - DEBUG ("Failed to set import_mc4_accounts key: %s\n", error->message); - g_clear_error (&error); - } - out: + gconf_client_set_bool (client, IMPORTED_MC4_ACCOUNTS, TRUE, NULL); + g_slist_free (dirs); g_object_unref (client); return imported; -- cgit v1.2.3 From 96ae3367ff3aca2ef4c33e7e1f4790c7d5cc6fe3 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 18:55:54 +0100 Subject: Refactor the startup sequence a bit On initial start the following should happen: * If we haven't tried to import mc4 accounts, do so * If there were no mc4 accounts imported and there are no accounts defined show the account creation assistant. * If we haven't created a salut account, do so --- src/empathy.c | 67 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/src/empathy.c b/src/empathy.c index a80d39684..38fd56c54 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -323,39 +323,41 @@ create_salut_account_if_needed (EmpathyConnectionManagers *managers) } static void -connection_managers_ready_cb (EmpathyConnectionManagers *managers, - GParamSpec *spec, - gpointer user_data) +maybe_show_account_assistant (void) { - if (empathy_connection_managers_is_ready (managers)) + EmpathyAccountManager *manager; + manager = empathy_account_manager_dup_singleton (); + + if (empathy_account_manager_get_count (manager) == 0) { - empathy_import_mc4_accounts (); - create_salut_account_if_needed (managers); - g_object_unref (managers); - managers = NULL; + GtkWidget * assistant = empathy_account_assistant_new ( + GTK_WINDOW (empathy_main_window_get ())); + gtk_window_present (GTK_WINDOW (assistant)); } } -static void -create_salut_account (void) +static gboolean +check_connection_managers_ready (EmpathyConnectionManagers *managers) { - EmpathyConnectionManagers *managers; - - if (!should_create_salut_account ()) - return; - - managers = empathy_connection_managers_dup_singleton (); - if (empathy_connection_managers_is_ready (managers)) { + if (!empathy_import_mc4_accounts (managers)) + maybe_show_account_assistant (); + create_salut_account_if_needed (managers); g_object_unref (managers); + managers = NULL; + return TRUE; } - else - { - g_signal_connect (managers, "notify::ready", - G_CALLBACK (connection_managers_ready_cb), NULL); - } + return FALSE; +} + +static void +connection_managers_ready_cb (EmpathyConnectionManagers *managers, + GParamSpec *spec, + gpointer user_data) +{ + check_connection_managers_ready (managers); } static void @@ -536,19 +538,24 @@ account_manager_ready_cb (EmpathyAccountManager *manager, GParamSpec *spec, gpointer user_data) { - GtkWidget *assistant; - if (!empathy_account_manager_is_ready (manager)) return; - if (empathy_account_manager_get_count (manager) == 0) + if (should_create_salut_account () || !empathy_import_mc4_has_imported ()) { - assistant = empathy_account_assistant_new ( - GTK_WINDOW (empathy_main_window_get ())); - gtk_window_present (GTK_WINDOW (assistant)); - } + EmpathyConnectionManagers *managers; + managers = empathy_connection_managers_dup_singleton (); - create_salut_account (); + if (!check_connection_managers_ready (managers)) + { + g_signal_connect (managers, "notify::ready", + G_CALLBACK (connection_managers_ready_cb), NULL); + } + } + else + { + maybe_show_account_assistant (); + } } int -- cgit v1.2.3 From a71220d4f3f8c5acec4e17b18573225dd0a5c125 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 21:26:17 +0100 Subject: Make the dir names for the logs look nicer --- libempathy/empathy-log-store-empathy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 81cbcade7..fe1afd9b0 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -37,6 +37,7 @@ #define G_DISABLE_DEPRECATED #include +#include #include "empathy-log-store.h" #include "empathy-log-store-empathy.h" @@ -122,15 +123,16 @@ log_store_empathy_get_dir (EmpathyLogStore *self, { gchar *basedir; gchar *escaped; + const gchar *name; EmpathyLogStoreEmpathyPriv *priv; priv = GET_PRIV (self); - /* unique name is an object path, ignore the initial / and replace the others - * by % */ - escaped = g_strdup (empathy_account_get_unique_name (account) + 1); + name = empathy_account_get_unique_name (account); + if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE)) + name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); - g_strdelimit (escaped, "/", '%'); + escaped = g_strdelimit (g_strdup (name), "/", '_'); if (chatroom) basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, escaped, -- cgit v1.2.3 From 35d058ac2d105c9c77aa378e4dc4a9e7abae8597 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 22:43:14 +0100 Subject: Move the logs to the new location after creating the account --- src/empathy-import-mc4-accounts.c | 96 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 4 deletions(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 6f2a02c83..df4668720 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,11 @@ static ProfileProtocolMapItem profile_protocol_map[] = { "sofiasip", "sip" }, }; +typedef struct { + gchar *account_name; + gboolean enable; +} Misc; + static gchar * _account_name_from_key (const gchar *key) { @@ -131,6 +137,76 @@ out: return cm != NULL ? tp_connection_manager_get_name (cm) : NULL; } +static void +_move_contents (const gchar *old, const gchar *new) +{ + GDir *source; + const gchar *f; + int ret; + + ret = g_mkdir_with_parents (new, 0777); + if (ret == -1) + return; + + source = g_dir_open (old, 0, NULL); + if (source == NULL) + return; + + while ((f = g_dir_read_name (source)) != NULL) + { + gchar *old_path; + gchar *new_path; + + old_path = g_build_path (G_DIR_SEPARATOR_S, old, f, NULL); + new_path = g_build_path (G_DIR_SEPARATOR_S, new, f, NULL); + + if (g_file_test (old_path, G_FILE_TEST_IS_DIR)) + { + _move_contents (old_path, new_path); + } + else + { + GFile *f_old, *f_new; + + f_old = g_file_new_for_path (old_path); + f_new = g_file_new_for_path (new_path); + + g_file_move (f_old, f_new, G_FILE_COPY_NONE, + NULL, NULL, NULL, NULL); + + g_object_unref (f_old); + g_object_unref (f_new); + } + + g_free (old_path); + g_free (new_path); + } + + g_dir_close (source); +} + +static void +_move_logs (EmpathyAccount *account, const gchar *account_name) +{ + gchar *old_path, *new_path, *escaped; + const gchar *name; + + name = empathy_account_get_unique_name (account); + if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE)) + name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); + + escaped = g_strdelimit (g_strdup (name), "/", '_'); + new_path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), + PACKAGE_NAME, "logs", escaped, NULL); + g_free (escaped); + + old_path = g_build_path (G_DIR_SEPARATOR_S, + g_get_home_dir (), + ".gnome2", PACKAGE_NAME, "logs", account_name, NULL); + + _move_contents (old_path, new_path); +} + static void _create_account_cb (GObject *source, GAsyncResult *result, @@ -138,6 +214,7 @@ _create_account_cb (GObject *source, { EmpathyAccount *account; GError *error = NULL; + Misc *misc = (Misc *)user_data; if (!empathy_account_settings_apply_finish ( EMPATHY_ACCOUNT_SETTINGS (source), result, &error)) @@ -151,8 +228,14 @@ _create_account_cb (GObject *source, DEBUG ("account created\n"); account = empathy_account_settings_get_account ( EMPATHY_ACCOUNT_SETTINGS (source)); + + _move_logs (account, misc->account_name); + empathy_account_set_enabled_async (account, - GPOINTER_TO_INT (user_data), NULL, NULL); + misc->enable, NULL, NULL); + + g_free (misc->account_name); + g_slice_free (Misc, misc); out: g_object_unref (source); @@ -299,6 +382,7 @@ import_one_account (const char *path, gchar *key; gboolean enabled = FALSE; gboolean ret = FALSE; + Misc *misc; DEBUG ("Starting import of %s (%s)", path, account_name); @@ -338,7 +422,6 @@ import_one_account (const char *path, if (entries == NULL) { - DEBUG ("Failed to get all entries: %s\n", error->message); g_error_free (error); goto failed; @@ -349,20 +432,25 @@ import_one_account (const char *path, key = g_strdup_printf ("%s/enabled", path); enabled = gconf_client_get_bool (client, key, NULL); g_free (key); + + misc = g_slice_new (Misc); + misc->account_name = account_name; + misc->enable = enabled; + empathy_account_settings_apply_async (settings, - _create_account_cb, GINT_TO_POINTER (enabled)); + _create_account_cb, misc); ret = TRUE; out: g_free (protocol); g_free (profile); g_slist_free (entries); - g_free (account_name); return ret; failed: DEBUG ("Failed to import %s", path); + g_free (account_name); if (settings != NULL) g_object_unref (settings); goto out; -- cgit v1.2.3 From 6d77d369532c3806c8bba9ab2374d7b795657c0d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 22:50:36 +0100 Subject: Fix some broken english --- data/empathy.schemas.in | 4 ++-- src/empathy-import-mc4-accounts.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/empathy.schemas.in b/data/empathy.schemas.in index 3c752ad12..6aa7f8a5f 100644 --- a/data/empathy.schemas.in +++ b/data/empathy.schemas.in @@ -485,9 +485,9 @@ bool false - MC 4 accounts were imported + MC 4 accounts have been imported - MC 4 accounts were to be imported. + MC 4 accounts have been imported. diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index df4668720..c9a0bf238 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -116,7 +116,7 @@ _get_manager_for_protocol (EmpathyConnectionManagers *managers, { TpConnectionManager *tp_cm = l->data; - /* Only use haze if no other cm provides this account */ + /* Only use haze if no other cm provides this protocol */ if (!tp_strdiff (tp_connection_manager_get_name (tp_cm), "haze")) { haze = tp_cm; -- cgit v1.2.3 From 93e0d79fad604f7b0494f738f65cd5c6c46ecc8c Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 22:51:02 +0100 Subject: Fix copyright date --- src/empathy-import-mc4-accounts.c | 2 +- src/empathy-import-mc4-accounts.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index c9a0bf238..53063d6c2 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2009 Collabora Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as diff --git a/src/empathy-import-mc4-accounts.h b/src/empathy-import-mc4-accounts.h index 98fb86916..0a30fdff7 100644 --- a/src/empathy-import-mc4-accounts.h +++ b/src/empathy-import-mc4-accounts.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2009 Collabora Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as -- cgit v1.2.3 From 81ad518058d0ae188c1dc229c55d6c8f71f84dbe Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 22:51:32 +0100 Subject: Fix use after free --- src/empathy-import-mc4-accounts.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 53063d6c2..602cfc1f9 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -85,13 +85,16 @@ _param_name_from_key (const gchar *key) { const gchar *base, *slash; gchar *account_name; + gchar *ret; account_name = _account_name_from_key (key); base = strstr (key, account_name); slash = strchr (base, '/'); + + ret = g_strdup (slash+1); g_free (account_name); - return g_strdup (slash+1); + return ret; } static gchar * -- cgit v1.2.3 From 05deeddf094d51dfdfc6133850f40e3e1d5591ca Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 22:51:52 +0100 Subject: Put string up for translation --- src/empathy-import-mc4-accounts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 602cfc1f9..c4ceb2f4b 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -103,7 +103,7 @@ _create_default_display_name (const gchar *protocol) if (!tp_strdiff (protocol, "local-xmpp")) return g_strdup (_("People Nearby")); - return g_strdup_printf ("%s account", protocol); + return g_strdup_printf (_("%s account"), protocol); } static const gchar * -- cgit v1.2.3 From 74bba154cc8476d831140e27148d4897633e2d18 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 22:52:40 +0100 Subject: When empathy_account_settings_apply_finish returns false the error is always set --- src/empathy-import-mc4-accounts.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index c4ceb2f4b..a7a08ea84 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -222,8 +222,7 @@ _create_account_cb (GObject *source, if (!empathy_account_settings_apply_finish ( EMPATHY_ACCOUNT_SETTINGS (source), result, &error)) { - DEBUG ("Failed to create account: %s", - error ? error->message : "No error given"); + DEBUG ("Failed to create account: %s", error->message); g_error_free (error); goto out; } -- cgit v1.2.3 From 25bd33610962da0a8ff8dba645ac84e9f84d7e4f Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 23:13:12 +0100 Subject: Add a new _ensure_account API Have one call which only gets the account if it exists and a different one which creates the account on the given path when needed. --- libempathy/empathy-account-manager.c | 16 +++++++++++++--- libempathy/empathy-account-manager.h | 3 +++ libempathy/empathy-dispatcher.c | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 2f0f13415..20facd379 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -337,6 +337,15 @@ empathy_account_manager_get_account (EmpathyAccountManager *manager, const gchar *path) { EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + + return g_hash_table_lookup (priv->accounts, path); +} + +EmpathyAccount * +empathy_account_manager_ensure_account (EmpathyAccountManager *manager, + const gchar *path) +{ + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); EmpathyAccount *account; account = g_hash_table_lookup (priv->accounts, path); @@ -352,6 +361,7 @@ empathy_account_manager_get_account (EmpathyAccountManager *manager, return account; } + static void account_manager_got_all_cb (TpProxy *proxy, GHashTable *properties, @@ -378,7 +388,7 @@ account_manager_got_all_cb (TpProxy *proxy, { gchar *name = g_ptr_array_index (accounts, i); - empathy_account_manager_get_account (manager, name); + empathy_account_manager_ensure_account (manager, name); } } @@ -397,7 +407,7 @@ account_validity_changed_cb (TpAccountManager *proxy, if (!valid) return; - empathy_account_manager_get_account (manager, path); + empathy_account_manager_ensure_account (manager, path); } static void @@ -909,7 +919,7 @@ empathy_account_manager_created_cb (TpAccountManager *proxy, return; } - account = empathy_account_manager_get_account (manager, account_path); + account = empathy_account_manager_ensure_account (manager, account_path); g_hash_table_insert (priv->create_results, account, my_res); } diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h index e0ec93761..25adfdbeb 100644 --- a/libempathy/empathy-account-manager.h +++ b/libempathy/empathy-account-manager.h @@ -69,6 +69,9 @@ int empathy_account_manager_get_count EmpathyAccount * empathy_account_manager_get_account_for_connection (EmpathyAccountManager *manager, TpConnection *connection); +EmpathyAccount * empathy_account_manager_ensure_account + (EmpathyAccountManager *manager, + const gchar *unique_name); EmpathyAccount * empathy_account_manager_get_account (EmpathyAccountManager *manager, const gchar *unique_name); diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 7e1492de8..465f23b75 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -1800,7 +1800,7 @@ empathy_dispatcher_handle_channels (TpSvcClientHandler *self, EmpathyAccount *account; TpConnection *connection; - account = empathy_account_manager_get_account (priv->account_manager, + account = empathy_account_manager_ensure_account (priv->account_manager, account_path); g_assert (account != NULL); -- cgit v1.2.3 From 7894d6060831bbb8134386cb24e1cf741a146ace Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 23:15:29 +0100 Subject: Ensure that the connection data is setup when handle channels --- libempathy/empathy-dispatcher.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 465f23b75..c1a19f699 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -104,6 +104,10 @@ enum static guint signals[LAST_SIGNAL]; static EmpathyDispatcher *dispatcher = NULL; +static void dispatcher_init_connection_if_needed ( + EmpathyDispatcher *dispatcher, + TpConnection *connection); + static GList * empathy_dispatcher_find_channel_classes (EmpathyDispatcher *dispatcher, TpConnection *connection, const gchar *channel_type, guint handle_type, GArray *fixed_properties); @@ -590,6 +594,8 @@ dispatcher_connection_new_channel (EmpathyDispatcher *dispatcher, NULL }; + dispatcher_init_connection_if_needed (dispatcher, connection); + cd = g_hash_table_lookup (priv->connections, connection); /* Don't bother with channels we have already dispatched or are dispatching @@ -784,9 +790,8 @@ dispatcher_connection_advertise_capabilities_cb (TpConnection *connection, } static void -dispatcher_new_connection_cb (EmpathyAccountManager *manager, - TpConnection *connection, - EmpathyDispatcher *dispatcher) +dispatcher_init_connection_if_needed (EmpathyDispatcher *dispatcher, + TpConnection *connection) { EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); GPtrArray *capabilities; @@ -835,6 +840,14 @@ dispatcher_new_connection_cb (EmpathyAccountManager *manager, g_ptr_array_free (capabilities, TRUE); } +static void +dispatcher_new_connection_cb (EmpathyAccountManager *manager, + TpConnection *connection, + EmpathyDispatcher *dispatcher) +{ + dispatcher_init_connection_if_needed (dispatcher, connection); +} + static void remove_idle_handlers (gpointer key, gpointer value, -- cgit v1.2.3 From aa0487edef4dc671e99a9e4dc6a1895c0fdaca4a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 24 Aug 2009 00:21:27 +0100 Subject: Split out the account name to dirname translation --- libempathy/empathy-log-store-empathy.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index fe1afd9b0..723ee6434 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -115,6 +115,19 @@ empathy_log_store_empathy_init (EmpathyLogStoreEmpathy *self) priv->account_manager = empathy_account_manager_dup_singleton (); } +static gchar * +log_store_account_to_dirname (EmpathyAccount *account) +{ + const gchar *name; + + name = empathy_account_get_unique_name (account); + if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE)) + name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); + + return g_strdelimit (g_strdup (name), "/", '_'); +} + + static gchar * log_store_empathy_get_dir (EmpathyLogStore *self, EmpathyAccount *account, @@ -123,16 +136,11 @@ log_store_empathy_get_dir (EmpathyLogStore *self, { gchar *basedir; gchar *escaped; - const gchar *name; EmpathyLogStoreEmpathyPriv *priv; priv = GET_PRIV (self); - name = empathy_account_get_unique_name (account); - if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE)) - name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); - - escaped = g_strdelimit (g_strdup (name), "/", '_'); + escaped = log_store_account_to_dirname (account); if (chatroom) basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, escaped, -- cgit v1.2.3 From f23c28d9775e5679fa17568cb49e296b8251e0ea Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 24 Aug 2009 00:22:54 +0100 Subject: Have log_store_empathy_search_hit_new lookup accounts properly --- libempathy/empathy-log-store-empathy.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 723ee6434..2049fc24a 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -389,11 +389,11 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self, { EmpathyLogStoreEmpathyPriv *priv = GET_PRIV (self); EmpathyLogSearchHit *hit; - gchar *unescaped; gchar *account_name; const gchar *end; gchar **strv; guint len; + GList *accounts, *l; if (!g_str_has_suffix (filename, LOG_FILENAME_SUFFIX)) return NULL; @@ -413,15 +413,25 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self, else account_name = strv[len-3]; - unescaped = g_strdup_printf ("/%s", g_strdelimit (account_name, "%", '/')); + accounts = empathy_account_manager_dup_accounts(priv->account_manager); + + for (l = accounts; l != NULL; l = g_list_next (l)) + { + EmpathyAccount *account = EMPATHY_ACCOUNT (l->data); + gchar *name; + name = log_store_account_to_dirname (account); + if (!tp_strdiff (name, account_name)) + { + g_assert (hit->account == NULL); + hit->account = account; + g_object_ref (account); + } + g_object_unref (account); + } + g_list_free (accounts); - hit->account = empathy_account_manager_get_account (priv->account_manager, - unescaped); - if (hit->account != NULL) - g_object_ref (hit->account); hit->filename = g_strdup (filename); - g_free (unescaped); g_strfreev (strv); return hit; -- cgit v1.2.3 From 276a8e15dae658c49849aed43ac3094a0f6225e1 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 24 Aug 2009 00:23:27 +0100 Subject: Don't use a custom function to build the log dir --- libempathy/empathy-log-store-empathy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 2049fc24a..ff59eccbc 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -748,8 +748,7 @@ log_store_empathy_get_chats (EmpathyLogStore *self, priv = GET_PRIV (self); - dir = g_build_filename (priv->basedir, - empathy_account_get_unique_name (account), NULL); + dir = log_store_empathy_get_dir (self, account, NULL, FALSE); hits = log_store_empathy_get_chats_for_dir (self, dir, FALSE); -- cgit v1.2.3 From 82c599881220294274e047813bd060e73fe45718 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 24 Aug 2009 11:34:45 +0100 Subject: Add empathy-import-mc4-accounts to POTFILES --- po/POTFILES.in | 1 + 1 file changed, 1 insertion(+) diff --git a/po/POTFILES.in b/po/POTFILES.in index a140f16c4..b2a6382df 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -79,6 +79,7 @@ src/empathy-import-dialog.c src/empathy-import-widget.c [type: gettext/glade]src/empathy-import-dialog.ui src/empathy-import-widget.c +src/empathy-import-mc4-accounts.c src/empathy-main-window.c [type: gettext/glade]src/empathy-main-window.ui src/empathy-new-chatroom-dialog.c -- cgit v1.2.3 From f421f61bb5e2ef7e8067b5874e0230961be389d5 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 24 Aug 2009 11:35:00 +0100 Subject: Fix several coding style issues --- libempathy/empathy-log-store-empathy.c | 2 +- src/empathy-import-mc4-accounts.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index ff59eccbc..8b228794f 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -413,7 +413,7 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self, else account_name = strv[len-3]; - accounts = empathy_account_manager_dup_accounts(priv->account_manager); + accounts = empathy_account_manager_dup_accounts (priv->account_manager); for (l = accounts; l != NULL; l = g_list_next (l)) { diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index a7a08ea84..968293bd2 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -217,7 +217,7 @@ _create_account_cb (GObject *source, { EmpathyAccount *account; GError *error = NULL; - Misc *misc = (Misc *)user_data; + Misc *misc = (Misc *) user_data; if (!empathy_account_settings_apply_finish ( EMPATHY_ACCOUNT_SETTINGS (source), result, &error)) @@ -354,7 +354,7 @@ _recurse_account (GSList *entries, EmpathyAccountSettings *settings, GConfEntry *entry; gchar *param; - entry = (GConfEntry*) tmp->data; + entry = (GConfEntry *) tmp->data; param = _param_name_from_key (gconf_entry_get_key (entry)); if (g_str_has_prefix (param, "param-")) @@ -517,7 +517,7 @@ empathy_import_mc4_accounts (EmpathyConnectionManagers *managers) for (dir = dirs; NULL != dir; dir = dir->next) { - if (import_one_account ((gchar *)dir->data, managers, client)) + if (import_one_account ((gchar *) dir->data, managers, client)) imported = TRUE; g_free (dir->data); } -- cgit v1.2.3 From 1cd5827a7e47c76834ed22ab4548a564623d3245 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 24 Aug 2009 11:37:23 +0100 Subject: Free the allocated dirname after usage --- libempathy/empathy-log-store-empathy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 8b228794f..9963bfc44 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -419,6 +419,7 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self, { EmpathyAccount *account = EMPATHY_ACCOUNT (l->data); gchar *name; + name = log_store_account_to_dirname (account); if (!tp_strdiff (name, account_name)) { @@ -427,6 +428,7 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self, g_object_ref (account); } g_object_unref (account); + g_free (name); } g_list_free (accounts); -- cgit v1.2.3 From 532d0bd9055bdc5ff75eba8568953022ffa6e6df Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 24 Aug 2009 12:00:23 +0100 Subject: empathy-account-widget: don't expand and fill vertically the 'Activate' checkbox --- libempathy-gtk/empathy-account-widget.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 9712ae984..0927d109c 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -1232,8 +1232,9 @@ do_constructed (GObject *obj) gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows, nb_columns); - gtk_table_attach_defaults (GTK_TABLE (priv->table_common_settings), - priv->enabled_checkbox, 0, nb_columns, nb_rows - 1, nb_rows); + gtk_table_attach (GTK_TABLE (priv->table_common_settings), + priv->enabled_checkbox, 0, nb_columns, nb_rows - 1, nb_rows, + GTK_EXPAND | GTK_FILL, 0, 0, 0); gtk_widget_show (priv->enabled_checkbox); -- cgit v1.2.3 From cdf5ef7743814ca18104d5dba1a04e79a3554d0e Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 24 Aug 2009 12:01:52 +0100 Subject: empathy-accounts-dialog: remove the hardcoded Gmail label --- src/empathy-accounts-dialog.ui | 1 - 1 file changed, 1 deletion(-) diff --git a/src/empathy-accounts-dialog.ui b/src/empathy-accounts-dialog.ui index cd98415d7..e5226b270 100644 --- a/src/empathy-accounts-dialog.ui +++ b/src/empathy-accounts-dialog.ui @@ -80,7 +80,6 @@ True True - Gmail True -- cgit v1.2.3 From 2b0b994dca5c7fe90f26befab4fd01d92908edef Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 24 Aug 2009 14:08:50 +0200 Subject: Add example labels to all protocols Also, fix padding and make the label prettier. --- libempathy-gtk/empathy-account-widget-aim.ui | 33 ++++++++++++++++++---- libempathy-gtk/empathy-account-widget-groupwise.ui | 28 ++++++++++++++---- libempathy-gtk/empathy-account-widget-icq.ui | 33 ++++++++++++++++++---- libempathy-gtk/empathy-account-widget-jabber.ui | 3 +- libempathy-gtk/empathy-account-widget-msn.ui | 28 ++++++++++++++---- libempathy-gtk/empathy-account-widget-sip.ui | 26 ++++++++++++++--- libempathy-gtk/empathy-account-widget-yahoo.ui | 33 ++++++++++++++++++---- 7 files changed, 151 insertions(+), 33 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget-aim.ui b/libempathy-gtk/empathy-account-widget-aim.ui index 05c942d9c..2dfdde216 100644 --- a/libempathy-gtk/empathy-account-widget-aim.ui +++ b/libempathy-gtk/empathy-account-widget-aim.ui @@ -15,7 +15,7 @@ True - 2 + 3 3 12 6 @@ -28,8 +28,8 @@ entry_password - 1 - 2 + 2 + 3 GTK_FILL @@ -63,8 +63,8 @@ 2 3 - 1 - 2 + 2 + 3 @@ -88,12 +88,33 @@ False + + 1 + 2 + 2 + 3 + + + + + + + + + + + + True + 0 + 3 + <span size="small"><b>Example:</b> MyScreenName</span> + True + 1 2 1 2 - diff --git a/libempathy-gtk/empathy-account-widget-groupwise.ui b/libempathy-gtk/empathy-account-widget-groupwise.ui index c0a717e5e..d8ce768f9 100644 --- a/libempathy-gtk/empathy-account-widget-groupwise.ui +++ b/libempathy-gtk/empathy-account-widget-groupwise.ui @@ -14,7 +14,7 @@ True - 2 + 3 2 6 6 @@ -56,8 +56,8 @@ 1 2 - 1 - 2 + 2 + 3 @@ -69,8 +69,8 @@ True - 1 - 2 + 2 + 3 GTK_FILL @@ -100,6 +100,24 @@ + + + + + + True + 0 + 3 + <span size="small"><b>Example:</b> username</span> + True + + + 1 + 2 + 1 + 2 + + False diff --git a/libempathy-gtk/empathy-account-widget-icq.ui b/libempathy-gtk/empathy-account-widget-icq.ui index 1a19500b5..a36698a09 100644 --- a/libempathy-gtk/empathy-account-widget-icq.ui +++ b/libempathy-gtk/empathy-account-widget-icq.ui @@ -15,7 +15,7 @@ True - 2 + 3 3 12 6 @@ -28,8 +28,8 @@ entry_password - 1 - 2 + 2 + 3 GTK_FILL @@ -63,8 +63,8 @@ 2 3 - 1 - 2 + 2 + 3 @@ -88,12 +88,33 @@ False + + 1 + 2 + 2 + 3 + + + + + + + + + + + + True + 0 + 3 + <span size="small"><b>Example:</b> 123456789</span> + True + 1 2 1 2 - diff --git a/libempathy-gtk/empathy-account-widget-jabber.ui b/libempathy-gtk/empathy-account-widget-jabber.ui index 2d602cb7f..d32182257 100644 --- a/libempathy-gtk/empathy-account-widget-jabber.ui +++ b/libempathy-gtk/empathy-account-widget-jabber.ui @@ -107,7 +107,8 @@ True 0 - Example: <span size="small">test@jabber.org</span> + 3 + <span size="small"><b>Example:</b> user@jabber.org</span> True diff --git a/libempathy-gtk/empathy-account-widget-msn.ui b/libempathy-gtk/empathy-account-widget-msn.ui index dbca5fc7e..27de65a2a 100644 --- a/libempathy-gtk/empathy-account-widget-msn.ui +++ b/libempathy-gtk/empathy-account-widget-msn.ui @@ -14,7 +14,7 @@ True - 2 + 3 2 6 6 @@ -56,8 +56,8 @@ 1 2 - 1 - 2 + 2 + 3 @@ -69,8 +69,8 @@ True - 1 - 2 + 2 + 3 GTK_FILL @@ -100,6 +100,24 @@ + + + + + + True + 0 + 3 + <span size="small"><b>Example:</b> user@hotmail.com</span> + True + + + 1 + 2 + 1 + 2 + + False diff --git a/libempathy-gtk/empathy-account-widget-sip.ui b/libempathy-gtk/empathy-account-widget-sip.ui index 45e0f7d31..e8491a6a5 100644 --- a/libempathy-gtk/empathy-account-widget-sip.ui +++ b/libempathy-gtk/empathy-account-widget-sip.ui @@ -13,7 +13,7 @@ True - 2 + 3 2 12 6 @@ -26,8 +26,8 @@ entry_password - 1 - 2 + 2 + 3 GTK_FILL @@ -89,12 +89,30 @@ + + 1 + 2 + 2 + 3 + + + + + + + + + True + 0 + 3 + <span size="small"><b>Example:</b> user@my.sip.server</span> + True + 1 2 1 2 - diff --git a/libempathy-gtk/empathy-account-widget-yahoo.ui b/libempathy-gtk/empathy-account-widget-yahoo.ui index 0800ac1dc..554e0dbec 100644 --- a/libempathy-gtk/empathy-account-widget-yahoo.ui +++ b/libempathy-gtk/empathy-account-widget-yahoo.ui @@ -16,7 +16,7 @@ True - 2 + 3 3 12 6 @@ -29,8 +29,8 @@ entry_password - 1 - 2 + 2 + 3 GTK_FILL @@ -51,8 +51,8 @@ 2 3 - 1 - 2 + 2 + 3 GTK_FILL @@ -89,12 +89,33 @@ False + + 1 + 2 + 2 + 3 + + + + + + + + + + + + True + 0 + 3 + <span size="small"><b>Example:</b> username</span> + True + 1 2 1 2 - -- cgit v1.2.3 From db8e44564590cc422920d83ed80fda900400abc0 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Mon, 24 Aug 2009 18:43:04 +0100 Subject: Fallback to setting the global presence to offline if no account has a better presence. Signed-off-by: Jonny Lamb --- libempathy/empathy-account-manager.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 20facd379..75de6f193 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -183,6 +183,7 @@ emp_account_manager_update_global_presence (EmpathyAccountManager *manager) if (account == NULL) { + priv->global_presence = presence; priv->global_status = NULL; priv->global_status_message = NULL; return; -- cgit v1.2.3 From de0881ae79de1418b8a2400ab1b8c5df64efff30 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 24 Aug 2009 19:42:46 +0100 Subject: Remove non-existing file from POTFILES.in --- po/POTFILES.in | 1 - 1 file changed, 1 deletion(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index b2a6382df..b7dcd7828 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -22,7 +22,6 @@ libempathy-gtk/empathy-account-widget-irc.c [type: gettext/glade]libempathy-gtk/empathy-account-widget-jabber.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-msn.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-local-xmpp.ui -[type: gettext/glade]libempathy-gtk/empathy-account-widget-salut.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-sip.ui [type: gettext/glade]libempathy-gtk/empathy-account-widget-yahoo.ui libempathy-gtk/empathy-avatar-chooser.c -- cgit v1.2.3 From d7f82b00ea09c62be272ed2d0c98e9120a722ca9 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 24 Aug 2009 19:44:28 +0100 Subject: Rename empathy_profile_chooser_get_type to _protocol_ --- docs/libempathy-gtk/libempathy-gtk.types | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/libempathy-gtk/libempathy-gtk.types b/docs/libempathy-gtk/libempathy-gtk.types index ead69316b..e82fdc914 100644 --- a/docs/libempathy-gtk/libempathy-gtk.types +++ b/docs/libempathy-gtk/libempathy-gtk.types @@ -22,7 +22,7 @@ empathy_contact_widget_flags_get_type empathy_gst_video_src_channel_get_type empathy_sound_get_type empathy_presence_chooser_get_type -empathy_profile_chooser_get_type +empathy_protocol_chooser_get_type empathy_smiley_manager_get_type empathy_status_preset_dialog_get_type empathy_theme_adium_get_type -- cgit v1.2.3