summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2011-04-05 21:36:32 +0200
committerJavier Jardón <jjardon@gnome.org>2012-03-09 17:37:26 +0000
commit7d32d907d0997d8dbdafc08ca807f132820660e3 (patch)
tree77349e2f17e1550aea95fd36385d4356280ddf54
parent0729a784672e2a26fe19185c01562798039eb926 (diff)
downloadlibgweather-7d32d907d0997d8dbdafc08ca807f132820660e3.tar.gz
Port to GSettings
Kill GWeatherPrefs and GWeatherGConf, as it is very easy to just construct a GSettings object. Make GWeatherInfo use a default settings object for its string methods. Make GWeatherLocation serializable to a GVariant and store that in the settings, killing WeatherLocation. https://bugzilla.gnome.org/show_bug.cgi?id=646854
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac10
-rw-r--r--data/Makefile.am9
-rw-r--r--data/org.gnome.GWeather.gschema.xml.in71
-rw-r--r--libgweather/Makefile.am31
-rw-r--r--libgweather/gweather-enum-types.c.tmpl1
-rw-r--r--libgweather/gweather-enums.h67
-rw-r--r--libgweather/gweather-gconf.c315
-rw-r--r--libgweather/gweather-gconf.h78
-rw-r--r--libgweather/gweather-location.c71
-rw-r--r--libgweather/gweather-location.h2
-rw-r--r--libgweather/gweather-prefs.c402
-rw-r--r--libgweather/gweather-prefs.h57
-rw-r--r--libgweather/gweather.schemas.in173
-rw-r--r--libgweather/test_metar.c1
-rw-r--r--libgweather/test_sun_moon.c3
-rw-r--r--libgweather/weather-iwin.c76
-rw-r--r--libgweather/weather-metar.c124
-rw-r--r--libgweather/weather-priv.h33
-rw-r--r--libgweather/weather-sun.c2
-rw-r--r--libgweather/weather.c584
-rw-r--r--libgweather/weather.h199
-rw-r--r--po/POTFILES.in4
23 files changed, 642 insertions, 1673 deletions
diff --git a/Makefile.am b/Makefile.am
index f20e069..0093f08 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = libgweather icons doc data po po-locations
+SUBDIRS = data libgweather icons doc po po-locations
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
diff --git a/configure.ac b/configure.ac
index 418809b..8b994e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,7 +51,8 @@ IT_PROG_INTLTOOL([0.40.6])
PKG_PROG_PKG_CONFIG([0.19])
AC_PROG_CC
-AC_PATH_PROG(GCONFTOOL, gconftool-2)
+
+GLIB_GSETTINGS
AC_ARG_ENABLE(all-translations-in-one-xml,
[AS_HELP_STRING([--enable-all-translations-in-one-xml],
@@ -90,10 +91,9 @@ PKG_CHECK_MODULES(LIBSOUP_GNOME,
AC_SUBST(LIBSOUP_CFLAGS)
AC_SUBST(LIBSOUP_LIBS)
-dnl -- check for gconf (required) -----------------------------------------
-PKG_CHECK_MODULES(GCONF,
- [gconf-2.0 >= $GCONF_REQUIRED])
-AM_GCONF_SOURCE_2
+dnl -- check for gio (required) -----------------------------------------
+PKG_CHECK_MODULES(GIO,
+ [gio-2.0 >= $GLIB_REQUIRED])
dnl -- check for glib; redundant at this point, but sets $GLIB_MKENUMS
AM_PATH_GLIB_2_0($GLIB_REQUIRED)
diff --git a/data/Makefile.am b/data/Makefile.am
index f1f82c0..309b457 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -64,6 +64,13 @@ check:
xmllint --valid --noout $(top_srcdir)/data/Locations.xml.in
$(srcdir)/check-timezones.sh $(srcdir)/Locations.xml.in
+gsettings_ENUM_NAMESPACE = org.gnome.GWeather
+gsettings_ENUM_FILES = $(top_srcdir)/libgweather/gweather-enums.h
+
+gsettings_SCHEMAS = org.gnome.GWeather.gschema.xml
+@INTLTOOL_XML_NOMERGE_RULE@
+@GSETTINGS_RULES@
+
EXTRA_DIST = \
$(libgweatherlocations_in_files) \
$(libgweatherdtd_DATA) \
@@ -73,6 +80,8 @@ EXTRA_DIST = \
CLEANFILES = \
$(libgweatherlocations_DATA) \
+ $(gsettings_SCHEMAS) \
+ *.valid \
$(LOCATIONS_STAMP)
-include $(top_srcdir)/git.mk
diff --git a/data/org.gnome.GWeather.gschema.xml.in b/data/org.gnome.GWeather.gschema.xml.in
new file mode 100644
index 0000000..a8582a7
--- /dev/null
+++ b/data/org.gnome.GWeather.gschema.xml.in
@@ -0,0 +1,71 @@
+<schemalist gettext-domain="libgweather-3.0">
+ <schema id="org.gnome.GWeather" path="/org/gnome/GWeather/">
+ <key name="radar" type="s">
+ <default>''</default>
+ <_summary>URL for the radar map</_summary>
+ <_description>
+ The custom URL from where to retrieve a radar map, or empty
+ for disabling radar maps.
+ </_description>
+ </key>
+ <key name="temperature-unit" enum="org.gnome.GWeather.GWeatherTemperatureUnit">
+ <!-- TRANSLATORS: pick a temperature unit that should be used by default in your
+ locale; values must be quoted -->
+ <_default l10n="messages">'fahrenheit'</_default>
+ <_summary>Temperature unit</_summary>
+ <_description>
+ The unit of temperature used for showing weather. Valid values are 'kelvin',
+ 'centigrade' and 'fahrenheit'.
+ </_description>
+ </key>
+ <key name="distance-unit" enum="org.gnome.GWeather.GWeatherDistanceUnit">
+ <!-- TRANSLATORS: pick a default distance unit for your locale, see key description
+ for valid values -->
+ <_default l10n="messages">'miles'</_default>
+ <_summary>Distance unit</_summary>
+ <_description>
+ The unit of distance used for showing weather (for example for visibility or for
+ distance of important events). Valid values are 'meters', 'km' and 'miles'.
+ </_description>
+ </key>
+ <key name="speed-unit" enum="org.gnome.GWeather.GWeatherSpeedUnit">
+ <!-- TRANSLATORS: pick a default speed unit for your locale, see key description
+ for valid values -->
+ <_default l10n="messages">'knots'</_default>
+ <_summary>Speed unit</_summary>
+ <_description>
+ The unit of speed used for showing weather (for example for wind speed). Valid
+ values are 'ms' (meters per second), 'kph' (kilometers per hour), 'mph' (miles
+ per hour), 'knots' and 'bft' (Beaufort scale).
+ </_description>
+ </key>
+ <key name="pressure-unit" enum="org.gnome.GWeather.GWeatherPressureUnit">
+ <!-- TRANSLATORS: pick a default pressure unit for your locale, see key description
+ for valid values -->
+ <_default l10n="messages">'inch-hg'</_default>
+ <_summary>Pressure unit</_summary>
+ <_description>
+ The unit of pressure used for showing weather. Valid values are 'kpa' (kilopascal),
+ 'hpa' (hectopascal), 'mb' (millibar, mathematically equivalent to 1 hPa but shown
+ differently), 'mm-hg' (millimiters of mercury), 'inch-hg' (inches of mercury), 'atm'
+ (atmospheres).
+ </_description>
+ </key>
+ <key name="default-location" type="(ssm(dd))">
+ <!-- TRANSLATORS: pick a default location to use in the weather applet. This should
+ usually be the largest city or the capital of your country. If you're not picking
+ a <location> in the database, don't forget to set name and coordinates. -->
+ <_default>('', 'KNYC', nothing)</_default>
+ <_summary>Default location</_summary>
+ <_description>
+ The default location for the weather applet. The first field is the name that will
+ be shown. If empty, it will be taken from the locations database.
+ The second field is the METAR code for the default weather station. It must not be
+ empty and must correspond to a &lt;code&gt; tag in the Locations.xml file.
+ The third field is a tuple of (latitude, longitude), to override the value taken
+ from the database. This is only used for sunrise and moon phase calculations, not
+ for weather forecast.
+ </_description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/libgweather/Makefile.am b/libgweather/Makefile.am
index 01af8c5..ae6511c 100644
--- a/libgweather/Makefile.am
+++ b/libgweather/Makefile.am
@@ -9,10 +9,11 @@ AM_CPPFLAGS = \
AM_CFLAGS = $(WARN_CFLAGS)
gweather_old_headers = \
- gweather-gconf.h gweather-prefs.h gweather-xml.h
+ gweather-xml.h
gweather_new_headers = \
gweather-location.h location-entry.h \
- gweather-timezone.h timezone-menu.h
+ gweather-timezone.h timezone-menu.h \
+ gweather-enums.h
libgweatherincdir = $(includedir)/libgweather-3.0/libgweather
libgweatherinc_HEADERS = \
$(gweather_old_headers) \
@@ -27,8 +28,6 @@ libgweather_3_la_SOURCES = \
weather-bom.c weather-wx.c \
weather-sun.c weather-moon.c \
gweather-enum-types.c \
- gweather-prefs.c gweather-prefs.h \
- gweather-gconf.c gweather-gconf.h \
gweather-xml.c gweather-xml.h \
gweather-location.c gweather-location.h \
gweather-timezone.c gweather-timezone.h \
@@ -47,7 +46,7 @@ libgweather_3_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(LIBXML_CFLAGS) \
$(LIBSOUP_CFLAGS) \
- $(GCONF_CFLAGS) \
+ $(GIO_CFLAGS) \
-DG_LOG_DOMAIN=\"GWeather\" \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-DGWEATHER_XML_LOCATION_DIR=\""$(pkgdatadir)"\"
@@ -57,7 +56,7 @@ libgweather_3_la_LIBADD = \
$(GTK_LIBS) \
$(LIBXML_LIBS) \
$(LIBSOUP_LIBS) \
- $(GCONF_LIBS) \
+ $(GIO_LIBS) \
$(REGEX_LIBS)
libgweather_3_la_LDFLAGS = \
@@ -91,10 +90,6 @@ BUILT_SOURCES = gweather-enum-types.c gweather-enum-types.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gweather-3.0.pc
-schemadir = @GCONF_SCHEMA_FILE_DIR@
-schema_in_files = gweather.schemas.in
-schema_DATA = $(schema_in_files:.schemas.in=.schemas)
-
@INTLTOOL_SCHEMAS_RULE@
EXTRA_DIST = gweather-3.0.pc.in gweather-3.0-uninstalled.pc.in $(schema_in_files)
@@ -114,7 +109,8 @@ introspection_sources = \
gweather-timezone.c gweather-timezone.h \
location-entry.c location-entry.h \
timezone-menu.c timezone-menu.h
-built_introspection_sources = gweather-enum-types.h
+
+built_introspection_sources = gweather-enum-types.h gweather-enums.h
GWeather-3.0.gir: libgweather-3.la Makefile
GWeather_3_0_gir_INCLUDES = GObject-2.0 Gtk-3.0
@@ -133,17 +129,4 @@ typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
CLEANFILES += $(gir_DATA) $(typelib_DATA)
endif
-if GCONF_SCHEMAS_INSTALL
-install-data-local:
- if test -z "$(DESTDIR)" ; then \
- for p in $(schema_DATA) ; do \
- GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(top_builddir)/libgweather/$$p ; \
- done \
- fi
-uninstall-local:
- for p in $(schema_DATA) ; do \
- GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-uninstall-rule $(top_builddir)/libgweather/$$p ; \
- done
-endif
-
-include $(top_srcdir)/git.mk
diff --git a/libgweather/gweather-enum-types.c.tmpl b/libgweather/gweather-enum-types.c.tmpl
index b2c20bc..c9521d4 100644
--- a/libgweather/gweather-enum-types.c.tmpl
+++ b/libgweather/gweather-enum-types.c.tmpl
@@ -2,6 +2,7 @@
#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
#include "gweather-enum-types.h"
#include "gweather-location.h"
+#include "gweather-enums.h"
/*** END file-header ***/
/*** BEGIN file-production ***/
diff --git a/libgweather/gweather-enums.h b/libgweather/gweather-enums.h
new file mode 100644
index 0000000..1191cd6
--- /dev/null
+++ b/libgweather/gweather-enums.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* gweather-enums.h: enumerations for GWeather settings
+ *
+ * Copyright: 2011 Giovanni Campagna <scampa.giovanni@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GWEATHER_ENUMS_H_
+#define __GWEATHER_ENUMS_H_
+
+typedef enum { /*< underscore_name=gweather_forecast_type >*/
+ GWEATHER_FORECAST_STATE,
+ GWEATHER_FORECAST_ZONE,
+ GWEATHER_FORECAST_LIST
+} GWeatherForecastType;
+
+typedef enum { /*< underscore_name=gweather_temperature_unit >*/
+ GWEATHER_TEMP_UNIT_INVALID = 0,
+ GWEATHER_TEMP_UNIT_DEFAULT,
+ GWEATHER_TEMP_UNIT_KELVIN,
+ GWEATHER_TEMP_UNIT_CENTIGRADE,
+ GWEATHER_TEMP_UNIT_FAHRENHEIT
+} GWeatherTemperatureUnit;
+
+typedef enum { /*< underscore_name=gweather_speed_unit >*/
+ GWEATHER_SPEED_UNIT_INVALID = 0,
+ GWEATHER_SPEED_UNIT_DEFAULT,
+ GWEATHER_SPEED_UNIT_MS, /* metres per second */
+ GWEATHER_SPEED_UNIT_KPH, /* kilometres per hour */
+ GWEATHER_SPEED_UNIT_MPH, /* miles per hour */
+ GWEATHER_SPEED_UNIT_KNOTS, /* Knots */
+ GWEATHER_SPEED_UNIT_BFT /* Beaufort scale */
+} GWeatherSpeedUnit;
+
+typedef enum { /*< underscore_name=gweather_pressure_unit >*/
+ GWEATHER_PRESSURE_UNIT_INVALID = 0,
+ GWEATHER_PRESSURE_UNIT_DEFAULT,
+ GWEATHER_PRESSURE_UNIT_KPA, /* kiloPascal */
+ GWEATHER_PRESSURE_UNIT_HPA, /* hectoPascal */
+ GWEATHER_PRESSURE_UNIT_MB, /* 1 millibars = 1 hectoPascal */
+ GWEATHER_PRESSURE_UNIT_MM_HG, /* millimeters of mercury */
+ GWEATHER_PRESSURE_UNIT_INCH_HG, /* inches of mercury */
+ GWEATHER_PRESSURE_UNIT_ATM /* atmosphere */
+} GWeatherPressureUnit;
+
+typedef enum { /*< underscore_name=gweather_distance_unit >*/
+ GWEATHER_DISTANCE_UNIT_INVALID = 0,
+ GWEATHER_DISTANCE_UNIT_DEFAULT,
+ GWEATHER_DISTANCE_UNIT_METERS,
+ GWEATHER_DISTANCE_UNIT_KM,
+ GWEATHER_DISTANCE_UNIT_MILES
+} GWeatherDistanceUnit;
+
+#endif /* __GWEATHER_ENUMS_H_ */
diff --git a/libgweather/gweather-gconf.c b/libgweather/gweather-gconf.c
deleted file mode 100644
index 9230002..0000000
--- a/libgweather/gweather-gconf.c
+++ /dev/null
@@ -1,315 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * gweather-gconf.c: GConf interaction methods for gweather.
- *
- * Copyright (C) 2005 Philip Langdale, Papadimitriou Spiros
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, see
- * <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Philip Langdale <philipl@mail.utexas.edu>
- * Papadimitriou Spiros <spapadim+@cs.cmu.edu>
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string.h>
-
-#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
-#include "gweather-gconf.h"
-#include "weather-priv.h"
-
-/**
- * SECTION:gweather-gconf
- * @Title: gweather-gconf
- */
-
-struct _GWeatherGConf
-{
- GConfClient *gconf;
- char *prefix;
-};
-
-
-GWeatherGConf *
-gweather_gconf_new (const char *prefix)
-{
- GWeatherGConf *ctx = g_new0 (GWeatherGConf, 1);
- ctx->gconf = gconf_client_get_default ();
- ctx->prefix = g_strdup (prefix);
-
- return ctx;
-}
-
-
-void
-gweather_gconf_free (GWeatherGConf *ctx)
-{
- if (!ctx)
- return;
-
- g_object_unref (ctx->gconf);
- g_free (ctx->prefix);
- g_free (ctx);
-}
-
-
-GConfClient *
-gweather_gconf_get_client (GWeatherGConf *ctx)
-{
- g_return_val_if_fail (ctx != NULL, NULL);
- return ctx->gconf;
-}
-
-
-gchar *
-gweather_gconf_get_full_key (GWeatherGConf *ctx,
- const gchar *key)
-{
- g_return_val_if_fail (ctx != NULL, NULL);
- g_return_val_if_fail (key != NULL, NULL);
-
- return g_strdup_printf ("%s/%s", ctx->prefix, key);
-}
-
-void
-gweather_gconf_set_bool (GWeatherGConf *ctx,
- const gchar *key,
- gboolean the_bool,
- GError **opt_error)
-{
- gchar *full_key;
-
- g_return_if_fail (ctx != NULL);
- g_return_if_fail (key != NULL);
- g_return_if_fail (opt_error == NULL || *opt_error == NULL);
-
- full_key = gweather_gconf_get_full_key (ctx, key);
- gconf_client_set_bool (ctx->gconf, full_key, the_bool, opt_error);
- g_free (full_key);
-}
-
-void
-gweather_gconf_set_int (GWeatherGConf *ctx,
- const gchar *key,
- gint the_int,
- GError **opt_error)
-{
- gchar *full_key;
-
- g_return_if_fail (ctx != NULL);
- g_return_if_fail (key != NULL);
- g_return_if_fail (opt_error == NULL || *opt_error == NULL);
-
- full_key = gweather_gconf_get_full_key (ctx, key);
- gconf_client_set_int (ctx->gconf, full_key, the_int, opt_error);
- g_free (full_key);
-}
-
-void
-gweather_gconf_set_string (GWeatherGConf *ctx,
- const gchar *key,
- const gchar *the_string,
- GError **opt_error)
-{
- gchar *full_key;
-
- g_return_if_fail (ctx != NULL);
- g_return_if_fail (key != NULL);
- g_return_if_fail (opt_error == NULL || *opt_error == NULL);
-
- full_key = gweather_gconf_get_full_key (ctx, key);
- gconf_client_set_string (ctx->gconf, full_key, the_string, opt_error);
- g_free (full_key);
-}
-
-gboolean
-gweather_gconf_get_bool (GWeatherGConf *ctx,
- const gchar *key,
- GError **opt_error)
-{
- gchar *full_key;
- gboolean ret;
-
- g_return_val_if_fail (ctx != NULL, FALSE);
- g_return_val_if_fail (key != NULL, FALSE);
- g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, FALSE);
-
- full_key = gweather_gconf_get_full_key (ctx, key);
- ret = gconf_client_get_bool (ctx->gconf, full_key, opt_error);
- g_free (full_key);
- return ret;
-}
-
-gint
-gweather_gconf_get_int (GWeatherGConf *ctx,
- const gchar *key,
- GError **opt_error)
-{
- gchar *full_key;
- gint ret;
-
- g_return_val_if_fail (ctx != NULL, 0);
- g_return_val_if_fail (key != NULL, 0);
- g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, 0);
-
- full_key = gweather_gconf_get_full_key (ctx, key);
- ret = gconf_client_get_int (ctx->gconf, full_key, opt_error);
- g_free (full_key);
- return ret;
-}
-
-gchar *
-gweather_gconf_get_string (GWeatherGConf *ctx,
- const gchar *key,
- GError **opt_error)
-{
- gchar *full_key;
- gchar *ret;
-
- g_return_val_if_fail (ctx != NULL, NULL);
- g_return_val_if_fail (key != NULL, NULL);
- g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, NULL);
-
- full_key = gweather_gconf_get_full_key (ctx, key);
- ret = gconf_client_get_string (ctx->gconf, full_key, opt_error);
- g_free (full_key);
- return ret;
-}
-
-
-WeatherLocation *
-_gweather_gconf_get_location (GWeatherGConf *ctx)
-{
- WeatherLocation *location;
- gchar *name, *code, *zone, *radar, *coordinates;
-
- g_return_val_if_fail (ctx != NULL, NULL);
-
- name = gweather_gconf_get_string (ctx, "location4", NULL);
- if (!name)
- {
- /* TRANSLATOR: Change this to the default location name,
- * used when you first start the Weather Applet. This is
- * the common localised name that corresponds to
- * the location code (DEFAULT_CODE) you will put on the next message
- * For example, for the Greek locale, we set this to "Athens", the
- * capital city and we write it in Greek. It's important to translate
- * this name.
- *
- * If you do not require a DEFAULT_LOCATION, set this to
- * "DEFAULT_LOCATION".
- */
- if (strcmp ("DEFAULT_LOCATION", _("DEFAULT_LOCATION")))
- name = g_strdup (_("DEFAULT_LOCATION"));
- else
- name = g_strdup ("Pittsburgh");
- }
-
- code = gweather_gconf_get_string (ctx, "location1", NULL);
- if (!code)
- {
- /* TRANSLATOR: Change this to the code of your default location that
- * corresponds to the DEFAULT_LOCATION name you put above. This is
- * normally a four-letter (ICAO) code and can be found in
- * http://git.gnome.org/cgit/libgweather/plain/data/Locations.xml.in
- * NB. The web page is over 1.7MB in size.
- * Pick a default location like a capital city so that it would be ok
- * for more of your users. For example, for Greek, we use "LGAV" for
- * the capital city, Athens.
- *
- * If you do not require a DEFAULT_CODE, set this to "DEFAULT_CODE".
- */
- if (strcmp ("DEFAULT_CODE", _("DEFAULT_CODE")))
- code = g_strdup (_("DEFAULT_CODE"));
- else
- code = g_strdup ("KPIT");
- }
-
- zone = gweather_gconf_get_string (ctx, "location2", NULL);
- if (!zone)
- {
- /* TRANSLATOR: Change this to the zone of your default location that
- * corresponds to the DEFAULT_LOCATION and DEFAULT_CODE you put above.
- * Normally, US and Canada locations have zones while the rest do not.
- * Check
- * http://git.gnome.org/cgit/libgweather/plain/data/Locations.xml.in
- * as any zone you put here must also be present in the Locations.xml
- * file.
- *
- * If your default location does not have a zone, set this to
- * "DEFAULT_ZONE".
- */
- if (strcmp ("DEFAULT_ZONE", _("DEFAULT_ZONE")))
- zone = g_strdup (_("DEFAULT_ZONE" ));
- else
- zone = g_strdup ("PAZ021");
- }
-
- radar = gweather_gconf_get_string (ctx, "location3", NULL);
- if (!radar)
- {
- /* TRANSLATOR: Change this to the radar of your default location that
- * corresponds to the DEFAULT_LOCATION and DEFAULT_CODE you put above.
- * Normally, US and Canada locations have radar names while the rest do
- * not. Check
- * http://git.gnome.org/cgit/libgweather/plain/data/Locations.xml.in
- * as any radar you put here must also be present in the Locations.xml
- * file.
- *
- * If your default location does not have a radar, set this to " "
- * (or space).
- * If you do not have a default location, set this to DEFAULT_RADAR.
- */
- if (strcmp ("DEFAULT_RADAR", _("DEFAULT_RADAR")))
- radar = g_strdup (_("DEFAULT_RADAR"));
- else
- radar = g_strdup ("pit");
- }
-
- coordinates = gweather_gconf_get_string (ctx, "coordinates", NULL);
- if (!coordinates)
- {
- /* TRANSLATOR: Change this to the coordinates of your default location
- * that corresponds to the DEFAULT_LOCATION and DEFAULT_CODE you put
- * above. Check
- * http://git.gnome.org/cgit/libgweather/plain/data/Locations.xml.in
- * as any coordinates you put here must also be present in the
- * Locations.xml file.
- *
- * If your default location does not have known coordinates, set this
- * to " " (or space).
- * If you do not have a default location, set this to
- * DEFAULT_COORDINATES.
- */
- if (strcmp ("DEFAULT_COORDINATES", _("DEFAULT_COORDINATES")))
- coordinates = g_strdup (_("DEFAULT_COORDINATES"));
- else
- coordinates = g_strdup ("40-32N 080-13W");
- }
-
- location = _weather_location_new (name, code, zone, radar, coordinates,
- NULL, NULL);
-
- g_free (name);
- g_free (code);
- g_free (zone);
- g_free (radar);
- g_free (coordinates);
-
- return location;
-}
diff --git a/libgweather/gweather-gconf.h b/libgweather/gweather-gconf.h
deleted file mode 100644
index 4f3f1a2..0000000
--- a/libgweather/gweather-gconf.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * gweather-gconf.h: GConf interaction methods for gweather.
- *
- * Copyright (C) 2005 Philip Langdale, Papadimitriou Spiros
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, see
- * <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Philip Langdale <philipl@mail.utexas.edu>
- * Papadimitriou Spiros <spapadim+@cs.cmu.edu>
- */
-
-#ifndef __GWEATHER_GCONF_WRAPPER_H__
-#define __GWEATHER_GCONF_WRAPPER_H__
-
-
-#ifndef GWEATHER_I_KNOW_THIS_IS_UNSTABLE
-#error "libgweather 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"
-#endif
-
-
-#include <glib.h>
-#include <gconf/gconf-client.h>
-#include <gconf/gconf-value.h>
-
-#include <libgweather/weather.h>
-
-G_BEGIN_DECLS
-
-typedef struct _GWeatherGConf GWeatherGConf;
-
-GWeatherGConf * gweather_gconf_new (const char *prefix);
-void gweather_gconf_free (GWeatherGConf *ctx);
-
-GConfClient * gweather_gconf_get_client (GWeatherGConf *ctx);
-
-gchar * gweather_gconf_get_full_key (GWeatherGConf *ctx,
- const gchar *key);
-
-void gweather_gconf_set_bool (GWeatherGConf *ctx,
- const gchar *key,
- gboolean the_bool,
- GError **opt_error);
-void gweather_gconf_set_int (GWeatherGConf *ctx,
- const gchar *key,
- gint the_int,
- GError **opt_error);
-void gweather_gconf_set_string (GWeatherGConf *ctx,
- const gchar *key,
- const gchar *the_string,
- GError **opt_error);
-
-gboolean gweather_gconf_get_bool (GWeatherGConf *ctx,
- const gchar *key,
- GError **opt_error);
-gint gweather_gconf_get_int (GWeatherGConf *ctx,
- const gchar *key,
- GError **opt_error);
-gchar * gweather_gconf_get_string (GWeatherGConf *ctx,
- const gchar *key,
- GError **opt_error);
-
-G_END_DECLS
-
-#endif /* __GWEATHER_GCONF_WRAPPER_H__ */
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index fa76640..5460302 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -34,6 +34,8 @@
#include "parser.h"
#include "weather-priv.h"
+static GHashTable *metar_code_cache;
+
/**
* SECTION:gweather-location
* @Title: GWeatherLocation
@@ -125,38 +127,6 @@ parse_coordinates (const char *coordinates,
return !*p;
}
-static char *
-unparse_coordinates (double latitude, double longitude)
-{
- int lat_d, lat_m, lat_s, lon_d, lon_m, lon_s;
- char lat_dir, lon_dir;
-
- latitude = latitude * 180.0 / M_PI;
- longitude = longitude * 180.0 / M_PI;
-
- if (latitude < 0.0) {
- lat_dir = 'S';
- latitude = -latitude;
- } else
- lat_dir = 'N';
- if (longitude < 0.0) {
- lon_dir = 'W';
- longitude = -longitude;
- } else
- lon_dir = 'E';
-
- lat_d = (int)latitude;
- lat_m = (int)(latitude * 60.0) - lat_d * 60;
- lat_s = (int)(latitude * 3600.0) - lat_d * 3600 - lat_m * 60;
- lon_d = (int)longitude;
- lon_m = (int)(longitude * 60.0) - lon_d * 60;
- lon_s = (int)(longitude * 3600.0) - lon_d * 3600 - lon_m * 60;
-
- return g_strdup_printf ("%02d-%02d-%02d%c %03d-%02d-%02d%c",
- lat_d, lat_m, lat_s, lat_dir,
- lon_d, lon_m, lon_s, lon_dir);
-}
-
static GWeatherLocation *
location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
GWeatherLocation *parent)
@@ -168,6 +138,7 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
int tagtype, i;
loc = g_slice_new0 (GWeatherLocation);
+ loc->latitude = loc->longitude = DBL_MAX;
loc->parent = parent;
loc->level = level;
loc->ref_count = 1;
@@ -279,6 +250,11 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
if (xmlTextReaderRead (parser->xml) != 1 && parent)
goto error_out;
+ if (level == GWEATHER_LOCATION_WEATHER_STATION) {
+ /* Cache weather stations by METAR code */
+ g_hash_table_replace (metar_code_cache, loc->station_code, gweather_location_ref (loc));
+ }
+
if (children->len) {
if (level == GWEATHER_LOCATION_CITY)
g_ptr_array_sort_with_data (children, sort_locations_by_distance, loc);
@@ -326,6 +302,9 @@ gweather_location_new_world (gboolean use_regions)
GWeatherParser *parser;
GWeatherLocation *world;
+ if (!metar_code_cache)
+ metar_code_cache = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) gweather_location_unref);
+
parser = gweather_parser_new (use_regions);
if (!parser)
return NULL;
@@ -751,9 +730,10 @@ WeatherLocation *
_weather_location_from_gweather_location (GWeatherLocation *gloc, const gchar *name)
{
const char *code = NULL, *zone = NULL, *radar = NULL, *tz_hint = NULL;
+ gboolean latlon_valid = FALSE;
+ gdouble lat = DBL_MAX, lon = DBL_MAX;
GWeatherLocation *l;
WeatherLocation *wloc;
- char *coords;
g_return_val_if_fail (gloc != NULL, NULL);
@@ -762,12 +742,7 @@ _weather_location_from_gweather_location (GWeatherLocation *gloc, const gchar *n
else
l = gloc;
- if (l->latlon_valid)
- coords = unparse_coordinates (l->latitude, l->longitude);
- else
- coords = NULL;
-
- while (l && (!code || !zone || !radar || !tz_hint)) {
+ while (l && (!code || !zone || !radar || !tz_hint || !latlon_valid)) {
if (!code && l->station_code)
code = l->station_code;
if (!zone && l->forecast_zone)
@@ -776,13 +751,27 @@ _weather_location_from_gweather_location (GWeatherLocation *gloc, const gchar *n
radar = l->radar;
if (!tz_hint && l->tz_hint)
tz_hint = l->tz_hint;
+ if (!latlon_valid && l->latlon_valid) {
+ lat = l->latitude;
+ lon = l->longitude;
+ latlon_valid = TRUE;
+ }
l = l->parent;
}
wloc = _weather_location_new (name ? name : gweather_location_get_name (gloc),
- code, zone, radar, coords,
+ code, zone, radar,
+ latlon_valid, lat, lon,
gweather_location_get_country (gloc),
tz_hint);
- g_free (coords);
return wloc;
}
+
+GWeatherLocation *
+gweather_location_find_by_station_code (const gchar *station_code) {
+ if (!metar_code_cache)
+ gweather_location_unref (gweather_location_new_world (FALSE));
+
+ return g_hash_table_lookup (metar_code_cache, station_code);
+}
+
diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h
index 6ef869a..89b97d9 100644
--- a/libgweather/gweather-location.h
+++ b/libgweather/gweather-location.h
@@ -79,6 +79,8 @@ void gweather_location_free_timezones (GWeatherLocation *loc,
const char *gweather_location_get_code (GWeatherLocation *loc);
char *gweather_location_get_city_name (GWeatherLocation *loc);
+GWeatherLocation *gweather_location_find_by_station_code (const gchar *code);
+
G_END_DECLS
#endif /* __GWEATHER_LOCATIONS_H__ */
diff --git a/libgweather/gweather-prefs.c b/libgweather/gweather-prefs.c
deleted file mode 100644
index b453700..0000000
--- a/libgweather/gweather-prefs.c
+++ /dev/null
@@ -1,402 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* gweather-prefs.c - Preference handling functions
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
-#include <langinfo.h>
-#endif
-
-#include <gconf/gconf-client.h>
-
-#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
-#include "gweather-prefs.h"
-#include "weather-priv.h"
-
-/**
- * SECTION:gweather-prefs
- * @Title: gweather-prefs
- */
-
-WeatherLocation * _gweather_gconf_get_location (GWeatherGConf *ctx);
-
-static GConfEnumStringPair temp_unit_enum_map [] = {
- { TEMP_UNIT_DEFAULT, N_("Default") },
- /* translators: Kelvin */
- { TEMP_UNIT_KELVIN, N_("K") },
- /* translators: Celsius */
- { TEMP_UNIT_CENTIGRADE, N_("C") },
- /* translators: Fahrenheit */
- { TEMP_UNIT_FAHRENHEIT, N_("F") },
- { 0, NULL }
-};
-
-static GConfEnumStringPair speed_unit_enum_map [] = {
- { SPEED_UNIT_DEFAULT, N_("Default") },
- /* translators: meters per second */
- { SPEED_UNIT_MS, N_("m/s") },
- /* translators: kilometers per hour */
- { SPEED_UNIT_KPH, N_("km/h") },
- /* translators: miles per hour */
- { SPEED_UNIT_MPH, N_("mph") },
- /* translators: knots (speed unit) */
- { SPEED_UNIT_KNOTS, N_("knots") },
- /* translators: wind speed */
- { SPEED_UNIT_BFT, N_("Beaufort scale") },
- { 0, NULL }
-};
-
-static GConfEnumStringPair pressure_unit_enum_map [] = {
- { PRESSURE_UNIT_DEFAULT, N_("Default") },
- /* translators: kilopascals */
- { PRESSURE_UNIT_KPA, N_("kPa") },
- /* translators: hectopascals */
- { PRESSURE_UNIT_HPA, N_("hPa") },
- /* translators: millibars */
- { PRESSURE_UNIT_MB, N_("mb") },
- /* translators: millimeters of mercury */
- { PRESSURE_UNIT_MM_HG, N_("mmHg") },
- /* translators: inches of mercury */
- { PRESSURE_UNIT_INCH_HG, N_("inHg") },
- /* translators: atmosphere */
- { PRESSURE_UNIT_ATM, N_("atm") },
- { 0, NULL }
-};
-
-static GConfEnumStringPair distance_unit_enum_map [] = {
- { DISTANCE_UNIT_DEFAULT, N_("Default") },
- /* translators: meters */
- { DISTANCE_UNIT_METERS, N_("m") },
- /* translators: kilometers */
- { DISTANCE_UNIT_KM, N_("km") },
- /* translators: miles */
- { DISTANCE_UNIT_MILES, N_("mi") },
- { 0, NULL }
-};
-
-
-static void
-parse_temp_string (const gchar *gconf_str, GWeatherPrefs *prefs)
-{
- gint value = 0;
-#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
- char *imperial = NULL;
-#endif
-
- prefs->temperature_unit = TEMP_UNIT_INVALID;
- prefs->use_temperature_default = TRUE;
-
- if ( gconf_str && gconf_string_to_enum (temp_unit_enum_map, gconf_str, &value) ) {
- prefs->temperature_unit = value;
-
- if ((prefs->temperature_unit == TEMP_UNIT_DEFAULT) &&
- (gconf_string_to_enum (temp_unit_enum_map, _("DEFAULT_TEMP_UNIT"), &value)) ) {
- prefs->temperature_unit = value;
- } else {
- prefs->use_temperature_default = FALSE;
- }
- } else {
- /* TRANSLATOR: This is the default unit to use for temperature measurements. */
- /* Valid values are: "K" (Kelvin), "C" (Celsius) and "F" (Fahrenheit) */
- if (gconf_string_to_enum (temp_unit_enum_map, _("DEFAULT_TEMP_UNIT"), &value) ) {
- prefs->temperature_unit = value;
- }
- }
- if (!prefs->temperature_unit || prefs->temperature_unit == TEMP_UNIT_DEFAULT ) {
-#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
- imperial = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
- if ( imperial && imperial[0] == 2 ) {
- /* imperial */
- prefs->temperature_unit = TEMP_UNIT_FAHRENHEIT;
- } else
-#endif
- prefs->temperature_unit = TEMP_UNIT_CENTIGRADE;
- }
-}
-
-static void
-parse_speed_string (const gchar *gconf_str, GWeatherPrefs *prefs)
-{
- gint value = 0;
-#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
- char *imperial = NULL;
-#endif
-
- prefs->speed_unit = SPEED_UNIT_INVALID;
- prefs->use_speed_default = TRUE;
-
- if (gconf_str && gconf_string_to_enum (speed_unit_enum_map, gconf_str, &value) ) {
- prefs->speed_unit = value;
- if ((prefs->speed_unit == SPEED_UNIT_DEFAULT) &&
- (gconf_string_to_enum (speed_unit_enum_map, _("DEFAULT_SPEED_UNIT"), &value)) ) {
- prefs->speed_unit = value;
- } else {
- prefs->use_speed_default = FALSE;
- }
- }
- else {
- /* TRANSLATOR: This is the default unit to use for wind speed. */
- /* Valid values are: "m/s" (meters per second), "km/h" (kilometers per hour), */
- /* "mph" (miles per hour) and "knots" */
- if (gconf_string_to_enum (speed_unit_enum_map, _("DEFAULT_SPEED_UNIT"), &value) ) {
- prefs->speed_unit = value;
- }
- }
- if ((!prefs->speed_unit) || prefs->speed_unit == SPEED_UNIT_DEFAULT) {
-#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
- imperial = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
- if (imperial && imperial[0] == 2) {
- /* imperial */
- prefs->speed_unit = SPEED_UNIT_KNOTS;
- } else
-#endif
- prefs->speed_unit = SPEED_UNIT_MS;
- }
-}
-
-
-static void
-parse_pressure_string (const gchar *gconf_str, GWeatherPrefs *prefs)
-{
- gint value = 0;
-#ifdef _NL_MEASUREMENT_MEASUREMENT
- char *imperial = NULL;
-#endif
-
- prefs->pressure_unit = PRESSURE_UNIT_INVALID;
- prefs->use_pressure_default = TRUE;
-
- if ( gconf_str && gconf_string_to_enum (pressure_unit_enum_map, gconf_str, &value) ) {
- prefs->pressure_unit = value;
-
- if ((prefs->pressure_unit == PRESSURE_UNIT_DEFAULT) &&
- (gconf_string_to_enum (pressure_unit_enum_map, _("DEFAULT_PRESSURE_UNIT"), &value)) ) {
- prefs->pressure_unit = value;
- } else {
- prefs->use_pressure_default = FALSE;
- }
- }
- else {
- /* TRANSLATOR: This is the default unit to use for atmospheric pressure. */
- /* Valid values are: "kPa" (kiloPascals), "hPa" (hectoPascals),
- "mb" (millibars), "mmHg" (millimeters of mercury),
- "inHg" (inches of mercury) and "atm" (atmosphere) */
- if (gconf_string_to_enum (pressure_unit_enum_map, _("DEFAULT_PRESSURE_UNIT"), &value) ) {
- prefs->pressure_unit = value;
- }
- }
- if ( (!prefs->pressure_unit) || prefs->pressure_unit == PRESSURE_UNIT_DEFAULT ) {
-#ifdef _NL_MEASUREMENT_MEASUREMENT
- imperial = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
- if (imperial && imperial[0] == 2) {
- /* imperial */
- prefs->pressure_unit = PRESSURE_UNIT_INCH_HG;
- } else
-#endif
- prefs->pressure_unit = PRESSURE_UNIT_HPA;
- }
-}
-
-static void
-parse_distance_string (const gchar *gconf_str, GWeatherPrefs *prefs)
-{
- gint value = 0;
-#ifdef _NL_MEASUREMENT_MEASUREMENT
- char *imperial = NULL;
-#endif
-
- prefs->distance_unit = DISTANCE_UNIT_INVALID;
- prefs->use_distance_default = TRUE;
- if (gconf_str && gconf_string_to_enum (distance_unit_enum_map, gconf_str, &value)) {
- prefs->distance_unit = value;
-
- if ((prefs->distance_unit == DISTANCE_UNIT_DEFAULT) &&
- (gconf_string_to_enum (distance_unit_enum_map, _("DEFAULT_DISTANCE_UNIT"), &value)) ) {
- prefs->distance_unit = value;
- } else {
- prefs->use_distance_default = FALSE;
- }
- }
- else {
- /* TRANSLATOR: This is the default unit to use for visibility distance. */
- /* Valid values are: "m" (meters), "km" (kilometers) and "mi" (miles) */
- if (gconf_string_to_enum (distance_unit_enum_map, _("DEFAULT_DISTANCE_UNIT"), &value) ) {
- prefs->distance_unit = value;
- }
- }
-
- if ((!prefs->distance_unit) || prefs->distance_unit == DISTANCE_UNIT_DEFAULT) {
-#ifdef _NL_MEASUREMENT_MEASUREMENT
- imperial = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
- if (imperial && imperial[0] == 2) {
- /* imperial */
- prefs->distance_unit = DISTANCE_UNIT_MILES;
- } else
-#endif
- prefs->distance_unit = DISTANCE_UNIT_METERS;
- }
-
- return;
-}
-
-const char *
-gweather_prefs_temp_enum_to_string (GWeatherTemperatureUnit temp)
-{
- return gconf_enum_to_string (temp_unit_enum_map, temp);
-}
-
-const char *
-gweather_prefs_speed_enum_to_string (GWeatherSpeedUnit speed)
-{
- return gconf_enum_to_string (speed_unit_enum_map, speed);
-}
-
-const char *
-gweather_prefs_pressure_enum_to_string (GWeatherPressureUnit pressure)
-{
- return gconf_enum_to_string (pressure_unit_enum_map, pressure);
-}
-
-const char *
-gweather_prefs_distance_enum_to_string (GWeatherDistanceUnit distance)
-{
- return gconf_enum_to_string (distance_unit_enum_map, distance);
-}
-
-
-void
-gweather_prefs_load (GWeatherPrefs *prefs, GWeatherGConf *ctx)
-{
- GError *error = NULL;
- gchar *gconf_str = NULL;
-
- g_return_if_fail (prefs != NULL);
- g_return_if_fail (ctx != NULL);
-
- if (prefs->location) {
- _weather_location_free (prefs->location);
- }
- prefs->location = _gweather_gconf_get_location (ctx);
-
- /* Assume we use unit defaults */
- prefs->use_temperature_default = TRUE;
- prefs->use_speed_default = TRUE;
- prefs->use_pressure_default = TRUE;
- prefs->use_distance_default = TRUE;
-
- prefs->update_interval =
- gweather_gconf_get_int (ctx, "auto_update_interval", &error);
- if (error) {
- g_print ("%s \n", error->message);
- g_error_free (error);
- error = NULL;
- }
- prefs->update_interval = MAX (prefs->update_interval, 60);
- prefs->update_enabled =
- gweather_gconf_get_bool (ctx, "auto_update", NULL);
- prefs->detailed =
- gweather_gconf_get_bool (ctx, "enable_detailed_forecast", NULL);
- prefs->radar_enabled =
- gweather_gconf_get_bool (ctx, "enable_radar_map", NULL);
- prefs->use_custom_radar_url =
- gweather_gconf_get_bool (ctx, "use_custom_radar_url", NULL);
-
- if (prefs->radar) {
- g_free (prefs->radar);
- prefs->radar = NULL;
- }
- prefs->radar = gweather_gconf_get_string (ctx, "radar", NULL);
-
- gconf_str = gweather_gconf_get_string (ctx, GCONF_TEMP_UNIT, NULL);
- parse_temp_string (gconf_str, prefs);
- g_free (gconf_str);
-
- gconf_str = gweather_gconf_get_string (ctx, GCONF_SPEED_UNIT, NULL);
- parse_speed_string (gconf_str, prefs);
- g_free (gconf_str);
-
- gconf_str = gweather_gconf_get_string (ctx, GCONF_PRESSURE_UNIT, NULL);
- parse_pressure_string (gconf_str, prefs);
- g_free (gconf_str);
-
- gconf_str = gweather_gconf_get_string (ctx, GCONF_DISTANCE_UNIT, NULL);
- parse_distance_string (gconf_str, prefs);
- g_free (gconf_str);
-
- return;
-}
-
-GWeatherTemperatureUnit
-gweather_prefs_parse_temperature (const char *str, gboolean *is_default)
-{
- GWeatherPrefs prefs;
-
- g_return_val_if_fail (str != NULL, TEMP_UNIT_INVALID);
- g_return_val_if_fail (is_default != NULL, TEMP_UNIT_INVALID);
-
- parse_temp_string (str, &prefs);
- *is_default = prefs.use_temperature_default;
- return prefs.temperature_unit;
-}
-
-GWeatherSpeedUnit
-gweather_prefs_parse_speed (const char *str, gboolean *is_default)
-{
- GWeatherPrefs prefs;
-
- g_return_val_if_fail (str != NULL, SPEED_UNIT_INVALID);
- g_return_val_if_fail (is_default != NULL, SPEED_UNIT_INVALID);
-
- parse_speed_string (str, &prefs);
- *is_default = prefs.use_speed_default;
- return prefs.speed_unit;
-}
-
-static const char *
-get_translated_unit (int unit, GConfEnumStringPair *pairs, int min_value, int max_value)
-{
- g_return_val_if_fail (unit >= min_value && unit <= max_value, NULL);
-
- return _(pairs[unit - 1].str); /* minus 1 because enum value 0 is for "invalid" (look at weather.h) */
-}
-
-const char *
-gweather_prefs_get_temp_display_name (GWeatherTemperatureUnit temp)
-{
- return get_translated_unit (temp, temp_unit_enum_map, TEMP_UNIT_DEFAULT, TEMP_UNIT_FAHRENHEIT);
-}
-
-const char *
-gweather_prefs_get_speed_display_name (GWeatherSpeedUnit speed)
-{
- return get_translated_unit (speed, speed_unit_enum_map, SPEED_UNIT_DEFAULT, SPEED_UNIT_BFT);
-}
-
-const char *
-gweather_prefs_get_pressure_display_name (GWeatherPressureUnit pressure)
-{
- return get_translated_unit (pressure, pressure_unit_enum_map, PRESSURE_UNIT_DEFAULT, PRESSURE_UNIT_ATM);
-}
-
-const char *
-gweather_prefs_get_distance_display_name (GWeatherDistanceUnit distance)
-{
- return get_translated_unit (distance, distance_unit_enum_map, DISTANCE_UNIT_DEFAULT, DISTANCE_UNIT_MILES);
-}
diff --git a/libgweather/gweather-prefs.h b/libgweather/gweather-prefs.h
deleted file mode 100644
index 430c966..0000000
--- a/libgweather/gweather-prefs.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* gweather-prefs.h - Preference handling functions
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GWEATHER_PREFS_H_
-#define __GWEATHER_PREFS_H_
-
-
-#ifndef GWEATHER_I_KNOW_THIS_IS_UNSTABLE
-#error "libgweather 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"
-#endif
-
-
-#include <libgweather/weather.h>
-#include <libgweather/gweather-gconf.h>
-
-/* gconf keys */
-#define GCONF_TEMP_UNIT "temperature_unit"
-#define GCONF_SPEED_UNIT "speed_unit"
-#define GCONF_PRESSURE_UNIT "pressure_unit"
-#define GCONF_DISTANCE_UNIT "distance_unit"
-
-typedef struct _GWeatherPrefs GWeatherPrefs;
-
-void gweather_prefs_load (GWeatherPrefs *prefs,
- GWeatherGConf *ctx);
-
-const char * gweather_prefs_temp_enum_to_string (GWeatherTemperatureUnit temp);
-const char * gweather_prefs_speed_enum_to_string (GWeatherSpeedUnit speed);
-const char * gweather_prefs_pressure_enum_to_string (GWeatherPressureUnit pressure);
-const char * gweather_prefs_distance_enum_to_string (GWeatherDistanceUnit distance);
-
-GWeatherTemperatureUnit gweather_prefs_parse_temperature (const char *str,
- gboolean *is_default);
-GWeatherSpeedUnit gweather_prefs_parse_speed (const char *str,
- gboolean *is_default);
-
-const char * gweather_prefs_get_temp_display_name (GWeatherTemperatureUnit temp);
-const char * gweather_prefs_get_speed_display_name (GWeatherSpeedUnit speed);
-const char * gweather_prefs_get_pressure_display_name (GWeatherPressureUnit pressure);
-const char * gweather_prefs_get_distance_display_name (GWeatherDistanceUnit distance);
-
-#endif /* __GWEATHER_PREFS_H_ */
diff --git a/libgweather/gweather.schemas.in b/libgweather/gweather.schemas.in
deleted file mode 100644
index 7ec8da7..0000000
--- a/libgweather/gweather.schemas.in
+++ /dev/null
@@ -1,173 +0,0 @@
-<gconfschemafile>
-<schemalist>
-
-<schema>
- <key>/schemas/apps/gweather/prefs/auto_update</key>
- <owner>gweather-applet-2</owner>
- <type>bool</type>
- <default>true</default>
- <locale name="C">
- <short>Update the data automatically</short>
- <long>Determines whether the applet automatically updates its weather statistics or not.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/auto_update_interval</key>
- <owner>gweather-applet-2</owner>
- <type>int</type>
- <default>1800</default>
- <locale name="C">
- <short>Update interval</short>
- <long>The interval, in seconds, between automatic updates.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/enable_metric</key>
- <owner>gweather-applet-2</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Use metric units</short>
- <long>Use metric units instead of english units.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/distance_unit</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <default>Default</default>
- <locale name="C">
- <short>Distance unit</short>
- <long>The unit to use for visibility.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/pressure_unit</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <default>Default</default>
- <locale name="C">
- <short>Pressure unit</short>
- <long>The unit to use for pressure.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/speed_unit</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <default>Default</default>
- <locale name="C">
- <short>Speed unit</short>
- <long>The unit to use for wind speed.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/temperature_unit</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <default>Default</default>
- <locale name="C">
- <short>Temperature unit</short>
- <long>The unit to use for temperature.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/enable_detailed_forecast</key>
- <owner>gweather-applet-2</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Not used anymore</short>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/enable_radar_map</key>
- <owner>gweather-applet-2</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Display radar map</short>
- <long>Fetch a radar map on each update.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/location0</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <locale name="C">
- <default>DEFAULT_LOCATION</default>
- <short>Weather location information</short>
- <long>Weather location information.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/location1</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <locale name="C">
- <default>DEFAULT_CODE</default>
- <short>Nearby city</short>
- <long>Nearby major zone, such as a capital city, as found from http://git.gnome.org/cgit/libgweather/plain/data/Locations.xml.in</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/location2</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <locale name="C">
- <default>DEFAULT_ZONE</default>
- <short>Zone location</short>
- <long>A unique zone for the city, as found from http://git.gnome.org/cgit/libgweather/plain/data/Locations.xml.in</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/location3</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <locale name="C">
- <default>DEFAULT_RADAR</default>
- <short>Radar location</short>
- <long>A three-digit-long code for retrieving radar maps from weather.com, found from http://git.gnome.org/cgit/libgweather/plain/data/Locations.xml.in</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/location4</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <locale name="C">
- <default>DEFAULT_LOCATION</default>
- <short>Weather for a city</short>
- <long>The city that gweather displays information for.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/coordinates</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <locale name="C">
- <default>DEFAULT_COORDINATES</default>
- <short>Location coordinates</short>
- <long>Latitude and longitude of your location expressed in DD-MM-SS[NS] DD-MM-SS[EW].</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/use_custom_radar_url</key>
- <owner>gweather-applet-2</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Use custom url for the radar map</short>
- <long>If true, then retrieve a radar map from a location specified by the "radar" key.</long>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/gweather/prefs/radar</key>
- <owner>gweather-applet-2</owner>
- <type>string</type>
- <locale name="C">
- <short>Url for the radar map</short>
- <long>The custom url from where to retrieve a radar map.</long>
- </locale>
-</schema>
-</schemalist>
-</gconfschemafile>
diff --git a/libgweather/test_metar.c b/libgweather/test_metar.c
index 3ab2ace..3ecad6d 100644
--- a/libgweather/test_metar.c
+++ b/libgweather/test_metar.c
@@ -60,7 +60,6 @@ main (int argc, char **argv)
info = g_object_new (GWEATHER_TYPE_INFO, NULL);
info->priv->valid = 1;
metar_parse (buf, info);
- gweather_info_to_metric (info);
printf ("Returned info:\n");
printf (" update: %s", ctime (&info->priv->update));
printf (" sky: %s\n", gweather_info_get_sky (info));
diff --git a/libgweather/test_sun_moon.c b/libgweather/test_sun_moon.c
index dc17e3f..325696f 100644
--- a/libgweather/test_sun_moon.c
+++ b/libgweather/test_sun_moon.c
@@ -52,8 +52,7 @@ main (int argc, char **argv)
location.latitude = DEGREES_TO_RADIANS(latitude);
location.longitude = DEGREES_TO_RADIANS(longitude);
- /* any string will do here, just it cannot be NULL */
- location.coordinates = "dummy";
+ location.latlon_valid = TRUE;
info = g_object_new (GWEATHER_TYPE_INFO, NULL);
info->priv->location = _weather_location_clone(&location);
info->priv->valid = TRUE;
diff --git a/libgweather/weather-iwin.c b/libgweather/weather-iwin.c
index e929656..09a4374 100644
--- a/libgweather/weather-iwin.c
+++ b/libgweather/weather-iwin.c
@@ -177,6 +177,7 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info)
for (i = 0; i < 7; i++) {
GWeatherInfo *nfo = _gweather_info_new_clone (master_info);
+ nfo->priv->update = update_times[i];
if (nfo)
res = g_slist_append (res, nfo);
@@ -238,44 +239,44 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info)
const char *name;
GWeatherConditionPhenomenon ph;
} ph_list[] = {
- { "Ice Crystals", PHENOMENON_ICE_CRYSTALS } ,
- { "Volcanic Ash", PHENOMENON_VOLCANIC_ASH } ,
- { "Blowing Sand", PHENOMENON_SANDSTORM } ,
- { "Blowing Dust", PHENOMENON_DUSTSTORM } ,
- { "Blowing Snow", PHENOMENON_FUNNEL_CLOUD } ,
- { "Drizzle", PHENOMENON_DRIZZLE } ,
- { "Rain", PHENOMENON_RAIN } ,
- { "Snow", PHENOMENON_SNOW } ,
- { "Fog", PHENOMENON_FOG } ,
- { "Smoke", PHENOMENON_SMOKE } ,
- { "Sand", PHENOMENON_SAND } ,
- { "Haze", PHENOMENON_HAZE } ,
- { "Dust", PHENOMENON_DUST } /*,
- { "", PHENOMENON_SNOW_GRAINS } ,
- { "", PHENOMENON_ICE_PELLETS } ,
- { "", PHENOMENON_HAIL } ,
- { "", PHENOMENON_SMALL_HAIL } ,
- { "", PHENOMENON_UNKNOWN_PRECIPITATION } ,
- { "", PHENOMENON_MIST } ,
- { "", PHENOMENON_SPRAY } ,
- { "", PHENOMENON_SQUALL } ,
- { "", PHENOMENON_TORNADO } ,
- { "", PHENOMENON_DUST_WHIRLS } */
+ { "Ice Crystals", GWEATHER_PHENOMENON_ICE_CRYSTALS } ,
+ { "Volcanic Ash", GWEATHER_PHENOMENON_VOLCANIC_ASH } ,
+ { "Blowing Sand", GWEATHER_PHENOMENON_SANDSTORM } ,
+ { "Blowing Dust", GWEATHER_PHENOMENON_DUSTSTORM } ,
+ { "Blowing Snow", GWEATHER_PHENOMENON_FUNNEL_CLOUD } ,
+ { "Drizzle", GWEATHER_PHENOMENON_DRIZZLE } ,
+ { "Rain", GWEATHER_PHENOMENON_RAIN } ,
+ { "Snow", GWEATHER_PHENOMENON_SNOW } ,
+ { "Fog", GWEATHER_PHENOMENON_FOG } ,
+ { "Smoke", GWEATHER_PHENOMENON_SMOKE } ,
+ { "Sand", GWEATHER_PHENOMENON_SAND } ,
+ { "Haze", GWEATHER_PHENOMENON_HAZE } ,
+ { "Dust", GWEATHER_PHENOMENON_DUST } /*,
+ { "", GWEATHER_PHENOMENON_SNOW_GRAINS } ,
+ { "", GWEATHER_PHENOMENON_ICE_PELLETS } ,
+ { "", GWEATHER_PHENOMENON_HAIL } ,
+ { "", GWEATHER_PHENOMENON_SMALL_HAIL } ,
+ { "", GWEATHER_PHENOMENON_UNKNOWN_PRECIPITATION } ,
+ { "", GWEATHER_PHENOMENON_MIST } ,
+ { "", GWEATHER_PHENOMENON_SPRAY } ,
+ { "", GWEATHER_PHENOMENON_SQUALL } ,
+ { "", GWEATHER_PHENOMENON_TORNADO } ,
+ { "", GWEATHER_PHENOMENON_DUST_WHIRLS } */
};
struct _sky_list {
const char *name;
GWeatherSky sky;
} sky_list[] = {
- { "Mostly Sunny", SKY_BROKEN } ,
- { "Mostly Clear", SKY_BROKEN } ,
- { "Partly Cloudy", SKY_SCATTERED } ,
- { "Mostly Cloudy", SKY_FEW } ,
- { "Sunny", SKY_CLEAR } ,
- { "Clear", SKY_CLEAR } ,
- { "Cloudy", SKY_OVERCAST } ,
- { "Clouds", SKY_SCATTERED } ,
- { "Rain", SKY_SCATTERED } ,
- { "Snow", SKY_SCATTERED }
+ { "Mostly Sunny", GWEATHER_SKY_BROKEN } ,
+ { "Mostly Clear", GWEATHER_SKY_BROKEN } ,
+ { "Partly Cloudy", GWEATHER_SKY_SCATTERED } ,
+ { "Mostly Cloudy", GWEATHER_SKY_FEW } ,
+ { "Sunny", GWEATHER_SKY_CLEAR } ,
+ { "Clear", GWEATHER_SKY_CLEAR } ,
+ { "Cloudy", GWEATHER_SKY_OVERCAST } ,
+ { "Clouds", GWEATHER_SKY_SCATTERED } ,
+ { "Rain", GWEATHER_SKY_SCATTERED } ,
+ { "Snow", GWEATHER_SKY_SCATTERED }
};
priv->valid = TRUE;
@@ -284,6 +285,7 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info)
for (i = 0; i < G_N_ELEMENTS (ph_list); i++) {
if (strstr ((const char *)val, ph_list [i].name)) {
+ priv->cond.significant = TRUE;
priv->cond.phenomenon = ph_list [i].ph;
break;
}
@@ -372,7 +374,7 @@ iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data)
priv = info->priv;
- if (priv->forecast_type == FORECAST_LIST)
+ if (priv->forecast_type == GWEATHER_FORECAST_LIST)
priv->forecast_list = parseForecastXml (msg->response_body->data, info);
else
priv->forecast = formatWeatherMsg (g_strdup (msg->response_body->data));
@@ -395,7 +397,7 @@ iwin_start_open (GWeatherInfo *info)
loc = priv->location;
g_return_if_fail (loc != NULL);
- if (loc->zone[0] == '-' && (priv->forecast_type != FORECAST_LIST || loc->coordinates == NULL))
+ if ((!loc->zone || loc->zone[0] == '-') && (priv->forecast_type != GWEATHER_FORECAST_LIST || !loc->latlon_valid))
return;
if (priv->forecast) {
@@ -405,9 +407,9 @@ iwin_start_open (GWeatherInfo *info)
free_forecast_list (info);
- if (priv->forecast_type == FORECAST_LIST) {
+ if (priv->forecast_type == GWEATHER_FORECAST_LIST) {
/* see the description here: http://www.weather.gov/forecasts/xml/ */
- if (loc->coordinates != NULL) {
+ if (loc->latlon_valid) {
struct tm tm;
time_t now = time (NULL);
diff --git a/libgweather/weather-metar.c b/libgweather/weather-metar.c
index 3630646..83e8cf2 100644
--- a/libgweather/weather-metar.c
+++ b/libgweather/weather-metar.c
@@ -116,37 +116,37 @@ metar_tok_wind (gchar *tokp, GWeatherInfo *info)
priv->windspeed = (GWeatherWindSpeed)spd;
if ((349 <= dir) || (dir <= 11))
- priv->wind = WIND_N;
+ priv->wind = GWEATHER_WIND_N;
else if ((12 <= dir) && (dir <= 33))
- priv->wind = WIND_NNE;
+ priv->wind = GWEATHER_WIND_NNE;
else if ((34 <= dir) && (dir <= 56))
- priv->wind = WIND_NE;
+ priv->wind = GWEATHER_WIND_NE;
else if ((57 <= dir) && (dir <= 78))
- priv->wind = WIND_ENE;
+ priv->wind = GWEATHER_WIND_ENE;
else if ((79 <= dir) && (dir <= 101))
- priv->wind = WIND_E;
+ priv->wind = GWEATHER_WIND_E;
else if ((102 <= dir) && (dir <= 123))
- priv->wind = WIND_ESE;
+ priv->wind = GWEATHER_WIND_ESE;
else if ((124 <= dir) && (dir <= 146))
- priv->wind = WIND_SE;
+ priv->wind = GWEATHER_WIND_SE;
else if ((147 <= dir) && (dir <= 168))
- priv->wind = WIND_SSE;
+ priv->wind = GWEATHER_WIND_SSE;
else if ((169 <= dir) && (dir <= 191))
- priv->wind = WIND_S;
+ priv->wind = GWEATHER_WIND_S;
else if ((192 <= dir) && (dir <= 213))
- priv->wind = WIND_SSW;
+ priv->wind = GWEATHER_WIND_SSW;
else if ((214 <= dir) && (dir <= 236))
- priv->wind = WIND_SW;
+ priv->wind = GWEATHER_WIND_SW;
else if ((237 <= dir) && (dir <= 258))
- priv->wind = WIND_WSW;
+ priv->wind = GWEATHER_WIND_WSW;
else if ((259 <= dir) && (dir <= 281))
- priv->wind = WIND_W;
+ priv->wind = GWEATHER_WIND_W;
else if ((282 <= dir) && (dir <= 303))
- priv->wind = WIND_WNW;
+ priv->wind = GWEATHER_WIND_WNW;
else if ((304 <= dir) && (dir <= 326))
- priv->wind = WIND_NW;
+ priv->wind = GWEATHER_WIND_NW;
else if ((327 <= dir) && (dir <= 348))
- priv->wind = WIND_NNW;
+ priv->wind = GWEATHER_WIND_NNW;
}
static void
@@ -164,7 +164,7 @@ metar_tok_vis (gchar *tokp, GWeatherInfo *info)
if (!strcmp (tokp,"CAVOK")) {
// "Ceiling And Visibility OK": visibility >= 10 KM
priv->visibility=10000. / VISIBILITY_SM_TO_M (1.);
- priv->sky = SKY_CLEAR;
+ priv->sky = GWEATHER_SKY_CLEAR;
} else if (0 != (pend = strstr (tokp, "SM"))) {
// US observation: field ends with "SM"
pfrac = strchr (tokp, '/');
@@ -215,19 +215,19 @@ metar_tok_cloud (gchar *tokp, GWeatherInfo *info)
}
if (!strcmp (stype, "CLR")) {
- priv->sky = SKY_CLEAR;
+ priv->sky = GWEATHER_SKY_CLEAR;
} else if (!strcmp (stype, "SKC")) {
- priv->sky = SKY_CLEAR;
+ priv->sky = GWEATHER_SKY_CLEAR;
} else if (!strcmp (stype, "NSC")) {
- priv->sky = SKY_CLEAR;
+ priv->sky = GWEATHER_SKY_CLEAR;
} else if (!strcmp (stype, "BKN")) {
- priv->sky = SKY_BROKEN;
+ priv->sky = GWEATHER_SKY_BROKEN;
} else if (!strcmp (stype, "SCT")) {
- priv->sky = SKY_SCATTERED;
+ priv->sky = GWEATHER_SKY_SCATTERED;
} else if (!strcmp (stype, "FEW")) {
- priv->sky = SKY_FEW;
+ priv->sky = GWEATHER_SKY_FEW;
} else if (!strcmp (stype, "OVC")) {
- priv->sky = SKY_OVERCAST;
+ priv->sky = GWEATHER_SKY_OVERCAST;
}
}
@@ -312,89 +312,89 @@ metar_tok_cond (gchar *tokp, GWeatherInfo *info)
sphen[sizeof (sphen)-1] = '\0';
/* Defaults */
- priv->cond.qualifier = QUALIFIER_NONE;
- priv->cond.phenomenon = PHENOMENON_NONE;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_NONE;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_NONE;
priv->cond.significant = FALSE;
if (!strcmp (squal, "")) {
- priv->cond.qualifier = QUALIFIER_MODERATE;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_MODERATE;
} else if (!strcmp (squal, "-")) {
- priv->cond.qualifier = QUALIFIER_LIGHT;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_LIGHT;
} else if (!strcmp (squal, "+")) {
- priv->cond.qualifier = QUALIFIER_HEAVY;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_HEAVY;
} else if (!strcmp (squal, "VC")) {
- priv->cond.qualifier = QUALIFIER_VICINITY;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_VICINITY;
} else if (!strcmp (squal, "MI")) {
- priv->cond.qualifier = QUALIFIER_SHALLOW;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_SHALLOW;
} else if (!strcmp (squal, "BC")) {
- priv->cond.qualifier = QUALIFIER_PATCHES;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_PATCHES;
} else if (!strcmp (squal, "PR")) {
- priv->cond.qualifier = QUALIFIER_PARTIAL;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_PARTIAL;
} else if (!strcmp (squal, "TS")) {
- priv->cond.qualifier = QUALIFIER_THUNDERSTORM;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_THUNDERSTORM;
} else if (!strcmp (squal, "BL")) {
- priv->cond.qualifier = QUALIFIER_BLOWING;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_BLOWING;
} else if (!strcmp (squal, "SH")) {
- priv->cond.qualifier = QUALIFIER_SHOWERS;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_SHOWERS;
} else if (!strcmp (squal, "DR")) {
- priv->cond.qualifier = QUALIFIER_DRIFTING;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_DRIFTING;
} else if (!strcmp (squal, "FZ")) {
- priv->cond.qualifier = QUALIFIER_FREEZING;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_FREEZING;
} else {
return;
}
if (!strcmp (sphen, "DZ")) {
- priv->cond.phenomenon = PHENOMENON_DRIZZLE;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_DRIZZLE;
} else if (!strcmp (sphen, "RA")) {
- priv->cond.phenomenon = PHENOMENON_RAIN;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_RAIN;
} else if (!strcmp (sphen, "SN")) {
- priv->cond.phenomenon = PHENOMENON_SNOW;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_SNOW;
} else if (!strcmp (sphen, "SG")) {
- priv->cond.phenomenon = PHENOMENON_SNOW_GRAINS;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_SNOW_GRAINS;
} else if (!strcmp (sphen, "IC")) {
- priv->cond.phenomenon = PHENOMENON_ICE_CRYSTALS;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_ICE_CRYSTALS;
} else if (!strcmp (sphen, "PE")) {
- priv->cond.phenomenon = PHENOMENON_ICE_PELLETS;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_ICE_PELLETS;
} else if (!strcmp (sphen, "GR")) {
- priv->cond.phenomenon = PHENOMENON_HAIL;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_HAIL;
} else if (!strcmp (sphen, "GS")) {
- priv->cond.phenomenon = PHENOMENON_SMALL_HAIL;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_SMALL_HAIL;
} else if (!strcmp (sphen, "UP")) {
- priv->cond.phenomenon = PHENOMENON_UNKNOWN_PRECIPITATION;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_UNKNOWN_PRECIPITATION;
} else if (!strcmp (sphen, "BR")) {
- priv->cond.phenomenon = PHENOMENON_MIST;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_MIST;
} else if (!strcmp (sphen, "FG")) {
- priv->cond.phenomenon = PHENOMENON_FOG;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_FOG;
} else if (!strcmp (sphen, "FU")) {
- priv->cond.phenomenon = PHENOMENON_SMOKE;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_SMOKE;
} else if (!strcmp (sphen, "VA")) {
- priv->cond.phenomenon = PHENOMENON_VOLCANIC_ASH;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_VOLCANIC_ASH;
} else if (!strcmp (sphen, "SA")) {
- priv->cond.phenomenon = PHENOMENON_SAND;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_SAND;
} else if (!strcmp (sphen, "HZ")) {
- priv->cond.phenomenon = PHENOMENON_HAZE;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_HAZE;
} else if (!strcmp (sphen, "PY")) {
- priv->cond.phenomenon = PHENOMENON_SPRAY;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_SPRAY;
} else if (!strcmp (sphen, "DU")) {
- priv->cond.phenomenon = PHENOMENON_DUST;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_DUST;
} else if (!strcmp (sphen, "SQ")) {
- priv->cond.phenomenon = PHENOMENON_SQUALL;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_SQUALL;
} else if (!strcmp (sphen, "SS")) {
- priv->cond.phenomenon = PHENOMENON_SANDSTORM;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_SANDSTORM;
} else if (!strcmp (sphen, "DS")) {
- priv->cond.phenomenon = PHENOMENON_DUSTSTORM;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_DUSTSTORM;
} else if (!strcmp (sphen, "PO")) {
- priv->cond.phenomenon = PHENOMENON_DUST_WHIRLS;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_DUST_WHIRLS;
} else if (!strcmp (sphen, "+FC")) {
- priv->cond.phenomenon = PHENOMENON_TORNADO;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_TORNADO;
} else if (!strcmp (sphen, "FC")) {
- priv->cond.phenomenon = PHENOMENON_FUNNEL_CLOUD;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_FUNNEL_CLOUD;
} else {
return;
}
- if ((priv->cond.qualifier != QUALIFIER_NONE) || (priv->cond.phenomenon != PHENOMENON_NONE))
+ if ((priv->cond.qualifier != GWEATHER_QUALIFIER_NONE) || (priv->cond.phenomenon != GWEATHER_PHENOMENON_NONE))
priv->cond.significant = TRUE;
}
diff --git a/libgweather/weather-priv.h b/libgweather/weather-priv.h
index 0d89cfb..cb02331 100644
--- a/libgweather/weather-priv.h
+++ b/libgweather/weather-priv.h
@@ -24,6 +24,7 @@
#include <time.h>
#include <libintl.h>
#include <math.h>
+#include <gio/gio.h>
#ifdef HAVE_LIBSOUP_GNOME
#include <libsoup/soup-gnome.h>
#else
@@ -54,7 +55,7 @@ typedef struct {
gchar *code;
gchar *zone;
gchar *radar;
- gchar *coordinates;
+ gboolean latlon_valid;
gdouble latitude;
gdouble longitude;
gchar *country_code;
@@ -67,7 +68,9 @@ WeatherLocation * _weather_location_new (const gchar *trans_name,
const gchar *code,
const gchar *zone,
const gchar *radar,
- const gchar *coordinates,
+ gboolean latlon_valid,
+ double latitude,
+ double longitude,
const gchar *country_code,
const gchar *tz_hint);
WeatherLocation * _weather_location_clone (const WeatherLocation *location);
@@ -89,10 +92,7 @@ typedef time_t GWeatherUpdate;
struct _GWeatherInfoPrivate {
GWeatherForecastType forecast_type;
- GWeatherTemperatureUnit temperature_unit;
- GWeatherSpeedUnit speed_unit;
- GWeatherPressureUnit pressure_unit;
- GWeatherDistanceUnit distance_unit;
+ GSettings *settings;
gboolean valid;
gboolean network_error;
@@ -120,7 +120,7 @@ struct _GWeatherInfoPrivate {
GWeatherMoonPhase moonphase;
GWeatherMoonLatitude moonlatitude;
gchar *forecast;
- GSList *forecast_list; /* list of WeatherInfo* for the forecast, NULL if not available */
+ GSList *forecast_list; /* list of GWeatherInfo* for the forecast, NULL if not available */
gchar *radar_buffer;
gchar *radar_url;
GdkPixbufLoader *radar_loader;
@@ -201,24 +201,5 @@ void free_forecast_list (GWeatherInfo *info);
GWeatherInfo *_gweather_info_new_clone (GWeatherInfo *info);
-struct _GWeatherPrefs {
- WeatherLocation *location;
- gint update_interval; /* in seconds */
- gboolean update_enabled;
- gboolean detailed;
- gboolean radar_enabled;
- gboolean use_custom_radar_url;
- gchar *radar;
-
- GWeatherTemperatureUnit temperature_unit;
- gboolean use_temperature_default;
- GWeatherSpeedUnit speed_unit;
- gboolean use_speed_default;
- GWeatherPressureUnit pressure_unit;
- gboolean use_pressure_default;
- GWeatherDistanceUnit distance_unit;
- gboolean use_distance_default;
-};
-
#endif /* __WEATHER_PRIV_H_ */
diff --git a/libgweather/weather-sun.c b/libgweather/weather-sun.c
index b0f299a..781345d 100644
--- a/libgweather/weather-sun.c
+++ b/libgweather/weather-sun.c
@@ -298,7 +298,7 @@ calc_sun2 (GWeatherInfo *info, time_t t)
gboolean
calc_sun_time (GWeatherInfo *info, time_t t)
{
- return info->priv->location->coordinates != NULL && calc_sun2 (info, t);
+ return info->priv->location->latlon_valid && calc_sun2 (info, t);
}
/**
diff --git a/libgweather/weather.c b/libgweather/weather.c
index 953f490..31f1b6e 100644
--- a/libgweather/weather.c
+++ b/libgweather/weather.c
@@ -40,7 +40,6 @@
#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
#include "weather.h"
#include "weather-priv.h"
-#include "gweather-prefs.h"
#include "gweather-enum-types.h"
#define MOON_PHASES 36
@@ -54,11 +53,17 @@
static void _weather_internal_check (void);
+#define TEMPERATURE_UNIT "temperature-unit"
+#define DISTANCE_UNIT "distance-unit"
+#define SPEED_UNIT "speed-unit"
+#define PRESSURE_UNIT "pressure-unit"
+#define RADAR_KEY "radar"
+#define DEFAULT_LOCATION "default-location"
+
enum {
PROP_0,
PROP_LOCATION,
PROP_TYPE,
- PROP_PREFS,
PROP_LAST
};
@@ -100,48 +105,12 @@ gweather_dpgettext (const char *context,
return g_dpgettext2 (GETTEXT_PACKAGE, context, str);
}
-/*
- * Convert string of the form "DD-MM-SSH" to radians
- * DD:degrees (to 3 digits), MM:minutes, SS:seconds H:hemisphere (NESW)
- * Return value is positive for N,E; negative for S,W.
- */
-static gdouble
-dmsh2rad (const gchar *latlon)
-{
- char *p1, *p2;
- int deg, min, sec, dir;
- gdouble value;
-
- if (latlon == NULL)
- return DBL_MAX;
- p1 = strchr (latlon, '-');
- p2 = strrchr (latlon, '-');
- if (p1 == NULL || p1 == latlon) {
- return DBL_MAX;
- } else if (p1 == p2) {
- sscanf (latlon, "%d-%d", &deg, &min);
- sec = 0;
- } else if (p2 == 1 + p1) {
- return DBL_MAX;
- } else {
- sscanf (latlon, "%d-%d-%d", &deg, &min, &sec);
- }
- if (deg > 180 || min >= 60 || sec >= 60)
- return DBL_MAX;
- value = (gdouble)((deg * 60 + min) * 60 + sec) * M_PI / 648000.;
-
- dir = g_ascii_toupper (latlon[strlen (latlon) - 1]);
- if (dir == 'W' || dir == 'S')
- value = -value;
- else if (dir != 'E' && dir != 'N' && (value != 0.0 || dir != '0'))
- value = DBL_MAX;
- return value;
-}
-
WeatherLocation *
_weather_location_new (const gchar *name, const gchar *code,
const gchar *zone, const gchar *radar,
- const gchar *coordinates,
+ gboolean latlon_valid,
+ double latitude,
+ double longitude,
const gchar *country_code,
const gchar *tz_hint)
{
@@ -161,28 +130,9 @@ _weather_location_new (const gchar *name, const gchar *code,
if (radar)
location->radar = g_strdup (radar);
- if (coordinates)
- {
- char **pieces;
-
- pieces = g_strsplit (coordinates, " ", -1);
-
- if (g_strv_length (pieces) == 2)
- {
- location->coordinates = g_strdup (coordinates);
- location->latitude = dmsh2rad (pieces[0]);
- location->longitude = dmsh2rad (pieces[1]);
- }
-
- g_strfreev (pieces);
- }
-
- if (!location->coordinates)
- {
- location->latitude = DBL_MAX;
- location->longitude = DBL_MAX;
- }
-
+ location->latlon_valid = latlon_valid;
+ location->latitude = latitude;
+ location->longitude = longitude;
location->country_code = g_strdup (country_code);
location->tz_hint = g_strdup (tz_hint);
@@ -208,14 +158,9 @@ _weather_location_clone (const WeatherLocation *location)
if (location->radar)
clone->radar = g_strdup (location->radar);
- if (location->coordinates) {
- clone->coordinates = g_strdup (location->coordinates);
- clone->latitude = location->latitude;
- clone->longitude = location->longitude;
- } else {
- clone->latitude = DBL_MAX;
- clone->longitude = DBL_MAX;
- }
+ clone->latlon_valid = location->latlon_valid;
+ clone->latitude = location->latitude;
+ clone->longitude = location->longitude;
return clone;
}
@@ -228,7 +173,6 @@ _weather_location_free (WeatherLocation *location)
g_free (location->code);
g_free (location->zone);
g_free (location->radar);
- g_free (location->coordinates);
g_free (location->country_code);
g_free (location->tz_hint);
@@ -262,7 +206,7 @@ static const gchar *wind_direction_str[] = {
const gchar *
gweather_wind_direction_to_string (GWeatherWindDirection wind)
{
- if (wind <= WIND_INVALID || wind >= WIND_LAST)
+ if (wind <= GWEATHER_WIND_INVALID || wind >= GWEATHER_WIND_LAST)
return _("Invalid");
return _(wind_direction_str[(int)wind]);
@@ -279,7 +223,7 @@ static const gchar *sky_str[] = {
const gchar *
gweather_sky_to_string (GWeatherSky sky)
{
- if (sky <= SKY_INVALID || sky >= SKY_LAST)
+ if (sky <= GWEATHER_SKY_INVALID || sky >= GWEATHER_SKY_LAST)
return _("Invalid");
return _(sky_str[(int)sky]);
@@ -346,10 +290,10 @@ gweather_conditions_to_string (GWeatherConditions *cond)
if (!cond->significant) {
return "-";
} else {
- if (cond->phenomenon > PHENOMENON_INVALID &&
- cond->phenomenon < PHENOMENON_LAST &&
- cond->qualifier > QUALIFIER_INVALID &&
- cond->qualifier < QUALIFIER_LAST)
+ if (cond->phenomenon > GWEATHER_PHENOMENON_INVALID &&
+ cond->phenomenon < GWEATHER_PHENOMENON_LAST &&
+ cond->qualifier > GWEATHER_QUALIFIER_INVALID &&
+ cond->qualifier < GWEATHER_QUALIFIER_LAST)
str = _(conditions_str[(int)cond->phenomenon][(int)cond->qualifier]);
else
str = _("Invalid");
@@ -509,8 +453,8 @@ gweather_info_reset (GWeatherInfo *info)
priv->update = 0;
priv->sky = -1;
priv->cond.significant = FALSE;
- priv->cond.phenomenon = PHENOMENON_NONE;
- priv->cond.qualifier = QUALIFIER_NONE;
+ priv->cond.phenomenon = GWEATHER_PHENOMENON_NONE;
+ priv->cond.qualifier = GWEATHER_QUALIFIER_NONE;
priv->temp = -1000.0;
priv->tempMinMaxValid = FALSE;
priv->temp_min = -1000.0;
@@ -535,33 +479,18 @@ gweather_info_reset (GWeatherInfo *info)
void
gweather_info_init (GWeatherInfo *info)
{
- info->priv = G_TYPE_INSTANCE_GET_PRIVATE (info, GWEATHER_TYPE_INFO, GWeatherInfoPrivate);
-
- gweather_info_reset (info);
-}
-
-void
-gweather_info_set_preferences (GWeatherInfo *info,
- const GWeatherPrefs *prefs)
-{
GWeatherInfoPrivate *priv;
- g_return_if_fail (GWEATHER_IS_INFO (info));
- g_return_if_fail (prefs != NULL);
-
- priv = info->priv;
-
- priv->temperature_unit = prefs->temperature_unit;
- priv->speed_unit = prefs->speed_unit;
- priv->pressure_unit = prefs->pressure_unit;
- priv->distance_unit = prefs->distance_unit;
+ priv = info->priv = G_TYPE_INSTANCE_GET_PRIVATE (info, GWEATHER_TYPE_INFO, GWeatherInfoPrivate);
- g_free (priv->radar_url);
- priv->radar_url = prefs->use_custom_radar_url && prefs->radar ?
- g_strdup (prefs->radar) : NULL;
+ priv->settings = g_settings_new ("org.gnome.GWeather");
+ priv->radar_url = g_settings_get_string (priv->settings, RADAR_KEY);
+ if (g_strcmp0 (priv->radar_url, "") == 0) {
+ g_free (priv->radar_url);
+ priv->radar_url = NULL;
+ }
- if (!priv->location)
- priv->location = _weather_location_clone (prefs->location);
+ gweather_info_reset (info);
}
void
@@ -632,7 +561,7 @@ gweather_info_finalize (GObject *object)
priv->radar = NULL;
}
- G_OBJECT_GET_CLASS (gweather_info_parent_class)->finalize (object);
+ G_OBJECT_CLASS (gweather_info_parent_class)->finalize (object);
}
gboolean
@@ -649,34 +578,6 @@ gweather_info_network_error (GWeatherInfo *info)
return info->priv->network_error;
}
-void
-gweather_info_to_metric (GWeatherInfo *info)
-{
- GWeatherInfoPrivate *priv;
-
- g_return_if_fail (GWEATHER_IS_INFO (info));
- priv = info->priv;
-
- priv->temperature_unit = TEMP_UNIT_CENTIGRADE;
- priv->speed_unit = SPEED_UNIT_MS;
- priv->pressure_unit = PRESSURE_UNIT_HPA;
- priv->distance_unit = DISTANCE_UNIT_METERS;
-}
-
-void
-gweather_info_to_imperial (GWeatherInfo *info)
-{
- GWeatherInfoPrivate *priv;
-
- g_return_if_fail (info != NULL);
- priv = info->priv;
-
- priv->temperature_unit = TEMP_UNIT_FAHRENHEIT;
- priv->speed_unit = SPEED_UNIT_MPH;
- priv->pressure_unit = PRESSURE_UNIT_INCH_HG;
- priv->distance_unit = DISTANCE_UNIT_MILES;
-}
-
const GWeatherLocation *
gweather_info_get_location (GWeatherInfo *info)
{
@@ -759,7 +660,7 @@ temperature_string (gfloat temp_f, GWeatherTemperatureUnit to_unit, gboolean wan
static gchar buf[100];
switch (to_unit) {
- case TEMP_UNIT_FAHRENHEIT:
+ case GWEATHER_TEMP_UNIT_FAHRENHEIT:
if (!want_round) {
/* TRANSLATOR: This is the temperature in degrees Fahrenheit (\302\260 is U+00B0 DEGREE SIGN) */
g_snprintf (buf, sizeof (buf), _("%.1f \302\260F"), temp_f);
@@ -768,7 +669,7 @@ temperature_string (gfloat temp_f, GWeatherTemperatureUnit to_unit, gboolean wan
g_snprintf (buf, sizeof (buf), _("%d \302\260F"), (int)floor (temp_f + 0.5));
}
break;
- case TEMP_UNIT_CENTIGRADE:
+ case GWEATHER_TEMP_UNIT_CENTIGRADE:
if (!want_round) {
/* TRANSLATOR: This is the temperature in degrees Celsius (\302\260 is U+00B0 DEGREE SIGN) */
g_snprintf (buf, sizeof (buf), _("%.1f \302\260C"), TEMP_F_TO_C (temp_f));
@@ -777,7 +678,7 @@ temperature_string (gfloat temp_f, GWeatherTemperatureUnit to_unit, gboolean wan
g_snprintf (buf, sizeof (buf), _("%d \302\260C"), (int)floor (TEMP_F_TO_C (temp_f) + 0.5));
}
break;
- case TEMP_UNIT_KELVIN:
+ case GWEATHER_TEMP_UNIT_KELVIN:
if (!want_round) {
/* TRANSLATOR: This is the temperature in kelvin */
g_snprintf (buf, sizeof (buf), _("%.1f K"), TEMP_F_TO_K (temp_f));
@@ -787,8 +688,8 @@ temperature_string (gfloat temp_f, GWeatherTemperatureUnit to_unit, gboolean wan
}
break;
- case TEMP_UNIT_INVALID:
- case TEMP_UNIT_DEFAULT:
+ case GWEATHER_TEMP_UNIT_INVALID:
+ case GWEATHER_TEMP_UNIT_DEFAULT:
default:
g_warning ("Conversion to illegal temperature unit: %d", to_unit);
return _("Unknown");
@@ -800,53 +701,65 @@ temperature_string (gfloat temp_f, GWeatherTemperatureUnit to_unit, gboolean wan
const gchar *
gweather_info_get_temp (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv;
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
+ priv = info->priv;
- if (!info->priv->valid)
+ if (!priv->valid)
return "-";
- if (info->priv->temp < -500.0)
+ if (priv->temp < -500.0)
return _("Unknown");
- return temperature_string (info->priv->temp, info->priv->temperature_unit, FALSE);
+ return temperature_string (priv->temp, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE);
}
const gchar *
gweather_info_get_temp_min (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv;
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
+ priv = info->priv;
- if (!info->priv->valid || !info->priv->tempMinMaxValid)
+ if (!priv->valid || !priv->tempMinMaxValid)
return "-";
- if (info->priv->temp_min < -500.0)
+ if (priv->temp_min < -500.0)
return _("Unknown");
- return temperature_string (info->priv->temp_min, info->priv->temperature_unit, FALSE);
+ return temperature_string (priv->temp_min, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE);
}
const gchar *
gweather_info_get_temp_max (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv;
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
+ priv = info->priv;
- if (!info->priv->valid || !info->priv->tempMinMaxValid)
+ if (!priv->valid || !priv->tempMinMaxValid)
return "-";
- if (info->priv->temp_max < -500.0)
+ if (priv->temp_max < -500.0)
return _("Unknown");
- return temperature_string (info->priv->temp_max, info->priv->temperature_unit, FALSE);
+ return temperature_string (priv->temp_max, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE);
}
const gchar *
gweather_info_get_dew (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv;
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
+ priv = info->priv;
- if (!info->priv->valid)
+ if (!priv->valid)
return "-";
- if (info->priv->dew < -500.0)
+ if (priv->dew < -500.0)
return _("Unknown");
- return temperature_string (info->priv->dew, info->priv->temperature_unit, FALSE);
+ return temperature_string (priv->dew, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE);
}
const gchar *
@@ -874,17 +787,20 @@ gweather_info_get_humidity (GWeatherInfo *info)
const gchar *
gweather_info_get_apparent (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv;
gdouble apparent;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- if (!info->priv->valid)
+ priv = info->priv;
+
+ if (!priv->valid)
return "-";
apparent = calc_apparent (info);
if (apparent < -500.0)
return _("Unknown");
- return temperature_string (apparent, info->priv->temperature_unit, FALSE);
+ return temperature_string (apparent, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE);
}
static const gchar *
@@ -893,31 +809,31 @@ windspeed_string (gfloat knots, GWeatherSpeedUnit to_unit)
static gchar buf[100];
switch (to_unit) {
- case SPEED_UNIT_KNOTS:
+ case GWEATHER_SPEED_UNIT_KNOTS:
/* TRANSLATOR: This is the wind speed in knots */
g_snprintf (buf, sizeof (buf), _("%0.1f knots"), knots);
break;
- case SPEED_UNIT_MPH:
+ case GWEATHER_SPEED_UNIT_MPH:
/* TRANSLATOR: This is the wind speed in miles per hour */
g_snprintf (buf, sizeof (buf), _("%.1f mph"), WINDSPEED_KNOTS_TO_MPH (knots));
break;
- case SPEED_UNIT_KPH:
+ case GWEATHER_SPEED_UNIT_KPH:
/* TRANSLATOR: This is the wind speed in kilometers per hour */
g_snprintf (buf, sizeof (buf), _("%.1f km/h"), WINDSPEED_KNOTS_TO_KPH (knots));
break;
- case SPEED_UNIT_MS:
+ case GWEATHER_SPEED_UNIT_MS:
/* TRANSLATOR: This is the wind speed in meters per second */
g_snprintf (buf, sizeof (buf), _("%.1f m/s"), WINDSPEED_KNOTS_TO_MS (knots));
break;
- case SPEED_UNIT_BFT:
+ case GWEATHER_SPEED_UNIT_BFT:
/* TRANSLATOR: This is the wind speed as a Beaufort force factor
* (commonly used in nautical wind estimation).
*/
g_snprintf (buf, sizeof (buf), _("Beaufort force %.1f"),
WINDSPEED_KNOTS_TO_BFT (knots));
break;
- case SPEED_UNIT_INVALID:
- case SPEED_UNIT_DEFAULT:
+ case GWEATHER_SPEED_UNIT_INVALID:
+ case GWEATHER_SPEED_UNIT_DEFAULT:
default:
g_warning ("Conversion to illegal speed unit: %d", to_unit);
return _("Unknown");
@@ -947,7 +863,7 @@ gweather_info_get_wind (GWeatherInfo *info)
/* TRANSLATOR: This is 'wind direction' / 'wind speed' */
g_snprintf (buf, sizeof (buf), _("%s / %s"),
gweather_wind_direction_to_string (priv->wind),
- windspeed_string (priv->windspeed, priv->speed_unit));
+ windspeed_string (priv->windspeed, g_settings_get_enum (priv->settings, SPEED_UNIT)));
}
return buf;
}
@@ -967,36 +883,36 @@ gweather_info_get_pressure (GWeatherInfo *info)
if (priv->pressure < 0.0)
return _("Unknown");
- switch (priv->pressure_unit) {
- case PRESSURE_UNIT_INCH_HG:
+ switch (g_settings_get_enum (priv->settings, PRESSURE_UNIT)) {
+ case GWEATHER_PRESSURE_UNIT_INCH_HG:
/* TRANSLATOR: This is pressure in inches of mercury */
g_snprintf (buf, sizeof (buf), _("%.2f inHg"), priv->pressure);
break;
- case PRESSURE_UNIT_MM_HG:
+ case GWEATHER_PRESSURE_UNIT_MM_HG:
/* TRANSLATOR: This is pressure in millimeters of mercury */
g_snprintf (buf, sizeof (buf), _("%.1f mmHg"), PRESSURE_INCH_TO_MM (priv->pressure));
break;
- case PRESSURE_UNIT_KPA:
+ case GWEATHER_PRESSURE_UNIT_KPA:
/* TRANSLATOR: This is pressure in kiloPascals */
g_snprintf (buf, sizeof (buf), _("%.2f kPa"), PRESSURE_INCH_TO_KPA (priv->pressure));
break;
- case PRESSURE_UNIT_HPA:
+ case GWEATHER_PRESSURE_UNIT_HPA:
/* TRANSLATOR: This is pressure in hectoPascals */
g_snprintf (buf, sizeof (buf), _("%.2f hPa"), PRESSURE_INCH_TO_HPA (priv->pressure));
break;
- case PRESSURE_UNIT_MB:
+ case GWEATHER_PRESSURE_UNIT_MB:
/* TRANSLATOR: This is pressure in millibars */
g_snprintf (buf, sizeof (buf), _("%.2f mb"), PRESSURE_INCH_TO_MB (priv->pressure));
break;
- case PRESSURE_UNIT_ATM:
+ case GWEATHER_PRESSURE_UNIT_ATM:
/* TRANSLATOR: This is pressure in atmospheres */
g_snprintf (buf, sizeof (buf), _("%.3f atm"), PRESSURE_INCH_TO_ATM (priv->pressure));
break;
- case PRESSURE_UNIT_INVALID:
- case PRESSURE_UNIT_DEFAULT:
+ case GWEATHER_PRESSURE_UNIT_INVALID:
+ case GWEATHER_PRESSURE_UNIT_DEFAULT:
default:
- g_warning ("Conversion to illegal pressure unit: %d", priv->pressure_unit);
+ g_warning ("Conversion to illegal pressure unit");
return _("Unknown");
}
@@ -1018,24 +934,24 @@ gweather_info_get_visibility (GWeatherInfo *info)
if (priv->visibility < 0.0)
return _("Unknown");
- switch (priv->distance_unit) {
- case DISTANCE_UNIT_MILES:
+ switch (g_settings_get_enum (priv->settings, DISTANCE_UNIT)) {
+ case GWEATHER_DISTANCE_UNIT_MILES:
/* TRANSLATOR: This is the visibility in miles */
g_snprintf (buf, sizeof (buf), _("%.1f miles"), priv->visibility);
break;
- case DISTANCE_UNIT_KM:
+ case GWEATHER_DISTANCE_UNIT_KM:
/* TRANSLATOR: This is the visibility in kilometers */
g_snprintf (buf, sizeof (buf), _("%.1f km"), VISIBILITY_SM_TO_KM (priv->visibility));
break;
- case DISTANCE_UNIT_METERS:
+ case GWEATHER_DISTANCE_UNIT_METERS:
/* TRANSLATOR: This is the visibility in meters */
g_snprintf (buf, sizeof (buf), _("%.0fm"), VISIBILITY_SM_TO_M (priv->visibility));
break;
- case DISTANCE_UNIT_INVALID:
- case DISTANCE_UNIT_DEFAULT:
+ case GWEATHER_DISTANCE_UNIT_INVALID:
+ case GWEATHER_DISTANCE_UNIT_DEFAULT:
default:
- g_warning ("Conversion to illegal visibility unit: %d", priv->pressure_unit);
+ g_warning ("Conversion to illegal visibility unit");
return _("Unknown");
}
@@ -1054,7 +970,7 @@ gweather_info_get_sunrise (GWeatherInfo *info)
priv = info->priv;
- if (!priv->location->coordinates)
+ if (!priv->location->latlon_valid)
return "-";
if (!priv->valid)
return "-";
@@ -1079,7 +995,7 @@ gweather_info_get_sunset (GWeatherInfo *info)
priv = info->priv;
- if (!priv->location->coordinates)
+ if (!priv->location->latlon_valid)
return "-";
if (!priv->valid)
return "-";
@@ -1147,7 +1063,7 @@ gweather_info_get_temp_summary (GWeatherInfo *info)
if (!priv->valid || priv->temp < -500.0)
return "--";
- return temperature_string (priv->temp, priv->temperature_unit, TRUE);
+ return temperature_string (priv->temp, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), TRUE);
}
/**
@@ -1196,45 +1112,45 @@ gweather_info_get_icon_name (GWeatherInfo *info)
sky = priv->sky;
if (cond.significant) {
- if (cond.phenomenon != PHENOMENON_NONE &&
- cond.qualifier == QUALIFIER_THUNDERSTORM)
+ if (cond.phenomenon != GWEATHER_PHENOMENON_NONE &&
+ cond.qualifier == GWEATHER_QUALIFIER_THUNDERSTORM)
return "weather-storm";
switch (cond.phenomenon) {
- case PHENOMENON_INVALID:
- case PHENOMENON_LAST:
- case PHENOMENON_NONE:
+ case GWEATHER_PHENOMENON_INVALID:
+ case GWEATHER_PHENOMENON_LAST:
+ case GWEATHER_PHENOMENON_NONE:
break;
- case PHENOMENON_DRIZZLE:
- case PHENOMENON_RAIN:
- case PHENOMENON_UNKNOWN_PRECIPITATION:
- case PHENOMENON_HAIL:
- case PHENOMENON_SMALL_HAIL:
+ case GWEATHER_PHENOMENON_DRIZZLE:
+ case GWEATHER_PHENOMENON_RAIN:
+ case GWEATHER_PHENOMENON_UNKNOWN_PRECIPITATION:
+ case GWEATHER_PHENOMENON_HAIL:
+ case GWEATHER_PHENOMENON_SMALL_HAIL:
return "weather-showers";
- case PHENOMENON_SNOW:
- case PHENOMENON_SNOW_GRAINS:
- case PHENOMENON_ICE_PELLETS:
- case PHENOMENON_ICE_CRYSTALS:
+ case GWEATHER_PHENOMENON_SNOW:
+ case GWEATHER_PHENOMENON_SNOW_GRAINS:
+ case GWEATHER_PHENOMENON_ICE_PELLETS:
+ case GWEATHER_PHENOMENON_ICE_CRYSTALS:
return "weather-snow";
- case PHENOMENON_TORNADO:
- case PHENOMENON_SQUALL:
+ case GWEATHER_PHENOMENON_TORNADO:
+ case GWEATHER_PHENOMENON_SQUALL:
return "weather-storm";
- case PHENOMENON_MIST:
- case PHENOMENON_FOG:
- case PHENOMENON_SMOKE:
- case PHENOMENON_VOLCANIC_ASH:
- case PHENOMENON_SAND:
- case PHENOMENON_HAZE:
- case PHENOMENON_SPRAY:
- case PHENOMENON_DUST:
- case PHENOMENON_SANDSTORM:
- case PHENOMENON_DUSTSTORM:
- case PHENOMENON_FUNNEL_CLOUD:
- case PHENOMENON_DUST_WHIRLS:
+ case GWEATHER_PHENOMENON_MIST:
+ case GWEATHER_PHENOMENON_FOG:
+ case GWEATHER_PHENOMENON_SMOKE:
+ case GWEATHER_PHENOMENON_VOLCANIC_ASH:
+ case GWEATHER_PHENOMENON_SAND:
+ case GWEATHER_PHENOMENON_HAZE:
+ case GWEATHER_PHENOMENON_SPRAY:
+ case GWEATHER_PHENOMENON_DUST:
+ case GWEATHER_PHENOMENON_SANDSTORM:
+ case GWEATHER_PHENOMENON_DUSTSTORM:
+ case GWEATHER_PHENOMENON_FUNNEL_CLOUD:
+ case GWEATHER_PHENOMENON_DUST_WHIRLS:
return "weather-fog";
}
}
@@ -1252,9 +1168,9 @@ gweather_info_get_icon_name (GWeatherInfo *info)
}
switch (sky) {
- case SKY_INVALID:
- case SKY_LAST:
- case SKY_CLEAR:
+ case GWEATHER_SKY_INVALID:
+ case GWEATHER_SKY_LAST:
+ case GWEATHER_SKY_CLEAR:
if (daytime)
return "weather-clear";
else {
@@ -1262,9 +1178,9 @@ gweather_info_get_icon_name (GWeatherInfo *info)
break;
}
- case SKY_BROKEN:
- case SKY_SCATTERED:
- case SKY_FEW:
+ case GWEATHER_SKY_BROKEN:
+ case GWEATHER_SKY_SCATTERED:
+ case GWEATHER_SKY_FEW:
if (daytime)
return "weather-few-clouds";
else {
@@ -1272,7 +1188,7 @@ gweather_info_get_icon_name (GWeatherInfo *info)
break;
}
- case SKY_OVERCAST:
+ case GWEATHER_SKY_OVERCAST:
return "weather-overcast";
default: /* unrecognized */
@@ -1316,7 +1232,7 @@ static gboolean
temperature_value (gdouble temp_f,
GWeatherTemperatureUnit to_unit,
gdouble *value,
- GWeatherTemperatureUnit def_unit)
+ GSettings *settings)
{
gboolean ok = TRUE;
@@ -1324,21 +1240,21 @@ temperature_value (gdouble temp_f,
if (temp_f < -500.0)
return FALSE;
- if (to_unit == TEMP_UNIT_DEFAULT)
- to_unit = def_unit;
+ if (to_unit == GWEATHER_TEMP_UNIT_DEFAULT)
+ to_unit = g_settings_get_enum (settings, TEMPERATURE_UNIT);
switch (to_unit) {
- case TEMP_UNIT_FAHRENHEIT:
+ case GWEATHER_TEMP_UNIT_FAHRENHEIT:
*value = temp_f;
break;
- case TEMP_UNIT_CENTIGRADE:
+ case GWEATHER_TEMP_UNIT_CENTIGRADE:
*value = TEMP_F_TO_C (temp_f);
break;
- case TEMP_UNIT_KELVIN:
+ case GWEATHER_TEMP_UNIT_KELVIN:
*value = TEMP_F_TO_K (temp_f);
break;
- case TEMP_UNIT_INVALID:
- case TEMP_UNIT_DEFAULT:
+ case GWEATHER_TEMP_UNIT_INVALID:
+ case GWEATHER_TEMP_UNIT_DEFAULT:
default:
ok = FALSE;
break;
@@ -1348,7 +1264,10 @@ temperature_value (gdouble temp_f,
}
static gboolean
-speed_value (gdouble knots, GWeatherSpeedUnit to_unit, gdouble *value, GWeatherSpeedUnit def_unit)
+speed_value (gdouble knots,
+ GWeatherSpeedUnit to_unit,
+ gdouble *value,
+ GSettings *settings)
{
gboolean ok = TRUE;
@@ -1357,27 +1276,27 @@ speed_value (gdouble knots, GWeatherSpeedUnit to_unit, gdouble *value, GWeatherS
if (knots < 0.0)
return FALSE;
- if (to_unit == SPEED_UNIT_DEFAULT)
- to_unit = def_unit;
+ if (to_unit == GWEATHER_SPEED_UNIT_DEFAULT)
+ to_unit = g_settings_get_enum (settings, SPEED_UNIT);
switch (to_unit) {
- case SPEED_UNIT_KNOTS:
+ case GWEATHER_SPEED_UNIT_KNOTS:
*value = knots;
break;
- case SPEED_UNIT_MPH:
+ case GWEATHER_SPEED_UNIT_MPH:
*value = WINDSPEED_KNOTS_TO_MPH (knots);
break;
- case SPEED_UNIT_KPH:
+ case GWEATHER_SPEED_UNIT_KPH:
*value = WINDSPEED_KNOTS_TO_KPH (knots);
break;
- case SPEED_UNIT_MS:
+ case GWEATHER_SPEED_UNIT_MS:
*value = WINDSPEED_KNOTS_TO_MS (knots);
break;
- case SPEED_UNIT_BFT:
+ case GWEATHER_SPEED_UNIT_BFT:
*value = WINDSPEED_KNOTS_TO_BFT (knots);
break;
- case SPEED_UNIT_INVALID:
- case SPEED_UNIT_DEFAULT:
+ case GWEATHER_SPEED_UNIT_INVALID:
+ case GWEATHER_SPEED_UNIT_DEFAULT:
default:
ok = FALSE;
break;
@@ -1387,7 +1306,10 @@ speed_value (gdouble knots, GWeatherSpeedUnit to_unit, gdouble *value, GWeatherS
}
static gboolean
-pressure_value (gdouble inHg, GWeatherPressureUnit to_unit, gdouble *value, GWeatherPressureUnit def_unit)
+pressure_value (gdouble inHg,
+ GWeatherPressureUnit to_unit,
+ gdouble *value,
+ GSettings *settings)
{
gboolean ok = TRUE;
@@ -1396,30 +1318,30 @@ pressure_value (gdouble inHg, GWeatherPressureUnit to_unit, gdouble *value, GWea
if (inHg < 0.0)
return FALSE;
- if (to_unit == PRESSURE_UNIT_DEFAULT)
- to_unit = def_unit;
+ if (to_unit == GWEATHER_PRESSURE_UNIT_DEFAULT)
+ to_unit = g_settings_get_enum (settings, PRESSURE_UNIT);
switch (to_unit) {
- case PRESSURE_UNIT_INCH_HG:
+ case GWEATHER_PRESSURE_UNIT_INCH_HG:
*value = inHg;
break;
- case PRESSURE_UNIT_MM_HG:
+ case GWEATHER_PRESSURE_UNIT_MM_HG:
*value = PRESSURE_INCH_TO_MM (inHg);
break;
- case PRESSURE_UNIT_KPA:
+ case GWEATHER_PRESSURE_UNIT_KPA:
*value = PRESSURE_INCH_TO_KPA (inHg);
break;
- case PRESSURE_UNIT_HPA:
+ case GWEATHER_PRESSURE_UNIT_HPA:
*value = PRESSURE_INCH_TO_HPA (inHg);
break;
- case PRESSURE_UNIT_MB:
+ case GWEATHER_PRESSURE_UNIT_MB:
*value = PRESSURE_INCH_TO_MB (inHg);
break;
- case PRESSURE_UNIT_ATM:
+ case GWEATHER_PRESSURE_UNIT_ATM:
*value = PRESSURE_INCH_TO_ATM (inHg);
break;
- case PRESSURE_UNIT_INVALID:
- case PRESSURE_UNIT_DEFAULT:
+ case GWEATHER_PRESSURE_UNIT_INVALID:
+ case GWEATHER_PRESSURE_UNIT_DEFAULT:
default:
ok = FALSE;
break;
@@ -1429,7 +1351,10 @@ pressure_value (gdouble inHg, GWeatherPressureUnit to_unit, gdouble *value, GWea
}
static gboolean
-distance_value (gdouble miles, GWeatherDistanceUnit to_unit, gdouble *value, GWeatherDistanceUnit def_unit)
+distance_value (gdouble miles,
+ GWeatherDistanceUnit to_unit,
+ gdouble *value,
+ GSettings *settings)
{
gboolean ok = TRUE;
@@ -1438,21 +1363,21 @@ distance_value (gdouble miles, GWeatherDistanceUnit to_unit, gdouble *value, GWe
if (miles < 0.0)
return FALSE;
- if (to_unit == DISTANCE_UNIT_DEFAULT)
- to_unit = def_unit;
+ if (to_unit == GWEATHER_DISTANCE_UNIT_DEFAULT)
+ to_unit = g_settings_get_enum (settings, DISTANCE_UNIT);
switch (to_unit) {
- case DISTANCE_UNIT_MILES:
+ case GWEATHER_DISTANCE_UNIT_MILES:
*value = miles;
break;
- case DISTANCE_UNIT_KM:
+ case GWEATHER_DISTANCE_UNIT_KM:
*value = VISIBILITY_SM_TO_KM (miles);
break;
- case DISTANCE_UNIT_METERS:
+ case GWEATHER_DISTANCE_UNIT_METERS:
*value = VISIBILITY_SM_TO_M (miles);
break;
- case DISTANCE_UNIT_INVALID:
- case DISTANCE_UNIT_DEFAULT:
+ case GWEATHER_DISTANCE_UNIT_INVALID:
+ case GWEATHER_DISTANCE_UNIT_DEFAULT:
default:
ok = FALSE;
break;
@@ -1478,7 +1403,7 @@ gweather_info_get_value_sky (GWeatherInfo *info, GWeatherSky *sky)
if (!info->priv->valid)
return FALSE;
- if (info->priv->sky <= SKY_INVALID || info->priv->sky >= SKY_LAST)
+ if (info->priv->sky <= GWEATHER_SKY_INVALID || info->priv->sky >= GWEATHER_SKY_LAST)
return FALSE;
*sky = info->priv->sky;
@@ -1512,10 +1437,10 @@ gweather_info_get_value_conditions (GWeatherInfo *info, GWeatherConditionPhenome
if (!priv->cond.significant)
return FALSE;
- if (!(priv->cond.phenomenon > PHENOMENON_INVALID &&
- priv->cond.phenomenon < PHENOMENON_LAST &&
- priv->cond.qualifier > QUALIFIER_INVALID &&
- priv->cond.qualifier < QUALIFIER_LAST))
+ if (!(priv->cond.phenomenon > GWEATHER_PHENOMENON_INVALID &&
+ priv->cond.phenomenon < GWEATHER_PHENOMENON_LAST &&
+ priv->cond.qualifier > GWEATHER_QUALIFIER_INVALID &&
+ priv->cond.qualifier < GWEATHER_QUALIFIER_LAST))
return FALSE;
*phenomenon = priv->cond.phenomenon;
@@ -1541,7 +1466,7 @@ gweather_info_get_value_temp (GWeatherInfo *info, GWeatherTemperatureUnit unit,
if (!info->priv->valid)
return FALSE;
- return temperature_value (info->priv->temp, unit, value, info->priv->temperature_unit);
+ return temperature_value (info->priv->temp, unit, value, info->priv->settings);
}
/**
@@ -1555,13 +1480,17 @@ gweather_info_get_value_temp (GWeatherInfo *info, GWeatherTemperatureUnit unit,
gboolean
gweather_info_get_value_temp_min (GWeatherInfo *info, GWeatherTemperatureUnit unit, gdouble *value)
{
+ GWeatherInfoPrivate *priv;
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- if (!info->priv->valid || !info->priv->tempMinMaxValid)
+ priv = info->priv;
+
+ if (!priv->valid || !priv->tempMinMaxValid)
return FALSE;
- return temperature_value (info->priv->temp_min, unit, value, info->priv->temperature_unit);
+ return temperature_value (priv->temp_min, unit, value, priv->settings);
}
/**
@@ -1575,13 +1504,17 @@ gweather_info_get_value_temp_min (GWeatherInfo *info, GWeatherTemperatureUnit un
gboolean
gweather_info_get_value_temp_max (GWeatherInfo *info, GWeatherTemperatureUnit unit, gdouble *value)
{
+ GWeatherInfoPrivate *priv;
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- if (!info->priv->valid || !info->priv->tempMinMaxValid)
+ priv = info->priv;
+
+ if (!priv->valid || !priv->tempMinMaxValid)
return FALSE;
- return temperature_value (info->priv->temp_max, unit, value, info->priv->temperature_unit);
+ return temperature_value (priv->temp_max, unit, value, priv->settings);
}
/**
@@ -1601,7 +1534,7 @@ gweather_info_get_value_dew (GWeatherInfo *info, GWeatherTemperatureUnit unit, g
if (!info->priv->valid)
return FALSE;
- return temperature_value (info->priv->dew, unit, value, info->priv->temperature_unit);
+ return temperature_value (info->priv->dew, unit, value, info->priv->settings);
}
/**
@@ -1621,7 +1554,7 @@ gweather_info_get_value_apparent (GWeatherInfo *info, GWeatherTemperatureUnit un
if (!info->priv->valid)
return FALSE;
- return temperature_value (calc_apparent (info), unit, value, info->priv->temperature_unit);
+ return temperature_value (calc_apparent (info), unit, value, info->priv->settings);
}
/**
@@ -1740,10 +1673,10 @@ gweather_info_get_value_wind (GWeatherInfo *info,
if (!priv->valid)
return FALSE;
- if (priv->windspeed < 0.0 || priv->wind <= WIND_INVALID || priv->wind >= WIND_LAST)
+ if (priv->windspeed < 0.0 || priv->wind <= GWEATHER_WIND_INVALID || priv->wind >= GWEATHER_WIND_LAST)
return FALSE;
- res = speed_value (priv->windspeed, unit, speed, priv->speed_unit);
+ res = speed_value (priv->windspeed, unit, speed, priv->settings);
*direction = priv->wind;
return res;
@@ -1768,7 +1701,7 @@ gweather_info_get_value_pressure (GWeatherInfo *info,
if (!info->priv->valid)
return FALSE;
- return pressure_value (info->priv->pressure, unit, value, info->priv->pressure_unit);
+ return pressure_value (info->priv->pressure, unit, value, info->priv->settings);
}
/**
@@ -1790,7 +1723,7 @@ gweather_info_get_value_visibility (GWeatherInfo *info,
if (!info->priv->valid)
return FALSE;
- return distance_value (info->priv->visibility, unit, value, info->priv->distance_unit);
+ return distance_value (info->priv->visibility, unit, value, info->priv->settings);
}
/**
@@ -1815,10 +1748,68 @@ gweather_info_get_upcoming_moonphases (GWeatherInfo *info, time_t *phases)
static void
_weather_internal_check (void)
{
- g_assert (G_N_ELEMENTS (wind_direction_str) == WIND_LAST);
- g_assert (G_N_ELEMENTS (sky_str) == SKY_LAST);
- g_assert (G_N_ELEMENTS (conditions_str) == PHENOMENON_LAST);
- g_assert (G_N_ELEMENTS (conditions_str[0]) == QUALIFIER_LAST);
+ g_assert (G_N_ELEMENTS (wind_direction_str) == GWEATHER_WIND_LAST);
+ g_assert (G_N_ELEMENTS (sky_str) == GWEATHER_SKY_LAST);
+ g_assert (G_N_ELEMENTS (conditions_str) == GWEATHER_PHENOMENON_LAST);
+ g_assert (G_N_ELEMENTS (conditions_str[0]) == GWEATHER_QUALIFIER_LAST);
+}
+
+static void
+gweather_info_set_location_internal (GWeatherInfo *info,
+ GWeatherLocation *location)
+{
+ GWeatherInfoPrivate *priv = info->priv;
+ GVariant *default_loc = NULL;
+ const gchar *name = NULL;
+ gboolean latlon_override = FALSE;
+ gdouble lat, lon;
+
+ if (priv->glocation)
+ gweather_location_unref (priv->glocation);
+ if (priv->location)
+ _weather_location_free (priv->location);
+
+ priv->glocation = location;
+ if (priv->glocation) {
+ gweather_location_ref (location);
+ } else {
+ GVariant *default_loc = g_settings_get_value (priv->settings, DEFAULT_LOCATION);
+ const gchar *station_code;
+
+ g_variant_get (default_loc, "(&s&sm(dd))", &name, &station_code, &latlon_override, &lat, &lon);
+
+ if (strcmp(name, "") == 0)
+ name = NULL;
+
+ priv->glocation = gweather_location_find_by_station_code (station_code);
+ }
+
+ priv->location = _weather_location_from_gweather_location (priv->glocation, name);
+
+ if (latlon_override) {
+ priv->location->latitude = DEGREES_TO_RADIANS (lat);
+ priv->location->longitude = DEGREES_TO_RADIANS (lon);
+ }
+
+ if (default_loc)
+ g_variant_unref (default_loc);
+}
+
+/**
+ * gweather_info_set_location:
+ * @info: a #GWeatherInfo
+ * @location: (allow-none): a location for which weather is desired
+ *
+ * Changes @info to report weather for @location.
+ */
+void
+gweather_info_set_location (GWeatherInfo *info,
+ GWeatherLocation *location)
+{
+ g_return_if_fail (GWEATHER_IS_INFO (info));
+
+ gweather_info_set_location_internal (info, location);
+ gweather_info_update (info);
}
static void
@@ -1832,15 +1823,10 @@ gweather_info_set_property (GObject *object,
switch (property_id) {
case PROP_LOCATION:
- priv->glocation = (GWeatherLocation *) g_value_dup_boxed (value);
- if (priv->glocation)
- priv->location = _weather_location_from_gweather_location (priv->glocation, NULL);
- break;
- case PROP_PREFS:
- gweather_info_set_preferences (self, (const GWeatherPrefs *) g_value_get_pointer (value));
+ gweather_info_set_location_internal (self, (GWeatherLocation*) g_value_get_boxed (value));
break;
case PROP_TYPE:
- priv->forecast_type = g_value_get_int (value);
+ priv->forecast_type = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -1865,19 +1851,12 @@ gweather_info_class_init (GWeatherInfoClass *klass)
G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (gobject_class, PROP_LOCATION, pspec);
- /* FIXME: make this a boxed */
- pspec = g_param_spec_pointer ("preferences",
- "Preferences",
- "The preferences and defaults used by this info",
- G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE);
- g_object_class_install_property (gobject_class, PROP_PREFS, pspec);
-
- /* FIXME: glib-mkenums hangs when I add weather.h to the list of enums */
- pspec = g_param_spec_int ("forecast-type",
- "Forecast type",
- "The type of forecast desired (list, zone or state)",
- 0, 3, FORECAST_LIST,
- G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
+ pspec = g_param_spec_enum ("forecast-type",
+ "Forecast type",
+ "The type of forecast desired (list, zone or state)",
+ GWEATHER_TYPE_FORECAST_TYPE,
+ GWEATHER_FORECAST_LIST,
+ G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (gobject_class, PROP_TYPE, pspec);
gweather_info_signals[SIGNAL_UPDATED] = g_signal_new ("updated",
@@ -1894,23 +1873,19 @@ gweather_info_class_init (GWeatherInfoClass *klass)
* gweather_info_new:
* @location: (allow-none): the desidered #GWeatherLocation (NULL for default)
* @forecast_type: the type of forecast requested
- * @prefs: an object providing defaults for units, radars, etc.
*
* Returns: (transfer full): a new #GWeatherInfo
*/
GWeatherInfo *
gweather_info_new (GWeatherLocation *location,
- GWeatherForecastType forecast_type,
- const GWeatherPrefs *prefs)
+ GWeatherForecastType forecast_type)
{
GWeatherInfo *self;
- g_return_val_if_fail (prefs != NULL, NULL);
-
if (location != NULL)
- self = g_object_new (GWEATHER_TYPE_INFO, "location", location, "forecast-type", forecast_type, "preferences", prefs, NULL);
+ self = g_object_new (GWEATHER_TYPE_INFO, "location", location, "forecast-type", forecast_type, NULL);
else
- self = g_object_new (GWEATHER_TYPE_INFO, "forecast-type", forecast_type, "preferences", prefs, NULL);
+ self = g_object_new (GWEATHER_TYPE_INFO, "forecast-type", forecast_type, NULL);
gweather_info_update (self);
return self;
@@ -1919,16 +1894,5 @@ gweather_info_new (GWeatherLocation *location,
GWeatherInfo *
_gweather_info_new_clone (GWeatherInfo *other)
{
- GWeatherInfoPrivate *priv;
- GWeatherPrefs prefs;
-
- priv = other->priv;
- prefs.temperature_unit = priv->temperature_unit;
- prefs.speed_unit = priv->speed_unit;
- prefs.distance_unit = priv->distance_unit;
- prefs.pressure_unit = priv->pressure_unit;
- prefs.use_custom_radar_url = priv->radar_url != NULL;
- prefs.radar = priv->radar_url;
-
- return g_object_new (GWEATHER_TYPE_INFO, "location", priv->glocation, "type", priv->forecast_type, "preferences", &prefs, NULL);
+ return g_object_new (GWEATHER_TYPE_INFO, "location", other->priv->glocation, "forecast-type", other->priv->forecast_type, NULL);
}
diff --git a/libgweather/weather.h b/libgweather/weather.h
index 1ec47e8..545bfb9 100644
--- a/libgweather/weather.h
+++ b/libgweather/weather.h
@@ -19,84 +19,17 @@
#ifndef __WEATHER_H_
#define __WEATHER_H_
-
#ifndef GWEATHER_I_KNOW_THIS_IS_UNSTABLE
#error "libgweather 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"
#endif
#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <libgweather/gweather-enums.h>
#include <libgweather/gweather-location.h>
G_BEGIN_DECLS
-/*
- * Weather prefs
- */
-
-typedef enum _GWeatherForecastType {
- FORECAST_STATE,
- FORECAST_ZONE,
- FORECAST_LIST
-} GWeatherForecastType;
-
-typedef enum _GWeatherTempeatureUnit {
- TEMP_UNIT_INVALID = 0,
- TEMP_UNIT_DEFAULT,
- TEMP_UNIT_KELVIN,
- TEMP_UNIT_CENTIGRADE,
- TEMP_UNIT_FAHRENHEIT
-} GWeatherTemperatureUnit;
-
-typedef enum _GWeatherSpeedUnit {
- SPEED_UNIT_INVALID = 0,
- SPEED_UNIT_DEFAULT,
- SPEED_UNIT_MS, /* metres per second */
- SPEED_UNIT_KPH, /* kilometres per hour */
- SPEED_UNIT_MPH, /* miles per hour */
- SPEED_UNIT_KNOTS, /* Knots */
- SPEED_UNIT_BFT /* Beaufort scale */
-} GWeatherSpeedUnit;
-
-typedef enum _GWeatherPressureUnit {
- PRESSURE_UNIT_INVALID = 0,
- PRESSURE_UNIT_DEFAULT,
- PRESSURE_UNIT_KPA, /* kiloPascal */
- PRESSURE_UNIT_HPA, /* hectoPascal */
- PRESSURE_UNIT_MB, /* 1 millibars = 1 hectoPascal */
- PRESSURE_UNIT_MM_HG, /* millimeters of mecury */
- PRESSURE_UNIT_INCH_HG, /* inches of mercury */
- PRESSURE_UNIT_ATM /* atmosphere */
-} GWeatherPressureUnit;
-
-typedef enum _GWeatherDistanceUnit {
- DISTANCE_UNIT_INVALID = 0,
- DISTANCE_UNIT_DEFAULT,
- DISTANCE_UNIT_METERS,
- DISTANCE_UNIT_KM,
- DISTANCE_UNIT_MILES
-} GWeatherDistanceUnit;
-
-#if 0
-struct _GWeatherPrefs {
- GWeatherForecastType type;
-
- gboolean radar;
- const char *radar_custom_url;
-
- GWeatherTemperatureUnit temperature_unit;
- GWeatherSpeedUnit speed_unit;
- GWeatherPressureUnit pressure_unit;
- GWeatherDistanceUnit distance_unit;
-};
-#endif
-
-typedef struct _GWeatherPrefs GWeatherPrefs;
-
-/*
- * Weather Info
- */
-
typedef struct _GWeatherInfo GWeatherInfo;
typedef struct _GWeatherInfoClass GWeatherInfoClass;
typedef struct _GWeatherInfoPrivate GWeatherInfoPrivate;
@@ -127,20 +60,16 @@ typedef void (*GWeatherInfoFunc) (GWeatherInfo *info, gpointer data);
GType gweather_info_get_type (void) G_GNUC_CONST;
GWeatherInfo * gweather_info_new (GWeatherLocation *location,
- GWeatherForecastType forecast_type,
- const GWeatherPrefs *prefs);
-void gweather_info_set_preferences (GWeatherInfo *info,
- const GWeatherPrefs *prefs);
+ GWeatherForecastType forecast_type);
void gweather_info_update (GWeatherInfo *info);
void gweather_info_abort (GWeatherInfo *info);
gboolean gweather_info_is_valid (GWeatherInfo *info);
gboolean gweather_info_network_error (GWeatherInfo *info);
-void gweather_info_to_metric (GWeatherInfo *info);
-void gweather_info_to_imperial (GWeatherInfo *info);
-
const GWeatherLocation * gweather_info_get_location (GWeatherInfo *info);
+void gweather_info_set_location (GWeatherInfo *info,
+ GWeatherLocation *location);
const gchar * gweather_info_get_location_name (GWeatherInfo *info);
const gchar * gweather_info_get_update (GWeatherInfo *info);
const gchar * gweather_info_get_sky (GWeatherInfo *info);
@@ -169,83 +98,83 @@ gint gweather_info_next_sun_event (GWeatherInfo *info);
/* values retrieving functions */
typedef enum _GWeatherWindDirection {
- WIND_INVALID = -1,
- WIND_VARIABLE,
- WIND_N, WIND_NNE, WIND_NE, WIND_ENE,
- WIND_E, WIND_ESE, WIND_SE, WIND_SSE,
- WIND_S, WIND_SSW, WIND_SW, WIND_WSW,
- WIND_W, WIND_WNW, WIND_NW, WIND_NNW,
- WIND_LAST
+ GWEATHER_WIND_INVALID = -1,
+ GWEATHER_WIND_VARIABLE,
+ GWEATHER_WIND_N, GWEATHER_WIND_NNE, GWEATHER_WIND_NE, GWEATHER_WIND_ENE,
+ GWEATHER_WIND_E, GWEATHER_WIND_ESE, GWEATHER_WIND_SE, GWEATHER_WIND_SSE,
+ GWEATHER_WIND_S, GWEATHER_WIND_SSW, GWEATHER_WIND_SW, GWEATHER_WIND_WSW,
+ GWEATHER_WIND_W, GWEATHER_WIND_WNW, GWEATHER_WIND_NW, GWEATHER_WIND_NNW,
+ GWEATHER_WIND_LAST
} GWeatherWindDirection;
const gchar * gweather_wind_direction_to_string (GWeatherWindDirection wind);
typedef enum _GWeatherSky {
- SKY_INVALID = -1,
- SKY_CLEAR,
- SKY_BROKEN,
- SKY_SCATTERED,
- SKY_FEW,
- SKY_OVERCAST,
- SKY_LAST
+ GWEATHER_SKY_INVALID = -1,
+ GWEATHER_SKY_CLEAR,
+ GWEATHER_SKY_BROKEN,
+ GWEATHER_SKY_SCATTERED,
+ GWEATHER_SKY_FEW,
+ GWEATHER_SKY_OVERCAST,
+ GWEATHER_SKY_LAST
} GWeatherSky;
const gchar * gweather_sky_to_string (GWeatherSky sky);
typedef enum _GWeatherConditionPhenomenon {
- PHENOMENON_INVALID = -1,
-
- PHENOMENON_NONE,
-
- PHENOMENON_DRIZZLE,
- PHENOMENON_RAIN,
- PHENOMENON_SNOW,
- PHENOMENON_SNOW_GRAINS,
- PHENOMENON_ICE_CRYSTALS,
- PHENOMENON_ICE_PELLETS,
- PHENOMENON_HAIL,
- PHENOMENON_SMALL_HAIL,
- PHENOMENON_UNKNOWN_PRECIPITATION,
-
- PHENOMENON_MIST,
- PHENOMENON_FOG,
- PHENOMENON_SMOKE,
- PHENOMENON_VOLCANIC_ASH,
- PHENOMENON_SAND,
- PHENOMENON_HAZE,
- PHENOMENON_SPRAY,
- PHENOMENON_DUST,
-
- PHENOMENON_SQUALL,
- PHENOMENON_SANDSTORM,
- PHENOMENON_DUSTSTORM,
- PHENOMENON_FUNNEL_CLOUD,
- PHENOMENON_TORNADO,
- PHENOMENON_DUST_WHIRLS,
-
- PHENOMENON_LAST
+ GWEATHER_PHENOMENON_INVALID = -1,
+
+ GWEATHER_PHENOMENON_NONE,
+
+ GWEATHER_PHENOMENON_DRIZZLE,
+ GWEATHER_PHENOMENON_RAIN,
+ GWEATHER_PHENOMENON_SNOW,
+ GWEATHER_PHENOMENON_SNOW_GRAINS,
+ GWEATHER_PHENOMENON_ICE_CRYSTALS,
+ GWEATHER_PHENOMENON_ICE_PELLETS,
+ GWEATHER_PHENOMENON_HAIL,
+ GWEATHER_PHENOMENON_SMALL_HAIL,
+ GWEATHER_PHENOMENON_UNKNOWN_PRECIPITATION,
+
+ GWEATHER_PHENOMENON_MIST,
+ GWEATHER_PHENOMENON_FOG,
+ GWEATHER_PHENOMENON_SMOKE,
+ GWEATHER_PHENOMENON_VOLCANIC_ASH,
+ GWEATHER_PHENOMENON_SAND,
+ GWEATHER_PHENOMENON_HAZE,
+ GWEATHER_PHENOMENON_SPRAY,
+ GWEATHER_PHENOMENON_DUST,
+
+ GWEATHER_PHENOMENON_SQUALL,
+ GWEATHER_PHENOMENON_SANDSTORM,
+ GWEATHER_PHENOMENON_DUSTSTORM,
+ GWEATHER_PHENOMENON_FUNNEL_CLOUD,
+ GWEATHER_PHENOMENON_TORNADO,
+ GWEATHER_PHENOMENON_DUST_WHIRLS,
+
+ GWEATHER_PHENOMENON_LAST
} GWeatherConditionPhenomenon;
typedef enum _GWeatherConditionQualifier {
- QUALIFIER_INVALID = -1,
+ GWEATHER_QUALIFIER_INVALID = -1,
- QUALIFIER_NONE,
+ GWEATHER_QUALIFIER_NONE,
- QUALIFIER_VICINITY,
+ GWEATHER_QUALIFIER_VICINITY,
- QUALIFIER_LIGHT,
- QUALIFIER_MODERATE,
- QUALIFIER_HEAVY,
- QUALIFIER_SHALLOW,
- QUALIFIER_PATCHES,
- QUALIFIER_PARTIAL,
- QUALIFIER_THUNDERSTORM,
- QUALIFIER_BLOWING,
- QUALIFIER_SHOWERS,
- QUALIFIER_DRIFTING,
- QUALIFIER_FREEZING,
+ GWEATHER_QUALIFIER_LIGHT,
+ GWEATHER_QUALIFIER_MODERATE,
+ GWEATHER_QUALIFIER_HEAVY,
+ GWEATHER_QUALIFIER_SHALLOW,
+ GWEATHER_QUALIFIER_PATCHES,
+ GWEATHER_QUALIFIER_PARTIAL,
+ GWEATHER_QUALIFIER_THUNDERSTORM,
+ GWEATHER_QUALIFIER_BLOWING,
+ GWEATHER_QUALIFIER_SHOWERS,
+ GWEATHER_QUALIFIER_DRIFTING,
+ GWEATHER_QUALIFIER_FREEZING,
- QUALIFIER_LAST
+ GWEATHER_QUALIFIER_LAST
} GWeatherConditionQualifier;
typedef gdouble GWeatherMoonPhase;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4aa2bf5..747299f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,13 +2,11 @@
# Please keep this file sorted alphabetically.
#
[encoding: UTF-8]
-libgweather/gweather-gconf.c
-libgweather/gweather-prefs.c
libgweather/gweather-timezone.c
-libgweather/gweather.schemas.in
libgweather/timezone-menu.c
libgweather/weather-iwin.c
libgweather/weather-metar.c
libgweather/weather-wx.c
libgweather/weather.c
+data/org.gnome.GWeather.gschema.xml.in