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- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row
127{
128PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:row];
129BOOL ret = (partInfo != nil && [partInfo hidden]== false) ? YES : NO;
130[partInfo release];
131
132return ret;
133}
134
135//--------------------------------------------------------------------------
136#if 0
137// TODO: rows of hidden parts should look disable ...
138-(NSCell *) tableView:(NSTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
139{
140NSCell *cell = [super tableView: tableView cellForRowAtIndexPath: indexPath];
141
142if (cell == nil)
143{
144//cell.selectionStyle = UITableViewCellSelectionStyleNone;
145//cell.selectionStyle = UITableViewCellSelectionStyleBlue;
146// cell.userInteractionEnabled = NO;
147}
148
149return cell;
150
151}
152#endif
153
154//--------------------------------------------------------------------------
155- (void)tableViewSelectionDidChange:(NSNotification *)notification {
156
157NSTableView* tv= [notification object];
158if (tv == mPartitionsTable)
159{
160if ([tv selectedRow] != currentRowSel)
161{
162currentRowSel = [tv selectedRow];
163if (currentRowSel>=0)
164{
165PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:currentRowSel];
166NSString* s;
167
168#if 0
169// Chameleon is difficult for now to synchronize with uuid
170// because windows partitions have a different uuid format than osx ones in the booter ...
171// we'll address that interfacing problem later, probably in chameleon itself first.
172if ( [partInfo vUUID].length>>0)
173s = [partInfo vUUID];
174else
175#endif
176s = [partInfo hdString];
177
178AuthorizationRef auth= [TableViewsController authorization];
179if(BootProp::instance().setStringForKey(kDefaultPartition, [s UTF8String]))
180BootProp::instance().save(auth);
181[ PreferencesControllerBase loadOptionsFromBootFile];
182[partInfo release];
183}
184else
185{ // no line selected
186BootProp::instance().removeKeyAndValue(kDefaultPartition);
187[ PreferencesControllerBase loadOptionsFromBootFile];
188
189}
190}
191}
192else if (tv == mTabViewPanesSelect)
193{
194int selected = [tv selectedRow];
195if(selected>=0)
196{
197switch (sMenuList[selected].pane)
198{
199case PaneBootFrom:
200[mTabViewPanes selectTabViewItem: mBootFrom];
201break;
202case PaneBootSetup:
203[mTabViewPanes selectTabViewItem: mBootSetup];
204break;
205case PaneBootFlags:
206[mTabViewPanes selectTabViewItem: mBootFlags];
207break;
208case PanePeripherals:
209[mTabViewPanes selectTabViewItem: mPeripherals];
210break;
211case PaneEfiInject:
212[mTabViewPanes selectTabViewItem: mEfiInject];
213break;
214case PaneAdvanced:
215[mTabViewPanes selectTabViewItem: mAdvanced];
216break;
217case PaneSmbios:
218[mTabViewPanes selectTabViewItem: mSmbios];
219break;
220case PaneAbout:
221[mTabViewPanes selectTabViewItem: mAbout];
222break;
223default:
224break;
225}
226[mTabViewPanes setNeedsDisplay: true ];
227}
228}
229}
230
231//--------------------------------------------------------------------------
232- (void) tableView:(NSTableView*) tableView setObjectValue:(id) object
233forTableColumn:(NSTableColumn*) tableColumn row:(NSInteger) row
234{
235if (object == nil) return;
236PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:row];
237
238if (tableColumn == mHideOrViewColumn)
239{
240[partInfo setHidden: ([object intValue] ? false : true) ];
241}
242else if (tableColumn == mPartitionNameColumn)
243{
244[partInfo setVAliasName: (object==nil || [object length] == 0) ? [partInfo vName] : object];
245const char * sCur = BootProp::instance().getStringForKey(kRenamePartition);
246NSString * currentStr = [NSString stringWithUTF8String: sCur ? sCur : ""] ;
247NSString* renStr = [PartsInfoMgr getRenameStringFrom:(NSString*) currentStr
248andPartition: (PartitionInfoElement*) partInfo];
249if (renStr!=nil &&
250 BootProp::instance().setStringForKey(kRenamePartition, [renStr UTF8String])
251 )
252{
253AuthorizationRef auth= [TableViewsController authorization];
254BootProp::instance().save(auth);
255[ PreferencesControllerBase loadOptionsFromBootFile];
256}
257
258}
259
260[partInfo release];
261
262NSLog(@"object at column %@ row %d Set %@", [[tableColumn headerCell] stringValue], row, object);
263}
264//--------------------------------------------------------------------------
265- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
266{
267int size=0;
268if (tableView == mPartitionsTable)
269size = [PartsInfoMgr count];
270else
271size = iMenuListSize;
272return size;
273}
274
275//--------------------------------------------------------------------------
276- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
277{
278id ret=nil;
279if (tableView == mPartitionsTable)
280{
281PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:row];
282
283if (tableColumn == mHideOrViewColumn)
284{
285ret = [NSNumber numberWithInt:(int) [partInfo hidden] ? 0 : 1];
286}
287else if (tableColumn == mPartitionUIDColumn)
288{
289ret = [partInfo vUUID ];
290}
291else if (tableColumn == mPartitionImgColumn)
292{
293switch( [partInfo imageIndexFromFs])
294{
295case 0:
296ret = mMacOSXImage;
297break;
298case 1:
299ret = mWindowsImage;
300break;
301case 2:
302ret = mLinuxImage;
303break;
304default:
305ret = mUnknownImage;
306break;
307
308}
309}
310else if (tableColumn == mFileSystemColumn)
311{
312ret = [partInfo vKind];
313}
314else if (tableColumn == mPartitionNameColumn)
315{
316ret = [partInfo vAliasName]; // vAliasName is vName if no alias
317}
318else if (tableColumn == mPartitionIDColumn)
319{
320ret= [partInfo hdString];
321}
322
323[partInfo release];
324}
325else if (tableView == mTabViewPanesSelect)
326{
327// menu tv handling
328if (tableColumn == mMenuName)
329{
330NSBundle * b = [NSBundle bundleForClass:[self class]];
331ret = NSLocalizedStringFromTableInBundle(sMenuList[row].title, nil, b, @"comment");
332}
333else if (tableColumn == mMenuIcon)
334{
335ret = *sMenuList[row].img;
336}
337}
338
339return ret;
340}
341//--------------------------------------------------------------------------
342
343@end
344

Archive Download this file

Revision: 355