86d21d7
From 87248d5c3e0a90c3b0748c7be05a9e6eac231737 Mon Sep 17 00:00:00 2001
86d21d7
From: Ray Strode <rstrode@redhat.com>
86d21d7
Date: Wed, 21 Oct 2009 10:57:59 -0400
86d21d7
Subject: [PATCH] Move date to tooltip in panel clock
86d21d7
86d21d7
It's a bit long at the moment. Dropping the
86d21d7
date makes the screen look a little cleaner, and putting
86d21d7
the date in the tooltip makes it still available for those
86d21d7
people who want to see it.
86d21d7
---
86d21d7
 gui/simple-greeter/gdm-clock-widget.c |   97 +++++++++++++++++++++++----------
86d21d7
 1 files changed, 67 insertions(+), 30 deletions(-)
86d21d7
86d21d7
diff --git a/gui/simple-greeter/gdm-clock-widget.c b/gui/simple-greeter/gdm-clock-widget.c
86d21d7
index a3816d2..9008e6d 100644
86d21d7
--- a/gui/simple-greeter/gdm-clock-widget.c
86d21d7
+++ b/gui/simple-greeter/gdm-clock-widget.c
86d21d7
@@ -44,8 +44,10 @@ struct GdmClockWidgetPrivate
86d21d7
 {
86d21d7
         GtkWidget *label;
86d21d7
         char      *time_format;
86d21d7
+        char      *tooltip_format;
86d21d7
         guint      update_clock_id;
86d21d7
         guint      should_show_seconds : 1;
86d21d7
+        guint      should_show_date : 1;
86d21d7
 };
86d21d7
 
86d21d7
 static void     gdm_clock_widget_class_init  (GdmClockWidgetClass *klass);
86d21d7
@@ -55,38 +57,59 @@ static gboolean update_timeout_cb            (GdmClockWidget      *clock);
86d21d7
 
86d21d7
 G_DEFINE_TYPE (GdmClockWidget, gdm_clock_widget, GTK_TYPE_ALIGNMENT)
86d21d7
 
86d21d7
-static char *
86d21d7
-get_time_format (GdmClockWidget *clock)
86d21d7
+static void
86d21d7
+update_time_format (GdmClockWidget *clock)
86d21d7
 {
86d21d7
-        const char *time_format;
86d21d7
-        const char *date_format;
86d21d7
         char       *clock_format;
86d21d7
-        char       *result;
86d21d7
-
86d21d7
-        time_format = clock->priv->should_show_seconds ? _("%l:%M:%S %p") : _("%l:%M %p");
86d21d7
-        /* translators: replace %e with %d if, when the day of the
86d21d7
-         *              month as a decimal number is a single digit, it
86d21d7
-         *              should begin with a 0 in your locale (e.g. "May
86d21d7
-         *              01" instead of "May  1").
86d21d7
-         */
86d21d7
-        date_format = _("%a %b %e");
86d21d7
-        /* translators: reverse the order of these arguments
86d21d7
-         *              if the time should come before the
86d21d7
-         *              date on a clock in your locale.
86d21d7
-         */
86d21d7
-        clock_format = g_strdup_printf (_("%1$s, %2$s"),
86d21d7
-                                        date_format,
86d21d7
-                                        time_format);
86d21d7
-
86d21d7
-        result = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
86d21d7
-        g_free (clock_format);
86d21d7
-
86d21d7
-        return result;
86d21d7
+        char       *tooltip_format;
86d21d7
+
86d21d7
+        if (clock->priv->should_show_date && clock->priv->should_show_seconds) {
86d21d7
+                /* translators: This is the time format to use when both
86d21d7
+                 * the date and time with seconds are being shown together.
86d21d7
+                 */
86d21d7
+                clock_format = _("%a %b %e, %l:%M:%S %p");
86d21d7
+                tooltip_format = NULL;
86d21d7
+        } else if (clock->priv->should_show_date && !clock->priv->should_show_seconds) {
86d21d7
+                /* translators: This is the time format to use when both
86d21d7
+                 * the date and time without seconds are being shown together.
86d21d7
+                 */
86d21d7
+                clock_format = _("%a %b %e, %l:%M %p");
86d21d7
+
86d21d7
+                tooltip_format = NULL;
86d21d7
+        } else if (!clock->priv->should_show_date && clock->priv->should_show_seconds) {
86d21d7
+                /* translators: This is the time format to use when there is
86d21d7
+                 * no date, just weekday and time with seconds.
86d21d7
+                 */
86d21d7
+                clock_format = _("%a %l:%M:%S %p");
86d21d7
+
86d21d7
+                /* translators: This is the time format to use for the date
86d21d7
+                 */
86d21d7
+                tooltip_format = _("%x");
86d21d7
+        } else {
86d21d7
+                /* translators: This is the time format to use when there is
86d21d7
+                 * no date, just weekday and time without seconds.
86d21d7
+                 */
86d21d7
+                clock_format = _("%a %l:%M %p");
86d21d7
+
86d21d7
+                tooltip_format = _("%x");
86d21d7
+        }
86d21d7
+
86d21d7
+        g_free (clock->priv->time_format);
86d21d7
+        clock->priv->time_format = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
86d21d7
+
86d21d7
+        g_free (clock->priv->tooltip_format);
86d21d7
+
86d21d7
+        if (tooltip_format != NULL) {
86d21d7
+                clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
86d21d7
+        } else {
86d21d7
+                clock->priv->tooltip_format = NULL;
86d21d7
+        }
86d21d7
 }
