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

Archive Download this file

Revision: 87