Untitled

 avatar
unknown
c_cpp
2 years ago
2.2 kB
3
Indexable
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) {
        bool isUtilityCategoryInResponse = false;
        //ContentValues utility = ContentValues();
        QList<ContentValues>::iterator it;
        for (it = categoriesList.begin(); it != categoriesList.end(); it++) {
            //If the Utility was found on the list, we set it as Utilities and change the boolean state
            if (it->getAsQString(CategoriesTableColumns::cResourceId) == utilityResourceId) {
                it->put(CategoriesTableColumns::cType, static_cast<int>(CategoryType::Utilities));
                isUtilityCategoryInResponse = true;
                break;
            }
        }

        // If the Utility wasn't on the list, we create the ContentValue and add it to the result.
        if (!isUtilityCategoryInResponse) {
            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.
            categoriesList.erase(it);
            categoriesList.append(*it);
        }
    }
    return categoriesList;
}
Editor is loading...