diff options
author | Jonathan Bauer | 2011-03-30 14:08:04 +0200 |
---|---|---|
committer | Jonathan Bauer | 2011-03-30 14:08:04 +0200 |
commit | dd78cf7adfc03344147828ca51017e75c25e71f8 (patch) | |
tree | 6d1b6a640b0ac8286197e2110a2fb29eaadfe276 /src | |
parent | Merge branch 'master' of git.openslx.org:lsfks/master-teamprojekt/fbgui (diff) | |
download | fbgui-dd78cf7adfc03344147828ca51017e75c25e71f8.tar.gz fbgui-dd78cf7adfc03344147828ca51017e75c25e71f8.tar.xz fbgui-dd78cf7adfc03344147828ca51017e75c25e71f8.zip |
jsi code strcture
Diffstat (limited to 'src')
-rw-r--r-- | src/javascriptinterface.cpp | 112 | ||||
-rw-r--r-- | src/javascriptinterface.h | 16 |
2 files changed, 71 insertions, 57 deletions
diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp index d0fa5a9..49eef82 100644 --- a/src/javascriptinterface.cpp +++ b/src/javascriptinterface.cpp @@ -4,32 +4,54 @@ //------------------------------------------------------------------------------------------------------- +// Initialisation +//------------------------------------------------------------------------------------------------------- JavascriptInterface::JavascriptInterface(QWebFrame *parent){ qxtLog->debug() << "Initializing javascript interface..."; _parent = parent; } //------------------------------------------------------------------------------------------------------- -JavascriptInterface::~JavascriptInterface() {} -//------------------------------------------------------------------------------------------------------- -const QString JavascriptInterface::getSysInfo(const QString& info){ - SysInfo si; - return si.getInfo(info); -} +JavascriptInterface::~JavascriptInterface() { /* destructor dummy */ } //------------------------------------------------------------------------------------------------------- void JavascriptInterface::attachToDOM(){ _parent->addToJavaScriptWindowObject(QString("fbgui"), this); loadJQuery(); } //------------------------------------------------------------------------------------------------------- -void JavascriptInterface::notify(const QString& msg){ - qxtLog->debug() << "[jvi] Notifying: " << msg; - QString code = QString("notify('\%1')").arg(msg); - _parent->evaluateJavaScript(code); +void JavascriptInterface::loadJQuery(){ + 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") + { + //qDebug()<< fi.fileName(); + //qxtLog->debug() << fi.fileName(); + if(fi.fileName()!="test.js") + { + QFile file; + file.setFileName(pathToJsDir + "/" + fi.fileName()); + file.open(QIODevice::ReadOnly); + js = file.readAll(); + file.close(); + + _parent->evaluateJavaScript(js); + //qxtLog->debug() << "evaluated " + fi.fileName(); + } + } + } } //------------------------------------------------------------------------------------------------------- +// Javascript functions for webpage +//------------------------------------------------------------------------------------------------------- void JavascriptInterface::getSession(const QString& session){ - qxtLog->debug() << "[jvi] Received session id: " << session; - sessionID = session; + qxtLog->debug() << "[jsi] Received session id: " << session; + sessionID = session; } //------------------------------------------------------------------------------------------------------- void JavascriptInterface::startDownload(const QString& filename){ @@ -41,6 +63,22 @@ void JavascriptInterface::startDownload(const QString& filename){ emit requestFile(filename); } //------------------------------------------------------------------------------------------------------- +void JavascriptInterface::setCallbackOnFinished(const QString& function){ + qxtLog->debug() << "[jsi] Callback set: " << function; + _callbackOnDownloadsFinished = QString(function); +} +//------------------------------------------------------------------------------------------------------- +const QString JavascriptInterface::getSysInfo(const QString& info){ + SysInfo si; + return si.getInfo(info); +} +//------------------------------------------------------------------------------------------------------- +void JavascriptInterface::quit(){ + emit quitFbgui(); +} +//------------------------------------------------------------------------------------------------------- +// Download Manager information exchange +//------------------------------------------------------------------------------------------------------- void JavascriptInterface::downloadInfo(const QString& filename, const double& filesize){ QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(filesize); _parent->evaluateJavaScript(code); @@ -52,9 +90,10 @@ void JavascriptInterface::updateProgressBar(const int& percent, const double& sp _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- -void JavascriptInterface::setCallbackOnFinished(const QString& function){ - qxtLog->debug() << "[jvi] Callback set: " << function; - _callbackOnDownloadsFinished = QString(function); +void JavascriptInterface::notify(const QString& msg){ + qxtLog->debug() << "[jsi] Notifying: " << msg; + QString code = QString("notify('\%1')").arg(msg); + _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- void JavascriptInterface::callbackOnFinished(){ @@ -62,43 +101,12 @@ void JavascriptInterface::callbackOnFinished(){ _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- -void JavascriptInterface::quit(){ - emit quitFbgui(); -} //------------------------------------------------------------------------------------------------------- -void JavascriptInterface::loadJQuery(){ - 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") - { - //qDebug()<< fi.fileName(); - //qxtLog->debug() << fi.fileName(); - if(fi.fileName()!="test.js") - { - QFile file; - file.setFileName(pathToJsDir + "/" + fi.fileName()); - file.open(QIODevice::ReadOnly); - js = file.readAll(); - file.close(); - - _parent->evaluateJavaScript(js); - //qxtLog->debug() << "evaluated " + fi.fileName(); - } - } - } -} void JavascriptInterface::trigger(){ - QFile file(fileToTriggerURL); - if (file.open(QIODevice::WriteOnly)){ - file.write("data\n"); - qxtLog->debug() << "[jvi] *trigger watcher*"; - } - file.close(); + QFile file(fileToTriggerURL); + if (file.open(QIODevice::WriteOnly)){ + file.write("data\n"); + qxtLog->debug() << "[jsi] *trigger watcher*"; + } + file.close(); } diff --git a/src/javascriptinterface.h b/src/javascriptinterface.h index 65a29a9..fc2caf3 100644 --- a/src/javascriptinterface.h +++ b/src/javascriptinterface.h @@ -28,28 +28,34 @@ public: ~JavascriptInterface(); private: + // pointer to parent QWebFrame* _parent; + // function to be called withint javascript when downloads are done. QString _callbackOnDownloadsFinished; - + // loads jQuery code void loadJQuery(); signals: + // request the file from download manager void requestFile(const QString& filename); + // quit the application void quitFbgui(); public slots: // make sure the interface stays attached on webpage reload void attachToDOM(); - // Slots for calling from the webpage + // slots for calling from the webpage void getSession(const QString& session); - const QString getSysInfo(const QString& info); void startDownload(const QString& filename); void setCallbackOnFinished(const QString& function); + const QString getSysInfo(const QString& info); void quit(); - // Slots for information exchange with the download manager. - void callbackOnFinished(); + // callback when downloads are done. + void callbackOnFinished(); + + // slots for information exchange with the download manager. void updateProgressBar(const int& percent, const double& speed, const QString& unit); void downloadInfo(const QString& filename, const double& filesize); void notify(const QString& msg); |