Sun, 21 Jul 2013 14:13:05 +0530
Started GObjectification of PurpleStatus.
Renamed purple_status_get_type() to purple_status_get_status_type().
| libpurple/status.c | file | annotate | diff | comparison | revisions | |
| libpurple/status.h | file | annotate | diff | comparison | revisions |
--- a/libpurple/status.c Sun Jul 21 13:55:41 2013 +0530 +++ b/libpurple/status.c Sun Jul 21 14:13:05 2013 +0530 @@ -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 @@ }; /** - * An active status. + * Private data for PurpleStatus */ -struct _PurpleStatus +struct _PurpleStatusPrivate { PurpleStatusType *type; PurplePresence *presence; @@ -491,10 +497,10 @@ 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 @@ 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 @@ { 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 @@ { 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 @@ 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 @@ 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 @@ } 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 @@ { g_return_val_if_fail(status != NULL, NULL); - return status->presence; + return priv->presence; } const char * @@ -910,7 +916,7 @@ { g_return_val_if_fail(status != NULL, FALSE); - return status->active; + return priv->active; } gboolean @@ -932,7 +938,7 @@ 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 @@ } 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 @@ } void -purple_status_uninit(void) +purple_statuses_uninit(void) { purple_prefs_disconnect_by_handle(purple_prefs_get_handle()); }
--- a/libpurple/status.h Sun Jul 21 13:55:41 2013 +0530 +++ b/libpurple/status.h Sun Jul 21 14:13:05 2013 +0530 @@ -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 _PurpleStatus PurpleStatus; -typedef struct _PurpleStatusType PurpleStatusType; -typedef struct _PurpleStatusAttr PurpleStatusAttr; +#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 @@ #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 @@ /*@{*/ /** + * 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 @@ /*@}*/ /**************************************************************************/ -/** @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 @@ /*@}*/ /**************************************************************************/ -/** @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 @@ 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 @@ * * @return The status's type. */ -PurpleStatusType *purple_status_get_type(const PurpleStatus *status); +PurpleStatusType *purple_status_get_status_type(const PurpleStatus *status); /** * Returns the status's presence. @@ -642,7 +688,7 @@ /*@}*/ /**************************************************************************/ -/** @name Status subsystem */ +/** @name Statuses subsystem */ /**************************************************************************/ /*@{*/ @@ -651,17 +697,17 @@ * * @return the handle to the status subsystem */ -void *purple_status_get_handle(void); +void *purple_statuses_get_handle(void); /** * Initializes the status subsystem. */ -void purple_status_init(void); +void purple_statuses_init(void); /** * Uninitializes the status subsystem. */ -void purple_status_uninit(void); +void purple_statuses_uninit(void); /*@}*/