From a173af9719ee3183c360c9e2416c1e16e9e68397 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 20:28:37 -0500 Subject: Setting up basic property stuff and making a husk of a first property. --- src/indicator-datetime.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 6b32f1a..deef2f5 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -70,6 +70,17 @@ struct _IndicatorDatetimePrivate { DbusmenuGtkMenu * menu; }; +/* Enum for the properties so that they can be quickly + found and looked up. */ +enum { + PROP_0, + PROP_TIME_FORMAT +}; + +#define PROP_TIME_FORMAT_S "time-format" + +#define SETTING_TIME_FORMAT_S "indicator-time-format" + #define INDICATOR_DATETIME_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_DATETIME_TYPE, IndicatorDatetimePrivate)) @@ -77,6 +88,8 @@ GType indicator_datetime_get_type (void); static void indicator_datetime_class_init (IndicatorDatetimeClass *klass); static void indicator_datetime_init (IndicatorDatetime *self); +static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); +static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static void indicator_datetime_dispose (GObject *object); static void indicator_datetime_finalize (GObject *object); static GtkLabel * get_label (IndicatorObject * io); @@ -98,11 +111,27 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) object_class->dispose = indicator_datetime_dispose; object_class->finalize = indicator_datetime_finalize; + object_class->set_property = set_property; + object_class->get_property = get_property; + IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); io_class->get_label = get_label; io_class->get_menu = get_menu; + /** + IndicatorDatetime:time-format: + + The format that is used to show the time on the panel. + */ + g_object_class_install_property (object_class, + PROP_TIME_FORMAT, + g_param_spec_string(PROP_TIME_FORMAT_S, + "The format that is used to show the time on the panel.", + "A format string in the form used to pass to strftime to make a string for displaying on the panel.", + "%l:%M %p", + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + return; } @@ -167,6 +196,20 @@ indicator_datetime_finalize (GObject *object) return; } +static void +set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) +{ + + return; +} + +static void +get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) +{ + + return; +} + /* Looks at the size of the label, if it grew beyond what we thought was the max, make sure it doesn't shrink again. */ static gboolean -- cgit v1.2.3 From 72de11ccac28b0bad7485a5501bc87329560f39b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 20:35:50 -0500 Subject: Setting up a 'time_format' variable and pulling it into a property. --- src/indicator-datetime.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index deef2f5..847cb8e 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -63,6 +63,8 @@ struct _IndicatorDatetimePrivate { GtkLabel * label; guint timer; + gchar * time_format; + guint idle_measure; gint max_width; @@ -146,6 +148,8 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->idle_measure = 0; self->priv->max_width = 0; + self->priv->time_format = NULL; + self->priv->sm = NULL; self->priv->menu = NULL; @@ -191,6 +195,12 @@ indicator_datetime_dispose (GObject *object) static void indicator_datetime_finalize (GObject *object) { + IndicatorDatetime * self = INDICATOR_DATETIME(object); + + if (self->priv->time_format != NULL) { + g_free(self->priv->time_format); + self->priv->time_format = NULL; + } G_OBJECT_CLASS (indicator_datetime_parent_class)->finalize (object); return; @@ -199,6 +209,16 @@ indicator_datetime_finalize (GObject *object) static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { + g_return_if_fail(prop_id == PROP_TIME_FORMAT); + IndicatorDatetime * self = INDICATOR_DATETIME(object); + + if (self->priv->time_format != NULL) { + g_free(self->priv->time_format); + self->priv->time_format = NULL; + } + + self->priv->time_format = g_value_dup_string(value); + g_debug("Changing time format to '%s'", self->priv->time_format); return; } @@ -206,6 +226,10 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { + g_return_if_fail(prop_id == PROP_TIME_FORMAT); + IndicatorDatetime * self = INDICATOR_DATETIME(object); + + g_value_set_string(value, self->priv->time_format); return; } -- cgit v1.2.3 From 5c0172d8d390f7f5ff1d8475ef7aea40106f58ea Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 20:42:55 -0500 Subject: Moving the default format into a define and using our new variable. --- src/indicator-datetime.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 847cb8e..854bf4d 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -83,6 +83,8 @@ enum { #define SETTING_TIME_FORMAT_S "indicator-time-format" +#define DEFAULT_TIME_FORMAT "%l:%M %p" + #define INDICATOR_DATETIME_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_DATETIME_TYPE, IndicatorDatetimePrivate)) @@ -131,7 +133,7 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) g_param_spec_string(PROP_TIME_FORMAT_S, "The format that is used to show the time on the panel.", "A format string in the form used to pass to strftime to make a string for displaying on the panel.", - "%l:%M %p", + DEFAULT_TIME_FORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); return; @@ -148,7 +150,7 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->idle_measure = 0; self->priv->max_width = 0; - self->priv->time_format = NULL; + self->priv->time_format = g_strdup(DEFAULT_TIME_FORMAT); self->priv->sm = NULL; self->priv->menu = NULL; @@ -276,7 +278,7 @@ update_label (IndicatorDatetime * io) return; } - strftime(longstr, 128, "%l:%M %p", ltime); + strftime(longstr, 128, self->priv->time_format, ltime); gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL); gtk_label_set_label(self->priv->label, utf8); -- cgit v1.2.3 From a994c55bc39f419ce752d02a60bc01d5659aad62 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 12 Jul 2010 20:56:23 -0500 Subject: Going into the gsettings world. --- src/indicator-datetime.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 854bf4d..4779313 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -27,6 +27,7 @@ with this program. If not, see . #include #include #include +#include /* Indicator Stuff */ #include @@ -70,6 +71,8 @@ struct _IndicatorDatetimePrivate { IndicatorServiceManager * sm; DbusmenuGtkMenu * menu; + + GSettings * settings; }; /* Enum for the properties so that they can be quickly @@ -81,6 +84,7 @@ enum { #define PROP_TIME_FORMAT_S "time-format" +#define SETTING_INTERFACE "org.ayatana.indicator.datetime" #define SETTING_TIME_FORMAT_S "indicator-time-format" #define DEFAULT_TIME_FORMAT "%l:%M %p" @@ -155,6 +159,17 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->sm = NULL; self->priv->menu = NULL; + self->priv->settings = g_settings_new(SETTING_INTERFACE); + if (self->priv->settings != NULL) { + g_settings_bind(self->priv->settings, + SETTING_TIME_FORMAT_S, + self, + PROP_TIME_FORMAT_S, + G_SETTINGS_BIND_DEFAULT); + } else { + g_warning("Unable to get settings for '" SETTING_INTERFACE "'"); + } + self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION); return; @@ -190,6 +205,11 @@ indicator_datetime_dispose (GObject *object) self->priv->sm = NULL; } + if (self->priv->settings != NULL) { + g_object_unref(G_OBJECT(self->priv->settings)); + self->priv->settings = NULL; + } + G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object); return; } -- cgit v1.2.3