gobjectification: 31146d0c: Setup chat privates
aluink at soc.pidgin.im
aluink at soc.pidgin.im
Mon Aug 3 23:55:39 EDT 2009
-----------------------------------------------------------------
Revision: 31146d0cdfc652391cb42db42bbbfe27650d706e
Ancestor: f17fab7dff6375c82edd66f3c95aa385eac2dffc
Author: aluink at soc.pidgin.im
Date: 2009-08-02T06:43:38
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/31146d0cdfc652391cb42db42bbbfe27650d706e
Modified files:
libpurple/blist-node.c libpurple/blist-node.h
libpurple/blist.c libpurple/blist.h libpurple/buddy.c
libpurple/chat.c libpurple/chat.h libpurple/group.c
ChangeLog:
Setup chat privates
-------------- next part --------------
============================================================
--- libpurple/blist-node.c d8eb580f1897b2ae200a011426896d92c47d7855
+++ libpurple/blist-node.c b5601df7bc90f43af5682b6483c38fb6bda9afd9
@@ -705,7 +705,9 @@ purple_blist_node_init(GTypeInstance *in
static void
purple_blist_node_init(GTypeInstance *instance, gpointer class)
{
- purple_blist_node_initialize_settings(PURPLE_BLIST_NODE(instance));
+ PurpleBlistNode *node = PURPLE_BLIST_NODE(instance);
+ node->priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
+ purple_blist_node_initialize_settings(node);
}
GType
============================================================
--- libpurple/blist-node.h 871f35b0d7192f7a85ea312482921189b24421d0
+++ libpurple/blist-node.h 6f284bac12500e34ddaea23db760f0eeb3a88883
@@ -24,11 +24,9 @@
* 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>
#define PURPLE_BUDDY_IS_ONLINE(b) \
((b) != NULL && purple_account_is_connected(purple_buddy_get_account(b)) && \
@@ -51,6 +49,8 @@ typedef struct _PurpleBlistNodeClass Pur
typedef struct _PurpleBlistNodePrivate PurpleBlistNodePrivate;
typedef struct _PurpleBlistNodeClass PurpleBlistNodeClass;
+#include "pobject.h"
+
#define PURPLE_BLIST_NODE_TYPE (purple_blist_node_get_gtype ())
#define PURPLE_BLIST_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_BLIST_NODE_TYPE, PurpleBlistNode))
#define PURPLE_IS_BLIST_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_BLIST_NODE_TYPE))
@@ -59,6 +59,7 @@ typedef struct _PurpleBlistNodeClass Pur
#define PURPLE_GET_BLIST_NODE_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_BLIST_NODE_TYPE, PurpleBlistNodeClass))
#define PURPLE_BLIST_NODE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PURPLE_BLIST_NODE_TYPE, PurpleBlistNodePrivate))
+
/**
* 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
@@ -363,4 +364,5 @@ GType purple_blist_node_get_gtype(void);
*/
GType purple_blist_node_get_gtype(void);
+PurpleBlistNode *purple_blist_get_last_child(PurpleBlistNode *node);
#endif
============================================================
--- libpurple/blist.c 99067738250d7dd840ae39e7f7f5ea0ea6cca691
+++ libpurple/blist.c 15be403dfac57b4baedf58c821dacf1acee44d85
@@ -24,12 +24,12 @@
#define _BLIST_HELPERS_
#include "internal.h"
-#include "blist.h"
#include "dbus-maybe.h"
#include "debug.h"
#include "server.h"
#include "signals.h"
#include "xmlnode.h"
+#include "chat.h"
static GType purple_blist_get_gtype(void);
@@ -940,6 +940,7 @@ void purple_blist_remove_chat(PurpleChat
PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
PurpleBlistNode *node, *gnode;
PurpleGroup *group;
+ PurpleAccount *account;
g_return_if_fail(chat != NULL);
@@ -953,7 +954,8 @@ void purple_blist_remove_chat(PurpleChat
purple_blist_node_remove(node);
/* Adjust size counts */
- if (purple_account_is_connected(chat->account)) {
+ account = purple_chat_get_account(chat);
+ if (purple_account_is_connected(account)) {
group->online--;
group->currentsize--;
}
@@ -1129,7 +1131,7 @@ void purple_blist_add_account(PurpleAcco
ops->update(cnode);
}
} else if (PURPLE_IS_CHAT(cnode) &&
- ((PurpleChat*)cnode)->account == account) {
+ purple_chat_get_account(PURPLE_CHAT(cnode)) == account) {
(PURPLE_GROUP(gnode))->online++;
(PURPLE_GROUP(gnode))->currentsize++;
ops->update(cnode);
@@ -1206,7 +1208,7 @@ void purple_blist_remove_account(PurpleA
} else if (PURPLE_IS_CHAT(cnode)) {
chat = (PurpleChat *)cnode;
- if(chat->account == account) {
+ if(purple_chat_get_account(chat) == account) {
group->currentsize--;
group->online--;
@@ -1233,8 +1235,8 @@ gboolean purple_group_on_account(PurpleG
return TRUE;
} else if (PURPLE_IS_CHAT(cnode)) {
PurpleChat *chat = (PurpleChat *)cnode;
- if ((!account && purple_account_is_connected(chat->account))
- || chat->account == account)
+ if ((!account && purple_account_is_connected(purple_chat_get_account(chat)))
+ || purple_chat_get_account(chat) == account)
return TRUE;
}
}
@@ -1291,7 +1293,7 @@ void purple_blist_add_chat(PurpleChat *c
cnode->parent = node->parent;
node->next = cnode;
(PURPLE_GROUP(node->parent))->totalsize++;
- if (purple_account_is_connected(chat->account)) {
+ if (purple_account_is_connected(purple_chat_get_account(chat))) {
(PURPLE_GROUP(node->parent))->online++;
(PURPLE_GROUP(node->parent))->currentsize++;
}
@@ -1303,7 +1305,7 @@ void purple_blist_add_chat(PurpleChat *c
(PURPLE_BLIST_NODE(group))->child = cnode;
cnode->parent = PURPLE_BLIST_NODE(group);
group->totalsize++;
- if (purple_account_is_connected(chat->account)) {
+ if (purple_account_is_connected(purple_chat_get_account(chat))) {
group->online++;
group->currentsize++;
}
@@ -1473,7 +1475,7 @@ purple_blist_find_chat(PurpleAccount *ac
PurpleChat *
purple_blist_find_chat(PurpleAccount *account, const char *name)
{
- char *chat_name;
+ const char *chat_name;
PurpleChat *chat;
PurplePlugin *prpl;
PurplePluginProtocolInfo *prpl_info = NULL;
@@ -1502,19 +1504,21 @@ purple_blist_find_chat(PurpleAccount *ac
chat = (PurpleChat*)node;
- if (account != chat->account)
+ if (account != purple_chat_get_account(chat))
continue;
parts = prpl_info->chat_info(
- purple_account_get_connection(chat->account));
+ purple_account_get_connection(purple_chat_get_account(chat)));
pce = parts->data;
- chat_name = g_hash_table_lookup(chat->components,
- pce->identifier);
+#warning not sure if this is right, old code below
+ chat_name = purple_chat_get_name(chat);
+/* chat_name = g_hash_table_lookup(chat->components,
+ pce->identifier);*/
g_list_foreach(parts, (GFunc)g_free, NULL);
g_list_free(parts);
- if (chat->account == account && chat_name != NULL &&
+ if (purple_chat_get_account(chat) == account && chat_name != NULL &&
normname != NULL && !strcmp(purple_normalize(account, chat_name), normname)) {
g_free(normname);
return chat;
============================================================
--- libpurple/blist.h 43ffa5b030dca0fad6550ae56950005a197a080d
+++ libpurple/blist.h 3ae362bbe097e323dbbf496b40969ada5b4a818a
@@ -117,22 +117,20 @@ struct _PurpleBlistUiOps
void (*_purple_reserved1)(void);
};
+void parse_setting(PurpleBlistNode *node, xmlnode *setting);
+void value_to_xmlnode(gpointer key, gpointer hvalue, gpointer user_data);
+gboolean purple_strings_are_different(const char *one, const char *two);
+
#ifdef _BLIST_HELPERS_
-void value_to_xmlnode(gpointer key, gpointer hvalue, gpointer user_data);
xmlnode *contact_to_xmlnode(PurpleBlistNode *cnode);
-xmlnode *chat_to_xmlnode(PurpleBlistNode *cnode);
xmlnode *buddy_to_xmlnode(PurpleBlistNode *bnode);
xmlnode *group_to_xmlnode(PurpleBlistNode *bnode);
PurpleBlistNode *purple_blist_get_last_sibling(PurpleBlistNode *node);
-PurpleBlistNode *purple_blist_get_last_child(PurpleBlistNode *node);
-void parse_setting(PurpleBlistNode *node, xmlnode *setting);
void parse_contact(PurpleGroup *group, xmlnode *cnode);
-void parse_chat(PurpleGroup *group, xmlnode *cnode);
void parse_buddy(PurpleGroup *group, PurpleContact *contact, xmlnode *bnode);
void parse_group(xmlnode *groupnode);
void purple_contact_compute_priority_buddy(PurpleContact *contact);
-gboolean purple_strings_are_different(const char *one, const char *two);
/* The global static members */
struct _list_account_buddies {
============================================================
--- libpurple/buddy.c b82ac2cda8d38d5ae788d7bf0a49dcce3e7e7cd9
+++ libpurple/buddy.c 29a366bd54cedfaab7b9ceb67a2a786f5c98bae1
@@ -607,7 +607,6 @@ purple_buddy_class_init(PurpleBuddyClass
parent_class = PURPLE_BLIST_NODE_CLASS(klass);
parent_class->is_online = purple_buddy_is_online;
-
parent_class = g_type_class_peek_parent(klass);
obj_class->finalize = purple_buddy_finalize;
@@ -639,7 +638,8 @@ purple_buddy_init(GTypeInstance *instanc
PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
PurpleBuddy *buddy = PURPLE_BUDDY(instance);
PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
-
+
+ buddy->priv = priv;
priv->presence = purple_presence_new_for_buddy(buddy);
purple_presence_set_status_active(priv->presence, "offline", TRUE);
============================================================
--- libpurple/chat.c 38ba33a0d999a7fdc7d562764138ae448640339e
+++ libpurple/chat.c e403fa1dad2fe7e4ad00db9a9b6493fba1c69f90
@@ -20,17 +20,23 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*
*/
-#define _PURPLE_CHAT_C
-#define _BLIST_HELPERS_
-
#include "internal.h"
-#include "chat.h"
#include "dbus-maybe.h"
#include "debug.h"
#include "server.h"
#include "signals.h"
#include "xmlnode.h"
+#include "chat.h"
+#include "blist.h"
+#define PURPLE_CHAT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PURPLE_CHAT_TYPE, PurpleChatPrivate))
+
+struct _PurpleChatPrivate {
+ char *alias; /**< The display name of this chat. */
+ GHashTable *components; /**< the stuff the protocol needs to know to join the chat */
+ PurpleAccount *account; /**< The account this chat is attached to */
+};
+
static void
chat_component_to_xmlnode(gpointer key, gpointer value, gpointer user_data)
{
@@ -54,21 +60,25 @@ chat_to_xmlnode(PurpleBlistNode *cnode)
{
xmlnode *node, *child;
PurpleChat *chat;
+ PurpleChatPrivate *priv;
- chat = (PurpleChat *)cnode;
+ g_return_val_if_fail(PURPLE_IS_CHAT(cnode), NULL);
+ chat = PURPLE_CHAT(cnode);
+ priv = PURPLE_CHAT_GET_PRIVATE(chat);
+
node = xmlnode_new("chat");
- xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(chat->account));
- xmlnode_set_attrib(node, "account", purple_account_get_username(chat->account));
+ xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(priv->account));
+ xmlnode_set_attrib(node, "account", purple_account_get_username(priv->account));
- if (chat->alias != NULL)
+ if (priv->alias != NULL)
{
child = xmlnode_new_child(node, "alias");
- xmlnode_insert_data(child, chat->alias, -1);
+ xmlnode_insert_data(child, priv->alias, -1);
}
/* Write chat components */
- g_hash_table_foreach(chat->components, chat_component_to_xmlnode, node);
+ g_hash_table_foreach(priv->components, chat_component_to_xmlnode, node);
/* Write chat settings */
g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(chat)), value_to_xmlnode, node);
@@ -128,23 +138,25 @@ void purple_chat_set_alias(PurpleChat *c
PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
char *old_alias;
char *new_alias = NULL;
+ PurpleChatPrivate *priv;
- g_return_if_fail(chat != NULL);
+ g_return_if_fail(PURPLE_IS_CHAT(chat));
+ priv = PURPLE_CHAT_GET_PRIVATE(chat);
if ((alias != NULL) && (*alias != '\0'))
new_alias = purple_utf8_strip_unprintables(alias);
- if (!purple_strings_are_different(chat->alias, new_alias)) {
+ if (!purple_strings_are_different(priv->alias, new_alias)) {
g_free(new_alias);
return;
}
- old_alias = chat->alias;
+ old_alias = priv->alias;
if ((new_alias != NULL) && (*new_alias != '\0'))
- chat->alias = new_alias;
+ priv->alias = new_alias;
else {
- chat->alias = NULL;
+ priv->alias = NULL;
g_free(new_alias); /* could be "\0" */
}
@@ -172,20 +184,22 @@ const char *purple_chat_get_name(PurpleC
char *ret = NULL;
PurplePlugin *prpl;
PurplePluginProtocolInfo *prpl_info = NULL;
+ PurpleChatPrivate *priv;
- g_return_val_if_fail(chat != NULL, NULL);
+ g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL);
+ priv = PURPLE_CHAT_GET_PRIVATE(chat);
- if ((chat->alias != NULL) && (*chat->alias != '\0'))
- return chat->alias;
+ if ((priv->alias != NULL) && (*priv->alias != '\0'))
+ return priv->alias;
- prpl = purple_find_prpl(purple_account_get_protocol_id(chat->account));
+ prpl = purple_find_prpl(purple_account_get_protocol_id(priv->account));
prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
if (prpl_info->chat_info) {
struct proto_chat_entry *pce;
- GList *parts = prpl_info->chat_info(purple_account_get_connection(chat->account));
+ GList *parts = prpl_info->chat_info(purple_account_get_connection(priv->account));
pce = parts->data;
- ret = g_hash_table_lookup(chat->components, pce->identifier);
+ ret = g_hash_table_lookup(priv->components, pce->identifier);
g_list_foreach(parts, (GFunc)g_free, NULL);
g_list_free(parts);
}
@@ -196,42 +210,51 @@ purple_chat_get_account(PurpleChat *chat
PurpleAccount *
purple_chat_get_account(PurpleChat *chat)
{
- g_return_val_if_fail(chat != NULL, NULL);
+ PurpleChatPrivate *priv;
+ g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL);
+ priv = PURPLE_CHAT_GET_PRIVATE(chat);
- return chat->account;
+ return priv->account;
}
static void
purple_chat_set_account(PurpleChat *chat, PurpleAccount *account)
{
- g_return_if_fail(chat != NULL);
+ PurpleChatPrivate *priv;
+ g_return_if_fail(PURPLE_IS_CHAT(chat));
+ priv = PURPLE_CHAT_GET_PRIVATE(chat);
- chat->account = account;
+ priv->account = account;
}
GHashTable *
purple_chat_get_components(PurpleChat *chat)
{
- g_return_val_if_fail(chat != NULL, NULL);
+ PurpleChatPrivate *priv;
+ g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL);
+ priv = PURPLE_CHAT_GET_PRIVATE(chat);
- return chat->components;
+ return priv->components;
}
static void
purple_chat_set_components(PurpleChat *chat, GHashTable *components)
{
- g_return_if_fail(chat != NULL);
+ PurpleChatPrivate *priv;
+ g_return_if_fail(PURPLE_IS_CHAT(chat));
+ priv = PURPLE_CHAT_GET_PRIVATE(chat);
- chat->components = components;
+ priv->components = components;
}
static gboolean
purple_chat_is_online(PurpleBlistNode *node)
{
- PurpleChat *chat;
+ PurpleChatPrivate *priv;
+ g_return_val_if_fail(PURPLE_IS_CHAT(node), FALSE);
+ priv = PURPLE_CHAT_GET_PRIVATE(PURPLE_CHAT(node));
- g_return_val_if_fail(node, FALSE);
- return purple_account_is_connected(PURPLE_CHAT(chat)->account);
+ return purple_account_is_connected(priv->account);
}
/******************/
@@ -271,8 +294,9 @@ purple_chat_finalize(GObject *object)
purple_chat_finalize(GObject *object)
{
PurpleChat *chat = PURPLE_CHAT(object);
- g_hash_table_destroy(chat->components);
- g_free(chat->alias);
+ PurpleChatPrivate *priv = PURPLE_CHAT_GET_PRIVATE(chat);
+ g_hash_table_destroy(priv->components);
+ g_free(priv->alias);
PURPLE_DBUS_UNREGISTER_POINTER(chat);
G_OBJECT_CLASS(parent_class)->finalize(object);
}
@@ -333,6 +357,8 @@ purple_chat_class_init(PurpleChatClass *
obj_class->get_property = purple_chat_get_property;
obj_class->set_property = purple_chat_set_property;
+ g_type_class_add_private(klass, sizeof(PurpleChatPrivate));
+
g_object_class_install_property(obj_class, PROP_ALIAS,
g_param_spec_string(PROP_ALIAS_S, _("Alias"),
_("The alias for the chat."), NULL,
@@ -355,7 +381,7 @@ purple_chat_get_group(PurpleChat *chat)
PurpleGroup *
purple_chat_get_group(PurpleChat *chat)
{
- g_return_val_if_fail(chat != NULL, NULL);
+ g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL);
return PURPLE_GROUP(purple_blist_node_find_container(PURPLE_BLIST_NODE(chat), PURPLE_GROUP_TYPE));
}
@@ -366,6 +392,8 @@ purple_chat_init(GTypeInstance *instance
PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
PurpleChat *chat = PURPLE_CHAT(instance);
+ chat->priv = PURPLE_CHAT_GET_PRIVATE(chat);
+
if (ops != NULL && ops->new_node != NULL)
ops->new_node(PURPLE_BLIST_NODE(chat));
============================================================
--- libpurple/chat.h e199901f0b0b69575d240498d2365644445d7df4
+++ libpurple/chat.h 670af1dfb25d69940059bdf57fa79b38a4b51ed6
@@ -27,13 +27,15 @@
#ifndef _PURPLE_CHAT_H_
#define _PURPLE_CHAT_H_
-#include <glib.h>
/** @copydoc _PurpleChat */
typedef struct _PurpleChat PurpleChat;
+typedef struct _PurpleChatPrivate PurpleChatPrivate;
typedef struct _PurpleChatClass PurpleChatClass;
#include "blist-node.h"
+#include "account.h"
+#include "xmlnode.h"
#define PURPLE_CHAT_TYPE (purple_chat_get_type ())
#define PURPLE_CHAT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_CHAT_TYPE, PurpleChat))
@@ -42,23 +44,18 @@ typedef struct _PurpleChatClass PurpleCh
#define PURPLE_IS_CHAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_CHAT_TYPE))
#define PURPLE_GET_CHAT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_CHAT_TYPE, PurpleChatClass))
-#if !(defined PURPLE_HIDE_STRUCTS) || (defined _PURPLE_CHAT_C_)
-
/**
* A chat. This contains everything Purple needs to put a chat room in the
* buddy list.
*/
struct _PurpleChat {
PurpleBlistNode node; /**< The node that this chat inherits from */
- char *alias; /**< The display name of this chat. */
- GHashTable *components; /**< the stuff the protocol needs to know to join the chat */
- PurpleAccount *account; /**< The account this chat is attached to */
+ PurpleChatPrivate *priv;
};
struct _PurpleChatClass {
PurpleBlistNodeClass parent;
};
-#endif
/**
* Creates a new chat for the buddy list
@@ -131,4 +128,6 @@ GType purple_chat_get_type(void);
*/
GType purple_chat_get_type(void);
+xmlnode *chat_to_xmlnode(PurpleBlistNode *cnode);
+void parse_chat(PurpleGroup *group, xmlnode *cnode);
#endif
============================================================
--- libpurple/group.c f9d6f29ddb66545b1cd9ac9c53f9e380727d5068
+++ libpurple/group.c f6ed937d8e00158a9d5fb43cafad49ee34a65066
@@ -77,8 +77,8 @@ GSList *purple_group_get_accounts(Purple
for (cnode = gnode->child; cnode; cnode = cnode->next) {
if (PURPLE_IS_CHAT(cnode)) {
- if (!g_slist_find(l, ((PurpleChat *)cnode)->account))
- l = g_slist_append(l, ((PurpleChat *)cnode)->account);
+ if (!g_slist_find(l, purple_chat_get_account(PURPLE_CHAT(cnode))))
+ l = g_slist_append(l, purple_chat_get_account(PURPLE_CHAT(cnode)));
} else if (PURPLE_IS_CONTACT(cnode)) {
for (bnode = cnode->child; bnode; bnode = bnode->next) {
if (PURPLE_IS_BUDDY(bnode)) {
@@ -103,7 +103,7 @@ purple_group_child_updated(PurpleGroup *
if(PURPLE_IS_CHAT(child)){
chat = PURPLE_CHAT(child);
- if (purple_account_is_connected(chat->account)) {
+ if (purple_account_is_connected(purple_chat_get_account(chat))) {
group->online++;
group->currentsize++;
}
@@ -135,7 +135,7 @@ purple_group_add_child_helper(PurpleGrou
if(PURPLE_IS_CHAT(child)){
chat = PURPLE_CHAT(child);
- if (purple_account_is_connected(chat->account)) {
+ if (purple_account_is_connected(purple_chat_get_account(chat))) {
group->online++;
group->currentsize++;
}
@@ -197,7 +197,7 @@ purple_group_remove_node(PurpleBlistNode
if(PURPLE_IS_CHAT(child)){
chat = PURPLE_CHAT(child);
- if (purple_account_is_connected(chat->account)) {
+ if (purple_account_is_connected(purple_chat_get_account(chat))) {
group->online--;
group->currentsize--;
}
More information about the Commits
mailing list