Qt 4.8
Classes | Macros | Typedefs | Enumerations | Functions | Variables
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 "qtextcodec.h"
#include "qsize.h"
#include "qpoint.h"
#include "qrect.h"
#include "qcoreapplication.h"
#include "qt_windows.h"
#include <private/qsystemlibrary_p.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  QConfFileCustomFormat
 
class  QSettingsIniKey
 
struct  QSettingsIniSection
 

Macros

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

Typedefs

typedef QCache< QString, QConfFileConfFileCache
 
typedef QHash< QString, QConfFile * > ConfFileHash
 
typedef QVector< QConfFileCustomFormatCustomFormatVector
 
typedef QMap< QSettingsIniKey, QVariantIniKeyMap
 
typedef QMap< QString, QSettingsIniSectionIniMap
 
typedef QHash< int, QStringPathHash
 

Enumerations

enum  { Space = 0x1, Special = 0x2 }
 

Functions

static QString getPath (QSettings::Format format, QSettings::Scope scope)
 
static void iniChopTrailingSpaces (QString &str)
 
static void initDefaultPaths (QMutexLocker *locker)
 
static bool operator< (const QSettingsIniKey &k1, const QSettingsIniKey &k2)
 
static int pathHashKey (QSettings::Format format, QSettings::Scope scope)
 
static QString windowsConfigPath (int type)
 

Variables

static const char charTraits [256]
 
static QSettings::Format globalDefaultFormat = QSettings::NativeFormat
 
static const char hexDigits [] = "0123456789ABCDEF"
 

Macro Definition Documentation

◆ CSIDL_APPDATA

#define CSIDL_APPDATA   0x001a

Definition at line 87 of file qsettings.cpp.

Referenced by initDefaultPaths(), launchWebBrowser(), and windowsConfigPath().

◆ CSIDL_COMMON_APPDATA

#define CSIDL_COMMON_APPDATA   0x0023

Definition at line 83 of file qsettings.cpp.

Referenced by initDefaultPaths(), and windowsConfigPath().

◆ FLUSH_CURRENT_SECTION

#define FLUSH_CURRENT_SECTION ( )
Value:
{ \
QByteArray &sectionData = (*unparsedIniSections)[QSettingsKey(currentSection, \
sectionPosition)]; \
if (!sectionData.isEmpty()) \
sectionData.append('\n'); \
sectionData += data.mid(currentSectionStart, lineStart - currentSectionStart); \
sectionPosition = ++position; \
}
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
static const char * data(const QByteArray &arr)
static const Qt::CaseSensitivity IniCaseSensitivity
Definition: qsettings_p.h:81

Referenced by QConfFileSettingsPrivate::readIniFile().

◆ Q_AUTOTEST_EXPORT_HELPER

#define Q_AUTOTEST_EXPORT_HELPER   Q_AUTOTEST_EXPORT

Definition at line 91 of file qsettings.cpp.

Typedef Documentation

◆ ConfFileCache

Definition at line 117 of file qsettings.cpp.

◆ ConfFileHash

Definition at line 116 of file qsettings.cpp.

◆ CustomFormatVector

Definition at line 119 of file qsettings.cpp.

◆ IniKeyMap

Definition at line 1865 of file qsettings.cpp.

◆ IniMap

Definition at line 1875 of file qsettings.cpp.

◆ PathHash

typedef QHash<int, QString> PathHash

Definition at line 118 of file qsettings.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
Space 
Special 

Definition at line 1633 of file qsettings.cpp.

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

Function Documentation

◆ getPath()

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

Definition at line 1132 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate::QConfFileSettingsPrivate().

1133 {
1134  Q_ASSERT((int)QSettings::NativeFormat == 0);
1135  Q_ASSERT((int)QSettings::IniFormat == 1);
1136 
1137  QMutexLocker locker(globalMutex());
1138  PathHash *pathHash = pathHashFunc();
1139  if (pathHash->isEmpty())
1140  initDefaultPaths(&locker);
1141 
1142  QString result = pathHash->value(pathHashKey(format, scope));
1143  if (!result.isEmpty())
1144  return result;
1145 
1146  // fall back on INI path
1147  return pathHash->value(pathHashKey(QSettings::IniFormat, scope));
1148 }
static void initDefaultPaths(QMutexLocker *locker)
Definition: qsettings.cpp:1073
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static int pathHashKey(QSettings::Format format, QSettings::Scope scope)
Definition: qsettings.cpp:1068

◆ iniChopTrailingSpaces()

static void iniChopTrailingSpaces ( QString str)
inlinestatic

Definition at line 758 of file qsettings.cpp.

Referenced by QSettingsPrivate::iniUnescapedStringList().

