[Xfce4-commits] <xfce4-weather-plugin:master> Support for night icons (current weather and forecast).

Harald Judt noreply at xfce.org
Mon Jul 2 12:38:08 CEST 2012


Updating branch refs/heads/master
         to 9f53cf03f769aa711896cf8fea84345f594ccebf (commit)
       from a053b251698babadbe476bf401ff65128741d7cc (commit)

commit 9f53cf03f769aa711896cf8fea84345f594ccebf
Author: Harald Judt <h.judt at gmx.at>
Date:   Tue Jun 26 01:30:42 2012 +0200

    Support for night icons (current weather and forecast).
    
    Since the migration to the new data provider, the different
    appearance between night and day forecasts has been lost.
    Depending on your location, it might be a bit strange to
    have sunny nights. This patch adds back support for night
    and day icons.
    
    There are only a couple of icons which are different at night.
    Let the calling functions find out if it's night or day, and
    get_icon can then choose the right icon.

 panel-plugin/weather-icon.c    |   45 +++++++++++++++++++++++++++++++--------
 panel-plugin/weather-icon.h    |    2 +-
 panel-plugin/weather-summary.c |    5 +---
 panel-plugin/weather.c         |   17 ++++++++------
 4 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/panel-plugin/weather-icon.c b/panel-plugin/weather-icon.c
index c4e7c27..6aaf75c 100644
--- a/panel-plugin/weather-icon.c
+++ b/panel-plugin/weather-icon.c
@@ -25,25 +25,50 @@
 
 #include "weather-icon.h"
 
-
-
 #define DEFAULT_W_THEME "liquid"
 
-
+const gchar *night_symbols[] = {
+  "CLOUD",
+  "LIGHTCLOUD",
+  "LIGHTRAINSUN",
+  "LIGHTRAINTHUNDERSUN",
+  "PARTLYCLOUD",
+  "SNOWSUN",
+  "SUN",
+  NULL
+};
 
 GdkPixbuf *
 get_icon (const gchar *number,
-          gint         size)
+          gint         size,
+          gboolean     night)
 {
   GdkPixbuf *image = NULL;
-  gchar     *filename;
-  gchar     *night;
+  gchar     *filename, *night_suffix = "";
+  gint       number_len, night_symbol_len;
+  guint      i;
 
-  if (number == NULL || strlen(number) == 0 || strcmp (number, "-") == 0)
+  if (number == NULL || strlen(number) == 0)
     number = "99";
+  else if (night)
+    {
+      number_len = strlen(number);
+      for (i = 0; night_symbols[i] != NULL; i++)
+        {
+          night_symbol_len = strlen(night_symbols[i]);
+          if (number_len != night_symbol_len)
+            continue;
+
+          if (number[0] != night_symbols[i][0])
+            continue;
+
+          if (!g_ascii_strncasecmp (night_symbols[i], number, number_len))
+            night_suffix = "-night";
+        }
+    }
 
-  filename = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s.png",
-                              THEMESDIR, DEFAULT_W_THEME, number);
+  filename = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s%s.png",
+                              THEMESDIR, DEFAULT_W_THEME, number, night_suffix);
 
   image = gdk_pixbuf_new_from_file_at_scale (filename, size, size, TRUE, NULL);
 
@@ -51,7 +76,7 @@ get_icon (const gchar *number,
     g_warning ("Unable to open image: %s", filename);
     if (number && strcmp(number, "99")) {
       g_free(filename);
-      return get_icon("99", size);
+      return get_icon("99", size, FALSE);
     }
   }
   g_free (filename);
diff --git a/panel-plugin/weather-icon.h b/panel-plugin/weather-icon.h
index abea3da..cee80ef 100644
--- a/panel-plugin/weather-icon.h
+++ b/panel-plugin/weather-icon.h
@@ -20,7 +20,7 @@
 
 G_BEGIN_DECLS
 
