[Xfce4-commits] <xfce4-weather-plugin:master> Implement tooltip styles.

Harald Judt noreply at xfce.org
Tue Nov 27 16:46:37 CET 2012


Updating branch refs/heads/master
         to aca13750c4bcfea083cb834a7f88782554433648 (commit)
       from fc9c45857d9815c7548201f30029e11833e1f067 (commit)

commit aca13750c4bcfea083cb834a7f88782554433648
Author: Harald Judt <h.judt at gmx.at>
Date:   Mon Nov 26 17:10:54 2012 +0100

    Implement tooltip styles.
    
    Some people don't like the verboseness of the tooltip. This commit adds
    another simple tooltip style and makes it possible to easily add additional
    styles in the future should demand arise.

 panel-plugin/weather-config.c |   12 +++++
 panel-plugin/weather.c        |  100 ++++++++++++++++++++++++++++-------------
 panel-plugin/weather.h        |    6 +++
 3 files changed, 87 insertions(+), 31 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index d2b7e25..aa3545a 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -697,6 +697,15 @@ create_units_page(xfceweather_dialog *dialog)
 
 
 static void
+combo_tooltip_style_changed(GtkWidget *combo,
+                            gpointer user_data)
+{
+    xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
+    dialog->wd->tooltip_style = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
+}
+
+
+static void
 check_round_values_toggled(GtkWidget *button,
                            gpointer user_data)
 {
@@ -729,8 +738,11 @@ create_appearance_page(xfceweather_dialog *dialog)
     ADD_COMBO(dialog->combo_tooltip_style);
     ADD_COMBO_VALUE(dialog->combo_tooltip_style, _("Simple"));
     ADD_COMBO_VALUE(dialog->combo_tooltip_style, _("Verbose"));
+    SET_COMBO_VALUE(dialog->combo_tooltip_style, dialog->wd->tooltip_style);
     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(page), vbox, FALSE, FALSE, 0);
