diff options
author | Lincoln Ramsay <lincoln.ramsay@nokia.com> | 2012-03-27 16:30:41 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-28 07:27:45 +0200 |
commit | 5df9cfb3e754b4e73e84748e00db0c760212d319 (patch) | |
tree | 6360de1ca4cf5cda58e7d2559d33fa0a00f28d2b /src/sensors/qsensormanager.cpp | |
parent | d5fbd8c4a7e9aa19d5b71c02208c242754b84bdc (diff) |
If QStandardPaths doesn't give us a path, use /etc/xdg
If Qt has been built with the Json-backed QStandardPaths and
/etc/user-dirs.json doesn't contain a "CONFIG" entry then
we get no path. In that case, just look in /etc/xdg.
Change-Id: Id184912c70c940e73fdb2f7e771632c262460aea
Reviewed-by: Wolfgang Beck <wolfgang.beck@nokia.com>
Diffstat (limited to 'src/sensors/qsensormanager.cpp')
-rw-r--r-- | src/sensors/qsensormanager.cpp | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/src/sensors/qsensormanager.cpp b/src/sensors/qsensormanager.cpp index 380f8aa0..7107c0a5 100644 --- a/src/sensors/qsensormanager.cpp +++ b/src/sensors/qsensormanager.cpp @@ -89,6 +89,33 @@ public: // Holds the default identifier QHash<QByteArray, QByteArray> defaultIdentifierForType; bool defaultIdentifierForTypeLoaded; + void readConfigFile() + { + defaultIdentifierForTypeLoaded = true; + QStringList configs = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation); + // This shouldn't happen but just in case, check in /etc/xdg + if (configs.count() == 0) configs << QLatin1String("/etc/xdg"); + QString config = configs.at(configs.count()-1) + QLatin1String("/Nokia/Sensors.conf"); + if (!QFile::exists(config)) return; + QFile cfgfile(config); + if (!cfgfile.open(QFile::ReadOnly)) return; + + QTextStream stream(&cfgfile); + QString line; + bool isconfig = false; + while (!stream.atEnd()) { + line = stream.readLine(); + if (!isconfig && line == QLatin1String("[Default]")) + isconfig = true; + else if (isconfig) { + //read out setting line + line.remove(' '); + QStringList pair = line.split('='); + if (pair.count() == 2) + defaultIdentifierForType.insert(pair[0].toLatin1(), pair[1].toLatin1()); + } + } + } // Holds the first identifier for each type QHash<QByteArray, QByteArray> firstIdentifierForType; @@ -418,39 +445,8 @@ QByteArray QSensor::defaultSensorForType(const QByteArray &type) return QByteArray(); //check if we need to read the config setting file - if (!d->defaultIdentifierForTypeLoaded) { - d->defaultIdentifierForTypeLoaded = true; - QStringList abspath = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation); - QString cfgpath; - //first in the list is user specific, so ignore it and take the last - if (abspath.length() > 0) { - cfgpath = abspath[abspath.count() - 1]; - cfgpath += QString::fromLatin1("/Nokia/Sensors.conf"); - if (QFile::exists(cfgpath)){ - QFile cfgfile(cfgpath); - if (cfgfile.open(QFile::ReadOnly)){ - //Read the sensor default setting file - QTextStream stream(&cfgfile); - QString line; - bool isconfig = false; - while (!stream.atEnd()) { - line = stream.readLine(); - if (!isconfig && line == QString::fromLatin1("[Default]")) - isconfig = true; - else { - if (isconfig) { - //read out setting line - line.remove(' '); - QStringList pair = line.split('='); - if (pair.count() == 2) - d->defaultIdentifierForType.insert(pair[0].toLatin1(), pair[1].toLatin1()); - } - } - } - } - } - } - } + if (!d->defaultIdentifierForTypeLoaded) + d->readConfigFile(); QHash<QByteArray, QByteArray>::const_iterator i = d->defaultIdentifierForType.find(type); if (i != d->defaultIdentifierForType.end() && i.key() == type) { |