[Xfce4-commits] <xfce4-weather-plugin:master> More info in tooltip: Refactor tooltip code.
Harald Judt
noreply at xfce.org
Wed Aug 1 13:40:01 CEST 2012
Updating branch refs/heads/master
to f044e82b9f0348451386b2f88b695ecbb632254d (commit)
from d2496aeae3c2d56d859ea2a7a5400f97ecc11666 (commit)
commit f044e82b9f0348451386b2f88b695ecbb632254d
Author: Harald Judt <h.judt at gmx.at>
Date: Wed Aug 1 12:49:54 2012 +0200
More info in tooltip: Refactor tooltip code.
With just the weather description and location shown, the tooltip
is not very useful. By adding more data to it and only displaying
the icon and hiding the scrollbox, the plugin wouldn't need that
much space.
For a start, let's generate the tooltip text in a separate function.
panel-plugin/weather.c | 48 ++++++++++++++++++++++++++++++++----------------
1 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index b365e56..2b08f6d 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -869,34 +869,50 @@ xfceweather_create_options(XfcePanelPlugin *plugin,
}
-static gboolean weather_get_tooltip_cb(GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip,
- xfceweather_data *data)
+gchar *
+weather_get_tooltip_text(xfceweather_data *data)
{
- GdkPixbuf *icon;
- gchar *markup_text, *rawvalue;
xml_time *conditions;
+ gchar *text, *rawvalue;
conditions = get_current_conditions(data->weatherdata);
+ if (G_UNLIKELY(conditions == NULL)) {
+ text = g_strdup(_("Current conditions data unavailable"));
+ return text;
+ }
+
+ rawvalue = get_data(conditions, data->unit_system, SYMBOL);
+ text = g_markup_printf_escaped("<b>%s</b>\n"
+ "%s",
+ data->location_name,
+ translate_desc(rawvalue,
+ data->night_time));
+ g_free(rawvalue);
+ return text;
+}
+
+
+static gboolean
+weather_get_tooltip_cb(GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_mode,
+ GtkTooltip *tooltip,
+ xfceweather_data *data)
+{
+ GdkPixbuf *icon;
+ xml_time *conditions;
+ gchar *markup_text, *rawvalue;
if (data->weatherdata == NULL)
gtk_tooltip_set_text(tooltip, _("Cannot update weather data"));
else {
- rawvalue = get_data(conditions, data->unit_system, SYMBOL);
- markup_text =
- g_markup_printf_escaped("<b>%s</b>\n"
- "%s",
- data->location_name,
- translate_desc(rawvalue,
- data->night_time));
- g_free(rawvalue);
+ markup_text = weather_get_tooltip_text(data);
gtk_tooltip_set_markup(tooltip, markup_text);
g_free(markup_text);
}
+ conditions = get_current_conditions(data->weatherdata);
rawvalue = get_data(conditions, data->unit_system, SYMBOL);
icon = get_icon(rawvalue, 32, data->night_time);
g_free(rawvalue);
More information about the Xfce4-commits
mailing list