Qt 4.8
Public Functions | Static Public Functions | Private Functions | Properties | List of all members
QConfFileSettingsPrivate Class Reference

#include <qsettings_p.h>

Inheritance diagram for QConfFileSettingsPrivate:
QSettingsPrivate QObjectPrivate QObjectData

Public Functions

QStringList children (const QString &prefix, ChildSpec spec) const
 
void clear ()
 
QString fileName () const
 
void flush ()
 
bool get (const QString &key, QVariant *value) const
 
bool isWritable () const
 
 QConfFileSettingsPrivate (QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
 
 QConfFileSettingsPrivate (const QString &fileName, QSettings::Format format)
 
void remove (const QString &key)
 
void set (const QString &key, const QVariant &value)
 
void sync ()
 
 ~QConfFileSettingsPrivate ()
 
- Public Functions inherited from QSettingsPrivate
QString actualKey (const QString &key) const
 
void beginGroupOrArray (const QSettingsGroup &group)
 
 QSettingsPrivate (QSettings::Format format)
 
 QSettingsPrivate (QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
 
void requestUpdate ()
 
void setStatus (QSettings::Status status) const
 
void update ()
 
virtual ~QSettingsPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static bool readIniFile (const QByteArray &data, UnparsedSettingsMap *unparsedIniSections)
 
static bool readIniLine (const QByteArray &data, int &dataPos, int &lineStart, int &lineLen, int &equalsPos)
 
static bool readIniSection (const QSettingsKey &section, const QByteArray &data, ParsedSettingsMap *settingsMap, QTextCodec *codec)
 
- Static Public Functions inherited from QSettingsPrivate
static QSettingsPrivatecreate (QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
 
static QSettingsPrivatecreate (const QString &fileName, QSettings::Format format)
 
static void iniEscapedKey (const QString &key, QByteArray &result)
 
static void iniEscapedString (const QString &str, QByteArray &result, QTextCodec *codec)
 
static void iniEscapedStringList (const QStringList &strs, QByteArray &result, QTextCodec *codec)
 
static bool iniUnescapedKey (const QByteArray &key, int from, int to, QString &result)
 
static bool iniUnescapedStringList (const QByteArray &str, int from, int to, QString &stringResult, QStringList &stringListResult, QTextCodec *codec)
 
static QString normalizedKey (const QString &key)
 
static void processChild (QString key, ChildSpec spec, QMap< QString, QString > &result)
 
static QStringList splitArgs (const QString &s, int idx)
 
static QVariant stringListToVariantList (const QStringList &l)
 
static QVariant stringToVariant (const QString &s)
 
static QStringList variantListToStringList (const QVariantList &l)
 
static QString variantToString (const QVariant &v)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Private Functions

void ensureAllSectionsParsed (QConfFile *confFile) const
 
void ensureSectionParsed (QConfFile *confFile, const QSettingsKey &key) const
 
void initAccess ()
 
void initFormat ()
 
bool readPlistFile (const QString &fileName, ParsedSettingsMap *map) const
 
void syncConfFile (int confFileNo)
 
bool writeIniFile (QIODevice &device, const ParsedSettingsMap &map)
 
bool writePlistFile (const QString &fileName, const ParsedSettingsMap &map) const
 

Properties

Qt::CaseSensitivity caseSensitivity
 
QScopedSharedPointer< QConfFileconfFiles [NumConfFiles]
 
QString extension
 
int nextPosition
 
QSettings::ReadFunc readFunc
 
QSettings::WriteFunc writeFunc
 

Additional Inherited Members

- Public Types inherited from QSettingsPrivate
enum  {
  F_Application = 0x0, F_Organization = 0x1, F_User = 0x0, F_System = 0x2,
  NumConfFiles = 4
}
 
enum  ChildSpec { AllKeys, ChildKeys, ChildGroups }
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Public Variables inherited from QSettingsPrivate
QString applicationName
 
QSettings::Format format
 
QTextCodeciniCodec
 
QString organizationName
 
QSettings::Scope scope
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 
- Protected Variables inherited from QSettingsPrivate
bool fallbacks
 
QString groupPrefix
 
QStack< QSettingsGroupgroupStack
 
bool pendingChanges
 
int spec
 
QSettings::Status status
 

Detailed Description

Definition at line 273 of file qsettings_p.h.

Constructors and Destructors

◆ QConfFileSettingsPrivate() [1/2]

QConfFileSettingsPrivate::QConfFileSettingsPrivate ( QSettings::Format  format,
QSettings::Scope  scope,
const QString organization,
const QString application 
)

Definition at line 1150 of file qsettings.cpp.

1154  : QSettingsPrivate(format, scope, organization, application),
1155  nextPosition(0x40000000) // big positive number
1156 {
1157  int i;
1158  initFormat();
1159 
1160  QString org = organization;
1161  if (org.isEmpty()) {
1163  org = QLatin1String("Unknown Organization");
1164  }
1165 
1166 #if !defined(Q_OS_BLACKBERRY)
1167  QString appFile = org + QDir::separator() + application + extension;
1168  QString orgFile = org + extension;
1169 
1170  if (scope == QSettings::UserScope) {
1172  if (!application.isEmpty())
1173  confFiles[F_User | F_Application].reset(QConfFile::fromName(userPath + appFile, true));
1174  confFiles[F_User | F_Organization].reset(QConfFile::fromName(userPath + orgFile, true));
1175  }
1176 
1178  if (!application.isEmpty())
1179  confFiles[F_System | F_Application].reset(QConfFile::fromName(systemPath + appFile, false));
1180  confFiles[F_System | F_Organization].reset(QConfFile::fromName(systemPath + orgFile, false));
1181 #else
1182  QString confName = getPath(format, QSettings::UserScope) + org;
1183  if (!application.isEmpty())
1184  confName += QDir::separator() + application;
1185  confName += extension;
1186  confFiles[SandboxConfFile].reset(QConfFile::fromName(confName, true));
1187 #endif
1188 
1189  for (i = 0; i < NumConfFiles; ++i) {
1190  if (confFiles[i]) {
1191  spec = i;
1192  break;
1193  }
1194  }
1195 
1196  initAccess();
1197 }
void setStatus(QSettings::Status status) const
Definition: qsettings.cpp:410
QSettingsPrivate(QSettings::Format format)
Definition: qsettings.cpp:302
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
QSettings::Scope scope
Definition: qsettings_p.h:259
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QConfFile * fromName(const QString &name, bool _userPerms)
Definition: qsettings.cpp:272
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
static QString getPath(QSettings::Format format, QSettings::Scope scope)
Definition: qsettings.cpp:1132
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311

◆ QConfFileSettingsPrivate() [2/2]

QConfFileSettingsPrivate::QConfFileSettingsPrivate ( const QString fileName,
QSettings::Format  format 
)

Definition at line 1199 of file qsettings.cpp.

1202  nextPosition(0x40000000) // big positive number
1203 {
1204  initFormat();
1205 
1206  confFiles[0].reset(QConfFile::fromName(fileName, true));
1207 
1208  initAccess();
1209 }
QSettingsPrivate(QSettings::Format format)
Definition: qsettings.cpp:302
static QConfFile * fromName(const QString &name, bool _userPerms)
Definition: qsettings.cpp:272
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311

◆ ~QConfFileSettingsPrivate()

QConfFileSettingsPrivate::~QConfFileSettingsPrivate ( )

Definition at line 1211 of file qsettings.cpp.

1212 {
1213  QMutexLocker locker(globalMutex());
1214  ConfFileHash *usedHash = usedHashFunc();
1215  ConfFileCache *unusedCache = unusedCacheFunc();
1216 
1217  for (int i = 0; i < NumConfFiles; ++i) {
1218  if (confFiles[i] && !confFiles[i]->ref.deref()) {
1219  if (confFiles[i]->size == 0) {
1220  delete confFiles[i].take();
1221  } else {
1222  if (usedHash)
1223  usedHash->remove(confFiles[i]->name);
1224  if (unusedCache) {
1225  QT_TRY {
1226  // compute a better size?
1227  unusedCache->insert(confFiles[i]->name, confFiles[i].data(),
1228  10 + (confFiles[i]->originalKeys.size() / 4));
1229  confFiles[i].take();
1230  } QT_CATCH(...) {
1231  // out of memory. Do not cache the file.
1232  delete confFiles[i].take();
1233  }
1234  } else {
1235  // unusedCache is gone - delete the entry to prevent a memory leak
1236  delete confFiles[i].take();
1237  }
1238  }
1239  }
1240  // prevent the ScopedPointer to deref it again.
1241  confFiles[i].take();
1242  }
1243 }
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
Definition: qcache.h:54
T * take()
Returns the value of the pointer referenced by this object.
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const char * name
static const char * data(const QByteArray &arr)
#define QT_CATCH(A)
Definition: qglobal.h:1537
bool insert(const Key &key, T *object, int cost=1)
Definition: qcache.h:181
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
#define QT_TRY
Definition: qglobal.h:1536
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311

Functions

◆ children()

QStringList QConfFileSettingsPrivate::children ( const QString prefix,
ChildSpec  spec 
) const
virtual

Implements QSettingsPrivate.

Definition at line 1317 of file qsettings.cpp.

1318 {
1319  QMap<QString, QString> result;
1321 
1322  QSettingsKey thePrefix(prefix, caseSensitivity);
1323  int startPos = prefix.size();
1324 
1325  for (int i = 0; i < NumConfFiles; ++i) {
1326  if (QConfFile *confFile = confFiles[i].data()) {
1327  QMutexLocker locker(&confFile->mutex);
1328 
1329  if (thePrefix.isEmpty()) {
1330  ensureAllSectionsParsed(confFile);
1331  } else {
1332  ensureSectionParsed(confFile, thePrefix);
1333  }
1334 
1335  j = const_cast<const ParsedSettingsMap *>(
1336  &confFile->originalKeys)->lowerBound( thePrefix);
1337  while (j != confFile->originalKeys.constEnd() && j.key().startsWith(thePrefix)) {
1338  if (!confFile->removedKeys.contains(j.key()))
1339  processChild(j.key().originalCaseKey().mid(startPos), spec, result);
1340  ++j;
1341  }
1342 
1343  j = const_cast<const ParsedSettingsMap *>(
1344  &confFile->addedKeys)->lowerBound(thePrefix);
1345  while (j != confFile->addedKeys.constEnd() && j.key().startsWith(thePrefix)) {
1346  processChild(j.key().originalCaseKey().mid(startPos), spec, result);
1347  ++j;
1348  }
1349 
1350  if (!fallbacks)
1351  break;
1352  }
1353  }
1354  return result.keys();
1355 }
Qt::CaseSensitivity caseSensitivity
Definition: qsettings_p.h:315
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static const char * data(const QByteArray &arr)
void ensureSectionParsed(QConfFile *confFile, const QSettingsKey &key) const
Definition: qsettings.cpp:1982
void ensureAllSectionsParsed(QConfFile *confFile) const
Definition: qsettings.cpp:1970
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static void processChild(QString key, ChildSpec spec, QMap< QString, QString > &result)
Definition: qsettings.cpp:380
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311
friend class const_iterator
Definition: qmap.h:369

◆ clear()

void QConfFileSettingsPrivate::clear ( )
virtual

Implements QSettingsPrivate.

Definition at line 1357 of file qsettings.cpp.

1358 {
1359  QConfFile *confFile = confFiles[spec].data();
1360  if (!confFile)
1361  return;
1362 
1363  QMutexLocker locker(&confFile->mutex);
1364  ensureAllSectionsParsed(confFile);
1365  confFile->addedKeys.clear();
1366  confFile->removedKeys = confFile->originalKeys;
1367 }
T * data() const
Returns the value of the pointer referenced by this object.
ParsedSettingsMap addedKeys
Definition: qsettings_p.h:166
QMutex mutex
Definition: qsettings_p.h:169
void ensureAllSectionsParsed(QConfFile *confFile) const
Definition: qsettings.cpp:1970
ParsedSettingsMap originalKeys
Definition: qsettings_p.h:165
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
ParsedSettingsMap removedKeys
Definition: qsettings_p.h:167
void clear()
Removes all items from the map.
Definition: qmap.h:444
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311

◆ ensureAllSectionsParsed()

void QConfFileSettingsPrivate::ensureAllSectionsParsed ( QConfFile confFile) const
private

Definition at line 1970 of file qsettings.cpp.

Referenced by children(), clear(), and syncConfFile().

1971 {
1974 
1975  for (; i != end; ++i) {
1976  if (!QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec))
1978  }
1979  confFile->unparsedIniSections.clear();
1980 }
void setStatus(QSettings::Status status) const
Definition: qsettings.cpp:410
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
QTextCodec * iniCodec
Definition: qsettings_p.h:262
ParsedSettingsMap originalKeys
Definition: qsettings_p.h:165
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
static bool readIniSection(const QSettingsKey &section, const QByteArray &data, ParsedSettingsMap *settingsMap, QTextCodec *codec)
Definition: qsettings.cpp:1792
UnparsedSettingsMap unparsedIniSections
Definition: qsettings_p.h:164
static const KeyPair *const end
void clear()
Removes all items from the map.
Definition: qmap.h:444
friend class const_iterator
Definition: qmap.h:369

◆ ensureSectionParsed()

void QConfFileSettingsPrivate::ensureSectionParsed ( QConfFile confFile,
const QSettingsKey key 
) const
private

Definition at line 1982 of file qsettings.cpp.

Referenced by children(), get(), and remove().

1984 {
1985  if (confFile->unparsedIniSections.isEmpty())
1986  return;
1987 
1989 
1990  int indexOfSlash = key.indexOf(QLatin1Char('/'));
1991  if (indexOfSlash != -1) {
1992  i = confFile->unparsedIniSections.upperBound(key);
1993  if (i == confFile->unparsedIniSections.begin())
1994  return;
1995  --i;
1996  if (i.key().isEmpty() || !key.startsWith(i.key()))
1997  return;
1998  } else {
1999  i = confFile->unparsedIniSections.begin();
2000  if (i == confFile->unparsedIniSections.end() || !i.key().isEmpty())
2001  return;
2002  }
2003 
2004  if (!QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec))
2006  confFile->unparsedIniSections.erase(i);
2007 }
void setStatus(QSettings::Status status) const
Definition: qsettings.cpp:410
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
QTextCodec * iniCodec
Definition: qsettings_p.h:262
ParsedSettingsMap originalKeys
Definition: qsettings_p.h:165
static bool readIniSection(const QSettingsKey &section, const QByteArray &data, ParsedSettingsMap *settingsMap, QTextCodec *codec)
Definition: qsettings.cpp:1792
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
UnparsedSettingsMap unparsedIniSections
Definition: qsettings_p.h:164
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
iterator upperBound(const Key &key)
Returns an iterator pointing to the item that immediately follows the last item with key key in the m...
Definition: qmap.h:918
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ fileName()

QString QConfFileSettingsPrivate::fileName ( ) const
virtual

Implements QSettingsPrivate.

Definition at line 1388 of file qsettings.cpp.

1389 {
1390  QConfFile *confFile = confFiles[spec].data();
1391  if (!confFile)
1392  return QString();
1393  return confFile->name;
1394 }
T * data() const
Returns the value of the pointer referenced by this object.
QString name
Definition: qsettings_p.h:161
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311

◆ flush()

void QConfFileSettingsPrivate::flush ( )
virtual

Implements QSettingsPrivate.

Definition at line 1383 of file qsettings.cpp.

1384 {
1385  sync();
1386 }

◆ get()

bool QConfFileSettingsPrivate::get ( const QString key,
QVariant value 
) const
virtual

Implements QSettingsPrivate.

Definition at line 1284 of file qsettings.cpp.

1285 {
1286  QSettingsKey theKey(key, caseSensitivity);
1288  bool found = false;
1289 
1290  for (int i = 0; i < NumConfFiles; ++i) {
1291  if (QConfFile *confFile = confFiles[i].data()) {
1292  QMutexLocker locker(&confFile->mutex);
1293 
1294  if (!confFile->addedKeys.isEmpty()) {
1295  j = confFile->addedKeys.constFind(theKey);
1296  found = (j != confFile->addedKeys.constEnd());
1297  }
1298  if (!found) {
1299  ensureSectionParsed(confFile, theKey);
1300  j = confFile->originalKeys.constFind(theKey);
1301  found = (j != confFile->originalKeys.constEnd()
1302  && !confFile->removedKeys.contains(theKey));
1303  }
1304 
1305  if (found && value)
1306  *value = *j;
1307 
1308  if (found)
1309  return true;
1310  if (!fallbacks)
1311  break;
1312  }
1313  }
1314  return false;
1315 }
Qt::CaseSensitivity caseSensitivity
Definition: qsettings_p.h:315
static const char * data(const QByteArray &arr)
void ensureSectionParsed(QConfFile *confFile, const QSettingsKey &key) const
Definition: qsettings.cpp:1982
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311
friend class const_iterator
Definition: qmap.h:369

◆ initAccess()

void QConfFileSettingsPrivate::initAccess ( )
private

Definition at line 1012 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate().

1013 {
1014  if (confFiles[spec]) {
1015  if (format > QSettings::IniFormat) {
1016  if (!readFunc)
1018  }
1019  }
1020 
1021  sync(); // loads the files the first time
1022 }
void setStatus(QSettings::Status status) const
Definition: qsettings.cpp:410
QSettings::ReadFunc readFunc
Definition: qsettings_p.h:312
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311

◆ initFormat()

void QConfFileSettingsPrivate::initFormat ( )
private

Definition at line 986 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate().

987 {
989  readFunc = 0;
990  writeFunc = 0;
991 #if defined(Q_OS_MAC)
993 #else
995 #endif
996 
998  QMutexLocker locker(globalMutex());
999  const CustomFormatVector *customFormatVector = customFormatVectorFunc();
1000 
1001  int i = (int)format - (int)QSettings::CustomFormat1;
1002  if (i >= 0 && i < customFormatVector->size()) {
1003  QConfFileCustomFormat info = customFormatVector->at(i);
1004  extension = info.extension;
1005  readFunc = info.readFunc;
1006  writeFunc = info.writeFunc;
1008  }
1009  }
1010 }
Qt::CaseSensitivity caseSensitivity
Definition: qsettings_p.h:315
static mach_timebase_info_data_t info
QSettings::WriteFunc writeFunc
Definition: qsettings.cpp:112
QSettings::WriteFunc writeFunc
Definition: qsettings_p.h:313
QSettings::ReadFunc readFunc
Definition: qsettings.cpp:111
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
Qt::CaseSensitivity caseSensitivity
Definition: qsettings.cpp:113
QSettings::ReadFunc readFunc
Definition: qsettings_p.h:312
static const Qt::CaseSensitivity IniCaseSensitivity
Definition: qsettings_p.h:81
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ isWritable()

