SkyliveX js object in the bridge now has SkyliveX.open_window() method

parent ad8a46b4
......@@ -33,6 +33,7 @@
*
*/
#include <QString>
#include <QWebPage>
#include <iostream>
#include "ipcmsg.h"
#include "jsbridge.h"
......@@ -90,3 +91,12 @@ void JSBridge::change_telescope(QString tele)
wwin->sendMessage(msg);
}
SkylivexWin* JSBridge::open_window(QString url, bool Modal)
{
if(Modal)
return wwin->createSkyliveWindow(url, QWebPage::WebModalDialog);
else
return wwin->createSkyliveWindow(url, QWebPage::WebBrowserWindow);
}
......@@ -39,7 +39,7 @@
#include <QString>
#include "webwin.h"
class WebWin; // forward declaration for typedef
class SkylivexWin; // forward declaration for typedef
/*
* class JSBridge
......@@ -51,7 +51,7 @@ class JSBridge : public QObject
Q_OBJECT
public:
WebWin* wwin;
SkylivexWin* wwin;
void changePageContent(QString elementid, QString content);
signals:
......@@ -68,6 +68,7 @@ class JSBridge : public QObject
void chat_message_send(QString dest, QString message);
void chat_message_send(QString message);
void change_telescope(QString tele);
SkylivexWin* open_window(QString url, bool Modal);
};
......
......@@ -48,17 +48,14 @@
#define SENDER "maingui"
MainWin::MainWin(QString &htmlfile)
: WebWin(htmlfile)
: SkylivexWin(htmlfile)
{
registerHandler((QString)"coreStarted", (SKHandlerFunction)&MainWin::handle_corestarted);
registerHandler((QString)"telescopeConnected", (SKHandlerFunction)&MainWin::handle_connected);
registerHandler((QString)"asklogin", (SKHandlerFunction)&MainWin::handle_asklogin);
registerHandler((QString)"alert", (SKHandlerFunction)&MainWin::handle_alert);
registerHandler((QString)"notify", (SKHandlerFunction)&MainWin::handle_notify);
registerHandler((QString)"loginok", (SKHandlerFunction)&MainWin::handle_loginres);
registerHandler((QString)"loginfailed", (SKHandlerFunction)&MainWin::handle_loginres);
registerHandler((QString)"publicchatrcv", (SKHandlerFunction)&MainWin::handle_chatreceived);
msgsender = SENDER;
......@@ -95,18 +92,6 @@ void MainWin::handle_asklogin(SKMessage &msg)
}
void MainWin::handle_alert(SKMessage &msg)
{
if(msg.parameters.contains("msg"))
jsbridge->alertmsg(msg.parameters["msg"]);
}
void MainWin::handle_notify(SKMessage &msg)
{
if(msg.parameters.contains("msg"))
jsbridge->notify(msg.parameters["msg"]);
}
void MainWin::handle_loginres(SKMessage &msg)
{
if(msg.handle=="loginok")
......@@ -121,14 +106,3 @@ void MainWin::handle_loginres(SKMessage &msg)
}
}
void MainWin::handle_chatreceived(SKMessage &msg)
{
if(msg.handle=="publicchatrcv")
{
if(msg.parameters.contains("msg") && msg.parameters.contains("username"))
{
jsbridge->public_received(msg.parameters["username"], msg.parameters["msg"]);
}
}
}
......@@ -49,7 +49,7 @@
* This is just a little webkit transparent window
* to show the splash screen
*/
class MainWin : public WebWin
class MainWin : public SkylivexWin
{
Q_OBJECT
......@@ -61,10 +61,7 @@ class MainWin : public WebWin
void handle_corestarted(SKMessage &msg);
void handle_connected(SKMessage &msg);
void handle_asklogin(SKMessage &msg);
void handle_alert(SKMessage &msg);
void handle_notify(SKMessage &msg);
void handle_loginres(SKMessage &msg);
void handle_chatreceived(SKMessage &msg);
};
......
......@@ -38,6 +38,7 @@
#include <QWebFrame>
#include <QFile>
#include <QUrl>
#include <QList>
#include <QDir>
#include <QString>
#include <QPalette>
......@@ -68,12 +69,6 @@ WebWin::WebWin(QString &htmlfile)
setHtmlFile(htmlfile);
resize(250,200);
jsbridge = new JSBridge();
jsbridge->wwin = qobject_cast<WebWin *>(this);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", jsbridge);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(refreshJsObject()));
msgsender = SENDER;
......@@ -86,11 +81,6 @@ WebWin::WebWin()
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;
}
......@@ -103,11 +93,6 @@ 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)
......@@ -126,15 +111,6 @@ void WebWin::dragMoveEvent(QDragMoveEvent *ev)
}
*/
void WebWin::refreshJsObject()
{
//page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge);
jsbridge = new JSBridge();
jsbridge->wwin = qobject_cast<WebWin *>(this);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", jsbridge);
}
void WebWin::setHtmlFile(QString &fname)
{
......@@ -142,8 +118,6 @@ void WebWin::setHtmlFile(QString &fname)
filename.open(QIODevice::ReadOnly);
htmlFileCont = QString::fromUtf8(filename.readAll().constData());
setHtml(htmlFileCont, baseUrl);
//page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge);
//jsbridge.mwin=qobject_cast<WebWin *>(this);
}
void WebWin::setHtmlFile(QString &fname, bool borders, bool transparentbg)
......@@ -218,7 +192,6 @@ void WebWin::toggleTransparentBackground(bool transparentbg)
void WebWin::sendMessage(SKMessage &msg)
{
//msg.sender=SENDER;
msg.sender = msgsender;
emit putMessage(msg);
}
......@@ -229,3 +202,106 @@ void WebWin::registerHandler(QString type, SKHandlerFunction handler)
}
SkylivexWin::SkylivexWin(QString &htmlfile)
: WebWin(htmlfile)
{
msgsender = "SkylivexWin";
jsbridge = new JSBridge();
jsbridge->wwin = qobject_cast<SkylivexWin *>(this);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", jsbridge);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(refreshJsObject()));
registerHandler((QString)"alert", (SKHandlerFunction)&SkylivexWin::handle_alert);
registerHandler((QString)"notify", (SKHandlerFunction)&SkylivexWin::handle_notify);
registerHandler((QString)"publicchatrcv", (SKHandlerFunction)&SkylivexWin::handle_chatreceived);
}
SkylivexWin::SkylivexWin()
: WebWin()
{
jsbridge = new JSBridge();
jsbridge->wwin = qobject_cast<SkylivexWin *>(this);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", jsbridge);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(refreshJsObject()));
msgsender = SENDER;
registerHandler((QString)"alert", (SKHandlerFunction)&SkylivexWin::handle_alert);
registerHandler((QString)"notify", (SKHandlerFunction)&SkylivexWin::handle_notify);
registerHandler((QString)"publicchatrcv", (SKHandlerFunction)&SkylivexWin::handle_chatreceived);
}
SkylivexWin* SkylivexWin::createSkyliveWindow(QString url, QWebPage::WebWindowType type)
{
SkylivexWin *wv = new SkylivexWin;
QWebPage *newWeb = new QWebPage(wv);
wv->jsbridge = new JSBridge();
wv->jsbridge->wwin = qobject_cast<SkylivexWin *>(wv);
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);
QList<QString> urilist = url.split("://");
if(urilist.size() <= 1)
{
QString uristring = baseUrl.toString().replace("dummy.html", "");
url.prepend(uristring);
std::cout << "transform uri in local file " << url.toStdString() << std::endl;
}
wv->setUrl(QUrl(url));
wv->show();
return wv;
}
SkylivexWin::~SkylivexWin()
{
}
void SkylivexWin::refreshJsObject()
{
jsbridge = new JSBridge();
jsbridge->wwin = qobject_cast<SkylivexWin *>(this);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", jsbridge);
}
void SkylivexWin::handle_alert(SKMessage &msg)
{
if(msg.parameters.contains("msg"))
jsbridge->alertmsg(msg.parameters["msg"]);
}
void SkylivexWin::handle_notify(SKMessage &msg)
{
if(msg.parameters.contains("msg"))
jsbridge->notify(msg.parameters["msg"]);
}
void SkylivexWin::handle_chatreceived(SKMessage &msg)
{
if(msg.handle=="publicchatrcv")
{
if(msg.parameters.contains("msg") && msg.parameters.contains("username"))
{
jsbridge->public_received(msg.parameters["username"], msg.parameters["msg"]);
}
}
}
......@@ -62,7 +62,6 @@ class WebWin : public QWebView
Q_OBJECT
QUrl baseUrl;
QString htmlfile;
QString htmlFileCont;
......@@ -81,11 +80,8 @@ class WebWin : public QWebView
void toggleBorders(bool borders);
void toggleTransparentBackground(bool transparentbg);
QWebView* createWindow(QWebPage::WebWindowType type);
JSBridge* jsbridge;
QString msgsender;
private slots:
void refreshJsObject();
QUrl baseUrl;
public slots:
void msgFromCore(SKMessage &msg);
......@@ -99,4 +95,27 @@ class WebWin : public QWebView
};
class SkylivexWin : public WebWin
{
Q_OBJECT
public:
SkylivexWin();
SkylivexWin(QString &htmlfile);
~SkylivexWin();
SkylivexWin* createSkyliveWindow(QString url, QWebPage::WebWindowType type);
JSBridge* jsbridge;
QString msgsender;
void handle_alert(SKMessage &msg);
void handle_notify(SKMessage &msg);
void handle_chatreceived(SKMessage &msg);
private slots:
void refreshJsObject();
};
#endif
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