summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonathan Bauer2011-03-04 21:05:12 +0100
committerJonathan Bauer2011-03-04 21:05:12 +0100
commit9e5705b50b1187807e753888aebdbbb11b362bcb (patch)
tree33b803d07841411718cca8686b16216de8bd092b /src
parentAdded javascript functionality for download manager.. (diff)
downloadfbgui-9e5705b50b1187807e753888aebdbbb11b362bcb.tar.gz
fbgui-9e5705b50b1187807e753888aebdbbb11b362bcb.tar.xz
fbgui-9e5705b50b1187807e753888aebdbbb11b362bcb.zip
Progress bar for downloads (using jQuery) fixed
Diffstat (limited to 'src')
-rw-r--r--src/DownloadManager.cpp9
-rw-r--r--src/DownloadManager.h4
-rw-r--r--src/fbbrowser.cpp42
-rw-r--r--src/fbbrowser.h9
-rw-r--r--src/fbgui.cpp11
-rw-r--r--src/jsObject.h2
6 files changed, 48 insertions, 29 deletions
diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp
index b637994..b61b171 100644
--- a/src/DownloadManager.cpp
+++ b/src/DownloadManager.cpp
@@ -58,7 +58,7 @@ void DownloadManager::startNextDownload()
}
// Start the request for this URL.
QNetworkRequest request(url);
- currentDownload = (*qnam).get(request);
+ currentDownload = qnam->get(request);
QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT(downloadReady()));
QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)),
this, SLOT(downloadProgress(qint64, qint64)));
@@ -80,6 +80,10 @@ void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
{
qDebug() << "Download progress of " << currentDownload->url().toString()
<< ": " << bytesIn << "/" << bytesTotal;
+
+ qint64 tmp = ((bytesIn * 100) / bytesTotal);
+ emit updateProgress((int)tmp);
+ qDebug() << "progress in is: " << tmp << "(" << (int)tmp << ")";
}
// ----------------------------------------------------------------------------------------
// This slot listens to the finished() which is emmited
@@ -100,6 +104,8 @@ void DownloadManager::downloadFinished()
currentDownload->deleteLater();
// Initialise next download.
dip = false;
+ ++downloaded;
+ // qDebug() << "DM downloaded " << downloaded << "files";
startNextDownload();
}
// ----------------------------------------------------------------------------------------
@@ -110,6 +116,7 @@ DownloadManager::DownloadManager(const QUrl& baseUrl)
this->qnam = new QNetworkAccessManager();
this->baseUrl = baseUrl;
dip = false;
+ downloaded = 0;
}
// Destructor.
DownloadManager::~DownloadManager()
diff --git a/src/DownloadManager.h b/src/DownloadManager.h
index 12b94e1..b11e6b1 100644
--- a/src/DownloadManager.h
+++ b/src/DownloadManager.h
@@ -2,6 +2,7 @@
#define DOWNLOADMANAGER_H
#include "fbbrowser.h"
+#include <QObject>
#include <QtWebKit>
class DownloadManager : public QObject
@@ -12,6 +13,7 @@ public:
DownloadManager(const QUrl& baseUrl);
~DownloadManager();
void processDownloadRequest(QString& filename);
+ int downloaded;
private:
// Object required for downloading.
@@ -25,8 +27,10 @@ private:
// Download-in-progress flag.
bool dip;
+
signals:
void finished();
+ void updateProgress(int i);
public slots:
void downloadFile(QString name);
diff --git a/src/fbbrowser.cpp b/src/fbbrowser.cpp
index 262c68f..4deca61 100644
--- a/src/fbbrowser.cpp
+++ b/src/fbbrowser.cpp
@@ -1,4 +1,5 @@
#include "fbbrowser.h"
+#include "DownloadManager.h"
#include <QFile>
#include <QFileInfo>
@@ -32,15 +33,10 @@ fbbrowser::fbbrowser(const QUrl & url)
qDebug() << "Error occured, loading error page...";
view->load(QUrl("qrc:/html/errorPage.html"));
}
- // **** TEST ****
- DownloadManager* dm = new DownloadManager(baseUrl);
- QObject::connect(this, SIGNAL(downloadFile(QString)), dm, SLOT(downloadFile(QString)));
- //emit downloadFile(QString("test.php"));
- //emit downloadFile(QString("blacklist.txt"));
- //emit downloadFile(QString("whitelist.tar.gz"));
- qDebug() << "DM blocking app?";
- // **** TEST ****
+ // Initialize Download Manager.
+ dm = new DownloadManager(baseUrl);
+ QObject::connect(this, SIGNAL(downloadFile(QString)), dm, SLOT(downloadFile(QString)));
//remove the window decoration
this->setWindowFlags(Qt::SplashScreen);
@@ -72,7 +68,7 @@ void fbbrowser::addJSObject()
void fbbrowser::connectJsSignalsToSlots()
{
QObject::connect(jso, SIGNAL(closeBrowser()), this, SLOT(quitAll()));
- QObject::connect(jso, SIGNAL(startDownload()), this, SLOT(startDownload_Slot()));
+ QObject::connect(jso, SIGNAL(startDownload(QString)), this, SLOT(startDownload_Slot(QString)));
QObject::connect(jso, SIGNAL(getMacAddress()), this, SLOT(getMacAddress_Slot()));
QObject::connect(jso, SIGNAL(getIpAddress()), this, SLOT(getIpAddress_Slot()));
QObject::connect(jso, SIGNAL(getIntegratedHardwareDevices()), this, SLOT(getIntegratedHardwareDevices_Slot()));
@@ -83,8 +79,15 @@ void fbbrowser::connectJsSignalsToSlots()
QObject::connect(jso, SIGNAL(showTime()), this, SLOT(showTime_Slot()));
QObject::connect(jso, SIGNAL(showDate()), this, SLOT(showDate_Slot()));
QObject::connect(jso, SIGNAL(showHelloWorld()), this, SLOT(showHelloWorld_Slot()));
+ // further tests
+ QObject::connect(dm, SIGNAL(updateProgress(int)), this, SLOT(updateProgressSlot(int)));
+}
+//
+void fbbrowser::updateProgressSlot(int i)
+{
+ QString code = QString("updateProgress(\%1\)").arg(i);
+ view->page()->mainFrame()->evaluateJavaScript(code);
}
-
void fbbrowser::writeText(QString text)
{
QFile file("out.txt");
@@ -101,16 +104,14 @@ void fbbrowser::quitAll()
emit signalQuitAll();
}
-void fbbrowser::startDownload_Slot()
+
+void fbbrowser::startDownload_Slot(QString filename)
{
- QString code;
- code = QString("downloadFile()");
- QVariant returnValue;
- returnValue = view->page()->mainFrame()->evaluateJavaScript("downloadFile()");
- QString tmp = returnValue.toString();
- qDebug() << "Returned from JS: " << returnValue.toString();
+
+ qDebug() << "Returned from JS: " << filename;
// Start download.
- emit downloadFile(returnValue.toString());
+ emit downloadFile(filename);
+
}
void fbbrowser::getMacAddress_Slot()
@@ -178,9 +179,8 @@ void fbbrowser::showHelloWorld_Slot()
view->page()->mainFrame()->evaluateJavaScript("alert(\"Hello World\")");
}
-void fbbrowser::getSysInfo()
-{
- /*
+void fbbrowser::getSysInfo(){
+/*
QString time = QTime::currentTime().toString("hh:mm:ss");
QString date = QDate::currentDate().toString("dd.MM.yyyy");
QList<QHostAddress> ipList = QNetworkInterface::allAddresses();
diff --git a/src/fbbrowser.h b/src/fbbrowser.h
index 967c6e0..e349b98 100644
--- a/src/fbbrowser.h
+++ b/src/fbbrowser.h
@@ -2,6 +2,7 @@
#define FBBROWSER_H
#include "DownloadManager.h"
+
#include "jsObject.h"
#include <QString>
#include <QtGui>
@@ -12,6 +13,8 @@ class QWebView;
//class QLineEdit;
//QT_END_NAMESPACE
+class DownloadManager;
+
class fbbrowser : public QMainWindow
{
Q_OBJECT
@@ -31,14 +34,16 @@ private:
// Temporal stuff for the download function...
// Private download function.
- void download(const QString & file);
//the jsObject. connection to the webpage for emiting signals
jsObject *jso;
+ DownloadManager* dm;
// connects all jsObject signals with fbbrowser slots
void connectJsSignalsToSlots();
+public slots:
+ void updateProgressSlot(int i);
private slots:
void addJSObject();
@@ -47,7 +52,7 @@ private slots:
// slots which are emited by the jsObject signals
void quitAll();
- void startDownload_Slot();
+ void startDownload_Slot(QString filename);
void getMacAddress_Slot();
void getIpAddress_Slot();
void getIntegratedHardwareDevices_Slot();
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index 05a3cd2..f3a77c1 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -1,11 +1,12 @@
+#include "fbgui.h"
#include "fbbrowser.h"
#include "DownloadManager.h"
+#include "DMThread.h"
#include <getopt.h>
-#include <fbgui.h>
#include <limits.h>
#include <unistd.h>
#include <QApplication>
-
+#include <QThread>
void printUsage()
{
@@ -62,12 +63,14 @@ int main(int argc, char *argv[])
else //Default URL to load
url = QUrl("http://132.230.4.3/webkitTest.html");
// Create a new Framebuffer-Browser object for displaying the given URL.
- fbbrowser *fbb = new fbbrowser(url);
+ fbbrowser* fbb = new fbbrowser(url);
+
// Listen to the signalQuitAll() Signal to kill the app from within the browser.
QObject::connect(fbb, SIGNAL(signalQuitAll()), &a, SLOT(quit()));
+
// Display the browser.
fbb->show();
- // Exit the application.
+ // Execute the application.
return a.exec();
}
diff --git a/src/jsObject.h b/src/jsObject.h
index 50a7d8c..a58594f 100644
--- a/src/jsObject.h
+++ b/src/jsObject.h
@@ -46,7 +46,7 @@ signals:
// Will close the browser and continues the boot sequenze
void closeBrowser();
// will start the download of all needed files for the following boot sequence
- void startDownload();
+ void startDownload(QString filename);
// starts the slot which is responsible for extracting the MAC address of the machine
// the MAC Address will be the parameter of a javascript function which will present it on the webpage