~ubuntu-branches/ubuntu/raring/gdm/raring

« back to all changes in this revision

Viewing changes to debian/patches/45_time_display_on_greeter.patch

  • Committer: Package Import Robot
  • Author(s): Gunnar Hjalmarsson
  • Date: 2012-01-31 17:45:20 UTC
  • Revision ID: package-import@ubuntu.com-20120131174520-5y15hrfu5v9e6orf
Tags: 3.0.4-0ubuntu15
* debian/patches/45_time_display_on_greeter.patch:
  - Adapt to forwarded version of the patch.
  - Let the LANG environment variable serve as fallback when
    determining the display language for the weekday, since LANG
    has been redefined in Ubuntu to represent language instead of
    regional formats. This change also ought to make the patch work
    as intended upstream.
* debian/gdm.upstart:
  - No need to export LC_MESSAGES since it's not set any longer.
* debian/patches/ubuntu_no_LANG_setting_in_Xsession.patch:
  - Renamed from "ubuntu_i18n_oneiric.patch".
  - No need to unset LC_MESSAGES etc. since they are not set any
    longer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
Forwarded: yes
5
5
Author: Gunnar Hjalmarsson <ubuntu@gunnar.cc>
6
6
 
7
 
diff -Nur -x '*.orig' -x '*~' gdm-3.0.0//gui/simple-greeter/gdm-clock-widget.c gdm-3.0.0.new//gui/simple-greeter/gdm-clock-widget.c
8
 
--- gdm-3.0.0//gui/simple-greeter/gdm-clock-widget.c    2011-04-04 16:37:16.000000000 +0200
9
 
+++ gdm-3.0.0.new//gui/simple-greeter/gdm-clock-widget.c        2011-06-05 23:55:31.140297043 +0200
10
 
@@ -30,6 +30,7 @@
 
7
diff -Nur -x '*.orig' -x '*~' gdm-3.0.4/gui/simple-greeter/gdm-clock-widget.c gdm-3.0.4.new/gui/simple-greeter/gdm-clock-widget.c
 
8
--- gdm-3.0.4/gui/simple-greeter/gdm-clock-widget.c     2011-05-31 17:46:56.000000000 +0200
 
9
+++ gdm-3.0.4.new/gui/simple-greeter/gdm-clock-widget.c 2011-11-19 21:57:42.501647152 +0100
 
10
@@ -30,6 +30,8 @@
11
11
 #include <errno.h>
12
12
 #include <dirent.h>
13
13
 #include <sys/stat.h>
14
14
+#include <locale.h>
 
15
+#include <langinfo.h>
15
16
 
16
17
 #include <glib.h>
17
18
 #include <glib/gi18n.h>
18
 
@@ -60,39 +61,23 @@
 
19
@@ -46,8 +48,6 @@
 
20
         char      *time_format;
 
21
         char      *tooltip_format;
 
22
         guint      update_clock_id;
 
23
-        guint      should_show_seconds : 1;
 
24
-        guint      should_show_date : 1;
 
25
 };
 
26
 
 
27
 static void     gdm_clock_widget_class_init  (GdmClockWidgetClass *klass);
 
28
@@ -57,62 +57,52 @@
 
29
 
 
30
 G_DEFINE_TYPE (GdmClockWidget, gdm_clock_widget, GTK_TYPE_ALIGNMENT)
 
31
 
 
32
+gboolean
 
33
+is_24h (void)
 
34
+{
 
35
+        static const char *formats_24h[] = {"%H", "%R", "%T", "%OH", "%k", NULL};
 
36
+        const char        *t_fmt = nl_langinfo(T_FMT);
 
37
+        int                i;
 
38
+
 
39
+        for (i = 0; formats_24h[i]; ++i) {
 
40
+                if (strstr (t_fmt, formats_24h[i]) != NULL) {
 
41
+                        return TRUE;
 
42
+                }
 
43
+        }
 
44
+        return FALSE;
 
45
+}
 
46
+
19
47
 static void
20
 
 update_time_format (GdmClockWidget *clock)
 
48
-update_time_format (GdmClockWidget *clock)
 
