summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2010-05-18 07:31:42 (GMT)
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2010-05-18 07:52:31 (GMT)
commit8665f4ba8cbf63740cfb379c8f98d8d68d089bf5 (patch)
treeb27ad3143e99e57d75fd2f1a6981c177175780c5 /demos
parentcd68abc3df40d8c6b03d9f0f1c8fc78f2e984ffe (diff)
downloadQt-8665f4ba8cbf63740cfb379c8f98d8d68d089bf5.zip
Qt-8665f4ba8cbf63740cfb379c8f98d8d68d089bf5.tar.gz
Qt-8665f4ba8cbf63740cfb379c8f98d8d68d089bf5.tar.bz2
Fix weatherinfo and flightinfo to only request WLAN connection once
New bearer implementation will only keep connection alive as long as the QNetworkAccessManager instance is alive, so changed the demos to have single manager instance instead of recreating it for each request. Task-number: QTBUG-10151 Reviewed-by: Janne Anttila
Diffstat (limited to 'demos')
-rw-r--r--demos/embedded/flightinfo/flightinfo.cpp56
-rw-r--r--demos/embedded/weatherinfo/weatherinfo.cpp17
2 files changed, 23 insertions, 50 deletions
diff --git a/demos/embedded/flightinfo/flightinfo.cpp b/demos/embedded/flightinfo/flightinfo.cpp
index 10d3f02..6cc1876 100644
--- a/demos/embedded/flightinfo/flightinfo.cpp
+++ b/demos/embedded/flightinfo/flightinfo.cpp
@@ -43,10 +43,6 @@
#include <QtGui>
#include <QtNetwork>
-#if defined (Q_OS_SYMBIAN)
-#include "sym_iap_util.h"
-#endif
-
#include "ui_form.h"
#define FLIGHTVIEW_URL "http://mobile.flightview.com/TrackByFlight.aspx"
@@ -100,6 +96,8 @@ private:
QUrl m_url;
QDate m_searchDate;
QPixmap m_map;
+ QNetworkAccessManager m_manager;
+ QList<QNetworkReply *> mapReplies;
public:
@@ -115,7 +113,6 @@ public:
connect(ui.flightEdit, SIGNAL(returnPressed()), SLOT(startSearch()));
setWindowTitle("Flight Info");
- QTimer::singleShot(0, this, SLOT(delayedInit()));
// Rendered from the public-domain vectorized aircraft
// http://openclipart.org/media/people/Jarno
@@ -127,6 +124,8 @@ public:
connect(searchTodayAction, SIGNAL(triggered()), SLOT(today()));
connect(searchYesterdayAction, SIGNAL(triggered()), SLOT(yesterday()));
connect(randomAction, SIGNAL(triggered()), SLOT(randomFlight()));
+ connect(&m_manager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(handleNetworkData(QNetworkReply*)));
#if defined(Q_OS_SYMBIAN)
menuBar()->addAction(searchTodayAction);
menuBar()->addAction(searchYesterdayAction);
@@ -140,31 +139,21 @@ public:
}
private slots:
- void delayedInit() {
-#if defined(Q_OS_SYMBIAN)
- qt_SetDefaultIap();
-#endif
- }
-
void handleNetworkData(QNetworkReply *networkReply) {
if (!networkReply->error()) {
- // Assume UTF-8 encoded
- QByteArray data = networkReply->readAll();
- QString xml = QString::fromUtf8(data);
- digest(xml);
- }
- networkReply->deleteLater();
- networkReply->manager()->deleteLater();
- }
-
- void handleMapData(QNetworkReply *networkReply) {
- if (!networkReply->error()) {
- m_map.loadFromData(networkReply->readAll());
- update();
+ if (!mapReplies.contains(networkReply)) {
+ // Assume UTF-8 encoded
+ QByteArray data = networkReply->readAll();
+ QString xml = QString::fromUtf8(data);
+ digest(xml);
+ } else {
+ mapReplies.removeOne(networkReply);
+ m_map.loadFromData(networkReply->readAll());
+ update();
+ }
}
networkReply->deleteLater();
- networkReply->manager()->deleteLater();
}
void today() {
@@ -224,10 +213,7 @@ public slots:
ui.flightName->setText("Getting a random flight...");
}
- QNetworkAccessManager *manager = new QNetworkAccessManager(this);
- connect(manager, SIGNAL(finished(QNetworkReply*)),
- this, SLOT(handleNetworkData(QNetworkReply*)));
- manager->get(QNetworkRequest(m_url));
+ m_manager.get(QNetworkRequest(m_url));
}
@@ -248,10 +234,7 @@ private:
regex.indexIn(href);
QString airport = regex.cap(1);
m_url.addEncodedQueryItem("dpap", QUrl::toPercentEncoding(airport));
- QNetworkAccessManager *manager = new QNetworkAccessManager(this);
- connect(manager, SIGNAL(finished(QNetworkReply*)),
- this, SLOT(handleNetworkData(QNetworkReply*)));
- manager->get(QNetworkRequest(m_url));
+ m_manager.get(QNetworkRequest(m_url));
return;
}
@@ -287,12 +270,9 @@ private:
}
if (xml.name() == "img" && inFlightMap) {
QString src = xml.attributes().value("src").toString();
- src.prepend("http://mobile.flightview.com");
+ src.prepend("http://mobile.flightview.com/");
QUrl url = QUrl::fromPercentEncoding(src.toAscii());
- QNetworkAccessManager *manager = new QNetworkAccessManager(this);
- connect(manager, SIGNAL(finished(QNetworkReply*)),
- this, SLOT(handleMapData(QNetworkReply*)));
- manager->get(QNetworkRequest(url));
+ mapReplies.append(m_manager.get(QNetworkRequest(url)));
}
}
diff --git a/demos/embedded/weatherinfo/weatherinfo.cpp b/demos/embedded/weatherinfo/weatherinfo.cpp
index 42b685e..3e0226a 100644
--- a/demos/embedded/weatherinfo/weatherinfo.cpp
+++ b/demos/embedded/weatherinfo/weatherinfo.cpp
@@ -44,10 +44,6 @@
#include <QtNetwork>
#include <QtSvg>
-#if defined (Q_OS_SYMBIAN)
-#include "sym_iap_util.h"
-#endif
-
class WeatherInfo: public QMainWindow
{
Q_OBJECT
@@ -67,6 +63,7 @@ private:
QList<QGraphicsTextItem*> m_rangeItems;
QTimeLine m_timeLine;
QHash<QString, QString> m_icons;
+ QNetworkAccessManager m_manager;
public:
WeatherInfo(QWidget *parent = 0): QMainWindow(parent) {
@@ -98,14 +95,14 @@ public:
}
setContextMenuPolicy(Qt::ActionsContextMenu);
+ connect(&m_manager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(handleNetworkData(QNetworkReply*)));
+
QTimer::singleShot(0, this, SLOT(delayedInit()));
}
private slots:
void delayedInit() {
-#if defined(Q_OS_SYMBIAN)
- qt_SetDefaultIap();
-#endif
request("Oslo");
}
@@ -122,7 +119,6 @@ private slots:
if (!networkReply->error())
digest(QString::fromUtf8(networkReply->readAll()));
networkReply->deleteLater();
- networkReply->manager()->deleteLater();
}
void animate(int frame) {
@@ -185,10 +181,7 @@ private:
url.addEncodedQueryItem("hl", "en");
url.addEncodedQueryItem("weather", QUrl::toPercentEncoding(location));
- QNetworkAccessManager *manager = new QNetworkAccessManager(this);
- connect(manager, SIGNAL(finished(QNetworkReply*)),
- this, SLOT(handleNetworkData(QNetworkReply*)));
- manager->get(QNetworkRequest(url));
+ m_manager.get(QNetworkRequest(url));
city = QString();
setWindowTitle("Loading...");