[old map downloader] All download button implementation.

This commit is contained in:
Vladimir Byko-Ianko 2016-01-28 18:59:02 +03:00 committed by Sergey Yershov
parent 900e0a5689
commit b605a23e3a
3 changed files with 23 additions and 8 deletions

View file

@ -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<ActiveMapsLayout> 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;

View file

@ -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;

View file

@ -190,6 +190,8 @@ public:
void SetDownloaderForTesting(unique_ptr<MapFilesDownloader> && downloader);
void SetCurrentDataVersionForTesting(int64_t currentVersion);
bool IsLeaf(TIndex const & index) const { return CountriesCount(index) == 0; }
private:
friend void UnitTest_StorageTest_DeleteCountry();