bool QConfFileSettingsPrivate::isWritable ( ) const
virtual

Implements QSettingsPrivate.

Definition at line 1396 of file qsettings.cpp.

1397 {
1399  return false;
1400 
1401  QConfFile *confFile = confFiles[spec].data();
1402  if (!confFile)
1403  return false;
1404 
1405  return confFile->isWritable();
1406 }
T * data() const
Returns the value of the pointer referenced by this object.
QSettings::WriteFunc writeFunc
Definition: qsettings_p.h:313
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311
bool isWritable() const
Definition: qsettings.cpp:247

◆ readIniFile()

bool QConfFileSettingsPrivate::readIniFile ( const QByteArray data,
UnparsedSettingsMap unparsedIniSections 
)
static

Definition at line 1727 of file qsettings.cpp.

Referenced by syncConfFile().

1729 {
1730 #define FLUSH_CURRENT_SECTION() \
1731  { \
1732  QByteArray &sectionData = (*unparsedIniSections)[QSettingsKey(currentSection, \
1733  IniCaseSensitivity, \
1734  sectionPosition)]; \
1735  if (!sectionData.isEmpty()) \
1736  sectionData.append('\n'); \
1737  sectionData += data.mid(currentSectionStart, lineStart - currentSectionStart); \
1738  sectionPosition = ++position; \
1739  }
1740 
1741  QString currentSection;
1742  int currentSectionStart = 0;
1743  int dataPos = 0;
1744  int lineStart;
1745  int lineLen;
1746  int equalsPos;
1747  int position = 0;
1748  int sectionPosition = 0;
1749  bool ok = true;
1750 
1751  while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) {
1752  char ch = data.at(lineStart);
1753  if (ch == '[') {
1755 
1756  // this is a section
1757  QByteArray iniSection;
1758  int idx = data.indexOf(']', lineStart);
1759  if (idx == -1 || idx >= lineStart + lineLen) {
1760  ok = false;
1761  iniSection = data.mid(lineStart + 1, lineLen - 1);
1762  } else {
1763  iniSection = data.mid(lineStart + 1, idx - lineStart - 1);
1764  }
1765 
1766  iniSection = iniSection.trimmed();
1767 
1768  if (qstricmp(iniSection, "general") == 0) {
1769  currentSection.clear();
1770  } else {
1771  if (qstricmp(iniSection, "%general") == 0) {
1772  currentSection = QLatin1String(iniSection.constData() + 1);
1773  } else {
1774  currentSection.clear();
1775  iniUnescapedKey(iniSection, 0, iniSection.size(), currentSection);
1776  }
1777  currentSection += QLatin1Char('/');
1778  }
1779  currentSectionStart = dataPos;
1780  }
1781  ++position;
1782  }
1783 
1784  Q_ASSERT(lineStart == data.length());
1786 
1787  return ok;
1788 
1789 #undef FLUSH_CURRENT_SECTION
1790 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
#define FLUSH_CURRENT_SECTION()
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static bool readIniLine(const QByteArray &data, int &dataPos, int &lineStart, int &lineLen, int &equalsPos)
Definition: qsettings.cpp:1659
Q_CORE_EXPORT int qstricmp(const char *, const char *)
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static bool iniUnescapedKey(const QByteArray &key, int from, int to, QString &result)
Definition: qsettings.cpp:623

