src/corelib/io/qsettings.cpp
changeset 18 2f34d5167611
parent 0 1918ee327afb
child 33 3e2da88830cd
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtCore module of the Qt Toolkit.
     7 ** This file is part of the QtCore module of the Qt Toolkit.
     8 **
     8 **
  1089 static inline int pathHashKey(QSettings::Format format, QSettings::Scope scope)
  1089 static inline int pathHashKey(QSettings::Format format, QSettings::Scope scope)
  1090 {
  1090 {
  1091     return int((uint(format) << 1) | uint(scope == QSettings::SystemScope));
  1091     return int((uint(format) << 1) | uint(scope == QSettings::SystemScope));
  1092 }
  1092 }
  1093 
  1093 
  1094 static QString getPath(QSettings::Format format, QSettings::Scope scope)
  1094 static void initDefaultPaths(QMutexLocker *locker)
  1095 {
  1095 {
  1096     Q_ASSERT((int)QSettings::NativeFormat == 0);
  1096     PathHash *pathHash = pathHashFunc();
  1097     Q_ASSERT((int)QSettings::IniFormat == 1);
       
  1098 
       
  1099     QString homePath = QDir::homePath();
  1097     QString homePath = QDir::homePath();
  1100     QString systemPath;
  1098     QString systemPath;
  1101 
  1099 
  1102     QMutexLocker locker(globalMutex());
  1100     locker->unlock();
  1103     PathHash *pathHash = pathHashFunc();
  1101 	
  1104     bool loadSystemPath = pathHash->isEmpty();
  1102     /*
  1105     locker.unlock();
  1103        QLibraryInfo::location() uses QSettings, so in order to
  1106 
  1104        avoid a dead-lock, we can't hold the global mutex while
  1107     if (loadSystemPath) {
  1105        calling it.
  1108         /*
  1106     */
  1109            QLibraryInfo::location() uses QSettings, so in order to
  1107     systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath);
  1110            avoid a dead-lock, we can't hold the global mutex while
  1108     systemPath += QLatin1Char('/');
  1111            calling it.
  1109 
  1112        */
  1110     locker->relock();
  1113         systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath);
       
  1114         systemPath += QLatin1Char('/');
       
  1115     }
       
  1116 
       
  1117     locker.relock();
       
  1118     if (pathHash->isEmpty()) {
  1111     if (pathHash->isEmpty()) {
  1119         /*
  1112         /*
  1120            Lazy initialization of pathHash. We initialize the
  1113            Lazy initialization of pathHash. We initialize the
  1121            IniFormat paths and (on Unix) the NativeFormat paths.
  1114            IniFormat paths and (on Unix) the NativeFormat paths.
  1122            (The NativeFormat paths are not configurable for the
  1115            (The NativeFormat paths are not configurable for the
  1153         pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::UserScope), userPath);
  1146         pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::UserScope), userPath);
  1154         pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::SystemScope), systemPath);
  1147         pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::SystemScope), systemPath);
  1155 #endif
  1148 #endif
  1156 #endif
  1149 #endif
  1157     }
  1150     }
       
  1151 }
       
  1152 
       
  1153 static QString getPath(QSettings::Format format, QSettings::Scope scope)
       
  1154 {
       
  1155     Q_ASSERT((int)QSettings::NativeFormat == 0);
       
  1156     Q_ASSERT((int)QSettings::IniFormat == 1);
       
  1157 
       
  1158     QMutexLocker locker(globalMutex());
       
  1159     PathHash *pathHash = pathHashFunc();
       
  1160     if (pathHash->isEmpty())
       
  1161         initDefaultPaths(&locker);
  1158 
  1162 
  1159     QString result = pathHash->value(pathHashKey(format, scope));
  1163     QString result = pathHash->value(pathHashKey(format, scope));
  1160     if (!result.isEmpty())
  1164     if (!result.isEmpty())
  1161         return result;
  1165         return result;
  1162 
  1166 
  3453 */
  3457 */
  3454 void QSettings::setPath(Format format, Scope scope, const QString &path)
  3458 void QSettings::setPath(Format format, Scope scope, const QString &path)
  3455 {
  3459 {
  3456     QMutexLocker locker(globalMutex());
  3460     QMutexLocker locker(globalMutex());
  3457     PathHash *pathHash = pathHashFunc();
  3461     PathHash *pathHash = pathHashFunc();
       
  3462     if (pathHash->isEmpty())
       
  3463         initDefaultPaths(&locker);
  3458     pathHash->insert(pathHashKey(format, scope), path + QDir::separator());
  3464     pathHash->insert(pathHashKey(format, scope), path + QDir::separator());
  3459 }
  3465 }
  3460 
  3466 
  3461 /*!
  3467 /*!
  3462     \typedef QSettings::SettingsMap
  3468     \typedef QSettings::SettingsMap