Пример #1
0
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;
}
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);
}