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) {
138case PaneBootFrom:
139[mTabViewPanes selectTabViewItem: mBootFrom];
140break;
141case PaneBootSetup:
142[mTabViewPanes selectTabViewItem: mBootSetup];
143break;
144case PaneBootFlags:
145[mTabViewPanes selectTabViewItem: mBootFlags];
146break;
147case PanePeripherals:
148[mTabViewPanes selectTabViewItem: mPeripherals];
149break;
150case PaneEfiInject:
151[mTabViewPanes selectTabViewItem: mEfiInject];
152break;
153case PaneAdvanced:
154[mTabViewPanes selectTabViewItem: mAdvanced];
155break;
156case PaneSmbios:
157[mTabViewPanes selectTabViewItem: mSmbios];
158break;
159case PaneAbout:
160[mTabViewPanes selectTabViewItem: mAbout];
161break;
162default:
163break;
164}
165}
166}
167}
168
169//--------------------------------------------------------------------------
170- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
171{
172int size=0;
173if (tableView == mPartitionsTable)
174size = PartitionExtractor::instance().partList().size();
175else
176size = iMenuListSize;
177return size;
178}
179
180//--------------------------------------------------------------------------
181- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
182{
183id ret=nil;
184
185const std::vector<PartitionInfo>& partInfo = PartitionExtractor::instance().partList();
186
187if (tableColumn == mPartitionImgColumn)
188{
189switch(partInfo[row].imageIndexFromFs())
190{
191case 0:
192ret = mMacOSXImage;
193break;
194case 1:
195ret = mWindowsImage;
196break;
197case 2:
198ret = mLinuxImage;
199break;
200default:
201ret = mUnknownImage;
202break;
203
204}
205}
206else if (tableColumn == mFileSystemColumn)
207{
208ret = [NSString stringWithFormat: @"%s", partInfo[row].cfsType() ];
209}
210else if (tableColumn == mPartitionNameColumn)
211{
212ret = [NSString stringWithFormat: @"%s", partInfo[row].clabel()];
213}
214else if (tableColumn == mPartitionIDColumn)
215{
216ret= [NSString stringWithFormat: @"hd(%d,%d)",
217 partInfo[row].disk(),
218 partInfo[row].partition()
219 ];
220}
221// menu tv handling
222else if (tableColumn == mMenuName)
223{
224ret = sMenuList[row].title;
225}
226return ret;
227}
228//--------------------------------------------------------------------------
229
230@end
231

Archive Download this file

Revision: 83