* Authors: Xavier Claessens <xclaesse@gmail.com>
*/
+#include "config.h"
#include "empathy-presence-manager.h"
-#include <config.h>
-
-#include <string.h>
-
-#include <glib/gi18n-lib.h>
-#include <dbus/dbus-glib.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/dbus.h>
-#include <telepathy-glib/util.h>
+#include <tp-account-widgets/tpaw-utils.h>
#include "empathy-utils.h"
-#include "empathy-connectivity.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include "empathy-debug.h"
struct _EmpathyPresenceManagerPrivate
{
DBusGProxy *gs_proxy;
- EmpathyConnectivity *connectivity;
gboolean ready;
gboolean auto_away;
TpConnectionPresenceType away_saved_state;
- TpConnectionPresenceType saved_state;
- gchar *saved_status;
gboolean is_idle;
guint ext_away_timeout;
static EmpathyPresenceManager * singleton = NULL;
-static const gchar *presence_type_to_status[NUM_TP_CONNECTION_PRESENCE_TYPES] =
+static const gchar *presence_type_to_status[TP_NUM_CONNECTION_PRESENCE_TYPES] =
{
NULL,
"offline",
g_free (self->priv->status);
self->priv->state = state;
- if (EMP_STR_EMPTY (status_message))
+ if (TPAW_STR_EMPTY (status_message))
self->priv->status = NULL;
else
self->priv->status = g_strdup (status_message);
is_idle ? "yes" : "no");
if (!self->priv->auto_away ||
- (self->priv->saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
- (self->priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
- self->priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN)))
+ (self->priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
+ self->priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN))
{
/* We don't want to go auto away OR we explicitely asked to be
* offline, nothing to do here */
ext_away_start (self);
- if (self->priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET)
- /* We are disconnected, when coming back from away
- * we want to restore the presence before the
- * disconnection. */
- self->priv->away_saved_state = self->priv->saved_state;
- else
- self->priv->away_saved_state = self->priv->state;
+ self->priv->away_saved_state = self->priv->state;
new_state = TP_CONNECTION_PRESENCE_TYPE_AWAY;
if (self->priv->state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY)
self->priv->is_idle = is_idle;
}
-static void
-state_change_cb (EmpathyConnectivity *connectivity,
- gboolean new_online,
- EmpathyPresenceManager *self)
-{
- if (!new_online)
- {
- /* We are no longer connected */
- DEBUG ("Disconnected: Save state %d (%s)",
- self->priv->state, self->priv->status);
- self->priv->saved_state = self->priv->state;
- g_free (self->priv->saved_status);
- self->priv->saved_status = g_strdup (self->priv->status);
- empathy_presence_manager_set_state (self,
- TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
- }
- else if (new_online
- && self->priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET)
- {
- /* We are now connected */
- DEBUG ("Reconnected: Restore state %d (%s)",
- self->priv->saved_state, self->priv->saved_status);
- empathy_presence_manager_set_presence (self,
- self->priv->saved_state,
- self->priv->saved_status);
- self->priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
- g_free (self->priv->saved_status);
- self->priv->saved_status = NULL;
- }
-}
-
static void
presence_manager_dispose (GObject *object)
{
tp_clear_object (&self->priv->gs_proxy);
tp_clear_object (&self->priv->manager);
- tp_clear_object (&self->priv->connectivity);
tp_clear_pointer (&self->priv->connect_times, g_hash_table_unref);
next_away_stop (EMPATHY_PRESENCE_MANAGER (object));
g_object_class_install_property (object_class,
PROP_STATE,
g_param_spec_uint ("state", "state", "state",
- 0, NUM_TP_CONNECTION_PRESENCE_TYPES,
+ 0, TP_NUM_CONNECTION_PRESENCE_TYPES,
TP_CONNECTION_PRESENCE_TYPE_UNSET,
G_PARAM_READWRITE));
self->priv->ready = TRUE;
- if (!tp_account_manager_prepare_finish (account_manager, result, &error))
+ if (!tp_proxy_prepare_finish (account_manager, result, &error))
{
DEBUG ("Failed to prepare account manager: %s", error->message);
g_error_free (error);
most_available_presence_changed (account_manager, state, status,
status_message, self);
- accounts = tp_account_manager_get_valid_accounts (self->priv->manager);
+ accounts = tp_account_manager_dup_valid_accounts (self->priv->manager);
for (l = accounts; l != NULL; l = l->next)
{
tp_g_signal_connect_object (l->data, "status-changed",
G_CALLBACK (account_status_changed_cb), self, 0);
}
- g_list_free (accounts);
+ g_list_free_full (accounts, g_object_unref);
g_free (status);
g_free (status_message);
self->priv->manager = tp_account_manager_dup ();
- tp_account_manager_prepare_async (self->priv->manager, NULL,
+ tp_proxy_prepare_async (self->priv->manager, NULL,
account_manager_ready_cb, self);
tp_g_signal_connect_object (self->priv->manager,
g_object_unref (dbus);
- self->priv->connectivity = empathy_connectivity_dup_singleton ();
-
- tp_g_signal_connect_object (self->priv->connectivity,
- "state-change", G_CALLBACK (state_change_cb), self, 0);
-
self->priv->connect_times = g_hash_table_new (g_direct_hash, g_direct_equal);
}
{
const gchar *status;
- g_assert (status_type > 0 && status_type < NUM_TP_CONNECTION_PRESENCE_TYPES);
+ g_assert (status_type > 0 && status_type < TP_NUM_CONNECTION_PRESENCE_TYPES);
status = presence_type_to_status[status_type];
if (!tp_strdiff (status, default_status))
status = NULL;
- if (state != TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
- !empathy_connectivity_is_online (self->priv->connectivity))
- {
- DEBUG ("Empathy is not online");
-
- self->priv->saved_state = state;
- if (tp_strdiff (self->priv->status, status))
- {
- g_free (self->priv->saved_status);
- self->priv->saved_status = NULL;
- if (!EMP_STR_EMPTY (status))
- self->priv->saved_status = g_strdup (status);
- }
- return;
- }
-
empathy_presence_manager_do_set_presence (self, state, status);
}