gnome-panel r10847 - trunk/applets/clock
- From: matthiasc svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-panel r10847 - trunk/applets/clock
- Date: Tue, 19 Feb 2008 00:44:31 +0000 (GMT)
Author: matthiasc
Date: Tue Feb 19 00:44:31 2008
New Revision: 10847
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=10847&view=rev
Log:
2008-02-18 Matthias Clasen <mclasen redhat com>
Fix the time display in the location tiles to be the time at the
location (currently, all tiles show the local time, which is rather
pointless). Also fix the problem where the time is invisible for
a while after the popup has been shown.
This introduces some new strings (the strftime formats used for
formatting the time for the tiles), but there should be little
need to translate them.
* clock-location-tile.[hc]: Replace the need-formatted-time signal
by a need-clock-format. Do our own time formatting, since the
needs are somewhat different from the time display in the panel,
and we really only want to respect the 12/24h preference.
* clock.c: Handle the need-clock-format signal.
* clock-marshallers.list: Add INT:VOID marshaller for the
need-clock-format signal.
Modified:
trunk/applets/clock/ChangeLog
trunk/applets/clock/clock-location-tile.c
trunk/applets/clock/clock-location-tile.h
trunk/applets/clock/clock-marshallers.list
trunk/applets/clock/clock.c
Modified: trunk/applets/clock/clock-location-tile.c
==============================================================================
--- trunk/applets/clock/clock-location-tile.c (original)
+++ trunk/applets/clock/clock-location-tile.c Tue Feb 19 00:44:31 2008
@@ -11,6 +11,7 @@
#include "clock-face.h"
#include "clock-location-tile.h"
#include "clock-location.h"
+#include "clock-utils.h"
#include "clock-marshallers.h"
#include "set-timezone.h"
@@ -20,7 +21,7 @@
TILE_PRESSED,
TIMEZONE_SET,
WEATHER_UPDATED,
- NEED_FORMATTED_TIME,
+ NEED_CLOCK_FORMAT,
LAST_SIGNAL
};
@@ -122,14 +123,15 @@
G_TYPE_NONE, 2,
G_TYPE_OBJECT,
G_TYPE_STRING);
- signals[NEED_FORMATTED_TIME] = g_signal_new ("need-formatted-time",
- G_TYPE_FROM_CLASS (g_obj_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (ClockLocationTileClass, need_formatted_time),
- NULL,
- NULL,
- _clock_marshal_STRING__VOID,
- G_TYPE_STRING, 0);
+
+ signals[NEED_CLOCK_FORMAT] = g_signal_new ("need-clock-format",
+ G_TYPE_FROM_CLASS (g_obj_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ClockLocationTileClass, need_clock_format),
+ NULL,
+ NULL,
+ _clock_marshal_INT__VOID,
+ G_TYPE_INT, 0);
}
static void
@@ -310,7 +312,7 @@
gtk_container_add (GTK_CONTAINER (priv->box), alignment);
gtk_container_add (GTK_CONTAINER (this), priv->box);
- clock_location_tile_refresh (this);
+ clock_location_tile_refresh (this, TRUE);
}
static gboolean
@@ -378,13 +380,94 @@
g_signal_emit (this, signals[WEATHER_UPDATED], 0, weather_icon, temperature);
}
+static char *
+format_time (struct tm *now,
+ char *tzname,
+ ClockFormat clock_format,
+ long offset)
+{
+ char buf[256];
+ char *format;
+ time_t local_t;
+ struct tm local_now;
+ char *utf8;
+ char *tmp;
+ long hours, minutes;
+
+ time (&local_t);
+ localtime_r (&local_t, &local_now);
+
+ if (local_now.tm_wday != now->tm_wday) {
+ if (clock_format == CLOCK_FORMAT_12) {
+/* translators: This is a strftime format string that is used for formatting
+ * the time that is displayed for locations in the popup. This string is used
+ * for 12-hour format (the %p expands to am/pm), when the local weekday differs
+ * from the weekday at the location (the %A expands to the weekday).
+ * There should be little need to translate this string.
+ */
+ format = _("%l:%M <small>%p (%A)</small>");
+ }
+ else {
+/* translators: This is a strftime format string that is used for formatting
+ * the time that is displayed for locations in the popup. This string is used
+ * for 24-hour format (the %p expands to am/pm), when the local weekday differs
+ * from the weekday at the location (the %A expands to the weekday).
+ * There should be little need to translate this string.
+ */
+ format = _("%H:%M <small>(%A)</small>");
+ }
+ }
+ else {
+ if (clock_format == CLOCK_FORMAT_12) {
+/* translators: This is a strftime format string that is used for formatting
+ * the time that is displayed for locations in the popup. This string is used
+ * for 12-hour format (the %p expands to am/pm).
+ * There should be little need to translate this string.
+ */
+ format = _("%l:%M <small>%p</small>");
+ }
+ else {
+/* translators: This is a strftime format string that is used for formatting
+ * the time that is displayed for locations in the popup. This string is used
+ * for 24-hour format.
+ * There should be little need to translate this string.
+ */
+ format = _("%H:%M");
+ }
+ }
+
+ if (strftime (buf, sizeof (buf), format, now) <= 0) {
+ strcpy (buf, "???");
+ }
+
+ hours = offset / 3600;
+ minutes = labs (offset % 3600) / 60;
+
+ if (hours != 0 && minutes != 0) {
+ tmp = g_strdup_printf ("%s <small>%s %+ld:%ld</small>", buf, tzname, hours, minutes);
+ }
+ else if (hours != 0) {
+ tmp = g_strdup_printf ("%s <small>%s %+ld</small>", buf, tzname, hours);
+ }
+ else {
+ tmp = g_strdup_printf ("%s <small>%s</small>", buf, tzname);
+ }
+
+ utf8 = g_locale_to_utf8 (tmp, -1, NULL, NULL, NULL);
+
+ g_free (tmp);
+
+ return utf8;
+}
+
void
-clock_location_tile_refresh (ClockLocationTile *this)
+clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
{
ClockLocationTilePrivate *priv = PRIVATE (this);
- gchar *tmp, *tmp2, *tzname;
+ gchar *tmp, *tzname;
struct tm now;
long offset, hours, minutes;
+ int format;
g_return_if_fail (IS_CLOCK_LOCATION_TILE (this));
@@ -411,7 +494,7 @@
clock_face_refresh (CLOCK_FACE (priv->clock_face));
}
- if (!clock_needs_label_refresh (this)) {
+ if (!force_refresh && !clock_needs_label_refresh (this)) {
return;
}
@@ -426,26 +509,15 @@
gtk_label_set_markup (GTK_LABEL (priv->city_label), tmp);
g_free (tmp);
- tmp = NULL;
- g_signal_emit (this, signals[NEED_FORMATTED_TIME], 0, &tmp);
+ g_signal_emit (this, signals[NEED_CLOCK_FORMAT], 0, &format);
offset = - priv->last_offset;
- hours = offset / 3600;
- minutes = labs (offset % 3600) / 60;
+ tmp = format_time (&now, tzname, format, offset);
- if (hours != 0 && minutes != 0)
- tmp2 = g_strdup_printf ("%s <small>%+ld:%ld</small>", tmp ? tmp : "", hours, minutes);
- else if (hours != 0)
- tmp2 = g_strdup_printf ("%s <small>%+ld</small>", tmp ? tmp : "", hours);
- else {
- tmp2 = tmp;
- tmp = NULL;
- }
+ gtk_label_set_markup (GTK_LABEL (priv->time_label), tmp);
- gtk_label_set_markup (GTK_LABEL (priv->time_label), tmp2);
g_free (tmp);
- g_free (tmp2);
}
void
Modified: trunk/applets/clock/clock-location-tile.h
==============================================================================
--- trunk/applets/clock/clock-location-tile.h (original)
+++ trunk/applets/clock/clock-location-tile.h Tue Feb 19 00:44:31 2008
@@ -28,7 +28,7 @@
void (* tile_pressed) (ClockLocationTile *tile);
void (* timezone_set) (ClockLocationTile *tile);
void (* weather_updated) (ClockLocationTile *tile, GdkPixbuf *weather_icon, const char *temperature);
- char *(* need_formatted_time) (ClockLocationTile *tile);
+ int (* need_clock_format) (ClockLocationTile *tile);
} ClockLocationTileClass;
GType clock_location_tile_get_type (void);
@@ -40,7 +40,8 @@
void weather_info_setup_tooltip (WeatherInfo *info, GtkTooltip *tip);
-void clock_location_tile_refresh (ClockLocationTile *this);
+void clock_location_tile_refresh (ClockLocationTile *this,
+ gboolean force_refresh);
G_END_DECLS
#endif /* __CLOCK_H__ */
Modified: trunk/applets/clock/clock-marshallers.list
==============================================================================
--- trunk/applets/clock/clock-marshallers.list (original)
+++ trunk/applets/clock/clock-marshallers.list Tue Feb 19 00:44:31 2008
@@ -3,4 +3,4 @@
VOID:POINTER
POINTER:VOID
VOID:OBJECT,STRING
-STRING:VOID
+INT:VOID
Modified: trunk/applets/clock/clock.c
==============================================================================
--- trunk/applets/clock/clock.c (original)
+++ trunk/applets/clock/clock.c Tue Feb 19 00:44:31 2008
@@ -508,7 +508,7 @@
ClockLocationTile *tile;
tile = CLOCK_LOCATION_TILE (l->data);
- clock_location_tile_refresh (tile);
+ clock_location_tile_refresh (tile, FALSE);
}
}
@@ -1084,12 +1084,12 @@
gtk_label_set_text (GTK_LABEL (cd->panel_temperature_label), temperature);
}
-static char *
-location_tile_need_formatted_time_cb (ClockLocationTile *tile, gpointer data)
+static ClockFormat
+location_tile_need_clock_format_cb(ClockLocationTile *tile, gpointer data)
{
ClockData *cd = data;
- return format_time (cd);
+ return cd->format;
}
static void
@@ -1133,8 +1133,10 @@
G_CALLBACK (location_tile_timezone_set_cb), cd);
g_signal_connect (city, "weather-updated",
G_CALLBACK (location_tile_weather_updated_cb), cd);
- g_signal_connect (city, "need-formatted-time",
- G_CALLBACK (location_tile_need_formatted_time_cb), cd);
+ g_signal_connect (city, "need-clock-format",
+ G_CALLBACK (location_tile_need_clock_format_cb), cd);
+
+ clock_location_tile_refresh (city, TRUE);
gtk_box_pack_start (GTK_BOX (cd->cities_section),
GTK_WIDGET (city),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]