• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kapptemplate

  • sources
  • kde-4.14
  • kdesdk
  • kapptemplate
apptemplatesmodel.cpp
Go to the documentation of this file.
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 #include <ktar.h>
28 #include <kzip.h>
29 
30 #include "choicepage.h"
31 #include "apptemplatesmodel.h"
32 #include "apptemplateitem.h"
33 
34 AppTemplatesModel::AppTemplatesModel(ChoicePage *parent)
35  :QStandardItemModel(parent), m_choicePage(parent)
36 {
37 }
38 
39 void extractTemplateDescriptions( KStandardDirs* dirs )
40 {
41  const QStringList templateArchives = dirs->findAllResources("apptemplates");
42 
43  const QString localDescriptionsDir = dirs->saveLocation("apptemplate_descriptions");
44 
45  foreach (const QString &archName, templateArchives)
46  {
47  kDebug(9010) << "processing template" << archName;
48 #ifdef Q_WS_WIN
49  KZip templateArchive(archName);
50 #else
51  KTar templateArchive(archName, "application/x-bzip");
52 #endif //Q_WS_WIN
53  if (templateArchive.open(QIODevice::ReadOnly))
54  {
55  QFileInfo templateInfo(archName);
56  const KArchiveEntry *templateEntry =
57  templateArchive.directory()->entry(templateInfo.baseName() + ".kdevtemplate");
58  if (!templateEntry || !templateEntry->isFile())
59  {
60  kDebug(9010) << "template" << archName << "does not contain .kdevtemplate file";
61  continue;
62  }
63  const KArchiveFile *templateFile = (KArchiveFile*)templateEntry;
64 
65  kDebug(9010) << "copy template description to" << localDescriptionsDir;
66  templateFile->copyTo(localDescriptionsDir);
67  }
68  else
69  kDebug(9010) << "could not open template" << archName;
70  }
71 }
72 
73 void AppTemplatesModel::refresh()
74 {
75  m_templateItems.clear();
76  m_templateItems[""] = invisibleRootItem();
77 
78  extractTemplateDescriptions( KGlobal::dirs() );
79 
80  //find all .kdevtemplate files on the system
81  const QStringList templateArchives = KGlobal::dirs()->findAllResources("apptemplate_descriptions");
82  foreach (const QString &templateArchive, templateArchives)
83  {
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;
91  QString description = general.readEntry("Comment");
92  QString picture = general.readEntry("Icon");
93  AppTemplateItem *templateItem = createItem(name, category);
94  templateItem->setData(description, Qt::UserRole+1);
95  templateItem->setData(picture, Qt::UserRole+2);
96  templateItem->setData(baseName, Qt::UserRole+3);
97  }
98 }
99 
100 AppTemplateItem *AppTemplatesModel::createItem(const QString &name, const QString &category)
101 {
102  QStringList path = category.split("/");
103 
104  QStandardItem *parent = invisibleRootItem();
105  QStringList currentPath;
106  foreach (const QString &entry, path)
107  {
108  currentPath << entry;
109  kDebug() << "current path " << currentPath << endl;
110  if (!m_templateItems.contains(currentPath.join("/")))
111  {
112  kDebug() << "in if " << endl;
113  AppTemplateItem *item = new AppTemplateItem(entry);
114  parent->appendRow(item);
115  m_templateItems[currentPath.join("/")] = item;
116  parent = item;
117  }
118  else
119  parent = m_templateItems[currentPath.join("/")];
120  }
121 
122  AppTemplateItem *templateItem = new AppTemplateItem(name);
123  parent->appendRow(templateItem);
124  templateItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
125  return templateItem;
126 }
127 
128 // Set the column title (only 1 column in that case)
129 QVariant AppTemplatesModel::headerData(int section, Qt::Orientation orientation, int role) const
130 {
131  Q_UNUSED(orientation);
132  if (role != Qt::DisplayRole)
133  return QVariant();
134 
135  switch (section) {
136  case 0:
137  return i18n("Templates Projects");
138  default:
139  break;
140  }
141  return QVariant();
142 }
143 
QStandardItemModel
QMap::contains
bool contains(const Key &key) const
apptemplatesmodel.h
QStandardItemModel::invisibleRootItem
QStandardItem * invisibleRootItem() const
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QStringList::join
QString join(const QString &separator) const
QMap::clear
void clear()
QStandardItem::setData
virtual void setData(const QVariant &value, int role)
AppTemplateItem
Definition: apptemplateitem.h:26
AppTemplatesModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: apptemplatesmodel.cpp:129
QObject::name
const char * name() const
QStandardItem::appendRow
void appendRow(const QList< QStandardItem * > &items)
QStandardItem::setFlags
void setFlags(QFlags< Qt::ItemFlag > flags)
AppTemplatesModel::refresh
void refresh()
Definition: apptemplatesmodel.cpp:73
QString
QStringList
QFileInfo
QStandardItemModel::item
QStandardItem * item(int row, int column) const
extractTemplateDescriptions
void extractTemplateDescriptions(KStandardDirs *dirs)
Definition: apptemplatesmodel.cpp:39
ChoicePage
Definition: choicepage.h:32
description
static const char description[]
Definition: main.cpp:29
AppTemplatesModel::AppTemplatesModel
AppTemplatesModel(ChoicePage *parent)
Definition: apptemplatesmodel.cpp:34
QStandardItem
choicepage.h
QObject::parent
QObject * parent() const
QFileInfo::baseName
QString baseName() const
apptemplateitem.h
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:39:44 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kapptemplate

Skip menu "kapptemplate"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal