static void temp_combo_changed_cb(GtkComboBox* combo, MateWeatherPref* pref) { MateWeatherApplet* gw_applet = pref->priv->applet; TempUnit new_unit, old_unit; g_return_if_fail(gw_applet != NULL); new_unit = gtk_combo_box_get_active(combo) + 2; old_unit = gw_applet->mateweather_pref.temperature_unit; if (new_unit == old_unit) { return; } gw_applet->mateweather_pref.temperature_unit = new_unit; g_settings_set_enum (gw_applet->settings, "temperature-unit", new_unit); gtk_label_set_text(GTK_LABEL(gw_applet->label), weather_info_get_temp_summary(gw_applet->mateweather_info)); if (gw_applet->details_dialog) { mateweather_dialog_update(MATEWEATHER_DIALOG(gw_applet->details_dialog)); } }
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++; } }
static void place_widgets (MateWeatherApplet *gw_applet) { GtkRequisition req; int total_size = 0; gboolean horizontal = FALSE; int panel_size = gw_applet->size; const gchar *temp; const gchar *icon_name; switch (gw_applet->orient) { case MATE_PANEL_APPLET_ORIENT_LEFT: case MATE_PANEL_APPLET_ORIENT_RIGHT: horizontal = FALSE; break; case MATE_PANEL_APPLET_ORIENT_UP: case MATE_PANEL_APPLET_ORIENT_DOWN: horizontal = TRUE; break; } /* Create the weather icon */ icon_name = weather_info_get_icon_name (gw_applet->mateweather_info); gw_applet->image = gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_BUTTON); if (icon_name != NULL) { gtk_widget_size_request(gw_applet->image, &req); if (horizontal) total_size += req.height; else total_size += req.width; } /* Create the temperature label */ gw_applet->label = gtk_label_new("0\302\260F"); /* Update temperature text */ temp = weather_info_get_temp_summary(gw_applet->mateweather_info); if (temp) gtk_label_set_text(GTK_LABEL(gw_applet->label), temp); /* Check the label size to determine box layout */ gtk_widget_size_request(gw_applet->label, &req); if (horizontal) total_size += req.height; else total_size += req.width; /* Pack the box */ if (gw_applet->box) gtk_widget_destroy (gw_applet->box); if (horizontal && (total_size <= panel_size)) gw_applet->box = gtk_vbox_new(FALSE, 0); else if (horizontal && (total_size > panel_size)) gw_applet->box = gtk_hbox_new(FALSE, 2); else if (!horizontal && (total_size <= panel_size)) gw_applet->box = gtk_hbox_new(FALSE, 2); else gw_applet->box = gtk_vbox_new(FALSE, 0); /* Rebuild the applet it's visual area */ gtk_container_add (GTK_CONTAINER (gw_applet->container), gw_applet->box); gtk_box_pack_start (GTK_BOX (gw_applet->box), gw_applet->image, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (gw_applet->box), gw_applet->label, TRUE, TRUE, 0); gtk_widget_show_all (GTK_WIDGET (gw_applet->applet)); }