1 | //␊ |
2 | // TableViewsController.mm␊ |
3 | // ChameleonPrefPane␊ |
4 | //␊ |
5 | // Created by Rekursor on 1/29/10.␊ |
6 | //␊ |
7 | ␊ |
8 | #import "ChameleonPrefPane.h"␊ |
9 | #import "ChameleonPropertyList.h"␊ |
10 | #import "PreferencesControllerBase.H"␊ |
11 | #import "TableViewsController.h"␊ |
12 | #import "BootSetupController.h"␊ |
13 | #import "ShellProcess.h"␊ |
14 | ␊ |
15 | #import <SecurityFoundation/SFAuthorization.h>␊ |
16 | #import <SecurityInterface/SFAuthorizationView.h>␊ |
17 | #include <string>␊ |
18 | #include <vector>␊ |
19 | ␊ |
20 | //--------------------------------------------------------------------------␊ |
21 | // MenuEntry definitions␊ |
22 | //--------------------------------------------------------------------------␊ |
23 | typedef enum { ␊ |
24 | ␉PaneBootFrom, PaneBootSetup, PaneBootFlags, PanePeripherals, ␊ |
25 | ␉PaneAdvanced, PaneEfiInject, PaneSmbios, PaneAbout␊ |
26 | } MenuEntryPane;␊ |
27 | ␊ |
28 | struct MenuEntry␊ |
29 | {␊ |
30 | ␉NSString* title;␊ |
31 | ␉MenuEntryPane pane;␊ |
32 | } ;␊ |
33 | ␊ |
34 | static const MenuEntry sMenuList[] =␊ |
35 | {␊ |
36 | ␉{@" Boot From ...", PaneBootFrom}, ␊ |
37 | ␉{@" Boot Setup",␉PaneBootSetup},␊ |
38 | ␉{@" Boot Flags", PaneBootFlags}, ␊ |
39 | ␉{@" Peripherals", PanePeripherals}, ␊ |
40 | ␉{@" Advanced", PaneAdvanced}, ␊ |
41 | ␉{@" Efi Inject", PaneEfiInject}, ␊ |
42 | ␉{@" SMBIOS", PaneSmbios},␊ |
43 | ␉{@" About", PaneAbout}␊ |
44 | };␊ |
45 | const int iMenuListSize = sizeof(sMenuList)/ sizeof(MenuEntry);␊ |
46 | ␊ |
47 | static TableViewsController* _instance; // Singleton DP def.␊ |
48 | ␊ |
49 | //--------------------------------------------------------------------------␊ |
50 | ␊ |
51 | @implementation TableViewsController␊ |
52 | ␊ |
53 | //--------------------------------------------------------------------------␊ |
54 | - (id) init␊ |
55 | {␊ |
56 | ␉[super init];␊ |
57 | ␉_instance = self;␊ |
58 | ␉␊ |
59 | ␉currentRowSel = -1;␊ |
60 | ␉// set the image to display the current file being played␊ |
61 | ␉mMacOSXImage = [self getImageResource: @"MacOSX" ofType: @"png"];␊ |
62 | ␉mWindowsImage = [self getImageResource: @"Windows" ofType: @"png"];␊ |
63 | ␉mLinuxImage = [self getImageResource: @"Linux" ofType: @"png"];␊ |
64 | ␉mCDROMImage = [self getImageResource: @"CDROM" ofType: @"png"];␊ |
65 | ␉mUnknownImage = [self getImageResource: @"Chameleon" ofType: @"tiff"];␊ |
66 | ␉␊ |
67 | ␉return self;␊ |
68 | }␊ |
69 | ␊ |
70 | //--------------------------------------------------------------------------␊ |
71 | // Singleton impl␊ |
72 | + (TableViewsController*) instance␊ |
73 | {␊ |
74 | ␉return _instance;␊ |
75 | }␊ |
76 | //--------------------------------------------------------------------------␊ |
77 | + (bool) isUnlocked␊ |
78 | { ␊ |
79 | ␉return [[ChameleonPrefPane instance] isUnlocked];␊ |
80 | }␊ |
81 | ␊ |
82 | //--------------------------------------------------------------------------␊ |
83 | + (AuthorizationRef) authorization␊ |
84 | { ␊ |
85 | ␉return [TableViewsController isUnlocked] ?␊ |
86 | ␉[ [ [ChameleonPrefPane instance]->authView authorization] authorizationRef] : NULL;␊ |
87 | }␊ |
88 | //--------------------------------------------------------------------------␊ |
89 | - (NSTableView*) partitionsTable␊ |
90 | {␊ |
91 | ␉return mPartitionsTable;␊ |
92 | }␊ |
93 | //--------------------------------------------------------------------------␊ |
94 | - (id) getImageResource: (NSString *) str ofType: (NSString*) sType␊ |
95 | {␊ |
96 | ␉NSImage * img=nil;␊ |
97 | ␉if(!str) return nil;␊ |
98 | ␉NSBundle * b = [NSBundle bundleForClass:[self class]];␊ |
99 | ␉NSString* sRes = [b pathForResource: str ofType:sType ];␊ |
100 | ␉img = [[NSImage alloc] initWithContentsOfFile: sRes];␊ |
101 | ␉return img;␊ |
102 | }␊ |
103 | ␊ |
104 | //--------------------------------------------------------------------------␊ |
105 | - (void)tableViewSelectionDidChange:(NSNotification *)notification {␊ |
106 | ␉␊ |
107 | ␉NSTableView* tv= [notification object];␊ |
108 | ␉if (tv == mPartitionsTable)␊ |
109 | ␉{␊ |
110 | ␉␉if ([tv selectedRow] != currentRowSel)␊ |
111 | ␉␉{␊ |
112 | ␉␉␉currentRowSel = [tv selectedRow];␊ |
113 | ␉␉␉if (currentRowSel>=0)␊ |
114 | ␉␉␉{␊ |
115 | ␉␉␉␉const std::vector<PartitionInfo>& partInfo = PartitionExtractor::instance().partList();␊ |
116 | ␉␉␉␉char hd[7+1]="hd(n,m)";␊ |
117 | ␉␉␉␉hd[3]= ('0'+partInfo[currentRowSel].disk());␊ |
118 | ␉␉␉␉hd[5]= ('0'+partInfo[currentRowSel].partition());␉␊ |
119 | ␉␉␉␉AuthorizationRef auth= [TableViewsController authorization];␊ |
120 | ␉␉␉␉if(BootProp::instance().setStringForKey(kDefaultPartition, hd))␊ |
121 | ␉␉␉␉␉BootProp::instance().save(auth);␊ |
122 | ␉␉␉␉[ PreferencesControllerBase loadOptionsFromBootFile];␊ |
123 | ␉␉␉}␊ |
124 | ␉␉␉else␊ |
125 | ␉␉␉{ // no line selected␊ |
126 | ␉␉␉␉BootProp::instance().removeKeyAndValue(kDefaultPartition);␊ |
127 | ␉␉␉␉[ PreferencesControllerBase loadOptionsFromBootFile];␊ |
128 | ␉␉␉␉␊ |
129 | ␉␉␉}␊ |
130 | ␉␉}␊ |
131 | ␉}␊ |
132 | ␉else if (tv == mTabViewPanesSelect)␊ |
133 | ␉{␊ |
134 | ␉␉int selected = [tv selectedRow];␊ |
135 | ␉␉if(selected>=0)␊ |
136 | ␉␉{␊ |
137 | ␉␉␉switch (sMenuList[selected].pane) ␊ |
138 | ␉␉␉{␊ |
139 | ␉␉␉␉case PaneBootFrom:␊ |
140 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mBootFrom];␊ |
141 | ␉␉␉␉␉break;␊ |
142 | ␉␉␉␉case PaneBootSetup:␊ |
143 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mBootSetup];␊ |
144 | ␉␉␉␉␉break;␊ |
145 | ␉␉␉␉case PaneBootFlags:␊ |
146 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mBootFlags];␊ |
147 | ␉␉␉␉␉break;␊ |
148 | ␉␉␉␉case PanePeripherals:␊ |
149 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mPeripherals];␊ |
150 | ␉␉␉␉␉break;␊ |
151 | ␉␉␉␉case PaneEfiInject:␊ |
152 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mEfiInject];␊ |
153 | ␉␉␉␉␉break;␊ |
154 | ␉␉␉␉case PaneAdvanced:␊ |
155 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mAdvanced];␊ |
156 | ␉␉␉␉␉break;␊ |
157 | ␉␉␉␉case PaneSmbios:␊ |
158 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mSmbios];␊ |
159 | ␉␉␉␉␉break;␊ |
160 | ␉␉␉␉case PaneAbout:␊ |
161 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mAbout];␊ |
162 | ␉␉␉␉␉break;␊ |
163 | ␉␉␉␉default:␊ |
164 | ␉␉␉␉␉break;␊ |
165 | ␉␉␉}␊ |
166 | ␉␉␉[mTabViewPanes setNeedsDisplay: true ];␊ |
167 | ␉␉}␊ |
168 | ␉}␊ |
169 | }␊ |
170 | ␊ |
171 | //--------------------------------------------------------------------------␊ |
172 | - (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView␊ |
173 | {␊ |
174 | ␉int size=0;␊ |
175 | ␉if (tableView == mPartitionsTable)␊ |
176 | ␉␉size = PartitionExtractor::instance().partList().size();␊ |
177 | ␉else␊ |
178 | ␉␉size = iMenuListSize;␊ |
179 | ␉return size;␊ |
180 | }␊ |
181 | ␊ |
182 | //--------------------------------------------------------------------------␊ |
183 | - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row␊ |
184 | {␊ |
185 | ␉id ret=nil;␊ |
186 | ␉␊ |
187 | ␉const std::vector<PartitionInfo>& partInfo = PartitionExtractor::instance().partList();␊ |
188 | ␉␊ |
189 | ␉if (tableColumn == mPartitionImgColumn) ␊ |
190 | ␉{␊ |
191 | ␉␉switch(partInfo[row].imageIndexFromFs())␊ |
192 | ␉␉{␊ |
193 | ␉␉␉case 0:␊ |
194 | ␉␉␉␉ret = mMacOSXImage;␊ |
195 | ␉␉␉␉break;␊ |
196 | ␉␉␉case 1:␊ |
197 | ␉␉␉␉ret = mWindowsImage;␊ |
198 | ␉␉␉␉break;␊ |
199 | ␉␉␉case 2:␊ |
200 | ␉␉␉␉ret = mLinuxImage;␊ |
201 | ␉␉␉␉break;␊ |
202 | ␉␉␉default:␊ |
203 | ␉␉␉␉ret = mUnknownImage;␊ |
204 | ␉␉␉␉break;␊ |
205 | ␉␉␉␉␊ |
206 | ␉␉}␊ |
207 | ␉}␊ |
208 | ␉else if (tableColumn == mFileSystemColumn) ␊ |
209 | ␉{␊ |
210 | ␉␉ret = [NSString stringWithFormat: @"%s", partInfo[row].cfsType() ];␊ |
211 | ␉}␊ |
212 | ␉else if (tableColumn == mPartitionNameColumn) ␊ |
213 | ␉{␊ |
214 | ␉␉ret = [NSString stringWithFormat: @"%s", partInfo[row].clabel()␉];␊ |
215 | ␉}␊ |
216 | ␉else if (tableColumn == mPartitionIDColumn) ␊ |
217 | ␉{␊ |
218 | ␉␉ret= [NSString stringWithFormat: @"hd(%d,%d)", ␊ |
219 | ␉␉␉ partInfo[row].disk(),␊ |
220 | ␉␉␉ partInfo[row].partition()␊ |
221 | ␉␉␉ ];␊ |
222 | ␉} ␊ |
223 | ␉// menu tv handling␊ |
224 | ␉else if (tableColumn == mMenuName) ␊ |
225 | ␉{␊ |
226 | ␉␉ret = sMenuList[row].title;␊ |
227 | ␉}␉␊ |
228 | ␉return ret;␊ |
229 | }␊ |
230 | //--------------------------------------------------------------------------␊ |
231 | ␊ |
232 | @end␊ |
233 | |