759 {
760  int n = str.size() - 1;
761  QChar ch;
762  while (n >= 0 && ((ch = str.at(n)) == QLatin1Char(' ') || ch == QLatin1Char('\t')))
763  str.truncate(n--);
764 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ initDefaultPaths()

static void initDefaultPaths ( QMutexLocker locker)
static

Definition at line 1073 of file qsettings.cpp.

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

1074 {
1075  PathHash *pathHash = pathHashFunc();
1076  QString homePath = QDir::homePath();
1077  QString systemPath;
1078 
1079  locker->unlock();
1080 
1081  /*
1082  QLibraryInfo::location() uses QSettings, so in order to
1083  avoid a dead-lock, we can't hold the global mutex while
1084  calling it.
1085  */
1087  systemPath += QLatin1Char('/');
1088 
1089  locker->relock();
1090  if (pathHash->isEmpty()) {
1091  /*
1092  Lazy initialization of pathHash. We initialize the
1093  IniFormat paths and (on Unix) the NativeFormat paths.
1094  (The NativeFormat paths are not configurable for the
1095  Windows registry and the Mac CFPreferences.)
1096  */
1097 #ifdef Q_OS_WIN
1102 #else
1103  QString userPath;
1104  char *env = getenv("XDG_CONFIG_HOME");
1105  if (env == 0) {
1106  userPath = homePath;
1107  userPath += QLatin1Char('/');
1108 #if defined(Q_WS_QWS) || defined(Q_WS_QPA)
1109  userPath += QLatin1String("Settings");
1110 #else
1111  userPath += QLatin1String(".config");
1112 #endif
1113  } else if (*env == '/') {
1114  userPath = QFile::decodeName(env);
1115  } else {
1116  userPath = homePath;
1117  userPath += QLatin1Char('/');
1118  userPath += QFile::decodeName(env);
1119  }
1120  userPath += QLatin1Char('/');
1121 
1124 #ifndef Q_OS_MAC
1127 #endif
1128 #endif
1129  }
1130 }
void unlock()
Unlocks this mutex locker.
Definition: qmutex.h:117
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
void relock()
Relocks an unlocked mutex locker.
Definition: qmutex.h:125
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
static QString location(LibraryLocation)
Returns the location specified by loc.
#define CSIDL_APPDATA
Definition: qsettings.cpp:87
static int pathHashKey(QSettings::Format format, QSettings::Scope scope)
Definition: qsettings.cpp:1068
#define CSIDL_COMMON_APPDATA
Definition: qsettings.cpp:83
static QString windowsConfigPath(int type)
Definition: qsettings.cpp:1025
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static QString homePath()
Returns the absolute path of the user&#39;s home directory.
Definition: qdir.cpp:1942

◆ operator<()

static bool operator< ( const QSettingsIniKey k1,
const QSettingsIniKey k2 
)
static

Definition at line 1858 of file qsettings.cpp.

1859 {
1860  if (k1.position != k2.position)
1861  return k1.position < k2.position;
1862  return static_cast<const QString &>(k1) < static_cast<const QString &>(k2);
1863 }
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ pathHashKey()

static int pathHashKey ( QSettings::Format  format,
QSettings::Scope  scope 
)
inlinestatic

Definition at line 1068 of file qsettings.cpp.

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

1069 {
1070  return int((uint(format) << 1) | uint(scope == QSettings::SystemScope));
1071 }
unsigned int uint
Definition: qglobal.h:996

◆ windowsConfigPath()

static QString windowsConfigPath ( int  type)
static

Definition at line 1025 of file qsettings.cpp.

Referenced by initDefaultPaths().

1026 {
1027  QString result;
1028 
1029 #ifndef Q_OS_WINCE
1030  QSystemLibrary library(QLatin1String("shell32"));
1031 #else
1032  QSystemLibrary library(QLatin1String("coredll"));
1033 #endif // Q_OS_WINCE
1034  typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL);
1035  GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
1036  if (SHGetSpecialFolderPath) {
1037  wchar_t path[MAX_PATH];
1038  SHGetSpecialFolderPath(0, path, type, FALSE);
1039  result = QString::fromWCharArray(path);
1040  }
1041 
1042  if (result.isEmpty()) {
1043  switch (type) {
1044 #ifndef Q_OS_WINCE
1045  case CSIDL_COMMON_APPDATA:
1046  result = QLatin1String("C:\\temp\\qt-common");
1047  break;
1048  case CSIDL_APPDATA:
1049  result = QLatin1String("C:\\temp\\qt-user");
1050  break;
1051 #else
1052  case CSIDL_COMMON_APPDATA:
1053  result = QLatin1String("\\Temp\\qt-common");
1054  break;
1055  case CSIDL_APPDATA:
1056  result = QLatin1String("\\Temp\\qt-user");
1057  break;
1058 #endif
1059  default:
1060  ;
1061  }
1062  }
1063 
1064  return result;
1065 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
int type
Definition: qmetatype.cpp:239
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define FALSE
Synonym for false.
Definition: qglobal.h:1019
#define CSIDL_APPDATA
Definition: qsettings.cpp:87
#define CSIDL_COMMON_APPDATA
Definition: qsettings.cpp:83

Variable Documentation

◆ charTraits

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 1635 of file qsettings.cpp.

◆ globalDefaultFormat

QSettings::Format globalDefaultFormat = QSettings::NativeFormat
static

◆ hexDigits

const char hexDigits[] = "0123456789ABCDEF"
static

Definition at line 594 of file qsettings.cpp.

Referenced by QSettingsPrivate::iniUnescapedStringList().