[libgnome-volume-control/feature/gobject-cleanups] Improve GObject properties gunk a bit
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgnome-volume-control/feature/gobject-cleanups] Improve GObject properties gunk a bit
- Date: Mon, 5 Apr 2021 10:35:49 +0000 (UTC)
commit 2387065fb04278495234b1fa73a9fbed4d9498ad
Author: Niels De Graef <nielsdegraef gmail com>
Date: Mon Apr 5 12:18:34 2021 +0200
Improve GObject properties gunk a bit
Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.
Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
gvc-mixer-card.c | 92 ++++++++---------
gvc-mixer-control.c | 19 ++--
gvc-mixer-event-role.c | 19 ++--
gvc-mixer-stream.c | 261 +++++++++++++++++++++----------------------------
gvc-mixer-ui-device.c | 57 ++++++-----
5 files changed, 204 insertions(+), 244 deletions(-)
---
diff --git a/gvc-mixer-card.c b/gvc-mixer-card.c
index 93be4da..39f59ca 100644
--- a/gvc-mixer-card.c
+++ b/gvc-mixer-card.c
@@ -61,7 +61,9 @@ enum
PROP_ICON_NAME,
PROP_PROFILE,
PROP_HUMAN_PROFILE,
+ N_PROPS
};
+static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_card_finalize (GObject *object);
@@ -117,7 +119,7 @@ gvc_mixer_card_set_name (GvcMixerCard *card,
g_free (card->priv->name);
card->priv->name = g_strdup (name);
- g_object_notify (G_OBJECT (card), "name");
+ g_object_notify_by_pspec (G_OBJECT (card), obj_props[PROP_NAME]);
return TRUE;
}
@@ -137,7 +139,7 @@ gvc_mixer_card_set_icon_name (GvcMixerCard *card,
g_free (card->priv->icon_name);
card->priv->icon_name = g_strdup (icon_name);
- g_object_notify (G_OBJECT (card), "icon-name");
+ g_object_notify_by_pspec (G_OBJECT (card), obj_props[PROP_ICON_NAME]);
return TRUE;
}
@@ -191,7 +193,7 @@ gvc_mixer_card_set_profile (GvcMixerCard *card,
}
}
- g_object_notify (G_OBJECT (card), "profile");
+ g_object_notify_by_pspec (G_OBJECT (card), obj_props[PROP_PROFILE]);
return TRUE;
}
@@ -468,54 +470,42 @@ gvc_mixer_card_class_init (GvcMixerCardClass *klass)
gobject_class->set_property = gvc_mixer_card_set_property;
gobject_class->get_property = gvc_mixer_card_get_property;
- g_object_class_install_property (gobject_class,
- PROP_INDEX,
- g_param_spec_ulong ("index",
- "Index",
- "The index for this card",
- 0, G_MAXULONG, 0,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (gobject_class,
- PROP_ID,
- g_param_spec_ulong ("id",
- "id",
- "The id for this card",
- 0, G_MAXULONG, 0,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (gobject_class,
- PROP_PA_CONTEXT,
- g_param_spec_pointer ("pa-context",
- "PulseAudio context",
- "The PulseAudio context for this card",
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (gobject_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name to display for this card",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_ICON_NAME,
- g_param_spec_string ("icon-name",
- "Icon Name",
- "Name of icon to display for this card",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_PROFILE,
- g_param_spec_string ("profile",
- "Profile",
- "Name of current profile for this card",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (gobject_class,
- PROP_HUMAN_PROFILE,
- g_param_spec_string ("human-profile",
- "Profile (Human readable)",
- "Name of current profile for this card in
human readable form",
- NULL,
- G_PARAM_READABLE));
+ obj_props[PROP_INDEX] = g_param_spec_ulong ("index",
+ "Index",
+ "The index for this card",
+ 0, G_MAXULONG, 0,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_ID] = g_param_spec_ulong ("id",
+ "id",
+ "The id for this card",
+ 0, G_MAXULONG, 0,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_PA_CONTEXT] = g_param_spec_pointer ("pa-context",
+ "PulseAudio context",
+ "The PulseAudio context for this card",
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_NAME] = g_param_spec_string ("name",
+ "Name",
+ "Name to display for this card",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_ICON_NAME] = g_param_spec_string ("icon-name",
+ "Icon Name",
+ "Name of icon to display for this card",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_PROFILE] = g_param_spec_string ("profile",
+ "Profile",
+ "Name of current profile for this card",
+ NULL,
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_HUMAN_PROFILE] = g_param_spec_string ("human-profile",
+ "Profile (Human readable)",
+ "Name of current profile for this card in human
readable form",
+ NULL,
+ G_PARAM_READABLE|G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, obj_props);
}
static void
diff --git a/gvc-mixer-control.c b/gvc-mixer-control.c
index f44a257..a4aa42d 100644
--- a/gvc-mixer-control.c
+++ b/gvc-mixer-control.c
@@ -54,8 +54,10 @@
enum {
PROP_0,
- PROP_NAME
+ PROP_NAME,
+ N_PROPS
};
+static GParamSpec *obj_props[N_PROPS] = { NULL, };
struct GvcMixerControlPrivate
{
@@ -3627,7 +3629,7 @@ gvc_mixer_control_set_property (GObject *object,
case PROP_NAME:
g_free (self->priv->name);
self->priv->name = g_value_dup_string (value);
- g_object_notify (G_OBJECT (self), "name");
+ g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_NAME]);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -3683,13 +3685,12 @@ gvc_mixer_control_class_init (GvcMixerControlClass *klass)
object_class->set_property = gvc_mixer_control_set_property;
object_class->get_property = gvc_mixer_control_get_property;
- g_object_class_install_property (object_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name to display for this mixer control",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+ obj_props[PROP_NAME] = g_param_spec_string ("name",
+ "Name",
+ "Name to display for this mixer control",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
+ g_object_class_install_properties (object_class, N_PROPS, obj_props);
signals [STATE_CHANGED] =
g_signal_new ("state-changed",
diff --git a/gvc-mixer-event-role.c b/gvc-mixer-event-role.c
index 9f5e26a..272edb0 100644
--- a/gvc-mixer-event-role.c
+++ b/gvc-mixer-event-role.c
@@ -42,8 +42,10 @@ struct GvcMixerEventRolePrivate
enum
{
PROP_0,
- PROP_DEVICE
+ PROP_DEVICE,
+ N_PROPS
};
+static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_event_role_finalize (GObject *object);
@@ -115,7 +117,7 @@ gvc_mixer_event_role_set_device (GvcMixerEventRole *role,
g_free (role->priv->device);
role->priv->device = g_strdup (device);
- g_object_notify (G_OBJECT (role), "device");
+ g_object_notify_by_pspec (G_OBJECT (role), obj_props[PROP_DEVICE]);
return TRUE;
}
@@ -169,13 +171,12 @@ gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass)
stream_class->push_volume = gvc_mixer_event_role_push_volume;
stream_class->change_is_muted = gvc_mixer_event_role_change_is_muted;
- g_object_class_install_property (object_class,
- PROP_DEVICE,
- g_param_spec_string ("device",
- "Device",
- "Device",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+ obj_props[PROP_DEVICE] = g_param_spec_string ("device",
+ "Device",
+ "Device",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ g_object_class_install_properties (object_class, N_PROPS, obj_props);
}
static void
diff --git a/gvc-mixer-stream.c b/gvc-mixer-stream.c
index c324900..f9bcc40 100644
--- a/gvc-mixer-stream.c
+++ b/gvc-mixer-stream.c
@@ -83,7 +83,9 @@ enum
PROP_CARD_INDEX,
PROP_PORT,
PROP_STATE,
+ N_PROPS
};
+static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_stream_finalize (GObject *object);
@@ -198,7 +200,7 @@ gvc_mixer_stream_set_volume (GvcMixerStream *stream,
if (!pa_cvolume_equal(gvc_channel_map_get_cvolume(stream->priv->channel_map), &cv)) {
gvc_channel_map_volume_changed(stream->priv->channel_map, &cv, FALSE);
- g_object_notify (G_OBJECT (stream), "volume");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_VOLUME]);
return TRUE;
}
@@ -218,7 +220,7 @@ gvc_mixer_stream_set_decibel (GvcMixerStream *stream,
if (!pa_cvolume_equal(gvc_channel_map_get_cvolume(stream->priv->channel_map), &cv)) {
gvc_channel_map_volume_changed(stream->priv->channel_map, &cv, FALSE);
- g_object_notify (G_OBJECT (stream), "volume");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_VOLUME]);
}
return TRUE;
@@ -246,7 +248,7 @@ gvc_mixer_stream_set_is_muted (GvcMixerStream *stream,
if (is_muted != stream->priv->is_muted) {
stream->priv->is_muted = is_muted;
- g_object_notify (G_OBJECT (stream), "is-muted");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_IS_MUTED]);
}
return TRUE;
@@ -260,7 +262,7 @@ gvc_mixer_stream_set_can_decibel (GvcMixerStream *stream,
if (can_decibel != stream->priv->can_decibel) {
stream->priv->can_decibel = can_decibel;
- g_object_notify (G_OBJECT (stream), "can-decibel");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_CAN_DECIBEL]);
}
return TRUE;
@@ -288,7 +290,7 @@ gvc_mixer_stream_set_name (GvcMixerStream *stream,
g_free (stream->priv->name);
stream->priv->name = g_strdup (name);
- g_object_notify (G_OBJECT (stream), "name");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_NAME]);
return TRUE;
}
@@ -301,7 +303,7 @@ gvc_mixer_stream_set_description (GvcMixerStream *stream,
g_free (stream->priv->description);
stream->priv->description = g_strdup (description);
- g_object_notify (G_OBJECT (stream), "description");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_DESCRIPTION]);
return TRUE;
}
@@ -321,7 +323,7 @@ gvc_mixer_stream_set_is_event_stream (GvcMixerStream *stream,
g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE);
stream->priv->is_event_stream = is_event_stream;
- g_object_notify (G_OBJECT (stream), "is-event-stream");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_IS_EVENT_STREAM]);
return TRUE;
}
@@ -341,7 +343,7 @@ gvc_mixer_stream_set_is_virtual (GvcMixerStream *stream,
g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE);
stream->priv->is_virtual = is_virtual;
- g_object_notify (G_OBJECT (stream), "is-virtual");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_IS_VIRTUAL]);
return TRUE;
}
@@ -361,7 +363,7 @@ gvc_mixer_stream_set_application_id (GvcMixerStream *stream,
g_free (stream->priv->application_id);
stream->priv->application_id = g_strdup (application_id);
- g_object_notify (G_OBJECT (stream), "application-id");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_APPLICATION_ID]);
return TRUE;
}
@@ -374,7 +376,7 @@ on_channel_map_volume_changed (GvcChannelMap *channel_map,
if (set == TRUE)
gvc_mixer_stream_push_volume (stream);
- g_object_notify (G_OBJECT (stream), "volume");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_VOLUME]);
}
static gboolean
@@ -402,7 +404,7 @@ gvc_mixer_stream_set_channel_map (GvcMixerStream *stream,
G_CALLBACK (on_channel_map_volume_changed),
stream);
- g_object_notify (G_OBJECT (stream), "channel-map");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_CHANNEL_MAP]);
}
return TRUE;
@@ -452,7 +454,7 @@ gvc_mixer_stream_set_icon_name (GvcMixerStream *stream,
g_free (stream->priv->icon_name);
stream->priv->icon_name = g_strdup (icon_name);
- g_object_notify (G_OBJECT (stream), "icon-name");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_ICON_NAME]);
return TRUE;
}
@@ -465,7 +467,7 @@ gvc_mixer_stream_set_form_factor (GvcMixerStream *stream,
g_free (stream->priv->form_factor);
stream->priv->form_factor = g_strdup (form_factor);
- g_object_notify (G_OBJECT (stream), "form-factor");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_FORM_FACTOR]);
return TRUE;
}
@@ -478,7 +480,7 @@ gvc_mixer_stream_set_sysfs_path (GvcMixerStream *stream,
g_free (stream->priv->sysfs_path);
stream->priv->sysfs_path = g_strdup (sysfs_path);
- g_object_notify (G_OBJECT (stream), "sysfs-path");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_SYSFS_PATH]);
return TRUE;
}
@@ -558,7 +560,7 @@ gvc_mixer_stream_set_port (GvcMixerStream *stream,
}
}
- g_object_notify (G_OBJECT (stream), "port");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_PORT]);
return TRUE;
}
@@ -591,7 +593,7 @@ gvc_mixer_stream_set_state (GvcMixerStream *stream,
if (stream->priv->state != state) {
stream->priv->state = state;
- g_object_notify (G_OBJECT (stream), "state");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_STATE]);
}
return TRUE;
@@ -645,7 +647,7 @@ gvc_mixer_stream_set_card_index (GvcMixerStream *stream,
g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE);
stream->priv->card_index = card_index;
- g_object_notify (G_OBJECT (stream), "card-index");
+ g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_CARD_INDEX]);
return TRUE;
}
@@ -897,140 +899,103 @@ gvc_mixer_stream_class_init (GvcMixerStreamClass *klass)
klass->change_port = gvc_mixer_stream_real_change_port;
klass->change_is_muted = gvc_mixer_stream_real_change_is_muted;
- g_object_class_install_property (gobject_class,
- PROP_INDEX,
- g_param_spec_ulong ("index",
- "Index",
- "The index for this stream",
- 0, G_MAXULONG, 0,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (gobject_class,
- PROP_ID,
- g_param_spec_ulong ("id",
- "id",
- "The id for this stream",
- 0, G_MAXULONG, 0,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (gobject_class,
- PROP_CHANNEL_MAP,
- g_param_spec_object ("channel-map",
- "channel map",
- "The channel map for this stream",
- GVC_TYPE_CHANNEL_MAP,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_PA_CONTEXT,
- g_param_spec_pointer ("pa-context",
- "PulseAudio context",
- "The PulseAudio context for this stream",
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (gobject_class,
- PROP_VOLUME,
- g_param_spec_ulong ("volume",
- "Volume",
- "The volume for this stream",
- 0, G_MAXULONG, 0,
- G_PARAM_READWRITE));
- g_object_class_install_property (gobject_class,
- PROP_DECIBEL,
- g_param_spec_double ("decibel",
- "Decibel",
- "The decibel level for this stream",
- -G_MAXDOUBLE, G_MAXDOUBLE, 0,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
-
- g_object_class_install_property (gobject_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name to display for this stream",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_DESCRIPTION,
- g_param_spec_string ("description",
- "Description",
- "Description to display for this stream",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_APPLICATION_ID,
- g_param_spec_string ("application-id",
+ obj_props[PROP_INDEX] = g_param_spec_ulong ("index",
+ "Index",
+ "The index for this stream",
+ 0, G_MAXULONG, 0,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_ID] = g_param_spec_ulong ("id",
+ "id",
+ "The id for this stream",
+ 0, G_MAXULONG, 0,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_CHANNEL_MAP] = g_param_spec_object ("channel-map",
+ "channel map",
+ "The channel map for this stream",
+ GVC_TYPE_CHANNEL_MAP,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_PA_CONTEXT] = g_param_spec_pointer ("pa-context",
+ "PulseAudio context",
+ "The PulseAudio context for this stream",
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_VOLUME] = g_param_spec_ulong ("volume",
+ "Volume",
+ "The volume for this stream",
+ 0, G_MAXULONG, 0,
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_DECIBEL] = g_param_spec_double ("decibel",
+ "Decibel",
+ "The decibel level for this stream",
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_NAME] = g_param_spec_string ("name",
+ "Name",
+ "Name to display for this stream",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_DESCRIPTION] = g_param_spec_string ("description",
+ "Description",
+ "Description to display for this stream",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_APPLICATION_ID] = g_param_spec_string ("application-id",
"Application identifier",
"Application identifier for this stream",
NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_ICON_NAME,
- g_param_spec_string ("icon-name",
- "Icon Name",
- "Name of icon to display for this stream",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_FORM_FACTOR,
- g_param_spec_string ("form-factor",
- "Form Factor",
- "Device form factor for this stream, as
reported by PulseAudio",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_SYSFS_PATH,
- g_param_spec_string ("sysfs-path",
- "Sysfs path",
- "Sysfs path for the device associated with
this stream",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_IS_MUTED,
- g_param_spec_boolean ("is-muted",
- "is muted",
- "Whether stream is muted",
- FALSE,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_CAN_DECIBEL,
- g_param_spec_boolean ("can-decibel",
- "can decibel",
- "Whether stream volume can be converted to
decibel units",
- FALSE,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_IS_EVENT_STREAM,
- g_param_spec_boolean ("is-event-stream",
- "is event stream",
- "Whether stream's role is to play an event",
- FALSE,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_IS_VIRTUAL,
- g_param_spec_boolean ("is-virtual",
- "is virtual stream",
- "Whether the stream is virtual",
- FALSE,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class,
- PROP_PORT,
- g_param_spec_string ("port",
- "Port",
- "The name of the current port for this stream",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (gobject_class,
- PROP_STATE,
- g_param_spec_enum ("state",
- "State",
- "The current state of this stream",
- GVC_TYPE_MIXER_STREAM_STATE,
- GVC_STREAM_STATE_INVALID,
- G_PARAM_READWRITE));
- g_object_class_install_property (gobject_class,
- PROP_CARD_INDEX,
- g_param_spec_long ("card-index",
- "Card index",
- "The index of the card for this stream",
- PA_INVALID_INDEX, G_MAXLONG, PA_INVALID_INDEX,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_ICON_NAME] = g_param_spec_string ("icon-name",
+ "Icon Name",
+ "Name of icon to display for this stream",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_FORM_FACTOR] = g_param_spec_string ("form-factor",
+ "Form Factor",
+ "Device form factor for this stream, as reported
by PulseAudio",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_SYSFS_PATH] = g_param_spec_string ("sysfs-path",
+ "Sysfs path",
+ "Sysfs path for the device associated with this
stream",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_IS_MUTED] = g_param_spec_boolean ("is-muted",
+ "is muted",
+ "Whether stream is muted",
+ FALSE,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_CAN_DECIBEL] = g_param_spec_boolean ("can-decibel",
+ "can decibel",
+ "Whether stream volume can be converted to
decibel units",
+ FALSE,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_IS_EVENT_STREAM] = g_param_spec_boolean ("is-event-stream",
+ "is event stream",
+ "Whether stream's role is to play an event",
+ FALSE,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_IS_VIRTUAL] = g_param_spec_boolean ("is-virtual",
+ "is virtual stream",
+ "Whether the stream is virtual",
+ FALSE,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_PORT] = g_param_spec_string ("port",
+ "Port",
+ "The name of the current port for this stream",
+ NULL,
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_STATE] = g_param_spec_enum ("state",
+ "State",
+ "The current state of this stream",
+ GVC_TYPE_MIXER_STREAM_STATE,
+ GVC_STREAM_STATE_INVALID,
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
+ obj_props[PROP_CARD_INDEX] = g_param_spec_long ("card-index",
+ "Card index",
+ "The index of the card for this stream",
+ PA_INVALID_INDEX, G_MAXLONG, PA_INVALID_INDEX,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, obj_props);
}
static void
diff --git a/gvc-mixer-ui-device.c b/gvc-mixer-ui-device.c
index f7dd33e..db1a694 100644
--- a/gvc-mixer-ui-device.c
+++ b/gvc-mixer-ui-device.c
@@ -55,7 +55,9 @@ enum
PROP_UI_DEVICE_TYPE,
PROP_PORT_AVAILABLE,
PROP_ICON_NAME,
+ N_PROPS
};
+static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_ui_device_finalize (GObject *object);
@@ -224,7 +226,6 @@ static void
gvc_mixer_ui_device_class_init (GvcMixerUIDeviceClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
- GParamSpec *pspec;
object_class->constructor = gvc_mixer_ui_device_constructor;
object_class->dispose = gvc_mixer_ui_device_dispose;
@@ -232,62 +233,64 @@ gvc_mixer_ui_device_class_init (GvcMixerUIDeviceClass *klass)
object_class->set_property = gvc_mixer_ui_device_set_property;
object_class->get_property = gvc_mixer_ui_device_get_property;
- pspec = g_param_spec_string ("description",
+ obj_props[PROP_DESC_LINE_1] =
+ g_param_spec_string ("description",
"Description construct prop",
"Set first line description",
"no-name-set",
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_DESC_LINE_1, pspec);
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- pspec = g_param_spec_string ("origin",
+ obj_props[PROP_DESC_LINE_2] =
+ g_param_spec_string ("origin",
"origin construct prop",
"Set second line description name",
"no-name-set",
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_DESC_LINE_2, pspec);
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- pspec = g_param_spec_pointer ("card",
+ obj_props[PROP_CARD] =
+ g_param_spec_pointer ("card",
"Card from pulse",
"Set/Get card",
- G_PARAM_READWRITE);
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_CARD, pspec);
-
- pspec = g_param_spec_string ("port-name",
+ obj_props[PROP_PORT_NAME] =
+ g_param_spec_string ("port-name",
"port-name construct prop",
"Set port-name",
NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_PORT_NAME, pspec);
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- pspec = g_param_spec_uint ("stream-id",
+ obj_props[PROP_STREAM_ID] =
+ g_param_spec_uint ("stream-id",
"stream id assigned by gvc-stream",
"Set/Get stream id",
0,
G_MAXUINT,
GVC_MIXER_UI_DEVICE_INVALID,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_STREAM_ID, pspec);
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- pspec = g_param_spec_uint ("type",
+ obj_props[PROP_UI_DEVICE_TYPE] =
+ g_param_spec_uint ("type",
"ui-device type",
"determine whether its an input and output",
- 0, 1, 0, G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_UI_DEVICE_TYPE, pspec);
+ 0, 1, 0,
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- pspec = g_param_spec_boolean ("port-available",
+ obj_props[PROP_PORT_AVAILABLE] =
+ g_param_spec_boolean ("port-available",
"available",
"determine whether this port is available",
FALSE,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_PORT_AVAILABLE, pspec);
+ G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- pspec = g_param_spec_string ("icon-name",
+ obj_props[PROP_ICON_NAME] =
+ g_param_spec_string ("icon-name",
"Icon Name",
"Name of icon to display for this card",
NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT);
- g_object_class_install_property (object_class, PROP_ICON_NAME, pspec);
+ G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPS, obj_props);
}
/* Removes the part of the string that starts with skip_prefix
@@ -650,7 +653,7 @@ gvc_mixer_ui_device_set_icon_name (GvcMixerUIDevice *device,
g_free (device->priv->icon_name);
device->priv->icon_name = g_strdup (icon_name);
- g_object_notify (G_OBJECT (device), "icon-name");
+ g_object_notify_by_pspec (G_OBJECT (device), obj_props[PROP_ICON_NAME]);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]