Untitled
unknown
c_cpp
2 years ago
2.0 kB
4
Indexable
Never
QList<ContentValues> VRoomGetCategoriesFetcher::parseResponse(const QList<ODTagContainer>& odTags) { auto categoriesList = VRoomUtils::categoriesToContentValuesList(odTags); auto utilityCategoriesList = OneDriveCoreLibrary::getConfiguration().utilityCategories().get(); //Add the list of Utility categories to the list. If a Utility category is returned on the response, // we need to make sure to mark it as CategoriesTableColumns::cType = CategoryType::Utilities. // All categories are marked as CategoryType::Things by default since backend doesn't return this info. for (const auto& utilityResourceId: utilityCategoriesList) { auto it = std::find_if(categoriesList.begin(), categoriesList.end(), [utilityResourceId](ContentValues& category) { return category.getAsQString(CategoriesTableColumns::cResourceId) == utilityResourceId; }); // If the Utility wasn't on the list, we create the ContentValue and add it to the result. if (it == categoriesList.end()) { auto contentValues = ContentValues(); contentValues.put(CategoriesTableColumns::cResourceId, utilityResourceId); contentValues.put(CategoriesTableColumns::cLocalizedName, ""); contentValues.put(CategoriesTableColumns::cSource, CategoriesDBHelper::cCategoriesSource); contentValues.put(CategoriesTableColumns::cType, static_cast<int>(CategoryType::Utilities)); categoriesList.append(contentValues); } else { // Remove the utility found, and add it to the end. // This to ensure the utilities are always in the expected order at the end of the category List. auto categoryCopy = *it; categoryCopy.put(CategoriesTableColumns::cType, static_cast<int>(CategoryType::Utilities)); categoriesList.erase(it); categoriesList.append(categoryCopy); } } return categoriesList; }