Store property GParamSpecs in an array for notify emission

This commit is contained in:
Gergely Polonkai 2014-08-13 00:51:26 +02:00
parent 68b46d2aee
commit 8bf5a49c4b
1 changed files with 89 additions and 78 deletions

View File

@ -79,10 +79,12 @@ enum {
PROP_GREGORIAN_SECOND, PROP_GREGORIAN_SECOND,
PROP_GREGORIAN_MICROSECOND, PROP_GREGORIAN_MICROSECOND,
PROP_GREGORIAN_TIMEZONE_OFFSET, PROP_GREGORIAN_TIMEZONE_OFFSET,
PROP_JULIAN_DAY_VALID PROP_JULIAN_DAY_VALID,
PROP_COUNT
}; };
static guint gswe_timestamp_signals[SIGNAL_LAST] = { 0 }; static guint gswe_timestamp_signals[SIGNAL_LAST] = { 0 };
static GParamSpec *gswe_timestamp_props[PROP_COUNT];
static void gswe_timestamp_dispose( static void gswe_timestamp_dispose(
GObject *gobject); GObject *gobject);
@ -150,15 +152,16 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* Otherwise, the values are recalculated only upon request (e.g. on * Otherwise, the values are recalculated only upon request (e.g. on
* calling gswe_timestamp_get_julian_day()). * calling gswe_timestamp_get_julian_day()).
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_INSTANT_RECALC] = g_param_spec_boolean(
gobject_class,
PROP_INSTANT_RECALC,
g_param_spec_boolean(
"instant-recalc", "instant-recalc",
"Instant recalculation", "Instant recalculation",
"Instantly recalculate values upon parameter change", "Instantly recalculate values upon parameter change",
FALSE, G_PARAM_CONSTRUCT | G_PARAM_READWRITE FALSE, G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_INSTANT_RECALC,
gswe_timestamp_props[PROP_INSTANT_RECALC]
); );
/** /**
@ -169,16 +172,16 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* Otherwise, the Gregorian date components will be recalculated upon * Otherwise, the Gregorian date components will be recalculated upon
* request. * request.
*/ */
gswe_timestamp_props[PROP_GREGORIAN_VALID] = g_param_spec_boolean(
"gregorian-valid",
"Gregorian date is valid",
"TRUE if the Gregorian date components are considered as valid.",
TRUE, G_PARAM_READABLE
);
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
PROP_GREGORIAN_VALID, PROP_GREGORIAN_VALID,
g_param_spec_boolean( gswe_timestamp_props[PROP_GREGORIAN_VALID]
"gregorian-valid",
"Gregorian date is valid",
"TRUE if the Gregorian date components "
"are considered as valid.",
TRUE, G_PARAM_READABLE
)
); );
/** /**
@ -186,16 +189,17 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* *
* The Gregorian year of the timestamp * The Gregorian year of the timestamp
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_GREGORIAN_YEAR] = g_param_spec_int(
gobject_class,
PROP_GREGORIAN_YEAR,
g_param_spec_int(
"gregorian-year", "gregorian-year",
"Gregorian year", "Gregorian year",
"The year according to the Gregorian calendar", "The year according to the Gregorian calendar",
G_MININT, G_MAXINT, g_date_time_get_year(local_time), G_MININT, G_MAXINT, g_date_time_get_year(local_time),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_GREGORIAN_YEAR,
gswe_timestamp_props[PROP_GREGORIAN_YEAR]
); );
/** /**
@ -203,16 +207,17 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* *
* The Gregorian month of the timestamp * The Gregorian month of the timestamp
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_GREGORIAN_MONTH] = g_param_spec_int(
gobject_class,
PROP_GREGORIAN_MONTH,
g_param_spec_int(
"gregorian-month", "gregorian-month",
"Gregorian month", "Gregorian month",
"The month according to the Gregorian calendar", "The month according to the Gregorian calendar",
1, 12, g_date_time_get_month(local_time), 1, 12, g_date_time_get_month(local_time),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_GREGORIAN_MONTH,
gswe_timestamp_props[PROP_GREGORIAN_MONTH]
); );
/** /**
@ -220,16 +225,17 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* *
* The Gregorian day of the timestamp * The Gregorian day of the timestamp
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_GREGORIAN_DAY] = g_param_spec_int(
gobject_class,
PROP_GREGORIAN_DAY,
g_param_spec_int(
"gregorian-day", "gregorian-day",
"Gregorian day", "Gregorian day",
"The day according to the Gregorian calendar", "The day according to the Gregorian calendar",
1, 31, g_date_time_get_day_of_month(local_time), 1, 31, g_date_time_get_day_of_month(local_time),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_GREGORIAN_DAY,
gswe_timestamp_props[PROP_GREGORIAN_DAY]
); );
/** /**
@ -237,16 +243,17 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* *
* The Gregorian hour of the timestamp * The Gregorian hour of the timestamp
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_GREGORIAN_HOUR] = g_param_spec_int(
gobject_class,
PROP_GREGORIAN_HOUR,
g_param_spec_int(
"gregorian-hour", "gregorian-hour",
"Gregorian hour", "Gregorian hour",
"The hour according to the Gregorian calendar", "The hour according to the Gregorian calendar",
0, 23, g_date_time_get_hour(local_time), 0, 23, g_date_time_get_hour(local_time),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_GREGORIAN_HOUR,
gswe_timestamp_props[PROP_GREGORIAN_HOUR]
); );
/** /**
@ -254,16 +261,17 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* *
* The Gregorian minute of the timestamp * The Gregorian minute of the timestamp
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_GREGORIAN_MINUTE] = g_param_spec_int(
gobject_class,
PROP_GREGORIAN_MINUTE,
g_param_spec_int(
"gregorian-minute", "gregorian-minute",
"Gregorian minute", "Gregorian minute",
"The minute according to the Gregorian calendar", "The minute according to the Gregorian calendar",
0, 59, g_date_time_get_minute(local_time), 0, 59, g_date_time_get_minute(local_time),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_GREGORIAN_MINUTE,
gswe_timestamp_props[PROP_GREGORIAN_MINUTE]
); );
/** /**
@ -271,16 +279,17 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* *
* The Gregorian second of the timestamp * The Gregorian second of the timestamp
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_GREGORIAN_SECOND] = g_param_spec_int(
gobject_class,
PROP_GREGORIAN_SECOND,
g_param_spec_int(
"gregorian-second", "gregorian-second",
"Gregorian second", "Gregorian second",
"The second according to the Gregorian calendar", "The second according to the Gregorian calendar",
0, 61, g_date_time_get_second(local_time), 0, 61, g_date_time_get_second(local_time),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_GREGORIAN_SECOND,
gswe_timestamp_props[PROP_GREGORIAN_SECOND]
); );
/** /**
@ -288,16 +297,17 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* *
* The Gregorian microsecond of the timestamp * The Gregorian microsecond of the timestamp
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_GREGORIAN_MICROSECOND] = g_param_spec_int(
gobject_class,
PROP_GREGORIAN_MICROSECOND,
g_param_spec_int(
"gregorian-microsecond", "gregorian-microsecond",
"Gregorian microsecond", "Gregorian microsecond",
"The microsecond according to the Gregorian calendar", "The microsecond according to the Gregorian calendar",
0, G_MAXINT, g_date_time_get_microsecond(local_time), 0, G_MAXINT, g_date_time_get_microsecond(local_time),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_GREGORIAN_MICROSECOND,
gswe_timestamp_props[PROP_GREGORIAN_MICROSECOND]
); );
/** /**
@ -305,17 +315,18 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* *
* The time zone offset in hours, relative to UTC * The time zone offset in hours, relative to UTC
*/ */
g_object_class_install_property( gswe_timestamp_props[PROP_GREGORIAN_TIMEZONE_OFFSET] = g_param_spec_double(
gobject_class,
PROP_GREGORIAN_TIMEZONE_OFFSET,
g_param_spec_double(
"gregorian-timezone-offset", "gregorian-timezone-offset",
"Gregorian timezone offset", "Gregorian timezone offset",
"The offset relative to UTC in the Gregorian calendar", "The offset relative to UTC in the Gregorian calendar",
-24.0, 24.0, -24.0, 24.0,
0.0, 0.0,
G_PARAM_CONSTRUCT | G_PARAM_READWRITE G_PARAM_CONSTRUCT | G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_GREGORIAN_TIMEZONE_OFFSET,
gswe_timestamp_props[PROP_GREGORIAN_TIMEZONE_OFFSET]
); );
/** /**
@ -325,16 +336,16 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
* currently considered as valid, thus, no recalculation is needed. * currently considered as valid, thus, no recalculation is needed.
* Otherwise, the Julian day components will be recalculated upon request. * Otherwise, the Julian day components will be recalculated upon request.
*/ */
gswe_timestamp_props[PROP_JULIAN_DAY_VALID] = g_param_spec_boolean(
"julian-day-valid",
"Julian day is valid",
"TRUE if the Julian day components are considered as valid.",
TRUE, G_PARAM_READABLE
);
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
PROP_JULIAN_DAY_VALID, PROP_JULIAN_DAY_VALID,
g_param_spec_boolean( gswe_timestamp_props[PROP_JULIAN_DAY_VALID]
"julian-day-valid",
"Julian day is valid",
"TRUE if the Julian day components "
"are considered as valid.",
TRUE, G_PARAM_READABLE
)
); );
g_date_time_unref(local_time); g_date_time_unref(local_time);