static InspectorController::Setting variantToSetting(const QVariant& qvariant) { InspectorController::Setting retVal; switch (qvariant.type()) { case QVariant::Bool: retVal.set(qvariant.toBool()); break; case QVariant::Double: retVal.set(qvariant.toDouble()); break; case QVariant::Int: retVal.set((long)qvariant.toInt()); break; case QVariant::String: retVal.set(qvariant.toString()); break; case QVariant::StringList: { QStringList qsList = qvariant.toStringList(); int listCount = qsList.count(); Vector<String> vector(listCount); for (int i = 0; i < listCount; ++i) vector[i] = qsList[i]; retVal.set(vector); break; } } return retVal; }
void WebInspectorClient::populateSetting(const String& key, InspectorController::Setting& setting) { RetainPtr<CFStringRef> preferencesKey(AdoptCF, createKeyForPreferences(key)); RetainPtr<CFPropertyListRef> value(AdoptCF, CFPreferencesCopyAppValue(preferencesKey.get(), kCFPreferencesCurrentApplication)); if (!value) return; CFTypeID type = CFGetTypeID(value.get()); if (type == CFStringGetTypeID()) setting.set(static_cast<String>(static_cast<CFStringRef>(value.get()))); else if (type == CFBooleanGetTypeID()) setting.set(static_cast<bool>(CFBooleanGetValue(static_cast<CFBooleanRef>(value.get())))); else if (type == CFNumberGetTypeID()) { CFNumberRef number = static_cast<CFNumberRef>(value.get()); if (CFNumberIsFloatType(number)) { double doubleNumber = 0.0; CFNumberGetValue(static_cast<CFNumberRef>(value.get()), kCFNumberDoubleType, &doubleNumber); setting.set(doubleNumber); } else { long longNumber = 0; CFNumberGetValue(static_cast<CFNumberRef>(value.get()), kCFNumberLongType, &longNumber); setting.set(longNumber); } } else if (type == CFArrayGetTypeID()) { Vector<String> strings; CFArrayRef array = static_cast<CFArrayRef>(value.get()); unsigned length = CFArrayGetCount(array); for (unsigned i = 0; i < length; ++i) { CFStringRef string = static_cast<CFStringRef>(CFArrayGetValueAtIndex(array, i)); if (CFGetTypeID(string) == CFStringGetTypeID()) strings.append(static_cast<String>(static_cast<CFStringRef>(string))); } setting.set(strings); } else ASSERT_NOT_REACHED(); }