diff options
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-account-chooser.c | 185 | ||||
-rw-r--r-- | libempathy-gtk/empathy-account-chooser.h | 10 | ||||
-rw-r--r-- | libempathy-gtk/empathy-account-widget.c | 99 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat-text-view.c | 1 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 369 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat.h | 2 | ||||
-rw-r--r-- | libempathy-gtk/empathy-contact-dialogs.c | 7 | ||||
-rw-r--r-- | libempathy-gtk/empathy-contact-list-view.c | 18 | ||||
-rw-r--r-- | libempathy-gtk/empathy-contact-widget.c | 6 | ||||
-rw-r--r-- | libempathy-gtk/empathy-irc-network-dialog.c | 1 | ||||
-rw-r--r-- | libempathy-gtk/empathy-location-manager.c | 104 | ||||
-rw-r--r-- | libempathy-gtk/empathy-log-window.c | 79 | ||||
-rw-r--r-- | libempathy-gtk/empathy-log-window.h | 4 | ||||
-rw-r--r-- | libempathy-gtk/empathy-new-message-dialog.c | 27 | ||||
-rw-r--r-- | libempathy-gtk/empathy-presence-chooser.c | 59 | ||||
-rw-r--r-- | libempathy-gtk/empathy-theme-adium.c | 6 | ||||
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.h | 1 |
17 files changed, 715 insertions, 263 deletions
diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c index a91b0eb29..7624c2c13 100644 --- a/libempathy-gtk/empathy-account-chooser.c +++ b/libempathy-gtk/empathy-account-chooser.c @@ -29,12 +29,16 @@ #include <glib/gi18n-lib.h> #include <gtk/gtk.h> -#include <libempathy/empathy-account-manager.h> +#include <telepathy-glib/account-manager.h> + #include <libempathy/empathy-utils.h> #include "empathy-ui-utils.h" #include "empathy-account-chooser.h" +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include <libempathy/empathy-debug.h> + /** * SECTION:empathy-account-chooser * @title:EmpathyAccountChooser @@ -54,7 +58,7 @@ #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountChooser) typedef struct { - EmpathyAccountManager *manager; + TpAccountManager *manager; gboolean set_active_item; gboolean account_manually_set; gboolean has_all_option; @@ -64,7 +68,7 @@ typedef struct { typedef struct { EmpathyAccountChooser *chooser; - EmpathyAccount *account; + TpAccount *account; gboolean set; } SetAccountData; @@ -86,24 +90,26 @@ static void account_chooser_set_property (GObject const GValue *value, GParamSpec *pspec); static void account_chooser_setup (EmpathyAccountChooser *chooser); -static void account_chooser_account_created_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, +static void account_chooser_account_validity_changed_cb (TpAccountManager *manager, + TpAccount *account, + gboolean valid, EmpathyAccountChooser *chooser); -static void account_chooser_account_add_foreach (EmpathyAccount *account, +static void account_chooser_account_add_foreach (TpAccount *account, EmpathyAccountChooser *chooser); -static void account_chooser_account_deleted_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, +static void account_chooser_account_removed_cb (TpAccountManager *manager, + TpAccount *account, EmpathyAccountChooser *chooser); -static void account_chooser_account_remove_foreach (EmpathyAccount *account, +static void account_chooser_account_remove_foreach (TpAccount *account, EmpathyAccountChooser *chooser); static void account_chooser_update_iter (EmpathyAccountChooser *chooser, GtkTreeIter *iter); -static void account_chooser_connection_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - TpConnectionStatusReason reason, - TpConnectionStatus new_status, - TpConnectionStatus old_status, - EmpathyAccountChooser *chooser); +static void account_chooser_status_changed_cb (TpAccount *account, + guint old_status, + guint new_status, + guint reason, + gchar *dbus_error_name, + GHashTable *details, + gpointer user_data); static gboolean account_chooser_separator_func (GtkTreeModel *model, GtkTreeIter *iter, EmpathyAccountChooser *chooser); @@ -156,16 +162,13 @@ empathy_account_chooser_init (EmpathyAccountChooser *chooser) priv->filter = NULL; priv->filter_data = NULL; - priv->manager = empathy_account_manager_dup_singleton (); + priv->manager = tp_account_manager_dup (); - g_signal_connect (priv->manager, "account-created", - G_CALLBACK (account_chooser_account_created_cb), - chooser); - g_signal_connect (priv->manager, "account-deleted", - G_CALLBACK (account_chooser_account_deleted_cb), + g_signal_connect (priv->manager, "account-validity-changed", + G_CALLBACK (account_chooser_account_validity_changed_cb), chooser); - g_signal_connect (priv->manager, "account-connection-changed", - G_CALLBACK (account_chooser_connection_changed_cb), + g_signal_connect (priv->manager, "account-removed", + G_CALLBACK (account_chooser_account_removed_cb), chooser); account_chooser_setup (EMPATHY_ACCOUNT_CHOOSER (chooser)); @@ -177,13 +180,10 @@ account_chooser_finalize (GObject *object) EmpathyAccountChooserPriv *priv = GET_PRIV (object); g_signal_handlers_disconnect_by_func (priv->manager, - account_chooser_connection_changed_cb, + account_chooser_account_validity_changed_cb, object); g_signal_handlers_disconnect_by_func (priv->manager, - account_chooser_account_created_cb, - object); - g_signal_handlers_disconnect_by_func (priv->manager, - account_chooser_account_deleted_cb, + account_chooser_account_removed_cb, object); g_object_unref (priv->manager); @@ -253,16 +253,16 @@ empathy_account_chooser_new (void) * @chooser: an #EmpathyAccountChooser * * Returns the account which is currently selected in the chooser or %NULL - * if there is no account selected. The #EmpathyAccount returned should be + * if there is no account selected. The #TpAccount returned should be * unrefed with g_object_unref() when finished with. * - * Return value: a new ref to the #EmpathyAccount currently selected, or %NULL. + * Return value: a new ref to the #TpAccount currently selected, or %NULL. */ -EmpathyAccount * +TpAccount * empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser) { EmpathyAccountChooserPriv *priv; - EmpathyAccount *account; + TpAccount *account; GtkTreeModel *model; GtkTreeIter iter; @@ -295,7 +295,7 @@ TpConnection * empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser) { EmpathyAccountChooserPriv *priv; - EmpathyAccount *account; + TpAccount *account; TpConnection *connection; g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), NULL); @@ -303,7 +303,15 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser) priv = GET_PRIV (chooser); account = empathy_account_chooser_dup_account (chooser); - connection = empathy_account_get_connection (account); + + /* if the returned account is NULL, then the account manager probably + * hasn't been prepared yet. It should be safe to return NULL here + * though. */ + if (account == NULL) { + return NULL; + } + + connection = tp_account_get_connection (account); g_object_unref (account); return connection; @@ -312,7 +320,7 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser) /** * empathy_account_chooser_set_account: * @chooser: an #EmpathyAccountChooser - * @account: an #EmpathyAccount + * @account: a #TpAccount * * Sets the currently selected account to @account, if it exists in the list. * @@ -320,7 +328,7 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser) */ gboolean empathy_account_chooser_set_account (EmpathyAccountChooser *chooser, - EmpathyAccount *account) + TpAccount *account) { EmpathyAccountChooserPriv *priv; GtkComboBox *combobox; @@ -443,10 +451,40 @@ empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *chooser, } static void +account_manager_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + GList *accounts, *l; + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyAccountChooser *chooser = user_data; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (manager, result, &error)) { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } + + accounts = tp_account_manager_get_valid_accounts (manager); + + for (l = accounts; l != NULL; l = l->next) { + TpAccount *account = l->data; + + account_chooser_account_add_foreach (account, chooser); + + empathy_signal_connect_weak (account, "status-changed", + G_CALLBACK (account_chooser_status_changed_cb), + G_OBJECT (chooser)); + } + + g_list_free (accounts); +} + +static void account_chooser_setup (EmpathyAccountChooser *chooser) { EmpathyAccountChooserPriv *priv; - GList *accounts; GtkListStore *store; GtkCellRenderer *renderer; GtkComboBox *combobox; @@ -462,7 +500,7 @@ account_chooser_setup (EmpathyAccountChooser *chooser) G_TYPE_STRING, /* Image */ G_TYPE_STRING, /* Name */ G_TYPE_BOOLEAN, /* Enabled */ - EMPATHY_TYPE_ACCOUNT); + TP_TYPE_ACCOUNT); gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store)); @@ -482,25 +520,27 @@ account_chooser_setup (EmpathyAccountChooser *chooser) NULL); /* Populate accounts */ - accounts = empathy_account_manager_dup_accounts (priv->manager); - g_list_foreach (accounts, - (GFunc) account_chooser_account_add_foreach, - chooser); + tp_account_manager_prepare_async (priv->manager, NULL, + account_manager_prepared_cb, chooser); - g_list_free (accounts); g_object_unref (store); } static void -account_chooser_account_created_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountChooser *chooser) +account_chooser_account_validity_changed_cb (TpAccountManager *manager, + TpAccount *account, + gboolean valid, + EmpathyAccountChooser *chooser) { - account_chooser_account_add_foreach (account, chooser); + if (valid) { + account_chooser_account_add_foreach (account, chooser); + } else { + account_chooser_account_remove_foreach (account, chooser); + } } static void -account_chooser_account_add_foreach (EmpathyAccount *account, +account_chooser_account_add_foreach (TpAccount *account, EmpathyAccountChooser *chooser) { GtkListStore *store; @@ -516,20 +556,18 @@ account_chooser_account_add_foreach (EmpathyAccount *account, COL_ACCOUNT_POINTER, account, -1); account_chooser_update_iter (chooser, &iter); - /* We got a reffed account and it was reffed by the liststore as well */ - g_object_unref (account); } static void -account_chooser_account_deleted_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, +account_chooser_account_removed_cb (TpAccountManager *manager, + TpAccount *account, EmpathyAccountChooser *chooser) { account_chooser_account_remove_foreach (account, chooser); } typedef struct { - EmpathyAccount *account; + TpAccount *account; GtkTreeIter *iter; gboolean found; } FindAccountData; @@ -541,7 +579,7 @@ account_chooser_find_account_foreach (GtkTreeModel *model, gpointer user_data) { FindAccountData *data = user_data; - EmpathyAccount *account; + TpAccount *account; gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1); @@ -560,7 +598,7 @@ account_chooser_find_account_foreach (GtkTreeModel *model, static gboolean account_chooser_find_account (EmpathyAccountChooser *chooser, - EmpathyAccount *account, + TpAccount *account, GtkTreeIter *iter) { GtkListStore *store; @@ -580,7 +618,7 @@ account_chooser_find_account (EmpathyAccountChooser *chooser, } static void -account_chooser_account_remove_foreach (EmpathyAccount *account, +account_chooser_account_remove_foreach (TpAccount *account, EmpathyAccountChooser *chooser) { GtkListStore *store; @@ -602,7 +640,7 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser, EmpathyAccountChooserPriv *priv; GtkListStore *store; GtkComboBox *combobox; - EmpathyAccount *account; + TpAccount *account; const gchar *icon_name; gboolean is_enabled = TRUE; @@ -615,14 +653,14 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser, COL_ACCOUNT_POINTER, &account, -1); - icon_name = empathy_account_get_icon_name (account); + icon_name = tp_account_get_icon_name (account); if (priv->filter) { is_enabled = priv->filter (account, priv->filter_data); } gtk_list_store_set (store, iter, COL_ACCOUNT_IMAGE, icon_name, - COL_ACCOUNT_TEXT, empathy_account_get_display_name (account), + COL_ACCOUNT_TEXT, tp_account_get_display_name (account), COL_ACCOUNT_ENABLED, is_enabled, -1); @@ -637,13 +675,15 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser, } static void -account_chooser_connection_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - TpConnectionStatusReason reason, - TpConnectionStatus new_status, - TpConnectionStatus old_status, - EmpathyAccountChooser *chooser) +account_chooser_status_changed_cb (TpAccount *account, + guint old_status, + guint new_status, + guint reason, + gchar *dbus_error_name, + GHashTable *details, + gpointer user_data) { + EmpathyAccountChooser *chooser = user_data; GtkTreeIter iter; if (account_chooser_find_account (chooser, account, &iter)) { @@ -679,7 +719,7 @@ account_chooser_set_account_foreach (GtkTreeModel *model, GtkTreeIter *iter, SetAccountData *data) { - EmpathyAccount *account; + TpAccount *account; gboolean equal; gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1); @@ -750,7 +790,7 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser, /** * EmpathyAccountChooserFilterFunc: - * @account: an #EmpathyAccount + * @account: a #TpAccount * @user_data: user data, or %NULL * * A function which decides whether the account indicated by @account @@ -761,7 +801,7 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser, /** * empathy_account_chooser_filter_is_connected: - * @account: an #EmpathyAccount + * @account: a #TpAccount * @user_data: user data or %NULL * * A useful #EmpathyAccountChooserFilterFunc that one could pass into @@ -770,13 +810,10 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser, * Return value: Whether @account is connected */ gboolean -empathy_account_chooser_filter_is_connected (EmpathyAccount *account, +empathy_account_chooser_filter_is_connected (TpAccount *account, gpointer user_data) { - TpConnectionStatus status; - - g_object_get (account, "connection-status", &status, NULL); - - return status == TP_CONNECTION_STATUS_CONNECTED; + return (tp_account_get_connection_status (account, NULL) + == TP_CONNECTION_STATUS_CONNECTED); } diff --git a/libempathy-gtk/empathy-account-chooser.h b/libempathy-gtk/empathy-account-chooser.h index 255b6841f..075bea81c 100644 --- a/libempathy-gtk/empathy-account-chooser.h +++ b/libempathy-gtk/empathy-account-chooser.h @@ -27,7 +27,7 @@ #include <gtk/gtk.h> -#include <libempathy/empathy-account.h> +#include <telepathy-glib/account.h> G_BEGIN_DECLS @@ -38,7 +38,7 @@ G_BEGIN_DECLS #define EMPATHY_IS_ACCOUNT_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_ACCOUNT_CHOOSER)) #define EMPATHY_ACCOUNT_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserClass)) -typedef gboolean (* EmpathyAccountChooserFilterFunc) (EmpathyAccount *account, +typedef gboolean (* EmpathyAccountChooserFilterFunc) (TpAccount *account, gpointer user_data); @@ -58,17 +58,17 @@ struct _EmpathyAccountChooserClass { GType empathy_account_chooser_get_type (void) G_GNUC_CONST; GtkWidget * empathy_account_chooser_new (void); -EmpathyAccount * empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser); +TpAccount * empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser); TpConnection * empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser); gboolean empathy_account_chooser_set_account (EmpathyAccountChooser *chooser, - EmpathyAccount *account); + TpAccount *account); gboolean empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *chooser); void empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *chooser, gboolean has_all_option); void empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser, EmpathyAccountChooserFilterFunc filter, gpointer user_data); -gboolean empathy_account_chooser_filter_is_connected (EmpathyAccount *account, +gboolean empathy_account_chooser_filter_is_connected (TpAccount *account, gpointer user_data); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 05911144a..a8646d2bc 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -35,8 +35,9 @@ #endif #include <libempathy/empathy-utils.h> -#include <libempathy/empathy-account.h> +#include <libempathy/empathy-idle.h> +#include <telepathy-glib/account.h> #include <telepathy-glib/connection-manager.h> #include <telepathy-glib/util.h> #include <dbus/dbus-protocol.h> @@ -70,6 +71,11 @@ typedef struct { /* 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; + /* If we are creating a new account, this member is set to TRUE once the + * account has been created */ + gboolean account_created; + + EmpathyIdle *idle; gboolean dispose_run; } EmpathyAccountWidgetPriv; @@ -570,10 +576,11 @@ account_widget_account_enabled_cb (GObject *source_object, gpointer user_data) { GError *error = NULL; - EmpathyAccount *account = EMPATHY_ACCOUNT (source_object); + TpAccount *account = TP_ACCOUNT (source_object); EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data); + EmpathyAccountWidgetPriv *priv = GET_PRIV (widget); - empathy_account_set_enabled_finish (account, res, &error); + tp_account_set_enabled_finish (account, res, &error); if (error != NULL) { @@ -582,6 +589,7 @@ account_widget_account_enabled_cb (GObject *source_object, } else { + priv->account_created = TRUE; g_signal_emit (widget, signals[ACCOUNT_CREATED], 0); } } @@ -592,7 +600,7 @@ account_widget_applied_cb (GObject *source_object, gpointer user_data) { GError *error = NULL; - EmpathyAccount *account; + TpAccount *account; EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object); EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data); EmpathyAccountWidgetPriv *priv = GET_PRIV (widget); @@ -613,7 +621,7 @@ account_widget_applied_cb (GObject *source_object, if (priv->creating_account) { /* By default, when an account is created, we enable it. */ - empathy_account_set_enabled_async (account, TRUE, + tp_account_set_enabled_async (account, TRUE, account_widget_account_enabled_cb, widget); } else if (priv->enabled_checkbox != NULL) @@ -629,12 +637,12 @@ account_widget_applied_cb (GObject *source_object, NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox)); #endif - if (empathy_account_is_enabled (account) && enabled_checked) + if (tp_account_is_enabled (account) && enabled_checked) { /* After having applied changes to a user account, we * automatically reconnect it. This is done so the new * information entered by the user is validated on the server. */ - empathy_account_reconnect_async (account, NULL, NULL); + tp_account_reconnect_async (account, NULL, NULL); } } } @@ -1047,13 +1055,13 @@ account_widget_destroy_cb (GtkWidget *widget, } static void -empathy_account_widget_enabled_cb (EmpathyAccount *account, +empathy_account_widget_enabled_cb (TpAccount *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); + gboolean enabled = tp_account_is_enabled (account); if (priv->enabled_checkbox != NULL) { @@ -1079,7 +1087,7 @@ account_widget_switch_flipped_cb (NbtkGtkLightSwitch *sw, #endif /* HAVE_MOBLIN */ { EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data); - EmpathyAccount *account; + TpAccount *account; #ifndef HAVE_MOBLIN gboolean state; @@ -1089,7 +1097,7 @@ account_widget_switch_flipped_cb (NbtkGtkLightSwitch *sw, account = empathy_account_settings_get_account (priv->settings); /* Enable the account according to the value of the "Enabled" checkbox */ - empathy_account_set_enabled_async (account, state, NULL, NULL); + tp_account_set_enabled_async (account, state, NULL, NULL); } static void @@ -1144,6 +1152,26 @@ do_get_property (GObject *object, } } +static void +idle_state_change_cb (EmpathyIdle *idle, + GParamSpec *spec, + EmpathyAccountWidget *self) +{ + EmpathyAccountWidgetPriv *priv = GET_PRIV (self); + TpConnectionPresenceType state; + + state = empathy_idle_get_state (priv->idle); + + if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE) + { + g_object_set (priv->apply_button, "label", GTK_STOCK_CONNECT, NULL); + } + else + { + g_object_set (priv->apply_button, "label", GTK_STOCK_APPLY, NULL); + } +} + #define WIDGET(cm, proto) \ { #cm, #proto, "empathy-account-widget-"#proto".ui", \ account_widget_build_##proto } @@ -1153,7 +1181,7 @@ do_constructed (GObject *obj) { EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - EmpathyAccount *account; + TpAccount *account; const gchar *protocol, *cm_name; guint i = 0; struct { @@ -1240,10 +1268,38 @@ do_constructed (GObject *obj) if (!priv->simple) { GtkWidget *hbox = gtk_hbox_new (TRUE, 3); + const gchar *apply_button_id; priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); - priv->apply_button = gtk_button_new_from_stock ( - priv->creating_account ? GTK_STOCK_CONNECT : GTK_STOCK_APPLY); + + if (priv->creating_account) + { + TpConnectionPresenceType state; + priv->idle = empathy_idle_dup_singleton (); + + empathy_signal_connect_weak (priv->idle, "notify::state", + G_CALLBACK (idle_state_change_cb), obj); + + state = empathy_idle_get_state (priv->idle); + + if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE) + { + /* We are online, display a Connect button */ + apply_button_id = GTK_STOCK_CONNECT; + } + else + { + /* We are offline, display a Save button */ + apply_button_id = GTK_STOCK_SAVE; + } + } + else + { + /* We are editing an existing account, display an Apply button */ + apply_button_id = GTK_STOCK_APPLY; + } + + priv->apply_button = gtk_button_new_from_stock (apply_button_id); #ifdef HAVE_MOBLIN if (priv->creating_account) @@ -1295,7 +1351,7 @@ do_constructed (GObject *obj) guint nb_rows, nb_columns; gboolean is_enabled; - is_enabled = empathy_account_is_enabled (account); + is_enabled = tp_account_is_enabled (account); #ifndef HAVE_MOBLIN priv->enabled_checkbox = @@ -1373,7 +1429,7 @@ do_dispose (GObject *obj) if (priv->settings != NULL) { - EmpathyAccount *account; + TpAccount *account; account = empathy_account_settings_get_account (priv->settings); if (account != NULL) @@ -1386,6 +1442,12 @@ do_dispose (GObject *obj) priv->settings = NULL; } + if (priv->idle != NULL) + { + g_object_unref (priv->idle); + priv->idle = NULL; + } + if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL) G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj); } @@ -1494,6 +1556,11 @@ empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget) { EmpathyAccountWidgetPriv *priv = GET_PRIV (widget); + if (priv->creating_account && !priv->account_created) + /* We always want to warn the user if he's in the process of creating a + * new account which hasn't been actually created yet. */ + return TRUE; + return priv->contains_pending_changes; } diff --git a/libempathy-gtk/empathy-chat-text-view.c b/libempathy-gtk/empathy-chat-text-view.c index 5822a429d..de777f2fb 100644 --- a/libempathy-gtk/empathy-chat-text-view.c +++ b/libempathy-gtk/empathy-chat-text-view.c @@ -36,7 +36,6 @@ #include <telepathy-glib/util.h> #include <libempathy/empathy-utils.h> -#include <libempathy/empathy-account.h> #include "empathy-chat-text-view.h" #include "empathy-chat.h" diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index cfeb0073b..e96c02db2 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -34,9 +34,9 @@ #include <glib/gi18n-lib.h> #include <gtk/gtk.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-log-manager.h> #include <libempathy/empathy-contact-list.h> #include <libempathy/empathy-utils.h> @@ -64,7 +64,7 @@ #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat) typedef struct { EmpathyTpChat *tp_chat; - EmpathyAccount *account; + TpAccount *account; gchar *id; gchar *name; gchar *subject; @@ -72,9 +72,9 @@ typedef struct { gboolean show_contacts; EmpathyLogManager *log_manager; - EmpathyAccountManager *account_manager; - GSList *sent_messages; - gint sent_messages_index; + TpAccountManager *account_manager; + GList *input_history; + GList *input_history_current; GList *compositors; GCompletion *completion; guint composing_stop_timeout_id; @@ -94,6 +94,13 @@ typedef struct { GtkWidget *contact_list_view; } EmpathyChatPriv; +typedef struct { + gchar *text; /* Original message that was specified + * upon entry creation. */ + gchar *modified_text; /* Message that was modified by user. + * When no modifications were made, it is NULL */ +} InputHistoryEntry; + enum { COMPOSING, NEW_MESSAGE, @@ -196,15 +203,19 @@ chat_connect_channel_reconnected (EmpathyDispatchOperation *dispatch, } static void -chat_new_connection_cb (EmpathyAccountManager *manager, - TpConnection *connection, +chat_new_connection_cb (TpAccount *account, + guint old_status, + guint new_status, + guint reason, + gchar *dbus_error_name, + GHashTable *details, EmpathyChat *chat) { EmpathyChatPriv *priv = GET_PRIV (chat); - EmpathyAccount *account; + TpConnection *connection; + + connection = tp_account_get_connection (account); - 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)) { @@ -291,89 +302,280 @@ chat_composing_stop (EmpathyChat *chat) TP_CHANNEL_CHAT_STATE_ACTIVE); } +static gint +chat_input_history_entry_cmp (InputHistoryEntry *entry, + const gchar *text) +{ + if (!tp_strdiff (entry->text, text)) { + if (entry->modified_text != NULL) { + /* Modified entry and single string cannot be equal. */ + return 1; + } + return 0; + } + return 1; +} + +static InputHistoryEntry * +chat_input_history_entry_new_with_text (const gchar *text) +{ + InputHistoryEntry *entry; + entry = g_slice_new0 (InputHistoryEntry); + entry->text = g_strdup (text); + + return entry; +} + static void -chat_sent_message_add (EmpathyChat *chat, - const gchar *str) +chat_input_history_entry_free (InputHistoryEntry *entry) { - EmpathyChatPriv *priv; - GSList *list; - GSList *item; + g_free (entry->text); + g_free (entry->modified_text); + g_slice_free (InputHistoryEntry, entry); +} + +static void +chat_input_history_entry_revert (InputHistoryEntry *entry) +{ + g_free (entry->modified_text); + entry->modified_text = NULL; +} + +static void +chat_input_history_entry_update_text (InputHistoryEntry *entry, + const gchar *text) +{ + gchar *old; + + if (!tp_strdiff (text, entry->text)) { + g_free (entry->modified_text); + entry->modified_text = NULL; + return; + } + + old = entry->modified_text; + entry->modified_text = g_strdup (text); + g_free (old); +} + +static const gchar * +chat_input_history_entry_get_text (InputHistoryEntry *entry) +{ + if (entry == NULL) { + return NULL; + } + + if (entry->modified_text != NULL) { + return entry->modified_text; + } + return entry->text; +} + +static GList * +chat_input_history_remove_item (GList *list, + GList *item) +{ + list = g_list_remove_link (list, item); + chat_input_history_entry_free (item->data); + g_list_free_1 (item); + return list; +} + +static void +chat_input_history_revert (EmpathyChat *chat) +{ + EmpathyChatPriv *priv; + GList *list; + GList *item1; + GList *item2; + InputHistoryEntry *entry; priv = GET_PRIV (chat); + list = priv->input_history; - /* Save the sent message in our repeat buffer */ - list = priv->sent_messages; + if (list == NULL) { + DEBUG ("No input history"); + return; + } - /* Remove any other occurances of this msg */ - while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) { - list = g_slist_remove_link (list, item); - g_free (item->data); - g_slist_free1 (item); + /* Delete temporary entry */ + if (priv->input_history_current != NULL) { + item1 = list; + list = chat_input_history_remove_item (list, item1); + if (priv->input_history_current == item1) { + /* Removed temporary entry was current entry */ + priv->input_history = list; + priv->input_history_current = NULL; + return; + } + } + else { + /* There is no entry to revert */ + return; } - /* Trim the list to the last 10 items */ - while (g_slist_length (list) > 10) { - item = g_slist_last (list); - if (item) { - list = g_slist_remove_link (list, item); - g_free (item->data); - g_slist_free1 (item); + /* Restore the current history entry to original value */ + item1 = priv->input_history_current; + entry = item1->data; + chat_input_history_entry_revert (entry); + + /* Remove restored entry if there is other occurance before this entry */ + item2 = g_list_find_custom (list, chat_input_history_entry_get_text (entry), + (GCompareFunc) chat_input_history_entry_cmp); + if (item2 != item1) { + list = chat_input_history_remove_item (list, item1); + } + else { + /* Remove other occurance of the restored entry */ + item2 = g_list_find_custom (item1->next, + chat_input_history_entry_get_text (entry), + (GCompareFunc) chat_input_history_entry_cmp); + if (item2 != NULL) { + list = chat_input_history_remove_item (list, item2); } } - /* Add new message */ - list = g_slist_prepend (list, g_strdup (str)); + priv->input_history_current = NULL; + priv->input_history = list; +} - /* Set list and reset the index */ - priv->sent_messages = list; - priv->sent_messages_index = -1; +static void +chat_input_history_add (EmpathyChat *chat, + const gchar *str, + gboolean temporary) +{ + EmpathyChatPriv *priv; + GList *list; + GList *item; + InputHistoryEntry *entry; + + priv = GET_PRIV (chat); + + list = priv->input_history; + + /* Remove any other occurances of this entry, if not temporary */ + if (!temporary) { + while ((item = g_list_find_custom (list, str, + (GCompareFunc) chat_input_history_entry_cmp)) != NULL) { + list = chat_input_history_remove_item (list, item); + } + + /* Trim the list to the last 10 items */ + while (g_list_length (list) > 10) { + item = g_list_last (list); + if (item != NULL) { + list = chat_input_history_remove_item (list, item); + } + } + } + + + + /* Add new entry */ + entry = chat_input_history_entry_new_with_text (str); + list = g_list_prepend (list, entry); + + /* Set the list and the current item pointer */ + priv->input_history = list; + if (temporary) { + priv->input_history_current = list; + } + else { + priv->input_history_current = NULL; + } } static const gchar * -chat_sent_message_get_next (EmpathyChat *chat) +chat_input_history_get_next (EmpathyChat *chat) { EmpathyChatPriv *priv; - gint max; + GList *item; + const gchar *msg; priv = GET_PRIV (chat); - if (!priv->sent_messages) { - DEBUG ("No sent messages, next message is NULL"); + if (priv->input_history == NULL) { + DEBUG ("No input history, next entry is NULL"); return NULL; } + g_assert (priv->input_history_current != NULL); - max = g_slist_length (priv->sent_messages) - 1; - - if (priv->sent_messages_index < max) { - priv->sent_messages_index++; + if ((item = g_list_next (priv->input_history_current)) == NULL) + { + item = priv->input_history_current; } - DEBUG ("Returning next message index:%d", priv->sent_messages_index); + msg = chat_input_history_entry_get_text (item->data); + + DEBUG ("Returning next entry: '%s'", msg); - return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index); + priv->input_history_current = item; + + return msg; } static const gchar * -chat_sent_message_get_last (EmpathyChat *chat) +chat_input_history_get_prev (EmpathyChat *chat) { EmpathyChatPriv *priv; + GList *item; + const gchar *msg; g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL); priv = GET_PRIV (chat); - if (!priv->sent_messages) { - DEBUG ("No sent messages, last message is NULL"); + if (priv->input_history == NULL) { + DEBUG ("No input history, previous entry is NULL"); return NULL; } - if (priv->sent_messages_index >= 0) { - priv->sent_messages_index--; + if (priv->input_history_current == NULL) + { + return NULL; + } + else if ((item = g_list_previous (priv->input_history_current)) == NULL) + { + item = priv->input_history_current; } - DEBUG ("Returning last message index:%d", priv->sent_messages_index); + msg = chat_input_history_entry_get_text (item->data); - return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index); + DEBUG ("Returning previous entry: '%s'", msg); + + priv->input_history_current = item; + + return msg; +} + +static void +chat_input_history_update (EmpathyChat *chat, + GtkTextBuffer *buffer) +{ + EmpathyChatPriv *priv; + GtkTextIter start, end; + gchar *text; + InputHistoryEntry *entry; + + priv = GET_PRIV (chat); + + gtk_text_buffer_get_bounds (buffer, &start, &end); + text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); + + if (priv->input_history_current == NULL) { + /* Add the current text temporarily to the history */ + chat_input_history_add (chat, text, TRUE); + g_free (text); + return; + } + + /* Save the changes in the history */ + entry = priv->input_history_current->data; + if (tp_strdiff (chat_input_history_entry_get_text (entry), text)) { + chat_input_history_entry_update_text (entry, text); + } + + g_free (text); } static void @@ -680,7 +882,7 @@ chat_send (EmpathyChat *chat, priv = GET_PRIV (chat); - chat_sent_message_add (chat, msg); + chat_input_history_add (chat, msg, FALSE); if (msg[0] == '/') { gboolean second_slash = FALSE; @@ -754,6 +956,8 @@ chat_input_text_view_send (EmpathyChat *chat) /* clear the input field */ gtk_text_buffer_set_text (buffer, "", -1); + /* delete input history modifications */ + chat_input_history_revert (chat); chat_send (chat, msg); g_free (msg); @@ -1025,11 +1229,12 @@ chat_input_key_press_event_cb (GtkWidget *widget, const gchar *str; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view)); + chat_input_history_update (chat, buffer); if (event->keyval == GDK_Up) { - str = chat_sent_message_get_next (chat); + str = chat_input_history_get_next (chat); } else { - str = chat_sent_message_get_last (chat); + str = chat_input_history_get_prev (chat); } g_signal_handlers_block_by_func (buffer, @@ -1859,17 +2064,14 @@ chat_finalize (GObject *object) DEBUG ("Finalized: %p", object); - g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL); - g_slist_free (priv->sent_messages); + g_list_foreach (priv->input_history, (GFunc) chat_input_history_entry_free, NULL); + g_list_free (priv->input_history); g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL); g_list_free (priv->compositors); chat_composing_remove_timeout (chat); - g_signal_handlers_disconnect_by_func (priv->account_manager, - chat_new_connection_cb, object); - g_object_unref (priv->account_manager); g_object_unref (priv->log_manager); @@ -1947,7 +2149,7 @@ empathy_chat_class_init (EmpathyChatClass *klass) g_param_spec_object ("account", "Account of the chat", "The account of the chat", - EMPATHY_TYPE_ACCOUNT, + TP_TYPE_ACCOUNT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, @@ -2025,6 +2227,34 @@ chat_block_events_timeout_cb (gpointer data) } static void +account_manager_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + GList *accounts, *l; + TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyChat *chat = user_data; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (account_manager, result, &error)) { + DEBUG ("Failed to prepare the account manager: %s", error->message); + g_error_free (error); + return; + } + + accounts = tp_account_manager_get_valid_accounts (account_manager); + + for (l = accounts; l != NULL; l = l->next) { + TpAccount *account = l->data; + empathy_signal_connect_weak (account, "status-changed", + G_CALLBACK (chat_new_connection_cb), + G_OBJECT (chat)); + } + + g_list_free (accounts); +} + +static void empathy_chat_init (EmpathyChat *chat) { EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat, @@ -2033,14 +2263,12 @@ empathy_chat_init (EmpathyChat *chat) chat->priv = priv; priv->log_manager = empathy_log_manager_dup_singleton (); priv->contacts_width = -1; - priv->sent_messages = NULL; - priv->sent_messages_index = -1; - priv->account_manager = empathy_account_manager_dup_singleton (); + priv->input_history = NULL; + priv->input_history_current = NULL; + priv->account_manager = tp_account_manager_dup (); - g_signal_connect (priv->account_manager, - "new-connection", - G_CALLBACK (chat_new_connection_cb), - chat); + tp_account_manager_prepare_async (priv->account_manager, NULL, + account_manager_prepared_cb, chat); empathy_conf_get_bool (empathy_conf_get (), EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS, @@ -2096,10 +2324,7 @@ 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_for_connection ( - priv->account_manager, - connection); - g_object_ref (priv->account); + priv->account = g_object_ref (empathy_get_account_for_connection (connection)); g_signal_connect (tp_chat, "destroy", G_CALLBACK (chat_destroy_cb), @@ -2161,7 +2386,7 @@ empathy_chat_set_tp_chat (EmpathyChat *chat, show_pending_messages (chat); } -EmpathyAccount * +TpAccount * empathy_chat_get_account (EmpathyChat *chat) { EmpathyChatPriv *priv = GET_PRIV (chat); diff --git a/libempathy-gtk/empathy-chat.h b/libempathy-gtk/empathy-chat.h index c7158759a..9123d11dd 100644 --- a/libempathy-gtk/empathy-chat.h +++ b/libempathy-gtk/empathy-chat.h @@ -66,7 +66,7 @@ EmpathyChat * empathy_chat_new (EmpathyTpChat *tp_chat); EmpathyTpChat * empathy_chat_get_tp_chat (EmpathyChat *chat); void empathy_chat_set_tp_chat (EmpathyChat *chat, EmpathyTpChat *tp_chat); -EmpathyAccount * empathy_chat_get_account (EmpathyChat *chat); +TpAccount * empathy_chat_get_account (EmpathyChat *chat); const gchar * empathy_chat_get_id (EmpathyChat *chat); const gchar * empathy_chat_get_name (EmpathyChat *chat); const gchar * empathy_chat_get_subject (EmpathyChat *chat); diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 6c15dd876..b7108d8f3 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -27,8 +27,9 @@ #include <gtk/gtk.h> #include <glib/gi18n-lib.h> +#include <telepathy-glib/account-manager.h> + #include <libempathy/empathy-contact-manager.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-contact-list.h> #include <libempathy/empathy-utils.h> @@ -327,14 +328,14 @@ empathy_contact_personal_dialog_show (GtkWindow *parent) */ static gboolean -can_add_contact_to_account (EmpathyAccount *account, +can_add_contact_to_account (TpAccount *account, gpointer user_data) { EmpathyContactManager *contact_manager; TpConnection *connection; gboolean result; - connection = empathy_account_get_connection (account); + connection = tp_account_get_connection (account); if (connection == NULL) return FALSE; diff --git a/libempathy-gtk/empathy-contact-list-view.c b/libempathy-gtk/empathy-contact-list-view.c index a6623506b..c19ad32df 100644 --- a/libempathy-gtk/empathy-contact-list-view.c +++ b/libempathy-gtk/empathy-contact-list-view.c @@ -31,9 +31,9 @@ #include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-call-factory.h> #include <libempathy/empathy-tp-contact-factory.h> #include <libempathy/empathy-contact-list.h> @@ -244,9 +244,9 @@ contact_list_view_drag_data_received (GtkWidget *view, guint time_) { EmpathyContactListViewPriv *priv; - EmpathyAccountManager *account_manager; + TpAccountManager *account_manager; EmpathyTpContactFactory *factory = NULL; - EmpathyAccount *account = NULL; + TpAccount *account = NULL; GtkTreeModel *model; GtkTreeViewDropPosition position; GtkTreePath *path; @@ -298,17 +298,19 @@ contact_list_view_drag_data_received (GtkWidget *view, context->action == GDK_ACTION_COPY ? "copy" : "", id); - account_manager = empathy_account_manager_dup_singleton (); + /* FIXME: should probably make sure the account manager is prepared + * before calling _ensure_account on it. See bug 600115. */ + account_manager = tp_account_manager_dup (); strv = g_strsplit (id, ":", 2); if (g_strv_length (strv) == 2) { account_id = strv[0]; contact_id = strv[1]; - account = empathy_account_manager_get_account (account_manager, account_id); + account = tp_account_manager_ensure_account (account_manager, account_id); } if (account) { TpConnection *connection; - connection = empathy_account_get_connection (account); + connection = tp_account_get_connection (account); if (connection) { factory = empathy_tp_contact_factory_dup_singleton (connection); } @@ -458,7 +460,7 @@ contact_list_view_drag_data_get (GtkWidget *widget, GtkTreeIter iter; GtkTreeModel *model; EmpathyContact *contact; - EmpathyAccount *account; + TpAccount *account; const gchar *contact_id; const gchar *account_id; gchar *str; @@ -488,7 +490,7 @@ contact_list_view_drag_data_get (GtkWidget *widget, } account = empathy_contact_get_account (contact); - account_id = empathy_account_get_unique_name (account); + account_id = tp_proxy_get_object_path (account); contact_id = empathy_contact_get_id (contact); g_object_unref (contact); str = g_strconcat (account_id, ":", contact_id, NULL); diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c index 17bed7298..81e01ff0b 100644 --- a/libempathy-gtk/empathy-contact-widget.c +++ b/libempathy-gtk/empathy-contact-widget.c @@ -32,6 +32,7 @@ #include <champlain-gtk/champlain-gtk.h> #endif +#include <telepathy-glib/account.h> #include <telepathy-glib/util.h> #include <libempathy/empathy-tp-contact-factory.h> @@ -40,7 +41,6 @@ #include <libempathy/empathy-location.h> #include <libempathy/empathy-time.h> #include <libempathy/empathy-utils.h> -#include <libempathy/empathy-account.h> #include "empathy-contact-widget.h" #include "empathy-account-chooser.h" @@ -718,7 +718,7 @@ contact_widget_contact_setup (EmpathyContactWidget *information) static void contact_widget_contact_update (EmpathyContactWidget *information) { - EmpathyAccount *account = NULL; + TpAccount *account = NULL; const gchar *id = NULL; /* Connect and get info from new contact */ @@ -758,7 +758,7 @@ contact_widget_contact_update (EmpathyContactWidget *information) { const gchar *name; - name = empathy_account_get_display_name (account); + name = tp_account_get_display_name (account); gtk_label_set_label (GTK_LABEL (information->widget_account), name); } } diff --git a/libempathy-gtk/empathy-irc-network-dialog.c b/libempathy-gtk/empathy-irc-network-dialog.c index 8d4676417..69f83637d 100644 --- a/libempathy-gtk/empathy-irc-network-dialog.c +++ b/libempathy-gtk/empathy-irc-network-dialog.c @@ -28,7 +28,6 @@ #include <gtk/gtk.h> #include <libempathy/empathy-utils.h> -#include <libempathy/empathy-account.h> #include <libempathy/empathy-irc-network-manager.h> #include "empathy-ui-utils.h" diff --git a/libempathy-gtk/empathy-location-manager.c b/libempathy-gtk/empathy-location-manager.c index a00d6cb63..4ef27dba7 100644 --- a/libempathy-gtk/empathy-location-manager.c +++ b/libempathy-gtk/empathy-location-manager.c @@ -26,6 +26,7 @@ #include <glib/gi18n.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <geoclue/geoclue-master.h> @@ -35,7 +36,6 @@ #include "empathy-location-manager.h" #include "empathy-conf.h" -#include "libempathy/empathy-account-manager.h" #include "libempathy/empathy-enum-types.h" #include "libempathy/empathy-location.h" #include "libempathy/empathy-tp-contact-factory.h" @@ -63,7 +63,7 @@ typedef struct { GeoclueAddress *gc_address; gboolean reduce_accuracy; - EmpathyAccountManager *account_manager; + TpAccountManager *account_manager; /* The idle id for publish_on_idle func */ guint timeout_id; @@ -217,21 +217,57 @@ publish_location (EmpathyLocationManager *self, g_object_unref (factory); } +typedef struct +{ + EmpathyLocationManager *self; + gboolean force_publication; +} PublishToAllData; + +static void +publish_to_all_am_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + PublishToAllData *data = user_data; + GList *accounts, *l; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + goto out; + } + + accounts = tp_account_manager_get_valid_accounts (manager); + for (l = accounts; l; l = l->next) + { + TpConnection *conn = tp_account_get_connection (TP_ACCOUNT (l->data)); + + if (conn != NULL) + publish_location (data->self, conn, data->force_publication); + } + g_list_free (accounts); + +out: + g_object_unref (data->self); + g_slice_free (PublishToAllData, data); +} + static void publish_to_all_connections (EmpathyLocationManager *self, gboolean force_publication) { EmpathyLocationManagerPriv *priv = GET_PRIV (self); - GList *connections = NULL, *l; + PublishToAllData *data; - connections = empathy_account_manager_dup_connections (priv->account_manager); - for (l = connections; l; l = l->next) - { - publish_location (self, l->data, force_publication); - g_object_unref (l->data); - } - g_list_free (connections); + data = g_slice_new0 (PublishToAllData); + data->self = g_object_ref (self); + data->force_publication = force_publication; + tp_account_manager_prepare_async (priv->account_manager, NULL, + publish_to_all_am_prepared_cb, data); } static gboolean @@ -246,11 +282,19 @@ publish_on_idle (gpointer user_data) } static void -new_connection_cb (EmpathyAccountManager *manager, - TpConnection *conn, +new_connection_cb (TpAccount *account, + guint old_status, + guint new_status, + guint reason, + gchar *dbus_error_name, + GHashTable *details, gpointer *self) { EmpathyLocationManagerPriv *priv = GET_PRIV (self); + TpConnection *conn; + + conn = tp_account_get_connection (account); + DEBUG ("New connection %p", conn); /* Don't publish if it is already planned (ie startup) */ @@ -626,6 +670,34 @@ accuracy_cb (EmpathyConf *conf, } static void +account_manager_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + GList *accounts, *l; + TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyLocationManager *self = user_data; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (account_manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } + + accounts = tp_account_manager_get_valid_accounts (account_manager); + for (l = accounts; l != NULL; l = l->next) + { + TpAccount *account = TP_ACCOUNT (l->data); + + empathy_signal_connect_weak (account, "status-changed", + G_CALLBACK (new_connection_cb), G_OBJECT (self)); + } + g_list_free (accounts); +} + +static void empathy_location_manager_init (EmpathyLocationManager *self) { EmpathyConf *conf; @@ -638,10 +710,10 @@ empathy_location_manager_init (EmpathyLocationManager *self) g_free, (GDestroyNotify) tp_g_value_slice_free); /* Setup account status callbacks */ - priv->account_manager = empathy_account_manager_dup_singleton (); - g_signal_connect (priv->account_manager, - "new-connection", - G_CALLBACK (new_connection_cb), self); + priv->account_manager = tp_account_manager_dup (); + + tp_account_manager_prepare_async (priv->account_manager, NULL, + account_manager_prepared_cb, self); /* Setup settings status callbacks */ conf = empathy_conf_get (); diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index 11ddca74b..247a99806 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -30,8 +30,9 @@ #include <glib/gi18n-lib.h> #include <gtk/gtk.h> +#include <telepathy-glib/account-manager.h> + #include <libempathy/empathy-log-manager.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-chatroom-manager.h> #include <libempathy/empathy-chatroom.h> #include <libempathy/empathy-message.h> @@ -95,11 +96,11 @@ static void log_window_chats_setup (EmpathyLogWindow *wi static void log_window_chats_accounts_changed_cb (GtkWidget *combobox, EmpathyLogWindow *window); static void log_window_chats_set_selected (EmpathyLogWindow *window, - EmpathyAccount *account, + TpAccount *account, const gchar *chat_id, gboolean is_chatroom); static gboolean log_window_chats_get_selected (EmpathyLogWindow *window, - EmpathyAccount **account, + TpAccount **account, gchar **chat_id, gboolean *is_chatroom); static void log_window_chats_get_messages (EmpathyLogWindow *window, @@ -134,16 +135,45 @@ enum { COL_CHAT_COUNT }; +static void +account_manager_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyLogWindow *window = user_data; + guint account_num; + GList *accounts; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (account_manager, result, &error)) { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } + + accounts = tp_account_manager_get_valid_accounts (account_manager); + account_num = g_list_length (accounts); + g_list_free (accounts); + + if (account_num > 1) { + gtk_widget_show (window->vbox_chats); + gtk_widget_show (window->account_chooser_chats); + } else { + gtk_widget_hide (window->vbox_chats); + gtk_widget_hide (window->account_chooser_chats); + } +} + GtkWidget * -empathy_log_window_show (EmpathyAccount *account, +empathy_log_window_show (TpAccount *account, const gchar *chat_id, gboolean is_chatroom, GtkWindow *parent) { static EmpathyLogWindow *window = NULL; EmpathyAccountChooser *account_chooser; - EmpathyAccountManager *account_manager; - gint account_num; + TpAccountManager *account_manager; GtkBuilder *gui; gchar *filename; @@ -229,18 +259,11 @@ empathy_log_window_show (EmpathyAccount *account, window); /* Populate */ - account_manager = empathy_account_manager_dup_singleton (); - account_num = empathy_account_manager_get_count (account_manager); + account_manager = tp_account_manager_dup (); + tp_account_manager_prepare_async (account_manager, NULL, + account_manager_prepared_cb, window); g_object_unref (account_manager); - if (account_num > 1) { - gtk_widget_show (window->vbox_chats); - gtk_widget_show (window->account_chooser_chats); - } else { - gtk_widget_hide (window->vbox_chats); - gtk_widget_hide (window->account_chooser_chats); - } - /* Search List */ log_window_find_setup (window); @@ -302,7 +325,7 @@ log_window_find_changed_cb (GtkTreeSelection *selection, GtkTreeView *view; GtkTreeModel *model; GtkTreeIter iter; - EmpathyAccount *account; + TpAccount *account; gchar *chat_id; gboolean is_chatroom; gchar *date; @@ -418,8 +441,8 @@ 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_account_get_icon_name (hit->account); + account_name = tp_account_get_display_name (hit->account); + account_icon = tp_account_get_icon_name (hit->account); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, @@ -465,7 +488,7 @@ log_window_find_setup (EmpathyLogWindow *window) store = gtk_list_store_new (COL_FIND_COUNT, G_TYPE_STRING, /* account icon name */ G_TYPE_STRING, /* account name */ - EMPATHY_TYPE_ACCOUNT, /* account */ + TP_TYPE_ACCOUNT, /* account */ G_TYPE_STRING, /* chat name */ G_TYPE_STRING, /* chat id */ G_TYPE_BOOLEAN, /* is chatroom */ @@ -609,7 +632,7 @@ static void log_window_chats_populate (EmpathyLogWindow *window) { EmpathyAccountChooser *account_chooser; - EmpathyAccount *account; + TpAccount *account; GList *chats, *l; GtkTreeView *view; @@ -687,7 +710,7 @@ log_window_chats_setup (EmpathyLogWindow *window) store = gtk_list_store_new (COL_CHAT_COUNT, G_TYPE_STRING, /* icon */ G_TYPE_STRING, /* name */ - EMPATHY_TYPE_ACCOUNT, /* account */ + TP_TYPE_ACCOUNT, /* account */ G_TYPE_STRING, /* id */ G_TYPE_BOOLEAN); /* is chatroom */ @@ -740,7 +763,7 @@ log_window_chats_accounts_changed_cb (GtkWidget *combobox, static void log_window_chats_set_selected (EmpathyLogWindow *window, - EmpathyAccount *account, + TpAccount *account, const gchar *chat_id, gboolean is_chatroom) { @@ -764,7 +787,7 @@ log_window_chats_set_selected (EmpathyLogWindow *window, } for (ok = TRUE; ok; ok = gtk_tree_model_iter_next (model, &iter)) { - EmpathyAccount *this_account; + TpAccount *this_account; gchar *this_chat_id; gboolean this_is_chatroom; @@ -793,7 +816,7 @@ log_window_chats_set_selected (EmpathyLogWindow *window, static gboolean log_window_chats_get_selected (EmpathyLogWindow *window, - EmpathyAccount **account, + TpAccount **account, gchar **chat_id, gboolean *is_chatroom) { @@ -802,7 +825,7 @@ log_window_chats_get_selected (EmpathyLogWindow *window, GtkTreeSelection *selection; GtkTreeIter iter; gchar *id = NULL; - EmpathyAccount *acc = NULL; + TpAccount *acc = NULL; gboolean room = FALSE; view = GTK_TREE_VIEW (window->treeview_chats); @@ -840,7 +863,7 @@ static void log_window_chats_get_messages (EmpathyLogWindow *window, const gchar *date_to_show) { - EmpathyAccount *account; + TpAccount *account; gchar *chat_id; gboolean is_chatroom; EmpathyMessage *message; @@ -1000,7 +1023,7 @@ static void log_window_calendar_chats_month_changed_cb (GtkWidget *calendar, EmpathyLogWindow *window) { - EmpathyAccount *account; + TpAccount *account; gchar *chat_id; gboolean is_chatroom; guint year_selected; diff --git a/libempathy-gtk/empathy-log-window.h b/libempathy-gtk/empathy-log-window.h index 298d96099..def0d846b 100644 --- a/libempathy-gtk/empathy-log-window.h +++ b/libempathy-gtk/empathy-log-window.h @@ -25,11 +25,11 @@ #ifndef __EMPATHY_LOG_WINDOW_H__ #define __EMPATHY_LOG_WINDOW_H__ -#include <libempathy/empathy-account.h> +#include <telepathy-glib/account.h> G_BEGIN_DECLS -GtkWidget * empathy_log_window_show (EmpathyAccount *account, +GtkWidget * empathy_log_window_show (TpAccount *account, const gchar *chat_id, gboolean chatroom, GtkWindow *parent); diff --git a/libempathy-gtk/empathy-new-message-dialog.c b/libempathy-gtk/empathy-new-message-dialog.c index 66b2adb2d..c1069f879 100644 --- a/libempathy-gtk/empathy-new-message-dialog.c +++ b/libempathy-gtk/empathy-new-message-dialog.c @@ -32,7 +32,6 @@ #include <libempathy/empathy-contact-manager.h> #include <libempathy/empathy-dispatcher.h> #include <libempathy/empathy-utils.h> -#include <libempathy/empathy-account.h> #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT #include <libempathy/empathy-debug.h> @@ -100,23 +99,21 @@ new_message_dialog_account_changed_cb (GtkWidget *widget, while (members) { EmpathyContact *contact = members->data; - if (empathy_contact_is_online (contact)) { - DEBUG ("Adding contact ID %s, Name %s", - empathy_contact_get_id (contact), - empathy_contact_get_name (contact)); + DEBUG ("Adding contact ID %s, Name %s", + empathy_contact_get_id (contact), + empathy_contact_get_name (contact)); - tmpstr = g_strdup_printf ("%s (%s)", - empathy_contact_get_name (contact), - empathy_contact_get_id (contact)); + tmpstr = g_strdup_printf ("%s (%s)", + empathy_contact_get_name (contact), + empathy_contact_get_id (contact)); - gtk_list_store_insert_with_values (store, &iter, -1, - COMPLETION_COL_TEXT, tmpstr, - COMPLETION_COL_ID, empathy_contact_get_id (contact), - COMPLETION_COL_NAME, empathy_contact_get_name (contact), - -1); + gtk_list_store_insert_with_values (store, &iter, -1, + COMPLETION_COL_TEXT, tmpstr, + COMPLETION_COL_ID, empathy_contact_get_id (contact), + COMPLETION_COL_NAME, empathy_contact_get_name (contact), + -1); - g_free (tmpstr); - } + g_free (tmpstr); g_object_unref (contact); members = g_list_delete_link (members, members); diff --git a/libempathy-gtk/empathy-presence-chooser.c b/libempathy-gtk/empathy-presence-chooser.c index 7113c77fd..678ec835c 100644 --- a/libempathy-gtk/empathy-presence-chooser.c +++ b/libempathy-gtk/empathy-presence-chooser.c @@ -33,13 +33,13 @@ #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <libempathy/empathy-connectivity.h> #include <libempathy/empathy-idle.h> #include <libempathy/empathy-utils.h> #include <libempathy/empathy-status-presets.h> -#include <libempathy/empathy-account-manager.h> #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include <libempathy/empathy-debug.h> @@ -114,7 +114,7 @@ typedef struct { TpConnectionPresenceType flash_state_2; guint flash_timeout_id; - EmpathyAccountManager *account_manager; + TpAccountManager *account_manager; } EmpathyPresenceChooserPriv; /* States to be listed in the menu. @@ -715,21 +715,32 @@ presence_chooser_entry_focus_out_cb (EmpathyPresenceChooser *chooser, } static void -presence_chooser_update_sensitivity (EmpathyPresenceChooser *chooser) +update_sensitivity_am_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyPresenceChooser *chooser = user_data; EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser); gboolean sensitive = FALSE; GList *accounts, *l; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (manager, result, &error)) { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } - accounts = empathy_account_manager_dup_accounts (priv->account_manager); + accounts = tp_account_manager_get_valid_accounts (manager); for (l = accounts ; l != NULL ; l = g_list_next (l)) { - EmpathyAccount *a = EMPATHY_ACCOUNT (l->data); + TpAccount *a = TP_ACCOUNT (l->data); - if (empathy_account_is_enabled (a)) + if (tp_account_is_enabled (a)) { sensitive = TRUE; - - g_object_unref (a); + break; + } } g_list_free (accounts); @@ -741,9 +752,29 @@ presence_chooser_update_sensitivity (EmpathyPresenceChooser *chooser) } static void +presence_chooser_update_sensitivity (EmpathyPresenceChooser *chooser) +{ + EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser); + + tp_account_manager_prepare_async (priv->account_manager, NULL, + update_sensitivity_am_prepared_cb, + chooser); +} + +static void +presence_chooser_account_manager_account_validity_changed_cb ( + TpAccountManager *manager, + TpAccount *account, + gboolean valid, + EmpathyPresenceChooser *chooser) +{ + presence_chooser_update_sensitivity (chooser); +} + +static void presence_chooser_account_manager_account_changed_cb ( - EmpathyAccountManager *manager, - EmpathyAccount *account, + TpAccountManager *manager, + TpAccount *account, EmpathyPresenceChooser *chooser) { presence_chooser_update_sensitivity (chooser); @@ -825,12 +856,12 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser) G_CALLBACK (presence_chooser_presence_changed_cb), chooser); - priv->account_manager = empathy_account_manager_dup_singleton (); + priv->account_manager = tp_account_manager_dup (); - empathy_signal_connect_weak (priv->account_manager, "account-created", - G_CALLBACK (presence_chooser_account_manager_account_changed_cb), + empathy_signal_connect_weak (priv->account_manager, "account-validity-changed", + G_CALLBACK (presence_chooser_account_manager_account_validity_changed_cb), G_OBJECT (chooser)); - empathy_signal_connect_weak (priv->account_manager, "account-deleted", + empathy_signal_connect_weak (priv->account_manager, "account-removed", G_CALLBACK (presence_chooser_account_manager_account_changed_cb), G_OBJECT (chooser)); empathy_signal_connect_weak (priv->account_manager, "account-enabled", diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index fcf95ca02..a41cbd6c0 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -441,7 +441,7 @@ theme_adium_append_message (EmpathyChatView *view, EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view); EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); EmpathyContact *sender; - EmpathyAccount *account; + TpAccount *account; gchar *dup_body = NULL; const gchar *body; const gchar *name; @@ -467,9 +467,9 @@ theme_adium_append_message (EmpathyChatView *view, sender = empathy_message_get_sender (msg); account = empathy_contact_get_account (sender); service_name = empathy_protocol_name_to_display_name - (empathy_account_get_protocol (account)); + (tp_account_get_protocol (account)); if (service_name == NULL) - service_name = empathy_account_get_protocol (account); + service_name = tp_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/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 39baeaf41..486301cb1 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -35,7 +35,6 @@ #include <gtk/gtk.h> #include <libempathy/empathy-contact.h> -#include <libempathy/empathy-account.h> #include <libempathy/empathy-ft-handler.h> #include "empathy-chat-view.h" |