1 | /* |
2 | * This file is part of the KDE Help Center |
3 | * |
4 | * Copyright (C) 1999 Matthias Elter (me@kde.org) |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
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. |
15 | * |
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. |
19 | */ |
20 | |
21 | #include "navigatoritem.h" |
22 | |
23 | #include "toc.h" |
24 | #include "docentry.h" |
25 | #include "view.h" |
26 | |
27 | #include <KDebug> |
28 | #include <KIconLoader> |
29 | |
30 | #include <QPixmap> |
31 | |
32 | using namespace KHC; |
33 | |
34 | NavigatorItem::NavigatorItem( DocEntry *entry, QTreeWidget *parent, |
35 | QTreeWidgetItem *after ) |
36 | : QTreeWidgetItem( parent, after ) |
37 | { |
38 | init( entry ); |
39 | } |
40 | |
41 | NavigatorItem::NavigatorItem( DocEntry *entry, QTreeWidgetItem *parent, |
42 | QTreeWidgetItem *after ) |
43 | : QTreeWidgetItem( parent, after ) |
44 | { |
45 | init( entry ); |
46 | } |
47 | |
48 | NavigatorItem::NavigatorItem( DocEntry *entry, QTreeWidget *parent ) |
49 | : QTreeWidgetItem( parent ) |
50 | { |
51 | init( entry ); |
52 | } |
53 | |
54 | NavigatorItem::NavigatorItem( DocEntry *entry, QTreeWidgetItem *parent ) |
55 | : QTreeWidgetItem( parent ) |
56 | { |
57 | init( entry ); |
58 | } |
59 | |
60 | NavigatorItem::~NavigatorItem() |
61 | { |
62 | delete mToc; |
63 | |
64 | if ( mAutoDeleteDocEntry ) delete mEntry; |
65 | } |
66 | |
67 | void NavigatorItem::init( DocEntry *entry ) |
68 | { |
69 | mEntry = entry; |
70 | mAutoDeleteDocEntry = false; |
71 | mToc = 0; |
72 | |
73 | updateItem(); |
74 | } |
75 | |
76 | DocEntry *NavigatorItem::entry() const |
77 | { |
78 | return mEntry; |
79 | } |
80 | |
81 | void NavigatorItem::setAutoDeleteDocEntry( bool enabled ) |
82 | { |
83 | mAutoDeleteDocEntry = enabled; |
84 | } |
85 | |
86 | void NavigatorItem::updateItem() |
87 | { |
88 | setText( 0, entry()->name() ); |
89 | setIcon( 0, SmallIcon( entry()->icon() ) ); |
90 | } |
91 | |
92 | void NavigatorItem::scheduleTOCBuild() |
93 | { |
94 | KUrl url ( entry()->url() ); |
95 | if ( !mToc && url.protocol() == "help" ) { |
96 | mToc = new TOC( this ); |
97 | |
98 | kDebug( 1400 ) << "Trying to build TOC for " << entry()->name() << endl; |
99 | mToc->setApplication( url.directory() ); |
100 | QString doc = View::langLookup( url.path() ); |
101 | // Enforce the original .docbook version, in case langLookup returns a |
102 | // cached version |
103 | if ( !doc.isNull() ) { |
104 | int pos = doc.indexOf( ".html" ); |
105 | if ( pos >= 0 ) { |
106 | doc.replace( pos, 5, ".docbook" ); |
107 | } |
108 | kDebug( 1400 ) << "doc = " << doc; |
109 | |
110 | mToc->build( doc ); |
111 | } |
112 | } |
113 | } |
114 | |
115 | void NavigatorItem::setExpanded( bool open ) |
116 | { |
117 | scheduleTOCBuild(); |
118 | QTreeWidgetItem::setExpanded( open ); |
119 | } |
120 | |
121 | // vim:ts=2:sw=2:et |
122 | |