diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2008-01-25 00:33:33 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2008-01-25 00:33:33 +0800 |
commit | a687b7c513d3bb967781f17dc5d247161bcffd8c (patch) | |
tree | 116b335b3c4fe96ddd09c64e9aa382516168af03 /libempathy | |
parent | ff21a5f6bfedae8ca32ac871ccad5c106e831b28 (diff) | |
download | gsoc2013-empathy-a687b7c513d3bb967781f17dc5d247161bcffd8c.tar gsoc2013-empathy-a687b7c513d3bb967781f17dc5d247161bcffd8c.tar.gz gsoc2013-empathy-a687b7c513d3bb967781f17dc5d247161bcffd8c.tar.bz2 gsoc2013-empathy-a687b7c513d3bb967781f17dc5d247161bcffd8c.tar.lz gsoc2013-empathy-a687b7c513d3bb967781f17dc5d247161bcffd8c.tar.xz gsoc2013-empathy-a687b7c513d3bb967781f17dc5d247161bcffd8c.tar.zst gsoc2013-empathy-a687b7c513d3bb967781f17dc5d247161bcffd8c.zip |
Remove EmpathyPresence object and have "presence" and "presence-message" properties directly in EmpathyContact
svn path=/trunk/; revision=601
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/Makefile.am | 2 | ||||
-rw-r--r-- | libempathy/empathy-contact.c | 108 | ||||
-rw-r--r-- | libempathy/empathy-contact.h | 9 | ||||
-rw-r--r-- | libempathy/empathy-idle.c | 4 | ||||
-rw-r--r-- | libempathy/empathy-presence.c | 339 | ||||
-rw-r--r-- | libempathy/empathy-presence.h | 67 | ||||
-rw-r--r-- | libempathy/empathy-status-presets.c | 6 | ||||
-rw-r--r-- | libempathy/empathy-status-presets.h | 2 | ||||
-rw-r--r-- | libempathy/empathy-tp-contact-factory.c | 47 | ||||
-rw-r--r-- | libempathy/empathy-utils.c | 71 | ||||
-rw-r--r-- | libempathy/empathy-utils.h | 3 |
11 files changed, 166 insertions, 492 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 285dff185..3c87db37c 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -18,7 +18,6 @@ lib_LTLIBRARIES = libempathy.la libempathy_la_SOURCES = \ empathy-avatar.c \ empathy-time.c \ - empathy-presence.c \ empathy-status-presets.c \ empathy-debug.c \ empathy-utils.c \ @@ -55,7 +54,6 @@ libempathy_la_LDFLAGS = \ libempathy_headers = \ empathy-avatar.h \ empathy-time.h \ - empathy-presence.h \ empathy-status-presets.h \ empathy-debug.h \ empathy-utils.h \ diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index 76cab2a6e..70025c7b0 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -29,6 +29,8 @@ #include <glib/gi18n.h> +#include <telepathy-glib/util.h> + #include "empathy-contact.h" #include "empathy-utils.h" #include "empathy-debug.h" @@ -45,7 +47,8 @@ struct _EmpathyContactPriv { gchar *name; EmpathyAvatar *avatar; McAccount *account; - EmpathyPresence *presence; + McPresence presence; + gchar *presence_message; guint handle; EmpathyCapabilities capabilities; gboolean is_user; @@ -72,6 +75,7 @@ enum { PROP_AVATAR, PROP_ACCOUNT, PROP_PRESENCE, + PROP_PRESENCE_MESSAGE, PROP_GROUPS, PROP_SUBSCRIPTION, PROP_HANDLE, @@ -124,13 +128,22 @@ empathy_contact_class_init (EmpathyContactClass *class) g_object_class_install_property (object_class, PROP_PRESENCE, - g_param_spec_object ("presence", - "Contact presence", - "Presence of contact", - EMPATHY_TYPE_PRESENCE, - G_PARAM_READWRITE)); + g_param_spec_uint ("presence", + "Contact presence", + "Presence of contact", + MC_PRESENCE_UNSET, + LAST_MC_PRESENCE, + MC_PRESENCE_UNSET, + G_PARAM_READWRITE)); g_object_class_install_property (object_class, + PROP_PRESENCE_MESSAGE, + g_param_spec_string ("presence-message", + "Contact presence message", + "Presence message of contact", + NULL, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_HANDLE, g_param_spec_uint ("handle", "Contact Handle", @@ -176,15 +189,12 @@ contact_finalize (GObject *object) g_free (priv->name); g_free (priv->id); + g_free (priv->presence_message); if (priv->avatar) { empathy_avatar_unref (priv->avatar); } - if (priv->presence) { - g_object_unref (priv->presence); - } - if (priv->account) { g_object_unref (priv->account); } @@ -218,7 +228,10 @@ contact_get_property (GObject *object, g_value_set_object (value, priv->account); break; case PROP_PRESENCE: - g_value_set_object (value, priv->presence); + g_value_set_uint (value, priv->presence); + break; + case PROP_PRESENCE_MESSAGE: + g_value_set_string (value, priv->presence_message); break; case PROP_HANDLE: g_value_set_uint (value, priv->handle); @@ -264,7 +277,11 @@ contact_set_property (GObject *object, break; case PROP_PRESENCE: empathy_contact_set_presence (EMPATHY_CONTACT (object), - EMPATHY_PRESENCE (g_value_get_object (value))); + g_value_get_uint (value)); + break; + case PROP_PRESENCE_MESSAGE: + empathy_contact_set_presence_message (EMPATHY_CONTACT (object), + g_value_get_string (value)); break; case PROP_HANDLE: empathy_contact_set_handle (EMPATHY_CONTACT (object), @@ -451,12 +468,12 @@ empathy_contact_set_account (EmpathyContact *contact, g_object_notify (G_OBJECT (contact), "account"); } -EmpathyPresence * +McPresence empathy_contact_get_presence (EmpathyContact *contact) { EmpathyContactPriv *priv; - g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), MC_PRESENCE_UNSET); priv = GET_PRIV (contact); @@ -464,8 +481,8 @@ empathy_contact_get_presence (EmpathyContact *contact) } void -empathy_contact_set_presence (EmpathyContact *contact, - EmpathyPresence *presence) +empathy_contact_set_presence (EmpathyContact *contact, + McPresence presence) { EmpathyContactPriv *priv; @@ -477,16 +494,39 @@ empathy_contact_set_presence (EmpathyContact *contact, return; } - if (priv->presence) { - g_object_unref (priv->presence); - priv->presence = NULL; - } + priv->presence = presence; + + g_object_notify (G_OBJECT (contact), "presence"); +} + +const gchar * +empathy_contact_get_presence_message (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; - if (presence) { - priv->presence = g_object_ref (presence); + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + + priv = GET_PRIV (contact); + + return priv->presence_message; +} + +void +empathy_contact_set_presence_message (EmpathyContact *contact, + const gchar *message) +{ + EmpathyContactPriv *priv = GET_PRIV (contact); + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + if (!tp_strdiff (message, priv->presence_message)) { + return; } - g_object_notify (G_OBJECT (contact), "presence"); + g_free (priv->presence_message); + priv->presence_message = g_strdup (message); + + g_object_notify (G_OBJECT (contact), "presence-message"); } guint @@ -591,11 +631,7 @@ empathy_contact_is_online (EmpathyContact *contact) priv = GET_PRIV (contact); - if (!priv->presence) { - return FALSE; - } - - return (empathy_presence_get_state (priv->presence) > MC_PRESENCE_OFFLINE); + return (priv->presence > MC_PRESENCE_OFFLINE); } const gchar * @@ -607,21 +643,11 @@ empathy_contact_get_status (EmpathyContact *contact) priv = GET_PRIV (contact); - if (priv->presence) { - const gchar *status; - - status = empathy_presence_get_status (priv->presence); - if (!status) { - McPresence state; - - state = empathy_presence_get_state (priv->presence); - status = empathy_presence_state_get_default_status (state); - } - - return status; + if (priv->presence_message) { + return priv->presence_message; } - return empathy_presence_state_get_default_status (MC_PRESENCE_OFFLINE); + return empathy_presence_get_default_message (priv->presence); } gboolean diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h index b5a3c1ec9..57a72c906 100644 --- a/libempathy/empathy-contact.h +++ b/libempathy/empathy-contact.h @@ -29,9 +29,9 @@ #include <glib-object.h> #include <libmissioncontrol/mc-account.h> +#include <libmissioncontrol/mission-control.h> #include "empathy-avatar.h" -#include "empathy-presence.h" G_BEGIN_DECLS @@ -75,9 +75,12 @@ void empathy_contact_set_avatar (EmpathyContact *con McAccount * empathy_contact_get_account (EmpathyContact *contact); void empathy_contact_set_account (EmpathyContact *contact, McAccount *account); -EmpathyPresence * empathy_contact_get_presence (EmpathyContact *contact); +McPresence empathy_contact_get_presence (EmpathyContact *contact); void empathy_contact_set_presence (EmpathyContact *contact, - EmpathyPresence *presence); + McPresence presence); +const gchar * empathy_contact_get_presence_message (EmpathyContact *contact); +void empathy_contact_set_presence_message (EmpathyContact *contact, + const gchar *message); guint empathy_contact_get_handle (EmpathyContact *contact); void empathy_contact_set_handle (EmpathyContact *contact, guint handle); diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 2f811a622..0f23037bd 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -345,7 +345,7 @@ empathy_idle_get_status (EmpathyIdle *idle) priv = GET_PRIV (idle); if (!priv->status) { - return empathy_presence_state_get_default_status (priv->state); + return empathy_presence_get_default_message (priv->state); } return priv->status; @@ -407,7 +407,7 @@ empathy_idle_set_presence (EmpathyIdle *idle, } /* Do not set translated default messages */ - default_status = empathy_presence_state_get_default_status (state); + default_status = empathy_presence_get_default_message (state); if (status && strcmp (status, default_status) == 0) { status = NULL; } diff --git a/libempathy/empathy-presence.c b/libempathy/empathy-presence.c deleted file mode 100644 index b7beb3900..000000000 --- a/libempathy/empathy-presence.c +++ /dev/null @@ -1,339 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004-2007 Imendio AB - * - * 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. - * - * Authors: Mikael Hallendal <micke@imendio.com> - */ - -#include "config.h" - -#include <string.h> - -#include <glib/gi18n.h> - -#include <libmissioncontrol/mc-enum-types.h> - -#include "empathy-presence.h" -#include "empathy-time.h" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_PRESENCE, EmpathyPresencePriv)) - -typedef struct _EmpathyPresencePriv EmpathyPresencePriv; - -struct _EmpathyPresencePriv { - McPresence state; - gchar *status; - time_t timestamp; -}; - -static void presence_finalize (GObject *object); -static void presence_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void presence_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -enum { - PROP_0, - PROP_STATE, - PROP_STATUS -}; - -G_DEFINE_TYPE (EmpathyPresence, empathy_presence, G_TYPE_OBJECT); - -static void -empathy_presence_class_init (EmpathyPresenceClass *class) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (class); - - object_class->finalize = presence_finalize; - object_class->get_property = presence_get_property; - object_class->set_property = presence_set_property; - - g_object_class_install_property (object_class, - PROP_STATE, - g_param_spec_enum ("state", - "Presence State", - "The current state of the presence", - MC_TYPE_PRESENCE, - MC_PRESENCE_AVAILABLE, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_STATUS, - g_param_spec_string ("status", - "Presence Status", - "Status string set on presence", - NULL, - G_PARAM_READWRITE)); - - g_type_class_add_private (object_class, sizeof (EmpathyPresencePriv)); -} - -static void -empathy_presence_init (EmpathyPresence *presence) -{ - EmpathyPresencePriv *priv; - - priv = GET_PRIV (presence); - - priv->state = MC_PRESENCE_AVAILABLE; - priv->status = NULL; - priv->timestamp = empathy_time_get_current (); -} - -static void -presence_finalize (GObject *object) -{ - EmpathyPresencePriv *priv; - - priv = GET_PRIV (object); - - g_free (priv->status); - - (G_OBJECT_CLASS (empathy_presence_parent_class)->finalize) (object); -} - -static void -presence_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - EmpathyPresencePriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_STATE: - g_value_set_enum (value, priv->state); - break; - case PROP_STATUS: - g_value_set_string (value, - empathy_presence_get_status (EMPATHY_PRESENCE (object))); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} -static void -presence_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - EmpathyPresencePriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_STATE: - priv->state = g_value_get_enum (value); - break; - case PROP_STATUS: - empathy_presence_set_status (EMPATHY_PRESENCE (object), - g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -EmpathyPresence * -empathy_presence_new (void) -{ - return g_object_new (EMPATHY_TYPE_PRESENCE, NULL); -} - -EmpathyPresence * -empathy_presence_new_full (McPresence state, - const gchar *status) -{ - return g_object_new (EMPATHY_TYPE_PRESENCE, - "state", state, - "status", status, - NULL); -} - -const gchar * -empathy_presence_get_status (EmpathyPresence *presence) -{ - EmpathyPresencePriv *priv; - - g_return_val_if_fail (EMPATHY_IS_PRESENCE (presence), - _("Offline")); - - priv = GET_PRIV (presence); - - return priv->status; -} - -McPresence -empathy_presence_get_state (EmpathyPresence *presence) -{ - EmpathyPresencePriv *priv; - - g_return_val_if_fail (EMPATHY_IS_PRESENCE (presence), - MC_PRESENCE_AVAILABLE); - - priv = GET_PRIV (presence); - - return priv->state; -} - -void -empathy_presence_set_state (EmpathyPresence *presence, - McPresence state) -{ - EmpathyPresencePriv *priv; - - g_return_if_fail (EMPATHY_IS_PRESENCE (presence)); - - priv = GET_PRIV (presence); - - priv->state = state; - - g_object_notify (G_OBJECT (presence), "state"); -} - -void -empathy_presence_set_status (EmpathyPresence *presence, - const gchar *status) -{ - EmpathyPresencePriv *priv; - - priv = GET_PRIV (presence); - g_return_if_fail (EMPATHY_IS_PRESENCE (presence)); - - g_free (priv->status); - - if (status) { - priv->status = g_strdup (status); - } else { - priv->status = NULL; - } - - g_object_notify (G_OBJECT (presence), "status"); -} - -gint -empathy_presence_sort_func (gconstpointer a, - gconstpointer b) -{ - EmpathyPresencePriv *priv_a; - EmpathyPresencePriv *priv_b; - gint diff; - - g_return_val_if_fail (EMPATHY_IS_PRESENCE (a), 0); - g_return_val_if_fail (EMPATHY_IS_PRESENCE (b), 0); - - priv_a = GET_PRIV (a); - priv_b = GET_PRIV (b); - - /* 1. State */ - diff = priv_a->state - priv_b->state; - if (diff != 0) { - return diff < 1 ? -1 : +1; - } - - /* 3. Time (newest first) */ - diff = priv_b->timestamp - priv_a->timestamp; - if (diff != 0) { - return diff < 1 ? -1 : +1; - } - - /* No real difference */ - return 0; -} - -const gchar * -empathy_presence_state_get_default_status (McPresence state) -{ - switch (state) { - case MC_PRESENCE_AVAILABLE: - return _("Available"); - case MC_PRESENCE_DO_NOT_DISTURB: - return _("Busy"); - case MC_PRESENCE_AWAY: - case MC_PRESENCE_EXTENDED_AWAY: - return _("Away"); - case MC_PRESENCE_HIDDEN: - return _("Hidden"); - case MC_PRESENCE_OFFLINE: - case MC_PRESENCE_UNSET: - return _("Offline"); - default: - g_assert_not_reached (); - } - - return NULL; -} - -const gchar * -empathy_presence_state_to_str (McPresence state) -{ - switch (state) { - case MC_PRESENCE_AVAILABLE: - return "available"; - case MC_PRESENCE_DO_NOT_DISTURB: - return "busy"; - case MC_PRESENCE_AWAY: - return "away"; - case MC_PRESENCE_EXTENDED_AWAY: - return "ext_away"; - case MC_PRESENCE_HIDDEN: - return "hidden"; - case MC_PRESENCE_OFFLINE: - return "offline"; - case MC_PRESENCE_UNSET: - return "unset"; - default: - g_assert_not_reached (); - } - - return NULL; -} - -McPresence -empathy_presence_state_from_str (const gchar *str) -{ - if (strcmp (str, "available") == 0) { - return MC_PRESENCE_AVAILABLE; - } else if ((strcmp (str, "dnd") == 0) || (strcmp (str, "busy") == 0)) { - return MC_PRESENCE_DO_NOT_DISTURB; - } else if ((strcmp (str, "away") == 0) || (strcmp (str, "brb") == 0)) { - return MC_PRESENCE_AWAY; - } else if ((strcmp (str, "xa") == 0) || (strcmp (str, "ext_away") == 0)) { - return MC_PRESENCE_EXTENDED_AWAY; - } else if (strcmp (str, "hidden") == 0) { - return MC_PRESENCE_HIDDEN; - } else if (strcmp (str, "offline") == 0) { - return MC_PRESENCE_OFFLINE; - } else if (strcmp (str, "unset") == 0) { - return MC_PRESENCE_UNSET; - } - - return MC_PRESENCE_AVAILABLE; -} - diff --git a/libempathy/empathy-presence.h b/libempathy/empathy-presence.h deleted file mode 100644 index 940bf9ca6..000000000 --- a/libempathy/empathy-presence.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004 Imendio AB - * - * 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. - */ - -#ifndef __EMPATHY_PRESENCE_H__ -#define __EMPATHY_PRESENCE_H__ - -#include <glib-object.h> -#include <libmissioncontrol/mission-control.h> - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_PRESENCE (empathy_presence_get_type ()) -#define EMPATHY_PRESENCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_PRESENCE, EmpathyPresence)) -#define EMPATHY_PRESENCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_PRESENCE, EmpathyPresenceClass)) -#define EMPATHY_IS_PRESENCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_PRESENCE)) -#define EMPATHY_IS_PRESENCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_PRESENCE)) -#define EMPATHY_PRESENCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_PRESENCE, EmpathyPresenceClass)) - -typedef struct _EmpathyPresence EmpathyPresence; -typedef struct _EmpathyPresenceClass EmpathyPresenceClass; - -struct _EmpathyPresence { - GObject parent; -}; - -struct _EmpathyPresenceClass { - GObjectClass parent_class; -}; - -GType empathy_presence_get_type (void) G_GNUC_CONST; - -EmpathyPresence * empathy_presence_new (void); -EmpathyPresence * empathy_presence_new_full (McPresence state, - const gchar *status); -McPresence empathy_presence_get_state (EmpathyPresence *presence); -const gchar * empathy_presence_get_status (EmpathyPresence *presence); -void empathy_presence_set_state (EmpathyPresence *presence, - McPresence state); -void empathy_presence_set_status (EmpathyPresence *presence, - const gchar *status); -gint empathy_presence_sort_func (gconstpointer a, - gconstpointer b); -const gchar * empathy_presence_state_get_default_status (McPresence state); -const gchar * empathy_presence_state_to_str (McPresence state); -McPresence empathy_presence_state_from_str (const gchar *str); - -G_END_DECLS - -#endif /* __EMPATHY_PRESENCE_H__ */ - diff --git a/libempathy/empathy-status-presets.c b/libempathy/empathy-status-presets.c index 54f7b629c..89b1874f3 100644 --- a/libempathy/empathy-status-presets.c +++ b/libempathy/empathy-status-presets.c @@ -130,7 +130,7 @@ status_presets_file_parse (const gchar *filename) state_str = (gchar *) xmlGetProp (node, "presence"); if (state_str) { - state = empathy_presence_state_from_str (state_str); + state = empathy_presence_from_str (state_str); if (is_default) { empathy_debug (DEBUG_DOMAIN, @@ -215,7 +215,7 @@ status_presets_file_save (void) xmlNodePtr subnode; xmlChar *state; - state = (gchar*) empathy_presence_state_to_str (default_preset->state); + state = (gchar*) empathy_presence_to_str (default_preset->state); subnode = xmlNewTextChild (root, NULL, "default", default_preset->status); @@ -228,7 +228,7 @@ status_presets_file_save (void) xmlChar *state; sp = l->data; - state = (gchar*) empathy_presence_state_to_str (sp->state); + state = (gchar*) empathy_presence_to_str (sp->state); count[sp->state]++; if (count[sp->state] > STATUS_PRESETS_MAX_EACH) { diff --git a/libempathy/empathy-status-presets.h b/libempathy/empathy-status-presets.h index 68f3cea56..06b6c7912 100644 --- a/libempathy/empathy-status-presets.h +++ b/libempathy/empathy-status-presets.h @@ -23,7 +23,7 @@ #ifndef __EMPATHY_STATUS_PRESETS_H__ #define __EMPATHY_STATUS_PRESETS_H__ -#include "empathy-presence.h" +#include <libmissioncontrol/mission-control.h> G_BEGIN_DECLS diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c index f71a91014..14d2640da 100644 --- a/libempathy/empathy-tp-contact-factory.c +++ b/libempathy/empathy-tp-contact-factory.c @@ -109,30 +109,19 @@ tp_contact_factory_weak_notify (gpointer data, } static void -tp_contact_factory_presences_table_foreach (const gchar *state_str, - GHashTable *presences_table, - EmpathyPresence **presence) +tp_contact_factory_presences_table_foreach (const gchar *state_str, + GHashTable *presences_table, + EmpathyContact *contact) { - McPresence state; const GValue *message; - state = empathy_presence_state_from_str (state_str); - if (state == MC_PRESENCE_UNSET) { - return; - } - - if (*presence) { - g_object_unref (*presence); - *presence = NULL; - } - - *presence = empathy_presence_new (); - empathy_presence_set_state (*presence, state); - + empathy_contact_set_presence (contact, + empathy_presence_from_str (state_str)); + message = g_hash_table_lookup (presences_table, "message"); if (message != NULL) { - empathy_presence_set_status (*presence, - g_value_get_string (message)); + empathy_contact_set_presence_message (contact, + g_value_get_string (message)); } } @@ -143,7 +132,6 @@ tp_contact_factory_parse_presence_foreach (guint handle, { GHashTable *presences_table; EmpathyContact *contact; - EmpathyPresence *presence = NULL; contact = tp_contact_factory_find_by_handle (tp_factory, handle); if (!contact) { @@ -154,16 +142,13 @@ tp_contact_factory_parse_presence_foreach (guint handle, g_hash_table_foreach (presences_table, (GHFunc) tp_contact_factory_presences_table_foreach, - &presence); + contact); empathy_debug (DEBUG_DOMAIN, "Changing presence for contact %s (%d) to %s (%d)", empathy_contact_get_id (contact), handle, - presence ? empathy_presence_get_status (presence) : "unset", - presence ? empathy_presence_get_state (presence) : MC_PRESENCE_UNSET); - - empathy_contact_set_presence (contact, presence); - g_object_unref (presence); + empathy_contact_get_presence_message (contact), + empathy_contact_get_presence (contact)); } static void @@ -699,7 +684,7 @@ tp_contact_factory_disconnect_contact_foreach (gpointer data, { EmpathyContact *contact = data; - empathy_contact_set_presence (contact, NULL); + empathy_contact_set_presence (contact, MC_PRESENCE_UNSET); empathy_contact_set_handle (contact, 0); } @@ -910,15 +895,9 @@ tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory, priv->contacts = g_list_prepend (priv->contacts, contact); if (!priv->presence_iface) { - EmpathyPresence *presence; - /* We have no presence iface, set default presence * to available */ - presence = empathy_presence_new_full (MC_PRESENCE_AVAILABLE, - NULL); - - empathy_contact_set_presence (contact, presence); - g_object_unref (presence); + empathy_contact_set_presence (contact, MC_PRESENCE_AVAILABLE); } empathy_debug (DEBUG_DOMAIN, "Contact added: %s (%d)", diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 4050f4673..c810f9cca 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -485,3 +485,74 @@ empathy_chat_with_contact_id (McAccount *account, const gchar *contact_id) g_object_unref (mc); } + +const gchar * +empathy_presence_get_default_message (McPresence presence) +{ + switch (presence) { + case MC_PRESENCE_AVAILABLE: + return _("Available"); + case MC_PRESENCE_DO_NOT_DISTURB: + return _("Busy"); + case MC_PRESENCE_AWAY: + case MC_PRESENCE_EXTENDED_AWAY: + return _("Away"); + case MC_PRESENCE_HIDDEN: + return _("Hidden"); + case MC_PRESENCE_OFFLINE: + case MC_PRESENCE_UNSET: + return _("Offline"); + default: + g_assert_not_reached (); + } + + return NULL; +} + +const gchar * +empathy_presence_to_str (McPresence presence) +{ + switch (presence) { + case MC_PRESENCE_AVAILABLE: + return "available"; + case MC_PRESENCE_DO_NOT_DISTURB: + return "busy"; + case MC_PRESENCE_AWAY: + return "away"; + case MC_PRESENCE_EXTENDED_AWAY: + return "ext_away"; + case MC_PRESENCE_HIDDEN: + return "hidden"; + case MC_PRESENCE_OFFLINE: + return "offline"; + case MC_PRESENCE_UNSET: + return "unset"; + default: + g_assert_not_reached (); + } + + return NULL; +} + +McPresence +empathy_presence_from_str (const gchar *str) +{ + if (strcmp (str, "available") == 0) { + return MC_PRESENCE_AVAILABLE; + } else if ((strcmp (str, "dnd") == 0) || (strcmp (str, "busy") == 0)) { + return MC_PRESENCE_DO_NOT_DISTURB; + } else if ((strcmp (str, "away") == 0) || (strcmp (str, "brb") == 0)) { + return MC_PRESENCE_AWAY; + } else if ((strcmp (str, "xa") == 0) || (strcmp (str, "ext_away") == 0)) { + return MC_PRESENCE_EXTENDED_AWAY; + } else if (strcmp (str, "hidden") == 0) { + return MC_PRESENCE_HIDDEN; + } else if (strcmp (str, "offline") == 0) { + return MC_PRESENCE_OFFLINE; + } else if (strcmp (str, "unset") == 0) { + return MC_PRESENCE_UNSET; + } + + return MC_PRESENCE_AVAILABLE; +} + diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 1f3700d22..875128c1e 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -92,6 +92,9 @@ void empathy_call_contact (EmpathyContact *contact); void empathy_chat_with_contact (EmpathyContact *contact); void empathy_chat_with_contact_id (McAccount *account, const gchar *contact_id); +const gchar * empathy_presence_get_default_message (McPresence presence); +const gchar * empathy_presence_to_str (McPresence presence); +McPresence empathy_presence_from_str (const gchar *str); G_END_DECLS |