/soc/2013/ankitkv/gobjectification: 9e2aff0b8476: libpurple: sta...

Ankit Vani a at nevitus.org
Tue Nov 19 18:58:24 EST 2013


Changeset: 9e2aff0b8476ab8487074691308a8bcf3dd05fa3
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-11-20 05:15 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/9e2aff0b8476

Description:

libpurple: started changing g_object_notify to g_object_notify_by_pspec

diffstat:

 libpurple/circularbuffer.c |  49 +++++++++++++++++++++----------------
 libpurple/media/codec.c    |  52 ++++++++++++++++++++++++---------------
 libpurple/smiley.c         |  18 ++++++++-----
 libpurple/theme-loader.c   |  23 +++++++++-------
 libpurple/theme.c          |  60 ++++++++++++++++++++++++++-------------------
 5 files changed, 118 insertions(+), 84 deletions(-)

diffs (truncated from 549 to 300 lines):

diff --git a/libpurple/circularbuffer.c b/libpurple/circularbuffer.c
--- a/libpurple/circularbuffer.c
+++ b/libpurple/circularbuffer.c
@@ -22,6 +22,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 #include "internal.h"
+#include "glibcompat.h"
 
 #include "circularbuffer.h"
 
@@ -72,6 +73,7 @@ enum {
  * Globals
  *****************************************************************************/
 static GObjectClass *parent_class = NULL;
+static GParamSpec *properties[PROP_LAST];
 
 /******************************************************************************
  * Circular Buffer Implementation
@@ -124,8 +126,8 @@ purple_circular_buffer_real_grow(PurpleC
 
 	obj = G_OBJECT(buffer);
 	g_object_freeze_notify(obj);
-	g_object_notify(obj, "input");
-	g_object_notify(obj, "output");
+	g_object_notify_by_pspec(obj, properties[PROP_INPUT]);
+	g_object_notify_by_pspec(obj, properties[PROP_OUTPUT]);
 	g_object_thaw_notify(obj);
 }
 
@@ -166,8 +168,8 @@ purple_circular_buffer_real_append(Purpl
 
 	obj = G_OBJECT(buffer);
 	g_object_freeze_notify(obj);
-	g_object_notify(obj, "buffer-used");
-	g_object_notify(obj, "input");
+	g_object_notify_by_pspec(obj, properties[PROP_BUFFER_USED]);
+	g_object_notify_by_pspec(obj, properties[PROP_INPUT]);
 	g_object_thaw_notify(obj);
 }
 
@@ -208,8 +210,8 @@ purple_circular_buffer_real_mark_read(Pu
 
 	obj = G_OBJECT(buffer);
 	g_object_freeze_notify(obj);
-	g_object_notify(obj, "buffer-used");
-	g_object_notify(obj, "output");
+	g_object_notify_by_pspec(obj, properties[PROP_BUFFER_USED]);
+	g_object_notify_by_pspec(obj, properties[PROP_OUTPUT]);
 	g_object_thaw_notify(obj);
 
 	return TRUE;
@@ -227,7 +229,7 @@ purple_circular_buffer_set_grow_size(Pur
 
 	priv->growsize = (grow_size != 0) ? grow_size : DEFAULT_BUF_SIZE;
 
-	g_object_notify(G_OBJECT(buffer), "grow-size");
+	g_object_notify_by_pspec(G_OBJECT(buffer), properties[PROP_GROW_SIZE]);
 }
 
 static const gchar *
@@ -321,28 +323,33 @@ purple_circular_buffer_class_init(Purple
 	/* using a ulong for the gsize properties since there is no
 	 * g_param_spec_size, and the ulong should always work. --gk 3/21/11
 	 */
-	g_object_class_install_property(obj_class, PROP_GROW_SIZE,
-		g_param_spec_ulong("grow-size", "grow-size",
+	properties[PROP_GROW_SIZE] = g_param_spec_ulong("grow-size", "grow-size",
 		                   "The grow size of the buffer",
 		                   0, G_MAXSIZE, 0,
 		                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
-		                   G_PARAM_STATIC_STRINGS));
+		                   G_PARAM_STATIC_STRINGS);
+	g_object_class_install_property(obj_class, PROP_GROW_SIZE,
+		                   properties[PROP_GROW_SIZE]);
 
-	g_object_class_install_property(obj_class, PROP_BUFFER_USED,
-		g_param_spec_ulong("buffer-used", "buffer-used",
+	properties[PROP_BUFFER_USED] = g_param_spec_ulong("buffer-used",
+		                   "buffer-used",
 		                   "The amount of the buffer used",
 		                   0, G_MAXSIZE, 0,
-		                   G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+		                   G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+	g_object_class_install_property(obj_class, PROP_BUFFER_USED,
+		                   properties[PROP_BUFFER_USED]);
 
+	properties[PROP_INPUT] = g_param_spec_pointer("input", "input",
+		                     "The input pointer of the buffer",
+		                     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 	g_object_class_install_property(obj_class, PROP_INPUT,
-		g_param_spec_pointer("input", "input",
-		                     "The input pointer of the buffer",
-		                     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+		                     properties[PROP_INPUT]);
 
+	properties[PROP_OUTPUT] = g_param_spec_pointer("output", "output",
+		                     "The output pointer of the buffer",
+		                     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 	g_object_class_install_property(obj_class, PROP_OUTPUT,
-		g_param_spec_pointer("output", "output",
-		                     "The output pointer of the buffer",
-		                     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+		                     properties[PROP_OUTPUT]);
 }
 
 /******************************************************************************
@@ -473,8 +480,8 @@ purple_circular_buffer_reset(PurpleCircu
 
 	obj = G_OBJECT(buffer);
 	g_object_freeze_notify(obj);
-	g_object_notify(obj, "input");
-	g_object_notify(obj, "output");
+	g_object_notify_by_pspec(obj, properties[PROP_INPUT]);
+	g_object_notify_by_pspec(obj, properties[PROP_OUTPUT]);
 	g_object_thaw_notify(obj);
 }
 
diff --git a/libpurple/media/codec.c b/libpurple/media/codec.c
--- a/libpurple/media/codec.c
+++ b/libpurple/media/codec.c
@@ -24,6 +24,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#include "internal.h"
+#include "glibcompat.h"
 #include "codec.h"
 
 /** @copydoc _PurpleMediaCodecClass */
@@ -65,8 +67,11 @@ enum {
 	PROP_CLOCK_RATE,
 	PROP_CHANNELS,
 	PROP_OPTIONAL_PARAMS,
+	PROP_LAST
 };
 
+static GParamSpec *properties[PROP_LAST];
+
 static void
 purple_media_codec_init(PurpleMediaCodec *info)
 {
@@ -171,49 +176,56 @@ purple_media_codec_class_init(PurpleMedi
 	gobject_class->set_property = purple_media_codec_set_property;
 	gobject_class->get_property = purple_media_codec_get_property;
 
-	g_object_class_install_property(gobject_class, PROP_ID,
-			g_param_spec_uint("id",
+	properties[PROP_ID] = g_param_spec_uint("id",
 			"ID",
 			"The numeric identifier of the codec.",
 			0, G_MAXUINT, 0,
 			G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
-			G_PARAM_STATIC_STRINGS));
+			G_PARAM_STATIC_STRINGS);
+	g_object_class_install_property(gobject_class, PROP_ID,
+			properties[PROP_ID]);
 
-	g_object_class_install_property(gobject_class, PROP_ENCODING_NAME,
-			g_param_spec_string("encoding-name",
+	properties[PROP_ENCODING_NAME] = g_param_spec_string("encoding-name",
 			"Encoding Name",
 			"The name of the codec.",
 			NULL,
 			G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
-			G_PARAM_STATIC_STRINGS));
+			G_PARAM_STATIC_STRINGS);
+	g_object_class_install_property(gobject_class, PROP_ENCODING_NAME,
+			properties[PROP_ENCODING_NAME]);
 
-	g_object_class_install_property(gobject_class, PROP_MEDIA_TYPE,
-			g_param_spec_flags("media-type",
+	properties[PROP_MEDIA_TYPE] = g_param_spec_flags("media-type",
 			"Media Type",
 			"Whether this is an audio of video codec.",
 			PURPLE_TYPE_MEDIA_SESSION_TYPE,
 			PURPLE_MEDIA_NONE,
 			G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
-			G_PARAM_STATIC_STRINGS));
+			G_PARAM_STATIC_STRINGS);
+	g_object_class_install_property(gobject_class, PROP_MEDIA_TYPE,
+			properties[PROP_MEDIA_TYPE]);
 
-	g_object_class_install_property(gobject_class, PROP_CLOCK_RATE,
-			g_param_spec_uint("clock-rate",
+	properties[PROP_CLOCK_RATE] = g_param_spec_uint("clock-rate",
 			"Create Callback",
 			"The function called to create this element.",
 			0, G_MAXUINT, 0,
-			G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+			G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+	g_object_class_install_property(gobject_class, PROP_CLOCK_RATE,
+			properties[PROP_CLOCK_RATE]);
 
-	g_object_class_install_property(gobject_class, PROP_CHANNELS,
-			g_param_spec_uint("channels",
+	properties[PROP_CHANNELS] = g_param_spec_uint("channels",
 			"Channels",
 			"The number of channels in this codec.",
 			0, G_MAXUINT, 0,
-			G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-	g_object_class_install_property(gobject_class, PROP_OPTIONAL_PARAMS,
-			g_param_spec_pointer("optional-params",
+			G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+	g_object_class_install_property(gobject_class, PROP_CHANNELS,
+			properties[PROP_CHANNELS]);
+
+	properties[PROP_OPTIONAL_PARAMS] = g_param_spec_pointer("optional-params",
 			"Optional Params",
 			"A list of optional parameters for the codec.",
-			G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+			G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+	g_object_class_install_property(gobject_class, PROP_OPTIONAL_PARAMS,
+			properties[PROP_OPTIONAL_PARAMS]);
 
 	g_type_class_add_private(klass, sizeof(PurpleMediaCodecPrivate));
 }
@@ -294,7 +306,7 @@ purple_media_codec_add_optional_paramete
 	priv->optional_params = g_list_append(
 			priv->optional_params, new_param);
 
-	g_object_notify(G_OBJECT(codec), "optional-params");
+	g_object_notify_by_pspec(G_OBJECT(codec), properties[PROP_OPTIONAL_PARAMS]);
 }
 
 void
@@ -314,7 +326,7 @@ purple_media_codec_remove_optional_param
 			g_list_remove(priv->optional_params, param);
 	g_free(param);
 
-	g_object_notify(G_OBJECT(codec), "optional-params");
+	g_object_notify_by_pspec(G_OBJECT(codec), properties[PROP_OPTIONAL_PARAMS]);
 }
 
 PurpleKeyValuePair *
diff --git a/libpurple/smiley.c b/libpurple/smiley.c
--- a/libpurple/smiley.c
+++ b/libpurple/smiley.c
@@ -25,6 +25,7 @@
  */
 
 #include "internal.h"
+#include "glibcompat.h"
 #include "dbus-maybe.h"
 #include "debug.h"
 #include "imgstore.h"
@@ -282,7 +283,8 @@ enum
 {
 	PROP_0,
 	PROP_SHORTCUT,
-	PROP_IMGSTORE
+	PROP_IMGSTORE,
+	PROP_LAST
 };
 
 enum
@@ -293,6 +295,7 @@ enum
 
 static guint signals[SIG_LAST];
 static GObjectClass *parent_class;
+static GParamSpec *properties[PROP_LAST];
 
 static void
 purple_smiley_init(GTypeInstance *instance, gpointer klass)
@@ -393,7 +396,6 @@ static void
 purple_smiley_class_init(PurpleSmileyClass *klass)
 {
 	GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
-	GParamSpec *pspec;
 
 	parent_class = g_type_class_peek_parent(klass);
 
@@ -405,17 +407,19 @@ purple_smiley_class_init(PurpleSmileyCla
 	gobj_class->dispose = purple_smiley_dispose;
 
 	/* Shortcut */
-	pspec = g_param_spec_string("shortcut", "Shortcut",
+	properties[PROP_SHORTCUT] = g_param_spec_string("shortcut", "Shortcut",
 			"The text-shortcut for the smiley",
 			NULL,
 			G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-	g_object_class_install_property(gobj_class, PROP_SHORTCUT, pspec);
+	g_object_class_install_property(gobj_class, PROP_SHORTCUT,
+			properties[PROP_SHORTCUT]);
 
 	/* Stored Image */
-	pspec = g_param_spec_pointer("image", "Stored Image",
+	properties[PROP_IMGSTORE] = g_param_spec_pointer("image", "Stored Image",
 			"Stored Image. (that'll have to do for now)",
 			G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-	g_object_class_install_property(gobj_class, PROP_IMGSTORE, pspec);
+	g_object_class_install_property(gobj_class, PROP_IMGSTORE,
+			properties[PROP_IMGSTORE]);
 
 	signals[SIG_DESTROY] = g_signal_new("destroy",
 			G_OBJECT_CLASS_TYPE(klass),
@@ -764,7 +768,7 @@ purple_smiley_set_shortcut(PurpleSmiley 
 	g_free(priv->shortcut);
 	priv->shortcut = g_strdup(shortcut);
 



More information about the Commits mailing list