gnome-panel r10849 - trunk/applets/clock
- From: matthiasc svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-panel r10849 - trunk/applets/clock
- Date: Tue, 19 Feb 2008 01:50:04 +0000 (GMT)
Author: matthiasc
Date: Tue Feb 19 01:50:04 2008
New Revision: 10849
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=10849&view=rev
Log:
2008-02-18 Matthias Clasen <mclasen redhat com>
Fix the display of the weather on the panel.
* clock.c: Fix some memory management issues wrt. to
ClockData.locations, and connect to the weather-updated
signal on the ClockLocation instead of the ClockLocationTile.
* clock-location-tile.[ch]: Get rid of the weather-updated
signal that is no longer used.
Modified:
trunk/applets/clock/ChangeLog
trunk/applets/clock/clock-location-tile.c
trunk/applets/clock/clock-location-tile.h
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 01:50:04 2008
@@ -20,7 +20,6 @@
enum {
TILE_PRESSED,
TIMEZONE_SET,
- WEATHER_UPDATED,
NEED_CLOCK_FORMAT,
LAST_SIGNAL
};
@@ -113,17 +112,6 @@
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- signals[WEATHER_UPDATED] = g_signal_new ("weather-updated",
- G_TYPE_FROM_CLASS (g_obj_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (ClockLocationTileClass, weather_updated),
- NULL,
- NULL,
- _clock_marshal_VOID__OBJECT_STRING,
- G_TYPE_NONE, 2,
- G_TYPE_OBJECT,
- G_TYPE_STRING);
-
signals[NEED_CLOCK_FORMAT] = g_signal_new ("need-clock-format",
G_TYPE_FROM_CLASS (g_obj_class),
G_SIGNAL_RUN_LAST,
@@ -374,12 +362,6 @@
to->tm_yday = from->tm_yday;
}
-static void
-emit_weather_updated (ClockLocationTile *this, GdkPixbuf *weather_icon, const char *temperature)
-{
- g_signal_emit (this, signals[WEATHER_UPDATED], 0, weather_icon, temperature);
-}
-
static char *
format_time (struct tm *now,
char *tzname,
@@ -466,23 +448,12 @@
ClockLocationTilePrivate *priv = PRIVATE (this);
gchar *tmp, *tzname;
struct tm now;
- long offset, hours, minutes;
+ long offset;
int format;
g_return_if_fail (IS_CLOCK_LOCATION_TILE (this));
if (clock_location_is_current (priv->location)) {
- if (!GTK_WIDGET_VISIBLE (priv->current_marker)) {
- GdkPixbuf *pixbuf;
- const gchar *temp = NULL;
-
- pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (priv->weather_icon));
- if (clock_location_get_weather_info (priv->location))
- temp = weather_info_get_temp_summary (clock_location_get_weather_info (priv->location));
-
- emit_weather_updated (this, pixbuf, temp);
- }
-
gtk_widget_hide (priv->current_button);
gtk_widget_show (priv->current_marker);
}
@@ -601,7 +572,6 @@
GdkPixbuf *pixbuf = NULL;
GtkIconTheme *theme = NULL;
const gchar *icon_name;
- const gchar *temp = NULL;
if (!info || !weather_info_is_valid (info))
return;
@@ -610,14 +580,9 @@
theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 16, 0, NULL);
- temp = weather_info_get_temp_summary (info);
-
if (pixbuf) {
gtk_image_set_from_pixbuf (GTK_IMAGE (priv->weather_icon), pixbuf);
gtk_alignment_set_padding (GTK_ALIGNMENT (gtk_widget_get_parent (priv->weather_icon)), 0, 0, 0, 6);
- if (clock_location_is_current (loc)) {
- emit_weather_updated (tile, pixbuf, temp);
- }
}
}
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 01:50:04 2008
@@ -27,7 +27,6 @@
void (* tile_pressed) (ClockLocationTile *tile);
void (* timezone_set) (ClockLocationTile *tile);
- void (* weather_updated) (ClockLocationTile *tile, GdkPixbuf *weather_icon, const char *temperature);
int (* need_clock_format) (ClockLocationTile *tile);
} ClockLocationTileClass;
Modified: trunk/applets/clock/clock.c
==============================================================================
--- trunk/applets/clock/clock.c (original)
+++ trunk/applets/clock/clock.c Tue Feb 19 01:50:04 2008
@@ -211,6 +211,7 @@
static void update_clock (ClockData * cd);
static void update_tooltip (ClockData * cd);
+static void update_panel_weather (ClockData *cd);
static int clock_timeout_callback (gpointer data);
static float get_itime (time_t current_time);
@@ -1131,8 +1132,6 @@
G_CALLBACK (location_tile_pressed_cb), cd);
g_signal_connect (city, "timezone-set",
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-clock-format",
G_CALLBACK (location_tile_need_clock_format_cb), cd);
@@ -1299,7 +1298,6 @@
GtkWidget *button;
button = gtk_toggle_button_new ();
- gtk_container_set_resize_mode (GTK_CONTAINER (button), GTK_RESIZE_IMMEDIATE);
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
force_no_focus_padding (button);
@@ -1408,6 +1406,8 @@
cd->orient = -1;
cd->size = panel_applet_get_size (PANEL_APPLET (cd->applet));
+ update_panel_weather (cd);
+
/* Refresh the clock so that it paints its first state */
refresh_clock_timeout (cd);
applet_change_orient (PANEL_APPLET (cd->applet),
@@ -1974,9 +1974,6 @@
static void
update_panel_weather (ClockData *cd)
{
- GtkWidget *weatherbox;
-
- weatherbox = gtk_widget_get_parent (cd->panel_weather_icon);
if (cd->show_weather)
gtk_widget_show (cd->panel_weather_icon);
else
@@ -1988,9 +1985,11 @@
gtk_widget_hide (cd->panel_temperature_label);
if (cd->show_weather || cd->show_temperature)
- gtk_widget_show (weatherbox);
+ gtk_widget_show (cd->weather_obox);
else
- gtk_widget_hide (weatherbox);
+ gtk_widget_hide (cd->weather_obox);
+
+ gtk_widget_queue_resize (cd->applet);
}
static void
@@ -2036,17 +2035,64 @@
}
static void
-set_locations (ClockData *cd, GList *locations)
+location_weather_updated_cb (ClockLocation *location,
+ WeatherInfo *info,
+ gpointer data)
{
- free_locations (cd);
+ ClockData *cd = data;
+ const gchar *icon_name;
+ const gchar *temp;
+ GtkIconTheme *theme;
+ GdkPixbuf *pixbuf;
- cd->locations = locations;
+ if (!info || !weather_info_is_valid (info))
+ return;
- if (cd->map_widget)
- clock_map_refresh (CLOCK_MAP (cd->map_widget));
+ if (!clock_location_is_current (location))
+ return;
+
+ icon_name = weather_info_get_icon_name (info);
+ theme = gtk_icon_theme_get_default ();
+ pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 16, 0, NULL);
+
+ temp = weather_info_get_temp_summary (info);
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (cd->panel_weather_icon), pixbuf);
+ gtk_label_set_text (GTK_LABEL (cd->panel_temperature_label), temp);
+}
+
+static void
+locations_changed (ClockData *cd)
+{
+ GList *l;
+ ClockLocation *loc;
+ glong id;
+
+ for (l = cd->locations; l; l = l->next) {
+ loc = l->data;
+
+ id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (loc), "weather-updated"));
+ if (id == 0) {
+ id = g_signal_connect (loc, "weather-updated",
+ G_CALLBACK (location_weather_updated_cb), cd);
+ g_object_set_data (G_OBJECT (loc), "weather-updated", GINT_TO_POINTER (id));
+ }
+ }
+
+ if (cd->map_widget)
+ clock_map_refresh (CLOCK_MAP (cd->map_widget));
if (cd->clock_vbox)
- create_cities_section (cd);
+ create_cities_section (cd);
+}
+
+
+static void
+set_locations (ClockData *cd, GList *locations)
+{
+ free_locations (cd);
+ cd->locations = locations;
+ locations_changed (cd);
}
typedef struct {
@@ -2948,7 +2994,6 @@
clock_location_set_coords (loc, lat, lon);
clock_location_set_weather_code (loc, weather_code);
} else {
- GList *locs;
WeatherPrefs prefs;
prefs.temperature_unit = cd->temperature_unit;
@@ -2956,9 +3001,8 @@
loc = clock_location_new (name, clock_zoneinfo_get_name (info), lat, lon, weather_code, &prefs);
- locs = g_list_copy (cd->locations);
- locs = g_list_append (locs, loc);
- set_locations (cd, locs);
+ cd->locations = g_list_append (cd->locations, loc);
+ locations_changed (cd);
}
save_cities_store (cd);
@@ -3522,14 +3566,13 @@
{
ClockData *cd = data;
ClockLocation *loc = NULL;
- GList *list = g_list_copy (cd->locations);
gtk_tree_model_get (model, iter, COL_CITY_LOC, &loc, -1);
- list = g_list_remove (list, loc);
-
gtk_list_store_remove (cd->cities_store, iter);
- set_locations (cd, list);
+ cd->locations = g_list_remove (cd->locations, loc);
+ locations_changed (cd);
+ g_object_unref (loc);
save_cities_store (cd);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]