Debian Codegraph @

src/Gui/OnlineDocumentation.h

raw
1 /***************************************************************************
2 * Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_ONLINEDOCUMENTATION_H
25 #define GUI_ONLINEDOCUMENTATION_H
26
27 #include <functional>
28 #include <CXX/Objects.hxx>
29 #include <QObject>
30 #include <QTcpServer>
31 #include "Command.h"
32
33
34 namespace Gui
35 {
36
37 /// opens a URL in the system Browser
38 bool GuiExport OpenURLInBrowser(const char* URL);
39
40 /**
41 * Returns the content of an HTML page which gets sent to
42 * the client to be displayed.
43 * @author Werner Mayer
44 */
45 class PythonOnlineHelp: public QObject
46 {
47 Q_OBJECT
48
49 public:
50 PythonOnlineHelp();
51 ~PythonOnlineHelp() override;
52
53 QByteArray loadResource(const QString& filename) const;
54
55 private:
56 QByteArray fileNotFound() const;
57 QByteArray loadFailed(const QString& error) const;
58 QByteArray loadFavicon() const;
59 QByteArray loadIndexPage() const;
60 QByteArray loadHelpPage(const QString& filename) const;
61 QByteArray invoke(const std::function<std::string(Py::Module&)>& func) const;
62 QByteArray tryInvoke(const std::function<std::string(Py::Module&)>& func) const;
63 };
64
65 /**
66 * The HttpServer class implements a simple HTTP server.
67 */
68 class HttpServer: public QTcpServer
69 {
70 Q_OBJECT
71
72 public:
73 explicit HttpServer(QObject* parent = nullptr);
74
75 void incomingConnection(qintptr socket) override;
76 void pause();
77 void resume();
78
79 private Q_SLOTS:
80 void readClient();
81 void discardClient();
82
83 private:
84 PythonOnlineHelp help;
85 bool disabled;
86 };
87
88 // --------------------------------------------------------------------
89
90 class StdCmdPythonHelp: public Command
91 {
92 public:
93 StdCmdPythonHelp();
94 ~StdCmdPythonHelp() override;
95 const char* className() const override
96 {
97 return "Gui::StdCmdPythonHelp";
98 }
99
100 protected:
101 void activated(int iMsg) override;
102
103 private:
104 HttpServer* server;
105 };
106
107 } // namespace Gui
108
109 #endif // GUI_ONLINEDOCUMENTATION_H