root/branches/0_9_1/qcontrol/cocoaControlPreferences.m

Revision 76, 7.1 KB (checked in by cordney, 3 years ago)

[fix] preferences: log output to console
[fix] Localization: nibs fixes/German

Line 
1/*
2 * QEMU Cocoa Control Preferences
3 *
4 * Copyright (c) 2005, 2006 Mike Kronenberg
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#import "cocoaControlPreferences.h"
26
27//#import "AppleHelp.h"
28#import "Carbon/Carbon.h"
29
30#import "cocoaControlController.h"
31
32@implementation cocoaControlPreferences
33- (id) init
34{
35//      NSLog(@"cocoaControlPreferences: init");
36
37        if ((self = [super init])) {
38                userDefaults = [NSUserDefaults standardUserDefaults];
39               
40                return self;
41        }
42
43        return nil;
44}
45
46- (void) dealloc
47{
48//      NSLog(@"cocoaControlPreferences: dealloc");
49
50        [userDefaults release];
51        [super dealloc];
52}
53
54- (void)awakeFromNib
55{
56//      NSLog(@"cocoaControlPreferences: awakeFromNib");
57
58        NSToolbar *preferencesPanelToolbar = [[[NSToolbar alloc] initWithIdentifier: @"preferencesPanelToolbarIdentifier"] autorelease];
59        [preferencesPanelToolbar setAllowsUserCustomization: NO]; //allow customisation
60        [preferencesPanelToolbar setAutosavesConfiguration: NO]; //autosave changes
61        [preferencesPanelToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel]; //what is shown
62        [preferencesPanelToolbar setSizeMode:NSToolbarSizeModeRegular]; //default Toolbar Size
63        [preferencesPanelToolbar setDelegate: self]; // We are the delegate
64        [preferencesPanel setToolbar: preferencesPanelToolbar]; // Attach the toolbar to the document window
65
66        [preferencesPanelToolbar setSelectedItemIdentifier:@"general"];
67}
68
69/* Toolbar Delegates*/
70- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted
71{
72        NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
73       
74        if ([itemIdent isEqual: @"general"]) {
75                [toolbarItem setLabel: NSLocalizedStringFromTable(@"toolbar:label:general", @"Localizable", @"cocoaControlPreferences")];
76                [toolbarItem setPaletteLabel: NSLocalizedStringFromTable(@"toolbar:paletteLabel:general", @"Localizable", @"cocoaControlPreferences")];
77                [toolbarItem setToolTip: NSLocalizedStringFromTable(@"toolbar:toolTip:general", @"Localizable", @"cocoaControlPreferences")];
78                [toolbarItem setImage: [NSImage imageNamed: @"cocoa_tb_general.png"]];
79                [toolbarItem setTarget: self];
80                [toolbarItem setAction: @selector( viewGeneral: )];
81        } else {
82                toolbarItem = nil;
83        }
84       
85        return toolbarItem;
86}
87
88- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
89{
90        return [NSArray arrayWithObjects:
91                @"general",
92                nil];
93}
94
95- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
96{
97        return [NSArray arrayWithObjects:
98                @"general",
99                nil];
100}
101
102- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
103{
104        return [NSArray arrayWithObjects:
105                @"general",
106                nil];   
107}
108
109- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
110{
111        return YES;
112}
113
114- (void)viewGeneral:(id)sender
115{
116//      NSLog(@"awakeFromNib: viewGeneral");
117
118        [preferencesPanel setTitle: NSLocalizedStringFromTable(@"viewGeneral:title", @"Localizable", @"cocoaControlPreferences")];
119}
120
121- (IBAction)ok:(id)sender;
122{
123//      NSLog(@"awakeFromNib: ok");
124
125        if ([popUpButtonDisplay indexOfSelectedItem] == 0) {
126                [userDefaults setObject:@"OpenGL" forKey:@"display"];
127        } else if ([popUpButtonDisplay indexOfSelectedItem] == 1) {
128                [userDefaults setObject:@"Quartz" forKey:@"display"];
129        } else {
130                [userDefaults setObject:@"QuickDraw" forKey:@"display"];
131        }
132       
133        if ([buttonEnableCheckForUpdates state] == NSOnState) {
134                [userDefaults setBool:TRUE forKey:@"enableCheckForUpdates"];
135        } else {
136                [userDefaults setBool:FALSE forKey:@"enableCheckForUpdates"];
137        }
138       
139        if ([buttonEnableLogToConsole state] == NSOnState) {
140                [userDefaults setBool:TRUE forKey:@"enableLogToConsole"];
141        } else {
142                [userDefaults setBool:FALSE forKey:@"enableLogToConsole"];
143        }
144       
145        [userDefaults setObject:[textFieldDataPath stringValue] forKey:@"dataPath"];
146       
147        /* Update qControl to new datapath */
148        [qControl loadConfigurations];
149       
150        [preferencesPanel close];
151}
152
153- (IBAction)cancel:(id)sender
154{
155//      NSLog(@"awakeFromNib: cancel");
156
157        [preferencesPanel close];
158}
159
160- (id)preferencesPanel
161{
162//      NSLog(@"awakeFromNib: preferencesPanel");
163
164        return preferencesPanel;
165}
166
167- (void)preparePreferences:(id)sender
168{
169//      NSLog(@"awakeFromNib: preparePreferences");
170
171    qControl = sender;
172
173        if ([[userDefaults objectForKey:@"display"] isEqual:@"OpenGL"]) {
174                [popUpButtonDisplay selectItemAtIndex:0];
175        } else if ([[userDefaults objectForKey:@"display"] isEqual:@"Quartz"]) {
176                [popUpButtonDisplay selectItemAtIndex:1];
177        } else {
178                [popUpButtonDisplay selectItemAtIndex:2];
179        }
180       
181        if ([userDefaults boolForKey:@"enableCheckForUpdates"]) {
182        [buttonEnableCheckForUpdates setState:NSOnState];
183    } else {
184        [buttonEnableCheckForUpdates setState:NSOffState];
185        }
186       
187    if ([userDefaults boolForKey:@"enableLogToConsole"]) {
188        [buttonEnableLogToConsole setState:NSOnState];
189        } else {
190        [buttonEnableLogToConsole setState:NSOffState];
191        }
192       
193        if ([userDefaults objectForKey:@"dataPath"]) {
194                [textFieldDataPath setStringValue:[userDefaults objectForKey:@"dataPath"]];
195        } else {
196                [textFieldDataPath setStringValue:[NSString stringWithFormat:@"%@/Documents/QEMU", NSHomeDirectory()]];
197        }
198}
199
200- (void) genericFolderSelectPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo
201{
202//      NSLog(@"cocoaControlPreferences: genericFolderSelectPanelDidEnd");
203
204        /* hide Sheet */
205        [ sheet orderOut:self ];
206               
207        /* dataPath */
208        if ([contextInfo isEqual:buttonDataPathChoose]) {
209                if ( returnCode == NSOKButton ) {
210                        [textFieldDataPath setStringValue:[sheet filename]];
211                }
212        }
213}
214
215- (IBAction) genericFolderSelectPanel:(id)sender
216{
217//      NSLog(@"cocoaControlPreferences: genericFolderSelectPanel");
218
219        NSOpenPanel *openPanel = [[NSOpenPanel alloc] init];
220        [openPanel setCanChooseDirectories:YES];
221        [openPanel setCanCreateDirectories:YES];
222        [openPanel setCanChooseFiles:NO];
223        [openPanel beginSheetForDirectory:[@"~/Documents" stringByExpandingTildeInPath]
224                file:nil
225                types:nil
226                modalForWindow:preferencesPanel
227                modalDelegate:self
228                didEndSelector:@selector(genericFolderSelectPanelDidEnd:returnCode:contextInfo:)
229                contextInfo:sender];
230}
231
232- (IBAction) resetDataPath: (id)sender
233{
234        [textFieldDataPath setStringValue:[NSString stringWithFormat:@"%@/Documents/QEMU", NSHomeDirectory()]];
235}
236@end
Note: See TracBrowser for help on using the browser.