diff --git a/storage/storage.cpp b/storage/storage.cpp index 1b8637f8f1..f9464f63e5 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -94,22 +94,6 @@ void CorrectJustDownloaded(Storage::TQueue::iterator justDownloadedItem, Storage else justDownloaded.insert(justDownloadedCountry); } - -bool IsDownloadingStatus(Status status) -{ - return status == Status::EDownloading || status == Status::EInQueue; -} - -bool IsUserAttentionNeededStatus(Status status) -{ - return status == Status::EDownloadFailed || status == Status::EOutOfMemFailed - || status == Status::EOnDiskOutOfDate || status == Status::EUnknown; -} - -bool IsPartlyDownloaded(Status status) -{ - return status == Status::ENotDownloaded; -} } // namespace void GetQueuedCountries(Storage::TQueue const & queue, TCountriesSet & resultCountries) @@ -1244,48 +1228,37 @@ void Storage::DeleteNode(TCountryId const & countryId) node->ForEachInSubtree(deleteAction); } -Status Storage::NodeStatus(TCountryTreeNode const & node) const +StatusAndError Storage::NodeStatus(TCountryTreeNode const & node) const { // Leaf node status. if (node.ChildrenCount() == 0) - return CountryStatusEx(node.Value().Name()); + return ParseStatus(CountryStatusEx(node.Value().Name())); // Group node status. - Status const kDownloadingInProgress = Status::EDownloading; - Status const kUsersAttentionNeeded = Status::EDownloadFailed; - Status const kPartlyDownloaded = Status::ENotDownloaded; - Status const kEverythingDownloaded = Status::EOnDisk; + enum NodeStatus result = NodeStatus::NotDownloaded; + bool allOnDisk = true; - Status result = kEverythingDownloaded; - auto groupStatusCalculator = [&result, this](TCountryTreeNode const & nodeInSubtree) + auto groupStatusCalculator = [&result, &allOnDisk, this](TCountryTreeNode const & nodeInSubtree) { - if (result == kDownloadingInProgress || nodeInSubtree.ChildrenCount() != 0) + if (result == NodeStatus::Downloading || nodeInSubtree.ChildrenCount() != 0) return; - Status status = this->CountryStatusEx(nodeInSubtree.Value().Name()); - ASSERT_NOT_EQUAL(status, Status::EUndefined, ()); - if (IsDownloadingStatus(status)) - { - result = kDownloadingInProgress; - return; - } + StatusAndError const statusAndError = ParseStatus(CountryStatusEx(nodeInSubtree.Value().Name())); + if (statusAndError.status != NodeStatus::OnDisk) + allOnDisk = false; - if (result == kUsersAttentionNeeded) - return; - if (IsUserAttentionNeededStatus(status)) - { - result = kUsersAttentionNeeded; - return; - } - - if (result == kPartlyDownloaded) - return; - if (IsPartlyDownloaded(status)) - result = kPartlyDownloaded; + if (static_cast(statusAndError.status) < static_cast(result)) + result = statusAndError.status; }; node.ForEachDescendant(groupStatusCalculator); - return result; + if (allOnDisk) + return ParseStatus(Status::EOnDisk); + if (!allOnDisk && result == NodeStatus::OnDisk) + return { NodeStatus::Mixed, NodeErrorCode::NoError }; + + ASSERT_NOT_EQUAL(result, NodeStatus::Undefined, ()); + return { result, NodeErrorCode::NoError }; } void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs) const @@ -1303,7 +1276,7 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs) Country const & nodeValue = node->Value(); nodeAttrs.m_mwmCounter = nodeValue.GetSubtreeMwmCounter(); nodeAttrs.m_mwmSize = nodeValue.GetSubtreeMwmSizeBytes(); - StatusAndError statusAndErr = ParseStatus(NodeStatus(*node)); + StatusAndError statusAndErr = NodeStatus(*node); nodeAttrs.m_status = statusAndErr.status; nodeAttrs.m_error = statusAndErr.error; nodeAttrs.m_nodeLocalName = m_countryNameGetter(countryId); diff --git a/storage/storage.hpp b/storage/storage.hpp index 3a2037acde..66a9098641 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -72,7 +72,18 @@ struct NodeAttrs /// So m_downloadingProgress.first <= m_downloadingProgress.second. MapFilesDownloader::TProgress m_downloadingProgress; + /// Status of group and leaf node. + /// For group nodes it's defined in the following way: + /// If an mwm in a group has Downloading status the group has Downloading status + /// If not and if an mwm in the group has InQueue status the group has InQueue status + /// If not and if an mwm in the group has Error status the group has Error status + /// If not and if an mwm in the group has OnDiskOutOfDate the group has OnDiskOutOfDate status + /// If not and if all the mwms in the group have OnDisk status the group has OnDisk status + /// If not and if all the mwms in the group have NotDownloaded status the group has NotDownloaded status + /// If not (that means a part of mwms in the group has OnDisk and the other part has NotDownloaded status) + /// the group has Mixed status NodeStatus m_status; + /// Error code of leaf node. In case of group node |m_error| == NodeErrorCode::NoError. NodeErrorCode m_error; /// Indicates if leaf mwm is currently downloaded and connected to storage. @@ -492,7 +503,7 @@ private: Status CountryStatus(TCountryId const & countryId) const; /// Returns status for a node (group node or not) - Status NodeStatus(TCountryTreeNode const & node) const; + StatusAndError NodeStatus(TCountryTreeNode const & node) const; void NotifyStatusChanged(TCountryId const & countryId); void NotifyStatusChangedForHierarchy(TCountryId const & countryId); diff --git a/storage/storage_defines.cpp b/storage/storage_defines.cpp index 65179cac83..bbba0d9410 100644 --- a/storage/storage_defines.cpp +++ b/storage/storage_defines.cpp @@ -47,6 +47,8 @@ string DebugPrint(NodeStatus status) return string("InQueue"); case NodeStatus::OnDiskOutOfDate: return string("OnDiskOutOfDate"); + case NodeStatus::Mixed: + return string("Mixed"); } } diff --git a/storage/storage_defines.hpp b/storage/storage_defines.hpp index 14027c41ec..69ea8a5189 100644 --- a/storage/storage_defines.hpp +++ b/storage/storage_defines.hpp @@ -24,15 +24,18 @@ namespace storage }; string DebugPrint(Status status); + /// \note The order of enum items is important. It is used in Storage::NodeStatus method. + /// If it's necessary to add more statuses it's better to add to the end. enum class NodeStatus { Undefined, - Error, /**< An error happened while downloading */ - OnDisk, /**< Downloaded mwm(s) is up to date. No need to update it. */ - NotDownloaded, /**< Mwm can be download but not downloaded yet. */ Downloading, /**< Downloading a new mwm or updating an old one. */ InQueue, /**< A mwm is waiting for downloading in the queue. */ + Error, /**< An error happened while downloading */ OnDiskOutOfDate, /**< An update for a downloaded mwm is ready according to counties.txt. */ + OnDisk, /**< Downloaded mwm(s) is up to date. No need to update it. */ + NotDownloaded, /**< Mwm can be download but not downloaded yet. */ + Mixed, /**< Leafs of group node has a mix of NotDownloaded and OnDisk status. */ }; string DebugPrint(NodeStatus status);