Permit opening subwindow from js with SkyliveX object working

parent 018ad60b
function skyliveClass () {} function skyliveClass () {}
skyliveClass.prototype.method = function(name, func){ skyliveClass.prototype.changeContent = function(id, content){
this.prototype[name] = func;
return this;
}
skyliveClass.method('changeContent', function(id, content){
var n=document.getElementById(id); var n=document.getElementById(id);
if(typeof(n)!="undefined") if(typeof(n)!="undefined")
n.innerHTML=content; n.innerHTML=content;
}); };
skyliveClass.method('notify', function(content){ skyliveClass.prototype.notify = function(content){
if(typeof(notifycb)=="function") if(typeof(notifycb)=="function")
notifycb(content); notifycb(content);
}); };
skyliveClass.method('msgalert', function(content){ skyliveClass.prototype.msgalert = function(content){
if(typeof(alertcb)=="function") if(typeof(alertcb)=="function")
alertcb(content); alertcb(content);
//else //else
// alert(content); // alert(content);
}); };
skyliveClass.method('publicReceived', function(user, msg){ skyliveClass.prototype.publicReceived = function(user, msg){
if(typeof(public_received)=="function") if(typeof(public_received)=="function")
{ {
public_received(user, msg); public_received(user, msg);
...@@ -32,9 +28,10 @@ skyliveClass.method('publicReceived', function(user, msg){ ...@@ -32,9 +28,10 @@ skyliveClass.method('publicReceived', function(user, msg){
n.scollTop = n.scrollHeight; n.scollTop = n.scrollHeight;
} }
} }
}); };
SkyliveX.page = new SkyliveClass();
SkyliveX.changeContent.connect(SkyliveX.page.changeContent); SkyliveXPage = new skyliveClass();
SkyliveX.notify.connect(SkyliveX.page.notify); SkyliveX.changeContent.connect(SkyliveXPage.changeContent);
SkyliveX.alertmsg.connect(SkyliveX.page.msgalert); SkyliveX.notify.connect(SkyliveXPage.notify);
SkyliveX.public_received.connect(SkyliveX.page.publicReceived); SkyliveX.alertmsg.connect(SkyliveXPage.msgalert);
SkyliveX.public_received.connect(SkyliveXPage.publicReceived);
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
*/ */
#include "webwin.h" #include "webwin.h"
#include <QWebView> #include <QWebView>
#include <QWebPage>
#include <QWebFrame> #include <QWebFrame>
#include <QFile> #include <QFile>
#include <QUrl> #include <QUrl>
...@@ -44,6 +45,7 @@ ...@@ -44,6 +45,7 @@
#include <iostream> #include <iostream>
#include "ipcmsg.h" #include "ipcmsg.h"
#include "jsbridge.h" #include "jsbridge.h"
#include "QWebSettings"
#define SENDER "webwin" #define SENDER "webwin"
...@@ -52,6 +54,10 @@ WebWin::WebWin(QString &htmlfile) ...@@ -52,6 +54,10 @@ WebWin::WebWin(QString &htmlfile)
{ {
baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html")); baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html"));
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
//settings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
QPalette pal = palette(); QPalette pal = palette();
pal.setBrush(QPalette::Base, Qt::transparent); pal.setBrush(QPalette::Base, Qt::transparent);
...@@ -74,11 +80,43 @@ WebWin::WebWin(QString &htmlfile) ...@@ -74,11 +80,43 @@ WebWin::WebWin(QString &htmlfile)
} }
WebWin::WebWin()
: QWebView()
{
baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html"));
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
jsbridge = new JSBridge();
jsbridge->wwin = qobject_cast<WebWin *>(this);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", jsbridge);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(refreshJsObject()));
msgsender = SENDER;
}
WebWin::~WebWin() WebWin::~WebWin()
{ {
} }
QWebView* WebWin::createWindow(QWebPage::WebWindowType type)
{
WebWin *wv = new WebWin;
QWebPage *newWeb = new QWebPage(wv);
wv->jsbridge = new JSBridge();
newWeb->mainFrame()->addToJavaScriptWindowObject("SkyliveX", wv->jsbridge);
connect(newWeb->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), wv, SLOT(refreshJsObject()));
wv->setPage(newWeb);
wv->setAttribute(Qt::WA_DeleteOnClose, true);
if (type == QWebPage::WebModalDialog)
wv->setWindowModality(Qt::ApplicationModal);
wv->show();
return wv;
}
// XXX This can be used in future to permit // XXX This can be used in future to permit
// to drag a window borderless on the desktop. // to drag a window borderless on the desktop.
/* /*
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#define WEBWIN_H #define WEBWIN_H
#include <QWebView> #include <QWebView>
#include <QWebPage>
#include <QUrl> #include <QUrl>
#include <QFile> #include <QFile>
#include <QHash> #include <QHash>
...@@ -69,6 +70,7 @@ class WebWin : public QWebView ...@@ -69,6 +70,7 @@ class WebWin : public QWebView
QHash<QString, SKHandlerFunction> _handlers; QHash<QString, SKHandlerFunction> _handlers;
public: public:
WebWin();
WebWin(QString &htmlfile); WebWin(QString &htmlfile);
~WebWin(); ~WebWin();
void setHtmlFile(QString &fname); void setHtmlFile(QString &fname);
...@@ -78,6 +80,7 @@ class WebWin : public QWebView ...@@ -78,6 +80,7 @@ class WebWin : public QWebView
void registerHandler(QString type, SKHandlerFunction handler); void registerHandler(QString type, SKHandlerFunction handler);
void toggleBorders(bool borders); void toggleBorders(bool borders);
void toggleTransparentBackground(bool transparentbg); void toggleTransparentBackground(bool transparentbg);
QWebView* createWindow(QWebPage::WebWindowType type);
JSBridge* jsbridge; JSBridge* jsbridge;
QString msgsender; QString msgsender;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment