blob: 0ecf30cbed6fa5de213a5398ac1aae46f9f0362f (
plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/***************************************************************************
dtds.h - description
-------------------
begin : 12.02.2004 (extract from quanta_init and others)
copyright : (C) 2000 by Dmitry Poplavsky & Alexander Yakovlev <pdima@users.sourceforge.net,yshurik@linuxfan.com>
(C) 2001-2003 by Andras Mantia <amantia@kde.org>
(C) 2000, 2003 by Eric Laffoon <sequitur@kde.org>
(C) 2004 by Jens Herden <jhe at epost.de>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; version 2 of the License. *
* *
***************************************************************************/
#ifndef DTDS_H
#define DTDS_H
// application specific includes
#include "qtag.h"
#include "tqobject.h"
#include "tqfile.h"
//qt includes
#include <tqdict.h>
//kde includes
#include <kdebug.h>
class TQDomNode;
class TQDomDocument;
class TQTag;
class TQString;
class TQStringList;
class KConfig;
struct DTDStruct;
/** @short This class manages the DTD's for Quanta.
*
* The constructor only loads the necessary information from the description.rc file.
* The rest is later loaded on demand of the find() function.
*/
class DTDs : public TQObject
{
Q_OBJECT
TQ_OBJECT
public:
/**
* since this class is a singleton you must use this function to access it
* @return the class pointer
*/
static DTDs* ref(TQObject *tqparent = 0L)
{
static DTDs *m_ref;
if (!m_ref) m_ref = new DTDs(tqparent);
return m_ref;
}
~DTDs();
/**
* searchs a dtd and loads it from disk if not present in memory
*
* @param dtdName name of the dtd, will be converted to lowercase inside
* @return the found dtd structure
*/
const DTDStruct * find (const TQString &dtdName)
{
// kdDebug(24000) << "dtds::find " << dtdName << endl;
DTDStruct *dtd = m_dict->find(dtdName.lower()) ;
if (dtd && ! dtd->loaded ) readTagDir2(dtd);
return dtd;
}
/**
* @param nickName nickname of the DTD
* @return the name (identifier) to the nickname. If the DTD is not found you get
* nickName back!
*/
TQString getDTDNameFromNickName(const TQString& nickName);
/**
* @param name name of the DTD
* @return the nickname to the name. If the DTD is not found you get
* name back!
*/
TQString getDTDNickNameFromName(const TQString& name)
{
DTDStruct *dtd = m_dict->find(name);
if ( dtd )
return dtd->nickName;
else
return name;
};
/**
* creates a list of all available nicknames
*
* @param topLevelOnly true = only the DTD's which can be the main DTD of a document
* are included
* @return all known nick names
*/
TQStringList nickNameList (bool topLevelOnly=false);
/**
* creates a list of all available names
*
* @param topLevelOnly true = only the DTD's which can be the main DTD of a document
* are included
* @return all known names
*/
TQStringList nameList (bool topLevelOnly=false);
/**
* creates a list with the path to the description.rc of all available DTEPs
*
* @param topLevelOnly true = only the DTD's which can be the main DTD of a document
* are included
* @return a list with the name and the path to the description.rc of all available DTEPs in form of
* DTEPName | path to description.rc
*/
TQStringList fileNameList (bool topLevelOnly=false);
/** finds a dtd for a given url
*
* @param url look for this file
* @return the first DTD for this mimetype or the "empty" DTD if not found
*/
const DTDStruct * DTDforURL(const KURL &url);
/**
* Checks if a DTD can handle the file or not.
* @param dtd the DTD to check against
* @param url the url pointing to the file
* @return true if it can handle
*/
static bool canHandle(const DTDStruct *dtd, const KURL &url);
public slots:
/** Load a DTD and convert to a DTEP */
void slotLoadDTD();
/** Loads a DTEP from a directory
* @param dirName The directory containing the DTEP
* @param askForAutoLoad if true and the user answer with yes to the autoload question
* the DTEP will be copied to the local resource directory and will be autoloaded on
* startup
*/
void slotLoadDTEP(const TQString& dirName, bool askForAutoLoad);
/**
* Loads (replaces) the entities for a DTEP.
*/
void slotLoadEntities();
signals:
/** used to hide the splash screen */
void hideSplash();
/** DTD has changed need reparse */
void forceReparse();
/** Enable/disbale the idle timer*/
void enableIdleTimer(bool);
void loadToolbarForDTD(const TQString&);
private:
/** The constructor is privat because we use singleton patter.
* If you need the class use DTDs::ref() for
* construction and reference
*/
DTDs(TQObject *tqparent);
/** Reads the tag files and the description.rc from tagDir in order to
* build up the internal DTD and tag structures.
*
* @param dirName folder where dtd definition is located
* @param loadAll true = all information and tags will be loaded now (@ref readTagDir2 will be called)
* @return true = no error
*/
bool readTagDir(const TQString &dirName, bool loadAll=true);
/** Reads the tag files and the description.rc from tagDir in order to
* build up the internal DTD and tag structures.
*
* @param dtd the already preloaded dtd structure
* @return true = no error
*/
bool readTagDir2(DTDStruct *dtd);
/** helper for @ref readTagDir2
*
* @param dtd the already preloaded dtd structure
*/
void resolveInherited (DTDStruct *dtd);
/** Reads the tags from the tag files.
*
* @param fileName path of the tag file
* @param parentDTD the DTD where the tags belog to
* @param tagList the list where the tags are inserted
* @return the number of read tags.
*/
uint readTagFile(const TQString& fileName, DTDStruct* parentDTD, TQTagList *tagList);
/** Parses the dom document and retrieve the tag attributes
*
* @param dom the DOM node containing the tag definition
* @param tag the TQTag object that will be initialized by using the information in dom
* @param common will be true, if the tag is a just a list of common group attributes
*/
void setAttributes(TQDomNode *dom, TQTag* tag, bool &common);
/** removes dtd from dictonary and deletes all components
*
* @param dtd the dtd to delete
*/
void removeDTD(DTDStruct *dtd);
/** helper to read the tag files */
TQDomDocument *m_doc;
/** dictonary with references to all DTD's in memory */
TQDict<DTDStruct> *m_dict;
};
#endif
|