Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/diebuche/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
15#import <SecurityFoundation/SFAuthorization.h>
16#import <SecurityInterface/SFAuthorizationView.h>
17#include <string>
18#include <vector>
19
20//--------------------------------------------------------------------------
21// MenuEntry definitions
22//--------------------------------------------------------------------------
23typedef enum {
24PaneBootFrom, PaneBootSetup, PaneBootFlags, PanePeripherals,
25PaneAdvanced, PaneEfiInject, PaneSmbios, PaneAbout
26} MenuEntryPane;
27
28struct MenuEntry
29{
30NSString* title;
31MenuEntryPane pane;
32NSImage**img;
33};
34
35
36static NSImage*mImgPaneBootFrom;
37static NSImage*mImgPaneBootSetup;
38static NSImage*mImgPaneBootFlags;
39static NSImage*mImgPanePeripherals;
40static NSImage*mImgPaneAdvanced;
41static NSImage*mImgPaneEfiInject;
42static NSImage*mImgPaneSmbios;
43static NSImage*mImgPaneAbout;
44
45
46static const MenuEntry sMenuList[] =
47{
48{(NSLocalizedString(@"Boot_From", nil)), PaneBootFrom, &mImgPaneBootFrom},
49{(NSLocalizedString(@"Boot_Setup", nil)),PaneBootSetup, &mImgPaneBootSetup},
50{(NSLocalizedString(@"Boot_Flags", nil)), PaneBootFlags, &mImgPaneBootFlags},
51{(NSLocalizedString(@"Peripherals", nil)), PanePeripherals, &mImgPanePeripherals},
52{(NSLocalizedString(@"Advanced", nil)), PaneAdvanced, &mImgPaneAdvanced},
53{(NSLocalizedString(@"Efi_Inject", nil)), PaneEfiInject, &mImgPaneEfiInject},
54{(NSLocalizedString(@"Bios", nil)), PaneSmbios, &mImgPaneSmbios},
55{(NSLocalizedString(@"About", nil)), PaneAbout, &mImgPaneAbout}
56};
57const int iMenuListSize = sizeof(sMenuList)/ sizeof(MenuEntry);
58
59static TableViewsController* _instance; // Singleton DP def.
60
61//--------------------------------------------------------------------------
62
63@implementation TableViewsController
64
65//--------------------------------------------------------------------------
66- (id) init
67{
68[super init];
69_instance = self;
70
71currentRowSel = -1;
72// set the image to display the current file being played
73mMacOSXImage = [self getImageResource: @"MacOSX" ofType: @"png"];
74mWindowsImage = [self getImageResource: @"Windows" ofType: @"png"];
75mLinuxImage = [self getImageResource: @"Linux" ofType: @"png"];
76mCDROMImage = [self getImageResource: @"CDROM" ofType: @"png"];
77mUnknownImage = [self getImageResource: @"Chameleon" ofType: @"tiff"];
78
79mImgPaneBootFrom = [self getImageResource:@"disk" ofType:@"png"];
80mImgPaneBootSetup = [self getImageResource:@"wrench" ofType:@"png"];
81mImgPaneBootFlags = [self getImageResource:@"flag" ofType:@"png"];
82mImgPanePeripherals = [self getImageResource:@"plug" ofType:@"png"];
83mImgPaneAdvanced = [self getImageResource:@"advanced" ofType:@"png"];
84mImgPaneEfiInject = [self getImageResource:@"syringe" ofType:@"png"];
85mImgPaneSmbios = [self getImageResource:@"chip" ofType:@"png"];
86mImgPaneAbout = [self getImageResource:@"chamsmall" ofType:@"png"];
87
88return self;
89}
90
91//--------------------------------------------------------------------------
92// Singleton impl
93+ (TableViewsController*) instance
94{
95return _instance;
96}
97//--------------------------------------------------------------------------
98+ (bool) isUnlocked
99{
100return [[ChameleonPrefPane instance] isUnlocked];
101}
102
103//--------------------------------------------------------------------------
104+ (AuthorizationRef) authorization
105{
106return [TableViewsController isUnlocked] ?
107[ [ [ChameleonPrefPane instance]->authView authorization] authorizationRef] : NULL;
108}
109//--------------------------------------------------------------------------
110- (NSTableView*) partitionsTable
111{
112return mPartitionsTable;
113}
114//--------------------------------------------------------------------------
115- (id) getImageResource: (NSString *) str ofType: (NSString*) sType
116{
117NSImage * img=nil;
118if(!str) return nil;
119NSBundle * b = [NSBundle bundleForClass:[self class]];
120NSString* sRes = [b pathForResource: str ofType:sType ];
121img = [[NSImage alloc] initWithContentsOfFile: sRes];
122return img;
123}
124
125//--------------------------------------------------------------------------
126- (void)tableViewSelectionDidChange:(NSNotification *)notification {
127
128NSTableView* tv= [notification object];
129if (tv == mPartitionsTable)
130{
131if ([tv selectedRow] != currentRowSel)
132{
133currentRowSel = [tv selectedRow];
134if (currentRowSel>=0)
135{
136const std::vector<PartitionInfo>& partInfo = PartitionExtractor::instance().partList();
137char hd[7+1]="hd(n,m)";
138hd[3]= ('0'+partInfo[currentRowSel].disk());
139hd[5]= ('0'+partInfo[currentRowSel].partition());
140AuthorizationRef auth= [TableViewsController authorization];
141if(BootProp::instance().setStringForKey(kDefaultPartition, hd))
142BootProp::instance().save(auth);
143[ PreferencesControllerBase loadOptionsFromBootFile];
144}
145else
146{ // no line selected
147BootProp::instance().removeKeyAndValue(kDefaultPartition);
148[ PreferencesControllerBase loadOptionsFromBootFile];
149
150}
151}
152}
153else if (tv == mTabViewPanesSelect)
154{
155int selected = [tv selectedRow];
156if(selected>=0)
157{
158switch (sMenuList[selected].pane)
159{
160case PaneBootFrom:
161[mTabViewPanes selectTabViewItem: mBootFrom];
162break;
163case PaneBootSetup:
164[mTabViewPanes selectTabViewItem: mBootSetup];
165break;
166case PaneBootFlags:
167[mTabViewPanes selectTabViewItem: mBootFlags];
168break;
169case PanePeripherals:
170[mTabViewPanes selectTabViewItem: mPeripherals];
171break;
172case PaneEfiInject:
173[mTabViewPanes selectTabViewItem: mEfiInject];
174break;
175case PaneAdvanced:
176[mTabViewPanes selectTabViewItem: mAdvanced];
177break;
178case PaneSmbios:
179[mTabViewPanes selectTabViewItem: mSmbios];
180break;
181case PaneAbout:
182[mTabViewPanes selectTabViewItem: mAbout];
183break;
184default:
185break;
186}
187[mTabViewPanes setNeedsDisplay: true ];
188}
189}
190}
191
192//--------------------------------------------------------------------------
193- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
194{
195int size=0;
196if (tableView == mPartitionsTable)
197size = PartitionExtractor::instance().partList().size();
198else
199size = iMenuListSize;
200return size;
201}
202
203//--------------------------------------------------------------------------
204- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
205{
206id ret=nil;
207
208const std::vector<PartitionInfo>& partInfo = PartitionExtractor::instance().partList();
209
210if (tableColumn == mPartitionImgColumn)
211{
212switch(partInfo[row].imageIndexFromFs())
213{
214case 0:
215ret = mMacOSXImage;
216break;
217case 1:
218ret = mWindowsImage;
219break;
220case 2:
221ret = mLinuxImage;
222break;
223default:
224ret = mUnknownImage;
225break;
226
227}
228}
229else if (tableColumn == mFileSystemColumn)
230{
231ret = [NSString stringWithFormat: @"%s", partInfo[row].cfsType() ];
232}
233else if (tableColumn == mPartitionNameColumn)
234{
235ret = [NSString stringWithFormat: @"%s", partInfo[row].clabel()];
236}
237else if (tableColumn == mPartitionIDColumn)
238{
239ret= [NSString stringWithFormat: @"hd(%d,%d)",
240 partInfo[row].disk(),
241 partInfo[row].partition()
242 ];
243}
244// menu tv handling
245else if (tableColumn == mMenuName)
246{
247ret = sMenuList[row].title;
248}
249else if (tableColumn == mMenuIcon)
250{
251ret = *sMenuList[row].img;
252}
253return ret;
254}
255//--------------------------------------------------------------------------
256
257@end
258

Archive Download this file

Revision: 100