summaryrefslogtreecommitdiff
path: root/libmateweather/mateweather-prefs.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmateweather/mateweather-prefs.c')
-rw-r--r--libmateweather/mateweather-prefs.c370
1 files changed, 27 insertions, 343 deletions
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);
-}