Login page and login sequence complete!

There is also a command SERMES to be added!
parent 6bff57e7
...@@ -2,7 +2,7 @@ function changeContent(id, content) ...@@ -2,7 +2,7 @@ function changeContent(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="ESTICAZZI";
} }
function notify(content) function notify(content)
......
gui/img/logo.png

25.9 KB | W: | H:

gui/img/logo.png

23.6 KB | W: | H:

gui/img/logo.png
gui/img/logo.png
gui/img/logo.png
gui/img/logo.png
  • 2-up
  • Swipe
  • Onion skin
<html>
<head>
<title>SkyliveX</title>
<script type="text/javascript" src="SkyliveX.js"></script>
<script type="text/javascript">
function sendLogin()
{
SkyliveX.pushLogin(document.forms.loginform.user.value, document.forms.loginform.pass.value);
}
</script>
<style>
#page {
background-color: #0000FF;
color: #FFFFFF;
text-align: center;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="page">
<b>SkyliveX 0.1.0 Login</b>
<form id="login" name="loginform">
Username: <input type="text" value="" name="user" placeholder="username">
Password: <input type="password" value="" name="pass" placeholder="password">
<input type="submit" value="Login" onClick="sendLogin();">
</form>
</div>
</body>
</html>
...@@ -2,15 +2,24 @@ ...@@ -2,15 +2,24 @@
<head> <head>
<title>SkyliveX</title> <title>SkyliveX</title>
<script type="text/javascript"> <script type="text/javascript">
function notifycb(content) function notifycb(c)
{ {
document.getElementById("loadstring").innerHTML=content; document.getElementById("loadstring").innerHTML=c;
} }
</script> </script>
<script type="text/javascript" src="SkyliveX.js"></script> <script type="text/javascript" src="SkyliveX.js"></script>
<style> <style>
#loading { #loading {
color: #ff0000; color: #FFFFFF;
text-align: center;
margin: 0 auto;
}
#loading h3 {
background-color: #0000ff;
width:100%;
text-align: center;
padding-bottom:5px;
padding-top: 3px;
} }
</style> </style>
</head> </head>
......
...@@ -40,16 +40,47 @@ ...@@ -40,16 +40,47 @@
void SkyliveAuth::startPlugin() void SkyliveAuth::startPlugin()
{ {
std::cout << "SkyliveAuth initialized in thread " << thread() << std::endl; std::cout << "SkyliveAuth initialized in thread " << thread() << std::endl;
registerHandler((QString)"getlogin", &SkyliveAuth::handle_getlogin);
} }
void SkyliveAuth::receiveMessage(SKMessage::SKMessage msg) void SkyliveAuth::receiveMessage(SKMessage::SKMessage msg)
{ {
std::cout << "SkyliveAuth msg received: " << msg.handle.toStdString() << std::endl; std::cout << "SkyliveAuth msg received: " << msg.handle.toStdString() << std::endl;
if(_handlers.contains(msg.handle) && msg.sender != SENDER)
{
SKHandlerFunction mf =_handlers[msg.handle];
(this->*mf)(msg);
}
} }
void SkyliveAuth::sendMessage(SKMessage::SKMessage msg) void SkyliveAuth::sendMessage(SKMessage::SKMessage msg)
{ {
msg.sender=SENDER;
emit putMessage(msg); emit putMessage(msg);
} }
void SkyliveAuth::registerHandler(QString type, SKHandlerFunction handler)
{
_handlers[type] = handler;
}
void SkyliveAuth::handle_getlogin(SKMessage::SKMessage msg)
{
std::cout << "Auth module handle Login by " << msg.sender.toStdString() << std::endl;
/*
* XXX: This is, for the moment, a dummy plugin.
* Here we should check if we have a saved user and pass,
* and ask the main process only if we donesn't yet have one
* or if the user has logged out.
*/
SKMessage::SKMessage smsg("asklogin");
sendMessage(smsg);
}
...@@ -32,20 +32,38 @@ ...@@ -32,20 +32,38 @@
* Purpose: * Purpose:
* *
*/ */
#ifndef SKAUTH_H
#define SKAUTH_H
#define SENDER "skauth"
#include <QObject> #include <QObject>
#include <QHash>
#include <QString>
#include <QtPlugin> #include <QtPlugin>
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include "ipcmsg.h" #include "ipcmsg.h"
class SkyliveAuth;
typedef void (SkyliveAuth::*SKHandlerFunction)(SKMessage::SKMessage);
class SkyliveAuth : public QObject, SkylivexPluginInterface class SkyliveAuth : public QObject, SkylivexPluginInterface
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "com.skylivex.SkylivexPlugin/1.0" FILE "skauth.json") Q_PLUGIN_METADATA(IID "com.skylivex.SkylivexPlugin/1.0" FILE "skauth.json")
Q_INTERFACES(SkylivexPluginInterface) Q_INTERFACES(SkylivexPluginInterface)
private:
QHash<QString, SKHandlerFunction> _handlers;
public: public:
void startPlugin(); void startPlugin();
void sendMessage(SKMessage::SKMessage msg); void sendMessage(SKMessage::SKMessage msg);
void registerHandler(QString type, SKHandlerFunction handler);
void handle_getlogin(SKMessage::SKMessage msg);
public slots: public slots:
void receiveMessage(SKMessage::SKMessage msg); void receiveMessage(SKMessage::SKMessage msg);
signals: signals:
...@@ -53,3 +71,4 @@ class SkyliveAuth : public QObject, SkylivexPluginInterface ...@@ -53,3 +71,4 @@ class SkyliveAuth : public QObject, SkylivexPluginInterface
}; };
#endif
...@@ -44,13 +44,16 @@ ...@@ -44,13 +44,16 @@
void SkyliveProtocol::startPlugin() void SkyliveProtocol::startPlugin()
{ {
SM_TCPCLIENT = HOME; SM_TCPCLIENT = HOME;
cver=CLIENTVERSION;
std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl; std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl;
registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect); registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect);
registerHandler((QString)"putlogin", &SkyliveProtocol::handle_putlogin);
pktTimer = new QTimer(); pktTimer = new QTimer();
QObject::connect(pktTimer, SIGNAL(timeout()), this, SLOT(processPackets())); QObject::connect(pktTimer, SIGNAL(timeout()), this, SLOT(processPackets()));
pktTimer->start(); pktTimer->start();
} }
...@@ -121,6 +124,8 @@ void SkyliveProtocol::processPackets() ...@@ -121,6 +124,8 @@ void SkyliveProtocol::processPackets()
std::cout << "Packet CRC OK command: " << pkt.cmd.toStdString() <<std::endl; std::cout << "Packet CRC OK command: " << pkt.cmd.toStdString() <<std::endl;
if(pkt.cmd=="LOGIN") if(pkt.cmd=="LOGIN")
{ {
SKMessage::SKMessage msg("getlogin");
sendMessage(msg);
} }
else if(pkt.cmd=="PING") else if(pkt.cmd=="PING")
...@@ -260,16 +265,30 @@ void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg) ...@@ -260,16 +265,30 @@ void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg)
tcpSocket->connectToHost(SERVERHOST, SERVERPORT); tcpSocket->connectToHost(SERVERHOST, SERVERPORT);
} }
void SkyliveProtocol::handle_putlogin(SKMessage::SKMessage msg)
{
QString cmd("LOGIN");
QList<QString> paramlist;
paramlist.append(msg.parameters["username"]);
paramlist.append(msg.parameters["password"]);
paramlist.append(cver);
sendPacket(cmd, paramlist);
}
void SkyliveProtocol::clientConnected() void SkyliveProtocol::clientConnected()
{ {
SM_TCPCLIENT = CONNECTED; SM_TCPCLIENT = CONNECTED;
SKMessage::SKMessage msg("telescopeConnected");
sendMessage(msg);
} }
void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg) void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg)
{ {
std::cout << "SkyliveProtocol msg received: " << msg.handle.toStdString() << std::endl; std::cout << "SkyliveProtocol msg received: " << msg.handle.toStdString() << std::endl;
if(_handlers.contains(msg.handle)) if(_handlers.contains(msg.handle) && msg.sender!=SENDER)
{ {
SKHandlerFunction mf =_handlers[msg.handle]; SKHandlerFunction mf =_handlers[msg.handle];
(this->*mf)(msg); (this->*mf)(msg);
...@@ -279,6 +298,7 @@ void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg) ...@@ -279,6 +298,7 @@ void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg)
void SkyliveProtocol::sendMessage(SKMessage::SKMessage msg) void SkyliveProtocol::sendMessage(SKMessage::SKMessage msg)
{ {
msg.sender=SENDER;
emit putMessage(msg); emit putMessage(msg);
} }
......
...@@ -47,9 +47,13 @@ ...@@ -47,9 +47,13 @@
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include "ipcmsg.h" #include "ipcmsg.h"
#define SENDER "skproto"
#define SERVERHOST "www.skylive.name" #define SERVERHOST "www.skylive.name"
#define SERVERPORT 8080 #define SERVERPORT 8080
#define CLIENTVERSION "X_0.1.0"
#define MAX_PACKETREAD 2048 #define MAX_PACKETREAD 2048
struct SKProtoMsg struct SKProtoMsg
...@@ -96,12 +100,14 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface ...@@ -96,12 +100,14 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
QQueue<SKProtoMsg> protoQueue; QQueue<SKProtoMsg> protoQueue;
QTimer* pktTimer; QTimer* pktTimer;
void clearPkt(); void clearPkt();
QString cver;
public: public:
void startPlugin(); void startPlugin();
void sendMessage(SKMessage::SKMessage msg); void sendMessage(SKMessage::SKMessage msg);
void registerHandler(QString type, SKHandlerFunction handler); void registerHandler(QString type, SKHandlerFunction handler);
void handle_connect(SKMessage::SKMessage msg); void handle_connect(SKMessage::SKMessage msg);
void handle_putlogin(SKMessage::SKMessage msg);
void sendPacket(const char* cmd, const char* params); void sendPacket(const char* cmd, const char* params);
void sendPacket(QString &cmd, QString &params); void sendPacket(QString &cmd, QString &params);
void sendPacket(SKProtoMsg &pkt); void sendPacket(SKProtoMsg &pkt);
......
...@@ -57,6 +57,13 @@ SKMessage::SKMessage(QString h, QHash<QString, QString > p) ...@@ -57,6 +57,13 @@ SKMessage::SKMessage(QString h, QHash<QString, QString > p)
handle = h; handle = h;
} }
SKMessage::SKMessage(QString s, QString h)
{
sender = s;
handle = h;
time = QTime::currentTime();
}
SKMessage::SKMessage(QString h) SKMessage::SKMessage(QString h)
{ {
sender= QString("unknown"); sender= QString("unknown");
......
...@@ -60,6 +60,7 @@ class SKMessage ...@@ -60,6 +60,7 @@ class SKMessage
SKMessage(QString s, QString h, QHash<QString, QString > p); SKMessage(QString s, QString h, QHash<QString, QString > p);
SKMessage(QString h, QHash<QString, QString > p); SKMessage(QString h, QHash<QString, QString > p);
SKMessage(QString s, QString h);
SKMessage(QString h); SKMessage(QString h);
}; };
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
* *
*/ */
#include <QApplication> #include <QApplication>
#include <QFile> #include <QString>
#include <QTimer> #include <QTimer>
#include "mainwin.h" #include "mainwin.h"
#include "skylivex.h" #include "skylivex.h"
...@@ -59,7 +59,7 @@ int main(int argc, char *argv[]) ...@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
// Start the splash screen. also // Start the splash screen. also
// the splash screen is a (transparent) webkit object // the splash screen is a (transparent) webkit object
QFile splashfile("gui/splash.html"); QString splashfile("gui/splash.html");
MainWin mainw(splashfile); MainWin mainw(splashfile);
mainw.show(); mainw.show();
......
...@@ -36,18 +36,20 @@ ...@@ -36,18 +36,20 @@
#include <QWebView> #include <QWebView>
#include <QWebFrame> #include <QWebFrame>
#include <QFile> #include <QFile>
#include <QUrl>
#include <QDir> #include <QDir>
#include <QString> #include <QString>
#include <QPalette> #include <QPalette>
#include <iostream> #include <iostream>
#include "ipcmsg.h" #include "ipcmsg.h"
MainWin::MainWin(QFile &htmlfile) #define SENDER "maingui"
MainWin::MainWin(QString &htmlfile)
: QWebView(0) : QWebView(0)
{ {
htmlfile.open(QIODevice::ReadOnly); baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html"));
htmlFileName = QString::fromUtf8(htmlfile.readAll().constData());
QUrl baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html"));
QPalette pal = palette(); QPalette pal = palette();
pal.setBrush(QPalette::Base, Qt::transparent); pal.setBrush(QPalette::Base, Qt::transparent);
...@@ -57,12 +59,14 @@ MainWin::MainWin(QFile &htmlfile) ...@@ -57,12 +59,14 @@ MainWin::MainWin(QFile &htmlfile)
setAttribute(Qt::WA_TranslucentBackground, true); setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_OpaquePaintEvent, false); setAttribute(Qt::WA_OpaquePaintEvent, false);
setHtml(htmlFileName, baseUrl); setHtmlFile(htmlfile);
resize(250,200); resize(250,200);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge); jsbridge.mwin=qobject_cast<MainWin *>(this);
registerHandler((QString)"coreStarted", &MainWin::handle_corestarted); registerHandler((QString)"coreStarted", &MainWin::handle_corestarted);
registerHandler((QString)"telescopeConnected", &MainWin::handle_connected);
registerHandler((QString)"asklogin", &MainWin::handle_asklogin);
} }
MainWin::~MainWin() MainWin::~MainWin()
...@@ -70,10 +74,21 @@ MainWin::~MainWin() ...@@ -70,10 +74,21 @@ MainWin::~MainWin()
} }
void MainWin::setHtmlFile(QString &fname)
{
QFile filename(fname);
filename.open(QIODevice::ReadOnly);
htmlFileCont = QString::fromUtf8(filename.readAll().constData());
setHtml(htmlFileCont, baseUrl);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge);
}
void MainWin::msgFromCore(SKMessage::SKMessage &msg) void MainWin::msgFromCore(SKMessage::SKMessage &msg)
{ {
std::cout << "MainWindow msg reveived: " << msg.handle.toStdString() << std::endl; std::cout << "MainWindow msg reveived: " << msg.handle.toStdString() << std::endl;
if(_handlers.contains(msg.handle)) if(_handlers.contains(msg.handle) && msg.sender != SENDER)
{ {
SKHandlerFunction mf =_handlers[msg.handle]; SKHandlerFunction mf =_handlers[msg.handle];
(this->*mf)(msg); (this->*mf)(msg);
...@@ -84,6 +99,7 @@ void MainWin::msgFromCore(SKMessage::SKMessage &msg) ...@@ -84,6 +99,7 @@ void MainWin::msgFromCore(SKMessage::SKMessage &msg)
void MainWin::sendMessage(SKMessage::SKMessage &msg) void MainWin::sendMessage(SKMessage::SKMessage &msg)
{ {
msg.sender=SENDER;
emit putMessage(msg); emit putMessage(msg);
} }
...@@ -102,8 +118,32 @@ void MainWin::handle_corestarted(SKMessage::SKMessage &msg) ...@@ -102,8 +118,32 @@ void MainWin::handle_corestarted(SKMessage::SKMessage &msg)
} }
void MainWin::handle_connected(SKMessage::SKMessage &msg)
{
std::cout << "Connected by " << msg.sender.toStdString() << std::endl;
jsbridge.notify("Connected");
}
void MainWin::handle_asklogin(SKMessage::SKMessage &msg)
{
std::cout << "asklogin by " << msg.sender.toStdString() << std::endl;
jsbridge.notify("Logging in");
QString html("gui/login.html");
setHtmlFile(html);
resize(250, 200);
}
void JSBridge::changePageContent(QString elementid, QString content) void JSBridge::changePageContent(QString elementid, QString content)
{ {
emit changeContent(elementid, content); emit changeContent(elementid, content);
} }
void JSBridge::pushLogin(QString username, QString password)
{
std::cout << "pushLogin called from JS" << std::endl;
SKMessage::SKMessage loginmsg("putlogin");
loginmsg.parameters.insert("username", username);
loginmsg.parameters.insert("password", password);
mwin->sendMessage(loginmsg);
}
...@@ -59,11 +59,14 @@ class JSBridge : public QObject ...@@ -59,11 +59,14 @@ class JSBridge : public QObject
Q_OBJECT Q_OBJECT
public: public:
MainWin* mwin;
void changePageContent(QString elementid, QString content); void changePageContent(QString elementid, QString content);
signals: signals:
void changeContent(QString elementid, QString content); void changeContent(QString elementid, QString content);
void notify(QString content); void notify(QString content);
public slots:
void pushLogin(QString username, QString password);
}; };
...@@ -78,20 +81,23 @@ class MainWin : public QWebView ...@@ -78,20 +81,23 @@ class MainWin : public QWebView
Q_OBJECT Q_OBJECT
QUrl baseurl; QUrl baseUrl;
QFile htmlfile; QString htmlfile;
QString htmlFileName; QString htmlFileCont;
JSBridge jsbridge; JSBridge jsbridge;
private: private:
QHash<QString, SKHandlerFunction> _handlers; QHash<QString, SKHandlerFunction> _handlers;
void setHtmlFile(QString &fname);
public: public:
MainWin(QFile &htmlfile); MainWin(QString &htmlfile);
~MainWin(); ~MainWin();
void sendMessage(SKMessage::SKMessage &msg); void sendMessage(SKMessage::SKMessage &msg);
void registerHandler(QString type, SKHandlerFunction handler); void registerHandler(QString type, SKHandlerFunction handler);
void handle_corestarted(SKMessage::SKMessage &msg); void handle_corestarted(SKMessage::SKMessage &msg);
void handle_connected(SKMessage::SKMessage &msg);
void handle_asklogin(SKMessage::SKMessage &msg);
public slots: public slots:
void msgFromCore(SKMessage::SKMessage &msg); void msgFromCore(SKMessage::SKMessage &msg);
......
...@@ -119,7 +119,7 @@ void SkyliveX::sendMessage(SKMessage::SKMessage &msg) ...@@ -119,7 +119,7 @@ void SkyliveX::sendMessage(SKMessage::SKMessage &msg)
void SkyliveX::receiveFromMainWin(SKMessage::SKMessage &msg) void SkyliveX::receiveFromMainWin(SKMessage::SKMessage &msg)
{ {
std::cout << "received from MainWin " << msg.handle.toStdString() << std::endl; std::cout << "received from MainWin " << msg.handle.toStdString() << std::endl;
//emit msgForPlugins(msg); emit msgForPlugins(msg);
} }
void SkyliveX::receiveFromPlugins(SKMessage::SKMessage msg) void SkyliveX::receiveFromPlugins(SKMessage::SKMessage msg)
......
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