summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DownloadManager.cpp154
-rw-r--r--src/DownloadManager.h53
-rw-r--r--src/fbgui.cpp4
-rw-r--r--src/fbgui.pro11
-rw-r--r--src/main.cpp6
-rw-r--r--src/sysInfo.cpp23
-rw-r--r--src/sysInfo.h6
7 files changed, 44 insertions, 213 deletions
diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp
deleted file mode 100644
index 5c2b123..0000000
--- a/src/DownloadManager.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-#include "DownloadManager.h"
-//#include <QDir>
-#include <QFileInfo>
-
-int DownloadManager::downloaded = 0;
-// ----------------------------------------------------------------------------------------
-DownloadManager::DownloadManager()
-{
- qnam = new QNetworkAccessManager();
- dip = false;
- // the whole QDir thing is questionable..
- downloadDir = QDir(downloadPath);
- // Check if downloadPath exists, if not create it.
- if (!downloadDir.exists()){
- if (debug) qDebug() << "Download directory: " << downloadDir.path() << "doesn't exist.";
- QDir::current().mkdir(downloadPath);
- if (downloadDir.exists() && debug)
- qDebug() << "Created download directory: " << downloadDir.path();
- }
- else if (debug) qDebug() << "Download directory: " << downloadDir.path() << "exists.";
-}
-// ----------------------------------------------------------------------------------------
-void DownloadManager::downloadFile(QString& filename){
- if (debug) qDebug() << "DM received signal for: " << filename;
- QUrl fileUrl;
- fileUrl = baseURL.resolved(QUrl(filename));
- this->processDownloadRequest(fileUrl);
-}
-// ----------------------------------------------------------------------------------------
-void DownloadManager::downloadFile(QUrl& fileUrl){
- if (debug) qDebug() << "Received downloadFile signal for:" << fileUrl;
- this->processDownloadRequest(fileUrl);
-}
-// ----------------------------------------------------------------------------------------
-void DownloadManager::processDownloadRequest(QUrl& url)
-{
- // Test on empty URL in case such a call happens, which should not
- // happen given how javascriptInterface::startDownload(..) is implemented.
- if (url.isEmpty()){
- if (debug) qDebug() << "No URL specified for download.";
- return;
- }
- // If download in progress, enqueue file and return.
- if (dip)
- {
- if (debug) qDebug() << "Download in progress! Enqueueing:" << url.toString()
- << "(" << dlQ.size() << "in queue)";
- dlQ.enqueue(url);
- return;
- }
- // No running downloads: enqueue and start next download.
- dlQ.enqueue(url);
- if (debug) qDebug() << "Enqueueing:" << url.toString() << endl;
- startNextDownload();
-}
-// ----------------------------------------------------------------------------------------
-void DownloadManager::startNextDownload()
-{
- if (dlQ.isEmpty())
- {
- emit downloadQueueEmpty();
- if (debug) qDebug() << "Download manager ready. (1)";
- return;
- }
- if (debug) qDebug() << "Starting next download: " << dlQ.head().toString()
- << "(" << dlQ.size() << "in queue.)";
- // Dequeue next URL to download.
- QUrl url = dlQ.dequeue();
-
- // Get filename from URL.
- QString tmp = url.path();
- tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1);
- if (debug) qDebug() << "Extracted " << tmp << "from " << url.toString();
- // TODO: check for if relative path, if so prepend binPath
- outfile.setFileName(downloadPath + "/" + tmp);
- if (debug) qDebug() << "Trying to save to: " << downloadPath + "/" + tmp;
- if (outfile.exists()){
- if (debug) qDebug() << "File already exists. Skipping: " << url.toString();
- startNextDownload();
- return;
- }
- // If error upon opening, skip this file.
- if (!outfile.open(QIODevice::WriteOnly))
- {
- if (debug) qDebug() << "Couldn't open file! Skipping: " << url.toString();
- startNextDownload();
- return;
- }
- // Start the request for this URL.
- if (debug) qDebug() << "Saving " << url.toString() << "to " << outfile.fileName();
- QNetworkRequest request(url);
- currentDownload = qnam->get(request);
- // TODO: Error handling not working properly...
- if (currentDownload->error() != QNetworkReply::NoError)
- {
- if (debug) qDebug() << "Network reply error, skipping download...";
- return;
- }
- dip = true;
- currentProgress = 0;
- QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT(downloadReady()));
- QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)),
- this, SLOT(downloadProgress(qint64, qint64)));
- QObject::connect(currentDownload, SIGNAL(finished()), this, SLOT(downloadFinished()));
-}
-// ----------------------------------------------------------------------------------------
-// Private slots
-// ----------------------------------------------------------------------------------------
-// This slot listens to readyRead() emmited when data is available for reading.
-void DownloadManager::downloadReady()
-{
- // readyRead() fired, so save the readable data.
- outfile.write(currentDownload->readAll());
-}
-// ----------------------------------------------------------------------------------------
-// This triggers sends the update progress back to the site.
-void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
-{
-
- if (debug) qDebug() << "Download progress of " << currentDownload->url().toString()
- << ": " << bytesIn << "/" << bytesTotal;
-
- int tmp = ((bytesIn * 100) / bytesTotal);
- if (tmp > currentProgress){
- currentProgress = tmp;
- emit updateProgress(currentDownload->url().toString(), tmp);
- }
- // Progress difference < 1%
- return;
-}
-// ----------------------------------------------------------------------------------------
-// This slot listens to the finished() which is emmited
-// when all the data from the reply has been read.
-void DownloadManager::downloadFinished()
-{
- // Second check if the download actually is finished just to be sure.
- if (currentDownload->isFinished())
- if (debug) qDebug() << "Download of " << currentDownload->url().toString()
- << "finished." << endl;
- // Close output file.
- outfile.close();
- currentDownload->deleteLater();
- downloaded++;
- dip = false;
- // If queue is empty, we are done.
- if (dlQ.isEmpty()){
- emit downloadQueueEmpty();
- if (debug) qDebug() << "Download manager ready. (2)";
- return;
- }
- // Queue not empty: initialise next download.
- startNextDownload();
-}
-
diff --git a/src/DownloadManager.h b/src/DownloadManager.h
deleted file mode 100644
index 7b5a3c1..0000000
--- a/src/DownloadManager.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef DOWNLOADMANAGER_H
-#define DOWNLOADMANAGER_H
-
-#include "fbgui.h"
-#include <QObject>
-#include <QDir>
-#include <QtNetwork>
-
-extern bool debug;
-extern QUrl baseURL;
-extern QString binPath;
-extern QString downloadPath;
-
-
-class DownloadManager : public QObject
-{
- Q_OBJECT
-
-public:
- DownloadManager();
-
-
-private:
- void processDownloadRequest(QUrl& url);
- // Object required for downloading.
- QNetworkAccessManager* qnam;
- QQueue<QUrl> dlQ;
- QNetworkRequest request;
- QNetworkReply* currentDownload;
- QFile outfile;
- QDir downloadDir;
- // Download-in-progress flag.
- bool dip;
- int currentProgress;
- static int downloaded;
-
-signals:
- void finished();
- void updateProgress(QString current, int i);
- void downloadQueueEmpty();
-
-public slots:
- void downloadFile(QUrl& fileUrl);
- void downloadFile(QString& fileUrl);
-
-private slots:
- void startNextDownload();
- void downloadReady();
- void downloadProgress(qint64 bytesIn, qint64 bytesTotal);
- void downloadFinished();
-};
-
-#endif // DOWNLOADMANAGER_H
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index dc1891c..7fc93c8 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -1,5 +1,5 @@
#include "fbgui.h"
-#include "DownloadManager.h"
+#include "downloadManager.h"
#include "javascriptInterface.h"
#include <iostream>
@@ -29,7 +29,7 @@ fbgui::fbgui()
QObject::connect(webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
jsi, SLOT(attachToDOM()));
/* Init Download Manager */
- DownloadManager* dm = new DownloadManager();
+ downloadManager* dm = new downloadManager();
QObject::connect(jsi, SIGNAL(requestFile(QString&)), dm, SLOT(downloadFile(QString&)));
QObject::connect(dm, SIGNAL(updateProgress(QString, int)), jsi, SLOT(updateProgressBar(QString, int)));
QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnDlQueueFinished()));
diff --git a/src/fbgui.pro b/src/fbgui.pro
index ad6c6fd..2fdaf93 100644
--- a/src/fbgui.pro
+++ b/src/fbgui.pro
@@ -2,18 +2,21 @@ TEMPLATE = app
TARGET = fbgui
CONFIG += qt \
debug
+LIBS += -L/usr/local/qjson/lib \
+ -lqjson
+INCLUDEPATH += -I/usr/local/qjson/include
QT += core \
gui \
webkit \
network
-HEADERS += fbgui.h \
+HEADERS += downloadManager.h \
+ fbgui.h \
javascriptInterface.h \
- DownloadManager.h \
sysInfo.h
-SOURCES += main.cpp \
+SOURCES += downloadManager.cpp \
+ main.cpp \
fbgui.cpp \
javascriptInterface.cpp \
- DownloadManager.cpp \
sysInfo.cpp
FORMS +=
RESOURCES += fbgui.qrc
diff --git a/src/main.cpp b/src/main.cpp
index b53f25e..f134d76 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,6 +22,12 @@ void printHelp()
int main(int argc, char *argv[])
{
+
+ /* TEST */
+
+
+ /* TEST */
+
QApplication app(argc, argv, QApplication::GuiServer);
app.setOrganizationName("team_projekt_2011");
app.setApplicationName("prebootGUI");
diff --git a/src/sysInfo.cpp b/src/sysInfo.cpp
index 8da1c46..19117a5 100644
--- a/src/sysInfo.cpp
+++ b/src/sysInfo.cpp
@@ -2,6 +2,9 @@
#include <QString>
#include <QTime>
#include <QNetworkInterface>
+#include <QVariantMap>
+#include <QVariantList>
+#include <QByteArray>
//static int eth0_index = 0;
// ------------------------------------------------------------------------------------------------
@@ -47,3 +50,23 @@ QString sysInfo::getIPAddress(){
// still here?
return "ip_error";
}
+QByteArray sysInfo::getNames(){
+
+ QVariantMap foo;
+ foo.insert("name", "foo");
+ foo.insert("type", 123);
+
+ QVariantMap fooo;
+ fooo.insert("name", "boo");
+ fooo.insert("type", 321);
+
+ QVariantList jsonV;
+ jsonV << foo << fooo;
+
+ QJson::Serializer serializer;
+ QByteArray json = serializer.serialize(jsonV);
+
+ qDebug() << json;
+ return json;
+
+}
diff --git a/src/sysInfo.h b/src/sysInfo.h
index 86443b8..3cd01b8 100644
--- a/src/sysInfo.h
+++ b/src/sysInfo.h
@@ -1,6 +1,8 @@
#ifndef SYSINFO_H
#define SYSINFO_H
#include "fbgui.h"
+#include <qjson/serializer.h>
+#include <QVariantMap>
#include <QString>
class sysInfo {
@@ -10,6 +12,10 @@ class sysInfo {
QString getInfo(QString& infoName);
private:
+ QJson::Serializer serializer;
+
+
+ QByteArray getNames();
QString getMACAddress();
QString getIPAddress();
};