47 #include "private/qcore_mac_p.h" 48 #ifndef QT_BOOTSTRAPPED 51 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 52 #include <Security/SecCode.h> 53 #include <Security/SecRequirement.h> 73 static const int NumKnights = 3;
74 static const char knightsOfTheRoundTable[NumKnights] = {
'/',
'.',
'\xb7' };
77 for (
int i = 0; i < result.
size(); ++i) {
78 for (
int j = 0; j < NumKnights; ++j) {
104 for (
int i = 0; i < n; ++i)
106 return CFArrayCreate(kCFAllocatorDefault, reinterpret_cast<const void **>(cfvalues.
data()),
107 CFIndex(n), &kCFTypeArrayCallBacks);
112 CFPropertyListRef result = 0;
114 switch (value.
type()) {
118 result = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(ba.
data()),
140 int maxUniqueKeys = map.
size();
141 int numUniqueKeys = 0;
154 bool singleton = (values.
count() == 1);
172 result = CFDictionaryCreate(kCFAllocatorDefault,
173 reinterpret_cast<const void **>(cfkeys.
data()),
174 reinterpret_cast<const void **>(cfvalues.
data()),
175 CFIndex(numUniqueKeys),
176 &kCFTypeDictionaryKeyCallBacks,
177 &kCFTypeDictionaryValueCallBacks);
189 result = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTime(reference.
secsTo(dt)));
196 result = value.
toBool() ? kCFBooleanTrue : kCFBooleanFalse;
201 int n = value.
toInt();
202 result = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &n);
208 result = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &n);
215 result = CFNumberCreate(0, kCFNumberLongLongType, &n);
231 CFTypeID typeId = CFGetTypeID(cfvalue);
236 if (typeId == CFStringGetTypeID()) {
238 }
else if (typeId == CFNumberGetTypeID()) {
239 CFNumberRef cfnumber =
static_cast<CFNumberRef
>(cfvalue);
240 if (CFNumberIsFloatType(cfnumber)) {
242 CFNumberGetValue(cfnumber, kCFNumberDoubleType, &d);
248 if (CFNumberGetValue(cfnumber, kCFNumberIntType, &i))
250 CFNumberGetValue(cfnumber, kCFNumberLongLongType, &ll);
253 }
else if (typeId == CFArrayGetTypeID()) {
256 CFIndex size = CFArrayGetCount(cfarray);
257 bool metNonString =
false;
258 for (CFIndex i = 0; i < size; ++i) {
268 }
else if (typeId == CFBooleanGetTypeID()) {
269 return (
bool)CFBooleanGetValue(static_cast<CFBooleanRef>(cfvalue));
270 }
else if (typeId == CFDataGetTypeID()) {
271 CFDataRef cfdata =
static_cast<CFDataRef
>(cfvalue);
272 return QByteArray(reinterpret_cast<const char *>(CFDataGetBytePtr(cfdata)),
273 CFDataGetLength(cfdata));
274 }
else if (typeId == CFDictionaryGetTypeID()) {
275 CFDictionaryRef cfdict =
static_cast<CFDictionaryRef
>(cfvalue);
276 CFTypeID arrayTypeId = CFArrayGetTypeID();
277 int size = (int)CFDictionaryGetCount(cfdict);
280 CFDictionaryGetKeysAndValues(cfdict, keys.
data(), values.
data());
283 for (
int i = 0; i < size; ++i) {
286 if (CFGetTypeID(values[i]) == arrayTypeId) {
288 CFIndex arraySize = CFArrayGetCount(cfarray);
289 for (CFIndex j = arraySize - 1; j >= 0; --j)
290 map.insert(key,
qtValue(CFArrayGetValueAtIndex(cfarray, j)));
292 map.insert(key,
qtValue(values[i]));
296 }
else if (typeId == CFDateGetTypeID()) {
299 return dt.
addSecs((
int)CFDateGetAbsoluteTime(static_cast<CFDateRef>(cfvalue)));
306 for (
int i = organization.
size() - 1; i >= 0; --i) {
309 || ch ==
QChar(0xff61)) {
325 if ((uc < 'a' || uc >
'z') && (uc < 'A' || uc >
'Z'))
330 for (
int i = 0; i < organization.
size(); ++i) {
333 if ((uc >=
'a' && uc <=
'z') || (uc >=
'0' && uc <=
'9')) {
335 }
else if (uc >=
'A' && uc <=
'Z') {
391 domainName =
QLatin1String(
"unknown-organization.trolltech.com");
395 javaPackageName.
prepend(domainName.
mid(curPos, nextDot - curPos));
397 curPos = nextDot + 1;
399 javaPackageName.
prepend(domainName.
mid(curPos));
400 javaPackageName = javaPackageName.
toLower();
412 javaPackageName += application;
420 domain.
userName = (i == 0) ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
438 CFRetain(bundleIdentifier);
440 CFRetain(bundleIdentifier);
459 for (
int i = -1; i < keys.
size(); ++i) {
463 subKey += keys.
at(i);
465 CFPreferencesSetValue(
macKey(subKey), 0,
domains[0].applicationOrSuiteId,
482 CFPreferencesCopyValue(k,
domains[i].applicationOrSuiteId,
domains[i].userName,
500 int startPos = prefix.
size();
508 CFIndex size = CFArrayGetCount(cfarray);
509 for (CFIndex k = 0; k < size; ++k) {
511 qtKey(static_cast<CFStringRef>(CFArrayGetValueAtIndex(cfarray, k)));
521 return result.
keys();
528 CFPreferencesSetMultiple(0, cfarray,
domains[0].applicationOrSuiteId,
domains[0].userName,
536 Boolean ok = CFPreferencesSynchronize(
domains[i].applicationOrSuiteId,
547 CFIndex size = CFArrayGetCount(appIds);
548 for (CFIndex k = 0; k < size; ++k) {
549 const void *cfvalue = CFArrayGetValueAtIndex(appIds, k);
550 if (CFGetTypeID(cfvalue) == CFStringGetTypeID()) {
551 if (CFStringCompare(static_cast<CFStringRef>(cfvalue),
552 domains[i].applicationOrSuiteId,
553 kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
583 that->
remove(impossibleKey);
606 #ifndef QT_BOOTSTRAPPED 607 static bool useAppLocalStorage =
false;
608 static bool initialized =
false;
611 bool inSandbox =
false;
613 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 617 Gestalt(gestaltSystemVersion, &version);
618 SecCodeRef secCodeSelf;
619 if (version >= 0x1070 && SecCodeCopySelf(kSecCSDefaultFlags, &secCodeSelf) == errSecSuccess) {
620 SecRequirementRef sandboxReq;
621 CFStringRef entitlement = CFSTR(
"entitlement [\"com.apple.security.app-sandbox\"]");
622 if (SecRequirementCreateWithString(entitlement, kSecCSDefaultFlags, &sandboxReq) == errSecSuccess) {
623 if (SecCodeCheckValidity(secCodeSelf, kSecCSDefaultFlags, sandboxReq) == errSecSuccess)
625 CFRelease(sandboxReq);
627 CFRelease(secCodeSelf);
631 bool forAppStore =
false;
633 CFTypeRef val = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR(
"ForAppStore"));
634 forAppStore = (val &&
635 CFGetTypeID(val) == CFStringGetTypeID() &&
636 CFStringCompare(
CFStringRef(val), CFSTR(
"yes"), kCFCompareCaseInsensitive) == 0);
639 useAppLocalStorage = inSandbox || forAppStore;
643 if (useAppLocalStorage) {
648 (organization ==
qApp->organizationDomain() && application ==
qApp->applicationName()) ||
649 (organization ==
qApp->organizationName()) && application ==
qApp->applicationName())
651 CFStringRef bundleIdentifier = CFBundleGetIdentifier(CFBundleGetMainBundle());
652 if (!bundleIdentifier) {
653 qWarning(
"QSettingsPrivate::create: You must set the bundle identifier when using ForAppStore");
673 return CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
QCFString(fileName),
674 kCFURLPOSIXPathStyle,
false);
681 if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
urlFromFileName(fileName),
682 &resource, 0, 0, &code))
687 CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resource, kCFPropertyListImmutable,
692 if (CFGetTypeID(propertyList) != CFDictionaryGetTypeID())
695 CFDictionaryRef cfdict =
696 static_cast<CFDictionaryRef
>(
static_cast<CFPropertyListRef
>(propertyList));
697 int size = (int)CFDictionaryGetCount(cfdict);
700 CFDictionaryGetKeysAndValues(cfdict, keys.
data(), values.
data());
702 for (
int i = 0; i < size; ++i) {
717 cfkeys[i] =
macKey(j.key());
723 CFDictionaryCreate(kCFAllocatorDefault,
724 reinterpret_cast<const void **>(cfkeys.data()),
725 reinterpret_cast<const void **>(cfvalues.data()),
727 &kCFTypeDictionaryKeyCallBacks,
728 &kCFTypeDictionaryValueCallBacks);
730 QCFType<CFDataRef> xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, propertyList);
733 return CFURLWriteDataAndPropertiesToResource(
urlFromFileName(fileName), xmlData, 0, &code);
The QVariant class acts like a union for the most common Qt data types.
The QMultiMap class is a convenience QMap subclass that provides multi-valued maps.
QDateTime addSecs(int secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
bool get(const QString &key, QVariant *value) const
void setStatus(QSettings::Status status) const
const struct __CFString * CFStringRef
Status
The following status values are possible:
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
void set(const QString &key, const QVariant &value)
bool readPlistFile(const QString &fileName, ParsedSettingsMap *map) const
#define QT_END_NAMESPACE
This macro expands to.
const Key key(const T &value) const
Returns the first key with value value.
char * data()
Returns a pointer to the data stored in the byte array.
const QChar at(int i) const
Returns the character at the given index position in the string.
QMap< QString, QVariant > toMap() const
Returns the variant as a QMap<QString, QVariant> if the variant has type() Map ; otherwise returns an...
static QVariant qtValue(CFPropertyListRef cfvalue)
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QSettings class provides persistent platform-independent application settings.
static QString comify(const QString &organization)
QString & replace(int i, int len, QChar after)
static QCFType< CFStringRef > macKey(const QString &key)
The QByteArray class provides an array of bytes.
Format
This enum type specifies the storage format used by QSettings.
QString & prepend(QChar c)
QMacSettingsPrivate(QSettings::Scope scope, const QString &organization, const QString &application)
static CFStringRef toCFStringRef(const QString &str)
int size() const
Returns the number of (key, value) pairs in the map.
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
static QString toQString(CFStringRef cfstr)
CFStringRef applicationOrSuiteId
bool writePlistFile(const QString &fileName, const ParsedSettingsMap &map) const
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
static QCFType< CFURLRef > urlFromFileName(const QString &fileName)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
int count(const T &t) const
Returns the number of occurrences of value in the list.
void remove(const QString &key)
The QString class provides a Unicode character string.
static QSettingsPrivate * create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
The QChar class provides a 16-bit Unicode character.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
QFuture< void > map(Sequence &sequence, MapFunction function)
#define QT_BEGIN_NAMESPACE
This macro expands to.
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
static QCFType< CFPropertyListRef > macValue(const QVariant &value)
void setTime_t(uint secsSince1Jan1970UTC)
Sets the date and time given the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void beginGroupOrArray(const QSettingsGroup &group)
static const int numHostNames
const T value(const Key &key) const
Returns the value associated with the key key.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
int secsTo(const QDateTime &) const
Returns the number of seconds from this datetime to the other datetime.
Q_CORE_EXPORT void qWarning(const char *,...)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
static QString variantToString(const QVariant &v)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
ushort unicode() const
Converts a Latin-1 character to an 16-bit-encoded Unicode representation of the character.
static const CFStringRef hostNames[2]
T & first()
Returns a reference to the first item in the list.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
static QString rotateSlashesDotsAndMiddots(const QString &key, int shift)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
QString & append(QChar c)
The QDateTime class provides date and time functions.
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Type type() const
Returns the storage type of the value stored in the variant.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Qt::TimeSpec timeSpec() const
Returns the time specification of the datetime.
int size() const
Returns the number of items in the list.
int size() const
Returns the number of bytes in this byte array.
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
static QVariant stringToVariant(const QString &s)
static CFArrayRef macList(const QList< QVariant > &list)
static QString qtKey(CFStringRef cfkey)
const struct __CFArray * CFArrayRef
static void processChild(QString key, ChildSpec spec, QMap< QString, QString > &result)
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QStringList children(const QString &prefix, ChildSpec spec) const
friend class const_iterator
static QString homePath()
Returns the absolute path of the user's home directory.