[iPhone] Added "Download failed" status in GUI

This commit is contained in:
Alex Zolotarev 2011-01-06 02:39:01 +02:00 committed by Alex Zolotarev
parent 1e23c6a072
commit 87fc869a56
4 changed files with 27 additions and 6 deletions

View file

@ -123,6 +123,7 @@ static NSInteger RowFromIndex(TIndex const & index)
case EDownloading:
{
cell.textLabel.textColor = [UIColor blueColor];
cell.detailTextLabel.text = @"Downloading...";
if (!indicator)
{
indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray];

View file

@ -57,20 +57,20 @@ using namespace storage;
g_navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
// tricky boost::bind for objC class methods
typedef void (*TChangeFunc)(SEL, TIndex const &);
typedef void (*TChangeFunc)(id, SEL, TIndex const &);
SEL changeSel = @selector(OnCountryChange:);
TChangeFunc changeImpl = (TChangeFunc)[self methodForSelector:changeSel];
typedef void (*TProgressFunc)(SEL, TIndex const &, TDownloadProgress const &);
typedef void (*TProgressFunc)(id, SEL, TIndex const &, TDownloadProgress const &);
SEL progressSel = @selector(OnCountryDownload:withProgress:);
TProgressFunc progressImpl = (TProgressFunc)[self methodForSelector:progressSel];
typedef void (*TUpdateFunc)(SEL, int64_t, char const *);
typedef void (*TUpdateFunc)(id, SEL, int64_t, char const *);
SEL updateSel = @selector(OnUpdateCheck:);
TUpdateFunc updateImpl = (TUpdateFunc)[self methodForSelector:updateSel];
storage.Subscribe(boost::bind(changeImpl, changeSel, _1),
boost::bind(progressImpl, progressSel, _1, _2), boost::bind(updateImpl, updateSel, _1, _2));
storage.Subscribe(boost::bind(changeImpl, self, changeSel, _1),
boost::bind(progressImpl, self, progressSel, _1, _2), boost::bind(updateImpl, self, updateSel, _1, _2));
}
[parentController presentModalViewController:g_navController animated:YES];

View file

@ -85,6 +85,10 @@ namespace storage
return EInQueue;
}
// second, check if this country has failed while downloading
if (m_failedCountries.find(index) != m_failedCountries.end())
return EDownloadFailed;
TLocalAndRemoteSize size = CountryByIndex(index).Size();
if (size.first == size.second)
{
@ -105,7 +109,9 @@ namespace storage
{ // do nothing
return;
}
// otherwise add it into the queue
// remove it from failed list
m_failedCountries.erase(index);
// add it into the queue
m_queue.push_back(index);
// and start download if necessary
if (m_queue.size() == 1)
@ -280,6 +286,7 @@ namespace storage
// remove failed country from the queue
TIndex failedIndex = m_queue.front();
m_queue.pop_front();
m_failedCountries.insert(failedIndex);
// notify GUI about failed country
if (m_observerChange)
m_observerChange(failedIndex);

View file

@ -10,6 +10,7 @@
#include "../std/map.hpp"
#include "../std/list.hpp"
#include "../std/string.hpp"
#include "../std/set.hpp"
#include <boost/function.hpp>
@ -37,6 +38,14 @@ namespace storage
{
return m_group == other.m_group && m_country == other.m_country && m_region == other.m_region;
}
bool operator<(TIndex const & other) const
{
if (m_group != other.m_group)
return m_group < other.m_group;
else if (m_country != other.m_country)
return m_country < other.m_country;
return m_region < other.m_region;
}
};
/// Can be used to store local maps and/or maps available for download
@ -52,6 +61,10 @@ namespace storage
/// used to correctly calculate total country download progress
TDownloadProgress m_countryProgress;
typedef set<TIndex> TFailedCountries;
/// stores countries which download has failed recently
TFailedCountries m_failedCountries;
/// @name Communicate with GUI
//@{
typedef boost::function<void (TIndex const &)> TObserverChangeCountryFunction;