Changeset View
Changeset View
Standalone View
Standalone View
step/infobrowser.cc
Show All 21 Lines | |||||
22 | #include "settings.h" | 22 | #include "settings.h" | ||
23 | 23 | | |||
24 | #include <QItemSelectionModel> | 24 | #include <QItemSelectionModel> | ||
25 | #include <QVBoxLayout> | 25 | #include <QVBoxLayout> | ||
26 | #include <QAction> | 26 | #include <QAction> | ||
27 | #include <QFile> | 27 | #include <QFile> | ||
28 | #include <QCoreApplication> | 28 | #include <QCoreApplication> | ||
29 | #include <KToolBar> | 29 | #include <KToolBar> | ||
30 | #include <KHTMLPart> | | |||
31 | 30 | | |||
32 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
33 | #include <KIO/Job> | 32 | #include <KIO/Job> | ||
34 | #include <QDesktopServices> | 33 | #include <QDesktopServices> | ||
35 | #include <QIcon> | 34 | #include <QIcon> | ||
36 | #include <QStandardPaths> | 35 | #include <QStandardPaths> | ||
37 | 36 | | |||
38 | InfoBrowser::InfoBrowser(WorldModel* worldModel, QWidget* parent) | 37 | InfoBrowser::InfoBrowser(WorldModel* worldModel, QWidget* parent) | ||
39 | : QDockWidget(i18n("Context info"), parent), | 38 | : QDockWidget(i18n("Context info"), parent), | ||
40 | _worldModel(worldModel), _wikiJob(NULL), _wikiFromHistory(false), _selectionChanged(false) | 39 | _worldModel(worldModel), _selectionChanged(false) | ||
41 | { | 40 | { | ||
42 | QWidget* widget = new QWidget(this); | 41 | QWidget* widget = new QWidget(this); | ||
43 | setWidget(widget); | 42 | setWidget(widget); | ||
44 | 43 | | |||
45 | QVBoxLayout* layout = new QVBoxLayout(widget); | 44 | QVBoxLayout* layout = new QVBoxLayout(widget); | ||
46 | layout->setContentsMargins(0,0,0,0); | 45 | layout->setContentsMargins(0,0,0,0); | ||
47 | layout->setSpacing(0); | 46 | layout->setSpacing(0); | ||
48 | 47 | | |||
Show All 16 Lines | |||||
65 | _followAction = _toolBar->addAction(QIcon::fromTheme(QStringLiteral("note2")), i18n("Follow selection")/*, this, SLOT(syncSelection(bool))*/); // XXX: icon | 64 | _followAction = _toolBar->addAction(QIcon::fromTheme(QStringLiteral("note2")), i18n("Follow selection")/*, this, SLOT(syncSelection(bool))*/); // XXX: icon | ||
66 | _followAction->setCheckable(true); | 65 | _followAction->setCheckable(true); | ||
67 | _followAction->setChecked(true); | 66 | _followAction->setChecked(true); | ||
68 | 67 | | |||
69 | _toolBar->addSeparator(); | 68 | _toolBar->addSeparator(); | ||
70 | _execAction = _toolBar->addAction(QIcon::fromTheme(QStringLiteral("system-run")), i18n("Open in browser"), this, SLOT(openInBrowser())); | 69 | _execAction = _toolBar->addAction(QIcon::fromTheme(QStringLiteral("system-run")), i18n("Open in browser"), this, SLOT(openInBrowser())); | ||
71 | _execAction->setEnabled(false); | 70 | _execAction->setEnabled(false); | ||
72 | 71 | | |||
73 | _htmlPart = new KHTMLPart(widget); | 72 | _htmlBrowser = new QTextBrowser(widget); | ||
74 | layout->addWidget(_htmlPart->widget()); | 73 | _htmlBrowser->setOpenLinks(false); | ||
75 | 74 | layout->addWidget(_htmlBrowser); | |||
76 | _htmlPart->setJavaEnabled(false); | 75 | | ||
77 | _htmlPart->setPluginsEnabled(false); | 76 | connect(_htmlBrowser, &QTextBrowser::anchorClicked, this, [=](const QUrl &url){ | ||
78 | _htmlPart->setJScriptEnabled(true); | 77 | openUrl(url); | ||
79 | _htmlPart->setMetaRefreshEnabled(true); | 78 | }); | ||
80 | _htmlPart->setDNDEnabled(false); | | |||
81 | | ||||
82 | connect(_htmlPart->browserExtension(), | | |||
83 | SIGNAL(openUrlRequest(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)), | | |||
84 | this, SLOT(openUrl(QUrl))); | | |||
85 | 79 | | |||
86 | connect(_worldModel->selectionModel(), &QItemSelectionModel::currentChanged, | 80 | connect(_worldModel->selectionModel(), &QItemSelectionModel::currentChanged, | ||
87 | this, &InfoBrowser::worldCurrentChanged); | 81 | this, &InfoBrowser::worldCurrentChanged); | ||
88 | 82 | | |||
89 | syncSelection(); | 83 | syncSelection(); | ||
90 | } | 84 | } | ||
91 | 85 | | |||
92 | void InfoBrowser::showEvent(QShowEvent* event) | 86 | void InfoBrowser::showEvent(QShowEvent* event) | ||
Show All 22 Lines | 108 | if(checked) { | |||
115 | const QModelIndex current = _worldModel->selectionModel()->currentIndex(); | 109 | const QModelIndex current = _worldModel->selectionModel()->currentIndex(); | ||
116 | const QUrl url(QStringLiteral("objinfo:").append(current.data(WorldModel::ClassNameRole).toString())); | 110 | const QUrl url(QStringLiteral("objinfo:").append(current.data(WorldModel::ClassNameRole).toString())); | ||
117 | openUrl(url, true); | 111 | openUrl(url, true); | ||
118 | } | 112 | } | ||
119 | } | 113 | } | ||
120 | 114 | | |||
121 | void InfoBrowser::updateSyncSelection() | 115 | void InfoBrowser::updateSyncSelection() | ||
122 | { | 116 | { | ||
123 | if(_htmlPart->url().scheme() == QLatin1String("objinfo")) { | 117 | if(_htmlBrowser->source().scheme() == QLatin1String("objinfo")) { | ||
124 | QModelIndex current = _worldModel->selectionModel()->currentIndex(); | 118 | QModelIndex current = _worldModel->selectionModel()->currentIndex(); | ||
125 | if(_htmlPart->url().path() == current.data(WorldModel::ClassNameRole).toString()) { | 119 | if(_htmlBrowser->source().path() == current.data(WorldModel::ClassNameRole).toString()) { | ||
126 | _syncAction->setEnabled(false); | 120 | _syncAction->setEnabled(false); | ||
127 | return; | 121 | return; | ||
128 | } | 122 | } | ||
129 | } | 123 | } | ||
130 | _syncAction->setEnabled(true); | 124 | _syncAction->setEnabled(true); | ||
131 | } | 125 | } | ||
132 | 126 | | |||
133 | void InfoBrowser::openUrl(const QUrl& url, bool clearHistory, bool fromHistory) | 127 | void InfoBrowser::openUrl(const QUrl& url, bool clearHistory, bool fromHistory) | ||
134 | { | 128 | { | ||
135 | // Cancel the old job | 129 | if(url.scheme() == QLatin1String("objinfo")) { | ||
136 | if(_wikiJob) _wikiJob->kill(); | | |||
137 | _wikiJob = NULL; | | |||
138 | | ||||
139 | if(clearHistory) { | 130 | if(clearHistory) { | ||
140 | _forwardHistory.clear(); | 131 | _forwardHistory.clear(); | ||
141 | _forwardAction->setEnabled(false); | 132 | _forwardAction->setEnabled(false); | ||
142 | _backHistory.clear(); | 133 | _backHistory.clear(); | ||
143 | _backAction->setEnabled(false); | 134 | _backAction->setEnabled(false); | ||
144 | fromHistory = true; | 135 | fromHistory = true; | ||
145 | } | 136 | } | ||
146 | | ||||
147 | if(url.scheme() == QLatin1String("objinfo")) { | | |||
148 | QString className = url.path(); | 137 | QString className = url.path(); | ||
149 | if(className.isEmpty()) { | 138 | if(className.isEmpty()) { | ||
150 | setHtml("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" | 139 | setHtml("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" | ||
151 | "</head><body>\n" | 140 | "</head><body>\n" | ||
152 | "<div id='doc_box' class='box'>\n" | 141 | "<div id='doc_box' class='box'>\n" | ||
153 | "<div id='doc_box-header' class='box-header'>\n" | 142 | "<div id='doc_box-header' class='box-header'>\n" | ||
154 | "<span id='doc_box-header-title' class='box-header-title'>\n" | 143 | "<span id='doc_box-header-title' class='box-header-title'>\n" | ||
155 | + i18n( "Documentation" ) + | 144 | + i18n( "Documentation" ) + | ||
156 | "</span>\n" | 145 | "</span>\n" | ||
157 | "</div>\n" | 146 | "</div>\n" | ||
158 | "<div id='doc_box-body' class='box-body'>\n" | 147 | "<div id='doc_box-body' class='box-body'>\n" | ||
159 | "<div class='info'><p>\n" | 148 | "<div class='info'><p>\n" | ||
160 | + i18n("No current object.") + | 149 | + i18n("No current object.") + | ||
161 | "</p></div>\n" | 150 | "</p></div>\n" | ||
162 | "</div>\n" | 151 | "</div>\n" | ||
163 | "</div>\n" | 152 | "</div>\n" | ||
164 | "</body></html>", fromHistory, url ); | 153 | "</body></html>", fromHistory, url ); | ||
165 | return; | 154 | return; | ||
166 | } | 155 | } | ||
167 | QString fileName = QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("objinfo/%1.html").arg(className)); | 156 | QString fileName = QStringLiteral(":/objectinfo/%1.html").arg(className.toLower()); | ||
168 | if(!fileName.isEmpty()) { | 157 | if(!fileName.isEmpty()) { | ||
169 | QFile file(fileName); | 158 | QFile file(fileName); | ||
170 | if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { | 159 | if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||
171 | setHtml(QString::fromUtf8(file.readAll()), fromHistory, url /*QUrl::fromLocalFile(fileName)*/); | 160 | setHtml(QString::fromUtf8(file.readAll()), fromHistory, url); | ||
172 | return; | 161 | return; | ||
162 | } else { | ||||
163 | qWarning() << "Could not open help file at location:" << fileName; | ||||
173 | } | 164 | } | ||
174 | } | 165 | } | ||
175 | setHtml("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" | 166 | setHtml("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" | ||
176 | "</head><body>\n" | 167 | "</head><body>\n" | ||
177 | "<div id='doc_box' class='box'>\n" | 168 | "<div id='doc_box' class='box'>\n" | ||
178 | "<div id='doc_box-header' class='box-header'>\n" | 169 | "<div id='doc_box-header' class='box-header'>\n" | ||
179 | "<span id='doc_box-header-title' class='box-header-title'>\n" | 170 | "<span id='doc_box-header-title' class='box-header-title'>\n" | ||
180 | + i18n( "Documentation error" ) + | 171 | + i18n( "Documentation error" ) + | ||
181 | "</span>\n" | 172 | "</span>\n" | ||
182 | "</div>\n" | 173 | "</div>\n" | ||
183 | "<div id='doc_box-body' class='box-body'>\n" | 174 | "<div id='doc_box-body' class='box-body'>\n" | ||
184 | "<div class='error'><p>\n" | 175 | "<div class='error'><p>\n" | ||
185 | + i18n("Documentation for %1 not available. ", QCoreApplication::translate("ObjectClass", className.toUtf8().constData())) | 176 | + i18n("Documentation for %1 not available. ", QCoreApplication::translate("ObjectClass", className.toUtf8().constData())) | ||
186 | + i18n("You can help <a href=\"http://edu.kde.org/step\">Step</a> by writing it!") + | 177 | + i18n("You can help <a href=\"http://edu.kde.org/step\">Step</a> by writing it!") + | ||
187 | "</p></div>\n" | 178 | "</p></div>\n" | ||
188 | "</div>\n" | 179 | "</div>\n" | ||
189 | "</div>\n" | 180 | "</div>\n" | ||
190 | "</body></html>", fromHistory, url ); | 181 | "</body></html>", fromHistory, url ); | ||
191 | return; | 182 | show(); | ||
192 | } else if(url.scheme() == QLatin1String("http")) { | 183 | } else if(url.scheme() == QLatin1String("https") || url.scheme() == QLatin1String("http")) { | ||
193 | if(!Settings::wikiExternal() && | 184 | // do not clear history when open external URL | ||
194 | QRegExp("[a-zA-Z-]+\\.wikipedia\\.org").exactMatch(url.host())) { | | |||
195 | setHtml( | | |||
196 | "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" | | |||
197 | "</head><body>\n" | | |||
198 | "<div id='wiki_box' class='box'>\n" | | |||
199 | "<div id='wiki_box-header' class='box-header'>\n" | | |||
200 | "<span id='wiki_box-header-title' class='box-header-title'>\n" | | |||
201 | + i18n( "Wikipedia" ) + | | |||
202 | "</span>\n" | | |||
203 | "</div>\n" | | |||
204 | "<div id='wiki_box-body' class='box-body'>\n" | | |||
205 | "<div class='info'><p>\n" + i18n( "Fetching Wikipedia Information..." ) + "</p></div>\n" | | |||
206 | "</div>\n" | | |||
207 | "</div>\n" | | |||
208 | "</body></html>\n", fromHistory); | | |||
209 | | ||||
210 | _wikiUrl = url; | | |||
211 | _wikiFromHistory = fromHistory; | | |||
212 | _wikiJob = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); | | |||
213 | connect(_wikiJob, &KJob::result, this, &InfoBrowser::wikiResult); | | |||
214 | } else { | | |||
215 | QDesktopServices::openUrl(url); | 185 | QDesktopServices::openUrl(url); | ||
186 | } else { | ||||
187 | qWarning() << "Unknown URL scheme detected, skipping:" << url; | ||||
216 | } | 188 | } | ||
217 | } | 189 | } | ||
218 | 190 | | |||
219 | show(); | | |||
220 | } | | |||
221 | | ||||
222 | void InfoBrowser::setHtml(const QString& data, bool fromHistory, const QUrl& url) | 191 | void InfoBrowser::setHtml(const QString& data, bool fromHistory, const QUrl& url) | ||
223 | { | 192 | { | ||
224 | if(!fromHistory) { | 193 | if(!fromHistory) { | ||
225 | _forwardAction->setEnabled(false); | 194 | _forwardAction->setEnabled(false); | ||
226 | _forwardHistory.clear(); | 195 | _forwardHistory.clear(); | ||
227 | 196 | | |||
228 | QString oldUrl = _htmlPart->url().url(); | 197 | QString oldUrl = _htmlBrowser->source().url(); | ||
229 | if(!oldUrl.isEmpty()) { | 198 | if(!oldUrl.isEmpty()) { | ||
230 | _backHistory << oldUrl; | 199 | _backHistory << oldUrl; | ||
231 | _backAction->setEnabled(true); | 200 | _backAction->setEnabled(true); | ||
232 | } | 201 | } | ||
233 | } | 202 | } | ||
234 | 203 | | |||
235 | if(url.scheme() == QLatin1String("http")) _execAction->setEnabled(true); | 204 | if(url.scheme() == QLatin1String("http")) { | ||
236 | else _execAction->setEnabled(false); | 205 | _execAction->setEnabled(true); | ||
206 | } | ||||
207 | else { | ||||
208 | _execAction->setEnabled(false); | ||||
209 | } | ||||
237 | 210 | | |||
238 | _htmlPart->begin(url); | 211 | _htmlBrowser->setSource(url); | ||
239 | _htmlPart->write( data ); | 212 | _htmlBrowser->setHtml(data); | ||
240 | _htmlPart->end(); | | |||
241 | 213 | | |||
242 | updateSyncSelection(); | 214 | updateSyncSelection(); | ||
243 | } | 215 | } | ||
244 | 216 | | |||
245 | void InfoBrowser::back() | 217 | void InfoBrowser::back() | ||
246 | { | 218 | { | ||
247 | Q_ASSERT(!_backHistory.isEmpty()); | 219 | Q_ASSERT(!_backHistory.isEmpty()); | ||
248 | 220 | | |||
249 | QString url(_backHistory.takeLast()); | 221 | QString url(_backHistory.takeLast()); | ||
250 | if(_backHistory.isEmpty()) | 222 | if(_backHistory.isEmpty()) | ||
251 | _backAction->setEnabled(false); | 223 | _backAction->setEnabled(false); | ||
252 | 224 | | |||
253 | QString curUrl = _htmlPart->url().url(); | 225 | QString curUrl = _htmlBrowser->source().url(); | ||
254 | if(!curUrl.isEmpty()) { | 226 | if(!curUrl.isEmpty()) { | ||
255 | _forwardHistory << curUrl; | 227 | _forwardHistory << curUrl; | ||
256 | _forwardAction->setEnabled(true); | 228 | _forwardAction->setEnabled(true); | ||
257 | } | 229 | } | ||
258 | 230 | | |||
259 | openUrl(QUrl(url), false, true); | 231 | openUrl(QUrl(url), false, true); | ||
260 | } | 232 | } | ||
261 | 233 | | |||
262 | void InfoBrowser::forward() | 234 | void InfoBrowser::forward() | ||
263 | { | 235 | { | ||
264 | Q_ASSERT(!_forwardHistory.isEmpty()); | 236 | Q_ASSERT(!_forwardHistory.isEmpty()); | ||
265 | 237 | | |||
266 | QString url(_forwardHistory.takeLast()); | 238 | QString url(_forwardHistory.takeLast()); | ||
267 | if(_forwardHistory.isEmpty()) | 239 | if(_forwardHistory.isEmpty()) | ||
268 | _forwardAction->setEnabled(false); | 240 | _forwardAction->setEnabled(false); | ||
269 | 241 | | |||
270 | QString curUrl = _htmlPart->url().url(); | 242 | QString curUrl = _htmlBrowser->source().url(); | ||
271 | if(!curUrl.isEmpty()) { | 243 | if(!curUrl.isEmpty()) { | ||
272 | _backHistory << curUrl; | 244 | _backHistory << curUrl; | ||
273 | _backAction->setEnabled(true); | 245 | _backAction->setEnabled(true); | ||
274 | } | 246 | } | ||
275 | 247 | | |||
276 | openUrl(QUrl(url), false, true); | 248 | openUrl(QUrl(url), false, true); | ||
277 | } | 249 | } | ||
278 | 250 | | |||
279 | void InfoBrowser::openInBrowser() | 251 | void InfoBrowser::openInBrowser() | ||
280 | { | 252 | { | ||
281 | if(_htmlPart->url().scheme() == QLatin1String("http")) { | 253 | if(_htmlBrowser->source().scheme() == QLatin1String("https")) { | ||
282 | QDesktopServices::openUrl(_htmlPart->url()); | 254 | QDesktopServices::openUrl(_htmlBrowser->source()); | ||
283 | } | 255 | } | ||
284 | } | 256 | } | ||
285 | | ||||
286 | void InfoBrowser::wikiResult(KJob* job) | | |||
287 | { | | |||
288 | // inspired by amarok | | |||
289 | | ||||
290 | if(job != _wikiJob) return; | | |||
291 | | ||||
292 | if(job->error() != 0) | | |||
293 | { | | |||
294 | setHtml("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" | | |||
295 | "</head><body>\n" | | |||
296 | "<div id='wiki_box' class='box'>\n" | | |||
297 | "<div id='wiki_box-header' class='box-header'>\n" | | |||
298 | "<span id='wiki_box-header-title' class='box-header-title'>\n" | | |||
299 | + i18n( "Wikipedia error" ) + | | |||
300 | "</span>\n" | | |||
301 | "</div>\n" | | |||
302 | "<div id='wiki_box-body' class='box-body'>\n<div class='error'><p>\n" | | |||
303 | + i18n( "Information could not be retrieved because the server was not reachable." ) + | | |||
304 | "</div></p>\n</div>\n" | | |||
305 | "</div>\n" | | |||
306 | "</body></html>\n", _wikiFromHistory); | | |||
307 | | ||||
308 | return; | | |||
309 | } | | |||
310 | | ||||
311 | KIO::StoredTransferJob* const storedJob = static_cast<KIO::StoredTransferJob*>( job ); | | |||
312 | QByteArray rawData = storedJob->data(); | | |||
313 | QString data; | | |||
314 | | ||||
315 | // TODO: better regexp | | |||
316 | if(rawData.contains("charset=utf-8")) data = QString::fromUtf8(rawData.data()); | | |||
317 | else data = QString(rawData); | | |||
318 | | ||||
319 | //if(data.find( "var wgArticleId = 0" ) != -1) // - article not found | | |||
320 | | ||||
321 | // remove the new-lines and tabs | | |||
322 | data.replace( '\n', ' ' ); | | |||
323 | data.replace( '\t', ' ' ); | | |||
324 | | ||||
325 | QString wikiLanguages; | | |||
326 | // Get the available language list | | |||
327 | if ( data.indexOf(QLatin1String("<div id=\"p-lang\" class=\"portlet\">")) != -1 ) | | |||
328 | { | | |||
329 | wikiLanguages = data.mid( data.indexOf(QLatin1String("<div id=\"p-lang\" class=\"portlet\">")) ); | | |||
330 | wikiLanguages = wikiLanguages.mid( wikiLanguages.indexOf(QLatin1String("<ul>")) ); | | |||
331 | wikiLanguages = wikiLanguages.mid( 0, wikiLanguages.indexOf( QLatin1String("</div>") ) ); | | |||
332 | } | | |||
333 | | ||||
334 | QString copyright; | | |||
335 | QString copyrightMark = QStringLiteral("<li id=\"f-copyright\">"); | | |||
336 | if ( data.indexOf( copyrightMark ) != -1 ) | | |||
337 | { | | |||
338 | copyright = data.mid( data.indexOf(copyrightMark) + copyrightMark.length() ); | | |||
339 | copyright = copyright.mid( 0, copyright.indexOf( QLatin1String("</li>") ) ); | | |||
340 | copyright.remove( QStringLiteral("<br />") ); | | |||
341 | //only one br at the beginning | | |||
342 | copyright.prepend( "<br />" ); | | |||
343 | } | | |||
344 | | ||||
345 | // Ok lets remove the top and bottom parts of the page | | |||
346 | data = data.mid( data.indexOf( QLatin1String("<h1 class=\"firstHeading\">") ) ); | | |||
347 | data = data.mid( 0, data.indexOf( QLatin1String("<div class=\"printfooter\">") ) ); | | |||
348 | | ||||
349 | // Adding back license information | | |||
350 | data += copyright; | | |||
351 | data.append( "</div>" ); | | |||
352 | | ||||
353 | // Remove unnecessary sections (do it with style?) | | |||
354 | data.remove( QRegExp("<h3 *id=\"siteSub\">[^<]*</h3>") ); | | |||
355 | | ||||
356 | data.remove( QRegExp( "<span class=\"editsection\"[^>]*>[^<]*<[^>]*>[^<]*<[^>]*>[^<]*</span>" ) ); | | |||
357 | | ||||
358 | data.replace( QRegExp( "<a href=\"[^\"]*\" class=\"new\"[^>]*>([^<]*)</a>" ), "\\1" ); | | |||
359 | | ||||
360 | // Remove anything inside of a class called urlexpansion, as it's pointless for us | | |||
361 | data.remove( QRegExp( "<span class= *'urlexpansion'>[^(]*[(][^)]*[)]</span>ttp inthttp" ) ); | | |||
362 | | ||||
363 | // Remove hidden table rows as well | | |||
364 | QRegExp hidden( "<tr *class= *[\"\']hiddenStructure[\"\']>.*</tr>", Qt::CaseInsensitive ); | | |||
365 | hidden.setMinimal( true ); //greedy behavior wouldn't be any good! | | |||
366 | data.remove( hidden ); | | |||
367 | | ||||
368 | // Remove jump-to-nav | | |||
369 | QRegExp jumpToNav( "<div *id= *[\"\']jump-to-nav[\"\']>.*</div>", Qt::CaseInsensitive ); | | |||
370 | jumpToNav.setMinimal( true ); | | |||
371 | data.remove( jumpToNav ); | | |||
372 | | ||||
373 | // we want to keep our own style (we need to modify the stylesheet a bit to handle things nicely) | | |||
374 | //data.remove( QRegExp( "style= *\"[^\"]*\"" ) ); | | |||
375 | //data.remove( QRegExp( "class= *\"[^\"]*\"" ) ); | | |||
376 | | ||||
377 | // let's remove the form elements, we don't want them. | | |||
378 | data.remove( QRegExp( "<input[^>]*>" ) ); | | |||
379 | data.remove( QRegExp( "<select[^>]*>" ) ); | | |||
380 | data.remove( QStringLiteral("</select>\n") ); | | |||
381 | data.remove( QRegExp( "<option[^>]*>" ) ); | | |||
382 | data.remove( QStringLiteral("</option>\n") ); | | |||
383 | data.remove( QRegExp( "<textarea[^>]*>" ) ); | | |||
384 | data.remove( QStringLiteral("</textarea>") ); | | |||
385 | | ||||
386 | //first we convert all the links with protocol to external, as they should all be External Links. | | |||
387 | //data.replace( QRegExp( "href= *\"http:" ), "href=\"externalurl:" ); | | |||
388 | //QString url = _wikiUrl.url(); | | |||
389 | //QString baseUrl = url.mid(0, url.indexOf("wiki/")); | | |||
390 | //data.replace( QRegExp( "href= *\"/" ), "href=\"" + baseUrl ); | | |||
391 | //data.replace( QRegExp( "href= *\"#" ), "href=\"" + baseUrl + '#' ); | | |||
392 | | ||||
393 | data.prepend("<html><body>\n" | | |||
394 | "<div id='wiki_box' class='box'>\n" | | |||
395 | "<div id='wiki_box-header' class='box-header'>\n" | | |||
396 | "<span id='wiki_box-header-title' class='box-header-title'>\n" | | |||
397 | + i18n( "Wikipedia Information" ) + | | |||
398 | "</span>\n" | | |||
399 | "</div>\n" | | |||
400 | "<div id='wiki_box-body' class='box-body'>\n"); | | |||
401 | data.append( "</div>\n" | | |||
402 | "</div>\n"); | | |||
403 | | ||||
404 | if (!wikiLanguages.isEmpty()) { | | |||
405 | data.append( | | |||
406 | "<br />" | | |||
407 | "<div id='wiki_box' class='box'>\n" | | |||
408 | "<div id='wiki_box-header' class='box-header'>\n" | | |||
409 | "<span id='wiki_box-header-title' class='box-header-title'>\n" | | |||
410 | + i18n( "Wikipedia Other Languages" ) + | | |||
411 | "</span>\n" | | |||
412 | "</div>\n" | | |||
413 | "<div id='wiki_box-body' class='box-body'>\n" | | |||
414 | + wikiLanguages + | | |||
415 | "</div>\n" | | |||
416 | "</div>\n" | | |||
417 | ); | | |||
418 | } | | |||
419 | data.append( "</body></html>\n" ); | | |||
420 | | ||||
421 | setHtml( data, _wikiFromHistory, _wikiUrl ); | | |||
422 | | ||||
423 | _wikiJob = NULL; | | |||
424 | } | | |||
425 | |