1
/* This file is part of the KDE project
2
Copyright 2007 Will Stephenson <wstephenson@kde.org>
3
Copyright (C) 2009 Ben Cooksley <bcooksley@kde.org>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License or (at your option) version 3 or any later version
9
accepted by the membership of KDE e.V. (or its successor approved
10
by the membership of KDE e.V.), which shall act as a proxy
11
defined in Section 14 of version 3 of the license.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include <KCModuleInfo>
29
static bool childIsLessThan( MenuItem *left, MenuItem *right )
31
return left->weight() < right->weight();
34
class MenuItem::Private {
39
QList<MenuItem*> children;
44
KService::Ptr service;
48
MenuItem::MenuItem( bool isMenu, MenuItem * itsParent )
51
d->parent = itsParent;
55
d->parent->children().append( this );
61
qDeleteAll( d->children );
65
void MenuItem::sortChildrenByWeight()
67
qSort( d->children.begin(), d->children.end(), childIsLessThan );
70
MenuItem * MenuItem::child( int index )
72
return d->children.at(index);
75
QStringList MenuItem::keywords()
77
QStringList listOfKeywords;
79
listOfKeywords << d->item.keywords() << d->name;
80
foreach ( MenuItem * child, d->children ) {
81
listOfKeywords += child->keywords();
83
return listOfKeywords;
86
MenuItem* MenuItem::parent() const
91
QList<MenuItem*>& MenuItem::children() const
96
KService::Ptr& MenuItem::service() const
101
KCModuleInfo& MenuItem::item() const
106
QString& MenuItem::name() const
111
QString& MenuItem::category() const
116
int MenuItem::weight()
121
bool MenuItem::menu() const
126
void MenuItem::setService( const KService::Ptr& service )
128
d->service = service;
129
d->category = service->property("X-KDE-System-Settings-Category").toString();
130
d->name = service->name();
131
d->item = KCModuleInfo( service );
132
const QVariant itemWeight = service->property( "X-KDE-Weight", QVariant::Int );
133
if( itemWeight.isValid() ) {
134
d->weight = itemWeight.toInt();