src/corelib/io/qsettings.cpp File Reference

#include <qdebug.h>
#include "qplatformdefs.h"
#include "qsettings.h"
#include "qsettings_p.h"
#include "qcache.h"
#include "qfile.h"
#include "qdir.h"
#include "qfileinfo.h"
#include "qmutex.h"
#include "qlibraryinfo.h"
#include "qtemporaryfile.h"
#include "qsize.h"
#include "qpoint.h"
#include "qrect.h"
#include "qcoreapplication.h"
#include <stdlib.h>

Include dependency graph for qsettings.cpp:

Go to the source code of this file.

Classes

struct  QConfFileCustomFormat

Defines

#define CSIDL_COMMON_APPDATA   0x0023
#define CSIDL_APPDATA   0x001a
#define FLUSH_CURRENT_SECTION()

Typedefs

typedef QHash< QString, QConfFile * > ConfFileHash
typedef QCache< QString, QConfFileConfFileCache
typedef QHash< int, QStringPathHash
typedef QVector< QConfFileCustomFormatCustomFormatVector

Enumerations

enum  

Functions

bool qt_isEvilFsTypeName (const char *name)
static bool isLikelyToBeNfs (int)
static bool unixLock (int handle, int lockType)
static void iniChopTrailingSpaces (QString &str)
static bool checkAccess (const QString &name)
static int pathHashKey (QSettings::Format format, QSettings::Scope scope)
static QString getPath (QSettings::Format format, QSettings::Scope scope)

Variables

static const char hexDigits [] = "0123456789ABCDEF"
static const char charTraits [256]


Define Documentation

#define CSIDL_APPDATA   0x001a

Definition at line 62 of file qsettings.cpp.

Referenced by getPath().

#define CSIDL_COMMON_APPDATA   0x0023

Definition at line 58 of file qsettings.cpp.

Referenced by getPath().

 
#define FLUSH_CURRENT_SECTION (  ) 

Value:

{ \
        QByteArray &sectionData = (*unparsedIniSections)[QSettingsKey(currentSection, \
                                                                      IniCaseSensitivity)]; \
        if (!sectionData.isEmpty()) \
            sectionData.append('\n'); \
        sectionData += data.mid(currentSectionStart, lineStart - currentSectionStart); \
    }

Referenced by QConfFileSettingsPrivate::readIniFile().


Typedef Documentation

typedef QCache<QString, QConfFile> ConfFileCache

Definition at line 84 of file qsettings.cpp.

typedef QHash<QString, QConfFile *> ConfFileHash

Definition at line 83 of file qsettings.cpp.

typedef QVector<QConfFileCustomFormat> CustomFormatVector

Definition at line 86 of file qsettings.cpp.

typedef QHash<int, QString> PathHash

Definition at line 85 of file qsettings.cpp.


Enumeration Type Documentation

anonymous enum

Definition at line 1563 of file qsettings.cpp.

01563 { Space = 0x1, Special = 0x2 };


Function Documentation

static bool checkAccess ( const QString name  )  [static]

Definition at line 887 of file qsettings.cpp.

References QList< T >::at(), QDir::cd(), QDir::current(), QFileInfo::exists(), i, QDir::isRelativePath(), QDir::mkdir(), name, QIODevice::ReadOnly, QDir::root(), QList< T >::size(), and QString::SkipEmptyParts.

Referenced by QConfFileSettingsPrivate::initAccess().

00888 {
00889     QFileInfo fileInfo(name);
00890 
00891     if (fileInfo.exists()) {
00892         QFile file(name);
00893         // if the file exists but we can't open it, report an error
00894         return file.open(QFile::ReadOnly);
00895     } else {
00896         QDir dir;
00897         if (QDir::isRelativePath(name))
00898             dir = QDir::current();
00899         else
00900             dir = QDir::root();
00901 
00902         /*
00903             Create the directories to the file.
00904         */
00905         QStringList pathElements = name.split(QLatin1Char('/'), QString::SkipEmptyParts);
00906         for (int i = 0; i < pathElements.size() - 1; ++i) {
00907             const QString &elt = pathElements.at(i);
00908             if (dir.cd(elt))
00909                 continue;
00910 
00911             if (dir.mkdir(elt) && dir.cd(elt))
00912                 continue;
00913 
00914             if (dir.cd(elt))
00915                 continue;
00916 
00917             // if the path can't be created/reached, report an error
00918             return false;
00919         }
00920         // we treat non-existent files as if they existed but were empty
00921         return true;
00922     }
00923 }

Here is the call graph for this function:

static QString getPath ( QSettings::Format  format,
QSettings::Scope  scope 
) [static]

Definition at line 1018 of file qsettings.cpp.

References CSIDL_APPDATA, CSIDL_COMMON_APPDATA, QDir::homePath(), QSettings::IniFormat, QHash< Key, T >::insert(), QString::isEmpty(), QHash< Key, T >::isEmpty(), QLibraryInfo::location(), QSettings::NativeFormat, pathHashKey(), QDir::separator(), QLibraryInfo::SettingsPath, QSettings::SystemScope, QSettings::UserScope, and QHash< Key, T >::value().

Referenced by QConfFileSettingsPrivate::QConfFileSettingsPrivate().

