Chameleon Applications

Chameleon Applications Svn Source Tree

Root/trunk/ChameleonPrefPane/Sources/TableViewsController.mm

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#import "CenterTextFieldCell.h"
15#import "PartitionInfoManager.h"
16
17#import <SecurityFoundation/SFAuthorization.h>
18#import <SecurityInterface/SFAuthorizationView.h>
19#include <string>
20#include <vector>
21
22//--------------------------------------------------------------------------
23// MenuEntry definitions
24//--------------------------------------------------------------------------
25typedef enum {
26PaneBootFrom, PaneBootSetup, PaneBootFlags, PanePeripherals,
27PaneAdvanced, PaneEfiInject, PaneSmbios, PaneAbout
28} MenuEntryPane;
29
30struct MenuEntry
31{
32NSString* title;
33MenuEntryPane pane;
34NSImage**img;
35};
36
37
38static NSImage*mImgPaneBootFrom;
39static NSImage*mImgPaneBootSetup;
40static NSImage*mImgPaneBootFlags;
41static NSImage*mImgPanePeripherals;
42static NSImage*mImgPaneAdvanced;
43static NSImage*mImgPaneEfiInject;
44static NSImage*mImgPaneSmbios;
45static NSImage*mImgPaneAbout;
46
47
48static const MenuEntry sMenuList[] =
49{
50{@"Boot_From", PaneBootFrom, &mImgPaneBootFrom},
51{@"Boot_Setup",PaneBootSetup, &mImgPaneBootSetup},
52{@"Boot_Flags", PaneBootFlags, &mImgPaneBootFlags},
53{@"Peripherals", PanePeripherals, &mImgPanePeripherals},
54{@"Efi_Inject", PaneEfiInject, &mImgPaneEfiInject},
55{@"Bios", PaneSmbios, &mImgPaneSmbios},
56{@"Advanced", PaneAdvanced, &mImgPaneAdvanced},
57{@"About", PaneAbout, &mImgPaneAbout}
58};
59const int iMenuListSize = sizeof(sMenuList)/ sizeof(MenuEntry);
60
61static TableViewsController* _instance; // Singleton DP def.
62
63
64//--------------------------------------------------------------------------
65@implementation TableViewsController
66//--------------------------------------------------------------------------
67- (id) init
68{
69[super init];
70_instance = self;
71
72currentRowSel = -1;
73// set the image to display the current file being played
74mMacOSXImage = [self getImageResource: @"MacOSX" ofType: @"png"];
75mWindowsImage = [self getImageResource: @"Windows" ofType: @"png"];
76mLinuxImage = [self getImageResource: @"Linux" ofType: @"png"];
77mCDROMImage = [self getImageResource: @"CDROM" ofType: @"png"];
78mUnknownImage = [self getImageResource: @"Chameleon" ofType: @"tiff"];
79
80mImgPaneBootFrom = [self getImageResource:@"disk" ofType:@"png"];
81mImgPaneBootSetup = [self getImageResource:@"wrench" ofType:@"png"];
82mImgPaneBootFlags = [self getImageResource:@"flag" ofType:@"png"];
83mImgPanePeripherals = [self getImageResource:@"plug" ofType:@"png"];
84mImgPaneAdvanced = [self getImageResource:@"advanced" ofType:@"png"];
85mImgPaneEfiInject = [self getImageResource:@"syringe" ofType:@"png"];
86mImgPaneSmbios = [self getImageResource:@"chip" ofType:@"png"];
87mImgPaneAbout = [self getImageResource:@"chamsmall" ofType:@"png"];
88
89return self;
90}
91
92//--------------------------------------------------------------------------
93// Singleton impl
94+ (TableViewsController*) instance
95{
96return _instance;
97}
98//--------------------------------------------------------------------------
99+ (bool) isUnlocked
100{
101return [[ChameleonPrefPane instance] isUnlocked];
102}
103
104//--------------------------------------------------------------------------
105+ (AuthorizationRef) authorization
106{
107return [TableViewsController isUnlocked] ?
108[ [ [ChameleonPrefPane instance]->authView authorization] authorizationRef] : NULL;
109}
110//--------------------------------------------------------------------------
111- (NSTableView*) partitionsTable
112{
113return mPartitionsTable;
114}
115//--------------------------------------------------------------------------
116- (id) getImageResource: (NSString *) str ofType: (NSString*) sType
117{
118NSImage * img=nil;
119if(!str) return nil;
120NSBundle * b = [NSBundle bundleForClass:[self class]];
121NSString* sRes = [b pathForResource: str ofType:sType ];
122img = [[NSImage alloc] initWithContentsOfFile: sRes];
123return img;
124}
125
126//--------------------------------------------------------------------------
127- (void)tableViewSelectionDidChange:(NSNotification *)notification {
128
129NSTableView* tv= [notification object];
130if (tv == mPartitionsTable)
131{
132if ([tv selectedRow] != currentRowSel)
133{
134currentRowSel = [tv selectedRow];
135if (currentRowSel>=0)
136{
137PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:currentRowSel];
138NSString* s;
139
140#if 0
141// Chameleon is difficult for now to synchronize with uuid
142// because windows partitions have a different uuid format than osx ones in the booter ...
143// we'll address that interfacing problem later, probably in chameleon itself first.
144if ( [partInfo vUUID].length>>0)
145s = [partInfo vUUID];
146else
147#endif
148s = [partInfo hdString];
149
150AuthorizationRef auth= [TableViewsController authorization];
151if(BootProp::instance().setStringForKey(kDefaultPartition, [s UTF8String]))
152BootProp::instance().save(auth);
153[ PreferencesControllerBase loadOptionsFromBootFile];
154[partInfo release];
155}
156else
157{ // no line selected
158BootProp::instance().removeKeyAndValue(kDefaultPartition);
159[ PreferencesControllerBase loadOptionsFromBootFile];
160
161}
162}
163}
164else if (tv == mTabViewPanesSelect)
165{
166int selected = [tv selectedRow];
167if(selected>=0)
168{
169switch (sMenuList[selected].pane)
170{
171case PaneBootFrom:
172[mTabViewPanes selectTabViewItem: mBootFrom];
173break;
174case PaneBootSetup:
175[mTabViewPanes selectTabViewItem: mBootSetup];
176break;
177case PaneBootFlags:
178[mTabViewPanes selectTabViewItem: mBootFlags];
179break;
180case PanePeripherals:
181[mTabViewPanes selectTabViewItem: mPeripherals];
182break;
183case PaneEfiInject:
184[mTabViewPanes selectTabViewItem: mEfiInject];
185break;
186case PaneAdvanced:
187[mTabViewPanes selectTabViewItem: mAdvanced];
188break;
189case PaneSmbios:
190[mTabViewPanes selectTabViewItem: mSmbios];
191break;
192case PaneAbout:
193[mTabViewPanes selectTabViewItem: mAbout];
194break;
195default:
196break;
197}
198[mTabViewPanes setNeedsDisplay: true ];
199}
200}
201}
202
203//--------------------------------------------------------------------------
204- (void) tableView:(NSTableView*) tableView setObjectValue:(id) object
205forTableColumn:(NSTableColumn*) tableColumn row:(NSInteger) row
206{
207if (object == nil) return;
208PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:row];
209if (tableColumn == mHideOrViewColumn)
210{
211[partInfo setHidden: ([object intValue] ? false : true) ];
212}
213[partInfo release];
214
215NSLog(@"object at column %@ row %d Set %@", [[tableColumn headerCell] stringValue], row, object);
216}
217//--------------------------------------------------------------------------
218- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
219{
220int size=0;
221if (tableView == mPartitionsTable)
222size = [PartsInfoMgr count];
223else
224size = iMenuListSize;
225return size;
226}
227
228//--------------------------------------------------------------------------
229- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
230{
231id ret=nil;
232if (tableView == mPartitionsTable)
233{
234PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:row];
235
236if (tableColumn == mHideOrViewColumn)
237{
238ret = [NSNumber numberWithInt:(int) [partInfo hidden] ? 0 : 1];
239}
240else if (tableColumn == mPartitionUIDColumn)
241{
242ret = [partInfo vUUID ];
243}
244else if (tableColumn == mPartitionImgColumn)
245{
246switch( [partInfo imageIndexFromFs])
247{
248case 0:
249ret = mMacOSXImage;
250break;
251case 1:
252ret = mWindowsImage;
253break;
254case 2:
255ret = mLinuxImage;
256break;
257default:
258ret = mUnknownImage;
259break;
260
261}
262}
263else if (tableColumn == mFileSystemColumn)
264{
265ret = [partInfo vKind];
266}
267else if (tableColumn == mPartitionNameColumn)
268{
269ret = [partInfo vAliasName]; // vAliasName is vName if no alias
270}
271else if (tableColumn == mPartitionIDColumn)
272{
273ret= [partInfo hdString];
274}
275
276[partInfo release];
277}
278else if (tableView == mTabViewPanesSelect)
279{
280// menu tv handling
281if (tableColumn == mMenuName)
282{
283NSBundle * b = [NSBundle bundleForClass:[self class]];
284ret = NSLocalizedStringFromTableInBundle(sMenuList[row].title, nil, b, @"comment");
285}
286else if (tableColumn == mMenuIcon)
287{
288ret = *sMenuList[row].img;
289}
290}
291
292return ret;
293}
294//--------------------------------------------------------------------------
295
296@end
297

Archive Download this file

Revision: 344