[cheese] Use better API to notify and install properties
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cheese] Use better API to notify and install properties
- Date: Thu, 10 Nov 2011 22:04:34 +0000 (UTC)
commit 3121f971a4db839642b5c136b7ede8b088691220
Author: Adrian ZgorzaÅek <a zgorzalek gmail com>
Date: Thu Nov 10 22:59:51 2011 +0100
Use better API to notify and install properties
Changed g_object_notify_by_pspec() to g_object_notify() and
g_object_class_install_property() to
g_object_class_install_properties(). Added properties static array to
hold properties. Added enum constants identifying properties and
sentinels for array length definitions. Fixes bug 663098.
libcheese/cheese-aspect-frame.c | 42 +++++++++++++++---------------
libcheese/cheese-avatar-chooser.c | 23 ++++++++++------
libcheese/cheese-camera-device.c | 51 +++++++++++++++++++------------------
libcheese/cheese-camera.c | 35 +++++++++++-------------
libcheese/cheese-effect.c | 28 +++++++++++---------
libcheese/cheese-flash.c | 18 ++++++++-----
libcheese/cheese-widget.c | 24 ++++++++++-------
7 files changed, 117 insertions(+), 104 deletions(-)
---
diff --git a/libcheese/cheese-aspect-frame.c b/libcheese/cheese-aspect-frame.c
index 9a281e2..eb22d67 100644
--- a/libcheese/cheese-aspect-frame.c
+++ b/libcheese/cheese-aspect-frame.c
@@ -31,11 +31,13 @@ G_DEFINE_TYPE (CheeseAspectFrame, cheese_aspect_frame, MX_TYPE_BIN)
enum
{
PROP_0,
-
PROP_EXPAND,
- PROP_RATIO
+ PROP_RATIO,
+ PROP_LAST
};
+static GParamSpec *properties[PROP_LAST];
+
struct _CheeseAspectFramePrivate
{
guint expand : 1;
@@ -304,8 +306,6 @@ cheese_aspect_frame_pick (ClutterActor *actor,
static void
cheese_aspect_frame_class_init (CheeseAspectFrameClass *klass)
{
- GParamSpec *pspec;
-
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
@@ -322,21 +322,21 @@ cheese_aspect_frame_class_init (CheeseAspectFrameClass *klass)
actor_class->paint = cheese_aspect_frame_paint;
actor_class->pick = cheese_aspect_frame_pick;
- pspec = g_param_spec_boolean ("expand",
- "Expand",
- "Fill the allocated area with the child and "
- "clip off the excess.",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_EXPAND, pspec);
-
- pspec = g_param_spec_float ("ratio",
- "Ratio",
- "Override the child's aspect ratio "
- "(width/height).",
- -1.f, G_MAXFLOAT, -1.f,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_RATIO, pspec);
+ properties[PROP_EXPAND] = g_param_spec_boolean ("expand",
+ "Expand",
+ "Fill the allocated area with the child and "
+ "clip off the excess.",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ properties[PROP_RATIO] = g_param_spec_float ("ratio",
+ "Ratio",
+ "Override the child's aspect ratio "
+ "(width/height).",
+ -1.f, G_MAXFLOAT, -1.f,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, PROP_LAST, properties);
}
static void
@@ -364,7 +364,7 @@ cheese_aspect_frame_set_expand (CheeseAspectFrame *frame, gboolean expand)
{
priv->expand = expand;
clutter_actor_queue_relayout (CLUTTER_ACTOR (frame));
- g_object_notify (G_OBJECT (frame), "expand");
+ g_object_notify_by_pspec (G_OBJECT (frame), properties[PROP_EXPAND]);
}
}
@@ -387,7 +387,7 @@ cheese_aspect_frame_set_ratio (CheeseAspectFrame *frame, gfloat ratio)
{
priv->ratio = ratio;
clutter_actor_queue_relayout (CLUTTER_ACTOR (frame));
- g_object_notify (G_OBJECT (frame), "ratio");
+ g_object_notify_by_pspec (G_OBJECT (frame), properties[PROP_RATIO]);
}
}
diff --git a/libcheese/cheese-avatar-chooser.c b/libcheese/cheese-avatar-chooser.c
index 2fa0dee..9ef716a 100644
--- a/libcheese/cheese-avatar-chooser.c
+++ b/libcheese/cheese-avatar-chooser.c
@@ -46,7 +46,8 @@ enum
enum
{
PROP_0,
- PROP_PIXBUF
+ PROP_PIXBUF,
+ PROP_LAST
};
enum
@@ -66,6 +67,8 @@ struct _CheeseAvatarChooserPrivate
gulong photo_taken_id;
};
+static GParamSpec *properties[PROP_LAST];
+
#define CHEESE_AVATAR_CHOOSER_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_AVATAR_CHOOSER, \
CheeseAvatarChooserPrivate))
@@ -102,7 +105,7 @@ cheese_widget_photo_taken_cb (CheeseCamera *camera,
gdk_threads_leave ();
- g_object_notify (G_OBJECT (chooser), "pixbuf");
+ g_object_notify_by_pspec (G_OBJECT (chooser), properties[PROP_PIXBUF]);
}
/*
@@ -160,7 +163,8 @@ take_again_button_clicked_cb (GtkButton *button,
FALSE);
um_crop_area_set_picture (UM_CROP_AREA (priv->image), NULL);
- g_object_notify (G_OBJECT (chooser), "pixbuf");
+
+ g_object_notify_by_pspec (G_OBJECT (chooser), properties[PROP_PIXBUF]);
}
/* state_change_cb:
@@ -351,12 +355,13 @@ cheese_avatar_chooser_class_init (CheeseAvatarChooserClass *klass)
*
* A #GdkPixbuf object representing the cropped area of the picture, or %NULL.
*/
- g_object_class_install_property (object_class, PROP_PIXBUF,
- g_param_spec_object ("pixbuf",
- "Pixbuf",
- "A #GdkPixbuf object representing the cropped area of the picture, or %NULL.",
- GDK_TYPE_PIXBUF,
- G_PARAM_READABLE));
+ properties[PROP_PIXBUF] = g_param_spec_object ("pixbuf",
+ "Pixbuf",
+ "A #GdkPixbuf object representing the cropped area of the picture, or %NULL.",
+ GDK_TYPE_PIXBUF,
+ G_PARAM_READABLE);
+
+ g_object_class_install_properties (object_class, PROP_LAST, properties);
g_type_class_add_private (klass, sizeof (CheeseAvatarChooserPrivate));
}
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index e0706d8..8812c76 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -96,9 +96,12 @@ enum
PROP_NAME,
PROP_DEVICE_NODE,
PROP_UUID,
- PROP_V4LAPI_VERSION
+ PROP_V4LAPI_VERSION,
+ PROP_LAST
};
+static GParamSpec *properties[PROP_LAST];
+
struct _CheeseCameraDevicePrivate
{
gchar *device_node;
@@ -532,36 +535,33 @@ cheese_camera_device_class_init (CheeseCameraDeviceClass *klass)
*
* Human-readable name of the video capture device, for display to the user.
*/
- g_object_class_install_property (object_class, PROP_NAME,
- g_param_spec_string ("name",
- "Name of the device",
- "Human-readable name of the video capture device",
- NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ properties[PROP_NAME] = g_param_spec_string ("name",
+ "Name of the device",
+ "Human-readable name of the video capture device",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* CheeseCameraDevice:device-node:
*
* Path to the device node of the video capture device.
*/
- g_object_class_install_property (object_class, PROP_DEVICE_NODE,
- g_param_spec_string ("device-node",
- "Device node",
- "Path to the device node of the video capture device",
- NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ properties[PROP_DEVICE_NODE] = g_param_spec_string ("device-node",
+ "Device node",
+ "Path to the device node of the video capture device",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* CheeseCameraDevice:uuid:
*
* UUID of the video capture device.
*/
- g_object_class_install_property (object_class, PROP_UUID,
- g_param_spec_string ("uuid",
- "Device UUID",
- "UUID of the video capture device",
- NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ properties[PROP_UUID] = g_param_spec_string ("uuid",
+ "Device UUID",
+ "UUID of the video capture device",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* CheeseCameraDevice:v4l-api-version:
@@ -569,12 +569,13 @@ cheese_camera_device_class_init (CheeseCameraDeviceClass *klass)
* Version of the Video4Linux API that the device supports. Currently, either
* 1 or 2 are supported.
*/
- g_object_class_install_property (object_class, PROP_V4LAPI_VERSION,
- g_param_spec_uint ("v4l-api-version",
- "Video4Linux API version",
- "Version of the Video4Linux API that the device supports",
- 1, 2, 2,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ properties[PROP_V4LAPI_VERSION] = g_param_spec_uint ("v4l-api-version",
+ "Video4Linux API version",
+ "Version of the Video4Linux API that the device supports",
+ 1, 2, 2,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (object_class, PROP_LAST, properties);
g_type_class_add_private (klass, sizeof (CheeseCameraDevicePrivate));
}
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index a8adcb9..edd1c65 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -716,7 +716,7 @@ cheese_camera_play (CheeseCamera *camera)
gst_caps_unref (caps);
g_boxed_free (CHEESE_TYPE_VIDEO_FORMAT, priv->current_format);
priv->current_format = cheese_camera_device_get_best_format (device);
- g_object_notify (G_OBJECT (camera), "format");
+ g_object_notify_by_pspec (G_OBJECT (camera), properties[PROP_FORMAT]);
caps = cheese_camera_device_get_caps_for_format (device, priv->current_format);
}
@@ -806,7 +806,7 @@ cheese_camera_element_from_effect (CheeseCamera *camera, CheeseEffect *effect)
GstPad *pad;
g_object_get (G_OBJECT (effect),
- "pipeline_desc", &effect_desc,
+ "pipeline-desc", &effect_desc,
"name", &name, NULL);
effects_pipeline_desc = g_strconcat ("ffmpegcolorspace name=colorspace1 ! ",
@@ -906,7 +906,7 @@ cheese_camera_connect_effect_texture (CheeseCamera *camera, CheeseEffect *effect
g_object_set (G_OBJECT (priv->effects_valve), "drop", TRUE, NULL);
control_valve = gst_element_factory_make ("valve", NULL);
- g_object_set (G_OBJECT (effect), "control_valve", control_valve, NULL);
+ g_object_set (G_OBJECT (effect), "control-valve", control_valve, NULL);
display_queue = gst_element_factory_make ("queue", NULL);
@@ -1278,35 +1278,32 @@ cheese_camera_class_init (CheeseCameraClass *klass)
*
* The video texture for the #CheeseCamera to render into.
*/
- g_object_class_install_property (object_class, PROP_VIDEO_TEXTURE,
- g_param_spec_pointer ("video-texture",
+ properties[PROP_VIDEO_TEXTURE] = g_param_spec_pointer ("video-texture",
"Video texture",
"The video texture for the CheeseCamera to render into",
- G_PARAM_READWRITE));
+ G_PARAM_READWRITE);
/**
* CheeseCamera:device-node:
*
* The path to the device node for the video capture device.
*/
- g_object_class_install_property (object_class, PROP_DEVICE_NODE,
- g_param_spec_string ("device-node",
- "Device node",
- "The path to the device node for the video capture device",
- "",
- G_PARAM_READWRITE));
+ properties[PROP_DEVICE_NODE] = g_param_spec_string ("device-node",
+ "Device node",
+ "The path to the device node for the video capture device",
+ "",
+ G_PARAM_READWRITE);
/**
* CheeseCamera:format:
*
* The format of the video capture device.
*/
- g_object_class_install_property (object_class, PROP_FORMAT,
- g_param_spec_boxed ("format",
- "Video format",
- "The format of the video capture device",
- CHEESE_TYPE_VIDEO_FORMAT,
- G_PARAM_READWRITE));
+ properties[PROP_FORMAT] = g_param_spec_boxed ("format",
+ "Video format",
+ "The format of the video capture device",
+ CHEESE_TYPE_VIDEO_FORMAT,
+ G_PARAM_READWRITE);
/**
* CheeseCamera:num-camera-devices:
@@ -1322,7 +1319,7 @@ cheese_camera_class_init (CheeseCameraClass *klass)
0,
G_PARAM_READABLE);
- g_object_class_install_property (object_class, PROP_NUM_CAMERA_DEVICES, properties[PROP_NUM_CAMERA_DEVICES]);
+ g_object_class_install_properties (object_class, PROP_LAST, properties);
g_type_class_add_private (klass, sizeof (CheeseCameraPrivate));
}
diff --git a/libcheese/cheese-effect.c b/libcheese/cheese-effect.c
index 4d275cc..796d432 100644
--- a/libcheese/cheese-effect.c
+++ b/libcheese/cheese-effect.c
@@ -36,9 +36,12 @@ enum
PROP_O,
PROP_NAME,
PROP_PIPELINE_DESC,
- PROP_CONTROL_VALVE
+ PROP_CONTROL_VALVE,
+ PROP_LAST
};
+static GParamSpec *properties[PROP_LAST];
+
G_DEFINE_TYPE (CheeseEffect, cheese_effect, G_TYPE_OBJECT)
#define CHEESE_EFFECT_GET_PRIVATE(o) \
@@ -115,24 +118,22 @@ cheese_effect_class_init (CheeseEffectClass *klass)
*
* Name of the effect, for display in a UI.
*/
- g_object_class_install_property (object_class, PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name of the effect",
- "",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ properties[PROP_NAME] = g_param_spec_string ("name",
+ "Name",
+ "Name of the effect",
+ "",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* CheeseEffect:pipeline-desc:
*
* Description of the GStreamer pipeline associated with the effect.
*/
- g_object_class_install_property (object_class, PROP_PIPELINE_DESC,
- g_param_spec_string ("pipeline_desc",
+ properties[PROP_PIPELINE_DESC] = g_param_spec_string ("pipeline-desc",
"Pipeline description",
"Description of the GStreamer pipeline associated with the effect",
"",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* CheeseEffect:control-valve:
@@ -140,12 +141,13 @@ cheese_effect_class_init (CheeseEffectClass *klass)
* If the control valve is active, then the effect is currently connected to
* a video stream, for previews.
*/
- g_object_class_install_property (object_class, PROP_CONTROL_VALVE,
- g_param_spec_object ("control_valve",
+ properties[PROP_CONTROL_VALVE] = g_param_spec_object ("control-valve",
"Control valve",
"If the control valve is active, the effect is connected to a video stream",
GST_TYPE_ELEMENT,
- G_PARAM_READWRITE));
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, PROP_LAST, properties);
}
/**
diff --git a/libcheese/cheese-flash.c b/libcheese/cheese-flash.c
index 44eee85..317c28f 100644
--- a/libcheese/cheese-flash.c
+++ b/libcheese/cheese-flash.c
@@ -45,9 +45,12 @@
enum
{
PROP_0,
- PROP_PARENT
+ PROP_PARENT,
+ PROP_LAST
};
+static GParamSpec *properties[PROP_LAST];
+
/* How long to hold the flash for, in milliseconds. */
static const guint FLASH_DURATION = 250;
@@ -312,12 +315,13 @@ cheese_flash_class_init (CheeseFlashClass *klass)
* Parent #GtkWidget for the #CheeseFlash. The flash will be fired on the
* screen where the parent widget is shown.
*/
- g_object_class_install_property (object_class, PROP_PARENT,
- g_param_spec_object ("parent",
- "Parent widget",
- "The flash will be fired on the screen where the parent widget is shown",
- GTK_TYPE_WIDGET,
- G_PARAM_WRITABLE));
+ properties[PROP_PARENT] = g_param_spec_object ("parent",
+ "Parent widget",
+ "The flash will be fired on the screen where the parent widget is shown",
+ GTK_TYPE_WIDGET,
+ G_PARAM_WRITABLE);
+
+ g_object_class_install_properties (object_class, PROP_LAST, properties);
}
/*
diff --git a/libcheese/cheese-widget.c b/libcheese/cheese-widget.c
index 82ba66d..93e2ff2 100644
--- a/libcheese/cheese-widget.c
+++ b/libcheese/cheese-widget.c
@@ -49,9 +49,12 @@ enum
enum
{
PROP_0,
- PROP_STATE
+ PROP_STATE,
+ PROP_LAST
};
+static GParamSpec *properties[PROP_LAST];
+
typedef struct
{
GtkWidget *spinner;
@@ -348,7 +351,7 @@ setup_camera (CheeseWidget *widget)
if (priv->error != NULL)
{
priv->state = CHEESE_WIDGET_STATE_ERROR;
- g_object_notify (G_OBJECT (widget), "state");
+ g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_STATE]);
cheese_widget_set_problem_page (CHEESE_WIDGET (widget), "error");
}
else
@@ -358,7 +361,7 @@ setup_camera (CheeseWidget *widget)
cheese_camera_set_balance_property (priv->webcam, "saturation", saturation);
cheese_camera_set_balance_property (priv->webcam, "hue", hue);
priv->state = CHEESE_WIDGET_STATE_READY;
- g_object_notify (G_OBJECT (widget), "state");
+ g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_STATE]);
cheese_camera_play (priv->webcam);
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WEBCAM_PAGE);
}
@@ -407,13 +410,14 @@ cheese_widget_class_init (CheeseWidgetClass *klass)
* Useful to update other widgets sensitivities when the camera is ready or
* to handle errors if camera setup fails.
*/
- g_object_class_install_property (object_class, PROP_STATE,
- g_param_spec_enum ("state",
- "State",
- "The current state of the widget",
- CHEESE_TYPE_WIDGET_STATE,
- CHEESE_WIDGET_STATE_NONE,
- G_PARAM_READABLE));
+ properties[PROP_STATE] = g_param_spec_enum ("state",
+ "State",
+ "The current state of the widget",
+ CHEESE_TYPE_WIDGET_STATE,
+ CHEESE_WIDGET_STATE_NONE,
+ G_PARAM_READABLE);
+
+ g_object_class_install_properties (object_class, PROP_LAST, properties);
g_type_class_add_private (klass, sizeof (CheeseWidgetPrivate));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]