12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /*
- * StateModel.m
- *
- * Copyright (c) 2013, Thomas Buck <xythobuz@xythobuz.de>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #import "StateModel.h"
-
- @implementation StateModel
-
- @synthesize username, modhash, useSubscriptions, subreddits, length, showSubreddit, titleLength, refreshInterval;
-
- NSString *s_username = @"username";
- NSString *s_modhash = @"modhash";
- NSString *s_useSubs = @"subscriptions";
- NSString *s_subreddits = @"subreddits";
- NSString *s_length = @"length";
- NSString *s_subs = @"showSubs";
- NSString *s_title = @"titleLength";
- NSString *s_refresh = @"refreshInterval";
-
- -(void)registerDefaultPreferences {
- NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
- NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObject:@"" forKey:s_username];
- [appDefaults setValue:@"" forKey:s_modhash];
- [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_useSubs];
- [appDefaults setValue:[NSNumber numberWithInt:10] forKey:s_length];
- [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_subs];
- [appDefaults setValue:[NSNumber numberWithInt:66] forKey:s_title];
- [appDefaults setValue:[NSNumber numberWithInt:5] forKey:s_refresh];
- [store registerDefaults:appDefaults];
- }
-
- -(void)savePreferences {
- NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
- [store setObject:username forKey:s_username];
- [store setObject:modhash forKey:s_modhash];
- [store setBool:useSubscriptions forKey:s_useSubs];
- [store setObject:subreddits forKey:s_subreddits];
- [store setInteger:length forKey:s_length];
- [store setBool:showSubreddit forKey:s_subs];
- [store setInteger:titleLength forKey:s_title];
- [store setInteger:refreshInterval forKey:s_refresh];
- [store synchronize];
- }
-
- -(void)loadPreferences {
- NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
- [store synchronize];
- username = [store stringForKey:s_username];
- modhash = [store stringForKey:s_modhash];
- useSubscriptions = [store boolForKey:s_useSubs];
- subreddits = [store arrayForKey:s_subreddits];
- length = [store integerForKey:s_length];
- showSubreddit = [store boolForKey:s_subs];
- titleLength = [store integerForKey:s_title];
- refreshInterval = [store integerForKey:s_refresh];
- }
-
- @end
|