demos/embedded/lightmaps/lightmaps.cpp
changeset 33 3e2da88830cd
parent 18 2f34d5167611
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include <QtCore>
    42 #include <QtCore>
    43 #include <QtGui>
    43 #include <QtGui>
    44 #include <QtNetwork>
    44 #include <QtNetwork>
    45 
       
    46 #if defined (Q_OS_SYMBIAN)
       
    47 #include "sym_iap_util.h"
       
    48 #endif
       
    49 
    45 
    50 #include <math.h>
    46 #include <math.h>
    51 
    47 
    52 #ifndef M_PI
    48 #ifndef M_PI
    53 #define M_PI 3.14159265358979323846
    49 #define M_PI 3.14159265358979323846
   488 {
   484 {
   489     Q_OBJECT
   485     Q_OBJECT
   490 
   486 
   491 private:
   487 private:
   492     LightMaps *map;
   488     LightMaps *map;
       
   489     QNetworkSession *networkSession;
   493 
   490 
   494 public:
   491 public:
   495     MapZoom(): QMainWindow(0) {
   492     MapZoom(): QMainWindow(0) {
   496         map = new LightMaps(this);
   493         map = new LightMaps(this);
   497         setCentralWidget(map);
   494         setCentralWidget(map);
   524         menu->addSeparator();
   521         menu->addSeparator();
   525         menu->addAction(nightModeAction);
   522         menu->addAction(nightModeAction);
   526         menu->addAction(osmAction);
   523         menu->addAction(osmAction);
   527 #endif
   524 #endif
   528 
   525 
   529         QTimer::singleShot(0, this, SLOT(delayedInit()));
   526         QNetworkConfigurationManager manager;
       
   527         if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
       
   528             // Get saved network configuration
       
   529             QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
       
   530             settings.beginGroup(QLatin1String("QtNetwork"));
       
   531             const QString id =
       
   532                 settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
       
   533             settings.endGroup();
       
   534 
       
   535             // If the saved network configuration is not currently discovered use the system
       
   536             // default
       
   537             QNetworkConfiguration config = manager.configurationFromIdentifier(id);
       
   538             if ((config.state() & QNetworkConfiguration::Discovered) !=
       
   539                 QNetworkConfiguration::Discovered) {
       
   540                 config = manager.defaultConfiguration();
       
   541             }
       
   542 
       
   543             networkSession = new QNetworkSession(config, this);
       
   544             connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
       
   545 
       
   546             networkSession->open();
       
   547         } else {
       
   548             networkSession = 0;
       
   549         }
   530     }
   550     }
   531 
   551 
   532 private slots:
   552 private slots:
   533 
   553 
   534     void delayedInit() {
   554     void sessionOpened() {
   535 #if defined(Q_OS_SYMBIAN)
   555         // Save the used configuration
   536         qt_SetDefaultIap();
   556         QNetworkConfiguration config = networkSession->configuration();
   537 #endif
   557         QString id;
       
   558         if (config.type() == QNetworkConfiguration::UserChoice) {
       
   559             id = networkSession->sessionProperty(
       
   560                     QLatin1String("UserChoiceConfiguration")).toString();
       
   561         } else {
       
   562             id = config.identifier();
       
   563         }
       
   564 
       
   565         QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
       
   566         settings.beginGroup(QLatin1String("QtNetwork"));
       
   567         settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
       
   568         settings.endGroup();
   538     }
   569     }
   539 
   570 
   540     void chooseOslo() {
   571     void chooseOslo() {
   541         map->setCenter(59.9138204, 10.7387413);
   572         map->setCenter(59.9138204, 10.7387413);
   542     }
   573     }