aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-07-16 00:10:47 -0500
committerTed Gould <ted@gould.cx>2010-07-16 00:10:47 -0500
commitb197777ca10de554d7ab4fc6bfa60c89de13139a (patch)
tree82acff56c5a3edb7ea0ca516ed95371d6a83e1d1
parent4da93424d08120d6eb46515d3de65928e4a90b14 (diff)
downloadayatana-indicator-datetime-b197777ca10de554d7ab4fc6bfa60c89de13139a.tar.gz
ayatana-indicator-datetime-b197777ca10de554d7ab4fc6bfa60c89de13139a.tar.bz2
ayatana-indicator-datetime-b197777ca10de554d7ab4fc6bfa60c89de13139a.zip
Gets us somewhere of coming up with a time string. Wow, complex.
-rw-r--r--src/indicator-datetime.c78
1 files changed, 77 insertions, 1 deletions
diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c
index 334ecd8..5bbfd48 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -131,6 +131,7 @@ static GtkLabel * get_label (IndicatorObject * io);
static GtkMenu * get_menu (IndicatorObject * io);
static GVariant * bind_enum_set (const GValue * value, const GVariantType * type, gpointer user_data);
static gboolean bind_enum_get (GValue * value, GVariant * variant, gpointer user_data);
+static gchar * generate_format_string (IndicatorDatetime * self);
/* Indicator Module Config */
INDICATOR_SET_VERSION
@@ -414,7 +415,24 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec
return;
}
- g_debug("Updating format string");
+ /* Get the new format string */
+ gchar * newformat = generate_format_string(self);
+
+ /* check to ensure the format really changed */
+ if (g_strcmp0(self->priv->time_string, newformat) == 0) {
+ g_free(newformat);
+ return;
+ }
+
+ /* Okay now process the change */
+ if (self->priv->time_string != NULL) {
+ g_free(self->priv->time_string);
+ self->priv->time_string = NULL;
+ }
+ self->priv->time_string = newformat;
+
+ /* And update everything */
+ /* TODO: Update everything */
return;
}
@@ -580,6 +598,64 @@ style_changed (GtkWidget * widget, GtkStyle * oldstyle, gpointer data)
return;
}
+/* Tries to figure out what our format string should be. Lots
+ of translator comments in here. */
+static gchar *
+generate_format_string (IndicatorDatetime * self)
+{
+ if (self->priv->time_mode == SETTINGS_TIME_CUSTOM) {
+ return g_strdup(self->priv->custom_string);
+ }
+
+ gboolean twelvehour = TRUE;
+
+ if (self->priv->time_mode == SETTINGS_TIME_LOCALE) {
+ /* TRANSLATORS: This string is used to determine the default
+ clock style for your locale. If it is the string '12' then
+ the default will be a 12-hour clock using AM/PM string. If
+ it is '24' then it will be a 24-hour clock. Users may over
+ ride this setting so it's still important to translate the
+ other strings no matter how this is set. */
+ const gchar * locale_default = _("12");
+
+ if (g_strcmp0(locale_default, "24") == 0) {
+ twelvehour = FALSE;
+ }
+ } else if (self->priv->time_mode == SETTINGS_TIME_24_HOUR) {
+ twelvehour = FALSE;
+ }
+
+ const gchar * time_string = NULL;
+ if (twelvehour) {
+ if (self->priv->show_seconds) {
+ /* TRANSLATORS: A format string for the strftime function for
+ a clock showing 12-hour time with seconds. */
+ time_string = _("%l:%M:%S %p");
+ } else {
+ /* TRANSLATORS: A format string for the strftime function for
+ a clock showing 12-hour time. */
+ time_string = _(DEFAULT_TIME_12_FORMAT);
+ }
+ } else {
+ if (self->priv->show_seconds) {
+ /* TRANSLATORS: A format string for the strftime function for
+ a clock showing 24-hour time with seconds. */
+ time_string = _("%H:%M:%S");
+ } else {
+ /* TRANSLATORS: A format string for the strftime function for
+ a clock showing 24-hour time. */
+ time_string = _(DEFAULT_TIME_24_FORMAT);
+ }
+ }
+
+ /* Checkpoint, let's not fail */
+ g_return_val_if_fail(time_string != NULL, g_strdup(DEFAULT_TIME_FORMAT));
+
+ /* TODO: Date */
+
+ return g_strdup(time_string);
+}
+
/* Grabs the label. Creates it if it doesn't
exist already */
static GtkLabel *