WebView GUI window and core bridge connection established

parent 03fe344b
function changeContent(id, content)
{
document.getElementById(id).innerHTML=content;
}
SkyliveX.changeContent.connect(changeContent);
<html>
<head>
<title>SkyliveX</title>
<script type="text/javascript" src="SkyliveX.js"></script>
<style>
#loading {
color: #ff0000;
......@@ -10,7 +11,7 @@
<body>
<div id="loading">
<img src="img/logo.png"></img>
<h3>Loading...</h3>
<h3 id="loadstring">Loading...</h3>
</div>
</body>
</html>
......@@ -53,7 +53,7 @@ void SkyliveProtocol::readFromNetwork()
while(tcpSocket->bytesAvailable())
{
tcpSocket->read(buffer, 50);
std::cout << "Received From Skylive Server" << buffer << std::endl;
std::cout << "Received From Skylive Server: " << buffer << std::endl;
}
}
......
......@@ -34,6 +34,7 @@
*/
#include "mainwin.h"
#include <QWebView>
#include <QWebFrame>
#include <QFile>
#include <QDir>
#include <QString>
......@@ -59,6 +60,8 @@ MainWin::MainWin(QFile &htmlfile)
setHtml(htmlFileName, baseUrl);
resize(250,200);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge);
registerHandler((QString)"coreStarted", &MainWin::handle_corestarted);
}
......@@ -95,4 +98,11 @@ void MainWin::handle_corestarted(SKMessage::SKMessage &msg)
{
msg.handle = "connectTelescopes";
sendMessage(msg);
jsbridge.changePageContent("loadstring", "Connecting...");
}
void JSBridge::changePageContent(QString elementid, QString content)
{
emit changeContent(elementid, content);
}
......@@ -48,6 +48,25 @@ class MainWin; // forward declaration for typedef
// This is for member pointers to map messages
typedef void (MainWin::*SKHandlerFunction)(SKMessage::SKMessage&);
/*
* class JSBridge
* This class connect the javascript object SkyliveX
* to c++
*/
class JSBridge : public QObject
{
Q_OBJECT
public:
void changePageContent(QString elementid, QString content);
signals:
void changeContent(QString elementid, QString content);
};
/*
* class MainWin
* This is just a little webkit transparent window
......@@ -61,6 +80,7 @@ class MainWin : public QWebView
QUrl baseurl;
QFile htmlfile;
QString htmlFileName;
JSBridge jsbridge;
private:
QHash<QString, SKHandlerFunction> _handlers;
......
......@@ -10,7 +10,8 @@ HEADERS = skylivex.h \
QT += core network webkitwidgets widgets
OTHER_FILES += \
../gui/splash.html \
../gui/img/logo.png
OTHER_FILES += ../gui/ \
../gui/*.js \
../gui/*.html \
../gui/img/*
DESTDIR = ../build/
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