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

kalgebra

  • sources
  • kde-4.14
  • kdeedu
  • kalgebra
  • mobile
pluginsmodel.cpp
Go to the documentation of this file.
1 /*************************************************************************************
2  * Copyright (C) 2010 by Aleix Pol <aleixpol@kde.org> *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License *
6  * as published by the Free Software Foundation; either version 2 *
7  * of the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the Free Software *
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17  *************************************************************************************/
18 
19 
20 #include "pluginsmodel.h"
21 #include <KStandardDirs>
22 #include <KConfigGroup>
23 #include <KConfig>
24 #include <QIcon>
25 #include <QDir>
26 #include <QDebug>
27 
28 PluginsModel::PluginsModel(QObject* parent) :QStandardItemModel(parent)
29 {
30  QHash<int, QByteArray> rolenames=QStandardItemModel::roleNames();
31  rolenames.insert(PathRole, "path");
32  rolenames.insert(PriorityRole, "priority");
33  rolenames.insert(TitleRole, "title");
34  rolenames.insert(SubtitleRole, "subtitle");
35  setRoleNames(rolenames);
36 
37  QStringList foundPlugins = KGlobal::dirs()->findAllResources("appdata", "plugins/*.desktop");
38 
39  qDebug() << "Plugins found:" << foundPlugins;
40 
41  QList<QStandardItem*> items;
42  Q_FOREACH(const QString& file, foundPlugins) {
43  KConfig info(file, KConfig::SimpleConfig, "appdata");
44  KConfigGroup cg = info.group("Desktop Entry");
45  QStandardItem* item = new QStandardItem;
46 
47  QString postfix = "plugins/"+cg.readEntry("X-KDE-PluginInfo-Name", QString());
48  QString scriptPath = KStandardDirs::locate("appdata", postfix);
49 
50  Q_ASSERT(!scriptPath.isEmpty());
51 
52  QVariant priority = cg.readEntry("X-KAlgebra-Priority", QString());
53  if(!priority.isValid())
54  priority = 1000;
55 
56  item->setData(scriptPath, PathRole);
57  item->setData(priority, PriorityRole);
58  item->setData(cg.readEntry("Name", QString()), TitleRole);
59  item->setData(cg.readEntry("Comment", QString()), SubtitleRole);
60  item->setData(cg.readEntry("Icon", QString()), Qt::DecorationRole);
61 
62  items += item;
63  }
64  invisibleRootItem()->appendRows(items);
65  setSortRole(PriorityRole);
66  sort(0, Qt::DescendingOrder);
67 }
68 
69 QString PluginsModel::pluginPath(int row)
70 {
71  return data(index(row, 0), PathRole).toString();
72 }
QStandardItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QStandardItemModel
QHash::insert
iterator insert(const Key &key, const T &value)
QAbstractItemModel::setRoleNames
void setRoleNames(const QHash< int, QByteArray > &roleNames)
QStandardItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const
QStandardItemModel::invisibleRootItem
QStandardItem * invisibleRootItem() const
PluginsModel::PriorityRole
Definition: pluginsmodel.h:29
QAbstractItemModel::roleNames
const QHash< int, QByteArray > & roleNames() const
QStandardItem::setData
virtual void setData(const QVariant &value, int role)
QHash
QObject
QString::isEmpty
bool isEmpty() const
QStandardItemModel::setSortRole
void setSortRole(int role)
pluginsmodel.h
QString
QList
QStandardItem::appendRows
void appendRows(const QList< QStandardItem * > &items)
PluginsModel::TitleRole
Definition: pluginsmodel.h:29
QStringList
QStandardItemModel::item
QStandardItem * item(int row, int column) const
PluginsModel::PluginsModel
PluginsModel(QObject *parent=0)
Definition: pluginsmodel.cpp:28
PluginsModel::PathRole
Definition: pluginsmodel.h:29
QStandardItem
QStandardItemModel::sort
virtual void sort(int column, Qt::SortOrder order)
QVariant::toString
QString toString() const
PluginsModel::SubtitleRole
Definition: pluginsmodel.h:29
QVariant
PluginsModel::pluginPath
QString pluginPath(int row)
qml can't access data. Yay!
Definition: pluginsmodel.cpp:69
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:11:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalgebra

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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