[Xfce4-commits] <xfce4-weather-plugin:master> Summary window: Add tooltips to forecast cells.

Harald Judt noreply at xfce.org
Wed Dec 19 11:32:01 CET 2012


Updating branch refs/heads/master
         to 2f811dd18c8337992281eaa0059018663d9eccf0 (commit)
       from 93f1c3705abf0a910902a5d79a8c317759e6a477 (commit)

commit 2f811dd18c8337992281eaa0059018663d9eccf0
Author: Harald Judt <h.judt at gmx.at>
Date:   Sun Dec 16 03:36:52 2012 +0100

    Summary window: Add tooltips to forecast cells.

 panel-plugin/weather-summary.c |   65 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index 5b01319..8fce6f3 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -83,6 +83,14 @@ lnk_clicked(GtkTextTag *tag,
              add_forecast_header(title, 0.0, &darkbg),  \
              pos, pos+1, 0, 1);                         \
 
+#define APPEND_TOOLTIP_ITEM(description, item)                  \
+    value = get_data(fcdata, data->units, item, data->round);   \
+    unit = get_unit(data->units, item);                         \
+    g_string_append_printf(text, description, value,            \
+                           strcmp(unit, "°") ? " " : "",        \
+                           unit);                               \
+    g_free(value);
+
 
 static gboolean
 lnk_clicked(GtkTextTag *tag,
@@ -270,6 +278,18 @@ weather_summary_get_logo(plugin_data *data)
 }
 
 
+static gchar *
+format_date(time_t t)
+{
+    struct tm *tm;
+    gchar buf[80];
+
+    tm = localtime(&t);
+    strftime(buf, 80, "%c", tm);
+    return g_strdup(buf);
+}
+
+
 static GtkWidget *
 create_summary_tab(plugin_data *data)
 {
@@ -509,6 +529,47 @@ get_dayname(gint day)
 }
 
 
+static gchar *
+forecast_cell_get_tooltip_text(plugin_data *data,
+                               xml_time *fcdata)
+{
+    GString *text;
+    gchar *result, *value;
+    const gchar *unit;
+
+    /* TRANSLATORS: Please use \t as needed to properly align the values */
+    text = g_string_new(_("<b>Times used for calculation</b>\n"));
+    value = format_date(fcdata->start);
+    g_string_append_printf(text, _("Interval start:\t\t\t%s\n"), value);
+    g_free(value);
+    value = format_date(fcdata->end);
+    g_string_append_printf(text, _("Interval end:\t\t\t%s\n"), value);
+    g_free(value);
+    value = format_date(fcdata->point);
+    g_string_append_printf(text, _("Data calculated for:\t%s\n\n"), value);
+    g_free(value);
+
+    g_string_append(text, _("<b>Atmosphere</b>\n"));
+    APPEND_TOOLTIP_ITEM(_("Pressure:\t%s%s%s\n"), PRESSURE);
+    APPEND_TOOLTIP_ITEM(_("Humidity:\t%s%s%s\n\n"), HUMIDITY);
+
+    g_string_append(text, _("<b>Precipitations</b>\n"));
+    APPEND_TOOLTIP_ITEM(_("Amount:\t\t%s%s%s\n\n"), PRECIPITATIONS);
+
+    g_string_append(text, _("<b>Clouds</b>\n"));
+    APPEND_TOOLTIP_ITEM(_("Fog:\t\t%s%s%s\n"), FOG);
+    APPEND_TOOLTIP_ITEM(_("Low:\t\t%s%s%s\n"), CLOUDS_LOW);
+    APPEND_TOOLTIP_ITEM(_("Medium\t\t%s%s%s\n"), CLOUDS_MED);
+    APPEND_TOOLTIP_ITEM(_("High:\t\t%s%s%s\n"), CLOUDS_HIGH);
+    APPEND_TOOLTIP_ITEM(_("Cloudiness:\t%s%s%s"), CLOUDINESS);
+
+    /* Free GString only and return its character data */
+    result = text->str;
+    g_string_free(text, FALSE);
+    return result;
+}
+
+
 static GtkWidget *
 wrap_forecast_cell(const GtkWidget *widget,
                    const GdkColor *color)
@@ -623,6 +684,10 @@ add_forecast_cell(plugin_data *data,
 
     gtk_widget_set_size_request(GTK_WIDGET(box), 150, -1);
 
+    value = forecast_cell_get_tooltip_text(data, fcdata);
+    gtk_widget_set_tooltip_markup(GTK_WIDGET(box), value);
+    g_free(value);
+
     xml_time_free(fcdata);
     return box;
 }


More information about the Xfce4-commits mailing list