/soc/2013/ankitkv/gobjectification: cfe2b7ce3421: Added GObject ...
Ankit Vani
a at nevitus.org
Sun Jul 21 11:23:53 EDT 2013
Changeset: cfe2b7ce3421fa32bb38a3e276a751fb222af384
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-21 20:53 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/cfe2b7ce3421
Description:
Added GObject code to status.[ch]
diffstat:
libpurple/status.c | 395 ++++++++++++++++++++++++++++++++++++++++++++--------
libpurple/status.h | 3 +
2 files changed, 337 insertions(+), 61 deletions(-)
diffs (truncated from 502 to 300 lines):
diff --git a/libpurple/status.c b/libpurple/status.c
--- a/libpurple/status.c
+++ b/libpurple/status.c
@@ -65,7 +65,7 @@ struct _PurpleStatusAttr
*/
struct _PurpleStatusPrivate
{
- PurpleStatusType *type;
+ PurpleStatusType *status_type;
PurplePresence *presence;
gboolean active;
@@ -79,12 +79,24 @@ struct _PurpleStatusPrivate
GHashTable *attr_values;
};
+/* GObject property enums */
+enum
+{
+ PROP_0,
+ PROP_STATUS_TYPE,
+ PROP_PRESENCE,
+ PROP_ACTIVE,
+ PROP_LAST
+};
+
typedef struct
{
PurpleAccount *account;
char *name;
} PurpleStatusBuddyKey;
+static GObjectClass *parent_class;
+
static int primitive_scores[] =
{
0, /* unset */
@@ -485,54 +497,6 @@ purple_status_attr_get_value(const Purpl
/**************************************************************************
* PurpleStatus API
**************************************************************************/
-PurpleStatus *
-purple_status_new(PurpleStatusType *status_type, PurplePresence *presence)
-{
- PurpleStatus *status;
- GList *l;
-
- g_return_val_if_fail(status_type != NULL, NULL);
- g_return_val_if_fail(presence != NULL, NULL);
-
- status = g_new0(PurpleStatus, 1);
- PURPLE_DBUS_REGISTER_POINTER(status, PurpleStatus);
-
- priv->type = status_type;
- priv->presence = presence;
-
- priv->attr_values =
- g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
- (GDestroyNotify)purple_g_value_free);
-
- for (l = purple_status_type_get_attrs(status_type); l != NULL; l = l->next)
- {
- PurpleStatusAttr *attr = (PurpleStatusAttr *)l->data;
- GValue *value = purple_status_attr_get_value(attr);
- GValue *new_value = purple_g_value_dup(value);
-
- g_hash_table_insert(priv->attr_values,
- (char *)purple_status_attr_get_id(attr),
- new_value);
- }
-
- return status;
-}
-
-/*
- * TODO: If the PurpleStatus is in a PurplePresence, then
- * remove it from the PurplePresence?
- */
-void
-purple_status_destroy(PurpleStatus *status)
-{
- g_return_if_fail(status != NULL);
-
- g_hash_table_destroy(priv->attr_values);
-
- PURPLE_DBUS_UNREGISTER_POINTER(status);
- g_free(status);
-}
-
static void
notify_buddy_status_update(PurpleBuddy *buddy, PurplePresence *presence,
PurpleStatus *old_status, PurpleStatus *new_status)
@@ -604,9 +568,9 @@ notify_status_update(PurplePresence *pre
}
else if (PURPLE_IS_BUDDY_PRESENCE(presence))
{
- notify_buddy_status_update(purple_buddy_presence_get_buddy(
- PURPLE_BUDDY_PRESENCE(presence)), presence, old_status,
- new_status);
+ notify_buddy_status_update(purple_buddy_presence_get_buddy(
+ PURPLE_BUDDY_PRESENCE(presence)), presence, old_status,
+ new_status);
}
}
@@ -627,7 +591,7 @@ status_has_changed(PurpleStatus *status)
{
old_status = purple_presence_get_active_status(presence);
if (old_status != NULL && (old_status != status))
- old_priv->active = FALSE;
+ PURPLE_STATUS_GET_PRIVATE(old_status)->active = FALSE;
g_object_set(presence, "active-status", status, NULL);
}
else
@@ -735,8 +699,9 @@ purple_status_set_active_with_attrs_list
GList *l;
GList *specified_attr_ids = NULL;
PurpleStatusType *status_type;
+ PurpleStatusPrivate *priv = PURPLE_STATUS_GET_PRIVATE(status);
- g_return_if_fail(status != NULL);
+ g_return_if_fail(priv != NULL);
if (!active && purple_status_is_exclusive(status))
{
@@ -766,7 +731,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, priv->type->name);
+ "not supported.\n", id, priv->status_type->name);
/* Skip over the data and move on to the next attribute */
l = l->next;
continue;
@@ -858,15 +823,19 @@ purple_status_set_active_with_attrs_list
PurpleStatusType *
purple_status_get_status_type(const PurpleStatus *status)
{
- g_return_val_if_fail(status != NULL, NULL);
+ PurpleStatusPrivate *priv = PURPLE_STATUS_GET_PRIVATE(status);
- return priv->type;
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return priv->status_type;
}
PurplePresence *
purple_status_get_presence(const PurpleStatus *status)
{
- g_return_val_if_fail(status != NULL, NULL);
+ PurpleStatusPrivate *priv = PURPLE_STATUS_GET_PRIVATE(status);
+
+ g_return_val_if_fail(priv != NULL, NULL);
return priv->presence;
}
@@ -914,7 +883,9 @@ purple_status_is_available(const PurpleS
gboolean
purple_status_is_active(const PurpleStatus *status)
{
- g_return_val_if_fail(status != NULL, FALSE);
+ PurpleStatusPrivate *priv = PURPLE_STATUS_GET_PRIVATE(status);
+
+ g_return_val_if_fail(priv != NULL, FALSE);
return priv->active;
}
@@ -935,8 +906,10 @@ purple_status_is_online(const PurpleStat
GValue *
purple_status_get_attr_value(const PurpleStatus *status, const char *id)
{
- g_return_val_if_fail(status != NULL, NULL);
- g_return_val_if_fail(id != NULL, NULL);
+ PurpleStatusPrivate *priv = PURPLE_STATUS_GET_PRIVATE(status);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+ g_return_val_if_fail(id != NULL, NULL);
return (GValue *)g_hash_table_lookup(priv->attr_values, id);
}
@@ -1024,6 +997,306 @@ purple_status_compare(const PurpleStatus
/**************************************************************************
+* GBoxed code for PurpleStatusType
+**************************************************************************/
+static PurpleStatusType *
+purple_status_type_copy(PurpleStatusType *status_type)
+{
+ PurpleStatusType *status_type_copy;
+ GList *l;
+
+ g_return_val_if_fail(status_type != NULL, NULL);
+
+ status_type_copy = purple_status_type_new_full(status_type->primitive,
+ status_type->id,
+ status_type->name,
+ status_type->saveable,
+ status_type->user_settable,
+ status_type->independent);
+
+ for (l = status_type->attrs; l != NULL; l = l->next) {
+ PurpleStatusAttr *new_attr, *attr = l->data;
+
+ new_attr = g_boxed_copy(PURPLE_TYPE_STATUS_ATTR, attr);
+ status_type_copy->attrs = g_list_append(status_type_copy->attrs, new_attr);
+ }
+
+ return status_type_copy;
+}
+
+GType
+purple_status_type_get_type(void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ type = g_boxed_type_register_static("PurpleStatusType",
+ (GBoxedCopyFunc)purple_status_type_copy,
+ (GBoxedFreeFunc)purple_status_type_destroy);
+ }
+
+ return type;
+}
+
+/**************************************************************************
+* GBoxed code for PurpleStatusAttr
+**************************************************************************/
+static PurpleStatusAttr *
+purple_status_attr_copy(PurpleStatusAttr *status_attr)
+{
+ g_return_val_if_fail(status_attr != NULL, NULL);
+
+ return purple_status_attr_new(status_attr->id,
+ status_attr->name,
+ purple_g_value_dup(status_attr->value_type));
+}
+
+GType
+purple_status_attr_get_type(void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ type = g_boxed_type_register_static("PurpleStatusAttr",
+ (GBoxedCopyFunc)purple_status_attr_copy,
+ (GBoxedFreeFunc)purple_status_attr_destroy);
+ }
+
+ return type;
+}
+
+/**************************************************************************
+* GBoxed code for PurpleMood
+**************************************************************************/
+static PurpleMood *
+purple_mood_copy(PurpleMood *mood)
+{
+ PurpleMood *mood_copy;
+
+ g_return_val_if_fail(mood != NULL, NULL);
+
+ mood_copy = g_new(PurpleMood, 1);
+
+ mood_copy->mood = g_strdup(mood->mood);
+ mood_copy->description = g_strdup(mood->description);
+
+ return mood_copy;
+}
+
+static void
+purple_mood_free(PurpleMood *mood)
+{
+ g_free((gchar *)mood->mood);
+ g_free((gchar *)mood->description);
+
+ g_free(mood);
+}
+
+GType
+purple_mood_get_type(void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ type = g_boxed_type_register_static("PurpleMood",
+ (GBoxedCopyFunc)purple_mood_copy,
+ (GBoxedFreeFunc)purple_mood_free);
+ }
+
+ return type;
+}
+
+
+/**************************************************************************
+* GObject code
+**************************************************************************/
+
+/* GObject Property names */
More information about the Commits
mailing list