diff --git a/src/gui/weather.cpp b/src/gui/weather.cpp index 02c27f1f2..cecb1de6d 100644 --- a/src/gui/weather.cpp +++ b/src/gui/weather.cpp @@ -181,12 +181,9 @@ bool CWeather::GetWeatherDetails() return false; } -bool CWeather::FindCoords(int postcode, std::string country, int pc_len) +bool CWeather::FindCoords(std::string postcode, std::string country) { - std::string pcode = to_string(postcode); - unsigned int number_of_zeros = pc_len - pcode.length(); - pcode.insert(0, number_of_zeros, '0'); - std::string data = "http://api.openweathermap.org/geo/1.0/zip?zip=" + pcode + "," + country + "&appid=" + key; + std::string data = "http://api.openweathermap.org/geo/1.0/zip?zip=" + postcode + "," + country + "&appid=" + key; JSONCPP_STRING answer; JSONCPP_STRING formattedErrors; Json::CharReaderBuilder builder; diff --git a/src/gui/weather.h b/src/gui/weather.h index d27592e54..49e170eef 100644 --- a/src/gui/weather.h +++ b/src/gui/weather.h @@ -90,7 +90,7 @@ class CWeather ~CWeather(); bool checkUpdate(bool forceUpdate = false); void setCoords(std::string new_coords, std::string new_city = "Unknown"); - bool FindCoords(int postcode, std::string country = "DE", int pc_len = 5); + bool FindCoords(std::string postcode, std::string country = "DE"); // globals std::string getCity() diff --git a/src/gui/weather_setup.cpp b/src/gui/weather_setup.cpp index 9031b24f7..2fafcd3cf 100644 --- a/src/gui/weather_setup.cpp +++ b/src/gui/weather_setup.cpp @@ -158,12 +158,11 @@ int CWeatherSetup::findLocation() { int ret = menu_return::RETURN_REPAINT; - int postcode = WEATHER_DEFAULT_POSTCODE; - CIntInput zipcode(LOCALE_WEATHER_LOCATION_POSTCODE, &postcode, (unsigned int)5); + CStringInput zipcode(LOCALE_WEATHER_LOCATION_POSTCODE, &g_settings.weather_postcode, 5); ret = zipcode.exec(NULL, ""); zipcode.hide(); - if (CWeather::getInstance()->FindCoords(postcode)) + if (CWeather::getInstance()->FindCoords(g_settings.weather_postcode)) { CWeather::getInstance()->setCoords(g_settings.weather_location, g_settings.weather_city); } diff --git a/src/gui/weather_setup.h b/src/gui/weather_setup.h index eb13d48c8..70fb9bdd3 100644 --- a/src/gui/weather_setup.h +++ b/src/gui/weather_setup.h @@ -23,7 +23,7 @@ #define WEATHER_DEFAULT_CITY "Berlin" #define WEATHER_DEFAULT_LOCATION "52.52,13.40" -#define WEATHER_DEFAULT_POSTCODE 10178 +#define WEATHER_DEFAULT_POSTCODE "10178" #include diff --git a/src/neutrino.cpp b/src/neutrino.cpp index 4349e9b3b..2857f09cf 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -1114,6 +1114,7 @@ int CNeutrinoApp::loadSetup(const char *fname) g_settings.weather_city = configfile.getString("weather_city", WEATHER_DEFAULT_CITY); g_settings.weather_location = configfile.getString("weather_location", WEATHER_DEFAULT_LOCATION); + g_settings.weather_postcode = configfile.getString("weather_postcode", WEATHER_DEFAULT_POSTCODE); g_settings.youtube_dev_id = YT_DEV_KEY; #if ENABLE_YOUTUBE_KEY_MANAGE @@ -2106,6 +2107,7 @@ void CNeutrinoApp::saveSetup(const char *fname) configfile.setString("weather_city", g_settings.weather_city); configfile.setString("weather_location", g_settings.weather_location); + configfile.setString("weather_postcode", g_settings.weather_postcode); #if ENABLE_YOUTUBE_KEY_MANAGE configfile.setString("youtube_dev_id", g_settings.youtube_dev_id); diff --git a/src/system/settings.h b/src/system/settings.h index e81da55a2..0459f2ae1 100644 --- a/src/system/settings.h +++ b/src/system/settings.h @@ -911,6 +911,7 @@ struct SNeutrinoSettings std::string weather_city; std::string weather_location; + std::string weather_postcode; std::string youtube_dev_id; int youtube_enabled;