2 * This file is part of the KDE Help Center
4 * Copyright (C) 2001 Waldo Bastian <bastian@kde.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License version 2 or at your option version 3 as published
9 * by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "navigatorappitem.h"
27 #include <kservicegroup.h>
31 NavigatorAppItem::NavigatorAppItem( DocEntry
*entry
, Q3ListView
*parent
,
32 const QString
&relPath
)
33 : NavigatorItem( entry
, parent
),
37 setExpandable( true );
40 NavigatorAppItem::NavigatorAppItem( DocEntry
*entry
, Q3ListViewItem
*parent
,
41 const QString
&relPath
)
42 : NavigatorItem( entry
, parent
),
46 setExpandable( true );
49 NavigatorAppItem::NavigatorAppItem( DocEntry
*entry
, Q3ListView
*parent
,
50 Q3ListViewItem
*after
)
51 : NavigatorItem( entry
, parent
, after
),
54 setExpandable( true );
57 NavigatorAppItem::NavigatorAppItem( DocEntry
*entry
, Q3ListViewItem
*parent
,
58 Q3ListViewItem
*after
)
59 : NavigatorItem( entry
, parent
, after
),
62 setExpandable( true );
65 void NavigatorAppItem::setRelpath( const QString
&relpath
)
70 void NavigatorAppItem::setOpen(bool open
)
72 kDebug() << "NavigatorAppItem::setOpen()";
74 if ( open
&& (childCount() == 0) && !mPopulated
)
76 kDebug() << "NavigatorAppItem::setOpen(" << this << ", "
77 << mRelpath
<< ")" << endl
;
80 Q3ListViewItem::setOpen(open
);
83 void NavigatorAppItem::populate( bool recursive
)
85 if ( mPopulated
) return;
87 KServiceGroup::Ptr root
= KServiceGroup::group(mRelpath
);
89 kWarning() << "No Service groups\n";
92 KServiceGroup::List list
= root
->entries();
95 for ( KServiceGroup::List::ConstIterator it
= list
.constBegin();
96 it
!= list
.constEnd(); ++it
)
98 const KSycocaEntry::Ptr e
= *it
;
102 switch ( e
->sycocaType() ) {
105 const KService::Ptr s
= KService::Ptr::staticCast(e
);
106 url
= documentationURL( s
.data() );
107 if ( !url
.isEmpty() ) {
108 DocEntry
*entry
= new DocEntry( s
->name(), url
, s
->icon() );
109 item
= new NavigatorItem( entry
, this );
110 item
->setAutoDeleteDocEntry( true );
111 item
->setExpandable( true );
115 case KST_KServiceGroup
:
117 KServiceGroup::Ptr g
= KServiceGroup::Ptr::staticCast(e
);
118 if ( ( g
->childCount() == 0 ) || g
->name().startsWith( '.' ) )
120 DocEntry
*entry
= new DocEntry( g
->caption(), "", g
->icon() );
121 NavigatorAppItem
*appItem
;
122 appItem
= new NavigatorAppItem( entry
, this, g
->relPath() );
123 appItem
->setAutoDeleteDocEntry( true );
124 if ( recursive
) appItem
->populate( recursive
);
131 sortChildItems( 0, true /* ascending */ );
135 QString
NavigatorAppItem::documentationURL( const KService
*s
)
137 QString docPath
= s
->property( QLatin1String("DocPath") ).toString();
138 if ( docPath
.isEmpty() ) {
139 docPath
= s
->property( QLatin1String("X-DocPath") ).toString();
140 if ( docPath
.isEmpty() ) {
145 if ( docPath
.startsWith( QLatin1String("file:")) || docPath
.startsWith( QLatin1String("http:") ) )
148 return QLatin1String( "help:/" ) + docPath
;