/soc/2013/ankitkv/gobjectification: 3662bb1c9435: Backed out cha...
Ankit Vani
a at nevitus.org
Fri Jul 19 12:29:30 EDT 2013
Changeset: 3662bb1c943551e1aae8e58d7f14d7c100327fd8
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-19 21:53 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/3662bb1c9435
Description:
Backed out changeset 1feefa206b17
diffstat:
libpurple/buddyicon.c | 39 +++++++++++++++++++++++++++-----
libpurple/buddyicon.h | 60 ++++++++++++++++++++++----------------------------
2 files changed, 59 insertions(+), 40 deletions(-)
diffs (152 lines):
diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -33,19 +33,17 @@
#include "imgstore.h"
#include "util.h"
-#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
+/* 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
{
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. */
-
-} PurpleBuddyIconPrivate;
+ unsigned int ref_count; /**< The buddy icon reference count. */
+};
/**
* This is the big grand daddy hash table that contains references to
@@ -1133,3 +1131,30 @@ 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,17 +26,14 @@
#ifndef _PURPLE_BUDDYICON_H_
#define _PURPLE_BUDDYICON_H_
-#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))
+#define PURPLE_TYPE_BUDDY_ICON (purple_buddy_icon_get_type())
-/** @copydoc _PurpleBuddyIcon */
+/** 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.
+ */
typedef struct _PurpleBuddyIcon PurpleBuddyIcon;
-/** @copydoc _PurpleBuddyIconClass */
-typedef struct _PurpleBuddyIconClass PurpleBuddyIconClass;
#include "account.h"
#include "buddylist.h"
@@ -44,29 +41,6 @@ typedef struct _PurpleBuddyIconClass Pur
#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
/**************************************************************************/
@@ -75,7 +49,9 @@ G_BEGIN_DECLS
/*@{*/
/**
- * Returns the GType for the PurpleBuddyIcon object.
+ * 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.
*/
GType purple_buddy_icon_get_type(void);
@@ -98,6 +74,24 @@ 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