diff --git a/configure.ac b/configure.ac index b5c6f2495..08cdae6eb 100644 --- a/configure.ac +++ b/configure.ac @@ -203,6 +203,12 @@ AC_ARG_WITH(weather-dev-key, [WEATHER_DEV_KEY=""]) AC_DEFINE_UNQUOTED([WEATHER_DEV_KEY], ["$WEATHER_DEV_KEY"], [API dev key to get data from weather data base, required for additional weather informations]) +AC_ARG_WITH(weather-dev-ver, + AS_HELP_STRING([--with-weather-dev-ver=version], [API version to get data from weather data base, required for additional weather informations]), + [WEATHER_DEV_VER="$withval"], + [WEATHER_DEV_VER=""]) +AC_DEFINE_UNQUOTED([WEATHER_DEV_VER], ["$WEATHER_DEV_VER"], [API version to get data from weather data base, required for additional weather informations]) + AC_ARG_ENABLE([weather-key-manage], AS_HELP_STRING([--enable-weather-key-manage], [enable manage weather api dev key via gui for additional weather informations @<:@default=yes@:>@]), [enable_weather_key_manage="$enableval"], diff --git a/data/locale/deutsch.locale b/data/locale/deutsch.locale index aa79a3893..91dcb87eb 100644 --- a/data/locale/deutsch.locale +++ b/data/locale/deutsch.locale @@ -2922,6 +2922,7 @@ videomenu.zappingmode_holdtilllock Standbild bis lock videomenu.zappingmode_mute Schwarzes Bild videomenu.zappingmode_mutetilllock Schwarzes Bild bis lock weather.api_key Wetter API Schlüssel (OpenWeather) +weather.api_ver Wetter API Version weather.direction_e O weather.direction_ene ONO weather.direction_ese OSO diff --git a/data/locale/english.locale b/data/locale/english.locale index e4b70dab6..782066390 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -2922,6 +2922,7 @@ videomenu.zappingmode_holdtilllock Hold screen until lock videomenu.zappingmode_mute Black screen videomenu.zappingmode_mutetilllock Black screen until lock weather.api_key Weather API key (OpenWeather) +weather.api_ver Weather API version weather.direction_e E weather.direction_ene ENE weather.direction_ese ESE diff --git a/src/gui/weather.cpp b/src/gui/weather.cpp index ce2b33c29..4e7d05b31 100644 --- a/src/gui/weather.cpp +++ b/src/gui/weather.cpp @@ -54,6 +54,7 @@ CWeather *CWeather::getInstance() CWeather::CWeather() { key = g_settings.weather_api_key; + api = g_settings.weather_api_version; v_forecast.clear(); last_time = 0; coords = ""; @@ -78,6 +79,22 @@ void CWeather::setCoords(std::string new_coords, std::string new_city) } } +void CWeather::updateApi() +{ + bool force = false; + if (key.compare(g_settings.weather_api_key)) + { + key = g_settings.weather_api_key; + force = true; + } + if (api.compare(g_settings.weather_api_version)) + { + api = g_settings.weather_api_version; + force = true; + } + checkUpdate(force); +} + bool CWeather::checkUpdate(bool forceUpdate) { time_t current_time = time(NULL); @@ -100,7 +117,7 @@ bool CWeather::GetWeatherDetails() std::string lat = coords.substr(0, coords.find_first_of(',')); std::string lon = coords.substr(coords.find_first_of(',') + 1); - std::string data = "https://api.openweathermap.org/data/2.5/onecall?lat=" + lat + "&lon=" + lon + "&units=metric&lang=de&exclude=minutely,hourly,flags,alerts&appid=" + key; + std::string data = "https://api.openweathermap.org/data/"+api+"/onecall?lat=" + lat + "&lon=" + lon + "&units=metric&lang=de&exclude=minutely,hourly,flags,alerts&appid=" + key; JSONCPP_STRING answer; JSONCPP_STRING formattedErrors; diff --git a/src/gui/weather.h b/src/gui/weather.h index a81a931f2..b08c129ba 100644 --- a/src/gui/weather.h +++ b/src/gui/weather.h @@ -81,6 +81,7 @@ class CWeather std::vector v_forecast; CComponentsForm *form; std::string key; + std::string api; bool GetWeatherDetails(); time_t last_time; std::string getDirectionString(int degree); @@ -89,6 +90,7 @@ class CWeather static CWeather *getInstance(); CWeather(); ~CWeather(); + void updateApi(); bool checkUpdate(bool forceUpdate = false); void setCoords(std::string new_coords, std::string new_city = "Unknown"); bool FindCoords(std::string postalcode, std::string country = "DE"); diff --git a/src/gui/weather_setup.cpp b/src/gui/weather_setup.cpp index d4fc7cddd..cc1bb2e68 100644 --- a/src/gui/weather_setup.cpp +++ b/src/gui/weather_setup.cpp @@ -37,11 +37,27 @@ #include +CMenuOptionChooser::keyval_ext WEATHER_API_OPTIONS[] = +{ + { 0, NONEXISTANT_LOCALE, "2.5" }, + { 1, NONEXISTANT_LOCALE, "3.0" } + +}; +#define WEATHER_API_OPTION_COUNT (sizeof(WEATHER_API_OPTIONS)/sizeof(CMenuOptionChooser::keyval_ext)) + CWeatherSetup::CWeatherSetup() { width = 40; selected = -1; - + weather_api_version = 0; + for (size_t i = 0; i < WEATHER_API_OPTION_COUNT; i++) + { + if (WEATHER_API_OPTIONS[i].valname == g_settings.weather_api_version) + { + weather_api_version = i; + break; + } + } locations.clear(); loadLocations(CONFIGDIR "/weather-favorites.xml"); loadLocations(WEATHERDIR "/weather-locations.xml"); @@ -90,6 +106,9 @@ int CWeatherSetup::showWeatherSetup() ms_oservices->addItem(mf_we); #endif + weather_api = new CMenuOptionChooser(LOCALE_WEATHER_API_VER, &weather_api_version, WEATHER_API_OPTIONS, WEATHER_API_OPTION_COUNT, CApiKey::check_weather_api_key(), this); + ms_oservices->addItem(weather_api); + CMenuForwarder *mf_wl = new CMenuForwarder(LOCALE_WEATHER_LOCATION, g_settings.weather_enabled, g_settings.weather_city, this, "select_location"); mf_wl->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_WEATHER_LOCATION); ms_oservices->addItem(mf_wl); @@ -180,11 +199,19 @@ bool CWeatherSetup::changeNotify(const neutrino_locale_t OptionName, void */*dat { g_settings.weather_enabled = g_settings.weather_enabled && CApiKey::check_weather_api_key(); if (g_settings.weather_enabled) + { + CWeather::getInstance()->updateApi(); weather_api_key_short = g_settings.weather_api_key.substr(0, 8) + "..."; + } else weather_api_key_short.clear(); weather_onoff->setActive(CApiKey::check_weather_api_key()); } + else if(ARE_LOCALES_EQUAL(OptionName, LOCALE_WEATHER_API_VER)) + { + g_settings.weather_api_version = WEATHER_API_OPTIONS[weather_api_version].valname; + CWeather::getInstance()->updateApi(); + } return ret; } diff --git a/src/gui/weather_setup.h b/src/gui/weather_setup.h index 9762fdfac..d7124fee6 100644 --- a/src/gui/weather_setup.h +++ b/src/gui/weather_setup.h @@ -44,7 +44,9 @@ class CWeatherSetup : public CMenuTarget, CChangeObserver int width, selected; CMenuOptionChooser *weather_onoff; + CMenuOptionChooser *weather_api; std::string weather_api_key_short; + int weather_api_version; int showWeatherSetup(); int selectLocation(); diff --git a/src/neutrino.cpp b/src/neutrino.cpp index b05e0a14d..13d29594d 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -1113,8 +1113,10 @@ int CNeutrinoApp::loadSetup(const char *fname) // online services g_settings.weather_api_key = WEATHER_DEV_KEY; + g_settings.weather_api_version = WEATHER_DEV_VER; #if ENABLE_WEATHER_KEY_MANAGE g_settings.weather_api_key = configfile.getString("weather_api_key", g_settings.weather_api_key.empty() ? "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" : g_settings.weather_api_key); + g_settings.weather_api_version = configfile.getString("weather_api_ver", g_settings.weather_api_version.empty() ? "2.5" : g_settings.weather_api_version); #endif g_settings.weather_enabled = configfile.getInt32("weather_enabled", 1); g_settings.weather_enabled = g_settings.weather_enabled && CApiKey::check_weather_api_key(); @@ -2014,6 +2016,7 @@ void CNeutrinoApp::saveSetup(const char *fname) // online services #if ENABLE_WEATHER_KEY_MANAGE configfile.setString("weather_api_key", g_settings.weather_api_key); + configfile.setString( "weather_api_ver", g_settings.weather_api_version); #endif configfile.setInt32("weather_enabled", g_settings.weather_enabled); diff --git a/src/system/locals.h b/src/system/locals.h index 2a9d791d6..3576426f8 100644 --- a/src/system/locals.h +++ b/src/system/locals.h @@ -2949,6 +2949,7 @@ typedef enum LOCALE_VIDEOMENU_ZAPPINGMODE_MUTE, LOCALE_VIDEOMENU_ZAPPINGMODE_MUTETILLLOCK, LOCALE_WEATHER_API_KEY, + LOCALE_WEATHER_API_VER, LOCALE_WEATHER_DIRECTION_E, LOCALE_WEATHER_DIRECTION_ENE, LOCALE_WEATHER_DIRECTION_ESE, diff --git a/src/system/locals_intern.h b/src/system/locals_intern.h index 78056fcc8..c893fd549 100644 --- a/src/system/locals_intern.h +++ b/src/system/locals_intern.h @@ -2949,6 +2949,7 @@ const char * locale_real_names[] = "videomenu.zappingmode_mute", "videomenu.zappingmode_mutetilllock", "weather.api_key", + "weather.api_ver", "weather.direction_e", "weather.direction_ene", "weather.direction_ese", diff --git a/src/system/settings.h b/src/system/settings.h index 7d6b6b8dc..15ce82aa1 100644 --- a/src/system/settings.h +++ b/src/system/settings.h @@ -936,6 +936,7 @@ struct SNeutrinoSettings // online services std::string weather_api_key; + std::string weather_api_version; int weather_enabled; std::string weather_city;