Modified: trunk/Tools/ChangeLog (88160 => 88161)
--- trunk/Tools/ChangeLog 2011-06-06 12:41:55 UTC (rev 88160)
+++ trunk/Tools/ChangeLog 2011-06-06 13:19:23 UTC (rev 88161)
@@ -1,3 +1,16 @@
+2011-06-06 Barát Tibor <[email protected]>
+
+ Reviewed by Csaba Osztrogonác.
+
+ [Qt] Implement download feature for QtTestBrowser
+ https://bugs.webkit.org/show_bug.cgi?id=61865
+
+ * QtTestBrowser/launcherwindow.cpp:
+ (LauncherWindow::LauncherWindow):
+ (LauncherWindow::downloadRequest):
+ (LauncherWindow::fileDownloadFinished):
+ * QtTestBrowser/launcherwindow.h:
+
2011-06-04 Dominic Cooney <[email protected]>
Reviewed by Dimitri Glazkov.
Modified: trunk/Tools/QtTestBrowser/launcherwindow.cpp (88160 => 88161)
--- trunk/Tools/QtTestBrowser/launcherwindow.cpp 2011-06-06 12:41:55 UTC (rev 88160)
+++ trunk/Tools/QtTestBrowser/launcherwindow.cpp 2011-06-06 13:19:23 UTC (rev 88161)
@@ -34,6 +34,10 @@
#include "launcherwindow.h"
#include "urlloader.h"
+#include <QFileDialog>
+#include <QFileInfo>
+#include <QMessageBox>
+#include <QNetworkReply>
const int gExitClickArea = 80;
QVector<int> LauncherWindow::m_zoomLevels;
@@ -46,6 +50,7 @@
, m_inspector(0)
, m_formatMenuAction(0)
, m_zoomAnimation(0)
+ , m_reply(0)
#ifndef QT_NO_LINEEDIT
, m_findFlag(0)
#endif
@@ -58,6 +63,8 @@
static_cast<QGraphicsView*>(m_view)->setScene(sharedScene);
createChrome();
+
+ connect(page(), SIGNAL(downloadRequested(const QNetworkRequest&)), this, SLOT(downloadRequest(const QNetworkRequest&)));
}
LauncherWindow::~LauncherWindow()
@@ -968,6 +975,32 @@
output << "Loaded: " << url.toString() << endl;
}
+void LauncherWindow::downloadRequest(const QNetworkRequest &request)
+{
+ QNetworkAccessManager* manager = new QNetworkAccessManager(this);
+ m_reply = manager->get(request);
+ connect(m_reply, SIGNAL(finished()), this, SLOT(fileDownloadFinished()));
+}
+
+void LauncherWindow::fileDownloadFinished()
+{
+ QFileInfo fileInf(m_reply->request().url().toString());
+ QString requestFileName = QDir::homePath() + "/" + fileInf.fileName();
+ QString fileName = QFileDialog::getSaveFileName(this, "Save as...", requestFileName, "All Files (*)");
+
+ if (fileName.isEmpty())
+ return;
+ if (m_reply->error() != QNetworkReply::NoError)
+ QMessageBox::critical(this, QString("Download"), QString("Download failed."));
+ else {
+ QFile file(fileName);
+ file.open(QIODevice::WriteOnly);
+ file.write(m_reply->readAll());
+ file.close();
+ QMessageBox::information(this, QString("Download"), fileName + QString(" downloaded successfully."));
+ }
+}
+
void LauncherWindow::updateFPS(int fps)
{
QString fpsStatusText = QString("Current FPS: %1").arg(fps);
Modified: trunk/Tools/QtTestBrowser/launcherwindow.h (88160 => 88161)
--- trunk/Tools/QtTestBrowser/launcherwindow.h 2011-06-06 12:41:55 UTC (rev 88160)
+++ trunk/Tools/QtTestBrowser/launcherwindow.h 2011-06-06 13:19:23 UTC (rev 88161)
@@ -206,6 +206,8 @@
void showUserAgentDialog();
void printURL(const QUrl&);
+ void downloadRequest(const QNetworkRequest&);
+ void fileDownloadFinished();
public slots:
LauncherWindow* newWindow();
@@ -238,6 +240,7 @@
QAction* m_formatMenuAction;
QPropertyAnimation* m_zoomAnimation;
+ QNetworkReply* m_reply;
QList<QTouchEvent::TouchPoint> m_touchPoints;
bool m_touchMocking;