summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fbgui.conf4
-rw-r--r--src/downloadManager.cpp72
-rw-r--r--src/downloadManager.h23
-rw-r--r--src/fbgui.conf3
-rw-r--r--src/fbgui.cpp10
-rw-r--r--src/fbgui.h20
-rw-r--r--src/javascriptInterface.cpp29
-rw-r--r--src/javascriptInterface.h29
-rw-r--r--src/main.cpp47
-rw-r--r--src/sysInfo.h20
10 files changed, 161 insertions, 96 deletions
diff --git a/fbgui.conf b/fbgui.conf
new file mode 100644
index 0000000..58c35e8
--- /dev/null
+++ b/fbgui.conf
@@ -0,0 +1,4 @@
+[default]
+url=http://m.openslx.org
+downloadDirectory=/downloads
+updateInterval=2
diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp
index c15454a..dca99d3 100644
--- a/src/downloadManager.cpp
+++ b/src/downloadManager.cpp
@@ -1,7 +1,5 @@
#include "downloadManager.h"
-//#include <QDir>
#include <QFileInfo>
-#include <QVariant>
#include <QByteArray>
int downloadManager::downloaded = 0;
@@ -10,9 +8,8 @@ downloadManager::downloadManager()
{
qnam = new QNetworkAccessManager();
dip = false;
- // the whole QDir thing is questionable..
downloadDir = QDir(downloadPath);
- // Check if downloadPath exists, if not create it.
+ /* 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);
@@ -26,7 +23,7 @@ void downloadManager::downloadFile(QString& filename){
if (debug) qDebug() << "Received downloadFile signal for:" << filename;
QUrl fileUrl;
fileUrl = baseURL.resolved(QUrl(filename));
- qDebug() << "fileUrl: " << fileUrl;
+ if (debug) qDebug() << "fileUrl: " << fileUrl;
this->processDownloadRequest(fileUrl);
}
// ----------------------------------------------------------------------------------------
@@ -37,13 +34,11 @@ void downloadManager::downloadFile(QUrl& 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 download in progress, enqueue file and return. */
if (dip)
{
if (debug) qDebug() << "Download in progress! Enqueueing:" << url.toString()
@@ -51,7 +46,7 @@ void downloadManager::processDownloadRequest(QUrl& url)
dlQ.enqueue(url);
return;
}
- // No running downloads: enqueue and start next download.
+ /* No running downloads: enqueue and start next download. */
dlQ.enqueue(url);
if (debug) qDebug() << "Enqueueing:" << url.toString() << endl;
startNextDownload();
@@ -69,18 +64,15 @@ void downloadManager::startNextDownload()
if (debug) qDebug() << "Starting next download: " << dlQ.head().toString()
<< "(" << dlQ.size() << "in queue.)";
- // Dequeue next URL to download.
+ /* Dequeue next URL to download. */
QUrl url = dlQ.dequeue();
- // Get temporary filename from URL.
+ /* Get temporary filename from URL. */
QString tmp = url.path();
tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1);
if (debug) qDebug() << "Extracted " << tmp << "from " << url.toString();
- // temp file name will be renamed to the filename parsed from the
- // header ("Content-Disposition" --> filename)
outfile.setFileName(downloadPath + "/" + tmp);
-
if (!outfile.open(QIODevice::WriteOnly))
{
if (debug) qDebug() << "Couldn't open file! Skipping...";
@@ -95,7 +87,7 @@ void downloadManager::startNextDownload()
return;
}
- currentProgress = 0;
+ lastProgress = 0;
dip = true;
QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT(downloadReady()));
QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)),
@@ -103,46 +95,39 @@ void downloadManager::startNextDownload()
QObject::connect(currentDownload, SIGNAL(finished()), this, SLOT(downloadFinished()));
}
// ----------------------------------------------------------------------------------------
-// Private slots
+// Private slots
// ----------------------------------------------------------------------------------------
-// This slot listens to readyRead() emmited when data is available for reading.
void downloadManager::downloadReady()
{
-
- // this is done every signal call atm, to fix...
- const QByteArray cd = "Content-Disposition";
- QByteArray cdc = currentDownload->rawHeader(cd);
- cdc.chop(1);
- int x = cdc.indexOf("filename=\"") + 10;
- cdc.remove(0, x);
- // End file name = cdc.
- currentTargetFilename = cdc;
- // readyRead() fired, so save the readable data.
+ /* Data ready, save it */
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);
+ /* Update progress only if difference higher than the updateInterval setting */
+ int currentProgress = ((bytesIn * 100) / bytesTotal);
+ if (currentProgress - lastProgress > updateInterval){
+ lastProgress = currentProgress;
+ emit updateProgress(currentDownload->url().toString(), currentProgress);
+ if (debug) qDebug() << "Download progress of " << currentDownload->url().toString()
+ << ": " << bytesIn << "/" << bytesTotal << "(" << currentProgress << "\%)";
}
- // 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()
{
- // Close output file.
- outfile.close();
+ /* Header filename fetching & renaming, old-ish
+ const QByteArray cd = "Content-Disposition";
+ QByteArray cdc = currentDownload->rawHeader(cd);
+ int x = cdc.indexOf("filename=\"") + 10;
+ cdc.remove(0, x).chop(1);
+ if (!cdc.isEmpty())
+ currentTargetFilename = cdc;
+ else
+ currentTargetFilename = QString("download.\%1").arg(downloaded);
+
QString tmp = outfile.fileName();
tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1);
qDebug() << "Trying to rename " << tmp << " to --> " << currentTargetFilename;
@@ -153,19 +138,20 @@ void downloadManager::downloadFinished()
else {
if (debug) qDebug() << "Failure to rename file!";
}
+ */
+ outfile.close();
currentDownload->deleteLater();
downloaded++;
dip = false;
if (debug) qDebug() << "Download of " << currentDownload->url().toString()
<< "finished. (dlcount = "<< downloaded << ")";
- // 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
index bf2d341..98381a2 100644
--- a/src/downloadManager.h
+++ b/src/downloadManager.h
@@ -1,3 +1,20 @@
+/*
+# Copyright (c) 2010,2011 - RZ Uni Freiburg
+# Copyright (c) 2010,2011 - OpenSLX Project
+#
+# This program/file is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your feedback to feedback@openslx.org
+#
+# General information about OpenSLX can be found under http://openslx.org
+#
+#
+# Helper class managing downloads.
+#
+*/
+
#ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H
@@ -11,6 +28,7 @@ extern bool debug;
extern QUrl baseURL;
extern QString binPath;
extern QString downloadPath;
+extern int updateInterval;
class downloadManager : public QObject
@@ -22,16 +40,15 @@ public:
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;
+ int lastProgress;
+
static int downloaded;
QString currentTargetFilename;
diff --git a/src/fbgui.conf b/src/fbgui.conf
index 99d7d0e..58c35e8 100644
--- a/src/fbgui.conf
+++ b/src/fbgui.conf
@@ -1,3 +1,4 @@
[default]
-url=http://132.230.4.3/mockup/openslx.php
+url=http://m.openslx.org
downloadDirectory=/downloads
+updateInterval=2
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index 7fc93c8..cd58863 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -14,18 +14,21 @@ QString binPath("");
QString downloadPath(binPath + "/downloads");
QUrl baseURL(DEFAULT_URL);
bool debug = false;
+int updateInterval = DEFAULT_UPDATE_INTERVAL;
//-------------------------------------------------------------------------------------------
fbgui::fbgui()
{
- if (debug) qDebug() << "Application dir path: " << QApplication::applicationDirPath();
+ //grabKeyboard();
- checkHost();
/* Init "browser" */
+ checkHost();
QWebView* webView = new QWebView(this);
webView->load(baseURL);
+
/* Init JavaScript interface */
javascriptInterface* jsi = new javascriptInterface(webView->page()->mainFrame());
QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close()));
+
QObject::connect(webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
jsi, SLOT(attachToDOM()));
/* Init Download Manager */
@@ -33,7 +36,8 @@ fbgui::fbgui()
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()));
- setWindowFlags(Qt::Window);
+
+ setAttribute(Qt::WA_QuitOnClose, true);
showFullScreen();
setCentralWidget(webView);
show();
diff --git a/src/fbgui.h b/src/fbgui.h
index d1f0852..68bb2cf 100644
--- a/src/fbgui.h
+++ b/src/fbgui.h
@@ -1,3 +1,20 @@
+/*
+# Copyright (c) 2010,2011 - RZ Uni Freiburg
+# Copyright (c) 2010,2011 - OpenSLX Project
+#
+# This program/file is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your feedback to feedback@openslx.org
+#
+# General information about OpenSLX can be found under http://openslx.org
+#
+#
+# Main class for the fbgui.
+#
+*/
+
#ifndef FBGUI_H
#define FBGUI_H
@@ -6,11 +23,14 @@
#include <QtWebKit>
#define DEFAULT_URL "http://www.google.com"
+#define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui/downloads"
+#define DEFAULT_UPDATE_INTERVAL 1;
extern QString binPath;
extern QString downloadPath;
extern QUrl baseURL;
extern bool debug;
+extern int updateInterval;
class fbgui : public QMainWindow
{
diff --git a/src/javascriptInterface.cpp b/src/javascriptInterface.cpp
index f8b8ef6..d57ce44 100644
--- a/src/javascriptInterface.cpp
+++ b/src/javascriptInterface.cpp
@@ -1,17 +1,11 @@
-/*
- * jsObject.cpp javascriptInterface
- *
- * Created on: Feb 1, 2011
- * Author: niklas
- */
#include "fbgui.h"
#include "javascriptInterface.h"
#include "sysInfo.h"
-
//-------------------------------------------------------------------------------------------------------
-javascriptInterface::javascriptInterface(QWebFrame *parent) {
- // check for better way to use evaluateJavaScript()
+javascriptInterface::javascriptInterface(QWebFrame *parent)
+{
+ //TODO: check for better way to use evaluateJavaScript()
_parent = parent;
}
//-------------------------------------------------------------------------------------------------------
@@ -26,30 +20,24 @@ QString javascriptInterface::getSysInfo(QString info)
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::attachToDOM()
{
- //_parent->addToJavaScriptWindowObject(QString("jsObject"), this);
_parent->addToJavaScriptWindowObject(QString("fbgui"), this);
}
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::startDownload(QString filename)
{
- /* return if no filename in input field */
- //if (debug) qDebug() << "javascriptInterace: requesting download: " << filename;
- if (filename.isEmpty())
- {
+ /* ignore if empty filename */
+ if (filename.isEmpty()){
_parent->evaluateJavaScript("alert(\"No filename!\")");
return;
}
- //if (debug) qDebug() << "Request download: " << baseURL.resolved(QUrl(filename)).toString();
emit requestFile(filename);
-
}
//-------------------------------------------------------------------------------------------------------
void javascriptInterface::updateProgressBar(QString current, int i)
{
- if (i == 0)
- return;
+ if (i == 0) return;
QString code = QString("updateProgress('\%1', \%2)").arg(current).arg(i);
- qDebug() << "To JS: " << code;
+ if (debug) qDebug() << "To JS: " << code;
_parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
@@ -57,12 +45,13 @@ void javascriptInterface::setCallbackOnDlQueueFinished(QString jsFunction)
{
callBackOnDownloadsFinished = jsFunction;
}
+//-------------------------------------------------------------------------------------------------------
void javascriptInterface::callbackOnDlQueueFinished()
{
QString code = QString("\%1").arg(callBackOnDownloadsFinished);
- qDebug() << "to JS: " << code;
_parent->evaluateJavaScript(code);
}
+//-------------------------------------------------------------------------------------------------------
void javascriptInterface::quit()
{
if (debug) qDebug() << "Quit signal.";
diff --git a/src/javascriptInterface.h b/src/javascriptInterface.h
index d23a6e0..6ee113b 100644
--- a/src/javascriptInterface.h
+++ b/src/javascriptInterface.h
@@ -1,19 +1,25 @@
/*
- * jsObject.h
- *
- * Created on: Feb 1, 2011
- * Author: niklas
- * The purpose of the jsObject class is to provide signals which will be emited in the javascript functions.
- * Those javascript functions are writen in a seperate file: jsFunktions.js
- */
+# Copyright (c) 2010,2011 - RZ Uni Freiburg
+# Copyright (c) 2010,2011 - OpenSLX Project
+#
+# This program/file is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your feedback to feedback@openslx.org
+#
+# General information about OpenSLX can be found under http://openslx.org
+#
+#
+# Interface for javascript.
+#
+*/
#ifndef JAVASCRIPTINTERFACE_H_
#define JAVASCRIPTINTERFACE_H_
-
#include "fbgui.h"
-
class javascriptInterface : public QObject{
Q_OBJECT
private:
@@ -30,11 +36,12 @@ signals:
public slots:
void attachToDOM();
- QString getSysInfo(QString info);
void startDownload(QString filename);
- void updateProgressBar(QString current, int i);
void setCallbackOnDlQueueFinished(QString fctOnDownloadsFinished);
void callbackOnDlQueueFinished();
+ void updateProgressBar(QString current, int i);
+
+ QString getSysInfo(QString info);
void quit();
};
diff --git a/src/main.cpp b/src/main.cpp
index f134d76..8f2b6a5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,12 +22,6 @@ void printHelp()
int main(int argc, char *argv[])
{
-
- /* TEST */
-
-
- /* TEST */
-
QApplication app(argc, argv, QApplication::GuiServer);
app.setOrganizationName("team_projekt_2011");
app.setApplicationName("prebootGUI");
@@ -42,11 +36,12 @@ int main(int argc, char *argv[])
/* Parse cmdline argus. */
QMap<QString, QString> clOpts;
int longIndex = 0;
- static const char *optString = "u:hDd:";
+ static const char *optString = "u:d:c:Dh";
static const struct option longOpts[] =
{
{"url", required_argument, NULL, 'u'},
- {"downloaddir", required_argument, NULL, 'd'},
+ {"download", required_argument, NULL, 'd'},
+ {"config", required_argument, NULL, 'c'},
{"debug", no_argument, NULL, 'D'},
{"help", no_argument, NULL, 'h'}
};
@@ -61,10 +56,12 @@ int main(int argc, char *argv[])
case 'd':
clOpts.insert("downloadDir", optarg);
break;
- case 'D':
+ case 'c':
+ clOpts.insert("configFile", optarg);
+ case 'D':
clOpts.insert("debug", "debug");
break;
- case 'h':
+ case 'h':
clOpts.insert("help", "help");
break;
}
@@ -78,8 +75,27 @@ int main(int argc, char *argv[])
debug = true;
qDebug() << "Debug mode activated.";
}
+ QString configFilePath;
+ QFileInfo confInfo;
+ if (clOpts.contains("configFile"))
+ configFilePath = clOpts.value("configFile");
+ else {
+ confInfo = QFileInfo(QDir::home(), ".fbgui.conf");
+ if (confInfo.exists())
+ configFilePath = confInfo.absoluteFilePath();
+ else {
+ confInfo = QFileInfo(QString("/etc/fbgui.conf"));
+ if (confInfo.exists())
+ configFilePath = QString("/etc/fbgui.conf");
+ else
+ /* temporary */
+ configFilePath = QApplication::applicationDirPath() + "/fbgui.conf";
+ }
+ }
+ if (debug) qDebug() << "Config file is: " << configFilePath;
+
// Read the config file, for now hardcoded expected name.
- QSettings confFileSettings(app.applicationDirPath() + "/fbgui.conf", QSettings::IniFormat);
+ QSettings confFileSettings(configFilePath, QSettings::IniFormat);
confFileSettings.setIniCodec("UTF-8");
if (clOpts.contains("url")) {
@@ -107,13 +123,16 @@ int main(int argc, char *argv[])
}
else
{
- downloadPath = "/downloads"; // Default download dir.
+ downloadPath = DEFAULT_DOWNLOAD_DIR; // Default download dir.
if (debug) qDebug() << "Download directory set by default.";
}
-
if (debug) qDebug() << "Download directory: " << downloadPath;
+ if (confFileSettings.contains("default/updateInterval")){
+ updateInterval = confFileSettings.value("default/updateInterval").toInt();
+ if (debug) qDebug() << "Read updateInterval from confFile: " << updateInterval;
+ }
+
fbgui gui;
- gui.setAttribute(Qt::WA_QuitOnClose, true);
return app.exec();
}
diff --git a/src/sysInfo.h b/src/sysInfo.h
index 936f517..3a6c217 100644
--- a/src/sysInfo.h
+++ b/src/sysInfo.h
@@ -1,5 +1,23 @@
+/*
+# Copyright (c) 2010,2011 - RZ Uni Freiburg
+# Copyright (c) 2010,2011 - OpenSLX Project
+#
+# This program/file is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your feedback to feedback@openslx.org
+#
+# General information about OpenSLX can be found under http://openslx.org
+#
+#
+# Helper class to get system information.
+#
+*/
+
#ifndef SYSINFO_H
#define SYSINFO_H
+
#include "fbgui.h"
#include <qjson/serializer.h>
#include <QVariantMap>
@@ -22,4 +40,4 @@ class sysInfo {
QString getScriptOutput(QString cmd);
};
-#endif // SYSTEMINFO_H
+#endif // SYSTINFO_H