[Xfce4-commits] <xfce4-weather-plugin:master> Make translate_day take an integer for weekday instead of a string.

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


Updating branch refs/heads/master
         to 1534943e33bdb685f48eb79364e17e4c10762693 (commit)
       from d4833eb9c94b03b6164a183bbf9f1aedb289631d (commit)

commit 1534943e33bdb685f48eb79364e17e4c10762693
Author: Harald Judt <h.judt at gmx.at>
Date:   Tue Jun 26 01:14:26 2012 +0200

    Make translate_day take an integer for weekday instead of a string.
    
    Rewrite translate_day for the new forecast. It's easier and
    shorter to just use an integer value.

 panel-plugin/weather-translate.c |   36 ++++++++++++------------------------
 panel-plugin/weather-translate.h |    2 +-
 2 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/panel-plugin/weather-translate.c b/panel-plugin/weather-translate.c
index d8a3040..da991c1 100644
--- a/panel-plugin/weather-translate.c
+++ b/panel-plugin/weather-translate.c
@@ -390,40 +390,28 @@ translate_lsup (const gchar *lsup)
 
 
 gchar *
-translate_day (const gchar *day)
+translate_day (gint weekday)
 {
-  gint         wday = -1;
   struct tm    time_tm;
-  guint        i;
-  const gchar *days[] = {"su", "mo", "tu", "we", "th", "fr", "sa", NULL};
   gchar       *day_loc;
   int          len;
 
-  if (day == NULL || strlen (day) < 2)
+  if (weekday < 0 || weekday > 6)
     return NULL;
 
-  for (i = 0; days[i] != NULL; i++)
-    if (!g_ascii_strncasecmp (day, days[i], 2))
-      wday = i;
+  time_tm.tm_wday = weekday;
 
-  if (wday == -1)
-    return NULL;
-  else
-    {
-      time_tm.tm_wday = wday;
-
-      day_loc = g_malloc (DAY_LOC_N);
+  day_loc = g_malloc (DAY_LOC_N);
 
-      len = strftime (day_loc, DAY_LOC_N, "%A", &time_tm);
-      day_loc[len] = 0;
-      if (!g_utf8_validate(day_loc, -1, NULL)) {
-         gchar *utf8 = g_locale_to_utf8(day_loc, -1, NULL, NULL, NULL);
-	 g_free(day_loc);
-	 day_loc = utf8;
-      }
+  len = strftime (day_loc, DAY_LOC_N, "%A", &time_tm);
+  day_loc[len] = 0;
+  if (!g_utf8_validate(day_loc, -1, NULL)) {
+    gchar *utf8 = g_locale_to_utf8(day_loc, -1, NULL, NULL, NULL);
+    g_free(day_loc);
+    day_loc = utf8;
+  }
 
-      return day_loc;
-    }
+  return day_loc;
 }
 
 
diff --git a/panel-plugin/weather-translate.h b/panel-plugin/weather-translate.h
index b1529eb..a63edcc 100644
--- a/panel-plugin/weather-translate.h
+++ b/panel-plugin/weather-translate.h
@@ -32,7 +32,7 @@ const gchar *translate_risk (const gchar *);
 /* these return a newly alocted string, that should be freed */
 gchar *translate_lsup (const gchar *);
 
-gchar *translate_day (const gchar *);
+gchar *translate_day (gint);
 
 gchar *translate_wind_direction (const gchar *);
 


More information about the Xfce4-commits mailing list