Sun, 21 Jul 2013 05:49:05 +0530
Renamed blistnodes.[ch] to blistnode.[ch], presences.[ch] to presence.[ch]
--- a/libpurple/Makefile.am Sun Jul 21 02:52:23 2013 +0530 +++ b/libpurple/Makefile.am Sun Jul 21 05:49:05 2013 +0530 @@ -40,7 +40,7 @@ account.c \ accounts.c \ accountopt.c \ - blistnodes.c \ + blistnode.c \ blistnodetypes.c \ buddylist.c \ buddyicon.c \ @@ -79,7 +79,7 @@ pluginpref.c \ pounce.c \ prefs.c \ - presences.c \ + presence.c \ proxy.c \ prpl.c \ request.c \ @@ -114,7 +114,7 @@ account.h \ accounts.h \ accountopt.h \ - blistnodes.h \ + blistnode.h \ blistnodetypes.h \ buddylist.h \ buddyicon.h \ @@ -150,7 +150,7 @@ pluginpref.h \ pounce.h \ prefs.h \ - presences.h \ + presence.h \ proxy.h \ prpl.h \ request.h \ @@ -227,10 +227,10 @@ dbus_sources = dbus-server.c dbus-useful.c dbus_headers = dbus-bindings.h dbus-purple.h dbus-server.h dbus-useful.h dbus-define-api.h dbus-types.h -dbus_exported = dbus-useful.h dbus-define-api.h account.h accounts.h blistnodes.h \ +dbus_exported = dbus-useful.h dbus-define-api.h account.h accounts.h blistnode.h \ blistnodetypes.h buddylist.h buddyicon.h connection.h conversation.h \ conversationtypes.h conversations.h core.h ft.h log.h notify.h \ - prefs.h presences.h roomlist.h savedstatuses.h smiley.h status.h \ + prefs.h presence.h roomlist.h savedstatuses.h smiley.h status.h \ server.h util.h xmlnode.h prpl.h purple_build_coreheaders = $(addprefix $(srcdir)/, $(purple_coreheaders)) \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/blistnode.c Sun Jul 21 05:49:05 2013 +0530 @@ -0,0 +1,662 @@ +/* + * purple + * + * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + * + */ +#include "blistnodetypes.h" +#include "internal.h" + +#define PURPLE_BLIST_NODE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_BLIST_NODE, PurpleBListNodePrivate)) + +/** @copydoc _PurpleBListNodePrivate */ +typedef struct _PurpleBListNodePrivate PurpleBListNodePrivate; + +#define PURPLE_COUNTING_NODE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodePrivate)) + +/** @copydoc _PurpleCountingNodePrivate */ +typedef struct _PurpleCountingNodePrivate PurpleCountingNodePrivate; + +/** Private data of a buddy list node */ +struct _PurpleBListNodePrivate { + GHashTable *settings; /**< per-node settings */ + gboolean dont_save; /**< node should not be saved with the buddy list */ +}; + +/* BList node property enums */ +enum +{ + BLNODE_PROP_0, + BLNODE_PROP_DONT_SAVE, + BLNODE_PROP_LAST +}; + +/** Private data of a counting node */ +struct _PurpleCountingNodePrivate { + int totalsize; /**< The number of children under this node */ + int currentsize; /**< The number of children under this node + corresponding to online accounts */ + int onlinecount; /**< The number of children under this contact who are + currently online */ +}; + +/* Counting node property enums */ +enum +{ + CNODE_PROP_0, + CNODE_PROP_TOTAL_SIZE, + CNODE_PROP_CURRENT_SIZE, + CNODE_PROP_ONLINE_COUNT, + CNODE_PROP_LAST +}; + +static GObjectClass *parent_class; + +/**************************************************************************/ +/* Buddy list node API */ +/**************************************************************************/ + +static PurpleBListNode *get_next_node(PurpleBListNode *node, gboolean godeep) +{ + if (node == NULL) + return NULL; + + if (godeep && node->child) + return node->child; + + if (node->next) + return node->next; + + return get_next_node(node->parent, FALSE); +} + +PurpleBListNode *purple_blist_node_next(PurpleBListNode *node, gboolean offline) +{ + PurpleBListNode *ret = node; + + if (offline) + return get_next_node(ret, TRUE); + do + { + ret = get_next_node(ret, TRUE); + } while (ret && PURPLE_IS_BUDDY(ret) && + !purple_account_is_connected(purple_buddy_get_account((PurpleBuddy *)ret))); + + return ret; +} + +PurpleBListNode *purple_blist_node_get_parent(PurpleBListNode *node) +{ + return node ? node->parent : NULL; +} + +PurpleBListNode *purple_blist_node_get_first_child(PurpleBListNode *node) +{ + return node ? node->child : NULL; +} + +PurpleBListNode *purple_blist_node_get_sibling_next(PurpleBListNode *node) +{ + return node? node->next : NULL; +} + +PurpleBListNode *purple_blist_node_get_sibling_prev(PurpleBListNode *node) +{ + return node? node->prev : NULL; +} + +void * +purple_blist_node_get_ui_data(const PurpleBListNode *node) +{ + g_return_val_if_fail(node, NULL); + + return node->ui_data; +} + +void +purple_blist_node_set_ui_data(PurpleBListNode *node, void *ui_data) { + g_return_if_fail(node); + + node->ui_data = ui_data; +} + +void purple_blist_node_remove_setting(PurpleBListNode *node, const char *key) +{ + PurpleBListUiOps *ops; + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_if_fail(priv != NULL); + g_return_if_fail(priv->settings != NULL); + g_return_if_fail(key != NULL); + + g_hash_table_remove(priv->settings, key); + + ops = purple_blist_get_ui_ops(); + if (ops && ops->save_node) + ops->save_node(node); +} + +void +purple_blist_node_set_dont_save(PurpleBListNode *node, gboolean dont_save) +{ + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_if_fail(priv != NULL); + + priv->dont_save = dont_save; +} + +gboolean +purple_blist_node_get_dont_save(PurpleBListNode *node) +{ + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_val_if_fail(priv != NULL, 0); + + return priv->dont_save; +} + +GHashTable * +purple_blist_node_get_settings(PurpleBListNode *node) +{ + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_val_if_fail(priv != NULL, NULL); + + return priv->settings; +} + +gboolean +purple_blist_node_has_setting(PurpleBListNode* node, const char *key) +{ + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_val_if_fail(priv != NULL, FALSE); + g_return_val_if_fail(priv->settings != NULL, FALSE); + g_return_val_if_fail(key != NULL, FALSE); + + /* Boxed type, so it won't ever be NULL, so no need for _extended */ + return (g_hash_table_lookup(priv->settings, key) != NULL); +} + +void +purple_blist_node_set_bool(PurpleBListNode* node, const char *key, gboolean data) +{ + GValue *value; + PurpleBListUiOps *ops; + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_if_fail(priv != NULL); + g_return_if_fail(priv->settings != NULL); + g_return_if_fail(key != NULL); + + value = purple_g_value_new(G_TYPE_BOOLEAN); + g_value_set_boolean(value, data); + + g_hash_table_replace(priv->settings, g_strdup(key), value); + + ops = purple_blist_get_ui_ops(); + if (ops && ops->save_node) + ops->save_node(node); +} + +gboolean +purple_blist_node_get_bool(PurpleBListNode* node, const char *key) +{ + GValue *value; + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_val_if_fail(priv != NULL, FALSE); + g_return_val_if_fail(priv->settings != NULL, FALSE); + g_return_val_if_fail(key != NULL, FALSE); + + value = g_hash_table_lookup(priv->settings, key); + + if (value == NULL) + return FALSE; + + g_return_val_if_fail(G_VALUE_HOLDS_BOOLEAN(value), FALSE); + + return g_value_get_boolean(value); +} + +void +purple_blist_node_set_int(PurpleBListNode* node, const char *key, int data) +{ + GValue *value; + PurpleBListUiOps *ops; + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_if_fail(priv != NULL); + g_return_if_fail(priv->settings != NULL); + g_return_if_fail(key != NULL); + + value = purple_g_value_new(G_TYPE_INT); + g_value_set_int(value, data); + + g_hash_table_replace(priv->settings, g_strdup(key), value); + + ops = purple_blist_get_ui_ops(); + if (ops && ops->save_node) + ops->save_node(node); +} + +int +purple_blist_node_get_int(PurpleBListNode* node, const char *key) +{ + GValue *value; + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_val_if_fail(priv != NULL, 0); + g_return_val_if_fail(priv->settings != NULL, 0); + g_return_val_if_fail(key != NULL, 0); + + value = g_hash_table_lookup(priv->settings, key); + + if (value == NULL) + return 0; + + g_return_val_if_fail(G_VALUE_HOLDS_INT(value), 0); + + return g_value_get_int(value); +} + +void +purple_blist_node_set_string(PurpleBListNode* node, const char *key, const char *data) +{ + GValue *value; + PurpleBListUiOps *ops; + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_if_fail(priv != NULL); + g_return_if_fail(priv->settings != NULL); + g_return_if_fail(key != NULL); + + value = purple_g_value_new(G_TYPE_STRING); + g_value_set_string(value, data); + + g_hash_table_replace(priv->settings, g_strdup(key), value); + + ops = purple_blist_get_ui_ops(); + if (ops && ops->save_node) + ops->save_node(node); +} + +const char * +purple_blist_node_get_string(PurpleBListNode* node, const char *key) +{ + GValue *value; + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); + + g_return_val_if_fail(priv != NULL, NULL); + g_return_val_if_fail(priv->settings != NULL, NULL); + g_return_val_if_fail(key != NULL, NULL); + + value = g_hash_table_lookup(priv->settings, key); + + if (value == NULL) + return NULL; + + g_return_val_if_fail(G_VALUE_HOLDS_STRING(value), NULL); + + return g_value_get_string(value); +} + +GList * +purple_blist_node_get_extended_menu(PurpleBListNode *n) +{ + GList *menu = NULL; + + g_return_val_if_fail(n != NULL, NULL); + + purple_signal_emit(purple_blist_get_handle(), "blist-node-extended-menu", + n, &menu); + return menu; +} + +/************************************************************************** + * GObject code for PurpleBListNode + **************************************************************************/ + +/* GObject Property names */ +#define BLNODE_PROP_DONT_SAVE_S "dont-save" + +/* Set method for GObject properties */ +static void +purple_blist_node_set_property(GObject *obj, guint param_id, const GValue *value, + GParamSpec *pspec) +{ + PurpleBListNode *node = PURPLE_BLIST_NODE(obj); + + switch (param_id) { + case BLNODE_PROP_DONT_SAVE: + purple_blist_node_set_dont_save(node, g_value_get_boolean(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* Get method for GObject properties */ +static void +purple_blist_node_get_property(GObject *obj, guint param_id, GValue *value, + GParamSpec *pspec) +{ + PurpleBListNode *node = PURPLE_BLIST_NODE(obj); + + switch (param_id) { + case BLNODE_PROP_DONT_SAVE: + g_value_set_boolean(value, purple_blist_node_get_dont_save(node)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* GObject initialization function */ +static void +purple_blist_node_init(GTypeInstance *instance, gpointer klass) +{ + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(instance); + + priv->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + (GDestroyNotify)purple_g_value_free); +} + +/* GObject finalize function */ +static void +purple_blist_node_finalize(GObject *object) +{ + PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(object); + + g_hash_table_destroy(priv->settings); + + parent_class->finalize(object); +} + +/* Class initializer function */ +static void +purple_blist_node_class_init(PurpleBListNodeClass *klass) +{ + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + + parent_class = g_type_class_peek_parent(klass); + + obj_class->finalize = purple_blist_node_finalize; + + /* Setup properties */ + obj_class->get_property = purple_blist_node_get_property; + obj_class->set_property = purple_blist_node_set_property; + + g_object_class_install_property(obj_class, BLNODE_PROP_DONT_SAVE, + g_param_spec_boolean(BLNODE_PROP_DONT_SAVE_S, _("Do not save"), + _("Whether node should not be saved with the buddy list."), + FALSE, G_PARAM_READWRITE) + ); + + g_type_class_add_private(klass, sizeof(PurpleBListNodePrivate)); +} + +GType +purple_blist_node_get_type(void) +{ + static GType type = 0; + + if(type == 0) { + static const GTypeInfo info = { + sizeof(PurpleBListNodeClass), + NULL, + NULL, + (GClassInitFunc)purple_blist_node_class_init, + NULL, + NULL, + sizeof(PurpleBListNode), + 0, + (GInstanceInitFunc)purple_blist_node_init, + NULL, + }; + + type = g_type_register_static(G_TYPE_OBJECT, "PurpleBListNode", + &info, G_TYPE_FLAG_ABSTRACT); + } + + return type; +} + +/**************************************************************************/ +/* Counting node API */ +/**************************************************************************/ + +int +purple_counting_node_get_total_size(PurpleCountingNode *counter) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_val_if_fail(priv != NULL, -1); + + return priv->totalsize; +} + +int +purple_counting_node_get_current_size(PurpleCountingNode *counter) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_val_if_fail(priv != NULL, -1); + + return priv->currentsize; +} + +int +purple_counting_node_get_online_count(PurpleCountingNode *counter) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_val_if_fail(priv != NULL, -1); + + return priv->onlinecount; +} + +void +purple_counting_node_change_total_size(PurpleCountingNode *counter, int delta) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_if_fail(priv != NULL); + + priv->totalsize += delta; +} + +void +purple_counting_node_change_current_size(PurpleCountingNode *counter, int delta) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_if_fail(priv != NULL); + + priv->currentsize += delta; +} + +void +purple_counting_node_change_online_count(PurpleCountingNode *counter, int delta) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_if_fail(priv != NULL); + + priv->onlinecount += delta; +} + +void +purple_counting_node_set_total_size(PurpleCountingNode *counter, int totalsize) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_if_fail(priv != NULL); + + priv->totalsize = totalsize; +} + +void +purple_counting_node_set_current_size(PurpleCountingNode *counter, int currentsize) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_if_fail(priv != NULL); + + priv->currentsize = currentsize; +} + +void +purple_counting_node_set_online_count(PurpleCountingNode *counter, int onlinecount) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); + + g_return_if_fail(priv != NULL); + + priv->onlinecount = onlinecount; +} + +/************************************************************************** + * GObject code for PurpleCountingNode + **************************************************************************/ + +/* GObject Property names */ +#define CNODE_PROP_TOTAL_SIZE_S "total-size" +#define CNODE_PROP_CURRENT_SIZE_S "current-size" +#define CNODE_PROP_ONLINE_COUNT_S "online-count" + +/* Set method for GObject properties */ +static void +purple_counting_node_set_property(GObject *obj, guint param_id, const GValue *value, + GParamSpec *pspec) +{ + PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj); + + switch (param_id) { + case CNODE_PROP_TOTAL_SIZE: + purple_counting_node_set_total_size(node, g_value_get_int(value)); + break; + case CNODE_PROP_CURRENT_SIZE: + purple_counting_node_set_current_size(node, g_value_get_int(value)); + break; + case CNODE_PROP_ONLINE_COUNT: + purple_counting_node_set_online_count(node, g_value_get_int(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* Get method for GObject properties */ +static void +purple_counting_node_get_property(GObject *obj, guint param_id, GValue *value, + GParamSpec *pspec) +{ + PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj); + + switch (param_id) { + case CNODE_PROP_TOTAL_SIZE: + g_value_set_int(value, purple_counting_node_get_total_size(node)); + break; + case CNODE_PROP_CURRENT_SIZE: + g_value_set_int(value, purple_counting_node_get_current_size(node)); + break; + case CNODE_PROP_ONLINE_COUNT: + g_value_set_int(value, purple_counting_node_get_online_count(node)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* GObject initialization function */ +static void +purple_counting_node_init(GTypeInstance *instance, gpointer klass) +{ + PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(instance); + + priv->totalsize = 0; + priv->currentsize = 0; + priv->onlinecount = 0; +} + +/* Class initializer function */ +static void +purple_counting_node_class_init(PurpleCountingNodeClass *klass) +{ + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + + /* Setup properties */ + obj_class->get_property = purple_counting_node_get_property; + obj_class->set_property = purple_counting_node_set_property; + + g_object_class_install_property(obj_class, CNODE_PROP_TOTAL_SIZE, + g_param_spec_int(CNODE_PROP_TOTAL_SIZE_S, _("Total size"), + _("The number of children under this node."), + G_MININT, G_MAXINT, 0, G_PARAM_READWRITE) + ); + + g_object_class_install_property(obj_class, CNODE_PROP_CURRENT_SIZE, + g_param_spec_int(CNODE_PROP_CURRENT_SIZE_S, _("Current size"), + _("The number of children with online accounts."), + G_MININT, G_MAXINT, 0, G_PARAM_READWRITE) + ); + + g_object_class_install_property(obj_class, CNODE_PROP_ONLINE_COUNT, + g_param_spec_int(CNODE_PROP_ONLINE_COUNT_S, _("Online count"), + _("The number of children that are online."), + G_MININT, G_MAXINT, 0, G_PARAM_READWRITE) + ); + + g_type_class_add_private(klass, sizeof(PurpleCountingNodePrivate)); +} + +GType +purple_counting_node_get_type(void) +{ + static GType type = 0; + + if(type == 0) { + static const GTypeInfo info = { + sizeof(PurpleCountingNodeClass), + NULL, + NULL, + (GClassInitFunc)purple_counting_node_class_init, + NULL, + NULL, + sizeof(PurpleCountingNode), + 0, + (GInstanceInitFunc)purple_counting_node_init, + NULL, + }; + + type = g_type_register_static(PURPLE_TYPE_BLIST_NODE, + "PurpleCountingNode", + &info, G_TYPE_FLAG_ABSTRACT); + } + + return type; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/blistnode.h Sun Jul 21 05:49:05 2013 +0530 @@ -0,0 +1,423 @@ +/** + * @file blistnode.h Buddy list node and Counting node API + * @ingroup core + */ +/* purple + * + * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ +#ifndef _PURPLE_BLIST_NODE_H_ +#define _PURPLE_BLIST_NODE_H_ + +#include <glib.h> +#include <glib-object.h> + +#define PURPLE_TYPE_BLIST_NODE (purple_blist_node_get_type()) +#define PURPLE_BLIST_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BLIST_NODE, PurpleBListNode)) +#define PURPLE_BLIST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BLIST_NODE, PurpleBListNodeClass)) +#define PURPLE_IS_BLIST_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BLIST_NODE)) +#define PURPLE_IS_BLIST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BLIST_NODE)) +#define PURPLE_BLIST_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BLIST_NODE, PurpleBListNodeClass)) + +/** @copydoc _PurpleBListNode */ +typedef struct _PurpleBListNode PurpleBListNode; +/** @copydoc _PurpleBListNodeClass */ +typedef struct _PurpleBListNodeClass PurpleBListNodeClass; + +#define PURPLE_TYPE_COUNTING_NODE (purple_counting_node_get_type()) +#define PURPLE_COUNTING_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNode)) +#define PURPLE_COUNTING_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodeClass)) +#define PURPLE_IS_COUNTING_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_COUNTING_NODE)) +#define PURPLE_IS_COUNTING_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_COUNTING_NODE)) +#define PURPLE_COUNTING_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodeClass)) + +/** @copydoc _PurpleCountingNode */ +typedef struct _PurpleCountingNode PurpleCountingNode; +/** @copydoc _PurpleCountingNodeClass */ +typedef struct _PurpleCountingNodeClass PurpleCountingNodeClass; + +/**************************************************************************/ +/* Data Structures */ +/**************************************************************************/ + +/** + * A Buddy list node. This can represent a group, a buddy, or anything else. + * This is a base class for PurpleBuddy, PurpleContact, PurpleGroup, and for + * anything else that wants to put itself in the buddy list. */ +struct _PurpleBListNode { + /*< private >*/ + GObject gparent; + + /** The UI data associated with this node. This is a convenience + * field provided to the UIs -- it is not used by the libpurple core. + */ + gpointer ui_data; + + PurpleBListNode *prev; /**< The sibling before this buddy. */ + PurpleBListNode *next; /**< The sibling after this buddy. */ + PurpleBListNode *parent; /**< The parent of this node */ + PurpleBListNode *child; /**< The child of this node */ +}; + +/** The base class for all #PurpleBListNode's. */ +struct _PurpleBListNodeClass { + /*< private >*/ + GObjectClass gparent_class; + + void (*_purple_reserved1)(void); + void (*_purple_reserved2)(void); + void (*_purple_reserved3)(void); + void (*_purple_reserved4)(void); +}; + +/** + * A node that keeps count of the number of children that it has. It tracks the + * total number of children, the number of children corresponding to online + * accounts, and the number of online children. + * + * The two types of counting nodes are: + * 1. Contact: Keeps track of the number of buddies under it. + * 2. Group: Keeps track of the number of chats and contacts under it. + * + * @see PurpleContact + * @see PurpleGroup + */ +struct _PurpleCountingNode { + /** The blist node that this counting node inherits from */ + PurpleBListNode node; +}; + +/** The base class for all #PurpleCountingNode's. */ +struct _PurpleCountingNodeClass { + /*< private >*/ + PurpleBListNodeClass node_class; + + void (*_purple_reserved1)(void); + void (*_purple_reserved2)(void); + void (*_purple_reserved3)(void); + void (*_purple_reserved4)(void); +}; + +G_BEGIN_DECLS + +/**************************************************************************/ +/** @name Buddy list node API */ +/**************************************************************************/ +/*@{*/ + +/** + * Returns the GType for the PurpleBListNode object. + */ +GType purple_blist_node_get_type(void); + +/** + * Returns the next node of a given node. This function is to be used to iterate + * over the tree returned by purple_blist_get_buddy_list. + * + * @param node A node. + * @param offline Whether to include nodes for offline accounts + * @return The next node + * @see purple_blist_node_get_parent + * @see purple_blist_node_get_first_child + * @see purple_blist_node_get_sibling_next + * @see purple_blist_node_get_sibling_prev + */ +PurpleBListNode *purple_blist_node_next(PurpleBListNode *node, gboolean offline); + +/** + * Returns the parent node of a given node. + * + * @param node A node. + * @return The parent node. + * + * @see purple_blist_node_get_first_child + * @see purple_blist_node_get_sibling_next + * @see purple_blist_node_get_sibling_prev + * @see purple_blist_node_next + */ +PurpleBListNode *purple_blist_node_get_parent(PurpleBListNode *node); + +/** + * Returns the the first child node of a given node. + * + * @param node A node. + * @return The child node. + * + * @see purple_blist_node_get_parent + * @see purple_blist_node_get_sibling_next + * @see purple_blist_node_get_sibling_prev + * @see purple_blist_node_next + */ +PurpleBListNode *purple_blist_node_get_first_child(PurpleBListNode *node); + +/** + * Returns the sibling node of a given node. + * + * @param node A node. + * @return The sibling node. + * + * @see purple_blist_node_get_parent + * @see purple_blist_node_get_first_child + * @see purple_blist_node_get_sibling_prev + * @see purple_blist_node_next + */ +PurpleBListNode *purple_blist_node_get_sibling_next(PurpleBListNode *node); + +/** + * Returns the previous sibling node of a given node. + * + * @param node A node. + * @return The sibling node. + * + * @see purple_blist_node_get_parent + * @see purple_blist_node_get_first_child + * @see purple_blist_node_get_sibling_next + * @see purple_blist_node_next + */ +PurpleBListNode *purple_blist_node_get_sibling_prev(PurpleBListNode *node); + +/** + * Returns the UI data of a given node. + * + * @param node The node. + * @return The UI data. + */ +gpointer purple_blist_node_get_ui_data(const PurpleBListNode *node); + +/** + * Sets the UI data of a given node. + * + * @param node The node. + * @param ui_data The UI data. + */ +void purple_blist_node_set_ui_data(PurpleBListNode *node, gpointer ui_data); + +/** + * Returns a node's settings + * + * @param node The node to from which to get settings + * + * @return The hash table with the node's settings + */ +GHashTable *purple_blist_node_get_settings(PurpleBListNode *node); + +/** + * Checks whether a named setting exists for a node in the buddy list + * + * @param node The node to check from which to check settings + * @param key The identifier of the data + * + * @return TRUE if a value exists, or FALSE if there is no setting + */ +gboolean purple_blist_node_has_setting(PurpleBListNode *node, const char *key); + +/** + * Associates a boolean with a node in the buddy list + * + * @param node The node to associate the data with + * @param key The identifier for the data + * @param value The value to set + */ +void purple_blist_node_set_bool(PurpleBListNode *node, const char *key, gboolean value); + +/** + * Retrieves a named boolean setting from a node in the buddy list + * + * @param node The node to retrieve the data from + * @param key The identifier of the data + * + * @return The value, or FALSE if there is no setting + */ +gboolean purple_blist_node_get_bool(PurpleBListNode *node, const char *key); + +/** + * Associates an integer with a node in the buddy list + * + * @param node The node to associate the data with + * @param key The identifier for the data + * @param value The value to set + */ +void purple_blist_node_set_int(PurpleBListNode *node, const char *key, int value); + +/** + * Retrieves a named integer setting from a node in the buddy list + * + * @param node The node to retrieve the data from + * @param key The identifier of the data + * + * @return The value, or 0 if there is no setting + */ +int purple_blist_node_get_int(PurpleBListNode *node, const char *key); + +/** + * Associates a string with a node in the buddy list + * + * @param node The node to associate the data with + * @param key The identifier for the data + * @param value The value to set + */ +void purple_blist_node_set_string(PurpleBListNode *node, const char *key, + const char *value); + +/** + * Retrieves a named string setting from a node in the buddy list + * + * @param node The node to retrieve the data from + * @param key The identifier of the data + * + * @return The value, or NULL if there is no setting + */ +const char *purple_blist_node_get_string(PurpleBListNode *node, const char *key); + +/** + * Removes a named setting from a blist node + * + * @param node The node from which to remove the setting + * @param key The name of the setting + */ +void purple_blist_node_remove_setting(PurpleBListNode *node, const char *key); + +/** + * Sets whether the node should be saved with the buddy list or not + * + * @param node The node + * @param dont_save TRUE if the node should NOT be saved, FALSE if node should + * be saved + */ +void purple_blist_node_set_dont_save(PurpleBListNode *node, gboolean dont_save); + +/** + * Gets whether the node should be saved with the buddy list or not + * + * @param node The node + * + * @return TRUE if the node should NOT be saved, FALSE if node should be saved + */ +gboolean purple_blist_node_get_dont_save(PurpleBListNode *node); + +/*@}*/ + +/** + * Retrieves the extended menu items for a buddy list node. + * @param n The blist node for which to obtain the extended menu items. + * @return A list of PurpleMenuAction items, as harvested by the + * blist-node-extended-menu signal. + */ +GList *purple_blist_node_get_extended_menu(PurpleBListNode *n); + +/*@}*/ + +/**************************************************************************/ +/** @name Counting node API */ +/**************************************************************************/ +/*@{*/ + +/** + * Returns the GType for the PurpleCountingNode object. + */ +GType purple_counting_node_get_type(void); + +/** + * Returns the total number of children of the counting node. + * + * @param counter The node + * + * @return The total number of children of the node + */ +int purple_counting_node_get_total_size(PurpleCountingNode *counter); + +/** + * Returns the number of children of the counting node corresponding to online + * accounts. + * + * @param counter The node + * + * @return The number of children with online accounts + */ +int purple_counting_node_get_current_size(PurpleCountingNode *counter); + +/** + * Returns the number of children of the counting node that are online. + * + * @param counter The node + * + * @return The total number of online children + */ +int purple_counting_node_get_online_count(PurpleCountingNode *counter); + +/** + * Changes the total number of children of the counting node. The provided + * delta value is added to the count, or if it's negative, the count is + * decreased. + * + * @param counter The node + * @param delta The value to change the total size by + */ +void purple_counting_node_change_total_size(PurpleCountingNode *counter, int delta); + +/** + * Changes the number of children of the counting node corresponding to online + * accounts. The provided delta value is added to the count, or if it's + * negative, the count is decreased. + * + * @param counter The node + * @param delta The value to change the current size by + */ +void purple_counting_node_change_current_size(PurpleCountingNode *counter, int delta); + +/** + * Changes the number of children of the counting node that are online. The + * provided delta value is added to the count, or if it's negative, the count is + * decreased. + * + * @param counter The node + * @param delta The value to change the online count by + */ +void purple_counting_node_change_online_count(PurpleCountingNode *counter, int delta); + +/** + * Sets the total number of children of the counting node. + * + * @param counter The node + * @param totalsize The total number of children of the node + */ +void purple_counting_node_set_total_size(PurpleCountingNode *counter, int totalsize); + +/** + * Sets the number of children of the counting node corresponding to online + * accounts. + * + * @param counter The node + * @param currentsize The number of children with online accounts + */ +void purple_counting_node_set_current_size(PurpleCountingNode *counter, int currentsize); + +/** + * Sets the number of children of the counting node that are online. + * + * @param counter The node + * @param onlinecount The total number of online children + */ +void purple_counting_node_set_online_count(PurpleCountingNode *counter, int onlinecount); + +/*@}*/ + +G_END_DECLS + +#endif /* _PURPLE_BLIST_NODE_H_ */
--- a/libpurple/blistnodes.c Sun Jul 21 02:52:23 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,662 +0,0 @@ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - * - */ -#include "blistnodetypes.h" -#include "internal.h" - -#define PURPLE_BLIST_NODE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_BLIST_NODE, PurpleBListNodePrivate)) - -/** @copydoc _PurpleBListNodePrivate */ -typedef struct _PurpleBListNodePrivate PurpleBListNodePrivate; - -#define PURPLE_COUNTING_NODE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodePrivate)) - -/** @copydoc _PurpleCountingNodePrivate */ -typedef struct _PurpleCountingNodePrivate PurpleCountingNodePrivate; - -/** Private data of a buddy list node */ -struct _PurpleBListNodePrivate { - GHashTable *settings; /**< per-node settings */ - gboolean dont_save; /**< node should not be saved with the buddy list */ -}; - -/* BList node property enums */ -enum -{ - BLNODE_PROP_0, - BLNODE_PROP_DONT_SAVE, - BLNODE_PROP_LAST -}; - -/** Private data of a counting node */ -struct _PurpleCountingNodePrivate { - int totalsize; /**< The number of children under this node */ - int currentsize; /**< The number of children under this node - corresponding to online accounts */ - int onlinecount; /**< The number of children under this contact who are - currently online */ -}; - -/* Counting node property enums */ -enum -{ - CNODE_PROP_0, - CNODE_PROP_TOTAL_SIZE, - CNODE_PROP_CURRENT_SIZE, - CNODE_PROP_ONLINE_COUNT, - CNODE_PROP_LAST -}; - -static GObjectClass *parent_class; - -/**************************************************************************/ -/* Buddy list node API */ -/**************************************************************************/ - -static PurpleBListNode *get_next_node(PurpleBListNode *node, gboolean godeep) -{ - if (node == NULL) - return NULL; - - if (godeep && node->child) - return node->child; - - if (node->next) - return node->next; - - return get_next_node(node->parent, FALSE); -} - -PurpleBListNode *purple_blist_node_next(PurpleBListNode *node, gboolean offline) -{ - PurpleBListNode *ret = node; - - if (offline) - return get_next_node(ret, TRUE); - do - { - ret = get_next_node(ret, TRUE); - } while (ret && PURPLE_IS_BUDDY(ret) && - !purple_account_is_connected(purple_buddy_get_account((PurpleBuddy *)ret))); - - return ret; -} - -PurpleBListNode *purple_blist_node_get_parent(PurpleBListNode *node) -{ - return node ? node->parent : NULL; -} - -PurpleBListNode *purple_blist_node_get_first_child(PurpleBListNode *node) -{ - return node ? node->child : NULL; -} - -PurpleBListNode *purple_blist_node_get_sibling_next(PurpleBListNode *node) -{ - return node? node->next : NULL; -} - -PurpleBListNode *purple_blist_node_get_sibling_prev(PurpleBListNode *node) -{ - return node? node->prev : NULL; -} - -void * -purple_blist_node_get_ui_data(const PurpleBListNode *node) -{ - g_return_val_if_fail(node, NULL); - - return node->ui_data; -} - -void -purple_blist_node_set_ui_data(PurpleBListNode *node, void *ui_data) { - g_return_if_fail(node); - - node->ui_data = ui_data; -} - -void purple_blist_node_remove_setting(PurpleBListNode *node, const char *key) -{ - PurpleBListUiOps *ops; - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_if_fail(priv != NULL); - g_return_if_fail(priv->settings != NULL); - g_return_if_fail(key != NULL); - - g_hash_table_remove(priv->settings, key); - - ops = purple_blist_get_ui_ops(); - if (ops && ops->save_node) - ops->save_node(node); -} - -void -purple_blist_node_set_dont_save(PurpleBListNode *node, gboolean dont_save) -{ - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_if_fail(priv != NULL); - - priv->dont_save = dont_save; -} - -gboolean -purple_blist_node_get_dont_save(PurpleBListNode *node) -{ - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_val_if_fail(priv != NULL, 0); - - return priv->dont_save; -} - -GHashTable * -purple_blist_node_get_settings(PurpleBListNode *node) -{ - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_val_if_fail(priv != NULL, NULL); - - return priv->settings; -} - -gboolean -purple_blist_node_has_setting(PurpleBListNode* node, const char *key) -{ - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_val_if_fail(priv != NULL, FALSE); - g_return_val_if_fail(priv->settings != NULL, FALSE); - g_return_val_if_fail(key != NULL, FALSE); - - /* Boxed type, so it won't ever be NULL, so no need for _extended */ - return (g_hash_table_lookup(priv->settings, key) != NULL); -} - -void -purple_blist_node_set_bool(PurpleBListNode* node, const char *key, gboolean data) -{ - GValue *value; - PurpleBListUiOps *ops; - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_if_fail(priv != NULL); - g_return_if_fail(priv->settings != NULL); - g_return_if_fail(key != NULL); - - value = purple_g_value_new(G_TYPE_BOOLEAN); - g_value_set_boolean(value, data); - - g_hash_table_replace(priv->settings, g_strdup(key), value); - - ops = purple_blist_get_ui_ops(); - if (ops && ops->save_node) - ops->save_node(node); -} - -gboolean -purple_blist_node_get_bool(PurpleBListNode* node, const char *key) -{ - GValue *value; - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_val_if_fail(priv != NULL, FALSE); - g_return_val_if_fail(priv->settings != NULL, FALSE); - g_return_val_if_fail(key != NULL, FALSE); - - value = g_hash_table_lookup(priv->settings, key); - - if (value == NULL) - return FALSE; - - g_return_val_if_fail(G_VALUE_HOLDS_BOOLEAN(value), FALSE); - - return g_value_get_boolean(value); -} - -void -purple_blist_node_set_int(PurpleBListNode* node, const char *key, int data) -{ - GValue *value; - PurpleBListUiOps *ops; - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_if_fail(priv != NULL); - g_return_if_fail(priv->settings != NULL); - g_return_if_fail(key != NULL); - - value = purple_g_value_new(G_TYPE_INT); - g_value_set_int(value, data); - - g_hash_table_replace(priv->settings, g_strdup(key), value); - - ops = purple_blist_get_ui_ops(); - if (ops && ops->save_node) - ops->save_node(node); -} - -int -purple_blist_node_get_int(PurpleBListNode* node, const char *key) -{ - GValue *value; - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_val_if_fail(priv != NULL, 0); - g_return_val_if_fail(priv->settings != NULL, 0); - g_return_val_if_fail(key != NULL, 0); - - value = g_hash_table_lookup(priv->settings, key); - - if (value == NULL) - return 0; - - g_return_val_if_fail(G_VALUE_HOLDS_INT(value), 0); - - return g_value_get_int(value); -} - -void -purple_blist_node_set_string(PurpleBListNode* node, const char *key, const char *data) -{ - GValue *value; - PurpleBListUiOps *ops; - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_if_fail(priv != NULL); - g_return_if_fail(priv->settings != NULL); - g_return_if_fail(key != NULL); - - value = purple_g_value_new(G_TYPE_STRING); - g_value_set_string(value, data); - - g_hash_table_replace(priv->settings, g_strdup(key), value); - - ops = purple_blist_get_ui_ops(); - if (ops && ops->save_node) - ops->save_node(node); -} - -const char * -purple_blist_node_get_string(PurpleBListNode* node, const char *key) -{ - GValue *value; - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node); - - g_return_val_if_fail(priv != NULL, NULL); - g_return_val_if_fail(priv->settings != NULL, NULL); - g_return_val_if_fail(key != NULL, NULL); - - value = g_hash_table_lookup(priv->settings, key); - - if (value == NULL) - return NULL; - - g_return_val_if_fail(G_VALUE_HOLDS_STRING(value), NULL); - - return g_value_get_string(value); -} - -GList * -purple_blist_node_get_extended_menu(PurpleBListNode *n) -{ - GList *menu = NULL; - - g_return_val_if_fail(n != NULL, NULL); - - purple_signal_emit(purple_blist_get_handle(), "blist-node-extended-menu", - n, &menu); - return menu; -} - -/************************************************************************** - * GObject code for PurpleBListNode - **************************************************************************/ - -/* GObject Property names */ -#define BLNODE_PROP_DONT_SAVE_S "dont-save" - -/* Set method for GObject properties */ -static void -purple_blist_node_set_property(GObject *obj, guint param_id, const GValue *value, - GParamSpec *pspec) -{ - PurpleBListNode *node = PURPLE_BLIST_NODE(obj); - - switch (param_id) { - case BLNODE_PROP_DONT_SAVE: - purple_blist_node_set_dont_save(node, g_value_get_boolean(value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* Get method for GObject properties */ -static void -purple_blist_node_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurpleBListNode *node = PURPLE_BLIST_NODE(obj); - - switch (param_id) { - case BLNODE_PROP_DONT_SAVE: - g_value_set_boolean(value, purple_blist_node_get_dont_save(node)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* GObject initialization function */ -static void -purple_blist_node_init(GTypeInstance *instance, gpointer klass) -{ - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(instance); - - priv->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, - (GDestroyNotify)purple_g_value_free); -} - -/* GObject finalize function */ -static void -purple_blist_node_finalize(GObject *object) -{ - PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(object); - - g_hash_table_destroy(priv->settings); - - parent_class->finalize(object); -} - -/* Class initializer function */ -static void -purple_blist_node_class_init(PurpleBListNodeClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - obj_class->finalize = purple_blist_node_finalize; - - /* Setup properties */ - obj_class->get_property = purple_blist_node_get_property; - obj_class->set_property = purple_blist_node_set_property; - - g_object_class_install_property(obj_class, BLNODE_PROP_DONT_SAVE, - g_param_spec_boolean(BLNODE_PROP_DONT_SAVE_S, _("Do not save"), - _("Whether node should not be saved with the buddy list."), - FALSE, G_PARAM_READWRITE) - ); - - g_type_class_add_private(klass, sizeof(PurpleBListNodePrivate)); -} - -GType -purple_blist_node_get_type(void) -{ - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleBListNodeClass), - NULL, - NULL, - (GClassInitFunc)purple_blist_node_class_init, - NULL, - NULL, - sizeof(PurpleBListNode), - 0, - (GInstanceInitFunc)purple_blist_node_init, - NULL, - }; - - type = g_type_register_static(G_TYPE_OBJECT, "PurpleBListNode", - &info, G_TYPE_FLAG_ABSTRACT); - } - - return type; -} - -/**************************************************************************/ -/* Counting node API */ -/**************************************************************************/ - -int -purple_counting_node_get_total_size(PurpleCountingNode *counter) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_val_if_fail(priv != NULL, -1); - - return priv->totalsize; -} - -int -purple_counting_node_get_current_size(PurpleCountingNode *counter) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_val_if_fail(priv != NULL, -1); - - return priv->currentsize; -} - -int -purple_counting_node_get_online_count(PurpleCountingNode *counter) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_val_if_fail(priv != NULL, -1); - - return priv->onlinecount; -} - -void -purple_counting_node_change_total_size(PurpleCountingNode *counter, int delta) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_if_fail(priv != NULL); - - priv->totalsize += delta; -} - -void -purple_counting_node_change_current_size(PurpleCountingNode *counter, int delta) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_if_fail(priv != NULL); - - priv->currentsize += delta; -} - -void -purple_counting_node_change_online_count(PurpleCountingNode *counter, int delta) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_if_fail(priv != NULL); - - priv->onlinecount += delta; -} - -void -purple_counting_node_set_total_size(PurpleCountingNode *counter, int totalsize) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_if_fail(priv != NULL); - - priv->totalsize = totalsize; -} - -void -purple_counting_node_set_current_size(PurpleCountingNode *counter, int currentsize) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_if_fail(priv != NULL); - - priv->currentsize = currentsize; -} - -void -purple_counting_node_set_online_count(PurpleCountingNode *counter, int onlinecount) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter); - - g_return_if_fail(priv != NULL); - - priv->onlinecount = onlinecount; -} - -/************************************************************************** - * GObject code for PurpleCountingNode - **************************************************************************/ - -/* GObject Property names */ -#define CNODE_PROP_TOTAL_SIZE_S "total-size" -#define CNODE_PROP_CURRENT_SIZE_S "current-size" -#define CNODE_PROP_ONLINE_COUNT_S "online-count" - -/* Set method for GObject properties */ -static void -purple_counting_node_set_property(GObject *obj, guint param_id, const GValue *value, - GParamSpec *pspec) -{ - PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj); - - switch (param_id) { - case CNODE_PROP_TOTAL_SIZE: - purple_counting_node_set_total_size(node, g_value_get_int(value)); - break; - case CNODE_PROP_CURRENT_SIZE: - purple_counting_node_set_current_size(node, g_value_get_int(value)); - break; - case CNODE_PROP_ONLINE_COUNT: - purple_counting_node_set_online_count(node, g_value_get_int(value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* Get method for GObject properties */ -static void -purple_counting_node_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj); - - switch (param_id) { - case CNODE_PROP_TOTAL_SIZE: - g_value_set_int(value, purple_counting_node_get_total_size(node)); - break; - case CNODE_PROP_CURRENT_SIZE: - g_value_set_int(value, purple_counting_node_get_current_size(node)); - break; - case CNODE_PROP_ONLINE_COUNT: - g_value_set_int(value, purple_counting_node_get_online_count(node)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* GObject initialization function */ -static void -purple_counting_node_init(GTypeInstance *instance, gpointer klass) -{ - PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(instance); - - priv->totalsize = 0; - priv->currentsize = 0; - priv->onlinecount = 0; -} - -/* Class initializer function */ -static void -purple_counting_node_class_init(PurpleCountingNodeClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - - /* Setup properties */ - obj_class->get_property = purple_counting_node_get_property; - obj_class->set_property = purple_counting_node_set_property; - - g_object_class_install_property(obj_class, CNODE_PROP_TOTAL_SIZE, - g_param_spec_int(CNODE_PROP_TOTAL_SIZE_S, _("Total size"), - _("The number of children under this node."), - G_MININT, G_MAXINT, 0, G_PARAM_READWRITE) - ); - - g_object_class_install_property(obj_class, CNODE_PROP_CURRENT_SIZE, - g_param_spec_int(CNODE_PROP_CURRENT_SIZE_S, _("Current size"), - _("The number of children with online accounts."), - G_MININT, G_MAXINT, 0, G_PARAM_READWRITE) - ); - - g_object_class_install_property(obj_class, CNODE_PROP_ONLINE_COUNT, - g_param_spec_int(CNODE_PROP_ONLINE_COUNT_S, _("Online count"), - _("The number of children that are online."), - G_MININT, G_MAXINT, 0, G_PARAM_READWRITE) - ); - - g_type_class_add_private(klass, sizeof(PurpleCountingNodePrivate)); -} - -GType -purple_counting_node_get_type(void) -{ - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleCountingNodeClass), - NULL, - NULL, - (GClassInitFunc)purple_counting_node_class_init, - NULL, - NULL, - sizeof(PurpleCountingNode), - 0, - (GInstanceInitFunc)purple_counting_node_init, - NULL, - }; - - type = g_type_register_static(PURPLE_TYPE_BLIST_NODE, - "PurpleCountingNode", - &info, G_TYPE_FLAG_ABSTRACT); - } - - return type; -}
--- a/libpurple/blistnodes.h Sun Jul 21 02:52:23 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,423 +0,0 @@ -/** - * @file blistnodes.h Buddy list node and Counting node API - * @ingroup core - */ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ -#ifndef _PURPLE_BLIST_NODE_H_ -#define _PURPLE_BLIST_NODE_H_ - -#include <glib.h> -#include <glib-object.h> - -#define PURPLE_TYPE_BLIST_NODE (purple_blist_node_get_type()) -#define PURPLE_BLIST_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BLIST_NODE, PurpleBListNode)) -#define PURPLE_BLIST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BLIST_NODE, PurpleBListNodeClass)) -#define PURPLE_IS_BLIST_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BLIST_NODE)) -#define PURPLE_IS_BLIST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BLIST_NODE)) -#define PURPLE_BLIST_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BLIST_NODE, PurpleBListNodeClass)) - -/** @copydoc _PurpleBListNode */ -typedef struct _PurpleBListNode PurpleBListNode; -/** @copydoc _PurpleBListNodeClass */ -typedef struct _PurpleBListNodeClass PurpleBListNodeClass; - -#define PURPLE_TYPE_COUNTING_NODE (purple_counting_node_get_type()) -#define PURPLE_COUNTING_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNode)) -#define PURPLE_COUNTING_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodeClass)) -#define PURPLE_IS_COUNTING_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_COUNTING_NODE)) -#define PURPLE_IS_COUNTING_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_COUNTING_NODE)) -#define PURPLE_COUNTING_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodeClass)) - -/** @copydoc _PurpleCountingNode */ -typedef struct _PurpleCountingNode PurpleCountingNode; -/** @copydoc _PurpleCountingNodeClass */ -typedef struct _PurpleCountingNodeClass PurpleCountingNodeClass; - -/**************************************************************************/ -/* Data Structures */ -/**************************************************************************/ - -/** - * A Buddy list node. This can represent a group, a buddy, or anything else. - * This is a base class for PurpleBuddy, PurpleContact, PurpleGroup, and for - * anything else that wants to put itself in the buddy list. */ -struct _PurpleBListNode { - /*< private >*/ - GObject gparent; - - /** The UI data associated with this node. This is a convenience - * field provided to the UIs -- it is not used by the libpurple core. - */ - gpointer ui_data; - - PurpleBListNode *prev; /**< The sibling before this buddy. */ - PurpleBListNode *next; /**< The sibling after this buddy. */ - PurpleBListNode *parent; /**< The parent of this node */ - PurpleBListNode *child; /**< The child of this node */ -}; - -/** The base class for all #PurpleBListNode's. */ -struct _PurpleBListNodeClass { - /*< private >*/ - GObjectClass gparent_class; - - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -/** - * A node that keeps count of the number of children that it has. It tracks the - * total number of children, the number of children corresponding to online - * accounts, and the number of online children. - * - * The two types of counting nodes are: - * 1. Contact: Keeps track of the number of buddies under it. - * 2. Group: Keeps track of the number of chats and contacts under it. - * - * @see PurpleContact - * @see PurpleGroup - */ -struct _PurpleCountingNode { - /** The blist node that this counting node inherits from */ - PurpleBListNode node; -}; - -/** The base class for all #PurpleCountingNode's. */ -struct _PurpleCountingNodeClass { - /*< private >*/ - PurpleBListNodeClass node_class; - - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -/**************************************************************************/ -/** @name Buddy list node API */ -/**************************************************************************/ -/*@{*/ - -/** - * Returns the GType for the PurpleBListNode object. - */ -GType purple_blist_node_get_type(void); - -/** - * Returns the next node of a given node. This function is to be used to iterate - * over the tree returned by purple_blist_get_buddy_list. - * - * @param node A node. - * @param offline Whether to include nodes for offline accounts - * @return The next node - * @see purple_blist_node_get_parent - * @see purple_blist_node_get_first_child - * @see purple_blist_node_get_sibling_next - * @see purple_blist_node_get_sibling_prev - */ -PurpleBListNode *purple_blist_node_next(PurpleBListNode *node, gboolean offline); - -/** - * Returns the parent node of a given node. - * - * @param node A node. - * @return The parent node. - * - * @see purple_blist_node_get_first_child - * @see purple_blist_node_get_sibling_next - * @see purple_blist_node_get_sibling_prev - * @see purple_blist_node_next - */ -PurpleBListNode *purple_blist_node_get_parent(PurpleBListNode *node); - -/** - * Returns the the first child node of a given node. - * - * @param node A node. - * @return The child node. - * - * @see purple_blist_node_get_parent - * @see purple_blist_node_get_sibling_next - * @see purple_blist_node_get_sibling_prev - * @see purple_blist_node_next - */ -PurpleBListNode *purple_blist_node_get_first_child(PurpleBListNode *node); - -/** - * Returns the sibling node of a given node. - * - * @param node A node. - * @return The sibling node. - * - * @see purple_blist_node_get_parent - * @see purple_blist_node_get_first_child - * @see purple_blist_node_get_sibling_prev - * @see purple_blist_node_next - */ -PurpleBListNode *purple_blist_node_get_sibling_next(PurpleBListNode *node); - -/** - * Returns the previous sibling node of a given node. - * - * @param node A node. - * @return The sibling node. - * - * @see purple_blist_node_get_parent - * @see purple_blist_node_get_first_child - * @see purple_blist_node_get_sibling_next - * @see purple_blist_node_next - */ -PurpleBListNode *purple_blist_node_get_sibling_prev(PurpleBListNode *node); - -/** - * Returns the UI data of a given node. - * - * @param node The node. - * @return The UI data. - */ -gpointer purple_blist_node_get_ui_data(const PurpleBListNode *node); - -/** - * Sets the UI data of a given node. - * - * @param node The node. - * @param ui_data The UI data. - */ -void purple_blist_node_set_ui_data(PurpleBListNode *node, gpointer ui_data); - -/** - * Returns a node's settings - * - * @param node The node to from which to get settings - * - * @return The hash table with the node's settings - */ -GHashTable *purple_blist_node_get_settings(PurpleBListNode *node); - -/** - * Checks whether a named setting exists for a node in the buddy list - * - * @param node The node to check from which to check settings - * @param key The identifier of the data - * - * @return TRUE if a value exists, or FALSE if there is no setting - */ -gboolean purple_blist_node_has_setting(PurpleBListNode *node, const char *key); - -/** - * Associates a boolean with a node in the buddy list - * - * @param node The node to associate the data with - * @param key The identifier for the data - * @param value The value to set - */ -void purple_blist_node_set_bool(PurpleBListNode *node, const char *key, gboolean value); - -/** - * Retrieves a named boolean setting from a node in the buddy list - * - * @param node The node to retrieve the data from - * @param key The identifier of the data - * - * @return The value, or FALSE if there is no setting - */ -gboolean purple_blist_node_get_bool(PurpleBListNode *node, const char *key); - -/** - * Associates an integer with a node in the buddy list - * - * @param node The node to associate the data with - * @param key The identifier for the data - * @param value The value to set - */ -void purple_blist_node_set_int(PurpleBListNode *node, const char *key, int value); - -/** - * Retrieves a named integer setting from a node in the buddy list - * - * @param node The node to retrieve the data from - * @param key The identifier of the data - * - * @return The value, or 0 if there is no setting - */ -int purple_blist_node_get_int(PurpleBListNode *node, const char *key); - -/** - * Associates a string with a node in the buddy list - * - * @param node The node to associate the data with - * @param key The identifier for the data - * @param value The value to set - */ -void purple_blist_node_set_string(PurpleBListNode *node, const char *key, - const char *value); - -/** - * Retrieves a named string setting from a node in the buddy list - * - * @param node The node to retrieve the data from - * @param key The identifier of the data - * - * @return The value, or NULL if there is no setting - */ -const char *purple_blist_node_get_string(PurpleBListNode *node, const char *key); - -/** - * Removes a named setting from a blist node - * - * @param node The node from which to remove the setting - * @param key The name of the setting - */ -void purple_blist_node_remove_setting(PurpleBListNode *node, const char *key); - -/** - * Sets whether the node should be saved with the buddy list or not - * - * @param node The node - * @param dont_save TRUE if the node should NOT be saved, FALSE if node should - * be saved - */ -void purple_blist_node_set_dont_save(PurpleBListNode *node, gboolean dont_save); - -/** - * Gets whether the node should be saved with the buddy list or not - * - * @param node The node - * - * @return TRUE if the node should NOT be saved, FALSE if node should be saved - */ -gboolean purple_blist_node_get_dont_save(PurpleBListNode *node); - -/*@}*/ - -/** - * Retrieves the extended menu items for a buddy list node. - * @param n The blist node for which to obtain the extended menu items. - * @return A list of PurpleMenuAction items, as harvested by the - * blist-node-extended-menu signal. - */ -GList *purple_blist_node_get_extended_menu(PurpleBListNode *n); - -/*@}*/ - -/**************************************************************************/ -/** @name Counting node API */ -/**************************************************************************/ -/*@{*/ - -/** - * Returns the GType for the PurpleCountingNode object. - */ -GType purple_counting_node_get_type(void); - -/** - * Returns the total number of children of the counting node. - * - * @param counter The node - * - * @return The total number of children of the node - */ -int purple_counting_node_get_total_size(PurpleCountingNode *counter); - -/** - * Returns the number of children of the counting node corresponding to online - * accounts. - * - * @param counter The node - * - * @return The number of children with online accounts - */ -int purple_counting_node_get_current_size(PurpleCountingNode *counter); - -/** - * Returns the number of children of the counting node that are online. - * - * @param counter The node - * - * @return The total number of online children - */ -int purple_counting_node_get_online_count(PurpleCountingNode *counter); - -/** - * Changes the total number of children of the counting node. The provided - * delta value is added to the count, or if it's negative, the count is - * decreased. - * - * @param counter The node - * @param delta The value to change the total size by - */ -void purple_counting_node_change_total_size(PurpleCountingNode *counter, int delta); - -/** - * Changes the number of children of the counting node corresponding to online - * accounts. The provided delta value is added to the count, or if it's - * negative, the count is decreased. - * - * @param counter The node - * @param delta The value to change the current size by - */ -void purple_counting_node_change_current_size(PurpleCountingNode *counter, int delta); - -/** - * Changes the number of children of the counting node that are online. The - * provided delta value is added to the count, or if it's negative, the count is - * decreased. - * - * @param counter The node - * @param delta The value to change the online count by - */ -void purple_counting_node_change_online_count(PurpleCountingNode *counter, int delta); - -/** - * Sets the total number of children of the counting node. - * - * @param counter The node - * @param totalsize The total number of children of the node - */ -void purple_counting_node_set_total_size(PurpleCountingNode *counter, int totalsize); - -/** - * Sets the number of children of the counting node corresponding to online - * accounts. - * - * @param counter The node - * @param currentsize The number of children with online accounts - */ -void purple_counting_node_set_current_size(PurpleCountingNode *counter, int currentsize); - -/** - * Sets the number of children of the counting node that are online. - * - * @param counter The node - * @param onlinecount The total number of online children - */ -void purple_counting_node_set_online_count(PurpleCountingNode *counter, int onlinecount); - -/*@}*/ - -G_END_DECLS - -#endif /* _PURPLE_BLIST_NODE_H_ */
--- a/libpurple/blistnodetypes.h Sun Jul 21 02:52:23 2013 +0530 +++ b/libpurple/blistnodetypes.h Sun Jul 21 05:49:05 2013 +0530 @@ -25,7 +25,7 @@ #ifndef _PURPLE_BLISTNODE_TYPES_H_ #define _PURPLE_BLISTNODE_TYPES_H_ -#include "blistnodes.h" +#include "blistnode.h" #define PURPLE_TYPE_BUDDY (purple_buddy_get_type()) #define PURPLE_BUDDY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BUDDY, PurpleBuddy)) @@ -78,7 +78,7 @@ #include "account.h" #include "buddyicon.h" #include "media.h" -#include "presences.h" +#include "presence.h" #include "status.h" #define PURPLE_BUDDY_IS_ONLINE(b) \
--- a/libpurple/plugins/idle.c Sun Jul 21 02:52:23 2013 +0530 +++ b/libpurple/plugins/idle.c Sun Jul 21 05:49:05 2013 +0530 @@ -28,7 +28,7 @@ #include "debug.h" #include "notify.h" #include "plugin.h" -#include "presences.h" +#include "presence.h" #include "request.h" #include "server.h" #include "status.h"
--- a/libpurple/plugins/perl/common/module.h Sun Jul 21 02:52:23 2013 +0530 +++ b/libpurple/plugins/perl/common/module.h Sun Jul 21 05:49:05 2013 +0530 @@ -59,7 +59,7 @@ #include "pluginpref.h" #include "pounce.h" #include "prefs.h" -#include "presences.h" +#include "presence.h" #include "prpl.h" #include "proxy.h" #include "request.h"
--- a/libpurple/plugins/tcl/tcl_cmds.c Sun Jul 21 02:52:23 2013 +0530 +++ b/libpurple/plugins/tcl/tcl_cmds.c Sun Jul 21 05:49:05 2013 +0530 @@ -33,7 +33,7 @@ #include "savedstatuses.h" #include "debug.h" #include "prefs.h" -#include "presences.h" +#include "presence.h" #include "core.h" #include "tcl_purple.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/presence.c Sun Jul 21 05:49:05 2013 +0530 @@ -0,0 +1,998 @@ +/* purple + * + * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ +#include "internal.h" +#include "debug.h" +#include "dbus-maybe.h" +#include "presence.h" + +#define PURPLE_PRESENCE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_PRESENCE, PurplePresencePrivate)) + +/** @copydoc _PurplePresencePrivate */ +typedef struct _PurplePresencePrivate PurplePresencePrivate; + +#define PURPLE_ACCOUNT_PRESENCE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresencePrivate)) + +/** @copydoc _PurpleAccountPresencePrivate */ +typedef struct _PurpleAccountPresencePrivate PurpleAccountPresencePrivate; + +#define PURPLE_BUDDY_PRESENCE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresencePrivate)) + +/** @copydoc _PurpleBuddyPresencePrivate */ +typedef struct _PurpleBuddyPresencePrivate PurpleBuddyPresencePrivate; + +/** Private data for a presence */ +struct _PurplePresencePrivate +{ + gboolean idle; + time_t idle_time; + time_t login_time; + + GList *statuses; + GHashTable *status_table; + + PurpleStatus *active_status; +}; + +/* Presence property enums */ +enum +{ + PRES_PROP_0, + PRES_PROP_IDLE, + PRES_PROP_IDLE_TIME, + PRES_PROP_LOGIN_TIME, + PRES_PROP_STATUSES, + PRES_PROP_ACTIVE_STATUS, + PRES_PROP_LAST +}; + +/** Private data for an account presence */ +struct _PurpleAccountPresencePrivate +{ + PurpleAccount *account; +}; + +/* Account presence property enums */ +enum +{ + ACPRES_PROP_0, + ACPRES_PROP_ACCOUNT, + ACPRES_PROP_LAST +}; + +/** Private data for a buddy presence */ +struct _PurpleBuddyPresencePrivate +{ + PurpleBuddy *buddy; +}; + +/* Buddy presence property enums */ +enum +{ + BUDPRES_PROP_0, + BUDPRES_PROP_BUDDY, + BUDPRES_PROP_LAST +}; + +static GObjectClass *parent_class; +static PurplePresenceClass *presence_class; + +int *_purple_get_primitive_scores(void); + +/************************************************************************** +* PurplePresence API +**************************************************************************/ + +void +purple_presence_set_status_active(PurplePresence *presence, const char *status_id, + gboolean active) +{ + PurpleStatus *status; + + g_return_if_fail(presence != NULL); + g_return_if_fail(status_id != NULL); + + status = purple_presence_get_status(presence, status_id); + + g_return_if_fail(status != NULL); + /* TODO: Should we do the following? */ + /* g_return_if_fail(active == status->active); */ + + if (purple_status_is_exclusive(status)) + { + if (!active) + { + purple_debug_warning("status", + "Attempted to set a non-independent status " + "(%s) inactive. Only independent statuses " + "can be specifically marked inactive.", + status_id); + return; + } + } + + purple_status_set_active(status, active); +} + +void +purple_presence_switch_status(PurplePresence *presence, const char *status_id) +{ + purple_presence_set_status_active(presence, status_id, TRUE); +} + +void +purple_presence_set_idle(PurplePresence *presence, gboolean idle, time_t idle_time) +{ + gboolean old_idle; + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + PurplePresenceClass *klass = PURPLE_PRESENCE_GET_CLASS(presence); + + g_return_if_fail(priv != NULL); + + if (priv->idle == idle && priv->idle_time == idle_time) + return; + + old_idle = priv->idle; + priv->idle = idle; + priv->idle_time = (idle ? idle_time : 0); + + if (klass->update_idle) + klass->update_idle(presence, old_idle); +} + +void +purple_presence_set_login_time(PurplePresence *presence, time_t login_time) +{ + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + + g_return_if_fail(priv != NULL); + + if (priv->login_time == login_time) + return; + + priv->login_time = login_time; +} + +GList * +purple_presence_get_statuses(const PurplePresence *presence) +{ + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + + g_return_val_if_fail(priv != NULL, NULL); + + return priv->statuses; +} + +PurpleStatus * +purple_presence_get_status(const PurplePresence *presence, const char *status_id) +{ + PurpleStatus *status; + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + GList *l = NULL; + + g_return_val_if_fail(priv != NULL, NULL); + g_return_val_if_fail(status_id != NULL, NULL); + + /* What's the purpose of this hash table? */ + status = (PurpleStatus *)g_hash_table_lookup(priv->status_table, + status_id); + + if (status == NULL) { + for (l = purple_presence_get_statuses(presence); + l != NULL && status == NULL; l = l->next) + { + PurpleStatus *temp_status = l->data; + + if (purple_strequal(status_id, purple_status_get_id(temp_status))) + status = temp_status; + } + + if (status != NULL) + g_hash_table_insert(priv->status_table, + g_strdup(purple_status_get_id(status)), status); + } + + return status; +} + +PurpleStatus * +purple_presence_get_active_status(const PurplePresence *presence) +{ + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + + g_return_val_if_fail(priv != NULL, NULL); + + return priv->active_status; +} + +gboolean +purple_presence_is_available(const PurplePresence *presence) +{ + PurpleStatus *status; + + g_return_val_if_fail(presence != NULL, FALSE); + + status = purple_presence_get_active_status(presence); + + return ((status != NULL && purple_status_is_available(status)) && + !purple_presence_is_idle(presence)); +} + +gboolean +purple_presence_is_online(const PurplePresence *presence) +{ + PurpleStatus *status; + + g_return_val_if_fail(presence != NULL, FALSE); + + if ((status = purple_presence_get_active_status(presence)) == NULL) + return FALSE; + + return purple_status_is_online(status); +} + +gboolean +purple_presence_is_status_active(const PurplePresence *presence, + const char *status_id) +{ + PurpleStatus *status; + + g_return_val_if_fail(presence != NULL, FALSE); + g_return_val_if_fail(status_id != NULL, FALSE); + + status = purple_presence_get_status(presence, status_id); + + return (status != NULL && purple_status_is_active(status)); +} + +gboolean +purple_presence_is_status_primitive_active(const PurplePresence *presence, + PurpleStatusPrimitive primitive) +{ + GList *l; + + g_return_val_if_fail(presence != NULL, FALSE); + g_return_val_if_fail(primitive != PURPLE_STATUS_UNSET, FALSE); + + for (l = purple_presence_get_statuses(presence); + l != NULL; l = l->next) + { + PurpleStatus *temp_status = l->data; + PurpleStatusType *type = purple_status_get_type(temp_status); + + if (purple_status_type_get_primitive(type) == primitive && + purple_status_is_active(temp_status)) + return TRUE; + } + return FALSE; +} + +gboolean +purple_presence_is_idle(const PurplePresence *presence) +{ + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + + g_return_val_if_fail(priv != NULL, FALSE); + + return purple_presence_is_online(presence) && priv->idle; +} + +time_t +purple_presence_get_idle_time(const PurplePresence *presence) +{ + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + + g_return_val_if_fail(priv != NULL, 0); + + return priv->idle_time; +} + +time_t +purple_presence_get_login_time(const PurplePresence *presence) +{ + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + + g_return_val_if_fail(priv != NULL, 0); + + return purple_presence_is_online(presence) ? priv->login_time : 0; +} + +/************************************************************************** + * GObject code for PurplePresence + **************************************************************************/ + +/* GObject Property names */ +#define PRES_PROP_IDLE_S "idle" +#define PRES_PROP_IDLE_TIME_S "idle-time" +#define PRES_PROP_LOGIN_TIME_S "login-time" +#define PRES_PROP_STATUSES_S "statuses" +#define PRES_PROP_ACTIVE_STATUS_S "active-status" + +/* Set method for GObject properties */ +static void +purple_presence_set_property(GObject *obj, guint param_id, const GValue *value, + GParamSpec *pspec) +{ + PurplePresence *presence = PURPLE_PRESENCE(obj); + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); + + switch (param_id) { + case PRES_PROP_IDLE: + purple_presence_set_idle(presence, g_value_get_boolean(value), 0); + break; + case PRES_PROP_IDLE_TIME: +#if SIZEOF_TIME_T == 4 + purple_presence_set_idle(presence, TRUE, g_value_get_int(value)); +#elif SIZEOF_TIME_T == 8 + purple_presence_set_idle(presence, TRUE, g_value_get_int64(value)); +#else +#error Unknown size of time_t +#endif + break; + case PRES_PROP_LOGIN_TIME: +#if SIZEOF_TIME_T == 4 + purple_presence_set_login_time(presence, g_value_get_int(value)); +#elif SIZEOF_TIME_T == 8 + purple_presence_set_login_time(presence, g_value_get_int64(value)); +#else +#error Unknown size of time_t +#endif + break; + case PRES_PROP_ACTIVE_STATUS: +#warning TODO: change get_pointer to get_object when PurpleStatus is a GObject + priv->active_status = g_value_get_pointer(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* Get method for GObject properties */ +static void +purple_presence_get_property(GObject *obj, guint param_id, GValue *value, + GParamSpec *pspec) +{ + PurplePresence *presence = PURPLE_PRESENCE(obj); + + switch (param_id) { + case PRES_PROP_IDLE: + g_value_set_boolean(value, purple_presence_is_idle(presence)); + break; + case PRES_PROP_IDLE_TIME: +#if SIZEOF_TIME_T == 4 + g_value_set_int(value, purple_presence_get_idle_time(presence)); +#elif SIZEOF_TIME_T == 8 + g_value_set_int64(value, purple_presence_get_idle_time(presence)); +#else +#error Unknown size of time_t +#endif + break; + case PRES_PROP_LOGIN_TIME: +#if SIZEOF_TIME_T == 4 + g_value_set_int(value, purple_presence_get_login_time(presence)); +#elif SIZEOF_TIME_T == 8 + g_value_set_int64(value, purple_presence_get_login_time(presence)); +#else +#error Unknown size of time_t +#endif + break; + case PRES_PROP_STATUSES: + g_value_set_pointer(value, purple_presence_get_statuses(presence)); + break; + case PRES_PROP_ACTIVE_STATUS: +#warning TODO: change set_pointer to set_object when PurpleStatus is a GObject + g_value_set_pointer(value, purple_presence_get_active_status(presence)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* GObject initialization function */ +static void +purple_presence_init(GTypeInstance *instance, gpointer klass) +{ + PURPLE_DBUS_REGISTER_POINTER(PURPLE_PRESENCE(instance), PurplePresence); + + PURPLE_PRESENCE_GET_PRIVATE(instance)->status_table = + g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, NULL); +} + +/* GObject dispose function */ +static void +purple_presence_dispose(GObject *object) +{ + PURPLE_DBUS_UNREGISTER_POINTER(object); + + g_list_foreach(PURPLE_PRESENCE_GET_PRIVATE(object)->statuses, + (GFunc)purple_status_destroy, NULL); + + parent_class->dispose(object); +} + +/* GObject finalize function */ +static void +purple_presence_finalize(GObject *object) +{ + PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(object); + + g_list_free(priv->statuses); + g_hash_table_destroy(priv->status_table); + + parent_class->finalize(object); +} + +/* Class initializer function */ +static void purple_presence_class_init(PurplePresenceClass *klass) +{ + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + + parent_class = g_type_class_peek_parent(klass); + + obj_class->dispose = purple_presence_dispose; + obj_class->finalize = purple_presence_finalize; + + /* Setup properties */ + obj_class->get_property = purple_presence_get_property; + obj_class->set_property = purple_presence_set_property; + + g_object_class_install_property(obj_class, PRES_PROP_IDLE, + g_param_spec_boolean(PRES_PROP_IDLE_S, _("Idle"), + _("Whether the presence is in idle state."), FALSE, + G_PARAM_READWRITE) + ); + + + g_object_class_install_property(obj_class, PRES_PROP_IDLE_TIME, +#if SIZEOF_TIME_T == 4 + g_param_spec_int +#elif SIZEOF_TIME_T == 8 + g_param_spec_int64 +#else +#error Unknown size of time_t +#endif + (PRES_PROP_IDLE_TIME_S, _("Idle time"), + _("The idle time of the presence"), +#if SIZEOF_TIME_T == 4 + G_MININT, G_MAXINT, 0, +#elif SIZEOF_TIME_T == 8 + G_MININT64, G_MAXINT64, 0, +#else +#error Unknown size of time_t +#endif + G_PARAM_READWRITE) + ); + + g_object_class_install_property(obj_class, PRES_PROP_LOGIN_TIME, +#if SIZEOF_TIME_T == 4 + g_param_spec_int +#elif SIZEOF_TIME_T == 8 + g_param_spec_int64 +#else +#error Unknown size of time_t +#endif + (PRES_PROP_LOGIN_TIME_S, _("Login time"), + _("The login time of the presence."), +#if SIZEOF_TIME_T == 4 + G_MININT, G_MAXINT, 0, +#elif SIZEOF_TIME_T == 8 + G_MININT64, G_MAXINT64, 0, +#else +#error Unknown size of time_t +#endif + G_PARAM_READWRITE) + ); + + g_object_class_install_property(obj_class, PRES_PROP_STATUSES, + g_param_spec_pointer(PRES_PROP_STATUSES_S, _("Statuses"), + _("The list of statuses in the presence."), + G_PARAM_READABLE) + ); + + g_object_class_install_property(obj_class, PRES_PROP_ACTIVE_STATUS, + g_param_spec_pointer(PRES_PROP_ACTIVE_STATUS_S, _("Active status"), + _("The active status for the presence."), + G_PARAM_READWRITE) + ); + + g_type_class_add_private(klass, sizeof(PurplePresencePrivate)); +} + +GType +purple_presence_get_type(void) +{ + static GType type = 0; + + if(type == 0) { + static const GTypeInfo info = { + sizeof(PurplePresenceClass), + NULL, + NULL, + (GClassInitFunc)purple_presence_class_init, + NULL, + NULL, + sizeof(PurplePresence), + 0, + (GInstanceInitFunc)purple_presence_init, + NULL, + }; + + type = g_type_register_static(G_TYPE_OBJECT, "PurplePresence", + &info, G_TYPE_FLAG_ABSTRACT); + } + + return type; +} + +/************************************************************************** +* PurpleAccountPresence API +**************************************************************************/ +static void +purple_account_presence_update_idle(PurplePresence *presence, gboolean old_idle) +{ + PurpleAccount *account; + PurpleConnection *gc = NULL; + PurplePlugin *prpl = NULL; + PurplePluginProtocolInfo *prpl_info = NULL; + gboolean idle = purple_presence_is_idle(presence); + time_t idle_time = purple_presence_get_idle_time(presence); + time_t current_time = time(NULL); + + account = purple_account_presence_get_account(PURPLE_ACCOUNT_PRESENCE(presence)); + + if (purple_prefs_get_bool("/purple/logging/log_system")) + { + PurpleLog *log = purple_account_get_log(account, FALSE); + + if (log != NULL) + { + char *msg, *tmp; + + if (idle) + tmp = g_strdup_printf(_("+++ %s became idle"), purple_account_get_username(account)); + else + tmp = g_strdup_printf(_("+++ %s became unidle"), purple_account_get_username(account)); + + msg = g_markup_escape_text(tmp, -1); + g_free(tmp); + purple_log_write(log, PURPLE_MESSAGE_SYSTEM, + purple_account_get_username(account), + (idle ? idle_time : current_time), msg); + g_free(msg); + } + } + + gc = purple_account_get_connection(account); + + if(gc) + prpl = purple_connection_get_prpl(gc); + + if(PURPLE_CONNECTION_IS_CONNECTED(gc) && prpl != NULL) + prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); + + if (prpl_info && prpl_info->set_idle) + prpl_info->set_idle(gc, (idle ? (current_time - idle_time) : 0)); +} + +PurpleAccount * +purple_account_presence_get_account(const PurpleAccountPresence *presence) +{ + PurpleAccountPresencePrivate *priv = PURPLE_ACCOUNT_PRESENCE_GET_PRIVATE(presence); + + g_return_val_if_fail(priv != NULL, NULL); + + return priv->account; +} + +static int +purple_buddy_presence_compute_score(const PurpleBuddyPresence *buddy_presence) +{ + GList *l; + int score = 0; + PurplePresence *presence = PURPLE_PRESENCE(buddy_presence); + PurpleBuddy *b = purple_buddy_presence_get_buddy(buddy_presence); + int *primitive_scores = _purple_get_primitive_scores(); + int offline_score = purple_prefs_get_int("/purple/status/scores/offline_msg"); + int idle_score = purple_prefs_get_int("/purple/status/scores/idle"); + + for (l = purple_presence_get_statuses(presence); l != NULL; l = l->next) { + PurpleStatus *status = (PurpleStatus *)l->data; + PurpleStatusType *type = purple_status_get_type(status); + + if (purple_status_is_active(status)) { + score += primitive_scores[purple_status_type_get_primitive(type)]; + if (!purple_status_is_online(status)) { + if (b && purple_account_supports_offline_message(purple_buddy_get_account(b), b)) + score += offline_score; + } + } + } + score += purple_account_get_int(purple_buddy_get_account(b), "score", 0); + if (purple_presence_is_idle(presence)) + score += idle_score; + return score; +} + +gint +purple_buddy_presence_compare(const PurpleBuddyPresence *buddy_presence1, + const PurpleBuddyPresence *buddy_presence2) +{ + PurplePresence *presence1 = PURPLE_PRESENCE(buddy_presence1); + PurplePresence *presence2 = PURPLE_PRESENCE(buddy_presence2); + time_t idle_time_1, idle_time_2; + int score1 = 0, score2 = 0; + int idle_time_score = purple_prefs_get_int("/purple/status/scores/idle_time"); + + if (presence1 == presence2) + return 0; + else if (presence1 == NULL) + return 1; + else if (presence2 == NULL) + return -1; + + if (purple_presence_is_online(presence1) && + !purple_presence_is_online(presence2)) + return -1; + else if (purple_presence_is_online(presence2) && + !purple_presence_is_online(presence1)) + return 1; + + /* Compute the score of the first set of statuses. */ + score1 = purple_buddy_presence_compute_score(buddy_presence1); + + /* Compute the score of the second set of statuses. */ + score2 = purple_buddy_presence_compute_score(buddy_presence2); + + idle_time_1 = time(NULL) - purple_presence_get_idle_time(presence1); + idle_time_2 = time(NULL) - purple_presence_get_idle_time(presence2); + + if (idle_time_1 > idle_time_2) + score1 += idle_time_score; + else if (idle_time_1 < idle_time_2) + score2 += idle_time_score; + + if (score1 < score2) + return 1; + else if (score1 > score2) + return -1; + + return 0; +} + +/************************************************************************** + * GObject code for PurpleAccountPresence + **************************************************************************/ + +/* GObject Property names */ +#define ACPRES_PROP_ACCOUNT_S "account" + +/* Set method for GObject properties */ +static void +purple_account_presence_set_property(GObject *obj, guint param_id, const GValue *value, + GParamSpec *pspec) +{ + PurpleAccountPresence *account_presence = PURPLE_ACCOUNT_PRESENCE(obj); + PurpleAccountPresencePrivate *priv = + PURPLE_ACCOUNT_PRESENCE_GET_PRIVATE(account_presence); + + switch (param_id) { + case ACPRES_PROP_ACCOUNT: + priv->account = g_value_get_object(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* Get method for GObject properties */ +static void +purple_account_presence_get_property(GObject *obj, guint param_id, GValue *value, + GParamSpec *pspec) +{ + PurpleAccountPresence *account_presence = PURPLE_ACCOUNT_PRESENCE(obj); + + switch (param_id) { + case ACPRES_PROP_ACCOUNT: + g_value_set_object(value, + purple_account_presence_get_account(account_presence)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* Called when done constructing */ +static void +purple_account_presence_constructed(GObject *object) +{ + PurplePresence *presence = PURPLE_PRESENCE(object); + PurpleAccountPresencePrivate *priv = PURPLE_ACCOUNT_PRESENCE_GET_PRIVATE(presence); + + G_OBJECT_CLASS(presence_class)->constructed(object); + + PURPLE_PRESENCE_GET_PRIVATE(presence)->statuses = + purple_prpl_get_statuses(priv->account, presence); +} + +/* Class initializer function */ +static void purple_account_presence_class_init(PurpleAccountPresenceClass *klass) +{ + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + + PURPLE_PRESENCE_CLASS(klass)->update_idle = purple_account_presence_update_idle; + + presence_class = g_type_class_peek_parent(klass); + + obj_class->constructed = purple_account_presence_constructed; + + /* Setup properties */ + obj_class->get_property = purple_account_presence_get_property; + obj_class->set_property = purple_account_presence_set_property; + + g_object_class_install_property(obj_class, ACPRES_PROP_ACCOUNT, + g_param_spec_object(ACPRES_PROP_ACCOUNT_S, _("Account"), + _("The account that this presence is of."), PURPLE_TYPE_ACCOUNT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY) + ); + + g_type_class_add_private(klass, sizeof(PurpleAccountPresencePrivate)); +} + +GType +purple_account_presence_get_type(void) +{ + static GType type = 0; + + if(type == 0) { + static const GTypeInfo info = { + sizeof(PurpleAccountPresenceClass), + NULL, + NULL, + (GClassInitFunc)purple_account_presence_class_init, + NULL, + NULL, + sizeof(PurpleAccountPresence), + 0, + NULL, + NULL, + }; + + type = g_type_register_static(PURPLE_TYPE_PRESENCE, + "PurpleAccountPresence", + &info, 0); + } + + return type; +} + +PurpleAccountPresence * +purple_account_presence_new(PurpleAccount *account) +{ + g_return_val_if_fail(account != NULL, NULL); + + return g_object_new(PURPLE_TYPE_ACCOUNT_PRESENCE, + ACPRES_PROP_ACCOUNT_S, account, + NULL); +} + +/************************************************************************** +* PurpleBuddyPresence API +**************************************************************************/ +static void +purple_buddy_presence_update_idle(PurplePresence *presence, gboolean old_idle) +{ + PurpleBuddy *buddy = purple_buddy_presence_get_buddy(PURPLE_BUDDY_PRESENCE(presence)); + time_t current_time = time(NULL); + PurpleBListUiOps *ops = purple_blist_get_ui_ops(); + PurpleAccount *account = purple_buddy_get_account(buddy); + gboolean idle = purple_presence_is_idle(presence); + + if (!old_idle && idle) + { + if (purple_prefs_get_bool("/purple/logging/log_system")) + { + PurpleLog *log = purple_account_get_log(account, FALSE); + + if (log != NULL) + { + char *tmp, *tmp2; + tmp = g_strdup_printf(_("%s became idle"), + purple_buddy_get_alias(buddy)); + tmp2 = g_markup_escape_text(tmp, -1); + g_free(tmp); + + purple_log_write(log, PURPLE_MESSAGE_SYSTEM, + purple_buddy_get_alias(buddy), current_time, tmp2); + g_free(tmp2); + } + } + } + else if (old_idle && !idle) + { + if (purple_prefs_get_bool("/purple/logging/log_system")) + { + PurpleLog *log = purple_account_get_log(account, FALSE); + + if (log != NULL) + { + char *tmp, *tmp2; + tmp = g_strdup_printf(_("%s became unidle"), + purple_buddy_get_alias(buddy)); + tmp2 = g_markup_escape_text(tmp, -1); + g_free(tmp); + + purple_log_write(log, PURPLE_MESSAGE_SYSTEM, + purple_buddy_get_alias(buddy), current_time, tmp2); + g_free(tmp2); + } + } + } + + if (old_idle != idle) + purple_signal_emit(purple_blist_get_handle(), "buddy-idle-changed", buddy, + old_idle, idle); + + purple_contact_invalidate_priority_buddy(purple_buddy_get_contact(buddy)); + + /* Should this be done here? It'd perhaps make more sense to + * connect to buddy-[un]idle signals and update from there + */ + + if (ops != NULL && ops->update != NULL) + ops->update(purple_blist_get_buddy_list(), (PurpleBListNode *)buddy); +} + +PurpleBuddy * +purple_buddy_presence_get_buddy(const PurpleBuddyPresence *presence) +{ + PurpleBuddyPresencePrivate *priv = PURPLE_BUDDY_PRESENCE_GET_PRIVATE(presence); + + g_return_val_if_fail(priv != NULL, NULL); + + return priv->buddy; +} + +/************************************************************************** + * GObject code for PurpleBuddyPresence + **************************************************************************/ + +/* GObject Property names */ +#define BUDPRES_PROP_BUDDY_S "buddy" + +/* Set method for GObject properties */ +static void +purple_buddy_presence_set_property(GObject *obj, guint param_id, const GValue *value, + GParamSpec *pspec) +{ + PurpleBuddyPresence *buddy_presence = PURPLE_BUDDY_PRESENCE(obj); + PurpleBuddyPresencePrivate *priv = + PURPLE_BUDDY_PRESENCE_GET_PRIVATE(buddy_presence); + + switch (param_id) { + case BUDPRES_PROP_BUDDY: + priv->buddy = g_value_get_object(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* Get method for GObject properties */ +static void +purple_buddy_presence_get_property(GObject *obj, guint param_id, GValue *value, + GParamSpec *pspec) +{ + PurpleBuddyPresence *buddy_presence = PURPLE_BUDDY_PRESENCE(obj); + + switch (param_id) { + case BUDPRES_PROP_BUDDY: + g_value_set_object(value, + purple_buddy_presence_get_buddy(buddy_presence)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; + } +} + +/* Called when done constructing */ +static void +purple_buddy_presence_constructed(GObject *object) +{ + PurplePresence *presence = PURPLE_PRESENCE(object); + PurpleBuddyPresencePrivate *priv = PURPLE_BUDDY_PRESENCE_GET_PRIVATE(presence); + PurpleAccount *account; + + G_OBJECT_CLASS(presence_class)->constructed(object); + + account = purple_buddy_get_account(priv->buddy); + PURPLE_PRESENCE_GET_PRIVATE(presence)->statuses = + purple_prpl_get_statuses(account, presence); +} + +/* Class initializer function */ +static void purple_buddy_presence_class_init(PurpleBuddyPresenceClass *klass) +{ + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + + PURPLE_PRESENCE_CLASS(klass)->update_idle = purple_buddy_presence_update_idle; + + presence_class = g_type_class_peek_parent(klass); + + obj_class->constructed = purple_buddy_presence_constructed; + + /* Setup properties */ + obj_class->get_property = purple_buddy_presence_get_property; + obj_class->set_property = purple_buddy_presence_set_property; + + g_object_class_install_property(obj_class, BUDPRES_PROP_BUDDY, + g_param_spec_object(BUDPRES_PROP_BUDDY_S, _("Buddy"), + _("The buddy that this presence is of."), PURPLE_TYPE_BUDDY, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY) + ); + + g_type_class_add_private(klass, sizeof(PurpleBuddyPresencePrivate)); +} + +GType +purple_buddy_presence_get_type(void) +{ + static GType type = 0; + + if(type == 0) { + static const GTypeInfo info = { + sizeof(PurpleBuddyPresenceClass), + NULL, + NULL, + (GClassInitFunc)purple_buddy_presence_class_init, + NULL, + NULL, + sizeof(PurpleBuddyPresence), + 0, + NULL, + NULL, + }; + + type = g_type_register_static(PURPLE_TYPE_PRESENCE, + "PurpleBuddyPresence", + &info, 0); + } + + return type; +} + +PurpleBuddyPresence * +purple_buddy_presence_new(PurpleBuddy *buddy) +{ + g_return_val_if_fail(buddy != NULL, NULL); + + return g_object_new(PURPLE_TYPE_BUDDY_PRESENCE, + BUDPRES_PROP_BUDDY_S, buddy, + NULL); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/presence.h Sun Jul 21 05:49:05 2013 +0530 @@ -0,0 +1,387 @@ +/** + * @file presence.h Presence, account presence and buddy presence API + * @ingroup core + */ +/* + * purple + * + * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ +#ifndef _PURPLE_PRESENCE_H_ +#define _PURPLE_PRESENCE_H_ + +#define PURPLE_TYPE_PRESENCE (purple_presence_get_type()) +#define PURPLE_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_PRESENCE, PurplePresence)) +#define PURPLE_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_PRESENCE, PurplePresenceClass)) +#define PURPLE_IS_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_PRESENCE)) +#define PURPLE_IS_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_PRESENCE)) +#define PURPLE_PRESENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_PRESENCE, PurplePresenceClass)) + +/** @copydoc _PurplePresence */ +typedef struct _PurplePresence PurplePresence; +/** @copydoc _PurplePresenceClass */ +typedef struct _PurplePresenceClass PurplePresenceClass; + +#define PURPLE_TYPE_ACCOUNT_PRESENCE (purple_account_presence_get_type()) +#define PURPLE_ACCOUNT_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresence)) +#define PURPLE_ACCOUNT_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresenceClass)) +#define PURPLE_IS_ACCOUNT_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_ACCOUNT_PRESENCE)) +#define PURPLE_IS_ACCOUNT_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_ACCOUNT_PRESENCE)) +#define PURPLE_ACCOUNT_PRESENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresenceClass)) + +/** @copydoc _PurpleAccountPresence */ +typedef struct _PurpleAccountPresence PurpleAccountPresence; +/** @copydoc _PurpleAccountPresenceClass */ +typedef struct _PurpleAccountPresenceClass PurpleAccountPresenceClass; + +#define PURPLE_TYPE_BUDDY_PRESENCE (purple_buddy_presence_get_type()) +#define PURPLE_BUDDY_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresence)) +#define PURPLE_BUDDY_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresenceClass)) +#define PURPLE_IS_BUDDY_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BUDDY_PRESENCE)) +#define PURPLE_IS_BUDDY_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BUDDY_PRESENCE)) +#define PURPLE_BUDDY_PRESENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresenceClass)) + +/** @copydoc _PurpleBuddyPresence */ +typedef struct _PurpleBuddyPresence PurpleBuddyPresence; +/** @copydoc _PurpleBuddyPresenceClass */ +typedef struct _PurpleBuddyPresenceClass PurpleBuddyPresenceClass; + +#include "account.h" +#include "buddylist.h" +#include "status.h" + +/** + * A PurplePresence is like a collection of PurpleStatuses (plus some + * other random info). For any buddy, or for any one of your accounts, + * or for any person with which you're chatting, you may know various + * amounts of information. This information is all contained in + * one PurplePresence. If one of your buddies is away and idle, + * then the presence contains the PurpleStatus for their awayness, + * and it contains their current idle time. PurplePresences are + * never saved to disk. The information they contain is only relevant + * for the current PurpleSession. + * + * @note When a presence is destroyed with the last g_object_unref(), all + * statuses added to this list will be destroyed along with the presence. + */ +struct _PurplePresence +{ + /*< private >*/ + GObject gparent; +}; + +/** Base class for all #PurplePresence's */ +struct _PurplePresenceClass { + /*< private >*/ + GObjectClass parent_class; + + /** + * Updates the logs and the UI when the idle state or time of the presence + * changes. + */ + void (*update_idle)(PurplePresence *presence, gboolean old_idle); + + void (*_purple_reserved1)(void); + void (*_purple_reserved2)(void); + void (*_purple_reserved3)(void); + void (*_purple_reserved4)(void); +}; + +/** + * A presence for an account + */ +struct _PurpleAccountPresence +{ + /*< private >*/ + PurplePresence parent; +}; + +/** Base class for all #PurpleAccountPresence's */ +struct _PurpleAccountPresenceClass { + /*< private >*/ + PurplePresenceClass parent_class; + + void (*_purple_reserved1)(void); + void (*_purple_reserved2)(void); + void (*_purple_reserved3)(void); + void (*_purple_reserved4)(void); +}; + +/** + * A presence for a buddy + */ +struct _PurpleBuddyPresence +{ + /*< private >*/ + PurplePresence parent; +}; + +/** Base class for all #PurpleBuddyPresence's */ +struct _PurpleBuddyPresenceClass { + /*< private >*/ + PurplePresenceClass parent_class; + + void (*_purple_reserved1)(void); + void (*_purple_reserved2)(void); + void (*_purple_reserved3)(void); + void (*_purple_reserved4)(void); +}; + +G_BEGIN_DECLS + +/**************************************************************************/ +/** @name PurpleAccountPresence API */ +/**************************************************************************/ +/*@{*/ + +/** + * Returns the GType for the PurpleAccountPresence object. + */ +GType purple_account_presence_get_type(void); + +/** + * Creates a presence for an account. + * + * @param account The account to associate with the presence. + * + * @return The new presence. + */ +PurpleAccountPresence *purple_account_presence_new(PurpleAccount *account); + +/** + * Returns an account presence's account. + * + * @param presence The presence. + * + * @return The presence's account. + */ +PurpleAccount *purple_account_presence_get_account(const PurpleAccountPresence *presence); + +/*@}*/ + +/**************************************************************************/ +/** @name PurpleBuddyPresence API */ +/**************************************************************************/ +/*@{*/ + +/** + * Returns the GType for the PurpleBuddyPresence object. + */ +GType purple_buddy_presence_get_type(void); + +/** + * Creates a presence for a buddy. + * + * @param buddy The buddy to associate with the presence. + * + * @return The new presence. + */ +PurpleBuddyPresence *purple_buddy_presence_new(PurpleBuddy *buddy); + +/** + * Returns the buddy presence's buddy. + * + * @param presence The presence. + * + * @return The presence's buddy. + */ +PurpleBuddy *purple_buddy_presence_get_buddy(const PurpleBuddyPresence *presence); + +/** + * Compares two buddy presences for availability. + * + * @param buddy_presence1 The first presence. + * @param buddy_presence2 The second presence. + * + * @return -1 if @a buddy_presence1 is more available than @a buddy_presence2. + * 0 if @a buddy_presence1 is equal to @a buddy_presence2. + * 1 if @a buddy_presence1 is less available than @a buddy_presence2. + */ +gint purple_buddy_presence_compare(const PurpleBuddyPresence *buddy_presence1, + const PurpleBuddyPresence *buddy_presence2); + +/*@}*/ + +/**************************************************************************/ +/** @name PurplePresence API */ +/**************************************************************************/ +/*@{*/ + +/** + * Returns the GType for the PurplePresence object. + */ +GType purple_presence_get_type(void); + +/** + * Sets the active state of a status in a presence. + * + * Only independent statuses can be set unactive. Normal statuses can only + * be set active, so if you wish to disable a status, set another + * non-independent status to active, or use purple_presence_switch_status(). + * + * @param presence The presence. + * @param status_id The ID of the status. + * @param active The active state. + */ +void purple_presence_set_status_active(PurplePresence *presence, + const char *status_id, gboolean active); + +/** + * Switches the active status in a presence. + * + * This is similar to purple_presence_set_status_active(), except it won't + * activate independent statuses. + * + * @param presence The presence. + * @param status_id The status ID to switch to. + */ +void purple_presence_switch_status(PurplePresence *presence, + const char *status_id); + +/** + * Sets the idle state and time on a presence. + * + * @param presence The presence. + * @param idle The idle state. + * @param idle_time The idle time, if @a idle is TRUE. This + * is the time at which the user became idle, + * in seconds since the epoch. If this value is + * unknown then 0 should be used. + */ +void purple_presence_set_idle(PurplePresence *presence, gboolean idle, + time_t idle_time); + +/** + * Sets the login time on a presence. + * + * @param presence The presence. + * @param login_time The login time. + */ +void purple_presence_set_login_time(PurplePresence *presence, time_t login_time); + +/** + * Returns all the statuses in a presence. + * + * @param presence The presence. + * + * @constreturn The statuses. + */ +GList *purple_presence_get_statuses(const PurplePresence *presence); + +/** + * Returns the status with the specified ID from a presence. + * + * @param presence The presence. + * @param status_id The ID of the status. + * + * @return The status if found, or NULL. + */ +PurpleStatus *purple_presence_get_status(const PurplePresence *presence, + const char *status_id); + +/** + * Returns the active exclusive status from a presence. + * + * @param presence The presence. + * + * @return The active exclusive status. + */ +PurpleStatus *purple_presence_get_active_status(const PurplePresence *presence); + +/** + * Returns whether or not a presence is available. + * + * Available presences are online and possibly invisible, but not away or idle. + * + * @param presence The presence. + * + * @return TRUE if the presence is available, or FALSE otherwise. + */ +gboolean purple_presence_is_available(const PurplePresence *presence); + +/** + * Returns whether or not a presence is online. + * + * @param presence The presence. + * + * @return TRUE if the presence is online, or FALSE otherwise. + */ +gboolean purple_presence_is_online(const PurplePresence *presence); + +/** + * Returns whether or not a status in a presence is active. + * + * A status is active if itself or any of its sub-statuses are active. + * + * @param presence The presence. + * @param status_id The ID of the status. + * + * @return TRUE if the status is active, or FALSE. + */ +gboolean purple_presence_is_status_active(const PurplePresence *presence, + const char *status_id); + +/** + * Returns whether or not a status with the specified primitive type + * in a presence is active. + * + * A status is active if itself or any of its sub-statuses are active. + * + * @param presence The presence. + * @param primitive The status primitive. + * + * @return TRUE if the status is active, or FALSE. + */ +gboolean purple_presence_is_status_primitive_active( + const PurplePresence *presence, PurpleStatusPrimitive primitive); + +/** + * Returns whether or not a presence is idle. + * + * @param presence The presence. + * + * @return TRUE if the presence is idle, or FALSE otherwise. + * If the presence is offline (purple_presence_is_online() + * returns FALSE) then FALSE is returned. + */ +gboolean purple_presence_is_idle(const PurplePresence *presence); + +/** + * Returns the presence's idle time. + * + * @param presence The presence. + * + * @return The presence's idle time. + */ +time_t purple_presence_get_idle_time(const PurplePresence *presence); + +/** + * Returns the presence's login time. + * + * @param presence The presence. + * + * @return The presence's login time. + */ +time_t purple_presence_get_login_time(const PurplePresence *presence); + +/*@}*/ + +G_END_DECLS + +#endif /* _PURPLE_PRESENCE_H_ */
--- a/libpurple/presences.c Sun Jul 21 02:52:23 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,998 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ -#include "internal.h" -#include "debug.h" -#include "dbus-maybe.h" -#include "presences.h" - -#define PURPLE_PRESENCE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_PRESENCE, PurplePresencePrivate)) - -/** @copydoc _PurplePresencePrivate */ -typedef struct _PurplePresencePrivate PurplePresencePrivate; - -#define PURPLE_ACCOUNT_PRESENCE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresencePrivate)) - -/** @copydoc _PurpleAccountPresencePrivate */ -typedef struct _PurpleAccountPresencePrivate PurpleAccountPresencePrivate; - -#define PURPLE_BUDDY_PRESENCE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresencePrivate)) - -/** @copydoc _PurpleBuddyPresencePrivate */ -typedef struct _PurpleBuddyPresencePrivate PurpleBuddyPresencePrivate; - -/** Private data for a presence */ -struct _PurplePresencePrivate -{ - gboolean idle; - time_t idle_time; - time_t login_time; - - GList *statuses; - GHashTable *status_table; - - PurpleStatus *active_status; -}; - -/* Presence property enums */ -enum -{ - PRES_PROP_0, - PRES_PROP_IDLE, - PRES_PROP_IDLE_TIME, - PRES_PROP_LOGIN_TIME, - PRES_PROP_STATUSES, - PRES_PROP_ACTIVE_STATUS, - PRES_PROP_LAST -}; - -/** Private data for an account presence */ -struct _PurpleAccountPresencePrivate -{ - PurpleAccount *account; -}; - -/* Account presence property enums */ -enum -{ - ACPRES_PROP_0, - ACPRES_PROP_ACCOUNT, - ACPRES_PROP_LAST -}; - -/** Private data for a buddy presence */ -struct _PurpleBuddyPresencePrivate -{ - PurpleBuddy *buddy; -}; - -/* Buddy presence property enums */ -enum -{ - BUDPRES_PROP_0, - BUDPRES_PROP_BUDDY, - BUDPRES_PROP_LAST -}; - -static GObjectClass *parent_class; -static PurplePresenceClass *presence_class; - -int *_purple_get_primitive_scores(void); - -/************************************************************************** -* PurplePresence API -**************************************************************************/ - -void -purple_presence_set_status_active(PurplePresence *presence, const char *status_id, - gboolean active) -{ - PurpleStatus *status; - - g_return_if_fail(presence != NULL); - g_return_if_fail(status_id != NULL); - - status = purple_presence_get_status(presence, status_id); - - g_return_if_fail(status != NULL); - /* TODO: Should we do the following? */ - /* g_return_if_fail(active == status->active); */ - - if (purple_status_is_exclusive(status)) - { - if (!active) - { - purple_debug_warning("status", - "Attempted to set a non-independent status " - "(%s) inactive. Only independent statuses " - "can be specifically marked inactive.", - status_id); - return; - } - } - - purple_status_set_active(status, active); -} - -void -purple_presence_switch_status(PurplePresence *presence, const char *status_id) -{ - purple_presence_set_status_active(presence, status_id, TRUE); -} - -void -purple_presence_set_idle(PurplePresence *presence, gboolean idle, time_t idle_time) -{ - gboolean old_idle; - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - PurplePresenceClass *klass = PURPLE_PRESENCE_GET_CLASS(presence); - - g_return_if_fail(priv != NULL); - - if (priv->idle == idle && priv->idle_time == idle_time) - return; - - old_idle = priv->idle; - priv->idle = idle; - priv->idle_time = (idle ? idle_time : 0); - - if (klass->update_idle) - klass->update_idle(presence, old_idle); -} - -void -purple_presence_set_login_time(PurplePresence *presence, time_t login_time) -{ - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - - g_return_if_fail(priv != NULL); - - if (priv->login_time == login_time) - return; - - priv->login_time = login_time; -} - -GList * -purple_presence_get_statuses(const PurplePresence *presence) -{ - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - - g_return_val_if_fail(priv != NULL, NULL); - - return priv->statuses; -} - -PurpleStatus * -purple_presence_get_status(const PurplePresence *presence, const char *status_id) -{ - PurpleStatus *status; - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - GList *l = NULL; - - g_return_val_if_fail(priv != NULL, NULL); - g_return_val_if_fail(status_id != NULL, NULL); - - /* What's the purpose of this hash table? */ - status = (PurpleStatus *)g_hash_table_lookup(priv->status_table, - status_id); - - if (status == NULL) { - for (l = purple_presence_get_statuses(presence); - l != NULL && status == NULL; l = l->next) - { - PurpleStatus *temp_status = l->data; - - if (purple_strequal(status_id, purple_status_get_id(temp_status))) - status = temp_status; - } - - if (status != NULL) - g_hash_table_insert(priv->status_table, - g_strdup(purple_status_get_id(status)), status); - } - - return status; -} - -PurpleStatus * -purple_presence_get_active_status(const PurplePresence *presence) -{ - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - - g_return_val_if_fail(priv != NULL, NULL); - - return priv->active_status; -} - -gboolean -purple_presence_is_available(const PurplePresence *presence) -{ - PurpleStatus *status; - - g_return_val_if_fail(presence != NULL, FALSE); - - status = purple_presence_get_active_status(presence); - - return ((status != NULL && purple_status_is_available(status)) && - !purple_presence_is_idle(presence)); -} - -gboolean -purple_presence_is_online(const PurplePresence *presence) -{ - PurpleStatus *status; - - g_return_val_if_fail(presence != NULL, FALSE); - - if ((status = purple_presence_get_active_status(presence)) == NULL) - return FALSE; - - return purple_status_is_online(status); -} - -gboolean -purple_presence_is_status_active(const PurplePresence *presence, - const char *status_id) -{ - PurpleStatus *status; - - g_return_val_if_fail(presence != NULL, FALSE); - g_return_val_if_fail(status_id != NULL, FALSE); - - status = purple_presence_get_status(presence, status_id); - - return (status != NULL && purple_status_is_active(status)); -} - -gboolean -purple_presence_is_status_primitive_active(const PurplePresence *presence, - PurpleStatusPrimitive primitive) -{ - GList *l; - - g_return_val_if_fail(presence != NULL, FALSE); - g_return_val_if_fail(primitive != PURPLE_STATUS_UNSET, FALSE); - - for (l = purple_presence_get_statuses(presence); - l != NULL; l = l->next) - { - PurpleStatus *temp_status = l->data; - PurpleStatusType *type = purple_status_get_type(temp_status); - - if (purple_status_type_get_primitive(type) == primitive && - purple_status_is_active(temp_status)) - return TRUE; - } - return FALSE; -} - -gboolean -purple_presence_is_idle(const PurplePresence *presence) -{ - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - - g_return_val_if_fail(priv != NULL, FALSE); - - return purple_presence_is_online(presence) && priv->idle; -} - -time_t -purple_presence_get_idle_time(const PurplePresence *presence) -{ - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - - g_return_val_if_fail(priv != NULL, 0); - - return priv->idle_time; -} - -time_t -purple_presence_get_login_time(const PurplePresence *presence) -{ - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - - g_return_val_if_fail(priv != NULL, 0); - - return purple_presence_is_online(presence) ? priv->login_time : 0; -} - -/************************************************************************** - * GObject code for PurplePresence - **************************************************************************/ - -/* GObject Property names */ -#define PRES_PROP_IDLE_S "idle" -#define PRES_PROP_IDLE_TIME_S "idle-time" -#define PRES_PROP_LOGIN_TIME_S "login-time" -#define PRES_PROP_STATUSES_S "statuses" -#define PRES_PROP_ACTIVE_STATUS_S "active-status" - -/* Set method for GObject properties */ -static void -purple_presence_set_property(GObject *obj, guint param_id, const GValue *value, - GParamSpec *pspec) -{ - PurplePresence *presence = PURPLE_PRESENCE(obj); - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(presence); - - switch (param_id) { - case PRES_PROP_IDLE: - purple_presence_set_idle(presence, g_value_get_boolean(value), 0); - break; - case PRES_PROP_IDLE_TIME: -#if SIZEOF_TIME_T == 4 - purple_presence_set_idle(presence, TRUE, g_value_get_int(value)); -#elif SIZEOF_TIME_T == 8 - purple_presence_set_idle(presence, TRUE, g_value_get_int64(value)); -#else -#error Unknown size of time_t -#endif - break; - case PRES_PROP_LOGIN_TIME: -#if SIZEOF_TIME_T == 4 - purple_presence_set_login_time(presence, g_value_get_int(value)); -#elif SIZEOF_TIME_T == 8 - purple_presence_set_login_time(presence, g_value_get_int64(value)); -#else -#error Unknown size of time_t -#endif - break; - case PRES_PROP_ACTIVE_STATUS: -#warning TODO: change get_pointer to get_object when PurpleStatus is a GObject - priv->active_status = g_value_get_pointer(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* Get method for GObject properties */ -static void -purple_presence_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurplePresence *presence = PURPLE_PRESENCE(obj); - - switch (param_id) { - case PRES_PROP_IDLE: - g_value_set_boolean(value, purple_presence_is_idle(presence)); - break; - case PRES_PROP_IDLE_TIME: -#if SIZEOF_TIME_T == 4 - g_value_set_int(value, purple_presence_get_idle_time(presence)); -#elif SIZEOF_TIME_T == 8 - g_value_set_int64(value, purple_presence_get_idle_time(presence)); -#else -#error Unknown size of time_t -#endif - break; - case PRES_PROP_LOGIN_TIME: -#if SIZEOF_TIME_T == 4 - g_value_set_int(value, purple_presence_get_login_time(presence)); -#elif SIZEOF_TIME_T == 8 - g_value_set_int64(value, purple_presence_get_login_time(presence)); -#else -#error Unknown size of time_t -#endif - break; - case PRES_PROP_STATUSES: - g_value_set_pointer(value, purple_presence_get_statuses(presence)); - break; - case PRES_PROP_ACTIVE_STATUS: -#warning TODO: change set_pointer to set_object when PurpleStatus is a GObject - g_value_set_pointer(value, purple_presence_get_active_status(presence)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* GObject initialization function */ -static void -purple_presence_init(GTypeInstance *instance, gpointer klass) -{ - PURPLE_DBUS_REGISTER_POINTER(PURPLE_PRESENCE(instance), PurplePresence); - - PURPLE_PRESENCE_GET_PRIVATE(instance)->status_table = - g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, NULL); -} - -/* GObject dispose function */ -static void -purple_presence_dispose(GObject *object) -{ - PURPLE_DBUS_UNREGISTER_POINTER(object); - - g_list_foreach(PURPLE_PRESENCE_GET_PRIVATE(object)->statuses, - (GFunc)purple_status_destroy, NULL); - - parent_class->dispose(object); -} - -/* GObject finalize function */ -static void -purple_presence_finalize(GObject *object) -{ - PurplePresencePrivate *priv = PURPLE_PRESENCE_GET_PRIVATE(object); - - g_list_free(priv->statuses); - g_hash_table_destroy(priv->status_table); - - parent_class->finalize(object); -} - -/* Class initializer function */ -static void purple_presence_class_init(PurplePresenceClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - obj_class->dispose = purple_presence_dispose; - obj_class->finalize = purple_presence_finalize; - - /* Setup properties */ - obj_class->get_property = purple_presence_get_property; - obj_class->set_property = purple_presence_set_property; - - g_object_class_install_property(obj_class, PRES_PROP_IDLE, - g_param_spec_boolean(PRES_PROP_IDLE_S, _("Idle"), - _("Whether the presence is in idle state."), FALSE, - G_PARAM_READWRITE) - ); - - - g_object_class_install_property(obj_class, PRES_PROP_IDLE_TIME, -#if SIZEOF_TIME_T == 4 - g_param_spec_int -#elif SIZEOF_TIME_T == 8 - g_param_spec_int64 -#else -#error Unknown size of time_t -#endif - (PRES_PROP_IDLE_TIME_S, _("Idle time"), - _("The idle time of the presence"), -#if SIZEOF_TIME_T == 4 - G_MININT, G_MAXINT, 0, -#elif SIZEOF_TIME_T == 8 - G_MININT64, G_MAXINT64, 0, -#else -#error Unknown size of time_t -#endif - G_PARAM_READWRITE) - ); - - g_object_class_install_property(obj_class, PRES_PROP_LOGIN_TIME, -#if SIZEOF_TIME_T == 4 - g_param_spec_int -#elif SIZEOF_TIME_T == 8 - g_param_spec_int64 -#else -#error Unknown size of time_t -#endif - (PRES_PROP_LOGIN_TIME_S, _("Login time"), - _("The login time of the presence."), -#if SIZEOF_TIME_T == 4 - G_MININT, G_MAXINT, 0, -#elif SIZEOF_TIME_T == 8 - G_MININT64, G_MAXINT64, 0, -#else -#error Unknown size of time_t -#endif - G_PARAM_READWRITE) - ); - - g_object_class_install_property(obj_class, PRES_PROP_STATUSES, - g_param_spec_pointer(PRES_PROP_STATUSES_S, _("Statuses"), - _("The list of statuses in the presence."), - G_PARAM_READABLE) - ); - - g_object_class_install_property(obj_class, PRES_PROP_ACTIVE_STATUS, - g_param_spec_pointer(PRES_PROP_ACTIVE_STATUS_S, _("Active status"), - _("The active status for the presence."), - G_PARAM_READWRITE) - ); - - g_type_class_add_private(klass, sizeof(PurplePresencePrivate)); -} - -GType -purple_presence_get_type(void) -{ - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurplePresenceClass), - NULL, - NULL, - (GClassInitFunc)purple_presence_class_init, - NULL, - NULL, - sizeof(PurplePresence), - 0, - (GInstanceInitFunc)purple_presence_init, - NULL, - }; - - type = g_type_register_static(G_TYPE_OBJECT, "PurplePresence", - &info, G_TYPE_FLAG_ABSTRACT); - } - - return type; -} - -/************************************************************************** -* PurpleAccountPresence API -**************************************************************************/ -static void -purple_account_presence_update_idle(PurplePresence *presence, gboolean old_idle) -{ - PurpleAccount *account; - PurpleConnection *gc = NULL; - PurplePlugin *prpl = NULL; - PurplePluginProtocolInfo *prpl_info = NULL; - gboolean idle = purple_presence_is_idle(presence); - time_t idle_time = purple_presence_get_idle_time(presence); - time_t current_time = time(NULL); - - account = purple_account_presence_get_account(PURPLE_ACCOUNT_PRESENCE(presence)); - - if (purple_prefs_get_bool("/purple/logging/log_system")) - { - PurpleLog *log = purple_account_get_log(account, FALSE); - - if (log != NULL) - { - char *msg, *tmp; - - if (idle) - tmp = g_strdup_printf(_("+++ %s became idle"), purple_account_get_username(account)); - else - tmp = g_strdup_printf(_("+++ %s became unidle"), purple_account_get_username(account)); - - msg = g_markup_escape_text(tmp, -1); - g_free(tmp); - purple_log_write(log, PURPLE_MESSAGE_SYSTEM, - purple_account_get_username(account), - (idle ? idle_time : current_time), msg); - g_free(msg); - } - } - - gc = purple_account_get_connection(account); - - if(gc) - prpl = purple_connection_get_prpl(gc); - - if(PURPLE_CONNECTION_IS_CONNECTED(gc) && prpl != NULL) - prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); - - if (prpl_info && prpl_info->set_idle) - prpl_info->set_idle(gc, (idle ? (current_time - idle_time) : 0)); -} - -PurpleAccount * -purple_account_presence_get_account(const PurpleAccountPresence *presence) -{ - PurpleAccountPresencePrivate *priv = PURPLE_ACCOUNT_PRESENCE_GET_PRIVATE(presence); - - g_return_val_if_fail(priv != NULL, NULL); - - return priv->account; -} - -static int -purple_buddy_presence_compute_score(const PurpleBuddyPresence *buddy_presence) -{ - GList *l; - int score = 0; - PurplePresence *presence = PURPLE_PRESENCE(buddy_presence); - PurpleBuddy *b = purple_buddy_presence_get_buddy(buddy_presence); - int *primitive_scores = _purple_get_primitive_scores(); - int offline_score = purple_prefs_get_int("/purple/status/scores/offline_msg"); - int idle_score = purple_prefs_get_int("/purple/status/scores/idle"); - - for (l = purple_presence_get_statuses(presence); l != NULL; l = l->next) { - PurpleStatus *status = (PurpleStatus *)l->data; - PurpleStatusType *type = purple_status_get_type(status); - - if (purple_status_is_active(status)) { - score += primitive_scores[purple_status_type_get_primitive(type)]; - if (!purple_status_is_online(status)) { - if (b && purple_account_supports_offline_message(purple_buddy_get_account(b), b)) - score += offline_score; - } - } - } - score += purple_account_get_int(purple_buddy_get_account(b), "score", 0); - if (purple_presence_is_idle(presence)) - score += idle_score; - return score; -} - -gint -purple_buddy_presence_compare(const PurpleBuddyPresence *buddy_presence1, - const PurpleBuddyPresence *buddy_presence2) -{ - PurplePresence *presence1 = PURPLE_PRESENCE(buddy_presence1); - PurplePresence *presence2 = PURPLE_PRESENCE(buddy_presence2); - time_t idle_time_1, idle_time_2; - int score1 = 0, score2 = 0; - int idle_time_score = purple_prefs_get_int("/purple/status/scores/idle_time"); - - if (presence1 == presence2) - return 0; - else if (presence1 == NULL) - return 1; - else if (presence2 == NULL) - return -1; - - if (purple_presence_is_online(presence1) && - !purple_presence_is_online(presence2)) - return -1; - else if (purple_presence_is_online(presence2) && - !purple_presence_is_online(presence1)) - return 1; - - /* Compute the score of the first set of statuses. */ - score1 = purple_buddy_presence_compute_score(buddy_presence1); - - /* Compute the score of the second set of statuses. */ - score2 = purple_buddy_presence_compute_score(buddy_presence2); - - idle_time_1 = time(NULL) - purple_presence_get_idle_time(presence1); - idle_time_2 = time(NULL) - purple_presence_get_idle_time(presence2); - - if (idle_time_1 > idle_time_2) - score1 += idle_time_score; - else if (idle_time_1 < idle_time_2) - score2 += idle_time_score; - - if (score1 < score2) - return 1; - else if (score1 > score2) - return -1; - - return 0; -} - -/************************************************************************** - * GObject code for PurpleAccountPresence - **************************************************************************/ - -/* GObject Property names */ -#define ACPRES_PROP_ACCOUNT_S "account" - -/* Set method for GObject properties */ -static void -purple_account_presence_set_property(GObject *obj, guint param_id, const GValue *value, - GParamSpec *pspec) -{ - PurpleAccountPresence *account_presence = PURPLE_ACCOUNT_PRESENCE(obj); - PurpleAccountPresencePrivate *priv = - PURPLE_ACCOUNT_PRESENCE_GET_PRIVATE(account_presence); - - switch (param_id) { - case ACPRES_PROP_ACCOUNT: - priv->account = g_value_get_object(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* Get method for GObject properties */ -static void -purple_account_presence_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurpleAccountPresence *account_presence = PURPLE_ACCOUNT_PRESENCE(obj); - - switch (param_id) { - case ACPRES_PROP_ACCOUNT: - g_value_set_object(value, - purple_account_presence_get_account(account_presence)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* Called when done constructing */ -static void -purple_account_presence_constructed(GObject *object) -{ - PurplePresence *presence = PURPLE_PRESENCE(object); - PurpleAccountPresencePrivate *priv = PURPLE_ACCOUNT_PRESENCE_GET_PRIVATE(presence); - - G_OBJECT_CLASS(presence_class)->constructed(object); - - PURPLE_PRESENCE_GET_PRIVATE(presence)->statuses = - purple_prpl_get_statuses(priv->account, presence); -} - -/* Class initializer function */ -static void purple_account_presence_class_init(PurpleAccountPresenceClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - - PURPLE_PRESENCE_CLASS(klass)->update_idle = purple_account_presence_update_idle; - - presence_class = g_type_class_peek_parent(klass); - - obj_class->constructed = purple_account_presence_constructed; - - /* Setup properties */ - obj_class->get_property = purple_account_presence_get_property; - obj_class->set_property = purple_account_presence_set_property; - - g_object_class_install_property(obj_class, ACPRES_PROP_ACCOUNT, - g_param_spec_object(ACPRES_PROP_ACCOUNT_S, _("Account"), - _("The account that this presence is of."), PURPLE_TYPE_ACCOUNT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY) - ); - - g_type_class_add_private(klass, sizeof(PurpleAccountPresencePrivate)); -} - -GType -purple_account_presence_get_type(void) -{ - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleAccountPresenceClass), - NULL, - NULL, - (GClassInitFunc)purple_account_presence_class_init, - NULL, - NULL, - sizeof(PurpleAccountPresence), - 0, - NULL, - NULL, - }; - - type = g_type_register_static(PURPLE_TYPE_PRESENCE, - "PurpleAccountPresence", - &info, 0); - } - - return type; -} - -PurpleAccountPresence * -purple_account_presence_new(PurpleAccount *account) -{ - g_return_val_if_fail(account != NULL, NULL); - - return g_object_new(PURPLE_TYPE_ACCOUNT_PRESENCE, - ACPRES_PROP_ACCOUNT_S, account, - NULL); -} - -/************************************************************************** -* PurpleBuddyPresence API -**************************************************************************/ -static void -purple_buddy_presence_update_idle(PurplePresence *presence, gboolean old_idle) -{ - PurpleBuddy *buddy = purple_buddy_presence_get_buddy(PURPLE_BUDDY_PRESENCE(presence)); - time_t current_time = time(NULL); - PurpleBListUiOps *ops = purple_blist_get_ui_ops(); - PurpleAccount *account = purple_buddy_get_account(buddy); - gboolean idle = purple_presence_is_idle(presence); - - if (!old_idle && idle) - { - if (purple_prefs_get_bool("/purple/logging/log_system")) - { - PurpleLog *log = purple_account_get_log(account, FALSE); - - if (log != NULL) - { - char *tmp, *tmp2; - tmp = g_strdup_printf(_("%s became idle"), - purple_buddy_get_alias(buddy)); - tmp2 = g_markup_escape_text(tmp, -1); - g_free(tmp); - - purple_log_write(log, PURPLE_MESSAGE_SYSTEM, - purple_buddy_get_alias(buddy), current_time, tmp2); - g_free(tmp2); - } - } - } - else if (old_idle && !idle) - { - if (purple_prefs_get_bool("/purple/logging/log_system")) - { - PurpleLog *log = purple_account_get_log(account, FALSE); - - if (log != NULL) - { - char *tmp, *tmp2; - tmp = g_strdup_printf(_("%s became unidle"), - purple_buddy_get_alias(buddy)); - tmp2 = g_markup_escape_text(tmp, -1); - g_free(tmp); - - purple_log_write(log, PURPLE_MESSAGE_SYSTEM, - purple_buddy_get_alias(buddy), current_time, tmp2); - g_free(tmp2); - } - } - } - - if (old_idle != idle) - purple_signal_emit(purple_blist_get_handle(), "buddy-idle-changed", buddy, - old_idle, idle); - - purple_contact_invalidate_priority_buddy(purple_buddy_get_contact(buddy)); - - /* Should this be done here? It'd perhaps make more sense to - * connect to buddy-[un]idle signals and update from there - */ - - if (ops != NULL && ops->update != NULL) - ops->update(purple_blist_get_buddy_list(), (PurpleBListNode *)buddy); -} - -PurpleBuddy * -purple_buddy_presence_get_buddy(const PurpleBuddyPresence *presence) -{ - PurpleBuddyPresencePrivate *priv = PURPLE_BUDDY_PRESENCE_GET_PRIVATE(presence); - - g_return_val_if_fail(priv != NULL, NULL); - - return priv->buddy; -} - -/************************************************************************** - * GObject code for PurpleBuddyPresence - **************************************************************************/ - -/* GObject Property names */ -#define BUDPRES_PROP_BUDDY_S "buddy" - -/* Set method for GObject properties */ -static void -purple_buddy_presence_set_property(GObject *obj, guint param_id, const GValue *value, - GParamSpec *pspec) -{ - PurpleBuddyPresence *buddy_presence = PURPLE_BUDDY_PRESENCE(obj); - PurpleBuddyPresencePrivate *priv = - PURPLE_BUDDY_PRESENCE_GET_PRIVATE(buddy_presence); - - switch (param_id) { - case BUDPRES_PROP_BUDDY: - priv->buddy = g_value_get_object(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* Get method for GObject properties */ -static void -purple_buddy_presence_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurpleBuddyPresence *buddy_presence = PURPLE_BUDDY_PRESENCE(obj); - - switch (param_id) { - case BUDPRES_PROP_BUDDY: - g_value_set_object(value, - purple_buddy_presence_get_buddy(buddy_presence)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* Called when done constructing */ -static void -purple_buddy_presence_constructed(GObject *object) -{ - PurplePresence *presence = PURPLE_PRESENCE(object); - PurpleBuddyPresencePrivate *priv = PURPLE_BUDDY_PRESENCE_GET_PRIVATE(presence); - PurpleAccount *account; - - G_OBJECT_CLASS(presence_class)->constructed(object); - - account = purple_buddy_get_account(priv->buddy); - PURPLE_PRESENCE_GET_PRIVATE(presence)->statuses = - purple_prpl_get_statuses(account, presence); -} - -/* Class initializer function */ -static void purple_buddy_presence_class_init(PurpleBuddyPresenceClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - - PURPLE_PRESENCE_CLASS(klass)->update_idle = purple_buddy_presence_update_idle; - - presence_class = g_type_class_peek_parent(klass); - - obj_class->constructed = purple_buddy_presence_constructed; - - /* Setup properties */ - obj_class->get_property = purple_buddy_presence_get_property; - obj_class->set_property = purple_buddy_presence_set_property; - - g_object_class_install_property(obj_class, BUDPRES_PROP_BUDDY, - g_param_spec_object(BUDPRES_PROP_BUDDY_S, _("Buddy"), - _("The buddy that this presence is of."), PURPLE_TYPE_BUDDY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY) - ); - - g_type_class_add_private(klass, sizeof(PurpleBuddyPresencePrivate)); -} - -GType -purple_buddy_presence_get_type(void) -{ - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleBuddyPresenceClass), - NULL, - NULL, - (GClassInitFunc)purple_buddy_presence_class_init, - NULL, - NULL, - sizeof(PurpleBuddyPresence), - 0, - NULL, - NULL, - }; - - type = g_type_register_static(PURPLE_TYPE_PRESENCE, - "PurpleBuddyPresence", - &info, 0); - } - - return type; -} - -PurpleBuddyPresence * -purple_buddy_presence_new(PurpleBuddy *buddy) -{ - g_return_val_if_fail(buddy != NULL, NULL); - - return g_object_new(PURPLE_TYPE_BUDDY_PRESENCE, - BUDPRES_PROP_BUDDY_S, buddy, - NULL); -}
--- a/libpurple/presences.h Sun Jul 21 02:52:23 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,387 +0,0 @@ -/** - * @file presences.h Presence, account presence and buddy presence API - * @ingroup core - */ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ -#ifndef _PURPLE_PRESENCE_H_ -#define _PURPLE_PRESENCE_H_ - -#define PURPLE_TYPE_PRESENCE (purple_presence_get_type()) -#define PURPLE_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_PRESENCE, PurplePresence)) -#define PURPLE_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_PRESENCE, PurplePresenceClass)) -#define PURPLE_IS_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_PRESENCE)) -#define PURPLE_IS_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_PRESENCE)) -#define PURPLE_PRESENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_PRESENCE, PurplePresenceClass)) - -/** @copydoc _PurplePresence */ -typedef struct _PurplePresence PurplePresence; -/** @copydoc _PurplePresenceClass */ -typedef struct _PurplePresenceClass PurplePresenceClass; - -#define PURPLE_TYPE_ACCOUNT_PRESENCE (purple_account_presence_get_type()) -#define PURPLE_ACCOUNT_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresence)) -#define PURPLE_ACCOUNT_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresenceClass)) -#define PURPLE_IS_ACCOUNT_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_ACCOUNT_PRESENCE)) -#define PURPLE_IS_ACCOUNT_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_ACCOUNT_PRESENCE)) -#define PURPLE_ACCOUNT_PRESENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresenceClass)) - -/** @copydoc _PurpleAccountPresence */ -typedef struct _PurpleAccountPresence PurpleAccountPresence; -/** @copydoc _PurpleAccountPresenceClass */ -typedef struct _PurpleAccountPresenceClass PurpleAccountPresenceClass; - -#define PURPLE_TYPE_BUDDY_PRESENCE (purple_buddy_presence_get_type()) -#define PURPLE_BUDDY_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresence)) -#define PURPLE_BUDDY_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresenceClass)) -#define PURPLE_IS_BUDDY_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BUDDY_PRESENCE)) -#define PURPLE_IS_BUDDY_PRESENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BUDDY_PRESENCE)) -#define PURPLE_BUDDY_PRESENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresenceClass)) - -/** @copydoc _PurpleBuddyPresence */ -typedef struct _PurpleBuddyPresence PurpleBuddyPresence; -/** @copydoc _PurpleBuddyPresenceClass */ -typedef struct _PurpleBuddyPresenceClass PurpleBuddyPresenceClass; - -#include "account.h" -#include "buddylist.h" -#include "status.h" - -/** - * A PurplePresence is like a collection of PurpleStatuses (plus some - * other random info). For any buddy, or for any one of your accounts, - * or for any person with which you're chatting, you may know various - * amounts of information. This information is all contained in - * one PurplePresence. If one of your buddies is away and idle, - * then the presence contains the PurpleStatus for their awayness, - * and it contains their current idle time. PurplePresences are - * never saved to disk. The information they contain is only relevant - * for the current PurpleSession. - * - * @note When a presence is destroyed with the last g_object_unref(), all - * statuses added to this list will be destroyed along with the presence. - */ -struct _PurplePresence -{ - /*< private >*/ - GObject gparent; -}; - -/** Base class for all #PurplePresence's */ -struct _PurplePresenceClass { - /*< private >*/ - GObjectClass parent_class; - - /** - * Updates the logs and the UI when the idle state or time of the presence - * changes. - */ - void (*update_idle)(PurplePresence *presence, gboolean old_idle); - - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -/** - * A presence for an account - */ -struct _PurpleAccountPresence -{ - /*< private >*/ - PurplePresence parent; -}; - -/** Base class for all #PurpleAccountPresence's */ -struct _PurpleAccountPresenceClass { - /*< private >*/ - PurplePresenceClass parent_class; - - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -/** - * A presence for a buddy - */ -struct _PurpleBuddyPresence -{ - /*< private >*/ - PurplePresence parent; -}; - -/** Base class for all #PurpleBuddyPresence's */ -struct _PurpleBuddyPresenceClass { - /*< private >*/ - PurplePresenceClass parent_class; - - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -/**************************************************************************/ -/** @name PurpleAccountPresence API */ -/**************************************************************************/ -/*@{*/ - -/** - * Returns the GType for the PurpleAccountPresence object. - */ -GType purple_account_presence_get_type(void); - -/** - * Creates a presence for an account. - * - * @param account The account to associate with the presence. - * - * @return The new presence. - */ -PurpleAccountPresence *purple_account_presence_new(PurpleAccount *account); - -/** - * Returns an account presence's account. - * - * @param presence The presence. - * - * @return The presence's account. - */ -PurpleAccount *purple_account_presence_get_account(const PurpleAccountPresence *presence); - -/*@}*/ - -/**************************************************************************/ -/** @name PurpleBuddyPresence API */ -/**************************************************************************/ -/*@{*/ - -/** - * Returns the GType for the PurpleBuddyPresence object. - */ -GType purple_buddy_presence_get_type(void); - -/** - * Creates a presence for a buddy. - * - * @param buddy The buddy to associate with the presence. - * - * @return The new presence. - */ -PurpleBuddyPresence *purple_buddy_presence_new(PurpleBuddy *buddy); - -/** - * Returns the buddy presence's buddy. - * - * @param presence The presence. - * - * @return The presence's buddy. - */ -PurpleBuddy *purple_buddy_presence_get_buddy(const PurpleBuddyPresence *presence); - -/** - * Compares two buddy presences for availability. - * - * @param buddy_presence1 The first presence. - * @param buddy_presence2 The second presence. - * - * @return -1 if @a buddy_presence1 is more available than @a buddy_presence2. - * 0 if @a buddy_presence1 is equal to @a buddy_presence2. - * 1 if @a buddy_presence1 is less available than @a buddy_presence2. - */ -gint purple_buddy_presence_compare(const PurpleBuddyPresence *buddy_presence1, - const PurpleBuddyPresence *buddy_presence2); - -/*@}*/ - -/**************************************************************************/ -/** @name PurplePresence API */ -/**************************************************************************/ -/*@{*/ - -/** - * Returns the GType for the PurplePresence object. - */ -GType purple_presence_get_type(void); - -/** - * Sets the active state of a status in a presence. - * - * Only independent statuses can be set unactive. Normal statuses can only - * be set active, so if you wish to disable a status, set another - * non-independent status to active, or use purple_presence_switch_status(). - * - * @param presence The presence. - * @param status_id The ID of the status. - * @param active The active state. - */ -void purple_presence_set_status_active(PurplePresence *presence, - const char *status_id, gboolean active); - -/** - * Switches the active status in a presence. - * - * This is similar to purple_presence_set_status_active(), except it won't - * activate independent statuses. - * - * @param presence The presence. - * @param status_id The status ID to switch to. - */ -void purple_presence_switch_status(PurplePresence *presence, - const char *status_id); - -/** - * Sets the idle state and time on a presence. - * - * @param presence The presence. - * @param idle The idle state. - * @param idle_time The idle time, if @a idle is TRUE. This - * is the time at which the user became idle, - * in seconds since the epoch. If this value is - * unknown then 0 should be used. - */ -void purple_presence_set_idle(PurplePresence *presence, gboolean idle, - time_t idle_time); - -/** - * Sets the login time on a presence. - * - * @param presence The presence. - * @param login_time The login time. - */ -void purple_presence_set_login_time(PurplePresence *presence, time_t login_time); - -/** - * Returns all the statuses in a presence. - * - * @param presence The presence. - * - * @constreturn The statuses. - */ -GList *purple_presence_get_statuses(const PurplePresence *presence); - -/** - * Returns the status with the specified ID from a presence. - * - * @param presence The presence. - * @param status_id The ID of the status. - * - * @return The status if found, or NULL. - */ -PurpleStatus *purple_presence_get_status(const PurplePresence *presence, - const char *status_id); - -/** - * Returns the active exclusive status from a presence. - * - * @param presence The presence. - * - * @return The active exclusive status. - */ -PurpleStatus *purple_presence_get_active_status(const PurplePresence *presence); - -/** - * Returns whether or not a presence is available. - * - * Available presences are online and possibly invisible, but not away or idle. - * - * @param presence The presence. - * - * @return TRUE if the presence is available, or FALSE otherwise. - */ -gboolean purple_presence_is_available(const PurplePresence *presence); - -/** - * Returns whether or not a presence is online. - * - * @param presence The presence. - * - * @return TRUE if the presence is online, or FALSE otherwise. - */ -gboolean purple_presence_is_online(const PurplePresence *presence); - -/** - * Returns whether or not a status in a presence is active. - * - * A status is active if itself or any of its sub-statuses are active. - * - * @param presence The presence. - * @param status_id The ID of the status. - * - * @return TRUE if the status is active, or FALSE. - */ -gboolean purple_presence_is_status_active(const PurplePresence *presence, - const char *status_id); - -/** - * Returns whether or not a status with the specified primitive type - * in a presence is active. - * - * A status is active if itself or any of its sub-statuses are active. - * - * @param presence The presence. - * @param primitive The status primitive. - * - * @return TRUE if the status is active, or FALSE. - */ -gboolean purple_presence_is_status_primitive_active( - const PurplePresence *presence, PurpleStatusPrimitive primitive); - -/** - * Returns whether or not a presence is idle. - * - * @param presence The presence. - * - * @return TRUE if the presence is idle, or FALSE otherwise. - * If the presence is offline (purple_presence_is_online() - * returns FALSE) then FALSE is returned. - */ -gboolean purple_presence_is_idle(const PurplePresence *presence); - -/** - * Returns the presence's idle time. - * - * @param presence The presence. - * - * @return The presence's idle time. - */ -time_t purple_presence_get_idle_time(const PurplePresence *presence); - -/** - * Returns the presence's login time. - * - * @param presence The presence. - * - * @return The presence's login time. - */ -time_t purple_presence_get_login_time(const PurplePresence *presence); - -/*@}*/ - -G_END_DECLS - -#endif /* _PURPLE_PRESENCE_H_ */
--- a/libpurple/purple.h.in Sun Jul 21 02:52:23 2013 +0530 +++ b/libpurple/purple.h.in Sun Jul 21 05:49:05 2013 +0530 @@ -75,7 +75,7 @@ #include <pluginpref.h> #include <pounce.h> #include <prefs.h> -#include <presences.h> +#include <presence.h> #include <proxy.h> #include <prpl.h> #include <request.h>
--- a/libpurple/status.h Sun Jul 21 02:52:23 2013 +0530 +++ b/libpurple/status.h Sun Jul 21 05:49:05 2013 +0530 @@ -64,7 +64,7 @@ * A PurplePresence is like a collection of PurpleStatuses (plus some * other random info). * - * @see presences.h + * @see presence.h */ /** @@ -111,7 +111,7 @@ PURPLE_STATUS_NUM_PRIMITIVES } PurpleStatusPrimitive; -#include "presences.h" +#include "presence.h" #define PURPLE_TUNE_ARTIST "tune_artist" #define PURPLE_TUNE_TITLE "tune_title"