◆ readIniLine()

bool QConfFileSettingsPrivate::readIniLine ( const QByteArray data,
int &  dataPos,
int &  lineStart,
int &  lineLen,
int &  equalsPos 
)
static

Definition at line 1659 of file qsettings.cpp.

Referenced by readIniFile(), and readIniSection().

1661 {
1662  int dataLen = data.length();
1663  bool inQuotes = false;
1664 
1665  equalsPos = -1;
1666 
1667  lineStart = dataPos;
1668  while (lineStart < dataLen && (charTraits[uint(uchar(data.at(lineStart)))] & Space))
1669  ++lineStart;
1670 
1671  int i = lineStart;
1672  while (i < dataLen) {
1673  while (!(charTraits[uint(uchar(data.at(i)))] & Special)) {
1674  if (++i == dataLen)
1675  goto break_out_of_outer_loop;
1676  }
1677 
1678  char ch = data.at(i++);
1679  if (ch == '=') {
1680  if (!inQuotes && equalsPos == -1)
1681  equalsPos = i - 1;
1682  } else if (ch == '\n' || ch == '\r') {
1683  if (i == lineStart + 1) {
1684  ++lineStart;
1685  } else if (!inQuotes) {
1686  --i;
1687  goto break_out_of_outer_loop;
1688  }
1689  } else if (ch == '\\') {
1690  if (i < dataLen) {
1691  char ch = data.at(i++);
1692  if (i < dataLen) {
1693  char ch2 = data.at(i);
1694  // \n, \r, \r\n, and \n\r are legitimate line terminators in INI files
1695  if ((ch == '\n' && ch2 == '\r') || (ch == '\r' && ch2 == '\n'))
1696  ++i;
1697  }
1698  }
1699  } else if (ch == '"') {
1700  inQuotes = !inQuotes;
1701  } else {
1702  Q_ASSERT(ch == ';');
1703 
1704  if (i == lineStart + 1) {
1705  char ch;
1706  while (i < dataLen && ((ch = data.at(i) != '\n') && ch != '\r'))
1707  ++i;
1708  lineStart = i;
1709  } else if (!inQuotes) {
1710  --i;
1711  goto break_out_of_outer_loop;
1712  }
1713  }
1714  }
1715 
1716 break_out_of_outer_loop:
1717  dataPos = i;
1718  lineLen = i - lineStart;
1719  return lineLen > 0;
1720 }
static const char charTraits[256]
Definition: qsettings.cpp:1635
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996
int length() const
Same as size().
Definition: qbytearray.h:356
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413

