MCPcopy Create free account
hub / github.com/KDE/kdevelop / setTemplateDescription

Method setTemplateDescription

kdevplatform/language/codegen/sourcefiletemplate.cpp:161–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161void 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
209bool SourceFileTemplate::isValid() const
210{

Callers 4

loadTemplateMethod · 0.45
templateChosenMethod · 0.45
yamlTemplateMethod · 0.45
cppTemplateMethod · 0.45

Calls 7

baseNameMethod · 0.80
QFileInfoClass · 0.50
QDirClass · 0.50
appendMethod · 0.45
isEmptyMethod · 0.45
openMethod · 0.45
errorStringMethod · 0.45

Tested by 3

loadTemplateMethod · 0.36
yamlTemplateMethod · 0.36
cppTemplateMethod · 0.36