diff options
author | Guillaume Desmottes <gdesmott@gnome.org> | 2008-01-25 05:23:09 +0800 |
---|---|---|
committer | Guillaume Desmottes <gdesmott@gnome.org> | 2008-01-25 05:23:09 +0800 |
commit | e1a2ac951fec7ef11aaeaf3da6b62c036b2be7e9 (patch) | |
tree | 7523f8ac52a5fd7b958d55f9f6533c6add0ace11 /libempathy | |
parent | 915e5f6d71da5ce14b2462f2db850c90be7546bf (diff) | |
parent | ec3abba0aee010621b096c854851938d9501b3fd (diff) | |
download | gsoc2013-empathy-e1a2ac951fec7ef11aaeaf3da6b62c036b2be7e9.tar gsoc2013-empathy-e1a2ac951fec7ef11aaeaf3da6b62c036b2be7e9.tar.gz gsoc2013-empathy-e1a2ac951fec7ef11aaeaf3da6b62c036b2be7e9.tar.bz2 gsoc2013-empathy-e1a2ac951fec7ef11aaeaf3da6b62c036b2be7e9.tar.lz gsoc2013-empathy-e1a2ac951fec7ef11aaeaf3da6b62c036b2be7e9.tar.xz gsoc2013-empathy-e1a2ac951fec7ef11aaeaf3da6b62c036b2be7e9.tar.zst gsoc2013-empathy-e1a2ac951fec7ef11aaeaf3da6b62c036b2be7e9.zip |
Merge branch 'master' into irc
Conflicts:
docs/libempathy/libempathy-docs.sgml
docs/libempathy/libempathy.types
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/Makefile.am | 10 | ||||
-rw-r--r-- | libempathy/empathy-conf.c | 372 | ||||
-rw-r--r-- | libempathy/empathy-conf.h | 87 | ||||
-rw-r--r-- | libempathy/empathy-contact-groups.c | 285 | ||||
-rw-r--r-- | libempathy/empathy-contact-groups.dtd | 17 | ||||
-rw-r--r-- | libempathy/empathy-contact-groups.h | 38 | ||||
-rw-r--r-- | libempathy/empathy-contact-list.c | 2 | ||||
-rw-r--r-- | libempathy/empathy-contact.c | 108 | ||||
-rw-r--r-- | libempathy/empathy-contact.h | 9 | ||||
-rw-r--r-- | libempathy/empathy-idle.c | 41 | ||||
-rw-r--r-- | libempathy/empathy-log-manager.c | 22 | ||||
-rw-r--r-- | libempathy/empathy-presence.c | 339 | ||||
-rw-r--r-- | libempathy/empathy-presence.h | 67 | ||||
-rw-r--r-- | libempathy/empathy-status-presets.c | 407 | ||||
-rw-r--r-- | libempathy/empathy-status-presets.dtd | 14 | ||||
-rw-r--r-- | libempathy/empathy-status-presets.h | 46 | ||||
-rw-r--r-- | libempathy/empathy-time.h | 2 | ||||
-rw-r--r-- | libempathy/empathy-tp-contact-factory.c | 47 | ||||
-rw-r--r-- | libempathy/empathy-tp-contact-list.c | 21 | ||||
-rw-r--r-- | libempathy/empathy-tp-group.c | 21 | ||||
-rw-r--r-- | libempathy/empathy-utils.c | 79 | ||||
-rw-r--r-- | libempathy/empathy-utils.h | 3 |
22 files changed, 1057 insertions, 980 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 4bb6fbf2a..9ec10b3b4 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -16,16 +16,16 @@ BUILT_SOURCES = \ lib_LTLIBRARIES = libempathy.la libempathy_la_SOURCES = \ - empathy-conf.c \ empathy-avatar.c \ empathy-time.c \ - empathy-presence.c \ + empathy-status-presets.c \ empathy-debug.c \ empathy-utils.c \ empathy-message.c \ empathy-chatroom-manager.c \ empathy-chatroom.c \ empathy-contact.c \ + empathy-contact-groups.c \ empathy-contact-list.c \ empathy-contact-manager.c \ empathy-contact-factory.c \ @@ -55,16 +55,16 @@ libempathy_la_LDFLAGS = \ -version-info ${LIBEMPATHY_CURRENT}:${LIBEMPATHY_REVISION}:${LIBEMPATHY_AGE} libempathy_headers = \ - empathy-conf.h \ empathy-avatar.h \ empathy-time.h \ - empathy-presence.h \ + empathy-status-presets.h \ empathy-debug.h \ empathy-utils.h \ empathy-message.h \ empathy-chatroom-manager.h \ empathy-chatroom.h \ empathy-contact.h \ + empathy-contact-groups.h \ empathy-contact-list.h \ empathy-contact-manager.h \ empathy-contact-factory.h \ @@ -145,6 +145,8 @@ empathy-enum-types.c: $(libempathy_headers) Makefile dtddir = $(datadir)/empathy dtd_DATA = \ + empathy-status-presets.dtd \ + empathy-contact-groups.dtd \ empathy-chatroom-manager.dtd stylesheetdir = $(datadir)/empathy diff --git a/libempathy/empathy-conf.c b/libempathy/empathy-conf.c deleted file mode 100644 index 71e520f72..000000000 --- a/libempathy/empathy-conf.c +++ /dev/null @@ -1,372 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2006 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: Richard Hult <richard@imendio.com> - */ - -#include "config.h" - -#include <string.h> - -#include <gconf/gconf-client.h> - -#include "empathy-conf.h" -#include "empathy-debug.h" - -#define DEBUG_DOMAIN "Config" - -#define EMPATHY_CONF_ROOT "/apps/empathy" -#define DESKTOP_INTERFACE_ROOT "/desktop/gnome/interface" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONF, EmpathyConfPriv)) - -typedef struct { - GConfClient *gconf_client; -} EmpathyConfPriv; - -typedef struct { - EmpathyConf *conf; - EmpathyConfNotifyFunc func; - gpointer user_data; -} EmpathyConfNotifyData; - -static void conf_finalize (GObject *object); - -G_DEFINE_TYPE (EmpathyConf, empathy_conf, G_TYPE_OBJECT); - -static EmpathyConf *global_conf = NULL; - -static void -empathy_conf_class_init (EmpathyConfClass *class) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (class); - - object_class->finalize = conf_finalize; - - g_type_class_add_private (object_class, sizeof (EmpathyConfPriv)); -} - -static void -empathy_conf_init (EmpathyConf *conf) -{ - EmpathyConfPriv *priv; - - priv = GET_PRIV (conf); - - priv->gconf_client = gconf_client_get_default (); - - gconf_client_add_dir (priv->gconf_client, - EMPATHY_CONF_ROOT, - GCONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - gconf_client_add_dir (priv->gconf_client, - DESKTOP_INTERFACE_ROOT, - GCONF_CLIENT_PRELOAD_NONE, - NULL); -} - -static void -conf_finalize (GObject *object) -{ - EmpathyConfPriv *priv; - - priv = GET_PRIV (object); - - gconf_client_remove_dir (priv->gconf_client, - EMPATHY_CONF_ROOT, - NULL); - gconf_client_remove_dir (priv->gconf_client, - DESKTOP_INTERFACE_ROOT, - NULL); - - g_object_unref (priv->gconf_client); - - G_OBJECT_CLASS (empathy_conf_parent_class)->finalize (object); -} - -EmpathyConf * -empathy_conf_get (void) -{ - if (!global_conf) { - global_conf = g_object_new (EMPATHY_TYPE_CONF, NULL); - } - - return global_conf; -} - -void -empathy_conf_shutdown (void) -{ - if (global_conf) { - g_object_unref (global_conf); - global_conf = NULL; - } -} - -gboolean -empathy_conf_set_int (EmpathyConf *conf, - const gchar *key, - gint value) -{ - EmpathyConfPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - - empathy_debug (DEBUG_DOMAIN, "Setting int:'%s' to %d", key, value); - - priv = GET_PRIV (conf); - - return gconf_client_set_int (priv->gconf_client, - key, - value, - NULL); -} - -gboolean -empathy_conf_get_int (EmpathyConf *conf, - const gchar *key, - gint *value) -{ - EmpathyConfPriv *priv; - GError *error = NULL; - - *value = 0; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - priv = GET_PRIV (conf); - - *value = gconf_client_get_int (priv->gconf_client, - key, - &error); - - if (error) { - g_error_free (error); - return FALSE; - } - - return TRUE; -} - -gboolean -empathy_conf_set_bool (EmpathyConf *conf, - const gchar *key, - gboolean value) -{ - EmpathyConfPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - - empathy_debug (DEBUG_DOMAIN, "Setting bool:'%s' to %d ---> %s", - key, value, value ? "true" : "false"); - - priv = GET_PRIV (conf); - - return gconf_client_set_bool (priv->gconf_client, - key, - value, - NULL); -} - -gboolean -empathy_conf_get_bool (EmpathyConf *conf, - const gchar *key, - gboolean *value) -{ - EmpathyConfPriv *priv; - GError *error = NULL; - - *value = FALSE; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - priv = GET_PRIV (conf); - - *value = gconf_client_get_bool (priv->gconf_client, - key, - &error); - - if (error) { - g_error_free (error); - return FALSE; - } - - return TRUE; -} - -gboolean -empathy_conf_set_string (EmpathyConf *conf, - const gchar *key, - const gchar *value) -{ - EmpathyConfPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - - empathy_debug (DEBUG_DOMAIN, "Setting string:'%s' to '%s'", - key, value); - - priv = GET_PRIV (conf); - - return gconf_client_set_string (priv->gconf_client, - key, - value, - NULL); -} - -gboolean -empathy_conf_get_string (EmpathyConf *conf, - const gchar *key, - gchar **value) -{ - EmpathyConfPriv *priv; - GError *error = NULL; - - *value = NULL; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - - priv = GET_PRIV (conf); - - *value = gconf_client_get_string (priv->gconf_client, - key, - &error); - - if (error) { - g_error_free (error); - return FALSE; - } - - return TRUE; -} - -gboolean -empathy_conf_set_string_list (EmpathyConf *conf, - const gchar *key, - GSList *value) -{ - EmpathyConfPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - - priv = GET_PRIV (conf); - - return gconf_client_set_list (priv->gconf_client, - key, - GCONF_VALUE_STRING, - value, - NULL); -} - -gboolean -empathy_conf_get_string_list (EmpathyConf *conf, - const gchar *key, - GSList **value) -{ - EmpathyConfPriv *priv; - GError *error = NULL; - - *value = NULL; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - - priv = GET_PRIV (conf); - - *value = gconf_client_get_list (priv->gconf_client, - key, - GCONF_VALUE_STRING, - &error); - if (error) { - g_error_free (error); - return FALSE; - } - - return TRUE; -} - -static void -conf_notify_data_free (EmpathyConfNotifyData *data) -{ - g_object_unref (data->conf); - g_slice_free (EmpathyConfNotifyData, data); -} - -static void -conf_notify_func (GConfClient *client, - guint id, - GConfEntry *entry, - gpointer user_data) -{ - EmpathyConfNotifyData *data; - - data = user_data; - - data->func (data->conf, - gconf_entry_get_key (entry), - data->user_data); -} - -guint -empathy_conf_notify_add (EmpathyConf *conf, - const gchar *key, - EmpathyConfNotifyFunc func, - gpointer user_data) -{ - EmpathyConfPriv *priv; - guint id; - EmpathyConfNotifyData *data; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), 0); - - priv = GET_PRIV (conf); - - data = g_slice_new (EmpathyConfNotifyData); - data->func = func; - data->user_data = user_data; - data->conf = g_object_ref (conf); - - id = gconf_client_notify_add (priv->gconf_client, - key, - conf_notify_func, - data, - (GFreeFunc) conf_notify_data_free, - NULL); - - return id; -} - -gboolean -empathy_conf_notify_remove (EmpathyConf *conf, - guint id) -{ - EmpathyConfPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); - - priv = GET_PRIV (conf); - - gconf_client_notify_remove (priv->gconf_client, id); - - return TRUE; -} - diff --git a/libempathy/empathy-conf.h b/libempathy/empathy-conf.h deleted file mode 100644 index 7e8e60e25..000000000 --- a/libempathy/empathy-conf.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2006 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_CONF_H__ -#define __EMPATHY_CONF_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_CONF (empathy_conf_get_type ()) -#define EMPATHY_CONF(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CONF, EmpathyConf)) -#define EMPATHY_CONF_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_CONF, EmpathyConfClass)) -#define EMPATHY_IS_CONF(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CONF)) -#define EMPATHY_IS_CONF_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CONF)) -#define EMPATHY_CONF_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CONF, EmpathyConfClass)) - -typedef struct _EmpathyConf EmpathyConf; -typedef struct _EmpathyConfClass EmpathyConfClass; - -struct _EmpathyConf { - GObject parent; -}; - -struct _EmpathyConfClass { - GObjectClass parent_class; -}; - -typedef void (*EmpathyConfNotifyFunc) (EmpathyConf *conf, - const gchar *key, - gpointer user_data); - -GType empathy_conf_get_type (void) G_GNUC_CONST; -EmpathyConf *empathy_conf_get (void); -void empathy_conf_shutdown (void); -guint empathy_conf_notify_add (EmpathyConf *conf, - const gchar *key, - EmpathyConfNotifyFunc func, - gpointer data); -gboolean empathy_conf_notify_remove (EmpathyConf *conf, - guint id); -gboolean empathy_conf_set_int (EmpathyConf *conf, - const gchar *key, - gint value); -gboolean empathy_conf_get_int (EmpathyConf *conf, - const gchar *key, - gint *value); -gboolean empathy_conf_set_bool (EmpathyConf *conf, - const gchar *key, - gboolean value); -gboolean empathy_conf_get_bool (EmpathyConf *conf, - const gchar *key, - gboolean *value); -gboolean empathy_conf_set_string (EmpathyConf *conf, - const gchar *key, - const gchar *value); -gboolean empathy_conf_get_string (EmpathyConf *conf, - const gchar *key, - gchar **value); -gboolean empathy_conf_set_string_list (EmpathyConf *conf, - const gchar *key, - GSList *value); -gboolean empathy_conf_get_string_list (EmpathyConf *conf, - const gchar *key, - GSList **value); - -G_END_DECLS - -#endif /* __EMPATHY_CONF_H__ */ - diff --git a/libempathy/empathy-contact-groups.c b/libempathy/empathy-contact-groups.c new file mode 100644 index 000000000..b71cf6642 --- /dev/null +++ b/libempathy/empathy-contact-groups.c @@ -0,0 +1,285 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2005-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: Martyn Russell <martyn@imendio.com> + */ + +#include "config.h" + +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <glib.h> +#include <glib/gi18n.h> + +#include <libxml/parser.h> +#include <libxml/tree.h> + +#include "empathy-debug.h" +#include "empathy-utils.h" +#include "empathy-contact-groups.h" + +#define DEBUG_DOMAIN "ContactGroups" + +#define CONTACT_GROUPS_XML_FILENAME "contact-groups.xml" +#define CONTACT_GROUPS_DTD_FILENAME "empathy-contact-groups.dtd" + +typedef struct { + gchar *name; + gboolean expanded; +} ContactGroup; + +static void contact_groups_file_parse (const gchar *filename); +static gboolean contact_groups_file_save (void); +static ContactGroup *contact_group_new (const gchar *name, + gboolean expanded); +static void contact_group_free (ContactGroup *group); + +static GList *groups = NULL; + +void +empathy_contact_groups_get_all (void) +{ + gchar *dir; + gchar *file_with_path; + + /* If already set up clean up first */ + if (groups) { + g_list_foreach (groups, (GFunc)contact_group_free, NULL); + g_list_free (groups); + groups = NULL; + } + + dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + file_with_path = g_build_filename (dir, CONTACT_GROUPS_XML_FILENAME, NULL); + g_free (dir); + + if (g_file_test (file_with_path, G_FILE_TEST_EXISTS)) { + contact_groups_file_parse (file_with_path); + } + + g_free (file_with_path); +} + +static void +contact_groups_file_parse (const gchar *filename) +{ + xmlParserCtxtPtr ctxt; + xmlDocPtr doc; + xmlNodePtr contacts; + xmlNodePtr account; + xmlNodePtr node; + + empathy_debug (DEBUG_DOMAIN, "Attempting to parse file:'%s'...", filename); + + ctxt = xmlNewParserCtxt (); + + /* Parse and validate the file. */ + doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); + if (!doc) { + g_warning ("Failed to parse file:'%s'", filename); + xmlFreeParserCtxt (ctxt); + return; + } + + if (!empathy_xml_validate (doc, CONTACT_GROUPS_DTD_FILENAME)) { + g_warning ("Failed to validate file:'%s'", filename); + xmlFreeDoc(doc); + xmlFreeParserCtxt (ctxt); + return; + } + + /* The root node, contacts. */ + contacts = xmlDocGetRootElement (doc); + + account = NULL; + node = contacts->children; + while (node) { + if (strcmp ((gchar *) node->name, "account") == 0) { + account = node; + break; + } + node = node->next; + } + + node = NULL; + if (account) { + node = account->children; + } + + while (node) { + if (strcmp ((gchar *) node->name, "group") == 0) { + gchar *name; + gchar *expanded_str; + gboolean expanded; + ContactGroup *contact_group; + + name = (gchar *) xmlGetProp (node, "name"); + expanded_str = (gchar *) xmlGetProp (node, "expanded"); + + if (expanded_str && strcmp (expanded_str, "yes") == 0) { + expanded = TRUE; + } else { + expanded = FALSE; + } + + contact_group = contact_group_new (name, expanded); + groups = g_list_append (groups, contact_group); + + xmlFree (name); + xmlFree (expanded_str); + } + + node = node->next; + } + + empathy_debug (DEBUG_DOMAIN, "Parsed %d contact groups", g_list_length (groups)); + + xmlFreeDoc(doc); + xmlFreeParserCtxt (ctxt); +} + +static ContactGroup * +contact_group_new (const gchar *name, + gboolean expanded) +{ + ContactGroup *group; + + group = g_new0 (ContactGroup, 1); + + group->name = g_strdup (name); + group->expanded = expanded; + + return group; +} + +static void +contact_group_free (ContactGroup *group) +{ + g_return_if_fail (group != NULL); + + g_free (group->name); + + g_free (group); +} + +static gboolean +contact_groups_file_save (void) +{ + xmlDocPtr doc; + xmlNodePtr root; + xmlNodePtr node; + GList *l; + gchar *dir; + gchar *file; + + dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); + file = g_build_filename (dir, CONTACT_GROUPS_XML_FILENAME, NULL); + g_free (dir); + + doc = xmlNewDoc ("1.0"); + root = xmlNewNode (NULL, "contacts"); + xmlDocSetRootElement (doc, root); + + node = xmlNewChild (root, NULL, "account", NULL); + xmlNewProp (node, "name", "Default"); + + for (l = groups; l; l = l->next) { + ContactGroup *cg; + xmlNodePtr subnode; + + cg = l->data; + + subnode = xmlNewChild (node, NULL, "group", NULL); + xmlNewProp (subnode, "expanded", cg->expanded ? "yes" : "no"); + xmlNewProp (subnode, "name", cg->name); + } + + /* Make sure the XML is indented properly */ + xmlIndentTreeOutput = 1; + + empathy_debug (DEBUG_DOMAIN, "Saving file:'%s'", file); + xmlSaveFormatFileEnc (file, doc, "utf-8", 1); + xmlFreeDoc (doc); + + xmlCleanupParser (); + xmlMemoryDump (); + + g_free (file); + + return TRUE; +} + +gboolean +empathy_contact_group_get_expanded (const gchar *group) +{ + GList *l; + gboolean default_val = TRUE; + + g_return_val_if_fail (group != NULL, default_val); + + for (l = groups; l; l = l->next) { + ContactGroup *cg = l->data; + + if (!cg || !cg->name) { + continue; + } + + if (strcmp (cg->name, group) == 0) { + return cg->expanded; + } + } + + return default_val; +} + +void +empathy_contact_group_set_expanded (const gchar *group, + gboolean expanded) +{ + GList *l; + ContactGroup *cg; + gboolean changed = FALSE; + + g_return_if_fail (group != NULL); + + for (l = groups; l; l = l->next) { + ContactGroup *cg = l->data; + + if (!cg || !cg->name) { + continue; + } + + if (strcmp (cg->name, group) == 0) { + cg->expanded = expanded; + changed = TRUE; + break; + } + } + + /* if here... we don't have a ContactGroup for the group. */ + if (!changed) { + cg = contact_group_new (group, expanded); + groups = g_list_append (groups, cg); + } + + contact_groups_file_save (); +} diff --git a/libempathy/empathy-contact-groups.dtd b/libempathy/empathy-contact-groups.dtd new file mode 100644 index 000000000..b4de2260a --- /dev/null +++ b/libempathy/empathy-contact-groups.dtd @@ -0,0 +1,17 @@ +<!-- + DTD for Empathys contact groups. + by Martyn Russell <mr@gnome.org> +--> + +<!-- Root element. --> +<!ELEMENT contacts (account)> + +<!ELEMENT account (group)+> +<!ATTLIST account + name CDATA #REQUIRED> + +<!-- Groups in the roster. --> +<!ELEMENT group EMPTY> +<!ATTLIST group + name CDATA #REQUIRED + expanded CDATA #REQUIRED> diff --git a/libempathy/empathy-contact-groups.h b/libempathy/empathy-contact-groups.h new file mode 100644 index 000000000..e2e9810e3 --- /dev/null +++ b/libempathy/empathy-contact-groups.h @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2005 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: Martyn Russell <martyn@imendio.com> + */ + +#ifndef __EMPATHY_CONTACT_GROUPS_H__ +#define __EMPATHY_CONTACT_GROUPS_H__ + +G_BEGIN_DECLS + +#include <glib.h> + +void empathy_contact_groups_get_all (void); + +gboolean empathy_contact_group_get_expanded (const gchar *group); +void empathy_contact_group_set_expanded (const gchar *group, + gboolean expanded); + +G_END_DECLS + +#endif /* __EMPATHY_CONTACT_GROUPS_H__ */ diff --git a/libempathy/empathy-contact-list.c b/libempathy/empathy-contact-list.c index 5164ccf1a..510e41957 100644 --- a/libempathy/empathy-contact-list.c +++ b/libempathy/empathy-contact-list.c @@ -41,6 +41,8 @@ empathy_contact_list_get_type (void) type = g_type_register_static (G_TYPE_INTERFACE, "EmpathyContactList", &type_info, 0); + + g_type_interface_add_prerequisite (type, G_TYPE_OBJECT); } return type; 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 0239d144e..0f23037bd 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -60,7 +60,9 @@ struct _EmpathyIdlePriv { gboolean auto_away; gboolean use_nm; + gboolean away_reset_status; McPresence away_saved_state; + gboolean nm_reset_status; McPresence nm_saved_state; gboolean is_idle; @@ -81,6 +83,7 @@ static void idle_set_property (GObject *object, GParamSpec *pspec); static void idle_presence_changed_cb (MissionControl *mc, McPresence state, + gchar *status, EmpathyIdle *idle); static void idle_session_idle_changed_cb (DBusGProxy *gs_proxy, gboolean is_idle, @@ -167,10 +170,10 @@ empathy_idle_init (EmpathyIdle *idle) priv->is_idle = FALSE; priv->mc = empathy_mission_control_new (); priv->state = mission_control_get_presence_actual (priv->mc, NULL); - idle_presence_changed_cb (priv->mc, priv->state, idle); + priv->status = mission_control_get_presence_message_actual (priv->mc, NULL); dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), - "PresenceStatusActual", + "PresenceChanged", G_CALLBACK (idle_presence_changed_cb), idle, NULL); @@ -342,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; @@ -404,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; } @@ -487,19 +490,21 @@ empathy_idle_set_use_nm (EmpathyIdle *idle, static void idle_presence_changed_cb (MissionControl *mc, McPresence state, + gchar *status, EmpathyIdle *idle) { EmpathyIdlePriv *priv; priv = GET_PRIV (idle); + empathy_debug (DEBUG_DOMAIN, "Presence changed to '%s' (%d)", + status, state); + g_free (priv->status); priv->state = state; - priv->status = mission_control_get_presence_message_actual (priv->mc, NULL); - - if (G_STR_EMPTY (priv->status)) { - g_free (priv->status); - priv->status = NULL; + priv->status = NULL; + if (!G_STR_EMPTY (status)) { + priv->status = g_strdup (status); } g_object_notify (G_OBJECT (idle), "state"); @@ -538,9 +543,11 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy, * default presence. */ new_state = priv->state; priv->away_saved_state = MC_PRESENCE_AVAILABLE; + priv->away_reset_status = TRUE; } else { new_state = MC_PRESENCE_AWAY; priv->away_saved_state = priv->state; + priv->away_reset_status = FALSE; } empathy_debug (DEBUG_DOMAIN, "Going to autoaway"); @@ -551,18 +558,23 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy, /* We are no more idle, restore state */ idle_ext_away_stop (idle); - empathy_debug (DEBUG_DOMAIN, "Restoring state to %d", - priv->away_saved_state); + empathy_debug (DEBUG_DOMAIN, "Restoring state to %d, reset status: %s", + priv->away_saved_state, + priv->away_reset_status ? "Yes" : "No"); if (priv->nm_connected) { - empathy_idle_set_state (idle, priv->away_saved_state); + empathy_idle_set_presence (idle, + priv->away_saved_state, + priv->away_reset_status ? NULL : priv->status); } else { /* We can't restore state now, will do when NM gets * connected. */ priv->nm_saved_state = priv->away_saved_state; + priv->nm_reset_status = priv->away_reset_status; } priv->away_saved_state = MC_PRESENCE_UNSET; + priv->away_reset_status = FALSE; } priv->is_idle = is_idle; @@ -600,8 +612,11 @@ idle_nm_state_change_cb (DBusGProxy *proxy, } else if (!old_nm_connected && new_nm_connected) { /* We are now connected */ - empathy_idle_set_state (idle, priv->nm_saved_state); + empathy_idle_set_presence (idle, + priv->nm_saved_state, + priv->nm_reset_status ? NULL : priv->status); priv->nm_saved_state = MC_PRESENCE_UNSET; + priv->nm_reset_status = FALSE; } priv->nm_connected = new_nm_connected; diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c index c7721a1b5..bb9ece083 100644 --- a/libempathy/empathy-log-manager.c +++ b/libempathy/empathy-log-manager.c @@ -138,6 +138,8 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, EmpathyContact *sender; const gchar *body_str; const gchar *str; + EmpathyAvatar *avatar; + gchar *avatar_token = NULL; gchar *filename; gchar *basedir; gchar *body; @@ -193,11 +195,17 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, str = empathy_contact_get_id (sender); contact_id = g_markup_escape_text (str, -1); + avatar = empathy_contact_get_avatar (sender); + if (avatar) { + avatar_token = g_markup_escape_text (avatar->token, -1); + } + g_fprintf (file, - "<message time='%s' id='%s' name='%s' isuser='%s' type='%s'>%s</message>\n" LOG_FOOTER, + "<message time='%s' id='%s' name='%s' token='%s' isuser='%s' type='%s'>%s</message>\n" LOG_FOOTER, timestamp, contact_id, contact_name, + avatar_token ? avatar_token : "", empathy_contact_is_user (sender) ? "true" : "false", empathy_message_type_to_str (msg_type), body); @@ -208,6 +216,7 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, g_free (contact_name); g_free (timestamp); g_free (body); + g_free (avatar_token); } gboolean @@ -329,10 +338,12 @@ empathy_log_manager_get_messages_for_file (EmpathyLogManager *manager, for (node = log_node->children; node; node = node->next) { EmpathyMessage *message; EmpathyContact *sender; + EmpathyAvatar *avatar = NULL; gchar *time; time_t t; gchar *sender_id; gchar *sender_name; + gchar *sender_avatar_token; gchar *body; gchar *is_user_str; gboolean is_user = FALSE; @@ -347,9 +358,13 @@ empathy_log_manager_get_messages_for_file (EmpathyLogManager *manager, time = xmlGetProp (node, "time"); sender_id = xmlGetProp (node, "id"); sender_name = xmlGetProp (node, "name"); + sender_avatar_token = xmlGetProp (node, "token"); is_user_str = xmlGetProp (node, "isuser"); msg_type_str = xmlGetProp (node, "type"); + if (sender_avatar_token) { + avatar = empathy_avatar_new_from_cache (sender_avatar_token); + } if (is_user_str) { is_user = strcmp (is_user_str, "true") == 0; } @@ -361,6 +376,11 @@ empathy_log_manager_get_messages_for_file (EmpathyLogManager *manager, sender = empathy_contact_new_full (account, sender_id, sender_name); empathy_contact_set_is_user (sender, is_user); + if (avatar) { + empathy_contact_set_avatar (sender, avatar); + empathy_avatar_unref (avatar); + } + message = empathy_message_new (body); empathy_message_set_sender (message, sender); empathy_message_set_timestamp (message, t); 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 new file mode 100644 index 000000000..89b1874f3 --- /dev/null +++ b/libempathy/empathy-status-presets.c @@ -0,0 +1,407 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2005-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. + * + * Author: Martyn Russell <martyn@imendio.com> + */ + +#include "config.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> + +#include <glib.h> +#include <glib/gi18n.h> + +#include <libxml/parser.h> +#include <libxml/tree.h> + +#include <telepathy-glib/util.h> + +#include "empathy-debug.h" +#include "empathy-utils.h" +#include "empathy-status-presets.h" + +#define DEBUG_DOMAIN "StatusPresets" + +#define STATUS_PRESETS_XML_FILENAME "status-presets.xml" +#define STATUS_PRESETS_DTD_FILENAME "empathy-status-presets.dtd" +#define STATUS_PRESETS_MAX_EACH 15 + +typedef struct { + gchar *status; + McPresence state; +} StatusPreset; + +static StatusPreset *status_preset_new (McPresence state, + const gchar *status); +static void status_preset_free (StatusPreset *status); +static void status_presets_file_parse (const gchar *filename); +const gchar * status_presets_get_state_as_str (McPresence state); +static gboolean status_presets_file_save (void); +static void status_presets_set_default (McPresence state, + const gchar *status); + +static GList *presets = NULL; +static StatusPreset *default_preset = NULL; + +static StatusPreset * +status_preset_new (McPresence state, + const gchar *status) +{ + StatusPreset *preset; + + preset = g_new0 (StatusPreset, 1); + + preset->status = g_strdup (status); + preset->state = state; + + return preset; +} + +static void +status_preset_free (StatusPreset *preset) +{ + g_free (preset->status); + g_free (preset); +} + +static void +status_presets_file_parse (const gchar *filename) +{ + xmlParserCtxtPtr ctxt; + xmlDocPtr doc; + xmlNodePtr presets_node; + xmlNodePtr node; + + empathy_debug (DEBUG_DOMAIN, "Attempting to parse file:'%s'...", filename); + + ctxt = xmlNewParserCtxt (); + + /* Parse and validate the file. */ + doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); + if (!doc) { + g_warning ("Failed to parse file:'%s'", filename); + xmlFreeParserCtxt (ctxt); + return; + } + + if (!empathy_xml_validate (doc, STATUS_PRESETS_DTD_FILENAME)) { + g_warning ("Failed to validate file:'%s'", filename); + xmlFreeDoc(doc); + xmlFreeParserCtxt (ctxt); + return; + } + + /* The root node, presets. */ + presets_node = xmlDocGetRootElement (doc); + + node = presets_node->children; + while (node) { + if (strcmp ((gchar *) node->name, "status") == 0 || + strcmp ((gchar *) node->name, "default") == 0) { + McPresence state; + gchar *status; + gchar *state_str; + StatusPreset *preset; + gboolean is_default = FALSE; + + if (strcmp ((gchar *) node->name, "default") == 0) { + is_default = TRUE; + } + + status = (gchar *) xmlNodeGetContent (node); + state_str = (gchar *) xmlGetProp (node, "presence"); + + if (state_str) { + state = empathy_presence_from_str (state_str); + + if (is_default) { + empathy_debug (DEBUG_DOMAIN, + "Default status preset state is:'%s', status:'%s'", + state_str, status); + + status_presets_set_default (state, status); + } else { + preset = status_preset_new (state, status); + presets = g_list_append (presets, preset); + } + } + + xmlFree (status); + xmlFree (state_str); + } + + node = node->next; + } + + /* Use the default if not set */ + if (!default_preset) { + status_presets_set_default (MC_PRESENCE_OFFLINE, NULL); + } + + empathy_debug (DEBUG_DOMAIN, "Parsed %d status presets", g_list_length (presets)); + + xmlFreeDoc (doc); + xmlFreeParserCtxt (ctxt); +} + +void +empathy_status_presets_get_all (void) +{ + gchar *dir; + gchar *file_with_path; + + /* If already set up clean up first. */ + if (presets) { + g_list_foreach (presets, (GFunc) status_preset_free, NULL); + g_list_free (presets); + presets = NULL; + } + + dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); + file_with_path = g_build_filename (dir, STATUS_PRESETS_XML_FILENAME, NULL); + g_free (dir); + + if (g_file_test (file_with_path, G_FILE_TEST_EXISTS)) { + status_presets_file_parse (file_with_path); + } + + g_free (file_with_path); +} + +static gboolean +status_presets_file_save (void) +{ + xmlDocPtr doc; + xmlNodePtr root; + GList *l; + gchar *dir; + gchar *file; + gint count[LAST_MC_PRESENCE]; + gint i; + + for (i = 0; i < LAST_MC_PRESENCE; i++) { + count[i] = 0; + } + + dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); + file = g_build_filename (dir, STATUS_PRESETS_XML_FILENAME, NULL); + g_free (dir); + + doc = xmlNewDoc ("1.0"); + root = xmlNewNode (NULL, "presets"); + xmlDocSetRootElement (doc, root); + + if (default_preset) { + xmlNodePtr subnode; + xmlChar *state; + + state = (gchar*) empathy_presence_to_str (default_preset->state); + + subnode = xmlNewTextChild (root, NULL, "default", + default_preset->status); + xmlNewProp (subnode, "presence", state); + } + + for (l = presets; l; l = l->next) { + StatusPreset *sp; + xmlNodePtr subnode; + xmlChar *state; + + sp = l->data; + state = (gchar*) empathy_presence_to_str (sp->state); + + count[sp->state]++; + if (count[sp->state] > STATUS_PRESETS_MAX_EACH) { + continue; + } + + subnode = xmlNewTextChild (root, NULL, + "status", sp->status); + xmlNewProp (subnode, "presence", state); + } + + /* Make sure the XML is indented properly */ + xmlIndentTreeOutput = 1; + + empathy_debug (DEBUG_DOMAIN, "Saving file:'%s'", file); + xmlSaveFormatFileEnc (file, doc, "utf-8", 1); + xmlFreeDoc (doc); + + g_free (file); + + return TRUE; +} + +GList * +empathy_status_presets_get (McPresence state, + gint max_number) +{ + GList *list = NULL; + GList *l; + gint i; + + i = 0; + for (l = presets; l; l = l->next) { + StatusPreset *sp; + + sp = l->data; + + if (sp->state != state) { + continue; + } + + list = g_list_append (list, sp->status); + i++; + + if (max_number != -1 && i >= max_number) { + break; + } + } + + return list; +} + +void +empathy_status_presets_set_last (McPresence state, + const gchar *status) +{ + GList *l; + StatusPreset *preset; + gint num; + + /* Check if duplicate */ + for (l = presets; l; l = l->next) { + preset = l->data; + + if (state == preset->state && + !tp_strdiff (status, preset->status)) { + return; + } + } + + preset = status_preset_new (state, status); + presets = g_list_prepend (presets, preset); + + num = 0; + for (l = presets; l; l = l->next) { + preset = l->data; + + if (state != preset->state) { + continue; + } + + num++; + + if (num > STATUS_PRESETS_MAX_EACH) { + status_preset_free (preset); + presets = g_list_delete_link (presets, l); + break; + } + } + + status_presets_file_save (); +} + +void +empathy_status_presets_remove (McPresence state, + const gchar *status) +{ + StatusPreset *preset; + GList *l; + + for (l = presets; l; l = l->next) { + preset = l->data; + + if (state == preset->state && + !tp_strdiff (status, preset->status)) { + status_preset_free (preset); + presets = g_list_delete_link (presets, l); + status_presets_file_save (); + break; + } + } +} + +void +empathy_status_presets_reset (void) +{ + g_list_foreach (presets, (GFunc) status_preset_free, NULL); + g_list_free (presets); + + presets = NULL; + + status_presets_set_default (MC_PRESENCE_AVAILABLE, NULL); + + status_presets_file_save (); +} + +McPresence +empathy_status_presets_get_default_state (void) +{ + if (!default_preset) { + return MC_PRESENCE_OFFLINE; + } + + return default_preset->state; +} + +const gchar * +empathy_status_presets_get_default_status (void) +{ + if (!default_preset || + !default_preset->status) { + return NULL; + } + + return default_preset->status; +} + +static void +status_presets_set_default (McPresence state, + const gchar *status) +{ + if (default_preset) { + status_preset_free (default_preset); + } + + default_preset = status_preset_new (state, status); +} + +void +empathy_status_presets_set_default (McPresence state, + const gchar *status) +{ + status_presets_set_default (state, status); + status_presets_file_save (); +} + +void +empathy_status_presets_clear_default (void) +{ + if (default_preset) { + status_preset_free (default_preset); + default_preset = NULL; + } + + status_presets_file_save (); +} diff --git a/libempathy/empathy-status-presets.dtd b/libempathy/empathy-status-presets.dtd new file mode 100644 index 000000000..872be6b4e --- /dev/null +++ b/libempathy/empathy-status-presets.dtd @@ -0,0 +1,14 @@ +<!-- + DTD for Empathys status presets. + by Martyn Russell <martyn@imendio.com> +--> + +<!-- Root element. --> +<!ELEMENT presets ((default?),status*)> + +<!ELEMENT default (#PCDATA)> +<!ATTLIST default presence CDATA #REQUIRED> + +<!ELEMENT status (#PCDATA)> +<!ATTLIST status presence CDATA #REQUIRED> + diff --git a/libempathy/empathy-status-presets.h b/libempathy/empathy-status-presets.h new file mode 100644 index 000000000..06b6c7912 --- /dev/null +++ b/libempathy/empathy-status-presets.h @@ -0,0 +1,46 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2005-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. + * + * Author: Martyn Russell <martyn@imendio.com> + */ + +#ifndef __EMPATHY_STATUS_PRESETS_H__ +#define __EMPATHY_STATUS_PRESETS_H__ + +#include <libmissioncontrol/mission-control.h> + +G_BEGIN_DECLS + +void empathy_status_presets_get_all (void); +GList * empathy_status_presets_get (McPresence state, + gint max_number); +void empathy_status_presets_set_last (McPresence state, + const gchar *status); +void empathy_status_presets_remove (McPresence state, + const gchar *status); +void empathy_status_presets_reset (void); +McPresence empathy_status_presets_get_default_state (void); +const gchar * empathy_status_presets_get_default_status (void); +void empathy_status_presets_set_default (McPresence state, + const gchar *status); +void empathy_status_presets_clear_default (void); + +G_END_DECLS + +#endif /* __EMPATHY_STATUS_PRESETS_H__ */ diff --git a/libempathy/empathy-time.h b/libempathy/empathy-time.h index 560b4655a..ce520cdf9 100644 --- a/libempathy/empathy-time.h +++ b/libempathy/empathy-time.h @@ -36,8 +36,6 @@ G_BEGIN_DECLS time_t empathy_time_get_current (void); time_t empathy_time_get_local_time (struct tm *tm); time_t empathy_time_parse (const gchar *str); -time_t empathy_time_parse_format (const gchar *str, - const gchar *format); gchar *empathy_time_to_string_utc (time_t t, const gchar *format); gchar *empathy_time_to_string_local (time_t t, 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-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c index 2f366ff10..793cd3e19 100644 --- a/libempathy/empathy-tp-contact-list.c +++ b/libempathy/empathy-tp-contact-list.c @@ -29,6 +29,7 @@ #include <libtelepathy/tp-conn.h> #include <libtelepathy/tp-chan.h> #include <libtelepathy/tp-chan-type-contact-list-gen.h> +#include <telepathy-glib/util.h> #include "empathy-tp-contact-list.h" #include "empathy-contact-list.h" @@ -169,7 +170,7 @@ tp_contact_list_find_group (EmpathyTpContactList *list, GList *l; for (l = priv->groups; l; l = l->next) { - if (strcmp (group, empathy_tp_group_get_name (l->data)) == 0) { + if (!tp_strdiff (group, empathy_tp_group_get_name (l->data))) { return l->data; } } @@ -180,22 +181,16 @@ static TpContactListType tp_contact_list_get_type (EmpathyTpContactList *list, EmpathyTpGroup *group) { - EmpathyTpContactListPriv *priv; - TpContactListType list_type; - const gchar *name; - - priv = GET_PRIV (list); + const gchar *name; name = empathy_tp_group_get_name (group); - if (strcmp (name, "subscribe") == 0) { - list_type = TP_CONTACT_LIST_TYPE_SUBSCRIBE; - } else if (strcmp (name, "publish") == 0) { - list_type = TP_CONTACT_LIST_TYPE_PUBLISH; - } else { - list_type = TP_CONTACT_LIST_TYPE_UNKNOWN; + if (!tp_strdiff (name, "subscribe")) { + return TP_CONTACT_LIST_TYPE_SUBSCRIBE; + } else if (!tp_strdiff (name, "publish")) { + return TP_CONTACT_LIST_TYPE_PUBLISH; } - return list_type; + return TP_CONTACT_LIST_TYPE_UNKNOWN; } static void diff --git a/libempathy/empathy-tp-group.c b/libempathy/empathy-tp-group.c index 9c70321d7..30a0097c6 100644 --- a/libempathy/empathy-tp-group.c +++ b/libempathy/empathy-tp-group.c @@ -562,8 +562,8 @@ empathy_tp_group_new (McAccount *account, DBusGProxy *group_iface; GError *error = NULL; - g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); group_iface = tp_chan_get_interface (tp_chan, TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP); @@ -620,10 +620,12 @@ tp_group_async_cb (DBusGProxy *proxy, GError *error, gpointer user_data) } void -empathy_tp_group_close (EmpathyTpGroup *group) +empathy_tp_group_close (EmpathyTpGroup *group) { EmpathyTpGroupPriv *priv = GET_PRIV (group); + g_return_if_fail (EMPATHY_IS_TP_GROUP (group)); + tp_chan_close_async (DBUS_G_PROXY (priv->tp_chan), tp_group_async_cb, "Failed to close"); @@ -679,6 +681,9 @@ empathy_tp_group_add_member (EmpathyTpGroup *group, GArray *handles; guint handle; + g_return_if_fail (EMPATHY_IS_TP_GROUP (group)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + handle = empathy_contact_get_handle (contact); handles = g_array_new (FALSE, FALSE, sizeof (guint)); g_array_append_val (handles, handle); @@ -722,6 +727,9 @@ empathy_tp_group_remove_member (EmpathyTpGroup *group, GArray *handles; guint handle; + g_return_if_fail (EMPATHY_IS_TP_GROUP (group)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + handle = empathy_contact_get_handle (contact); handles = g_array_new (FALSE, FALSE, sizeof (guint)); g_array_append_val (handles, handle); @@ -740,6 +748,8 @@ empathy_tp_group_get_members (EmpathyTpGroup *group) { EmpathyTpGroupPriv *priv = GET_PRIV (group); + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL); + g_list_foreach (priv->members, (GFunc) g_object_ref, NULL); return g_list_copy (priv->members); @@ -751,6 +761,8 @@ empathy_tp_group_get_local_pendings (EmpathyTpGroup *group) EmpathyTpGroupPriv *priv = GET_PRIV (group); GList *pendings = NULL, *l; + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL); + for (l = priv->local_pendings; l; l = l->next) { EmpathyPendingInfo *info; EmpathyPendingInfo *new_info; @@ -770,6 +782,8 @@ empathy_tp_group_get_remote_pendings (EmpathyTpGroup *group) { EmpathyTpGroupPriv *priv = GET_PRIV (group); + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL); + g_list_foreach (priv->remote_pendings, (GFunc) g_object_ref, NULL); return g_list_copy (priv->remote_pendings); @@ -820,6 +834,9 @@ empathy_tp_group_is_member (EmpathyTpGroup *group, { EmpathyTpGroupPriv *priv = GET_PRIV (group); + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), FALSE); + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE); + return g_list_find (priv->members, contact) != NULL; } diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 0e2c4b588..c810f9cca 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -208,11 +208,15 @@ empathy_xml_validate (xmlDoc *doc, xmlDtd *dtd; gboolean ret; - path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL); + path = g_build_filename (UNINSTALLED_DTD_DIR, dtd_filename, NULL); + if (!g_file_test (path, G_FILE_TEST_EXISTS)) { + g_free (path); + path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL); + } + empathy_debug (DEBUG_DOMAIN, "Loading dtd file %s", path); /* The list of valid chars is taken from libxml. */ escaped = xmlURIEscapeStr (path, ":@&=+$,/?;"); - g_free (path); memset (&cvp, 0, sizeof (cvp)); @@ -481,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 |