Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/codegen/templatesmodel.cpp
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 76 | { | |||
---|---|---|---|---|---|
88 | } | 88 | } | ||
89 | return filter + suffix; | 89 | return filter + suffix; | ||
90 | } | 90 | } | ||
91 | }; | 91 | }; | ||
92 | 92 | | |||
93 | TemplatesModelPrivate::TemplatesModelPrivate(const QString& _typePrefix) | 93 | TemplatesModelPrivate::TemplatesModelPrivate(const QString& _typePrefix) | ||
94 | : typePrefix(_typePrefix) | 94 | : typePrefix(_typePrefix) | ||
95 | { | 95 | { | ||
96 | if (!typePrefix.endsWith('/')) { | 96 | if (!typePrefix.endsWith(QLatin1Char('/'))) { | ||
97 | typePrefix.append('/'); | 97 | typePrefix.append(QLatin1Char('/')); | ||
98 | } | 98 | } | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | TemplatesModel::TemplatesModel(const QString& typePrefix, QObject* parent) | 101 | TemplatesModel::TemplatesModel(const QString& typePrefix, QObject* parent) | ||
102 | : QStandardItemModel(parent) | 102 | : QStandardItemModel(parent) | ||
103 | , d(new TemplatesModelPrivate(typePrefix)) | 103 | , d(new TemplatesModelPrivate(typePrefix)) | ||
104 | { | 104 | { | ||
105 | const QStringList dataPaths = {QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)}; | 105 | const QStringList dataPaths = {QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)}; | ||
Show All 15 Lines | 114 | { | |||
121 | foreach(const QString& archivePath, d->searchPaths) { | 121 | foreach(const QString& archivePath, d->searchPaths) { | ||
122 | const QStringList files = QDir(archivePath).entryList(QDir::Files); | 122 | const QStringList files = QDir(archivePath).entryList(QDir::Files); | ||
123 | foreach(const QString& file, files) { | 123 | foreach(const QString& file, files) { | ||
124 | templateArchives.append(archivePath + file); | 124 | templateArchives.append(archivePath + file); | ||
125 | } | 125 | } | ||
126 | } | 126 | } | ||
127 | 127 | | |||
128 | QStringList templateDescriptions; | 128 | QStringList templateDescriptions; | ||
129 | const QStringList templatePaths = {QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +'/'+ d->resourceFilter(TemplatesModelPrivate::Description)}; | 129 | const QStringList templatePaths = {QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + d->resourceFilter(TemplatesModelPrivate::Description)}; | ||
130 | foreach(const QString& templateDescription, templatePaths) { | 130 | foreach(const QString& templateDescription, templatePaths) { | ||
131 | const QStringList files = QDir(templateDescription).entryList(QDir::Files); | 131 | const QStringList files = QDir(templateDescription).entryList(QDir::Files); | ||
132 | foreach(const QString& file, files) { | 132 | foreach(const QString& file, files) { | ||
133 | templateDescriptions.append(templateDescription + file); | 133 | templateDescriptions.append(templateDescription + file); | ||
134 | } | 134 | } | ||
135 | } | 135 | } | ||
136 | 136 | | |||
137 | foreach (const QString &templateDescription, templateDescriptions) { | 137 | foreach (const QString &templateDescription, templateDescriptions) { | ||
Show All 24 Lines | 160 | { | |||
162 | // saves us the extra lookups for templateExists on the next run | 162 | // saves us the extra lookups for templateExists on the next run | ||
163 | QFile(templateDescription).remove(); | 163 | QFile(templateDescription).remove(); | ||
164 | } | 164 | } | ||
165 | } | 165 | } | ||
166 | } | 166 | } | ||
167 | 167 | | |||
168 | QStandardItem *TemplatesModelPrivate::createItem(const QString& name, const QString& category, QStandardItem* parent) | 168 | QStandardItem *TemplatesModelPrivate::createItem(const QString& name, const QString& category, QStandardItem* parent) | ||
169 | { | 169 | { | ||
170 | QStringList path = category.split('/'); | 170 | QStringList path = category.split(QLatin1Char('/')); | ||
171 | 171 | | |||
172 | QStringList currentPath; | 172 | QStringList currentPath; | ||
173 | foreach (const QString& entry, path) | 173 | foreach (const QString& entry, path) | ||
174 | { | 174 | { | ||
175 | currentPath << entry; | 175 | currentPath << entry; | ||
176 | if (!templateItems.contains(currentPath.join(QLatin1Char('/')))) { | 176 | if (!templateItems.contains(currentPath.join(QLatin1Char('/')))) { | ||
177 | QStandardItem *item = new QStandardItem(entry); | 177 | QStandardItem *item = new QStandardItem(entry); | ||
178 | item->setEditable(false); | 178 | item->setEditable(false); | ||
Show All 21 Lines | 198 | foreach(const QString &archivePath, searchPaths) { | |||
200 | foreach(const QString& file, files) { | 200 | foreach(const QString& file, files) { | ||
201 | if(file.endsWith(QLatin1String(".zip")) || file.endsWith(QLatin1String(".tar.bz2"))) { | 201 | if(file.endsWith(QLatin1String(".zip")) || file.endsWith(QLatin1String(".tar.bz2"))) { | ||
202 | QString archfile = archivePath + file; | 202 | QString archfile = archivePath + file; | ||
203 | templateArchives.append(archfile); | 203 | templateArchives.append(archfile); | ||
204 | } | 204 | } | ||
205 | } | 205 | } | ||
206 | } | 206 | } | ||
207 | 207 | | |||
208 | QString localDescriptionsDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +'/'+ resourceFilter(Description); | 208 | QString localDescriptionsDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + resourceFilter(Description); | ||
209 | 209 | | |||
210 | QDir dir(localDescriptionsDir); | 210 | QDir dir(localDescriptionsDir); | ||
211 | if(!dir.exists()) | 211 | if(!dir.exists()) | ||
212 | dir.mkpath(QStringLiteral(".")); | 212 | dir.mkpath(QStringLiteral(".")); | ||
213 | 213 | | |||
214 | foreach (const QString &archName, templateArchives) | 214 | foreach (const QString &archName, templateArchives) | ||
215 | { | 215 | { | ||
216 | qCDebug(LANGUAGE) << "processing template" << archName; | 216 | qCDebug(LANGUAGE) << "processing template" << archName; | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 302 | { | |||
303 | qCWarning(LANGUAGE) << "could not open template" << archName; | 303 | qCWarning(LANGUAGE) << "could not open template" << archName; | ||
304 | } | 304 | } | ||
305 | } | 305 | } | ||
306 | } | 306 | } | ||
307 | 307 | | |||
308 | QModelIndexList TemplatesModel::templateIndexes(const QString& fileName) const | 308 | QModelIndexList TemplatesModel::templateIndexes(const QString& fileName) const | ||
309 | { | 309 | { | ||
310 | QFileInfo info(fileName); | 310 | QFileInfo info(fileName); | ||
311 | QString description = QStandardPaths::locate(QStandardPaths::GenericDataLocation, d->resourceFilter(TemplatesModelPrivate::Description, info.baseName() + ".kdevtemplate")); | 311 | QString description = QStandardPaths::locate(QStandardPaths::GenericDataLocation, d->resourceFilter(TemplatesModelPrivate::Description, info.baseName() + QLatin1String(".kdevtemplate"))); | ||
312 | if (description.isEmpty()) | 312 | if (description.isEmpty()) | ||
313 | { | 313 | { | ||
314 | description = QStandardPaths::locate(QStandardPaths::GenericDataLocation, d->resourceFilter(TemplatesModelPrivate::Description, info.baseName() + ".desktop")); | 314 | description = QStandardPaths::locate(QStandardPaths::GenericDataLocation, d->resourceFilter(TemplatesModelPrivate::Description, info.baseName() + QLatin1String(".desktop"))); | ||
315 | } | 315 | } | ||
316 | 316 | | |||
317 | QModelIndexList indexes; | 317 | QModelIndexList indexes; | ||
318 | 318 | | |||
319 | if (!description.isEmpty()) | 319 | if (!description.isEmpty()) | ||
320 | { | 320 | { | ||
321 | KConfig templateConfig(description); | 321 | KConfig templateConfig(description); | ||
322 | KConfigGroup general(&templateConfig, "General"); | 322 | KConfigGroup general(&templateConfig, "General"); | ||
323 | QStringList categories = general.readEntry("Category").split('/'); | 323 | QStringList categories = general.readEntry("Category").split(QLatin1Char('/')); | ||
324 | 324 | | |||
325 | QStringList levels; | 325 | QStringList levels; | ||
326 | foreach (const QString& category, categories) | 326 | foreach (const QString& category, categories) | ||
327 | { | 327 | { | ||
328 | levels << category; | 328 | levels << category; | ||
329 | indexes << d->templateItems[levels.join(QString('/'))]->index(); | 329 | indexes << d->templateItems[levels.join(QStringLiteral("/"))]->index(); | ||
330 | } | 330 | } | ||
331 | 331 | | |||
332 | if (!indexes.isEmpty()) | 332 | if (!indexes.isEmpty()) | ||
333 | { | 333 | { | ||
334 | QString name = general.readEntry("Name"); | 334 | QString name = general.readEntry("Name"); | ||
335 | QStandardItem* categoryItem = d->templateItems[levels.join(QString('/'))]; | 335 | QStandardItem* categoryItem = d->templateItems[levels.join(QStringLiteral("/"))]; | ||
336 | for (int i = 0; i < categoryItem->rowCount(); ++i) | 336 | for (int i = 0; i < categoryItem->rowCount(); ++i) | ||
337 | { | 337 | { | ||
338 | QStandardItem* templateItem = categoryItem->child(i); | 338 | QStandardItem* templateItem = categoryItem->child(i); | ||
339 | if (templateItem->text() == name) | 339 | if (templateItem->text() == name) | ||
340 | { | 340 | { | ||
341 | indexes << templateItem->index(); | 341 | indexes << templateItem->index(); | ||
342 | break; | 342 | break; | ||
343 | } | 343 | } | ||
Show All 12 Lines | |||||
356 | void TemplatesModel::addDataPath(const QString& path) | 356 | void TemplatesModel::addDataPath(const QString& path) | ||
357 | { | 357 | { | ||
358 | QString realpath = path + d->resourceFilter(TemplatesModelPrivate::Template); | 358 | QString realpath = path + d->resourceFilter(TemplatesModelPrivate::Template); | ||
359 | d->searchPaths.append(realpath); | 359 | d->searchPaths.append(realpath); | ||
360 | } | 360 | } | ||
361 | 361 | | |||
362 | QString TemplatesModel::loadTemplateFile(const QString& fileName) | 362 | QString TemplatesModel::loadTemplateFile(const QString& fileName) | ||
363 | { | 363 | { | ||
364 | QString saveLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +'/'+ d->resourceFilter(TemplatesModelPrivate::Template); | 364 | QString saveLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + d->resourceFilter(TemplatesModelPrivate::Template); | ||
365 | 365 | | |||
366 | QDir dir(saveLocation); | 366 | QDir dir(saveLocation); | ||
367 | if(!dir.exists()) | 367 | if(!dir.exists()) | ||
368 | dir.mkpath(QStringLiteral(".")); | 368 | dir.mkpath(QStringLiteral(".")); | ||
369 | 369 | | |||
370 | QFileInfo info(fileName); | 370 | QFileInfo info(fileName); | ||
371 | QString destination = saveLocation + info.baseName(); | 371 | QString destination = saveLocation + info.baseName(); | ||
372 | 372 | | |||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |