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

Archive Download this file

Revision: 463