summaryrefslogtreecommitdiffstats
path: root/src/fbbrowser.cpp
diff options
context:
space:
mode:
authorJonathan Bauer2011-01-27 18:18:56 +0100
committerJonathan Bauer2011-01-27 18:18:56 +0100
commitd7b3217e900faf29857abdac39f3d94829c0a50e (patch)
treeff26cdc7bb3c91d280389ddc631b4b380f81d5d4 /src/fbbrowser.cpp
parentremove absolute path from test script .. (diff)
downloadfbgui-d7b3217e900faf29857abdac39f3d94829c0a50e.tar.gz
fbgui-d7b3217e900faf29857abdac39f3d94829c0a50e.tar.xz
fbgui-d7b3217e900faf29857abdac39f3d94829c0a50e.zip
Started the download functionality, imcomplete though...
Diffstat (limited to 'src/fbbrowser.cpp')
-rw-r--r--src/fbbrowser.cpp69
1 files changed, 48 insertions, 21 deletions
diff --git a/src/fbbrowser.cpp b/src/fbbrowser.cpp
index 2e4fee6..4b2b66f 100644
--- a/src/fbbrowser.cpp
+++ b/src/fbbrowser.cpp
@@ -1,11 +1,13 @@
#include "fbbrowser.h"
-#include <QtGui>
+
+#include <QFile>
+#include <QFileInfo>
#include <QtWebKit>
-#include <QApplication>
+// This function is not used at the moment.
+// TODO: Fix function or find another way...
void fbbrowser::httpReqFinished()
{
- // TODO: fix this up..
// This slot listens to readyRead() signal from our QNetworkReply.
qDebug() << "finished() signal emmited!" << endl;
if(reply->error() == QNetworkReply::NoError)
@@ -15,6 +17,29 @@ void fbbrowser::httpReqFinished()
}
}
+void fbbrowser::saveData()
+{
+ QFile outfile(filename);
+ if (!outfile.open(QIODevice::WriteOnly))
+ {
+ qDebug() << "Couldnt open file! exiting...";
+ exit(1);
+ }
+ outfile.write(qiod->readAll());
+ outfile.close();
+}
+
+// This function requires the file name of the file to download.
+void fbbrowser::download(const QString &file)
+{
+ // This function is in developement...
+ QUrl u = baseUrl.resolved(file);
+ req.setUrl(u);
+ rep = manager->get(req);
+ qiod = rep;
+ QObject::connect(rep, SIGNAL(finished()), this, SLOT(saveData()));
+}
+
fbbrowser::fbbrowser(const QUrl & url)
{
view = new QWebView(this);
@@ -22,33 +47,35 @@ fbbrowser::fbbrowser(const QUrl & url)
// Create QNetworkAccessManager which is needed to send/receive requests.
manager = new QNetworkAccessManager(this);
// Create a QNetworkRequest object and set its URL.
- // QNetworkRequest request;
+ //* QNetworkRequest request;
request.setUrl(url);
// Check Internet connection
// Let the manager send the request and receive the reply.
// QNetworkReply *reply = manager->get(request);
- reply = manager->get(request);
- connect(reply, SIGNAL(finished()), this, SLOT(httpReqFinished()));
- //connect(reply, SIGNAL(finished()), this, SLOT());
+ reply = manager->get(request);
+ // connect(reply, SIGNAL(finished()), this, SLOT(httpReqFinished()));
// Check if the reply is an error message.
- qDebug() << "QNetworkReply error code: " << reply->error();
+ qDebug() << "QNetworkReply error code is: " << reply->error();
// TODO: error differentiation
- // reply->error() returns 0 even for invalid URL.
- // A possibility to check for validity, is to listen to readyRead()
- // signal, haven't found a better way yet ...
- //if(reply->error() == QNetworkReply::NoError)
- //{
- // qDebug() << "No error, loading given URL...";
- // view->load(url);
- //}
- //else
- //{
- // qDebug() << "Error occured, loading error page...";
- // view->load(QUrl("qrc:/html/errorPage.html"));
- //}
+ // reply->error() returns 0 even for invalid URL.
+ // A possibility to check for validity, is to listen to readyRead()
+ // signal, haven't found a better way yet ...
+ if(reply->error() == QNetworkReply::NoError)
+ {
+ qDebug() << "No error, loading given URL...";
+ view->load(url);
+ }
+ else
+ {
+ qDebug() << "Error occured, loading error page...";
+ view->load(QUrl("qrc:/html/errorPage.html"));
+ }
+ // This part is just a test call of download()...
+ filename = "test.php";
+ download(filename);
//remove the window decoration
this->setWindowFlags(Qt::SplashScreen);