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
141if ( [partInfo vUUID].length>>0)
142s = [partInfo vUUID];
143else
144#endif
145s = [partInfo hdString];
146
147AuthorizationRef auth= [TableViewsController authorization];
148if(BootProp::instance().setStringForKey(kDefaultPartition, [s UTF8String]))
149BootProp::instance().save(auth);
150[ PreferencesControllerBase loadOptionsFromBootFile];
151[partInfo release];
152}
153else
154{ // no line selected
155BootProp::instance().removeKeyAndValue(kDefaultPartition);
156[ PreferencesControllerBase loadOptionsFromBootFile];
157
158}
159}
160}
161else if (tv == mTabViewPanesSelect)
162{
163int selected = [tv selectedRow];
164if(selected>=0)
165{
166switch (sMenuList[selected].pane)
167{
168case PaneBootFrom:
169[mTabViewPanes selectTabViewItem: mBootFrom];
170break;
171case PaneBootSetup:
172[mTabViewPanes selectTabViewItem: mBootSetup];
173break;
174case PaneBootFlags:
175[mTabViewPanes selectTabViewItem: mBootFlags];
176break;
177case PanePeripherals:
178[mTabViewPanes selectTabViewItem: mPeripherals];
179break;
180case PaneEfiInject:
181[mTabViewPanes selectTabViewItem: mEfiInject];
182break;
183case PaneAdvanced:
184[mTabViewPanes selectTabViewItem: mAdvanced];
185break;
186case PaneSmbios:
187[mTabViewPanes selectTabViewItem: mSmbios];
188break;
189case PaneAbout:
190[mTabViewPanes selectTabViewItem: mAbout];
191break;
192default:
193break;
194}
195[mTabViewPanes setNeedsDisplay: true ];
196}
197}
198}
199
200//--------------------------------------------------------------------------
201- (void) tableView:(NSTableView*) tableView setObjectValue:(id) object
202forTableColumn:(NSTableColumn*) tableColumn row:(NSInteger) row
203{
204if (object == nil) return;
205PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:row];
206if (tableColumn == mHideOrViewColumn)
207{
208[partInfo setHidden: ([object intValue] ? false : true) ];
209}
210[partInfo release];
211
212NSLog(@"object at column %@ row %d Set %@", [[tableColumn headerCell] stringValue], row, object);
213}
214//--------------------------------------------------------------------------
215- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
216{
217int size=0;
218if (tableView == mPartitionsTable)
219size = [PartsInfoMgr count];
220else
221size = iMenuListSize;
222return size;
223}
224
225//--------------------------------------------------------------------------
226- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
227{
228id ret=nil;
229if (tableView == mPartitionsTable)
230{
231PartitionInfoElement* partInfo = [PartsInfoMgr objectAtIndex:row];
232
233if (tableColumn == mHideOrViewColumn)
234{
235ret = [NSNumber numberWithInt:(int) [partInfo hidden] ? 0 : 1];
236}
237else if (tableColumn == mPartitionUIDColumn)
238{
239ret = [partInfo vUUID ];
240}
241else if (tableColumn == mPartitionImgColumn)
242{
243switch( [partInfo imageIndexFromFs])
244{
245case 0:
246ret = mMacOSXImage;
247break;
248case 1:
249ret = mWindowsImage;
250break;
251case 2:
252ret = mLinuxImage;
253break;
254default:
255ret = mUnknownImage;
256break;
257
258}
259}
260else if (tableColumn == mFileSystemColumn)
261{
262ret = [partInfo vKind];
263}
264else if (tableColumn == mPartitionNameColumn)
265{
266ret = [partInfo vAliasName]; // vAliasName is vName if no alias
267}
268else if (tableColumn == mPartitionIDColumn)
269{
270ret= [partInfo hdString];
271}
272
273[partInfo release];
274}
275else if (tableView == mTabViewPanesSelect)
276{
277// menu tv handling
278if (tableColumn == mMenuName)
279{
280NSBundle * b = [NSBundle bundleForClass:[self class]];
281ret = NSLocalizedStringFromTableInBundle(sMenuList[row].title, nil, b, @"comment");
282}
283else if (tableColumn == mMenuIcon)
284{
285ret = *sMenuList[row].img;
286}
287}
288
289return ret;
290}
291//--------------------------------------------------------------------------
292
293@end
294

Archive Download this file

Revision: 341