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

Archive Download this file

Revision: 385