◆ readIniSection()

bool QConfFileSettingsPrivate::readIniSection ( const QSettingsKey section,
const QByteArray data,
ParsedSettingsMap settingsMap,
QTextCodec codec 
)
static

Definition at line 1792 of file qsettings.cpp.

Referenced by ensureAllSectionsParsed(), and ensureSectionParsed().

1794 {
1795  QStringList strListValue;
1796  bool sectionIsLowercase = (section == section.originalCaseKey());
1797  int equalsPos;
1798 
1799  bool ok = true;
1800  int dataPos = 0;
1801  int lineStart;
1802  int lineLen;
1803  int position = section.originalKeyPosition();
1804 
1805  while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) {
1806  char ch = data.at(lineStart);
1807  Q_ASSERT(ch != '[');
1808 
1809  if (equalsPos == -1) {
1810  if (ch != ';')
1811  ok = false;
1812  continue;
1813  }
1814 
1815  int keyEnd = equalsPos;
1816  while (keyEnd > lineStart && ((ch = data.at(keyEnd - 1)) == ' ' || ch == '\t'))
1817  --keyEnd;
1818  int valueStart = equalsPos + 1;
1819 
1820  QString key = section.originalCaseKey();
1821  bool keyIsLowercase = (iniUnescapedKey(data, lineStart, keyEnd, key) && sectionIsLowercase);
1822 
1823  QString strValue;
1824  strValue.reserve(lineLen - (valueStart - lineStart));
1825  bool isStringList = iniUnescapedStringList(data, valueStart, lineStart + lineLen,
1826  strValue, strListValue, codec);
1827  QVariant variant;
1828  if (isStringList) {
1829  variant = stringListToVariantList(strListValue);
1830  } else {
1831  variant = stringToVariant(strValue);
1832  }
1833 
1834  /*
1835  We try to avoid the expensive toLower() call in
1836  QSettingsKey by passing Qt::CaseSensitive when the
1837  key is already in lowercase.
1838  */
1839  settingsMap->insert(QSettingsKey(key, keyIsLowercase ? Qt::CaseSensitive
1841  position),
1842  variant);
1843  ++position;
1844  }
1845 
1846  return ok;
1847 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QString originalCaseKey() const
Definition: qsettings_p.h:89
static bool iniUnescapedStringList(const QByteArray &str, int from, int to, QString &stringResult, QStringList &stringListResult, QTextCodec *codec)
Definition: qsettings.cpp:789
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const Qt::CaseSensitivity IniCaseSensitivity
Definition: qsettings_p.h:81
int originalKeyPosition() const
Definition: qsettings_p.h:90
static QVariant stringListToVariantList(const QStringList &l)
Definition: qsettings.cpp:444
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
int key
static bool readIniLine(const QByteArray &data, int &dataPos, int &lineStart, int &lineLen, int &equalsPos)
Definition: qsettings.cpp:1659
static QVariant stringToVariant(const QString &s)
Definition: qsettings.cpp:551
const char * variant
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
static bool iniUnescapedKey(const QByteArray &key, int from, int to, QString &result)
Definition: qsettings.cpp:623

