From 34dba6b23c64d675a240ba5f36d8b74d3f4dd2c0 Mon Sep 17 00:00:00 2001 From: TangoCash Date: Tue, 18 Jan 2022 23:31:52 +0100 Subject: [PATCH] move weather locations to xml file Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/2eed1b5e20185c7f79cd42f18ef837b82878f3d6 Author: TangoCash Date: 2022-01-18 (Tue, 18 Jan 2022) Origin message was: ------------------ - move weather locations to xml file ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- data/config/Makefile.am | 3 +- data/config/weather_locations.xml | 288 ++++++++++++++++++++++++++++++ src/gui/weather_setup.cpp | 59 +++++- src/gui/weather_setup.h | 9 + 4 files changed, 351 insertions(+), 8 deletions(-) create mode 100644 data/config/weather_locations.xml diff --git a/data/config/Makefile.am b/data/config/Makefile.am index ddca88619..9ab7f62b7 100644 --- a/data/config/Makefile.am +++ b/data/config/Makefile.am @@ -11,7 +11,8 @@ install_DATA = \ providermap.xml \ satellites.xml \ terrestrial.xml \ - tobackup.conf + tobackup.conf \ + weather_locations.xml if ENABLE_EXTUPDATE EXTRA_DIST += \ diff --git a/data/config/weather_locations.xml b/data/config/weather_locations.xml new file mode 100644 index 000000000..70f8d42cd --- /dev/null +++ b/data/config/weather_locations.xml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gui/weather_setup.cpp b/src/gui/weather_setup.cpp index 8a110c899..a4957ae66 100644 --- a/src/gui/weather_setup.cpp +++ b/src/gui/weather_setup.cpp @@ -27,11 +27,11 @@ #include #include +#include #include #include #include -#include #include @@ -41,6 +41,8 @@ CWeatherSetup::CWeatherSetup() { width = 40; selected = -1; + locations.clear(); + loadLocations(); } CWeatherSetup::~CWeatherSetup() @@ -98,7 +100,16 @@ int CWeatherSetup::showSelectWeatherLocation() int select = 0; int res = 0; - if (WEATHER_LOCATION_OPTION_COUNT > 1) + if (locations.size() == 0) + { + ShowHint("Warning", "Failed to load weather_locations.xml\nPlease press any key or wait some seconds! ...", 700, 10, NULL, NEUTRINO_ICON_HINT_IMAGEINFO, CComponentsHeader::CC_BTN_EXIT); + g_settings.weather_location = "52.52,13.40"; + g_settings.weather_city = "Berlin"; + CWeather::getInstance()->setCoords(g_settings.weather_location, g_settings.weather_city); + return menu_return::RETURN_REPAINT; + } + + if (locations.size() > 1) { CMenuWidget *m = new CMenuWidget(LOCALE_WEATHER_LOCATION, NEUTRINO_ICON_LANGUAGE); CMenuSelectorTarget *selector = new CMenuSelectorTarget(&select); @@ -106,10 +117,10 @@ int CWeatherSetup::showSelectWeatherLocation() m->addItem(GenericMenuSeparator); CMenuForwarder *mf; - for (size_t i = 0; i < WEATHER_LOCATION_OPTION_COUNT; i++) + for (size_t i = 0; i < locations.size(); i++) { - mf = new CMenuForwarder(WEATHER_LOCATION_OPTIONS[i].key, true, NULL, selector, to_string(i).c_str()); - mf->setHint(NEUTRINO_ICON_HINT_SETTINGS, WEATHER_LOCATION_OPTIONS[i].value.c_str()); + mf = new CMenuForwarder(locations[i].key, true, NULL, selector, to_string(i).c_str()); + mf->setHint(NEUTRINO_ICON_HINT_SETTINGS, locations[i].value.c_str()); m->addItem(mf); } @@ -122,8 +133,8 @@ int CWeatherSetup::showSelectWeatherLocation() delete selector; } - g_settings.weather_location = WEATHER_LOCATION_OPTIONS[select].value; - g_settings.weather_city = std::string(WEATHER_LOCATION_OPTIONS[select].key); + g_settings.weather_location = locations[select].value; + g_settings.weather_city = std::string(locations[select].key); CWeather::getInstance()->setCoords(g_settings.weather_location, g_settings.weather_city); return res; @@ -144,3 +155,37 @@ bool CWeatherSetup::changeNotify(const neutrino_locale_t OptionName, void * /*da } return ret; } + +void CWeatherSetup::loadLocations() +{ + xmlDocPtr parser = parseXmlFile(CONFIGDIR"/weather_locations.xml"); + + if (parser == NULL) + { + dprintf(DEBUG_INFO, "failed to load weather_locations.xml\n"); + return; + } + + + xmlNodePtr l0 = xmlDocGetRootElement(parser); + xmlNodePtr l1 = xmlChildrenNode(l0); + + if (l1) + { + while ((xmlGetNextOccurence(l1, "location"))) + { + const char *country = xmlGetAttribute(l1, "country"); + const char *city = xmlGetAttribute(l1, "city"); + const char *latitude = xmlGetAttribute(l1, "latitude"); + const char *longitude = xmlGetAttribute(l1, "longitude"); + weather_loc loc; + loc.key = strdup(city); + loc.value = std::string(latitude) + "," + std::string(longitude); + locations.push_back(loc); + l1 = xmlNextNode(l1); + } + } + + xmlFreeDoc(parser); +} + diff --git a/src/gui/weather_setup.h b/src/gui/weather_setup.h index 06d52ebcb..27cc61231 100644 --- a/src/gui/weather_setup.h +++ b/src/gui/weather_setup.h @@ -22,10 +22,18 @@ #include #include +#include class CWeatherSetup : public CMenuTarget, CChangeObserver { private: + struct weather_loc + { + char *key; + std::string value; + }; + std::vector locations; + int width, selected; CMenuOptionChooser *weather_onoff; @@ -33,6 +41,7 @@ class CWeatherSetup : public CMenuTarget, CChangeObserver int showWeatherSetup(); int showSelectWeatherLocation(); + void loadLocations(); public: CWeatherSetup();