WebView GUI window and core bridge connection established

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