forked from organicmaps/organicmaps
[new downloader] Storage::DownloadNode implementation and imporovement in Storage::CancelDownloading and Storage::RetryDownloading.
This commit is contained in:
parent
1743e52bfc
commit
132cffc1a4
2 changed files with 58 additions and 16 deletions
|
@ -84,12 +84,6 @@ TCountriesContainer const & LeafNodeFromCountryId(TCountriesContainer const & ro
|
|||
return *node;
|
||||
}
|
||||
|
||||
void GetQueuedCountries(Storage::TQueue const & queue, TCountriesSet & countries)
|
||||
{
|
||||
for (auto const & country : queue)
|
||||
countries.insert(country.GetCountryId());
|
||||
}
|
||||
|
||||
void CorrectJustDownloaded(Storage::TQueue::iterator justDownloadedItem, Storage::TQueue & queue,
|
||||
TCountriesSet & justDownloaded)
|
||||
{
|
||||
|
@ -118,6 +112,12 @@ bool IsPartlyDownloaded(Status status)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
void GetQueuedCountries(Storage::TQueue const & queue, TCountriesSet & countries)
|
||||
{
|
||||
for (auto const & country : queue)
|
||||
countries.insert(country.GetCountryId());
|
||||
}
|
||||
|
||||
bool HasCountryId(TCountriesVec const & sortedCountryIds, TCountryId const & countryId)
|
||||
{
|
||||
ASSERT(is_sorted(sortedCountryIds.begin(), sortedCountryIds.end()), ());
|
||||
|
@ -1383,4 +1383,31 @@ MapFilesDownloader::TProgress Storage::CalculateProgress(TCountryId const & down
|
|||
|
||||
return localAndRemoteBytes;
|
||||
}
|
||||
|
||||
void Storage::UpdateNode(TCountryId const & countryId)
|
||||
{
|
||||
ForEachInSubtree(countryId, [this](TCountryId const & descendantId, bool expandableNode)
|
||||
{
|
||||
if (!expandableNode && this->m_localFiles.find(descendantId) != this->m_localFiles.end())
|
||||
this->DownloadNode(descendantId);
|
||||
});
|
||||
}
|
||||
|
||||
void Storage::CancelDownloadNode(TCountryId const & countryId)
|
||||
{
|
||||
ForEachInSubtreeAndInQueue(countryId, [this](TCountryId const & descendantId, bool expandableNode)
|
||||
{
|
||||
ASSERT(!expandableNode, ());
|
||||
this->DeleteNode(descendantId);
|
||||
});
|
||||
}
|
||||
|
||||
void Storage::RetryDownloadNode(TCountryId const & countryId)
|
||||
{
|
||||
ForEachInSubtreeAndInQueue(countryId, [this](TCountryId const & descendantId, bool expandableNode)
|
||||
{
|
||||
ASSERT(!expandableNode, ());
|
||||
this->DownloadNode(descendantId);
|
||||
});
|
||||
}
|
||||
} // namespace storage
|
||||
|
|
|
@ -284,23 +284,21 @@ public:
|
|||
/// \brief Delete node with all children (expandable or not).
|
||||
void DeleteNode(TCountryId const & countryId);
|
||||
|
||||
/// \brief Updates one node (expandable or not).
|
||||
/// \brief Updates one node. It works for leaf and group mwms.
|
||||
/// \note If you want to update all the maps and this update is without changing
|
||||
/// borders or hierarchy just call UpdateNode(GetRootId()).
|
||||
/// \return false in case of error and true otherwise.
|
||||
bool UpdateNode(TCountryId const & countryId) { return true; }
|
||||
void UpdateNode(TCountryId const & countryId);
|
||||
|
||||
/// \brief If the downloading is in process cancels downloading a node and deletes
|
||||
/// downloaded part of the map. If the map is in queue, remove the map from the queue.
|
||||
/// If the map has been downloaded removes the map. It works for leaf and for group mwms.
|
||||
void CancelDownloadNode(TCountryId const & countryId) { DeleteNode(countryId); }
|
||||
/// It works for leaf and for group mwms.
|
||||
void CancelDownloadNode(TCountryId const & countryId);
|
||||
|
||||
/// \brief Downloading process could be interupted because of bad internet connection.
|
||||
/// In that case user could want to recover it. This method is done for it.
|
||||
/// This method works with leaf and group mwm.
|
||||
/// In case of group mwm this method retry downloading and add to the download queue
|
||||
/// all mwms of the |countryId|.
|
||||
void RetryDownloadNode(TCountryId const & countryId) { DownloadNode(countryId); }
|
||||
/// In case of group mwm this method retries downloading ...
|
||||
void RetryDownloadNode(TCountryId const & countryId);
|
||||
|
||||
/// \brief Get information for mwm update button.
|
||||
/// \return true if updateInfo is filled correctly and false otherwise.
|
||||
|
@ -507,8 +505,14 @@ private:
|
|||
TCountriesVec const & descendants,
|
||||
MapFilesDownloader::TProgress const & downloadingMwmProgress,
|
||||
TCountriesSet const & mwmsInQueue) const;
|
||||
|
||||
template <class ToDo>
|
||||
void ForEachInSubtreeAndInQueue(TCountryId const & root, ToDo && toDo) const;
|
||||
};
|
||||
|
||||
void GetQueuedCountries(Storage::TQueue const & queue, TCountriesSet & countries);
|
||||
bool HasCountryId(TCountriesVec const & sorted, TCountryId const & countyId);
|
||||
|
||||
template <class ToDo>
|
||||
void Storage::ForEachInSubtree(TCountryId const & root, ToDo && toDo) const
|
||||
{
|
||||
|
@ -525,6 +529,19 @@ void Storage::ForEachInSubtree(TCountryId const & root, ToDo && toDo) const
|
|||
});
|
||||
}
|
||||
|
||||
template <class ToDo>
|
||||
void Storage::ForEachInSubtreeAndInQueue(TCountryId const & root, ToDo && toDo) const
|
||||
{
|
||||
TCountriesSet setQueue;
|
||||
GetQueuedCountries(m_queue, setQueue);
|
||||
|
||||
ForEachInSubtree(root, [&setQueue, &toDo](TCountryId const & descendantId, bool expandableNode)
|
||||
{
|
||||
if (setQueue.count(descendantId) != 0)
|
||||
toDo(descendantId, expandableNode);
|
||||
});
|
||||
}
|
||||
|
||||
/// Calls functor |toDo| with signature
|
||||
/// void(const TCountryId const & parentId, TCountriesVec const & descendantCountryId)
|
||||
/// for each ancestor except for the main root of the tree.
|
||||
|
@ -558,6 +575,4 @@ void Storage::ForEachAncestorExceptForTheRoot(TCountryId const & countryId, ToDo
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool HasCountryId(TCountriesVec const & sorted, TCountryId const & countyId);
|
||||
} // storage
|
||||
|
|
Loading…
Add table
Reference in a new issue