/soc/2013/ankitkv/gobjectification: 8417ea6a9235: Started GObjec...

Ankit Vani a at nevitus.org
Sun Jul 21 04:43:16 EDT 2013


Changeset: 8417ea6a9235e8b09f08994e47c60cbb3f73d4aa
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-21 14:13 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/8417ea6a9235

Description:

Started GObjectification of PurpleStatus.
Renamed purple_status_get_type() to purple_status_get_status_type().

diffstat:

 libpurple/status.c |  44 +++++++++++++++-----------
 libpurple/status.h |  90 ++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 93 insertions(+), 41 deletions(-)

diffs (truncated from 334 to 300 lines):

diff --git a/libpurple/status.c b/libpurple/status.c
--- a/libpurple/status.c
+++ b/libpurple/status.c
@@ -27,6 +27,12 @@
 #include "prefs.h"
 #include "status.h"
 
+#define PURPLE_STATUS_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_STATUS, PurpleStatusPrivate))
+
+/** @copydoc _PurpleStatusPrivate */
+typedef struct _PurpleStatusPrivate  PurpleStatusPrivate;
+
 /**
  * A type of status.
  */
@@ -55,9 +61,9 @@ struct _PurpleStatusAttr
 };
 
 /**
- * An active status.
+ * Private data for PurpleStatus
  */
