From 6db85bfa17869e85d34553e59f1ccedb0bc4b5e6 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 13 Jun 2012 01:10:06 -0700 Subject: [PATCH] Fix bug with downloaded country name in startup view. --- .../jni/com/mapswithme/maps/MapStorage.cpp | 6 +++- map/country_status_display.cpp | 20 +++---------- map/country_status_display.hpp | 5 ++-- storage/country_decl.cpp | 28 +++++++++++++++++++ storage/country_decl.hpp | 3 ++ storage/country_info.cpp | 10 +------ storage/storage.pro | 1 + 7 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 storage/country_decl.cpp diff --git a/android/jni/com/mapswithme/maps/MapStorage.cpp b/android/jni/com/mapswithme/maps/MapStorage.cpp index 606e59684b..af4bb094f7 100644 --- a/android/jni/com/mapswithme/maps/MapStorage.cpp +++ b/android/jni/com/mapswithme/maps/MapStorage.cpp @@ -123,7 +123,11 @@ extern "C" if (!strCountry) return IndexBinding::toJava(storage::TIndex()); - return IndexBinding::toJava(g_framework->Storage().FindIndexByName(strCountry)); + // In case of countries, splitted on regions. + string group, map; + storage::CountryInfo::FullName2GroupAndMap(strCountry, group, map); + + return IndexBinding::toJava(g_framework->Storage().FindIndexByName(map)); } JNIEXPORT void JNICALL diff --git a/map/country_status_display.cpp b/map/country_status_display.cpp index e7c4161ab5..85e851bc01 100644 --- a/map/country_status_display.cpp +++ b/map/country_status_display.cpp @@ -2,14 +2,13 @@ #include "../gui/controller.hpp" -#include "../std/bind.hpp" -#include "../std/sstream.hpp" +#include "../yg/overlay_renderer.hpp" #include "../base/string_format.hpp" -#include "../storage/storage.hpp" +#include "../std/bind.hpp" +#include "../std/sstream.hpp" -#include "../yg/overlay_renderer.hpp" string const CountryStatusDisplay::displayName() const { @@ -181,18 +180,7 @@ void CountryStatusDisplay::setCountryName(string const & name) { if (m_fullName != name) { - size_t pos = name.find(","); - if (pos == string::npos) - { - m_mapName = name; - m_mapGroupName.clear(); - } - else - { - m_mapName = name.substr(pos + 2); - m_mapGroupName = name.substr(0, pos); - } - + storage::CountryInfo::FullName2GroupAndMap(name, m_mapGroupName, m_mapName); LOG(LINFO, (m_mapName, m_mapGroupName)); m_countryIdx = m_storage->FindIndexByName(m_mapName); diff --git a/map/country_status_display.hpp b/map/country_status_display.hpp index 37e439a709..4fec7730d6 100644 --- a/map/country_status_display.hpp +++ b/map/country_status_display.hpp @@ -2,12 +2,13 @@ #include "../storage/storage.hpp" -#include "../std/shared_ptr.hpp" - #include "../gui/element.hpp" #include "../gui/button.hpp" #include "../gui/text_view.hpp" +#include "../std/shared_ptr.hpp" + + /// This class is a composite GUI element to display /// an on-screen GUI for the country, which is not downloaded yet. class CountryStatusDisplay : public gui::Element diff --git a/storage/country_decl.cpp b/storage/country_decl.cpp new file mode 100644 index 0000000000..857d6db17c --- /dev/null +++ b/storage/country_decl.cpp @@ -0,0 +1,28 @@ +#include "country_decl.hpp" + + +string storage::CountryInfo::FileName2FullName(string fName) +{ + size_t const i = fName.find('_'); + if (i != string::npos) + { + // replace '_' with ", " + fName[i] = ','; + fName.insert(i+1, " "); + } + return fName; +} + +void storage::CountryInfo::FullName2GroupAndMap(string const & fName, string & group, string & map) +{ + size_t pos = fName.find(","); + if (pos == string::npos) + { + map = fName; + } + else + { + map = fName.substr(pos + 2); + group = fName.substr(0, pos); + } +} diff --git a/storage/country_decl.hpp b/storage/country_decl.hpp index 1ddb4b6a64..e0d154bb87 100644 --- a/storage/country_decl.hpp +++ b/storage/country_decl.hpp @@ -29,5 +29,8 @@ namespace storage string m_flag; bool IsNotEmpty() const { return !m_flag.empty(); } + + static string FileName2FullName(string fName); + static void FullName2GroupAndMap(string const & fName, string & group, string & map); }; } diff --git a/storage/country_info.cpp b/storage/country_info.cpp index 74074f6b37..a9e59c2fb1 100644 --- a/storage/country_info.cpp +++ b/storage/country_info.cpp @@ -108,15 +108,7 @@ namespace storage if (info.m_name.empty()) info.m_name = id; - if (id.find('_') != string::npos) - { - size_t const i = info.m_name.find('_'); - ASSERT ( i != string::npos, () ); - - // replace '_' with ", " - info.m_name[i] = ','; - info.m_name.insert(i+1, " "); - } + info.m_name = CountryInfo::FileName2FullName(info.m_name); } void CountryInfoGetter::CalcUSALimitRect(m2::RectD rects[3]) const diff --git a/storage/storage.pro b/storage/storage.pro index 33faa0509c..86f141289b 100644 --- a/storage/storage.pro +++ b/storage/storage.pro @@ -24,3 +24,4 @@ SOURCES += \ country.cpp \ storage.cpp \ country_info.cpp \ + country_decl.cpp \