Root/
Source at commit 1322 created 12 years 8 months ago. By meklort, Add doxygen to utils folder | |
---|---|
1 | /*␊ |
2 | * Copyright (C) 2008 by Sebastian Pipping.␊ |
3 | * Copyright (C) 2008 Dimitri van Heesch.␊ |
4 | *␊ |
5 | * Permission to use, copy, modify, and distribute this software and its␊ |
6 | * documentation under the terms of the GNU General Public License is hereby ␊ |
7 | * granted. No representations are made about the suitability of this software ␊ |
8 | * for any purpose. It is provided "as is" without express or implied warranty.␊ |
9 | * See the GNU General Public License for more details.␊ |
10 | *␊ |
11 | * Documents produced by Doxygen are derivative works derived from the␊ |
12 | * input used in their production; they are not affected by this license.␊ |
13 | *␊ |
14 | * Sebastian Pipping <sebastian@pipping.org>␊ |
15 | */␊ |
16 | ␊ |
17 | #include "qhp.h"␊ |
18 | #include "qhpxmlwriter.h"␊ |
19 | #include "message.h"␊ |
20 | #include "config.h"␊ |
21 | #include "memberdef.h"␊ |
22 | #include "groupdef.h"␊ |
23 | #include "filedef.h"␊ |
24 | ␊ |
25 | #include <qstringlist.h>␊ |
26 | #include <string.h>␊ |
27 | ␊ |
28 | static QCString makeFileName(const char * withoutExtension)␊ |
29 | {␊ |
30 | if (!withoutExtension) return QCString();␊ |
31 | return QCString(withoutExtension)+".html";␊ |
32 | }␊ |
33 | ␊ |
34 | static QCString makeRef(const char * withoutExtension, const char * anchor)␊ |
35 | {␊ |
36 | if (!withoutExtension) return QCString(); ␊ |
37 | QCString result = makeFileName(withoutExtension);␊ |
38 | if (!anchor) return result;␊ |
39 | return result+"#"+anchor;␊ |
40 | }␊ |
41 | ␊ |
42 | Qhp::Qhp() : m_prevSectionLevel(0), m_sectionLevel(0)␊ |
43 | {␊ |
44 | m_doc.setIndentLevel(0);␊ |
45 | m_toc.setIndentLevel(2);␊ |
46 | m_index.setIndentLevel(2);␊ |
47 | m_files.setIndentLevel(2);␊ |
48 | }␊ |
49 | ␊ |
50 | Qhp::~Qhp()␊ |
51 | {␊ |
52 | clearPrevSection();␊ |
53 | }␊ |
54 | ␊ |
55 | void Qhp::initialize()␊ |
56 | {␊ |
57 | /*␊ |
58 | <QtHelpProject version="1.0">␊ |
59 | <namespace>mycompany.com.myapplication.1_0</namespace>␊ |
60 | <virtualFolder>doc</virtualFolder>␊ |
61 | <customFilter name="My Application 1.0">␊ |
62 | <filterAttribute>myapp</filterAttribute>␊ |
63 | <filterAttribute>1.0</filterAttribute>␊ |
64 | </customFilter>␊ |
65 | <filterSection>␊ |
66 | <filterAttribute>myapp</filterAttribute>␊ |
67 | <filterAttribute>1.0</filterAttribute>␊ |
68 | ..␊ |
69 | */␊ |
70 | QCString nameSpace = Config_getString("QHP_NAMESPACE");␊ |
71 | QCString virtualFolder = Config_getString("QHP_VIRTUAL_FOLDER");␊ |
72 | ␊ |
73 | const char * rootAttributes[] =␊ |
74 | { "version", "1.0", 0 };␊ |
75 | ␊ |
76 | m_doc.open("QtHelpProject", rootAttributes);␊ |
77 | m_doc.openCloseContent("namespace", nameSpace);␊ |
78 | m_doc.openCloseContent("virtualFolder", virtualFolder);␊ |
79 | ␊ |
80 | // Add custom filter␊ |
81 | QCString filterName = Config_getString("QHP_CUST_FILTER_NAME");␊ |
82 | if (!filterName.isEmpty())␊ |
83 | {␊ |
84 | const char * tagAttributes[] = ␊ |
85 | { "name", filterName, 0 };␊ |
86 | m_doc.open("customFilter", tagAttributes);␊ |
87 | ␊ |
88 | QStringList customFilterAttributes = QStringList::split(QChar(' '), Config_getString("QHP_CUST_FILTER_ATTRS"));␊ |
89 | for (int i = 0; i < (int)customFilterAttributes.count(); i++)␊ |
90 | {␊ |
91 | m_doc.openCloseContent("filterAttribute", customFilterAttributes[i]);␊ |
92 | }␊ |
93 | m_doc.close("customFilter");␊ |
94 | }␊ |
95 | ␊ |
96 | m_doc.open("filterSection");␊ |
97 | ␊ |
98 | // Add section attributes␊ |
99 | QStringList sectionFilterAttributes = QStringList::split(QChar(' '),␊ |
100 | Config_getString("QHP_SECT_FILTER_ATTRS"));␊ |
101 | if (!sectionFilterAttributes.contains(QString("doxygen")))␊ |
102 | {␊ |
103 | sectionFilterAttributes << "doxygen";␊ |
104 | }␊ |
105 | for (int i = 0; i < (int)sectionFilterAttributes.count(); i++)␊ |
106 | {␊ |
107 | m_doc.openCloseContent("filterAttribute", sectionFilterAttributes[i]);␊ |
108 | }␊ |
109 | ␊ |
110 | m_toc.open("toc");␊ |
111 | ␊ |
112 | // Add extra root node␊ |
113 | QCString fullProjectname = getFullProjectName();␊ |
114 | const char * const attributes[] =␊ |
115 | { "title", fullProjectname,␊ |
116 | "ref", "index.html",␊ |
117 | NULL␊ |
118 | };␊ |
119 | m_toc.open("section", attributes);␊ |
120 | m_prevSectionLevel = 1;␊ |
121 | m_sectionLevel = 1;␊ |
122 | ␊ |
123 | m_index.open("keywords");␊ |
124 | m_files.open("files");␊ |
125 | }␊ |
126 | ␊ |
127 | void Qhp::finalize()␊ |
128 | {␊ |
129 | // Finish TOC␊ |
130 | handlePrevSection();␊ |
131 | for (int i = m_prevSectionLevel; i > 0; i--)␊ |
132 | {␊ |
133 | m_toc.close("section");␊ |
134 | }␊ |
135 | m_toc.close("toc");␊ |
136 | m_doc.insert(m_toc);␊ |
137 | ␊ |
138 | // Finish index␊ |
139 | m_index.close("keywords");␊ |
140 | m_doc.insert(m_index);␊ |
141 | ␊ |
142 | // Finish files␊ |
143 | m_files.close("files");␊ |
144 | m_doc.insert(m_files);␊ |
145 | ␊ |
146 | m_doc.close("filterSection");␊ |
147 | m_doc.close("QtHelpProject");␊ |
148 | ␊ |
149 | QCString fileName = Config_getString("HTML_OUTPUT") + "/" + getQhpFileName();␊ |
150 | QFile file(fileName);␊ |
151 | if (!file.open(IO_WriteOnly))␊ |
152 | {␊ |
153 | err("Could not open file %s for writing\n", fileName.data());␊ |
154 | exit(1);␊ |
155 | }␊ |
156 | m_doc.dumpTo(file);␊ |
157 | }␊ |
158 | ␊ |
159 | void Qhp::incContentsDepth()␊ |
160 | {␊ |
161 | m_sectionLevel++;␊ |
162 | }␊ |
163 | ␊ |
164 | void Qhp::decContentsDepth()␊ |
165 | {␊ |
166 | if (m_sectionLevel <= 0)␊ |
167 | {␊ |
168 | return;␊ |
169 | }␊ |
170 | m_sectionLevel--;␊ |
171 | }␊ |
172 | ␊ |
173 | void Qhp::addContentsItem(bool /*isDir*/, const char * name, ␊ |
174 | const char * /*ref*/, const char * file, ␊ |
175 | const char * /*anchor*/)␊ |
176 | {␊ |
177 | // Backup difference before modification␊ |
178 | int diff = m_prevSectionLevel - m_sectionLevel;␊ |
179 | ␊ |
180 | handlePrevSection();␊ |
181 | setPrevSection(name, file, m_sectionLevel);␊ |
182 | ␊ |
183 | // Close sections as needed␊ |
184 | for (; diff > 0; diff--)␊ |
185 | {␊ |
186 | m_toc.close("section");␊ |
187 | }␊ |
188 | }␊ |
189 | ␊ |
190 | void Qhp::addIndexItem(Definition *context,MemberDef *md,␊ |
191 | const char *word)␊ |
192 | {␊ |
193 | (void)word;␊ |
194 | ␊ |
195 | if (md) // member␊ |
196 | {␊ |
197 | static bool separateMemberPages = Config_getBool("SEPARATE_MEMBER_PAGES");␊ |
198 | if (context==0) // global member␊ |
199 | {␊ |
200 | if (md->getGroupDef())␊ |
201 | context = md->getGroupDef();␊ |
202 | else if (md->getFileDef())␊ |
203 | context = md->getFileDef();␊ |
204 | }␊ |
205 | if (context==0) return; // should not happen␊ |
206 | QCString cfname = md->getOutputFileBase();␊ |
207 | QCString cfiname = context->getOutputFileBase();␊ |
208 | QCString level1 = context->name();␊ |
209 | QCString level2 = word ? QCString(word) : md->name();␊ |
210 | QCString contRef = separateMemberPages ? cfname : cfiname;␊ |
211 | QCString anchor = md->anchor();␊ |
212 | ␊ |
213 | QCString ref;␊ |
214 | ␊ |
215 | // <keyword name="foo" id="MyApplication::foo" ref="doc.html#foo"/>␊ |
216 | ref = makeRef(contRef, anchor);␊ |
217 | QCString id = level1+"::"+level2;␊ |
218 | const char * attributes[] =␊ |
219 | {␊ |
220 | "name", level2,␊ |
221 | "id", id,␊ |
222 | "ref", ref,␊ |
223 | 0␊ |
224 | };␊ |
225 | m_index.openClose("keyword", attributes);␊ |
226 | }␊ |
227 | else if (context) // container␊ |
228 | {␊ |
229 | // <keyword name="Foo" id="Foo" ref="doc.html"/>␊ |
230 | QCString contRef = context->getOutputFileBase();␊ |
231 | QCString level1 = word ? QCString(word) : context->name();␊ |
232 | QCString ref = makeFileName(contRef);␊ |
233 | const char * attributes[] =␊ |
234 | {␊ |
235 | "name", level1,␊ |
236 | "id", level1,␊ |
237 | "ref", ref,␊ |
238 | 0␊ |
239 | };␊ |
240 | m_index.openClose("keyword", attributes);␊ |
241 | }␊ |
242 | }␊ |
243 | ␊ |
244 | void Qhp::addIndexFile(const char * name)␊ |
245 | {␊ |
246 | addFile(name);␊ |
247 | }␊ |
248 | ␊ |
249 | QCString Qhp::getQhpFileName()␊ |
250 | {␊ |
251 | return "index.qhp";␊ |
252 | }␊ |
253 | ␊ |
254 | QCString Qhp::getFullProjectName()␊ |
255 | {␊ |
256 | QCString projectName = Config_getString("PROJECT_NAME");␊ |
257 | QCString versionText = Config_getString("PROJECT_NUMBER");␊ |
258 | if (projectName.isEmpty()) projectName="Root";␊ |
259 | return projectName + (versionText.isEmpty()␊ |
260 | ? QCString("")␊ |
261 | : QCString(" ") + versionText);␊ |
262 | }␊ |
263 | ␊ |
264 | void Qhp::handlePrevSection()␊ |
265 | {␊ |
266 | /*␊ |
267 | <toc>␊ |
268 | <section title="My Application Manual" ref="index.html">␊ |
269 | <section title="Chapter 1" ref="doc.html#chapter1"/>␊ |
270 | <section title="Chapter 2" ref="doc.html#chapter2"/>␊ |
271 | <section title="Chapter 3" ref="doc.html#chapter3"/>␊ |
272 | </section>␊ |
273 | </toc>␊ |
274 | */␊ |
275 | ␊ |
276 | if (m_prevSectionTitle.isNull())␊ |
277 | {␊ |
278 | return;␊ |
279 | }␊ |
280 | ␊ |
281 | // We skip "Main Page" as our extra root is pointing to that␊ |
282 | if (!((m_prevSectionLevel==1) && (m_prevSectionTitle=="Main Page")))␊ |
283 | {␊ |
284 | QCString finalRef = makeFileName(m_prevSectionRef);␊ |
285 | ␊ |
286 | const char * const attributes[] =␊ |
287 | { "title", m_prevSectionTitle,␊ |
288 | "ref", finalRef,␊ |
289 | NULL␊ |
290 | };␊ |
291 | ␊ |
292 | if (m_prevSectionLevel < m_sectionLevel)␊ |
293 | {␊ |
294 | // Section with children␊ |
295 | m_toc.open("section", attributes);␊ |
296 | }␊ |
297 | else␊ |
298 | {␊ |
299 | // Section without children␊ |
300 | m_toc.openClose("section", attributes);␊ |
301 | }␊ |
302 | }␊ |
303 | ␊ |
304 | clearPrevSection();␊ |
305 | }␊ |
306 | ␊ |
307 | void Qhp::setPrevSection(const char * title, const char * ref, int level)␊ |
308 | {␊ |
309 | m_prevSectionTitle = title;␊ |
310 | m_prevSectionRef = ref;␊ |
311 | m_prevSectionLevel = level;␊ |
312 | }␊ |
313 | ␊ |
314 | void Qhp::clearPrevSection()␊ |
315 | {␊ |
316 | m_prevSectionTitle.resize(0);␊ |
317 | m_prevSectionRef.resize(0);␊ |
318 | }␊ |
319 | ␊ |
320 | void Qhp::addFile(const char * fileName)␊ |
321 | {␊ |
322 | m_files.openCloseContent("file", fileName);␊ |
323 | }␊ |
324 | ␊ |
325 | void Qhp::addImageFile(const char *fileName)␊ |
326 | {␊ |
327 | addFile(fileName);␊ |
328 | }␊ |
329 | ␊ |
330 | void Qhp::addStyleSheetFile(const char *fileName)␊ |
331 | {␊ |
332 | addFile(fileName);␊ |
333 | }␊ |
334 | ␊ |
335 |