-GdkPixbuf *get_icon (const gchar * icon, gint size);
+GdkPixbuf *get_icon (const gchar * icon, gint size, gboolean night);
 
 G_END_DECLS
 
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index 4edbac6..e15fd66 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -557,10 +557,7 @@ create_summary_window (xfceweather_data *data)
                       0);
 
   timeslice = get_current_timeslice(data->weatherdata, TRUE);
-  icon = get_icon (get_data (timeslice, SYMBOL), 48);
-
-  if (!icon)
-    icon = get_icon ("99", 48);
+  icon = get_icon (get_data (timeslice, SYMBOL), 48, is_night_time());
 
   gtk_window_set_icon (GTK_WINDOW (window), icon);
 
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index b344a2d..85aa950 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -240,9 +240,9 @@ set_icon_error (xfceweather_data *data)
   gtk_widget_get_size_request (data->scrollbox, NULL, &height);
 
   if (data->orientation == GTK_ORIENTATION_VERTICAL)
-    icon = get_icon ("99", data->size - height - 2);
+    icon = get_icon ("99", data->size - height - 2, FALSE);
   else
-    icon = get_icon ("99", data->size);
+    icon = get_icon ("99", data->size, FALSE);
 
   gtk_image_set_from_pixbuf (GTK_IMAGE (data->iconimage), icon);
 
@@ -266,6 +266,7 @@ set_icon_current (xfceweather_data *data)
   datas           opt;
   gchar          *str;
   gint            size, height;
+  gboolean        nighttime;
 
   for (i = 0; i < data->labels->len; i++)
     {
@@ -293,7 +294,8 @@ set_icon_current (xfceweather_data *data)
  
   /* get data from current timeslice */
   timeslice = get_current_timeslice(data->weatherdata, TRUE);
-  icon = get_icon (get_data (timeslice, SYMBOL), size);
+  nighttime = is_night_time();
+  icon = get_icon (get_data (timeslice, SYMBOL), size, nighttime);
  
   gtk_image_set_from_pixbuf (GTK_IMAGE (data->iconimage), icon);
 
@@ -765,9 +767,10 @@ static gboolean weather_get_tooltip_cb (GtkWidget        *widget,
   GdkPixbuf *icon;
   gchar *markup_text;
   xml_time *timeslice;
+  gboolean nighttime;
 
   timeslice = get_current_timeslice(data->weatherdata, TRUE);
-
+  nighttime = is_night_time();
   if (data->weatherdata == NULL) {
     gtk_tooltip_set_text (tooltip, _("Cannot update weather data"));
   } else {
@@ -780,7 +783,7 @@ static gboolean weather_get_tooltip_cb (GtkWidget        *widget,
     gtk_tooltip_set_markup (tooltip, markup_text);
     g_free(markup_text);
   }
-  icon = get_icon (get_data (timeslice, SYMBOL), 32);
+  icon = get_icon (get_data (timeslice, SYMBOL), 32, nighttime);
   gtk_tooltip_set_icon (tooltip, icon);
   g_object_unref (G_OBJECT(icon));
 
@@ -805,7 +808,7 @@ xfceweather_create_control (XfcePanelPlugin *plugin)
 #endif
   data->scrollbox = gtk_scrollbox_new ();
 
-  icon = get_icon ("99", 16);
+  icon = get_icon ("99", 16, FALSE);
   data->iconimage = gtk_image_new_from_pixbuf (icon);
 
   if (G_LIKELY (icon))
@@ -853,7 +856,7 @@ xfceweather_create_control (XfcePanelPlugin *plugin)
 
   /* add refresh button to right click menu, for people who missed the middle mouse click feature */
   mi = gtk_image_menu_item_new_with_mnemonic (_("_Forecast"));
-  icon = get_icon ("SUN", 16);
+  icon = get_icon ("SUN", 16, FALSE);
   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi),
   	gtk_image_new_from_pixbuf(icon));
   if (G_LIKELY (icon))


More information about the Xfce4-commits mailing list