1 | //␊ |
2 | // PreferencesControllerBase.mm␊ |
3 | // ChameleonPrefPane␊ |
4 | //␊ |
5 | // Created by Rekursor on 1/22/10.␊ |
6 | //␊ |
7 | ␊ |
8 | #import "PreferencesControllerBase.h"␊ |
9 | #include <string>␊ |
10 | ␊ |
11 | ␊ |
12 | @implementation PreferencesControllerBase␊ |
13 | ␊ |
14 | -(ChameleonPrefPane*) chameleon { return [ChameleonPrefPane instance]; }␊ |
15 | ␊ |
16 | //--------------------------------------------------------------------------␊ |
17 | - (id) init␊ |
18 | {␊ |
19 | ␉self = [super init];␊ |
20 | ␉return self;␊ |
21 | }␉␊ |
22 | ␊ |
23 | //--------------------------------------------------------------------------␊ |
24 | // from the id to desc map in prop, set all default values for dict␊ |
25 | + (void) setDefaultValues: (NSMutableDictionary*) dict ␊ |
26 | {␊ |
27 | ␉␊ |
28 | ␉for(const BootOptionDesc* bod = prop->firstOption();bod; bod=prop->nextOption())␊ |
29 | ␉{␊ |
30 | ␉␉switch (bod->Type) ␊ |
31 | ␉␉{␊ |
32 | ␉␉␉case OptionYesNo:␊ |
33 | ␉␉␉␉[(NSButton*)bod->ID setIntValue: (toupper(bod->Default[0])=='Y' ? 1 : 0) ];␊ |
34 | ␉␉␉␉break;␊ |
35 | ␉␉␉case OptionKernel:␊ |
36 | ␉␉␉case OptionString:␊ |
37 | ␉␉␉␉[(NSButton*)bod->ID setIntValue: 0 ];␊ |
38 | ␉␉␉case OptionKernel1:␊ |
39 | ␉␉␉␉[(NSTextField*)bod->contentID setStringValue: ␊ |
40 | ␉␉␉␉␉[[NSString alloc] initWithUTF8String: bod->Default] ];␊ |
41 | ␉␉␉␉break;␊ |
42 | ␉␉␉case OptionUnix:␊ |
43 | ␉␉␉␉[(NSButton*)bod->ID setIntValue: 0 ];␊ |
44 | ␉␉␉␉break;␊ |
45 | ␉␉␉␉␊ |
46 | ␉␉␉default:␊ |
47 | ␉␉␉␉break;␊ |
48 | ␉␉}␊ |
49 | ␉}␊ |
50 | }␊ |
51 | //--------------------------------------------------------------------------␊ |
52 | - (void) refreshLockState: (id) item␊ |
53 | {␊ |
54 | [item setEnabled:[[ChameleonPrefPane instance] isUnlocked]];␊ |
55 | ␉␊ |
56 | }␊ |
57 | ␊ |
58 | //--------------------------------------------------------------------------␊ |
59 | - (void) loadPreferences␊ |
60 | {␊ |
61 | ␉[ [ChameleonPrefPane instance] loadPreferences];␊ |
62 | }␊ |
63 | ␊ |
64 | //--------------------------------------------------------------------------␊ |
65 | - (bool) savePreferences␊ |
66 | {␊ |
67 | ␉return [ [ChameleonPrefPane instance] savePreferences: [self preferencesFile] ];␊ |
68 | ␉␊ |
69 | }␊ |
70 | //--------------------------------------------------------------------------␊ |
71 | -(NSMutableDictionary*) preferencesFile␊ |
72 | {␉␊ |
73 | ␉return [[ChameleonPrefPane instance] preferencesFile];␊ |
74 | }␊ |
75 | ␊ |
76 | //--------------------------------------------------------------------------␊ |
77 | -(NSMutableDictionary*) preferencesParts ␊ |
78 | { ␊ |
79 | ␉return [[ChameleonPrefPane instance] preferencesParts];␊ |
80 | }␊ |
81 | ␊ |
82 | //--------------------------------------------------------------------------␊ |
83 | - (bool) handleSender: (id) sender withButton: (NSButton*) button forKey:(const char*) key␊ |
84 | {␊ |
85 | ␉return [self handleSender: sender withButton: button andField: nil forKey: key];␊ |
86 | }␊ |
87 | ␊ |
88 | //--------------------------------------------------------------------------␊ |
89 | - (bool) handleSender: (id) sender withButton: (NSButton*) button andField:(NSTextField*) field forKey:(const char*) key␊ |
90 | {␊ |
91 | ␉if((NSButton*)sender!=button || (NSTextField*)sender !=field) return false;␊ |
92 | ␉if ((NSButton*)sender==button)␊ |
93 | ␉{␊ |
94 | ␉␉if (prop && prop->isValid())␊ |
95 | ␉␉{␊ |
96 | ␉␉␉std::string keyValue = ␉prop->getStringForKey(key);␊ |
97 | ␉␉␉if ( !![button intValue])␊ |
98 | ␉␉␉{␊ |
99 | ␉␉␉␉␊ |
100 | ␉␉␉}␊ |
101 | ␉␉␉else␊ |
102 | ␉␉␉{␊ |
103 | ␉␉␉␉␊ |
104 | ␉␉␉}␊ |
105 | ␉␉}␊ |
106 | ␉}␊ |
107 | ␉else ␊ |
108 | ␉{ // field␊ |
109 | ␉␉␊ |
110 | ␉}␊ |
111 | ␊ |
112 | ␉return true;␊ |
113 | }␊ |
114 | ␊ |
115 | @end␊ |
116 | |