Changeset View
Changeset View
Standalone View
Standalone View
src/sycoca/kbuildservicefactory.cpp
Show First 20 Lines • Show All 153 Lines • ▼ Show 20 Line(s) | |||||
154 | 154 | | |||
155 | void KBuildServiceFactory::collectInheritedServices() | 155 | void KBuildServiceFactory::collectInheritedServices() | ||
156 | { | 156 | { | ||
157 | // For each mimetype, go up the parent-mimetype chains and collect offers. | 157 | // For each mimetype, go up the parent-mimetype chains and collect offers. | ||
158 | // For "removed associations" to work, we can't just grab everything from all parents. | 158 | // For "removed associations" to work, we can't just grab everything from all parents. | ||
159 | // We need to process parents before children, hence the recursive call in | 159 | // We need to process parents before children, hence the recursive call in | ||
160 | // collectInheritedServices(mime) and the QSet to process a given parent only once. | 160 | // collectInheritedServices(mime) and the QSet to process a given parent only once. | ||
161 | QSet<QString> visitedMimes; | 161 | QSet<QString> visitedMimes; | ||
162 | Q_FOREACH (const QString &mimeType, m_mimeTypeFactory->allMimeTypes()) { | 162 | const auto lst = m_mimeTypeFactory->allMimeTypes(); | ||
163 | for (const QString &mimeType : lst) { | ||||
163 | collectInheritedServices(mimeType, visitedMimes); | 164 | collectInheritedServices(mimeType, visitedMimes); | ||
164 | } | 165 | } | ||
165 | } | 166 | } | ||
166 | 167 | | |||
167 | void KBuildServiceFactory::collectInheritedServices(const QString &mimeTypeName, QSet<QString> &visitedMimes) | 168 | void KBuildServiceFactory::collectInheritedServices(const QString &mimeTypeName, QSet<QString> &visitedMimes) | ||
168 | { | 169 | { | ||
169 | if (visitedMimes.contains(mimeTypeName)) { | 170 | if (visitedMimes.contains(mimeTypeName)) { | ||
170 | return; | 171 | return; | ||
171 | } | 172 | } | ||
172 | visitedMimes.insert(mimeTypeName); | 173 | visitedMimes.insert(mimeTypeName); | ||
173 | 174 | | |||
174 | // With multiple inheritance, the "mimeTypeInheritanceLevel" isn't exactly | 175 | // With multiple inheritance, the "mimeTypeInheritanceLevel" isn't exactly | ||
175 | // correct (it should only be increased when going up a level, not when iterating | 176 | // correct (it should only be increased when going up a level, not when iterating | ||
176 | // through the multiple parents at a given level). I don't think we care, though. | 177 | // through the multiple parents at a given level). I don't think we care, though. | ||
177 | int mimeTypeInheritanceLevel = 0; | 178 | int mimeTypeInheritanceLevel = 0; | ||
178 | 179 | | |||
179 | QMimeDatabase db; | 180 | QMimeDatabase db; | ||
180 | QMimeType qmime = db.mimeTypeForName(mimeTypeName); | 181 | const QMimeType qmime = db.mimeTypeForName(mimeTypeName); | ||
181 | Q_FOREACH (QString parentMimeType, qmime.parentMimeTypes()) { | 182 | const auto lst = qmime.parentMimeTypes(); | ||
183 | for (QString parentMimeType : lst) { | ||||
182 | 184 | | |||
183 | // Workaround issue in shared-mime-info and/or Qt, which sometimes return an alias as parent | 185 | // Workaround issue in shared-mime-info and/or Qt, which sometimes return an alias as parent | ||
184 | parentMimeType = db.mimeTypeForName(parentMimeType).name(); | 186 | parentMimeType = db.mimeTypeForName(parentMimeType).name(); | ||
185 | 187 | | |||
186 | collectInheritedServices(parentMimeType, visitedMimes); | 188 | collectInheritedServices(parentMimeType, visitedMimes); | ||
187 | 189 | | |||
188 | ++mimeTypeInheritanceLevel; | 190 | ++mimeTypeInheritanceLevel; | ||
189 | const QList<KServiceOffer> &offers = m_offerHash.offersFor(parentMimeType); | 191 | const QList<KServiceOffer> &offers = m_offerHash.offersFor(parentMimeType); | ||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | 291 | if (!mime.isValid()) { | |||
294 | } else { | 296 | } else { | ||
295 | //qCDebug(SYCOCA) << service->entryPath() << "specifies undefined mimetype/servicetype" << stName; | 297 | //qCDebug(SYCOCA) << service->entryPath() << "specifies undefined mimetype/servicetype" << stName; | ||
296 | // technically we could call addServiceOffer here, 'mime' isn't used. But it | 298 | // technically we could call addServiceOffer here, 'mime' isn't used. But it | ||
297 | // would be useless, since we have no mimetype entry where to write the offers offset. | 299 | // would be useless, since we have no mimetype entry where to write the offers offset. | ||
298 | continue; | 300 | continue; | ||
299 | } | 301 | } | ||
300 | } else { | 302 | } else { | ||
301 | bool shouldAdd = true; | 303 | bool shouldAdd = true; | ||
302 | foreach (const QString &otherType, service->serviceTypes()) { | 304 | const auto lst = service->serviceTypes(); | ||
305 | for (const QString &otherType : lst) { | ||||
303 | // Skip derived types if the base class is listed (#321706) | 306 | // Skip derived types if the base class is listed (#321706) | ||
304 | if (stName != otherType && mime.inherits(otherType)) { | 307 | if (stName != otherType && mime.inherits(otherType)) { | ||
305 | // But don't skip aliases (they got resolved into mime->name() already, but don't let two aliases cancel out) | 308 | // But don't skip aliases (they got resolved into mime->name() already, but don't let two aliases cancel out) | ||
306 | if (db.mimeTypeForName(otherType).name() != mime.name()) { | 309 | if (db.mimeTypeForName(otherType).name() != mime.name()) { | ||
307 | //qCDebug(SYCOCA) << "Skipping" << mime->name() << "because of" << otherType << "(canonical" << KMimeTypeRepository::self()->canonicalName(otherType) << ") while parsing" << service->entryPath(); | 310 | //qCDebug(SYCOCA) << "Skipping" << mime->name() << "because of" << otherType << "(canonical" << KMimeTypeRepository::self()->canonicalName(otherType) << ") while parsing" << service->entryPath(); | ||
308 | shouldAdd = false; | 311 | shouldAdd = false; | ||
309 | } | 312 | } | ||
310 | } | 313 | } | ||
▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines |