1
/***************************************************************************
2
* Copyright 2007 Alexander Dymo <adymo@kdevelop.org> *
3
* Copyright 2008 Anne-Marie Mahfouf <annma@kde.org> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
23
#include <kconfiggroup.h>
26
#include <kstandarddirs.h>
28
#include "choicepage.h"
29
#include "apptemplatesmodel.h"
30
#include "apptemplateitem.h"
32
AppTemplatesModel::AppTemplatesModel(ChoicePage *parent)
33
:QStandardItemModel(parent), m_choicePage(parent)
37
void AppTemplatesModel::refresh()
39
m_templateItems.clear();
40
m_templateItems[""] = invisibleRootItem();
41
//find all .kdevtemplate files on the system
42
QStringList templateArchives = KGlobal::dirs()->findAllResources("data", "kdevappwizard/template_descriptions/*.kdevtemplate");
44
foreach (const QString &templateArchive, templateArchives)
46
QFileInfo archiveInfo(templateArchive);
47
QString baseName = archiveInfo.baseName();
48
KConfig templateConfig(templateArchive);
49
KConfigGroup general(&templateConfig, "General");
50
QString name = general.readEntry("Name");
51
QString category = general.readEntry("Category");
52
kDebug() << "category " << category << endl;
53
QString description = general.readEntry("Comment");
54
QString picture = general.readEntry("Icon");
55
AppTemplateItem *templateItem = createItem(name, category);
56
templateItem->setData(description, Qt::UserRole+1);
57
templateItem->setData(picture, Qt::UserRole+2);
58
templateItem->setData(baseName, Qt::UserRole+3);
62
AppTemplateItem *AppTemplatesModel::createItem(const QString &name, const QString &category)
64
QStringList path = category.split("/");
66
QStandardItem *parent = invisibleRootItem();
67
QStringList currentPath;
68
foreach (const QString &entry, path)
71
kDebug() << "current path " << currentPath << endl;
72
if (!m_templateItems.contains(currentPath.join("/")))
74
kDebug() << "in if " << endl;
75
AppTemplateItem *item = new AppTemplateItem(entry);
76
parent->appendRow(item);
77
m_templateItems[currentPath.join("/")] = item;
81
parent = m_templateItems[currentPath.join("/")];
84
AppTemplateItem *templateItem = new AppTemplateItem(name);
85
parent->appendRow(templateItem);
86
templateItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
90
// Set the column title (only 1 column in that case)
91
QVariant AppTemplatesModel::headerData(int section, Qt::Orientation orientation, int role) const
93
Q_UNUSED(orientation);
94
if (role != Qt::DisplayRole)
99
return i18n("Templates Projects");