aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-datetime.c
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2010-12-23 00:32:36 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2010-12-23 00:32:36 +0100
commit1231e651a4e628b9fa7aedc28fa5345faf3b6876 (patch)
treee564440916b2b91a8ce494f5417f01a0b24d83bc /src/indicator-datetime.c
parent0ce656f73bb9426e97f3d1785c92571b6cb01671 (diff)
downloadayatana-indicator-datetime-1231e651a4e628b9fa7aedc28fa5345faf3b6876.tar.gz
ayatana-indicator-datetime-1231e651a4e628b9fa7aedc28fa5345faf3b6876.tar.bz2
ayatana-indicator-datetime-1231e651a4e628b9fa7aedc28fa5345faf3b6876.zip
Add markup support to clock label
This adds exactly the same markup support to the indicator-datetime label respect to the clock gnome panel applet. Now formats like the ones below can be correctly set: <span weight="Bold">%I:%M %p</span> <sup><span rise="3000" font_desc="ubuntu 7.5" color="#DFD8C8" weight="normal">%a %d %b</span></sup>%n<sub><span font_desc="ubuntu 7.5" color="#DFD8C8" weight="bold">%I:%M %p</span></sub> %a <b>%I:%M %p</b>
Diffstat (limited to 'src/indicator-datetime.c')
-rw-r--r--src/indicator-datetime.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c
index 5bf20e9..c325f49 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -557,9 +557,10 @@ update_label (IndicatorDatetime * io)
if (self->priv->label == NULL) return NULL;
- gchar longstr[128];
+ gchar longstr[256];
time_t t;
struct tm *ltime;
+ gboolean use_markup;
t = time(NULL);
ltime = localtime(&t);
@@ -569,10 +570,18 @@ update_label (IndicatorDatetime * io)
return NULL;
}
- strftime(longstr, 128, self->priv->time_string, ltime);
+ strftime(longstr, 256, self->priv->time_string, ltime);
gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL);
- gtk_label_set_label(self->priv->label, utf8);
+
+ if (pango_parse_markup(utf8, -1, 0, NULL, NULL, NULL, NULL))
+ use_markup = TRUE;
+
+ if (use_markup)
+ gtk_label_set_markup(self->priv->label, utf8);
+ else
+ gtk_label_set_text(self->priv->label, utf8);
+
g_free(utf8);
if (self->priv->idle_measure == 0) {
@@ -636,7 +645,12 @@ static gint
measure_string (GtkStyle * style, PangoContext * context, const gchar * string)
{
PangoLayout * layout = pango_layout_new(context);
- pango_layout_set_text(layout, string, -1);
+
+ if (pango_parse_markup(string, -1, 0, NULL, NULL, NULL, NULL))
+ pango_layout_set_markup(layout, string, -1);
+ else
+ pango_layout_set_text(layout, string, -1);
+
pango_layout_set_font_description(layout, style->font_desc);
gint width;
@@ -818,9 +832,9 @@ guess_label_size (IndicatorDatetime * self)
g_debug("Checking against %d posible times", timevals->len);
gint check_time;
for (check_time = 0; check_time < timevals->len; check_time++) {
- gchar longstr[128];
- strftime(longstr, 128, self->priv->time_string, &(g_array_index(timevals, struct tm, check_time)));
-
+ gchar longstr[256];
+ strftime(longstr, 256, self->priv->time_string, &(g_array_index(timevals, struct tm, check_time)));
+
gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL);
gint length = measure_string(style, context, utf8);
g_free(utf8);