delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / khelpcenter / navigatorappitem.cpp
blob82a3dc5a1383ac430a0be33af8e8af74e6168577
1 /*
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"
23 #include "docentry.h"
25 #include <kdebug.h>
26 #include <kservice.h>
27 #include <kservicegroup.h>
29 using namespace KHC;
31 NavigatorAppItem::NavigatorAppItem( DocEntry *entry, Q3ListView *parent,
32 const QString &relPath )
33 : NavigatorItem( entry, parent ),
34 mRelpath( relPath ),
35 mPopulated( false )
37 setExpandable( true );
40 NavigatorAppItem::NavigatorAppItem( DocEntry *entry, Q3ListViewItem *parent,
41 const QString &relPath )
42 : NavigatorItem( entry, parent ),
43 mRelpath( relPath ),
44 mPopulated( false )
46 setExpandable( true );
49 NavigatorAppItem::NavigatorAppItem( DocEntry *entry, Q3ListView *parent,
50 Q3ListViewItem *after )
51 : NavigatorItem( entry, parent, after ),
52 mPopulated( false )
54 setExpandable( true );
57 NavigatorAppItem::NavigatorAppItem( DocEntry *entry, Q3ListViewItem *parent,
58 Q3ListViewItem *after )
59 : NavigatorItem( entry, parent, after ),
60 mPopulated( false )
62 setExpandable( true );
65 void NavigatorAppItem::setRelpath( const QString &relpath )
67 mRelpath = 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;
78 populate();
80 Q3ListViewItem::setOpen(open);
83 void NavigatorAppItem::populate( bool recursive )
85 if ( mPopulated ) return;
87 KServiceGroup::Ptr root = KServiceGroup::group(mRelpath);
88 if ( !root ) {
89 kWarning() << "No Service groups\n";
90 return;
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;
99 NavigatorItem *item;
100 QString url;
102 switch ( e->sycocaType() ) {
103 case KST_KService:
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 );
113 break;
115 case KST_KServiceGroup:
117 KServiceGroup::Ptr g = KServiceGroup::Ptr::staticCast(e);
118 if ( ( g->childCount() == 0 ) || g->name().startsWith( '.' ) )
119 continue;
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 );
125 break;
127 default:
128 break;
131 sortChildItems( 0, true /* ascending */ );
132 mPopulated = true;
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() ) {
141 return QString();
145 if ( docPath.startsWith( QLatin1String("file:")) || docPath.startsWith( QLatin1String("http:") ) )
146 return docPath;
148 return QLatin1String( "help:/" ) + docPath;
151 // vim:ts=2:sw=2:et