1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ 2 /* weather.h - Public header for weather server functions. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License as 6 * published by the Free Software Foundation; either version 2 of the 7 * License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, see 16 * <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __WEATHER_H_ 20 #define __WEATHER_H_ 21 22 23 #ifndef MATEWEATHER_I_KNOW_THIS_IS_UNSTABLE 24 #error "libmateweather should only be used if you understand that it's subject to change, and is not supported as a fixed API/ABI or as part of the platform" 25 #endif 26 27 28 #include <gdk-pixbuf/gdk-pixbuf.h> 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /* 35 * Location 36 */ 37 38 struct _WeatherLocation { 39 gchar *name; 40 gchar *code; 41 gchar *zone; 42 gchar *radar; 43 gboolean zone_valid; 44 gchar *coordinates; 45 gdouble latitude; 46 gdouble longitude; 47 gboolean latlon_valid; 48 gchar *country_code; 49 gchar *tz_hint; 50 }; 51 52 typedef struct _WeatherLocation WeatherLocation; 53 54 WeatherLocation * weather_location_new (const gchar *trans_name, 55 const gchar *code, 56 const gchar *zone, 57 const gchar *radar, 58 const gchar *coordinates, 59 const gchar *country_code, 60 const gchar *tz_hint); 61 WeatherLocation * weather_location_clone (const WeatherLocation *location); 62 void weather_location_free (WeatherLocation *location); 63 gboolean weather_location_equal (const WeatherLocation *location1, 64 const WeatherLocation *location2); 65 66 /* 67 * Weather prefs 68 */ 69 70 typedef enum _WeatherForecastType { 71 FORECAST_STATE, 72 FORECAST_ZONE, 73 FORECAST_LIST 74 } WeatherForecastType; 75 76 typedef enum { 77 TEMP_UNIT_INVALID = 0, 78 TEMP_UNIT_DEFAULT, 79 TEMP_UNIT_KELVIN, 80 TEMP_UNIT_CENTIGRADE, 81 TEMP_UNIT_FAHRENHEIT 82 } TempUnit; 83 84 typedef enum { 85 SPEED_UNIT_INVALID = 0, 86 SPEED_UNIT_DEFAULT, 87 SPEED_UNIT_MS, /* metres per second */ 88 SPEED_UNIT_KPH, /* kilometres per hour */ 89 SPEED_UNIT_MPH, /* miles per hour */ 90 SPEED_UNIT_KNOTS, /* Knots */ 91 SPEED_UNIT_BFT /* Beaufort scale */ 92 } SpeedUnit; 93 94 typedef enum { 95 PRESSURE_UNIT_INVALID = 0, 96 PRESSURE_UNIT_DEFAULT, 97 PRESSURE_UNIT_KPA, /* kiloPascal */ 98 PRESSURE_UNIT_HPA, /* hectoPascal */ 99 PRESSURE_UNIT_MB, /* 1 millibars = 1 hectoPascal */ 100 PRESSURE_UNIT_MM_HG, /* millimeters of mecury */ 101 PRESSURE_UNIT_INCH_HG, /* inches of mercury */ 102 PRESSURE_UNIT_ATM /* atmosphere */ 103 } PressureUnit; 104 105 typedef enum { 106 DISTANCE_UNIT_INVALID = 0, 107 DISTANCE_UNIT_DEFAULT, 108 DISTANCE_UNIT_METERS, 109 DISTANCE_UNIT_KM, 110 DISTANCE_UNIT_MILES 111 } DistanceUnit; 112 113 struct _WeatherPrefs { 114 WeatherForecastType type; 115 116 gboolean radar; 117 const char *radar_custom_url; 118 119 TempUnit temperature_unit; 120 SpeedUnit speed_unit; 121 PressureUnit pressure_unit; 122 DistanceUnit distance_unit; 123 }; 124 125 typedef struct _WeatherPrefs WeatherPrefs; 126 127 /* 128 * Weather Info 129 */ 130 131 typedef struct _WeatherInfo WeatherInfo; 132 133 typedef void (*WeatherInfoFunc) (WeatherInfo *info, gpointer data); 134 135 WeatherInfo * _weather_info_fill (WeatherInfo *info, 136 WeatherLocation *location, 137 const WeatherPrefs *prefs, 138 WeatherInfoFunc cb, 139 gpointer data); 140 #define weather_info_new(location, prefs, cb, data) _weather_info_fill (NULL, (location), (prefs), (cb), (data)) 141 #define weather_info_update(info, prefs, cb, data) _weather_info_fill ((info), NULL, (prefs), (cb), (data)) 142 143 void weather_info_abort (WeatherInfo *info); 144 WeatherInfo * weather_info_clone (const WeatherInfo *info); 145 void weather_info_free (WeatherInfo *info); 146 147 gboolean weather_info_is_valid (WeatherInfo *info); 148 gboolean weather_info_network_error (WeatherInfo *info); 149 150 void weather_info_to_metric (WeatherInfo *info); 151 void weather_info_to_imperial (WeatherInfo *info); 152 153 const WeatherLocation * weather_info_get_location (WeatherInfo *info); 154 const gchar * weather_info_get_location_name (WeatherInfo *info); 155 const gchar * weather_info_get_update (WeatherInfo *info); 156 const gchar * weather_info_get_sky (WeatherInfo *info); 157 const gchar * weather_info_get_conditions (WeatherInfo *info); 158 const gchar * weather_info_get_temp (WeatherInfo *info); 159 const gchar * weather_info_get_temp_min (WeatherInfo *info); 160 const gchar * weather_info_get_temp_max (WeatherInfo *info); 161 const gchar * weather_info_get_dew (WeatherInfo *info); 162 const gchar * weather_info_get_humidity (WeatherInfo *info); 163 const gchar * weather_info_get_wind (WeatherInfo *info); 164 const gchar * weather_info_get_pressure (WeatherInfo *info); 165 const gchar * weather_info_get_visibility (WeatherInfo *info); 166 const gchar * weather_info_get_apparent (WeatherInfo *info); 167 const gchar * weather_info_get_sunrise (WeatherInfo *info); 168 const gchar * weather_info_get_sunset (WeatherInfo *info); 169 const gchar * weather_info_get_forecast (WeatherInfo *info); 170 GSList * weather_info_get_forecast_list (WeatherInfo *info); 171 GdkPixbufAnimation * weather_info_get_radar (WeatherInfo *info); 172 173 const gchar * weather_info_get_temp_summary (WeatherInfo *info); 174 gchar * weather_info_get_weather_summary(WeatherInfo *info); 175 176 const gchar * weather_info_get_icon_name (WeatherInfo *info); 177 gint weather_info_next_sun_event (WeatherInfo *info); 178 179 /* values retrieving functions */ 180 181 enum _WeatherWindDirection { 182 WIND_INVALID = -1, 183 WIND_VARIABLE, 184 WIND_N, WIND_NNE, WIND_NE, WIND_ENE, 185 WIND_E, WIND_ESE, WIND_SE, WIND_SSE, 186 WIND_S, WIND_SSW, WIND_SW, WIND_WSW, 187 WIND_W, WIND_WNW, WIND_NW, WIND_NNW, 188 WIND_LAST 189 }; 190 191 typedef enum _WeatherWindDirection WeatherWindDirection; 192 193 enum _WeatherSky { 194 SKY_INVALID = -1, 195 SKY_CLEAR, 196 SKY_BROKEN, 197 SKY_SCATTERED, 198 SKY_FEW, 199 SKY_OVERCAST, 200 SKY_LAST 201 }; 202 203 typedef enum _WeatherSky WeatherSky; 204 205 enum _WeatherConditionPhenomenon { 206 PHENOMENON_INVALID = -1, 207 208 PHENOMENON_NONE, 209 210 PHENOMENON_DRIZZLE, 211 PHENOMENON_RAIN, 212 PHENOMENON_SNOW, 213 PHENOMENON_SNOW_GRAINS, 214 PHENOMENON_ICE_CRYSTALS, 215 PHENOMENON_ICE_PELLETS, 216 PHENOMENON_HAIL, 217 PHENOMENON_SMALL_HAIL, 218 PHENOMENON_UNKNOWN_PRECIPITATION, 219 220 PHENOMENON_MIST, 221 PHENOMENON_FOG, 222 PHENOMENON_SMOKE, 223 PHENOMENON_VOLCANIC_ASH, 224 PHENOMENON_SAND, 225 PHENOMENON_HAZE, 226 PHENOMENON_SPRAY, 227 PHENOMENON_DUST, 228 229 PHENOMENON_SQUALL, 230 PHENOMENON_SANDSTORM, 231 PHENOMENON_DUSTSTORM, 232 PHENOMENON_FUNNEL_CLOUD, 233 PHENOMENON_TORNADO, 234 PHENOMENON_DUST_WHIRLS, 235 236 PHENOMENON_LAST 237 }; 238 239 typedef enum _WeatherConditionPhenomenon WeatherConditionPhenomenon; 240 241 enum _WeatherConditionQualifier { 242 QUALIFIER_INVALID = -1, 243 244 QUALIFIER_NONE, 245 246 QUALIFIER_VICINITY, 247 248 QUALIFIER_LIGHT, 249 QUALIFIER_MODERATE, 250 QUALIFIER_HEAVY, 251 QUALIFIER_SHALLOW, 252 QUALIFIER_PATCHES, 253 QUALIFIER_PARTIAL, 254 QUALIFIER_THUNDERSTORM, 255 QUALIFIER_BLOWING, 256 QUALIFIER_SHOWERS, 257 QUALIFIER_DRIFTING, 258 QUALIFIER_FREEZING, 259 260 QUALIFIER_LAST 261 }; 262 263 typedef enum _WeatherConditionQualifier WeatherConditionQualifier; 264 typedef gdouble WeatherMoonPhase; 265 typedef gdouble WeatherMoonLatitude; 266 267 gboolean weather_info_get_value_update (WeatherInfo *info, time_t *value); 268 gboolean weather_info_get_value_sky (WeatherInfo *info, WeatherSky *sky); 269 gboolean weather_info_get_value_conditions (WeatherInfo *info, WeatherConditionPhenomenon *phenomenon, WeatherConditionQualifier *qualifier); 270 gboolean weather_info_get_value_temp (WeatherInfo *info, TempUnit unit, gdouble *value); 271 gboolean weather_info_get_value_temp_min (WeatherInfo *info, TempUnit unit, gdouble *value); 272 gboolean weather_info_get_value_temp_max (WeatherInfo *info, TempUnit unit, gdouble *value); 273 gboolean weather_info_get_value_dew (WeatherInfo *info, TempUnit unit, gdouble *value); 274 gboolean weather_info_get_value_apparent (WeatherInfo *info, TempUnit unit, gdouble *value); 275 gboolean weather_info_get_value_wind (WeatherInfo *info, SpeedUnit unit, gdouble *speed, WeatherWindDirection *direction); 276 gboolean weather_info_get_value_pressure (WeatherInfo *info, PressureUnit unit, gdouble *value); 277 gboolean weather_info_get_value_visibility (WeatherInfo *info, DistanceUnit unit, gdouble *value); 278 gboolean weather_info_get_value_sunrise (WeatherInfo *info, time_t *value); 279 gboolean weather_info_get_value_sunset (WeatherInfo *info, time_t *value); 280 gboolean weather_info_get_value_moonphase (WeatherInfo *info, WeatherMoonPhase *value, WeatherMoonLatitude *lat); 281 gboolean weather_info_get_upcoming_moonphases (WeatherInfo *info, time_t *phases); 282 283 284 #ifdef __cplusplus 285 } 286 #endif 287 288 #endif /* __WEATHER_H_ */ 289