summaryrefslogtreecommitdiff
path: root/qmake/tools/qsettings.cpp
Side-by-side diff
Diffstat (limited to 'qmake/tools/qsettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qsettings.cpp371
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,14 +1,14 @@
/****************************************************************************
-** $Id$
+**
**
** Implementation of QSettings class
**
** 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.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
@@ -57,13 +57,15 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode )
#include "qfile.h"
#include "qfileinfo.h"
#include "qmap.h"
#include "qtextstream.h"
#include "qregexp.h"
#include <private/qsettings_p.h>
+#ifndef NO_ERRNO_H
#include <errno.h>
+#endif
/*!
\class QSettings
\brief The QSettings class provides persistent platform-independent application settings.
\ingroup io
@@ -98,34 +100,37 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode )
/MyCompany/MyApplication/recent files/1
/MyCompany/MyApplication/recent files/2
/MyCompany/MyApplication/recent files/3
\endcode
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;
settings.setPath( "MyCompany.com", "MyApplication" );
QString bgColor = settings.readEntry( "/colors/background", "white" );
int width = settings.readNumEntry( "/geometry/width", 640 );
// ...
\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;
settings.setPath( "MyCompany.com", "MyApplication" );
settings.writeEntry( "/colors/background", bgColor );
settings.writeEntry( "/geometry/width", width );
// ...
\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;
settings.beginGroup( "/MainWindow" );
settings.beginGroup( "/Geometry" );
int x = settings.readEntry( "/x" );
@@ -151,51 +156,52 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode )
// subkeys contains 'geometry' and 'recent files'
QStringList subkeys = subkeyList( "/MyApplication/recent files" );
// subkeys is empty.
\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.
\i An entry's value may not exceed 16,300 characters.
\i All the values of a key (for example, all the 'recent files'
subkeys values), may not exceed 65,535 characters.
\endlist
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
\section1 Notes for Unix Applications
There is no universally accepted place for storing application
settings under Unix. In the examples the settings file will be
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
above, with later settings overriding earlier settings. Files for
which the user doesn't have read permission are ignored. When saving
settings QSettings works in the order shown above, writing
to the first settings file for which the user has write permission.
@@ -214,14 +220,14 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode )
settings.writeEntry( "/MyApplication/geometry/width", width );
\endcode
will end up writing the "geometry/width" setting to the file
\c{$HOME/.qt/myapplicationrc} (assuming that the application is
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.
*/
/*!
\enum QSettings::System
\value Mac Macintosh execution environments
@@ -307,51 +313,12 @@ static void closelock( HANDLE fd )
fl.l_len = 0;
// ignore the return value, so that the unlock fails silently
(void) fcntl( fd, F_SETLKW, &fl );
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
QSettingsGroup::QSettingsGroup()
: modified(FALSE)
{
@@ -362,13 +329,15 @@ QSettingsGroup::QSettingsGroup()
void QSettingsHeading::read(const QString &filename)
{
if (! QFileInfo(filename).exists())
return;
+#ifndef Q_WS_WIN
HANDLE lockfd = openlock( filename, Q_LOCKREAD );
+#endif
QFile file(filename);
if (! file.open(IO_ReadOnly)) {
#if defined(QT_CHECK_STATE)
qWarning("QSettings: failed to open file '%s'", filename.latin1());
#endif
@@ -383,13 +352,15 @@ void QSettingsHeading::read(const QString &filename)
parseLine(stream);
git = end();
file.close();
+#ifndef Q_WS_WIN
closelock( lockfd );
+#endif
}
void QSettingsHeading::parseLine(QTextStream &stream)
{
QString line = stream.readLine();
@@ -401,13 +372,13 @@ void QSettingsHeading::parseLine(QTextStream &stream)
// commented line
return;
if (line[0] == QChar('[')) {
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);
git = find(gname);
if (git == end())
git = replace(gname, QSettingsGroup());
@@ -523,17 +494,13 @@ QSettingsPrivate::QSettingsPrivate( QSettings::Format format )
SHGetSpecialFolderPath( 0, path, CSIDL_COMMON_APPDATA, FALSE );
defPath = QString::fromLocal8Bit( path );
}
} );
#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);
if (! dir.exists()) {
if (! dir.mkdir(dir.path()))
#if defined(QT_CHECK_STATE)
qWarning("QSettings: error creating %s", dir.path().latin1());
@@ -698,33 +665,38 @@ QDateTime QSettingsPrivate::modificationTime()
return datetime;
}
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
Windows the function does nothing. Similarly when \a s is \e Unix and
the execution environment is \e not Unix the function does nothing.
When \a s is \e Windows, and the execution environment is Windows, the
@@ -763,37 +735,41 @@ static inline QString groupKey( const QString &group, const QString &key )
When \a s is \e Unix, and the execution environment is Unix, the
search path list will be used when trying to determine a suitable
filename for reading and writing settings files. By default, there are
two entries in the search path:
\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
All insertions into the search path will go before $HOME/.qt/.
For example:
\code
QSettings settings;
settings.insertSearchPath( QSettings::Unix, "/opt/MyCompany/share/etc" );
settings.insertSearchPath( QSettings::Unix, "/opt/MyCompany/share/MyApplication/etc" );
// ...
\endcode
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
\i $HOME/.qt
\endlist
When reading settings the files are searched in the order shown
above, with later settings overriding earlier settings. Files for
which the user doesn't have read permission are ignored. When saving
settings QSettings works in the order shown above, writing
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
for creating names is essentially: lowercase the first subkey, replace
spaces with underscores and add 'rc', e.g.
<tt>/MyCompany/MyApplication/background color</tt> will be stored in
<tt>myapplicationrc</tt> (assuming that <tt>/MyCompany</tt> is part of
@@ -812,13 +788,13 @@ void QSettings::insertSearchPath( System s, const QString &path)
#endif
#if !defined(Q_WS_WIN)
if ( s == Windows )
return;
#endif
-#if !defined(Q_WS_WIN)
+#if !defined(Q_OS_MAC)
if ( s == Mac )
return;
#endif
if ( !qt_verify_key( path ) ) {
#if defined(QT_CHECK_STATE)
@@ -961,43 +937,57 @@ bool QSettings::sync()
QMap<QString,QSettingsHeading>::Iterator it = d->headings.begin();
while (it != d->headings.end()) {
// determine filename
QSettingsHeading hd(*it);
QSettingsHeading::Iterator hdit = hd.begin();
- QFile file;
+ QString filename;
QStringList::Iterator pit = d->searchPaths.begin();
if ( !d->globalScope )
++pit;
while (pit != d->searchPaths.end()) {
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;
}
}
++it;
- if ( file.name().isEmpty() ) {
+ if ( filename.isEmpty() ) {
#ifdef QT_CHECK_STATE
qWarning("QSettings::sync: filename is null/empty");
#endif // QT_CHECK_STATE
success = FALSE;
continue;
}
- 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)) {
#ifdef QT_CHECK_STATE
qWarning("QSettings::sync: failed to open '%s' for writing",
file.name().latin1());
#endif // QT_CHECK_STATE
@@ -1044,13 +1034,32 @@ bool QSettings::sync()
success = FALSE;
}
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
}
d->modified = FALSE;
return success;
}
@@ -1069,25 +1078,26 @@ bool QSettings::sync()
/*!
\internal
*/
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 )
*ok = FALSE;
return def;
}
#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
QString value = readEntry( key, ( def ? "true" : "false" ), ok );
if (value.lower() == "true")
return TRUE;
@@ -1120,25 +1130,26 @@ bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok )
/*!
\internal
*/
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 )
*ok = FALSE;
return def;
}
#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
QString value = readEntry( key, QString::number(def), ok );
bool conv_ok;
double retval = value.toDouble( &conv_ok );
if ( conv_ok )
@@ -1165,24 +1176,25 @@ double QSettings::readDoubleEntry(const QString &key, double def, bool *ok )
/*!
\internal
*/
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 )
*ok = FALSE;
return def;
}
#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
QString value = readEntry( key, QString::number( def ), ok );
bool conv_ok;
int retval = value.toInt( &conv_ok );
if ( conv_ok )
@@ -1209,41 +1221,40 @@ int QSettings::readNumEntry(const QString &key, int def, bool *ok )
/*!
\internal
*/
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 )
*ok = FALSE;
return def;
}
- 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
if ( ok ) // no, everything is not ok
*ok = FALSE;
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 )
*ok = FALSE;
return def;
}
@@ -1259,14 +1270,15 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok )
list.remove(list.at(1));
// remove the heading from the list
list.remove(list.at(0));
realkey = list.join("/");
}
- } else
- realkey = theKey;
+ } else {
+ realkey = grp_key;
+ }
QSettingsGroup grp = d->readGroup();
QSettingsGroup::const_iterator it = grp.find( realkey ), end = grp.end();
QString retval = def;
if ( it != end ) {
// found the value we needed
@@ -1287,22 +1299,23 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok )
returned; otherwise TRUE is returned.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
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;
}
#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");
return writeEntry(key, s);
}
#endif
@@ -1317,22 +1330,23 @@ bool QSettings::writeEntry(const QString &key, bool value)
returned; otherwise TRUE is returned.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
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;
}
#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));
return writeEntry(key, s);
}
@@ -1346,22 +1360,23 @@ bool QSettings::writeEntry(const QString &key, double value)
returned; otherwise TRUE is returned.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
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;
}
#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));
return writeEntry(key, s);
}
@@ -1380,19 +1395,12 @@ bool QSettings::writeEntry(const QString &key, int value)
unchanged.
\sa readEntry(), removeEntry()
*/
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));
}
/*!
\overload
@@ -1405,36 +1413,35 @@ bool QSettings::writeEntry(const QString &key, const char *value)
returned; otherwise TRUE is returned.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
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
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
return FALSE;
}
if (list.count() == 2) {
@@ -1449,14 +1456,15 @@ bool QSettings::writeEntry(const QString &key, const QString &value)
list.remove(list.at(1));
// remove the heading from the list
list.remove(list.at(0));
realkey = list.join("/");
}
- } else
- realkey = theKey;
+ } else {
+ realkey = grp_key;
+ }
d->writeGroup(realkey, value);
return TRUE;
}
@@ -1466,35 +1474,33 @@ bool QSettings::writeEntry(const QString &key, const QString &value)
Returns TRUE if the entry existed and was removed; otherwise returns FALSE.
\sa readEntry(), writeEntry()
*/
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
return FALSE;
}
if (list.count() == 2) {
@@ -1509,14 +1515,15 @@ bool QSettings::removeEntry(const QString &key)
list.remove(list.at(1));
// remove the heading from the list
list.remove(list.at(0));
realkey = list.join("/");
}
- } else
- realkey = theKey;
+ } else {
+ realkey = grp_key;
+ }
d->removeGroup(realkey);
return TRUE;
}
@@ -1545,34 +1552,33 @@ bool QSettings::removeEntry(const QString &key)
"/MyCompany/MyApplication/geometry/y".
\sa subkeyList()
*/
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
return QStringList();
}
if (list.count() == 1) {
@@ -1587,13 +1593,13 @@ QStringList QSettings::entryList(const QString &key) const
// remove the heading from the list
list.remove(list.at(0));
realkey = list.join("/");
}
} else
- realkey = theKey;
+ realkey = grp_key;
QSettingsGroup grp = d->readGroup();
QSettingsGroup::Iterator it = grp.begin();
QStringList ret;
QString itkey;
while (it != grp.end()) {
@@ -1642,35 +1648,34 @@ QStringList QSettings::entryList(const QString &key) const
rather than subkeys use entryList().
\sa entryList()
*/
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
return QStringList();
}
subkeycount = list.count();
@@ -1688,13 +1693,13 @@ QStringList QSettings::subkeyList(const QString &key) const
list.remove(list.at(0));
realkey = list.join("/");
}
} else
- realkey = theKey;
+ realkey = grp_key;
QStringList ret;
if ( subkeycount == 1 ) {
QMap<QString,QSettingsHeading>::Iterator it = d->headings.begin();
while ( it != d->headings.end() ) {
if ( it.key() != "General" && ! ret.contains( it.key() ) )
@@ -1734,35 +1739,34 @@ QStringList QSettings::subkeyList(const QString &key) const
/*!
\internal
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 )
return QDateTime();
#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
return QDateTime();
}
if (list.count() == 2) {
@@ -1777,12 +1781,13 @@ QDateTime QSettings::lastModficationTime(const QString &key)
return d->modificationTime();
}
/*!
\overload
+ \obsolete
Writes the string list entry \a value into key \a key. The \a key
is created if it doesn't exist. Any previous value is overwritten
by \a value. The list is stored as a sequence of strings separated
by \a separator (using QStringList::join()), so none of the
strings in the list should contain the separator. If the list is
@@ -1793,16 +1798,17 @@ QDateTime QSettings::lastModficationTime(const QString &key)
list. As the documentation states, QStringList::split() will omit
empty strings from the list. Because of this, it is impossible to
retrieve identical list data that is stored with this function.
We recommend using the writeEntry() and readListEntry() overloads
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,
const QChar &separator)
{
QString s(value.join(separator));
return writeEntry(key, s);
@@ -1836,25 +1842,25 @@ bool QSettings::writeEntry(const QString &key, const QStringList &value)
return writeEntry(key, s);
}
/*!
\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
omit empty strings from the list. Because of this, it is
impossible to retrieve identical list data with this function. We
recommend using the readListEntry() and writeEntry() overloads
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.
\code
QStringList list = mySettings.readListEntry( "size", " " );
QStringList::Iterator it = list.begin();
while( it != list.end() ) {
@@ -1946,14 +1952,13 @@ void qt_setSettingsBasePath(const QString &); //qsettings_mac.cpp
The \a scope should be
QSettings::User for user-specific settings, or
QSettings::Global for system-wide settings (generally
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.
*/
void QSettings::setPath( const QString &domain, const QString &product, Scope scope )
{
// On Windows, any trailing ".com(\..*)" is stripped from the domain. The
// Global scope corresponds to HKEY_LOCAL_MACHINE, and User corresponds to
@@ -1977,19 +1982,25 @@ void QSettings::setPath( const QString &domain, const QString &product, Scope sc
int lastDot = domain.findRev( '.' );
#if defined(Q_WS_WIN)
actualSearchPath = "/" + domain.mid( 0, lastDot ) + "/" + product;
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
}
/*!
Appends \a group to the current key prefix.