Main Page | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages

DAPreferences Class Reference

#import <DAPreferences.h>

List of all members.


Detailed Description

Alternative preferences structure for DownAndOut[tm].

The normal storage for preferences for screen-saver modules is in ~/Library/Preferences/ByHost, with the subsequent path hashed from machine-dependent data. This was not satisfactory to those who specified DownAndOut, as they wanted a quick way to deposit a DownAndOut configuration into any user's preference folder.

This class tracks a mutable-dictionary document, effectively duplicating the NSUserDefaults mechanism with the preferences in the dictionary, and the file in the assigned path. It knows when it's dirty, and can flush itself out to the file. It provides key accessors for the common data types.

Bug:
DAPreferences ought to support usage as a singleton.

Definition at line 32 of file DAPreferences.h.

Public Member Functions

(id) - initWithDictionary:forPath:
 Designated initializer for a new preference file.
(id) - initWithPath:
 Designated initializer for existing preference file, when there are no default values.
(id) - initWithDefaults:
 Initialize the DownAndOut[tm] preferences with defaults.
(void) - flushToFile
 Write the preference file if the contents have changed.
(int) - integerForKey:
 Access integer value for a preference.
(void) - setInteger:forKey:
 Set integer value for a preference.
(id) - objectForKey:
 Access object value for a preference.
(void) - setObject:forKey:
 Set object value for a preference.
(BOOL) - boolForKey:
 Access BOOL value for a preference.
(void) - setBool:forKey:
 Set Boolean value for a preference.
(NSData *) - dataForKey:
 Access NSData stored under a key.
(NSString *) - stringForKey:
 Access NSString stored under a key.
(void) - removeObjectForKey:
 Remove a preference from the dictionary.
(void) - dealloc [implementation]
 Unremarkable deallocator.

Protected Attributes

NSMutableDictionary * prefs
 the preferences dictionary
NSString * path
 path to preferences file
BOOL dirty
 whether prefs have changed since last write.


Member Function Documentation

- (BOOL) boolForKey: (NSString *)  aKey  
 

Access BOOL value for a preference.

Parameters:
aKey NSString, the preference sought.
Return values:
YES if the preference existed and was YES.
NO if the preference did not exist, or was NO.

Definition at line 95 of file DAPreferences.m.

References objectForKey:.

- (NSData *) dataForKey: (NSString *)  aKey  
 

Access NSData stored under a key.

The inverse of this operation is setObject:forKey:

Parameters:
aKey NSString, the preference sought.
Return values:
NSData the value of the preference, if it exists and is NSData.
nil if the preference did not exist, or was not NSData.

Definition at line 106 of file DAPreferences.m.

References objectForKey:.

- (void) flushToFile  
 

Write the preference file if the contents have changed.

This method writes the preferences dictionary to the designated preference file atomically, if any preference has changed since the last write.

Definition at line 65 of file DAPreferences.m.

References dirty, and prefs.

- (id) initWithDefaults: (NSDictionary *)  initial  
 

Initialize the DownAndOut[tm] preferences with defaults.

This method hard-codes a path to edu.uchicago.DownAndOut[tm].plist in the user's preferences folder. An attempt is made to read preferences from that file with initWithPath:. If that fails, that path and the given initial preferences are used in initWithDictionary:forPath:.

Parameters:
initial NSDictionary, the values the preferences are to have if none have been set before.
Return values:
self if the preference file exists and could be read.
id a fresh DAPreferences object if no usable preference file existed.

Definition at line 49 of file DAPreferences.m.

References initWithPath:.

- (id) initWithDictionary: (NSDictionary *)  initial
forPath: (NSString *)  fullPath
 
 

Designated initializer for a new preference file.

Creates a DAPreferences ex nihilo, with preference state and a path to a file, which will be created or overwritten when the preferences are written. This method is for internal use only, as there it makes little sense to do this without more context.

Parameters:
initial NSDictionary containing the current state of the preferences.
fullPath NSString, path to the preference file.
Return values:
self always.

Definition at line 29 of file DAPreferences.m.

References dirty, path, and prefs.

- (id) initWithPath: (NSString *)  fullPath  
 

Designated initializer for existing preference file, when there are no default values.

The dictionary file at fullPath is read and made the preference set. Changes will be written back to fullPath.

Parameters:
fullPath NSString, path to the preference file.
Return values:
self if a dictionary was read from fullPath.
nil if fullPath was not a dictionary file.

Definition at line 37 of file DAPreferences.m.

References dirty, path, and prefs.

Referenced by initWithDefaults:.

- (int) integerForKey: (NSString *)  aKey  
 

Access integer value for a preference.

Parameters:
aKey NSString, the preference sought.
Return values:
int value for the preference, including zero.
zero if the preference did not exist.

Definition at line 73 of file DAPreferences.m.

References objectForKey:.

- (id) objectForKey: (NSString *)  aKey  
 

Access object value for a preference.

Parameters:
aKey NSString, the preference sought.
Return values:
id the value for the preference.
nil if the preference did not exist.

Definition at line 84 of file DAPreferences.m.

References prefs.

Referenced by boolForKey:, dataForKey:, integerForKey:, and stringForKey:.

- (void) removeObjectForKey: (NSString *)  aKey  
 

Remove a preference from the dictionary.

Marks the preference dictionary dirty.

Parameters:
aKey NSString, the preference to delete.

Definition at line 118 of file DAPreferences.m.

References dirty, and prefs.

- (void) setBool: (BOOL)  aBool
forKey: (NSString *)  aKey
 
 

Set Boolean value for a preference.

Marks the preference dictionary dirty.

Parameters:
aBool BOOL, the value to set.
aKey NSString, the preference to set.

Definition at line 101 of file DAPreferences.m.

References setObject:forKey:.

- (void) setInteger: (int)  anInt
forKey: (NSString *)  aKey
 
 

Set integer value for a preference.

Marks the preference dictionary dirty.

Parameters:
anInt int, the value to set.
aKey NSString, the preference to set.

Definition at line 79 of file DAPreferences.m.

References setObject:forKey:.

- (void) setObject: (id)  value
forKey: (NSString *)  aKey
 
 

Set object value for a preference.

Marks the preference dictionary dirty.

Parameters:
value id, the value to set.
aKey NSString, the preference to set.

Definition at line 89 of file DAPreferences.m.

References dirty, and prefs.

Referenced by setBool:forKey:, and setInteger:forKey:.

- (NSString *) stringForKey: (NSString *)  aKey  
 

Access NSString stored under a key.

The inverse of this operation is setObject:forKey:

Parameters:
aKey NSString, the preference sought.
Return values:
NSString the value of the preference, if it exists and is NSString.
nil if the preference did not exist, or was not NSString.

Definition at line 112 of file DAPreferences.m.

References objectForKey:.


The documentation for this class was generated from the following files:
Generated on Wed Jan 25 12:04:27 2006 for DownAndOut by  doxygen 1.4.4