/soc/2013/ankitkv/gobjectification: 9d1d1e5d19b4: GObjectified P...
Ankit Vani
a at nevitus.org
Sun Jul 7 15:11:47 EDT 2013
Changeset: 9d1d1e5d19b494e6bd01642bce73841df736a6cf
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-07 13:10 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/9d1d1e5d19b4
Description:
GObjectified PurpleBuddy.
* Added purple_buddy_set_name()
* Added purple_buddy_set_server_alias()
* Renamed purple_buddy_get_local_buddy_alias() to purple_buddy_get_local_alias()
* Added purple_buddy_set_local_alias()
diffstat:
libpurple/blistnodetypes.c | 613 ++++++++++++++++++++++++++++++++------------
libpurple/blistnodetypes.h | 52 ++-
2 files changed, 482 insertions(+), 183 deletions(-)
diffs (truncated from 901 to 300 lines):
diff --git a/libpurple/blistnodetypes.c b/libpurple/blistnodetypes.c
--- a/libpurple/blistnodetypes.c
+++ b/libpurple/blistnodetypes.c
@@ -52,7 +52,7 @@ typedef struct _PurpleChatPrivate
/** Private data for a buddy. */
struct _PurpleBuddyPrivate {
char *name; /**< The name of the buddy. */
- char *alias; /**< The user-set alias of the buddy */
+ char *local_alias; /**< The user-set alias of the buddy */
char *server_alias; /**< The server-specified alias of the buddy.
(i.e. MSN "Friendly Names") */
void *proto_data; /**< TODO remove - use protocol subclasses
@@ -64,6 +64,20 @@ struct _PurpleBuddyPrivate {
PurpleMediaCaps media_caps; /**< The media capabilities of the buddy. */
};
+/* Buddy property enums */
+enum
+{
+ BUDDY_PROP_0,
+ BUDDY_PROP_NAME,
+ BUDDY_PROP_LOCAL_ALIAS,
+ BUDDY_PROP_SERVER_ALIAS,
+ BUDDY_PROP_ICON,
+ BUDDY_PROP_ACCOUNT,
+ BUDDY_PROP_PRESENCE,
+ BUDDY_PROP_MEDIA_CAPS,
+ BUDDY_PROP_LAST
+};
+
/** Private data for a contact TODO: move counts to PurpleCountingNode */
struct _PurpleContactPrivate {
char *alias; /**< The user-set alias of the contact */
@@ -72,10 +86,19 @@ struct _PurpleContactPrivate {
corresponding to online accounts */
int online; /**< The number of buddies in this contact who
are currently online */
- PurpleBuddy *priority; /**< The "top" buddy for this contact */
+ PurpleBuddy *priority; /**< TODO rename to priority_buddy
+ The "top" buddy for this contact */
gboolean priority_valid; /**< Is priority valid? */
};
+/* Contact property enums */
+enum
+{
+ CONTACT_PROP_0,
+ CONTACT_PROP_ALIAS,
+ CONTACT_PROP_PRIORITY_BUDDY,
+ CONTACT_PROP_LAST
+};
/** Private data for a group TODO: move counts to PurpleCountingNode */
struct _PurpleGroupPrivate {
@@ -87,6 +110,14 @@ struct _PurpleGroupPrivate {
are currently online */
};
+/* Group property enums */
+enum
+{
+ GROUP_PROP_0,
+ GROUP_PROP_NAME,
+ GROUP_PROP_LAST
+};
+
/** Private data for a chat node */
struct _PurpleChatPrivate {
char *alias; /**< The display name of this chat. */
@@ -95,74 +126,21 @@ struct _PurpleChatPrivate {
PurpleAccount *account; /**< The account this chat is attached to */
};
+/* Chat property enums */
+enum
+{
+ CHAT_PROP_0,
+ CHAT_PROP_ALIAS,
+ CHAT_PROP_ACCOUNT,
+ CHAT_PROP_LAST
+};
+
+static PurpleBListNode *parent_class;
+
/**************************************************************************/
/* Buddy API */
/**************************************************************************/
-/* TODO GObjectify */
-PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name, const char *alias)
-{
- PurpleBListUiOps *ops = purple_blist_get_ui_ops();
- PurpleBuddy *buddy;
-
- g_return_val_if_fail(account != NULL, NULL);
- g_return_val_if_fail(name != NULL, NULL);
-
- buddy = g_new0(PurpleBuddy, 1);
- buddy->account = account;
- buddy->name = purple_utf8_strip_unprintables(name);
- buddy->alias = purple_utf8_strip_unprintables(alias);
- buddy->presence = purple_presence_new_for_buddy(buddy);
- ((PurpleBListNode *)buddy)->type = PURPLE_BLIST_BUDDY_NODE;
-
- purple_presence_set_status_active(buddy->presence, "offline", TRUE);
-
- purple_blist_node_initialize_settings((PurpleBListNode *)buddy);
-
- if (ops && ops->new_node)
- ops->new_node((PurpleBListNode *)buddy);
-
- PURPLE_DBUS_REGISTER_POINTER(buddy, PurpleBuddy);
- return buddy;
-}
-
-/* TODO GObjectify */
-void
-purple_buddy_destroy(PurpleBuddy *buddy)
-{
- PurplePlugin *prpl;
- PurplePluginProtocolInfo *prpl_info;
-
- /*
- * Tell the owner PRPL that we're about to free the buddy so it
- * can free proto_data
- */
- prpl = purple_find_prpl(purple_account_get_protocol_id(buddy->account));
- if (prpl) {
- prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
- if (prpl_info && prpl_info->buddy_free)
- prpl_info->buddy_free(buddy);
- }
-
- /* Delete the node */
- purple_buddy_icon_unref(buddy->icon);
- g_hash_table_destroy(buddy->node.settings);
- purple_presence_destroy(buddy->presence);
- g_free(buddy->name);
- g_free(buddy->alias);
- g_free(buddy->server_alias);
-
- PURPLE_DBUS_UNREGISTER_POINTER(buddy);
- g_free(buddy);
-
- /* FIXME: Once PurpleBuddy is a GObject, timeout callbacks can
- * g_object_ref() it when connecting the callback and
- * g_object_unref() it in the handler. That way, it won't
- * get freed while the timeout is pending and this line can
- * be removed. */ /* TODO do this */
- while (g_source_remove_by_user_data((gpointer *)buddy));
-}
-
void
purple_buddy_set_icon(PurpleBuddy *buddy, PurpleBuddyIcon *icon)
{
@@ -181,6 +159,16 @@ purple_buddy_set_icon(PurpleBuddy *buddy
purple_blist_update_node_icon(PURPLE_BLIST_NODE(buddy));
}
+PurpleBuddyIcon *
+purple_buddy_get_icon(const PurpleBuddy *buddy)
+{
+ PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return priv->icon;
+}
+
PurpleAccount *
purple_buddy_get_account(const PurpleBuddy *buddy)
{
@@ -191,6 +179,16 @@ purple_buddy_get_account(const PurpleBud
return priv->account;
}
+void
+purple_buddy_set_name(PurpleBuddy *buddy, const char *name)
+{
+ PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
+
+ g_return_if_fail(priv != NULL);
+
+ priv->name = purple_utf8_strip_unprintables(name);
+}
+
const char *
purple_buddy_get_name(const PurpleBuddy *buddy)
{
@@ -201,16 +199,6 @@ purple_buddy_get_name(const PurpleBuddy
return priv->name;
}
-PurpleBuddyIcon *
-purple_buddy_get_icon(const PurpleBuddy *buddy)
-{
- PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
-
- g_return_val_if_fail(priv != NULL, NULL);
-
- return priv->icon;
-}
-
gpointer
purple_buddy_get_protocol_data(const PurpleBuddy *buddy)
{
@@ -237,8 +225,8 @@ const char *purple_buddy_get_alias_only(
g_return_val_if_fail(priv != NULL, NULL);
- if ((priv->alias != NULL) && (*priv->alias != '\0')) {
- return priv->alias;
+ if ((priv->local_alias != NULL) && (*priv->local_alias != '\0')) {
+ return priv->local_alias;
} else if ((priv->server_alias != NULL) &&
(*priv->server_alias != '\0')) {
@@ -248,7 +236,6 @@ const char *purple_buddy_get_alias_only(
return NULL;
}
-
const char *purple_buddy_get_contact_alias(PurpleBuddy *buddy)
{
PurpleContact *c;
@@ -257,9 +244,9 @@ const char *purple_buddy_get_contact_ali
g_return_val_if_fail(priv != NULL, NULL);
/* Search for an alias for the buddy. In order of precedence: */
- /* The buddy alias */
- if (priv->alias != NULL)
- return priv->alias;
+ /* The local buddy alias */
+ if (priv->local_alias != NULL)
+ return priv->local_alias;
/* The contact alias */
c = purple_buddy_get_contact(buddy);
@@ -274,7 +261,6 @@ const char *purple_buddy_get_contact_ali
return priv->name;
}
-
const char *purple_buddy_get_alias(PurpleBuddy *buddy)
{
PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
@@ -283,8 +269,8 @@ const char *purple_buddy_get_alias(Purpl
/* Search for an alias for the buddy. In order of precedence: */
/* The buddy alias */
- if (priv->alias != NULL)
- return priv->alias;
+ if (priv->local_alias != NULL)
+ return priv->local_alias;
/* The server alias */
if ((priv->server_alias) && (*priv->server_alias))
@@ -294,13 +280,33 @@ const char *purple_buddy_get_alias(Purpl
return priv->name;
}
-const char *purple_buddy_get_local_buddy_alias(PurpleBuddy *buddy)
+void
+purple_buddy_set_local_alias(PurpleBuddy *buddy, const char *alias)
{
PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
- g_return_val_if_fail(priv, NULL);
+ g_return_if_fail(priv != NULL);
- return priv->alias;
+ priv->local_alias = purple_utf8_strip_unprintables(alias);
+}
+
+const char *purple_buddy_get_local_alias(PurpleBuddy *buddy)
+{
+ PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return priv->local_alias;
+}
+
+void
+purple_buddy_set_server_alias(PurpleBuddy *buddy, const char *server_alias)
+{
+ PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
+
+ g_return_if_fail(priv != NULL);
+
+ priv->server_alias = purple_utf8_strip_unprintables(server_alias);
}
const char *purple_buddy_get_server_alias(PurpleBuddy *buddy)
@@ -359,6 +365,255 @@ PurpleGroup *purple_buddy_get_group(Purp
return PURPLE_GROUP(PURPLE_BLIST_NODE(buddy)->parent->parent);
}
+/**************************************************************************
+ * GObject code for PurpleBuddy
More information about the Commits
mailing list