blob: 72d08443518524e9323e1c83728f4c24af9bfa6c (
plain) (
tree)
|
|
#include "fbgui.h"
#include "ndgui.h"
#include "javascriptinterface.h"
#include "sysinfo.h"
#include <log4cxx/logger.h>
#include "qlog4cxx.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
LoggerPtr jsiLogger(Logger::getLogger("fbgui.jsi"));
//-------------------------------------------------------------------------------------------------------
// Initialisation
//-------------------------------------------------------------------------------------------------------
/**
* A constructor.
*
* @param parent
* Is of type QWebFrame.
*/
JavascriptInterface::JavascriptInterface(QWebFrame *parent) {
LOG4CXX_DEBUG(jsiLogger, "Initializing javascript interface...");
_targetFrame = parent;
}
//-------------------------------------------------------------------------------------------------------
/**
* An empty destructor.
*/
JavascriptInterface::~JavascriptInterface() { /* destructor dummy */
}
//-------------------------------------------------------------------------------------------------------
/**
* Attaches an instance of this class to the DOM of the HTML page.
*
* Attaches an instance of this class to the DOM of the HTML page.
* This enables the possibility to call slots/methods of this class in
* JavaScript functions of HTML page. It also calls the
* JavascriptInterface::loadJQuery() method.
*
* @see JavascriptInterface::loadJQuery()
*/
void JavascriptInterface::attachToDOM() {
_targetFrame->addToJavaScriptWindowObject(QString("fbgui"), this);
loadJQuery();
}
//-------------------------------------------------------------------------------------------------------
/**
* This method load the required jQuery libraries into the HTML page.
*
* This method load the required jQuery libraries into the HTML page.
* The libraries are contained in the fbgui.qrc file.
* The Path to the files is: ":/html/js".
* Each library will be read and loaded into the HTML page via
* the evaluateJavaScript() method.
*
* @see JavascriptInterface::attachToDOM()
*/
void JavascriptInterface::loadJQuery() {
// to test if this actually works...
QString js;
QString pathToJsDir(DEFAULT_QRC_HTML_DIR);
pathToJsDir.append("/js");
QDir qrcJSDir(pathToJsDir);
QFileInfoList fiList = qrcJSDir.entryInfoList();
QFileInfo fi;
foreach(fi, fiList) {
if (fi.suffix() == "js") {
QFile file;
file.setFileName(pathToJsDir + "/" + fi.fileName());
file.open(QIODevice::ReadOnly);
js = file.readAll();
file.close();
_targetFrame->evaluateJavaScript(js);
//LOG4CXX_DEBUG(jsiLogger, "evaluated " + fi.fileName());
}
}
}
//-------------------------------------------------------------------------------------------------------
/**
* This method quits the whole program.
*
* This method quits the whole program.
* Can be called from inside a JavaScript function of the HTML page.
* Emits JavascriptInterface::quitFbgui() signal
*/
void JavascriptInterface::quit() {
emit quitFbgui();
}
//-------------------------------------------------------------------------------------------------------
/**
* This method performs a shutdown of the client.
*
* This method performs a shutdown of the client.
* Emits the JavascriptInterface::shutDownClient() signal.It is
* connected with the fbgui::performShutDown() method.
*
* @see fbgui::performShutDown()
*/
void JavascriptInterface::shutDown() {
emit shutDownClient();
}
//-------------------------------------------------------------------------------------------------------
/**
* This method performs a reboot of the client.
*
* This method performs a reboot of the client.
* Emits the JavascriptInterface::rebootClient() signal. It is
* connected with the fbgui::performReboot() method.
*
* @see fbgui::performReboot()
*/
void JavascriptInterface::reboot() {
emit rebootClient();
}
//-------------------------------------------------------------------------------------------------------
/**
* This method sends out messages to Javascript. A corresponding function must be implemented
* on the webpage to receive these.
*/
void JavascriptInterface::notify(const QString& msg) {
LOG4CXX_DEBUG(jsiLogger, "Notifying: " << msg);
QString code = QString("notify('\%1')").arg(msg);
_targetFrame->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
// Network Discovery Communication
//-------------------------------------------------------------------------------------------------------
|