1/*
2 * glossary.h - part of the KDE Help Center
3 *
4 * Copyright (C) 2002 Frerich Raabe (raabe@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#ifndef KHC_GLOSSARY_H
21#define KHC_GLOSSARY_H
22
23#include <QTreeWidget>
24#include <QDomElement>
25#include <QList>
26#include <KSharedConfig>
27#include <QHash>
28#include <KProcess>
29
30class EntryItem;
31
32namespace KHC {
33
34 class GlossaryEntryXRef
35 {
36 friend QDataStream &operator>>( QDataStream &, GlossaryEntryXRef & );
37 public:
38 typedef QList<GlossaryEntryXRef> List;
39
40 GlossaryEntryXRef() {}
41 GlossaryEntryXRef( const QString &term, const QString &id ) :
42 m_term( term ),
43 m_id( id )
44 {
45 }
46
47 QString term() const { return m_term; }
48 QString id() const { return m_id; }
49
50 private:
51 QString m_term;
52 QString m_id;
53 };
54
55 inline QDataStream &operator<<( QDataStream &stream, const GlossaryEntryXRef &e )
56 {
57 return stream << e.term() << e.id();
58 }
59
60 inline QDataStream &operator>>( QDataStream &stream, GlossaryEntryXRef &e )
61 {
62 return stream >> e.m_term >> e.m_id;
63 }
64
65 class GlossaryEntry
66 {
67 friend QDataStream &operator>>( QDataStream &, GlossaryEntry & );
68 public:
69 GlossaryEntry() {}
70 GlossaryEntry( const QString &term, const QString &definition,
71 const GlossaryEntryXRef::List &seeAlso ) :
72 m_term( term ),
73 m_definition( definition ),
74 m_seeAlso( seeAlso )
75 { }
76
77 QString term() const { return m_term; }
78 QString definition() const { return m_definition; }
79 GlossaryEntryXRef::List seeAlso() const { return m_seeAlso; }
80
81 private:
82 QString m_term;
83 QString m_definition;
84 GlossaryEntryXRef::List m_seeAlso;
85 };
86
87 inline QDataStream &operator<<( QDataStream &stream, const GlossaryEntry &e )
88 {
89 return stream << e.term() << e.definition() << e.seeAlso();
90 }
91
92 inline QDataStream &operator>>( QDataStream &stream, GlossaryEntry &e )
93 {
94 return stream >> e.m_term >> e.m_definition >> e.m_seeAlso;
95 }
96
97 class Glossary : public QTreeWidget
98 {
99 Q_OBJECT
100 public:
101 Glossary( QWidget *parent );
102 virtual ~Glossary();
103
104 const GlossaryEntry &entry( const QString &id ) const;
105
106 static QString entryToHtml( const GlossaryEntry &entry );
107
108 public Q_SLOTS:
109 void slotSelectGlossEntry( const QString &id );
110
111 Q_SIGNALS:
112 void entrySelected( const GlossaryEntry &entry );
113
114 private Q_SLOTS:
115 void meinprocFinished(int exitCode, QProcess::ExitStatus exitStatus);
116 void treeItemSelected( QTreeWidgetItem *item );
117
118 protected:
119 virtual void showEvent(QShowEvent *event);
120
121 private:
122 enum CacheStatus { NeedRebuild, CacheOk };
123
124 CacheStatus cacheStatus() const;
125 int glossaryCTime() const;
126 void rebuildGlossaryCache();
127 void buildGlossaryTree();
128 QDomElement childElement( const QDomElement &e, const QString &name );
129
130 KSharedConfigPtr m_config;
131 QTreeWidgetItem *m_byTopicItem;
132 QTreeWidgetItem *m_alphabItem;
133 QString m_sourceFile;
134 QString m_cacheFile;
135 CacheStatus m_status;
136 QHash<QString, GlossaryEntry*> m_glossEntries;
137 QHash<QString, EntryItem*> m_idDict;
138 bool m_initialized;
139 static bool m_alreadyWarned;
140 };
141
142}
143
144#endif // KHC_GLOSSARY_H
145// vim:ts=2:sw=2:et
146