diff options
author | Pierre-Luc Beaudoin <pierre-luc@pierlux.com> | 2008-12-02 11:14:20 -0500 |
---|---|---|
committer | Pierre-Luc Beaudoin <pierre-luc@pierlux.com> | 2009-05-07 13:37:01 -0400 |
commit | b643c127ad280dee6669578f1f79f7fd9fe868a1 (patch) | |
tree | 2f844c50ce166fe92890c6daf771d81fc3a8aa49 | |
parent | 80c31561d6d867ccbfaa2aa53f4bfdff1dc631c1 (diff) |
Add Location to EmpathyContact
-rw-r--r-- | libempathy/Makefile.am | 1 | ||||
-rw-r--r-- | libempathy/empathy-contact.c | 60 | ||||
-rw-r--r-- | libempathy/empathy-contact.h | 4 | ||||
-rw-r--r-- | libempathy/empathy-location.h | 55 |
4 files changed, 120 insertions, 0 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 67966695..3122342c 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -83,6 +83,7 @@ libempathy_headers = \ empathy-irc-network.h \ empathy-irc-network-manager.h \ empathy-irc-server.h \ + empathy-location.h \ empathy-log-manager.h \ empathy-log-store.h \ empathy-log-store-empathy.h \ diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index fe8cf823..3663a0a9 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -50,6 +50,7 @@ typedef struct { EmpathyCapabilities capabilities; gboolean is_user; guint hash; + GHashTable *location; } EmpathyContactPriv; static void contact_finalize (GObject *object); @@ -73,6 +74,7 @@ enum PROP_HANDLE, PROP_CAPABILITIES, PROP_IS_USER, + PROP_LOCATION }; enum { @@ -225,6 +227,15 @@ empathy_contact_class_init (EmpathyContactClass *class) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, + PROP_LOCATION, + g_param_spec_boxed ("location", + "Contact location", + "Physical location of the contact", + G_TYPE_HASH_TABLE, + G_PARAM_READABLE)); + signals[PRESENCE_CHANGED] = g_signal_new ("presence-changed", G_TYPE_FROM_CLASS (class), @@ -246,6 +257,10 @@ empathy_contact_init (EmpathyContact *contact) EMPATHY_TYPE_CONTACT, EmpathyContactPriv); contact->priv = priv; + + priv->location = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) tp_g_value_slice_free); } static void @@ -1001,3 +1016,48 @@ empathy_avatar_save_to_file (EmpathyAvatar *self, return g_file_set_contents (filename, self->data, self->len, error); } +/** + * empathy_contact_get_location: + * @contact: the contact + * + * Returns the user's location if available. The keys are defined in + * empathy-location.h. If the contact doesn't have location + * information, the GHashTable will be empthy. + * + * Returns: a #GHashTable of location values + */ +GHashTable * +empathy_contact_get_location (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_CONTACT (contact), NULL); + + priv = GET_PRIV (contact); + + return priv->location; +} + +/** + * empathy_contact_set_location: + * @contact: the contact + * @location: the location + * + * Sets the user's location based on the location #GHashTable passed. + */ +void +empathy_contact_set_location (EmpathyContact *contact, + GHashTable *location) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_CONTACT (contact)); + g_return_if_fail (location != NULL); + + priv = GET_PRIV (contact); + + g_hash_table_unref (priv->location); + + priv->location = g_hash_table_ref (location); + g_object_notify (G_OBJECT (contact), "location"); +} diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h index c10561d0..fecb9664 100644 --- a/libempathy/empathy-contact.h +++ b/libempathy/empathy-contact.h @@ -119,6 +119,10 @@ void empathy_avatar_unref (EmpathyAvatar *avatar); gboolean empathy_avatar_save_to_file (EmpathyAvatar *avatar, const gchar *filename, GError **error); +GHashTable * empathy_contact_get_location (EmpathyContact *contact); +void empathy_contact_set_location (EmpathyContact *contact, + GHashTable *location); + G_END_DECLS #endif /* __EMPATHY_CONTACT_H__ */ diff --git a/libempathy/empathy-location.h b/libempathy/empathy-location.h new file mode 100644 index 00000000..a43e2d38 --- /dev/null +++ b/libempathy/empathy-location.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Pierre-Luc Beaudoin <pierre-luc.beaudoin@collabora.co.uk> + */ + +#ifndef __EMPATHY_LOCATION_H__ +#define __EMPATHY_LOCATION_H__ + +#include <glib.h> + +G_BEGIN_DECLS + +#define EMPATHY_LOCATION_COUNTRY_CODE "countrycode" +#define EMPATHY_LOCATION_COUNTRY "country" +#define EMPATHY_LOCATION_REGION "region" +#define EMPATHY_LOCATION_LOCALITY "locality" +#define EMPATHY_LOCATION_AREA "area" +#define EMPATHY_LOCATION_POSTAL_CODE "postalcode" +#define EMPATHY_LOCATION_STREET "street" +#define EMPATHY_LOCATION_BUILDING "building" +#define EMPATHY_LOCATION_FLOOR "floor" +#define EMPATHY_LOCATION_ROOM "room" +#define EMPATHY_LOCATION_TEXT "text" +#define EMPATHY_LOCATION_DESCRIPTION "description" +#define EMPATHY_LOCATION_URI "uri" +#define EMPATHY_LOCATION_LAT "lat" +#define EMPATHY_LOCATION_LON "lon" +#define EMPATHY_LOCATION_ALT "alt" +#define EMPATHY_LOCATION_ACCURACY_LEVEL "accuracy-level" +#define EMPATHY_LOCATION_ERROR "error" +#define EMPATHY_LOCATION_VERTICAL_ERROR_M "vertical-error-m" +#define EMPATHY_LOCATION_HORIZONTAL_ERROR_M "horizontal-error-m" +#define EMPATHY_LOCATION_SPEED "speed" +#define EMPATHY_LOCATION_BEARING "bearing" +#define EMPATHY_LOCATION_CLIMB "climb" +#define EMPATHY_LOCATION_TIMESTAMP "timestamp" + +G_END_DECLS + +#endif /* __EMPATHY_LOCATION_H__ */ |