1 /* Copyright (c) 2003-2014 Xfce Development Team 2 * 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation; either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program; if not, write to the Free Software 15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef __WEATHER_PARSERS_H__ 20 #define __WEATHER_PARSERS_H__ 21 22 #include <glib.h> 23 #include <gtk/gtk.h> 24 #include <libxml/parser.h> 25 #include <libsoup/soup.h> 26 27 #define DATA_EXPIRY_TIME (24 * 3600) 28 29 G_BEGIN_DECLS 30 31 enum { 32 CLOUDS_PERC_LOW = 0, 33 CLOUDS_PERC_MID, 34 CLOUDS_PERC_HIGH, 35 CLOUDS_PERC_CLOUDINESS, 36 CLOUDS_PERC_NUM 37 }; 38 39 typedef gpointer (*XmlParseFunc) (xmlNode *node); 40 41 typedef struct { 42 gchar *altitude; 43 gchar *latitude; 44 gchar *longitude; 45 46 gchar *temperature_value; 47 gchar *temperature_unit; 48 49 gchar *wind_dir_deg; 50 gchar *wind_dir_name; 51 gchar *wind_speed_mps; 52 gchar *wind_speed_beaufort; 53 54 gchar *humidity_value; 55 gchar *humidity_unit; 56 57 gchar *pressure_value; 58 gchar *pressure_unit; 59 60 gchar *clouds_percent[CLOUDS_PERC_NUM]; 61 gchar *fog_percent; 62 63 gchar *precipitation_value; 64 gchar *precipitation_unit; 65 66 gint symbol_id; 67 gchar *symbol; 68 } xml_location; 69 70 typedef struct { 71 time_t start; 72 time_t end; 73 time_t point; 74 xml_location *location; 75 } xml_time; 76 77 typedef struct { 78 GArray *timeslices; 79 xml_time *current_conditions; 80 } xml_weather; 81 82 typedef struct { 83 time_t day; 84 85 time_t sunrise; 86 time_t sunset; 87 gboolean sun_never_rises; 88 gboolean sun_never_sets; 89 gdouble solarnoon_elevation; 90 gdouble solarmidnight_elevation; 91 92 time_t moonrise; 93 time_t moonset; 94 gboolean moon_never_rises; 95 gboolean moon_never_sets; 96 gchar *moon_phase; 97 } xml_astro; 98 99 typedef struct { 100 gchar *city; 101 gchar *country_name; 102 gchar *country_code; 103 gchar *region_name; 104 gchar *latitude; 105 gchar *longitude; 106 } xml_geolocation; 107 108 typedef struct { 109 gchar *display_name; 110 gchar *lat; 111 gchar *lon; 112 } xml_place; 113 114 typedef struct { 115 gchar *altitude; 116 } xml_altitude; 117 118 typedef struct { 119 gchar *country_code; 120 gchar *country_name; 121 gchar *timezone_id; 122 } xml_timezone; 123 124 125 xml_weather *make_weather_data(void); 126 127 xml_time *make_timeslice(void); 128 129 time_t parse_timestring(const gchar *ts, 130 gchar *format, 131 gboolean local); 132 133 gboolean parse_weather(xmlNode *cur_node, 134 xml_weather *wd); 135 136 xml_astro *parse_astro(xmlNode *cur_node); 137 138 gboolean parse_astrodata(xmlNode *cur_node, 139 GArray *astrodata); 140 141 xml_geolocation *parse_geolocation(xmlNode *cur_node); 142 143 xml_place *parse_place(xmlNode *cur_node); 144 145 xml_altitude *parse_altitude(xmlNode *cur_node); 146 147 xml_timezone *parse_timezone(xmlNode *cur_node); 148 149 xml_time *get_timeslice(xml_weather *wd, 150 const time_t start_t, 151 const time_t end_t, 152 guint *index); 153 154 xml_astro *get_astro(const GArray *astrodata, 155 const time_t day_t, 156 guint *index); 157 158 xmlDoc *get_xml_document(SoupMessage *msg); 159 160 gpointer parse_xml_document(SoupMessage *msg, 161 XmlParseFunc parse_func); 162 163 xml_astro *xml_astro_copy(const xml_astro *src); 164 165 xml_time *xml_time_copy(const xml_time *src); 166 167 void xml_time_free(xml_time *timeslice); 168 169 void xml_weather_free(xml_weather *wd); 170 171 void xml_weather_clean(xml_weather *wd); 172 173 void xml_astro_free(xml_astro *astro); 174 175 void astrodata_free(GArray *astrodata); 176 177 void xml_geolocation_free(xml_geolocation *geo); 178 179 void xml_place_free(xml_place *place); 180 181 void xml_altitude_free(xml_altitude *alt); 182 183 void xml_timezone_free(xml_timezone *tz); 184 185 G_END_DECLS 186 187 #endif 188