From 6e0544a9f58e172920e7c62cac5b56de8d5bb2cd Mon Sep 17 00:00:00 2001
From: kh1 <qt-info@nokia.com>
Date: Wed, 14 Jul 2010 13:36:23 +0200
Subject: [PATCH] Sync against Assistant

Reviewed-by: ck
---
 src/shared/help/contentwindow.cpp | 27 ++++++++++++++-------------
 src/shared/help/contentwindow.h   |  1 -
 src/shared/help/indexwindow.cpp   |  5 +++--
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/shared/help/contentwindow.cpp b/src/shared/help/contentwindow.cpp
index ef3479f170d..f61e09f67f9 100644
--- a/src/shared/help/contentwindow.cpp
+++ b/src/shared/help/contentwindow.cpp
@@ -29,7 +29,9 @@
 
 #include "contentwindow.h"
 
+#include "centralwidget.h"
 #include "helpmanager.h"
+#include "helpviewer.h"
 #include "openpagesmanager.h"
 
 #include <QtGui/QLayout>
@@ -102,18 +104,21 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e)
     if (m_contentWidget && o == m_contentWidget->viewport()
         && e->type() == QEvent::MouseButtonRelease) {
         QMouseEvent *me = static_cast<QMouseEvent*>(e);
-        QModelIndex index = m_contentWidget->indexAt(me->pos());
         QItemSelectionModel *sm = m_contentWidget->selectionModel();
+        if (!me || !sm)
+            return QWidget::eventFilter(o, e);
 
         Qt::MouseButtons button = me->button();
-        if (index.isValid() && (sm && sm->isSelected(index))) {
+        const QModelIndex &index = m_contentWidget->indexAt(me->pos());
+
+        if (index.isValid() && sm->isSelected(index)) {
             if ((button == Qt::LeftButton && (me->modifiers() & Qt::ControlModifier))
                 || (button == Qt::MidButton)) {
                 QHelpContentModel *contentModel =
                     qobject_cast<QHelpContentModel*>(m_contentWidget->model());
                 if (contentModel) {
                     QHelpContentItem *itm = contentModel->contentItemAt(index);
-                    if (itm && !isPdfFile(itm))
+                    if (itm && HelpViewer::canOpenPage(itm->url().path()))
                         OpenPagesManager::instance().createPage(itm->url());
                 }
             } else if (button == Qt::LeftButton) {
@@ -137,7 +142,7 @@ void ContentWindow::showContextMenu(const QPoint &pos)
     QMenu menu;
     QAction *curTab = menu.addAction(tr("Open Link"));
     QAction *newTab = menu.addAction(tr("Open Link as New Page"));
-    if (isPdfFile(itm))
+    if (!HelpViewer::canOpenPage(itm->url().path()))
         newTab->setEnabled(false);
 
     menu.move(m_contentWidget->mapToGlobal(pos));
@@ -155,14 +160,10 @@ void ContentWindow::itemClicked(const QModelIndex &index)
         qobject_cast<QHelpContentModel*>(m_contentWidget->model());
 
     if (contentModel) {
-        QHelpContentItem *itm = contentModel->contentItemAt(index);
-        if (itm)
-            emit linkActivated(itm->url());
+        if (QHelpContentItem *itm = contentModel->contentItemAt(index)) {
+            const QUrl &url = itm->url();
+            if (url != CentralWidget::instance()->currentHelpViewer()->source())
+                emit linkActivated(itm->url());
+        }
     }
 }
-
-bool ContentWindow::isPdfFile(QHelpContentItem *item) const
-{
-    const QString &path = item->url().path();
-    return path.endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive);
-}
diff --git a/src/shared/help/contentwindow.h b/src/shared/help/contentwindow.h
index 4bfd0d0f6a9..df98dac82e2 100644
--- a/src/shared/help/contentwindow.h
+++ b/src/shared/help/contentwindow.h
@@ -62,7 +62,6 @@ private slots:
 
 private:
     bool eventFilter(QObject *o, QEvent *e);
-    bool isPdfFile(QHelpContentItem *item) const;
 
     QHelpContentWidget *m_contentWidget;
     int m_expandDepth;
diff --git a/src/shared/help/indexwindow.cpp b/src/shared/help/indexwindow.cpp
index b12d517c6d3..d58188b3f13 100644
--- a/src/shared/help/indexwindow.cpp
+++ b/src/shared/help/indexwindow.cpp
@@ -30,6 +30,7 @@
 #include "centralwidget.h"
 
 #include "helpmanager.h"
+#include "helpviewer.h"
 #include "indexwindow.h"
 #include "openpagesmanager.h"
 #include "topicchooser.h"
@@ -209,8 +210,8 @@ void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index)
             return;
         }
 
-        if (url.path().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive))
-            Help::Internal::CentralWidget::instance()->setSource(url);
+        if (!HelpViewer::canOpenPage(url.path()))
+            CentralWidget::instance()->setSource(url);
         else
             OpenPagesManager::instance().createPage(url);
     }
-- 
GitLab