01019 {
01020     Q_ASSERT((int)QSettings::NativeFormat == 0);
01021     Q_ASSERT((int)QSettings::IniFormat == 1);
01022 
01023     QString homePath = QDir::homePath();
01024     QString systemPath;
01025 
01026     globalMutex()->lock();
01027     PathHash *pathHash = pathHashFunc();
01028     bool loadSystemPath = pathHash->isEmpty();
01029     globalMutex()->unlock();
01030 
01031     if (loadSystemPath) {
01032         /*
01033            QLibraryInfo::location() uses QSettings, so in order to
01034            avoid a dead-lock, we can't hold the global mutex while
01035            calling it.
01036        */
01037         systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath);
01038         systemPath += QLatin1Char('/');
01039     }
01040 
01041     QMutexLocker locker(globalMutex());
01042     if (pathHash->isEmpty()) {
01043         /*
01044            Lazy initialization of pathHash. We initialize the
01045            IniFormat paths and (on Unix) the NativeFormat paths.
01046            (The NativeFormat paths are not configurable for the
01047            Windows registry and the Mac CFPreferences.)
01048        */
01049 #ifdef Q_OS_WIN
01050         pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope),
01051                          windowsConfigPath(CSIDL_APPDATA) + QDir::separator());
01052         pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope),
01053                          windowsConfigPath(CSIDL_COMMON_APPDATA) + QDir::separator());
01054 #else
01055         QString userPath;
01056         char *env = getenv("XDG_CONFIG_HOME");
01057         if (env == 0) {
01058             userPath = homePath;
01059             userPath += QLatin1Char('/');
01060 #ifdef Q_WS_QWS
01061             userPath += QLatin1String("Settings");
01062 #else
01063             userPath += QLatin1String(".config");
01064 #endif
01065         } else if (*env == '/') {
01066             userPath = QLatin1String(env);
01067         } else {
01068             userPath = homePath;
01069             userPath += QLatin1Char('/');
01070             userPath += QLatin1String(env);
01071         }
01072         userPath += QLatin1Char('/');
01073 
01074         pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), userPath);
01075         pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), systemPath);
01076 #ifndef Q_OS_MAC
01077         pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::UserScope), userPath);
01078         pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::SystemScope), systemPath);
01079 #endif
01080 #endif
01081     }
01082 
01083     QString result = pathHash->value(pathHashKey(format, scope));
01084     if (!result.isEmpty())
01085         return result;
01086 
01087     // fall back on INI path
01088     return pathHash->value(pathHashKey(QSettings::IniFormat, scope));
01089 }

Here is the call graph for this function:

static void iniChopTrailingSpaces ( QString str  )  [inline, static]

Definition at line 666 of file qsettings.cpp.

References QString::at(), n, QString::size(), and QString::truncate().

Referenced by QSettingsPrivate::iniUnescapedStringList().

00667 {
00668     int n = str.size() - 1;
00669     QChar ch;
00670     while (n >= 0 && ((ch = str.at(n)) == QLatin1Char(' ') || ch == QLatin1Char('\t')))
00671         str.truncate(n--);
00672 }

Here is the call graph for this function:

static bool isLikelyToBeNfs ( int   )  [inline, static]

Definition at line 149 of file qsettings.cpp.

Referenced by unixLock().

00150 {
00151     return true;
00152 }

static int pathHashKey ( QSettings::Format  format,
QSettings::Scope  scope 
) [inline, static]

Definition at line 1013 of file qsettings.cpp.

References int, and QSettings::SystemScope.

Referenced by getPath(), and QSettings::setPath().

01014 {
01015     return int((uint(format) << 1) | uint(scope == QSettings::SystemScope));
01016 }

bool qt_isEvilFsTypeName ( const char *  name  )  [inline]

Definition at line 95 of file qsettings.cpp.

References QByteArray::qstrncmp().

00096 {
00097     return (qstrncmp(name, "nfs", 3) == 0
00098             || qstrncmp(name, "autofs", 6) == 0
00099             || qstrncmp(name, "cachefs", 7) == 0);
00100 }

Here is the call graph for this function:

static bool unixLock ( int  handle,
int  lockType 
) [static]

Definition at line 155 of file qsettings.cpp.

References isLikelyToBeNfs(), and SEEK_SET.

Referenced by QConfFileSettingsPrivate::syncConfFile().

00156 {
00157     /*
00158         NFS hangs on the fcntl() call below when statd or lockd isn't
00159         running. There's no way to detect this. Our work-around for
00160         now is to disable locking when we detect NFS (or AutoFS or
00161         CacheFS, which are probably wrapping NFS).
00162     */
00163     if (isLikelyToBeNfs(handle))
00164         return false;
00165 
00166     struct flock fl;
00167     fl.l_whence = SEEK_SET;
00168     fl.l_start = 0;
00169     fl.l_len = 0;
00170     fl.l_type = lockType;
00171     return fcntl(handle, F_SETLKW, &fl) == 0;
00172 }

Here is the call graph for this function:


Variable Documentation

const char charTraits[256] [static]

Initial value:

{
    
    

    0, 0, 0, 0, 0, 0, 0, 0, 0, Space, Space | Special, 0, 0, Space | Special, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    Space, 0, Special, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Special, 0, Special, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Special, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

Definition at line 1565 of file qsettings.cpp.

const char hexDigits[] = "0123456789ABCDEF" [static]

Definition at line 507 of file qsettings.cpp.


Generated on Thu Mar 15 12:37:04 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1