summaryrefslogtreecommitdiffstats
path: root/src/fbgui/javascriptinterfacefbgui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fbgui/javascriptinterfacefbgui.cpp')
-rw-r--r--src/fbgui/javascriptinterfacefbgui.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/fbgui/javascriptinterfacefbgui.cpp b/src/fbgui/javascriptinterfacefbgui.cpp
new file mode 100644
index 0000000..d9ff225
--- /dev/null
+++ b/src/fbgui/javascriptinterfacefbgui.cpp
@@ -0,0 +1,115 @@
+/*
+ * javascriptinterfacefbgui.cpp
+ *
+ * Created on: Feb 21, 2012
+ * Author: joe
+ */
+
+#include "javascriptinterfacefbgui.h"
+#include "sysinfo.h"
+
+JavascriptInterfaceFBGUI::JavascriptInterfaceFBGUI(QWebFrame* parent)
+ : JavascriptInterface(parent){
+}
+
+JavascriptInterfaceFBGUI::~JavascriptInterfaceFBGUI() {
+}
+
+//-------------------------------------------------------------------------------------------------------
+// Javascript functions for webpage
+//-------------------------------------------------------------------------------------------------------
+/**
+ * This method start a download.
+ *
+ * This method start a download.
+ * Can be called from inside a JavaScript function of the HTML page.
+ * Emits the JavascriptInterface::requestFile(const QString) signal.
+ */
+void JavascriptInterfaceFBGUI::startDownload(const QString& filename) {
+ // ignore if empty filename
+ if (filename.isEmpty()) {
+ _targetFrame->evaluateJavaScript("alert(\"No filename!\")");
+ return;
+ }
+ emit requestFile(filename);
+}
+//-------------------------------------------------------------------------------------------------------
+/**
+ * This method start a download.
+ *
+ * This method start a download.
+ * Can be called from inside a JavaScript function of the HTML page.
+ *
+ * @todo add some more informations
+ */
+void JavascriptInterfaceFBGUI::setCallbackOnFinished(const QString& function) {
+ //LOG4CXX_DEBUG(jsiLogger, "Callback set: " << function);
+ _callbackOnDownloadsFinished = QString(function);
+}
+//-------------------------------------------------------------------------------------------------------
+/**
+ * This method delivers system informations.
+ *
+ * This method delivers system informations. Type of informations, are defined by
+ * the parameter. The output of this method depends on the parameter.
+ * Can be called from inside a JavaScript function of the HTML page.
+ *
+ * @param infoName
+ * Is of type QString. Defines which method will be called. Possible values are:
+ * - mac
+ * - ip
+ * - mbserial
+ * - usb
+ *
+ * @return QString
+ * the output of the called method or "info_error" if an error occurred
+ * (e. g. invalid parameter).
+ *
+ * @see SysInfo::getInfo(const QString& infoName)
+ */
+const QString JavascriptInterfaceFBGUI::getSysInfo(const QString& info) {
+ SysInfo si;
+ return si.getInfo(info);
+}
+
+//-------------------------------------------------------------------------------------------------------
+// Download Manager information exchange
+//-------------------------------------------------------------------------------------------------------
+/**
+ * This method delivers some informations about the downloading file.
+ *
+ * This method delivers some informations about the downloading file.
+ *
+ * @todo add some more informations
+ */
+void JavascriptInterfaceFBGUI::downloadInfo(const QString& filename,
+ const double& filesize) {
+ QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(
+ filesize);
+ _targetFrame->evaluateJavaScript(code);
+}
+//-------------------------------------------------------------------------------------------------------
+/**
+ * This method updates the progress bar.
+ *
+ * This method calls a Javascript function to update the progress bar of the download.
+ * Javascript must have a function called "updateProgress" to receive this information.
+ *
+ * @todo add some more informations
+ */
+void JavascriptInterfaceFBGUI::updateProgressBar(const int& percent,
+ const double& speed, const QString& unit) {
+ if (percent == 0)
+ return;
+ QString code = QString("updateProgress(\%1, \%2, '\%3')").arg(percent).arg(
+ speed).arg(unit);
+ _targetFrame->evaluateJavaScript(code);
+}
+//-------------------------------------------------------------------------------------------------------
+/**
+ * Sets a callback function for when downloads are finished (will be called when the queue is empty).
+ */
+void JavascriptInterfaceFBGUI::callbackOnFinished() {
+ QString code = QString("\%1").arg(_callbackOnDownloadsFinished);
+ _targetFrame->evaluateJavaScript(code);
+}