diff options
author | Stefano Karapetsas <[email protected]> | 2012-09-04 16:57:10 +0200 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2012-09-04 16:57:10 +0200 |
commit | 44b85ff8d08023f49be431f1a8514240b9b4b276 (patch) | |
tree | 637ef9c57a778e3e7e0fb45fcb3248c49a375733 /libmateweather | |
parent | 9f6a41dc0563e92cb59609aa3dcc8b9d42d1d40b (diff) | |
download | libmateweather-44b85ff8d08023f49be431f1a8514240b9b4b276.tar.bz2 libmateweather-44b85ff8d08023f49be431f1a8514240b9b4b276.tar.xz |
migrate to gsettings
Diffstat (limited to 'libmateweather')
-rw-r--r-- | libmateweather/Makefile.am | 29 | ||||
-rw-r--r-- | libmateweather/mateweather-mateconf.c | 310 | ||||
-rw-r--r-- | libmateweather/mateweather-mateconf.h | 84 | ||||
-rw-r--r-- | libmateweather/mateweather-prefs.c | 370 | ||||
-rw-r--r-- | libmateweather/mateweather-prefs.h | 32 | ||||
-rw-r--r-- | libmateweather/mateweather-uninstalled.pc.in | 2 | ||||
-rw-r--r-- | libmateweather/mateweather.pc.in | 2 | ||||
-rw-r--r-- | libmateweather/mateweather.schemas.in | 173 | ||||
-rw-r--r-- | libmateweather/org.mate.weather.gschema.xml | 121 |
9 files changed, 163 insertions, 960 deletions
diff --git a/libmateweather/Makefile.am b/libmateweather/Makefile.am index 8502708..41a35fe 100644 --- a/libmateweather/Makefile.am +++ b/libmateweather/Makefile.am @@ -2,7 +2,7 @@ lib_LTLIBRARIES = libmateweather.la libmateweatherincdir = $(includedir)/libmateweather mateweather_old_headers = \ - weather.h mateweather-mateconf.h mateweather-prefs.h mateweather-xml.h + weather.h mateweather-prefs.h mateweather-xml.h mateweather_new_headers = \ mateweather-location.h location-entry.h \ mateweather-timezone.h timezone-menu.h @@ -21,7 +21,6 @@ libmateweather_la_SOURCES = \ weather-sun.c weather-moon.c \ mateweather-enum-types.c \ mateweather-prefs.c mateweather-prefs.h \ - mateweather-mateconf.c mateweather-mateconf.h \ mateweather-xml.c mateweather-xml.h \ mateweather-location.c mateweather-location.h \ mateweather-timezone.c mateweather-timezone.h \ @@ -43,7 +42,7 @@ libmateweather_la_CFLAGS = \ $(GTK_CFLAGS) \ $(LIBXML_CFLAGS) \ $(LIBSOUP_CFLAGS) \ - $(MATECONF_CFLAGS) \ + $(GIO_CFLAGS) \ -DG_LOG_DOMAIN=\"MateWeather\" \ -DMATELOCALEDIR=\""$(datadir)/locale"\" \ -DMATEWEATHER_XML_LOCATION_DIR=\""$(pkgdatadir)"\" @@ -53,7 +52,7 @@ libmateweather_la_LIBADD = \ $(GTK_LIBS) \ $(LIBXML_LIBS) \ $(LIBSOUP_LIBS) \ - $(MATECONF_LIBS) \ + $(GIO_LIBS) \ $(REGEX_LIBS) libmateweather_la_LDFLAGS = \ @@ -123,26 +122,10 @@ test_sun_moon_LDADD = \ noinst_HEADERS = weather-priv.h mateweather-win32.h noinst_PROGRAMS = test_metar test_locations test_sun_moon -schemadir = @MATECONF_SCHEMA_FILE_DIR@ -schema_in_files = mateweather.schemas.in -schema_DATA = $(schema_in_files:.schemas.in=.schemas) - -@INTLTOOL_SCHEMAS_RULE@ - -if MATECONF_SCHEMAS_INSTALL -install-data-local: - if test -z "$(DESTDIR)" ; then \ - for p in $(schema_DATA) ; do \ - MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-install-rule $$p ; \ - done \ - fi -uninstall-local: - for p in $(schema_DATA) ; do \ - MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-uninstall-rule $$p ; \ - done -endif +gsettings_SCHEMAS = org.mate.weather.gschema.xml +@GSETTINGS_RULES@ -EXTRA_DIST = mateweather.pc.in mateweather-uninstalled.pc.in $(schema_in_files) +EXTRA_DIST = mateweather.pc.in mateweather-uninstalled.pc.in $(gsettings_SCHEMAS) EXTRA_PROGRAMS = test_metar test_sun_moon diff --git a/libmateweather/mateweather-mateconf.c b/libmateweather/mateweather-mateconf.c deleted file mode 100644 index f8f6f1b..0000000 --- a/libmateweather/mateweather-mateconf.c +++ /dev/null @@ -1,310 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * mateweather-mateconf.c: MateConf interaction methods for mateweather. - * - * 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 <[email protected]> - * Papadimitriou Spiros <[email protected]> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#define MATEWEATHER_I_KNOW_THIS_IS_UNSTABLE -#include "mateweather-mateconf.h" -#include "weather-priv.h" - -struct _MateWeatherMateConf -{ - MateConfClient *mateconf; - char *prefix; -}; - - -MateWeatherMateConf * -mateweather_mateconf_new (const char *prefix) -{ - MateWeatherMateConf *ctx = g_new0 (MateWeatherMateConf, 1); - ctx->mateconf = mateconf_client_get_default (); - ctx->prefix = g_strdup (prefix); - - return ctx; -} - - -void -mateweather_mateconf_free (MateWeatherMateConf *ctx) -{ - if (!ctx) - return; - - g_object_unref (ctx->mateconf); - g_free (ctx->prefix); - g_free (ctx); -} - - -MateConfClient * -mateweather_mateconf_get_client (MateWeatherMateConf *ctx) -{ - g_return_val_if_fail (ctx != NULL, NULL); - return ctx->mateconf; -} - - -gchar * -mateweather_mateconf_get_full_key (MateWeatherMateConf *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 -mateweather_mateconf_set_bool (MateWeatherMateConf *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 = mateweather_mateconf_get_full_key (ctx, key); - mateconf_client_set_bool (ctx->mateconf, full_key, the_bool, opt_error); - g_free (full_key); -} - -void -mateweather_mateconf_set_int (MateWeatherMateConf *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 = mateweather_mateconf_get_full_key (ctx, key); - mateconf_client_set_int (ctx->mateconf, full_key, the_int, opt_error); - g_free (full_key); -} - -void -mateweather_mateconf_set_string (MateWeatherMateConf *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 = mateweather_mateconf_get_full_key (ctx, key); - mateconf_client_set_string (ctx->mateconf, full_key, the_string, opt_error); - g_free (full_key); -} - -gboolean -mateweather_mateconf_get_bool (MateWeatherMateConf *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 = mateweather_mateconf_get_full_key (ctx, key); - ret = mateconf_client_get_bool (ctx->mateconf, full_key, opt_error); - g_free (full_key); - return ret; -} - -gint -mateweather_mateconf_get_int (MateWeatherMateConf *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 = mateweather_mateconf_get_full_key (ctx, key); - ret = mateconf_client_get_int (ctx->mateconf, full_key, opt_error); - g_free (full_key); - return ret; -} - -gchar * -mateweather_mateconf_get_string (MateWeatherMateConf *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 = mateweather_mateconf_get_full_key (ctx, key); - ret = mateconf_client_get_string (ctx->mateconf, full_key, opt_error); - g_free (full_key); - return ret; -} - - -WeatherLocation * -mateweather_mateconf_get_location (MateWeatherMateConf *ctx) -{ - WeatherLocation *location; - gchar *name, *code, *zone, *radar, *coordinates; - - g_return_val_if_fail (ctx != NULL, NULL); - - name = mateweather_mateconf_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 = mateweather_mateconf_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/libmateweather/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 = mateweather_mateconf_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/libmateweather/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 = mateweather_mateconf_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/libmateweather/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 = mateweather_mateconf_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/libmateweather/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/libmateweather/mateweather-mateconf.h b/libmateweather/mateweather-mateconf.h deleted file mode 100644 index 5132d81..0000000 --- a/libmateweather/mateweather-mateconf.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * mateweather-mateconf.h: MateConf interaction methods for mateweather. - * - * 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 <[email protected]> - * Papadimitriou Spiros <[email protected]> - */ - -#ifndef __MATEWEATHER_MATECONF_WRAPPER_H__ -#define __MATEWEATHER_MATECONF_WRAPPER_H__ - - -#ifndef MATEWEATHER_I_KNOW_THIS_IS_UNSTABLE -#error "libmateweather should only be used if you understand that it's subject to change, and is not supported as a fixed API/ABI or as part of the platform" -#endif - - -#include <glib.h> -#include <mateconf/mateconf-client.h> -#include <mateconf/mateconf-value.h> - -#include <libmateweather/weather.h> - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _MateWeatherMateConf MateWeatherMateConf; - -MateWeatherMateConf * mateweather_mateconf_new (const char *prefix); -void mateweather_mateconf_free (MateWeatherMateConf *ctx); - -MateConfClient * mateweather_mateconf_get_client (MateWeatherMateConf *ctx); - -WeatherLocation * mateweather_mateconf_get_location (MateWeatherMateConf *ctx); - -gchar * mateweather_mateconf_get_full_key (MateWeatherMateConf *ctx, - const gchar *key); - -void mateweather_mateconf_set_bool (MateWeatherMateConf *ctx, - const gchar *key, - gboolean the_bool, - GError **opt_error); -void mateweather_mateconf_set_int (MateWeatherMateConf *ctx, - const gchar *key, - gint the_int, - GError **opt_error); -void mateweather_mateconf_set_string (MateWeatherMateConf *ctx, - const gchar *key, - const gchar *the_string, - GError **opt_error); - -gboolean mateweather_mateconf_get_bool (MateWeatherMateConf *ctx, - const gchar *key, - GError **opt_error); -gint mateweather_mateconf_get_int (MateWeatherMateConf *ctx, - const gchar *key, - GError **opt_error); -gchar * mateweather_mateconf_get_string (MateWeatherMateConf *ctx, - const gchar *key, - GError **opt_error); - -#ifdef __cplusplus -} -#endif - -#endif /* __MATEWEATHER_MATECONF_WRAPPER_H__ */ diff --git a/libmateweather/mateweather-prefs.c b/libmateweather/mateweather-prefs.c index b533ca2..d964085 100644 --- a/libmateweather/mateweather-prefs.c +++ b/libmateweather/mateweather-prefs.c @@ -24,372 +24,56 @@ #include <langinfo.h> #endif -#include <mateconf/mateconf-client.h> - #define MATEWEATHER_I_KNOW_THIS_IS_UNSTABLE #include "mateweather-prefs.h" #include "weather-priv.h" -static MateConfEnumStringPair 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 MateConfEnumStringPair 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 MateConfEnumStringPair 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 MateConfEnumStringPair 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 *mateconf_str, MateWeatherPrefs *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 ( mateconf_str && mateconf_string_to_enum (temp_unit_enum_map, mateconf_str, &value) ) { - prefs->temperature_unit = value; - - if ((prefs->temperature_unit == TEMP_UNIT_DEFAULT) && - (mateconf_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 (mateconf_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 *mateconf_str, MateWeatherPrefs *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 (mateconf_str && mateconf_string_to_enum (speed_unit_enum_map, mateconf_str, &value) ) { - prefs->speed_unit = value; - if ((prefs->speed_unit == SPEED_UNIT_DEFAULT) && - (mateconf_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 (mateconf_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 *mateconf_str, MateWeatherPrefs *prefs) -{ - gint value = 0; -#ifdef _NL_MEASUREMENT_MEASUREMENT - char *imperial = NULL; -#endif - - prefs->pressure_unit = PRESSURE_UNIT_INVALID; - prefs->use_pressure_default = TRUE; - - if ( mateconf_str && mateconf_string_to_enum (pressure_unit_enum_map, mateconf_str, &value) ) { - prefs->pressure_unit = value; - - if ((prefs->pressure_unit == PRESSURE_UNIT_DEFAULT) && - (mateconf_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 (mateconf_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 *mateconf_str, MateWeatherPrefs *prefs) -{ - gint value = 0; -#ifdef _NL_MEASUREMENT_MEASUREMENT - char *imperial = NULL; -#endif - - prefs->distance_unit = DISTANCE_UNIT_INVALID; - prefs->use_distance_default = TRUE; - if (mateconf_str && mateconf_string_to_enum (distance_unit_enum_map, mateconf_str, &value)) { - prefs->distance_unit = value; - - if ((prefs->distance_unit == DISTANCE_UNIT_DEFAULT) && - (mateconf_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 (mateconf_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 * -mateweather_prefs_temp_enum_to_string (TempUnit temp) -{ - return mateconf_enum_to_string (temp_unit_enum_map, temp); -} - -const char * -mateweather_prefs_speed_enum_to_string (SpeedUnit speed) -{ - return mateconf_enum_to_string (speed_unit_enum_map, speed); -} - -const char * -mateweather_prefs_pressure_enum_to_string (PressureUnit pressure) -{ - return mateconf_enum_to_string (pressure_unit_enum_map, pressure); -} - -const char * -mateweather_prefs_distance_enum_to_string (DistanceUnit distance) -{ - return mateconf_enum_to_string (distance_unit_enum_map, distance); -} - - void -mateweather_prefs_load (MateWeatherPrefs *prefs, MateWeatherMateConf *ctx) +mateweather_prefs_load (MateWeatherPrefs *prefs, GSettings *settings) { - GError *error = NULL; - gchar *mateconf_str = NULL; - g_return_if_fail (prefs != NULL); - g_return_if_fail (ctx != NULL); + g_return_if_fail (settings != NULL); if (prefs->location) { weather_location_free (prefs->location); } - prefs->location = mateweather_mateconf_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; + gchar *name, *code, *zone, *radar, *coordinates; + name = g_settings_get_string (settings, "location4"); + code = g_settings_get_string (settings, "location1"); + zone = g_settings_get_string (settings, "location2"); + radar = g_settings_get_string (settings, "location3"); + coordinates = g_settings_get_string (settings, "coordinates"); + prefs->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); prefs->update_interval = - mateweather_mateconf_get_int (ctx, "auto_update_interval", &error); - if (error) { - g_print ("%s \n", error->message); - g_error_free (error); - error = NULL; - } + g_settings_get_int (settings, "auto-update-interval"); prefs->update_interval = MAX (prefs->update_interval, 60); prefs->update_enabled = - mateweather_mateconf_get_bool (ctx, "auto_update", NULL); + g_settings_get_boolean (settings, "auto-update"); prefs->detailed = - mateweather_mateconf_get_bool (ctx, "enable_detailed_forecast", NULL); + g_settings_get_boolean (settings, "enable-detailed-forecast"); prefs->radar_enabled = - mateweather_mateconf_get_bool (ctx, "enable_radar_map", NULL); + g_settings_get_boolean (settings, "enable-radar-map"); prefs->use_custom_radar_url = - mateweather_mateconf_get_bool (ctx, "use_custom_radar_url", NULL); + g_settings_get_boolean (settings, "use-custom-radar-url"); if (prefs->radar) { g_free (prefs->radar); prefs->radar = NULL; } - prefs->radar = mateweather_mateconf_get_string (ctx, "radar", NULL); - - mateconf_str = mateweather_mateconf_get_string (ctx, MATECONF_TEMP_UNIT, NULL); - parse_temp_string (mateconf_str, prefs); - g_free (mateconf_str); - - mateconf_str = mateweather_mateconf_get_string (ctx, MATECONF_SPEED_UNIT, NULL); - parse_speed_string (mateconf_str, prefs); - g_free (mateconf_str); - - mateconf_str = mateweather_mateconf_get_string (ctx, MATECONF_PRESSURE_UNIT, NULL); - parse_pressure_string (mateconf_str, prefs); - g_free (mateconf_str); - - mateconf_str = mateweather_mateconf_get_string (ctx, MATECONF_DISTANCE_UNIT, NULL); - parse_distance_string (mateconf_str, prefs); - g_free (mateconf_str); + prefs->radar = g_settings_get_string (settings, "radar"); + + prefs->temperature_unit = g_settings_get_enum (settings, GSETTINGS_TEMP_UNIT); + prefs->speed_unit = g_settings_get_enum (settings, GSETTINGS_SPEED_UNIT); + prefs->pressure_unit = g_settings_get_enum (settings, GSETTINGS_PRESSURE_UNIT); + prefs->distance_unit = g_settings_get_enum (settings, GSETTINGS_DISTANCE_UNIT); return; } - -TempUnit -mateweather_prefs_parse_temperature (const char *str, gboolean *is_default) -{ - MateWeatherPrefs 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; -} - -SpeedUnit -mateweather_prefs_parse_speed (const char *str, gboolean *is_default) -{ - MateWeatherPrefs 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, MateConfEnumStringPair *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 * -mateweather_prefs_get_temp_display_name (TempUnit temp) -{ - return get_translated_unit (temp, temp_unit_enum_map, TEMP_UNIT_DEFAULT, TEMP_UNIT_FAHRENHEIT); -} - -const char * -mateweather_prefs_get_speed_display_name (SpeedUnit speed) -{ - return get_translated_unit (speed, speed_unit_enum_map, SPEED_UNIT_DEFAULT, SPEED_UNIT_BFT); -} - -const char * -mateweather_prefs_get_pressure_display_name (PressureUnit pressure) -{ - return get_translated_unit (pressure, pressure_unit_enum_map, PRESSURE_UNIT_DEFAULT, PRESSURE_UNIT_ATM); -} - -const char * -mateweather_prefs_get_distance_display_name (DistanceUnit distance) -{ - return get_translated_unit (distance, distance_unit_enum_map, DISTANCE_UNIT_DEFAULT, DISTANCE_UNIT_MILES); -} diff --git a/libmateweather/mateweather-prefs.h b/libmateweather/mateweather-prefs.h index 17cc65f..042170b 100644 --- a/libmateweather/mateweather-prefs.h +++ b/libmateweather/mateweather-prefs.h @@ -26,13 +26,13 @@ #include <libmateweather/weather.h> -#include <libmateweather/mateweather-mateconf.h> +#include <gio/gio.h> -/* mateconf keys */ -#define MATECONF_TEMP_UNIT "temperature_unit" -#define MATECONF_SPEED_UNIT "speed_unit" -#define MATECONF_PRESSURE_UNIT "pressure_unit" -#define MATECONF_DISTANCE_UNIT "distance_unit" +/* gsettings keys */ +#define GSETTINGS_TEMP_UNIT "temperature-unit" +#define GSETTINGS_SPEED_UNIT "speed-unit" +#define GSETTINGS_PRESSURE_UNIT "pressure-unit" +#define GSETTINGS_DISTANCE_UNIT "distance-unit" typedef struct _MateWeatherPrefs MateWeatherPrefs; @@ -46,31 +46,13 @@ struct _MateWeatherPrefs { gchar *radar; TempUnit temperature_unit; - gboolean use_temperature_default; SpeedUnit speed_unit; - gboolean use_speed_default; PressureUnit pressure_unit; - gboolean use_pressure_default; DistanceUnit distance_unit; - gboolean use_distance_default; }; void mateweather_prefs_load (MateWeatherPrefs *prefs, - MateWeatherMateConf *ctx); + GSettings *settings); -const char * mateweather_prefs_temp_enum_to_string (TempUnit temp); -const char * mateweather_prefs_speed_enum_to_string (SpeedUnit speed); -const char * mateweather_prefs_pressure_enum_to_string (PressureUnit pressure); -const char * mateweather_prefs_distance_enum_to_string (DistanceUnit distance); - -TempUnit mateweather_prefs_parse_temperature (const char *str, - gboolean *is_default); -SpeedUnit mateweather_prefs_parse_speed (const char *str, - gboolean *is_default); - -const char * mateweather_prefs_get_temp_display_name (TempUnit temp); -const char * mateweather_prefs_get_speed_display_name (SpeedUnit speed); -const char * mateweather_prefs_get_pressure_display_name (PressureUnit pressure); -const char * mateweather_prefs_get_distance_display_name (DistanceUnit distance); #endif /* __MATEWEATHER_PREFS_H_ */ diff --git a/libmateweather/mateweather-uninstalled.pc.in b/libmateweather/mateweather-uninstalled.pc.in index ac37302..08e42f7 100644 --- a/libmateweather/mateweather-uninstalled.pc.in +++ b/libmateweather/mateweather-uninstalled.pc.in @@ -7,7 +7,7 @@ includedir=@includedir@ Name: MateWeather Description: MateWeather shared library Version: @VERSION@ -Requires: glib-2.0 gobject-2.0 gdk-pixbuf-2.0 gtk+-2.0 mateconf-2.0 +Requires: glib-2.0 gobject-2.0 gdk-pixbuf-2.0 gtk+-2.0 gio-2.0 Requires.private: libxml-2.0 libsoup-2.4 Libs: ${pc_top_builddir}/${pcfiledir}/libmateweather.la Cflags: -I${pc_top_builddir}/${pcfiledir}/.. diff --git a/libmateweather/mateweather.pc.in b/libmateweather/mateweather.pc.in index d332631..e90dbae 100644 --- a/libmateweather/mateweather.pc.in +++ b/libmateweather/mateweather.pc.in @@ -7,7 +7,7 @@ includedir=@includedir@ Name: MateWeather Description: MateWeather shared library Version: @VERSION@ -Requires: glib-2.0 gobject-2.0 gdk-pixbuf-2.0 gtk+-2.0 mateconf-2.0 +Requires: glib-2.0 gobject-2.0 gdk-pixbuf-2.0 gtk+-2.0 gio-2.0 Requires.private: libxml-2.0 libsoup-2.4 Libs: -L${libdir} -lmateweather Libs.private: -lm diff --git a/libmateweather/mateweather.schemas.in b/libmateweather/mateweather.schemas.in deleted file mode 100644 index 3b81d35..0000000 --- a/libmateweather/mateweather.schemas.in +++ /dev/null @@ -1,173 +0,0 @@ -<mateconfschemafile> -<schemalist> - -<schema> - <key>/schemas/apps/mateweather/prefs/auto_update</key> - <owner>mateweather-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/mateweather/prefs/auto_update_interval</key> - <owner>mateweather-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/mateweather/prefs/enable_metric</key> - <owner>mateweather-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/mateweather/prefs/distance_unit</key> - <owner>mateweather-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/mateweather/prefs/pressure_unit</key> - <owner>mateweather-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/mateweather/prefs/speed_unit</key> - <owner>mateweather-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/mateweather/prefs/temperature_unit</key> - <owner>mateweather-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/mateweather/prefs/enable_detailed_forecast</key> - <owner>mateweather-applet-2</owner> - <type>bool</type> - <default>false</default> - <locale name="C"> - <short>Not used anymore</short> - </locale> -</schema> -<schema> - <key>/schemas/apps/mateweather/prefs/enable_radar_map</key> - <owner>mateweather-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/mateweather/prefs/location0</key> - <owner>mateweather-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/mateweather/prefs/location1</key> - <owner>mateweather-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/libmateweather/plain/data/Locations.xml.in</long> - </locale> -</schema> -<schema> - <key>/schemas/apps/mateweather/prefs/location2</key> - <owner>mateweather-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/libmateweather/plain/data/Locations.xml.in</long> - </locale> -</schema> -<schema> - <key>/schemas/apps/mateweather/prefs/location3</key> - <owner>mateweather-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/libmateweather/plain/data/Locations.xml.in</long> - </locale> -</schema> -<schema> - <key>/schemas/apps/mateweather/prefs/location4</key> - <owner>mateweather-applet-2</owner> - <type>string</type> - <locale name="C"> - <default>DEFAULT_LOCATION</default> - <short>Weather for a city</short> - <long>The city that mateweather displays information for.</long> - </locale> -</schema> -<schema> - <key>/schemas/apps/mateweather/prefs/coordinates</key> - <owner>mateweather-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/mateweather/prefs/use_custom_radar_url</key> - <owner>mateweather-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/mateweather/prefs/radar</key> - <owner>mateweather-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> -</mateconfschemafile> diff --git a/libmateweather/org.mate.weather.gschema.xml b/libmateweather/org.mate.weather.gschema.xml new file mode 100644 index 0000000..4a62fb9 --- /dev/null +++ b/libmateweather/org.mate.weather.gschema.xml @@ -0,0 +1,121 @@ +<schemalist gettext-domain="FIXME"> + <enum id="org.mate.weather.TemperatureUnit"> + <value nick="Invalid" value="0"/> + <value nick="Default" value="1"/> + <value nick="Kelvin" value="2"/> + <value nick="Centigrade" value="3"/> + <value nick="Fahrenheit" value="4"/> + </enum> + <enum id="org.mate.weather.SpeedUnit"> + <value nick="Invalid" value="0"/> + <value nick="Default" value="1"/> + <value nick="m/s" value="2"/> + <value nick="km/h" value="3"/> + <value nick="mph" value="4"/> + <value nick="knots" value="5"/> + <value nick="Beaufort scale" value="6"/> + </enum> + <enum id="org.mate.weather.PressureUnit"> + <value nick="Invalid" value="0"/> + <value nick="Default" value="1"/> + <value nick="kPa" value="2"/> + <value nick="hPa" value="3"/> + <value nick="mb" value="4"/> + <value nick="mmHg" value="5"/> + <value nick="inHg" value="6"/> + <value nick="atm" value="7"/> + </enum> + <enum id="org.mate.weather.DistanceUnit"> + <value nick="Invalid" value="0"/> + <value nick="Default" value="1"/> + <value nick="meters" value="2"/> + <value nick="km" value="3"/> + <value nick="miles" value="4"/> + </enum> + <schema id="org.mate.weather"> + <key name="auto-update" type="b"> + <default>true</default> + <summary>Update the data automatically</summary> + <description>Determines whether the applet automatically updates its weather statistics or not.</description> + </key> + <key name="auto-update-interval" type="i"> + <default>1800</default> + <summary>Update interval</summary> + <description>The interval, in seconds, between automatic updates.</description> + </key> + <key name="enable-metric" type="b"> + <default>false</default> + <summary>Use metric units</summary> + <description>Use metric units instead of english units.</description> + </key> + <key name="distance-unit" enum="org.mate.weather.DistanceUnit"> + <default>'Default'</default> + <summary>Distance unit</summary> + <description>The unit to use for visibility.</description> + </key> + <key name="pressure-unit" enum="org.mate.weather.PressureUnit"> + <default>'Default'</default> + <summary>Pressure unit</summary> + <description>The unit to use for pressure.</description> + </key> + <key name="speed-unit" enum="org.mate.weather.SpeedUnit"> + <default>'Default'</default> + <summary>Speed unit</summary> + <description>The unit to use for wind speed.</description> + </key> + <key name="temperature-unit" enum="org.mate.weather.TemperatureUnit"> + <default>'Default'</default> + <summary>Temperature unit</summary> + <description>The unit to use for temperature.</description> + </key> + <key name="enable-detailed-forecast" type="b"> + <default>false</default> + <summary>Not used anymore</summary> + </key> + <key name="enable-radar-map" type="b"> + <default>false</default> + <summary>Display radar map</summary> + <description>Fetch a radar map on each update.</description> + </key> + <key name="location0" type="s"> + <default l10n="messages" context="location0">'DEFAULT_LOCATION'</default> + <summary>Weather location information</summary> + <description>Weather location information.</description> + </key> + <key name="location1" type="s"> + <default l10n="messages" context="location1">'DEFAULT_CODE'</default> + <summary>Nearby city</summary> + <description>Nearby major zone, such as a capital city, as found from https://raw.github.com/mate-desktop/libmateweather/master/data/Locations.xml.in</description> + </key> + <key name="location2" type="s"> + <default l10n="messages" context="location2">'DEFAULT_ZONE'</default> + <summary>Zone location</summary> + <description>A unique zone for the city, as found from https://raw.github.com/mate-desktop/libmateweather/master/data/Locations.xml.in</description> + </key> + <key name="location3" type="s"> + <default l10n="messages" context="location3">'DEFAULT_RADAR'</default> + <summary>Radar location</summary> + <description>A three-digit-long code for retrieving radar maps from weather.com, found from https://raw.github.com/mate-desktop/libmateweather/master/data/Locations.xml.in</description> + </key> + <key name="location4" type="s"> + <default l10n="messages" context="location4">'DEFAULT_LOCATION'</default> + <summary>Weather for a city</summary> + <description>The city that mateweather displays information for.</description> + </key> + <key name="coordinates" type="s"> + <default l10n="messages" context="coordinates">'DEFAULT_COORDINATES'</default> + <summary>Location coordinates</summary> + <description>Latitude and longitude of your location expressed in DD-MM-SS[NS] DD-MM-SS[EW].</description> + </key> + <key name="use-custom-radar-url" type="b"> + <default>false</default> + <summary>Use custom url for the radar map</summary> + <description>If true, then retrieve a radar map from a location specified by the "radar" key.</description> + </key> + <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.</description> + </key> + </schema> +</schemalist> |