Allow surfing, download and extract only .zip files
authorunc0rr
Sun, 04 Sep 2011 20:21:08 +0400
changeset 5765 e87f6756773e
parent 5764 d785d7e23113
child 5766 ca9c7551bc8a
Allow surfing, download and extract only .zip files
QTfrontend/pagedata.cpp
QTfrontend/pagedata.h
--- a/QTfrontend/pagedata.cpp	Sun Sep 04 12:19:31 2011 -0400
+++ b/QTfrontend/pagedata.cpp	Sun Sep 04 20:21:08 2011 +0400
@@ -44,7 +44,7 @@
     BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true);
 
     web = new DataBrowser(this);
-    connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(install(const QUrl&)));
+    connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(request(const QUrl&)));
     web->setOpenLinks(false);
     pageLayout->addWidget(web, 0, 0, 1, 3);
 
@@ -54,22 +54,34 @@
     fetchList();
 }
 
-void PageDataDownload::install(const QUrl &url)
+void PageDataDownload::request(const QUrl &url)
 {
-    qWarning() << "Download Request" << url.toString();
-    QString fileName = QFileInfo(url.toString()).fileName();
+    if(url.path().endsWith(".zip"))
+    {
+        qWarning() << "Download Request" << url.toString();
+        QString fileName = QFileInfo(url.toString()).fileName();
 
-    QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + url.toString()));
-    newRequest.setAttribute(QNetworkRequest::User, fileName);
+        QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + url.path()));
+        newRequest.setAttribute(QNetworkRequest::User, fileName);
 
-    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
-    QNetworkReply *reply = manager->get(newRequest);
-    connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded()));
-    connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
+        QNetworkAccessManager *manager = new QNetworkAccessManager(this);
+        QNetworkReply *reply = manager->get(newRequest);
+        connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded()));
+        connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
 
-    QProgressBar *progressBar = new QProgressBar(this);
-    progressBarsLayout->addWidget(progressBar);
-    progressBars.insert(reply, progressBar);
+        QProgressBar *progressBar = new QProgressBar(this);
+        progressBarsLayout->addWidget(progressBar);
+        progressBars.insert(reply, progressBar);
+    } else
+    {
+        qWarning() << "Page Request" << url.toString();
+
+        QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + url.path()));
+
+        QNetworkAccessManager *manager = new QNetworkAccessManager(this);
+        QNetworkReply *reply = manager->get(newRequest);
+        connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded()));
+    }
 }
 
 
@@ -123,12 +135,7 @@
 
 void PageDataDownload::fetchList()
 {
-    //QNetworkRequest newRequest(QUrl("http://hedgewars.org/node/2833"));
-    QNetworkRequest newRequest(QUrl("http://hedgewars.org/content.html"));
-
-    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
-    QNetworkReply *reply = manager->get(newRequest);
-    connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded()));
+    request(QUrl("http://hedgewars.org/content.html"));
 }
 
 bool PageDataDownload::extractDataPack(QByteArray * buf)
--- a/QTfrontend/pagedata.h	Sun Sep 04 12:19:31 2011 -0400
+++ b/QTfrontend/pagedata.h	Sun Sep 04 20:21:08 2011 +0400
@@ -47,7 +47,7 @@
     bool extractDataPack(QByteArray * buf);
 
 private slots:
-    void install(const QUrl &url);
+    void request(const QUrl &url);
 
     void pageDownloaded();
     void fileDownloaded();