+    g_signal_connect(dialog->combo_tooltip_style, "changed",
+                     G_CALLBACK(combo_tooltip_style_changed), dialog);
 
     /* forecast layout */
     vbox = gtk_vbox_new(FALSE, BORDER);
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 6951d6d..faee7ec 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -525,6 +525,9 @@ xfceweather_read_config(XfcePanelPlugin *plugin,
 
     data->round = xfce_rc_read_bool_entry(rc, "round", TRUE);
 
+    data->tooltip_style = xfce_rc_read_int_entry(rc, "tooltip_style",
+                                                 TOOLTIP_VERBOSE);
+
     val = xfce_rc_read_int_entry(rc, "forecast_days", DEFAULT_FORECAST_DAYS);
     data->forecast_days =
         (val > 0 && val <= MAX_FORECAST_DAYS) ? val : DEFAULT_FORECAST_DAYS;
@@ -617,6 +620,8 @@ xfceweather_write_config(XfcePanelPlugin *plugin,
 
     xfce_rc_write_bool_entry(rc, "round", data->round);
 
+    xfce_rc_write_int_entry(rc, "tooltip_style", data->tooltip_style);
+
     xfce_rc_write_int_entry(rc, "forecast_days", data->forecast_days);
 
     xfce_rc_write_bool_entry(rc, "scrollbox_animate", data->scrollbox_animate);
@@ -878,36 +883,59 @@ weather_get_tooltip_text(const xfceweather_data *data)
     DATA_AND_UNIT(fog, FOG);
     DATA_AND_UNIT(cloudiness, CLOUDINESS);
 
-    text = g_markup_printf_escaped
-        /*
-         * TRANSLATORS: Re-arrange and align at will, optionally using
-         * abbreviations for labels if desired or necessary. Just take
-         * into account the possible size constraints, the centered
-         * vertical alignment of the icon - which unfortunately cannot
-         * be changed easily - and try to make it compact and look
-         * good!
-         */
-        (_("<b><span size=\"large\">%s</span></b> "
-           "<span size=\"medium\">(%s)</span>\n"
-           "<b><span size=\"large\">%s</span></b>\n"
-           "<span size=\"smaller\">"
-           "from %s to %s, with %s precipitations</span>\n\n"
-           "<b>Temperature:</b> %s\t\t"
-           "<span size=\"smaller\">(values at %s)</span>\n"
-           "<b>Wind:</b> %s (%son the Beaufort scale) from %s(%s)\n"
-           "<b>Pressure:</b> %s    <b>Humidity:</b> %s\n"
-           "<b>Fog:</b> %s    <b>Cloudiness:</b> %s\n\n"
-           "<span size=\"smaller\">%s</span>"),
-         data->location_name,
-         alt,
-         translate_desc(sym, data->night_time),
-         interval_start, interval_end,
-         precipitations,
-         temp, point,
-         windspeed, windbeau, winddir, winddeg,
-         pressure, humidity,
-         fog, cloudiness,
-         sunval);
+    switch (data->tooltip_style) {
+    case TOOLTIP_SIMPLE:
+        text = g_markup_printf_escaped
+            /*
+             * TRANSLATORS: This is the simple tooltip. For a bigger challenge,
+             * look at the verbose tooltip style further below ;-)
+             */
+            (_("<b><span size=\"large\">%s</span></b> "
+               "<span size=\"medium\">(%s)</span>\n"
+               "<b><span size=\"large\">%s</span></b>\n\n"
+               "<b>Temperature:</b> %s\n"
+               "<b>Wind:</b> %s from %s\n"
+               "<b>Pressure:</b> %s\n"
+               "<b>Humidity:</b> %s\n"),
+             data->location_name, alt,
+             translate_desc(sym, data->night_time),
+             temp, windspeed, winddir, pressure, humidity);
+        break;
+
+    case TOOLTIP_VERBOSE:
+    default:
+        text = g_markup_printf_escaped
+            /*
+             * TRANSLATORS: Re-arrange and align at will, optionally using
+             * abbreviations for labels if desired or necessary. Just take
+             * into account the possible size constraints, the centered
+             * vertical alignment of the icon - which unfortunately cannot
+             * be changed easily - and try to make it compact and look
+             * good!
+             */
+            (_("<b><span size=\"large\">%s</span></b> "
+               "<span size=\"medium\">(%s)</span>\n"
+               "<b><span size=\"large\">%s</span></b>\n"
+               "<span size=\"smaller\">"
+               "from %s to %s, with %s precipitations</span>\n\n"
+               "<b>Temperature:</b> %s\t\t"
+               "<span size=\"smaller\">(values at %s)</span>\n"
+               "<b>Wind:</b> %s (%son the Beaufort scale) from %s(%s)\n"
+               "<b>Pressure:</b> %s    <b>Humidity:</b> %s\n"
+               "<b>Fog:</b> %s    <b>Cloudiness:</b> %s\n\n"
+               "<span size=\"smaller\">%s</span>"),
+             data->location_name,
+             alt,
+             translate_desc(sym, data->night_time),
+             interval_start, interval_end,
+             precipitations,
+             temp, point,
+             windspeed, windbeau, winddir, winddeg,
+             pressure, humidity,
+             fog, cloudiness,
+             sunval);
+        break;
+    }
     g_free(sunval);
     g_free(sym);
     g_free(symbol);
@@ -939,6 +967,7 @@ weather_get_tooltip_cb(GtkWidget *widget,
     GdkPixbuf *icon;
     xml_time *conditions;
     gchar *markup_text, *rawvalue;
+    guint icon_size;
 
     if (data->weatherdata == NULL)
         gtk_tooltip_set_text(tooltip, _("Cannot update weather data"));
@@ -950,7 +979,16 @@ weather_get_tooltip_cb(GtkWidget *widget,
 
     conditions = get_current_conditions(data->weatherdata);
     rawvalue = get_data(conditions, data->units, SYMBOL, data->round);
-    icon = get_icon(data->icon_theme, rawvalue, 128, data->night_time);
+    switch (data->tooltip_style) {
+    case TOOLTIP_SIMPLE:
+        icon_size = 96;
+        break;
+    case TOOLTIP_VERBOSE:
+    default:
+        icon_size = 128;
+        break;
+    }
+    icon = get_icon(data->icon_theme, rawvalue, icon_size, data->night_time);
     g_free(rawvalue);
     gtk_tooltip_set_icon(tooltip, icon);
     g_object_unref(G_OBJECT(icon));
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 7a1d352..ea64d40 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -72,6 +72,7 @@ typedef struct {
 
     units_config *units;
     gboolean round;
+    guint tooltip_style;
 
     xml_weather *weatherdata;
     xml_astro *astrodata;
@@ -80,6 +81,11 @@ typedef struct {
     gint forecast_days;
 } xfceweather_data;
 
+typedef enum {
+    TOOLTIP_SIMPLE,
+    TOOLTIP_VERBOSE
+} tooltip_styles;
+
 
 extern gboolean debug_mode;
 


More information about the Xfce4-commits mailing list