49
+update_clock_format (GdmClockWidget *clock)
21
50
 {
22
 
+        time_t      t;
23
 
+        struct tm  *tm;
24
 
+        char        ampm[16];
25
 
         char       *clock_format;
 
51
-        char       *clock_format;
 
52
+        char       *time_format;
26
53
         char       *tooltip_format;
27
54
 
28
55
-        if (clock->priv->should_show_date && clock->priv->should_show_seconds) {
47
74
-                /* translators: This is the time format to use for the date
48
75
-                 */
49
76
-                tooltip_format = "%x";
50
 
+        time (&t);
51
 
+        tm = localtime (&t);
52
 
+        setlocale(LC_TIME, "");
53
 
+        strftime(ampm, sizeof(ampm), "%p", tm);
54
 
55
 
+        if (strlen(ampm) > 0) {
56
 
+                clock_format = "%l:%M %p";
 
77
+        setlocale (LC_TIME, "");
 
78
+        if (is_24h ()) {
 
79
+                time_format = "%H:%M";
57
80
         } else {
58
81
-                /* translators: This is the time format to use when there is
59
82
-                 * no date, just weekday and time without seconds.
61
84
-                clock_format = _("%a %l:%M %p");
62
85
-
63
86
-                tooltip_format = "%x";
64
 
+                clock_format = "%H:%M";
 
87
+                time_format = "%l:%M %p";
65
88
         }
66
89
+        tooltip_format = "%x";
67
90
 
68
91
         g_free (clock->priv->time_format);
69
 
         clock->priv->time_format = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
70
 
@@ -113,6 +98,8 @@
 
92
-        clock->priv->time_format = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
 
93
+        clock->priv->time_format = g_locale_from_utf8 (time_format, -1, NULL, NULL, NULL);
 
94
 
 
95
         g_free (clock->priv->tooltip_format);
 
96
-
 
97
-        if (tooltip_format != NULL) {
 
98
-                clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
 
99
-        } else {
 
100
-                clock->priv->tooltip_format = NULL;
 
101
-        }
 
102
+        clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
 
103
 }
 
104
 
 
105
 static void
 
106
 update_clock (GtkLabel   *label,
 
107
-              const char *clock_format,
 
108
+              const char *time_format,
 
109
               const char *tooltip_format)
71
110
 {
72
111
         time_t     t;
73
112
         struct tm *tm;
74
 
+        char       showed_time[32];
 
113
+        char       displayed_time[32];
 
114
+        char      *msg_locale;
75
115
+        char       weekday[32];
76
116
         char       buf[256];
77
117
         char      *utf8;
78
118
         char      *markup;
79
 
@@ -123,10 +110,15 @@
 
119
@@ -123,27 +113,34 @@
80
120
                 g_warning ("Unable to get broken down local time");
81
121
                 return;
82
122
         }
83
123
-        if (strftime (buf, sizeof (buf), clock_format, tm) == 0) {
84
 
+        if (strftime (showed_time, sizeof (showed_time), clock_format, tm) == 0) {
85
 
                 g_warning ("Couldn't format time: %s", clock_format);
 
124
-                g_warning ("Couldn't format time: %s", clock_format);
86
125
-                strcpy (buf, "???");
87
 
+                strcpy (showed_time, "???");
 
126
+        if (strftime (displayed_time, sizeof (displayed_time), time_format, tm) == 0) {
 
127
+                g_warning ("Couldn't format time: %s", time_format);
 
128
+                strcpy (displayed_time, "???");
88
129
         }
89
130
+
90
 
+        setlocale( LC_TIME, getenv("LC_MESSAGES") );
91
 
+        strftime(weekday, sizeof(weekday), "%a", tm);
92
 
+        sprintf(buf, "%s %s", weekday, showed_time);
 
131
+        if ((msg_locale = getenv ("LC_MESSAGES")) == NULL)
 
132
+                msg_locale = getenv ("LANG");
 
133
+        setlocale (LC_TIME, msg_locale);
 
134
+        if (strftime (weekday, sizeof (weekday), "%a", tm) == 0) {
 
135
+                g_warning ("Couldn't format weekday: %%a");
 
136
+                strcpy (weekday, "???");
 
137
+        }
 
138
+        sprintf (buf, "%s %s", weekday, displayed_time);
93
139
+
94
140
         utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
95
141
         markup = g_strdup_printf ("<b><span foreground=\"white\">%s</span></b>", utf8);
96
142
         gtk_label_set_markup (label, markup);
97
 
@@ -134,6 +126,7 @@
 
143
         g_free (markup);
98
144
         g_free (utf8);
99
145
 
100
 
         if (tooltip_format != NULL) {
101
 
+                setlocale(LC_TIME, "");
102
 
                 if (strftime (buf, sizeof (buf), tooltip_format, tm) == 0) {
103
 
                         g_warning ("Couldn't format tooltip date: %s", tooltip_format);
104
 
                         strcpy (buf, "???");
 
146
-        if (tooltip_format != NULL) {
 
147
-                if (strftime (buf, sizeof (buf), tooltip_format, tm) == 0) {
 
148
-                        g_warning ("Couldn't format tooltip date: %s", tooltip_format);
 
149
-                        strcpy (buf, "???");
 
150
-                }
 
151
-                utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
 
152
-                gtk_widget_set_tooltip_text (GTK_WIDGET (label), utf8);
 
153
-                g_free (utf8);
 
154
-        } else {
 
155
-                gtk_widget_set_has_tooltip (GTK_WIDGET (label), FALSE);
 
156
+        setlocale (LC_TIME, "");
 
157
+        if (strftime (buf, sizeof (buf), tooltip_format, tm) == 0) {
 
158
+                g_warning ("Couldn't format tooltip date: %s", tooltip_format);
 
159
+                strcpy (buf, "???");
 
160
         }
 
161
+        utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
 
162
+        gtk_widget_set_tooltip_text (GTK_WIDGET (label), utf8);
 
163
+        g_free (utf8);
 
164
 }
 
165
 
 
166
 static void
 
167
@@ -160,11 +157,7 @@
 
168
 
 
169
         g_get_current_time (&tv);
 
170
         timeouttime = (G_USEC_PER_SEC - tv.tv_usec) / 1000 + 1;
 
171
-
 
172
-        /* timeout of one minute if we don't care about the seconds */
 
173
-        if (! clock->priv->should_show_seconds) {
 
174
-                timeouttime += 1000 * (59 - now % 60);
 
175
-        }
 
176
+        timeouttime += 1000 * (59 - now % 60);
 
177
 
 
178
         clock->priv->update_clock_id = g_timeout_add (timeouttime,
 
179
                                                       (GSourceFunc)update_timeout_cb,
 
180
@@ -281,7 +274,7 @@
 
181
         gtk_widget_show (widget->priv->label);
 
182
         gtk_box_pack_start (GTK_BOX (box), widget->priv->label, FALSE, FALSE, 0);
 
183
 
 
184
-        update_time_format (widget);
 
185
+        update_clock_format (widget);
 
186
         update_timeout_cb (widget);
 
187
 }
 
188