23 #include <kconfiggroup.h>
26 #include <kstandarddirs.h>
41 const QStringList templateArchives = dirs->findAllResources(
"apptemplates");
43 const QString localDescriptionsDir = dirs->saveLocation(
"apptemplate_descriptions");
45 foreach (
const QString &archName, templateArchives)
47 kDebug(9010) <<
"processing template" << archName;
49 KZip templateArchive(archName);
51 KTar templateArchive(archName,
"application/x-bzip");
53 if (templateArchive.open(QIODevice::ReadOnly))
55 QFileInfo templateInfo(archName);
56 const KArchiveEntry *templateEntry =
57 templateArchive.directory()->entry(templateInfo.baseName() +
".kdevtemplate");
58 if (!templateEntry || !templateEntry->isFile())
60 kDebug(9010) <<
"template" << archName <<
"does not contain .kdevtemplate file";
63 const KArchiveFile *templateFile = (KArchiveFile*)templateEntry;
65 kDebug(9010) <<
"copy template description to" << localDescriptionsDir;
66 templateFile->copyTo(localDescriptionsDir);
69 kDebug(9010) <<
"could not open template" << archName;
75 m_templateItems.clear();
76 m_templateItems[
""] = invisibleRootItem();
81 const QStringList templateArchives = KGlobal::dirs()->findAllResources(
"apptemplate_descriptions");
82 foreach (
const QString &templateArchive, templateArchives)
84 QFileInfo archiveInfo(templateArchive);
85 QString baseName = archiveInfo.baseName();
86 KConfig templateConfig(templateArchive);
87 KConfigGroup general(&templateConfig,
"General");
88 QString name = general.readEntry(
"Name");
89 QString category = general.readEntry(
"Category");
90 kDebug() <<
"category " << category << endl;
92 QString picture = general.readEntry(
"Icon");
94 templateItem->setData(description, Qt::UserRole+1);
95 templateItem->setData(picture, Qt::UserRole+2);
96 templateItem->setData(baseName, Qt::UserRole+3);
100 AppTemplateItem *AppTemplatesModel::createItem(
const QString &name,
const QString &category)
102 QStringList path = category.split(
"/");
105 QStringList currentPath;
106 foreach (
const QString &entry, path)
108 currentPath << entry;
109 kDebug() <<
"current path " << currentPath << endl;
110 if (!m_templateItems.contains(currentPath.join(
"/")))
112 kDebug() <<
"in if " << endl;
114 parent->appendRow(item);
115 m_templateItems[currentPath.join(
"/")] = item;
119 parent = m_templateItems[currentPath.join(
"/")];
123 parent->appendRow(templateItem);
124 templateItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
131 Q_UNUSED(orientation);
132 if (role != Qt::DisplayRole)
137 return i18n(
"Templates Projects");
QVariant headerData(int section, Qt::Orientation orientation, int role) const
void extractTemplateDescriptions(KStandardDirs *dirs)
static const char description[]
AppTemplatesModel(ChoicePage *parent)