From 58505161bcc63ba91190f6b38a3c52c0c564ca32 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 22 Jun 2007 10:47:42 +0000 Subject: Rename all filenames starting with "gossip" by "empathy", change namespace 2007-06-22 Xavier Claessens * libempathy/*.[ch]: * libempathy-gtk/*.[ch]: * src/*.[ch]: Rename all filenames starting with "gossip" by "empathy", change namespace of all gossip_*() functions to empathy_*(). Fixes bug #444490 (Mario Danic, Xavier Claessens). svn path=/trunk/; revision=170 --- libempathy/Makefile.am | 24 +- libempathy/empathy-avatar.c | 86 ++++ libempathy/empathy-avatar.h | 48 ++ libempathy/empathy-chandler.c | 4 +- libempathy/empathy-chatroom-manager.c | 501 ++++++++++++++++++++ libempathy/empathy-chatroom-manager.dtd | 17 + libempathy/empathy-chatroom-manager.h | 72 +++ libempathy/empathy-chatroom.c | 362 +++++++++++++++ libempathy/empathy-chatroom.h | 78 ++++ libempathy/empathy-conf.c | 372 +++++++++++++++ libempathy/empathy-conf.h | 87 ++++ libempathy/empathy-contact-list.c | 18 +- libempathy/empathy-contact-list.h | 22 +- libempathy/empathy-contact-manager.c | 60 +-- libempathy/empathy-contact-manager.h | 6 +- libempathy/empathy-contact.c | 800 ++++++++++++++++++++++++++++++++ libempathy/empathy-contact.h | 106 +++++ libempathy/empathy-debug.c | 92 ++++ libempathy/empathy-debug.h | 53 +++ libempathy/empathy-idle.c | 26 +- libempathy/empathy-log-manager.c | 88 ++-- libempathy/empathy-log-manager.h | 4 +- libempathy/empathy-message.c | 418 +++++++++++++++++ libempathy/empathy-message.h | 82 ++++ libempathy/empathy-presence.c | 337 ++++++++++++++ libempathy/empathy-presence.h | 67 +++ libempathy/empathy-time.c | 124 +++++ libempathy/empathy-time.h | 50 ++ libempathy/empathy-tp-chat.c | 78 ++-- libempathy/empathy-tp-chat.h | 8 +- libempathy/empathy-tp-chatroom.c | 94 ++-- libempathy/empathy-tp-chatroom.h | 2 +- libempathy/empathy-tp-contact-list.c | 622 ++++++++++++------------- libempathy/empathy-tp-contact-list.h | 8 +- libempathy/empathy-tp-group.c | 542 ++++++++++++++++++++++ libempathy/empathy-tp-group.h | 86 ++++ libempathy/empathy-utils.c | 495 ++++++++++++++++++++ libempathy/empathy-utils.h | 100 ++++ libempathy/gossip-avatar.c | 86 ---- libempathy/gossip-avatar.h | 48 -- libempathy/gossip-chatroom-manager.c | 501 -------------------- libempathy/gossip-chatroom-manager.dtd | 17 - libempathy/gossip-chatroom-manager.h | 72 --- libempathy/gossip-chatroom.c | 362 --------------- libempathy/gossip-chatroom.h | 78 ---- libempathy/gossip-conf.c | 372 --------------- libempathy/gossip-conf.h | 87 ---- libempathy/gossip-contact.c | 800 -------------------------------- libempathy/gossip-contact.h | 106 ----- libempathy/gossip-debug.c | 92 ---- libempathy/gossip-debug.h | 53 --- libempathy/gossip-message.c | 418 ----------------- libempathy/gossip-message.h | 82 ---- libempathy/gossip-presence.c | 337 -------------- libempathy/gossip-presence.h | 67 --- libempathy/gossip-telepathy-group.c | 543 ---------------------- libempathy/gossip-telepathy-group.h | 87 ---- libempathy/gossip-time.c | 124 ----- libempathy/gossip-time.h | 50 -- libempathy/gossip-utils.c | 495 -------------------- libempathy/gossip-utils.h | 100 ---- 61 files changed, 5507 insertions(+), 5509 deletions(-) create mode 100644 libempathy/empathy-avatar.c create mode 100644 libempathy/empathy-avatar.h create mode 100644 libempathy/empathy-chatroom-manager.c create mode 100644 libempathy/empathy-chatroom-manager.dtd create mode 100644 libempathy/empathy-chatroom-manager.h create mode 100644 libempathy/empathy-chatroom.c create mode 100644 libempathy/empathy-chatroom.h create mode 100644 libempathy/empathy-conf.c create mode 100644 libempathy/empathy-conf.h create mode 100644 libempathy/empathy-contact.c create mode 100644 libempathy/empathy-contact.h create mode 100644 libempathy/empathy-debug.c create mode 100644 libempathy/empathy-debug.h create mode 100644 libempathy/empathy-message.c create mode 100644 libempathy/empathy-message.h create mode 100644 libempathy/empathy-presence.c create mode 100644 libempathy/empathy-presence.h create mode 100644 libempathy/empathy-time.c create mode 100644 libempathy/empathy-time.h create mode 100644 libempathy/empathy-tp-group.c create mode 100644 libempathy/empathy-tp-group.h create mode 100644 libempathy/empathy-utils.c create mode 100644 libempathy/empathy-utils.h delete mode 100644 libempathy/gossip-avatar.c delete mode 100644 libempathy/gossip-avatar.h delete mode 100644 libempathy/gossip-chatroom-manager.c delete mode 100644 libempathy/gossip-chatroom-manager.dtd delete mode 100644 libempathy/gossip-chatroom-manager.h delete mode 100644 libempathy/gossip-chatroom.c delete mode 100644 libempathy/gossip-chatroom.h delete mode 100644 libempathy/gossip-conf.c delete mode 100644 libempathy/gossip-conf.h delete mode 100644 libempathy/gossip-contact.c delete mode 100644 libempathy/gossip-contact.h delete mode 100644 libempathy/gossip-debug.c delete mode 100644 libempathy/gossip-debug.h delete mode 100644 libempathy/gossip-message.c delete mode 100644 libempathy/gossip-message.h delete mode 100644 libempathy/gossip-presence.c delete mode 100644 libempathy/gossip-presence.h delete mode 100644 libempathy/gossip-telepathy-group.c delete mode 100644 libempathy/gossip-telepathy-group.h delete mode 100644 libempathy/gossip-time.c delete mode 100644 libempathy/gossip-time.h delete mode 100644 libempathy/gossip-utils.c delete mode 100644 libempathy/gossip-utils.h (limited to 'libempathy') diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 37bb98e09..00ce4233a 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -13,19 +13,19 @@ BUILT_SOURCES = \ noinst_LTLIBRARIES = libempathy.la libempathy_la_SOURCES = \ - gossip-conf.c gossip-conf.h \ - gossip-contact.c gossip-contact.h \ - gossip-avatar.c gossip-avatar.h \ - gossip-time.c gossip-time.h \ - gossip-presence.c gossip-presence.h \ - gossip-telepathy-group.c gossip-telepathy-group.h \ - gossip-debug.c gossip-debug.h \ - gossip-utils.c gossip-utils.h \ - gossip-message.c gossip-message.h \ - gossip-chatroom-manager.c gossip-chatroom-manager.h \ - gossip-chatroom.c gossip-chatroom.h \ + empathy-conf.c empathy-conf.h \ + empathy-contact.c empathy-contact.h \ + empathy-avatar.c empathy-avatar.h \ + empathy-time.c empathy-time.h \ + empathy-presence.c empathy-presence.h \ + empathy-debug.c empathy-debug.h \ + empathy-utils.c empathy-utils.h \ + empathy-message.c empathy-message.h \ + empathy-chatroom-manager.c empathy-chatroom-manager.h \ + empathy-chatroom.c empathy-chatroom.h \ empathy-contact-list.c empathy-contact-list.h \ empathy-contact-manager.c empathy-contact-manager.h \ + empathy-tp-group.c empathy-tp-group.h \ empathy-tp-contact-list.c empathy-tp-contact-list.h \ empathy-tp-chat.c empathy-tp-chat.h \ empathy-tp-chatroom.c empathy-tp-chatroom.h \ @@ -52,7 +52,7 @@ empathy-chandler-glue.h: empathy-chandler.xml dtddir = $(datadir)/empathy dtd_DATA = \ - gossip-chatroom-manager.dtd + empathy-chatroom-manager.dtd stylesheetdir = $(datadir)/empathy stylesheet_DATA = \ diff --git a/libempathy/empathy-avatar.c b/libempathy/empathy-avatar.c new file mode 100644 index 000000000..e5a2a73a9 --- /dev/null +++ b/libempathy/empathy-avatar.c @@ -0,0 +1,86 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2002-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 + * Xavier Claessens + */ + +#include "config.h" + +#include "empathy-avatar.h" + +#define DEBUG_DOMAIN "Avatar" + +GType +empathy_avatar_get_gtype (void) +{ + static GType type_id = 0; + + if (!type_id) { + type_id = g_boxed_type_register_static ("EmpathyAvatar", + (GBoxedCopyFunc) empathy_avatar_ref, + (GBoxedFreeFunc) empathy_avatar_unref); + } + + return type_id; +} + +EmpathyAvatar * +empathy_avatar_new (guchar *data, + gsize len, + gchar *format) +{ + EmpathyAvatar *avatar; + + g_return_val_if_fail (data != NULL, NULL); + g_return_val_if_fail (len > 0, NULL); + g_return_val_if_fail (format != NULL, NULL); + + avatar = g_slice_new0 (EmpathyAvatar); + avatar->data = g_memdup (data, len); + avatar->len = len; + avatar->format = g_strdup (format); + avatar->refcount = 1; + + return avatar; +} + +void +empathy_avatar_unref (EmpathyAvatar *avatar) +{ + g_return_if_fail (avatar != NULL); + + avatar->refcount--; + if (avatar->refcount == 0) { + g_free (avatar->data); + g_free (avatar->format); + g_slice_free (EmpathyAvatar, avatar); + } +} + +EmpathyAvatar * +empathy_avatar_ref (EmpathyAvatar *avatar) +{ + g_return_val_if_fail (avatar != NULL, NULL); + + avatar->refcount++; + + return avatar; +} + diff --git a/libempathy/empathy-avatar.h b/libempathy/empathy-avatar.h new file mode 100644 index 000000000..73d69cf79 --- /dev/null +++ b/libempathy/empathy-avatar.h @@ -0,0 +1,48 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2006 Xavier Claessens + * + * 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_AVATAR_H__ +#define __EMPATHY_AVATAR_H__ + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_AVATAR (empathy_avatar_get_gtype ()) + +typedef struct _EmpathyAvatar EmpathyAvatar; + +struct _EmpathyAvatar { + guchar *data; + gsize len; + gchar *format; + guint refcount; +}; + +GType empathy_avatar_get_gtype (void) G_GNUC_CONST; +EmpathyAvatar * empathy_avatar_new (guchar *avatar, + gsize len, + gchar *format); +EmpathyAvatar * empathy_avatar_ref (EmpathyAvatar *avatar); +void empathy_avatar_unref (EmpathyAvatar *avatar); + +G_END_DECLS + +#endif /* __EMPATHY_AVATAR_H__ */ diff --git a/libempathy/empathy-chandler.c b/libempathy/empathy-chandler.c index 5e9ca82f3..9bef4b1e1 100644 --- a/libempathy/empathy-chandler.c +++ b/libempathy/empathy-chandler.c @@ -29,7 +29,7 @@ #include #include "empathy-chandler.h" -#include "gossip-debug.h" +#include "empathy-debug.h" #include "empathy-marshal.h" #define DEBUG_DOMAIN "EmpathyChandler" @@ -100,7 +100,7 @@ empathy_chandler_new (const gchar *bus_name, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Failed to request name: %s", error ? error->message : "No error given"); g_clear_error (&error); diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c new file mode 100644 index 000000000..a0b6fbb26 --- /dev/null +++ b/libempathy/empathy-chatroom-manager.c @@ -0,0 +1,501 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2004-2007 Imendio AB + * Copyright (C) 2007 Collabora Ltd. + * + * 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: Xavier Claessens + * Martyn Russell + */ + +#include "config.h" + +#include +#include +#include + +#include +#include + +#include "empathy-debug.h" +#include "empathy-chatroom-manager.h" +#include "empathy-utils.h" + +#define DEBUG_DOMAIN "ChatroomManager" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CHATROOM_MANAGER, EmpathyChatroomManagerPriv)) + +#define CHATROOMS_XML_FILENAME "chatrooms.xml" +#define CHATROOMS_DTD_FILENAME "empathy-chatroom-manager.dtd" + +struct _EmpathyChatroomManagerPriv { + GList *chatrooms; +}; + +static void empathy_chatroom_manager_class_init (EmpathyChatroomManagerClass *klass); +static void empathy_chatroom_manager_init (EmpathyChatroomManager *manager); +static void chatroom_manager_finalize (GObject *object); +static gboolean chatroom_manager_get_all (EmpathyChatroomManager *manager); +static gboolean chatroom_manager_file_parse (EmpathyChatroomManager *manager, + const gchar *filename); +static void chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager, + xmlNodePtr node); +static gboolean chatroom_manager_file_save (EmpathyChatroomManager *manager); + +enum { + CHATROOM_ADDED, + CHATROOM_REMOVED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +G_DEFINE_TYPE (EmpathyChatroomManager, empathy_chatroom_manager, G_TYPE_OBJECT); + +static void +empathy_chatroom_manager_class_init (EmpathyChatroomManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = chatroom_manager_finalize; + + signals[CHATROOM_ADDED] = + g_signal_new ("chatroom-added", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, EMPATHY_TYPE_CHATROOM); + signals[CHATROOM_REMOVED] = + g_signal_new ("chatroom-removed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, EMPATHY_TYPE_CHATROOM); + + g_type_class_add_private (object_class, + sizeof (EmpathyChatroomManagerPriv)); +} + +static void +empathy_chatroom_manager_init (EmpathyChatroomManager *manager) +{ + EmpathyChatroomManagerPriv *priv; + + priv = GET_PRIV (manager); +} + +static void +chatroom_manager_finalize (GObject *object) +{ + EmpathyChatroomManagerPriv *priv; + + priv = GET_PRIV (object); + + g_list_foreach (priv->chatrooms, (GFunc) g_object_unref, NULL); + g_list_free (priv->chatrooms); + + (G_OBJECT_CLASS (empathy_chatroom_manager_parent_class)->finalize) (object); +} + +EmpathyChatroomManager * +empathy_chatroom_manager_new (void) +{ + static EmpathyChatroomManager *manager = NULL; + + if (!manager) { + EmpathyChatroomManagerPriv *priv; + + manager = g_object_new (EMPATHY_TYPE_CHATROOM_MANAGER, NULL); + priv = GET_PRIV (manager); + chatroom_manager_get_all (manager); + + g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager); + } else { + g_object_ref (manager); + } + + return manager; +} + +gboolean +empathy_chatroom_manager_add (EmpathyChatroomManager *manager, + EmpathyChatroom *chatroom) +{ + EmpathyChatroomManagerPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager), FALSE); + g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), FALSE); + + priv = GET_PRIV (manager); + + /* don't add more than once */ + if (!empathy_chatroom_manager_find (manager, + empathy_chatroom_get_account (chatroom), + empathy_chatroom_get_room (chatroom))) { + priv->chatrooms = g_list_prepend (priv->chatrooms, g_object_ref (chatroom)); + chatroom_manager_file_save (manager); + + g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); + + return TRUE; + } + + return FALSE; +} + +void +empathy_chatroom_manager_remove (EmpathyChatroomManager *manager, + EmpathyChatroom *chatroom) +{ + EmpathyChatroomManagerPriv *priv; + GList *l; + + g_return_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager)); + g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom)); + + priv = GET_PRIV (manager); + + for (l = priv->chatrooms; l; l = l->next) { + EmpathyChatroom *this_chatroom; + + this_chatroom = l->data; + + if (empathy_chatroom_equal (chatroom, this_chatroom)) { + priv->chatrooms = g_list_delete_link (priv->chatrooms, l); + + chatroom_manager_file_save (manager); + + g_signal_emit (manager, signals[CHATROOM_REMOVED], 0, this_chatroom); + g_object_unref (this_chatroom); + break; + } + } +} + +EmpathyChatroom * +empathy_chatroom_manager_find (EmpathyChatroomManager *manager, + McAccount *account, + const gchar *room) +{ + EmpathyChatroomManagerPriv *priv; + GList *l; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager), NULL); + g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (room != NULL, NULL); + + priv = GET_PRIV (manager); + + for (l = priv->chatrooms; l; l = l->next) { + EmpathyChatroom *chatroom; + McAccount *this_account; + const gchar *this_room; + + chatroom = l->data; + this_account = empathy_chatroom_get_account (chatroom); + this_room = empathy_chatroom_get_room (chatroom); + + if (this_account && this_room && + empathy_account_equal (account, this_account) && + strcmp (this_room, room) == 0) { + return chatroom; + } + } + + return NULL; +} + +GList * +empathy_chatroom_manager_get_chatrooms (EmpathyChatroomManager *manager, + McAccount *account) +{ + EmpathyChatroomManagerPriv *priv; + GList *chatrooms, *l; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager), NULL); + + priv = GET_PRIV (manager); + + if (!account) { + return g_list_copy (priv->chatrooms); + } + + chatrooms = NULL; + for (l = priv->chatrooms; l; l = l->next) { + EmpathyChatroom *chatroom; + + chatroom = l->data; + + if (empathy_account_equal (account, + empathy_chatroom_get_account (chatroom))) { + chatrooms = g_list_append (chatrooms, chatroom); + } + } + + return chatrooms; +} + +guint +empathy_chatroom_manager_get_count (EmpathyChatroomManager *manager, + McAccount *account) +{ + EmpathyChatroomManagerPriv *priv; + GList *l; + guint count = 0; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager), 0); + + priv = GET_PRIV (manager); + + if (!account) { + return g_list_length (priv->chatrooms); + } + + for (l = priv->chatrooms; l; l = l->next) { + EmpathyChatroom *chatroom; + + chatroom = l->data; + + if (empathy_account_equal (account, + empathy_chatroom_get_account (chatroom))) { + count++; + } + } + + return count; +} + +void +empathy_chatroom_manager_store (EmpathyChatroomManager *manager) +{ + g_return_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager)); + + chatroom_manager_file_save (manager); +} + +/* + * API to save/load and parse the chatrooms file. + */ + +static gboolean +chatroom_manager_get_all (EmpathyChatroomManager *manager) +{ + EmpathyChatroomManagerPriv *priv; + gchar *dir; + gchar *file_with_path = NULL; + + priv = GET_PRIV (manager); + + dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); + } + + file_with_path = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL); + g_free (dir); + + /* read file in */ + if (g_file_test (file_with_path, G_FILE_TEST_EXISTS) && + !chatroom_manager_file_parse (manager, file_with_path)) { + g_free (file_with_path); + return FALSE; + } + + g_free (file_with_path); + + return TRUE; +} + +static gboolean +chatroom_manager_file_parse (EmpathyChatroomManager *manager, + const gchar *filename) +{ + EmpathyChatroomManagerPriv *priv; + xmlParserCtxtPtr ctxt; + xmlDocPtr doc; + xmlNodePtr chatrooms; + xmlNodePtr node; + + priv = GET_PRIV (manager); + + 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 FALSE; + } + + if (!empathy_xml_validate (doc, CHATROOMS_DTD_FILENAME)) { + g_warning ("Failed to validate file:'%s'", filename); + xmlFreeDoc(doc); + xmlFreeParserCtxt (ctxt); + return FALSE; + } + + /* The root node, chatrooms. */ + chatrooms = xmlDocGetRootElement (doc); + + for (node = chatrooms->children; node; node = node->next) { + if (strcmp ((gchar *) node->name, "chatroom") == 0) { + chatroom_manager_parse_chatroom (manager, node); + } + } + + empathy_debug (DEBUG_DOMAIN, + "Parsed %d chatrooms", + g_list_length (priv->chatrooms)); + + xmlFreeDoc(doc); + xmlFreeParserCtxt (ctxt); + + return TRUE; +} + +static void +chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager, + xmlNodePtr node) +{ + EmpathyChatroomManagerPriv *priv; + EmpathyChatroom *chatroom; + McAccount *account; + xmlNodePtr child; + gchar *str; + gchar *name; + gchar *room; + gchar *account_id; + gboolean auto_connect; + + priv = GET_PRIV (manager); + + /* default values. */ + name = NULL; + room = NULL; + auto_connect = TRUE; + account_id = NULL; + + for (child = node->children; child; child = child->next) { + gchar *tag; + + if (xmlNodeIsText (child)) { + continue; + } + + tag = (gchar *) child->name; + str = (gchar *) xmlNodeGetContent (child); + + if (strcmp (tag, "name") == 0) { + name = g_strdup (str); + } + else if (strcmp (tag, "room") == 0) { + room = g_strdup (str); + } + else if (strcmp (tag, "auto_connect") == 0) { + if (strcmp (str, "yes") == 0) { + auto_connect = TRUE; + } else { + auto_connect = FALSE; + } + } + else if (strcmp (tag, "account") == 0) { + account_id = g_strdup (str); + } + + xmlFree (str); + } + + account = mc_account_lookup (account_id); + if (!account) { + g_free (name); + g_free (room); + g_free (account_id); + return; + } + + chatroom = empathy_chatroom_new_full (account, room, name, auto_connect); + priv->chatrooms = g_list_prepend (priv->chatrooms, chatroom); + g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); + + g_object_unref (account); + g_free (name); + g_free (room); + g_free (account_id); +} + +static gboolean +chatroom_manager_file_save (EmpathyChatroomManager *manager) +{ + EmpathyChatroomManagerPriv *priv; + xmlDocPtr doc; + xmlNodePtr root; + GList *l; + gchar *dir; + gchar *file; + + priv = GET_PRIV (manager); + + dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); + } + + file = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL); + g_free (dir); + + doc = xmlNewDoc ("1.0"); + root = xmlNewNode (NULL, "chatrooms"); + xmlDocSetRootElement (doc, root); + + for (l = priv->chatrooms; l; l = l->next) { + EmpathyChatroom *chatroom; + xmlNodePtr node; + const gchar *account_id; + + chatroom = l->data; + account_id = mc_account_get_unique_name (empathy_chatroom_get_account (chatroom)); + + node = xmlNewChild (root, NULL, "chatroom", NULL); + xmlNewTextChild (node, NULL, "name", empathy_chatroom_get_name (chatroom)); + xmlNewTextChild (node, NULL, "room", empathy_chatroom_get_room (chatroom)); + xmlNewTextChild (node, NULL, "account", account_id); + xmlNewTextChild (node, NULL, "auto_connect", empathy_chatroom_get_auto_connect (chatroom) ? "yes" : "no"); + } + + /* 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; +} diff --git a/libempathy/empathy-chatroom-manager.dtd b/libempathy/empathy-chatroom-manager.dtd new file mode 100644 index 000000000..df6b953f6 --- /dev/null +++ b/libempathy/empathy-chatroom-manager.dtd @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/libempathy/empathy-chatroom-manager.h b/libempathy/empathy-chatroom-manager.h new file mode 100644 index 000000000..758aa29c3 --- /dev/null +++ b/libempathy/empathy-chatroom-manager.h @@ -0,0 +1,72 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2004-2007 Imendio AB + * Copyright (C) 2007 Collabora Ltd. + * + * 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: Xavier Claessens + * Martyn Russell + */ + +#ifndef __EMPATHY_CHATROOM_MANAGER_H__ +#define __EMPATHY_CHATROOM_MANAGER_H__ + +#include + +#include + +#include "empathy-chatroom.h" + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_CHATROOM_MANAGER (empathy_chatroom_manager_get_type ()) +#define EMPATHY_CHATROOM_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CHATROOM_MANAGER, EmpathyChatroomManager)) +#define EMPATHY_CHATROOM_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_CHATROOM_MANAGER, EmpathyChatroomManagerClass)) +#define EMPATHY_IS_CHATROOM_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CHATROOM_MANAGER)) +#define EMPATHY_IS_CHATROOM_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CHATROOM_MANAGER)) +#define EMPATHY_CHATROOM_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CHATROOM_MANAGER, EmpathyChatroomManagerClass)) + +typedef struct _EmpathyChatroomManager EmpathyChatroomManager; +typedef struct _EmpathyChatroomManagerClass EmpathyChatroomManagerClass; +typedef struct _EmpathyChatroomManagerPriv EmpathyChatroomManagerPriv; + +struct _EmpathyChatroomManager { + GObject parent; +}; + +struct _EmpathyChatroomManagerClass { + GObjectClass parent_class; +}; + +GType empathy_chatroom_manager_get_type (void) G_GNUC_CONST; +EmpathyChatroomManager *empathy_chatroom_manager_new (void); +gboolean empathy_chatroom_manager_add (EmpathyChatroomManager *manager, + EmpathyChatroom *chatroom); +void empathy_chatroom_manager_remove (EmpathyChatroomManager *manager, + EmpathyChatroom *chatroom); +EmpathyChatroom * empathy_chatroom_manager_find (EmpathyChatroomManager *manager, + McAccount *account, + const gchar *room); +GList * empathy_chatroom_manager_get_chatrooms (EmpathyChatroomManager *manager, + McAccount *account); +guint empathy_chatroom_manager_get_count (EmpathyChatroomManager *manager, + McAccount *account); +void empathy_chatroom_manager_store (EmpathyChatroomManager *manager); + +G_END_DECLS + +#endif /* __EMPATHY_CHATROOM_MANAGER_H__ */ diff --git a/libempathy/empathy-chatroom.c b/libempathy/empathy-chatroom.c new file mode 100644 index 000000000..a2d8ae61e --- /dev/null +++ b/libempathy/empathy-chatroom.c @@ -0,0 +1,362 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2007 Collabora Ltd. + * + * 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: Xavier Claessens + */ + +#include "config.h" + +#include + +#include + +#include "empathy-chatroom.h" +#include "empathy-utils.h" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CHATROOM, EmpathyChatroomPriv)) + +struct _EmpathyChatroomPriv { + McAccount *account; + gchar *room; + gchar *name; + gboolean auto_connect; +}; + +static void empathy_chatroom_class_init (EmpathyChatroomClass *klass); +static void empathy_chatroom_init (EmpathyChatroom *chatroom); +static void chatroom_finalize (GObject *object); +static void chatroom_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec); +static void chatroom_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec); + +enum { + PROP_0, + PROP_ACCOUNT, + PROP_ROOM, + PROP_NAME, + PROP_AUTO_CONNECT, +}; + +G_DEFINE_TYPE (EmpathyChatroom, empathy_chatroom, G_TYPE_OBJECT); + +static void +empathy_chatroom_class_init (EmpathyChatroomClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = chatroom_finalize; + object_class->get_property = chatroom_get_property; + object_class->set_property = chatroom_set_property; + + g_object_class_install_property (object_class, + PROP_ACCOUNT, + g_param_spec_object ("account", + "Chatroom Account", + "The account associated with an chatroom", + MC_TYPE_ACCOUNT, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_ROOM, + g_param_spec_string ("room", + "Chatroom Room", + "Chatroom represented as 'room@server'", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_NAME, + g_param_spec_string ("name", + "Chatroom Name", + "Chatroom name", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_AUTO_CONNECT, + g_param_spec_boolean ("auto_connect", + "Chatroom Auto Connect", + "Connect on startup", + FALSE, + G_PARAM_READWRITE)); + + + g_type_class_add_private (object_class, sizeof (EmpathyChatroomPriv)); +} + +static void +empathy_chatroom_init (EmpathyChatroom *chatroom) +{ +} + +static void +chatroom_finalize (GObject *object) +{ + EmpathyChatroomPriv *priv; + + priv = GET_PRIV (object); + + g_object_unref (priv->account); + g_free (priv->room); + g_free (priv->name); + + (G_OBJECT_CLASS (empathy_chatroom_parent_class)->finalize) (object); +} + +static void +chatroom_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyChatroomPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_ACCOUNT: + g_value_set_object (value, priv->account); + break; + case PROP_ROOM: + g_value_set_string (value, priv->room); + break; + case PROP_NAME: + g_value_set_string (value, priv->name); + break; + case PROP_AUTO_CONNECT: + g_value_set_boolean (value, priv->auto_connect); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +chatroom_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyChatroomPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_ACCOUNT: + empathy_chatroom_set_account (EMPATHY_CHATROOM (object), + g_value_get_object (value)); + break; + case PROP_ROOM: + empathy_chatroom_set_room (EMPATHY_CHATROOM (object), + g_value_get_string (value)); + break; + case PROP_NAME: + empathy_chatroom_set_name (EMPATHY_CHATROOM (object), + g_value_get_string (value)); + break; + case PROP_AUTO_CONNECT: + empathy_chatroom_set_auto_connect (EMPATHY_CHATROOM (object), + g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +EmpathyChatroom * +empathy_chatroom_new (McAccount *account, + const gchar *room) +{ + g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (room != NULL, NULL); + + return g_object_new (EMPATHY_TYPE_CHATROOM, + "account", account, + "room", room, + NULL); +} + +EmpathyChatroom * +empathy_chatroom_new_full (McAccount *account, + const gchar *room, + const gchar *name, + gboolean auto_connect) +{ + g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (room != NULL, NULL); + + return g_object_new (EMPATHY_TYPE_CHATROOM, + "account", account, + "room", room, + "name", name, + "auto_connect", auto_connect, + NULL); +} + +McAccount * +empathy_chatroom_get_account (EmpathyChatroom *chatroom) +{ + EmpathyChatroomPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), NULL); + + priv = GET_PRIV (chatroom); + return priv->account; +} + +void +empathy_chatroom_set_account (EmpathyChatroom *chatroom, + McAccount *account) +{ + EmpathyChatroomPriv *priv; + + g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom)); + g_return_if_fail (MC_IS_ACCOUNT (account)); + + priv = GET_PRIV (chatroom); + + if (account == priv->account) { + return; + } + if (priv->account) { + g_object_unref (priv->account); + } + priv->account = g_object_ref (account); + + g_object_notify (G_OBJECT (chatroom), "account"); +} + +const gchar * +empathy_chatroom_get_room (EmpathyChatroom *chatroom) +{ + EmpathyChatroomPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), NULL); + + priv = GET_PRIV (chatroom); + return priv->room; +} + +void +empathy_chatroom_set_room (EmpathyChatroom *chatroom, + const gchar *room) +{ + EmpathyChatroomPriv *priv; + + g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom)); + g_return_if_fail (room != NULL); + + priv = GET_PRIV (chatroom); + + g_free (priv->room); + priv->room = g_strdup (room); + + g_object_notify (G_OBJECT (chatroom), "room"); +} + +const gchar * +empathy_chatroom_get_name (EmpathyChatroom *chatroom) +{ + EmpathyChatroomPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), NULL); + + priv = GET_PRIV (chatroom); + + if (G_STR_EMPTY (priv->name)) { + return priv->room; + } + + return priv->name; +} + +void +empathy_chatroom_set_name (EmpathyChatroom *chatroom, + const gchar *name) +{ + EmpathyChatroomPriv *priv; + + g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom)); + + priv = GET_PRIV (chatroom); + + g_free (priv->name); + priv->name = NULL; + if (name) { + priv->name = g_strdup (name); + } + + g_object_notify (G_OBJECT (chatroom), "name"); +} + +gboolean +empathy_chatroom_get_auto_connect (EmpathyChatroom *chatroom) +{ + EmpathyChatroomPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), FALSE); + + priv = GET_PRIV (chatroom); + return priv->auto_connect; +} + +void +empathy_chatroom_set_auto_connect (EmpathyChatroom *chatroom, + gboolean auto_connect) +{ + EmpathyChatroomPriv *priv; + + g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom)); + + priv = GET_PRIV (chatroom); + + priv->auto_connect = auto_connect; + + g_object_notify (G_OBJECT (chatroom), "auto-connect"); +} + +gboolean +empathy_chatroom_equal (gconstpointer v1, + gconstpointer v2) +{ + McAccount *account_a; + McAccount *account_b; + const gchar *room_a; + const gchar *room_b; + + g_return_val_if_fail (EMPATHY_IS_CHATROOM (v1), FALSE); + g_return_val_if_fail (EMPATHY_IS_CHATROOM (v2), FALSE); + + account_a = empathy_chatroom_get_account (EMPATHY_CHATROOM (v1)); + account_b = empathy_chatroom_get_account (EMPATHY_CHATROOM (v2)); + + room_a = empathy_chatroom_get_room (EMPATHY_CHATROOM (v1)); + room_b = empathy_chatroom_get_room (EMPATHY_CHATROOM (v2)); + + return empathy_account_equal (account_a, account_b) && g_str_equal (room_a, room_b); +} + + diff --git a/libempathy/empathy-chatroom.h b/libempathy/empathy-chatroom.h new file mode 100644 index 000000000..20f98ecc6 --- /dev/null +++ b/libempathy/empathy-chatroom.h @@ -0,0 +1,78 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2007 Collabora Ltd. + * + * 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: Xavier Claessens + */ + +#ifndef __EMPATHY_CHATROOM_H__ +#define __EMPATHY_CHATROOM_H__ + +#include + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_CHATROOM (empathy_chatroom_get_type ()) +#define EMPATHY_CHATROOM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CHATROOM, EmpathyChatroom)) +#define EMPATHY_CHATROOM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_CHATROOM, EmpathyChatroomClass)) +#define EMPATHY_IS_CHATROOM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CHATROOM)) +#define EMPATHY_IS_CHATROOM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CHATROOM)) +#define EMPATHY_CHATROOM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CHATROOM, EmpathyChatroomClass)) + +#define EMPATHY_TYPE_CHATROOM_INVITE (empathy_chatroom_invite_get_gtype ()) + +typedef struct _EmpathyChatroom EmpathyChatroom; +typedef struct _EmpathyChatroomClass EmpathyChatroomClass; +typedef struct _EmpathyChatroomPriv EmpathyChatroomPriv; + +struct _EmpathyChatroom { + GObject parent; +}; + +struct _EmpathyChatroomClass { + GObjectClass parent_class; +}; + +GType empathy_chatroom_get_type (void) G_GNUC_CONST; +EmpathyChatroom *empathy_chatroom_new (McAccount *account, + const gchar *room); +EmpathyChatroom *empathy_chatroom_new_full (McAccount *account, + const gchar *room, + const gchar *name, + gboolean auto_connect); +McAccount * empathy_chatroom_get_account (EmpathyChatroom *chatroom); +void empathy_chatroom_set_account (EmpathyChatroom *chatroom, + McAccount *account); +const gchar * empathy_chatroom_get_room (EmpathyChatroom *chatroom); +void empathy_chatroom_set_room (EmpathyChatroom *chatroom, + const gchar *room); +const gchar * empathy_chatroom_get_name (EmpathyChatroom *chatroom); +void empathy_chatroom_set_name (EmpathyChatroom *chatroom, + const gchar *name); +gboolean empathy_chatroom_get_auto_connect (EmpathyChatroom *chatroom); +void empathy_chatroom_set_auto_connect (EmpathyChatroom *chatroom, + gboolean auto_connect); +gboolean empathy_chatroom_equal (gconstpointer v1, + gconstpointer v2); + + +G_BEGIN_DECLS + +#endif /* __EMPATHY_CHATROOM_H__ */ diff --git a/libempathy/empathy-conf.c b/libempathy/empathy-conf.c new file mode 100644 index 000000000..71e520f72 --- /dev/null +++ b/libempathy/empathy-conf.c @@ -0,0 +1,372 @@ +/* -*- 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 + */ + +#include "config.h" + +#include + +#include + +#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 new file mode 100644 index 000000000..7e8e60e25 --- /dev/null +++ b/libempathy/empathy-conf.h @@ -0,0 +1,87 @@ +/* -*- 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 + +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-list.c b/libempathy/empathy-contact-list.c index 3dd398c06..cc388d7ec 100644 --- a/libempathy/empathy-contact-list.c +++ b/libempathy/empathy-contact-list.c @@ -60,7 +60,7 @@ contact_list_base_init (gpointer klass) NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, - 1, GOSSIP_TYPE_CONTACT); + 1, EMPATHY_TYPE_CONTACT); g_signal_new ("contact-removed", G_TYPE_FROM_CLASS (klass), @@ -69,7 +69,7 @@ contact_list_base_init (gpointer klass) NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, - 1, GOSSIP_TYPE_CONTACT); + 1, EMPATHY_TYPE_CONTACT); g_signal_new ("local-pending", G_TYPE_FROM_CLASS (klass), @@ -78,19 +78,19 @@ contact_list_base_init (gpointer klass) NULL, NULL, empathy_marshal_VOID__OBJECT_STRING, G_TYPE_NONE, - 2, GOSSIP_TYPE_CONTACT, G_TYPE_STRING); + 2, EMPATHY_TYPE_CONTACT, G_TYPE_STRING); initialized = TRUE; } } EmpathyContactListInfo * -empathy_contact_list_info_new (GossipContact *contact, +empathy_contact_list_info_new (EmpathyContact *contact, const gchar *message) { EmpathyContactListInfo *info; - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL); + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); info = g_slice_new0 (EmpathyContactListInfo); info->contact = g_object_ref (contact); @@ -124,7 +124,7 @@ empathy_contact_list_setup (EmpathyContactList *list) } } -GossipContact * +EmpathyContact * empathy_contact_list_find (EmpathyContactList *list, const gchar *id) { @@ -139,7 +139,7 @@ empathy_contact_list_find (EmpathyContactList *list, void empathy_contact_list_add (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message) { g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list)); @@ -151,7 +151,7 @@ empathy_contact_list_add (EmpathyContactList *list, void empathy_contact_list_remove (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message) { g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list)); @@ -187,7 +187,7 @@ empathy_contact_list_get_local_pending (EmpathyContactList *list) void empathy_contact_list_process_pending (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, gboolean accept) { g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list)); diff --git a/libempathy/empathy-contact-list.h b/libempathy/empathy-contact-list.h index c1f9b41e4..959f5c51f 100644 --- a/libempathy/empathy-contact-list.h +++ b/libempathy/empathy-contact-list.h @@ -25,7 +25,7 @@ #include -#include "gossip-contact.h" +#include "empathy-contact.h" G_BEGIN_DECLS @@ -38,7 +38,7 @@ typedef struct _EmpathyContactList EmpathyContactList; typedef struct _EmpathyContactListIface EmpathyContactListIface; typedef struct { - GossipContact *contact; + EmpathyContact *contact; gchar *message; } EmpathyContactListInfo; @@ -47,38 +47,38 @@ struct _EmpathyContactListIface { /* VTabled */ void (*setup) (EmpathyContactList *list); - GossipContact * (*find) (EmpathyContactList *list, + EmpathyContact * (*find) (EmpathyContactList *list, const gchar *id); void (*add) (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message); void (*remove) (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message); GList * (*get_members) (EmpathyContactList *list); GList * (*get_local_pending) (EmpathyContactList *list); void (*process_pending) (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, gboolean accept); }; GType empathy_contact_list_get_type (void) G_GNUC_CONST; -EmpathyContactListInfo *empathy_contact_list_info_new (GossipContact *contact, +EmpathyContactListInfo *empathy_contact_list_info_new (EmpathyContact *contact, const gchar *message); void empathy_contact_list_info_free (EmpathyContactListInfo *info); void empathy_contact_list_setup (EmpathyContactList *list); -GossipContact * empathy_contact_list_find (EmpathyContactList *list, +EmpathyContact * empathy_contact_list_find (EmpathyContactList *list, const gchar *id); void empathy_contact_list_add (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message); void empathy_contact_list_remove (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message); GList * empathy_contact_list_get_members (EmpathyContactList *list); GList * empathy_contact_list_get_local_pending (EmpathyContactList *list); void empathy_contact_list_process_pending (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, gboolean accept); G_END_DECLS diff --git a/libempathy/empathy-contact-manager.c b/libempathy/empathy-contact-manager.c index 7f8cdfed5..cc00108c8 100644 --- a/libempathy/empathy-contact-manager.c +++ b/libempathy/empathy-contact-manager.c @@ -28,8 +28,8 @@ #include "empathy-contact-manager.h" #include "empathy-contact-list.h" -#include "gossip-utils.h" -#include "gossip-debug.h" +#include "empathy-utils.h" +#include "empathy-debug.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ EMPATHY_TYPE_CONTACT_MANAGER, EmpathyContactManagerPriv)) @@ -48,7 +48,7 @@ typedef struct { } ContactManagerRenameGroupData; typedef struct { - GossipContact *contact; + EmpathyContact *contact; const gchar *id; } ContactManagerFindData; @@ -57,18 +57,18 @@ static void contact_manager_iface_init (EmpathyContactListIf static void empathy_contact_manager_init (EmpathyContactManager *manager); static void contact_manager_finalize (GObject *object); static void contact_manager_setup (EmpathyContactList *manager); -static GossipContact *contact_manager_find (EmpathyContactList *manager, +static EmpathyContact *contact_manager_find (EmpathyContactList *manager, const gchar *id); static void contact_manager_add (EmpathyContactList *manager, - GossipContact *contact, + EmpathyContact *contact, const gchar *message); static void contact_manager_remove (EmpathyContactList *manager, - GossipContact *contact, + EmpathyContact *contact, const gchar *message); static GList * contact_manager_get_members (EmpathyContactList *manager); static GList * contact_manager_get_local_pending (EmpathyContactList *manager); static void contact_manager_process_pending (EmpathyContactList *manager, - GossipContact *contact, + EmpathyContact *contact, gboolean accept); static void contact_manager_setup_foreach (McAccount *account, EmpathyTpContactList *list, @@ -79,13 +79,13 @@ static gboolean contact_manager_find_foreach (McAccount static void contact_manager_add_account (EmpathyContactManager *manager, McAccount *account); static void contact_manager_added_cb (EmpathyTpContactList *list, - GossipContact *contact, + EmpathyContact *contact, EmpathyContactManager *manager); static void contact_manager_removed_cb (EmpathyTpContactList *list, - GossipContact *contact, + EmpathyContact *contact, EmpathyContactManager *manager); static void contact_manager_local_pending_cb (EmpathyTpContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message, EmpathyContactManager *manager); static void contact_manager_destroy_cb (EmpathyTpContactList *list, @@ -143,12 +143,12 @@ empathy_contact_manager_init (EmpathyContactManager *manager) priv = GET_PRIV (manager); - priv->lists = g_hash_table_new_full (gossip_account_hash, - gossip_account_equal, + priv->lists = g_hash_table_new_full (empathy_account_hash, + empathy_account_equal, (GDestroyNotify) g_object_unref, (GDestroyNotify) g_object_unref); - priv->mc = gossip_mission_control_new (); + priv->mc = empathy_mission_control_new (); dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged", @@ -215,7 +215,7 @@ contact_manager_setup (EmpathyContactList *manager) priv->setup = TRUE; } -static GossipContact * +static EmpathyContact * contact_manager_find (EmpathyContactList *manager, const gchar *id) { @@ -239,7 +239,7 @@ contact_manager_find (EmpathyContactList *manager, static void contact_manager_add (EmpathyContactList *manager, - GossipContact *contact, + EmpathyContact *contact, const gchar *message) { EmpathyContactManagerPriv *priv; @@ -247,11 +247,11 @@ contact_manager_add (EmpathyContactList *manager, McAccount *account; g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager)); - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); priv = GET_PRIV (manager); - account = gossip_contact_get_account (contact); + account = empathy_contact_get_account (contact); list = g_hash_table_lookup (priv->lists, account); if (list) { @@ -261,7 +261,7 @@ contact_manager_add (EmpathyContactList *manager, static void contact_manager_remove (EmpathyContactList *manager, - GossipContact *contact, + EmpathyContact *contact, const gchar *message) { EmpathyContactManagerPriv *priv; @@ -269,11 +269,11 @@ contact_manager_remove (EmpathyContactList *manager, McAccount *account; g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager)); - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); priv = GET_PRIV (manager); - account = gossip_contact_get_account (contact); + account = empathy_contact_get_account (contact); list = g_hash_table_lookup (priv->lists, account); if (list) { @@ -317,7 +317,7 @@ contact_manager_get_local_pending (EmpathyContactList *manager) static void contact_manager_process_pending (EmpathyContactList *manager, - GossipContact *contact, + EmpathyContact *contact, gboolean accept) { EmpathyContactManagerPriv *priv; @@ -325,11 +325,11 @@ contact_manager_process_pending (EmpathyContactList *manager, McAccount *account; g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager)); - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); priv = GET_PRIV (manager); - account = gossip_contact_get_account (contact); + account = empathy_contact_get_account (contact); list = g_hash_table_lookup (priv->lists, account); if (list) { @@ -351,7 +351,7 @@ empathy_contact_manager_get_list (EmpathyContactManager *manager, return g_hash_table_lookup (priv->lists, account); } -GossipContact * +EmpathyContact * empathy_contact_manager_get_user (EmpathyContactManager *manager, McAccount *account) { @@ -372,7 +372,7 @@ empathy_contact_manager_get_user (EmpathyContactManager *manager, return empathy_tp_contact_list_get_user (list); } -GossipContact * +EmpathyContact * empathy_contact_manager_create (EmpathyContactManager *manager, McAccount *account, const gchar *id) @@ -470,7 +470,7 @@ contact_manager_add_account (EmpathyContactManager *manager, return; } - gossip_debug (DEBUG_DOMAIN, "Adding new account: %s", + empathy_debug (DEBUG_DOMAIN, "Adding new account: %s", mc_account_get_display_name (account)); list = empathy_tp_contact_list_new (account); @@ -501,7 +501,7 @@ contact_manager_add_account (EmpathyContactManager *manager, static void contact_manager_added_cb (EmpathyTpContactList *list, - GossipContact *contact, + EmpathyContact *contact, EmpathyContactManager *manager) { g_signal_emit_by_name (manager, "contact-added", contact); @@ -509,7 +509,7 @@ contact_manager_added_cb (EmpathyTpContactList *list, static void contact_manager_removed_cb (EmpathyTpContactList *list, - GossipContact *contact, + EmpathyContact *contact, EmpathyContactManager *manager) { g_signal_emit_by_name (manager, "contact-removed", contact); @@ -517,7 +517,7 @@ contact_manager_removed_cb (EmpathyTpContactList *list, static void contact_manager_local_pending_cb (EmpathyTpContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message, EmpathyContactManager *manager) { @@ -535,7 +535,7 @@ contact_manager_destroy_cb (EmpathyTpContactList *list, account = empathy_tp_contact_list_get_account (list); - gossip_debug (DEBUG_DOMAIN, "Removing account: %s", + empathy_debug (DEBUG_DOMAIN, "Removing account: %s", mc_account_get_display_name (account)); /* Disconnect signals from the list */ diff --git a/libempathy/empathy-contact-manager.h b/libempathy/empathy-contact-manager.h index db893b486..768301ae7 100644 --- a/libempathy/empathy-contact-manager.h +++ b/libempathy/empathy-contact-manager.h @@ -27,7 +27,7 @@ #include -#include "gossip-contact.h" +#include "empathy-contact.h" #include "empathy-tp-contact-list.h" G_BEGIN_DECLS @@ -55,9 +55,9 @@ GType empathy_contact_manager_get_type (void) G_GNUC_CONST; EmpathyContactManager *empathy_contact_manager_new (void); EmpathyTpContactList * empathy_contact_manager_get_list (EmpathyContactManager *manager, McAccount *account); -GossipContact * empathy_contact_manager_get_user (EmpathyContactManager *manager, +EmpathyContact * empathy_contact_manager_get_user (EmpathyContactManager *manager, McAccount *account); -GossipContact * empathy_contact_manager_create (EmpathyContactManager *manager, +EmpathyContact * empathy_contact_manager_create (EmpathyContactManager *manager, McAccount *account, const gchar *id); void empathy_contact_manager_rename_group (EmpathyContactManager *manager, diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c new file mode 100644 index 000000000..774a18f77 --- /dev/null +++ b/libempathy/empathy-contact.c @@ -0,0 +1,800 @@ +/* -*- 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 + * Martyn Russell + */ + +#include "config.h" + +#include + +#include + +#include "empathy-contact.h" +#include "empathy-utils.h" +#include "empathy-debug.h" + +#define DEBUG_DOMAIN "Contact" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT, EmpathyContactPriv)) + +typedef struct _EmpathyContactPriv EmpathyContactPriv; + +struct _EmpathyContactPriv { + gchar *id; + gchar *name; + EmpathyAvatar *avatar; + McAccount *account; + EmpathyPresence *presence; + GList *groups; + EmpathySubscription subscription; + guint handle; + gboolean is_user; +}; + +static void contact_class_init (EmpathyContactClass *class); +static void contact_init (EmpathyContact *contact); +static void contact_finalize (GObject *object); +static void contact_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec); +static void contact_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec); + +enum { + PROP_0, + PROP_ID, + PROP_NAME, + PROP_AVATAR, + PROP_ACCOUNT, + PROP_PRESENCE, + PROP_GROUPS, + PROP_SUBSCRIPTION, + PROP_HANDLE, + PROP_IS_USER +}; + +static gpointer parent_class = NULL; + +GType +empathy_contact_get_gtype (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (EmpathyContactClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) contact_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (EmpathyContact), + 0, /* n_preallocs */ + (GInstanceInitFunc) contact_init + }; + + type = g_type_register_static (G_TYPE_OBJECT, + "EmpathyContact", + &info, 0); + } + + return type; +} + +static void +contact_class_init (EmpathyContactClass *class) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (class); + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = contact_finalize; + object_class->get_property = contact_get_property; + object_class->set_property = contact_set_property; + + g_object_class_install_property (object_class, + PROP_ID, + g_param_spec_string ("id", + "Contact id", + "String identifying contact", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_NAME, + g_param_spec_string ("name", + "Contact Name", + "The name of the contact", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_AVATAR, + g_param_spec_boxed ("avatar", + "Avatar image", + "The avatar image", + EMPATHY_TYPE_AVATAR, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_ACCOUNT, + g_param_spec_object ("account", + "Contact Account", + "The account associated with the contact", + MC_TYPE_ACCOUNT, + G_PARAM_READWRITE)); + + 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_object_class_install_property (object_class, + PROP_GROUPS, + g_param_spec_pointer ("groups", + "Contact groups", + "Groups of contact", + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_SUBSCRIPTION, + g_param_spec_int ("subscription", + "Contact Subscription", + "The subscription status of the contact", + EMPATHY_SUBSCRIPTION_NONE, + EMPATHY_SUBSCRIPTION_BOTH, + EMPATHY_SUBSCRIPTION_NONE, + G_PARAM_READWRITE)); + + + g_object_class_install_property (object_class, + PROP_HANDLE, + g_param_spec_uint ("handle", + "Contact Handle", + "The handle of the contact", + 0, + G_MAXUINT, + 0, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_IS_USER, + g_param_spec_boolean ("is-user", + "Contact is-user", + "Is contact the user", + FALSE, + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (EmpathyContactPriv)); +} + +static void +contact_init (EmpathyContact *contact) +{ +} + +static void +contact_finalize (GObject *object) +{ + EmpathyContactPriv *priv; + + priv = GET_PRIV (object); + + empathy_debug (DEBUG_DOMAIN, "finalize: %p", object); + + g_free (priv->name); + g_free (priv->id); + + if (priv->avatar) { + empathy_avatar_unref (priv->avatar); + } + + if (priv->presence) { + g_object_unref (priv->presence); + } + + if (priv->groups) { + g_list_foreach (priv->groups, (GFunc) g_free, NULL); + g_list_free (priv->groups); + } + + if (priv->account) { + g_object_unref (priv->account); + } + + (G_OBJECT_CLASS (parent_class)->finalize) (object); +} + +static void +contact_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyContactPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_ID: + g_value_set_string (value, + empathy_contact_get_id (EMPATHY_CONTACT (object))); + break; + case PROP_NAME: + g_value_set_string (value, + empathy_contact_get_name (EMPATHY_CONTACT (object))); + break; + case PROP_AVATAR: + g_value_set_boxed (value, priv->avatar); + break; + case PROP_ACCOUNT: + g_value_set_object (value, priv->account); + break; + case PROP_PRESENCE: + g_value_set_object (value, priv->presence); + break; + case PROP_GROUPS: + g_value_set_pointer (value, priv->groups); + break; + case PROP_SUBSCRIPTION: + g_value_set_int (value, priv->subscription); + break; + case PROP_HANDLE: + g_value_set_uint (value, priv->handle); + break; + case PROP_IS_USER: + g_value_set_boolean (value, priv->is_user); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +contact_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyContactPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_ID: + empathy_contact_set_id (EMPATHY_CONTACT (object), + g_value_get_string (value)); + break; + case PROP_NAME: + empathy_contact_set_name (EMPATHY_CONTACT (object), + g_value_get_string (value)); + break; + case PROP_AVATAR: + empathy_contact_set_avatar (EMPATHY_CONTACT (object), + g_value_get_boxed (value)); + break; + case PROP_ACCOUNT: + empathy_contact_set_account (EMPATHY_CONTACT (object), + MC_ACCOUNT (g_value_get_object (value))); + break; + case PROP_PRESENCE: + empathy_contact_set_presence (EMPATHY_CONTACT (object), + EMPATHY_PRESENCE (g_value_get_object (value))); + break; + case PROP_GROUPS: + empathy_contact_set_groups (EMPATHY_CONTACT (object), + g_value_get_pointer (value)); + break; + case PROP_SUBSCRIPTION: + empathy_contact_set_subscription (EMPATHY_CONTACT (object), + g_value_get_int (value)); + break; + case PROP_HANDLE: + empathy_contact_set_handle (EMPATHY_CONTACT (object), + g_value_get_uint (value)); + break; + case PROP_IS_USER: + empathy_contact_set_is_user (EMPATHY_CONTACT (object), + g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +EmpathyContact * +empathy_contact_new (McAccount *account) +{ + return g_object_new (EMPATHY_TYPE_CONTACT, + "account", account, + NULL); +} + +EmpathyContact * +empathy_contact_new_full (McAccount *account, + const gchar *id, + const gchar *name) +{ + return g_object_new (EMPATHY_TYPE_CONTACT, + "account", account, + "name", name, + "id", id, + NULL); +} + +const gchar * +empathy_contact_get_id (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), ""); + + priv = GET_PRIV (contact); + + if (priv->id) { + return priv->id; + } + + return ""; +} + +const gchar * +empathy_contact_get_name (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), ""); + + priv = GET_PRIV (contact); + + if (G_STR_EMPTY (priv->name)) { + return empathy_contact_get_id (contact); + } + + return priv->name; +} + +EmpathyAvatar * +empathy_contact_get_avatar (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + + priv = GET_PRIV (contact); + + return priv->avatar; +} + +McAccount * +empathy_contact_get_account (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + + priv = GET_PRIV (contact); + + return priv->account; +} + +EmpathyPresence * +empathy_contact_get_presence (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + + priv = GET_PRIV (contact); + + return priv->presence; +} + +GList * +empathy_contact_get_groups (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + + priv = GET_PRIV (contact); + + return priv->groups; +} + +EmpathySubscription +empathy_contact_get_subscription (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), + EMPATHY_SUBSCRIPTION_NONE); + + priv = GET_PRIV (contact); + + return priv->subscription; +} + +guint +empathy_contact_get_handle (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0); + + priv = GET_PRIV (contact); + + return priv->handle; +} + +gboolean +empathy_contact_is_user (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE); + + priv = GET_PRIV (contact); + + return priv->is_user; +} + +void +empathy_contact_set_id (EmpathyContact *contact, + const gchar *id) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + g_return_if_fail (id != NULL); + + priv = GET_PRIV (contact); + + if (priv->id && strcmp (id, priv->id) == 0) { + return; + } + + g_free (priv->id); + priv->id = g_strdup (id); + + g_object_notify (G_OBJECT (contact), "id"); +} + +void +empathy_contact_set_name (EmpathyContact *contact, + const gchar *name) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + g_return_if_fail (name != NULL); + + priv = GET_PRIV (contact); + + if (priv->name && strcmp (name, priv->name) == 0) { + return; + } + + g_free (priv->name); + priv->name = g_strdup (name); + + g_object_notify (G_OBJECT (contact), "name"); +} + +void +empathy_contact_set_avatar (EmpathyContact *contact, + EmpathyAvatar *avatar) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + priv = GET_PRIV (contact); + + if (priv->avatar == avatar) { + return; + } + + if (priv->avatar) { + empathy_avatar_unref (priv->avatar); + priv->avatar = NULL; + } + + if (avatar) { + priv->avatar = empathy_avatar_ref (avatar); + } + + g_object_notify (G_OBJECT (contact), "avatar"); +} + +void +empathy_contact_set_account (EmpathyContact *contact, + McAccount *account) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + g_return_if_fail (MC_IS_ACCOUNT (account)); + + priv = GET_PRIV (contact); + + if (account == priv->account) { + return; + } + + if (priv->account) { + g_object_unref (priv->account); + } + priv->account = g_object_ref (account); + + g_object_notify (G_OBJECT (contact), "account"); +} + +void +empathy_contact_set_presence (EmpathyContact *contact, + EmpathyPresence *presence) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + priv = GET_PRIV (contact); + + if (presence == priv->presence) { + return; + } + + if (priv->presence) { + g_object_unref (priv->presence); + priv->presence = NULL; + } + + if (presence) { + priv->presence = g_object_ref (presence); + } + + g_object_notify (G_OBJECT (contact), "presence"); +} + +void +empathy_contact_set_groups (EmpathyContact *contact, + GList *groups) +{ + EmpathyContactPriv *priv; + GList *old_groups, *l; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + priv = GET_PRIV (contact); + + old_groups = priv->groups; + priv->groups = NULL; + + for (l = groups; l; l = l->next) { + priv->groups = g_list_append (priv->groups, + g_strdup (l->data)); + } + + g_list_foreach (old_groups, (GFunc) g_free, NULL); + g_list_free (old_groups); + + g_object_notify (G_OBJECT (contact), "groups"); +} + +void +empathy_contact_set_subscription (EmpathyContact *contact, + EmpathySubscription subscription) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + priv = GET_PRIV (contact); + + if (priv->subscription == subscription) { + return; + } + + priv->subscription = subscription; + + g_object_notify (G_OBJECT (contact), "subscription"); +} + +void +empathy_contact_set_handle (EmpathyContact *contact, + guint handle) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + priv = GET_PRIV (contact); + + if (priv->handle == handle) { + return; + } + + priv->handle = handle; + + g_object_notify (G_OBJECT (contact), "handle"); +} + +void +empathy_contact_set_is_user (EmpathyContact *contact, + gboolean is_user) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + priv = GET_PRIV (contact); + + if (priv->is_user == is_user) { + return; + } + + priv->is_user = is_user; + + g_object_notify (G_OBJECT (contact), "is-user"); +} + +void +empathy_contact_add_group (EmpathyContact *contact, + const gchar *group) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + g_return_if_fail (group != NULL); + + priv = GET_PRIV (contact); + + if (!g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp)) { + priv->groups = g_list_prepend (priv->groups, g_strdup (group)); + g_object_notify (G_OBJECT (contact), "groups"); + } +} + +void +empathy_contact_remove_group (EmpathyContact *contact, + const gchar *group) +{ + EmpathyContactPriv *priv; + GList *l; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + g_return_if_fail (group != NULL); + + priv = GET_PRIV (contact); + + l = g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp); + if (l) { + g_free (l->data); + priv->groups = g_list_delete_link (priv->groups, l); + g_object_notify (G_OBJECT (contact), "groups"); + } +} + +gboolean +empathy_contact_is_online (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE); + + priv = GET_PRIV (contact); + + if (!priv->presence) { + return FALSE; + } + + return (empathy_presence_get_state (priv->presence) > MC_PRESENCE_OFFLINE); +} + +gboolean +empathy_contact_is_in_group (EmpathyContact *contact, + const gchar *group) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE); + g_return_val_if_fail (!G_STR_EMPTY (group), FALSE); + + priv = GET_PRIV (contact); + + if (g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp)) { + return TRUE; + } + + return FALSE; +} + +const gchar * +empathy_contact_get_status (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (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; + } + + return empathy_presence_state_get_default_status (MC_PRESENCE_OFFLINE); +} + +gboolean +empathy_contact_equal (gconstpointer v1, + gconstpointer v2) +{ + McAccount *account_a; + McAccount *account_b; + const gchar *id_a; + const gchar *id_b; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (v1), FALSE); + g_return_val_if_fail (EMPATHY_IS_CONTACT (v2), FALSE); + + account_a = empathy_contact_get_account (EMPATHY_CONTACT (v1)); + account_b = empathy_contact_get_account (EMPATHY_CONTACT (v2)); + + id_a = empathy_contact_get_id (EMPATHY_CONTACT (v1)); + id_b = empathy_contact_get_id (EMPATHY_CONTACT (v2)); + + return empathy_account_equal (account_a, account_b) && g_str_equal (id_a, id_b); +} + +guint +empathy_contact_hash (gconstpointer key) +{ + EmpathyContactPriv *priv; + guint hash; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (key), +1); + + priv = GET_PRIV (EMPATHY_CONTACT (key)); + + hash = empathy_account_hash (empathy_contact_get_account (EMPATHY_CONTACT (key))); + hash += g_str_hash (empathy_contact_get_id (EMPATHY_CONTACT (key))); + + return hash; +} + diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h new file mode 100644 index 000000000..b32d451bb --- /dev/null +++ b/libempathy/empathy-contact.h @@ -0,0 +1,106 @@ +/* -*- 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_CONTACT_H__ +#define __EMPATHY_CONTACT_H__ + +#include + +#include + +#include "empathy-avatar.h" +#include "empathy-presence.h" + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_CONTACT (empathy_contact_get_gtype ()) +#define EMPATHY_CONTACT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CONTACT, EmpathyContact)) +#define EMPATHY_CONTACT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_CONTACT, EmpathyContactClass)) +#define EMPATHY_IS_CONTACT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CONTACT)) +#define EMPATHY_IS_CONTACT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CONTACT)) +#define EMPATHY_CONTACT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CONTACT, EmpathyContactClass)) + +typedef struct _EmpathyContact EmpathyContact; +typedef struct _EmpathyContactClass EmpathyContactClass; + +struct _EmpathyContact { + GObject parent; +}; + +struct _EmpathyContactClass { + GObjectClass parent_class; +}; + +typedef enum { + EMPATHY_SUBSCRIPTION_NONE = 0, + EMPATHY_SUBSCRIPTION_TO = 1 << 0, /* We send our presence to that contact */ + EMPATHY_SUBSCRIPTION_FROM = 1 << 1, /* That contact sends his presence to us */ + EMPATHY_SUBSCRIPTION_BOTH = EMPATHY_SUBSCRIPTION_TO | EMPATHY_SUBSCRIPTION_FROM +} EmpathySubscription; + +GType empathy_contact_get_gtype (void) G_GNUC_CONST; + +EmpathyContact * empathy_contact_new (McAccount *account); +EmpathyContact * empathy_contact_new_full (McAccount *account, + const gchar *id, + const gchar *name); +const gchar * empathy_contact_get_id (EmpathyContact *contact); +const gchar * empathy_contact_get_name (EmpathyContact *contact); +EmpathyAvatar * empathy_contact_get_avatar (EmpathyContact *contact); +McAccount * empathy_contact_get_account (EmpathyContact *contact); +EmpathyPresence * empathy_contact_get_presence (EmpathyContact *contact); +GList * empathy_contact_get_groups (EmpathyContact *contact); +EmpathySubscription empathy_contact_get_subscription (EmpathyContact *contact); +guint empathy_contact_get_handle (EmpathyContact *contact); +gboolean empathy_contact_is_user (EmpathyContact *contact); +void empathy_contact_set_id (EmpathyContact *contact, + const gchar *id); +void empathy_contact_set_name (EmpathyContact *contact, + const gchar *name); +void empathy_contact_set_avatar (EmpathyContact *contact, + EmpathyAvatar *avatar); +void empathy_contact_set_account (EmpathyContact *contact, + McAccount *account); +void empathy_contact_set_presence (EmpathyContact *contact, + EmpathyPresence *presence); +void empathy_contact_set_groups (EmpathyContact *contact, + GList *categories); +void empathy_contact_set_subscription (EmpathyContact *contact, + EmpathySubscription subscription); +void empathy_contact_set_handle (EmpathyContact *contact, + guint handle); +void empathy_contact_set_is_user (EmpathyContact *contact, + gboolean is_user); +void empathy_contact_add_group (EmpathyContact *contact, + const gchar *group); +void empathy_contact_remove_group (EmpathyContact *contact, + const gchar *group); +gboolean empathy_contact_is_online (EmpathyContact *contact); +gboolean empathy_contact_is_in_group (EmpathyContact *contact, + const gchar *group); +const gchar * empathy_contact_get_status (EmpathyContact *contact); +gboolean empathy_contact_equal (gconstpointer v1, + gconstpointer v2); +guint empathy_contact_hash (gconstpointer key); + +G_END_DECLS + +#endif /* __EMPATHY_CONTACT_H__ */ + diff --git a/libempathy/empathy-debug.c b/libempathy/empathy-debug.c new file mode 100644 index 000000000..2f5658499 --- /dev/null +++ b/libempathy/empathy-debug.c @@ -0,0 +1,92 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2006-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: Richard Hult + */ + +#include "config.h" + +#include +#include + +#include +#include + +/* Set EMPATHY_DEBUG to a colon/comma/space separated list of domains, or "all" + * to get all debug output. + */ + +#include "empathy-debug.h" + +static gchar **debug_strv; +static gboolean all_domains = FALSE; + +static void +debug_init (void) +{ + static gboolean inited = FALSE; + + if (!inited) { + const gchar *env; + gint i; + + env = g_getenv ("EMPATHY_DEBUG"); + + if (env) { + debug_strv = g_strsplit_set (env, ":, ", 0); + } else { + debug_strv = NULL; + } + + for (i = 0; debug_strv && debug_strv[i]; i++) { + if (strcmp ("all", debug_strv[i]) == 0) { + all_domains = TRUE; + } + } + + inited = TRUE; + } +} + +void +empathy_debug_impl (const gchar *domain, const gchar *msg, ...) +{ + gint i; + + g_return_if_fail (domain != NULL); + g_return_if_fail (msg != NULL); + + debug_init (); + + for (i = 0; debug_strv && debug_strv[i]; i++) { + if (all_domains || strcmp (domain, debug_strv[i]) == 0) { + va_list args; + + g_print ("%s: ", domain); + + va_start (args, msg); + g_vprintf (msg, args); + va_end (args); + + g_print ("\n"); + break; + } + } +} + diff --git a/libempathy/empathy-debug.h b/libempathy/empathy-debug.h new file mode 100644 index 000000000..19d2aa380 --- /dev/null +++ b/libempathy/empathy-debug.h @@ -0,0 +1,53 @@ +/* -*- 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_DEBUG_H__ +#define __EMPATHY_DEBUG_H__ + +#include + +G_BEGIN_DECLS + +#ifdef G_HAVE_ISO_VARARGS +# ifdef EMPATHY_DISABLE_DEBUG +# define empathy_debug(...) +# else +# define empathy_debug(...) empathy_debug_impl (__VA_ARGS__) +# endif +#elif defined(G_HAVE_GNUC_VARARGS) +# if EMPATHY_DISABLE_DEBUG +# define empathy_debug(fmt...) +# else +# define empathy_debug(fmt...) empathy_debug_impl(fmt) +# endif +#else +# if EMPATHY_DISABLE_DEBUG +# define empathy_debug(x) +# else +# define empathy_debug empathy_debug_impl +# endif +#endif + +void empathy_debug_impl (const gchar *domain, const gchar *msg, ...); + +G_END_DECLS + +#endif /* __EMPATHY_DEBUG_H__ */ + diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 8150effd3..5b04d363f 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -30,8 +30,8 @@ #include #include "empathy-idle.h" -#include "gossip-utils.h" -#include "gossip-debug.h" +#include "empathy-utils.h" +#include "empathy-debug.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ EMPATHY_TYPE_IDLE, EmpathyIdlePriv)) @@ -144,7 +144,7 @@ empathy_idle_init (EmpathyIdle *idle) priv = GET_PRIV (idle); priv->is_idle = FALSE; - priv->mc = gossip_mission_control_new (); + 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); @@ -165,13 +165,13 @@ empathy_idle_init (EmpathyIdle *idle) G_CALLBACK (idle_session_idle_changed_cb), idle, NULL); } else { - gossip_debug (DEBUG_DOMAIN, "Failed to get gs proxy"); + empathy_debug (DEBUG_DOMAIN, "Failed to get gs proxy"); } system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (!system_bus) { - gossip_debug (DEBUG_DOMAIN, "Failed to get system bus: %s", + empathy_debug (DEBUG_DOMAIN, "Failed to get system bus: %s", error ? error->message : "No error given"); } else { priv->nm_proxy = dbus_g_proxy_new_for_name (system_bus, @@ -186,7 +186,7 @@ empathy_idle_init (EmpathyIdle *idle) G_CALLBACK (idle_nm_state_change_cb), idle, NULL); } else { - gossip_debug (DEBUG_DOMAIN, "Failed to get nm proxy"); + empathy_debug (DEBUG_DOMAIN, "Failed to get nm proxy"); } /* FIXME: get value */ priv->nm_connected = TRUE; @@ -310,7 +310,7 @@ empathy_idle_get_status (EmpathyIdle *idle) priv = GET_PRIV (idle); if (!priv->status) { - return gossip_presence_state_get_default_status (priv->state); + return empathy_presence_state_get_default_status (priv->state); } return priv->status; @@ -371,7 +371,7 @@ empathy_idle_set_presence (EmpathyIdle *idle, } /* Do not set translated default messages */ - default_status = gossip_presence_state_get_default_status (state); + default_status = empathy_presence_state_get_default_status (state); if (status && strcmp (status, default_status) == 0) { status = NULL; } @@ -413,7 +413,7 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy, priv = GET_PRIV (idle); - gossip_debug (DEBUG_DOMAIN, "Session idle state changed, %s -> %s", + empathy_debug (DEBUG_DOMAIN, "Session idle state changed, %s -> %s", priv->is_idle ? "yes" : "no", is_idle ? "yes" : "no"); @@ -441,7 +441,7 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy, priv->saved_status = g_strdup (priv->status); } - gossip_debug (DEBUG_DOMAIN, "Going to autoaway"); + empathy_debug (DEBUG_DOMAIN, "Going to autoaway"); empathy_idle_set_state (idle, new_state); idle_ext_away_start (idle); @@ -449,7 +449,7 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy, /* We are no more idle, restore state */ idle_ext_away_stop (idle); - gossip_debug (DEBUG_DOMAIN, "Restoring state to %d %s", + empathy_debug (DEBUG_DOMAIN, "Restoring state to %d %s", priv->saved_state, priv->saved_status); @@ -473,7 +473,7 @@ idle_nm_state_change_cb (DBusGProxy *proxy, priv = GET_PRIV (idle); - gossip_debug (DEBUG_DOMAIN, "New network state (%d)", state); + empathy_debug (DEBUG_DOMAIN, "New network state (%d)", state); if (state != NM_STATE_CONNECTED && priv->state > MC_PRESENCE_OFFLINE) { @@ -529,7 +529,7 @@ idle_ext_away_cb (EmpathyIdle *idle) priv = GET_PRIV (idle); - gossip_debug (DEBUG_DOMAIN, "Going to extended autoaway"); + empathy_debug (DEBUG_DOMAIN, "Going to extended autoaway"); empathy_idle_set_state (idle, MC_PRESENCE_EXTENDED_AWAY); priv->ext_away_timeout = 0; diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c index afb40a533..f7e3540fc 100644 --- a/libempathy/empathy-log-manager.c +++ b/libempathy/empathy-log-manager.c @@ -27,10 +27,10 @@ #include #include "empathy-log-manager.h" -#include "gossip-contact.h" -#include "gossip-time.h" -#include "gossip-debug.h" -#include "gossip-utils.h" +#include "empathy-contact.h" +#include "empathy-time.h" +#include "empathy-debug.h" +#include "empathy-utils.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ EMPATHY_TYPE_LOG_MANAGER, EmpathyLogManagerPriv)) @@ -45,7 +45,7 @@ #define LOG_TIME_FORMAT "%Y%m%d" #define LOG_HEADER \ "\n" \ - "\n" \ + "\n" \ "\n" #define LOG_FOOTER \ @@ -78,7 +78,7 @@ static gchar * log_manager_get_filename_for_date (EmpathyLogMa gboolean chatroom, const gchar *date); static gchar * log_manager_get_timestamp_filename (void); -static gchar * log_manager_get_timestamp_from_message (GossipMessage *message); +static gchar * log_manager_get_timestamp_from_message (EmpathyMessage *message); static EmpathyLogSearchHit *log_manager_search_hit_new (EmpathyLogManager *manager, const gchar *filename); @@ -128,11 +128,11 @@ void empathy_log_manager_add_message (EmpathyLogManager *manager, const gchar *chat_id, gboolean chatroom, - GossipMessage *message) + EmpathyMessage *message) { FILE *file; McAccount *account; - GossipContact *sender; + EmpathyContact *sender; const gchar *body_str; const gchar *str; gchar *filename; @@ -144,11 +144,11 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, g_return_if_fail (EMPATHY_IS_LOG_MANAGER (manager)); g_return_if_fail (chat_id != NULL); - g_return_if_fail (GOSSIP_IS_MESSAGE (message)); + g_return_if_fail (EMPATHY_IS_MESSAGE (message)); - sender = gossip_message_get_sender (message); - account = gossip_contact_get_account (sender); - body_str = gossip_message_get_body (message); + sender = empathy_message_get_sender (message); + account = empathy_contact_get_account (sender); + body_str = empathy_message_get_body (message); if (G_STR_EMPTY (body_str)) { return; @@ -157,13 +157,13 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, filename = log_manager_get_filename (manager, account, chat_id, chatroom); basedir = g_path_get_dirname (filename); if (!g_file_test (basedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { - gossip_debug (DEBUG_DOMAIN, "Creating directory:'%s'", basedir); + empathy_debug (DEBUG_DOMAIN, "Creating directory:'%s'", basedir); g_mkdir_with_parents (basedir, LOG_DIR_CREATE_MODE); } g_free (basedir); - gossip_debug (DEBUG_DOMAIN, "Adding message: '%s' to file: '%s'", + empathy_debug (DEBUG_DOMAIN, "Adding message: '%s' to file: '%s'", body_str, filename); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { @@ -182,10 +182,10 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, body = g_markup_escape_text (body_str, -1); timestamp = log_manager_get_timestamp_from_message (message); - str = gossip_contact_get_name (sender); + str = empathy_contact_get_name (sender); contact_name = g_markup_escape_text (str, -1); - str = gossip_contact_get_id (sender); + str = empathy_contact_get_id (sender); contact_id = g_markup_escape_text (str, -1); g_fprintf (file, @@ -193,7 +193,7 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, timestamp, contact_id, contact_name, - gossip_contact_is_user (sender) ? "true" : "false", + empathy_contact_is_user (sender) ? "true" : "false", body); fclose (file); @@ -240,12 +240,12 @@ empathy_log_manager_get_dates (EmpathyLogManager *manager, directory = log_manager_get_dir (manager, account, chat_id, chatroom); dir = g_dir_open (directory, 0, NULL); if (!dir) { - gossip_debug (DEBUG_DOMAIN, "Could not open directory:'%s'", directory); + empathy_debug (DEBUG_DOMAIN, "Could not open directory:'%s'", directory); g_free (directory); return NULL; } - gossip_debug (DEBUG_DOMAIN, "Collating a list of dates in:'%s'", directory); + empathy_debug (DEBUG_DOMAIN, "Collating a list of dates in:'%s'", directory); while ((filename = g_dir_read_name (dir)) != NULL) { if (!g_str_has_suffix (filename, LOG_FILENAME_SUFFIX)) { @@ -264,7 +264,7 @@ empathy_log_manager_get_dates (EmpathyLogManager *manager, g_free (directory); g_dir_close (dir); - gossip_debug (DEBUG_DOMAIN, "Parsed %d dates", g_list_length (dates)); + empathy_debug (DEBUG_DOMAIN, "Parsed %d dates", g_list_length (dates)); return dates; } @@ -289,10 +289,10 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager, filename = log_manager_get_filename_for_date (manager, account, chat_id, chatroom, date); - gossip_debug (DEBUG_DOMAIN, "Attempting to parse filename:'%s'...", filename); + empathy_debug (DEBUG_DOMAIN, "Attempting to parse filename:'%s'...", filename); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { - gossip_debug (DEBUG_DOMAIN, "Filename:'%s' does not exist", filename); + empathy_debug (DEBUG_DOMAIN, "Filename:'%s' does not exist", filename); g_free (filename); return NULL; } @@ -320,10 +320,10 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager, /* Now get the messages. */ for (node = log_node->children; node; node = node->next) { - GossipMessage *message; - GossipContact *sender; + EmpathyMessage *message; + EmpathyContact *sender; gchar *time; - GossipTime t; + EmpathyTime t; gchar *sender_id; gchar *sender_name; gchar *body; @@ -344,13 +344,13 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager, is_user = strcmp (is_user_str, "true") == 0; } - t = gossip_time_parse (time); + t = empathy_time_parse (time); - sender = gossip_contact_new_full (account, sender_id, sender_name); - gossip_contact_set_is_user (sender, is_user); - message = gossip_message_new (body); - gossip_message_set_sender (message, sender); - gossip_message_set_timestamp (message, t); + sender = empathy_contact_new_full (account, sender_id, sender_name); + empathy_contact_set_is_user (sender, is_user); + message = empathy_message_new (body); + empathy_message_set_sender (message, sender); + empathy_message_set_timestamp (message, t); messages = g_list_append (messages, message); @@ -361,7 +361,7 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager, xmlFree (body); } - gossip_debug (DEBUG_DOMAIN, "Parsed %d messages", g_list_length (messages)); + empathy_debug (DEBUG_DOMAIN, "Parsed %d messages", g_list_length (messages)); g_free (filename); xmlFreeDoc (doc); @@ -430,7 +430,7 @@ empathy_log_manager_search_new (EmpathyLogManager *manager, text_casefold = g_utf8_casefold (text, -1); files = log_manager_get_all_files (manager, NULL); - gossip_debug (DEBUG_DOMAIN, "Found %d log files in total", + empathy_debug (DEBUG_DOMAIN, "Found %d log files in total", g_list_length (files)); for (l = files; l; l = l->next) { @@ -460,7 +460,7 @@ empathy_log_manager_search_new (EmpathyLogManager *manager, if (hit) { hits = g_list_prepend (hits, hit); - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Found text:'%s' in file:'%s' on date:'%s'...", text, hit->filename, hit->date); } @@ -503,11 +503,11 @@ empathy_log_manager_search_free (GList *hits) gchar * empathy_log_manager_get_date_readable (const gchar *date) { - GossipTime t; + EmpathyTime t; - t = gossip_time_parse (date); + t = empathy_time_parse (date); - return gossip_time_to_string_local (t, "%a %d %b %Y"); + return empathy_time_to_string_local (t, "%a %d %b %Y"); } static const gchar * @@ -681,12 +681,12 @@ log_manager_get_filename_for_date (EmpathyLogManager *manager, static gchar * log_manager_get_timestamp_filename (void) { - GossipTime t; + EmpathyTime t; gchar *time_str; gchar *filename; - t = gossip_time_get_current (); - time_str = gossip_time_to_string_local (t, LOG_TIME_FORMAT); + t = empathy_time_get_current (); + time_str = empathy_time_to_string_local (t, LOG_TIME_FORMAT); filename = g_strconcat (time_str, LOG_FILENAME_SUFFIX, NULL); g_free (time_str); @@ -695,14 +695,14 @@ log_manager_get_timestamp_filename (void) } static gchar * -log_manager_get_timestamp_from_message (GossipMessage *message) +log_manager_get_timestamp_from_message (EmpathyMessage *message) { - GossipTime t; + EmpathyTime t; - t = gossip_message_get_timestamp (message); + t = empathy_message_get_timestamp (message); /* We keep the timestamps in the messages as UTC. */ - return gossip_time_to_string_utc (t, LOG_TIME_FORMAT_FULL); + return empathy_time_to_string_utc (t, LOG_TIME_FORMAT_FULL); } static EmpathyLogSearchHit * diff --git a/libempathy/empathy-log-manager.h b/libempathy/empathy-log-manager.h index d1a5f431d..67ec19d52 100644 --- a/libempathy/empathy-log-manager.h +++ b/libempathy/empathy-log-manager.h @@ -27,7 +27,7 @@ #include -#include "gossip-message.h" +#include "empathy-message.h" G_BEGIN_DECLS @@ -64,7 +64,7 @@ EmpathyLogManager *empathy_log_manager_new (void); void empathy_log_manager_add_message (EmpathyLogManager *manager, const gchar *chat_id, gboolean chatroom, - GossipMessage *message); + EmpathyMessage *message); gboolean empathy_log_manager_exists (EmpathyLogManager *manager, McAccount *account, const gchar *chat_id, diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c new file mode 100644 index 000000000..8b4751ee2 --- /dev/null +++ b/libempathy/empathy-message.c @@ -0,0 +1,418 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2004-2007 Imendio AB + * Copyright (C) 2007 Collabora Ltd. + * + * 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 + * Xavier Claessens + */ + +#include "config.h" + +#include "empathy-message.h" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_MESSAGE, EmpathyMessagePriv)) + +typedef struct _EmpathyMessagePriv EmpathyMessagePriv; + +struct _EmpathyMessagePriv { + EmpathyMessageType type; + EmpathyContact *sender; + EmpathyContact *receiver; + gchar *body; + EmpathyTime timestamp; + +}; + +static void empathy_message_class_init (EmpathyMessageClass *class); +static void empathy_message_init (EmpathyMessage *message); +static void empathy_message_finalize (GObject *object); +static void message_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec); +static void message_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec); + +enum { + PROP_0, + PROP_TYPE, + PROP_SENDER, + PROP_RECEIVER, + PROP_BODY, + PROP_TIMESTAMP, +}; + +static gpointer parent_class = NULL; + +GType +empathy_message_get_gtype (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (EmpathyMessageClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) empathy_message_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (EmpathyMessage), + 0, /* n_preallocs */ + (GInstanceInitFunc) empathy_message_init + }; + + type = g_type_register_static (G_TYPE_OBJECT, + "EmpathyMessage", + &info, 0); + } + + return type; +} + +static void +empathy_message_class_init (EmpathyMessageClass *class) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (class); + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = empathy_message_finalize; + object_class->get_property = message_get_property; + object_class->set_property = message_set_property; + + g_object_class_install_property (object_class, + PROP_TYPE, + g_param_spec_int ("type", + "Message Type", + "The type of message", + EMPATHY_MESSAGE_TYPE_NORMAL, + EMPATHY_MESSAGE_TYPE_LAST, + EMPATHY_MESSAGE_TYPE_NORMAL, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_SENDER, + g_param_spec_object ("sender", + "Message Sender", + "The sender of the message", + EMPATHY_TYPE_CONTACT, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_RECEIVER, + g_param_spec_object ("receiver", + "Message Receiver", + "The receiver of the message", + EMPATHY_TYPE_CONTACT, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_BODY, + g_param_spec_string ("body", + "Message Body", + "The content of the message", + NULL, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_TIMESTAMP, + g_param_spec_long ("timestamp", + "timestamp", + "timestamp", + -1, + G_MAXLONG, + -1, + G_PARAM_READWRITE)); + + + g_type_class_add_private (object_class, sizeof (EmpathyMessagePriv)); + +} + +static void +empathy_message_init (EmpathyMessage *message) +{ + EmpathyMessagePriv *priv; + + priv = GET_PRIV (message); + + priv->timestamp = empathy_time_get_current (); +} + +static void +empathy_message_finalize (GObject *object) +{ + EmpathyMessagePriv *priv; + + priv = GET_PRIV (object); + + if (priv->sender) { + g_object_unref (priv->sender); + } + if (priv->receiver) { + g_object_unref (priv->receiver); + } + + g_free (priv->body); + + (G_OBJECT_CLASS (parent_class)->finalize) (object); +} + +static void +message_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyMessagePriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_TYPE: + g_value_set_int (value, priv->type); + break; + case PROP_SENDER: + g_value_set_object (value, priv->sender); + break; + case PROP_RECEIVER: + g_value_set_object (value, priv->receiver); + break; + case PROP_BODY: + g_value_set_string (value, priv->body); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +message_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyMessagePriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_TYPE: + empathy_message_set_type (EMPATHY_MESSAGE (object), + g_value_get_int (value)); + break; + case PROP_SENDER: + empathy_message_set_sender (EMPATHY_MESSAGE (object), + EMPATHY_CONTACT (g_value_get_object (value))); + break; + case PROP_RECEIVER: + empathy_message_set_receiver (EMPATHY_MESSAGE (object), + EMPATHY_CONTACT (g_value_get_object (value))); + break; + case PROP_BODY: + empathy_message_set_body (EMPATHY_MESSAGE (object), + g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +EmpathyMessage * +empathy_message_new (const gchar *body) +{ + return g_object_new (EMPATHY_TYPE_MESSAGE, + "body", body, + NULL); +} + +EmpathyMessageType +empathy_message_get_type (EmpathyMessage *message) +{ + EmpathyMessagePriv *priv; + + g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), + EMPATHY_MESSAGE_TYPE_NORMAL); + + priv = GET_PRIV (message); + + return priv->type; +} + +void +empathy_message_set_type (EmpathyMessage *message, + EmpathyMessageType type) +{ + EmpathyMessagePriv *priv; + + g_return_if_fail (EMPATHY_IS_MESSAGE (message)); + + priv = GET_PRIV (message); + + priv->type = type; + + g_object_notify (G_OBJECT (message), "type"); +} + +EmpathyContact * +empathy_message_get_sender (EmpathyMessage *message) +{ + EmpathyMessagePriv *priv; + + g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), NULL); + + priv = GET_PRIV (message); + + return priv->sender; +} + +void +empathy_message_set_sender (EmpathyMessage *message, EmpathyContact *contact) +{ + EmpathyMessagePriv *priv; + EmpathyContact *old_sender; + + g_return_if_fail (EMPATHY_IS_MESSAGE (message)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + priv = GET_PRIV (message); + + old_sender = priv->sender; + priv->sender = g_object_ref (contact); + + if (old_sender) { + g_object_unref (old_sender); + } + + g_object_notify (G_OBJECT (message), "sender"); +} + +EmpathyContact * +empathy_message_get_receiver (EmpathyMessage *message) +{ + EmpathyMessagePriv *priv; + + g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), NULL); + + priv = GET_PRIV (message); + + return priv->receiver; +} + +void +empathy_message_set_receiver (EmpathyMessage *message, EmpathyContact *contact) +{ + EmpathyMessagePriv *priv; + EmpathyContact *old_receiver; + + g_return_if_fail (EMPATHY_IS_MESSAGE (message)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + priv = GET_PRIV (message); + + old_receiver = priv->receiver; + priv->receiver = g_object_ref (contact); + + if (old_receiver) { + g_object_unref (old_receiver); + } + + g_object_notify (G_OBJECT (message), "receiver"); +} + +const gchar * +empathy_message_get_body (EmpathyMessage *message) +{ + EmpathyMessagePriv *priv; + + g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), NULL); + + priv = GET_PRIV (message); + + return priv->body; +} + +void +empathy_message_set_body (EmpathyMessage *message, + const gchar *body) +{ + EmpathyMessagePriv *priv; + EmpathyMessageType type; + + g_return_if_fail (EMPATHY_IS_MESSAGE (message)); + + priv = GET_PRIV (message); + + g_free (priv->body); + priv->body = NULL; + + type = EMPATHY_MESSAGE_TYPE_NORMAL; + if (g_str_has_prefix (body, "/me")) { + type = EMPATHY_MESSAGE_TYPE_ACTION; + body += 4; + } + else if (g_str_has_prefix (body, "/say")) { + body += 5; + } + + if (body) { + priv->body = g_strdup (body); + } + + if (type != priv->type) { + empathy_message_set_type (message, type); + } + + g_object_notify (G_OBJECT (message), "body"); +} + +EmpathyTime +empathy_message_get_timestamp (EmpathyMessage *message) +{ + EmpathyMessagePriv *priv; + + g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), -1); + + priv = GET_PRIV (message); + + return priv->timestamp; +} + +void +empathy_message_set_timestamp (EmpathyMessage *message, + EmpathyTime timestamp) +{ + EmpathyMessagePriv *priv; + + g_return_if_fail (EMPATHY_IS_MESSAGE (message)); + g_return_if_fail (timestamp >= -1); + + priv = GET_PRIV (message); + + if (timestamp <= 0) { + priv->timestamp = empathy_time_get_current (); + } else { + priv->timestamp = timestamp; + } + + g_object_notify (G_OBJECT (message), "timestamp"); +} + diff --git a/libempathy/empathy-message.h b/libempathy/empathy-message.h new file mode 100644 index 000000000..ba6f4c426 --- /dev/null +++ b/libempathy/empathy-message.h @@ -0,0 +1,82 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2004-2007 Imendio AB + * Copyright (C) 2007 Collabora Ltd. + * + * 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 + * Xavier Claessens + */ + +#ifndef __EMPATHY_MESSAGE_H__ +#define __EMPATHY_MESSAGE_H__ + +#include + +#include "empathy-contact.h" +#include "empathy-time.h" + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_MESSAGE (empathy_message_get_gtype ()) +#define EMPATHY_MESSAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_MESSAGE, EmpathyMessage)) +#define EMPATHY_MESSAGE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_MESSAGE, EmpathyMessageClass)) +#define EMPATHY_IS_MESSAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_MESSAGE)) +#define EMPATHY_IS_MESSAGE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_MESSAGE)) +#define EMPATHY_MESSAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_MESSAGE, EmpathyMessageClass)) + +typedef struct _EmpathyMessage EmpathyMessage; +typedef struct _EmpathyMessageClass EmpathyMessageClass; + +struct _EmpathyMessage { + GObject parent; +}; + +struct _EmpathyMessageClass { + GObjectClass parent_class; +}; + +typedef enum { + EMPATHY_MESSAGE_TYPE_NORMAL, + EMPATHY_MESSAGE_TYPE_ACTION, + EMPATHY_MESSAGE_TYPE_NOTICE, + EMPATHY_MESSAGE_TYPE_AUTO_REPLY, + EMPATHY_MESSAGE_TYPE_LAST +} EmpathyMessageType; + +GType empathy_message_get_gtype (void) G_GNUC_CONST; +EmpathyMessage * empathy_message_new (const gchar *body); +EmpathyMessageType empathy_message_get_type (EmpathyMessage *message); +void empathy_message_set_type (EmpathyMessage *message, + EmpathyMessageType type); +EmpathyContact * empathy_message_get_sender (EmpathyMessage *message); +void empathy_message_set_sender (EmpathyMessage *message, + EmpathyContact *contact); +EmpathyContact * empathy_message_get_receiver (EmpathyMessage *message); +void empathy_message_set_receiver (EmpathyMessage *message, + EmpathyContact *contact); +const gchar * empathy_message_get_body (EmpathyMessage *message); +void empathy_message_set_body (EmpathyMessage *message, + const gchar *body); +/* What return value should we have here? */ +EmpathyTime empathy_message_get_timestamp (EmpathyMessage *message); +void empathy_message_set_timestamp (EmpathyMessage *message, + EmpathyTime timestamp); + +G_END_DECLS + +#endif /* __EMPATHY_MESSAGE_H__ */ diff --git a/libempathy/empathy-presence.c b/libempathy/empathy-presence.c new file mode 100644 index 000000000..158707a8b --- /dev/null +++ b/libempathy/empathy-presence.c @@ -0,0 +1,337 @@ +/* -*- 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 + */ + +#include "config.h" + +#include + +#include + +#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; + EmpathyTime 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_int ("state", + "Presence State", + "The current state of the presence", + MC_PRESENCE_UNSET, + LAST_MC_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_int (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_int (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: + 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 new file mode 100644 index 000000000..940bf9ca6 --- /dev/null +++ b/libempathy/empathy-presence.h @@ -0,0 +1,67 @@ +/* -*- 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 +#include + +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-time.c b/libempathy/empathy-time.c new file mode 100644 index 000000000..0851add49 --- /dev/null +++ b/libempathy/empathy-time.c @@ -0,0 +1,124 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-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: Richard Hult + */ + +#include "config.h" + +#include +#include +#include + +#include "empathy-time.h" + +/* Note: EmpathyTime is always in UTC. */ + +EmpathyTime +empathy_time_get_current (void) +{ + return time (NULL); +} + +time_t +empathy_time_get_local_time (struct tm *tm) +{ + const gchar *timezone; + time_t t; + + timezone = g_getenv ("TZ"); + g_setenv ("TZ", "", TRUE); + + tzset (); + + t = mktime (tm); + + if (timezone) { + g_setenv ("TZ", timezone, TRUE); + } else { + g_unsetenv ("TZ"); + } + + tzset (); + + return t; +} + +/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on + * failure. The alternative format "20021209" is also accepted. + */ +EmpathyTime +empathy_time_parse (const gchar *str) +{ + struct tm tm; + gint year, month; + gint n_parsed; + + memset (&tm, 0, sizeof (struct tm)); + + n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d", + &year, &month, &tm.tm_mday, &tm.tm_hour, + &tm.tm_min, &tm.tm_sec); + if (n_parsed != 3 && n_parsed != 6) { + return 0; + } + + tm.tm_year = year - 1900; + tm.tm_mon = month - 1; + tm.tm_isdst = -1; + + return empathy_time_get_local_time (&tm); +} + +/* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */ +gchar * +empathy_time_to_string_utc (EmpathyTime t, + const gchar *format) +{ + gchar stamp[128]; + struct tm *tm; + + g_return_val_if_fail (format != NULL, NULL); + + tm = gmtime (&t); + if (strftime (stamp, sizeof (stamp), format, tm) == 0) { + return NULL; + } + + return g_strdup (stamp); +} + +/* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */ +gchar * +empathy_time_to_string_local (EmpathyTime t, + const gchar *format) +{ + gchar stamp[128]; + struct tm *tm; + + g_return_val_if_fail (format != NULL, NULL); + + tm = localtime (&t); + if (strftime (stamp, sizeof (stamp), format, tm) == 0) { + return NULL; + } + + return g_strdup (stamp); +} + diff --git a/libempathy/empathy-time.h b/libempathy/empathy-time.h new file mode 100644 index 000000000..0989391cd --- /dev/null +++ b/libempathy/empathy-time.h @@ -0,0 +1,50 @@ +/* -*- 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_TIME_H__ +#define __EMPATHY_TIME_H__ + +#define __USE_XOPEN +#include + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TIME_FORMAT_DISPLAY_SHORT "%H:%M" +#define EMPATHY_TIME_FORMAT_DISPLAY_LONG "%a %d %b %Y" + +/* Note: Always in UTC. */ +typedef long EmpathyTime; + +EmpathyTime empathy_time_get_current (void); +time_t empathy_time_get_local_time (struct tm *tm); +EmpathyTime empathy_time_parse (const gchar *str); +EmpathyTime empathy_time_parse_format (const gchar *str, + const gchar *format); +gchar *empathy_time_to_string_utc (EmpathyTime t, + const gchar *format); +gchar *empathy_time_to_string_local (EmpathyTime t, + const gchar *format); + +G_END_DECLS + +#endif /* __EMPATHY_TIME_H__ */ + diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index a2852e1d8..e97b5d641 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -34,9 +34,9 @@ #include "empathy-contact-manager.h" #include "empathy-tp-contact-list.h" #include "empathy-marshal.h" -#include "gossip-debug.h" -#include "gossip-time.h" -#include "gossip-utils.h" +#include "empathy-debug.h" +#include "empathy-time.h" +#include "empathy-utils.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv)) @@ -278,7 +278,7 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass) NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, - 1, GOSSIP_TYPE_MESSAGE); + 1, EMPATHY_TYPE_MESSAGE); signals[CHAT_STATE_CHANGED] = g_signal_new ("chat-state-changed", @@ -288,7 +288,7 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass) NULL, NULL, empathy_marshal_VOID__OBJECT_UINT, G_TYPE_NONE, - 2, GOSSIP_TYPE_CONTACT, G_TYPE_UINT); + 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT); signals[DESTROY] = g_signal_new ("destroy", @@ -320,14 +320,14 @@ tp_chat_finalize (GObject *object) priv = GET_PRIV (chat); if (priv->tp_chan) { - gossip_debug (DEBUG_DOMAIN, "Closing channel..."); + empathy_debug (DEBUG_DOMAIN, "Closing channel..."); g_signal_handlers_disconnect_by_func (priv->tp_chan, tp_chat_destroy_cb, object); if (!tp_chan_close (DBUS_G_PROXY (priv->tp_chan), &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Error closing text channel: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -366,7 +366,7 @@ tp_chat_constructor (GType type, priv->manager = empathy_contact_manager_new (); priv->list = empathy_contact_manager_get_list (priv->manager, priv->account); - priv->mc = gossip_mission_control_new (); + priv->mc = empathy_mission_control_new (); g_object_ref (priv->list); priv->text_iface = tp_chan_get_interface (priv->tp_chan, @@ -506,7 +506,7 @@ empathy_tp_chat_new (McAccount *account, } EmpathyTpChat * -empathy_tp_chat_new_with_contact (GossipContact *contact) +empathy_tp_chat_new_with_contact (EmpathyContact *contact) { EmpathyTpChat *chat; MissionControl *mc; @@ -516,10 +516,10 @@ empathy_tp_chat_new_with_contact (GossipContact *contact) const gchar *bus_name; guint handle; - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL); + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); - mc = gossip_mission_control_new (); - account = gossip_contact_get_account (contact); + mc = empathy_mission_control_new (); + account = empathy_contact_get_account (contact); if (mission_control_get_connection_status (mc, account, NULL) != 0) { /* The account is not connected, nothing to do. */ @@ -529,7 +529,7 @@ empathy_tp_chat_new_with_contact (GossipContact *contact) tp_conn = mission_control_get_connection (mc, account, NULL); g_return_val_if_fail (tp_conn != NULL, NULL); bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn)); - handle = gossip_contact_get_handle (contact); + handle = empathy_contact_get_handle (contact); text_chan = tp_conn_new_channel (tp_get_bus (), tp_conn, @@ -566,7 +566,7 @@ empathy_tp_chat_request_pending (EmpathyTpChat *chat) TRUE, &messages_list, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Error retrieving pending messages: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -591,7 +591,7 @@ empathy_tp_chat_request_pending (EmpathyTpChat *chat) message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4)); message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5)); - gossip_debug (DEBUG_DOMAIN, "Message pending: %s", message_body); + empathy_debug (DEBUG_DOMAIN, "Message pending: %s", message_body); tp_chat_emit_message (chat, message_type, @@ -607,27 +607,27 @@ empathy_tp_chat_request_pending (EmpathyTpChat *chat) void empathy_tp_chat_send (EmpathyTpChat *chat, - GossipMessage *message) + EmpathyMessage *message) { EmpathyTpChatPriv *priv; const gchar *message_body; - GossipMessageType message_type; + EmpathyMessageType message_type; GError *error = NULL; g_return_if_fail (EMPATHY_IS_TP_CHAT (chat)); - g_return_if_fail (GOSSIP_IS_MESSAGE (message)); + g_return_if_fail (EMPATHY_IS_MESSAGE (message)); priv = GET_PRIV (chat); - message_body = gossip_message_get_body (message); - message_type = gossip_message_get_type (message); + message_body = empathy_message_get_body (message); + message_type = empathy_message_get_type (message); - gossip_debug (DEBUG_DOMAIN, "Sending message: %s", message_body); + empathy_debug (DEBUG_DOMAIN, "Sending message: %s", message_body); if (!tp_chan_type_text_send (priv->text_iface, message_type, message_body, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Send Error: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -646,11 +646,11 @@ empathy_tp_chat_set_state (EmpathyTpChat *chat, priv = GET_PRIV (chat); if (priv->chat_state_iface) { - gossip_debug (DEBUG_DOMAIN, "Set state: %d", state); + empathy_debug (DEBUG_DOMAIN, "Set state: %d", state); if (!tp_chan_iface_chat_state_set_chat_state (priv->chat_state_iface, state, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Set Chat State Error: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -671,7 +671,7 @@ empathy_tp_chat_get_id (EmpathyTpChat *chat) return priv->id; } - priv->id = gossip_get_channel_id (priv->account, priv->tp_chan); + priv->id = empathy_get_channel_id (priv->account, priv->tp_chan); return priv->id; } @@ -684,7 +684,7 @@ tp_chat_destroy_cb (TpChan *text_chan, priv = GET_PRIV (chat); - gossip_debug (DEBUG_DOMAIN, "Channel Closed or CM crashed"); + empathy_debug (DEBUG_DOMAIN, "Channel Closed or CM crashed"); g_object_unref (priv->tp_chan); priv->tp_chan = NULL; @@ -726,7 +726,7 @@ tp_chat_received_cb (DBusGProxy *text_iface, priv = GET_PRIV (chat); - gossip_debug (DEBUG_DOMAIN, "Message received: %s", message_body); + empathy_debug (DEBUG_DOMAIN, "Message received: %s", message_body); tp_chat_emit_message (chat, message_type, @@ -748,7 +748,7 @@ tp_chat_sent_cb (DBusGProxy *text_iface, gchar *message_body, EmpathyTpChat *chat) { - gossip_debug (DEBUG_DOMAIN, "Message sent: %s", message_body); + empathy_debug (DEBUG_DOMAIN, "Message sent: %s", message_body); tp_chat_emit_message (chat, message_type, @@ -764,14 +764,14 @@ tp_chat_state_changed_cb (DBusGProxy *chat_state_iface, EmpathyTpChat *chat) { EmpathyTpChatPriv *priv; - GossipContact *contact; + EmpathyContact *contact; priv = GET_PRIV (chat); contact = empathy_tp_contact_list_get_from_handle (priv->list, handle); - gossip_debug (DEBUG_DOMAIN, "Chat state changed for %s (%d): %d", - gossip_contact_get_name (contact), + empathy_debug (DEBUG_DOMAIN, "Chat state changed for %s (%d): %d", + empathy_contact_get_name (contact), handle, state); @@ -788,9 +788,9 @@ tp_chat_emit_message (EmpathyTpChat *chat, const gchar *message_body) { EmpathyTpChatPriv *priv; - GossipMessage *message; - GossipContact *sender; - GossipContact *receiver; + EmpathyMessage *message; + EmpathyContact *sender; + EmpathyContact *receiver; priv = GET_PRIV (chat); @@ -802,11 +802,11 @@ tp_chat_emit_message (EmpathyTpChat *chat, from_handle); } - message = gossip_message_new (message_body); - gossip_message_set_type (message, type); - gossip_message_set_sender (message, sender); - gossip_message_set_receiver (message, receiver); - gossip_message_set_timestamp (message, (GossipTime) timestamp); + message = empathy_message_new (message_body); + empathy_message_set_type (message, type); + empathy_message_set_sender (message, sender); + empathy_message_set_receiver (message, receiver); + empathy_message_set_timestamp (message, (EmpathyTime) timestamp); g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message); diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h index 55bbfcd3d..ce4e2a836 100644 --- a/libempathy/empathy-tp-chat.h +++ b/libempathy/empathy-tp-chat.h @@ -30,8 +30,8 @@ #include -#include "gossip-message.h" -#include "gossip-contact.h" +#include "empathy-message.h" +#include "empathy-contact.h" G_BEGIN_DECLS @@ -58,10 +58,10 @@ struct _EmpathyTpChatClass { GType empathy_tp_chat_get_type (void) G_GNUC_CONST; EmpathyTpChat *empathy_tp_chat_new (McAccount *account, TpChan *tp_chan); -EmpathyTpChat *empathy_tp_chat_new_with_contact (GossipContact *contact); +EmpathyTpChat *empathy_tp_chat_new_with_contact (EmpathyContact *contact); void empathy_tp_chat_request_pending (EmpathyTpChat *chat); void empathy_tp_chat_send (EmpathyTpChat *chat, - GossipMessage *message); + EmpathyMessage *message); void empathy_tp_chat_set_state (EmpathyTpChat *chat, TelepathyChannelChatState state); const gchar * empathy_tp_chat_get_id (EmpathyTpChat *chat); diff --git a/libempathy/empathy-tp-chatroom.c b/libempathy/empathy-tp-chatroom.c index 232db30fd..fe8e7f8e7 100644 --- a/libempathy/empathy-tp-chatroom.c +++ b/libempathy/empathy-tp-chatroom.c @@ -28,9 +28,9 @@ #include "empathy-tp-contact-list.h" #include "empathy-contact-list.h" #include "empathy-contact-manager.h" -#include "gossip-telepathy-group.h" -#include "gossip-utils.h" -#include "gossip-debug.h" +#include "empathy-tp-group.h" +#include "empathy-utils.h" +#include "empathy-debug.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ EMPATHY_TYPE_TP_CHATROOM, EmpathyTpChatroomPriv)) @@ -40,10 +40,10 @@ struct _EmpathyTpChatroomPriv { EmpathyContactManager *manager; EmpathyTpContactList *list; - GossipTelepathyGroup *group; + EmpathyTpGroup *group; gboolean is_invited; - GossipContact *invitor; + EmpathyContact *invitor; gchar *invit_message; }; @@ -51,26 +51,26 @@ static void empathy_tp_chatroom_class_init (EmpathyTpChatroomClass * static void tp_chatroom_iface_init (EmpathyContactListIface *iface); static void empathy_tp_chatroom_init (EmpathyTpChatroom *chatroom); static void tp_chatroom_finalize (GObject *object); -static void tp_chatroom_members_added_cb (GossipTelepathyGroup *group, +static void tp_chatroom_members_added_cb (EmpathyTpGroup *group, GArray *handles, guint actor_handle, guint reason, const gchar *message, EmpathyTpChatroom *list); -static void tp_chatroom_members_removed_cb (GossipTelepathyGroup *group, +static void tp_chatroom_members_removed_cb (EmpathyTpGroup *group, GArray *handles, guint actor_handle, guint reason, const gchar *message, EmpathyTpChatroom *list); static void tp_chatroom_setup (EmpathyContactList *list); -static GossipContact * tp_chatroom_find (EmpathyContactList *list, +static EmpathyContact * tp_chatroom_find (EmpathyContactList *list, const gchar *id); static void tp_chatroom_add (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message); static void tp_chatroom_remove (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message); static GList * tp_chatroom_get_members (EmpathyContactList *list); @@ -145,11 +145,11 @@ empathy_tp_chatroom_new (McAccount *account, priv = GET_PRIV (chatroom); - mc = gossip_mission_control_new (); + mc = empathy_mission_control_new (); tp_conn = mission_control_get_connection (mc, account, NULL); priv->manager = empathy_contact_manager_new (); priv->list = empathy_contact_manager_get_list (priv->manager, account); - priv->group = gossip_telepathy_group_new (tp_chan, tp_conn); + priv->group = empathy_tp_group_new (tp_chan, tp_conn); g_signal_connect (priv->group, "members-added", G_CALLBACK (tp_chatroom_members_added_cb), @@ -159,10 +159,10 @@ empathy_tp_chatroom_new (McAccount *account, chatroom); /* Check if we are invited to join the chat */ - self_handle = gossip_telepathy_group_get_self_handle (priv->group); - members = gossip_telepathy_group_get_local_pending_members_with_info (priv->group); + self_handle = empathy_tp_group_get_self_handle (priv->group); + members = empathy_tp_group_get_local_pending_members_with_info (priv->group); for (l = members; l; l = l->next) { - GossipTpGroupInfo *info; + EmpathyTpGroupInfo *info; info = l->data; @@ -175,12 +175,12 @@ empathy_tp_chatroom_new (McAccount *account, priv->invit_message = g_strdup (info->message); priv->is_invited = TRUE; - gossip_debug (DEBUG_DOMAIN, "We are invited to join by %s: %s", - gossip_contact_get_name (priv->invitor), + empathy_debug (DEBUG_DOMAIN, "We are invited to join by %s: %s", + empathy_contact_get_name (priv->invitor), priv->invit_message); } - gossip_telepathy_group_info_list_free (members); + empathy_tp_group_info_list_free (members); g_object_unref (mc); g_object_unref (tp_conn); @@ -189,7 +189,7 @@ empathy_tp_chatroom_new (McAccount *account, gboolean empathy_tp_chatroom_get_invitation (EmpathyTpChatroom *chatroom, - GossipContact **contact, + EmpathyContact **contact, const gchar **message) { EmpathyTpChatroomPriv *priv; @@ -228,8 +228,8 @@ empathy_tp_chatroom_accept_invitation (EmpathyTpChatroom *chatroom) priv->invit_message = NULL; /* Add ourself in the members of the room */ - self_handle = gossip_telepathy_group_get_self_handle (priv->group); - gossip_telepathy_group_add_member (priv->group, self_handle, + self_handle = empathy_tp_group_get_self_handle (priv->group); + empathy_tp_group_add_member (priv->group, self_handle, "Just for fun"); } @@ -240,12 +240,12 @@ empathy_tp_chatroom_set_topic (EmpathyTpChatroom *chatroom, } static void -tp_chatroom_members_added_cb (GossipTelepathyGroup *group, - GArray *handles, - guint actor_handle, - guint reason, - const gchar *message, - EmpathyTpChatroom *chatroom) +tp_chatroom_members_added_cb (EmpathyTpGroup *group, + GArray *handles, + guint actor_handle, + guint reason, + const gchar *message, + EmpathyTpChatroom *chatroom) { EmpathyTpChatroomPriv *priv; GList *contacts, *l; @@ -254,7 +254,7 @@ tp_chatroom_members_added_cb (GossipTelepathyGroup *group, contacts = empathy_tp_contact_list_get_from_handles (priv->list, handles); for (l = contacts; l; l = l->next) { - GossipContact *contact; + EmpathyContact *contact; contact = l->data; @@ -266,12 +266,12 @@ tp_chatroom_members_added_cb (GossipTelepathyGroup *group, } static void -tp_chatroom_members_removed_cb (GossipTelepathyGroup *group, - GArray *handles, - guint actor_handle, - guint reason, - const gchar *message, - EmpathyTpChatroom *chatroom) +tp_chatroom_members_removed_cb (EmpathyTpGroup *group, + GArray *handles, + guint actor_handle, + guint reason, + const gchar *message, + EmpathyTpChatroom *chatroom) { EmpathyTpChatroomPriv *priv; GList *contacts, *l; @@ -280,7 +280,7 @@ tp_chatroom_members_removed_cb (GossipTelepathyGroup *group, contacts = empathy_tp_contact_list_get_from_handles (priv->list, handles); for (l = contacts; l; l = l->next) { - GossipContact *contact; + EmpathyContact *contact; contact = l->data; @@ -297,7 +297,7 @@ tp_chatroom_setup (EmpathyContactList *list) /* Nothing to do */ } -static GossipContact * +static EmpathyContact * tp_chatroom_find (EmpathyContactList *list, const gchar *id) { @@ -306,36 +306,36 @@ tp_chatroom_find (EmpathyContactList *list, static void tp_chatroom_add (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message) { EmpathyTpChatroomPriv *priv; g_return_if_fail (EMPATHY_IS_TP_CHATROOM (list)); - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); priv = GET_PRIV (list); - gossip_telepathy_group_add_member (priv->group, - gossip_contact_get_handle (contact), - message); + empathy_tp_group_add_member (priv->group, + empathy_contact_get_handle (contact), + message); } static void tp_chatroom_remove (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message) { EmpathyTpChatroomPriv *priv; g_return_if_fail (EMPATHY_IS_TP_CHATROOM (list)); - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); priv = GET_PRIV (list); - gossip_telepathy_group_remove_member (priv->group, - gossip_contact_get_handle (contact), - message); + empathy_tp_group_remove_member (priv->group, + empathy_contact_get_handle (contact), + message); } static GList * @@ -349,7 +349,7 @@ tp_chatroom_get_members (EmpathyContactList *list) priv = GET_PRIV (list); - members = gossip_telepathy_group_get_members (priv->group); + members = empathy_tp_group_get_members (priv->group); contacts = empathy_tp_contact_list_get_from_handles (priv->list, members); g_array_free (members, TRUE); diff --git a/libempathy/empathy-tp-chatroom.h b/libempathy/empathy-tp-chatroom.h index 488ac74fb..cbdd246c6 100644 --- a/libempathy/empathy-tp-chatroom.h +++ b/libempathy/empathy-tp-chatroom.h @@ -56,7 +56,7 @@ GType empathy_tp_chatroom_get_type (void) G_GNUC_CONST; EmpathyTpChatroom *empathy_tp_chatroom_new (McAccount *account, TpChan *tp_chan); gboolean empathy_tp_chatroom_get_invitation (EmpathyTpChatroom *chatroom, - GossipContact **contact, + EmpathyContact **contact, const gchar **message); void empathy_tp_chatroom_accept_invitation (EmpathyTpChatroom *chatroom); void empathy_tp_chatroom_set_topic (EmpathyTpChatroom *chatroom, diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c index c435218e8..dd04fac53 100644 --- a/libempathy/empathy-tp-contact-list.c +++ b/libempathy/empathy-tp-contact-list.c @@ -35,9 +35,9 @@ #include "empathy-tp-contact-list.h" #include "empathy-contact-list.h" -#include "gossip-telepathy-group.h" -#include "gossip-debug.h" -#include "gossip-utils.h" +#include "empathy-tp-group.h" +#include "empathy-debug.h" +#include "empathy-utils.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ EMPATHY_TYPE_TP_CONTACT_LIST, EmpathyTpContactListPriv)) @@ -46,25 +46,25 @@ #define MAX_AVATAR_REQUESTS 10 struct _EmpathyTpContactListPriv { - TpConn *tp_conn; - McAccount *account; - MissionControl *mc; - GossipContact *user_contact; - gboolean setup; + TpConn *tp_conn; + McAccount *account; + MissionControl *mc; + EmpathyContact *user_contact; + gboolean setup; - GossipTelepathyGroup *publish; - GossipTelepathyGroup *subscribe; + EmpathyTpGroup *publish; + EmpathyTpGroup *subscribe; - GHashTable *groups; - GHashTable *contacts; - GList *members; - GList *local_pending; + GHashTable *groups; + GHashTable *contacts; + GList *members; + GList *local_pending; - DBusGProxy *aliasing_iface; - DBusGProxy *avatars_iface; - DBusGProxy *presence_iface; + DBusGProxy *aliasing_iface; + DBusGProxy *avatars_iface; + DBusGProxy *presence_iface; - GList *avatar_requests_queue; + GList *avatar_requests_queue; }; typedef enum { @@ -89,129 +89,129 @@ typedef struct { guint *handles; } TpContactListAliasesRequestData; -static void empathy_tp_contact_list_class_init (EmpathyTpContactListClass *klass); -static void tp_contact_list_iface_init (EmpathyContactListIface *iface); -static void empathy_tp_contact_list_init (EmpathyTpContactList *list); -static void tp_contact_list_finalize (GObject *object); -static void tp_contact_list_finalize_proxies (EmpathyTpContactList *list); -static void tp_contact_list_setup (EmpathyContactList *list); -static GossipContact * tp_contact_list_find (EmpathyContactList *list, - const gchar *id); -static void tp_contact_list_add (EmpathyContactList *list, - GossipContact *contact, - const gchar *message); -static void tp_contact_list_remove (EmpathyContactList *list, - GossipContact *contact, - const gchar *message); -static GList * tp_contact_list_get_members (EmpathyContactList *list); -static GList * tp_contact_list_get_local_pending (EmpathyContactList *list); -static void tp_contact_list_process_pending (EmpathyContactList *list, - GossipContact *contact, - gboolean accept); -static void tp_contact_list_remove_local_pending (EmpathyTpContactList *list, - GossipContact *contact); -static void tp_contact_list_contact_removed_foreach (guint handle, - GossipContact *contact, - EmpathyTpContactList *list); -static void tp_contact_list_destroy_cb (DBusGProxy *proxy, - EmpathyTpContactList *list); -static gboolean tp_contact_list_find_foreach (guint handle, - GossipContact *contact, - gchar *id); -static void tp_contact_list_newchannel_cb (DBusGProxy *proxy, - const gchar *object_path, - const gchar *channel_type, - TelepathyHandleType handle_type, - guint channel_handle, - gboolean suppress_handle, - EmpathyTpContactList *list); -static TpContactListType tp_contact_list_get_type (EmpathyTpContactList *list, - GossipTelepathyGroup *group); -static void tp_contact_list_added_cb (GossipTelepathyGroup *group, - GArray *handles, - guint actor_handle, - guint reason, - const gchar *message, - EmpathyTpContactList *list); -static void tp_contact_list_removed_cb (GossipTelepathyGroup *group, - GArray *handles, - guint actor_handle, - guint reason, - const gchar *message, - EmpathyTpContactList *list); -static void tp_contact_list_pending_cb (GossipTelepathyGroup *group, - GArray *handles, - guint actor_handle, - guint reason, - const gchar *message, - EmpathyTpContactList *list); -static void tp_contact_list_groups_updated_cb (GossipContact *contact, - GParamSpec *param, - EmpathyTpContactList *list); -static void tp_contact_list_name_updated_cb (GossipContact *contact, - GParamSpec *param, - EmpathyTpContactList *list); -static void tp_contact_list_update_groups_foreach (gchar *object_path, - GossipTelepathyGroup *group, - TpContactListData *data); -static GossipTelepathyGroup * tp_contact_list_get_group (EmpathyTpContactList *list, - const gchar *name); -static gboolean tp_contact_list_find_group (gchar *key, - GossipTelepathyGroup *group, - gchar *group_name); -static void tp_contact_list_get_groups_foreach (gchar *key, - GossipTelepathyGroup *group, - GList **groups); -static void tp_contact_list_group_channel_closed_cb (TpChan *channel, - EmpathyTpContactList *list); -static void tp_contact_list_group_members_added_cb (GossipTelepathyGroup *group, - GArray *members, - guint actor_handle, - guint reason, - const gchar *message, - EmpathyTpContactList *list); -static void tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group, - GArray *members, - guint actor_handle, - guint reason, - const gchar *message, - EmpathyTpContactList *list); -static void tp_contact_list_get_info (EmpathyTpContactList *list, - GArray *handles); -static void tp_contact_list_request_avatar (EmpathyTpContactList *list, - guint handle); -static void tp_contact_list_start_avatar_requests (EmpathyTpContactList *list); -static void tp_contact_list_avatar_update_cb (DBusGProxy *proxy, - guint handle, - gchar *new_token, - EmpathyTpContactList *list); -static void tp_contact_list_request_avatar_cb (DBusGProxy *proxy, - GArray *avatar_data, - gchar *mime_type, - GError *error, - TpContactListAvatarRequestData *data); -static void tp_contact_list_aliases_update_cb (DBusGProxy *proxy, - GPtrArray *handlers, - EmpathyTpContactList *list); -static void tp_contact_list_request_aliases_cb (DBusGProxy *proxy, - gchar **contact_names, - GError *error, - TpContactListAliasesRequestData *data); -static void tp_contact_list_presence_update_cb (DBusGProxy *proxy, - GHashTable *handle_table, - EmpathyTpContactList *list); -static void tp_contact_list_parse_presence_foreach (guint handle, - GValueArray *presence_struct, - EmpathyTpContactList *list); -static void tp_contact_list_presences_table_foreach (const gchar *state_str, - GHashTable *presences_table, - GossipPresence **presence); -static void tp_contact_list_status_changed_cb (MissionControl *mc, - TelepathyConnectionStatus status, - McPresence presence, - TelepathyConnectionStatusReason reason, - const gchar *unique_name, - EmpathyTpContactList *list); +static void empathy_tp_contact_list_class_init (EmpathyTpContactListClass *klass); +static void tp_contact_list_iface_init (EmpathyContactListIface *iface); +static void empathy_tp_contact_list_init (EmpathyTpContactList *list); +static void tp_contact_list_finalize (GObject *object); +static void tp_contact_list_finalize_proxies (EmpathyTpContactList *list); +static void tp_contact_list_setup (EmpathyContactList *list); +static EmpathyContact * tp_contact_list_find (EmpathyContactList *list, + const gchar *id); +static void tp_contact_list_add (EmpathyContactList *list, + EmpathyContact *contact, + const gchar *message); +static void tp_contact_list_remove (EmpathyContactList *list, + EmpathyContact *contact, + const gchar *message); +static GList * tp_contact_list_get_members (EmpathyContactList *list); +static GList * tp_contact_list_get_local_pending (EmpathyContactList *list); +static void tp_contact_list_process_pending (EmpathyContactList *list, + EmpathyContact *contact, + gboolean accept); +static void tp_contact_list_remove_local_pending (EmpathyTpContactList *list, + EmpathyContact *contact); +static void tp_contact_list_contact_removed_foreach (guint handle, + EmpathyContact *contact, + EmpathyTpContactList *list); +static void tp_contact_list_destroy_cb (DBusGProxy *proxy, + EmpathyTpContactList *list); +static gboolean tp_contact_list_find_foreach (guint handle, + EmpathyContact *contact, + gchar *id); +static void tp_contact_list_newchannel_cb (DBusGProxy *proxy, + const gchar *object_path, + const gchar *channel_type, + TelepathyHandleType handle_type, + guint channel_handle, + gboolean suppress_handle, + EmpathyTpContactList *list); +static TpContactListType tp_contact_list_get_type (EmpathyTpContactList *list, + EmpathyTpGroup *group); +static void tp_contact_list_added_cb (EmpathyTpGroup *group, + GArray *handles, + guint actor_handle, + guint reason, + const gchar *message, + EmpathyTpContactList *list); +static void tp_contact_list_removed_cb (EmpathyTpGroup *group, + GArray *handles, + guint actor_handle, + guint reason, + const gchar *message, + EmpathyTpContactList *list); +static void tp_contact_list_pending_cb (EmpathyTpGroup *group, + GArray *handles, + guint actor_handle, + guint reason, + const gchar *message, + EmpathyTpContactList *list); +static void tp_contact_list_groups_updated_cb (EmpathyContact *contact, + GParamSpec *param, + EmpathyTpContactList *list); +static void tp_contact_list_name_updated_cb (EmpathyContact *contact, + GParamSpec *param, + EmpathyTpContactList *list); +static void tp_contact_list_update_groups_foreach (gchar *object_path, + EmpathyTpGroup *group, + TpContactListData *data); +static EmpathyTpGroup * tp_contact_list_get_group (EmpathyTpContactList *list, + const gchar *name); +static gboolean tp_contact_list_find_group (gchar *key, + EmpathyTpGroup *group, + gchar *group_name); +static void tp_contact_list_get_groups_foreach (gchar *key, + EmpathyTpGroup *group, + GList **groups); +static void tp_contact_list_group_channel_closed_cb (TpChan *channel, + EmpathyTpContactList *list); +static void tp_contact_list_group_members_added_cb (EmpathyTpGroup *group, + GArray *members, + guint actor_handle, + guint reason, + const gchar *message, + EmpathyTpContactList *list); +static void tp_contact_list_group_members_removed_cb (EmpathyTpGroup *group, + GArray *members, + guint actor_handle, + guint reason, + const gchar *message, + EmpathyTpContactList *list); +static void tp_contact_list_get_info (EmpathyTpContactList *list, + GArray *handles); +static void tp_contact_list_request_avatar (EmpathyTpContactList *list, + guint handle); +static void tp_contact_list_start_avatar_requests (EmpathyTpContactList *list); +static void tp_contact_list_avatar_update_cb (DBusGProxy *proxy, + guint handle, + gchar *new_token, + EmpathyTpContactList *list); +static void tp_contact_list_request_avatar_cb (DBusGProxy *proxy, + GArray *avatar_data, + gchar *mime_type, + GError *error, + TpContactListAvatarRequestData *data); +static void tp_contact_list_aliases_update_cb (DBusGProxy *proxy, + GPtrArray *handlers, + EmpathyTpContactList *list); +static void tp_contact_list_request_aliases_cb (DBusGProxy *proxy, + gchar **contact_names, + GError *error, + TpContactListAliasesRequestData *data); +static void tp_contact_list_presence_update_cb (DBusGProxy *proxy, + GHashTable *handle_table, + EmpathyTpContactList *list); +static void tp_contact_list_parse_presence_foreach (guint handle, + GValueArray *presence_struct, + EmpathyTpContactList *list); +static void tp_contact_list_presences_table_foreach (const gchar *state_str, + GHashTable *presences_table, + EmpathyPresence **presence); +static void tp_contact_list_status_changed_cb (MissionControl *mc, + TelepathyConnectionStatus status, + McPresence presence, + TelepathyConnectionStatusReason reason, + const gchar *unique_name, + EmpathyTpContactList *list); enum { DESTROY, @@ -283,7 +283,7 @@ tp_contact_list_finalize (GObject *object) list = EMPATHY_TP_CONTACT_LIST (object); priv = GET_PRIV (list); - gossip_debug (DEBUG_DOMAIN, "finalize: %p", object); + empathy_debug (DEBUG_DOMAIN, "finalize: %p", object); dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged", @@ -328,7 +328,7 @@ empathy_tp_contact_list_new (McAccount *account) g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); - mc = gossip_mission_control_new (); + mc = empathy_mission_control_new (); if (mission_control_get_connection_status (mc, account, NULL) != 0) { /* The account is not connected, nothing to do. */ @@ -381,12 +381,12 @@ empathy_tp_contact_list_new (McAccount *account) /* Get our own handle and contact */ if (!tp_conn_get_self_handle (DBUS_G_PROXY (priv->tp_conn), &handle, &error)) { - gossip_debug (DEBUG_DOMAIN, "GetSelfHandle Error: %s", + empathy_debug (DEBUG_DOMAIN, "GetSelfHandle Error: %s", error ? error->message : "No error given"); g_clear_error (&error); } else { priv->user_contact = empathy_tp_contact_list_get_from_handle (list, handle); - gossip_contact_set_is_user (priv->user_contact, TRUE); + empathy_contact_set_is_user (priv->user_contact, TRUE); } return list; @@ -404,7 +404,7 @@ tp_contact_list_setup (EmpathyContactList *list) priv = GET_PRIV (list); - gossip_debug (DEBUG_DOMAIN, "setup contact list: %p", list); + empathy_debug (DEBUG_DOMAIN, "setup contact list: %p", list); priv->setup = TRUE; dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel", @@ -415,7 +415,7 @@ tp_contact_list_setup (EmpathyContactList *list) if (!tp_conn_list_channels (DBUS_G_PROXY (priv->tp_conn), &channels, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Failed to get list of open channels: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -447,7 +447,7 @@ tp_contact_list_setup (EmpathyContactList *list) g_ptr_array_free (channels, TRUE); } -static GossipContact * +static EmpathyContact * tp_contact_list_find (EmpathyContactList *list, const gchar *id) { @@ -464,7 +464,7 @@ tp_contact_list_find (EmpathyContactList *list, static void tp_contact_list_add (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message) { EmpathyTpContactListPriv *priv; @@ -474,13 +474,13 @@ tp_contact_list_add (EmpathyContactList *list, priv = GET_PRIV (list); - handle = gossip_contact_get_handle (contact); - gossip_telepathy_group_add_member (priv->subscribe, handle, message); + handle = empathy_contact_get_handle (contact); + empathy_tp_group_add_member (priv->subscribe, handle, message); } static void tp_contact_list_remove (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, const gchar *message) { EmpathyTpContactListPriv *priv; @@ -490,8 +490,8 @@ tp_contact_list_remove (EmpathyContactList *list, priv = GET_PRIV (list); - handle = gossip_contact_get_handle (contact); - gossip_telepathy_group_remove_member (priv->subscribe, handle, message); + handle = empathy_contact_get_handle (contact); + empathy_tp_group_remove_member (priv->subscribe, handle, message); } static GList * @@ -521,22 +521,22 @@ tp_contact_list_get_local_pending (EmpathyContactList *list) static void tp_contact_list_process_pending (EmpathyContactList *list, - GossipContact *contact, + EmpathyContact *contact, gboolean accept) { EmpathyTpContactListPriv *priv; guint handle; g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list)); - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); priv = GET_PRIV (list); - handle = gossip_contact_get_handle (contact); + handle = empathy_contact_get_handle (contact); if (accept) { - gossip_telepathy_group_add_member (priv->publish, handle, NULL); + empathy_tp_group_add_member (priv->publish, handle, NULL); } else { - gossip_telepathy_group_remove_member (priv->publish, handle, NULL); + empathy_tp_group_remove_member (priv->publish, handle, NULL); } } @@ -552,7 +552,7 @@ empathy_tp_contact_list_get_account (EmpathyTpContactList *list) return priv->account; } -GossipContact * +EmpathyContact * empathy_tp_contact_list_get_user (EmpathyTpContactList *list) { EmpathyTpContactListPriv *priv; @@ -564,12 +564,12 @@ empathy_tp_contact_list_get_user (EmpathyTpContactList *list) return priv->user_contact; } -GossipContact * +EmpathyContact * empathy_tp_contact_list_get_from_id (EmpathyTpContactList *list, const gchar *id) { EmpathyTpContactListPriv *priv; - GossipContact *contact; + EmpathyContact *contact; const gchar *contact_ids[] = {id, NULL}; GArray *handles; guint handle; @@ -590,7 +590,7 @@ empathy_tp_contact_list_get_from_id (EmpathyTpContactList *list, TP_HANDLE_TYPE_CONTACT, contact_ids, &handles, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "RequestHandle for %s failed: %s", id, error ? error->message : "No error given"); g_clear_error (&error); @@ -603,11 +603,11 @@ empathy_tp_contact_list_get_from_id (EmpathyTpContactList *list, return empathy_tp_contact_list_get_from_handle (list, handle); } -GossipContact * +EmpathyContact * empathy_tp_contact_list_get_from_handle (EmpathyTpContactList *list, guint handle) { - GossipContact *contact; + EmpathyContact *contact; GArray *handles; GList *contacts; @@ -649,7 +649,7 @@ empathy_tp_contact_list_get_from_handles (EmpathyTpContactList *list, /* Search all handles we already have */ new_handles = g_array_new (FALSE, FALSE, sizeof (guint)); for (i = 0; i < handles->len; i++) { - GossipContact *contact; + EmpathyContact *contact; guint handle; handle = g_array_index (handles, guint, i); @@ -679,7 +679,7 @@ empathy_tp_contact_list_get_from_handles (EmpathyTpContactList *list, if (!tp_conn_hold_handles (DBUS_G_PROXY (priv->tp_conn), TP_HANDLE_TYPE_CONTACT, new_handles, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "HoldHandles Error: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -693,7 +693,7 @@ empathy_tp_contact_list_get_from_handles (EmpathyTpContactList *list, new_handles, &handles_names, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "InspectHandle Error: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -703,25 +703,25 @@ empathy_tp_contact_list_get_from_handles (EmpathyTpContactList *list, /* Create contact objects */ for (i = 0, id = handles_names; *id && i < new_handles->len; id++, i++) { - GossipContact *contact; + EmpathyContact *contact; guint handle; handle = g_array_index (new_handles, guint, i); - contact = g_object_new (GOSSIP_TYPE_CONTACT, + contact = g_object_new (EMPATHY_TYPE_CONTACT, "account", priv->account, "id", *id, "handle", handle, NULL); if (!priv->presence_iface) { - GossipPresence *presence; + EmpathyPresence *presence; /* We have no presence iface, set default presence * to available */ - presence = gossip_presence_new_full (MC_PRESENCE_AVAILABLE, + presence = empathy_presence_new_full (MC_PRESENCE_AVAILABLE, NULL); - gossip_contact_set_presence (contact, presence); + empathy_contact_set_presence (contact, presence); g_object_unref (presence); } @@ -732,7 +732,7 @@ empathy_tp_contact_list_get_from_handles (EmpathyTpContactList *list, G_CALLBACK (tp_contact_list_name_updated_cb), list); - gossip_debug (DEBUG_DOMAIN, "new contact created: %s (%d)", + empathy_debug (DEBUG_DOMAIN, "new contact created: %s (%d)", *id, handle); g_hash_table_insert (priv->contacts, @@ -756,7 +756,7 @@ empathy_tp_contact_list_rename_group (EmpathyTpContactList *list, const gchar *new_group) { EmpathyTpContactListPriv *priv; - GossipTelepathyGroup *group; + EmpathyTpGroup *group; GArray *members; g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list)); @@ -773,22 +773,22 @@ empathy_tp_contact_list_rename_group (EmpathyTpContactList *list, return; } - gossip_debug (DEBUG_DOMAIN, "rename group %s to %s", group, new_group); + empathy_debug (DEBUG_DOMAIN, "rename group %s to %s", group, new_group); /* Remove all members from the old group */ - members = gossip_telepathy_group_get_members (group); - gossip_telepathy_group_remove_members (group, members, ""); + members = empathy_tp_group_get_members (group); + empathy_tp_group_remove_members (group, members, ""); tp_contact_list_group_members_removed_cb (group, members, - 0, - TP_CHANNEL_GROUP_CHANGE_REASON_NONE, - NULL, list); + 0, + TP_CHANNEL_GROUP_CHANGE_REASON_NONE, + NULL, list); g_hash_table_remove (priv->groups, - gossip_telepathy_group_get_object_path (group)); + empathy_tp_group_get_object_path (group)); /* Add all members to the new group */ group = tp_contact_list_get_group (list, new_group); if (group) { - gossip_telepathy_group_add_members (group, members, ""); + empathy_tp_group_add_members (group, members, ""); } } @@ -857,7 +857,7 @@ tp_contact_list_destroy_cb (DBusGProxy *proxy, priv = GET_PRIV (list); - gossip_debug (DEBUG_DOMAIN, "Connection destroyed... " + empathy_debug (DEBUG_DOMAIN, "Connection destroyed... " "Account disconnected or CM crashed"); /* DBus proxies should NOT be used anymore */ @@ -879,7 +879,7 @@ tp_contact_list_destroy_cb (DBusGProxy *proxy, static void tp_contact_list_contact_removed_foreach (guint handle, - GossipContact *contact, + EmpathyContact *contact, EmpathyTpContactList *list) { g_signal_handlers_disconnect_by_func (contact, @@ -894,7 +894,7 @@ tp_contact_list_contact_removed_foreach (guint handle, static void tp_contact_list_block_contact (EmpathyTpContactList *list, - GossipContact *contact) + EmpathyContact *contact) { g_signal_handlers_block_by_func (contact, tp_contact_list_groups_updated_cb, @@ -906,7 +906,7 @@ tp_contact_list_block_contact (EmpathyTpContactList *list, static void tp_contact_list_unblock_contact (EmpathyTpContactList *list, - GossipContact *contact) + EmpathyContact *contact) { g_signal_handlers_unblock_by_func (contact, tp_contact_list_groups_updated_cb, @@ -918,10 +918,10 @@ tp_contact_list_unblock_contact (EmpathyTpContactList *list, static gboolean tp_contact_list_find_foreach (guint handle, - GossipContact *contact, + EmpathyContact *contact, gchar *id) { - if (strcmp (gossip_contact_get_id (contact), id) == 0) { + if (strcmp (empathy_contact_get_id (contact), id) == 0) { return TRUE; } @@ -938,7 +938,7 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, EmpathyTpContactList *list) { EmpathyTpContactListPriv *priv; - GossipTelepathyGroup *group; + EmpathyTpGroup *group; TpChan *new_chan; const gchar *bus_name; GArray *members; @@ -960,19 +960,19 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, if (handle_type == TP_HANDLE_TYPE_LIST) { TpContactListType list_type; - group = gossip_telepathy_group_new (new_chan, priv->tp_conn); + group = empathy_tp_group_new (new_chan, priv->tp_conn); list_type = tp_contact_list_get_type (list, group); if (list_type == TP_CONTACT_LIST_TYPE_UNKNOWN) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Type of contact list channel unknown: %s", - gossip_telepathy_group_get_name (group)); + empathy_tp_group_get_name (group)); g_object_unref (new_chan); g_object_unref (group); return; } else { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "New contact list channel of type: %d", list_type); } @@ -997,13 +997,13 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, G_CALLBACK (tp_contact_list_pending_cb), list); - pendings = gossip_telepathy_group_get_local_pending_members_with_info (group); + pendings = empathy_tp_group_get_local_pending_members_with_info (group); if (pendings) { GArray *pending; pending = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1); for (l = pendings; l; l = l->next) { - GossipTpGroupInfo *info; + EmpathyTpGroupInfo *info; info = l->data; @@ -1015,7 +1015,7 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, list); } g_array_free (pending, TRUE); - gossip_telepathy_group_info_list_free (pendings); + empathy_tp_group_info_list_free (pendings); } } if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) { @@ -1030,10 +1030,10 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, g_signal_connect (group, "remote-pending", G_CALLBACK (tp_contact_list_pending_cb), list); - gossip_telepathy_group_get_all_members (group, - &members, - NULL, - &remote_pendings); + empathy_tp_group_get_all_members (group, + &members, + NULL, + &remote_pendings); tp_contact_list_pending_cb (group, remote_pendings, 0, TP_CHANNEL_GROUP_CHANGE_REASON_NONE, @@ -1041,7 +1041,7 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, list); g_array_free (remote_pendings, TRUE); } else { - members = gossip_telepathy_group_get_members (group); + members = empathy_tp_group_get_members (group); } tp_contact_list_added_cb (group, members, 0, @@ -1058,10 +1058,10 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, return; } - group = gossip_telepathy_group_new (new_chan, priv->tp_conn); + group = empathy_tp_group_new (new_chan, priv->tp_conn); - gossip_debug (DEBUG_DOMAIN, "New server-side group channel: %s", - gossip_telepathy_group_get_name (group)); + empathy_debug (DEBUG_DOMAIN, "New server-side group channel: %s", + empathy_tp_group_get_name (group)); dbus_g_proxy_connect_signal (DBUS_G_PROXY (new_chan), "Closed", G_CALLBACK @@ -1076,10 +1076,10 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, G_CALLBACK (tp_contact_list_group_members_removed_cb), list); - members = gossip_telepathy_group_get_members (group); + members = empathy_tp_group_get_members (group); tp_contact_list_group_members_added_cb (group, members, 0, - TP_CHANNEL_GROUP_CHANGE_REASON_NONE, - NULL, list); + TP_CHANNEL_GROUP_CHANGE_REASON_NONE, + NULL, list); g_array_free (members, TRUE); } @@ -1088,15 +1088,15 @@ tp_contact_list_newchannel_cb (DBusGProxy *proxy, static TpContactListType tp_contact_list_get_type (EmpathyTpContactList *list, - GossipTelepathyGroup *group) + EmpathyTpGroup *group) { - EmpathyTpContactListPriv *priv; - TpContactListType list_type; - const gchar *name; + EmpathyTpContactListPriv *priv; + TpContactListType list_type; + const gchar *name; priv = GET_PRIV (list); - name = gossip_telepathy_group_get_name (group); + 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) { @@ -1109,7 +1109,7 @@ tp_contact_list_get_type (EmpathyTpContactList *list, } static void -tp_contact_list_added_cb (GossipTelepathyGroup *group, +tp_contact_list_added_cb (EmpathyTpGroup *group, GArray *handles, guint actor_handle, guint reason, @@ -1126,26 +1126,26 @@ tp_contact_list_added_cb (GossipTelepathyGroup *group, added_list = empathy_tp_contact_list_get_from_handles (list, handles); for (l = added_list; l; l = l->next) { - GossipContact *contact; - GossipSubscription subscription; + EmpathyContact *contact; + EmpathySubscription subscription; - contact = GOSSIP_CONTACT (l->data); + contact = EMPATHY_CONTACT (l->data); - gossip_debug (DEBUG_DOMAIN, "Contact '%s' added to list type %d", - gossip_contact_get_name (contact), + empathy_debug (DEBUG_DOMAIN, "Contact '%s' added to list type %d", + empathy_contact_get_name (contact), list_type); - subscription = gossip_contact_get_subscription (contact); + subscription = empathy_contact_get_subscription (contact); if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) { - subscription |= GOSSIP_SUBSCRIPTION_FROM; + subscription |= EMPATHY_SUBSCRIPTION_FROM; } else if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) { - subscription |= GOSSIP_SUBSCRIPTION_TO; + subscription |= EMPATHY_SUBSCRIPTION_TO; tp_contact_list_remove_local_pending (list, contact); } tp_contact_list_block_contact (list, contact); - gossip_contact_set_subscription (contact, subscription); + empathy_contact_set_subscription (contact, subscription); tp_contact_list_unblock_contact (list, contact); if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) { @@ -1163,7 +1163,7 @@ tp_contact_list_added_cb (GossipTelepathyGroup *group, } static void -tp_contact_list_removed_cb (GossipTelepathyGroup *group, +tp_contact_list_removed_cb (EmpathyTpGroup *group, GArray *handles, guint actor_handle, guint reason, @@ -1180,26 +1180,26 @@ tp_contact_list_removed_cb (GossipTelepathyGroup *group, removed_list = empathy_tp_contact_list_get_from_handles (list, handles); for (l = removed_list; l; l = l->next) { - GossipContact *contact; - GossipSubscription subscription; + EmpathyContact *contact; + EmpathySubscription subscription; - contact = GOSSIP_CONTACT (l->data); + contact = EMPATHY_CONTACT (l->data); - gossip_debug (DEBUG_DOMAIN, "Contact '%s' removed from list type %d", - gossip_contact_get_name (contact), + empathy_debug (DEBUG_DOMAIN, "Contact '%s' removed from list type %d", + empathy_contact_get_name (contact), list_type); - subscription = gossip_contact_get_subscription (contact); + subscription = empathy_contact_get_subscription (contact); if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) { - subscription &= !GOSSIP_SUBSCRIPTION_FROM; + subscription &= !EMPATHY_SUBSCRIPTION_FROM; } else if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) { - subscription &= !GOSSIP_SUBSCRIPTION_TO; + subscription &= !EMPATHY_SUBSCRIPTION_TO; tp_contact_list_remove_local_pending (list, contact); } tp_contact_list_block_contact (list, contact); - gossip_contact_set_subscription (contact, subscription); + empathy_contact_set_subscription (contact, subscription); tp_contact_list_unblock_contact (list, contact); if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) { @@ -1218,7 +1218,7 @@ tp_contact_list_removed_cb (GossipTelepathyGroup *group, } static void -tp_contact_list_pending_cb (GossipTelepathyGroup *group, +tp_contact_list_pending_cb (EmpathyTpGroup *group, GArray *handles, guint actor_handle, guint reason, @@ -1235,12 +1235,12 @@ tp_contact_list_pending_cb (GossipTelepathyGroup *group, pending_list = empathy_tp_contact_list_get_from_handles (list, handles); for (l = pending_list; l; l = l->next) { - GossipContact *contact; + EmpathyContact *contact; - contact = GOSSIP_CONTACT (l->data); + contact = EMPATHY_CONTACT (l->data); - gossip_debug (DEBUG_DOMAIN, "Contact '%s' pending in list type %d", - gossip_contact_get_name (contact), + empathy_debug (DEBUG_DOMAIN, "Contact '%s' pending in list type %d", + empathy_contact_get_name (contact), list_type); if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) { @@ -1269,7 +1269,7 @@ tp_contact_list_pending_cb (GossipTelepathyGroup *group, static void tp_contact_list_remove_local_pending (EmpathyTpContactList *list, - GossipContact *contact) + EmpathyContact *contact) { EmpathyTpContactListPriv *priv; GList *l; @@ -1280,9 +1280,9 @@ tp_contact_list_remove_local_pending (EmpathyTpContactList *list, EmpathyContactListInfo *info; info = l->data; - if (gossip_contact_equal (contact, info->contact)) { - gossip_debug (DEBUG_DOMAIN, "Contact no more local-pending: %s", - gossip_contact_get_name (contact)); + if (empathy_contact_equal (contact, info->contact)) { + empathy_debug (DEBUG_DOMAIN, "Contact no more local-pending: %s", + empathy_contact_get_name (contact)); priv->local_pending = g_list_delete_link (priv->local_pending, l); empathy_contact_list_info_free (info); @@ -1292,7 +1292,7 @@ tp_contact_list_remove_local_pending (EmpathyTpContactList *list, } static void -tp_contact_list_groups_updated_cb (GossipContact *contact, +tp_contact_list_groups_updated_cb (EmpathyContact *contact, GParamSpec *param, EmpathyTpContactList *list) { @@ -1303,12 +1303,12 @@ tp_contact_list_groups_updated_cb (GossipContact *contact, priv = GET_PRIV (list); /* Make sure all groups are created */ - groups = gossip_contact_get_groups (contact); + groups = empathy_contact_get_groups (contact); for (l = groups; l; l = l->next) { tp_contact_list_get_group (list, l->data); } - data.handle = gossip_contact_get_handle (contact); + data.handle = empathy_contact_get_handle (contact); data.new_groups = groups; g_hash_table_foreach (priv->groups, @@ -1317,7 +1317,7 @@ tp_contact_list_groups_updated_cb (GossipContact *contact, } static void -tp_contact_list_name_updated_cb (GossipContact *contact, +tp_contact_list_name_updated_cb (EmpathyContact *contact, GParamSpec *param, EmpathyTpContactList *list) { @@ -1333,10 +1333,10 @@ tp_contact_list_name_updated_cb (GossipContact *contact, return; } - handle = gossip_contact_get_handle (contact); - new_name = gossip_contact_get_name (contact); + handle = empathy_contact_get_handle (contact); + new_name = empathy_contact_get_name (contact); - gossip_debug (DEBUG_DOMAIN, "renaming handle %d to %s", + empathy_debug (DEBUG_DOMAIN, "renaming handle %d to %s", handle, new_name); new_alias = g_hash_table_new_full (g_direct_hash, @@ -1351,7 +1351,7 @@ tp_contact_list_name_updated_cb (GossipContact *contact, if (!tp_conn_iface_aliasing_set_aliases (priv->aliasing_iface, new_alias, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Couldn't rename contact: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -1361,17 +1361,17 @@ tp_contact_list_name_updated_cb (GossipContact *contact, } static void -tp_contact_list_update_groups_foreach (gchar *object_path, - GossipTelepathyGroup *group, - TpContactListData *data) +tp_contact_list_update_groups_foreach (gchar *object_path, + EmpathyTpGroup *group, + TpContactListData *data) { gboolean is_member; gboolean found = FALSE; const gchar *group_name; GList *l; - is_member = gossip_telepathy_group_is_member (group, data->handle); - group_name = gossip_telepathy_group_get_name (group); + is_member = empathy_tp_group_is_member (group, data->handle); + group_name = empathy_tp_group_get_name (group); for (l = data->new_groups; l; l = l->next) { if (strcmp (group_name, l->data) == 0) { @@ -1382,25 +1382,25 @@ tp_contact_list_update_groups_foreach (gchar *object_path, if (is_member && !found) { /* We are no longer member of this group */ - gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'", + empathy_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'", data->handle, group_name); - gossip_telepathy_group_remove_member (group, data->handle, ""); + empathy_tp_group_remove_member (group, data->handle, ""); } if (!is_member && found) { /* We are now member of this group */ - gossip_debug (DEBUG_DOMAIN, "Contact %d added to group '%s'", + empathy_debug (DEBUG_DOMAIN, "Contact %d added to group '%s'", data->handle, group_name); - gossip_telepathy_group_add_member (group, data->handle, ""); + empathy_tp_group_add_member (group, data->handle, ""); } } -static GossipTelepathyGroup * +static EmpathyTpGroup * tp_contact_list_get_group (EmpathyTpContactList *list, const gchar *name) { EmpathyTpContactListPriv *priv; - GossipTelepathyGroup *group; + EmpathyTpGroup *group; TpChan *group_channel; GArray *handles; guint group_handle; @@ -1417,14 +1417,14 @@ tp_contact_list_get_group (EmpathyTpContactList *list, return group; } - gossip_debug (DEBUG_DOMAIN, "creating new group: %s", name); + empathy_debug (DEBUG_DOMAIN, "creating new group: %s", name); if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn), TP_HANDLE_TYPE_GROUP, names, &handles, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Couldn't request the creation of a new handle for group: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -1440,7 +1440,7 @@ tp_contact_list_get_group (EmpathyTpContactList *list, FALSE, &group_object_path, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Couldn't request the creation of a new group channel: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -1461,7 +1461,7 @@ tp_contact_list_get_group (EmpathyTpContactList *list, list, NULL); - group = gossip_telepathy_group_new (group_channel, priv->tp_conn); + group = empathy_tp_group_new (group_channel, priv->tp_conn); g_hash_table_insert (priv->groups, group_object_path, group); g_signal_connect (group, "members-added", G_CALLBACK (tp_contact_list_group_members_added_cb), @@ -1474,11 +1474,11 @@ tp_contact_list_get_group (EmpathyTpContactList *list, } static gboolean -tp_contact_list_find_group (gchar *key, - GossipTelepathyGroup *group, - gchar *group_name) +tp_contact_list_find_group (gchar *key, + EmpathyTpGroup *group, + gchar *group_name) { - if (strcmp (group_name, gossip_telepathy_group_get_name (group)) == 0) { + if (strcmp (group_name, empathy_tp_group_get_name (group)) == 0) { return TRUE; } @@ -1486,13 +1486,13 @@ tp_contact_list_find_group (gchar *key, } static void -tp_contact_list_get_groups_foreach (gchar *key, - GossipTelepathyGroup *group, - GList **groups) +tp_contact_list_get_groups_foreach (gchar *key, + EmpathyTpGroup *group, + GList **groups) { const gchar *name; - name = gossip_telepathy_group_get_name (group); + name = empathy_tp_group_get_name (group); *groups = g_list_append (*groups, g_strdup (name)); } @@ -1509,7 +1509,7 @@ tp_contact_list_group_channel_closed_cb (TpChan *channel, } static void -tp_contact_list_group_members_added_cb (GossipTelepathyGroup *group, +tp_contact_list_group_members_added_cb (EmpathyTpGroup *group, GArray *members, guint actor_handle, guint reason, @@ -1522,16 +1522,16 @@ tp_contact_list_group_members_added_cb (GossipTelepathyGroup *group, priv = GET_PRIV (list); - group_name = gossip_telepathy_group_get_name (group); + group_name = empathy_tp_group_get_name (group); added_list = empathy_tp_contact_list_get_from_handles (list, members); for (l = added_list; l; l = l->next) { - GossipContact *contact; + EmpathyContact *contact; - contact = GOSSIP_CONTACT (l->data); + contact = EMPATHY_CONTACT (l->data); tp_contact_list_block_contact (list, contact); - gossip_contact_add_group (contact, group_name); + empathy_contact_add_group (contact, group_name); tp_contact_list_unblock_contact (list, contact); g_object_unref (contact); @@ -1541,7 +1541,7 @@ tp_contact_list_group_members_added_cb (GossipTelepathyGroup *group, } static void -tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group, +tp_contact_list_group_members_removed_cb (EmpathyTpGroup *group, GArray *members, guint actor_handle, guint reason, @@ -1554,16 +1554,16 @@ tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group, priv = GET_PRIV (list); - group_name = gossip_telepathy_group_get_name (group); + group_name = empathy_tp_group_get_name (group); removed_list = empathy_tp_contact_list_get_from_handles (list, members); for (l = removed_list; l; l = l->next) { - GossipContact *contact; + EmpathyContact *contact; contact = l->data; tp_contact_list_block_contact (list, contact); - gossip_contact_remove_group (contact, group_name); + empathy_contact_remove_group (contact, group_name); tp_contact_list_unblock_contact (list, contact); g_object_unref (contact); @@ -1585,7 +1585,7 @@ tp_contact_list_get_info (EmpathyTpContactList *list, /* FIXME: We should use GetPresence instead */ if (!tp_conn_iface_presence_request_presence (priv->presence_iface, handles, &error)) { - gossip_debug (DEBUG_DOMAIN, + empathy_debug (DEBUG_DOMAIN, "Could not request presences: %s", error ? error->message : "No error given"); g_clear_error (&error); @@ -1675,7 +1675,7 @@ tp_contact_list_avatar_update_cb (DBusGProxy *proxy, return; } - gossip_debug (DEBUG_DOMAIN, "Changing avatar for %d to %s", + empathy_debug (DEBUG_DOMAIN, "Changing avatar for %d to %s", handle, new_token); tp_contact_list_request_avatar (list, handle); @@ -1688,24 +1688,24 @@ tp_contact_list_request_avatar_cb (DBusGProxy *proxy, GError *error, TpContactListAvatarRequestData *data) { - GossipContact *contact; + EmpathyContact *contact; contact = empathy_tp_contact_list_get_from_handle (data->list, data->handle); if (error) { - gossip_debug (DEBUG_DOMAIN, "Error requesting avatar for %s: %s", - gossip_contact_get_name (contact), + empathy_debug (DEBUG_DOMAIN, "Error requesting avatar for %s: %s", + empathy_contact_get_name (contact), error ? error->message : "No error given"); } else { - GossipAvatar *avatar; + EmpathyAvatar *avatar; - avatar = gossip_avatar_new (avatar_data->data, + avatar = empathy_avatar_new (avatar_data->data, avatar_data->len, mime_type); tp_contact_list_block_contact (data->list, contact); - gossip_contact_set_avatar (contact, avatar); + empathy_contact_set_avatar (contact, avatar); tp_contact_list_unblock_contact (data->list, contact); - gossip_avatar_unref (avatar); + empathy_avatar_unref (avatar); } n_avatar_requests--; @@ -1729,7 +1729,7 @@ tp_contact_list_aliases_update_cb (DBusGProxy *proxy, guint handle; const gchar *alias; GValueArray *renamed_struct; - GossipContact *contact; + EmpathyContact *contact; renamed_struct = g_ptr_array_index (renamed_handlers, i); handle = g_value_get_uint(g_value_array_get_nth (renamed_struct, 0)); @@ -1746,11 +1746,11 @@ tp_contact_list_aliases_update_cb (DBusGProxy *proxy, contact = empathy_tp_contact_list_get_from_handle (list, handle); tp_contact_list_block_contact (list, contact); - gossip_contact_set_name (contact, alias); + empathy_contact_set_name (contact, alias); tp_contact_list_unblock_contact (list, contact); g_object_unref (contact); - gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (update cb)", + empathy_debug (DEBUG_DOMAIN, "contact %d renamed to %s (update cb)", handle, alias); } } @@ -1765,21 +1765,21 @@ tp_contact_list_request_aliases_cb (DBusGProxy *proxy, gchar **name; if (error) { - gossip_debug (DEBUG_DOMAIN, "Error requesting aliases: %s", + empathy_debug (DEBUG_DOMAIN, "Error requesting aliases: %s", error->message); } for (name = contact_names; *name && !error; name++) { - GossipContact *contact; + EmpathyContact *contact; contact = empathy_tp_contact_list_get_from_handle (data->list, data->handles[i]); tp_contact_list_block_contact (data->list, contact); - gossip_contact_set_name (contact, *name); + empathy_contact_set_name (contact, *name); tp_contact_list_unblock_contact (data->list, contact); g_object_unref (contact); - gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (request cb)", + empathy_debug (DEBUG_DOMAIN, "contact %d renamed to %s (request cb)", data->handles[i], *name); i++; @@ -1806,8 +1806,8 @@ tp_contact_list_parse_presence_foreach (guint handle, { EmpathyTpContactListPriv *priv; GHashTable *presences_table; - GossipContact *contact; - GossipPresence *presence = NULL; + EmpathyContact *contact; + EmpathyPresence *presence = NULL; priv = GET_PRIV (list); @@ -1823,14 +1823,14 @@ tp_contact_list_parse_presence_foreach (guint handle, (GHFunc) tp_contact_list_presences_table_foreach, &presence); - gossip_debug (DEBUG_DOMAIN, "Presence changed for %s (%d) to %s (%d)", - gossip_contact_get_name (contact), + empathy_debug (DEBUG_DOMAIN, "Presence changed for %s (%d) to %s (%d)", + empathy_contact_get_name (contact), handle, - presence ? gossip_presence_get_status (presence) : "unset", - presence ? gossip_presence_get_state (presence) : MC_PRESENCE_UNSET); + presence ? empathy_presence_get_status (presence) : "unset", + presence ? empathy_presence_get_state (presence) : MC_PRESENCE_UNSET); tp_contact_list_block_contact (list, contact); - gossip_contact_set_presence (contact, presence); + empathy_contact_set_presence (contact, presence); tp_contact_list_unblock_contact (list, contact); g_object_unref (contact); @@ -1839,12 +1839,12 @@ tp_contact_list_parse_presence_foreach (guint handle, static void tp_contact_list_presences_table_foreach (const gchar *state_str, GHashTable *presences_table, - GossipPresence **presence) + EmpathyPresence **presence) { McPresence state; const GValue *message; - state = gossip_presence_state_from_str (state_str); + state = empathy_presence_state_from_str (state_str); if ((state == MC_PRESENCE_UNSET) || (state == MC_PRESENCE_OFFLINE)) { return; } @@ -1854,12 +1854,12 @@ tp_contact_list_presences_table_foreach (const gchar *state_str, *presence = NULL; } - *presence = gossip_presence_new (); - gossip_presence_set_state (*presence, state); + *presence = empathy_presence_new (); + empathy_presence_set_state (*presence, state); message = g_hash_table_lookup (presences_table, "message"); if (message != NULL) { - gossip_presence_set_status (*presence, + empathy_presence_set_status (*presence, g_value_get_string (message)); } } @@ -1879,7 +1879,7 @@ tp_contact_list_status_changed_cb (MissionControl *mc, account = mc_account_lookup (unique_name); if (status != TP_CONN_STATUS_DISCONNECTED || - !gossip_account_equal (account, priv->account) || + !empathy_account_equal (account, priv->account) || !priv->tp_conn) { g_object_unref (account); return; diff --git a/libempathy/empathy-tp-contact-list.h b/libempathy/empathy-tp-contact-list.h index 580741328..f0eccb375 100644 --- a/libempathy/empathy-tp-contact-list.h +++ b/libempathy/empathy-tp-contact-list.h @@ -27,7 +27,7 @@ #include #include -#include "gossip-contact.h" +#include "empathy-contact.h" G_BEGIN_DECLS @@ -53,10 +53,10 @@ struct _EmpathyTpContactListClass { GType empathy_tp_contact_list_get_type (void) G_GNUC_CONST; EmpathyTpContactList * empathy_tp_contact_list_new (McAccount *account); McAccount * empathy_tp_contact_list_get_account (EmpathyTpContactList *list); -GossipContact * empathy_tp_contact_list_get_user (EmpathyTpContactList *list); -GossipContact * empathy_tp_contact_list_get_from_id (EmpathyTpContactList *list, +EmpathyContact * empathy_tp_contact_list_get_user (EmpathyTpContactList *list); +EmpathyContact * empathy_tp_contact_list_get_from_id (EmpathyTpContactList *list, const gchar *id); -GossipContact * empathy_tp_contact_list_get_from_handle (EmpathyTpContactList *list, +EmpathyContact * empathy_tp_contact_list_get_from_handle (EmpathyTpContactList *list, guint handle); GList * empathy_tp_contact_list_get_from_handles (EmpathyTpContactList *list, GArray *handles); diff --git a/libempathy/empathy-tp-group.c b/libempathy/empathy-tp-group.c new file mode 100644 index 000000000..45a5e784d --- /dev/null +++ b/libempathy/empathy-tp-group.c @@ -0,0 +1,542 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2006 Xavier Claessens + * + * 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. + */ + +#include + +#include +#include +#include +#include +#include + +#include "empathy-debug.h" +#include "empathy-tp-group.h" +#include "empathy-marshal.h" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ + EMPATHY_TYPE_TP_GROUP, EmpathyTpGroupPriv)) + +#define DEBUG_DOMAIN "TpGroup" + +struct _EmpathyTpGroupPriv { + DBusGProxy *group_iface; + TpConn *tp_conn; + TpChan *tp_chan; + gchar *group_name; +}; + +static void empathy_tp_group_class_init (EmpathyTpGroupClass *klass); +static void empathy_tp_group_init (EmpathyTpGroup *group); +static void tp_group_finalize (GObject *object); +static void tp_group_destroy_cb (DBusGProxy *proxy, + EmpathyTpGroup *group); +static void tp_group_members_changed_cb (DBusGProxy *group_iface, + gchar *message, + GArray *added, + GArray *removed, + GArray *local_pending, + GArray *remote_pending, + guint actor, + guint reason, + EmpathyTpGroup *group); + +enum { + MEMBERS_ADDED, + MEMBERS_REMOVED, + LOCAL_PENDING, + REMOTE_PENDING, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +G_DEFINE_TYPE (EmpathyTpGroup, empathy_tp_group, G_TYPE_OBJECT); + +static void +empathy_tp_group_class_init (EmpathyTpGroupClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = tp_group_finalize; + + signals[MEMBERS_ADDED] = + g_signal_new ("members-added", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + empathy_marshal_VOID__POINTER_UINT_UINT_STRING, + G_TYPE_NONE, + 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING); + + signals[MEMBERS_REMOVED] = + g_signal_new ("members-removed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + empathy_marshal_VOID__POINTER_UINT_UINT_STRING, + G_TYPE_NONE, + 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING); + + signals[LOCAL_PENDING] = + g_signal_new ("local-pending", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + empathy_marshal_VOID__POINTER_UINT_UINT_STRING, + G_TYPE_NONE, + 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING); + + signals[REMOTE_PENDING] = + g_signal_new ("remote-pending", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + empathy_marshal_VOID__POINTER_UINT_UINT_STRING, + G_TYPE_NONE, + 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING); + + g_type_class_add_private (object_class, sizeof (EmpathyTpGroupPriv)); +} + +static void +empathy_tp_group_init (EmpathyTpGroup *group) +{ +} + +static void +tp_group_finalize (GObject *object) +{ + EmpathyTpGroupPriv *priv; + + priv = GET_PRIV (object); + + if (priv->group_iface) { + g_signal_handlers_disconnect_by_func (priv->group_iface, + tp_group_destroy_cb, + object); + dbus_g_proxy_disconnect_signal (priv->group_iface, "MembersChanged", + G_CALLBACK (tp_group_members_changed_cb), + object); + g_object_unref (priv->group_iface); + } + + if (priv->tp_conn) { + g_object_unref (priv->tp_conn); + } + + if (priv->tp_chan) { + g_object_unref (priv->tp_chan); + } + + g_free (priv->group_name); + + G_OBJECT_CLASS (empathy_tp_group_parent_class)->finalize (object); +} + +EmpathyTpGroup * +empathy_tp_group_new (TpChan *tp_chan, + TpConn *tp_conn) +{ + EmpathyTpGroup *group; + EmpathyTpGroupPriv *priv; + DBusGProxy *group_iface; + + g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); + + group_iface = tp_chan_get_interface (tp_chan, + TELEPATHY_CHAN_IFACE_GROUP_QUARK); + g_return_val_if_fail (group_iface != NULL, NULL); + + group = g_object_new (EMPATHY_TYPE_TP_GROUP, NULL); + priv = GET_PRIV (group); + + priv->tp_conn = g_object_ref (tp_conn); + priv->tp_chan = g_object_ref (tp_chan); + priv->group_iface = g_object_ref (group_iface); + + dbus_g_proxy_connect_signal (priv->group_iface, "MembersChanged", + G_CALLBACK (tp_group_members_changed_cb), + group, NULL); + g_signal_connect (group_iface, "destroy", + G_CALLBACK (tp_group_destroy_cb), + group); + + return group; +} + +void +empathy_tp_group_add_members (EmpathyTpGroup *group, + GArray *handles, + const gchar *message) +{ + EmpathyTpGroupPriv *priv; + GError *error = NULL; + + g_return_if_fail (EMPATHY_IS_TP_GROUP (group)); + g_return_if_fail (handles != NULL); + + priv = GET_PRIV (group); + + if (!tp_chan_iface_group_add_members (priv->group_iface, + handles, + message, + &error)) { + empathy_debug (DEBUG_DOMAIN, + "Failed to add members: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + } +} + +void +empathy_tp_group_add_member (EmpathyTpGroup *group, + guint handle, + const gchar *message) +{ + GArray *handles; + + handles = g_array_new (FALSE, FALSE, sizeof (guint)); + g_array_append_val (handles, handle); + + empathy_tp_group_add_members (group, handles, message); + + g_array_free (handles, TRUE); +} + +void +empathy_tp_group_remove_members (EmpathyTpGroup *group, + GArray *handles, + const gchar *message) +{ + EmpathyTpGroupPriv *priv; + GError *error = NULL; + + g_return_if_fail (EMPATHY_IS_TP_GROUP (group)); + + priv = GET_PRIV (group); + + if (!tp_chan_iface_group_remove_members (priv->group_iface, + handles, + message, + &error)) { + empathy_debug (DEBUG_DOMAIN, + "Failed to remove members: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + } +} + +void +empathy_tp_group_remove_member (EmpathyTpGroup *group, + guint handle, + const gchar *message) +{ + GArray *handles; + + g_return_if_fail (EMPATHY_IS_TP_GROUP (group)); + + handles = g_array_new (FALSE, FALSE, sizeof (guint)); + g_array_append_val (handles, handle); + + empathy_tp_group_remove_members (group, handles, message); + + g_array_free (handles, TRUE); +} + +GArray * +empathy_tp_group_get_members (EmpathyTpGroup *group) +{ + EmpathyTpGroupPriv *priv; + GArray *members; + GError *error = NULL; + + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL); + + priv = GET_PRIV (group); + + if (!tp_chan_iface_group_get_members (priv->group_iface, + &members, + &error)) { + empathy_debug (DEBUG_DOMAIN, + "Couldn't get members: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + return NULL; + } + + return members; +} + +void +empathy_tp_group_get_all_members (EmpathyTpGroup *group, + GArray **members, + GArray **local_pending, + GArray **remote_pending) +{ + EmpathyTpGroupPriv *priv; + GError *error = NULL; + + g_return_if_fail (EMPATHY_IS_TP_GROUP (group)); + + priv = GET_PRIV (group); + + if (!tp_chan_iface_group_get_all_members (priv->group_iface, + members, + local_pending, + remote_pending, + &error)) { + empathy_debug (DEBUG_DOMAIN, + "Couldn't get all members: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + } +} + +GList * +empathy_tp_group_get_local_pending_members_with_info (EmpathyTpGroup *group) +{ + EmpathyTpGroupPriv *priv; + GPtrArray *array; + guint i; + GList *infos = NULL; + GError *error = NULL; + + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL); + + priv = GET_PRIV (group); + + if (!tp_chan_iface_group_get_local_pending_members_with_info (priv->group_iface, + &array, + &error)) { + empathy_debug (DEBUG_DOMAIN, + "GetLocalPendingMembersWithInfo failed: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + + return NULL; + } + + if (!array) { + /* This happens with butterfly because + * GetLocalPendingMembersWithInfo is not + * implemented */ + return NULL; + } + + for (i = 0; array->len > i; i++) { + GValueArray *pending_struct; + EmpathyTpGroupInfo *info; + const gchar *message; + + info = g_slice_new (EmpathyTpGroupInfo); + + pending_struct = g_ptr_array_index (array, i); + info->member = g_value_get_uint (g_value_array_get_nth (pending_struct, 0)); + info->actor = g_value_get_uint (g_value_array_get_nth (pending_struct, 1)); + info->reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2)); + message = g_value_get_string (g_value_array_get_nth (pending_struct, 3)); + info->message = g_strdup (message); + g_value_array_free (pending_struct); + + infos = g_list_prepend (infos, info); + } + g_ptr_array_free (array, TRUE); + + return infos; +} + +void +empathy_tp_group_info_list_free (GList *infos) +{ + GList *l; + + for (l = infos; l; l = l->next) { + EmpathyTpGroupInfo *info; + + info = l->data; + + g_free (info->message); + g_slice_free (EmpathyTpGroupInfo, info); + } + g_list_free (infos); +} + + +static void +tp_group_destroy_cb (DBusGProxy *proxy, + EmpathyTpGroup *group) +{ + EmpathyTpGroupPriv *priv; + + priv = GET_PRIV (group); + + g_object_unref (priv->group_iface); + g_object_unref (priv->tp_conn); + g_object_unref (priv->tp_chan); + priv->group_iface = NULL; + priv->tp_chan = NULL; + priv->tp_conn = NULL; +} + +static void +tp_group_members_changed_cb (DBusGProxy *group_iface, + gchar *message, + GArray *added, + GArray *removed, + GArray *local_pending, + GArray *remote_pending, + guint actor, + guint reason, + EmpathyTpGroup *group) +{ + EmpathyTpGroupPriv *priv; + + priv = GET_PRIV (group); + + /* emit signals */ + if (added->len > 0) { + g_signal_emit (group, signals[MEMBERS_ADDED], 0, + added, actor, reason, message); + } + if (removed->len > 0) { + g_signal_emit (group, signals[MEMBERS_REMOVED], 0, + removed, actor, reason, message); + } + if (local_pending->len > 0) { + g_signal_emit (group, signals[LOCAL_PENDING], 0, + local_pending, actor, reason, message); + } + if (remote_pending->len > 0) { + g_signal_emit (group, signals[REMOTE_PENDING], 0, + remote_pending, actor, reason, message); + } +} + +const gchar * +empathy_tp_group_get_name (EmpathyTpGroup *group) +{ + TelepathyHandleType handle_type; + guint channel_handle; + GArray *group_handles; + gchar **group_names; + GError *error = NULL; + + EmpathyTpGroupPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL); + + priv = GET_PRIV (group); + + /* Lazy initialisation */ + if (priv->group_name) { + return priv->group_name; + } + + if (!tp_chan_get_handle (DBUS_G_PROXY (priv->tp_chan), + &handle_type, + &channel_handle, + &error)) { + empathy_debug (DEBUG_DOMAIN, + "Couldn't retreive channel handle for group: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + return NULL; + } + + group_handles = g_array_new (FALSE, FALSE, sizeof (guint)); + g_array_append_val (group_handles, channel_handle); + if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn), + handle_type, + group_handles, + &group_names, + &error)) { + empathy_debug (DEBUG_DOMAIN, + "Couldn't get group name: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + g_array_free (group_handles, TRUE); + return NULL; + } + + priv->group_name = *group_names; + g_array_free (group_handles, TRUE); + g_free (group_names); + + return priv->group_name; +} + +guint +empathy_tp_group_get_self_handle (EmpathyTpGroup *group) +{ + EmpathyTpGroupPriv *priv; + guint handle; + GError *error = NULL; + + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), 0 ); + + priv = GET_PRIV (group); + + if (!tp_chan_iface_group_get_self_handle (priv->group_iface, &handle, &error)) { + empathy_debug (DEBUG_DOMAIN, + "Failed to get self handle: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + return 0; + } + + return handle; +} + +const gchar * +empathy_tp_group_get_object_path (EmpathyTpGroup *group) +{ + EmpathyTpGroupPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL); + + priv = GET_PRIV (group); + + return dbus_g_proxy_get_path (DBUS_G_PROXY (priv->tp_chan)); +} + +gboolean +empathy_tp_group_is_member (EmpathyTpGroup *group, + guint handle) +{ + GArray *members; + guint i; + gboolean found = FALSE; + + members = empathy_tp_group_get_members (group); + for (i = 0; i < members->len; i++) { + if (g_array_index (members, guint, i) == handle) { + found = TRUE; + break; + } + } + g_array_free (members, TRUE); + + return found; +} + diff --git a/libempathy/empathy-tp-group.h b/libempathy/empathy-tp-group.h new file mode 100644 index 000000000..2381ea10e --- /dev/null +++ b/libempathy/empathy-tp-group.h @@ -0,0 +1,86 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2006 Xavier Claessens + * + * 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_TP_GROUP_H__ +#define __EMPATHY_TP_GROUP_H__ + +#include + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_TP_GROUP (empathy_tp_group_get_type ()) +#define EMPATHY_TP_GROUP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_TP_GROUP, EmpathyTpGroup)) +#define EMPATHY_TP_GROUP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_TP_GROUP, EmpathyTpGroupClass)) +#define EMPATHY_IS_TP_GROUP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_TP_GROUP)) +#define EMPATHY_IS_TP_GROUP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_TP_GROUP)) +#define EMPATHY_TP_GROUP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_TP_GROUP, EmpathyTpGroupClass)) + +typedef struct _EmpathyTpGroup EmpathyTpGroup; +typedef struct _EmpathyTpGroupClass EmpathyTpGroupClass; +typedef struct _EmpathyTpGroupPriv EmpathyTpGroupPriv; + +struct _EmpathyTpGroup { + GObject parent; +}; + +struct _EmpathyTpGroupClass { + GObjectClass parent_class; +}; + +typedef struct { + guint member; + guint actor; + guint reason; + gchar *message; +} EmpathyTpGroupInfo; + +GType empathy_tp_group_get_type (void) G_GNUC_CONST; +EmpathyTpGroup * empathy_tp_group_new (TpChan *tp_chan, + TpConn *tp_conn); +void empathy_tp_group_add_members (EmpathyTpGroup *group, + GArray *handles, + const gchar *message); +void empathy_tp_group_add_member (EmpathyTpGroup *group, + guint handle, + const gchar *message); +void empathy_tp_group_remove_members (EmpathyTpGroup *group, + GArray *handle, + const gchar *message); +void empathy_tp_group_remove_member (EmpathyTpGroup *group, + guint handle, + const gchar *message); +GArray * empathy_tp_group_get_members (EmpathyTpGroup *group); +void empathy_tp_group_get_all_members (EmpathyTpGroup *group, + GArray **members, + GArray **local_pending, + GArray **remote_pending); +GList * empathy_tp_group_get_local_pending_members_with_info (EmpathyTpGroup *group); +void empathy_tp_group_info_list_free (GList *infos); +const gchar * empathy_tp_group_get_name (EmpathyTpGroup *group); +guint empathy_tp_group_get_self_handle (EmpathyTpGroup *group); +const gchar * empathy_tp_group_get_object_path (EmpathyTpGroup *group); +gboolean empathy_tp_group_is_member (EmpathyTpGroup *group, + guint handle); + +G_END_DECLS + +#endif /* __EMPATHY_TP_GROUP_H__ */ diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c new file mode 100644 index 000000000..74a6bc076 --- /dev/null +++ b/libempathy/empathy-utils.c @@ -0,0 +1,495 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007 Collabora Ltd. + * + * 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 + * Martyn Russell + * Xavier Claessens + */ + +#include "config.h" + +#include +#include +#include +#include + +#include + +#include +#include + +#include "empathy-debug.h" +#include "empathy-utils.h" +#include "empathy-contact-manager.h" + +#define DEBUG_DOMAIN "Utils" + +static void regex_init (void); + +gchar * +empathy_substring (const gchar *str, + gint start, + gint end) +{ + return g_strndup (str + start, end - start); +} + +/* + * Regular Expression code to match urls. + */ +#define USERCHARS "-A-Za-z0-9" +#define PASSCHARS "-A-Za-z0-9,?;.:/!%$^*&~\"#'" +#define HOSTCHARS "-A-Za-z0-9" +#define PATHCHARS "-A-Za-z0-9_$.+!*(),;:@&=?/~#%" +#define SCHEME "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)" +#define USER "[" USERCHARS "]+(:["PASSCHARS "]+)?" +#define URLPATH "/[" PATHCHARS "]*[^]'.}>) \t\r\n,\\\"]" + +static regex_t dingus[EMPATHY_REGEX_ALL]; + +static void +regex_init (void) +{ + static gboolean inited = FALSE; + const gchar *expression; + gint i; + + if (inited) { + return; + } + + for (i = 0; i < EMPATHY_REGEX_ALL; i++) { + switch (i) { + case EMPATHY_REGEX_AS_IS: + expression = + SCHEME "//(" USER "@)?[" HOSTCHARS ".]+" + "(:[0-9]+)?(" URLPATH ")?"; + break; + case EMPATHY_REGEX_BROWSER: + expression = + "(www|ftp)[" HOSTCHARS "]*\\.[" HOSTCHARS ".]+" + "(:[0-9]+)?(" URLPATH ")?"; + break; + case EMPATHY_REGEX_EMAIL: + expression = + "(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9]" + "[a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+"; + break; + case EMPATHY_REGEX_OTHER: + expression = + "news:[-A-Z\\^_a-z{|}~!\"#$%&'()*+,./0-9;:=?`]+" + "@[" HOSTCHARS ".]+(:[0-9]+)?"; + break; + default: + /* Silence the compiler. */ + expression = NULL; + continue; + } + + memset (&dingus[i], 0, sizeof (regex_t)); + regcomp (&dingus[i], expression, REG_EXTENDED | REG_ICASE); + } + + inited = TRUE; +} + +gint +empathy_regex_match (EmpathyRegExType type, + const gchar *msg, + GArray *start, + GArray *end) +{ + regmatch_t matches[1]; + gint ret = 0; + gint num_matches = 0; + gint offset = 0; + gint i; + + g_return_val_if_fail (type >= 0 || type <= EMPATHY_REGEX_ALL, 0); + + regex_init (); + + while (!ret && type != EMPATHY_REGEX_ALL) { + ret = regexec (&dingus[type], msg + offset, 1, matches, 0); + if (ret == 0) { + gint s; + + num_matches++; + + s = matches[0].rm_so + offset; + offset = matches[0].rm_eo + offset; + + g_array_append_val (start, s); + g_array_append_val (end, offset); + } + } + + if (type != EMPATHY_REGEX_ALL) { + empathy_debug (DEBUG_DOMAIN, + "Found %d matches for regex type:%d", + num_matches, type); + return num_matches; + } + + /* If EMPATHY_REGEX_ALL then we run ALL regex's on the string. */ + for (i = 0; i < EMPATHY_REGEX_ALL; i++, ret = 0) { + while (!ret) { + ret = regexec (&dingus[i], msg + offset, 1, matches, 0); + if (ret == 0) { + gint s; + + num_matches++; + + s = matches[0].rm_so + offset; + offset = matches[0].rm_eo + offset; + + g_array_append_val (start, s); + g_array_append_val (end, offset); + } + } + } + + empathy_debug (DEBUG_DOMAIN, + "Found %d matches for ALL regex types", + num_matches); + + return num_matches; +} + +gint +empathy_strcasecmp (const gchar *s1, + const gchar *s2) +{ + return empathy_strncasecmp (s1, s2, -1); +} + +gint +empathy_strncasecmp (const gchar *s1, + const gchar *s2, + gsize n) +{ + gchar *u1, *u2; + gint ret_val; + + u1 = g_utf8_casefold (s1, n); + u2 = g_utf8_casefold (s2, n); + + ret_val = g_utf8_collate (u1, u2); + g_free (u1); + g_free (u2); + + return ret_val; +} + +gboolean +empathy_xml_validate (xmlDoc *doc, + const gchar *dtd_filename) +{ + gchar *path, *escaped; + xmlValidCtxt cvp; + xmlDtd *dtd; + gboolean ret; + + path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL); + + /* The list of valid chars is taken from libxml. */ + escaped = xmlURIEscapeStr (path, ":@&=+$,/?;"); + + g_free (path); + + memset (&cvp, 0, sizeof (cvp)); + dtd = xmlParseDTD (NULL, escaped); + ret = xmlValidateDtd (&cvp, doc, dtd); + + xmlFree (escaped); + xmlFreeDtd (dtd); + + return ret; +} + +xmlNodePtr +empathy_xml_node_get_child (xmlNodePtr node, + const gchar *child_name) +{ + xmlNodePtr l; + + g_return_val_if_fail (node != NULL, NULL); + g_return_val_if_fail (child_name != NULL, NULL); + + for (l = node->children; l; l = l->next) { + if (l->name && strcmp (l->name, child_name) == 0) { + return l; + } + } + + return NULL; +} + +xmlChar * +empathy_xml_node_get_child_content (xmlNodePtr node, + const gchar *child_name) +{ + xmlNodePtr l; + + g_return_val_if_fail (node != NULL, NULL); + g_return_val_if_fail (child_name != NULL, NULL); + + l = empathy_xml_node_get_child (node, child_name); + if (l) { + return xmlNodeGetContent (l); + } + + return NULL; +} + +xmlNodePtr +empathy_xml_node_find_child_prop_value (xmlNodePtr node, + const gchar *prop_name, + const gchar *prop_value) +{ + xmlNodePtr l; + xmlNodePtr found = NULL; + + g_return_val_if_fail (node != NULL, NULL); + g_return_val_if_fail (prop_name != NULL, NULL); + g_return_val_if_fail (prop_value != NULL, NULL); + + for (l = node->children; l && !found; l = l->next) { + xmlChar *prop; + + if (!xmlHasProp (l, prop_name)) { + continue; + } + + prop = xmlGetProp (l, prop_name); + if (prop && strcmp (prop, prop_value) == 0) { + found = l; + } + + xmlFree (prop); + } + + return found; +} + +GType +empathy_dbus_type_to_g_type (const gchar *dbus_type_string) +{ + if (dbus_type_string == NULL) + return G_TYPE_NONE; + + if (dbus_type_string[0] == 's') { + return G_TYPE_STRING; + } + else if (dbus_type_string[0] == 'b') { + return G_TYPE_BOOLEAN; + } + else if (dbus_type_string[0] == 'q') { + return G_TYPE_UINT; + } + else if (dbus_type_string[0] == 'n') { + return G_TYPE_INT; + } + + g_assert_not_reached (); + return G_TYPE_NONE; +} + +const gchar * +empathy_g_type_to_dbus_type (GType g_type) +{ + switch (g_type) { + case G_TYPE_STRING: + return "s"; + case G_TYPE_BOOLEAN: + return "b"; + case G_TYPE_UINT: + return "q"; + case G_TYPE_INT: + return "n"; + default: + g_assert_not_reached (); + } + + return NULL; +} + +gchar * +empathy_g_value_to_string (const GValue *value) +{ + gchar *return_string = NULL; + GValue string_g_value = {0, }; + + g_value_init (&string_g_value, G_TYPE_STRING); + g_value_transform (value, &string_g_value); + return_string = g_value_dup_string (&string_g_value); + g_value_unset (&string_g_value); + + return return_string; +} + +GValue * +empathy_string_to_g_value (const gchar *str, GType type) +{ + GValue *g_value; + + g_value = g_new0 (GValue, 1); + g_value_init (g_value, type); + + switch (type) { + case G_TYPE_STRING: + g_value_set_string (g_value, str); + break; + case G_TYPE_BOOLEAN: + g_value_set_boolean (g_value, (str[0] == 'y' || str[0] == 'T')); + break; + case G_TYPE_UINT: + g_value_set_uint (g_value, atoi (str)); + break; + case G_TYPE_INT: + g_value_set_int (g_value, atoi (str)); + break; + default: + g_assert_not_reached (); + } + + return g_value; +} + +gboolean +empathy_g_value_equal (const GValue *value1, + const GValue *value2) +{ + GType type; + + g_return_val_if_fail (value1 != NULL, FALSE); + g_return_val_if_fail (value2 != NULL, FALSE); + + type = G_VALUE_TYPE (value1); + if (type != G_VALUE_TYPE (value2)) { + return FALSE; + } + + switch (type) + { + case G_TYPE_STRING: { + const gchar *str1; + const gchar *str2; + + str1 = g_value_get_string (value1); + str2 = g_value_get_string (value2); + return (str1 && str2 && strcmp (str1, str2) == 0) || + (G_STR_EMPTY (str1) && G_STR_EMPTY (str2)); + } + case G_TYPE_BOOLEAN: + return g_value_get_boolean (value1) == g_value_get_boolean (value2); + case G_TYPE_UINT: + return g_value_get_uint (value1) == g_value_get_uint (value2); + case G_TYPE_INT: + return g_value_get_int (value1) == g_value_get_int (value2); + default: + g_warning ("Unsupported GType in value comparaison"); + } + + return FALSE; +} + +guint +empathy_account_hash (gconstpointer key) +{ + return g_str_hash (mc_account_get_unique_name (MC_ACCOUNT (key))); +} + +gboolean +empathy_account_equal (gconstpointer a, + gconstpointer b) +{ + const gchar *name_a; + const gchar *name_b; + + name_a = mc_account_get_unique_name (MC_ACCOUNT (a)); + name_b = mc_account_get_unique_name (MC_ACCOUNT (b)); + + return g_str_equal (name_a, name_b); +} + +MissionControl * +empathy_mission_control_new (void) +{ + static MissionControl *mc = NULL; + + if (!mc) { + mc = mission_control_new (tp_get_bus ()); + g_object_add_weak_pointer (G_OBJECT (mc), (gpointer) &mc); + } else { + g_object_ref (mc); + } + + return mc; +} + +gchar * +empathy_get_channel_id (McAccount *account, + TpChan *tp_chan) +{ + MissionControl *mc; + TpConn *tp_conn; + GArray *handles; + gchar **names; + gchar *name; + GError *error; + + g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); + + mc = empathy_mission_control_new (); + tp_conn = mission_control_get_connection (mc, account, NULL); + g_object_unref (mc); + + if (!tp_conn) { + return NULL; + } + + /* Get the handle's name */ + handles = g_array_new (FALSE, FALSE, sizeof (guint)); + g_array_append_val (handles, tp_chan->handle); + if (!tp_conn_inspect_handles (DBUS_G_PROXY (tp_conn), + tp_chan->handle_type, + handles, + &names, + &error)) { + empathy_debug (DEBUG_DOMAIN, + "Couldn't get id: %s", + error ? error->message : "No error given"); + + g_clear_error (&error); + g_array_free (handles, TRUE); + g_object_unref (tp_conn); + + return NULL; + } + + name = *names; + g_free (names); + g_object_unref (tp_conn); + + return name; +} + diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h new file mode 100644 index 000000000..17be9ed3c --- /dev/null +++ b/libempathy/empathy-utils.h @@ -0,0 +1,100 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007 Collabora Ltd. + * + * 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 + * Martyn Russell + * Xavier Claessens + */ + +#ifndef __EMPATHY_UTILS_H__ +#define __EMPATHY_UTILS_H__ + +#include +#include + +#include +#include + +#include + +#include +#include + +#include "empathy-contact.h" + +G_BEGIN_DECLS + +#define G_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') + +typedef enum { + EMPATHY_REGEX_AS_IS, + EMPATHY_REGEX_BROWSER, + EMPATHY_REGEX_EMAIL, + EMPATHY_REGEX_OTHER, + EMPATHY_REGEX_ALL, +} EmpathyRegExType; + +/* Regular expressions */ +gchar * empathy_substring (const gchar *str, + gint start, + gint end); +gint empathy_regex_match (EmpathyRegExType type, + const gchar *msg, + GArray *start, + GArray *end); + +/* Strings */ +gint empathy_strcasecmp (const gchar *s1, + const gchar *s2); +gint empathy_strncasecmp (const gchar *s1, + const gchar *s2, + gsize n); + +/* XML */ +gboolean empathy_xml_validate (xmlDoc *doc, + const gchar *dtd_filename); +xmlNodePtr empathy_xml_node_get_child (xmlNodePtr node, + const gchar *child_name); +xmlChar * empathy_xml_node_get_child_content (xmlNodePtr node, + const gchar *child_name); +xmlNodePtr empathy_xml_node_find_child_prop_value (xmlNodePtr node, + const gchar *prop_name, + const gchar *prop_value); + + +/* GValue/GType */ +GType empathy_dbus_type_to_g_type (const gchar *dbus_type_string); +const gchar *empathy_g_type_to_dbus_type (GType g_type); +gchar * empathy_g_value_to_string (const GValue *value); +GValue * empathy_string_to_g_value (const gchar *str, + GType type); +gboolean empathy_g_value_equal (const GValue *value1, + const GValue *value2); + +guint empathy_account_hash (gconstpointer key); +gboolean empathy_account_equal (gconstpointer a, + gconstpointer b); +MissionControl *empathy_mission_control_new (void); +gchar * empathy_get_channel_id (McAccount *account, + TpChan *tp_chan); + +G_END_DECLS + +#endif /* __EMPATHY_UTILS_H__ */ diff --git a/libempathy/gossip-avatar.c b/libempathy/gossip-avatar.c deleted file mode 100644 index 5c17a5176..000000000 --- a/libempathy/gossip-avatar.c +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2002-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 - * Xavier Claessens - */ - -#include "config.h" - -#include "gossip-avatar.h" - -#define DEBUG_DOMAIN "Avatar" - -GType -gossip_avatar_get_gtype (void) -{ - static GType type_id = 0; - - if (!type_id) { - type_id = g_boxed_type_register_static ("GossipAvatar", - (GBoxedCopyFunc) gossip_avatar_ref, - (GBoxedFreeFunc) gossip_avatar_unref); - } - - return type_id; -} - -GossipAvatar * -gossip_avatar_new (guchar *data, - gsize len, - gchar *format) -{ - GossipAvatar *avatar; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (len > 0, NULL); - g_return_val_if_fail (format != NULL, NULL); - - avatar = g_slice_new0 (GossipAvatar); - avatar->data = g_memdup (data, len); - avatar->len = len; - avatar->format = g_strdup (format); - avatar->refcount = 1; - - return avatar; -} - -void -gossip_avatar_unref (GossipAvatar *avatar) -{ - g_return_if_fail (avatar != NULL); - - avatar->refcount--; - if (avatar->refcount == 0) { - g_free (avatar->data); - g_free (avatar->format); - g_slice_free (GossipAvatar, avatar); - } -} - -GossipAvatar * -gossip_avatar_ref (GossipAvatar *avatar) -{ - g_return_val_if_fail (avatar != NULL, NULL); - - avatar->refcount++; - - return avatar; -} - diff --git a/libempathy/gossip-avatar.h b/libempathy/gossip-avatar.h deleted file mode 100644 index 44fa9aba3..000000000 --- a/libempathy/gossip-avatar.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2006 Xavier Claessens - * - * 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 __GOSSIP_AVATAR_H__ -#define __GOSSIP_AVATAR_H__ - -#include - -G_BEGIN_DECLS - -#define GOSSIP_TYPE_AVATAR (gossip_avatar_get_gtype ()) - -typedef struct _GossipAvatar GossipAvatar; - -struct _GossipAvatar { - guchar *data; - gsize len; - gchar *format; - guint refcount; -}; - -GType gossip_avatar_get_gtype (void) G_GNUC_CONST; -GossipAvatar * gossip_avatar_new (guchar *avatar, - gsize len, - gchar *format); -GossipAvatar * gossip_avatar_ref (GossipAvatar *avatar); -void gossip_avatar_unref (GossipAvatar *avatar); - -G_END_DECLS - -#endif /* __GOSSIP_AVATAR_H__ */ diff --git a/libempathy/gossip-chatroom-manager.c b/libempathy/gossip-chatroom-manager.c deleted file mode 100644 index cc6aa81ad..000000000 --- a/libempathy/gossip-chatroom-manager.c +++ /dev/null @@ -1,501 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004-2007 Imendio AB - * Copyright (C) 2007 Collabora Ltd. - * - * 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: Xavier Claessens - * Martyn Russell - */ - -#include "config.h" - -#include -#include -#include - -#include -#include - -#include "gossip-debug.h" -#include "gossip-chatroom-manager.h" -#include "gossip-utils.h" - -#define DEBUG_DOMAIN "ChatroomManager" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CHATROOM_MANAGER, GossipChatroomManagerPriv)) - -#define CHATROOMS_XML_FILENAME "chatrooms.xml" -#define CHATROOMS_DTD_FILENAME "gossip-chatroom-manager.dtd" - -struct _GossipChatroomManagerPriv { - GList *chatrooms; -}; - -static void gossip_chatroom_manager_class_init (GossipChatroomManagerClass *klass); -static void gossip_chatroom_manager_init (GossipChatroomManager *manager); -static void chatroom_manager_finalize (GObject *object); -static gboolean chatroom_manager_get_all (GossipChatroomManager *manager); -static gboolean chatroom_manager_file_parse (GossipChatroomManager *manager, - const gchar *filename); -static void chatroom_manager_parse_chatroom (GossipChatroomManager *manager, - xmlNodePtr node); -static gboolean chatroom_manager_file_save (GossipChatroomManager *manager); - -enum { - CHATROOM_ADDED, - CHATROOM_REMOVED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -G_DEFINE_TYPE (GossipChatroomManager, gossip_chatroom_manager, G_TYPE_OBJECT); - -static void -gossip_chatroom_manager_class_init (GossipChatroomManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = chatroom_manager_finalize; - - signals[CHATROOM_ADDED] = - g_signal_new ("chatroom-added", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, GOSSIP_TYPE_CHATROOM); - signals[CHATROOM_REMOVED] = - g_signal_new ("chatroom-removed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, GOSSIP_TYPE_CHATROOM); - - g_type_class_add_private (object_class, - sizeof (GossipChatroomManagerPriv)); -} - -static void -gossip_chatroom_manager_init (GossipChatroomManager *manager) -{ - GossipChatroomManagerPriv *priv; - - priv = GET_PRIV (manager); -} - -static void -chatroom_manager_finalize (GObject *object) -{ - GossipChatroomManagerPriv *priv; - - priv = GET_PRIV (object); - - g_list_foreach (priv->chatrooms, (GFunc) g_object_unref, NULL); - g_list_free (priv->chatrooms); - - (G_OBJECT_CLASS (gossip_chatroom_manager_parent_class)->finalize) (object); -} - -GossipChatroomManager * -gossip_chatroom_manager_new (void) -{ - static GossipChatroomManager *manager = NULL; - - if (!manager) { - GossipChatroomManagerPriv *priv; - - manager = g_object_new (GOSSIP_TYPE_CHATROOM_MANAGER, NULL); - priv = GET_PRIV (manager); - chatroom_manager_get_all (manager); - - g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager); - } else { - g_object_ref (manager); - } - - return manager; -} - -gboolean -gossip_chatroom_manager_add (GossipChatroomManager *manager, - GossipChatroom *chatroom) -{ - GossipChatroomManagerPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM_MANAGER (manager), FALSE); - g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), FALSE); - - priv = GET_PRIV (manager); - - /* don't add more than once */ - if (!gossip_chatroom_manager_find (manager, - gossip_chatroom_get_account (chatroom), - gossip_chatroom_get_room (chatroom))) { - priv->chatrooms = g_list_prepend (priv->chatrooms, g_object_ref (chatroom)); - chatroom_manager_file_save (manager); - - g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); - - return TRUE; - } - - return FALSE; -} - -void -gossip_chatroom_manager_remove (GossipChatroomManager *manager, - GossipChatroom *chatroom) -{ - GossipChatroomManagerPriv *priv; - GList *l; - - g_return_if_fail (GOSSIP_IS_CHATROOM_MANAGER (manager)); - g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); - - priv = GET_PRIV (manager); - - for (l = priv->chatrooms; l; l = l->next) { - GossipChatroom *this_chatroom; - - this_chatroom = l->data; - - if (gossip_chatroom_equal (chatroom, this_chatroom)) { - priv->chatrooms = g_list_delete_link (priv->chatrooms, l); - - chatroom_manager_file_save (manager); - - g_signal_emit (manager, signals[CHATROOM_REMOVED], 0, this_chatroom); - g_object_unref (this_chatroom); - break; - } - } -} - -GossipChatroom * -gossip_chatroom_manager_find (GossipChatroomManager *manager, - McAccount *account, - const gchar *room) -{ - GossipChatroomManagerPriv *priv; - GList *l; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM_MANAGER (manager), NULL); - g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (room != NULL, NULL); - - priv = GET_PRIV (manager); - - for (l = priv->chatrooms; l; l = l->next) { - GossipChatroom *chatroom; - McAccount *this_account; - const gchar *this_room; - - chatroom = l->data; - this_account = gossip_chatroom_get_account (chatroom); - this_room = gossip_chatroom_get_room (chatroom); - - if (this_account && this_room && - gossip_account_equal (account, this_account) && - strcmp (this_room, room) == 0) { - return chatroom; - } - } - - return NULL; -} - -GList * -gossip_chatroom_manager_get_chatrooms (GossipChatroomManager *manager, - McAccount *account) -{ - GossipChatroomManagerPriv *priv; - GList *chatrooms, *l; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM_MANAGER (manager), NULL); - - priv = GET_PRIV (manager); - - if (!account) { - return g_list_copy (priv->chatrooms); - } - - chatrooms = NULL; - for (l = priv->chatrooms; l; l = l->next) { - GossipChatroom *chatroom; - - chatroom = l->data; - - if (gossip_account_equal (account, - gossip_chatroom_get_account (chatroom))) { - chatrooms = g_list_append (chatrooms, chatroom); - } - } - - return chatrooms; -} - -guint -gossip_chatroom_manager_get_count (GossipChatroomManager *manager, - McAccount *account) -{ - GossipChatroomManagerPriv *priv; - GList *l; - guint count = 0; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM_MANAGER (manager), 0); - - priv = GET_PRIV (manager); - - if (!account) { - return g_list_length (priv->chatrooms); - } - - for (l = priv->chatrooms; l; l = l->next) { - GossipChatroom *chatroom; - - chatroom = l->data; - - if (gossip_account_equal (account, - gossip_chatroom_get_account (chatroom))) { - count++; - } - } - - return count; -} - -void -gossip_chatroom_manager_store (GossipChatroomManager *manager) -{ - g_return_if_fail (GOSSIP_IS_CHATROOM_MANAGER (manager)); - - chatroom_manager_file_save (manager); -} - -/* - * API to save/load and parse the chatrooms file. - */ - -static gboolean -chatroom_manager_get_all (GossipChatroomManager *manager) -{ - GossipChatroomManagerPriv *priv; - gchar *dir; - gchar *file_with_path = NULL; - - priv = GET_PRIV (manager); - - dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); - if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { - g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); - } - - file_with_path = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL); - g_free (dir); - - /* read file in */ - if (g_file_test (file_with_path, G_FILE_TEST_EXISTS) && - !chatroom_manager_file_parse (manager, file_with_path)) { - g_free (file_with_path); - return FALSE; - } - - g_free (file_with_path); - - return TRUE; -} - -static gboolean -chatroom_manager_file_parse (GossipChatroomManager *manager, - const gchar *filename) -{ - GossipChatroomManagerPriv *priv; - xmlParserCtxtPtr ctxt; - xmlDocPtr doc; - xmlNodePtr chatrooms; - xmlNodePtr node; - - priv = GET_PRIV (manager); - - gossip_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 FALSE; - } - - if (!gossip_xml_validate (doc, CHATROOMS_DTD_FILENAME)) { - g_warning ("Failed to validate file:'%s'", filename); - xmlFreeDoc(doc); - xmlFreeParserCtxt (ctxt); - return FALSE; - } - - /* The root node, chatrooms. */ - chatrooms = xmlDocGetRootElement (doc); - - for (node = chatrooms->children; node; node = node->next) { - if (strcmp ((gchar *) node->name, "chatroom") == 0) { - chatroom_manager_parse_chatroom (manager, node); - } - } - - gossip_debug (DEBUG_DOMAIN, - "Parsed %d chatrooms", - g_list_length (priv->chatrooms)); - - xmlFreeDoc(doc); - xmlFreeParserCtxt (ctxt); - - return TRUE; -} - -static void -chatroom_manager_parse_chatroom (GossipChatroomManager *manager, - xmlNodePtr node) -{ - GossipChatroomManagerPriv *priv; - GossipChatroom *chatroom; - McAccount *account; - xmlNodePtr child; - gchar *str; - gchar *name; - gchar *room; - gchar *account_id; - gboolean auto_connect; - - priv = GET_PRIV (manager); - - /* default values. */ - name = NULL; - room = NULL; - auto_connect = TRUE; - account_id = NULL; - - for (child = node->children; child; child = child->next) { - gchar *tag; - - if (xmlNodeIsText (child)) { - continue; - } - - tag = (gchar *) child->name; - str = (gchar *) xmlNodeGetContent (child); - - if (strcmp (tag, "name") == 0) { - name = g_strdup (str); - } - else if (strcmp (tag, "room") == 0) { - room = g_strdup (str); - } - else if (strcmp (tag, "auto_connect") == 0) { - if (strcmp (str, "yes") == 0) { - auto_connect = TRUE; - } else { - auto_connect = FALSE; - } - } - else if (strcmp (tag, "account") == 0) { - account_id = g_strdup (str); - } - - xmlFree (str); - } - - account = mc_account_lookup (account_id); - if (!account) { - g_free (name); - g_free (room); - g_free (account_id); - return; - } - - chatroom = gossip_chatroom_new_full (account, room, name, auto_connect); - priv->chatrooms = g_list_prepend (priv->chatrooms, chatroom); - g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); - - g_object_unref (account); - g_free (name); - g_free (room); - g_free (account_id); -} - -static gboolean -chatroom_manager_file_save (GossipChatroomManager *manager) -{ - GossipChatroomManagerPriv *priv; - xmlDocPtr doc; - xmlNodePtr root; - GList *l; - gchar *dir; - gchar *file; - - priv = GET_PRIV (manager); - - dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); - if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { - g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); - } - - file = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL); - g_free (dir); - - doc = xmlNewDoc ("1.0"); - root = xmlNewNode (NULL, "chatrooms"); - xmlDocSetRootElement (doc, root); - - for (l = priv->chatrooms; l; l = l->next) { - GossipChatroom *chatroom; - xmlNodePtr node; - const gchar *account_id; - - chatroom = l->data; - account_id = mc_account_get_unique_name (gossip_chatroom_get_account (chatroom)); - - node = xmlNewChild (root, NULL, "chatroom", NULL); - xmlNewTextChild (node, NULL, "name", gossip_chatroom_get_name (chatroom)); - xmlNewTextChild (node, NULL, "room", gossip_chatroom_get_room (chatroom)); - xmlNewTextChild (node, NULL, "account", account_id); - xmlNewTextChild (node, NULL, "auto_connect", gossip_chatroom_get_auto_connect (chatroom) ? "yes" : "no"); - } - - /* Make sure the XML is indented properly */ - xmlIndentTreeOutput = 1; - - gossip_debug (DEBUG_DOMAIN, "Saving file:'%s'", file); - xmlSaveFormatFileEnc (file, doc, "utf-8", 1); - xmlFreeDoc (doc); - - xmlCleanupParser (); - xmlMemoryDump (); - - g_free (file); - - return TRUE; -} diff --git a/libempathy/gossip-chatroom-manager.dtd b/libempathy/gossip-chatroom-manager.dtd deleted file mode 100644 index 5d94a57c2..000000000 --- a/libempathy/gossip-chatroom-manager.dtd +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - diff --git a/libempathy/gossip-chatroom-manager.h b/libempathy/gossip-chatroom-manager.h deleted file mode 100644 index 7d10a0fc1..000000000 --- a/libempathy/gossip-chatroom-manager.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004-2007 Imendio AB - * Copyright (C) 2007 Collabora Ltd. - * - * 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: Xavier Claessens - * Martyn Russell - */ - -#ifndef __GOSSIP_CHATROOM_MANAGER_H__ -#define __GOSSIP_CHATROOM_MANAGER_H__ - -#include - -#include - -#include "gossip-chatroom.h" - -G_BEGIN_DECLS - -#define GOSSIP_TYPE_CHATROOM_MANAGER (gossip_chatroom_manager_get_type ()) -#define GOSSIP_CHATROOM_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOSSIP_TYPE_CHATROOM_MANAGER, GossipChatroomManager)) -#define GOSSIP_CHATROOM_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOSSIP_TYPE_CHATROOM_MANAGER, GossipChatroomManagerClass)) -#define GOSSIP_IS_CHATROOM_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOSSIP_TYPE_CHATROOM_MANAGER)) -#define GOSSIP_IS_CHATROOM_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOSSIP_TYPE_CHATROOM_MANAGER)) -#define GOSSIP_CHATROOM_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOSSIP_TYPE_CHATROOM_MANAGER, GossipChatroomManagerClass)) - -typedef struct _GossipChatroomManager GossipChatroomManager; -typedef struct _GossipChatroomManagerClass GossipChatroomManagerClass; -typedef struct _GossipChatroomManagerPriv GossipChatroomManagerPriv; - -struct _GossipChatroomManager { - GObject parent; -}; - -struct _GossipChatroomManagerClass { - GObjectClass parent_class; -}; - -GType gossip_chatroom_manager_get_type (void) G_GNUC_CONST; -GossipChatroomManager *gossip_chatroom_manager_new (void); -gboolean gossip_chatroom_manager_add (GossipChatroomManager *manager, - GossipChatroom *chatroom); -void gossip_chatroom_manager_remove (GossipChatroomManager *manager, - GossipChatroom *chatroom); -GossipChatroom * gossip_chatroom_manager_find (GossipChatroomManager *manager, - McAccount *account, - const gchar *room); -GList * gossip_chatroom_manager_get_chatrooms (GossipChatroomManager *manager, - McAccount *account); -guint gossip_chatroom_manager_get_count (GossipChatroomManager *manager, - McAccount *account); -void gossip_chatroom_manager_store (GossipChatroomManager *manager); - -G_END_DECLS - -#endif /* __GOSSIP_CHATROOM_MANAGER_H__ */ diff --git a/libempathy/gossip-chatroom.c b/libempathy/gossip-chatroom.c deleted file mode 100644 index 5b1760fdd..000000000 --- a/libempathy/gossip-chatroom.c +++ /dev/null @@ -1,362 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2007 Collabora Ltd. - * - * 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: Xavier Claessens - */ - -#include "config.h" - -#include - -#include - -#include "gossip-chatroom.h" -#include "gossip-utils.h" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CHATROOM, GossipChatroomPriv)) - -struct _GossipChatroomPriv { - McAccount *account; - gchar *room; - gchar *name; - gboolean auto_connect; -}; - -static void gossip_chatroom_class_init (GossipChatroomClass *klass); -static void gossip_chatroom_init (GossipChatroom *chatroom); -static void chatroom_finalize (GObject *object); -static void chatroom_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void chatroom_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -enum { - PROP_0, - PROP_ACCOUNT, - PROP_ROOM, - PROP_NAME, - PROP_AUTO_CONNECT, -}; - -G_DEFINE_TYPE (GossipChatroom, gossip_chatroom, G_TYPE_OBJECT); - -static void -gossip_chatroom_class_init (GossipChatroomClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = chatroom_finalize; - object_class->get_property = chatroom_get_property; - object_class->set_property = chatroom_set_property; - - g_object_class_install_property (object_class, - PROP_ACCOUNT, - g_param_spec_object ("account", - "Chatroom Account", - "The account associated with an chatroom", - MC_TYPE_ACCOUNT, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_ROOM, - g_param_spec_string ("room", - "Chatroom Room", - "Chatroom represented as 'room@server'", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_NAME, - g_param_spec_string ("name", - "Chatroom Name", - "Chatroom name", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_AUTO_CONNECT, - g_param_spec_boolean ("auto_connect", - "Chatroom Auto Connect", - "Connect on startup", - FALSE, - G_PARAM_READWRITE)); - - - g_type_class_add_private (object_class, sizeof (GossipChatroomPriv)); -} - -static void -gossip_chatroom_init (GossipChatroom *chatroom) -{ -} - -static void -chatroom_finalize (GObject *object) -{ - GossipChatroomPriv *priv; - - priv = GET_PRIV (object); - - g_object_unref (priv->account); - g_free (priv->room); - g_free (priv->name); - - (G_OBJECT_CLASS (gossip_chatroom_parent_class)->finalize) (object); -} - -static void -chatroom_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - GossipChatroomPriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_ACCOUNT: - g_value_set_object (value, priv->account); - break; - case PROP_ROOM: - g_value_set_string (value, priv->room); - break; - case PROP_NAME: - g_value_set_string (value, priv->name); - break; - case PROP_AUTO_CONNECT: - g_value_set_boolean (value, priv->auto_connect); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static void -chatroom_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - GossipChatroomPriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_ACCOUNT: - gossip_chatroom_set_account (GOSSIP_CHATROOM (object), - g_value_get_object (value)); - break; - case PROP_ROOM: - gossip_chatroom_set_room (GOSSIP_CHATROOM (object), - g_value_get_string (value)); - break; - case PROP_NAME: - gossip_chatroom_set_name (GOSSIP_CHATROOM (object), - g_value_get_string (value)); - break; - case PROP_AUTO_CONNECT: - gossip_chatroom_set_auto_connect (GOSSIP_CHATROOM (object), - g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -GossipChatroom * -gossip_chatroom_new (McAccount *account, - const gchar *room) -{ - g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (room != NULL, NULL); - - return g_object_new (GOSSIP_TYPE_CHATROOM, - "account", account, - "room", room, - NULL); -} - -GossipChatroom * -gossip_chatroom_new_full (McAccount *account, - const gchar *room, - const gchar *name, - gboolean auto_connect) -{ - g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (room != NULL, NULL); - - return g_object_new (GOSSIP_TYPE_CHATROOM, - "account", account, - "room", room, - "name", name, - "auto_connect", auto_connect, - NULL); -} - -McAccount * -gossip_chatroom_get_account (GossipChatroom *chatroom) -{ - GossipChatroomPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), NULL); - - priv = GET_PRIV (chatroom); - return priv->account; -} - -void -gossip_chatroom_set_account (GossipChatroom *chatroom, - McAccount *account) -{ - GossipChatroomPriv *priv; - - g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); - g_return_if_fail (MC_IS_ACCOUNT (account)); - - priv = GET_PRIV (chatroom); - - if (account == priv->account) { - return; - } - if (priv->account) { - g_object_unref (priv->account); - } - priv->account = g_object_ref (account); - - g_object_notify (G_OBJECT (chatroom), "account"); -} - -const gchar * -gossip_chatroom_get_room (GossipChatroom *chatroom) -{ - GossipChatroomPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), NULL); - - priv = GET_PRIV (chatroom); - return priv->room; -} - -void -gossip_chatroom_set_room (GossipChatroom *chatroom, - const gchar *room) -{ - GossipChatroomPriv *priv; - - g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); - g_return_if_fail (room != NULL); - - priv = GET_PRIV (chatroom); - - g_free (priv->room); - priv->room = g_strdup (room); - - g_object_notify (G_OBJECT (chatroom), "room"); -} - -const gchar * -gossip_chatroom_get_name (GossipChatroom *chatroom) -{ - GossipChatroomPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), NULL); - - priv = GET_PRIV (chatroom); - - if (G_STR_EMPTY (priv->name)) { - return priv->room; - } - - return priv->name; -} - -void -gossip_chatroom_set_name (GossipChatroom *chatroom, - const gchar *name) -{ - GossipChatroomPriv *priv; - - g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); - - priv = GET_PRIV (chatroom); - - g_free (priv->name); - priv->name = NULL; - if (name) { - priv->name = g_strdup (name); - } - - g_object_notify (G_OBJECT (chatroom), "name"); -} - -gboolean -gossip_chatroom_get_auto_connect (GossipChatroom *chatroom) -{ - GossipChatroomPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), FALSE); - - priv = GET_PRIV (chatroom); - return priv->auto_connect; -} - -void -gossip_chatroom_set_auto_connect (GossipChatroom *chatroom, - gboolean auto_connect) -{ - GossipChatroomPriv *priv; - - g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); - - priv = GET_PRIV (chatroom); - - priv->auto_connect = auto_connect; - - g_object_notify (G_OBJECT (chatroom), "auto-connect"); -} - -gboolean -gossip_chatroom_equal (gconstpointer v1, - gconstpointer v2) -{ - McAccount *account_a; - McAccount *account_b; - const gchar *room_a; - const gchar *room_b; - - g_return_val_if_fail (GOSSIP_IS_CHATROOM (v1), FALSE); - g_return_val_if_fail (GOSSIP_IS_CHATROOM (v2), FALSE); - - account_a = gossip_chatroom_get_account (GOSSIP_CHATROOM (v1)); - account_b = gossip_chatroom_get_account (GOSSIP_CHATROOM (v2)); - - room_a = gossip_chatroom_get_room (GOSSIP_CHATROOM (v1)); - room_b = gossip_chatroom_get_room (GOSSIP_CHATROOM (v2)); - - return gossip_account_equal (account_a, account_b) && g_str_equal (room_a, room_b); -} - - diff --git a/libempathy/gossip-chatroom.h b/libempathy/gossip-chatroom.h deleted file mode 100644 index 70614a368..000000000 --- a/libempathy/gossip-chatroom.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2007 Collabora Ltd. - * - * 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: Xavier Claessens - */ - -#ifndef __GOSSIP_CHATROOM_H__ -#define __GOSSIP_CHATROOM_H__ - -#include - -#include - -G_BEGIN_DECLS - -#define GOSSIP_TYPE_CHATROOM (gossip_chatroom_get_type ()) -#define GOSSIP_CHATROOM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOSSIP_TYPE_CHATROOM, GossipChatroom)) -#define GOSSIP_CHATROOM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOSSIP_TYPE_CHATROOM, GossipChatroomClass)) -#define GOSSIP_IS_CHATROOM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOSSIP_TYPE_CHATROOM)) -#define GOSSIP_IS_CHATROOM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOSSIP_TYPE_CHATROOM)) -#define GOSSIP_CHATROOM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOSSIP_TYPE_CHATROOM, GossipChatroomClass)) - -#define GOSSIP_TYPE_CHATROOM_INVITE (gossip_chatroom_invite_get_gtype ()) - -typedef struct _GossipChatroom GossipChatroom; -typedef struct _GossipChatroomClass GossipChatroomClass; -typedef struct _GossipChatroomPriv GossipChatroomPriv; - -struct _GossipChatroom { - GObject parent; -}; - -struct _GossipChatroomClass { - GObjectClass parent_class; -}; - -GType gossip_chatroom_get_type (void) G_GNUC_CONST; -GossipChatroom *gossip_chatroom_new (McAccount *account, - const gchar *room); -GossipChatroom *gossip_chatroom_new_full (McAccount *account, - const gchar *room, - const gchar *name, - gboolean auto_connect); -McAccount * gossip_chatroom_get_account (GossipChatroom *chatroom); -void gossip_chatroom_set_account (GossipChatroom *chatroom, - McAccount *account); -const gchar * gossip_chatroom_get_room (GossipChatroom *chatroom); -void gossip_chatroom_set_room (GossipChatroom *chatroom, - const gchar *room); -const gchar * gossip_chatroom_get_name (GossipChatroom *chatroom); -void gossip_chatroom_set_name (GossipChatroom *chatroom, - const gchar *name); -gboolean gossip_chatroom_get_auto_connect (GossipChatroom *chatroom); -void gossip_chatroom_set_auto_connect (GossipChatroom *chatroom, - gboolean auto_connect); -gboolean gossip_chatroom_equal (gconstpointer v1, - gconstpointer v2); - - -G_BEGIN_DECLS - -#endif /* __GOSSIP_CHATROOM_H__ */ diff --git a/libempathy/gossip-conf.c b/libempathy/gossip-conf.c deleted file mode 100644 index e788da6b4..000000000 --- a/libempathy/gossip-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 - */ - -#include "config.h" - -#include - -#include - -#include "gossip-conf.h" -#include "gossip-debug.h" - -#define DEBUG_DOMAIN "Config" - -#define GOSSIP_CONF_ROOT "/apps/empathy" -#define DESKTOP_INTERFACE_ROOT "/desktop/gnome/interface" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CONF, GossipConfPriv)) - -typedef struct { - GConfClient *gconf_client; -} GossipConfPriv; - -typedef struct { - GossipConf *conf; - GossipConfNotifyFunc func; - gpointer user_data; -} GossipConfNotifyData; - -static void conf_finalize (GObject *object); - -G_DEFINE_TYPE (GossipConf, gossip_conf, G_TYPE_OBJECT); - -static GossipConf *global_conf = NULL; - -static void -gossip_conf_class_init (GossipConfClass *class) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (class); - - object_class->finalize = conf_finalize; - - g_type_class_add_private (object_class, sizeof (GossipConfPriv)); -} - -static void -gossip_conf_init (GossipConf *conf) -{ - GossipConfPriv *priv; - - priv = GET_PRIV (conf); - - priv->gconf_client = gconf_client_get_default (); - - gconf_client_add_dir (priv->gconf_client, - GOSSIP_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) -{ - GossipConfPriv *priv; - - priv = GET_PRIV (object); - - gconf_client_remove_dir (priv->gconf_client, - GOSSIP_CONF_ROOT, - NULL); - gconf_client_remove_dir (priv->gconf_client, - DESKTOP_INTERFACE_ROOT, - NULL); - - g_object_unref (priv->gconf_client); - - G_OBJECT_CLASS (gossip_conf_parent_class)->finalize (object); -} - -GossipConf * -gossip_conf_get (void) -{ - if (!global_conf) { - global_conf = g_object_new (GOSSIP_TYPE_CONF, NULL); - } - - return global_conf; -} - -void -gossip_conf_shutdown (void) -{ - if (global_conf) { - g_object_unref (global_conf); - global_conf = NULL; - } -} - -gboolean -gossip_conf_set_int (GossipConf *conf, - const gchar *key, - gint value) -{ - GossipConfPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE); - - gossip_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 -gossip_conf_get_int (GossipConf *conf, - const gchar *key, - gint *value) -{ - GossipConfPriv *priv; - GError *error = NULL; - - *value = 0; - - g_return_val_if_fail (GOSSIP_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 -gossip_conf_set_bool (GossipConf *conf, - const gchar *key, - gboolean value) -{ - GossipConfPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE); - - gossip_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 -gossip_conf_get_bool (GossipConf *conf, - const gchar *key, - gboolean *value) -{ - GossipConfPriv *priv; - GError *error = NULL; - - *value = FALSE; - - g_return_val_if_fail (GOSSIP_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 -gossip_conf_set_string (GossipConf *conf, - const gchar *key, - const gchar *value) -{ - GossipConfPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE); - - gossip_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 -gossip_conf_get_string (GossipConf *conf, - const gchar *key, - gchar **value) -{ - GossipConfPriv *priv; - GError *error = NULL; - - *value = NULL; - - g_return_val_if_fail (GOSSIP_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 -gossip_conf_set_string_list (GossipConf *conf, - const gchar *key, - GSList *value) -{ - GossipConfPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE); - - priv = GET_PRIV (conf); - - return gconf_client_set_list (priv->gconf_client, - key, - GCONF_VALUE_STRING, - value, - NULL); -} - -gboolean -gossip_conf_get_string_list (GossipConf *conf, - const gchar *key, - GSList **value) -{ - GossipConfPriv *priv; - GError *error = NULL; - - *value = NULL; - - g_return_val_if_fail (GOSSIP_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 (GossipConfNotifyData *data) -{ - g_object_unref (data->conf); - g_slice_free (GossipConfNotifyData, data); -} - -static void -conf_notify_func (GConfClient *client, - guint id, - GConfEntry *entry, - gpointer user_data) -{ - GossipConfNotifyData *data; - - data = user_data; - - data->func (data->conf, - gconf_entry_get_key (entry), - data->user_data); -} - -guint -gossip_conf_notify_add (GossipConf *conf, - const gchar *key, - GossipConfNotifyFunc func, - gpointer user_data) -{ - GossipConfPriv *priv; - guint id; - GossipConfNotifyData *data; - - g_return_val_if_fail (GOSSIP_IS_CONF (conf), 0); - - priv = GET_PRIV (conf); - - data = g_slice_new (GossipConfNotifyData); - 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 -gossip_conf_notify_remove (GossipConf *conf, - guint id) -{ - GossipConfPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE); - - priv = GET_PRIV (conf); - - gconf_client_notify_remove (priv->gconf_client, id); - - return TRUE; -} - diff --git a/libempathy/gossip-conf.h b/libempathy/gossip-conf.h deleted file mode 100644 index 35fdfb902..000000000 --- a/libempathy/gossip-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 __GOSSIP_CONF_H__ -#define __GOSSIP_CONF_H__ - -#include - -G_BEGIN_DECLS - -#define GOSSIP_TYPE_CONF (gossip_conf_get_type ()) -#define GOSSIP_CONF(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOSSIP_TYPE_CONF, GossipConf)) -#define GOSSIP_CONF_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOSSIP_TYPE_CONF, GossipConfClass)) -#define GOSSIP_IS_CONF(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOSSIP_TYPE_CONF)) -#define GOSSIP_IS_CONF_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOSSIP_TYPE_CONF)) -#define GOSSIP_CONF_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOSSIP_TYPE_CONF, GossipConfClass)) - -typedef struct _GossipConf GossipConf; -typedef struct _GossipConfClass GossipConfClass; - -struct _GossipConf { - GObject parent; -}; - -struct _GossipConfClass { - GObjectClass parent_class; -}; - -typedef void (*GossipConfNotifyFunc) (GossipConf *conf, - const gchar *key, - gpointer user_data); - -GType gossip_conf_get_type (void) G_GNUC_CONST; -GossipConf *gossip_conf_get (void); -void gossip_conf_shutdown (void); -guint gossip_conf_notify_add (GossipConf *conf, - const gchar *key, - GossipConfNotifyFunc func, - gpointer data); -gboolean gossip_conf_notify_remove (GossipConf *conf, - guint id); -gboolean gossip_conf_set_int (GossipConf *conf, - const gchar *key, - gint value); -gboolean gossip_conf_get_int (GossipConf *conf, - const gchar *key, - gint *value); -gboolean gossip_conf_set_bool (GossipConf *conf, - const gchar *key, - gboolean value); -gboolean gossip_conf_get_bool (GossipConf *conf, - const gchar *key, - gboolean *value); -gboolean gossip_conf_set_string (GossipConf *conf, - const gchar *key, - const gchar *value); -gboolean gossip_conf_get_string (GossipConf *conf, - const gchar *key, - gchar **value); -gboolean gossip_conf_set_string_list (GossipConf *conf, - const gchar *key, - GSList *value); -gboolean gossip_conf_get_string_list (GossipConf *conf, - const gchar *key, - GSList **value); - -G_END_DECLS - -#endif /* __GOSSIP_CONF_H__ */ - diff --git a/libempathy/gossip-contact.c b/libempathy/gossip-contact.c deleted file mode 100644 index ba97fa758..000000000 --- a/libempathy/gossip-contact.c +++ /dev/null @@ -1,800 +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 - * Martyn Russell - */ - -#include "config.h" - -#include - -#include - -#include "gossip-contact.h" -#include "gossip-utils.h" -#include "gossip-debug.h" - -#define DEBUG_DOMAIN "Contact" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CONTACT, GossipContactPriv)) - -typedef struct _GossipContactPriv GossipContactPriv; - -struct _GossipContactPriv { - gchar *id; - gchar *name; - GossipAvatar *avatar; - McAccount *account; - GossipPresence *presence; - GList *groups; - GossipSubscription subscription; - guint handle; - gboolean is_user; -}; - -static void contact_class_init (GossipContactClass *class); -static void contact_init (GossipContact *contact); -static void contact_finalize (GObject *object); -static void contact_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void contact_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -enum { - PROP_0, - PROP_ID, - PROP_NAME, - PROP_AVATAR, - PROP_ACCOUNT, - PROP_PRESENCE, - PROP_GROUPS, - PROP_SUBSCRIPTION, - PROP_HANDLE, - PROP_IS_USER -}; - -static gpointer parent_class = NULL; - -GType -gossip_contact_get_gtype (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (GossipContactClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) contact_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GossipContact), - 0, /* n_preallocs */ - (GInstanceInitFunc) contact_init - }; - - type = g_type_register_static (G_TYPE_OBJECT, - "GossipContact", - &info, 0); - } - - return type; -} - -static void -contact_class_init (GossipContactClass *class) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (class); - parent_class = g_type_class_peek_parent (class); - - object_class->finalize = contact_finalize; - object_class->get_property = contact_get_property; - object_class->set_property = contact_set_property; - - g_object_class_install_property (object_class, - PROP_ID, - g_param_spec_string ("id", - "Contact id", - "String identifying contact", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_NAME, - g_param_spec_string ("name", - "Contact Name", - "The name of the contact", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_AVATAR, - g_param_spec_boxed ("avatar", - "Avatar image", - "The avatar image", - GOSSIP_TYPE_AVATAR, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_ACCOUNT, - g_param_spec_object ("account", - "Contact Account", - "The account associated with the contact", - MC_TYPE_ACCOUNT, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_PRESENCE, - g_param_spec_object ("presence", - "Contact presence", - "Presence of contact", - GOSSIP_TYPE_PRESENCE, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_GROUPS, - g_param_spec_pointer ("groups", - "Contact groups", - "Groups of contact", - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_SUBSCRIPTION, - g_param_spec_int ("subscription", - "Contact Subscription", - "The subscription status of the contact", - GOSSIP_SUBSCRIPTION_NONE, - GOSSIP_SUBSCRIPTION_BOTH, - GOSSIP_SUBSCRIPTION_NONE, - G_PARAM_READWRITE)); - - - g_object_class_install_property (object_class, - PROP_HANDLE, - g_param_spec_uint ("handle", - "Contact Handle", - "The handle of the contact", - 0, - G_MAXUINT, - 0, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_IS_USER, - g_param_spec_boolean ("is-user", - "Contact is-user", - "Is contact the user", - FALSE, - G_PARAM_READWRITE)); - - g_type_class_add_private (object_class, sizeof (GossipContactPriv)); -} - -static void -contact_init (GossipContact *contact) -{ -} - -static void -contact_finalize (GObject *object) -{ - GossipContactPriv *priv; - - priv = GET_PRIV (object); - - gossip_debug (DEBUG_DOMAIN, "finalize: %p", object); - - g_free (priv->name); - g_free (priv->id); - - if (priv->avatar) { - gossip_avatar_unref (priv->avatar); - } - - if (priv->presence) { - g_object_unref (priv->presence); - } - - if (priv->groups) { - g_list_foreach (priv->groups, (GFunc) g_free, NULL); - g_list_free (priv->groups); - } - - if (priv->account) { - g_object_unref (priv->account); - } - - (G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -static void -contact_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - GossipContactPriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_ID: - g_value_set_string (value, - gossip_contact_get_id (GOSSIP_CONTACT (object))); - break; - case PROP_NAME: - g_value_set_string (value, - gossip_contact_get_name (GOSSIP_CONTACT (object))); - break; - case PROP_AVATAR: - g_value_set_boxed (value, priv->avatar); - break; - case PROP_ACCOUNT: - g_value_set_object (value, priv->account); - break; - case PROP_PRESENCE: - g_value_set_object (value, priv->presence); - break; - case PROP_GROUPS: - g_value_set_pointer (value, priv->groups); - break; - case PROP_SUBSCRIPTION: - g_value_set_int (value, priv->subscription); - break; - case PROP_HANDLE: - g_value_set_uint (value, priv->handle); - break; - case PROP_IS_USER: - g_value_set_boolean (value, priv->is_user); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static void -contact_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - GossipContactPriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_ID: - gossip_contact_set_id (GOSSIP_CONTACT (object), - g_value_get_string (value)); - break; - case PROP_NAME: - gossip_contact_set_name (GOSSIP_CONTACT (object), - g_value_get_string (value)); - break; - case PROP_AVATAR: - gossip_contact_set_avatar (GOSSIP_CONTACT (object), - g_value_get_boxed (value)); - break; - case PROP_ACCOUNT: - gossip_contact_set_account (GOSSIP_CONTACT (object), - MC_ACCOUNT (g_value_get_object (value))); - break; - case PROP_PRESENCE: - gossip_contact_set_presence (GOSSIP_CONTACT (object), - GOSSIP_PRESENCE (g_value_get_object (value))); - break; - case PROP_GROUPS: - gossip_contact_set_groups (GOSSIP_CONTACT (object), - g_value_get_pointer (value)); - break; - case PROP_SUBSCRIPTION: - gossip_contact_set_subscription (GOSSIP_CONTACT (object), - g_value_get_int (value)); - break; - case PROP_HANDLE: - gossip_contact_set_handle (GOSSIP_CONTACT (object), - g_value_get_uint (value)); - break; - case PROP_IS_USER: - gossip_contact_set_is_user (GOSSIP_CONTACT (object), - g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -GossipContact * -gossip_contact_new (McAccount *account) -{ - return g_object_new (GOSSIP_TYPE_CONTACT, - "account", account, - NULL); -} - -GossipContact * -gossip_contact_new_full (McAccount *account, - const gchar *id, - const gchar *name) -{ - return g_object_new (GOSSIP_TYPE_CONTACT, - "account", account, - "name", name, - "id", id, - NULL); -} - -const gchar * -gossip_contact_get_id (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), ""); - - priv = GET_PRIV (contact); - - if (priv->id) { - return priv->id; - } - - return ""; -} - -const gchar * -gossip_contact_get_name (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), ""); - - priv = GET_PRIV (contact); - - if (G_STR_EMPTY (priv->name)) { - return gossip_contact_get_id (contact); - } - - return priv->name; -} - -GossipAvatar * -gossip_contact_get_avatar (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL); - - priv = GET_PRIV (contact); - - return priv->avatar; -} - -McAccount * -gossip_contact_get_account (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL); - - priv = GET_PRIV (contact); - - return priv->account; -} - -GossipPresence * -gossip_contact_get_presence (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL); - - priv = GET_PRIV (contact); - - return priv->presence; -} - -GList * -gossip_contact_get_groups (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL); - - priv = GET_PRIV (contact); - - return priv->groups; -} - -GossipSubscription -gossip_contact_get_subscription (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), - GOSSIP_SUBSCRIPTION_NONE); - - priv = GET_PRIV (contact); - - return priv->subscription; -} - -guint -gossip_contact_get_handle (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), 0); - - priv = GET_PRIV (contact); - - return priv->handle; -} - -gboolean -gossip_contact_is_user (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), FALSE); - - priv = GET_PRIV (contact); - - return priv->is_user; -} - -void -gossip_contact_set_id (GossipContact *contact, - const gchar *id) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - g_return_if_fail (id != NULL); - - priv = GET_PRIV (contact); - - if (priv->id && strcmp (id, priv->id) == 0) { - return; - } - - g_free (priv->id); - priv->id = g_strdup (id); - - g_object_notify (G_OBJECT (contact), "id"); -} - -void -gossip_contact_set_name (GossipContact *contact, - const gchar *name) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - g_return_if_fail (name != NULL); - - priv = GET_PRIV (contact); - - if (priv->name && strcmp (name, priv->name) == 0) { - return; - } - - g_free (priv->name); - priv->name = g_strdup (name); - - g_object_notify (G_OBJECT (contact), "name"); -} - -void -gossip_contact_set_avatar (GossipContact *contact, - GossipAvatar *avatar) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - - priv = GET_PRIV (contact); - - if (priv->avatar == avatar) { - return; - } - - if (priv->avatar) { - gossip_avatar_unref (priv->avatar); - priv->avatar = NULL; - } - - if (avatar) { - priv->avatar = gossip_avatar_ref (avatar); - } - - g_object_notify (G_OBJECT (contact), "avatar"); -} - -void -gossip_contact_set_account (GossipContact *contact, - McAccount *account) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - g_return_if_fail (MC_IS_ACCOUNT (account)); - - priv = GET_PRIV (contact); - - if (account == priv->account) { - return; - } - - if (priv->account) { - g_object_unref (priv->account); - } - priv->account = g_object_ref (account); - - g_object_notify (G_OBJECT (contact), "account"); -} - -void -gossip_contact_set_presence (GossipContact *contact, - GossipPresence *presence) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - - priv = GET_PRIV (contact); - - if (presence == priv->presence) { - return; - } - - if (priv->presence) { - g_object_unref (priv->presence); - priv->presence = NULL; - } - - if (presence) { - priv->presence = g_object_ref (presence); - } - - g_object_notify (G_OBJECT (contact), "presence"); -} - -void -gossip_contact_set_groups (GossipContact *contact, - GList *groups) -{ - GossipContactPriv *priv; - GList *old_groups, *l; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - - priv = GET_PRIV (contact); - - old_groups = priv->groups; - priv->groups = NULL; - - for (l = groups; l; l = l->next) { - priv->groups = g_list_append (priv->groups, - g_strdup (l->data)); - } - - g_list_foreach (old_groups, (GFunc) g_free, NULL); - g_list_free (old_groups); - - g_object_notify (G_OBJECT (contact), "groups"); -} - -void -gossip_contact_set_subscription (GossipContact *contact, - GossipSubscription subscription) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - - priv = GET_PRIV (contact); - - if (priv->subscription == subscription) { - return; - } - - priv->subscription = subscription; - - g_object_notify (G_OBJECT (contact), "subscription"); -} - -void -gossip_contact_set_handle (GossipContact *contact, - guint handle) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - - priv = GET_PRIV (contact); - - if (priv->handle == handle) { - return; - } - - priv->handle = handle; - - g_object_notify (G_OBJECT (contact), "handle"); -} - -void -gossip_contact_set_is_user (GossipContact *contact, - gboolean is_user) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - - priv = GET_PRIV (contact); - - if (priv->is_user == is_user) { - return; - } - - priv->is_user = is_user; - - g_object_notify (G_OBJECT (contact), "is-user"); -} - -void -gossip_contact_add_group (GossipContact *contact, - const gchar *group) -{ - GossipContactPriv *priv; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - g_return_if_fail (group != NULL); - - priv = GET_PRIV (contact); - - if (!g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp)) { - priv->groups = g_list_prepend (priv->groups, g_strdup (group)); - g_object_notify (G_OBJECT (contact), "groups"); - } -} - -void -gossip_contact_remove_group (GossipContact *contact, - const gchar *group) -{ - GossipContactPriv *priv; - GList *l; - - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - g_return_if_fail (group != NULL); - - priv = GET_PRIV (contact); - - l = g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp); - if (l) { - g_free (l->data); - priv->groups = g_list_delete_link (priv->groups, l); - g_object_notify (G_OBJECT (contact), "groups"); - } -} - -gboolean -gossip_contact_is_online (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), FALSE); - - priv = GET_PRIV (contact); - - if (!priv->presence) { - return FALSE; - } - - return (gossip_presence_get_state (priv->presence) > MC_PRESENCE_OFFLINE); -} - -gboolean -gossip_contact_is_in_group (GossipContact *contact, - const gchar *group) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), FALSE); - g_return_val_if_fail (!G_STR_EMPTY (group), FALSE); - - priv = GET_PRIV (contact); - - if (g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp)) { - return TRUE; - } - - return FALSE; -} - -const gchar * -gossip_contact_get_status (GossipContact *contact) -{ - GossipContactPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), ""); - - priv = GET_PRIV (contact); - - if (priv->presence) { - const gchar *status; - - status = gossip_presence_get_status (priv->presence); - if (!status) { - McPresence state; - - state = gossip_presence_get_state (priv->presence); - status = gossip_presence_state_get_default_status (state); - } - - return status; - } - - return gossip_presence_state_get_default_status (MC_PRESENCE_OFFLINE); -} - -gboolean -gossip_contact_equal (gconstpointer v1, - gconstpointer v2) -{ - McAccount *account_a; - McAccount *account_b; - const gchar *id_a; - const gchar *id_b; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (v1), FALSE); - g_return_val_if_fail (GOSSIP_IS_CONTACT (v2), FALSE); - - account_a = gossip_contact_get_account (GOSSIP_CONTACT (v1)); - account_b = gossip_contact_get_account (GOSSIP_CONTACT (v2)); - - id_a = gossip_contact_get_id (GOSSIP_CONTACT (v1)); - id_b = gossip_contact_get_id (GOSSIP_CONTACT (v2)); - - return gossip_account_equal (account_a, account_b) && g_str_equal (id_a, id_b); -} - -guint -gossip_contact_hash (gconstpointer key) -{ - GossipContactPriv *priv; - guint hash; - - g_return_val_if_fail (GOSSIP_IS_CONTACT (key), +1); - - priv = GET_PRIV (GOSSIP_CONTACT (key)); - - hash = gossip_account_hash (gossip_contact_get_account (GOSSIP_CONTACT (key))); - hash += g_str_hash (gossip_contact_get_id (GOSSIP_CONTACT (key))); - - return hash; -} - diff --git a/libempathy/gossip-contact.h b/libempathy/gossip-contact.h deleted file mode 100644 index 14b32fdc2..000000000 --- a/libempathy/gossip-contact.h +++ /dev/null @@ -1,106 +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 __GOSSIP_CONTACT_H__ -#define __GOSSIP_CONTACT_H__ - -#include - -#include - -#include "gossip-avatar.h" -#include "gossip-presence.h" - -G_BEGIN_DECLS - -#define GOSSIP_TYPE_CONTACT (gossip_contact_get_gtype ()) -#define GOSSIP_CONTACT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOSSIP_TYPE_CONTACT, GossipContact)) -#define GOSSIP_CONTACT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOSSIP_TYPE_CONTACT, GossipContactClass)) -#define GOSSIP_IS_CONTACT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOSSIP_TYPE_CONTACT)) -#define GOSSIP_IS_CONTACT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOSSIP_TYPE_CONTACT)) -#define GOSSIP_CONTACT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOSSIP_TYPE_CONTACT, GossipContactClass)) - -typedef struct _GossipContact GossipContact; -typedef struct _GossipContactClass GossipContactClass; - -struct _GossipContact { - GObject parent; -}; - -struct _GossipContactClass { - GObjectClass parent_class; -}; - -typedef enum { - GOSSIP_SUBSCRIPTION_NONE = 0, - GOSSIP_SUBSCRIPTION_TO = 1 << 0, /* We send our presence to that contact */ - GOSSIP_SUBSCRIPTION_FROM = 1 << 1, /* That contact sends his presence to us */ - GOSSIP_SUBSCRIPTION_BOTH = GOSSIP_SUBSCRIPTION_TO | GOSSIP_SUBSCRIPTION_FROM -} GossipSubscription; - -GType gossip_contact_get_gtype (void) G_GNUC_CONST; - -GossipContact * gossip_contact_new (McAccount *account); -GossipContact * gossip_contact_new_full (McAccount *account, - const gchar *id, - const gchar *name); -const gchar * gossip_contact_get_id (GossipContact *contact); -const gchar * gossip_contact_get_name (GossipContact *contact); -GossipAvatar * gossip_contact_get_avatar (GossipContact *contact); -McAccount * gossip_contact_get_account (GossipContact *contact); -GossipPresence * gossip_contact_get_presence (GossipContact *contact); -GList * gossip_contact_get_groups (GossipContact *contact); -GossipSubscription gossip_contact_get_subscription (GossipContact *contact); -guint gossip_contact_get_handle (GossipContact *contact); -gboolean gossip_contact_is_user (GossipContact *contact); -void gossip_contact_set_id (GossipContact *contact, - const gchar *id); -void gossip_contact_set_name (GossipContact *contact, - const gchar *name); -void gossip_contact_set_avatar (GossipContact *contact, - GossipAvatar *avatar); -void gossip_contact_set_account (GossipContact *contact, - McAccount *account); -void gossip_contact_set_presence (GossipContact *contact, - GossipPresence *presence); -void gossip_contact_set_groups (GossipContact *contact, - GList *categories); -void gossip_contact_set_subscription (GossipContact *contact, - GossipSubscription subscription); -void gossip_contact_set_handle (GossipContact *contact, - guint handle); -void gossip_contact_set_is_user (GossipContact *contact, - gboolean is_user); -void gossip_contact_add_group (GossipContact *contact, - const gchar *group); -void gossip_contact_remove_group (GossipContact *contact, - const gchar *group); -gboolean gossip_contact_is_online (GossipContact *contact); -gboolean gossip_contact_is_in_group (GossipContact *contact, - const gchar *group); -const gchar * gossip_contact_get_status (GossipContact *contact); -gboolean gossip_contact_equal (gconstpointer v1, - gconstpointer v2); -guint gossip_contact_hash (gconstpointer key); - -G_END_DECLS - -#endif /* __GOSSIP_CONTACT_H__ */ - diff --git a/libempathy/gossip-debug.c b/libempathy/gossip-debug.c deleted file mode 100644 index a6bbeea2a..000000000 --- a/libempathy/gossip-debug.c +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2006-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: Richard Hult - */ - -#include "config.h" - -#include -#include - -#include -#include - -/* Set EMPATHY_DEBUG to a colon/comma/space separated list of domains, or "all" - * to get all debug output. - */ - -#include "gossip-debug.h" - -static gchar **debug_strv; -static gboolean all_domains = FALSE; - -static void -debug_init (void) -{ - static gboolean inited = FALSE; - - if (!inited) { - const gchar *env; - gint i; - - env = g_getenv ("EMPATHY_DEBUG"); - - if (env) { - debug_strv = g_strsplit_set (env, ":, ", 0); - } else { - debug_strv = NULL; - } - - for (i = 0; debug_strv && debug_strv[i]; i++) { - if (strcmp ("all", debug_strv[i]) == 0) { - all_domains = TRUE; - } - } - - inited = TRUE; - } -} - -void -gossip_debug_impl (const gchar *domain, const gchar *msg, ...) -{ - gint i; - - g_return_if_fail (domain != NULL); - g_return_if_fail (msg != NULL); - - debug_init (); - - for (i = 0; debug_strv && debug_strv[i]; i++) { - if (all_domains || strcmp (domain, debug_strv[i]) == 0) { - va_list args; - - g_print ("%s: ", domain); - - va_start (args, msg); - g_vprintf (msg, args); - va_end (args); - - g_print ("\n"); - break; - } - } -} - diff --git a/libempathy/gossip-debug.h b/libempathy/gossip-debug.h deleted file mode 100644 index 39dae0f1c..000000000 --- a/libempathy/gossip-debug.h +++ /dev/null @@ -1,53 +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 __GOSSIP_DEBUG_H__ -#define __GOSSIP_DEBUG_H__ - -#include - -G_BEGIN_DECLS - -#ifdef G_HAVE_ISO_VARARGS -# ifdef GOSSIP_DISABLE_DEBUG -# define gossip_debug(...) -# else -# define gossip_debug(...) gossip_debug_impl (__VA_ARGS__) -# endif -#elif defined(G_HAVE_GNUC_VARARGS) -# if GOSSIP_DISABLE_DEBUG -# define gossip_debug(fmt...) -# else -# define gossip_debug(fmt...) gossip_debug_impl(fmt) -# endif -#else -# if GOSSIP_DISABLE_DEBUG -# define gossip_debug(x) -# else -# define gossip_debug gossip_debug_impl -# endif -#endif - -void gossip_debug_impl (const gchar *domain, const gchar *msg, ...); - -G_END_DECLS - -#endif /* __GOSSIP_DEBUG_H__ */ - diff --git a/libempathy/gossip-message.c b/libempathy/gossip-message.c deleted file mode 100644 index a46a2a5dc..000000000 --- a/libempathy/gossip-message.c +++ /dev/null @@ -1,418 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004-2007 Imendio AB - * Copyright (C) 2007 Collabora Ltd. - * - * 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 - * Xavier Claessens - */ - -#include "config.h" - -#include "gossip-message.h" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_MESSAGE, GossipMessagePriv)) - -typedef struct _GossipMessagePriv GossipMessagePriv; - -struct _GossipMessagePriv { - GossipMessageType type; - GossipContact *sender; - GossipContact *receiver; - gchar *body; - GossipTime timestamp; - -}; - -static void gossip_message_class_init (GossipMessageClass *class); -static void gossip_message_init (GossipMessage *message); -static void gossip_message_finalize (GObject *object); -static void message_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void message_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -enum { - PROP_0, - PROP_TYPE, - PROP_SENDER, - PROP_RECEIVER, - PROP_BODY, - PROP_TIMESTAMP, -}; - -static gpointer parent_class = NULL; - -GType -gossip_message_get_gtype (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (GossipMessageClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) gossip_message_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GossipMessage), - 0, /* n_preallocs */ - (GInstanceInitFunc) gossip_message_init - }; - - type = g_type_register_static (G_TYPE_OBJECT, - "GossipMessage", - &info, 0); - } - - return type; -} - -static void -gossip_message_class_init (GossipMessageClass *class) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (class); - parent_class = g_type_class_peek_parent (class); - - object_class->finalize = gossip_message_finalize; - object_class->get_property = message_get_property; - object_class->set_property = message_set_property; - - g_object_class_install_property (object_class, - PROP_TYPE, - g_param_spec_int ("type", - "Message Type", - "The type of message", - GOSSIP_MESSAGE_TYPE_NORMAL, - GOSSIP_MESSAGE_TYPE_LAST, - GOSSIP_MESSAGE_TYPE_NORMAL, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_SENDER, - g_param_spec_object ("sender", - "Message Sender", - "The sender of the message", - GOSSIP_TYPE_CONTACT, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_RECEIVER, - g_param_spec_object ("receiver", - "Message Receiver", - "The receiver of the message", - GOSSIP_TYPE_CONTACT, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_BODY, - g_param_spec_string ("body", - "Message Body", - "The content of the message", - NULL, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_TIMESTAMP, - g_param_spec_long ("timestamp", - "timestamp", - "timestamp", - -1, - G_MAXLONG, - -1, - G_PARAM_READWRITE)); - - - g_type_class_add_private (object_class, sizeof (GossipMessagePriv)); - -} - -static void -gossip_message_init (GossipMessage *message) -{ - GossipMessagePriv *priv; - - priv = GET_PRIV (message); - - priv->timestamp = gossip_time_get_current (); -} - -static void -gossip_message_finalize (GObject *object) -{ - GossipMessagePriv *priv; - - priv = GET_PRIV (object); - - if (priv->sender) { - g_object_unref (priv->sender); - } - if (priv->receiver) { - g_object_unref (priv->receiver); - } - - g_free (priv->body); - - (G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -static void -message_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - GossipMessagePriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_TYPE: - g_value_set_int (value, priv->type); - break; - case PROP_SENDER: - g_value_set_object (value, priv->sender); - break; - case PROP_RECEIVER: - g_value_set_object (value, priv->receiver); - break; - case PROP_BODY: - g_value_set_string (value, priv->body); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static void -message_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - GossipMessagePriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_TYPE: - gossip_message_set_type (GOSSIP_MESSAGE (object), - g_value_get_int (value)); - break; - case PROP_SENDER: - gossip_message_set_sender (GOSSIP_MESSAGE (object), - GOSSIP_CONTACT (g_value_get_object (value))); - break; - case PROP_RECEIVER: - gossip_message_set_receiver (GOSSIP_MESSAGE (object), - GOSSIP_CONTACT (g_value_get_object (value))); - break; - case PROP_BODY: - gossip_message_set_body (GOSSIP_MESSAGE (object), - g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -GossipMessage * -gossip_message_new (const gchar *body) -{ - return g_object_new (GOSSIP_TYPE_MESSAGE, - "body", body, - NULL); -} - -GossipMessageType -gossip_message_get_type (GossipMessage *message) -{ - GossipMessagePriv *priv; - - g_return_val_if_fail (GOSSIP_IS_MESSAGE (message), - GOSSIP_MESSAGE_TYPE_NORMAL); - - priv = GET_PRIV (message); - - return priv->type; -} - -void -gossip_message_set_type (GossipMessage *message, - GossipMessageType type) -{ - GossipMessagePriv *priv; - - g_return_if_fail (GOSSIP_IS_MESSAGE (message)); - - priv = GET_PRIV (message); - - priv->type = type; - - g_object_notify (G_OBJECT (message), "type"); -} - -GossipContact * -gossip_message_get_sender (GossipMessage *message) -{ - GossipMessagePriv *priv; - - g_return_val_if_fail (GOSSIP_IS_MESSAGE (message), NULL); - - priv = GET_PRIV (message); - - return priv->sender; -} - -void -gossip_message_set_sender (GossipMessage *message, GossipContact *contact) -{ - GossipMessagePriv *priv; - GossipContact *old_sender; - - g_return_if_fail (GOSSIP_IS_MESSAGE (message)); - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - - priv = GET_PRIV (message); - - old_sender = priv->sender; - priv->sender = g_object_ref (contact); - - if (old_sender) { - g_object_unref (old_sender); - } - - g_object_notify (G_OBJECT (message), "sender"); -} - -GossipContact * -gossip_message_get_receiver (GossipMessage *message) -{ - GossipMessagePriv *priv; - - g_return_val_if_fail (GOSSIP_IS_MESSAGE (message), NULL); - - priv = GET_PRIV (message); - - return priv->receiver; -} - -void -gossip_message_set_receiver (GossipMessage *message, GossipContact *contact) -{ - GossipMessagePriv *priv; - GossipContact *old_receiver; - - g_return_if_fail (GOSSIP_IS_MESSAGE (message)); - g_return_if_fail (GOSSIP_IS_CONTACT (contact)); - - priv = GET_PRIV (message); - - old_receiver = priv->receiver; - priv->receiver = g_object_ref (contact); - - if (old_receiver) { - g_object_unref (old_receiver); - } - - g_object_notify (G_OBJECT (message), "receiver"); -} - -const gchar * -gossip_message_get_body (GossipMessage *message) -{ - GossipMessagePriv *priv; - - g_return_val_if_fail (GOSSIP_IS_MESSAGE (message), NULL); - - priv = GET_PRIV (message); - - return priv->body; -} - -void -gossip_message_set_body (GossipMessage *message, - const gchar *body) -{ - GossipMessagePriv *priv; - GossipMessageType type; - - g_return_if_fail (GOSSIP_IS_MESSAGE (message)); - - priv = GET_PRIV (message); - - g_free (priv->body); - priv->body = NULL; - - type = GOSSIP_MESSAGE_TYPE_NORMAL; - if (g_str_has_prefix (body, "/me")) { - type = GOSSIP_MESSAGE_TYPE_ACTION; - body += 4; - } - else if (g_str_has_prefix (body, "/say")) { - body += 5; - } - - if (body) { - priv->body = g_strdup (body); - } - - if (type != priv->type) { - gossip_message_set_type (message, type); - } - - g_object_notify (G_OBJECT (message), "body"); -} - -GossipTime -gossip_message_get_timestamp (GossipMessage *message) -{ - GossipMessagePriv *priv; - - g_return_val_if_fail (GOSSIP_IS_MESSAGE (message), -1); - - priv = GET_PRIV (message); - - return priv->timestamp; -} - -void -gossip_message_set_timestamp (GossipMessage *message, - GossipTime timestamp) -{ - GossipMessagePriv *priv; - - g_return_if_fail (GOSSIP_IS_MESSAGE (message)); - g_return_if_fail (timestamp >= -1); - - priv = GET_PRIV (message); - - if (timestamp <= 0) { - priv->timestamp = gossip_time_get_current (); - } else { - priv->timestamp = timestamp; - } - - g_object_notify (G_OBJECT (message), "timestamp"); -} - diff --git a/libempathy/gossip-message.h b/libempathy/gossip-message.h deleted file mode 100644 index aa4948025..000000000 --- a/libempathy/gossip-message.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004-2007 Imendio AB - * Copyright (C) 2007 Collabora Ltd. - * - * 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 - * Xavier Claessens - */ - -#ifndef __GOSSIP_MESSAGE_H__ -#define __GOSSIP_MESSAGE_H__ - -#include - -#include "gossip-contact.h" -#include "gossip-time.h" - -G_BEGIN_DECLS - -#define GOSSIP_TYPE_MESSAGE (gossip_message_get_gtype ()) -#define GOSSIP_MESSAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOSSIP_TYPE_MESSAGE, GossipMessage)) -#define GOSSIP_MESSAGE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOSSIP_TYPE_MESSAGE, GossipMessageClass)) -#define GOSSIP_IS_MESSAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOSSIP_TYPE_MESSAGE)) -#define GOSSIP_IS_MESSAGE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOSSIP_TYPE_MESSAGE)) -#define GOSSIP_MESSAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOSSIP_TYPE_MESSAGE, GossipMessageClass)) - -typedef struct _GossipMessage GossipMessage; -typedef struct _GossipMessageClass GossipMessageClass; - -struct _GossipMessage { - GObject parent; -}; - -struct _GossipMessageClass { - GObjectClass parent_class; -}; - -typedef enum { - GOSSIP_MESSAGE_TYPE_NORMAL, - GOSSIP_MESSAGE_TYPE_ACTION, - GOSSIP_MESSAGE_TYPE_NOTICE, - GOSSIP_MESSAGE_TYPE_AUTO_REPLY, - GOSSIP_MESSAGE_TYPE_LAST -} GossipMessageType; - -GType gossip_message_get_gtype (void) G_GNUC_CONST; -GossipMessage * gossip_message_new (const gchar *body); -GossipMessageType gossip_message_get_type (GossipMessage *message); -void gossip_message_set_type (GossipMessage *message, - GossipMessageType type); -GossipContact * gossip_message_get_sender (GossipMessage *message); -void gossip_message_set_sender (GossipMessage *message, - GossipContact *contact); -GossipContact * gossip_message_get_receiver (GossipMessage *message); -void gossip_message_set_receiver (GossipMessage *message, - GossipContact *contact); -const gchar * gossip_message_get_body (GossipMessage *message); -void gossip_message_set_body (GossipMessage *message, - const gchar *body); -/* What return value should we have here? */ -GossipTime gossip_message_get_timestamp (GossipMessage *message); -void gossip_message_set_timestamp (GossipMessage *message, - GossipTime timestamp); - -G_END_DECLS - -#endif /* __GOSSIP_MESSAGE_H__ */ diff --git a/libempathy/gossip-presence.c b/libempathy/gossip-presence.c deleted file mode 100644 index 7add39669..000000000 --- a/libempathy/gossip-presence.c +++ /dev/null @@ -1,337 +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 - */ - -#include "config.h" - -#include - -#include - -#include "gossip-presence.h" -#include "gossip-time.h" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_PRESENCE, GossipPresencePriv)) - -typedef struct _GossipPresencePriv GossipPresencePriv; - -struct _GossipPresencePriv { - McPresence state; - gchar *status; - GossipTime 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 (GossipPresence, gossip_presence, G_TYPE_OBJECT); - -static void -gossip_presence_class_init (GossipPresenceClass *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_int ("state", - "Presence State", - "The current state of the presence", - MC_PRESENCE_UNSET, - LAST_MC_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 (GossipPresencePriv)); -} - -static void -gossip_presence_init (GossipPresence *presence) -{ - GossipPresencePriv *priv; - - priv = GET_PRIV (presence); - - priv->state = MC_PRESENCE_AVAILABLE; - priv->status = NULL; - priv->timestamp = gossip_time_get_current (); -} - -static void -presence_finalize (GObject *object) -{ - GossipPresencePriv *priv; - - priv = GET_PRIV (object); - - g_free (priv->status); - - (G_OBJECT_CLASS (gossip_presence_parent_class)->finalize) (object); -} - -static void -presence_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - GossipPresencePriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_STATE: - g_value_set_int (value, priv->state); - break; - case PROP_STATUS: - g_value_set_string (value, - gossip_presence_get_status (GOSSIP_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) -{ - GossipPresencePriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - case PROP_STATE: - priv->state = g_value_get_int (value); - break; - case PROP_STATUS: - gossip_presence_set_status (GOSSIP_PRESENCE (object), - g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -GossipPresence * -gossip_presence_new (void) -{ - return g_object_new (GOSSIP_TYPE_PRESENCE, NULL); -} - -GossipPresence * -gossip_presence_new_full (McPresence state, - const gchar *status) -{ - return g_object_new (GOSSIP_TYPE_PRESENCE, - "state", state, - "status", status, - NULL); -} - -const gchar * -gossip_presence_get_status (GossipPresence *presence) -{ - GossipPresencePriv *priv; - - g_return_val_if_fail (GOSSIP_IS_PRESENCE (presence), - _("Offline")); - - priv = GET_PRIV (presence); - - return priv->status; -} - -McPresence -gossip_presence_get_state (GossipPresence *presence) -{ - GossipPresencePriv *priv; - - g_return_val_if_fail (GOSSIP_IS_PRESENCE (presence), - MC_PRESENCE_AVAILABLE); - - priv = GET_PRIV (presence); - - return priv->state; -} - -void -gossip_presence_set_state (GossipPresence *presence, - McPresence state) -{ - GossipPresencePriv *priv; - - g_return_if_fail (GOSSIP_IS_PRESENCE (presence)); - - priv = GET_PRIV (presence); - - priv->state = state; - - g_object_notify (G_OBJECT (presence), "state"); -} - -void -gossip_presence_set_status (GossipPresence *presence, - const gchar *status) -{ - GossipPresencePriv *priv; - - priv = GET_PRIV (presence); - g_return_if_fail (GOSSIP_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 -gossip_presence_sort_func (gconstpointer a, - gconstpointer b) -{ - GossipPresencePriv *priv_a; - GossipPresencePriv *priv_b; - gint diff; - - g_return_val_if_fail (GOSSIP_IS_PRESENCE (a), 0); - g_return_val_if_fail (GOSSIP_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 * -gossip_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: - case MC_PRESENCE_OFFLINE: - case MC_PRESENCE_UNSET: - return _("Offline"); - default: - g_assert_not_reached (); - } - - return NULL; -} - -const gchar * -gossip_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 -gossip_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/gossip-presence.h b/libempathy/gossip-presence.h deleted file mode 100644 index 0029906f3..000000000 --- a/libempathy/gossip-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 __GOSSIP_PRESENCE_H__ -#define __GOSSIP_PRESENCE_H__ - -#include -#include - -G_BEGIN_DECLS - -#define GOSSIP_TYPE_PRESENCE (gossip_presence_get_type ()) -#define GOSSIP_PRESENCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOSSIP_TYPE_PRESENCE, GossipPresence)) -#define GOSSIP_PRESENCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOSSIP_TYPE_PRESENCE, GossipPresenceClass)) -#define GOSSIP_IS_PRESENCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOSSIP_TYPE_PRESENCE)) -#define GOSSIP_IS_PRESENCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOSSIP_TYPE_PRESENCE)) -#define GOSSIP_PRESENCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOSSIP_TYPE_PRESENCE, GossipPresenceClass)) - -typedef struct _GossipPresence GossipPresence; -typedef struct _GossipPresenceClass GossipPresenceClass; - -struct _GossipPresence { - GObject parent; -}; - -struct _GossipPresenceClass { - GObjectClass parent_class; -}; - -GType gossip_presence_get_type (void) G_GNUC_CONST; - -GossipPresence * gossip_presence_new (void); -GossipPresence * gossip_presence_new_full (McPresence state, - const gchar *status); -McPresence gossip_presence_get_state (GossipPresence *presence); -const gchar * gossip_presence_get_status (GossipPresence *presence); -void gossip_presence_set_state (GossipPresence *presence, - McPresence state); -void gossip_presence_set_status (GossipPresence *presence, - const gchar *status); -gint gossip_presence_sort_func (gconstpointer a, - gconstpointer b); -const gchar * gossip_presence_state_get_default_status (McPresence state); -const gchar * gossip_presence_state_to_str (McPresence state); -McPresence gossip_presence_state_from_str (const gchar *str); - -G_END_DECLS - -#endif /* __GOSSIP_PRESENCE_H__ */ - diff --git a/libempathy/gossip-telepathy-group.c b/libempathy/gossip-telepathy-group.c deleted file mode 100644 index 5d6bff670..000000000 --- a/libempathy/gossip-telepathy-group.c +++ /dev/null @@ -1,543 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2006 Xavier Claessens - * - * 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. - */ - -#include - -#include -#include -#include -#include -#include - -#include "gossip-debug.h" -#include "gossip-telepathy-group.h" -#include "empathy-marshal.h" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - GOSSIP_TYPE_TELEPATHY_GROUP, GossipTelepathyGroupPriv)) - -#define DEBUG_DOMAIN "TelepathyGroup" - -struct _GossipTelepathyGroupPriv { - DBusGProxy *group_iface; - TpConn *tp_conn; - TpChan *tp_chan; - gchar *group_name; -}; - -static void gossip_telepathy_group_class_init (GossipTelepathyGroupClass *klass); -static void gossip_telepathy_group_init (GossipTelepathyGroup *group); -static void telepathy_group_finalize (GObject *object); -static void telepathy_group_destroy_cb (DBusGProxy *proxy, - GossipTelepathyGroup *group); -static void telepathy_group_members_changed_cb (DBusGProxy *group_iface, - gchar *message, - GArray *added, - GArray *removed, - GArray *local_pending, - GArray *remote_pending, - guint actor, - guint reason, - GossipTelepathyGroup *group); - -enum { - MEMBERS_ADDED, - MEMBERS_REMOVED, - LOCAL_PENDING, - REMOTE_PENDING, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -G_DEFINE_TYPE (GossipTelepathyGroup, gossip_telepathy_group, G_TYPE_OBJECT); - -static void -gossip_telepathy_group_class_init (GossipTelepathyGroupClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = telepathy_group_finalize; - - signals[MEMBERS_ADDED] = - g_signal_new ("members-added", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - empathy_marshal_VOID__POINTER_UINT_UINT_STRING, - G_TYPE_NONE, - 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING); - - signals[MEMBERS_REMOVED] = - g_signal_new ("members-removed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - empathy_marshal_VOID__POINTER_UINT_UINT_STRING, - G_TYPE_NONE, - 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING); - - signals[LOCAL_PENDING] = - g_signal_new ("local-pending", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - empathy_marshal_VOID__POINTER_UINT_UINT_STRING, - G_TYPE_NONE, - 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING); - - signals[REMOTE_PENDING] = - g_signal_new ("remote-pending", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - empathy_marshal_VOID__POINTER_UINT_UINT_STRING, - G_TYPE_NONE, - 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING); - - g_type_class_add_private (object_class, sizeof (GossipTelepathyGroupPriv)); -} - -static void -gossip_telepathy_group_init (GossipTelepathyGroup *group) -{ -} - -static void -telepathy_group_finalize (GObject *object) -{ - GossipTelepathyGroupPriv *priv; - - priv = GET_PRIV (object); - - if (priv->group_iface) { - g_signal_handlers_disconnect_by_func (priv->group_iface, - telepathy_group_destroy_cb, - object); - dbus_g_proxy_disconnect_signal (priv->group_iface, "MembersChanged", - G_CALLBACK (telepathy_group_members_changed_cb), - object); - g_object_unref (priv->group_iface); - } - - if (priv->tp_conn) { - g_object_unref (priv->tp_conn); - } - - if (priv->tp_chan) { - g_object_unref (priv->tp_chan); - } - - g_free (priv->group_name); - - G_OBJECT_CLASS (gossip_telepathy_group_parent_class)->finalize (object); -} - -GossipTelepathyGroup * -gossip_telepathy_group_new (TpChan *tp_chan, - TpConn *tp_conn) -{ - GossipTelepathyGroup *group; - GossipTelepathyGroupPriv *priv; - DBusGProxy *group_iface; - - g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); - - group_iface = tp_chan_get_interface (tp_chan, - TELEPATHY_CHAN_IFACE_GROUP_QUARK); - g_return_val_if_fail (group_iface != NULL, NULL); - - group = g_object_new (GOSSIP_TYPE_TELEPATHY_GROUP, NULL); - priv = GET_PRIV (group); - - priv->tp_conn = g_object_ref (tp_conn); - priv->tp_chan = g_object_ref (tp_chan); - priv->group_iface = g_object_ref (group_iface); - - dbus_g_proxy_connect_signal (priv->group_iface, "MembersChanged", - G_CALLBACK (telepathy_group_members_changed_cb), - group, NULL); - g_signal_connect (group_iface, "destroy", - G_CALLBACK (telepathy_group_destroy_cb), - group); - - - return group; -} - -void -gossip_telepathy_group_add_members (GossipTelepathyGroup *group, - GArray *handles, - const gchar *message) -{ - GossipTelepathyGroupPriv *priv; - GError *error = NULL; - - g_return_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group)); - g_return_if_fail (handles != NULL); - - priv = GET_PRIV (group); - - if (!tp_chan_iface_group_add_members (priv->group_iface, - handles, - message, - &error)) { - gossip_debug (DEBUG_DOMAIN, - "Failed to add members: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - } -} - -void -gossip_telepathy_group_add_member (GossipTelepathyGroup *group, - guint handle, - const gchar *message) -{ - GArray *handles; - - handles = g_array_new (FALSE, FALSE, sizeof (guint)); - g_array_append_val (handles, handle); - - gossip_telepathy_group_add_members (group, handles, message); - - g_array_free (handles, TRUE); -} - -void -gossip_telepathy_group_remove_members (GossipTelepathyGroup *group, - GArray *handles, - const gchar *message) -{ - GossipTelepathyGroupPriv *priv; - GError *error = NULL; - - g_return_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group)); - - priv = GET_PRIV (group); - - if (!tp_chan_iface_group_remove_members (priv->group_iface, - handles, - message, - &error)) { - gossip_debug (DEBUG_DOMAIN, - "Failed to remove members: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - } -} - -void -gossip_telepathy_group_remove_member (GossipTelepathyGroup *group, - guint handle, - const gchar *message) -{ - GArray *handles; - - g_return_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group)); - - handles = g_array_new (FALSE, FALSE, sizeof (guint)); - g_array_append_val (handles, handle); - - gossip_telepathy_group_remove_members (group, handles, message); - - g_array_free (handles, TRUE); -} - -GArray * -gossip_telepathy_group_get_members (GossipTelepathyGroup *group) -{ - GossipTelepathyGroupPriv *priv; - GArray *members; - GError *error = NULL; - - g_return_val_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group), NULL); - - priv = GET_PRIV (group); - - if (!tp_chan_iface_group_get_members (priv->group_iface, - &members, - &error)) { - gossip_debug (DEBUG_DOMAIN, - "Couldn't get members: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - return NULL; - } - - return members; -} - -void -gossip_telepathy_group_get_all_members (GossipTelepathyGroup *group, - GArray **members, - GArray **local_pending, - GArray **remote_pending) -{ - GossipTelepathyGroupPriv *priv; - GError *error = NULL; - - g_return_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group)); - - priv = GET_PRIV (group); - - if (!tp_chan_iface_group_get_all_members (priv->group_iface, - members, - local_pending, - remote_pending, - &error)) { - gossip_debug (DEBUG_DOMAIN, - "Couldn't get all members: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - } -} - -GList * -gossip_telepathy_group_get_local_pending_members_with_info (GossipTelepathyGroup *group) -{ - GossipTelepathyGroupPriv *priv; - GPtrArray *array; - guint i; - GList *infos = NULL; - GError *error = NULL; - - g_return_val_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group), NULL); - - priv = GET_PRIV (group); - - if (!tp_chan_iface_group_get_local_pending_members_with_info (priv->group_iface, - &array, - &error)) { - gossip_debug (DEBUG_DOMAIN, - "GetLocalPendingMembersWithInfo failed: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - - return NULL; - } - - if (!array) { - /* This happens with butterfly because - * GetLocalPendingMembersWithInfo is not - * implemented */ - return NULL; - } - - for (i = 0; array->len > i; i++) { - GValueArray *pending_struct; - GossipTpGroupInfo *info; - const gchar *message; - - info = g_slice_new (GossipTpGroupInfo); - - pending_struct = g_ptr_array_index (array, i); - info->member = g_value_get_uint (g_value_array_get_nth (pending_struct, 0)); - info->actor = g_value_get_uint (g_value_array_get_nth (pending_struct, 1)); - info->reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2)); - message = g_value_get_string (g_value_array_get_nth (pending_struct, 3)); - info->message = g_strdup (message); - g_value_array_free (pending_struct); - - infos = g_list_prepend (infos, info); - } - g_ptr_array_free (array, TRUE); - - return infos; -} - -void -gossip_telepathy_group_info_list_free (GList *infos) -{ - GList *l; - - for (l = infos; l; l = l->next) { - GossipTpGroupInfo *info; - - info = l->data; - - g_free (info->message); - g_slice_free (GossipTpGroupInfo, info); - } - g_list_free (infos); -} - - -static void -telepathy_group_destroy_cb (DBusGProxy *proxy, - GossipTelepathyGroup *group) -{ - GossipTelepathyGroupPriv *priv; - - priv = GET_PRIV (group); - - g_object_unref (priv->group_iface); - g_object_unref (priv->tp_conn); - g_object_unref (priv->tp_chan); - priv->group_iface = NULL; - priv->tp_chan = NULL; - priv->tp_conn = NULL; -} - -static void -telepathy_group_members_changed_cb (DBusGProxy *group_iface, - gchar *message, - GArray *added, - GArray *removed, - GArray *local_pending, - GArray *remote_pending, - guint actor, - guint reason, - GossipTelepathyGroup *group) -{ - GossipTelepathyGroupPriv *priv; - - priv = GET_PRIV (group); - - /* emit signals */ - if (added->len > 0) { - g_signal_emit (group, signals[MEMBERS_ADDED], 0, - added, actor, reason, message); - } - if (removed->len > 0) { - g_signal_emit (group, signals[MEMBERS_REMOVED], 0, - removed, actor, reason, message); - } - if (local_pending->len > 0) { - g_signal_emit (group, signals[LOCAL_PENDING], 0, - local_pending, actor, reason, message); - } - if (remote_pending->len > 0) { - g_signal_emit (group, signals[REMOTE_PENDING], 0, - remote_pending, actor, reason, message); - } -} - -const gchar * -gossip_telepathy_group_get_name (GossipTelepathyGroup *group) -{ - TelepathyHandleType handle_type; - guint channel_handle; - GArray *group_handles; - gchar **group_names; - GError *error = NULL; - - GossipTelepathyGroupPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group), NULL); - - priv = GET_PRIV (group); - - /* Lazy initialisation */ - if (priv->group_name) { - return priv->group_name; - } - - if (!tp_chan_get_handle (DBUS_G_PROXY (priv->tp_chan), - &handle_type, - &channel_handle, - &error)) { - gossip_debug (DEBUG_DOMAIN, - "Couldn't retreive channel handle for group: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - return NULL; - } - - group_handles = g_array_new (FALSE, FALSE, sizeof (guint)); - g_array_append_val (group_handles, channel_handle); - if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn), - handle_type, - group_handles, - &group_names, - &error)) { - gossip_debug (DEBUG_DOMAIN, - "Couldn't get group name: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - g_array_free (group_handles, TRUE); - return NULL; - } - - priv->group_name = *group_names; - g_array_free (group_handles, TRUE); - g_free (group_names); - - return priv->group_name; -} - -guint -gossip_telepathy_group_get_self_handle (GossipTelepathyGroup *group) -{ - GossipTelepathyGroupPriv *priv; - guint handle; - GError *error = NULL; - - g_return_val_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group), 0 ); - - priv = GET_PRIV (group); - - if (!tp_chan_iface_group_get_self_handle (priv->group_iface, &handle, &error)) { - gossip_debug (DEBUG_DOMAIN, - "Failed to get self handle: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - return 0; - } - - return handle; -} - -const gchar * -gossip_telepathy_group_get_object_path (GossipTelepathyGroup *group) -{ - GossipTelepathyGroupPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_TELEPATHY_GROUP (group), NULL); - - priv = GET_PRIV (group); - - return dbus_g_proxy_get_path (DBUS_G_PROXY (priv->tp_chan)); -} - -gboolean -gossip_telepathy_group_is_member (GossipTelepathyGroup *group, - guint handle) -{ - GArray *members; - guint i; - gboolean found = FALSE; - - members = gossip_telepathy_group_get_members (group); - for (i = 0; i < members->len; i++) { - if (g_array_index (members, guint, i) == handle) { - found = TRUE; - break; - } - } - g_array_free (members, TRUE); - - return found; -} - diff --git a/libempathy/gossip-telepathy-group.h b/libempathy/gossip-telepathy-group.h deleted file mode 100644 index 17b96de2e..000000000 --- a/libempathy/gossip-telepathy-group.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2006 Xavier Claessens - * - * 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 __GOSSIP_TELEPATHY_GROUP_H__ -#define __GOSSIP_TELEPATHY_GROUP_H__ - -#include - -#include - -G_BEGIN_DECLS - -#define GOSSIP_TYPE_TELEPATHY_GROUP (gossip_telepathy_group_get_type ()) -#define GOSSIP_TELEPATHY_GROUP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOSSIP_TYPE_TELEPATHY_GROUP, GossipTelepathyGroup)) -#define GOSSIP_TELEPATHY_GROUP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GOSSIP_TYPE_TELEPATHY_GROUP, GossipTelepathyGroupClass)) -#define GOSSIP_IS_TELEPATHY_GROUP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOSSIP_TYPE_TELEPATHY_GROUP)) -#define GOSSIP_IS_TELEPATHY_GROUP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOSSIP_TYPE_TELEPATHY_GROUP)) -#define GOSSIP_TELEPATHY_GROUP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOSSIP_TYPE_TELEPATHY_GROUP, GossipTelepathyGroupClass)) - -typedef struct _GossipTelepathyGroup GossipTelepathyGroup; -typedef struct _GossipTelepathyGroupClass GossipTelepathyGroupClass; -typedef struct _GossipTelepathyGroupPriv GossipTelepathyGroupPriv; - -struct _GossipTelepathyGroup { - GObject parent; -}; - -struct _GossipTelepathyGroupClass { - GObjectClass parent_class; -}; - -typedef struct { - guint member; - guint actor; - guint reason; - gchar *message; -} GossipTpGroupInfo; - -GType gossip_telepathy_group_get_type (void) G_GNUC_CONST; -GossipTelepathyGroup *gossip_telepathy_group_new (TpChan *tp_chan, - TpConn *tp_conn); -void gossip_telepathy_group_add_members (GossipTelepathyGroup *group, - GArray *handles, - const gchar *message); -void gossip_telepathy_group_add_member (GossipTelepathyGroup *group, - guint handle, - const gchar *message); -void gossip_telepathy_group_remove_members (GossipTelepathyGroup *group, - GArray *handle, - const gchar *message); -void gossip_telepathy_group_remove_member (GossipTelepathyGroup *group, - guint handle, - const gchar *message); -GArray * gossip_telepathy_group_get_members (GossipTelepathyGroup *group); -void gossip_telepathy_group_get_all_members (GossipTelepathyGroup *group, - GArray **members, - GArray **local_pending, - GArray **remote_pending); -GList * gossip_telepathy_group_get_local_pending_members_with_info - (GossipTelepathyGroup *group); -void gossip_telepathy_group_info_list_free (GList *infos); -const gchar * gossip_telepathy_group_get_name (GossipTelepathyGroup *group); -guint gossip_telepathy_group_get_self_handle (GossipTelepathyGroup *group); -const gchar * gossip_telepathy_group_get_object_path (GossipTelepathyGroup *group); -gboolean gossip_telepathy_group_is_member (GossipTelepathyGroup *group, - guint handle); - -G_END_DECLS - -#endif /* __GOSSIP_TELEPATHY_GROUP_H__ */ diff --git a/libempathy/gossip-time.c b/libempathy/gossip-time.c deleted file mode 100644 index a1956354e..000000000 --- a/libempathy/gossip-time.c +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003-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: Richard Hult - */ - -#include "config.h" - -#include -#include -#include - -#include "gossip-time.h" - -/* Note: GossipTime is always in UTC. */ - -GossipTime -gossip_time_get_current (void) -{ - return time (NULL); -} - -time_t -gossip_time_get_local_time (struct tm *tm) -{ - const gchar *timezone; - time_t t; - - timezone = g_getenv ("TZ"); - g_setenv ("TZ", "", TRUE); - - tzset (); - - t = mktime (tm); - - if (timezone) { - g_setenv ("TZ", timezone, TRUE); - } else { - g_unsetenv ("TZ"); - } - - tzset (); - - return t; -} - -/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on - * failure. The alternative format "20021209" is also accepted. - */ -GossipTime -gossip_time_parse (const gchar *str) -{ - struct tm tm; - gint year, month; - gint n_parsed; - - memset (&tm, 0, sizeof (struct tm)); - - n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d", - &year, &month, &tm.tm_mday, &tm.tm_hour, - &tm.tm_min, &tm.tm_sec); - if (n_parsed != 3 && n_parsed != 6) { - return 0; - } - - tm.tm_year = year - 1900; - tm.tm_mon = month - 1; - tm.tm_isdst = -1; - - return gossip_time_get_local_time (&tm); -} - -/* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */ -gchar * -gossip_time_to_string_utc (GossipTime t, - const gchar *format) -{ - gchar stamp[128]; - struct tm *tm; - - g_return_val_if_fail (format != NULL, NULL); - - tm = gmtime (&t); - if (strftime (stamp, sizeof (stamp), format, tm) == 0) { - return NULL; - } - - return g_strdup (stamp); -} - -/* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */ -gchar * -gossip_time_to_string_local (GossipTime t, - const gchar *format) -{ - gchar stamp[128]; - struct tm *tm; - - g_return_val_if_fail (format != NULL, NULL); - - tm = localtime (&t); - if (strftime (stamp, sizeof (stamp), format, tm) == 0) { - return NULL; - } - - return g_strdup (stamp); -} - diff --git a/libempathy/gossip-time.h b/libempathy/gossip-time.h deleted file mode 100644 index 06057aa52..000000000 --- a/libempathy/gossip-time.h +++ /dev/null @@ -1,50 +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 __GOSSIP_TIME_H__ -#define __GOSSIP_TIME_H__ - -#define __USE_XOPEN -#include - -#include - -G_BEGIN_DECLS - -#define GOSSIP_TIME_FORMAT_DISPLAY_SHORT "%H:%M" -#define GOSSIP_TIME_FORMAT_DISPLAY_LONG "%a %d %b %Y" - -/* Note: Always in UTC. */ -typedef long GossipTime; - -GossipTime gossip_time_get_current (void); -time_t gossip_time_get_local_time (struct tm *tm); -GossipTime gossip_time_parse (const gchar *str); -GossipTime gossip_time_parse_format (const gchar *str, - const gchar *format); -gchar *gossip_time_to_string_utc (GossipTime t, - const gchar *format); -gchar *gossip_time_to_string_local (GossipTime t, - const gchar *format); - -G_END_DECLS - -#endif /* __GOSSIP_TIME_H__ */ - diff --git a/libempathy/gossip-utils.c b/libempathy/gossip-utils.c deleted file mode 100644 index 27bcb85d1..000000000 --- a/libempathy/gossip-utils.c +++ /dev/null @@ -1,495 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003-2007 Imendio AB - * Copyright (C) 2007 Collabora Ltd. - * - * 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 - * Martyn Russell - * Xavier Claessens - */ - -#include "config.h" - -#include -#include -#include -#include - -#include - -#include -#include - -#include "gossip-debug.h" -#include "gossip-utils.h" -#include "empathy-contact-manager.h" - -#define DEBUG_DOMAIN "Utils" - -static void regex_init (void); - -gchar * -gossip_substring (const gchar *str, - gint start, - gint end) -{ - return g_strndup (str + start, end - start); -} - -/* - * Regular Expression code to match urls. - */ -#define USERCHARS "-A-Za-z0-9" -#define PASSCHARS "-A-Za-z0-9,?;.:/!%$^*&~\"#'" -#define HOSTCHARS "-A-Za-z0-9" -#define PATHCHARS "-A-Za-z0-9_$.+!*(),;:@&=?/~#%" -#define SCHEME "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)" -#define USER "[" USERCHARS "]+(:["PASSCHARS "]+)?" -#define URLPATH "/[" PATHCHARS "]*[^]'.}>) \t\r\n,\\\"]" - -static regex_t dingus[GOSSIP_REGEX_ALL]; - -static void -regex_init (void) -{ - static gboolean inited = FALSE; - const gchar *expression; - gint i; - - if (inited) { - return; - } - - for (i = 0; i < GOSSIP_REGEX_ALL; i++) { - switch (i) { - case GOSSIP_REGEX_AS_IS: - expression = - SCHEME "//(" USER "@)?[" HOSTCHARS ".]+" - "(:[0-9]+)?(" URLPATH ")?"; - break; - case GOSSIP_REGEX_BROWSER: - expression = - "(www|ftp)[" HOSTCHARS "]*\\.[" HOSTCHARS ".]+" - "(:[0-9]+)?(" URLPATH ")?"; - break; - case GOSSIP_REGEX_EMAIL: - expression = - "(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9]" - "[a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+"; - break; - case GOSSIP_REGEX_OTHER: - expression = - "news:[-A-Z\\^_a-z{|}~!\"#$%&'()*+,./0-9;:=?`]+" - "@[" HOSTCHARS ".]+(:[0-9]+)?"; - break; - default: - /* Silence the compiler. */ - expression = NULL; - continue; - } - - memset (&dingus[i], 0, sizeof (regex_t)); - regcomp (&dingus[i], expression, REG_EXTENDED | REG_ICASE); - } - - inited = TRUE; -} - -gint -gossip_regex_match (GossipRegExType type, - const gchar *msg, - GArray *start, - GArray *end) -{ - regmatch_t matches[1]; - gint ret = 0; - gint num_matches = 0; - gint offset = 0; - gint i; - - g_return_val_if_fail (type >= 0 || type <= GOSSIP_REGEX_ALL, 0); - - regex_init (); - - while (!ret && type != GOSSIP_REGEX_ALL) { - ret = regexec (&dingus[type], msg + offset, 1, matches, 0); - if (ret == 0) { - gint s; - - num_matches++; - - s = matches[0].rm_so + offset; - offset = matches[0].rm_eo + offset; - - g_array_append_val (start, s); - g_array_append_val (end, offset); - } - } - - if (type != GOSSIP_REGEX_ALL) { - gossip_debug (DEBUG_DOMAIN, - "Found %d matches for regex type:%d", - num_matches, type); - return num_matches; - } - - /* If GOSSIP_REGEX_ALL then we run ALL regex's on the string. */ - for (i = 0; i < GOSSIP_REGEX_ALL; i++, ret = 0) { - while (!ret) { - ret = regexec (&dingus[i], msg + offset, 1, matches, 0); - if (ret == 0) { - gint s; - - num_matches++; - - s = matches[0].rm_so + offset; - offset = matches[0].rm_eo + offset; - - g_array_append_val (start, s); - g_array_append_val (end, offset); - } - } - } - - gossip_debug (DEBUG_DOMAIN, - "Found %d matches for ALL regex types", - num_matches); - - return num_matches; -} - -gint -gossip_strcasecmp (const gchar *s1, - const gchar *s2) -{ - return gossip_strncasecmp (s1, s2, -1); -} - -gint -gossip_strncasecmp (const gchar *s1, - const gchar *s2, - gsize n) -{ - gchar *u1, *u2; - gint ret_val; - - u1 = g_utf8_casefold (s1, n); - u2 = g_utf8_casefold (s2, n); - - ret_val = g_utf8_collate (u1, u2); - g_free (u1); - g_free (u2); - - return ret_val; -} - -gboolean -gossip_xml_validate (xmlDoc *doc, - const gchar *dtd_filename) -{ - gchar *path, *escaped; - xmlValidCtxt cvp; - xmlDtd *dtd; - gboolean ret; - - path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL); - - /* The list of valid chars is taken from libxml. */ - escaped = xmlURIEscapeStr (path, ":@&=+$,/?;"); - - g_free (path); - - memset (&cvp, 0, sizeof (cvp)); - dtd = xmlParseDTD (NULL, escaped); - ret = xmlValidateDtd (&cvp, doc, dtd); - - xmlFree (escaped); - xmlFreeDtd (dtd); - - return ret; -} - -xmlNodePtr -gossip_xml_node_get_child (xmlNodePtr node, - const gchar *child_name) -{ - xmlNodePtr l; - - g_return_val_if_fail (node != NULL, NULL); - g_return_val_if_fail (child_name != NULL, NULL); - - for (l = node->children; l; l = l->next) { - if (l->name && strcmp (l->name, child_name) == 0) { - return l; - } - } - - return NULL; -} - -xmlChar * -gossip_xml_node_get_child_content (xmlNodePtr node, - const gchar *child_name) -{ - xmlNodePtr l; - - g_return_val_if_fail (node != NULL, NULL); - g_return_val_if_fail (child_name != NULL, NULL); - - l = gossip_xml_node_get_child (node, child_name); - if (l) { - return xmlNodeGetContent (l); - } - - return NULL; -} - -xmlNodePtr -gossip_xml_node_find_child_prop_value (xmlNodePtr node, - const gchar *prop_name, - const gchar *prop_value) -{ - xmlNodePtr l; - xmlNodePtr found = NULL; - - g_return_val_if_fail (node != NULL, NULL); - g_return_val_if_fail (prop_name != NULL, NULL); - g_return_val_if_fail (prop_value != NULL, NULL); - - for (l = node->children; l && !found; l = l->next) { - xmlChar *prop; - - if (!xmlHasProp (l, prop_name)) { - continue; - } - - prop = xmlGetProp (l, prop_name); - if (prop && strcmp (prop, prop_value) == 0) { - found = l; - } - - xmlFree (prop); - } - - return found; -} - -GType -gossip_dbus_type_to_g_type (const gchar *dbus_type_string) -{ - if (dbus_type_string == NULL) - return G_TYPE_NONE; - - if (dbus_type_string[0] == 's') { - return G_TYPE_STRING; - } - else if (dbus_type_string[0] == 'b') { - return G_TYPE_BOOLEAN; - } - else if (dbus_type_string[0] == 'q') { - return G_TYPE_UINT; - } - else if (dbus_type_string[0] == 'n') { - return G_TYPE_INT; - } - - g_assert_not_reached (); - return G_TYPE_NONE; -} - -const gchar * -gossip_g_type_to_dbus_type (GType g_type) -{ - switch (g_type) { - case G_TYPE_STRING: - return "s"; - case G_TYPE_BOOLEAN: - return "b"; - case G_TYPE_UINT: - return "q"; - case G_TYPE_INT: - return "n"; - default: - g_assert_not_reached (); - } - - return NULL; -} - -gchar * -gossip_g_value_to_string (const GValue *value) -{ - gchar *return_string = NULL; - GValue string_g_value = {0, }; - - g_value_init (&string_g_value, G_TYPE_STRING); - g_value_transform (value, &string_g_value); - return_string = g_value_dup_string (&string_g_value); - g_value_unset (&string_g_value); - - return return_string; -} - -GValue * -gossip_string_to_g_value (const gchar *str, GType type) -{ - GValue *g_value; - - g_value = g_new0 (GValue, 1); - g_value_init (g_value, type); - - switch (type) { - case G_TYPE_STRING: - g_value_set_string (g_value, str); - break; - case G_TYPE_BOOLEAN: - g_value_set_boolean (g_value, (str[0] == 'y' || str[0] == 'T')); - break; - case G_TYPE_UINT: - g_value_set_uint (g_value, atoi (str)); - break; - case G_TYPE_INT: - g_value_set_int (g_value, atoi (str)); - break; - default: - g_assert_not_reached (); - } - - return g_value; -} - -gboolean -gossip_g_value_equal (const GValue *value1, - const GValue *value2) -{ - GType type; - - g_return_val_if_fail (value1 != NULL, FALSE); - g_return_val_if_fail (value2 != NULL, FALSE); - - type = G_VALUE_TYPE (value1); - if (type != G_VALUE_TYPE (value2)) { - return FALSE; - } - - switch (type) - { - case G_TYPE_STRING: { - const gchar *str1; - const gchar *str2; - - str1 = g_value_get_string (value1); - str2 = g_value_get_string (value2); - return (str1 && str2 && strcmp (str1, str2) == 0) || - (G_STR_EMPTY (str1) && G_STR_EMPTY (str2)); - } - case G_TYPE_BOOLEAN: - return g_value_get_boolean (value1) == g_value_get_boolean (value2); - case G_TYPE_UINT: - return g_value_get_uint (value1) == g_value_get_uint (value2); - case G_TYPE_INT: - return g_value_get_int (value1) == g_value_get_int (value2); - default: - g_warning ("Unsupported GType in value comparaison"); - } - - return FALSE; -} - -guint -gossip_account_hash (gconstpointer key) -{ - return g_str_hash (mc_account_get_unique_name (MC_ACCOUNT (key))); -} - -gboolean -gossip_account_equal (gconstpointer a, - gconstpointer b) -{ - const gchar *name_a; - const gchar *name_b; - - name_a = mc_account_get_unique_name (MC_ACCOUNT (a)); - name_b = mc_account_get_unique_name (MC_ACCOUNT (b)); - - return g_str_equal (name_a, name_b); -} - -MissionControl * -gossip_mission_control_new (void) -{ - static MissionControl *mc = NULL; - - if (!mc) { - mc = mission_control_new (tp_get_bus ()); - g_object_add_weak_pointer (G_OBJECT (mc), (gpointer) &mc); - } else { - g_object_ref (mc); - } - - return mc; -} - -gchar * -gossip_get_channel_id (McAccount *account, - TpChan *tp_chan) -{ - MissionControl *mc; - TpConn *tp_conn; - GArray *handles; - gchar **names; - gchar *name; - GError *error; - - g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); - - mc = gossip_mission_control_new (); - tp_conn = mission_control_get_connection (mc, account, NULL); - g_object_unref (mc); - - if (!tp_conn) { - return NULL; - } - - /* Get the handle's name */ - handles = g_array_new (FALSE, FALSE, sizeof (guint)); - g_array_append_val (handles, tp_chan->handle); - if (!tp_conn_inspect_handles (DBUS_G_PROXY (tp_conn), - tp_chan->handle_type, - handles, - &names, - &error)) { - gossip_debug (DEBUG_DOMAIN, - "Couldn't get id: %s", - error ? error->message : "No error given"); - - g_clear_error (&error); - g_array_free (handles, TRUE); - g_object_unref (tp_conn); - - return NULL; - } - - name = *names; - g_free (names); - g_object_unref (tp_conn); - - return name; -} - diff --git a/libempathy/gossip-utils.h b/libempathy/gossip-utils.h deleted file mode 100644 index 638c114bd..000000000 --- a/libempathy/gossip-utils.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003-2007 Imendio AB - * Copyright (C) 2007 Collabora Ltd. - * - * 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 - * Martyn Russell - * Xavier Claessens - */ - -#ifndef __GOSSIP_UTILS_H__ -#define __GOSSIP_UTILS_H__ - -#include -#include - -#include -#include - -#include - -#include -#include - -#include "gossip-contact.h" - -G_BEGIN_DECLS - -#define G_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') - -typedef enum { - GOSSIP_REGEX_AS_IS, - GOSSIP_REGEX_BROWSER, - GOSSIP_REGEX_EMAIL, - GOSSIP_REGEX_OTHER, - GOSSIP_REGEX_ALL, -} GossipRegExType; - -/* Regular expressions */ -gchar * gossip_substring (const gchar *str, - gint start, - gint end); -gint gossip_regex_match (GossipRegExType type, - const gchar *msg, - GArray *start, - GArray *end); - -/* Strings */ -gint gossip_strcasecmp (const gchar *s1, - const gchar *s2); -gint gossip_strncasecmp (const gchar *s1, - const gchar *s2, - gsize n); - -/* XML */ -gboolean gossip_xml_validate (xmlDoc *doc, - const gchar *dtd_filename); -xmlNodePtr gossip_xml_node_get_child (xmlNodePtr node, - const gchar *child_name); -xmlChar * gossip_xml_node_get_child_content (xmlNodePtr node, - const gchar *child_name); -xmlNodePtr gossip_xml_node_find_child_prop_value (xmlNodePtr node, - const gchar *prop_name, - const gchar *prop_value); - - -/* GValue/GType */ -GType gossip_dbus_type_to_g_type (const gchar *dbus_type_string); -const gchar *gossip_g_type_to_dbus_type (GType g_type); -gchar * gossip_g_value_to_string (const GValue *value); -GValue * gossip_string_to_g_value (const gchar *str, - GType type); -gboolean gossip_g_value_equal (const GValue *value1, - const GValue *value2); - -guint gossip_account_hash (gconstpointer key); -gboolean gossip_account_equal (gconstpointer a, - gconstpointer b); -MissionControl *gossip_mission_control_new (void); -gchar * gossip_get_channel_id (McAccount *account, - TpChan *tp_chan); - -G_END_DECLS - -#endif /* __GOSSIP_UTILS_H__ */ -- cgit v1.2.3