◆ readPlistFile()

bool QConfFileSettingsPrivate::readPlistFile ( const QString fileName,
ParsedSettingsMap map 
) const
private

Definition at line 677 of file qsettings_mac.cpp.

Referenced by syncConfFile().

678 {
679  QCFType<CFDataRef> resource;
680  SInt32 code;
681  if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, urlFromFileName(fileName),
682  &resource, 0, 0, &code))
683  return false;
684 
685  QCFString errorStr;
686  QCFType<CFPropertyListRef> propertyList =
687  CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resource, kCFPropertyListImmutable,
688  &errorStr);
689 
690  if (!propertyList)
691  return true;
692  if (CFGetTypeID(propertyList) != CFDictionaryGetTypeID())
693  return false;
694 
695  CFDictionaryRef cfdict =
696  static_cast<CFDictionaryRef>(static_cast<CFPropertyListRef>(propertyList));
697  int size = (int)CFDictionaryGetCount(cfdict);
700  CFDictionaryGetKeysAndValues(cfdict, keys.data(), values.data());
701 
702  for (int i = 0; i < size; ++i) {
703  QString key = qtKey(static_cast<CFStringRef>(keys[i]));
705  }
706  return true;
707 }
static QVariant qtValue(CFPropertyListRef cfvalue)
static QCFType< CFURLRef > urlFromFileName(const QString &fileName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QStringList keys
quint16 values[128]
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
int key
static QString qtKey(CFStringRef cfkey)

◆ remove()

void QConfFileSettingsPrivate::remove ( const QString key)
virtual

Implements QSettingsPrivate.

Definition at line 1245 of file qsettings.cpp.

1246 {
1247  QConfFile *confFile = confFiles[spec].data();
1248  if (!confFile)
1249  return;
1250 
1251  QSettingsKey theKey(key, caseSensitivity);
1252  QSettingsKey prefix(key + QLatin1Char('/'), caseSensitivity);
1253  QMutexLocker locker(&confFile->mutex);
1254 
1255  ensureSectionParsed(confFile, theKey);
1256  ensureSectionParsed(confFile, prefix);
1257 
1258  ParsedSettingsMap::iterator i = confFile->addedKeys.lowerBound(prefix);
1259  while (i != confFile->addedKeys.end() && i.key().startsWith(prefix))
1260  i = confFile->addedKeys.erase(i);
1261  confFile->addedKeys.remove(theKey);
1262 
1263  ParsedSettingsMap::const_iterator j = const_cast<const ParsedSettingsMap *>(&confFile->originalKeys)->lowerBound(prefix);
1264  while (j != confFile->originalKeys.constEnd() && j.key().startsWith(prefix)) {
1265  confFile->removedKeys.insert(j.key(), QVariant());
1266  ++j;
1267  }
1268  if (confFile->originalKeys.contains(theKey))
1269  confFile->removedKeys.insert(theKey, QVariant());
1270 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
Qt::CaseSensitivity caseSensitivity
Definition: qsettings_p.h:315
T * data() const
Returns the value of the pointer referenced by this object.
ParsedSettingsMap addedKeys
Definition: qsettings_p.h:166
QMutex mutex
Definition: qsettings_p.h:169
void ensureSectionParsed(QConfFile *confFile, const QSettingsKey &key) const
Definition: qsettings.cpp:1982
int remove(const Key &key)
Removes all the items that have the key key from the map.
Definition: qmap.h:662
ParsedSettingsMap originalKeys
Definition: qsettings_p.h:165
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
ParsedSettingsMap removedKeys
Definition: qsettings_p.h:167
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
iterator lowerBound(const Key &key)
Returns an iterator pointing to the first item with key key in the map.
Definition: qmap.h:899
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311
friend class const_iterator
Definition: qmap.h:369

◆ set()

void QConfFileSettingsPrivate::set ( const QString key,
const QVariant value 
)
virtual

Implements QSettingsPrivate.

Definition at line 1272 of file qsettings.cpp.

1273 {
1274  QConfFile *confFile = confFiles[spec].data();
1275  if (!confFile)
1276  return;
1277 
1278  QSettingsKey theKey(key, caseSensitivity, nextPosition++);
1279  QMutexLocker locker(&confFile->mutex);
1280  confFile->removedKeys.remove(theKey);
1281  confFile->addedKeys.insert(theKey, value);
1282 }
Qt::CaseSensitivity caseSensitivity
Definition: qsettings_p.h:315
T * data() const
Returns the value of the pointer referenced by this object.
ParsedSettingsMap addedKeys
Definition: qsettings_p.h:166
QMutex mutex
Definition: qsettings_p.h:169
int remove(const Key &key)
Removes all the items that have the key key from the map.
Definition: qmap.h:662
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
ParsedSettingsMap removedKeys
Definition: qsettings_p.h:167
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311

◆ sync()

void QConfFileSettingsPrivate::sync ( )
virtual

Implements QSettingsPrivate.

Definition at line 1369 of file qsettings.cpp.

Referenced by flush().

1370 {
1371  // people probably won't be checking the status a whole lot, so in case of
1372  // error we just try to go on and make the best of it
1373 
1374  for (int i = 0; i < NumConfFiles; ++i) {
1375  QConfFile *confFile = confFiles[i].data();
1376  if (confFile) {
1377  QMutexLocker locker(&confFile->mutex);
1378  syncConfFile(i);
1379  }
1380  }
1381 }
T * data() const
Returns the value of the pointer referenced by this object.
void syncConfFile(int confFileNo)
Definition: qsettings.cpp:1408
QMutex mutex
Definition: qsettings_p.h:169
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311

◆ syncConfFile()

void QConfFileSettingsPrivate::syncConfFile ( int  confFileNo)
private

Definition at line 1408 of file qsettings.cpp.

Referenced by sync().

1409 {
1410  QConfFile *confFile = confFiles[confFileNo].data();
1411  bool readOnly = confFile->addedKeys.isEmpty() && confFile->removedKeys.isEmpty();
1412  bool ok;
1413 
1414  /*
1415  We can often optimize the read-only case, if the file on disk
1416  hasn't changed.
1417  */
1418  if (readOnly && confFile->size > 0) {
1419  QFileInfo fileInfo(confFile->name);
1420  if (confFile->size == fileInfo.size() && confFile->timeStamp == fileInfo.lastModified())
1421  return;
1422  }
1423 
1424  /*
1425  Open the configuration file and try to use it using a named
1426  semaphore on Windows and an advisory lock on Unix-based
1427  systems. This protect us against other QSettings instances
1428  trying to access the same file from other threads or
1429  processes.
1430 
1431  As it stands now, the locking mechanism doesn't work for
1432  .plist files.
1433  */
1434  QFile file(confFile->name);
1435  bool createFile = !file.exists();
1436  if (!readOnly && confFile->isWritable())
1437  file.open(QFile::ReadWrite);
1438  if (!file.isOpen())
1439  file.open(QFile::ReadOnly);
1440 
1441  if (!createFile && !file.isOpen())
1443 
1444 #ifdef Q_OS_WIN
1445  HANDLE readSemaphore = 0;
1446  HANDLE writeSemaphore = 0;
1447  static const int FileLockSemMax = 50;
1448  int numReadLocks = readOnly ? 1 : FileLockSemMax;
1449 
1450  if (file.isOpen()) {
1451  // Acquire the write lock if we will be writing
1452  if (!readOnly) {
1453  QString writeSemName = QLatin1String("QSettingsWriteSem ");
1454  writeSemName.append(file.fileName());
1455 
1456  writeSemaphore = CreateSemaphore(0, 1, 1, reinterpret_cast<const wchar_t *>(writeSemName.utf16()));
1457 
1458  if (writeSemaphore) {
1459  WaitForSingleObject(writeSemaphore, INFINITE);
1460  } else {
1462  return;
1463  }
1464  }
1465 
1466  // Acquire all the read locks if we will be writing, to make sure nobody
1467  // reads while we're writing. If we are only reading, acquire a single
1468  // read lock.
1469  QString readSemName(QLatin1String("QSettingsReadSem "));
1470  readSemName.append(file.fileName());
1471 
1472  readSemaphore = CreateSemaphore(0, FileLockSemMax, FileLockSemMax, reinterpret_cast<const wchar_t *>(readSemName.utf16()));
1473 
1474  if (readSemaphore) {
1475  for (int i = 0; i < numReadLocks; ++i)
1476  WaitForSingleObject(readSemaphore, INFINITE);
1477  } else {
1479  if (writeSemaphore != 0) {
1480  ReleaseSemaphore(writeSemaphore, 1, 0);
1481  CloseHandle(writeSemaphore);
1482  }
1483  return;
1484  }
1485  }
1486 #else
1487  if (file.isOpen())
1488  unixLock(file.handle(), readOnly ? F_RDLCK : F_WRLCK);
1489 #endif
1490 
1491  // If we have created the file, apply the file perms
1492  if (file.isOpen()) {
1493  if (createFile) {
1494  QFile::Permissions perms = file.permissions() | QFile::ReadOwner | QFile::WriteOwner;
1495  if (!confFile->userPerms)
1497  file.setPermissions(perms);
1498  }
1499  }
1500 
1501  /*
1502  We hold the lock. Let's reread the file if it has changed
1503  since last time we read it.
1504  */
1505  QFileInfo fileInfo(confFile->name);
1506  bool mustReadFile = true;
1507 
1508  if (!readOnly)
1509  mustReadFile = (confFile->size != fileInfo.size()
1510  || (confFile->size != 0 && confFile->timeStamp != fileInfo.lastModified()));
1511 
1512  if (mustReadFile) {
1513  confFile->unparsedIniSections.clear();
1514  confFile->originalKeys.clear();
1515 
1516  /*
1517  Files that we can't read (because of permissions or
1518  because they don't exist) are treated as empty files.
1519  */
1520  if (file.isReadable() && fileInfo.size() != 0) {
1521 #ifdef Q_OS_MAC
1523  ok = readPlistFile(confFile->name, &confFile->originalKeys);
1524  } else
1525 #endif
1526  {
1527  if (format <= QSettings::IniFormat) {
1528  QByteArray data = file.readAll();
1529  ok = readIniFile(data, &confFile->unparsedIniSections);
1530  } else {
1531  if (readFunc) {
1532  QSettings::SettingsMap tempNewKeys;
1533  ok = readFunc(file, tempNewKeys);
1534 
1535  if (ok) {
1537  while (i != tempNewKeys.constEnd()) {
1538  confFile->originalKeys.insert(QSettingsKey(i.key(),
1539  caseSensitivity),
1540  i.value());
1541  ++i;
1542  }
1543  }
1544  } else {
1545  ok = false;
1546  }
1547  }
1548  }
1549 
1550  if (!ok)
1552  }
1553 
1554  confFile->size = fileInfo.size();
1555  confFile->timeStamp = fileInfo.lastModified();
1556  }
1557 
1558  /*
1559  We also need to save the file. We still hold the file lock,
1560  so everything is under control.
1561  */
1562  if (!readOnly) {
1563  ensureAllSectionsParsed(confFile);
1564  ParsedSettingsMap mergedKeys = confFile->mergedKeyMap();
1565 
1566  if (file.isWritable()) {
1567 #ifdef Q_OS_MAC
1569  ok = writePlistFile(confFile->name, mergedKeys);
1570  } else
1571 #endif
1572  {
1573  file.seek(0);
1574  file.resize(0);
1575 
1576  if (format <= QSettings::IniFormat) {
1577  ok = writeIniFile(file, mergedKeys);
1578  if (!ok) {
1579  // try to restore old data; might work if the disk was full and the new data
1580  // was larger than the old data
1581  file.seek(0);
1582  file.resize(0);
1583  writeIniFile(file, confFile->originalKeys);
1584  }
1585  } else {
1586  if (writeFunc) {
1587  QSettings::SettingsMap tempOriginalKeys;
1588 
1590  while (i != mergedKeys.constEnd()) {
1591  tempOriginalKeys.insert(i.key(), i.value());
1592  ++i;
1593  }
1594  ok = writeFunc(file, tempOriginalKeys);
1595  } else {
1596  ok = false;
1597  }
1598  }
1599  }
1600  } else {
1601  ok = false;
1602  }
1603 
1604  if (ok) {
1605  confFile->unparsedIniSections.clear();
1606  confFile->originalKeys = mergedKeys;
1607  confFile->addedKeys.clear();
1608  confFile->removedKeys.clear();
1609 
1610  QFileInfo fileInfo(confFile->name);
1611  confFile->size = fileInfo.size();
1612  confFile->timeStamp = fileInfo.lastModified();
1613  } else {
1615  }
1616  }
1617 
1618  /*
1619  Release the file lock.
1620  */
1621 #ifdef Q_OS_WIN
1622  if (readSemaphore != 0) {
1623  ReleaseSemaphore(readSemaphore, numReadLocks, 0);
1624  CloseHandle(readSemaphore);
1625  }
1626  if (writeSemaphore != 0) {
1627  ReleaseSemaphore(writeSemaphore, 1, 0);
1628  CloseHandle(writeSemaphore);
1629  }
1630 #endif
1631 }
void setStatus(QSettings::Status status) const
Definition: qsettings.cpp:410
Qt::CaseSensitivity caseSensitivity
Definition: qsettings_p.h:315
bool readPlistFile(const QString &fileName, ParsedSettingsMap *map) const
ParsedSettingsMap mergedKeyMap() const
Definition: qsettings.cpp:235
T * data() const
Returns the value of the pointer referenced by this object.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QSettings::WriteFunc writeFunc
Definition: qsettings_p.h:313
bool writePlistFile(const QString &fileName, const ParsedSettingsMap &map) const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QDateTime timeStamp
Definition: qsettings_p.h:162
QString name
Definition: qsettings_p.h:161
The QString class provides a Unicode character string.
Definition: qstring.h:83
QSettings::ReadFunc readFunc
Definition: qsettings_p.h:312
ParsedSettingsMap addedKeys
Definition: qsettings_p.h:166
static const char * data(const QByteArray &arr)
void ensureAllSectionsParsed(QConfFile *confFile) const
Definition: qsettings.cpp:1970
void * HANDLE
Definition: qnamespace.h:1671
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
ParsedSettingsMap originalKeys
Definition: qsettings_p.h:165
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
QString & append(QChar c)
Definition: qstring.cpp:1777
bool userPerms
Definition: qsettings_p.h:170
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
ParsedSettingsMap removedKeys
Definition: qsettings_p.h:167
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
UnparsedSettingsMap unparsedIniSections
Definition: qsettings_p.h:164
bool writeIniFile(QIODevice &device, const ParsedSettingsMap &map)
Definition: qsettings.cpp:1881
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
qint64 size
Definition: qsettings_p.h:163
void clear()
Removes all items from the map.
Definition: qmap.h:444
QScopedSharedPointer< QConfFile > confFiles[NumConfFiles]
Definition: qsettings_p.h:311
static bool readIniFile(const QByteArray &data, UnparsedSettingsMap *unparsedIniSections)
Definition: qsettings.cpp:1727
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
friend class const_iterator
Definition: qmap.h:369
bool isWritable() const
Definition: qsettings.cpp:247

