src/sensors/qsensormanager.cpp
changeset 5 603d3f8b6302
parent 0 876b1a06bc25
equal deleted inserted replaced
3:e4ebb16b39ea 5:603d3f8b6302
   225 /*!
   225 /*!
   226     Returns the default sensor identifier for \a type.
   226     Returns the default sensor identifier for \a type.
   227     This is set in a config file and can be overridden if required.
   227     This is set in a config file and can be overridden if required.
   228     If no default is available the system will return the first registered
   228     If no default is available the system will return the first registered
   229     sensor for \a type.
   229     sensor for \a type.
       
   230 
       
   231     \sa {Determining the default sensor for a type}
   230 */
   232 */
   231 QByteArray QSensor::defaultSensorForType(const QByteArray &type)
   233 QByteArray QSensor::defaultSensorForType(const QByteArray &type)
   232 {
   234 {
   233     QSensorManagerPrivate *d = sensorManagerPrivate();
   235     QSensorManagerPrivate *d = sensorManagerPrivate();
   234     if (!d->pluginsLoaded)
   236     if (!d->pluginsLoaded)
   236 
   238 
   237     // no sensors of that type exist
   239     // no sensors of that type exist
   238     if (!d->backendsByType.contains(type))
   240     if (!d->backendsByType.contains(type))
   239         return QByteArray();
   241         return QByteArray();
   240 
   242 
   241     QSettings settings(QLatin1String("Nokia"), QLatin1String("Sensors"));
   243     QSettings::Scope scope;
       
   244 #ifdef QTM_BUILD_UNITTESTS
       
   245     // The unit test needs to modify Sensors.conf but it can't access the system directory
       
   246     scope = QSettings::UserScope;
       
   247 #else
       
   248     scope = QSettings::SystemScope;
       
   249 #endif
       
   250     QSettings settings(scope, QLatin1String("Nokia"), QLatin1String("Sensors"));
   242     QVariant value = settings.value(QString(QLatin1String("Default/%1")).arg(QString::fromLatin1(type)));
   251     QVariant value = settings.value(QString(QLatin1String("Default/%1")).arg(QString::fromLatin1(type)));
   243     if (!value.isNull()) {
   252     if (!value.isNull()) {
   244         QByteArray defaultIdentifier = value.toByteArray();
   253         QByteArray defaultIdentifier = value.toByteArray();
   245         if (d->backendsByType[type].contains(defaultIdentifier)) // Don't return a value that we can't use!
   254         if (d->backendsByType[type].contains(defaultIdentifier)) // Don't return a value that we can't use!
   246             return defaultIdentifier;
   255             return defaultIdentifier;