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

Archive Download this file

Revision: 356