diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-07-07 06:28:45 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-07-19 00:32:33 (GMT) |
commit | 75db37022a9fd479e2a446b57e774eaf8e3e73ea (patch) | |
tree | c00dffdb4fe9f38aba2385ff686c2d16b2cae2e3 /demos | |
parent | 192a3c6d69b42f02aa9033c30502a6930cceb8f7 (diff) | |
download | Qt-75db37022a9fd479e2a446b57e774eaf8e3e73ea.zip Qt-75db37022a9fd479e2a446b57e774eaf8e3e73ea.tar.gz Qt-75db37022a9fd479e2a446b57e774eaf8e3e73ea.tar.bz2 |
Convert examples and demos to use Bearer Management.
Task-number: QTBUG-10439
Diffstat (limited to 'demos')
-rw-r--r-- | demos/embedded/anomaly/anomaly.pro | 2 | ||||
-rw-r--r-- | demos/embedded/anomaly/src/BrowserView.cpp | 33 | ||||
-rw-r--r-- | demos/embedded/anomaly/src/BrowserView.h | 3 | ||||
-rw-r--r-- | demos/embedded/lightmaps/lightmaps.cpp | 49 | ||||
-rw-r--r-- | demos/embedded/lightmaps/lightmaps.pro | 2 | ||||
-rw-r--r-- | demos/embedded/qmlflickr/qmlflickr.cpp | 63 | ||||
-rw-r--r-- | demos/embedded/qmlflickr/qmlflickr.pro | 2 | ||||
-rw-r--r-- | demos/embedded/qmlphotoviewer/qmlphotoviewer.cpp | 63 | ||||
-rw-r--r-- | demos/embedded/qmlphotoviewer/qmlphotoviewer.pro | 2 | ||||
-rw-r--r-- | demos/embedded/qmltwitter/qmltwitter.cpp | 63 | ||||
-rw-r--r-- | demos/embedded/qmltwitter/qmltwitter.pro | 2 |
11 files changed, 177 insertions, 107 deletions
diff --git a/demos/embedded/anomaly/anomaly.pro b/demos/embedded/anomaly/anomaly.pro index 584e5cd..a786b46 100644 --- a/demos/embedded/anomaly/anomaly.pro +++ b/demos/embedded/anomaly/anomaly.pro @@ -26,8 +26,6 @@ RESOURCES += src/anomaly.qrc symbian { TARGET.UID3 = 0xA000CF71 include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - INCLUDEPATH += $$QT_SOURCE_TREE/examples/network/qftp/ - LIBS += -lesock -lcommdb -linsock # For IAP selection TARGET.CAPABILITY = NetworkServices TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 } diff --git a/demos/embedded/anomaly/src/BrowserView.cpp b/demos/embedded/anomaly/src/BrowserView.cpp index a6e6f7a..73d0b70 100644 --- a/demos/embedded/anomaly/src/BrowserView.cpp +++ b/demos/embedded/anomaly/src/BrowserView.cpp @@ -51,10 +51,6 @@ #include "webview.h" #include "ZoomStrip.h" -#if defined (Q_OS_SYMBIAN) -#include "sym_iap_util.h" -#endif - BrowserView::BrowserView(QWidget *parent) : QWidget(parent) , m_titleBar(0) @@ -71,6 +67,26 @@ BrowserView::BrowserView(QWidget *parent) m_zoomLevels << 100; m_zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300; + QNetworkConfigurationManager manager; + if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { + // Get saved network configuration + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + const QString id = + settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); + settings.endGroup(); + + // If the saved network configuration is not currently discovered use the system + // default + QNetworkConfiguration config = manager.configurationFromIdentifier(id); + if ((config.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + config = manager.defaultConfiguration(); + } + + m_webView->page()->networkAccessManager()->setConfiguration(config); + } + QTimer::singleShot(0, this, SLOT(initialize())); } @@ -100,9 +116,6 @@ void BrowserView::initialize() m_webView->setHtml("about:blank"); m_webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_webView->setFocus(); -#ifdef Q_OS_SYMBIAN - QTimer::singleShot(0, this, SLOT(setDefaultIap())); -#endif } void BrowserView::start() @@ -173,12 +186,6 @@ void BrowserView::resizeEvent(QResizeEvent *event) int zh = m_zoomStrip->sizeHint().height(); m_zoomStrip->move(width() - zw, (height() - zh) / 2); } -#ifdef Q_OS_SYMBIAN -void BrowserView::setDefaultIap() -{ - qt_SetDefaultIap(); -} -#endif void BrowserView::navigate(const QUrl &url) { diff --git a/demos/embedded/anomaly/src/BrowserView.h b/demos/embedded/anomaly/src/BrowserView.h index 5ab1dd7..8981582 100644 --- a/demos/embedded/anomaly/src/BrowserView.h +++ b/demos/embedded/anomaly/src/BrowserView.h @@ -63,9 +63,6 @@ public slots: void navigate(const QUrl &url); void zoomIn(); void zoomOut(); -#ifdef Q_OS_SYMBIAN - void setDefaultIap(); -#endif private slots: void initialize(); diff --git a/demos/embedded/lightmaps/lightmaps.cpp b/demos/embedded/lightmaps/lightmaps.cpp index c76aed0..2eb1733 100644 --- a/demos/embedded/lightmaps/lightmaps.cpp +++ b/demos/embedded/lightmaps/lightmaps.cpp @@ -43,10 +43,6 @@ #include <QtGui> #include <QtNetwork> -#if defined (Q_OS_SYMBIAN) -#include "sym_iap_util.h" -#endif - #include <math.h> #ifndef M_PI @@ -490,6 +486,7 @@ class MapZoom : public QMainWindow private: LightMaps *map; + QNetworkSession *networkSession; public: MapZoom(): QMainWindow(0) { @@ -526,15 +523,49 @@ public: menu->addAction(osmAction); #endif - QTimer::singleShot(0, this, SLOT(delayedInit())); + QNetworkConfigurationManager manager; + if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { + // Get saved network configuration + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + const QString id = + settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); + settings.endGroup(); + + // If the saved network configuration is not currently discovered use the system + // default + QNetworkConfiguration config = manager.configurationFromIdentifier(id); + if ((config.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + config = manager.defaultConfiguration(); + } + + networkSession = new QNetworkSession(config, this); + connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened())); + + networkSession->open(); + } else { + networkSession = 0; + } } private slots: - void delayedInit() { -#if defined(Q_OS_SYMBIAN) - qt_SetDefaultIap(); -#endif + void sessionOpened() { + // Save the used configuration + QNetworkConfiguration config = networkSession->configuration(); + QString id; + if (config.type() == QNetworkConfiguration::UserChoice) { + id = networkSession->sessionProperty( + QLatin1String("UserChoiceConfiguration")).toString(); + } else { + id = config.identifier(); + } + + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); + settings.endGroup(); } void chooseOslo() { diff --git a/demos/embedded/lightmaps/lightmaps.pro b/demos/embedded/lightmaps/lightmaps.pro index ee4cc5a..9d83721 100644 --- a/demos/embedded/lightmaps/lightmaps.pro +++ b/demos/embedded/lightmaps/lightmaps.pro @@ -5,8 +5,6 @@ QT += network symbian { TARGET.UID3 = 0xA000CF75 include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - INCLUDEPATH += $$QT_SOURCE_TREE/examples/network/qftp/ - LIBS += -lesock -lcommdb -linsock # For IAP selection TARGET.CAPABILITY = NetworkServices TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 } diff --git a/demos/embedded/qmlflickr/qmlflickr.cpp b/demos/embedded/qmlflickr/qmlflickr.cpp index 6f0c528..7068f88 100644 --- a/demos/embedded/qmlflickr/qmlflickr.cpp +++ b/demos/embedded/qmlflickr/qmlflickr.cpp @@ -40,41 +40,59 @@ ****************************************************************************/ #include <QtCore/QFileInfo> +#include <QtCore/QSettings> #include <QtGui/QApplication> #include <QtDeclarative/QDeclarativeView> #include <QtDeclarative/QDeclarativeEngine> +#include <QtDeclarative/QDeclarativeNetworkAccessManagerFactory> +#include <QtNetwork/QNetworkConfiguration> +#include <QtNetwork/QNetworkConfigurationManager> +#include <QtNetwork/QNetworkAccessManager> -#if defined(Q_OS_SYMBIAN) -#include <QtCore/QTextCodec> -#include <QtCore/QTimer> -#include "sym_iap_util.h" - -class QmlAppView : public QDeclarativeView +// Factory to create QNetworkAccessManagers that use the saved network configuration; otherwise +// the system default. +class NetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory { -Q_OBJECT public: - QmlAppView(QWidget *parent = 0) - : QDeclarativeView(parent) - { - QTimer::singleShot(0, this, SLOT(setDefaultIap())); - } + ~NetworkAccessManagerFactory() { } -private slots: - void setDefaultIap() - { - qt_SetDefaultIap(); - } + QNetworkAccessManager *create(QObject *parent); }; -#else // Q_OS_SYMBIAN -typedef QDeclarativeView QmlAppView; -#endif // Q_OS_SYMBIAN + +QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent) +{ + QNetworkAccessManager *accessManager = new QNetworkAccessManager(parent); + + QNetworkConfigurationManager manager; + if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { + // Get saved network configuration + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); + settings.endGroup(); + + // If the saved network configuration is not currently discovered use the system default + QNetworkConfiguration config = manager.configurationFromIdentifier(id); + if ((config.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + config = manager.defaultConfiguration(); + } + + accessManager->setConfiguration(config); + } + + return accessManager; +} int main(int argc, char *argv[]) { QApplication application(argc, argv); + NetworkAccessManagerFactory networkAccessManagerFactory; + const QString mainQmlApp = QLatin1String("flickr.qml"); - QmlAppView view; + QDeclarativeView view; + view.engine()->setNetworkAccessManagerFactory(&networkAccessManagerFactory); view.setSource(QUrl(mainQmlApp)); view.setResizeMode(QDeclarativeView::SizeRootObjectToView); @@ -87,6 +105,3 @@ int main(int argc, char *argv[]) return application.exec(); } -#if defined(Q_OS_SYMBIAN) -#include "qmlflickr.moc" -#endif // Q_OS_SYMBIAN diff --git a/demos/embedded/qmlflickr/qmlflickr.pro b/demos/embedded/qmlflickr/qmlflickr.pro index e706134..39b316a 100644 --- a/demos/embedded/qmlflickr/qmlflickr.pro +++ b/demos/embedded/qmlflickr/qmlflickr.pro @@ -7,8 +7,6 @@ include($$PWD/deployment.pri) symbian { TARGET.UID3 = 0x$$qmlflickr_uid3 # defined in deployment.pri include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - INCLUDEPATH += $$QT_SOURCE_TREE/examples/network/qftp/ - LIBS += -lesock -lcommdb -linsock # For IAP selection TARGET.CAPABILITY = NetworkServices TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 } diff --git a/demos/embedded/qmlphotoviewer/qmlphotoviewer.cpp b/demos/embedded/qmlphotoviewer/qmlphotoviewer.cpp index 7889842..2b9db5e 100644 --- a/demos/embedded/qmlphotoviewer/qmlphotoviewer.cpp +++ b/demos/embedded/qmlphotoviewer/qmlphotoviewer.cpp @@ -40,41 +40,59 @@ ****************************************************************************/ #include <QtCore/QFileInfo> +#include <QtCore/QSettings> #include <QtGui/QApplication> #include <QtDeclarative/QDeclarativeView> #include <QtDeclarative/QDeclarativeEngine> +#include <QtDeclarative/QDeclarativeNetworkAccessManagerFactory> +#include <QtNetwork/QNetworkConfiguration> +#include <QtNetwork/QNetworkConfigurationManager> +#include <QtNetwork/QNetworkAccessManager> -#if defined(Q_OS_SYMBIAN) -#include <QtCore/QTextCodec> -#include <QtCore/QTimer> -#include "sym_iap_util.h" - -class QmlAppView : public QDeclarativeView +// Factory to create QNetworkAccessManagers that use the saved network configuration; otherwise +// the system default. +class NetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory { -Q_OBJECT public: - QmlAppView(QWidget *parent = 0) - : QDeclarativeView(parent) - { - QTimer::singleShot(0, this, SLOT(setDefaultIap())); - } + ~NetworkAccessManagerFactory() { } -private slots: - void setDefaultIap() - { - qt_SetDefaultIap(); - } + QNetworkAccessManager *create(QObject *parent); }; -#else // Q_OS_SYMBIAN -typedef QDeclarativeView QmlAppView; -#endif // Q_OS_SYMBIAN + +QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent) +{ + QNetworkAccessManager *accessManager = new QNetworkAccessManager(parent); + + QNetworkConfigurationManager manager; + if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { + // Get saved network configuration + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); + settings.endGroup(); + + // If the saved network configuration is not currently discovered use the system default + QNetworkConfiguration config = manager.configurationFromIdentifier(id); + if ((config.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + config = manager.defaultConfiguration(); + } + + accessManager->setConfiguration(config); + } + + return accessManager; +} int main(int argc, char *argv[]) { QApplication application(argc, argv); + NetworkAccessManagerFactory networkAccessManagerFactory; + const QString mainQmlApp = QLatin1String("photoviewer.qml"); - QmlAppView view; + QDeclarativeView view; + view.engine()->setNetworkAccessManagerFactory(&networkAccessManagerFactory); view.setSource(QUrl(mainQmlApp)); view.setResizeMode(QDeclarativeView::SizeRootObjectToView); @@ -87,6 +105,3 @@ int main(int argc, char *argv[]) return application.exec(); } -#if defined(Q_OS_SYMBIAN) -#include "qmlphotoviewer.moc" -#endif // Q_OS_SYMBIAN diff --git a/demos/embedded/qmlphotoviewer/qmlphotoviewer.pro b/demos/embedded/qmlphotoviewer/qmlphotoviewer.pro index ead5e67..a4234cf 100644 --- a/demos/embedded/qmlphotoviewer/qmlphotoviewer.pro +++ b/demos/embedded/qmlphotoviewer/qmlphotoviewer.pro @@ -7,8 +7,6 @@ include($$PWD/deployment.pri) symbian { TARGET.UID3 = 0x$$qmlphotoviewer_uid3 # defined in deployment.pri include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - INCLUDEPATH += $$QT_SOURCE_TREE/examples/network/qftp/ - LIBS += -lesock -lcommdb -linsock # For IAP selection TARGET.CAPABILITY = NetworkServices TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 } diff --git a/demos/embedded/qmltwitter/qmltwitter.cpp b/demos/embedded/qmltwitter/qmltwitter.cpp index e30ab24..c53098a4 100644 --- a/demos/embedded/qmltwitter/qmltwitter.cpp +++ b/demos/embedded/qmltwitter/qmltwitter.cpp @@ -40,41 +40,59 @@ ****************************************************************************/ #include <QtCore/QFileInfo> +#include <QtCore/QSettings> #include <QtGui/QApplication> #include <QtDeclarative/QDeclarativeView> #include <QtDeclarative/QDeclarativeEngine> +#include <QtDeclarative/QDeclarativeNetworkAccessManagerFactory> +#include <QtNetwork/QNetworkConfiguration> +#include <QtNetwork/QNetworkConfigurationManager> +#include <QtNetwork/QNetworkAccessManager> -#if defined(Q_OS_SYMBIAN) -#include <QtCore/QTextCodec> -#include <QtCore/QTimer> -#include "sym_iap_util.h" - -class QmlAppView : public QDeclarativeView +// Factory to create QNetworkAccessManagers that use the saved network configuration; otherwise +// the system default. +class NetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory { -Q_OBJECT public: - QmlAppView(QWidget *parent = 0) - : QDeclarativeView(parent) - { - QTimer::singleShot(0, this, SLOT(setDefaultIap())); - } + ~NetworkAccessManagerFactory() { } -private slots: - void setDefaultIap() - { - qt_SetDefaultIap(); - } + QNetworkAccessManager *create(QObject *parent); }; -#else // Q_OS_SYMBIAN -typedef QDeclarativeView QmlAppView; -#endif // Q_OS_SYMBIAN + +QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent) +{ + QNetworkAccessManager *accessManager = new QNetworkAccessManager(parent); + + QNetworkConfigurationManager manager; + if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { + // Get saved network configuration + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); + settings.endGroup(); + + // If the saved network configuration is not currently discovered use the system default + QNetworkConfiguration config = manager.configurationFromIdentifier(id); + if ((config.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + config = manager.defaultConfiguration(); + } + + accessManager->setConfiguration(config); + } + + return accessManager; +} int main(int argc, char *argv[]) { QApplication application(argc, argv); + NetworkAccessManagerFactory networkAccessManagerFactory; + const QString mainQmlApp = QLatin1String("twitter.qml"); - QmlAppView view; + QDeclarativeView view; + view.engine()->setNetworkAccessManagerFactory(&networkAccessManagerFactory); view.setSource(QUrl(mainQmlApp)); view.setResizeMode(QDeclarativeView::SizeRootObjectToView); @@ -87,6 +105,3 @@ int main(int argc, char *argv[]) return application.exec(); } -#if defined(Q_OS_SYMBIAN) -#include "qmltwitter.moc" -#endif // Q_OS_SYMBIAN diff --git a/demos/embedded/qmltwitter/qmltwitter.pro b/demos/embedded/qmltwitter/qmltwitter.pro index 7f9be57..7bd4617 100644 --- a/demos/embedded/qmltwitter/qmltwitter.pro +++ b/demos/embedded/qmltwitter/qmltwitter.pro @@ -7,8 +7,6 @@ include($$PWD/deployment.pri) symbian { TARGET.UID3 = 0x$$qmltwitter_uid3 # defined in deployment.pri include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - INCLUDEPATH += $$QT_SOURCE_TREE/examples/network/qftp/ - LIBS += -lesock -lcommdb -linsock # For IAP selection TARGET.CAPABILITY = NetworkServices TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 } |