static QVariant settingToVariant(const InspectorController::Setting& icSetting)
{
    QVariant retVal;

    switch (icSetting.type()) {
    case InspectorController::Setting::StringType:
        retVal.setValue(static_cast<QString>(icSetting.string()));
        break;
    case InspectorController::Setting::StringVectorType: {
        const Vector<String>& vector = icSetting.stringVector();
        Vector<String>::const_iterator iter;
        QStringList qsList;
        for (iter = vector.begin(); iter != vector.end(); ++iter)
            qsList << *iter;
        retVal.setValue(qsList);
        break;
    }
    case InspectorController::Setting::DoubleType:
        retVal.setValue(icSetting.doubleValue());
        break;
    case InspectorController::Setting::IntegerType:
        retVal.setValue((int)icSetting.integerValue());
        break;
    case InspectorController::Setting::BooleanType:
        retVal.setValue(icSetting.booleanValue());
        break;
    }

    return retVal;
}
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();
}
void WebInspectorClient::storeSetting(const String& key, const InspectorController::Setting& setting)
{
    RetainPtr<CFPropertyListRef> objectToStore;

    switch (setting.type()) {
        default:
        case InspectorController::Setting::NoType:
            ASSERT_NOT_REACHED();
            break;
        case InspectorController::Setting::StringType:
            objectToStore.adoptCF(setting.string().createCFString());
            break;
        case InspectorController::Setting::BooleanType:
            objectToStore = (setting.booleanValue() ? kCFBooleanTrue : kCFBooleanFalse);
            break;

        case InspectorController::Setting::DoubleType: {
            double value = setting.doubleValue();
            objectToStore.adoptCF(CFNumberCreate(0, kCFNumberDoubleType, &value));
            break;
        }

        case InspectorController::Setting::IntegerType: {
            long value = setting.integerValue();
            objectToStore.adoptCF(CFNumberCreate(0, kCFNumberLongType, &value));
            break;
        }

        case InspectorController::Setting::StringVectorType: {
            const Vector<String>& strings = setting.stringVector();
            const unsigned length = strings.size();

            RetainPtr<CFMutableArrayRef> array(AdoptCF, CFArrayCreateMutable(0, length, &kCFTypeArrayCallBacks));

            for (unsigned i = 0; i < length; ++i) {
                RetainPtr<CFStringRef> string(AdoptCF, strings[i].createCFString());
                CFArraySetValueAtIndex(array.get(), i, string.get());
            }

            objectToStore = array;
            break;
        }
    }

    ASSERT(objectToStore);

    RetainPtr<CFStringRef> preferencesKey(AdoptCF, createKeyForPreferences(key));
    CFPreferencesSetAppValue(preferencesKey.get(), objectToStore.get(), kCFPreferencesCurrentApplication);
}