summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/downloadManager.cpp154
-rw-r--r--src/downloadManager.h52
-rw-r--r--src/fbgui.conf2
-rw-r--r--src/fbgui_libs.tar.gzbin0 -> 13253479 bytes
-rw-r--r--src/sysInfo.cpp12
-rw-r--r--src/sysInfo.h1
-rw-r--r--src/t12/initramfsbin0 -> 6077072 bytes
-rw-r--r--src/t12/kernelbin0 -> 4173024 bytes
-rw-r--r--src/t123/initramfsbin0 -> 6077072 bytes
-rw-r--r--src/t123/kernelbin0 -> 4173024 bytes
10 files changed, 219 insertions, 2 deletions
diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp
new file mode 100644
index 0000000..c437710
--- /dev/null
+++ b/src/downloadManager.cpp
@@ -0,0 +1,154 @@
+#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
new file mode 100644
index 0000000..461d31a
--- /dev/null
+++ b/src/downloadManager.h
@@ -0,0 +1,52 @@
+#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.conf b/src/fbgui.conf
index 2319dbd..99d7d0e 100644
--- a/src/fbgui.conf
+++ b/src/fbgui.conf
@@ -1,3 +1,3 @@
[default]
-url=http://132.230.4.3/test.html
+url=http://132.230.4.3/mockup/openslx.php
downloadDirectory=/downloads
diff --git a/src/fbgui_libs.tar.gz b/src/fbgui_libs.tar.gz
new file mode 100644
index 0000000..44bcac0
--- /dev/null
+++ b/src/fbgui_libs.tar.gz
Binary files differ
diff --git a/src/sysInfo.cpp b/src/sysInfo.cpp
index 19117a5..4cf7d0e 100644
--- a/src/sysInfo.cpp
+++ b/src/sysInfo.cpp
@@ -21,6 +21,8 @@ QString sysInfo::getInfo(QString& infoName){
return getMACAddress();
else if (infoName == QString("ip"))
return getIPAddress();
+ else if (infoName == QString("all"))
+ return getAllInfos();
// still here?
return "info_error";
}
@@ -43,11 +45,13 @@ QString sysInfo::getIPAddress(){
QList<QHostAddress> addrlist = qni.allAddresses();
// This is does not return the right IP atm...
foreach(QHostAddress addr, addrlist){
- if (addr.protocol() == QAbstractSocket::IPv4Protocol)
+ if (addr.protocol() == QAbstractSocket::IPv4Protocol && addr != QHostAddress::LocalHost){
qDebug() << "eth0: IPv4 Address: " << addr.toString();
return addr.toString();
+ }
}
// still here?
+ qDebug() << "ip_error";
return "ip_error";
}
QByteArray sysInfo::getNames(){
@@ -69,4 +73,10 @@ QByteArray sysInfo::getNames(){
qDebug() << json;
return json;
+
+// ------------------------------------------------------------------------------------------------
+QString sysInfo::getAllInfos(){
+ QString tmp = "\"mac\":\"" + getMACAddress() + "\", \"ip\":\"" + getIPAddress() +"\"";
+
+ return tmp;
}
diff --git a/src/sysInfo.h b/src/sysInfo.h
index 3cd01b8..7ed4d71 100644
--- a/src/sysInfo.h
+++ b/src/sysInfo.h
@@ -18,6 +18,7 @@ class sysInfo {
QByteArray getNames();
QString getMACAddress();
QString getIPAddress();
+ QString getAllInfos();
};
#endif // SYSTEMINFO_H
diff --git a/src/t12/initramfs b/src/t12/initramfs
new file mode 100644
index 0000000..2737ebf
--- /dev/null
+++ b/src/t12/initramfs
Binary files differ
diff --git a/src/t12/kernel b/src/t12/kernel
new file mode 100644
index 0000000..c2b9070
--- /dev/null
+++ b/src/t12/kernel
Binary files differ
diff --git a/src/t123/initramfs b/src/t123/initramfs
new file mode 100644
index 0000000..2737ebf
--- /dev/null
+++ b/src/t123/initramfs
Binary files differ
diff --git a/src/t123/kernel b/src/t123/kernel
new file mode 100644
index 0000000..c2b9070
--- /dev/null
+++ b/src/t123/kernel
Binary files differ