◆ writeIniFile()

bool QConfFileSettingsPrivate::writeIniFile ( QIODevice device,
const ParsedSettingsMap map 
)
private

Definition at line 1881 of file qsettings.cpp.

Referenced by syncConfFile().

1882 {
1883  IniMap iniMap;
1885 
1886 #ifdef Q_OS_WIN
1887  const char * const eol = "\r\n";
1888 #else
1889  const char eol = '\n';
1890 #endif
1891 
1892  for (ParsedSettingsMap::const_iterator j = map.constBegin(); j != map.constEnd(); ++j) {
1893  QString section;
1894  QSettingsIniKey key(j.key().originalCaseKey(), j.key().originalKeyPosition());
1895  int slashPos;
1896 
1897  if ((slashPos = key.indexOf(QLatin1Char('/'))) != -1) {
1898  section = key.left(slashPos);
1899  key.remove(0, slashPos + 1);
1900  }
1901 
1902  QSettingsIniSection &iniSection = iniMap[section];
1903 
1904  // -1 means infinity
1905  if (uint(key.position) < uint(iniSection.position))
1906  iniSection.position = key.position;
1907  iniSection.keyMap[key] = j.value();
1908  }
1909 
1910  const int sectionCount = iniMap.size();
1911  QVector<QSettingsIniKey> sections;
1912  sections.reserve(sectionCount);
1913  for (i = iniMap.constBegin(); i != iniMap.constEnd(); ++i)
1914  sections.append(QSettingsIniKey(i.key(), i.value().position));
1915  qSort(sections);
1916 
1917  bool writeError = false;
1918  for (int j = 0; !writeError && j < sectionCount; ++j) {
1919  i = iniMap.constFind(sections.at(j));
1920  Q_ASSERT(i != iniMap.constEnd());
1921 
1922  QByteArray realSection;
1923 
1924  iniEscapedKey(i.key(), realSection);
1925 
1926  if (realSection.isEmpty()) {
1927  realSection = "[General]";
1928  } else if (qstricmp(realSection, "general") == 0) {
1929  realSection = "[%General]";
1930  } else {
1931  realSection.prepend('[');
1932  realSection.append(']');
1933  }
1934 
1935  if (j != 0)
1936  realSection.prepend(eol);
1937  realSection += eol;
1938 
1939  device.write(realSection);
1940 
1941  const IniKeyMap &ents = i.value().keyMap;
1942  for (IniKeyMap::const_iterator j = ents.constBegin(); j != ents.constEnd(); ++j) {
1943  QByteArray block;
1944  iniEscapedKey(j.key(), block);
1945  block += '=';
1946 
1947  const QVariant &value = j.value();
1948 
1949  /*
1950  The size() != 1 trick is necessary because
1951  QVariant(QString("foo")).toList() returns an empty
1952  list, not a list containing "foo".
1953  */
1954  if (value.type() == QVariant::StringList
1955  || (value.type() == QVariant::List && value.toList().size() != 1)) {
1957  } else {
1958  iniEscapedString(variantToString(value), block, iniCodec);
1959  }
1960  block += eol;
1961  if (device.write(block) == -1) {
1962  writeError = true;
1963  break;
1964  }
1965  }
1966  }
1967  return !writeError;
1968 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
const Key & key() const
Returns the current item&#39;s key.
Definition: qmap.h:324
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QStringList variantListToStringList(const QVariantList &l)
Definition: qsettings.cpp:435
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
unsigned int uint
Definition: qglobal.h:996
static QString variantToString(const QVariant &v)
Definition: qsettings.cpp:464
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static void iniEscapedKey(const QString &key, QByteArray &result)
Definition: qsettings.cpp:596
QTextCodec * iniCodec
Definition: qsettings_p.h:262
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const T & value() const
Returns the current item&#39;s value.
Definition: qmap.h:325
const_iterator constFind(const Key &key) const
Returns an const iterator pointing to the item with key key in the map.
Definition: qmap.h:612
static void iniEscapedString(const QString &str, QByteArray &result, QTextCodec *codec)
Definition: qsettings.cpp:679
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
Q_CORE_EXPORT int qstricmp(const char *, const char *)
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
static void iniEscapedStringList(const QStringList &strs, QByteArray &result, QTextCodec *codec)
Definition: qsettings.cpp:766
friend class const_iterator
Definition: qmap.h:369

◆ writePlistFile()

bool QConfFileSettingsPrivate::writePlistFile ( const QString fileName,
const ParsedSettingsMap map 
) const
private

Definition at line 709 of file qsettings_mac.cpp.

Referenced by syncConfFile().

711 {
714  int i = 0;
716  for (j = map.constBegin(); j != map.constEnd(); ++j) {
717  cfkeys[i] = macKey(j.key());
718  cfvalues[i] = macValue(j.value());
719  ++i;
720  }
721 
722  QCFType<CFDictionaryRef> propertyList =
723  CFDictionaryCreate(kCFAllocatorDefault,
724  reinterpret_cast<const void **>(cfkeys.data()),
725  reinterpret_cast<const void **>(cfvalues.data()),
726  CFIndex(map.size()),
727  &kCFTypeDictionaryKeyCallBacks,
728  &kCFTypeDictionaryValueCallBacks);
729 
730  QCFType<CFDataRef> xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, propertyList);
731 
732  SInt32 code;
733  return CFURLWriteDataAndPropertiesToResource(urlFromFileName(fileName), xmlData, 0, &code);
734 }
static QCFType< CFStringRef > macKey(const QString &key)
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
static QCFType< CFURLRef > urlFromFileName(const QString &fileName)
static QCFType< CFPropertyListRef > macValue(const QVariant &value)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
friend class const_iterator
Definition: qmap.h:369

Properties

◆ caseSensitivity

Qt::CaseSensitivity QConfFileSettingsPrivate::caseSensitivity
private

Definition at line 315 of file qsettings_p.h.

Referenced by children(), get(), remove(), set(), and syncConfFile().

◆ confFiles

QScopedSharedPointer<QConfFile> QConfFileSettingsPrivate::confFiles[NumConfFiles]
private

◆ extension

QString QConfFileSettingsPrivate::extension
private

Definition at line 314 of file qsettings_p.h.

Referenced by QConfFileSettingsPrivate().

◆ nextPosition

int QConfFileSettingsPrivate::nextPosition
private

Definition at line 316 of file qsettings_p.h.

Referenced by set().

◆ readFunc

QSettings::ReadFunc QConfFileSettingsPrivate::readFunc
private

Definition at line 312 of file qsettings_p.h.

Referenced by syncConfFile().

◆ writeFunc

QSettings::WriteFunc QConfFileSettingsPrivate::writeFunc
private

Definition at line 313 of file qsettings_p.h.

Referenced by isWritable(), and syncConfFile().


The documentation for this class was generated from the following files: