From 2295e03d517268605dfe0159bc10f4a4438c821b Mon Sep 17 00:00:00 2001 From: Kirill Zhdanovich Date: Sun, 3 Feb 2013 19:03:06 +0300 Subject: [PATCH] Loading bookmark fix --- map/framework.cpp | 22 +++++++++++++++++----- map/framework.hpp | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index 9afd72d7c9..53ed46ad4b 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -373,6 +373,17 @@ void Framework::LoadBookmarks() } } +void Framework::LoadBookmark(string const & filePath) +{ + BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(filePath); + if (cat) + { + m_bookmarks.push_back(cat); + + LOG(LINFO, ("Loaded bookmarks category", cat->GetName(), "with", cat->GetBookmarksCount(), "bookmarks")); + } +} + BookmarkCategory * Framework::AddBookmark(string const & category, Bookmark const & bm) { // Get global non-rotated viewport rect and calculate viewport scale level. @@ -574,10 +585,11 @@ string const GenerateValidandUniqFilePathForKLM(string const & filename) bool Framework::AddBookmarksFile(string const & filePath) { string const fileExt = GetFileExt(filePath); + string fileSavePath; if (fileExt == KML_EXTENSION) { - string savePath = GenerateValidandUniqFilePathForKLM( GetFileName(filePath) ); - if (!my::CopyFile(filePath, savePath)) + fileSavePath = GenerateValidandUniqFilePathForKLM( GetFileName(filePath) ); + if (!my::CopyFile(filePath, fileSavePath)) return false; } else if (fileExt == KMZ_EXTENSION) @@ -598,8 +610,8 @@ bool Framework::AddBookmarksFile(string const & filePath) } if (kmlFileName.empty()) return false; - string const savePath = GenerateValidandUniqFilePathForKLM(kmlFileName); - ZipFileReader::UnzipFile(filePath, kmlFileName, savePath); + fileSavePath = GenerateValidandUniqFilePathForKLM(kmlFileName); + ZipFileReader::UnzipFile(filePath, kmlFileName, fileSavePath); } catch (RootException const & e) { @@ -614,7 +626,7 @@ bool Framework::AddBookmarksFile(string const & filePath) } // Update freshly added bookmarks - LoadBookmarks(); + LoadBookmark(fileSavePath); return true; } diff --git a/map/framework.hpp b/map/framework.hpp index 8efe7f4acf..5c731eb0a4 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -187,6 +187,8 @@ public: /// Scans and loads all kml files with bookmarks in WritableDir void LoadBookmarks(); + void LoadBookmark(string const & filePath); + // Always returns existing or newly created bookmark category BookmarkCategory * AddBookmark(string const & category, Bookmark const & bm); inline size_t GetBmCategoriesCount() const { return m_bookmarks.size(); }