Build in search index generation after downloading.

This commit is contained in:
vng 2011-12-14 21:28:36 +03:00 committed by Alex Zolotarev
parent eb03ebc866
commit 8318252eaf
2 changed files with 44 additions and 14 deletions

View file

@ -6,6 +6,7 @@
#include "../base/string_utils.hpp"
#include "../indexer/data_factory.hpp"
#include "../indexer/search_index_builder.hpp"
#include "../platform/platform.hpp"
#include "../platform/settings.hpp"
@ -138,7 +139,8 @@ namespace storage
// check if we already downloading this country
TQueue::const_iterator found = find(m_queue.begin(), m_queue.end(), index);
if (found != m_queue.end())
{ // do nothing
{
// do nothing
return;
}
// remove it from failed list
@ -156,7 +158,8 @@ namespace storage
DownloadNextCountryFromQueue();
}
else
{ // notify about "In Queue" status
{
// notify about "In Queue" status
if (m_observerChange)
m_observerChange(index);
}
@ -256,7 +259,8 @@ namespace storage
if (found != m_queue.end())
{
if (found == m_queue.begin())
{ // stop download
{
// stop download
m_request.reset();
// remove from the queue
m_queue.erase(found);
@ -270,7 +274,8 @@ namespace storage
DownloadNextCountryFromQueue();
}
else
{ // remove from the queue
{
// remove from the queue
m_queue.erase(found);
}
}
@ -303,7 +308,8 @@ namespace storage
}
}
void Storage::Subscribe(TObserverChangeCountryFunction change, TObserverProgressFunction progress)
void Storage::Subscribe(TObserverChangeCountryFunction change,
TObserverProgressFunction progress)
{
m_observerChange = change;
m_observerProgress = progress;
@ -349,18 +355,35 @@ namespace storage
if (i != string::npos)
file = file.substr(i+1);
// activate downloaded map piece
m_addMap(file);
// update rect from downloaded file
feature::DataHeader header;
LoadMapHeader(GetPlatform().GetReader(file), header);
m_updateRect(header.GetBounds());
GetPlatform().RunAsync(bind(&Storage::GenerateSearchIndex, this, cref(file)));
}
m_request.reset();
DownloadNextCountryFromQueue();
}
void Storage::GenerateSearchIndex(string const & fName) const
{
if (indexer::BuildSearchIndexFromDatFile(fName))
{
GetPlatform().RunInGuiThread(bind(&Storage::UpdateAfterSearchIndex, this, cref(fName)));
}
else
{
LOG(LERROR, ("Can't build search index for", fName));
}
}
void Storage::UpdateAfterSearchIndex(string const & fName) const
{
// activate downloaded map piece
m_addMap(fName);
// update rect from downloaded file
feature::DataHeader header;
LoadMapHeader(GetPlatform().GetReader(fName), header);
m_updateRect(header.GetBounds());
}
void Storage::OnMapDownloadProgress(HttpRequest & request)
{
if (m_queue.empty())

View file

@ -35,7 +35,9 @@ namespace storage
: m_group(group), m_country(country), m_region(region) {}
bool operator==(TIndex const & other) const
{
return m_group == other.m_group && m_country == other.m_country && m_region == other.m_region;
return (m_group == other.m_group &&
m_country == other.m_country &&
m_region == other.m_region);
}
bool operator<(TIndex const & other) const
{
@ -94,12 +96,17 @@ namespace storage
void DownloadNextCountryFromQueue();
Country const & CountryByIndex(TIndex const & index) const;
void GenerateSearchIndex(string const & fName) const;
void UpdateAfterSearchIndex(string const & fName) const;
public:
Storage() {}
/// @TODO temporarily made public for Android, refactor
void ReInitCountries(bool forceReload);
void Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc, TUpdateRectFunction updateRectFunc);
void Init(TAddMapFunction addFunc,
TRemoveMapFunction removeFunc,
TUpdateRectFunction updateRectFunc);
/// @name Called from DownloadManager
//@{