/soc/2013/ankitkv/gobjectification: 1feefa206b17: Started GObjec...

Ankit Vani a at nevitus.org
Fri Jul 19 04:26:16 EDT 2013


Changeset: 1feefa206b171aa5a63843eb19746b506fafb29d
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-19 13:55 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/1feefa206b17

Description:

Started GObjectification of PurpleBuddyIcon.
Removed purple_buddy_icon_ref() and purple_buddy_icon_unref()

diffstat:

 libpurple/buddyicon.c |  39 +++++---------------------------
 libpurple/buddyicon.h |  60 ++++++++++++++++++++++++++++----------------------
 2 files changed, 40 insertions(+), 59 deletions(-)

diffs (152 lines):

diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -33,17 +33,19 @@
 #include "imgstore.h"
 #include "util.h"
 
-/* NOTE: Instances of this struct are allocated without zeroing the memory, so
- * NOTE: be sure to update purple_buddy_icon_new() if you add members. */
-struct _PurpleBuddyIcon
+#define PURPLE_BUDDY_ICON_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_BUDDY_ICON, PurpleBuddyIconPrivate))
+
+/** Private data for buddy icons */
+typedef struct
 {
 	PurpleAccount *account;    /**< The account the user is on.          */
 	PurpleStoredImage *img;    /**< The stored image containing
 	                                the icon data.                       */
 	char *username;            /**< The username the icon belongs to.    */
 	char *checksum;            /**< The protocol checksum.               */
-	unsigned int ref_count;    /**< The buddy icon reference count.      */
-};
+
+} PurpleBuddyIconPrivate;
 
 /**
  * This is the big grand daddy hash table that contains references to
@@ -1131,30 +1133,3 @@ void purple_buddy_icon_get_scale_size(Pu
 	*width = new_width;
 	*height = new_height;
 }
-
-static PurpleBuddyIcon *
-purple_buddy_icon_copy(PurpleBuddyIcon *icon)
-{
-	PurpleBuddyIcon *icon_copy;
-
-	g_return_val_if_fail(icon != NULL, NULL);
-
-	icon_copy = g_new(PurpleBuddyIcon, 1);
-	*icon_copy = *icon;
-
-	return icon_copy;
-}
-
-GType
-purple_buddy_icon_get_type(void)
-{
-	static GType type = 0;
-
-	if (type == 0) {
-		type = g_boxed_type_register_static("PurpleBuddyIcon",
-				(GBoxedCopyFunc)purple_buddy_icon_copy,
-				(GBoxedFreeFunc)g_free);
-	}
-
-	return type;
-}
diff --git a/libpurple/buddyicon.h b/libpurple/buddyicon.h
--- a/libpurple/buddyicon.h
+++ b/libpurple/buddyicon.h
@@ -26,14 +26,17 @@
 #ifndef _PURPLE_BUDDYICON_H_
 #define _PURPLE_BUDDYICON_H_
 
-#define PURPLE_TYPE_BUDDY_ICON (purple_buddy_icon_get_type())
+#define PURPLE_TYPE_BUDDY_ICON             (purple_buddy_icon_get_type())
+#define PURPLE_BUDDY_ICON(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BUDDY_ICON, PurpleBuddyIcon))
+#define PURPLE_BUDDY_ICON_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BUDDY_ICON, PurpleBuddyIconClass))
+#define PURPLE_IS_BUDDY_ICON(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BUDDY_ICON))
+#define PURPLE_IS_BUDDY_ICON_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BUDDY_ICON))
+#define PURPLE_BUDDY_ICON_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BUDDY_ICON, PurpleBuddyIconClass))
 
-/** An opaque structure representing a buddy icon for a particular user on a
- *  particular #PurpleAccount.  Instances are reference-counted; use
- *  purple_buddy_icon_ref() and purple_buddy_icon_unref() to take and release
- *  references.
- */
+/** @copydoc _PurpleBuddyIcon */
 typedef struct _PurpleBuddyIcon PurpleBuddyIcon;
+/** @copydoc _PurpleBuddyIconClass */
+typedef struct _PurpleBuddyIconClass PurpleBuddyIconClass;
 
 #include "account.h"
 #include "buddylist.h"
@@ -41,6 +44,29 @@ typedef struct _PurpleBuddyIcon PurpleBu
 #include "prpl.h"
 #include "util.h"
 
+/** An object representing a buddy icon for a particular user on a particular
+ *  #PurpleAccount.  Use g_object_ref() and g_object_unref() to take and release
+ *  references.
+ */
+struct _PurpleBuddyIcon
+{
+	/*< private >*/
+	GObject gparent;
+};
+
+/**
+ * The base class for all #PurpleBuddyIcon's.
+ */
+struct _PurpleBuddyIconClass {
+	/*< private >*/
+	GObjectClass parent_class;
+
+	void (*_purple_reserved1)(void);
+	void (*_purple_reserved2)(void);
+	void (*_purple_reserved3)(void);
+	void (*_purple_reserved4)(void);
+};
+
 G_BEGIN_DECLS
 
 /**************************************************************************/
@@ -49,9 +75,7 @@ G_BEGIN_DECLS
 /*@{*/
 
 /**
- * Returns the GType for the PurpleBuddyIcon boxed structure.
- * TODO Boxing of PurpleBuddyIcon is a temporary solution to having a GType for
- *      icons. This should rather be a GObject instead of a GBoxed.
+ * Returns the GType for the PurpleBuddyIcon object.
  */
 GType purple_buddy_icon_get_type(void);
 
@@ -74,24 +98,6 @@ PurpleBuddyIcon *purple_buddy_icon_new(P
                                        const char *checksum);
 
 /**
- * Increments the reference count on a buddy icon.
- *
- * @param icon The buddy icon.
- *
- * @return @a icon.
- */
-PurpleBuddyIcon *purple_buddy_icon_ref(PurpleBuddyIcon *icon);
-
-/**
- * Decrements the reference count on a buddy icon.
- *
- * If the reference count reaches 0, the icon will be destroyed.
- *
- * @param icon The buddy icon.
- */
-void purple_buddy_icon_unref(PurpleBuddyIcon *icon);
-
-/**
  * Updates every instance of this icon.
  *
  * @param icon The buddy icon.



More information about the Commits mailing list