static void auto_update_toggled(GtkToggleButton* button, MateWeatherPref* pref) { MateWeatherApplet* gw_applet = pref->priv->applet; gboolean toggled; gint nxtSunEvent; toggled = gtk_toggle_button_get_active(button); gw_applet->mateweather_pref.update_enabled = toggled; soft_set_sensitive(pref->priv->basic_update_spin, toggled); g_settings_set_boolean (gw_applet->settings, "auto-update", toggled); if (gw_applet->timeout_tag > 0) { g_source_remove(gw_applet->timeout_tag); } if (gw_applet->suncalc_timeout_tag > 0) { g_source_remove(gw_applet->suncalc_timeout_tag); } if (gw_applet->mateweather_pref.update_enabled) { gw_applet->timeout_tag = g_timeout_add_seconds(gw_applet->mateweather_pref.update_interval, timeout_cb, gw_applet); nxtSunEvent = weather_info_next_sun_event(gw_applet->mateweather_info); if (nxtSunEvent >= 0) { gw_applet->suncalc_timeout_tag = g_timeout_add_seconds(nxtSunEvent, suncalc_timeout_cb, gw_applet); } } }
static void update_finish (WeatherInfo *info, gpointer data) { static int gw_fault_counter = 0; #ifdef HAVE_LIBNOTIFY char *message, *detail; #endif char *s; MateWeatherApplet *gw_applet = (MateWeatherApplet *)data; gint nxtSunEvent; const gchar *icon_name; /* Update timer */ if (gw_applet->timeout_tag > 0) g_source_remove(gw_applet->timeout_tag); if (gw_applet->mateweather_pref.update_enabled) { gw_applet->timeout_tag = g_timeout_add_seconds ( gw_applet->mateweather_pref.update_interval, timeout_cb, gw_applet); nxtSunEvent = weather_info_next_sun_event(gw_applet->mateweather_info); if (nxtSunEvent >= 0) gw_applet->suncalc_timeout_tag = g_timeout_add_seconds (nxtSunEvent, suncalc_timeout_cb, gw_applet); } if ((TRUE == weather_info_is_valid (info)) || (gw_fault_counter >= MAX_CONSECUTIVE_FAULTS)) { gw_fault_counter = 0; icon_name = weather_info_get_icon_name (gw_applet->mateweather_info); gtk_image_set_from_icon_name (GTK_IMAGE(gw_applet->image), icon_name, GTK_ICON_SIZE_BUTTON); gtk_label_set_text (GTK_LABEL (gw_applet->label), weather_info_get_temp_summary( gw_applet->mateweather_info)); s = weather_info_get_weather_summary (gw_applet->mateweather_info); gtk_widget_set_tooltip_text (GTK_WIDGET (gw_applet->applet), s); g_free (s); /* Update dialog -- if one is present */ if (gw_applet->details_dialog) { mateweather_dialog_update (MATEWEATHER_DIALOG (gw_applet->details_dialog)); } /* update applet */ place_widgets(gw_applet); #ifdef HAVE_LIBNOTIFY if (gw_applet->mateweather_pref.show_notifications) { NotifyNotification *n; /* Show notifications if possible */ if (!notify_is_initted ()) notify_init (_("Weather Forecast")); if (notify_is_initted ()) { GError *error = NULL; const char *icon; /* Show notification */ message = g_strdup_printf ("%s: %s", weather_info_get_location_name (info), weather_info_get_sky (info)); detail = g_strdup_printf ( _("City: %s\nSky: %s\nTemperature: %s"), weather_info_get_location_name (info), weather_info_get_sky (info), weather_info_get_temp_summary (info)); icon = weather_info_get_icon_name (gw_applet->mateweather_info); if (icon == NULL) icon = "stock-unknown"; n = notify_notification_new (message, detail, icon); notify_notification_show (n, &error); if (error) { g_warning ("%s", error->message); g_error_free (error); } g_free (message); g_free (detail); } } #endif } else { /* there has been an error during retrival * just update the fault counter */ gw_fault_counter++; } }