| 159 | } |
| 160 | |
| 161 | void SourceFileTemplate::setTemplateDescription(const QString& templateDescription) |
| 162 | { |
| 163 | Q_D(SourceFileTemplate); |
| 164 | |
| 165 | delete d->archive; |
| 166 | |
| 167 | d->descriptionFileName = templateDescription; |
| 168 | QString archiveFileName; |
| 169 | |
| 170 | const QString templateBaseName = QFileInfo(templateDescription).baseName(); |
| 171 | |
| 172 | d->searchLocations.append(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, |
| 173 | QStringLiteral("/kdevfiletemplates/templates/"), |
| 174 | QStandardPaths::LocateDirectory)); |
| 175 | |
| 176 | for (const QString& dir : std::as_const(d->searchLocations)) { |
| 177 | const auto fileEntries = QDir(dir).entryInfoList(QDir::Files); |
| 178 | for (const auto& entry : fileEntries) { |
| 179 | if (entry.baseName() == templateBaseName) { |
| 180 | archiveFileName = entry.absoluteFilePath(); |
| 181 | qCDebug(LANGUAGE) << "Found template archive" << archiveFileName; |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | if (archiveFileName.isEmpty() || !QFileInfo::exists(archiveFileName)) { |
| 188 | qCWarning(LANGUAGE) << "Could not find a template archive for description" << templateDescription << |
| 189 | ", archive file" << archiveFileName; |
| 190 | d->archive = nullptr; |
| 191 | } else { |
| 192 | QFileInfo info(archiveFileName); |
| 193 | |
| 194 | if (info.suffix() == QLatin1String("zip")) { |
| 195 | d->archive = new KZip(archiveFileName); |
| 196 | } else { |
| 197 | d->archive = new KTar(archiveFileName); |
| 198 | } |
| 199 | |
| 200 | if (!d->archive->open(QIODevice::ReadOnly)) { |
| 201 | qCWarning(LANGUAGE) << "Could not open the template archive for description" << templateDescription |
| 202 | << ", archive file" << archiveFileName << ':' << d->archive->errorString(); |
| 203 | delete d->archive; |
| 204 | d->archive = nullptr; |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | bool SourceFileTemplate::isValid() const |
| 210 | { |