forked from organicmaps/organicmaps
[new downloader] Removing ActiveMapLayout, CoutryTree and StorageBridge.
This commit is contained in:
parent
9c54e61278
commit
93964bf15b
10 changed files with 1 additions and 1480 deletions
|
@ -1,670 +0,0 @@
|
|||
#include "map/active_maps_layout.hpp"
|
||||
#include "map/framework.hpp"
|
||||
|
||||
#include "std/algorithm.hpp"
|
||||
|
||||
|
||||
namespace storage
|
||||
{
|
||||
|
||||
bool ActiveMapsLayout::Item::IsEqual(TIndex const & index) const
|
||||
{
|
||||
return (find(m_indexes.begin(), m_indexes.end(), index) != m_indexes.end());
|
||||
}
|
||||
|
||||
bool ActiveMapsLayout::Item::IsEqual(Item const & item) const
|
||||
{
|
||||
for (TIndex const & i : m_indexes)
|
||||
if (item.IsEqual(i))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
ActiveMapsLayout::ActiveMapsLayout(Framework & framework)
|
||||
: m_framework(framework)
|
||||
{
|
||||
m_subscribeSlotID = GetStorage().Subscribe(bind(&ActiveMapsLayout::StatusChangedCallback, this, _1),
|
||||
bind(&ActiveMapsLayout::ProgressChangedCallback, this, _1, _2));
|
||||
}
|
||||
|
||||
ActiveMapsLayout::~ActiveMapsLayout()
|
||||
{
|
||||
GetStorage().Unsubscribe(m_subscribeSlotID);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::Init(vector<TLocalFilePtr> const & files)
|
||||
{
|
||||
Clear();
|
||||
|
||||
Storage & storage = GetStorage();
|
||||
for (auto const & file : files)
|
||||
{
|
||||
vector<TIndex> arr = storage.FindAllIndexesByFile(file->GetCountryName());
|
||||
if (!arr.empty())
|
||||
{
|
||||
TStatus status;
|
||||
MapOptions options;
|
||||
storage.CountryStatusEx(arr[0], status, options);
|
||||
if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
|
||||
m_items.push_back({ arr, status, options, options });
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LWARNING, ("Can't find map index for", file->GetCountryName()));
|
||||
}
|
||||
}
|
||||
|
||||
auto const comparatorFn = [&storage] (Item const & lhs, Item const & rhs)
|
||||
{
|
||||
if (lhs.m_status != rhs.m_status)
|
||||
return lhs.m_status > rhs.m_status;
|
||||
else
|
||||
return storage.CountryName(lhs.Index()) < storage.CountryName(rhs.Index());
|
||||
};
|
||||
|
||||
sort(m_items.begin(), m_items.end(), comparatorFn);
|
||||
|
||||
m_split = { 0, m_items.size() };
|
||||
for (size_t i = 0; i < m_items.size(); ++i)
|
||||
{
|
||||
if (m_items[i].m_status == TStatus::EOnDisk)
|
||||
{
|
||||
m_split.second = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::Clear()
|
||||
{
|
||||
m_items.clear();
|
||||
m_split = { 0, 0 };
|
||||
}
|
||||
|
||||
size_t ActiveMapsLayout::GetSizeToUpdateAllInBytes() const
|
||||
{
|
||||
size_t result = 0;
|
||||
for (int i = m_split.first; i < m_split.second; ++i)
|
||||
{
|
||||
Item const & item = m_items[i];
|
||||
if (item.m_status != TStatus::EInQueue && item.m_status != TStatus::EDownloading)
|
||||
result += GetStorage().CountryByIndex(item.Index()).GetFile().GetRemoteSize(item.m_options);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::UpdateAll()
|
||||
{
|
||||
vector<Item> toDownload;
|
||||
toDownload.reserve(m_items.size());
|
||||
for (int i = m_split.first; i < m_split.second; ++i)
|
||||
{
|
||||
Item const & item = m_items[i];
|
||||
if (item.m_status != TStatus::EInQueue && item.m_status != TStatus::EDownloading)
|
||||
toDownload.push_back(item);
|
||||
}
|
||||
|
||||
for (Item const & item : toDownload)
|
||||
DownloadMap(item.Index(), item.m_options);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::CancelAll()
|
||||
{
|
||||
vector<TIndex> downloading;
|
||||
downloading.reserve(m_items.size());
|
||||
for (Item const & item : m_items)
|
||||
{
|
||||
if (item.m_status == TStatus::EInQueue || item.m_status == TStatus::EDownloading)
|
||||
downloading.push_back(item.Index());
|
||||
}
|
||||
|
||||
Storage & st = m_framework.Storage();
|
||||
for (TIndex const & index : downloading)
|
||||
st.DeleteFromDownloader(index);
|
||||
}
|
||||
|
||||
int ActiveMapsLayout::GetOutOfDateCount() const
|
||||
{
|
||||
int result = 0;
|
||||
for (size_t i = m_split.first; i < m_split.second; ++i)
|
||||
{
|
||||
Item const & item = m_items[i];
|
||||
if (item.m_status != TStatus::ENotDownloaded)
|
||||
++result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ActiveMapsLayout::GetCountInGroup(TGroup const & group) const
|
||||
{
|
||||
int result = 0;
|
||||
switch (group)
|
||||
{
|
||||
case TGroup::ENewMap:
|
||||
result = m_split.first;
|
||||
break;
|
||||
case TGroup::EOutOfDate:
|
||||
result = m_split.second - m_split.first;
|
||||
break;
|
||||
case TGroup::EUpToDate:
|
||||
result = m_items.size() - m_split.second;
|
||||
break;
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ActiveMapsLayout::IsEmpty() const
|
||||
{
|
||||
return GetCountInGroup(TGroup::ENewMap) == 0 && GetCountInGroup(TGroup::EOutOfDate) == 0 && GetCountInGroup(TGroup::EUpToDate) == 0;
|
||||
}
|
||||
|
||||
string const & ActiveMapsLayout::GetCountryName(TGroup const & group, int position) const
|
||||
{
|
||||
return GetCountryName(GetItemInGroup(group, position).Index());
|
||||
}
|
||||
|
||||
string const & ActiveMapsLayout::GetCountryName(TIndex const & index) const
|
||||
{
|
||||
return GetStorage().CountryName(index);
|
||||
}
|
||||
|
||||
TStatus ActiveMapsLayout::GetCountryStatus(TGroup const & group, int position) const
|
||||
{
|
||||
return GetItemInGroup(group, position).m_status;
|
||||
}
|
||||
|
||||
TStatus ActiveMapsLayout::GetCountryStatus(TIndex const & index) const
|
||||
{
|
||||
Item const * item = FindItem(index);
|
||||
if (item != nullptr)
|
||||
return item->m_status;
|
||||
|
||||
return GetStorage().CountryStatusEx(index);
|
||||
}
|
||||
|
||||
MapOptions ActiveMapsLayout::GetCountryOptions(TGroup const & group, int position) const
|
||||
{
|
||||
return GetItemInGroup(group, position).m_options;
|
||||
}
|
||||
|
||||
MapOptions ActiveMapsLayout::GetCountryOptions(TIndex const & index) const
|
||||
{
|
||||
Item const * item = FindItem(index);
|
||||
if (item)
|
||||
return item->m_options;
|
||||
|
||||
TStatus status;
|
||||
MapOptions options;
|
||||
GetStorage().CountryStatusEx(index, status, options);
|
||||
return options;
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const ActiveMapsLayout::GetDownloadableCountrySize(TGroup const & group, int position) const
|
||||
{
|
||||
Item const & item = GetItemInGroup(group, position);
|
||||
return GetStorage().CountrySizeInBytes(item.Index(), item.m_downloadRequest);
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const ActiveMapsLayout::GetDownloadableCountrySize(TIndex const & index) const
|
||||
{
|
||||
Item const * item = FindItem(index);
|
||||
ASSERT(item, ());
|
||||
return GetStorage().CountrySizeInBytes(index, item->m_downloadRequest);
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const ActiveMapsLayout::GetCountrySize(TGroup const & group, int position,
|
||||
MapOptions const & options) const
|
||||
{
|
||||
return GetCountrySize(GetItemInGroup(group, position).Index(), options);
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const ActiveMapsLayout::GetCountrySize(TIndex const & index, MapOptions const & options) const
|
||||
{
|
||||
return GetStorage().CountrySizeInBytes(index, options);
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const ActiveMapsLayout::GetRemoteCountrySizes(TGroup const & group, int position) const
|
||||
{
|
||||
return GetRemoteCountrySizes(GetItemInGroup(group, position).Index());
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const ActiveMapsLayout::GetRemoteCountrySizes(TIndex const & index) const
|
||||
{
|
||||
platform::CountryFile const & c = GetStorage().CountryByIndex(index).GetFile();
|
||||
size_t const mapSize = c.GetRemoteSize(MapOptions::Map);
|
||||
return { mapSize, c.GetRemoteSize(MapOptions::CarRouting) };
|
||||
}
|
||||
|
||||
int ActiveMapsLayout::AddListener(ActiveMapsListener * listener)
|
||||
{
|
||||
m_listeners[m_currentSlotID] = listener;
|
||||
return m_currentSlotID++;
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::RemoveListener(int slotID)
|
||||
{
|
||||
m_listeners.erase(slotID);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::DownloadMap(TIndex const & index, MapOptions const & options)
|
||||
{
|
||||
MapOptions validOptions = ValidOptionsForDownload(options);
|
||||
Item * item = FindItem(index);
|
||||
if (item)
|
||||
{
|
||||
ASSERT(item != nullptr, ());
|
||||
item->m_downloadRequest = validOptions;
|
||||
}
|
||||
else
|
||||
{
|
||||
Storage const & s = GetStorage();
|
||||
vector<TIndex> arr = s.FindAllIndexesByFile(s.GetCountryFile(index).GetNameWithoutExt());
|
||||
int position = InsertInGroup(TGroup::ENewMap, { arr, TStatus::ENotDownloaded, validOptions, validOptions });
|
||||
NotifyInsertion(TGroup::ENewMap, position);
|
||||
}
|
||||
|
||||
m_framework.DownloadCountry(index, validOptions);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::DownloadMap(TGroup const & group, int position, MapOptions const & options)
|
||||
{
|
||||
Item & item = GetItemInGroup(group, position);
|
||||
item.m_downloadRequest = ValidOptionsForDownload(options);
|
||||
m_framework.DownloadCountry(item.Index(), item.m_downloadRequest);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::DeleteMap(TIndex const & index, const MapOptions & options)
|
||||
{
|
||||
TGroup group;
|
||||
int position;
|
||||
VERIFY(GetGroupAndPositionByIndex(index, group, position), ());
|
||||
DeleteMap(group, position, options);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::DeleteMap(TGroup const & group, int position, MapOptions const & options)
|
||||
{
|
||||
TIndex indexCopy = GetItemInGroup(group, position).Index();
|
||||
m_framework.DeleteCountry(indexCopy, ValidOptionsForDelete(options));
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::RetryDownloading(TGroup const & group, int position)
|
||||
{
|
||||
Item const & item = GetItemInGroup(group, position);
|
||||
m_framework.DownloadCountry(item.Index(), item.m_downloadRequest);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::RetryDownloading(TIndex const & index)
|
||||
{
|
||||
Item * item = FindItem(index);
|
||||
ASSERT(item != nullptr, ());
|
||||
m_framework.DownloadCountry(item->Index(), item->m_downloadRequest);
|
||||
}
|
||||
|
||||
TIndex const & ActiveMapsLayout::GetCoreIndex(TGroup const & group, int position) const
|
||||
{
|
||||
return GetItemInGroup(group, position).Index();
|
||||
}
|
||||
|
||||
string const ActiveMapsLayout::GetFormatedCountryName(TIndex const & index) const
|
||||
{
|
||||
string group, country;
|
||||
GetStorage().GetGroupAndCountry(index, group, country);
|
||||
if (!group.empty())
|
||||
return country + " (" + group + ")";
|
||||
else
|
||||
return country;
|
||||
}
|
||||
|
||||
bool ActiveMapsLayout::IsDownloadingActive() const
|
||||
{
|
||||
auto iter = find_if(m_items.begin(), m_items.end(), [] (Item const & item)
|
||||
{
|
||||
return item.m_status == TStatus::EDownloading || item.m_status == TStatus::EInQueue;
|
||||
});
|
||||
|
||||
return iter != m_items.end();
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::CancelDownloading(TGroup const & group, int position)
|
||||
{
|
||||
Item & item = GetItemInGroup(group, position);
|
||||
GetStorage().DeleteFromDownloader(item.Index());
|
||||
item.m_downloadRequest = item.m_options;
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::CancelDownloading(TIndex const & index)
|
||||
{
|
||||
GetStorage().DeleteFromDownloader(index);
|
||||
Item * item = FindItem(index);
|
||||
if (item != nullptr)
|
||||
item->m_downloadRequest = item->m_options;
|
||||
}
|
||||
|
||||
TIndex ActiveMapsLayout::GetCurrentDownloadingCountryIndex() const
|
||||
{
|
||||
return GetStorage().GetCurrentDownloadingCountryIndex();
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::ShowMap(TGroup const & group, int position)
|
||||
{
|
||||
ShowMap(GetItemInGroup(group, position).Index());
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::ShowMap(TIndex const & index)
|
||||
{
|
||||
m_framework.ShowCountry(index);
|
||||
}
|
||||
|
||||
Storage const & ActiveMapsLayout::GetStorage() const
|
||||
{
|
||||
return m_framework.Storage();
|
||||
}
|
||||
|
||||
Storage & ActiveMapsLayout::GetStorage()
|
||||
{
|
||||
return m_framework.Storage();
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::StatusChangedCallback(TIndex const & index)
|
||||
{
|
||||
TStatus newStatus = TStatus::EUnknown;
|
||||
MapOptions options = MapOptions::Map;
|
||||
GetStorage().CountryStatusEx(index, newStatus, options);
|
||||
|
||||
TGroup group = TGroup::ENewMap;
|
||||
int position = 0;
|
||||
VERIFY(GetGroupAndPositionByIndex(index, group, position), (index));
|
||||
Item & item = GetItemInGroup(group, position);
|
||||
|
||||
TStatus oldStatus = item.m_status;
|
||||
item.m_status = newStatus;
|
||||
|
||||
if (newStatus == TStatus::EOnDisk)
|
||||
{
|
||||
if (group != TGroup::EUpToDate)
|
||||
{
|
||||
// Here we handle
|
||||
// "NewMap" -> "Actual Map without routing"
|
||||
// "NewMap" -> "Actual Map with routing"
|
||||
// "OutOfDate without routing" -> "Actual map without routing"
|
||||
// "OutOfDate without routing" -> "Actual map with routing"
|
||||
// "OutOfDate with Routing" -> "Actual map with routing"
|
||||
// For "NewMaps" always true - m_options == m_m_downloadRequest == options
|
||||
// but we must notify that options changed because for "NewMaps" m_options is virtual state
|
||||
if (item.m_options != options || group == TGroup::ENewMap)
|
||||
{
|
||||
MapOptions requestOptions = options;
|
||||
item.m_downloadRequest = item.m_options = options;
|
||||
NotifyOptionsChanged(group, position, item.m_options, requestOptions);
|
||||
}
|
||||
|
||||
int newPosition = MoveItemToGroup(group, position, TGroup::EUpToDate);
|
||||
NotifyMove(group, position, TGroup::EUpToDate, newPosition);
|
||||
group = TGroup::EUpToDate;
|
||||
position = newPosition;
|
||||
}
|
||||
else if (item.m_options != options)
|
||||
{
|
||||
// Here we handle
|
||||
// "Actual map without routing" -> "Actual map with routing"
|
||||
// "Actual map with routing" -> "Actual map without routing"
|
||||
MapOptions requestOpt = item.m_downloadRequest;
|
||||
item.m_options = item.m_downloadRequest = options;
|
||||
NotifyOptionsChanged(group, position, item.m_options, requestOpt);
|
||||
}
|
||||
NotifyStatusChanged(group, position, oldStatus, item.m_status);
|
||||
}
|
||||
else if (newStatus == TStatus::ENotDownloaded)
|
||||
{
|
||||
if (group == TGroup::ENewMap)
|
||||
{
|
||||
// "NewMap downloading" -> "Cancel downloading"
|
||||
// We handle here only status change for "New maps"
|
||||
// because if new status ENotDownloaded than item.m_options is invalid.
|
||||
// Map have no options and gui not show routing icon
|
||||
NotifyStatusChanged(group, position, oldStatus, item.m_status);
|
||||
}
|
||||
else
|
||||
{
|
||||
// "Actual of not map been deleted"
|
||||
// We not notify about options changed!
|
||||
NotifyStatusChanged(group, position, oldStatus, item.m_status);
|
||||
DeleteFromGroup(group, position);
|
||||
NotifyDeletion(group, position);
|
||||
}
|
||||
}
|
||||
else if (newStatus == TStatus::EOnDiskOutOfDate)
|
||||
{
|
||||
// We can drop here only if user start update some map and cancel it
|
||||
NotifyStatusChanged(group, position, oldStatus, item.m_status);
|
||||
|
||||
ASSERT(item.m_options == options, ());
|
||||
item.m_downloadRequest = item.m_options = options;
|
||||
}
|
||||
else
|
||||
{
|
||||
// EDownloading
|
||||
// EInQueue
|
||||
// downloadig faild for some reason
|
||||
NotifyStatusChanged(group, position, oldStatus, item.m_status);
|
||||
}
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::ProgressChangedCallback(TIndex const & index, LocalAndRemoteSizeT const & sizes)
|
||||
{
|
||||
if (m_listeners.empty())
|
||||
return;
|
||||
|
||||
TGroup group = TGroup::ENewMap;
|
||||
int position = 0;
|
||||
VERIFY(GetGroupAndPositionByIndex(index, group, position), ());
|
||||
for (TListenerNode listener : m_listeners)
|
||||
listener.second->DownloadingProgressUpdate(group, position, sizes);
|
||||
}
|
||||
|
||||
ActiveMapsLayout::Item const & ActiveMapsLayout::GetItemInGroup(TGroup const & group, int position) const
|
||||
{
|
||||
int index = GetStartIndexInGroup(group) + position;
|
||||
ASSERT(index < m_items.size(), ());
|
||||
return m_items[index];
|
||||
}
|
||||
|
||||
ActiveMapsLayout::Item & ActiveMapsLayout::GetItemInGroup(TGroup const & group, int position)
|
||||
{
|
||||
int index = GetStartIndexInGroup(group) + position;
|
||||
ASSERT(index < m_items.size(), ());
|
||||
return m_items[index];
|
||||
}
|
||||
|
||||
int ActiveMapsLayout::GetStartIndexInGroup(TGroup const & group) const
|
||||
{
|
||||
switch (group)
|
||||
{
|
||||
case TGroup::ENewMap: return 0;
|
||||
case TGroup::EOutOfDate: return m_split.first;
|
||||
case TGroup::EUpToDate: return m_split.second;
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
}
|
||||
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
ActiveMapsLayout::Item * ActiveMapsLayout::FindItem(TIndex const & index)
|
||||
{
|
||||
auto iter = find_if(m_items.begin(), m_items.end(), [&index] (Item const & item)
|
||||
{
|
||||
return item.IsEqual(index);
|
||||
});
|
||||
|
||||
if (iter == m_items.end())
|
||||
return nullptr;
|
||||
|
||||
return &(*iter);
|
||||
}
|
||||
|
||||
ActiveMapsLayout::Item const * ActiveMapsLayout::FindItem(TIndex const & index) const
|
||||
{
|
||||
auto iter = find_if(m_items.begin(), m_items.end(), [&index] (Item const & item)
|
||||
{
|
||||
return item.IsEqual(index);
|
||||
});
|
||||
|
||||
if (iter == m_items.end())
|
||||
return nullptr;
|
||||
|
||||
return &(*iter);
|
||||
}
|
||||
|
||||
bool ActiveMapsLayout::GetGroupAndPositionByIndex(TIndex const & index, TGroup & group, int & position)
|
||||
{
|
||||
auto it = find_if(m_items.begin(), m_items.end(), [&index] (Item const & item)
|
||||
{
|
||||
return item.IsEqual(index);
|
||||
});
|
||||
|
||||
if (it == m_items.end())
|
||||
return false;
|
||||
|
||||
int vectorIndex = distance(m_items.begin(), it);
|
||||
if (vectorIndex >= m_split.second)
|
||||
{
|
||||
group = TGroup::EUpToDate;
|
||||
position = vectorIndex - m_split.second;
|
||||
}
|
||||
else if (vectorIndex >= m_split.first)
|
||||
{
|
||||
group = TGroup::EOutOfDate;
|
||||
position = vectorIndex - m_split.first;
|
||||
}
|
||||
else
|
||||
{
|
||||
group = TGroup::ENewMap;
|
||||
position = vectorIndex;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ActiveMapsLayout::InsertInGroup(TGroup const & group, Item const & item)
|
||||
{
|
||||
typedef vector<Item>::iterator TItemIter;
|
||||
TItemIter startSort;
|
||||
TItemIter endSort;
|
||||
|
||||
if (group == TGroup::ENewMap)
|
||||
{
|
||||
m_items.insert(m_items.begin(), item);
|
||||
++m_split.first;
|
||||
++m_split.second;
|
||||
startSort = m_items.begin();
|
||||
endSort = m_items.begin() + m_split.first;
|
||||
}
|
||||
else if (group == TGroup::EOutOfDate)
|
||||
{
|
||||
m_items.insert(m_items.begin() + m_split.first, item);
|
||||
++m_split.second;
|
||||
startSort = m_items.begin() + m_split.first;
|
||||
endSort = m_items.begin() + m_split.second;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_items.insert(m_items.begin() + m_split.second, item);
|
||||
startSort = m_items.begin() + m_split.second;
|
||||
endSort = m_items.end();
|
||||
}
|
||||
|
||||
Storage & st = m_framework.Storage();
|
||||
sort(startSort, endSort, [&] (Item const & lhs, Item const & rhs)
|
||||
{
|
||||
return st.CountryName(lhs.Index()) < st.CountryName(rhs.Index());
|
||||
});
|
||||
|
||||
TItemIter newPosIter = find_if(startSort, endSort, [&item] (Item const & it)
|
||||
{
|
||||
return it.IsEqual(item);
|
||||
});
|
||||
|
||||
ASSERT(m_split.first <= m_items.size(), ());
|
||||
ASSERT(m_split.second <= m_items.size(), ());
|
||||
|
||||
ASSERT(newPosIter != m_items.end(), ());
|
||||
return distance(startSort, newPosIter);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::DeleteFromGroup(TGroup const & group, int position)
|
||||
{
|
||||
if (group == TGroup::ENewMap)
|
||||
{
|
||||
--m_split.first;
|
||||
--m_split.second;
|
||||
}
|
||||
else if (group == TGroup::EOutOfDate)
|
||||
{
|
||||
--m_split.second;
|
||||
}
|
||||
|
||||
ASSERT(m_split.first >= 0, ());
|
||||
ASSERT(m_split.second >= 0, ());
|
||||
|
||||
m_items.erase(m_items.begin() + GetStartIndexInGroup(group) + position);
|
||||
}
|
||||
|
||||
int ActiveMapsLayout::MoveItemToGroup(TGroup const & group, int position, TGroup const & newGroup)
|
||||
{
|
||||
Item item = GetItemInGroup(group, position);
|
||||
DeleteFromGroup(group, position);
|
||||
return InsertInGroup(newGroup, item);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::NotifyInsertion(TGroup const & group, int position)
|
||||
{
|
||||
for (TListenerNode listener : m_listeners)
|
||||
listener.second->CountryGroupChanged(group, -1, group, position);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::NotifyDeletion(TGroup const & group, int position)
|
||||
{
|
||||
for (TListenerNode listener : m_listeners)
|
||||
listener.second->CountryGroupChanged(group, position, group, -1);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::NotifyMove(TGroup const & oldGroup, int oldPosition,
|
||||
TGroup const & newGroup, int newPosition)
|
||||
{
|
||||
for (TListenerNode listener : m_listeners)
|
||||
listener.second->CountryGroupChanged(oldGroup, oldPosition, newGroup, newPosition);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::NotifyStatusChanged(TGroup const & group, int position,
|
||||
TStatus const & oldStatus, TStatus const & newStatus)
|
||||
{
|
||||
for (TListenerNode listener : m_listeners)
|
||||
listener.second->CountryStatusChanged(group, position, oldStatus, newStatus);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::NotifyOptionsChanged(TGroup const & group, int position,
|
||||
MapOptions const & oldOpt, MapOptions const & newOpt)
|
||||
{
|
||||
for (TListenerNode listener : m_listeners)
|
||||
listener.second->CountryOptionsChanged(group, position, oldOpt, newOpt);
|
||||
}
|
||||
|
||||
MapOptions ActiveMapsLayout::ValidOptionsForDownload(MapOptions const & options)
|
||||
{
|
||||
return SetOptions(options, MapOptions::Map);
|
||||
}
|
||||
|
||||
MapOptions ActiveMapsLayout::ValidOptionsForDelete(MapOptions const & options)
|
||||
{
|
||||
if (HasOptions(options, MapOptions::Map))
|
||||
return SetOptions(options, MapOptions::CarRouting);
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,183 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "storage/index.hpp"
|
||||
#include "storage/storage_defines.hpp"
|
||||
|
||||
#include "platform/country_defines.hpp"
|
||||
#include "platform/local_country_file.hpp"
|
||||
|
||||
#include "base/buffer_vector.hpp"
|
||||
|
||||
#include "std/function.hpp"
|
||||
#include "std/map.hpp"
|
||||
#include "std/shared_ptr.hpp"
|
||||
#include "std/string.hpp"
|
||||
#include "std/vector.hpp"
|
||||
|
||||
|
||||
class Framework;
|
||||
|
||||
namespace storage
|
||||
{
|
||||
|
||||
class Storage;
|
||||
class ActiveMapsLayout
|
||||
{
|
||||
public:
|
||||
enum class TGroup
|
||||
{
|
||||
ENewMap = 0,
|
||||
EOutOfDate = 1,
|
||||
EUpToDate = 2,
|
||||
EGroupCount = 3
|
||||
};
|
||||
|
||||
class ActiveMapsListener
|
||||
{
|
||||
public:
|
||||
virtual ~ActiveMapsListener(){}
|
||||
/// if some country been inserted than oldGroup == newGroup, and oldPosition == -1
|
||||
/// if some country been deleted than oldGroup == newGroup, and newPosition == -1
|
||||
/// if group of country been changed. than oldGroup != newGroup, oldPosition >= 0 and newPosition >= 0
|
||||
virtual void CountryGroupChanged(TGroup const & oldGroup, int oldPosition,
|
||||
TGroup const & newGroup, int newPosition) = 0;
|
||||
virtual void CountryStatusChanged(TGroup const & group, int position,
|
||||
TStatus const & oldStatus, TStatus const & newStatus) = 0;
|
||||
virtual void CountryOptionsChanged(TGroup const & group, int position,
|
||||
MapOptions const & oldOpt, MapOptions const & newOpt) = 0;
|
||||
virtual void DownloadingProgressUpdate(TGroup const & group, int position,
|
||||
LocalAndRemoteSizeT const & progress) = 0;
|
||||
};
|
||||
|
||||
ActiveMapsLayout(Framework & framework);
|
||||
~ActiveMapsLayout();
|
||||
|
||||
size_t GetSizeToUpdateAllInBytes() const;
|
||||
void UpdateAll();
|
||||
void CancelAll();
|
||||
|
||||
int GetOutOfDateCount() const;
|
||||
|
||||
int GetCountInGroup(TGroup const & group) const;
|
||||
bool IsEmpty() const;
|
||||
string const & GetCountryName(TGroup const & group, int position) const;
|
||||
string const & GetCountryName(storage::TIndex const & index) const;
|
||||
TStatus GetCountryStatus(TGroup const & group, int position) const;
|
||||
TStatus GetCountryStatus(storage::TIndex const & index) const;
|
||||
MapOptions GetCountryOptions(TGroup const & group, int position) const;
|
||||
MapOptions GetCountryOptions(storage::TIndex const & index) const;
|
||||
LocalAndRemoteSizeT const GetDownloadableCountrySize(TGroup const & group, int position) const;
|
||||
LocalAndRemoteSizeT const GetDownloadableCountrySize(TIndex const & index) const;
|
||||
LocalAndRemoteSizeT const GetCountrySize(TGroup const & group, int position, MapOptions const & options) const;
|
||||
LocalAndRemoteSizeT const GetCountrySize(TIndex const & index, MapOptions const & options) const;
|
||||
LocalAndRemoteSizeT const GetRemoteCountrySizes(TGroup const & group, int position) const;
|
||||
LocalAndRemoteSizeT const GetRemoteCountrySizes(TIndex const & index) const;
|
||||
|
||||
int AddListener(ActiveMapsListener * listener);
|
||||
void RemoveListener(int slotID);
|
||||
|
||||
void DownloadMap(TIndex const & index, MapOptions const & options);
|
||||
void DownloadMap(TGroup const & group, int position, MapOptions const & options);
|
||||
void DeleteMap(TIndex const & index, MapOptions const & options);
|
||||
void DeleteMap(TGroup const & group, int position, MapOptions const & options);
|
||||
void RetryDownloading(TGroup const & group, int position);
|
||||
void RetryDownloading(TIndex const & index);
|
||||
|
||||
///@{ For CountryStatus only
|
||||
TIndex const & GetCoreIndex(TGroup const & group, int position) const;
|
||||
string const GetFormatedCountryName(TIndex const & index) const;
|
||||
///@}
|
||||
|
||||
bool IsDownloadingActive() const;
|
||||
void CancelDownloading(TGroup const & group, int position);
|
||||
void CancelDownloading(TIndex const & index);
|
||||
|
||||
TIndex GetCurrentDownloadingCountryIndex() const;
|
||||
|
||||
void ShowMap(TGroup const & group, int position);
|
||||
|
||||
/// @param[in] Sorted vector of current .mwm files.
|
||||
using TLocalFilePtr = shared_ptr<platform::LocalCountryFile>;
|
||||
void Init(vector<TLocalFilePtr> const & files);
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
friend class CountryTree;
|
||||
Storage const & GetStorage() const;
|
||||
Storage & GetStorage();
|
||||
|
||||
void ShowMap(TIndex const & index);
|
||||
|
||||
void StatusChangedCallback(TIndex const & index);
|
||||
void ProgressChangedCallback(TIndex const & index, LocalAndRemoteSizeT const & sizes);
|
||||
|
||||
class Item
|
||||
{
|
||||
/// Usually, this vector has size = 1 and sometimes = 2.
|
||||
buffer_vector<TIndex, 1> m_indexes;
|
||||
|
||||
public:
|
||||
template <class TCont> Item(TCont const & cont,
|
||||
TStatus status,
|
||||
MapOptions options,
|
||||
MapOptions downloadRequest)
|
||||
: m_indexes(cont.begin(), cont.end()), m_status(status),
|
||||
m_options(options), m_downloadRequest(downloadRequest)
|
||||
{
|
||||
ASSERT(!m_indexes.empty(), ());
|
||||
}
|
||||
|
||||
/// Use this functions to compare Items by input TIndex.
|
||||
//@{
|
||||
bool IsEqual(TIndex const & index) const;
|
||||
bool IsEqual(Item const & item) const;
|
||||
//@}
|
||||
|
||||
/// Get any key TIndex for the correspondent Item.
|
||||
TIndex const & Index() const { return m_indexes[0]; }
|
||||
|
||||
TStatus m_status;
|
||||
MapOptions m_options;
|
||||
MapOptions m_downloadRequest;
|
||||
};
|
||||
|
||||
Item const & GetItemInGroup(TGroup const & group, int position) const;
|
||||
Item & GetItemInGroup(TGroup const & group, int position);
|
||||
int GetStartIndexInGroup(TGroup const & group) const;
|
||||
Item * FindItem(TIndex const & index);
|
||||
Item const * FindItem(TIndex const & index) const;
|
||||
bool GetGroupAndPositionByIndex(TIndex const & index, TGroup & group, int & position);
|
||||
|
||||
int InsertInGroup(TGroup const & group, Item const & item);
|
||||
void DeleteFromGroup(TGroup const & group, int position);
|
||||
int MoveItemToGroup(TGroup const & group, int position, TGroup const & newGroup);
|
||||
|
||||
void NotifyInsertion(TGroup const & group, int position);
|
||||
void NotifyDeletion(TGroup const & group, int position);
|
||||
void NotifyMove(TGroup const & oldGroup, int oldPosition,
|
||||
TGroup const & newGroup, int newPosition);
|
||||
|
||||
void NotifyStatusChanged(TGroup const & group, int position,
|
||||
TStatus const & oldStatus, TStatus const & newStatus);
|
||||
void NotifyOptionsChanged(TGroup const & group, int position,
|
||||
MapOptions const & oldOpt, MapOptions const & newOpt);
|
||||
|
||||
MapOptions ValidOptionsForDownload(MapOptions const & options);
|
||||
MapOptions ValidOptionsForDelete(MapOptions const & options);
|
||||
|
||||
private:
|
||||
Framework & m_framework;
|
||||
int m_subscribeSlotID = 0;
|
||||
typedef pair<int, ActiveMapsListener *> TListenerNode;
|
||||
map<int, ActiveMapsListener *> m_listeners;
|
||||
int m_currentSlotID = 0;
|
||||
|
||||
vector<Item> m_items;
|
||||
/// ENewMap - [0, TRangeSplit.first)
|
||||
/// EOutOfDate - [TRangeSplit.first, TRangeSplit.second)
|
||||
/// EUpToDate - [TRangeSplit.second, m_items.size)
|
||||
typedef pair<int, int> TRangeSplit;
|
||||
TRangeSplit m_split;
|
||||
};
|
||||
|
||||
}
|
|
@ -1,325 +0,0 @@
|
|||
#include "map/country_tree.hpp"
|
||||
|
||||
#include "map/framework.hpp"
|
||||
|
||||
#include "storage/storage.hpp"
|
||||
|
||||
namespace storage
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
int const kRootItemIndex = 0;
|
||||
int const kChildItemsOffset = 1;
|
||||
|
||||
inline TIndex GetIndexChild(TIndex const & index, int i)
|
||||
{
|
||||
TIndex child(index);
|
||||
if (child.m_group == TIndex::INVALID)
|
||||
child.m_group = i;
|
||||
else if (child.m_country == TIndex::INVALID)
|
||||
child.m_country = i;
|
||||
else if (child.m_region == TIndex::INVALID)
|
||||
child.m_region = i;
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
inline TIndex GetIndexParent(TIndex const & index)
|
||||
{
|
||||
ASSERT(index != TIndex(), ());
|
||||
TIndex parent(index);
|
||||
if (parent.m_region != TIndex::INVALID)
|
||||
parent.m_region = TIndex::INVALID;
|
||||
else if (parent.m_country != TIndex::INVALID)
|
||||
parent.m_country = TIndex::INVALID;
|
||||
else
|
||||
parent.m_group = TIndex::INVALID;
|
||||
|
||||
return parent;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CountryTree::CountryTree(shared_ptr<ActiveMapsLayout> activeMaps)
|
||||
{
|
||||
m_layout = activeMaps;
|
||||
ConnectToCoreStorage();
|
||||
}
|
||||
|
||||
CountryTree::~CountryTree()
|
||||
{
|
||||
DisconnectFromCoreStorage();
|
||||
}
|
||||
|
||||
CountryTree & CountryTree::operator=(CountryTree const & other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
DisconnectFromCoreStorage();
|
||||
m_levelItems = other.m_levelItems;
|
||||
m_listener = other.m_listener;
|
||||
m_layout = other.m_layout;
|
||||
ConnectToCoreStorage();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ActiveMapsLayout & CountryTree::GetActiveMapLayout()
|
||||
{
|
||||
ASSERT(IsValid(), ());
|
||||
return *m_layout;
|
||||
}
|
||||
|
||||
ActiveMapsLayout const & CountryTree::GetActiveMapLayout() const
|
||||
{
|
||||
ASSERT(IsValid(), ());
|
||||
return *m_layout;
|
||||
}
|
||||
|
||||
bool CountryTree::IsValid() const
|
||||
{
|
||||
return m_layout != nullptr;
|
||||
}
|
||||
|
||||
void CountryTree::SetDefaultRoot()
|
||||
{
|
||||
SetRoot(TIndex());
|
||||
}
|
||||
|
||||
void CountryTree::SetParentAsRoot()
|
||||
{
|
||||
ASSERT(HasParent(), ());
|
||||
SetRoot(GetIndexParent(GetCurrentRoot()));
|
||||
}
|
||||
|
||||
void CountryTree::SetChildAsRoot(int childPosition)
|
||||
{
|
||||
ASSERT(!IsLeaf(childPosition), ());
|
||||
SetRoot(GetChild(childPosition));
|
||||
}
|
||||
|
||||
void CountryTree::ResetRoot()
|
||||
{
|
||||
m_levelItems.clear();
|
||||
}
|
||||
|
||||
bool CountryTree::HasRoot() const
|
||||
{
|
||||
return !m_levelItems.empty();
|
||||
}
|
||||
|
||||
bool CountryTree::HasParent() const
|
||||
{
|
||||
return GetCurrentRoot() != TIndex();
|
||||
}
|
||||
|
||||
int CountryTree::GetChildCount() const
|
||||
{
|
||||
ASSERT(HasRoot(), ());
|
||||
return m_levelItems.size() - kChildItemsOffset;
|
||||
}
|
||||
|
||||
bool CountryTree::IsLeaf(int childPosition) const
|
||||
{
|
||||
return GetStorage().IsLeaf(GetChild(childPosition));
|
||||
}
|
||||
|
||||
string const & CountryTree::GetChildName(int position) const
|
||||
{
|
||||
return GetStorage().CountryName(GetChild(position));
|
||||
}
|
||||
|
||||
TStatus CountryTree::GetLeafStatus(int position) const
|
||||
{
|
||||
return GetStorage().CountryStatusEx(GetChild(position));
|
||||
}
|
||||
|
||||
MapOptions CountryTree::GetLeafOptions(int position) const
|
||||
{
|
||||
TStatus status;
|
||||
MapOptions options;
|
||||
GetStorage().CountryStatusEx(GetChild(position), status, options);
|
||||
return options;
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const CountryTree::GetDownloadableLeafSize(int position) const
|
||||
{
|
||||
return GetActiveMapLayout().GetDownloadableCountrySize(GetChild(position));
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const CountryTree::GetLeafSize(int position, MapOptions const & options) const
|
||||
{
|
||||
return GetActiveMapLayout().GetCountrySize(GetChild(position), options);
|
||||
}
|
||||
|
||||
LocalAndRemoteSizeT const CountryTree::GetRemoteLeafSizes(int position) const
|
||||
{
|
||||
return GetActiveMapLayout().GetRemoteCountrySizes(GetChild(position));
|
||||
}
|
||||
|
||||
bool CountryTree::IsCountryRoot() const
|
||||
{
|
||||
TIndex index = GetCurrentRoot();
|
||||
ASSERT(index.m_region == TIndex::INVALID, ());
|
||||
if (index.m_country != TIndex::INVALID)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
string const & CountryTree::GetRootName() const
|
||||
{
|
||||
return GetStorage().CountryName(GetCurrentRoot());
|
||||
}
|
||||
|
||||
void CountryTree::DownloadCountry(int childPosition, MapOptions const & options)
|
||||
{
|
||||
ASSERT(IsLeaf(childPosition), ());
|
||||
GetActiveMapLayout().DownloadMap(GetChild(childPosition), options);
|
||||
}
|
||||
|
||||
void CountryTree::DeleteCountry(int childPosition, MapOptions const & options)
|
||||
{
|
||||
ASSERT(IsLeaf(childPosition), ());
|
||||
GetActiveMapLayout().DeleteMap(GetChild(childPosition), options);
|
||||
}
|
||||
|
||||
void CountryTree::RetryDownloading(int childPosition)
|
||||
{
|
||||
ASSERT(IsLeaf(childPosition), ());
|
||||
GetActiveMapLayout().RetryDownloading(GetChild(childPosition));
|
||||
}
|
||||
|
||||
void CountryTree::DownloadAllImpl(TIndex const & localRootIndex)
|
||||
{
|
||||
if (GetStorage().IsLeaf(localRootIndex))
|
||||
{
|
||||
GetActiveMapLayout().DownloadMap(localRootIndex, MapOptions::Map);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t const childCount = GetStorage().CountriesCount(localRootIndex);
|
||||
for (size_t i = 0; i < childCount; ++i)
|
||||
{
|
||||
TIndex const child = GetIndexChild(localRootIndex, i);
|
||||
ASSERT_NOT_EQUAL(localRootIndex, child, ());
|
||||
DownloadAllImpl(child);
|
||||
}
|
||||
}
|
||||
|
||||
void CountryTree::DownloadAll()
|
||||
{
|
||||
DownloadAllImpl(GetCurrentRoot());
|
||||
}
|
||||
|
||||
bool CountryTree::IsDownloadAllAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CountryTree::CancelDownloading(int childPosition)
|
||||
{
|
||||
GetStorage().DeleteFromDownloader(GetChild(childPosition));
|
||||
}
|
||||
|
||||
void CountryTree::SetListener(CountryTreeListener * listener)
|
||||
{
|
||||
m_listener = listener;
|
||||
}
|
||||
|
||||
void CountryTree::ResetListener()
|
||||
{
|
||||
m_listener = nullptr;
|
||||
}
|
||||
|
||||
void CountryTree::ShowLeafOnMap(int position)
|
||||
{
|
||||
ASSERT(IsLeaf(position), ());
|
||||
GetActiveMapLayout().ShowMap(GetChild(position));
|
||||
}
|
||||
|
||||
Storage const & CountryTree::GetStorage() const
|
||||
{
|
||||
ASSERT(IsValid(), ());
|
||||
return m_layout->GetStorage();
|
||||
}
|
||||
|
||||
Storage & CountryTree::GetStorage()
|
||||
{
|
||||
ASSERT(IsValid(), ());
|
||||
return m_layout->GetStorage();
|
||||
}
|
||||
|
||||
void CountryTree::ConnectToCoreStorage()
|
||||
{
|
||||
if (IsValid())
|
||||
{
|
||||
m_subscribeSlotID = GetStorage().Subscribe(bind(&CountryTree::NotifyStatusChanged, this, _1),
|
||||
bind(&CountryTree::NotifyProgressChanged, this, _1, _2));
|
||||
}
|
||||
}
|
||||
|
||||
void CountryTree::DisconnectFromCoreStorage()
|
||||
{
|
||||
if (IsValid())
|
||||
GetStorage().Unsubscribe(m_subscribeSlotID);
|
||||
}
|
||||
|
||||
TIndex const & CountryTree::GetCurrentRoot() const
|
||||
{
|
||||
ASSERT(HasRoot(), ());
|
||||
return m_levelItems[kRootItemIndex];
|
||||
}
|
||||
|
||||
void CountryTree::SetRoot(TIndex index)
|
||||
{
|
||||
ResetRoot();
|
||||
|
||||
size_t const count = GetStorage().CountriesCount(index);
|
||||
m_levelItems.reserve(kChildItemsOffset + count);
|
||||
m_levelItems.push_back(index);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
m_levelItems.push_back(GetIndexChild(index, i));
|
||||
}
|
||||
|
||||
TIndex const & CountryTree::GetChild(int childPosition) const
|
||||
{
|
||||
ASSERT(childPosition < GetChildCount(), ());
|
||||
return m_levelItems[kChildItemsOffset + childPosition];
|
||||
}
|
||||
|
||||
int CountryTree::GetChildPosition(TIndex const & index)
|
||||
{
|
||||
int result = -1;
|
||||
if (HasRoot())
|
||||
{
|
||||
auto iter = find(m_levelItems.begin(), m_levelItems.end(), index);
|
||||
if (iter != m_levelItems.end())
|
||||
result = distance(m_levelItems.begin(), iter) - kChildItemsOffset;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CountryTree::NotifyStatusChanged(TIndex const & index)
|
||||
{
|
||||
if (m_listener != nullptr)
|
||||
{
|
||||
int position = GetChildPosition(index);
|
||||
if (position != -1)
|
||||
m_listener->ItemStatusChanged(position);
|
||||
}
|
||||
}
|
||||
|
||||
void CountryTree::NotifyProgressChanged(TIndex const & index, LocalAndRemoteSizeT const & sizes)
|
||||
{
|
||||
if (m_listener != nullptr)
|
||||
{
|
||||
int position = GetChildPosition(index);
|
||||
if (position != -1)
|
||||
m_listener->ItemProgressChanged(position, sizes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "map/active_maps_layout.hpp"
|
||||
|
||||
#include "storage/index.hpp"
|
||||
#include "storage/storage_defines.hpp"
|
||||
|
||||
#include "platform/local_country_file.hpp"
|
||||
|
||||
#include "base/buffer_vector.hpp"
|
||||
|
||||
#include "std/function.hpp"
|
||||
#include "std/shared_ptr.hpp"
|
||||
#include "std/string.hpp"
|
||||
|
||||
|
||||
class Framework;
|
||||
|
||||
namespace storage
|
||||
{
|
||||
|
||||
class Storage;
|
||||
class CountryTree
|
||||
{
|
||||
public:
|
||||
class CountryTreeListener
|
||||
{
|
||||
public:
|
||||
virtual void ItemStatusChanged(int childPosition) = 0;
|
||||
virtual void ItemProgressChanged(int childPosition, LocalAndRemoteSizeT const & sizes) = 0;
|
||||
};
|
||||
|
||||
CountryTree() = default;
|
||||
explicit CountryTree(shared_ptr<ActiveMapsLayout> activeMaps);
|
||||
|
||||
CountryTree(CountryTree const & other) = delete;
|
||||
~CountryTree();
|
||||
|
||||
CountryTree & operator=(CountryTree const & other);
|
||||
|
||||
ActiveMapsLayout & GetActiveMapLayout();
|
||||
ActiveMapsLayout const & GetActiveMapLayout() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void SetDefaultRoot();
|
||||
void SetParentAsRoot();
|
||||
void SetChildAsRoot(int childPosition);
|
||||
void ResetRoot();
|
||||
bool HasRoot() const;
|
||||
|
||||
bool HasParent() const;
|
||||
|
||||
int GetChildCount() const;
|
||||
bool IsLeaf(int childPosition) const;
|
||||
string const & GetChildName(int position) const;
|
||||
/// call this only if child IsLeaf == true
|
||||
TStatus GetLeafStatus(int position) const;
|
||||
MapOptions GetLeafOptions(int position) const;
|
||||
LocalAndRemoteSizeT const GetDownloadableLeafSize(int position) const;
|
||||
LocalAndRemoteSizeT const GetLeafSize(int position, MapOptions const & options) const;
|
||||
LocalAndRemoteSizeT const GetRemoteLeafSizes(int position) const;
|
||||
bool IsCountryRoot() const;
|
||||
string const & GetRootName() const;
|
||||
|
||||
///@{
|
||||
void DownloadCountry(int childPosition, MapOptions const & options);
|
||||
void DeleteCountry(int childPosition, MapOptions const & options);
|
||||
void RetryDownloading(int childPosition);
|
||||
void DownloadAll();
|
||||
bool IsDownloadAllAvailable();
|
||||
///@}
|
||||
void CancelDownloading(int childPosition);
|
||||
|
||||
void SetListener(CountryTreeListener * listener);
|
||||
void ResetListener();
|
||||
|
||||
void ShowLeafOnMap(int position);
|
||||
|
||||
private:
|
||||
Storage const & GetStorage() const;
|
||||
Storage & GetStorage();
|
||||
void ConnectToCoreStorage();
|
||||
void DisconnectFromCoreStorage();
|
||||
|
||||
private:
|
||||
void DownloadAllImpl(TIndex const & index);
|
||||
TIndex const & GetCurrentRoot() const;
|
||||
void SetRoot(TIndex index);
|
||||
TIndex const & GetChild(int childPosition) const;
|
||||
int GetChildPosition(TIndex const & index);
|
||||
|
||||
void NotifyStatusChanged(TIndex const & index);
|
||||
void NotifyProgressChanged(TIndex const & index, LocalAndRemoteSizeT const & sizes);
|
||||
|
||||
private:
|
||||
int m_subscribeSlotID = 0;
|
||||
shared_ptr<ActiveMapsLayout> m_layout;
|
||||
|
||||
buffer_vector<TIndex, 16> m_levelItems;
|
||||
|
||||
CountryTreeListener * m_listener = nullptr;
|
||||
};
|
||||
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
#include "map/ge0_parser.hpp"
|
||||
#include "map/geourl_process.hpp"
|
||||
#include "map/gps_tracker.hpp"
|
||||
#include "map/storage_bridge.hpp"
|
||||
|
||||
#include "defines.hpp"
|
||||
|
||||
|
@ -255,10 +254,6 @@ Framework::Framework()
|
|||
: m_bmManager(*this)
|
||||
, m_fixedSearchResults(0)
|
||||
{
|
||||
m_activeMaps.reset(new ActiveMapsLayout(*this));
|
||||
m_globalCntTree = storage::CountryTree(m_activeMaps);
|
||||
m_storageBridge = make_unique_dp<StorageBridge>(m_activeMaps, bind(&Framework::UpdateCountryInfo, this, _1, false));
|
||||
|
||||
// Restore map style before classificator loading
|
||||
int mapStyle = MapStyleLight;
|
||||
if (!Settings::Get(kMapStyleKey, mapStyle))
|
||||
|
@ -368,8 +363,6 @@ Framework::~Framework()
|
|||
{
|
||||
m_drapeEngine.reset();
|
||||
|
||||
m_storageBridge.reset();
|
||||
m_activeMaps.reset();
|
||||
m_model.SetOnMapDeregisteredCallback(nullptr);
|
||||
}
|
||||
|
||||
|
@ -559,14 +552,11 @@ void Framework::RegisterAllMaps()
|
|||
minFormat = min(minFormat, static_cast<int>(id.GetInfo()->m_version.format));
|
||||
}
|
||||
|
||||
m_activeMaps->Init(maps);
|
||||
|
||||
m_searchEngine->SetSupportOldFormat(minFormat < static_cast<int>(version::Format::v3));
|
||||
}
|
||||
|
||||
void Framework::DeregisterAllMaps()
|
||||
{
|
||||
m_activeMaps->Clear();
|
||||
m_model.Clear();
|
||||
m_storage.Clear();
|
||||
}
|
||||
|
@ -924,29 +914,16 @@ void Framework::SetAutoDownloadListener(TAutoDownloadListener const & listener)
|
|||
|
||||
void Framework::OnDownloadMapCallback(storage::TIndex const & countryIndex)
|
||||
{
|
||||
if (m_downloadCountryListener != nullptr)
|
||||
m_downloadCountryListener(countryIndex, static_cast<int>(MapOptions::Map));
|
||||
else
|
||||
m_activeMaps->DownloadMap(countryIndex, MapOptions::Map);
|
||||
}
|
||||
|
||||
void Framework::OnDownloadRetryCallback(storage::TIndex const & countryIndex)
|
||||
{
|
||||
if (m_downloadCountryListener != nullptr)
|
||||
m_downloadCountryListener(countryIndex, -1 /* option for retry downloading */);
|
||||
else
|
||||
m_activeMaps->RetryDownloading(countryIndex);
|
||||
}
|
||||
|
||||
void Framework::OnDownloadCancelCallback(storage::TIndex const & countryIndex)
|
||||
{
|
||||
// Any cancel leads to disable auto-downloading.
|
||||
m_autoDownloadingOn = false;
|
||||
|
||||
if (m_downloadCancelListener != nullptr)
|
||||
m_downloadCancelListener(countryIndex);
|
||||
else
|
||||
m_activeMaps->CancelDownloading(countryIndex);
|
||||
}
|
||||
|
||||
void Framework::OnUpdateCountryIndex(storage::TIndex const & currentIndex, m2::PointF const & pt)
|
||||
|
@ -969,8 +946,6 @@ void Framework::OnUpdateCountryIndex(storage::TIndex const & currentIndex, m2::P
|
|||
|
||||
void Framework::UpdateCountryInfo(storage::TIndex const & countryIndex, bool isCurrentCountry)
|
||||
{
|
||||
ASSERT(m_activeMaps != nullptr, ());
|
||||
|
||||
if (!m_drapeEngine)
|
||||
return;
|
||||
|
||||
|
@ -984,15 +959,8 @@ void Framework::UpdateCountryInfo(storage::TIndex const & countryIndex, bool isC
|
|||
gui::CountryInfo countryInfo;
|
||||
|
||||
countryInfo.m_countryIndex = countryIndex;
|
||||
countryInfo.m_currentCountryName = m_activeMaps->GetFormatedCountryName(countryIndex);
|
||||
countryInfo.m_mapSize = m_activeMaps->GetRemoteCountrySizes(countryIndex).first;
|
||||
countryInfo.m_showMapSize = !platform::migrate::NeedMigrate();
|
||||
countryInfo.m_countryStatus = m_activeMaps->GetCountryStatus(countryIndex);
|
||||
if (countryInfo.m_countryStatus == storage::TStatus::EDownloading)
|
||||
{
|
||||
storage::LocalAndRemoteSizeT progress = m_activeMaps->GetDownloadableCountrySize(countryIndex);
|
||||
countryInfo.m_downloadProgress = progress.first * 100 / progress.second;
|
||||
}
|
||||
countryInfo.m_downloadProgress = 50;
|
||||
|
||||
m_drapeEngine->SetCountryInfo(countryInfo, isCurrentCountry);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "map/active_maps_layout.hpp"
|
||||
#include "map/api_mark_point.hpp"
|
||||
#include "map/bookmark.hpp"
|
||||
#include "map/bookmark_manager.hpp"
|
||||
#include "map/country_tree.hpp"
|
||||
#include "map/feature_vec_model.hpp"
|
||||
#include "map/mwm_url.hpp"
|
||||
#include "map/track.hpp"
|
||||
|
@ -119,7 +117,6 @@ protected:
|
|||
|
||||
routing::RoutingSession m_routingSession;
|
||||
|
||||
drape_ptr<StorageBridge> m_storageBridge;
|
||||
drape_ptr<df::DrapeEngine> m_drapeEngine;
|
||||
drape_ptr<df::watch::CPUDrawer> m_cpuDrawer;
|
||||
|
||||
|
@ -131,8 +128,6 @@ protected:
|
|||
bool m_autoDownloadingOn = true;
|
||||
|
||||
storage::Storage m_storage;
|
||||
shared_ptr<storage::ActiveMapsLayout> m_activeMaps;
|
||||
storage::CountryTree m_globalCntTree;
|
||||
|
||||
location::TMyPositionModeChanged m_myPositionListener;
|
||||
|
||||
|
@ -232,8 +227,6 @@ public:
|
|||
//@}
|
||||
|
||||
storage::Storage & Storage() { return m_storage; }
|
||||
shared_ptr<storage::ActiveMapsLayout> & GetActiveMaps() { return m_activeMaps; }
|
||||
storage::CountryTree & GetCountryTree() { return m_globalCntTree; }
|
||||
|
||||
/// @name Bookmarks, Tracks and other UserMarks
|
||||
//@{
|
||||
|
|
|
@ -11,12 +11,10 @@ INCLUDEPATH *= $$ROOT_DIR/3party/protobuf/src $$ROOT_DIR/3party/freetype/include
|
|||
include($$ROOT_DIR/common.pri)
|
||||
|
||||
HEADERS += \
|
||||
active_maps_layout.hpp \
|
||||
api_mark_container.hpp \
|
||||
api_mark_point.hpp \
|
||||
bookmark.hpp \
|
||||
bookmark_manager.hpp \
|
||||
country_tree.hpp \
|
||||
feature_vec_model.hpp \
|
||||
framework.hpp \
|
||||
ge0_parser.hpp \
|
||||
|
@ -27,7 +25,6 @@ HEADERS += \
|
|||
gps_track_storage.hpp \
|
||||
gps_tracker.hpp \
|
||||
mwm_url.hpp \
|
||||
storage_bridge.hpp \
|
||||
styled_point.hpp \
|
||||
track.hpp \
|
||||
user_mark.hpp \
|
||||
|
@ -35,12 +32,10 @@ HEADERS += \
|
|||
|
||||
SOURCES += \
|
||||
../api/src/c/api-client.c \
|
||||
active_maps_layout.cpp \
|
||||
address_finder.cpp \
|
||||
api_mark_container.cpp \
|
||||
bookmark.cpp \
|
||||
bookmark_manager.cpp \
|
||||
country_tree.cpp \
|
||||
feature_vec_model.cpp \
|
||||
framework.cpp \
|
||||
ge0_parser.cpp \
|
||||
|
@ -51,7 +46,6 @@ SOURCES += \
|
|||
gps_track_storage.cpp \
|
||||
gps_tracker.cpp \
|
||||
mwm_url.cpp \
|
||||
storage_bridge.cpp \
|
||||
styled_point.cpp \
|
||||
track.cpp \
|
||||
user_mark.cpp \
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
#include "storage_bridge.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/macros.hpp"
|
||||
|
||||
using namespace storage;
|
||||
|
||||
StorageBridge::StorageBridge(shared_ptr<storage::ActiveMapsLayout> activeMaps, TOnChangedHandler const & handler)
|
||||
: m_activeMaps(activeMaps)
|
||||
, m_handler(handler)
|
||||
{
|
||||
ASSERT(m_activeMaps != nullptr, ());
|
||||
m_slot = m_activeMaps->AddListener(this);
|
||||
}
|
||||
|
||||
StorageBridge::~StorageBridge()
|
||||
{
|
||||
m_activeMaps->RemoveListener(m_slot);
|
||||
}
|
||||
|
||||
void StorageBridge::CountryGroupChanged(ActiveMapsLayout::TGroup const & oldGroup, int oldPosition,
|
||||
ActiveMapsLayout::TGroup const & newGroup, int newPosition)
|
||||
{
|
||||
UNUSED_VALUE(oldGroup);
|
||||
UNUSED_VALUE(oldPosition);
|
||||
UNUSED_VALUE(newGroup);
|
||||
UNUSED_VALUE(newPosition);
|
||||
}
|
||||
|
||||
void StorageBridge::CountryStatusChanged(ActiveMapsLayout::TGroup const & group, int position,
|
||||
TStatus const & oldStatus, TStatus const & newStatus)
|
||||
{
|
||||
UNUSED_VALUE(oldStatus);
|
||||
UNUSED_VALUE(newStatus);
|
||||
ReportChanges(group, position);
|
||||
}
|
||||
|
||||
void StorageBridge::CountryOptionsChanged(ActiveMapsLayout::TGroup const & group, int position,
|
||||
MapOptions const & oldOpt, MapOptions const & newOpt)
|
||||
{
|
||||
UNUSED_VALUE(group);
|
||||
UNUSED_VALUE(position);
|
||||
UNUSED_VALUE(oldOpt);
|
||||
UNUSED_VALUE(newOpt);
|
||||
}
|
||||
|
||||
void StorageBridge::DownloadingProgressUpdate(ActiveMapsLayout::TGroup const & group, int position,
|
||||
LocalAndRemoteSizeT const & progress)
|
||||
{
|
||||
UNUSED_VALUE(progress);
|
||||
ReportChanges(group, position);
|
||||
}
|
||||
|
||||
void StorageBridge::ReportChanges(ActiveMapsLayout::TGroup const & group, int position)
|
||||
{
|
||||
storage::TIndex countryIndex = m_activeMaps->GetCoreIndex(group, position);
|
||||
|
||||
if (m_handler != nullptr)
|
||||
GetPlatform().RunOnGuiThread(bind(m_handler, countryIndex));
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "active_maps_layout.hpp"
|
||||
|
||||
#include "storage/index.hpp"
|
||||
#include "storage/storage_defines.hpp"
|
||||
|
||||
#include "std/shared_ptr.hpp"
|
||||
|
||||
class StorageBridge : public storage::ActiveMapsLayout::ActiveMapsListener
|
||||
{
|
||||
public:
|
||||
using TOnChangedHandler = function<void(storage::TIndex const & /*countryIndex*/)>;
|
||||
|
||||
StorageBridge(shared_ptr<storage::ActiveMapsLayout> activeMaps, TOnChangedHandler const & handler);
|
||||
~StorageBridge() override;
|
||||
|
||||
void CountryGroupChanged(storage::ActiveMapsLayout::TGroup const & oldGroup, int oldPosition,
|
||||
storage::ActiveMapsLayout::TGroup const & newGroup, int newPosition) override;
|
||||
void CountryStatusChanged(storage::ActiveMapsLayout::TGroup const & group, int position,
|
||||
storage::TStatus const & oldStatus, storage::TStatus const & newStatus) override;
|
||||
void CountryOptionsChanged(storage::ActiveMapsLayout::TGroup const & group, int position,
|
||||
MapOptions const & oldOpt, MapOptions const & newOpt) override;
|
||||
void DownloadingProgressUpdate(storage::ActiveMapsLayout::TGroup const & group, int position,
|
||||
storage::LocalAndRemoteSizeT const & progress) override;
|
||||
|
||||
private:
|
||||
shared_ptr<storage::ActiveMapsLayout> m_activeMaps;
|
||||
TOnChangedHandler m_handler;
|
||||
int m_slot;
|
||||
|
||||
void ReportChanges(storage::ActiveMapsLayout::TGroup const & group, int position);
|
||||
};
|
||||
|
|
@ -130,61 +130,6 @@ namespace qt
|
|||
// skip group items
|
||||
if (st.CountriesCount(countryIndex) > 0)
|
||||
return;
|
||||
|
||||
switch (m_framework.GetActiveMaps()->GetCountryStatus(countryIndex))
|
||||
{
|
||||
case TStatus::EOnDiskOutOfDate:
|
||||
{
|
||||
// map is already downloaded, so ask user about deleting!
|
||||
QMessageBox ask(this);
|
||||
ask.setIcon(QMessageBox::Question);
|
||||
ask.setText(tr("Do you want to update or delete %1?").arg(item->text(KColumnIndexCountry)));
|
||||
|
||||
QPushButton * btns[3];
|
||||
btns[0] = ask.addButton(tr("Update"), QMessageBox::ActionRole);
|
||||
btns[1] = ask.addButton(tr("Delete"), QMessageBox::ActionRole);
|
||||
btns[2] = ask.addButton(tr("Cancel"), QMessageBox::NoRole);
|
||||
|
||||
(void)ask.exec();
|
||||
|
||||
QAbstractButton * res = ask.clickedButton();
|
||||
|
||||
if (res == btns[0])
|
||||
m_framework.GetActiveMaps()->DownloadMap(countryIndex, MapOptions::MapWithCarRouting);
|
||||
|
||||
if (res == btns[1])
|
||||
m_framework.GetActiveMaps()->DeleteMap(countryIndex, MapOptions::MapWithCarRouting);
|
||||
}
|
||||
break;
|
||||
|
||||
case TStatus::EOnDisk:
|
||||
{
|
||||
// map is already downloaded, so ask user about deleting!
|
||||
QMessageBox ask(this);
|
||||
ask.setIcon(QMessageBox::Question);
|
||||
ask.setText(tr("Do you want to delete %1?").arg(item->text(KColumnIndexCountry)));
|
||||
ask.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
ask.setDefaultButton(QMessageBox::No);
|
||||
|
||||
if (ask.exec() == QMessageBox::Yes)
|
||||
m_framework.GetActiveMaps()->DeleteMap(countryIndex, MapOptions::MapWithCarRouting);
|
||||
}
|
||||
break;
|
||||
|
||||
case TStatus::ENotDownloaded:
|
||||
case TStatus::EDownloadFailed:
|
||||
m_framework.GetActiveMaps()->DownloadMap(countryIndex, MapOptions::MapWithCarRouting);
|
||||
break;
|
||||
|
||||
case TStatus::EInQueue:
|
||||
case TStatus::EDownloading:
|
||||
m_framework.GetActiveMaps()->DeleteMap(countryIndex, MapOptions::MapWithCarRouting);
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERT(false, ("We shouldn't be here"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QTreeWidgetItem * MatchedItem(QTreeWidgetItem & parent, int index)
|
||||
|
|
Loading…
Add table
Reference in a new issue