aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-datetime.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-07-12 20:58:24 -0500
committerTed Gould <ted@gould.cx>2010-07-12 20:58:24 -0500
commitfe6129a2aec01220da2e413a9141980bbd827ae8 (patch)
tree2a45dccba3d7fcc3851e3641e85bd111b16535f0 /src/indicator-datetime.c
parentd051dbe509a1e88a0c3047a19c94130d58a9aa94 (diff)
parenta994c55bc39f419ce752d02a60bc01d5659aad62 (diff)
downloadayatana-indicator-datetime-fe6129a2aec01220da2e413a9141980bbd827ae8.tar.gz
ayatana-indicator-datetime-fe6129a2aec01220da2e413a9141980bbd827ae8.tar.bz2
ayatana-indicator-datetime-fe6129a2aec01220da2e413a9141980bbd827ae8.zip
* Merge upstream
* Adding in GSettings for configuring the format on the panel.
Diffstat (limited to 'src/indicator-datetime.c')
-rw-r--r--src/indicator-datetime.c91
1 files changed, 90 insertions, 1 deletions
diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c
index 6b32f1a..4779313 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -27,6 +27,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
+#include <gio/gio.h>
/* Indicator Stuff */
#include <libindicator/indicator.h>
@@ -63,13 +64,31 @@ struct _IndicatorDatetimePrivate {
GtkLabel * label;
guint timer;
+ gchar * time_format;
+
guint idle_measure;
gint max_width;
IndicatorServiceManager * sm;
DbusmenuGtkMenu * menu;
+
+ GSettings * settings;
};
+/* 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_INTERFACE "org.ayatana.indicator.datetime"
+#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))
@@ -77,6 +96,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 +119,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.",
+ DEFAULT_TIME_FORMAT,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
return;
}
@@ -117,9 +154,22 @@ indicator_datetime_init (IndicatorDatetime *self)
self->priv->idle_measure = 0;
self->priv->max_width = 0;
+ self->priv->time_format = g_strdup(DEFAULT_TIME_FORMAT);
+
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;
@@ -155,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;
}
@@ -162,11 +217,45 @@ 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;
}
+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;
+}
+
+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;
+}
+
/* 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
@@ -209,7 +298,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);