summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/downloadmanager.cpp24
-rw-r--r--src/downloadmanager.h5
-rw-r--r--src/fbgui.cpp21
-rw-r--r--src/fbgui.qrc1
4 files changed, 29 insertions, 22 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index eb00354..9faad88 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -6,10 +6,13 @@ int DownloadManager::downloaded = 0;
DownloadManager::DownloadManager(){
qxtLog->debug() << "Initializing download manager...";
checkDownloadDirectory();
- qnam = new QNetworkAccessManager();
- qnam->moveToThread(&dmThread);
+ _qnam = new QNetworkAccessManager();
+ //_qnam->moveToThread(&dmThread);
dip = false;
}
+DownloadManager::~DownloadManager(){
+ delete _qnam;
+}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::checkDownloadDirectory()
{
@@ -66,7 +69,7 @@ void DownloadManager::processDownloadRequest(const QUrl& url)
qxtLog->debug() << "[dm] No URL specified for download.";
return;
}
- qxtLog->debug() << "[dm] Enqueueing:" << url.toString();
+ qxtLog->debug() << "[dm] Enqueueing: " << url.toString();
dlQ.enqueue(url);
if (dip){
// download in progress, return.
@@ -112,11 +115,11 @@ void DownloadManager::startNextDownload()
// send the request for the file
QNetworkRequest request(url);
- currentDownload = qnam->get(request);
+ currentDownload = _qnam->get(request);
lastProgress = 0;
currentProgress = 0;
dip = true;
- dltime.start();
+ _time.start();
QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT(downloadReady()));
QObject::connect(currentDownload, SIGNAL(metaDataChanged()), this, SLOT(processMetaInfo()));
QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)),
@@ -132,7 +135,8 @@ void DownloadManager::processMetaInfo()
const QByteArray cltag = "Content-Length";
QByteArray clinfo = currentDownload->rawHeader(cltag);
QFileInfo fi(outfile);
- emit downloadInfo(outfile.fileName(), clinfo.toDouble());
+ qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble() << ")";
+ emit downloadInfo(fi.fileName(), clinfo.toDouble());
}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadReady()
@@ -143,9 +147,13 @@ void DownloadManager::downloadReady()
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
{
- if (bytesIn > bytesTotal) return;
+ if (bytesIn > bytesTotal || bytesTotal <= 0){
+ qxtLog->debug() << "[dm] downloadProgress invalid values:"
+ << "In:" << bytesIn << " / Total: " << bytesTotal;
+ return;
+ }
// calculate current speed
- double speed = bytesIn * 1000 / dltime.elapsed();
+ double speed = bytesIn * 1000 / _time.elapsed();
QString unit;
if (speed < 1024){
unit = "bytes/sec";
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index 1b7d8af..44194d3 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -36,6 +36,8 @@ class DownloadManager : public QObject
public:
DownloadManager();
+ ~DownloadManager();
+ QTime _time;
private:
// checks for valid download directory, ran once in constructor
@@ -44,13 +46,12 @@ private:
void processDownloadRequest(const QUrl& url);
// base objects for downloading
- QNetworkAccessManager* qnam;
+ QNetworkAccessManager* _qnam;
QQueue<QUrl> dlQ;
QNetworkReply* currentDownload;
QFile outfile;
QDir downloadDir;
// download progress variables
- QTime dltime;
int currentProgress, lastProgress;
// download in progress flag
bool dip;
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index 4dbbc58..d991556 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -10,7 +10,7 @@
#include <QtWebKit>
#include <QxtCore>
-QThread dmThread;
+//QThread dmThread;
QString binPath("");
QUrl baseURL("");
QString downloadPath("");
@@ -65,10 +65,11 @@ fbgui::fbgui()
QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished()));
// move download manager to its own thread
- dm->moveToThread(&dmThread);
- dmThread.start();
+ //dm->moveToThread(&dmThread);
+ //dmThread.start();
- // show filler page
+ //_webView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar);
+ // show page
_webView->load(QUrl("qrc:/html/preload.html"));
// start watching for fileToTriggerURL
watchForTrigger();
@@ -81,7 +82,7 @@ fbgui::fbgui()
showFullScreen();
}
fbgui::~fbgui(){
- dmThread.quit();
+ //dmThread.quit();
}
//-------------------------------------------------------------------------------------------
// Layout / actions setup
@@ -140,7 +141,7 @@ void fbgui::watchForTrigger()
if (file.exists()){
qxtLog->debug() << "[watcher] " << fileToTriggerURL << " exists already!";
// try to load URL
- if (checkHost()) loadURL();
+ loadURL();
}
else {
// create it
@@ -179,7 +180,7 @@ void fbgui::prepareURLLoad()
_watcher->disconnect(this);
_watcher->deleteLater();
// try to load URL
- if (checkHost()) loadURL();
+ loadURL();
}
//-------------------------------------------------------------------------------------------
// Preparations for URL load
@@ -254,7 +255,6 @@ QByteArray fbgui::generatePOSTData()
QFile file(serialLocation);
if (!file.open(QIODevice::ReadOnly)){
qxtLog->debug() << "[post] No such file: " << file.fileName();
- serial = "10-23-43-55-67"; // tests
}
// everything ok, read data
serial = file.readAll();
@@ -296,8 +296,5 @@ void fbgui::createDebugConsole()
//-------------------------------------------------------------------------------------------
void fbgui::toggleDebugConsole()
{
- if (_debugConsole->isVisible())
- _debugConsole->hide();
- else
- _debugConsole->show();
+ (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show();
}
diff --git a/src/fbgui.qrc b/src/fbgui.qrc
index bb25211..10a8bd6 100644
--- a/src/fbgui.qrc
+++ b/src/fbgui.qrc
@@ -7,5 +7,6 @@
<file>html/style.css</file>
<file>html/preload.html</file>
<file>html/bg.png</file>
+ <file>html/preload-debug.html</file>
</qresource>
</RCC>