Luky/System/LLPersistantSettings.m

00001 //
00002 //  LLPersistantSettings.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 20/08/2006.
00006 //  Copyright 2006 Luky Soft. All rights reserved.
00007 //
00008 
00009 #import "LLPersistantSettings.h"
00010 
00011 
00012 @implementation LLPersistantSettings
00013 
00014 LLPersistantSettings* defaultSettings;
00015 
00016 - (id) init {
00017     self = [super init];
00018     if (self != nil) {
00019         
00020         NSString *pathToResources = [[NSBundle mainBundle] resourcePath];
00021         pathToSettings = [NSString stringWithFormat:@"%@/settings.xml", pathToResources];
00022         [pathToSettings retain];
00023         
00024         // load settings
00025         settings = [[NSMutableDictionary alloc] initWithContentsOfFile:pathToSettings];
00026               
00027         if ([settings count] == 0) {
00028             // something went wrong ?
00029             NSLog(@"LLPersistantSettings.init WARNING: settings file is empty");
00030         } 
00031     }
00032     return self;
00033 }
00034 
00035 + (LLPersistantSettings*) defaultSettings {
00036     if (defaultSettings == nil) {
00037         defaultSettings = [[LLPersistantSettings alloc] init];
00038     }
00039     return defaultSettings;
00040 }
00041 
00042 - (void)update {
00043     // we could check if something really changed..
00044     [settings writeToFile:pathToSettings atomically:YES];
00045 }
00046 
00047 - (void)removeAllObjects {
00048     [settings removeAllObjects];
00049     [self update];
00050 }
00051 
00052 - (void)removeObjectForKey:(id)aKey {
00053     [settings removeObjectForKey:aKey];
00054     [self update];
00055 }
00056 
00057 - (void)setObject:(id)anObject forKey:(id)aKey {
00058     [settings setObject:anObject forKey:aKey];
00059     [self update];
00060 }
00061 
00062 - (void)setValue:(id)value forKey:(NSString *)key {
00063     [settings setValue:value forKey:key];
00064     [self update];
00065 }
00066 
00067 - (void)setLazyObject:(id)anObject forKey:(id)aKey {
00068     [settings setObject:anObject forKey:aKey];
00069 }
00070 
00071 - (void)setLazyValue:(id)value forKey:(NSString *)key{
00072     [settings setValue:value forKey:key];
00073 }
00074 
00075 - (NSArray *)allKeys {
00076     return [settings allKeys];
00077 }
00078 
00079 - (NSArray *)allValues {
00080     return [settings allValues];
00081 }
00082 
00083 - (unsigned)count {
00084     return [settings count];
00085 }
00086 
00087 - (NSEnumerator *)keyEnumerator {
00088     return [settings keyEnumerator];
00089 }
00090 
00091 - (NSEnumerator *)objectEnumerator {
00092     return [settings objectEnumerator];
00093 }
00094 
00095 - (id)objectForKey:(id)aKey {
00096     return [settings objectForKey:aKey];
00097 }
00098 
00099 - (id)valueForKey:(NSString *)key {
00100     return [settings valueForKey:key];
00101 }
00102 
00103 
00104 @end

Generated on Sat Aug 26 21:14:16 2006 for MacTrek by  doxygen 1.4.7