[GB.QT4.WEBKIT]

* NEW: WebView.UserAgent is a new property to define a custom user agent 
  string for a specific WebView control.


git-svn-id: svn://localhost/gambas/trunk@4038 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2011-08-25 19:32:41 +00:00
parent 567ba1bb1d
commit de44c3803f
2 changed files with 41 additions and 0 deletions

View file

@ -198,6 +198,7 @@ BEGIN_METHOD_VOID(WebView_free)
_network_access_manager_view = 0;
GB.FreeString(&THIS->status);
GB.FreeString(&THIS->userAgent);
GB.Unref(POINTER(&THIS->icon));
END_METHOD
@ -522,6 +523,15 @@ BEGIN_METHOD(WebView_Eval, GB_STRING javascript)
END_METHOD
BEGIN_PROPERTY(WebView_UserAgent)
if (READ_PROPERTY)
GB.ReturnString(THIS->userAgent);
else
GB.StoreString(PROP(GB_STRING), &THIS->userAgent);
END_PROPERTY
/***************************************************************************/
GB_DESC CWebViewAuthDesc[] =
@ -583,6 +593,8 @@ GB_DESC CWebViewDesc[] =
//GB_METHOD("CanExec", "b", WebView_CanExec, "(Action)s"),
GB_METHOD("Eval", "v", WebView_Eval, "(JavaScript)s"),
GB_PROPERTY("UserAgent", "s", WebView_UserAgent),
GB_CONSTANT("_Properties", "s", "*,Url,Editable"),
GB_CONSTANT("_Group", "s", "View"),
@ -605,9 +617,23 @@ GB_DESC CWebViewDesc[] =
/***************************************************************************/
MyWebPage::MyWebPage(QObject *parent) : QWebPage(parent)
{
}
QString MyWebPage::userAgentForUrl(const QUrl& url) const
{
MyWebView *view = (MyWebView *)parent();
void *_object = QT.GetObject(view);
return (const char *)THIS->userAgent;
};
MyWebView::MyWebView(QWidget *parent) : QWebView(parent)
{
//settings()->setFontFamily(QWebSettings::FixedFont, "monospace");
setPage(new MyWebPage(this));
}
QWebView *MyWebView::createWindow(QWebPage::WebWindowType type)

View file

@ -29,6 +29,7 @@
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QWebFrame>
#include <QWebPage>
#include <QWebView>
#include "cwebdownload.h"
@ -47,6 +48,19 @@ extern GB_DESC CWebViewDownloadsDesc[];
#endif
class MyWebPage : public QWebPage
{
Q_OBJECT
public:
MyWebPage(QObject *parent);
protected:
virtual QString userAgentForUrl(const QUrl& url) const;
};
class MyWebView : public QWebView
{
Q_OBJECT
@ -70,6 +84,7 @@ typedef
QT_PICTURE icon;
QNetworkReply *reply;
QAuthenticator *authenticator;
char *userAgent;
}
CWEBVIEW;