diff options
author | kh1 <qt-info@nokia.com> | 2010-02-17 12:32:15 (GMT) |
---|---|---|
committer | kh1 <qt-info@nokia.com> | 2010-02-17 14:49:39 (GMT) |
commit | 5c1bcbf309339f017415c851ad74e928ed709e6b (patch) | |
tree | 14c844542544cb56291b6a3f340d483f6b58d32f /tools/assistant | |
parent | 4941c9b9a83a6ea5c07f470fb853d1111ce4c7b9 (diff) | |
download | Qt-5c1bcbf309339f017415c851ad74e928ed709e6b.zip Qt-5c1bcbf309339f017415c851ad74e928ed709e6b.tar.gz Qt-5c1bcbf309339f017415c851ad74e928ed709e6b.tar.bz2 |
Move launch with external app in base class.
Reviewed-by: ck
Diffstat (limited to 'tools/assistant')
-rw-r--r-- | tools/assistant/tools/assistant/centralwidget.cpp | 15 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer.cpp | 45 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer.h | 4 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer_qtb.cpp | 62 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer_qtb.h | 2 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer_qwv.cpp | 57 |
6 files changed, 82 insertions, 103 deletions
diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index dd91326..d0a6e56 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -310,7 +310,7 @@ void CentralWidget::setLastShownPages() { TRACE_OBJ HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); - const QStringList lastShownPageList = helpEngine.lastShownPages(); + const QStringList &lastShownPageList = helpEngine.lastShownPages(); const int pageCount = lastShownPageList.count(); if (pageCount == 0) { if (usesDefaultCollection) @@ -514,15 +514,12 @@ void CentralWidget::setGlobalActions(const QList<QAction*> &actions) void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom) { TRACE_OBJ - HelpViewer *viewer; - -#if defined(QT_NO_WEBKIT) - viewer = currentHelpViewer(); - if (viewer && viewer->launchedWithExternalApp(url)) - return; -#endif + if (HelpViewer *viewer = currentHelpViewer()) { + if (viewer->launchWithExternalApp(url)) + return; + } - viewer = new HelpViewer(this, zoom); + HelpViewer *viewer = new HelpViewer(this, zoom); viewer->installEventFilter(this); viewer->setSource(url); viewer->setFocus(Qt::OtherFocusReason); diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index 8597f6b..9b06400 100644 --- a/tools/assistant/tools/assistant/helpviewer.cpp +++ b/tools/assistant/tools/assistant/helpviewer.cpp @@ -39,13 +39,25 @@ ** ****************************************************************************/ #include "helpviewer.h" +#include "helpenginewrapper.h" #include "tracer.h" #include <QtCore/QCoreApplication> +#include <QtCore/QFileInfo> +#include <QtCore/QStringBuilder> +#include <QtCore/QTemporaryFile> #include <QtCore/QUrl> +#include <QtGui/QDesktopServices> + QT_BEGIN_NAMESPACE +QString AbstractHelpViewer::AboutBlank = + QCoreApplication::translate("HelpViewer", "<title>about:blank</title>"); + +QString AbstractHelpViewer::LocalHelpFile = QLatin1String("qthelp://" + "com.trolltech.com.assistantinternal-1.0.0/assistant/assistant.html"); + QString AbstractHelpViewer::PageNotFoundMessage = QCoreApplication::translate("HelpViewer", "<title>Error 404...</title><div " "align=\"center\"><br><br><h1>The page could not be found</h1><br><h3>'%1'" @@ -76,7 +88,38 @@ bool AbstractHelpViewer::canOpenPage(const QString &url) TRACE_OBJ return url.endsWith(QLatin1String(".html"), Qt::CaseInsensitive) || url.endsWith(QLatin1String(".htm"), Qt::CaseInsensitive) - || url == QLatin1String("blank"); + || url == QLatin1String("about:blank"); +} + +bool AbstractHelpViewer::launchWithExternalApp(const QUrl &url) +{ + TRACE_OBJ + if (isLocalUrl(url)) { + const HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + const QUrl &resolvedUrl = helpEngine.findFile(url); + if (!resolvedUrl.isValid()) + return false; + + const QString& path = resolvedUrl.path(); + if (!canOpenPage(path)) { + QTemporaryFile tmpTmpFile; + if (!tmpTmpFile.open()) + return false; + + const QString &extension = QFileInfo(path).completeSuffix(); + QFile actualTmpFile(tmpTmpFile.fileName() % QLatin1String(".") + % extension); + if (!actualTmpFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) + return false; + + actualTmpFile.write(helpEngine.fileData(resolvedUrl)); + actualTmpFile.close(); + return QDesktopServices::openUrl(QUrl(actualTmpFile.fileName())); + } + } else if (url.scheme() == QLatin1String("http")) { + return QDesktopServices::openUrl(url); + } + return false; } QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h index fe860fd..0bfe904 100644 --- a/tools/assistant/tools/assistant/helpviewer.h +++ b/tools/assistant/tools/assistant/helpviewer.h @@ -64,9 +64,13 @@ public: virtual void resetScale() = 0; virtual qreal scale() const = 0; + static QString AboutBlank; + static QString LocalHelpFile; static QString PageNotFoundMessage; + static bool isLocalUrl(const QUrl &url); static bool canOpenPage(const QString &url); + static bool launchWithExternalApp(const QUrl &url); }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.cpp b/tools/assistant/tools/assistant/helpviewer_qtb.cpp index 3aafe67..b5af165 100644 --- a/tools/assistant/tools/assistant/helpviewer_qtb.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qtb.cpp @@ -41,21 +41,17 @@ #if defined(QT_NO_WEBKIT) #include "helpviewer_qtb.h" -#include "helpviewer_qwv.h" #include "centralwidget.h" #include "helpenginewrapper.h" #include "tracer.h" -#include <QtCore/QDir> #include <QtCore/QStringBuilder> #include <QtGui/QContextMenuEvent> #include <QtGui/QMenu> #include <QtGui/QClipboard> #include <QtGui/QApplication> -#include <QtGui/QMessageBox> -#include <QtGui/QDesktopServices> QT_BEGIN_NAMESPACE @@ -136,62 +132,28 @@ void HelpViewer::resetScale() void HelpViewer::setSource(const QUrl &url) { TRACE_OBJ - bool help = url.toString() == QLatin1String("help"); - if (url.isValid() && !help) { - if (launchedWithExternalApp(url)) + const QString &string = url.toString(); + if (url.isValid() && string != QLatin1String("help")) { + if (launchWithExternalApp(url)) return; - QUrl u = helpEngine.findFile(url); - if (u.isValid()) { - QTextBrowser::setSource(u); + const QUrl &resolvedUrl = helpEngine.findFile(url); + if (resolvedUrl.isValid()) { + QTextBrowser::setSource(resolvedUrl); return; - } + } } - if (help) { - QTextBrowser::setSource(QUrl(QLatin1String("qthelp://com.trolltech.com." - "assistantinternal-1.0.0/assistant/assistant.html"))); - } else { + if (string != QLatin1String("help")) { QTextBrowser::setSource(url); - setHtml(PageNotFoundMessage.arg(url.toString())); + setHtml(string == QLatin1String("about:blank") ? AboutBlank + : PageNotFoundMessage.arg(url.toString())); emit sourceChanged(url); + } else { + QTextBrowser::setSource(LocalHelpFile); } } -bool HelpViewer::launchedWithExternalApp(const QUrl &url) -{ - TRACE_OBJ - const bool canOpen = canOpenPage(url.path()); - if (!isLocalUrl(url) || !canOpen) { - bool launched = false; - if (!canOpen && url.scheme() == QLatin1String("qthelp")) { - const QString& path = url.path(); - 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(); - } - launched = QDesktopServices::openUrl(QUrl(tmpFile.fileName())); - } else { - launched = QDesktopServices::openUrl(url); - } - - if (!launched) { - QMessageBox::information(this, tr("Help"), - tr("Unable to launch external application.\n"), tr("OK")); - } - return true; - } - return false; -} - QVariant HelpViewer::loadResource(int type, const QUrl &name) { TRACE_OBJ diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.h b/tools/assistant/tools/assistant/helpviewer_qtb.h index e927b34..98617cb 100644 --- a/tools/assistant/tools/assistant/helpviewer_qtb.h +++ b/tools/assistant/tools/assistant/helpviewer_qtb.h @@ -79,8 +79,6 @@ public: inline bool hasSelection() const { return textCursor().hasSelection(); } - bool launchedWithExternalApp(const QUrl &url); - public Q_SLOTS: void home(); diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp index 4857e00..b4e53a2 100644 --- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp @@ -49,10 +49,8 @@ #include <QtCore/QFileInfo> #include <QtCore/QString> #include <QtCore/QStringBuilder> -#include <QtCore/QTemporaryFile> #include <QtCore/QTimer> -#include <QtGui/QDesktopServices> #include <QtGui/QWheelEvent> #include <QtNetwork/QNetworkAccessManager> @@ -211,45 +209,27 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *, const QNetworkRequest &request, QWebPage::NavigationType type) { TRACE_OBJ - const QUrl &url = request.url(); const bool closeNewTab = closeNewTabIfNeeded; closeNewTabIfNeeded = false; - if (AbstractHelpViewer::isLocalUrl(url)) { - const QString& path = url.path(); - if (!AbstractHelpViewer::canOpenPage(path)) { - QTemporaryFile tmpTmpFile; - if (!tmpTmpFile.open()) - return false; - const QString &extension = QFileInfo(path).completeSuffix(); - QFile actualTmpFile(tmpTmpFile.fileName() % QLatin1String(".") - % extension); - if (actualTmpFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) { - actualTmpFile.write(HelpEngineWrapper::instance().fileData(url)); - actualTmpFile.close(); - QDesktopServices::openUrl(QUrl(actualTmpFile.fileName())); - } - - if (closeNewTab) - QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab"); + const QUrl &url = request.url(); + if (AbstractHelpViewer::launchWithExternalApp(url)) { + if (closeNewTab) + QMetaObject::invokeMethod(centralWidget, "closeTab"); + return false; + } + + if (type == QWebPage::NavigationTypeLinkClicked + && (m_keyboardModifiers & Qt::ControlModifier + || m_pressedButtons == Qt::MidButton)) { + if (HelpViewer* viewer = centralWidget->newEmptyTab()) + centralWidget->setSource(url); + m_pressedButtons = Qt::NoButton; + m_keyboardModifiers = Qt::NoModifier; 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; + return true; } // -- HelpViewer @@ -337,12 +317,7 @@ void HelpViewer::setSource(const QUrl &url) { TRACE_OBJ loadFinished = false; - if (url.toString() == QLatin1String("help")) { - load(QUrl(QLatin1String("qthelp://com.trolltech.com." - "assistantinternal-1.0.0/assistant/assistant.html"))); - } else { - load(url); - } + load(url.toString() == QLatin1String("help") ? LocalHelpFile : url); } void HelpViewer::home() |