-rw-r--r-- | qmake/tools/qsettings.cpp | 371 |
1 files changed, 191 insertions, 180 deletions
diff --git a/qmake/tools/qsettings.cpp b/qmake/tools/qsettings.cpp index 35fc039..598e94b 100644 --- a/qmake/tools/qsettings.cpp +++ b/qmake/tools/qsettings.cpp @@ -1,4 +1,4 @@ /**************************************************************************** -** $Id$ +** ** ** Implementation of QSettings class @@ -6,5 +6,5 @@ ** Created : 000626 ** -** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. ** ** This file is part of the tools module of the Qt GUI Toolkit. @@ -61,5 +61,7 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) #include "qregexp.h" #include <private/qsettings_p.h> +#ifndef NO_ERRNO_H #include <errno.h> +#endif /*! @@ -102,5 +104,6 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) Each line above is a complete key, made up of subkeys. - A typical usage pattern for reading application startup: + A typical usage pattern for reading settings at application + startup: \code QSettings settings; @@ -112,5 +115,6 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) \endcode - A typical usage pattern for application exit or 'save preferences': + A typical usage pattern for saving settings at application exit or + 'save preferences': \code QSettings settings; @@ -122,6 +126,7 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) \endcode - QSettings can build a key prefix that is prepended to all keys. To - build the key prefix, use beginGroup() and endGroup(). + A key prefix can be prepended to all keys using beginGroup(). The + application of the prefix is stopped using endGroup(). For + example: \code QSettings settings; @@ -155,6 +160,6 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) \endcode - Since settings for Windows are stored in the registry there are size - limits as follows: + Since settings for Windows are stored in the registry there are + some size limitations as follows: \list \i A subkey may not exceed 255 characters. @@ -166,20 +171,21 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) These limitations are not enforced on Unix or Mac OS X. - If you wish to use a different search path call insertSearchPath() - as often as necessary to add your preferred paths. Call - removeSearchPath() to remove any unwanted paths. + \warning Creating multiple, simultaneous instances of QSettings writing + to a text file may lead to data loss! This is a known issue which will + be fixed in a future release of Qt. \section1 Notes for Mac OS X Applications - Internal to the CFPreferences API it is not defined (for Mac OS 9 - support) where the settings will ultimitely be stored. However, at the - time of this writing the settings will be stored (either on a global or - user basis, preferring locally) into a plist file in - $ROOT/System/Library/Preferences (in XML format). QSettings will create - an appropriate plist file (com.<first group name>.plist) out of the - full path to a key. + The location where settings are stored is not formally defined by + the CFPreferences API. + + At the time of writing settings are stored (either on a global or + user basis, preferring locally) into a plist file in \c + $ROOT/System/Library/Preferences (in XML format). QSettings will + create an appropriate plist file (\c{com.<first group name>.plist}) + out of the full path to a key. - For further information on CFPreferences see also - \link http://developer.apple.com/techpubs/macosx/CoreFoundation/PreferenceServices/preferenceservices_carbon.html + For further information on CFPreferences see + \link http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFPreferences/index.html Apple's Specifications\endlink @@ -190,8 +196,8 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) searched for in the following directories: \list 1 - \i INSTALL/etc/settings - \i /opt/MyCompany/share/etc - \i /opt/MyCompany/share/MyApplication/etc - \i $HOME/.qt + \i \c SYSCONF - the default value is \c INSTALL/etc/settings + \i \c /opt/MyCompany/share/etc + \i \c /opt/MyCompany/share/MyApplication/etc + \i \c $HOME/.qt \endlist When reading settings the files are searched in the order shown @@ -218,6 +224,6 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) being run by an ordinary user, i.e. not by root). - For cross-platform applications you should ensure that the Windows - size limitations are not exceeded. + For cross-platform applications you should ensure that the + \link #sizelimit Windows size limitations \endlink are not exceeded. */ @@ -311,43 +317,4 @@ static void closelock( HANDLE fd ) close( fd ); } -#elif defined(Q_WS_WIN) -#define Q_LOCKREAD 1 -#define Q_LOCKWRITE 2 - -static HANDLE openlock( const QString &name, int /*type*/ ) -{ - if ( !QFile::exists( name ) ) - return 0; - - return 0; - - HANDLE fd = 0; - - QT_WA( { - fd = CreateFileW( (TCHAR*)name.ucs2(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); - } , { - fd = CreateFileA( name.local8Bit(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); - } ); - - if ( !LockFile( fd, 0, 0, (DWORD)-1, (DWORD)-1 ) ) { // ### (DWORD)-1 ??? -#ifdef QT_CHECK_STATE - qWarning( "QSettings: openlock failed!" ); -#endif - } - return fd; -} - -static void closelock( HANDLE fd ) -{ - if ( !fd ) - return; - - if ( !UnlockFile( fd, 0, 0, (DWORD)-1, (DWORD)-1 ) ) { // ### (DWORD)-1 ??? -#ifdef QT_CHECK_STATE - qWarning( "QSettings: closelock failed!"); -#endif - } - CloseHandle( fd ); -} #endif @@ -366,5 +333,7 @@ void QSettingsHeading::read(const QString &filename) return; +#ifndef Q_WS_WIN HANDLE lockfd = openlock( filename, Q_LOCKREAD ); +#endif QFile file(filename); @@ -387,5 +356,7 @@ void QSettingsHeading::read(const QString &filename) file.close(); +#ifndef Q_WS_WIN closelock( lockfd ); +#endif } @@ -405,5 +376,5 @@ void QSettingsHeading::parseLine(QTextStream &stream) QString gname = line; - gname = gname.remove(0, 1); + gname = gname.remove((uint)0, 1); if (gname[(int)gname.length() - 1] == QChar(']')) gname = gname.remove(gname.length() - 1, 1); @@ -527,9 +498,5 @@ QSettingsPrivate::QSettingsPrivate( QSettings::Format format ) #endif // Q_OS_TEMP #else -// for now -#define QSETTINGS_DEFAULT_PATH_SUFFIX "/etc/settings" - - defPath = qInstallPath(); - defPath += QSETTINGS_DEFAULT_PATH_SUFFIX; + defPath = qInstallPathSysconf(); #endif QDir dir(appSettings); @@ -702,25 +669,30 @@ QDateTime QSettingsPrivate::modificationTime() bool qt_verify_key( const QString &key ) { - if ( key.isEmpty() || key[0] != '/' || key.contains( QRegExp("[=\\\\r\\\\n" ) ) ) + if ( key.isEmpty() || key[0] != '/' || key.contains( QRegExp("[=\\r\\n]" ) ) ) return FALSE; return TRUE; } -static inline QString groupKey( const QString &group, const QString &key ) +static QString groupKey( const QString &group, const QString &key ) { + QString grp_key; if ( group.isEmpty() || ( group.length() == 1 && group[0] == '/' ) ) { // group is empty, or it contains a single '/', so we just return the key if ( key.startsWith( "/" ) ) - return key; - return "/" + key; + grp_key = key; + else + grp_key = "/" + key; } else if ( group.endsWith( "/" ) || key.startsWith( "/" ) ) { - return group + key; + grp_key = group + key; + } else { + grp_key = group + "/" + key; } - return group + "/" + key; + return grp_key; } /*! Inserts \a path into the settings search path. The semantics of \a - path depends on the system \a s. + path depends on the system \a s. It is usually easier and better to + use setPath() instead of this function. When \a s is \e Windows and the execution environment is \e not @@ -767,6 +739,7 @@ static inline QString groupKey( const QString &group, const QString &key ) \list 1 - \i INSTALL/etc - where \c INSTALL is the directory where Qt was installed. - \i $HOME/.qt/ - where \c $HOME is the user's home directory. + \i \c SYSCONF - where \c SYSCONF is a directory specified when + configuring Qt; by default it is INSTALL/etc/settings. + \i \c $HOME/.qt/ - where \c $HOME is the user's home directory. \endlist @@ -781,5 +754,5 @@ static inline QString groupKey( const QString &group, const QString &key ) Will result in a search path of: \list 1 - \i INSTALL/etc + \i SYSCONF \i /opt/MyCompany/share/etc \i /opt/MyCompany/share/MyApplication/etc @@ -792,4 +765,7 @@ static inline QString groupKey( const QString &group, const QString &key ) to the first settings file for which the user has write permission. + Note that paths in the file system are not created by this + function, so they must already exist to be useful. + Settings under Unix are stored in files whose names are based on the first subkey of the key (not including the search path). The algorithm @@ -816,5 +792,5 @@ void QSettings::insertSearchPath( System s, const QString &path) return; #endif -#if !defined(Q_WS_WIN) +#if !defined(Q_OS_MAC) if ( s == Mac ) return; @@ -965,5 +941,5 @@ bool QSettings::sync() QSettingsHeading hd(*it); QSettingsHeading::Iterator hdit = hd.begin(); - QFile file; + QString filename; QStringList::Iterator pit = d->searchPaths.begin(); @@ -973,9 +949,20 @@ bool QSettings::sync() QString filebase = it.key().lower().replace(QRegExp("\\s+"), "_"); QFileInfo di(*pit); + if ( !di.exists() ) { + QDir dir; + dir.mkdir( *pit ); + } + QFileInfo fi((*pit++) + "/" + filebase + "rc"); if ((fi.exists() && fi.isFile() && fi.isWritable()) || - (! fi.exists() && di.isDir() && di.isWritable())) { - file.setName(fi.filePath()); + (! fi.exists() && di.isDir() +#ifndef Q_WS_WIN + && di.isWritable() +#else + && ((qWinVersion()&Qt::WV_NT_based) > Qt::WV_2000 || di.isWritable()) +#endif + )) { + filename = fi.filePath(); break; } @@ -984,5 +971,5 @@ bool QSettings::sync() ++it; - if ( file.name().isEmpty() ) { + if ( filename.isEmpty() ) { #ifdef QT_CHECK_STATE @@ -994,6 +981,9 @@ bool QSettings::sync() } - HANDLE lockfd = openlock( file.name(), Q_LOCKWRITE ); +#ifndef Q_WS_WIN + HANDLE lockfd = openlock( filename, Q_LOCKWRITE ); +#endif + QFile file( filename + ".tmp" ); if (! file.open(IO_WriteOnly)) { @@ -1048,5 +1038,24 @@ bool QSettings::sync() file.close(); + if ( success ) { + QDir dir( QFileInfo( file ).dir( TRUE ) ); + if ( dir.exists( filename ) && !dir.remove( filename ) || + !dir.rename( file.name(), filename, TRUE ) ) { + +#ifdef QT_CHECK_STATE + qWarning( "QSettings::sync: error writing file '%s'", + QFile::encodeName( filename ).data() ); +#endif // QT_CHECK_STATE + + success = FALSE; + } + } + + // remove temporary file + file.remove(); + +#ifndef Q_WS_WIN closelock( lockfd ); +#endif } @@ -1073,7 +1082,8 @@ bool QSettings::sync() bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok ) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::readBoolEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::readBoolEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif if ( ok ) @@ -1085,5 +1095,5 @@ bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok ) #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysReadBoolEntry( groupKey( group(), key ), def, ok ); + return d->sysReadBoolEntry( grp_key, def, ok ); #endif @@ -1124,7 +1134,8 @@ bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok ) double QSettings::readDoubleEntry(const QString &key, double def, bool *ok ) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::readDoubleEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::readDoubleEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif if ( ok ) @@ -1136,5 +1147,5 @@ double QSettings::readDoubleEntry(const QString &key, double def, bool *ok ) #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysReadDoubleEntry( groupKey( group(), key ), def, ok ); + return d->sysReadDoubleEntry( grp_key, def, ok ); #endif @@ -1169,7 +1180,8 @@ double QSettings::readDoubleEntry(const QString &key, double def, bool *ok ) int QSettings::readNumEntry(const QString &key, int def, bool *ok ) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::readNumEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::readNumEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif if ( ok ) @@ -1180,5 +1192,5 @@ int QSettings::readNumEntry(const QString &key, int def, bool *ok ) #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysReadNumEntry( groupKey( group(), key ), def, ok ); + return d->sysReadNumEntry( grp_key, def, ok ); #endif @@ -1213,7 +1225,8 @@ int QSettings::readNumEntry(const QString &key, int def, bool *ok ) QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::readEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::readEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif if ( ok ) @@ -1223,9 +1236,7 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) } - QString theKey = groupKey( group(), key ); - #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysReadEntry( theKey, def, ok ); + return d->sysReadEntry( grp_key, def, ok ); #endif @@ -1235,11 +1246,11 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) QString realkey; - if (theKey[0] == '/') { + if (grp_key[0] == '/') { // parse our key - QStringList list(QStringList::split('/', theKey)); + QStringList list(QStringList::split('/', grp_key)); if (list.count() < 2) { #ifdef QT_CHECK_STATE - qWarning("QSettings::readEntry: invalid key '%s'", theKey.latin1()); + qWarning("QSettings::readEntry: invalid key '%s'", grp_key.latin1()); #endif // QT_CHECK_STATE if ( ok ) @@ -1263,6 +1274,7 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) realkey = list.join("/"); } - } else - realkey = theKey; + } else { + realkey = grp_key; + } QSettingsGroup grp = d->readGroup(); @@ -1291,7 +1303,8 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) bool QSettings::writeEntry(const QString &key, bool value) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::writeEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif return FALSE; @@ -1300,5 +1313,5 @@ bool QSettings::writeEntry(const QString &key, bool value) #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysWriteEntry( groupKey( group(), key ), value ); + return d->sysWriteEntry( grp_key, value ); #endif QString s(value ? "true" : "false"); @@ -1321,7 +1334,8 @@ bool QSettings::writeEntry(const QString &key, bool value) bool QSettings::writeEntry(const QString &key, double value) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::writeEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif return FALSE; @@ -1330,5 +1344,5 @@ bool QSettings::writeEntry(const QString &key, double value) #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysWriteEntry( groupKey( group(), key ), value ); + return d->sysWriteEntry( grp_key, value ); #endif QString s(QString::number(value)); @@ -1350,7 +1364,8 @@ bool QSettings::writeEntry(const QString &key, double value) bool QSettings::writeEntry(const QString &key, int value) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::writeEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif return FALSE; @@ -1359,5 +1374,5 @@ bool QSettings::writeEntry(const QString &key, int value) #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysWriteEntry( groupKey( group(), key ), value ); + return d->sysWriteEntry( grp_key, value ); #endif QString s(QString::number(value)); @@ -1384,11 +1399,4 @@ bool QSettings::writeEntry(const QString &key, int value) bool QSettings::writeEntry(const QString &key, const char *value) { - if ( !qt_verify_key( key ) ) { -#if defined(QT_CHECK_STATE) - qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); -#endif - return FALSE; - } - return writeEntry(key, QString(value)); } @@ -1409,16 +1417,15 @@ bool QSettings::writeEntry(const QString &key, const char *value) bool QSettings::writeEntry(const QString &key, const QString &value) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::writeEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif return FALSE; } - QString theKey = groupKey( group(), key ); - #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysWriteEntry( theKey, value ); + return d->sysWriteEntry( grp_key, value ); #endif // NOTE: we *do* allow value to be a null/empty string @@ -1426,11 +1433,11 @@ bool QSettings::writeEntry(const QString &key, const QString &value) QString realkey; - if (theKey[0] == '/') { + if (grp_key[0] == '/') { // parse our key - QStringList list(QStringList::split('/', theKey)); + QStringList list(QStringList::split('/', grp_key)); if (list.count() < 2) { #ifdef QT_CHECK_STATE - qWarning("QSettings::writeEntry: invalid key '%s'", theKey.latin1()); + qWarning("QSettings::writeEntry: invalid key '%s'", grp_key.latin1()); #endif // QT_CHECK_STATE @@ -1453,6 +1460,7 @@ bool QSettings::writeEntry(const QString &key, const QString &value) realkey = list.join("/"); } - } else - realkey = theKey; + } else { + realkey = grp_key; + } d->writeGroup(realkey, value); @@ -1470,27 +1478,25 @@ bool QSettings::writeEntry(const QString &key, const QString &value) bool QSettings::removeEntry(const QString &key) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::removeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::removeEntry: Invalid key: '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif return FALSE; } - QString theKey = groupKey( group(), key ); - #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysRemoveEntry( theKey ); + return d->sysRemoveEntry( grp_key ); #endif QString realkey; - - if (theKey[0] == '/') { + if (grp_key[0] == '/') { // parse our key - QStringList list(QStringList::split('/', theKey)); + QStringList list(QStringList::split('/', grp_key)); if (list.count() < 2) { #ifdef QT_CHECK_STATE - qWarning("QSettings::removeEntry: invalid key '%s'", theKey.latin1()); + qWarning("QSettings::removeEntry: invalid key '%s'", grp_key.latin1()); #endif // QT_CHECK_STATE @@ -1513,6 +1519,7 @@ bool QSettings::removeEntry(const QString &key) realkey = list.join("/"); } - } else - realkey = theKey; + } else { + realkey = grp_key; + } d->removeGroup(realkey); @@ -1549,26 +1556,25 @@ bool QSettings::removeEntry(const QString &key) QStringList QSettings::entryList(const QString &key) const { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::entryList: Invalid key: %s", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::entryList: Invalid key: %s", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif return QStringList(); } - QString theKey = groupKey( group(), key ); - #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysEntryList( theKey ); + return d->sysEntryList( grp_key ); #endif QString realkey; - if (theKey[0] == '/') { + if (grp_key[0] == '/') { // parse our key - QStringList list(QStringList::split('/', theKey)); + QStringList list(QStringList::split('/', grp_key)); if (list.count() < 1) { #ifdef QT_CHECK_STATE - qWarning("QSettings::listEntries: invalid key '%s'", theKey.latin1()); + qWarning("QSettings::listEntries: invalid key '%s'", grp_key.latin1()); #endif // QT_CHECK_STATE @@ -1591,5 +1597,5 @@ QStringList QSettings::entryList(const QString &key) const } } else - realkey = theKey; + realkey = grp_key; QSettingsGroup grp = d->readGroup(); @@ -1646,27 +1652,26 @@ QStringList QSettings::entryList(const QString &key) const QStringList QSettings::subkeyList(const QString &key) const { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::subkeyList: Invalid key: %s", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::subkeyList: Invalid key: %s", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif return QStringList(); } - QString theKey = groupKey( group(), key ); - #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) - return d->sysSubkeyList( theKey ); + return d->sysSubkeyList( grp_key ); #endif QString realkey; int subkeycount = 2; - if (theKey[0] == '/') { + if (grp_key[0] == '/') { // parse our key - QStringList list(QStringList::split('/', theKey)); + QStringList list(QStringList::split('/', grp_key)); if (list.count() < 1) { #ifdef QT_CHECK_STATE - qWarning("QSettings::subkeyList: invalid key '%s'", theKey.latin1()); + qWarning("QSettings::subkeyList: invalid key '%s'", grp_key.latin1()); #endif // QT_CHECK_STATE @@ -1692,5 +1697,5 @@ QStringList QSettings::subkeyList(const QString &key) const } else - realkey = theKey; + realkey = grp_key; QStringList ret; @@ -1738,15 +1743,14 @@ QStringList QSettings::subkeyList(const QString &key) const This function returns the time of last modification for \a key. */ -QDateTime QSettings::lastModficationTime(const QString &key) +QDateTime QSettings::lastModificationTime( const QString &key ) { - if ( !qt_verify_key( key ) ) { + QString grp_key( groupKey( group(), key ) ); + if ( !qt_verify_key( grp_key ) ) { #if defined(QT_CHECK_STATE) - qWarning( "QSettings::lastModficationTime: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); + qWarning( "QSettings::lastModificationTime: Invalid key '%s'", grp_key.isNull() ? "(null)" : grp_key.latin1() ); #endif return QDateTime(); } - QString theKey = groupKey( group(), key ); - #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) if ( d->sysd ) @@ -1754,11 +1758,11 @@ QDateTime QSettings::lastModficationTime(const QString &key) #endif - if (theKey[0] == '/') { + if (grp_key[0] == '/') { // parse our key - QStringList list(QStringList::split('/', theKey)); + QStringList list(QStringList::split('/', grp_key)); if (list.count() < 2) { #ifdef QT_CHECK_STATE - qWarning("QSettings::lastModficationTime: invalid key '%s'", theKey.latin1()); + qWarning("QSettings::lastModificationTime: Invalid key '%s'", grp_key.latin1()); #endif // QT_CHECK_STATE @@ -1781,4 +1785,5 @@ QDateTime QSettings::lastModficationTime(const QString &key) /*! \overload + \obsolete Writes the string list entry \a value into key \a key. The \a key @@ -1797,8 +1802,9 @@ QDateTime QSettings::lastModficationTime(const QString &key) that do not take a \a separator argument. + If an error occurs the settings are left unchanged and FALSE is returned; otherwise returns TRUE. - \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() + \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry(), QStringList::join() */ bool QSettings::writeEntry(const QString &key, const QStringList &value, @@ -1840,9 +1846,10 @@ bool QSettings::writeEntry(const QString &key, const QStringList &value) /*! \overload QStringList QSettings::readListEntry(const QString &key, const QChar &separator, bool *ok ) const + \obsolete Reads the entry specified by \a key as a string. The \a separator is used to create a QStringList by calling QStringList::split(\a - separator, entry). If \a ok is not 0: \a *ok is set to TRUE if the - key was read, otherwise \a *ok is set to FALSE. + separator, entry). If \a ok is not 0: \a *ok is set to TRUE + if the key was read, otherwise \a *ok is set to FALSE. \warning As the documentation states, QStringList::split() will @@ -1852,5 +1859,4 @@ bool QSettings::writeEntry(const QString &key, const QStringList &value) that do not take a \a separator argument. - Note that if you want to iterate over the list, you should iterate over a copy, e.g. @@ -1950,6 +1956,5 @@ void qt_setSettingsBasePath(const QString &); //qsettings_mac.cpp these will be read-only to many users). - Not all information is relevant on all systems (e.g. scoping is - currently used only if QSettings accesses the Windows registry). + Not all information is relevant on all systems. */ @@ -1981,11 +1986,17 @@ void QSettings::setPath( const QString &domain, const QString &product, Scope sc insertSearchPath( Windows, actualSearchPath ); #elif !defined(QWS) && defined(Q_OS_MAC) - QString topLevelDomain = domain.right( domain.length() - lastDot - 1 ) + "."; - if ( !topLevelDomain.isEmpty() ) - qt_setSettingsBasePath( topLevelDomain ); - actualSearchPath = "/" + domain.left( lastDot ) + product; + if(lastDot != -1) { + QString topLevelDomain = domain.right( domain.length() - lastDot - 1 ) + "."; + if ( !topLevelDomain.isEmpty() ) + qt_setSettingsBasePath( topLevelDomain ); + } + actualSearchPath = "/" + domain.left( lastDot ) + "." + product; insertSearchPath( Mac, actualSearchPath ); #else - actualSearchPath = "/" + domain.mid( 0, lastDot ) + "/" + product; + if (scope == User) + actualSearchPath = QDir::homeDirPath() + "/."; + else + actualSearchPath = QString(qInstallPathSysconf()) + "/"; + actualSearchPath += domain.mid( 0, lastDot ) + "/" + product; insertSearchPath( Unix, actualSearchPath ); #endif |