~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kinfocenter/kcmtreeitem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 *  kcmtreeitem.h
 
4
 *
 
5
 *  Copyright (C) 2010 David Hubner <hubnerd@ntlworld.com>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 *
 
21
 */
 
22
 
 
23
//Local
 
24
#include "kcmtreeitem.h"
 
25
 
 
26
//KDE
 
27
#include <KDebug>
 
28
KcmTreeItem::KcmTreeItem(const KService::Ptr module, KcmTreeItem *parent) : m_parent(parent), m_module(module), 
 
29
  m_moduleInfo(new KCModuleInfo(m_module))
 
30
{
 
31
}
 
32
 
 
33
KcmTreeItem::KcmTreeItem() : m_parent(NULL), m_moduleInfo(new KCModuleInfo())
 
34
{
 
35
}
 
36
 
 
37
KcmTreeItem::~KcmTreeItem()
 
38
{
 
39
  qDeleteAll(m_children);
 
40
  delete m_moduleInfo;
 
41
}
 
42
 
 
43
void KcmTreeItem::addChild(KcmTreeItem *child) 
 
44
{
 
45
  m_children.append(child);
 
46
}
 
47
 
 
48
KcmTreeItem *KcmTreeItem::child(const int row)
 
49
{
 
50
  if(childCount() > row) return m_children.value(row);
 
51
  return NULL;
 
52
}
 
53
 
 
54
int KcmTreeItem::childCount() 
 
55
{
 
56
  return m_children.count();
 
57
}
 
58
 
 
59
int KcmTreeItem::columnCount()
 
60
{
 
61
  // Hard coded, menu should never have more than one column
 
62
  return 1;
 
63
}
 
64
 
 
65
KcmTreeItem *KcmTreeItem::parent()
 
66
{
 
67
  return m_parent;
 
68
}
 
69
 
 
70
int KcmTreeItem::row()
 
71
{
 
72
  if (m_parent)
 
73
  {
 
74
    return indexOf(const_cast<KcmTreeItem*>(this));
 
75
  }
 
76
  
 
77
  return 0;
 
78
}
 
79
 
 
80
int KcmTreeItem::indexOf(KcmTreeItem *item)
 
81
{
 
82
  if (m_parent)
 
83
  {
 
84
    return m_parent->m_children.indexOf(item);
 
85
  }
 
86
  
 
87
  return 0;
 
88
}
 
89
 
 
90
QString KcmTreeItem::data() const
 
91
{
 
92
  return m_moduleInfo->moduleName();
 
93
}
 
94
 
 
95
QString KcmTreeItem::category() const
 
96
{
 
97
  return m_module->property("X-KDE-KInfoCenter-Category").toString().trimmed();
 
98
}
 
99
 
 
100
KcmTreeItem::itemType KcmTreeItem::type() const
 
101
{
 
102
  return KCM;
 
103
}
 
104
 
 
105
KcmTreeItem *KcmTreeItem::containsCategory(const QString& category) 
 
106
{
 
107
  foreach(KcmTreeItem *item, m_children)
 
108
  {
 
109
    if(item->type() == CATEGORY)
 
110
    {
 
111
      if(item->category().contains(category))
 
112
      {
 
113
        return item;
 
114
      }
 
115
      else
 
116
      {
 
117
        if(item->containsCategory(category))
 
118
        {
 
119
          return item;
 
120
        }
 
121
      }
 
122
    }
 
123
  }
 
124
  return NULL;
 
125
}
 
126
 
 
127
KCModuleInfo KcmTreeItem::kcm() const 
 
128
{
 
129
  return *m_moduleInfo;
 
130
}
 
131
 
 
132
int KcmTreeItem::weight()
 
133
{
 
134
  return m_moduleInfo->weight();
 
135
}
 
136
 
 
137
KIcon KcmTreeItem::icon() const
 
138
{
 
139
  return KIcon(m_moduleInfo->icon());
 
140
}
 
141
 
 
142
QString KcmTreeItem::whatsThis() const
 
143
{
 
144
  return m_moduleInfo->comment();
 
145
}
 
146
 
 
147
bool KcmTreeItem::childrenRegExp(const QRegExp& pattern)
 
148
{
 
149
  foreach(KcmTreeItem *item, m_children)
 
150
  {
 
151
    if((item->keywords().filter(pattern).count() > 0) == true)
 
152
    {
 
153
      return true;
 
154
    }
 
155
  }
 
156
  return false;
 
157
}
 
158
 
 
159
QStringList KcmTreeItem::keywords() const
 
160
{
 
161
  if(m_moduleInfo->keywords().isEmpty()) return QStringList(data());
 
162
  return m_moduleInfo->keywords();
 
163
}