11#include <qstringlist.h>
13#include <qvarlengtharray.h>
15#include <CoreFoundation/CoreFoundation.h>
17#include <sys/sysctl.h>
21static QString q_toString(
const CFStringRef &str)
23 CFIndex length = CFStringGetLength(str);
26 CFRange range = {0, length};
27 CFStringGetCharacters(str, range, buffer.data());
28 return QString(
reinterpret_cast<const QChar *
>(buffer.data()), length);
32static inline T convertCFNumber(
const CFNumberRef &num, CFNumberType type)
35 CFNumberGetValue(num, type, &n);
39static QVariant q_toVariant(
const CFTypeRef &obj)
41 const CFTypeID typeId = CFGetTypeID(obj);
43 if (typeId == CFStringGetTypeID()) {
44 return QVariant(q_toString(
static_cast<const CFStringRef
>(obj)));
47 if (typeId == CFNumberGetTypeID()) {
48 const CFNumberRef num =
static_cast<const CFNumberRef
>(obj);
49 const CFNumberType
type = CFNumberGetType(num);
51 case kCFNumberSInt8Type:
53 case kCFNumberSInt16Type:
55 case kCFNumberSInt32Type:
57 case kCFNumberSInt64Type:
59 case kCFNumberCharType:
61 case kCFNumberShortType:
63 case kCFNumberIntType:
65 case kCFNumberLongType:
67 case kCFNumberLongLongType:
69 case kCFNumberFloatType:
71 case kCFNumberDoubleType:
74 if (CFNumberIsFloatType(num)) {
81 if (typeId == CFDateGetTypeID()) {
84 return dt.
addSecs(
int(CFDateGetAbsoluteTime(
static_cast<const CFDateRef
>(obj))));
87 if (typeId == CFDataGetTypeID()) {
88 const CFDataRef cfdata =
static_cast<const CFDataRef
>(obj);
89 return QByteArray(
reinterpret_cast<const char *
>(CFDataGetBytePtr(cfdata)), CFDataGetLength(cfdata));
92 if (typeId == CFBooleanGetTypeID()) {
93 return QVariant(
bool(CFBooleanGetValue(
static_cast<const CFBooleanRef
>(obj))));
96 if (typeId == CFArrayGetTypeID()) {
97 const CFArrayRef cfarray =
static_cast<const CFArrayRef
>(obj);
99 CFIndex size = CFArrayGetCount(cfarray);
100 bool metNonString =
false;
101 for (CFIndex i = 0; i < size; ++i) {
102 QVariant value = q_toVariant(CFArrayGetValueAtIndex(cfarray, i));
115 if (typeId == CFDictionaryGetTypeID()) {
116 const CFDictionaryRef cfdict =
static_cast<const CFDictionaryRef
>(obj);
117 const CFTypeID arrayTypeId = CFArrayGetTypeID();
118 int size = int(CFDictionaryGetCount(cfdict));
121 CFDictionaryGetKeysAndValues(cfdict, keys.data(), values.data());
124 for (
int i = 0; i < size; ++i) {
125 QString key = q_toString(
static_cast<const CFStringRef
>(keys[i]));
127 if (CFGetTypeID(values[i]) == arrayTypeId) {
128 const CFArrayRef cfarray =
static_cast<const CFArrayRef
>(values[i]);
129 CFIndex arraySize = CFArrayGetCount(cfarray);
130 for (CFIndex j = arraySize - 1; j >= 0; --j) {
131 map.insert(key, q_toVariant(CFArrayGetValueAtIndex(cfarray, j)));
134 map.insert(key, q_toVariant(values[i]));
149 const int count = CFDictionaryGetCount(dict);
153 CFDictionaryGetKeysAndValues(dict,
const_cast<const void **
>(keys.data()),
const_cast<const void **
>(values.data()));
155 for (
int i = 0; i < count; ++i) {
156 const QString key = q_toString((CFStringRef)keys[i]);
157 const QVariant value = q_toVariant((CFTypeRef)values[i]);
164bool q_sysctlbyname(
const char *name,
QString &result)
166 char *
property =
nullptr;
169 if (name && sysctlbyname(name,
nullptr, &size,
nullptr, 0) == 0 && size > 0) {
170 property =
new char[size];
171 error = sysctlbyname(name, property, &size,
nullptr, 0);
Type type(const QSqlDatabase &db)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QDateTime addSecs(qint64 s) const const
void setSecsSinceEpoch(qint64 secs)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QVariant fromValue(T &&value)
QStringList toStringList() const const
int userType() const const