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 | ␉␉␉␉case PaneBootFrom:␊ |
139 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mBootFrom];␊ |
140 | ␉␉␉␉␉break;␊ |
141 | ␉␉␉␉case PaneBootSetup:␊ |
142 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mBootSetup];␊ |
143 | ␉␉␉␉␉break;␊ |
144 | ␉␉␉␉case PaneBootFlags:␊ |
145 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mBootFlags];␊ |
146 | ␉␉␉␉␉break;␊ |
147 | ␉␉␉␉case PanePeripherals:␊ |
148 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mPeripherals];␊ |
149 | ␉␉␉␉␉break;␊ |
150 | ␉␉␉␉case PaneEfiInject:␊ |
151 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mEfiInject];␊ |
152 | ␉␉␉␉␉break;␊ |
153 | ␉␉␉␉case PaneAdvanced:␊ |
154 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mAdvanced];␊ |
155 | ␉␉␉␉␉break;␊ |
156 | ␉␉␉␉case PaneSmbios:␊ |
157 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mSmbios];␊ |
158 | ␉␉␉␉␉break;␊ |
159 | ␉␉␉␉case PaneAbout:␊ |
160 | ␉␉␉␉␉[mTabViewPanes selectTabViewItem: mAbout];␊ |
161 | ␉␉␉␉␉break;␊ |
162 | ␉␉␉␉default:␊ |
163 | ␉␉␉␉␉break;␊ |
164 | ␉␉␉}␊ |
165 | ␉␉}␊ |
166 | ␉}␊ |
167 | }␊ |
168 | ␊ |
169 | //--------------------------------------------------------------------------␊ |
170 | - (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView␊ |
171 | {␊ |
172 | ␉int size=0;␊ |
173 | ␉if (tableView == mPartitionsTable)␊ |
174 | ␉␉size = PartitionExtractor::instance().partList().size();␊ |
175 | ␉else␊ |
176 | ␉␉size = iMenuListSize;␊ |
177 | ␉return size;␊ |
178 | }␊ |
179 | ␊ |
180 | //--------------------------------------------------------------------------␊ |
181 | - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row␊ |
182 | {␊ |
183 | ␉id ret=nil;␊ |
184 | ␉␊ |
185 | ␉const std::vector<PartitionInfo>& partInfo = PartitionExtractor::instance().partList();␊ |
186 | ␉␊ |
187 | ␉if (tableColumn == mPartitionImgColumn) ␊ |
188 | ␉{␊ |
189 | ␉␉switch(partInfo[row].imageIndexFromFs())␊ |
190 | ␉␉{␊ |
191 | ␉␉␉case 0:␊ |
192 | ␉␉␉␉ret = mMacOSXImage;␊ |
193 | ␉␉␉␉break;␊ |
194 | ␉␉␉case 1:␊ |
195 | ␉␉␉␉ret = mWindowsImage;␊ |
196 | ␉␉␉␉break;␊ |
197 | ␉␉␉case 2:␊ |
198 | ␉␉␉␉ret = mLinuxImage;␊ |
199 | ␉␉␉␉break;␊ |
200 | ␉␉␉default:␊ |
201 | ␉␉␉␉ret = mUnknownImage;␊ |
202 | ␉␉␉␉break;␊ |
203 | ␉␉␉␉␊ |
204 | ␉␉}␊ |
205 | ␉}␊ |
206 | ␉else if (tableColumn == mFileSystemColumn) ␊ |
207 | ␉{␊ |
208 | ␉␉ret = [NSString stringWithFormat: @"%s", partInfo[row].cfsType() ];␊ |
209 | ␉}␊ |
210 | ␉else if (tableColumn == mPartitionNameColumn) ␊ |
211 | ␉{␊ |
212 | ␉␉ret = [NSString stringWithFormat: @"%s", partInfo[row].clabel()␉];␊ |
213 | ␉}␊ |
214 | ␉else if (tableColumn == mPartitionIDColumn) ␊ |
215 | ␉{␊ |
216 | ␉␉ret= [NSString stringWithFormat: @"hd(%d,%d)", ␊ |
217 | ␉␉␉ partInfo[row].disk(),␊ |
218 | ␉␉␉ partInfo[row].partition()␊ |
219 | ␉␉␉ ];␊ |
220 | ␉} ␊ |
221 | ␉// menu tv handling␊ |
222 | ␉else if (tableColumn == mMenuName) ␊ |
223 | ␉{␊ |
224 | ␉␉ret = sMenuList[row].title;␊ |
225 | ␉}␉␊ |
226 | ␉return ret;␊ |
227 | }␊ |
228 | //--------------------------------------------------------------------------␊ |
229 | ␊ |
230 | @end␊ |
231 | |