summaryrefslogtreecommitdiff
path: root/applets/clock/clock-location-tile.c
diff options
context:
space:
mode:
Diffstat (limited to 'applets/clock/clock-location-tile.c')
-rw-r--r--applets/clock/clock-location-tile.c106
1 files changed, 72 insertions, 34 deletions
diff --git a/applets/clock/clock-location-tile.c b/applets/clock/clock-location-tile.c
index 82db27c9..58355da2 100644
--- a/applets/clock/clock-location-tile.c
+++ b/applets/clock/clock-location-tile.c
@@ -52,9 +52,10 @@ typedef struct {
G_DEFINE_TYPE_WITH_PRIVATE (ClockLocationTile, clock_location_tile, GTK_TYPE_BIN)
static void clock_location_tile_finalize (GObject *);
+static void clock_location_tile_dispose (GObject *g_obj);
static void clock_location_tile_fill (ClockLocationTile *this);
-static void update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data);
+static void update_weather_icon (ClockLocation *loc, GWeatherInfo *info, gpointer data);
static gboolean weather_tooltip (GtkWidget *widget,
gint x, gint y,
gboolean keyboard_mode,
@@ -77,7 +78,6 @@ clock_location_tile_new (ClockLocation *loc,
clock_location_tile_fill (this);
- update_weather_icon (loc, clock_location_get_weather_info (loc), this);
gtk_widget_set_has_tooltip (priv->weather_icon, TRUE);
g_signal_connect (priv->weather_icon, "query-tooltip",
@@ -93,7 +93,8 @@ clock_location_tile_class_init (ClockLocationTileClass *this_class)
{
GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class);
- g_obj_class->finalize = clock_location_tile_finalize;
+ g_obj_class->dispose = clock_location_tile_dispose;
+ //g_obj_class->finalize = clock_location_tile_finalize;
signals[TILE_PRESSED] = g_signal_new ("tile-pressed",
G_TYPE_FROM_CLASS (g_obj_class),
@@ -131,6 +132,37 @@ clock_location_tile_init (ClockLocationTile *this)
}
static void
+clock_location_tile_dispose (GObject *g_obj)
+{
+ ClockLocationTile *this;
+ ClockLocationTilePrivate *priv;
+
+ this = CLOCK_LOCATION_TILE (g_obj);
+ priv = clock_location_tile_get_instance_private (this);
+
+ if (priv->location) {
+ if (priv->location_weather_updated_id > 0)
+ g_signal_handler_disconnect (priv->location, priv->location_weather_updated_id);
+ priv->location_weather_updated_id = 0;
+
+ g_object_unref (priv->location);
+ priv->location = NULL;
+ }
+
+ if (priv->button_group) {
+ g_object_unref (priv->button_group);
+ priv->button_group = NULL;
+ }
+
+ if (priv->current_group) {
+ g_object_unref (priv->current_group);
+ priv->current_group = NULL;
+ }
+
+ G_OBJECT_CLASS (clock_location_tile_parent_class)->dispose (g_obj);
+}
+
+static void
clock_location_tile_finalize (GObject *g_obj)
{
ClockLocationTile *this;
@@ -140,7 +172,8 @@ clock_location_tile_finalize (GObject *g_obj)
priv = clock_location_tile_get_instance_private (this);
if (priv->location) {
- g_signal_handler_disconnect (priv->location, priv->location_weather_updated_id);
+ if (priv->location_weather_updated_id > 0)
+ g_signal_handler_disconnect (priv->location, priv->location_weather_updated_id);
priv->location_weather_updated_id = 0;
g_object_unref (priv->location);
@@ -415,7 +448,7 @@ copy_tm (struct tm *from, struct tm *to)
static char *
format_time (struct tm *now,
- char *tzname,
+ const char *tzname,
ClockFormat clock_format,
long offset)
{
@@ -425,7 +458,7 @@ format_time (struct tm *now,
struct tm local_now;
char *utf8;
char *tmp;
- long hours, minutes;
+ long hours;
time (&local_t);
localtime_r (&local_t, &local_now);
@@ -469,13 +502,9 @@ format_time (struct tm *now,
strcpy (buf, "???");
}
- hours = offset / 3600;
- minutes = labs (offset % 3600) / 60;
+ hours = offset / 60;
- if (minutes != 0) {
- tmp = g_strdup_printf ("%s <small>%s %+ld:%ld</small>", buf, tzname, hours, minutes);
- }
- else if (hours != 0) {
+ if (hours != 0) {
tmp = g_strdup_printf ("%s <small>%s %+ld</small>", buf, tzname, hours);
}
else {
@@ -521,7 +550,8 @@ void
clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
{
ClockLocationTilePrivate *priv = clock_location_tile_get_instance_private (this);
- gchar *tmp, *tzname;
+ gchar *tmp;
+ const gchar *tzname;
struct tm now;
long offset;
int format;
@@ -551,10 +581,16 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
clock_location_localtime (priv->location, &now);
tzname = clock_location_get_tzname (priv->location);
+ if (tzname == NULL) {
+ tzname = clock_location_get_tzid (priv->location);
+ }
copy_tm (&now, &(priv->last_refresh));
priv->last_offset = clock_location_get_offset (priv->location);
+ if (priv->location == NULL) {
+ return;
+ }
tmp = g_strdup_printf ("<big><b>%s</b></big>",
clock_location_get_display_name (priv->location));
gtk_label_set_markup (GTK_LABEL (priv->city_label), tmp);
@@ -562,9 +598,7 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
g_signal_emit (this, signals[NEED_CLOCK_FORMAT], 0, &format);
- offset = - priv->last_offset;
-
- tmp = format_time (&now, tzname, format, offset);
+ tmp = format_time (&now, tzname, format, priv->last_offset);
gtk_label_set_markup (GTK_LABEL (priv->time_label), tmp);
@@ -572,14 +606,14 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
}
void
-weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkTooltip *tooltip,
+weather_info_setup_tooltip (GWeatherInfo *info, ClockLocation *location, GtkTooltip *tooltip,
ClockFormat clock_format)
{
GdkPixbuf *pixbuf = NULL;
GtkIconTheme *theme = NULL;
const gchar *conditions, *wind;
gchar *temp, *apparent;
- gchar *line1, *line2, *line3, *line4, *tip;
+ gchar *line1, *line2, *line3, *line4, *line5, *tip;
const gchar *icon_name;
const gchar *sys_timezone;
time_t sunrise_time, sunset_time;
@@ -587,7 +621,7 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
gint icon_scale;
theme = gtk_icon_theme_get_default ();
- icon_name = weather_info_get_icon_name (info);
+ icon_name = gweather_info_get_icon_name (info);
icon_scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());
pixbuf = gtk_icon_theme_load_icon_for_scale (theme, icon_name, 48, icon_scale,
@@ -595,18 +629,18 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
if (pixbuf)
gtk_tooltip_set_icon (tooltip, pixbuf);
- conditions = weather_info_get_conditions (info);
+ conditions = gweather_info_get_conditions (info);
if (strcmp (conditions, "-") != 0)
line1 = g_strdup_printf (_("%s, %s"),
conditions,
- weather_info_get_sky (info));
+ gweather_info_get_sky (info));
else
- line1 = g_strdup (weather_info_get_sky (info));
+ line1 = g_strdup (gweather_info_get_weather_summary (info));
/* we need to g_strdup() since both functions return the same address
* of a static buffer */
- temp = g_strdup (weather_info_get_temp (info));
- apparent = g_strdup (weather_info_get_apparent (info));
+ temp = g_strdup (gweather_info_get_temp (info));
+ apparent = g_strdup (gweather_info_get_apparent (info));
if (strcmp (apparent, temp) != 0 &&
/* FMQ: it's broken to read from another module's translations; add some API to libmateweather. */
strcmp (apparent, dgettext ("mate-applets-2.0", "Unknown")) != 0)
@@ -617,20 +651,20 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
g_free (temp);
g_free (apparent);
- wind = weather_info_get_wind (info);
+ wind = gweather_info_get_wind (info);
if (strcmp (wind, dgettext ("mate-applets-2.0", "Unknown")) != 0)
line3 = g_strdup_printf ("%s\n", wind);
else
line3 = g_strdup ("");
sys_timezone = getenv ("TZ");
- setenv ("TZ", clock_location_get_timezone (location), 1);
+ setenv ("TZ", clock_location_get_tzid (location), 1);
tzset ();
- if (weather_info_get_value_sunrise (info, &sunrise_time))
+ if (gweather_info_get_value_sunrise (info, &sunrise_time))
sunrise_str = convert_time_to_str (sunrise_time, clock_format);
else
sunrise_str = g_strdup ("???");
- if (weather_info_get_value_sunset (info, &sunset_time))
+ if (gweather_info_get_value_sunset (info, &sunset_time))
sunset_str = convert_time_to_str (sunset_time, clock_format);
else
sunset_str = g_strdup ("???");
@@ -639,18 +673,22 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
g_free (sunrise_str);
g_free (sunset_str);
+ line5 = g_strdup_printf ("%s %s", gweather_info_get_visibility(info),
+ gweather_info_get_pressure(info));
+
if (sys_timezone)
setenv ("TZ", sys_timezone, 1);
else
unsetenv ("TZ");
tzset ();
- tip = g_strdup_printf ("<b>%s</b>\n%s\n%s%s", line1, line2, line3, line4);
+ tip = g_strdup_printf ("<b>%s</b>\n%s\n%s\n%s%s", line1, line2, line5, line3, line4);
gtk_tooltip_set_markup (tooltip, tip);
g_free (line1);
g_free (line2);
g_free (line3);
g_free (line4);
+ g_free (line5);
g_free (tip);
}
@@ -664,14 +702,14 @@ weather_tooltip (GtkWidget *widget,
{
ClockLocationTile *tile;
ClockLocationTilePrivate *priv;
- WeatherInfo *info;
+ GWeatherInfo *info;
int clock_format;
tile = CLOCK_LOCATION_TILE (data);
priv = clock_location_tile_get_instance_private (tile);
info = clock_location_get_weather_info (priv->location);
- if (!info || !weather_info_is_valid (info))
+ if (!info || !gweather_info_is_valid (info))
return FALSE;
g_signal_emit (tile, signals[NEED_CLOCK_FORMAT], 0, &clock_format);
@@ -682,7 +720,7 @@ weather_tooltip (GtkWidget *widget,
}
static void
-update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data)
+update_weather_icon (ClockLocation *loc, GWeatherInfo *info, gpointer data)
{
ClockLocationTile *tile;
ClockLocationTilePrivate *priv;
@@ -691,13 +729,13 @@ update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data)
const gchar *icon_name;
gint icon_scale;
- if (!info || !weather_info_is_valid (info))
+ if (!info || !gweather_info_is_valid (info))
return;
tile = CLOCK_LOCATION_TILE (data);
priv = clock_location_tile_get_instance_private (tile);
theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (priv->weather_icon)));
- icon_name = weather_info_get_icon_name (info);
+ icon_name = gweather_info_get_icon_name (info);
icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (priv->weather_icon));
surface = gtk_icon_theme_load_surface (theme, icon_name, 16, icon_scale,