/soc/2013/ankitkv/gobjectification: caeb3904c991: Added GObject ...
Ankit Vani
a at nevitus.org
Sat Jul 6 16:57:07 EDT 2013
Changeset: caeb3904c9919fe885d12cc69f441adb172ea4ae
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-07 02:26 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/caeb3904c991
Description:
Added GObject code to PurpleBListNode. Changed blist node setting value from PurpleValue to GValue.
diffstat:
libpurple/blistnode.c | 233 +++++++++++++++++++++++++++++++++----------------
libpurple/buddylist.c | 22 ++--
2 files changed, 164 insertions(+), 91 deletions(-)
diffs (truncated from 419 to 300 lines):
diff --git a/libpurple/blistnode.c b/libpurple/blistnode.c
--- a/libpurple/blistnode.c
+++ b/libpurple/blistnode.c
@@ -30,11 +30,20 @@ typedef struct _PurpleBListNodePrivate
/** Private data of a buddy list node */
struct _PurpleBListNodePrivate {
- GHashTable *settings; /**< per-node settings */
- gboolean dont_save; /**< node should not be saved with the buddy
- list */
+ GHashTable *settings; /**< per-node settings */
+ gboolean dont_save; /**< node should not be saved with the buddy list */
};
+/* GObject Property enums */
+enum
+{
+ PROP_0,
+ PROP_DONT_SAVE,
+ PROP_LAST
+};
+
+static GObjectClass *parent_class;
+
/**************************************************************************/
/* Buddy list node API */
/**************************************************************************/
@@ -89,62 +98,6 @@ purple_blist_node_set_ui_data(PurpleBLis
node->ui_data = ui_data;
}
-/* TODO GObjectify */
-static void
-purple_blist_node_destroy(PurpleBListNode *node)
-{
- PurpleBListUiOps *ui_ops;
- PurpleBListNode *child, *next_child;
-
- ui_ops = purple_blist_get_ui_ops();
- child = node->child;
- while (child) {
- next_child = child->next;
- purple_blist_node_destroy(child);
- child = next_child;
- }
-
- /* Allow the UI to free data */
- node->parent = NULL;
- node->child = NULL;
- node->next = NULL;
- node->prev = NULL;
- if (ui_ops && ui_ops->remove)
- ui_ops->remove(purplebuddylist, node);
-
- if (PURPLE_IS_BUDDY(node))
- purple_buddy_destroy((PurpleBuddy*)node);
- else if (PURPLE_IS_CHAT(node))
- purple_chat_destroy((PurpleChat*)node);
- else if (PURPLE_IS_CONTACT(node))
- purple_contact_destroy((PurpleContact*)node);
- else if (PURPLE_IS_GROUP(node))
- purple_group_destroy((PurpleGroup*)node);
-}
-
-static void
-purple_blist_node_setting_free(gpointer data)
-{
- PurpleValue *value;
-
- value = (PurpleValue *)data;
-
- purple_value_destroy(value);
-}
-
-static void purple_blist_node_initialize_settings(PurpleBListNode *node)
-{
- PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
-
- g_return_if_fail(priv != NULL);
-
- if (priv->settings)
- return;
-
- priv->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
- (GDestroyNotify)purple_blist_node_setting_free);
-}
-
void purple_blist_node_remove_setting(PurpleBListNode *node, const char *key)
{
PurpleBListUiOps *ops;
@@ -197,7 +150,7 @@ purple_blist_node_has_setting(PurpleBLis
void
purple_blist_node_set_bool(PurpleBListNode* node, const char *key, gboolean data)
{
- PurpleValue *value;
+ GValue *value;
PurpleBListUiOps *ops;
PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
@@ -205,8 +158,9 @@ purple_blist_node_set_bool(PurpleBListNo
g_return_if_fail(priv->settings != NULL);
g_return_if_fail(key != NULL);
- value = purple_value_new(PURPLE_TYPE_BOOLEAN);
- purple_value_set_boolean(value, data);
+ value = g_new0(GValue, 1);
+ g_value_init(value, G_TYPE_BOOLEAN);
+ g_value_set_boolean(value, data);
g_hash_table_replace(priv->settings, g_strdup(key), value);
@@ -218,7 +172,7 @@ purple_blist_node_set_bool(PurpleBListNo
gboolean
purple_blist_node_get_bool(PurpleBListNode* node, const char *key)
{
- PurpleValue *value;
+ GValue *value;
PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
g_return_val_if_fail(priv != NULL, FALSE);
@@ -230,15 +184,15 @@ purple_blist_node_get_bool(PurpleBListNo
if (value == NULL)
return FALSE;
- g_return_val_if_fail(purple_value_get_type(value) == PURPLE_TYPE_BOOLEAN, FALSE);
+ g_return_val_if_fail(G_VALUE_HOLDS_BOOLEAN(value), FALSE);
- return purple_value_get_boolean(value);
+ return g_value_get_boolean(value);
}
void
purple_blist_node_set_int(PurpleBListNode* node, const char *key, int data)
{
- PurpleValue *value;
+ GValue *value;
PurpleBListUiOps *ops;
PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
@@ -246,8 +200,9 @@ purple_blist_node_set_int(PurpleBListNod
g_return_if_fail(priv->settings != NULL);
g_return_if_fail(key != NULL);
- value = purple_value_new(PURPLE_TYPE_INT);
- purple_value_set_int(value, data);
+ value = g_new0(GValue, 1);
+ g_value_init(value, G_TYPE_INT);
+ g_value_set_int(value, data);
g_hash_table_replace(priv->settings, g_strdup(key), value);
@@ -259,7 +214,7 @@ purple_blist_node_set_int(PurpleBListNod
int
purple_blist_node_get_int(PurpleBListNode* node, const char *key)
{
- PurpleValue *value;
+ GValue *value;
PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
g_return_val_if_fail(priv != NULL, 0);
@@ -271,15 +226,15 @@ purple_blist_node_get_int(PurpleBListNod
if (value == NULL)
return 0;
- g_return_val_if_fail(purple_value_get_type(value) == PURPLE_TYPE_INT, 0);
+ g_return_val_if_fail(G_VALUE_HOLDS_INT(value), 0);
- return purple_value_get_int(value);
+ return g_value_get_int(value);
}
void
purple_blist_node_set_string(PurpleBListNode* node, const char *key, const char *data)
{
- PurpleValue *value;
+ GValue *value;
PurpleBListUiOps *ops;
PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
@@ -287,8 +242,9 @@ purple_blist_node_set_string(PurpleBList
g_return_if_fail(priv->settings != NULL);
g_return_if_fail(key != NULL);
- value = purple_value_new(PURPLE_TYPE_STRING);
- purple_value_set_string(value, data);
+ value = g_new0(GValue, 1);
+ g_value_init(value, G_TYPE_STRING);
+ g_value_set_int(value, data);
g_hash_table_replace(priv->settings, g_strdup(key), value);
@@ -300,7 +256,7 @@ purple_blist_node_set_string(PurpleBList
const char *
purple_blist_node_get_string(PurpleBListNode* node, const char *key)
{
- PurpleValue *value;
+ GValue *value;
PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
g_return_val_if_fail(priv != NULL, NULL);
@@ -312,9 +268,9 @@ purple_blist_node_get_string(PurpleBList
if (value == NULL)
return NULL;
- g_return_val_if_fail(purple_value_get_type(value) == PURPLE_TYPE_STRING, NULL);
+ g_return_val_if_fail(G_VALUE_HOLDS_STRING(value), NULL);
- return purple_value_get_string(value);
+ return g_value_get_string(value);
}
GList *
@@ -324,8 +280,127 @@ purple_blist_node_get_extended_menu(Purp
g_return_val_if_fail(n != NULL, NULL);
- purple_signal_emit(purple_blist_get_handle(),
- "blist-node-extended-menu",
+ purple_signal_emit(purple_blist_get_handle(), "blist-node-extended-menu",
n, &menu);
return menu;
}
+
+static void
+purple_blist_node_setting_free(gpointer data)
+{
+ GValue *value = (GValue *)data;
+
+ g_value_unset(value);
+ g_free(value);
+}
+
+/**************************************************************************/
+/* GObject code
+/**************************************************************************/
+
+/* GObject Property names */
+#define PROP_DONT_SAVE_S "dont-save"
+
+/* Set method for GObject properties */
+static void
+purple_blist_node_set_property(GObject *obj, guint param_id, const GValue *value,
+ GParamSpec *pspec)
+{
+ PurpleBListNode *node = PURPLE_BLIST_NODE(obj);
+
+ switch (param_id) {
+ case PROP_DONT_SAVE:
+ purple_blist_node_set_dont_save(node, g_value_get_boolean(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
+ }
+}
+
+/* Get method for GObject properties */
+static void
+purple_blist_node_get_property(GObject *obj, guint param_id, GValue *value,
+ GParamSpec *pspec)
+{
+ PurpleBListNode *node = PURPLE_BLIST_NODE(obj);
+
+ switch (param_id) {
+ case PROP_DONT_SAVE:
+ g_value_set_boolean(value, purple_blist_node_get_dont_save(node));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
+ }
+}
+
+/* GObject initialization function */
+static void
+purple_blist_node_init(GTypeInstance *instance, gpointer klass)
+{
+ PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(instance);
+
+ priv->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+ (GDestroyNotify)purple_blist_node_setting_free);
+}
+
+/* GObject finalize function */
+static void
+purple_blist_node_finalize(GObject *object)
+{
+ PurpleBListNode *priv = PURPLE_BLIST_NODE_GET_PRIVATE(object);
+
+ g_hash_table_destroy(priv->settings);
+
+ parent_class->finalize(object);
+}
+
+/* Class initializer function */
+static void
+purple_blist_node_class_init(PurpleBListNodeClass *klass)
+{
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+
More information about the Commits
mailing list