pqHelpWindowWebEngine.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: pqHelpWindowWebKit.h
5 
6  Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 ========================================================================*/
32 #ifndef pqHelpWindowWebKit_h
33 #define pqHelpWindowWebKit_h
34 
42 #include <QBuffer>
43 #include <QFileInfo>
44 #include <QNetworkAccessManager>
45 #include <QNetworkProxy>
46 #include <QTimer>
47 #include <QWebEngineProfile>
48 #include <QWebEngineUrlRequestJob>
49 #include <QWebEngineUrlSchemeHandler>
50 #include <QWebEngineView>
51 
52 namespace
53 {
54 
55 class pqUrlSchemeHandler : public QWebEngineUrlSchemeHandler
56 {
57  typedef QWebEngineUrlSchemeHandler Superclass;
58 
59 public:
60  pqUrlSchemeHandler(QHelpEngineCore* engine)
61  : Engine(engine)
62  {
63  }
64  ~pqUrlSchemeHandler() {}
65 
66  void requestStarted(QWebEngineUrlRequestJob* request) override
67  {
68  QMap<QString, QString> extension_type_map;
69  extension_type_map["jpg"] = "image/jpeg";
70  extension_type_map["jpeg"] = "image/jpeg";
71  extension_type_map["png"] = "image/png";
72  extension_type_map["gif"] = "image/gif";
73  extension_type_map["tiff"] = "image/tiff";
74  extension_type_map["htm"] = "text/html";
75  extension_type_map["html"] = "text/html";
76  extension_type_map["css"] = "text/css";
77  extension_type_map["xml"] = "text/xml";
78 
79  QUrl url = request->requestUrl();
80  QString extension = QFileInfo(url.path()).suffix().toLower();
81  QString content_type = extension_type_map.value(extension, "text/plain");
82 
83  QByteArray array = this->Engine->fileData(url);
84  QBuffer* buffer = new QBuffer;
85  buffer->setData(array);
86  buffer->open(QIODevice::ReadOnly);
87  connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater);
88  request->reply(content_type.toLocal8Bit(), buffer);
89  }
90 
91 private:
92  QHelpEngineCore* Engine;
93 };
94 //----------------------------------------------------------------------------------
98 class pqWebView : public QWebEngineView
99 {
100  typedef QWebEngineView Superclass;
101 
102 public:
103  pqWebView(QWidget* parentObject)
104  : Superclass(parentObject)
105  {
106  }
107  ~pqWebView() {}
108 
109  static pqWebView* newInstance(QHelpEngine* engine, QWidget* parentObject)
110  {
111  pqWebView* instance = new pqWebView(parentObject);
112  QWebEngineProfile* profile = QWebEngineProfile::defaultProfile();
113  profile->installUrlSchemeHandler("qthelp", new pqUrlSchemeHandler(engine));
114  return instance;
115  }
116 
117 private:
118  Q_DISABLE_COPY(pqWebView)
119 };
120 
121 } // end of namespace
122 #endif
profile
url
connect