-struct _PurpleStatus
+struct _PurpleStatusPrivate
 {
 	PurpleStatusType *type;
 	PurplePresence *presence;
@@ -491,10 +497,10 @@ purple_status_new(PurpleStatusType *stat
 	status = g_new0(PurpleStatus, 1);
 	PURPLE_DBUS_REGISTER_POINTER(status, PurpleStatus);
 
-	status->type     = status_type;
-	status->presence = presence;
+	priv->type     = status_type;
+	priv->presence = presence;
 
-	status->attr_values =
+	priv->attr_values =
 		g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
 		(GDestroyNotify)purple_g_value_free);
 
@@ -504,7 +510,7 @@ purple_status_new(PurpleStatusType *stat
 		GValue *value = purple_status_attr_get_value(attr);
 		GValue *new_value = purple_g_value_dup(value);
 
-		g_hash_table_insert(status->attr_values,
+		g_hash_table_insert(priv->attr_values,
 							(char *)purple_status_attr_get_id(attr),
 							new_value);
 	}
@@ -521,7 +527,7 @@ purple_status_destroy(PurpleStatus *stat
 {
 	g_return_if_fail(status != NULL);
 
-	g_hash_table_destroy(status->attr_values);
+	g_hash_table_destroy(priv->attr_values);
 
 	PURPLE_DBUS_UNREGISTER_POINTER(status);
 	g_free(status);
@@ -621,7 +627,7 @@ status_has_changed(PurpleStatus *status)
 	{
 		old_status = purple_presence_get_active_status(presence);
 		if (old_status != NULL && (old_status != status))
-			old_status->active = FALSE;
+			old_priv->active = FALSE;
 		g_object_set(presence, "active-status", status, NULL);
 	}
 	else
@@ -740,12 +746,12 @@ purple_status_set_active_with_attrs_list
 		return;
 	}
 
-	if (status->active != active)
+	if (priv->active != active)
 	{
 		changed = TRUE;
 	}
 
-	status->active = active;
+	priv->active = active;
 
 	/* Set any attributes */
 	l = attrs;
@@ -760,7 +766,7 @@ purple_status_set_active_with_attrs_list
 		if (value == NULL)
 		{
 			purple_debug_warning("status", "The attribute \"%s\" on the status \"%s\" is "
-							   "not supported.\n", id, status->type->name);
+							   "not supported.\n", id, priv->type->name);
 			/* Skip over the data and move on to the next attribute */
 			l = l->next;
 			continue;
@@ -850,11 +856,11 @@ purple_status_set_active_with_attrs_list
 }
 
 PurpleStatusType *
-purple_status_get_type(const PurpleStatus *status)
+purple_status_get_status_type(const PurpleStatus *status)
 {
 	g_return_val_if_fail(status != NULL, NULL);
 
-	return status->type;
+	return priv->type;
 }
 
 PurplePresence *
@@ -862,7 +868,7 @@ purple_status_get_presence(const PurpleS
 {
 	g_return_val_if_fail(status != NULL, NULL);
 
-	return status->presence;
+	return priv->presence;
 }
 
 const char *
@@ -910,7 +916,7 @@ purple_status_is_active(const PurpleStat
 {
 	g_return_val_if_fail(status != NULL, FALSE);
 
-	return status->active;
+	return priv->active;
 }
 
 gboolean
@@ -932,7 +938,7 @@ purple_status_get_attr_value(const Purpl
 	g_return_val_if_fail(status != NULL, NULL);
 	g_return_val_if_fail(id     != NULL, NULL);
 
-	return (GValue *)g_hash_table_lookup(status->attr_values, id);
+	return (GValue *)g_hash_table_lookup(priv->attr_values, id);
 }
 
 gboolean
@@ -1057,14 +1063,14 @@ score_pref_changed_cb(const char *name, 
 }
 
 void *
-purple_status_get_handle(void) {
+purple_statuses_get_handle(void) {
 	static int handle;
 
 	return &handle;
 }
 
 void
-purple_status_init(void)
+purple_statuses_init(void)
 {
 	void *handle = purple_status_get_handle();
 
@@ -1120,7 +1126,7 @@ purple_status_init(void)
 }
 
 void
-purple_status_uninit(void)
+purple_statuses_uninit(void)
 {
 	purple_prefs_disconnect_by_handle(purple_prefs_get_handle());
 }
diff --git a/libpurple/status.h b/libpurple/status.h
--- a/libpurple/status.h
+++ b/libpurple/status.h
@@ -77,11 +77,24 @@
  * hardcoded in each PRPL and will not change often.  And because
  * they are hardcoded, they do not need to be saved to any XML file.
  */
-#define PURPLE_TYPE_STATUS      (purple_status_get_g_type())
-typedef struct _PurpleStatus    PurpleStatus;
+#define PURPLE_TYPE_STATUS             (purple_status_get_type())
+#define PURPLE_STATUS(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_STATUS, PurpleStatus))
+#define PURPLE_STATUS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_STATUS, PurpleStatusClass))
+#define PURPLE_IS_STATUS(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_STATUS))
+#define PURPLE_IS_STATUS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_STATUS))
+#define PURPLE_STATUS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_STATUS, PurpleStatusClass))
 
-typedef struct _PurpleStatusType  PurpleStatusType;
-typedef struct _PurpleStatusAttr  PurpleStatusAttr;
+typedef struct _PurpleStatus           PurpleStatus;
+
+#define PURPLE_TYPE_STATUS_TYPE        (purple_status_type_get_type())
+
+typedef struct _PurpleStatusType       PurpleStatusType;
+
+#define PURPLE_TYPE_STATUS_ATTR        (purple_status_attr_get_type())
+
+typedef struct _PurpleStatusAttr       PurpleStatusAttr;
+
+#define PURPLE_TYPE_MOOD               (purple_mood_get_type())
 
 typedef struct _PurpleMood {
 	const char *mood;
@@ -127,6 +140,26 @@ typedef enum
 #define PURPLE_MOOD_NAME	"mood"
 #define PURPLE_MOOD_COMMENT	"moodtext"
 
+/**
+ * Represents an active status.
+ */
+struct _PurpleStatus
+{
+	/*< private >*/
+	GObject gparent;
+};
+
+/** Base class for all #PurpleStatus's */
+struct _PurpleStatusClass {
+	/*< private >*/
+	GObjectClass parent_class;
+
+	void (*_purple_reserved1)(void);
+	void (*_purple_reserved2)(void);
+	void (*_purple_reserved3)(void);
+	void (*_purple_reserved4)(void);
+};
+
 G_BEGIN_DECLS
 
 /**************************************************************************/
@@ -173,6 +206,11 @@ PurpleStatusPrimitive purple_primitive_g
 /*@{*/
 
 /**
+ * Returns the GType for the PurpleStatusType boxed structure.
+ */
+GType purple_status_type_get_type(void);
+
+/**
  * Creates a new status type.
  *
  * @param primitive     The primitive status type.
@@ -364,11 +402,16 @@ const PurpleStatusType *purple_status_ty
 /*@}*/
 
 /**************************************************************************/
-/** @name PurpleStatusAttr API                                              */
+/** @name PurpleStatusAttr API                                            */
 /**************************************************************************/
 /*@{*/
 
 /**
+ * Returns the GType for the PurpleStatusAttr boxed structure.
+ */
+GType purple_status_attr_get_type(void);
+
+/**
  * Creates a new status attribute.
  *
  * @param id         The ID of the attribute.
@@ -417,16 +460,26 @@ GValue *purple_status_attr_get_value(con
 /*@}*/
 
 /**************************************************************************/
-/** @name PurpleStatus API                                                  */
+/** @name PurpleMood API                                                  */
 /**************************************************************************/
 /*@{*/
 
 /**
- * Returns the GType for the PurpleStatus boxed structure.
- * TODO Boxing of PurpleStatus is a temporary solution to having a GType for
- *      statuses. This should rather be a GObject instead of a GBoxed.
+ * Returns the GType for the PurpleMood boxed structure.
  */
-GType purple_status_get_g_type(void);
+GType purple_mood_get_type(void);
+
+/*@}*/
+
+/**************************************************************************/
+/** @name PurpleStatus API                                                */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Returns the GType for the Status object.
+ */
+GType purple_status_get_type(void);
 
 /**
  * Creates a new status.
@@ -440,13 +493,6 @@ PurpleStatus *purple_status_new(PurpleSt
 							PurplePresence *presence);
 
 /**
- * Destroys a status.
- *
- * @param status The status to destroy.
- */
-void purple_status_destroy(PurpleStatus *status);
-
-/**
  * Sets whether or not a status is active.
  *
  * This should only be called by the account, conversation, and buddy APIs.
@@ -493,7 +539,7 @@ void purple_status_set_active_with_attrs
  *
  * @return The status's type.
  */
-PurpleStatusType *purple_status_get_type(const PurpleStatus *status);



More information about the Commits mailing list