5
5
Author: Gunnar Hjalmarsson <ubuntu@gunnar.cc>
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
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
12
12
#include <dirent.h>
13
13
#include <sys/stat.h>
14
14
+#include <locale.h>
15
+#include <langinfo.h>
17
18
#include <glib/gi18n.h>
22
guint update_clock_id;
23
- guint should_show_seconds : 1;
24
- guint should_show_date : 1;
27
static void gdm_clock_widget_class_init (GdmClockWidgetClass *klass);
30
G_DEFINE_TYPE (GdmClockWidget, gdm_clock_widget, GTK_TYPE_ALIGNMENT)
35
+ static const char *formats_24h[] = {"%H", "%R", "%T", "%OH", "%k", NULL};
36
+ const char *t_fmt = nl_langinfo(T_FMT);
39
+ for (i = 0; formats_24h[i]; ++i) {
40
+ if (strstr (t_fmt, formats_24h[i]) != NULL) {
20
update_time_format (GdmClockWidget *clock)
48
-update_time_format (GdmClockWidget *clock)
49
+update_clock_format (GdmClockWidget *clock)
26
53
char *tooltip_format;
28
55
- if (clock->priv->should_show_date && clock->priv->should_show_seconds) {
61
84
- clock_format = _("%a %l:%M %p");
63
86
- tooltip_format = "%x";
64
+ clock_format = "%H:%M";
87
+ time_format = "%l:%M %p";
66
89
+ tooltip_format = "%x";
68
91
g_free (clock->priv->time_format);
69
clock->priv->time_format = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
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);
95
g_free (clock->priv->tooltip_format);
97
- if (tooltip_format != NULL) {
98
- clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
100
- clock->priv->tooltip_format = NULL;
102
+ clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
106
update_clock (GtkLabel *label,
107
- const char *clock_format,
108
+ const char *time_format,
109
const char *tooltip_format)
74
+ char showed_time[32];
113
+ char displayed_time[32];
75
115
+ char weekday[32];
119
@@ -123,27 +113,34 @@
80
120
g_warning ("Unable to get broken down local time");
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, "???");
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, "???");
138
+ sprintf (buf, "%s %s", weekday, displayed_time);
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);
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);
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, "???");
151
- utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
152
- gtk_widget_set_tooltip_text (GTK_WIDGET (label), utf8);
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, "???");
161
+ utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
162
+ gtk_widget_set_tooltip_text (GTK_WIDGET (label), utf8);
169
g_get_current_time (&tv);
170
timeouttime = (G_USEC_PER_SEC - tv.tv_usec) / 1000 + 1;
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);
176
+ timeouttime += 1000 * (59 - now % 60);
178
clock->priv->update_clock_id = g_timeout_add (timeouttime,
179
(GSourceFunc)update_timeout_cb,
181
gtk_widget_show (widget->priv->label);
182
gtk_box_pack_start (GTK_BOX (box), widget->priv->label, FALSE, FALSE, 0);
184
- update_time_format (widget);
185
+ update_clock_format (widget);
186
update_timeout_cb (widget);