From 96c556e962bba2845d0e39c0ec7c98637725daae Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 29 Dec 2011 04:47:35 +0300 Subject: [PATCH] [search] Add EGeneratingIndex status for country. --- .../Maps/Settings/CountriesViewController.mm | 53 +++++++++++++------ qt/update_dialog.cpp | 18 +++++-- storage/storage.cpp | 39 +++++++++----- storage/storage.hpp | 21 +++++--- 4 files changed, 92 insertions(+), 39 deletions(-) diff --git a/iphone/Maps/Settings/CountriesViewController.mm b/iphone/Maps/Settings/CountriesViewController.mm index a314d1d9f4..96f871a5ae 100644 --- a/iphone/Maps/Settings/CountriesViewController.mm +++ b/iphone/Maps/Settings/CountriesViewController.mm @@ -179,14 +179,25 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours) green:43.f/255.f blue:182.f/255.f alpha:1.f]; - cell.detailTextLabel.text = NSLocalizedString(@"Downloading...", @"Settings/Downloader - info for country which started downloading"); + cell.detailTextLabel.text = NSLocalizedString(@"Downloading ...", @"Settings/Downloader - info for country which started downloading"); UIActivityIndicatorView * indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray]; cell.accessoryView = indicator; [indicator startAnimating]; [indicator release]; + break; + } + + case EGeneratingIndex: + { + cell.textLabel.textColor = [UIColor colorWithRed:52.f/255.f + green:43.f/255.f + blue:182.f/255.f + alpha:1.f]; + cell.detailTextLabel.text = NSLocalizedString(@"Generating search index ...", + @"Settings/Downloader - info for country which started downloading"); + break; } - break; case EDownloadFailed: cell.textLabel.textColor = [UIColor redColor]; @@ -249,7 +260,8 @@ UITableViewCell * g_clickedCell = nil; - (void) actionSheet: (UIActionSheet *) actionSheet clickedButtonAtIndex: (NSInteger) buttonIndex { if (buttonIndex == 0) - { // Delete country + { + // Delete country switch (m_storage->CountryStatus(g_clickedIndex)) { case ENotDownloaded: @@ -335,8 +347,9 @@ UITableViewCell * g_clickedCell = nil; destructiveButtonTitle: NSLocalizedString(@"Delete", @"Settings/Downloader - Delete country dialog - Confirm deletion button") otherButtonTitles: nil] autorelease]; [popupQuery showFromRect: [cell frame] inView: tableView animated: YES]; + break; } - break; + case ENotDownloaded: case EDownloadFailed: { @@ -345,7 +358,8 @@ UITableViewCell * g_clickedCell = nil; // check for disk free space first if (FreeDiskSpaceInBytes() < (size + 1024*1024)) - { // display warning dialog about not enough free disk space + { + // display warning dialog about not enough free disk space [[[[CustomAlertView alloc] initWithTitle:NSLocalizedString(@"There is not enough free disk space", @"Settings/Downloader - No free space dialog title") message:[NSString stringWithFormat:NSLocalizedString(@"Please free some space on your device first in order to download %@", @"Settings/Downloader - No free space dialog message"), countryName] delegate:nil @@ -356,7 +370,8 @@ UITableViewCell * g_clickedCell = nil; TActiveConnectionType const connType = GetActiveConnectionType(); if (connType == ENotConnected) - { // do not initiate any download + { + // do not initiate any download [[[[CustomAlertView alloc] initWithTitle:NSLocalizedString(@"No Internet connection detected", @"Settings/Downloader - No internet connection dialog title") message:NSLocalizedString(@"We recommend using WiFi to download large maps", @"Settings/Downloader - No internet connection dialog message") delegate:nil @@ -366,7 +381,8 @@ UITableViewCell * g_clickedCell = nil; else { if (connType == EConnectedBy3G && size > MAX_3G_MEGABYTES * MB) - { // If user uses 3G, show warning to him before downloading country + { + // If user uses 3G, show warning to him before downloading country [[[[CustomAlertView alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"No WiFi connection detected. Would you like to use cellular data (GPRS, EDGE or 3G) to download %@?", @"Settings/Downloader - 3G download warning dialog title"), countryName] message:nil delegate:self @@ -376,10 +392,12 @@ UITableViewCell * g_clickedCell = nil; else [self showDownloadCountryConfirmation:countryName withSize:size fromRect:[cell frame]]; } + break; } - break; + case EDownloading: - { // display confirmation popup + { + // display confirmation popup UIActionSheet * popupQuery = [[UIActionSheet alloc] initWithTitle: countryName delegate: self @@ -388,14 +406,17 @@ UITableViewCell * g_clickedCell = nil; otherButtonTitles: nil]; [popupQuery showFromRect: [cell frame] inView: tableView animated: YES]; [popupQuery release]; + break; } - break; - case EInQueue: - // cancel download - m_storage->DeleteCountry(index); - break; - default: - break; + + case EInQueue: + // cancel download + m_storage->DeleteCountry(index); + break; + + case EGeneratingIndex: + // we can't stop index generation at this moment + break; } } } diff --git a/qt/update_dialog.cpp b/qt/update_dialog.cpp index cda4080b8c..51c657254e 100644 --- a/qt/update_dialog.cpp +++ b/qt/update_dialog.cpp @@ -115,7 +115,8 @@ namespace qt switch (m_storage.CountryStatus(countryIndex)) { case EOnDisk: - { // aha.. map is already downloaded, so ask user about deleting! + { + // map is already downloaded, so ask user about deleting! QMessageBox ask(this); ask.setText(tr("Do you want to delete %1?").arg(item->text(KColumnIndexCountry))); ask.setStandardButtons(QMessageBox::Yes | QMessageBox::No); @@ -135,7 +136,8 @@ namespace qt m_storage.DeleteCountry(countryIndex); break; - default: + case EGeneratingIndex: + // we can't stop index genertion at this moment break; } } @@ -206,28 +208,36 @@ namespace qt rowColor = COLOR_NOTDOWNLOADED; size = m_storage.CountrySizeInBytes(index); break; + case EOnDisk: statusString = tr("Installed (click to delete)"); rowColor = COLOR_ONDISK; size = m_storage.CountrySizeInBytes(index); break; + case EDownloadFailed: statusString = tr("Download has failed"); rowColor = COLOR_DOWNLOADFAILED; size = m_storage.CountrySizeInBytes(index); break; + case EDownloading: - statusString = tr("Downloading..."); + statusString = tr("Downloading ..."); rowColor = COLOR_INPROGRESS; break; + case EInQueue: statusString = tr("Marked for download"); rowColor = COLOR_INQUEUE; size = m_storage.CountrySizeInBytes(index); break; - default: + + case EGeneratingIndex: + statusString = tr("Generatin search index ..."); + rowColor = COLOR_INPROGRESS; break; } + if (statusString.size()) item->setText(KColumnIndexStatus, statusString); diff --git a/storage/storage.cpp b/storage/storage.cpp index 1348c9c238..b2074fec79 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -119,9 +119,12 @@ namespace storage } // second, check if this country has failed while downloading - if (m_failedCountries.find(index) != m_failedCountries.end()) + if (m_failedCountries.count(index) > 0) return EDownloadFailed; + if (m_indexGeneration.count(index) > 0) + return EGeneratingIndex; + LocalAndRemoteSizeT const size = CountryByIndex(index).Size(); if (size.first == size.second) { @@ -327,23 +330,23 @@ namespace storage { if (m_queue.empty()) { - ASSERT(false, ("Invalid url?", request.Data())); + ASSERT ( false, ("Invalid url?", request.Data()) ); return; } + TIndex const index = m_queue.front(); if (request.Status() == HttpRequest::EFailed) { // remove failed country from the queue - TIndex const failedIndex = m_queue.front(); m_queue.pop_front(); - m_failedCountries.insert(failedIndex); + m_failedCountries.insert(index); // notify GUI about failed country if (m_observerChange) - m_observerChange(failedIndex); + m_observerChange(index); } else { - LocalAndRemoteSizeT const size = CountryByIndex(m_queue.front()).Size(); + LocalAndRemoteSizeT const size = CountryByIndex(index).Size(); if (size.second != 0) m_countryProgress.first = size.first; @@ -355,22 +358,29 @@ namespace storage if (i != string::npos) file = file.substr(i+1); - // Generate search index if it's supported in this build Platform & pl = GetPlatform(); if (pl.IsFeatureSupported("search")) - pl.RunAsync(bind(&Storage::GenerateSearchIndex, this, file)); - else // Or simply activate downloaded map - UpdateAfterSearchIndex(file); + { + // Generate search index if it's supported in this build + m_indexGeneration.insert(index); + pl.RunAsync(bind(&Storage::GenerateSearchIndex, this, index, file)); + } + else + { + // Or simply activate downloaded map + UpdateAfterSearchIndex(index, file); + } } + m_request.reset(); DownloadNextCountryFromQueue(); } - void Storage::GenerateSearchIndex(string const & fName) const + void Storage::GenerateSearchIndex(TIndex const & index, string const & fName) { if (indexer::BuildSearchIndexFromDatFile(fName)) { - GetPlatform().RunOnGuiThread(bind(&Storage::UpdateAfterSearchIndex, this, fName)); + GetPlatform().RunOnGuiThread(bind(&Storage::UpdateAfterSearchIndex, this, index, fName)); } else { @@ -378,8 +388,11 @@ namespace storage } } - void Storage::UpdateAfterSearchIndex(string const & fName) const + void Storage::UpdateAfterSearchIndex(TIndex const & index, string const & fName) { + // remove from index set + m_indexGeneration.erase(index); + // activate downloaded map piece m_addMap(fName); diff --git a/storage/storage.hpp b/storage/storage.hpp index 08a080bd85..1b0e042311 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -18,6 +18,7 @@ namespace storage enum TStatus { EOnDisk = 0, + EGeneratingIndex, ENotDownloaded, EDownloadFailed, EDownloading, @@ -28,11 +29,14 @@ namespace storage struct TIndex { static int const INVALID; + int m_group; int m_country; int m_region; + TIndex(int group = INVALID, int country = INVALID, int region = INVALID) : m_group(group), m_country(country), m_region(region) {} + bool operator==(TIndex const & other) const { return (m_group == other.m_group && @@ -60,16 +64,21 @@ namespace storage CountriesContainerT m_countries; + /// store queue for downloading typedef list TQueue; TQueue m_queue; + + /// stores countries which download has failed recently + typedef set TCountriesSet; + TCountriesSet m_failedCountries; + + /// store countries set for which search index is generating + TCountriesSet m_indexGeneration; + /// used to correctly calculate total country download progress with more than 1 file /// downloader::HttpRequest::ProgressT m_countryProgress; - typedef set TFailedCountries; - /// stores countries which download has failed recently - TFailedCountries m_failedCountries; - /// @name Communicate with GUI //@{ typedef function TObserverChangeCountryFunction; @@ -96,8 +105,8 @@ namespace storage void DownloadNextCountryFromQueue(); Country const & CountryByIndex(TIndex const & index) const; - void GenerateSearchIndex(string const & fName) const; - void UpdateAfterSearchIndex(string const & fName) const; + void GenerateSearchIndex(TIndex const & index, string const & fName); + void UpdateAfterSearchIndex(TIndex const & index, string const & fName); public: Storage() {}