00001 #ifndef MYTHUI_WEBBROWSER_H_
00002 #define MYTHUI_WEBBROWSER_H_
00003
00004 #include <QtGlobal>
00005 #include <QString>
00006 #include <QUrl>
00007 #include <QTime>
00008 #include <QColor>
00009 #include <QIcon>
00010
00011 #include <QWebView>
00012 #include <QWebPage>
00013 #include <QNetworkReply>
00014
00015 #include "mythuitype.h"
00016
00017 class MythUIScrollBar;
00018 class MythUIWebBrowser;
00019 class MythUIBusyDialog;
00020 class MythScreenType;
00021
00022 class BrowserApi : public QObject
00023 {
00024 Q_OBJECT
00025 public:
00026 BrowserApi(QObject *parent);
00027 ~BrowserApi(void);
00028
00029 void setWebView(QWebView *view);
00030
00031 public slots:
00032 void Play(void);
00033 void Stop(void);
00034 void Pause(void);
00035
00036 void SetVolume(int volumn);
00037 int GetVolume(void);
00038
00039 void PlayFile(QString filename);
00040 void PlayTrack(int trackID);
00041 void PlayURL(QString url);
00042
00043 QString GetMetadata(void);
00044
00045 private slots:
00046 void attachObject();
00047
00048 private:
00049 void customEvent(QEvent *e);
00050
00051 QWebFrame *m_frame;
00052
00053 bool m_gotAnswer;
00054 QString m_answer;
00055 };
00056
00057 class MythWebPage : public QWebPage
00058 {
00059 Q_OBJECT
00060
00061 public:
00062 MythWebPage(QObject *parent = 0);
00063 ~MythWebPage();
00064
00065 virtual bool extension (Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
00066 virtual bool supportsExtension (Extension extension) const;
00067
00068 protected:
00069 virtual QString userAgentForUrl(const QUrl &url) const;
00070
00071 private:
00072 friend class MythWebView;
00073 };
00074
00075 class MythWebView : public QWebView
00076 {
00077 Q_OBJECT
00078
00079 public:
00080 MythWebView(QWidget *parent, MythUIWebBrowser *parentBrowser);
00081 ~MythWebView(void);
00082
00083 virtual void keyPressEvent(QKeyEvent *event);
00084 virtual void wheelEvent(QWheelEvent *event);
00085 virtual void customEvent(QEvent *e);
00086
00087 protected slots:
00088 void handleUnsupportedContent(QNetworkReply *reply);
00089 void handleDownloadRequested(const QNetworkRequest &request);
00090 QWebView *createWindow(QWebPage::WebWindowType type);
00091
00092 private:
00093 void showDownloadMenu(void);
00094 void doDownloadRequested(const QNetworkRequest &request);
00095 void doDownload(const QString &saveFilename);
00096 void openBusyPopup(const QString &message);
00097 void closeBusyPopup(void);
00098
00099 bool isMusicFile(const QString &extension, const QString &mimetype);
00100 bool isVideoFile(const QString &extension, const QString &mimetype);
00101
00102 QString getReplyMimetype(void);
00103 QString getExtensionForMimetype(const QString &mimetype);
00104
00105 MythWebPage *m_webpage;
00106 MythUIWebBrowser *m_parentBrowser;
00107 BrowserApi *m_api;
00108 QNetworkRequest m_downloadRequest;
00109 QNetworkReply *m_downloadReply;
00110 MythUIBusyDialog *m_busyPopup;
00111 bool m_downloadAndPlay;
00112 };
00113
00120 class MUI_PUBLIC MythUIWebBrowser : public MythUIType
00121 {
00122 Q_OBJECT
00123
00124 public:
00125 MythUIWebBrowser(MythUIType *parent, const QString &name);
00126 ~MythUIWebBrowser();
00127
00128 void Init(void);
00129
00130 void LoadPage(QUrl url);
00131 void SetHtml(const QString &html, const QUrl &baseUrl = QUrl());
00132
00133 void LoadUserStyleSheet(QUrl url);
00134
00135 virtual bool keyPressEvent(QKeyEvent *event);
00136 virtual void Pulse(void);
00137 void Scroll(int dx, int dy);
00138
00139 QIcon GetIcon(void);
00140 QUrl GetUrl(void);
00141 QString GetTitle(void);
00142
00143 void SetActive(bool active);
00144 bool IsActive(void) { return m_active; }
00145
00147 bool IsInputToggled(void) { return m_inputToggled; }
00148 void SetInputToggled(bool inputToggled) { m_inputToggled = inputToggled; }
00149
00150 void SetZoom(float zoom);
00151 float GetZoom(void);
00152
00153 bool CanGoForward(void);
00154 bool CanGoBack(void);
00155
00156 QVariant evaluateJavaScript(const QString& scriptSource);
00157
00158 void SetDefaultSaveDirectory(const QString &saveDir);
00159 QString GetDefaultSaveDirectory(void) { return m_defaultSaveDir; }
00160
00161 void SetDefaultSaveFilename(const QString &filename);
00162 QString GetDefaultSaveFilename(void) { return m_defaultSaveFilename; }
00163
00164 public slots:
00165 void Back(void);
00166 void Forward(void);
00167 void ZoomIn(void);
00168 void ZoomOut(void);
00169
00170 signals:
00171 void loadStarted(void);
00172 void loadFinished(bool ok);
00173 void loadProgress(int progress);
00174 void titleChanged(const QString &title);
00175 void statusBarMessage(const QString &text);
00176 void iconChanged(void);
00177 void fileDownloaded(QString filename);
00178
00179 protected slots:
00180 void slotLoadStarted(void);
00181 void slotLoadFinished(bool Ok);
00182 void slotLoadProgress(int progress);
00183 void slotTitleChanged(const QString &title);
00184 void slotStatusBarMessage(const QString &text);
00185 void slotIconChanged(void);
00186 void slotLinkClicked(const QUrl &url);
00187 void slotTopScreenChanged(MythScreenType *screen);
00188
00189 protected:
00190 void Finalize(void);
00191 void UpdateBuffer(void);
00192 void HandleMouseAction(const QString &action);
00193 void SetBackgroundColor(QColor color);
00194 void ResetScrollBars(void);
00195 void UpdateScrollBars(void);
00196
00197 virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
00198 int alphaMod, QRect clipRegion);
00199
00200 virtual bool ParseElement(
00201 const QString &filename, QDomElement &element, bool showWarnings);
00202 virtual void CopyFrom(MythUIType *base);
00203 virtual void CreateCopy(MythUIType *parent);
00204
00205 MythScreenType *m_parentScreen;
00206
00207 MythWebView *m_browser;
00208 MythRect m_browserArea;
00209
00210 MythImage *m_image;
00211
00212 bool m_active;
00213 bool m_wasActive;
00214 bool m_initialized;
00215 QTime m_lastUpdateTime;
00216 int m_updateInterval;
00217
00218 float m_zoom;
00219 QColor m_bgColor;
00220 QUrl m_widgetUrl;
00221 QString m_userCssFile;
00222 QString m_defaultSaveDir;
00223 QString m_defaultSaveFilename;
00224
00225 bool m_inputToggled;
00226 QString m_lastMouseAction;
00227 int m_mouseKeyCount;
00228 QTime m_lastMouseActionTime;
00229
00230 MythUIScrollBar *m_horizontalScrollbar;
00231 MythUIScrollBar *m_verticalScrollbar;
00232 MythUIAnimation m_scrollAnimation;
00233 QPoint m_destinationScrollPos;
00234 };
00235
00236 #endif