view dwt/internal/cocoa/NSUserDefaults.d @ 13:f565d3a95c0a

Ported dwt.internal
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Fri, 22 Aug 2008 16:46:34 +0200
parents 8b48be5454ce
children
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     
 * Port to the D programming language:
 *     Jacob Carlborg <jacob.carlborg@gmail.com>
 *******************************************************************************/
module dwt.internal.cocoa.NSUserDefaults;

import dwt.internal.cocoa.id;
import dwt.internal.cocoa.NSArray;
import dwt.internal.cocoa.NSData;
import dwt.internal.cocoa.NSDictionary;
import dwt.internal.cocoa.NSInteger;
import dwt.internal.cocoa.NSObject;
import dwt.internal.cocoa.NSString;
import dwt.internal.cocoa.OS;
import objc = dwt.internal.objc.runtime;

public class NSUserDefaults : NSObject
{

    public this ()
    {
        super();
    }

    public this (objc.id id)
    {
        super(id);
    }

    public void addSuiteNamed (NSString suiteName)
    {
        OS.objc_msgSend(this.id_, OS.sel_addSuiteNamed_1, suiteName !is null ? suiteName.id_ : null);
    }

    public NSArray arrayForKey (NSString defaultName)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_arrayForKey_1, defaultName !is null ? defaultName.id_ : null);
        return result !is null ? new NSArray(result) : null;
    }

    public bool boolForKey (NSString defaultName)
    {
        return OS.objc_msgSend(this.id_, OS.sel_boolForKey_1, defaultName !is null ? defaultName.id_ : null) !is null;
    }

    public NSData dataForKey (NSString defaultName)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_dataForKey_1, defaultName !is null ? defaultName.id_ : null);
        return result !is null ? new NSData(result) : null;
    }

    public NSDictionary dictionaryForKey (NSString defaultName)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_dictionaryForKey_1, defaultName !is null ? defaultName.id_ : null);
        return result !is null ? new NSDictionary(result) : null;
    }

    public NSDictionary dictionaryRepresentation ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_dictionaryRepresentation);
        return result !is null ? new NSDictionary(result) : null;
    }

    public double doubleForKey (NSString defaultName)
    {
        return cast(double) OS.objc_msgSend_fpret(this.id_, OS.sel_doubleForKey_1, defaultName !is null ? defaultName.id_ : null);
    }

    public float floatForKey (NSString defaultName)
    {
        return cast(float) OS.objc_msgSend_fpret(this.id_, OS.sel_floatForKey_1, defaultName !is null ? defaultName.id_ : null);
    }

    public id initWithUser (NSString username)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithUser_1, username !is null ? username.id_ : null);
        return result !is null ? new id(result) : null;
    }

    public NSInteger integerForKey (NSString defaultName)
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_integerForKey_1, defaultName !is null ? defaultName.id_ : null);
    }

    public id objectForKey (NSString defaultName)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_objectForKey_1, defaultName !is null ? defaultName.id_ : null);
        return result !is null ? new id(result) : null;
    }

    public bool objectIsForcedForKey_ (NSString key)
    {
        return OS.objc_msgSend(this.id_, OS.sel_objectIsForcedForKey_1, key !is null ? key.id_ : null) !is null;
    }

    public bool objectIsForcedForKey_inDomain_ (NSString key, NSString domain)
    {
        return OS.objc_msgSend(this.id_, OS.sel_objectIsForcedForKey_1inDomain_1, key !is null ? key.id_ : null, domain !is null ? domain.id_ : null) !is null;
    }

    public NSDictionary persistentDomainForName (NSString domainName)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_persistentDomainForName_1, domainName !is null ? domainName.id_ : null);
        return result !is null ? new NSDictionary(result) : null;
    }

    public NSArray persistentDomainNames ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_persistentDomainNames);
        return result !is null ? new NSArray(result) : null;
    }

    public void registerDefaults (NSDictionary registrationDictionary)
    {
        OS.objc_msgSend(this.id_, OS.sel_registerDefaults_1, registrationDictionary !is null ? registrationDictionary.id_ : null);
    }

    public void removeObjectForKey (NSString defaultName)
    {
        OS.objc_msgSend(this.id_, OS.sel_removeObjectForKey_1, defaultName !is null ? defaultName.id_ : null);
    }

    public void removePersistentDomainForName (NSString domainName)
    {
        OS.objc_msgSend(this.id_, OS.sel_removePersistentDomainForName_1, domainName !is null ? domainName.id_ : null);
    }

    public void removeSuiteNamed (NSString suiteName)
    {
        OS.objc_msgSend(this.id_, OS.sel_removeSuiteNamed_1, suiteName !is null ? suiteName.id_ : null);
    }

    public void removeVolatileDomainForName (NSString domainName)
    {
        OS.objc_msgSend(this.id_, OS.sel_removeVolatileDomainForName_1, domainName !is null ? domainName.id_ : null);
    }

    public static void resetStandardUserDefaults ()
    {
        OS.objc_msgSend(OS.class_NSUserDefaults, OS.sel_resetStandardUserDefaults);
    }

    public void setBool (bool value, NSString defaultName)
    {
        OS.objc_msgSend(this.id_, OS.sel_setBool_1forKey_1, value, defaultName !is null ? defaultName.id_ : null);
    }

    public void setDouble (double value, NSString defaultName)
    {
        OS.objc_msgSend(this.id_, OS.sel_setDouble_1forKey_1, value, defaultName !is null ? defaultName.id_ : null);
    }

    public void setFloat (float value, NSString defaultName)
    {
        OS.objc_msgSend(this.id_, OS.sel_setFloat_1forKey_1, value, defaultName !is null ? defaultName.id_ : null);
    }

    public void setInteger (NSInteger value, NSString defaultName)
    {
        OS.objc_msgSend(this.id_, OS.sel_setInteger_1forKey_1, value, defaultName !is null ? defaultName.id_ : null);
    }

    public void setObject (id value, NSString defaultName)
    {
        OS.objc_msgSend(this.id_, OS.sel_setObject_1forKey_1, value !is null ? value.id_ : null, defaultName !is null ? defaultName.id_ : null);
    }

    public void setPersistentDomain (NSDictionary domain, NSString domainName)
    {
        OS.objc_msgSend(this.id_, OS.sel_setPersistentDomain_1forName_1, domain !is null ? domain.id_ : null,
                domainName !is null ? domainName.id_ : null);
    }

    public void setVolatileDomain (NSDictionary domain, NSString domainName)
    {
        OS.objc_msgSend(this.id_, OS.sel_setVolatileDomain_1forName_1, domain !is null ? domain.id_ : null, domainName !is null ? domainName.id_ : null);
    }

    public static NSUserDefaults standardUserDefaults ()
    {
        objc.id result = OS.objc_msgSend(OS.class_NSUserDefaults, OS.sel_standardUserDefaults);
        return result !is null ? new NSUserDefaults(result) : null;
    }

    public NSArray stringArrayForKey (NSString defaultName)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_stringArrayForKey_1, defaultName !is null ? defaultName.id_ : null);
        return result !is null ? new NSArray(result) : null;
    }

    public NSString stringForKey (NSString defaultName)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_stringForKey_1, defaultName !is null ? defaultName.id_ : null);
        return result !is null ? new NSString(result) : null;
    }

    public bool synchronize ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_synchronize) !is null;
    }

    public NSDictionary volatileDomainForName (NSString domainName)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_volatileDomainForName_1, domainName !is null ? domainName.id_ : null);
        return result !is null ? new NSDictionary(result) : null;
    }

    public NSArray volatileDomainNames ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_volatileDomainNames);
        return result !is null ? new NSArray(result) : null;
    }

}