~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to kapptemplate/apptemplatesmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright 2007 Alexander Dymo <adymo@kdevelop.org>                    *
 
3
 *   Copyright 2008 Anne-Marie Mahfouf <annma@kde.org>                     *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include <QFileInfo>
 
22
 
 
23
#include <kconfiggroup.h>
 
24
#include <KDebug>
 
25
#include <klocale.h>
 
26
#include <kstandarddirs.h>
 
27
 
 
28
#include "choicepage.h"
 
29
#include "apptemplatesmodel.h"
 
30
#include "apptemplateitem.h"
 
31
 
 
32
AppTemplatesModel::AppTemplatesModel(ChoicePage *parent)
 
33
    :QStandardItemModel(parent), m_choicePage(parent)
 
34
{
 
35
}
 
36
 
 
37
void AppTemplatesModel::refresh()
 
38
{
 
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");
 
43
    QStringList tempList;
 
44
    foreach (const QString &templateArchive, templateArchives)
 
45
    {
 
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);
 
59
    }
 
60
}
 
61
 
 
62
AppTemplateItem *AppTemplatesModel::createItem(const QString &name, const QString &category)
 
63
{
 
64
    QStringList path = category.split("/");
 
65
 
 
66
    QStandardItem *parent = invisibleRootItem();
 
67
    QStringList currentPath;
 
68
    foreach (const QString &entry, path)
 
69
    {
 
70
        currentPath << entry;
 
71
        kDebug() << "current path " << currentPath << endl;
 
72
        if (!m_templateItems.contains(currentPath.join("/")))
 
73
        {
 
74
            kDebug() << "in if " << endl;
 
75
            AppTemplateItem *item = new AppTemplateItem(entry);
 
76
            parent->appendRow(item);
 
77
            m_templateItems[currentPath.join("/")] = item;
 
78
            parent = item;
 
79
        }
 
80
        else
 
81
            parent = m_templateItems[currentPath.join("/")];
 
82
    }
 
83
 
 
84
    AppTemplateItem *templateItem = new AppTemplateItem(name);
 
85
    parent->appendRow(templateItem);
 
86
    templateItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
 
87
    return templateItem;
 
88
}
 
89
 
 
90
// Set the column title (only 1 column in that case)
 
91
QVariant AppTemplatesModel::headerData(int section, Qt::Orientation orientation, int role) const
 
92
{
 
93
    Q_UNUSED(orientation);
 
94
    if (role != Qt::DisplayRole)
 
95
        return QVariant();
 
96
 
 
97
    switch (section) {
 
98
    case 0:
 
99
        return i18n("Templates Projects");
 
100
    default:
 
101
        break;
 
102
    }
 
103
    return QVariant();
 
104
}
 
105