/
mythuiwebbrowser.h
267 lines (207 loc) · 6.98 KB
/
mythuiwebbrowser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#ifndef MYTHUI_WEBBROWSER_H_
#define MYTHUI_WEBBROWSER_H_
#include <QtGlobal>
#include <QUrl>
#include "mythuitype.h"
#include "mythuiexp.h"
#if QT_VERSION >= 0x050000
class MUI_PUBLIC MythUIWebBrowser : public MythUIType
{
Q_OBJECT
public:
MythUIWebBrowser(MythUIType *parent, const QString &name) :
MythUIType(parent, name) {}
~MythUIWebBrowser() {}
void SetHtml(const QString &, const QUrl &baseUrl = QUrl()) {}
void SetZoom(float) {}
float GetZoom(void) { return 1.0; }
void ZoomIn(void) {}
void ZoomOut(void) {}
};
#warning MythUIWebBrowser has not yet been ported to Qt5
#else
#include <QString>
#include <QTime>
#include <QColor>
#include <QIcon>
#include <QWebView>
#include <QWebPage>
#include <QNetworkReply>
class MythUIScrollBar;
class MythUIWebBrowser;
class MythUIBusyDialog;
class MythScreenType;
class BrowserApi : public QObject
{
Q_OBJECT
public:
BrowserApi(QObject *parent);
~BrowserApi(void);
void setWebView(QWebView *view);
public slots:
void Play(void);
void Stop(void);
void Pause(void);
void SetVolume(int volumn);
int GetVolume(void);
void PlayFile(QString filename);
void PlayTrack(int trackID);
void PlayURL(QString url);
QString GetMetadata(void);
private slots:
void attachObject();
private:
void customEvent(QEvent *e);
QWebFrame *m_frame;
bool m_gotAnswer;
QString m_answer;
};
class MythNetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT
public:
MythNetworkAccessManager();
protected:
QNetworkReply* createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0);
};
class MythWebPage : public QWebPage
{
Q_OBJECT
public:
MythWebPage(QObject *parent = 0);
~MythWebPage();
virtual bool extension (Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
virtual bool supportsExtension (Extension extension) const;
protected:
virtual QString userAgentForUrl(const QUrl &url) const;
private:
friend class MythWebView;
};
class MythWebView : public QWebView
{
Q_OBJECT
public:
MythWebView(QWidget *parent, MythUIWebBrowser *parentBrowser);
~MythWebView(void);
virtual void keyPressEvent(QKeyEvent *event);
virtual void wheelEvent(QWheelEvent *event);
virtual void customEvent(QEvent *e);
protected slots:
void handleUnsupportedContent(QNetworkReply *reply);
void handleDownloadRequested(const QNetworkRequest &request);
QWebView *createWindow(QWebPage::WebWindowType type);
private:
void showDownloadMenu(void);
void doDownloadRequested(const QNetworkRequest &request);
void doDownload(const QString &saveFilename);
void openBusyPopup(const QString &message);
void closeBusyPopup(void);
bool isMusicFile(const QString &extension, const QString &mimetype);
bool isVideoFile(const QString &extension, const QString &mimetype);
QString getReplyMimetype(void);
QString getExtensionForMimetype(const QString &mimetype);
MythWebPage *m_webpage;
MythUIWebBrowser *m_parentBrowser;
BrowserApi *m_api;
QNetworkRequest m_downloadRequest;
QNetworkReply *m_downloadReply;
MythUIBusyDialog *m_busyPopup;
bool m_downloadAndPlay;
};
/**
* \brief Web browsing widget. Can load and render local and remote html.
* Supports netscape plugins.
*
* \ingroup MythUI_Widgets
*/
class MUI_PUBLIC MythUIWebBrowser : public MythUIType
{
Q_OBJECT
public:
MythUIWebBrowser(MythUIType *parent, const QString &name);
~MythUIWebBrowser();
void Init(void);
void LoadPage(QUrl url);
void SetHtml(const QString &html, const QUrl &baseUrl = QUrl());
void LoadUserStyleSheet(QUrl url);
virtual bool keyPressEvent(QKeyEvent *event);
virtual void Pulse(void);
void Scroll(int dx, int dy);
QIcon GetIcon(void);
QUrl GetUrl(void);
QString GetTitle(void);
void SetActive(bool active);
bool IsActive(void) { return m_active; }
/// returns true if all keypresses are to be passed to the web page
bool IsInputToggled(void) { return m_inputToggled; }
void SetInputToggled(bool inputToggled) { m_inputToggled = inputToggled; }
void SetZoom(float zoom);
float GetZoom(void);
bool CanGoForward(void);
bool CanGoBack(void);
QVariant evaluateJavaScript(const QString& scriptSource);
void SetDefaultSaveDirectory(const QString &saveDir);
QString GetDefaultSaveDirectory(void) { return m_defaultSaveDir; }
void SetDefaultSaveFilename(const QString &filename);
QString GetDefaultSaveFilename(void) { return m_defaultSaveFilename; }
public slots:
void Back(void);
void Forward(void);
void ZoomIn(void);
void ZoomOut(void);
signals:
void loadStarted(void); /// a page is starting to load
void loadFinished(bool ok); /// a page has finished loading
void loadProgress(int progress); /// % of page loaded
void titleChanged(const QString &title); /// a pages title has changed
void statusBarMessage(const QString &text);/// link hit test messages
void iconChanged(void); /// a pages fav icon has changed
void fileDownloaded(QString filename); /// a file has been downloaded
protected slots:
void slotLoadStarted(void);
void slotLoadFinished(bool Ok);
void slotLoadProgress(int progress);
void slotTitleChanged(const QString &title);
void slotStatusBarMessage(const QString &text);
void slotIconChanged(void);
void slotLinkClicked(const QUrl &url);
void slotTopScreenChanged(MythScreenType *screen);
protected:
void Finalize(void);
void UpdateBuffer(void);
void HandleMouseAction(const QString &action);
void SetBackgroundColor(QColor color);
void ResetScrollBars(void);
void UpdateScrollBars(void);
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
int alphaMod, QRect clipRegion);
virtual bool ParseElement(
const QString &filename, QDomElement &element, bool showWarnings);
virtual void CopyFrom(MythUIType *base);
virtual void CreateCopy(MythUIType *parent);
MythScreenType *m_parentScreen;
MythWebView *m_browser;
MythRect m_browserArea;
MythImage *m_image;
bool m_active;
bool m_wasActive;
bool m_initialized;
QTime m_lastUpdateTime;
int m_updateInterval;
float m_zoom;
QColor m_bgColor;
QUrl m_widgetUrl;
QString m_userCssFile;
QString m_defaultSaveDir;
QString m_defaultSaveFilename;
bool m_inputToggled;
QString m_lastMouseAction;
int m_mouseKeyCount;
QTime m_lastMouseActionTime;
MythUIScrollBar *m_horizontalScrollbar;
MythUIScrollBar *m_verticalScrollbar;
MythUIAnimation m_scrollAnimation;
QPoint m_destinationScrollPos;
};
#endif // version check
#endif