qtmobility/examples/lightmaps/lightmaps.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
   315         QNetworkConfigurationManager manager;
   315         QNetworkConfigurationManager manager;
   316         const bool canStartIAP = (manager.capabilities()
   316         const bool canStartIAP = (manager.capabilities()
   317                                   & QNetworkConfigurationManager::CanStartAndStopInterfaces);
   317                                   & QNetworkConfigurationManager::CanStartAndStopInterfaces);
   318 
   318 
   319         // Is there default access point, use it
   319         // Is there default access point, use it
   320         QNetworkConfiguration cfg1 = manager.defaultConfiguration();
   320         QTM_PREPEND_NAMESPACE(QNetworkConfiguration) cfg1 = manager.defaultConfiguration();
   321         if (!cfg1.isValid() || (!canStartIAP && cfg1.state() != QNetworkConfiguration::Active)) {
   321         if (!cfg1.isValid() || (!canStartIAP && cfg1.state() != QTM_PREPEND_NAMESPACE(QNetworkConfiguration)::Active)) {
   322             m_networkSetupError = QString(tr("Avaliable Access Points not found."));
   322             m_networkSetupError = QString(tr("This example requires networking, and no avaliable networks or access points could be found."));
   323             m_normalMap = 0;
   323             QTimer::singleShot(0, this, SLOT(networkSetupError()));
   324             m_largeMap = 0;
       
   325             QTimer::singleShot(0, this, SLOT(delayedInit()));
       
   326             return;
   324             return;
   327         }
   325         }
   328 
   326 
   329         m_session = new QNetworkSession(cfg1, this);
   327         m_session = new QNetworkSession(cfg1, this);
   330         m_connectivityHelper = new ConnectivityHelper(m_session, this);
   328         m_connectivityHelper = new ConnectivityHelper(m_session, this);
   368         update();
   366         update();
   369     }
   367     }
   370 
   368 
   371 private slots:
   369 private slots:
   372 
   370 
       
   371     void networkSetupError() {
       
   372         QMessageBox::critical(this, tr("LightMaps"),
       
   373                                  m_networkSetupError);
       
   374         QTimer::singleShot(0, qApp, SLOT(quit()));
       
   375     }
       
   376 
   373     void networkSessionOpened() {
   377     void networkSessionOpened() {
   374         m_location = QGeoPositionInfoSource::createDefaultSource(this);
   378         m_location = QGeoPositionInfoSource::createDefaultSource(this);
   375         m_location->setUpdateInterval(10000);
       
   376 
   379 
   377         if (!m_location) {
   380         if (!m_location) {
   378             QNmeaPositionInfoSource *nmeaLocation = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode, this);
   381             QNmeaPositionInfoSource *nmeaLocation = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode, this);
   379             QFile *logFile = new QFile(QApplication::applicationDirPath()
   382             QFile *logFile = new QFile(QApplication::applicationDirPath()
   380                                        + QDir::separator() + "nmealog.txt", this);
   383                                        + QDir::separator() + "nmealog.txt", this);
   381             nmeaLocation->setDevice(logFile);
   384             nmeaLocation->setDevice(logFile);
   382             m_location = nmeaLocation;
   385             m_location = nmeaLocation;
   383             m_usingLogFile = true;
   386             m_usingLogFile = true;
   384         }
   387         }
   385 
   388 
       
   389         m_location->setUpdateInterval(10000);
       
   390 
   386         connect(m_location,
   391         connect(m_location,
   387                 SIGNAL(positionUpdated(QGeoPositionInfo)),
   392                 SIGNAL(positionUpdated(QGeoPositionInfo)),
   388                 this,
   393                 this,
   389                 SLOT(positionUpdated(QGeoPositionInfo)));
   394                 SLOT(positionUpdated(QGeoPositionInfo)));
   390 
   395 
   392             QMessageBox::information(this, tr("LightMaps"),
   397             QMessageBox::information(this, tr("LightMaps"),
   393                                      tr("No GPS support detected, using GPS data from a sample log file instead."));
   398                                      tr("No GPS support detected, using GPS data from a sample log file instead."));
   394         } else {
   399         } else {
   395             waitForFix();
   400             waitForFix();
   396             m_location->stopUpdates();
   401             m_location->stopUpdates();
   397         }
       
   398 
       
   399         if (!m_networkSetupError.isEmpty()) {
       
   400             QMessageBox::information(this, tr("LightMaps"),
       
   401                                      m_networkSetupError);
       
   402         }
   402         }
   403 
   403 
   404         m_normalMap = new SlippyMap(m_session, m_location, this);
   404         m_normalMap = new SlippyMap(m_session, m_location, this);
   405         m_largeMap = new SlippyMap(m_session, m_location, this);
   405         m_largeMap = new SlippyMap(m_session, m_location, this);
   406 
   406