Changeset View
Changeset View
Standalone View
Standalone View
language/codegen/templatesmodel.cpp
Show All 13 Lines | 1 | /* This file is part of KDevelop | |||
---|---|---|---|---|---|
14 | 14 | | |||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "templatesmodel.h" | 21 | #include "templatesmodel.h" | ||
22 | | ||||
23 | #include "templatepreviewicon.h" | ||||
22 | #include "util/debug.h" | 24 | #include "util/debug.h" | ||
23 | #include <interfaces/icore.h> | 25 | #include <interfaces/icore.h> | ||
24 | 26 | | |||
25 | #include <KConfig> | 27 | #include <KConfig> | ||
26 | #include <KTar> | 28 | #include <KTar> | ||
27 | #include <KZip> | 29 | #include <KZip> | ||
28 | #include <KConfigGroup> | 30 | #include <KConfigGroup> | ||
29 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | 142 | foreach( const QString& templateArchive, templateArchives ) { | |||
141 | if( QFileInfo(templateArchive).baseName() == fi.baseName() ) { | 143 | if( QFileInfo(templateArchive).baseName() == fi.baseName() ) { | ||
142 | archiveFound = true; | 144 | archiveFound = true; | ||
143 | 145 | | |||
144 | KConfig templateConfig(templateDescription); | 146 | KConfig templateConfig(templateDescription); | ||
145 | KConfigGroup general(&templateConfig, "General"); | 147 | KConfigGroup general(&templateConfig, "General"); | ||
146 | QString name = general.readEntry("Name"); | 148 | QString name = general.readEntry("Name"); | ||
147 | QString category = general.readEntry("Category"); | 149 | QString category = general.readEntry("Category"); | ||
148 | QString comment = general.readEntry("Comment"); | 150 | QString comment = general.readEntry("Comment"); | ||
151 | TemplatePreviewIcon icon(general.readEntry("Icon"), templateArchive, d->resourceFilter(TemplatesModelPrivate::Preview)); | ||||
149 | 152 | | |||
150 | QStandardItem *templateItem = d->createItem(name, category, invisibleRootItem()); | 153 | QStandardItem *templateItem = d->createItem(name, category, invisibleRootItem()); | ||
151 | templateItem->setData(templateDescription, DescriptionFileRole); | 154 | templateItem->setData(templateDescription, DescriptionFileRole); | ||
152 | templateItem->setData(templateArchive, ArchiveFileRole); | 155 | templateItem->setData(templateArchive, ArchiveFileRole); | ||
153 | templateItem->setData(comment, CommentRole); | 156 | templateItem->setData(comment, CommentRole); | ||
154 | 157 | templateItem->setData(QVariant::fromValue<TemplatePreviewIcon>(icon), PreviewIconRole); | |||
155 | if (general.hasKey("Icon")) | | |||
156 | { | | |||
157 | QString icon = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | | |||
158 | d->resourceFilter(TemplatesModelPrivate::Preview, general.readEntry("Icon"))); | | |||
159 | if (QFile::exists(icon)) { | | |||
160 | templateItem->setData(icon, IconNameRole); | | |||
161 | } | | |||
162 | } | | |||
163 | } | 158 | } | ||
164 | } | 159 | } | ||
165 | 160 | | |||
166 | if (!archiveFound) | 161 | if (!archiveFound) | ||
167 | { | 162 | { | ||
168 | // Template file doesn't exist anymore, so remove the description | 163 | // Template file doesn't exist anymore, so remove the description | ||
169 | // saves us the extra lookups for templateExists on the next run | 164 | // saves us the extra lookups for templateExists on the next run | ||
170 | QFile(templateDescription).remove(); | 165 | QFile(templateDescription).remove(); | ||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Line(s) | 231 | { | |||
295 | 290 | | |||
296 | /* | 291 | /* | ||
297 | * Rename the extracted description | 292 | * Rename the extracted description | ||
298 | * so that its basename matches the basename of the template archive | 293 | * so that its basename matches the basename of the template archive | ||
299 | */ | 294 | */ | ||
300 | QFileInfo descriptionInfo(localDescriptionsDir + templateEntry->name()); | 295 | QFileInfo descriptionInfo(localDescriptionsDir + templateEntry->name()); | ||
301 | QString destinationName = localDescriptionsDir + templateInfo.baseName() + '.' + descriptionInfo.suffix(); | 296 | QString destinationName = localDescriptionsDir + templateInfo.baseName() + '.' + descriptionInfo.suffix(); | ||
302 | QFile::rename(descriptionInfo.absoluteFilePath(), destinationName); | 297 | QFile::rename(descriptionInfo.absoluteFilePath(), destinationName); | ||
303 | | ||||
304 | KConfig config(destinationName); | | |||
305 | KConfigGroup group(&config, "General"); | | |||
306 | if (group.hasKey("Icon")) | | |||
307 | { | | |||
308 | const KArchiveEntry* iconEntry = templateArchive->directory()->entry(group.readEntry("Icon")); | | |||
309 | if (iconEntry && iconEntry->isFile()) | | |||
310 | { | | |||
311 | const KArchiveFile* iconFile = static_cast<const KArchiveFile*>(iconEntry); | | |||
312 | const QString saveDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +'/'+ resourceFilter(Preview); | | |||
313 | QDir dir(saveDir); | | |||
314 | if (!dir.exists()) { | | |||
315 | dir.mkpath(QStringLiteral(".")); | | |||
316 | } | | |||
317 | iconFile->copyTo(saveDir); | | |||
318 | QFileInfo iconInfo(saveDir + templateEntry->name()); | | |||
319 | QFile::rename(iconInfo.absoluteFilePath(), saveDir + templateInfo.baseName() + '.' + iconInfo.suffix()); | | |||
320 | } | | |||
321 | } | | |||
322 | } | 298 | } | ||
323 | else | 299 | else | ||
324 | { | 300 | { | ||
325 | qCWarning(LANGUAGE) << "could not open template" << archName; | 301 | qCWarning(LANGUAGE) << "could not open template" << archName; | ||
326 | } | 302 | } | ||
327 | } | 303 | } | ||
328 | } | 304 | } | ||
329 | 305 | | |||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |