5
* Copyright (C) 2010 David Hubner <hubnerd@ntlworld.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include "kcmtreeitem.h"
28
KcmTreeItem::KcmTreeItem(const KService::Ptr module, KcmTreeItem *parent) : m_parent(parent), m_module(module),
29
m_moduleInfo(new KCModuleInfo(m_module))
33
KcmTreeItem::KcmTreeItem() : m_parent(NULL), m_moduleInfo(new KCModuleInfo())
37
KcmTreeItem::~KcmTreeItem()
39
qDeleteAll(m_children);
43
void KcmTreeItem::addChild(KcmTreeItem *child)
45
m_children.append(child);
48
KcmTreeItem *KcmTreeItem::child(const int row)
50
if(childCount() > row) return m_children.value(row);
54
int KcmTreeItem::childCount()
56
return m_children.count();
59
int KcmTreeItem::columnCount()
61
// Hard coded, menu should never have more than one column
65
KcmTreeItem *KcmTreeItem::parent()
70
int KcmTreeItem::row()
74
return indexOf(const_cast<KcmTreeItem*>(this));
80
int KcmTreeItem::indexOf(KcmTreeItem *item)
84
return m_parent->m_children.indexOf(item);
90
QString KcmTreeItem::data() const
92
return m_moduleInfo->moduleName();
95
QString KcmTreeItem::category() const
97
return m_module->property("X-KDE-KInfoCenter-Category").toString().trimmed();
100
KcmTreeItem::itemType KcmTreeItem::type() const
105
KcmTreeItem *KcmTreeItem::containsCategory(const QString& category)
107
foreach(KcmTreeItem *item, m_children)
109
if(item->type() == CATEGORY)
111
if(item->category().contains(category))
117
if(item->containsCategory(category))
127
KCModuleInfo KcmTreeItem::kcm() const
129
return *m_moduleInfo;
132
int KcmTreeItem::weight()
134
return m_moduleInfo->weight();
137
KIcon KcmTreeItem::icon() const
139
return KIcon(m_moduleInfo->icon());
142
QString KcmTreeItem::whatsThis() const
144
return m_moduleInfo->comment();
147
bool KcmTreeItem::childrenRegExp(const QRegExp& pattern)
149
foreach(KcmTreeItem *item, m_children)
151
if((item->keywords().filter(pattern).count() > 0) == true)
159
QStringList KcmTreeItem::keywords() const
161
if(m_moduleInfo->keywords().isEmpty()) return QStringList(data());
162
return m_moduleInfo->keywords();