summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2011-03-08 13:17:12 +0100
committerJonathan Bauer2011-03-08 13:17:12 +0100
commit137022b7f0e2f38f3f517fd34954b3518114c920 (patch)
treeeb7717e8b42f0c2ac618be6eb51fdb7320227639
parentfirst fixes (diff)
downloadfbgui-137022b7f0e2f38f3f517fd34954b3518114c920.tar.gz
fbgui-137022b7f0e2f38f3f517fd34954b3518114c920.tar.xz
fbgui-137022b7f0e2f38f3f517fd34954b3518114c920.zip
first downloadDir fix
-rw-r--r--src/DownloadManager.cpp17
-rw-r--r--src/DownloadManager.h5
-rw-r--r--src/fbgui.conf2
-rw-r--r--src/fbgui.cpp6
-rw-r--r--src/fbgui.h2
-rw-r--r--src/javascriptInterface.cpp1
-rw-r--r--src/main.cpp13
-rwxr-xr-xsrc/testApp.sh2
8 files changed, 34 insertions, 14 deletions
diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp
index ce0e82a..7ab9333 100644
--- a/src/DownloadManager.cpp
+++ b/src/DownloadManager.cpp
@@ -1,4 +1,5 @@
#include "DownloadManager.h"
+//#include <QDir>
int DownloadManager::downloaded = 0;
// ----------------------------------------------------------------------------------------
@@ -46,8 +47,10 @@ void DownloadManager::startNextDownload()
// Get filename from URL.
QString tmp = url.path();
tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1);
- outfile.setFileName(downloadDirectory.path() + "/" + tmp);
- if (debug) qDebug() << "DM: Absolute path: " << downloadDirectory.path() + "/" + tmp;
+ 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() << "DM: Absolute path: " << downloadPath + "/" + tmp;
if (outfile.exists()){
if (debug) qDebug() << "File already exists. Skipping: " << url.toString();
startNextDownload();
@@ -122,4 +125,14 @@ DownloadManager::DownloadManager()
{
qnam = new QNetworkAccessManager();
dip = false;
+ downloadDir = QDir(downloadPath);
+ // Check if downloadPath exists, if not create it.
+ if (!downloadDir.exists()){
+ if (debug) qDebug() << downloadDir.path() << "doesn't exist.";
+ QDir::current().mkdir(downloadPath);
+ }
+ qDebug() << "1";
+ if (downloadDir.exists() && debug) qDebug() << "Created download directory: " << downloadPath;
+
+
}
diff --git a/src/DownloadManager.h b/src/DownloadManager.h
index 3003ad6..136437b 100644
--- a/src/DownloadManager.h
+++ b/src/DownloadManager.h
@@ -3,11 +3,13 @@
#include "fbgui.h"
#include <QObject>
+#include <QDir>
#include <QtNetwork>
extern bool debug;
extern QUrl baseURL;
-extern QDir downloadDirectory;
+extern QString binPath;
+extern QString downloadPath;
class DownloadManager : public QObject
@@ -26,6 +28,7 @@ private:
QNetworkRequest request;
QNetworkReply* currentDownload;
QFile outfile;
+ QDir downloadDir;
// Download-in-progress flag.
bool dip;
static int downloaded;
diff --git a/src/fbgui.conf b/src/fbgui.conf
index f835e84..3de418c 100644
--- a/src/fbgui.conf
+++ b/src/fbgui.conf
@@ -1,3 +1,3 @@
[default]
url=http://132.230.4.3/test.html
-downloadDirectory=./downloads/
+downloadDirectory=./downloads
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index f3fd320..6673d22 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -8,13 +8,15 @@
#include <QtWebKit>
#include <QApplication>
-
+// Note: Absolute paths.
+QString binPath(QApplication::applicationDirPath());
+QString downloadPath(binPath + "/downloads");
QUrl baseURL(DEFAULT_URL);
-QDir downloadDirectory("./downloads/");
bool debug = false;
fbgui::fbgui(QApplication *parent)
{
+ qDebug() << "Application dir path: " << QApplication::applicationDirPath();
/* Browser init. */
QWebView* webView = new QWebView(this);
webView->load(baseURL);
diff --git a/src/fbgui.h b/src/fbgui.h
index fe5242b..a413084 100644
--- a/src/fbgui.h
+++ b/src/fbgui.h
@@ -8,8 +8,8 @@
#define DEFAULT_URL "http://www.google.com"
extern QString binPath;
+extern QString downloadPath;
extern QUrl baseURL;
-extern QDir downloadDirectory;
extern bool debug;
class fbgui : public QMainWindow
diff --git a/src/javascriptInterface.cpp b/src/javascriptInterface.cpp
index e93d325..2808dda 100644
--- a/src/javascriptInterface.cpp
+++ b/src/javascriptInterface.cpp
@@ -35,6 +35,7 @@ void javascriptInterface::attachToDOM()
void javascriptInterface::startDownload(QString filename)
{
/* return if no filename in input field */
+ if (debug) qDebug() << "javascriptInterace: requesting download: " << filename;
if (filename.isEmpty())
{
_parent->evaluateJavaScript("alert(\"No filename!\")");
diff --git a/src/main.cpp b/src/main.cpp
index 6f3d283..bd7abb7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -84,17 +84,18 @@ int main(int argc, char *argv[])
else
baseURL = DEFAULT_URL;
+ // Setting downloads target directory.
if (clo.contains("downloadDir")){
- downloadDirectory = QDir(clo.value("downloadDir"));
- if (debug) qDebug() << "downloadDir set to: " << clo.value("downloadDir");
+ downloadPath = binPath + clo.value("downloadDir");
+ if (debug) qDebug() << "clo set downloadDir to: " << binPath + clo.value("downloadDir");
}
else if (confFileSettings.contains("default/downloadDirectory")){
- downloadDirectory = QDir(confFileSettings.value("default/downloadDirectory").toString());
- if (debug) qDebug() << "downloadDir set to: " << confFileSettings.value("default/downloadDirectory").toString();
+ downloadPath = binPath + confFileSettings.value("default/downloadDirectory").toString();
+ if (debug) qDebug() << "conf set downloadDir to: " << binPath + confFileSettings.value("default/downloadDirectory").toString();
}
else
- downloadDirectory = QDir(".");
- if (debug) qDebug() << "Downloads will be saved to: " << downloadDirectory.dirName();
+ downloadPath = binPath + "/downloads";
+ if (debug) qDebug() << "Downloads will be saved to: " << downloadPath;
// Start fbgui.
fbgui gui(&app);
gui.show();
diff --git a/src/testApp.sh b/src/testApp.sh
index 7ff12a4..c9fd5b7 100755
--- a/src/testApp.sh
+++ b/src/testApp.sh
@@ -17,7 +17,7 @@ display_id=$(grep -n $(whoami) /etc/passwd| head -n 1|awk -F : '{print $1}')
/usr/local/Trolltech/Qt-4.7.1/bin/qvfb -width 800 -height 600 -qwsdisplay :$display_id &
sleep 0.1
# Start fbgui.
-$working_path/fbgui -display QVFb:$display_id -D -u $url -d ./downdir/
+$working_path/fbgui -display QVFb:$display_id -D -u $url -d ./downdir
# Check if fbbrowser is not running, if so kill the qvfb.
if [ $(ps aux | grep -v grep | grep -c fbgui) -eq 1 ]
then