86d21d7
 
86d21d7
 static void
86d21d7
 update_clock (GtkLabel   *label,
86d21d7
-              const char *format)
86d21d7
+              const char *clock_format,
86d21d7
+              const char *tooltip_format)
86d21d7
 {
86d21d7
         time_t     t;
86d21d7
         struct tm *tm;
86d21d7
@@ -99,13 +122,25 @@ update_clock (GtkLabel   *label,
86d21d7
                 g_warning ("Unable to get broken down local time");
86d21d7
                 return;
86d21d7
         }
86d21d7
-        if (strftime (buf, sizeof (buf), format, tm) == 0) {
86d21d7
-                g_warning ("Couldn't format time: %s", format);
86d21d7
+        if (strftime (buf, sizeof (buf), clock_format, tm) == 0) {
86d21d7
+                g_warning ("Couldn't format time: %s", clock_format);
86d21d7
                 strcpy (buf, "???");
86d21d7
         }
86d21d7
         utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
86d21d7
         gtk_label_set_text (label, utf8);
86d21d7
         g_free (utf8);
86d21d7
+
86d21d7
+        if (tooltip_format != NULL) {
86d21d7
+                if (strftime (buf, sizeof (buf), tooltip_format, tm) == 0) {
86d21d7
+                        g_warning ("Couldn't format tooltip date: %s", tooltip_format);
86d21d7
+                        strcpy (buf, "???");
86d21d7
+                }
86d21d7
+                utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
86d21d7
+                gtk_widget_set_tooltip_text (GTK_WIDGET (label), utf8);
86d21d7
+                g_free (utf8);
86d21d7
+        } else {
86d21d7
+                gtk_widget_set_has_tooltip (GTK_WIDGET (label), FALSE);
86d21d7
+        }
86d21d7
 }
86d21d7
 
86d21d7
 static void
86d21d7
@@ -142,7 +177,8 @@ update_timeout_cb (GdmClockWidget *clock)
86d21d7
 
86d21d7
         if (clock->priv->label != NULL) {
86d21d7
                 update_clock (GTK_LABEL (clock->priv->label),
86d21d7
-                              clock->priv->time_format);
86d21d7
+                              clock->priv->time_format,
86d21d7
+                              clock->priv->tooltip_format);
86d21d7
         }
86d21d7
 
86d21d7
         set_clock_timeout (clock, new_time);
86d21d7
@@ -214,10 +250,11 @@ gdm_clock_widget_init (GdmClockWidget *widget)
86d21d7
         gtk_container_add (GTK_CONTAINER (widget), box);
86d21d7
 
86d21d7
         widget->priv->label = gtk_label_new ("");
86d21d7
+
86d21d7
         gtk_widget_show (widget->priv->label);
86d21d7
         gtk_box_pack_start (GTK_BOX (box), widget->priv->label, FALSE, FALSE, 0);
86d21d7
 
86d21d7
-        widget->priv->time_format = get_time_format (widget);
86d21d7
+        update_time_format (widget);
86d21d7
         update_timeout_cb (widget);
86d21d7
 }
86d21d7
 
86d21d7
-- 
86d21d7
1.6.5.rc2
86d21d7