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

Archive Download this file

Revision: 354