bool HelpPage::acceptNavigationRequest(QWebFrame *, const QNetworkRequest &request, QWebPage::NavigationType type) { const QUrl &url = request.url(); const bool closeNewTab = closeNewTabIfNeeded; closeNewTabIfNeeded = false; if (isLocalUrl(url)) { const QString& path = url.path(); if (path.endsWith(QLatin1String(".pdf"))) { const int lastDash = path.lastIndexOf(QChar('/')); QString fileName = QDir::tempPath() + QDir::separator(); if (lastDash < 0) fileName += path; else fileName += path.mid(lastDash + 1, path.length()); QFile tmpFile(QDir::cleanPath(fileName)); if (tmpFile.open(QIODevice::ReadWrite)) { tmpFile.write(helpEngine->fileData(url)); tmpFile.close(); } QDesktopServices::openUrl(QUrl(tmpFile.fileName())); if (closeNewTab) QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab"); return false; } if (type == QWebPage::NavigationTypeLinkClicked && (m_keyboardModifiers & Qt::ControlModifier || m_pressedButtons == Qt::MidButton)) { HelpViewer* viewer = centralWidget->newEmptyTab(); if (viewer) CentralWidget::instance()->setSource(url); m_pressedButtons = Qt::NoButton; m_keyboardModifiers = Qt::NoModifier; return false; } return true; } QDesktopServices::openUrl(url); return false; }
QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, const QNetworkRequest &request, QIODevice* /*outgoingData*/) { const QUrl& url = request.url(); QString mimeType = url.toString(); if (mimeType.endsWith(QLatin1String(".svg")) || mimeType.endsWith(QLatin1String(".svgz"))) { mimeType = QLatin1String("image/svg+xml"); } else if (mimeType.endsWith(QLatin1String(".css"))) { mimeType = QLatin1String("text/css"); } else if (mimeType.endsWith(QLatin1String(".js"))) { mimeType = QLatin1String("text/javascript"); } else { mimeType = QLatin1String("text/html"); } const QByteArray &data = helpEngine->findFile(url).isValid() ? helpEngine->fileData(url) : PageNotFoundMessage.arg(url.toString()).toUtf8(); return new HelpNetworkReply(request, data, mimeType); }
QNetworkReply *HelpNetworkAccessManager::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData) { const QString& scheme = request.url().scheme(); if (scheme == QLatin1String("qthelp") || scheme == QLatin1String("about")) { const QUrl& url = request.url(); QString mimeType = url.toString(); if (mimeType.endsWith(QLatin1String(".svg")) || mimeType.endsWith(QLatin1String(".svgz"))) { mimeType = QLatin1String("image/svg+xml"); } else if (mimeType.endsWith(QLatin1String(".css"))) { mimeType = QLatin1String("text/css"); } else if (mimeType.endsWith(QLatin1String(".js"))) { mimeType = QLatin1String("text/javascript"); } else { mimeType = QLatin1String("text/html"); } return new HelpNetworkReply(request, helpEngine->fileData(url), mimeType); } return QNetworkAccessManager::createRequest(op, request, outgoingData); }
bool HelpPage::acceptNavigationRequest(QWebFrame *, const QNetworkRequest &request, QWebPage::NavigationType) { const QUrl &url = request.url(); if (isLocalUrl(url)) { if (url.path().endsWith(QLatin1String("pdf"))) { QString fileName = url.toString(); fileName = QDir::tempPath() + QDir::separator() + fileName.right (fileName.length() - fileName.lastIndexOf(QChar('/'))); QFile tmpFile(QDir::cleanPath(fileName)); if (tmpFile.open(QIODevice::ReadWrite)) { tmpFile.write(helpEngine->fileData(url)); tmpFile.close(); } QDesktopServices::openUrl(QUrl(tmpFile.fileName())); return false; } return true; } QDesktopServices::openUrl(url); return false; }