[Xfce4-commits] [panel-plugins/xfce4-weather-plugin] 01/01: Fix moon phase integration

noreply at xfce.org noreply at xfce.org
Sat Mar 23 11:51:07 CET 2019


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-weather-plugin.

commit 431eaa01cde4a675e369612e1fdc4924d2d69319
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Sat Mar 23 06:51:00 2019 -0400

    Fix moon phase integration
---
 panel-plugin/weather-parsers.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index 726d2a0..109d726 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -96,6 +96,13 @@ remove_timezone_offset(gchar *date)
 }
 
 
+static gdouble
+extract_double(gchar *str)
+{
+    return g_ascii_strtod (str, NULL);
+}
+
+
 xml_time *
 get_timeslice(xml_weather *wd,
               const time_t start_t,
@@ -181,6 +188,28 @@ parse_timestring(const gchar *ts,
 }
 
 
+const gchar *
+parse_moonposition (gdouble pos) {
+    if (pos < 0.0 || pos > 100.0)
+        return "Unknown";
+    if (pos <= 12.5)
+        return "Waxing crescent";
+    else if (pos <= 25.0)
+        return "First quarter";
+    else if (pos <= 37.5)
+        return "Waxing gibbous";
+    else if (pos <= 50.0)
+        return "Full moon";
+    else if (pos <= 62.5)
+        return "Waning gibbous";
+    else if (pos <= 75.0)
+        return "Third quarter";
+    else if (pos <= 87.5)
+        return "Waning crescent";
+    return "New moon";
+}
+
+
 static void
 parse_location(xmlNode *cur_node,
                xml_location *loc)
@@ -401,6 +430,7 @@ parse_astro_time(xmlNode *cur_node)
     gchar *date, *sunrise, *sunset, *moonrise, *moonset;
     gboolean sun_rises = FALSE, sun_sets = FALSE;
     gboolean moon_rises = FALSE, moon_sets = FALSE;
+    gdouble moonposition;
 
     astro = g_slice_new0(xml_astro);
     if (G_UNLIKELY(astro == NULL))
@@ -440,6 +470,14 @@ parse_astro_time(xmlNode *cur_node)
                 xmlFree(moonrise);
                 moon_rises = TRUE;
             }
+
+            if (NODE_IS_TYPE(child_node, "moonposition")) {
+                moonposition = extract_double(PROP(child_node, "phase"));
+                if (astro->moon_phase) {
+                    g_free (astro->moon_phase);
+                }
+                astro->moon_phase = g_strdup(parse_moonposition(moonposition));
+            }
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list