59
58
G_DEFINE_TYPE (GdmClockWidget, gdm_clock_widget, GTK_TYPE_ALIGNMENT)
63
static const char *formats_24h[] = {"%H", "%R", "%T", "%OH", "%k", NULL};
64
const char *t_fmt = nl_langinfo(T_FMT);
67
for (i = 0; formats_24h[i]; ++i) {
68
if (strstr (t_fmt, formats_24h[i]) != NULL) {
62
update_time_format (GdmClockWidget *clock)
76
update_clock_format (GdmClockWidget *clock)
68
79
char *tooltip_format;
72
setlocale(LC_TIME, "");
73
strftime(ampm, sizeof(ampm), "%p", tm);
75
if (strlen(ampm) > 0) {
76
clock_format = "%l:%M %p";
81
setlocale (LC_TIME, "");
83
time_format = "%H:%M";
78
clock_format = "%H:%M";
85
time_format = "%l:%M %p";
80
87
tooltip_format = "%x";
82
89
g_free (clock->priv->time_format);
83
clock->priv->time_format = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
90
clock->priv->time_format = g_locale_from_utf8 (time_format, -1, NULL, NULL, NULL);
85
92
g_free (clock->priv->tooltip_format);
87
if (tooltip_format != NULL) {
88
clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
90
clock->priv->tooltip_format = NULL;
93
clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
95
97
update_clock (GtkLabel *label,
96
const char *clock_format,
98
const char *time_format,
97
99
const char *tooltip_format)
101
char showed_time[32];
103
char displayed_time[32];
102
105
char weekday[32];
110
113
g_warning ("Unable to get broken down local time");
113
if (strftime (showed_time, sizeof (showed_time), clock_format, tm) == 0) {
114
g_warning ("Couldn't format time: %s", clock_format);
115
strcpy (showed_time, "???");
116
if (strftime (displayed_time, sizeof (displayed_time), time_format, tm) == 0) {
117
g_warning ("Couldn't format time: %s", time_format);
118
strcpy (displayed_time, "???");
118
setlocale( LC_TIME, getenv("LC_MESSAGES") );
119
strftime(weekday, sizeof(weekday), "%a", tm);
120
sprintf(buf, "%s %s", weekday, showed_time);
121
if ((msg_locale = getenv ("LC_MESSAGES")) == NULL)
122
msg_locale = getenv ("LANG");
123
setlocale (LC_TIME, msg_locale);
124
if (strftime (weekday, sizeof (weekday), "%a", tm) == 0) {
125
g_warning ("Couldn't format weekday: %%a");
126
strcpy (weekday, "???");
128
sprintf (buf, "%s %s", weekday, displayed_time);
122
130
utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
123
131
markup = g_strdup_printf ("<b><span foreground=\"white\">%s</span></b>", utf8);
128
if (tooltip_format != NULL) {
129
setlocale(LC_TIME, "");
130
if (strftime (buf, sizeof (buf), tooltip_format, tm) == 0) {
131
g_warning ("Couldn't format tooltip date: %s", tooltip_format);
134
utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
135
gtk_widget_set_tooltip_text (GTK_WIDGET (label), utf8);
138
gtk_widget_set_has_tooltip (GTK_WIDGET (label), FALSE);
136
setlocale (LC_TIME, "");
137
if (strftime (buf, sizeof (buf), tooltip_format, tm) == 0) {
138
g_warning ("Couldn't format tooltip date: %s", tooltip_format);
141
utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
142
gtk_widget_set_tooltip_text (GTK_WIDGET (label), utf8);
154
158
g_get_current_time (&tv);
155
159
timeouttime = (G_USEC_PER_SEC - tv.tv_usec) / 1000 + 1;
157
/* timeout of one minute if we don't care about the seconds */
158
if (! clock->priv->should_show_seconds) {
159
timeouttime += 1000 * (59 - now % 60);
160
timeouttime += 1000 * (59 - now % 60);
162
162
clock->priv->update_clock_id = g_timeout_add (timeouttime,
163
163
(GSourceFunc)update_timeout_cb,
274
274
gtk_widget_show (widget->priv->label);
275
275
gtk_box_pack_start (GTK_BOX (box), widget->priv->label, FALSE, FALSE, 0);
277
update_time_format (widget);
277
update_clock_format (widget);
278
278
update_timeout_cb (widget);