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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
Index: khelpcenter/table-of-contents.xslt
================================================================================
--- khelpcenter/docentry.cpp
+++ khelpcenter/docentry.cpp
@@ -1,5 +1,6 @@
#include <qregexp.h>
#include <qfileinfo.h>
+#include <stdlib.h>
#include <kdebug.h>
#include <kdesktopfile.h>
@@ -206,6 +207,37 @@
{
KDesktopFile file( fileName );
+ static QString desktop;
+ if (desktop.isNull()) {
+ QString win_man = getenv("WINDOWMANAGER");
+ if (win_man.contains ("gnome", FALSE))
+ desktop = "GNOME";
+ else if (win_man.contains ("kde", FALSE))
+ desktop = "KDE";
+ else
+ desktop = "";
+ kdDebug() << "DocEntry::desktop = " << desktop << endl;
+ };
+
+ QString onlyShowIn = file.readEntry ("OnlyShowIn");
+
+ kdDebug() << "DocEntry::readFromFile(): " << fileName << " onlyShowIn = " << onlyShowIn << endl;
+
+ if ( !onlyShowIn.isNull() ) {
+ if (desktop.isEmpty())
+ return false;
+ QStringList list = QStringList::split (";", onlyShowIn);
+ if ( ! list.contains (desktop) )
+ return false;
+ }
+
+ QString notShowIn = file.readEntry ("NotShowIn");
+ if ( !notShowIn.isNull() ) {
+ QStringList list = QStringList::split (";", notShowIn);
+ if ( list.contains (desktop) )
+ return false;
+ }
+
mName = file.readName();
mSearch = file.readEntry( "X-DOC-Search" );
mIcon = file.readIcon();
--- khelpcenter/navigator.cpp
+++ khelpcenter/navigator.cpp
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <stdlib.h>
#include <qdir.h>
#include <qfile.h>
@@ -275,6 +276,38 @@
const QString &file )
{
KDesktopFile desktopFile( file );
+
+ static QString desktop;
+ if (desktop.isNull()) {
+ QString win_man = getenv("WINDOWMANAGER");
+ if (win_man.contains ("gnome", FALSE))
+ desktop = "GNOME";
+ else if (win_man.contains ("kde", FALSE))
+ desktop = "KDE";
+ else
+ desktop = "";
+ kdDebug() << "Navigator::desktop = " << desktop << endl;
+ };
+
+ QString onlyShowIn = desktopFile.readEntry ("OnlyShowIn");
+
+ kdDebug() << "Navigator::createItemFromDesktopFile(): " << file << " onlyShowIn = " << onlyShowIn << endl;
+
+ if ( !onlyShowIn.isNull() ) {
+ if (desktop.isEmpty())
+ return;
+ QStringList list = QStringList::split (";", onlyShowIn);
+ if ( ! list.contains (desktop) )
+ return;
+ }
+
+ QString notShowIn = desktopFile.readEntry ("NotShowIn");
+ if ( !notShowIn.isNull() ) {
+ QStringList list = QStringList::split (";", notShowIn);
+ if ( list.contains (desktop) )
+ return;
+ }
+
QString docPath = desktopFile.readDocPath();
if ( !docPath.isNull() ) {
// First parameter is ignored if second is an absolute path
@@ -317,6 +350,9 @@
{
alternativeURL.setQuery("anchor="+url.ref());
alternativeURL.setRef(QString::null);
+ } else if (url.url().endsWith("/index.html"))
+ {
+ alternativeURL = KURL (url.url().left (url.url().length() - strlen ("/index.html")));
}
// If the navigator already has the given URL selected, do nothing.
@@ -401,15 +437,43 @@
TOC *tocTree = item->createTOC();
kdDebug( 1400 ) << "slotItemSelected(): Trying to build TOC for "
<< item->entry()->name() << endl;
- tocTree->setApplication( url.directory() );
+ if (url.directory() != "/")
+ tocTree->setApplication( url.directory() );
+ else
+ tocTree->setApplication( url.path() );
QString doc = View::langLookup( url.path() );
// Enforce the original .docbook version, in case langLookup returns a
// cached version
if ( !doc.isNull() ) {
- int pos = doc.find( ".html" );
- if ( pos >= 0 ) {
- doc.replace( pos, 5, ".docbook" );
- }
+ if (doc.endsWith( ".html" )) {
+ doc = doc.left (doc.length() - 5) + ".docbook";
+ }
+
+ QFileInfo di (doc);
+ if (!di.isFile()) {
+
+ int last_slash = doc.findRev ('/');
+ if (last_slash >= 1) {
+
+ QString filename = doc.right(doc.length() - last_slash - 1);
+ if (filename == "index.html" || filename == "") {
+
+ int slash2 = doc.findRev('/', last_slash -1);
+ if (slash2 != -1 && slash2 != 0) {
+
+ int slash3 = doc.findRev('/', slash2 - 1);
+ if (slash3 != -1) {
+ QString xml_file = doc.left(last_slash) + "/" + doc.mid(slash3 + 1, slash2 - (slash3 + 1)) + ".xml";
+ kdDebug() << "xml_file " << xml_file << endl;
+ QFileInfo fi(xml_file);
+ if (fi.exists())
+ doc = xml_file;
+
+ }
+ }
+ }
+ }
+ }
kdDebug( 1400 ) << "slotItemSelected(): doc = " << doc << endl;
tocTree->build( doc );
--- khelpcenter/navigatorappitem.cpp
+++ khelpcenter/navigatorappitem.cpp
@@ -21,6 +21,8 @@
#include "docentry.h"
+#include <stdlib.h>
+
#include <kdebug.h>
#include <kservicegroup.h>
@@ -134,11 +136,42 @@
QString NavigatorAppItem::documentationURL( KService *s )
{
+ static QString desktop;
+ if (desktop.isNull()) {
+ QString win_man = getenv("WINDOWMANAGER");
+ if (win_man.contains ("gnome", FALSE))
+ desktop = "GNOME";
+ else if (win_man.contains ("kde", FALSE))
+ desktop = "KDE";
+ else
+ desktop = "";
+ kdDebug() << "NavigatorAppItem::desktop = " << desktop << endl;
+ };
+
+ QString onlyShowIn = s->property("OnlyShowIn", QVariant::String).toString();
+
+ kdDebug() << "NavigatorAppItem::onlyShowIn = " << onlyShowIn << endl;
+
+ if ( !onlyShowIn.isNull() ) {
+ if (desktop.isEmpty())
+ return QString::null;
+ QStringList list = QStringList::split (";", onlyShowIn);
+ if ( ! list.contains (desktop) )
+ return QString::null;
+ }
+
+ QString notShowIn = s->property("NotShowIn", QVariant::String).toString();
+ if ( !notShowIn.isNull() ) {
+ QStringList list = QStringList::split (";", notShowIn);
+ if ( list.contains (desktop) )
+ return QString::null;
+ }
+
QString docPath = s->property( "DocPath" ).toString();
if ( docPath.isEmpty() )
return QString::null;
- if ( docPath.startsWith( "file:") || docPath.startsWith( "http:" ) )
+ if ( docPath.startsWith( "file:") || docPath.startsWith( "http:" ) || docPath.startsWith( "ghelp:" ))
return docPath;
return QString( "help:/" ) + docPath;
--- khelpcenter/table-of-contents.xslt
+++ khelpcenter/table-of-contents.xslt
@@ -8,6 +8,12 @@
</table-of-contents>
</xsl:template>
+<xsl:template match="article">
+<table-of-contents>
+<xsl:apply-templates select="sect1"/>
+</table-of-contents>
+</xsl:template>
+
<xsl:template match="chapter">
<chapter>
<title><xsl:value-of select="title"/></title>
@@ -20,7 +26,15 @@
<section>
<title><xsl:value-of select="title"/></title>
<anchor><xsl:value-of select="@id"/></anchor>
+<xsl:apply-templates select="sect2"/>
</section>
</xsl:template>
+<xsl:template match="sect2">
+<subsection>
+<title><xsl:value-of select="title"/></title>
+<anchor><xsl:value-of select="@id"/></anchor>
+</subsection>
+</xsl:template>
+
</xsl:stylesheet>
--- khelpcenter/view.cpp
+++ khelpcenter/view.cpp
@@ -146,21 +146,51 @@
// assemble the local search paths
const QStringList localDoc = KGlobal::dirs()->resourceDirs("html");
+ kdDebug() << "Looking up help for: " << fname << endl;
+
+ QString path;
+ QString file_name;
+ int slash = fname.findRev ('/');
+ if (slash == -1 || slash == 0) {
+ path = fname;
+ file_name = "/";
+ } else {
+ path = fname.left (slash);
+ file_name = fname.right (fname.length() - slash);
+ }
+
+ QStringList langs = KGlobal::locale()->languageList();
+ QStringList::ConstIterator lang;
+ for (lang = langs.begin(); lang != langs.end(); ++lang)
+ if (*lang == "en")
+ search.append(QString("/opt/gnome/share/gnome/help/%1/C%2").arg(path).arg(file_name));
+ else
+ search.append(QString("/opt/gnome/share/gnome/help/%1/%2%3").arg(path).arg(*lang).arg(file_name));
+
+ langs.append( "en" );
+ langs.remove( "C" );
+
+ // this is kind of compat hack as we install our docs in en/ but the
+ // default language is en_US
+ for (QStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
+ if ( *it == "en_US" )
+ *it = "en";
+
// look up the different languages
- for (int id=localDoc.count()-1; id >= 0; --id)
+ int ldCount = localDoc.count();
+ for (int id=0; id < ldCount; id++)
{
- QStringList langs = KGlobal::locale()->languageList();
- langs.append( "en" );
- langs.remove( "C" );
QStringList::ConstIterator lang;
for (lang = langs.begin(); lang != langs.end(); ++lang)
- search.append(QString("%1%2/%3").arg(localDoc[id]).arg(*lang).arg(fname));
+ search.append(QString("%1%2/%3").arg(localDoc[id]).arg(*lang).arg(path + file_name));
}
// try to locate the file
QStringList::Iterator it;
for (it = search.begin(); it != search.end(); ++it)
{
+ kdDebug() << "Looking for help in: " << *it << endl;
+
QFileInfo info(*it);
if (info.exists() && info.isFile() && info.isReadable())
return *it;
@@ -168,7 +198,7 @@
// Fall back to the index.docbook for this language if we couldn't find its
// specific docbook file. If we are not looking up docbook (images,
// css etc) then look in other languages first.
- if ( ( *it ).endsWith( "docbook" ) )
+ if ( ( *it ).endsWith( "docbook" ) || ( *it).endsWith( ".xml") )
{
QString file = (*it).left((*it).findRev('/')) + "/index.docbook";
info.setFile(file);
@@ -176,9 +206,15 @@
{
return *it;
}
+
+ file = (*it).left((*it).findRev('/')) + "/" + path + ".xml";
+ info.setFile(file);
+ if (info.exists() && info.isFile() && info.isReadable())
+ return *it;
}
}
+
return QString::null;
}
|