/soc/2013/ankitkv/gobjectification: 289bc0df25bb: API changes fo...
Ankit Vani
a at nevitus.org
Fri Jul 19 15:53:15 EDT 2013
Changeset: 289bc0df25bb21679ca7bc3f4e8f4e94642d03c9
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-20 01:23 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/289bc0df25bb
Description:
API changes for PurplePresence. See details.
* Removed PurplePresenceContext.
* Subclasses of PurplePresence: PurpleAccountPresence, PurpleConversationPresence, PurpleBuddyPresence
* Removed purple_presence_new(), use subclass's new methods
* Removed purple_presence_destroy(), use g_object_unref()
* purple_presence_new_for_account() is now purple_account_presence_new()
* purple_presence_new_for_conv() is now purple_conversation_presence_new()
* purple_presence_new_for_buddy() is now purple_buddy_presence_new()
* Removed purple_presence_get_chat_user()
* purple_presence_get_account() is now purple_account_presence_get_account()
* purple_presence_get_conversation() is now purple_conversation_presence_get_conversation()
* purple_presence_get_buddy() is now purple_buddy_presence_get_buddy()
diffstat:
libpurple/blistnodetypes.c | 8 +-
libpurple/presence.c | 53 +++++++----
libpurple/presence.h | 205 +++++++++++++++++++++++++++-----------------
3 files changed, 162 insertions(+), 104 deletions(-)
diffs (truncated from 370 to 300 lines):
diff --git a/libpurple/blistnodetypes.c b/libpurple/blistnodetypes.c
--- a/libpurple/blistnodetypes.c
+++ b/libpurple/blistnodetypes.c
@@ -587,8 +587,7 @@ purple_buddy_get_property(GObject *obj,
g_value_set_object(value, purple_buddy_get_account(buddy));
break;
case BUDDY_PROP_PRESENCE:
-#warning TODO: change set_pointer to set_object when PurplePresence is a GObject
- g_value_set_pointer(value, purple_buddy_get_presence(buddy));
+ g_value_set_object(value, purple_buddy_get_presence(buddy));
break;
case BUDDY_PROP_MEDIA_CAPS:
g_value_set_enum(value, purple_buddy_get_media_caps(buddy));
@@ -710,10 +709,9 @@ static void purple_buddy_class_init(Purp
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)
);
-#warning TODO: change spec_pointer to spec_object when PurplePresence is a GObject
g_object_class_install_property(obj_class, BUDDY_PROP_PRESENCE,
- g_param_spec_pointer(BUDDY_PROP_PRESENCE_S, _("Presence"),
- _("The status information for the buddy."),
+ g_param_spec_object(BUDDY_PROP_PRESENCE_S, _("Presence"),
+ _("The status information for the buddy."), PURPLE_TYPE_PRESENCE,
G_PARAM_READABLE)
);
diff --git a/libpurple/presence.c b/libpurple/presence.c
--- a/libpurple/presence.c
+++ b/libpurple/presence.c
@@ -26,11 +26,27 @@
/** @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_CONVERSATION_PRESENCE_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_CONVERSATION_PRESENCE, PurpleConversationPresencePrivate))
+
+/** @copydoc _PurpleConversationPresencePrivate */
+typedef struct _PurpleConversationPresencePrivate PurpleConversationPresencePrivate;
+
+#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
{
- PurplePresenceContext context;
-
gboolean idle;
time_t idle_time;
time_t login_time;
@@ -39,27 +55,24 @@ struct _PurplePresencePrivate
GHashTable *status_table;
PurpleStatus *active_status;
+};
- union
- {
- PurpleAccount *account;
+/** Private data for an account presence */
+struct _PurpleAccountPresencePrivate
+{
+ PurpleAccount *account;
+};
- struct
- {
- PurpleConversation *conv;
- char *user;
+/** Private data for a conversation presence */
+struct _PurpleConversationPresencePrivate
+{
+ PurpleConversation *conv;
+};
- } chat;
-
- struct
- {
- PurpleAccount *account;
- char *name;
- PurpleBuddy *buddy;
-
- } buddy;
-
- } u;
+/** Private data for a buddy presence */
+struct _PurpleBuddyPresencePrivate
+{
+ PurpleBuddy *buddy;
};
/**************************************************************************
diff --git a/libpurple/presence.h b/libpurple/presence.h
--- a/libpurple/presence.h
+++ b/libpurple/presence.h
@@ -33,19 +33,20 @@ typedef struct _PurplePresence PurplePr
/** @copydoc _PurplePresenceClass */
typedef struct _PurplePresenceClass PurplePresenceClass;
-/** TODO Remove
- * A context for a presence.
- *
- * The context indicates to what the presence applies.
- */
-typedef enum
-{
- PURPLE_PRESENCE_CONTEXT_UNSET = 0,
- PURPLE_PRESENCE_CONTEXT_ACCOUNT,
- PURPLE_PRESENCE_CONTEXT_CONV,
- PURPLE_PRESENCE_CONTEXT_BUDDY
+/** @copydoc _PurpleAccountPresence */
+typedef struct _PurpleAccountPresence PurpleAccountPresence;
+/** @copydoc _PurpleAccountPresenceClass */
+typedef struct _PurpleAccountPresenceClass PurpleAccountPresenceClass;
-} PurplePresenceContext;
+/** @copydoc _PurpleConversationPresence */
+typedef struct _PurpleConversationPresence PurpleConversationPresence;
+/** @copydoc _PurpleConversationPresenceClass */
+typedef struct _PurpleConversationPresenceClass PurpleConversationPresenceClass;
+
+/** @copydoc _PurpleBuddyPresence */
+typedef struct _PurpleBuddyPresence PurpleBuddyPresence;
+/** @copydoc _PurpleBuddyPresenceClass */
+typedef struct _PurpleBuddyPresenceClass PurpleBuddyPresenceClass;
/**
* A PurplePresence is like a collection of PurpleStatuses (plus some
@@ -57,6 +58,9 @@ typedef enum
* 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
{
@@ -75,58 +79,147 @@ struct _PurplePresenceClass {
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 conversation
+ */
+struct _PurpleConversationPresence
+{
+ /*< private >*/
+ PurplePresence parent;
+};
+
+/** Base class for all #PurpleConversationPresence's */
+struct _PurpleConversationPresenceClass {
+ /*< 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 PurplePresence API */
+/** @name PurpleAccountPresence API */
/**************************************************************************/
/*@{*/
/**
- * Creates a new presence.
- *
- * @param context The presence context.
- *
- * @return A new presence.
- */
-PurplePresence *purple_presence_new(PurplePresenceContext context);
-
-/**
* Creates a presence for an account.
*
- * @param account The account.
+ * @param account The account to associate with the presence.
*
* @return The new presence.
*/
-PurplePresence *purple_presence_new_for_account(PurpleAccount *account);
+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 PurpleConversationPresence API */
+/**************************************************************************/
+/*@{*/
/**
* Creates a presence for a conversation.
*
- * @param conv The conversation.
+ * @param conv The conversation to associate with the presence.
*
* @return The new presence.
*/
-PurplePresence *purple_presence_new_for_conv(PurpleConversation *conv);
+PurpleConversationPresence *purple_conversation_presence_new(PurpleConversation *conv);
+
+/**
+ * Returns a conversation presence's conversation.
+ *
+ * @param presence The presence.
+ *
+ * @return The presence's conversation.
+ */
+PurpleConversation *purple_conversation_presence_get_conversation(const PurpleConversationPresence *presence);
+
+/*@}*/
+
+/**************************************************************************/
+/** @name PurpleBuddyPresence API */
+/**************************************************************************/
+/*@{*/
/**
* Creates a presence for a buddy.
*
- * @param buddy The buddy.
+ * @param buddy The buddy to associate with the presence.
*
* @return The new presence.
*/
-PurplePresence *purple_presence_new_for_buddy(PurpleBuddy *buddy);
+PurpleBuddyPresence *purple_buddy_presence_new(PurpleBuddy *buddy);
/**
- * Destroys a presence.
+ * Returns the buddy presence's buddy.
*
- * All statuses added to this list will be destroyed along with
- * the presence.
More information about the Commits
mailing list