| 286 | } |
| 287 | |
| 288 | QModelIndexList TemplatesModel::templateIndexes(const QString& fileName) const |
| 289 | { |
| 290 | Q_D(const TemplatesModel); |
| 291 | |
| 292 | QFileInfo info(fileName); |
| 293 | QString description = |
| 294 | QStandardPaths::locate(QStandardPaths::GenericDataLocation, |
| 295 | d->resourceFilter(TemplatesModelPrivate::Description, |
| 296 | info.baseName() + QLatin1String(".kdevtemplate"))); |
| 297 | if (description.isEmpty()) { |
| 298 | description = |
| 299 | QStandardPaths::locate(QStandardPaths::GenericDataLocation, |
| 300 | d->resourceFilter(TemplatesModelPrivate::Description, |
| 301 | info.baseName() + QLatin1String(".desktop"))); |
| 302 | } |
| 303 | |
| 304 | QModelIndexList indexes; |
| 305 | |
| 306 | if (!description.isEmpty()) { |
| 307 | KConfig templateConfig(description); |
| 308 | KConfigGroup general(&templateConfig, QStringLiteral("General")); |
| 309 | const QStringList categories = general.readEntry("Category").split(QLatin1Char('/')); |
| 310 | |
| 311 | QStringList levels; |
| 312 | levels.reserve(categories.size()); |
| 313 | for (const QString& category : categories) { |
| 314 | levels << category; |
| 315 | indexes << d->templateItems[levels.join(QLatin1Char('/'))]->index(); |
| 316 | } |
| 317 | |
| 318 | if (!indexes.isEmpty()) { |
| 319 | QString name = general.readEntry("Name"); |
| 320 | QStandardItem* categoryItem = d->templateItems[levels.join(QLatin1Char('/'))]; |
| 321 | for (int i = 0; i < categoryItem->rowCount(); ++i) { |
| 322 | QStandardItem* templateItem = categoryItem->child(i); |
| 323 | if (templateItem->text() == name) { |
| 324 | indexes << templateItem->index(); |
| 325 | break; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | return indexes; |
| 332 | } |
| 333 | |
| 334 | QString TemplatesModel::typePrefix() const |
| 335 | { |