MCPcopy Create free account
hub / github.com/comaps/comaps / CreateCategories

Method CreateCategories

libs/map/bookmark_manager.cpp:2847–2971  ·  view source on GitHub ↗

Despite the name, this method is called not only for newly created categories, but also for loaded/imported ones.

Source from the content-addressed store, hash-verified

2845
2846// Despite the name, this method is called not only for newly created categories, but also for loaded/imported ones.
2847void BookmarkManager::CreateCategories(KMLDataCollection && dataCollection, bool autoSave /* = false */)
2848{
2849 CHECK_THREAD_CHECKER(m_threadChecker, ());
2850 kml::GroupIdSet loadedGroups;
2851
2852 bool isUpdating = false;
2853 for (auto const & [fileName, fileDataPtr] : dataCollection)
2854 {
2855 auto & fileData = *fileDataPtr;
2856 auto & categoryData = fileData.m_categoryData;
2857
2858 // Initialize timestamp for newly created or imported categories.
2859 if (categoryData.m_lastModified == kml::Timestamp{})
2860 categoryData.m_lastModified = fileName.empty() ? kml::TimestampClock::now() : FileModificationTimestamp(fileName);
2861
2862 if (!UserMarkIdStorage::Instance().CheckIds(fileData) || HasDuplicatedIds(fileData))
2863 {
2864 LOG(LINFO, ("Reset bookmark ids in the file", fileName));
2865 // TODO: notify subscribers(like search subsystem). This KML could have been indexed.
2866 ResetIds(fileData);
2867 }
2868
2869 ankerl::unordered_dense::map<kml::CompilationId, BookmarkCategory *> compilations;
2870 ankerl::unordered_dense::set<std::string> compilationNames;
2871 for (auto & compilation : fileData.m_compilationsData)
2872 {
2873 SetUniqueName(compilation, [&compilationNames](auto const & name) { return compilationNames.count(name) == 0; });
2874
2875 auto const compilationId = compilation.m_compilationId;
2876 auto childGroup = CreateBookmarkCompilation(std::move(compilation));
2877 categoryData.m_compilationIds.push_back(childGroup->GetID());
2878
2879 compilations.emplace(compilationId, childGroup);
2880 compilationNames.emplace(childGroup->GetName());
2881 childGroup->SetFileName(fileName);
2882 childGroup->SetServerId(fileData.m_serverId);
2883 }
2884
2885 SetUniqueName(categoryData, [this](auto const & name) { return !IsUsedCategoryName(name); });
2886
2887 UserMarkIdStorage::Instance().EnableSaving(false);
2888
2889 auto groupId = GetCategoryByFileName(fileName);
2890 // Set autoSave = false now to avoid useless saving in NotifyChanges().
2891 // autoSave flag will be assigned in the end of this function.
2892 if (groupId != kml::kInvalidMarkGroupId)
2893 {
2894 isUpdating = true;
2895 UpdateBookmarkCategory(groupId, std::move(categoryData), false /* autoSave */);
2896 }
2897 else
2898 groupId = CreateBookmarkCategory(std::move(categoryData), false /* autoSave */);
2899 loadedGroups.insert(groupId);
2900 auto * group = GetBmCategory(groupId);
2901 group->SetFileName(fileName);
2902 // Only append to the custom order if it has been activated (non-empty).
2903 if (!m_metadata.m_categoryOrder.empty() && !fileName.empty())
2904 {

Callers 2

ProcessNextKmlMethod · 0.80
UNIT_CLASS_TESTFunction · 0.80

Calls 15

ResetIdsFunction · 0.85
FileNameFromFullPathFunction · 0.85
findFunction · 0.85
CheckIdsMethod · 0.80
SetFileNameMethod · 0.80
SetServerIdMethod · 0.80
EnableSavingMethod · 0.80
SetAccessRulesMethod · 0.80
EnableAutoSaveMethod · 0.80
SetParentIdMethod · 0.80
SetAuthorMethod · 0.80

Tested by 1

UNIT_CLASS_TESTFunction · 0.64