From b605a23e3a269a774431f1c691ff3021272d232b Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 28 Jan 2016 18:59:02 +0300 Subject: [PATCH] [old map downloader] All download button implementation. --- map/country_tree.cpp | 28 ++++++++++++++++++++-------- map/country_tree.hpp | 1 + storage/storage.hpp | 2 ++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/map/country_tree.cpp b/map/country_tree.cpp index dd2e18ab29..ec6a1218c4 100644 --- a/map/country_tree.cpp +++ b/map/country_tree.cpp @@ -9,9 +9,8 @@ namespace storage namespace { - int const RootItemIndex = 0; - int const ChildItemsOffset = 1; -} +int const RootItemIndex = 0; +int const ChildItemsOffset = 1; inline TIndex GetIndexChild(TIndex const & index, int i) { @@ -39,6 +38,7 @@ inline TIndex GetIndexParent(TIndex const & index) return parent; } +} // namespace CountryTree::CountryTree(shared_ptr activeMaps) { @@ -122,7 +122,7 @@ int CountryTree::GetChildCount() const bool CountryTree::IsLeaf(int childPosition) const { - return GetStorage().CountriesCount(GetChild(childPosition)) == 0; + return GetStorage().IsLeaf(GetChild(childPosition)); } string const & CountryTree::GetChildName(int position) const @@ -191,16 +191,28 @@ void CountryTree::RetryDownloading(int childPosition) GetActiveMapLayout().RetryDownloading(GetChild(childPosition)); } -void CountryTree::DownloadAll() +void CountryTree::DownloadAllImpl(TIndex const & index) { - size_t const childCount = GetChildCount(); + if (GetStorage().IsLeaf(index)) + { + GetActiveMapLayout().DownloadMap(index, MapOptions::MapWithCarRouting); + return; + } + + size_t const childCount = GetStorage().CountriesCount(index); for (size_t i = 0; i < childCount; ++i) { - if (IsLeaf(i)) - DownloadCountry(i, MapOptions::MapWithCarRouting); + TIndex const child = GetIndexChild(index, i); + ASSERT_NOT_EQUAL(index, child, ()); + DownloadAllImpl(child); } } +void CountryTree::DownloadAll() +{ + DownloadAllImpl(GetCurrentRoot()); +} + bool CountryTree::IsDownloadAllAvailable() { return true; diff --git a/map/country_tree.hpp b/map/country_tree.hpp index fdfc34c628..976f1d2b96 100644 --- a/map/country_tree.hpp +++ b/map/country_tree.hpp @@ -84,6 +84,7 @@ private: void DisconnectFromCoreStorage(); private: + void DownloadAllImpl(TIndex const & index); TIndex const & GetCurrentRoot() const; void SetRoot(TIndex index); TIndex const & GetChild(int childPosition) const; diff --git a/storage/storage.hpp b/storage/storage.hpp index 9f080ac614..2ccc3e111f 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -190,6 +190,8 @@ public: void SetDownloaderForTesting(unique_ptr && downloader); void SetCurrentDataVersionForTesting(int64_t currentVersion); + bool IsLeaf(TIndex const & index) const { return CountriesCount(index) == 0; } + private: friend void UnitTest_StorageTest_DeleteCountry();