1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*
* This file is part of the KDE Help Center
*
* Copyright (C) 2001 Waldo Bastian <bastian@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "navigatorappitem.h"
#include "docentry.h"
#include <kdebug.h>
#include <kservicegroup.h>
using namespace KHC;
NavigatorAppItem::NavigatorAppItem( DocEntry *entry, TQListView *parent,
const TQString &relPath )
: NavigatorItem( entry, parent ),
mRelpath( relPath ),
mPopulated( false )
{
setExpandable( true );
}
NavigatorAppItem::NavigatorAppItem( DocEntry *entry, TQListViewItem *parent,
const TQString &relPath )
: NavigatorItem( entry, parent ),
mRelpath( relPath ),
mPopulated( false )
{
setExpandable( true );
}
NavigatorAppItem::NavigatorAppItem( DocEntry *entry, TQListView *parent,
TQListViewItem *after )
: NavigatorItem( entry, parent, after ),
mPopulated( false )
{
setExpandable( true );
}
NavigatorAppItem::NavigatorAppItem( DocEntry *entry, TQListViewItem *parent,
TQListViewItem *after )
: NavigatorItem( entry, parent, after ),
mPopulated( false )
{
setExpandable( true );
}
void NavigatorAppItem::setRelpath( const TQString &relpath )
{
mRelpath = relpath;
}
void NavigatorAppItem::setOpen(bool open)
{
kdDebug() << "NavigatorAppItem::setOpen()" << endl;
if ( open && (childCount() == 0) && !mPopulated )
{
kdDebug() << "NavigatorAppItem::setOpen(" << this << ", "
<< mRelpath << ")" << endl;
populate();
}
TQListViewItem::setOpen(open);
}
void NavigatorAppItem::populate( bool recursive )
{
if ( mPopulated ) return;
KServiceGroup::Ptr root = KServiceGroup::group(mRelpath);
if ( !root ) {
kdWarning() << "No Service groups\n";
return;
}
KServiceGroup::List list = root->entries();
for ( KServiceGroup::List::ConstIterator it = list.begin();
it != list.end(); ++it )
{
KSycocaEntry * e = *it;
KService::Ptr s;
NavigatorItem *item;
KServiceGroup::Ptr g;
TQString url;
switch ( e->sycocaType() ) {
case KST_KService:
{
s = static_cast<KService*>(e);
url = documentationURL( s );
if ( !url.isEmpty() ) {
DocEntry *entry = new DocEntry( s->name(), url, s->icon() );
item = new NavigatorItem( entry, this );
item->setAutoDeleteDocEntry( true );
item->setExpandable( true );
}
break;
}
case KST_KServiceGroup:
{
g = static_cast<KServiceGroup*>(e);
if ( ( g->childCount() == 0 ) || g->name().startsWith( "." ) )
continue;
DocEntry *entry = new DocEntry( g->caption(), "", g->icon() );
NavigatorAppItem *appItem;
appItem = new NavigatorAppItem( entry, this, g->relPath() );
appItem->setAutoDeleteDocEntry( true );
if ( recursive ) appItem->populate( recursive );
break;
}
default:
break;
}
}
sortChildItems( 0, true /* ascending */ );
mPopulated = true;
}
TQString NavigatorAppItem::documentationURL( KService *s )
{
TQString docPath = s->property( "DocPath" ).toString();
if ( docPath.isEmpty() )
return TQString::null;
if ( docPath.startsWith( "file:") || docPath.startsWith( "http:" ) )
return docPath;
return TQString( "help:/" ) + docPath;
}
// vim:ts=2:sw=2:et
|