1 /*****************************************************************************
2 * simple_prefs.m: Simple Preferences for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
7 * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 #import "simple_prefs.h"
29 static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
30 static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
31 static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
33 @implementation VLCSimplePrefs
35 static VLCSimplePrefs *_o_sharedInstance = nil;
37 + (VLCSimplePrefs *)sharedInstance
39 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
44 if (_o_sharedInstance) {
48 _o_sharedInstance = [super init];
51 return _o_sharedInstance;
56 [o_currentlyShownCategoryView release];
57 [o_sprefs_toolbar release];
66 o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
68 [o_sprefs_toolbar setAllowsUserCustomization: NO];
69 [o_sprefs_toolbar setAutosavesConfiguration: NO];
70 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
71 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
73 [o_sprefs_toolbar setDelegate: self];
75 [o_sprefs_win setToolbar: o_sprefs_toolbar];
78 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
79 itemForItemIdentifier: (NSString *)o_itemIdent
80 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
82 NSToolbarItem *o_toolbarItem = nil;
84 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
86 o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease];
88 [o_toolbarItem setLabel: _NS("Interface")];
89 [o_toolbarItem setPaletteLabel: _NS("Interface settings")];
91 [o_toolbarItem setToolTip: _NS("Interface settings")];
92 [o_toolbarItem setImage: [NSImage imageNamed: @"spref_cone_Interface_64"]];
94 [o_toolbarItem setTarget: self];
95 [o_toolbarItem setAction: @selector(showInterfaceSettings)];
97 [o_toolbarItem setEnabled: YES];
98 [o_toolbarItem setAutovalidates: YES];
100 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
102 o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease];
104 [o_toolbarItem setLabel: _NS("Audio")];
105 [o_toolbarItem setPaletteLabel: _NS("General Audio settings")];
107 [o_toolbarItem setToolTip: _NS("General Audio settings")];
108 [o_toolbarItem setImage: [NSImage imageNamed: @"spref_cone_Audio_64"]];
110 [o_toolbarItem setTarget: self];
111 [o_toolbarItem setAction: @selector(showAudioSettings)];
113 [o_toolbarItem setEnabled: YES];
114 [o_toolbarItem setAutovalidates: YES];
117 return o_toolbarItem;
120 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
122 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
125 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
127 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
130 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
132 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
137 [o_sprefs_reset_btn setEnabled: NO];
138 msg_Warn( p_intf, "localisation of the simple preferences not implemented!" );
141 - (void)showSimplePrefs
143 /* we want to show the interface settings, if no category was chosen */
144 if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
146 [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
147 [self showInterfaceSettings];
150 [o_sprefs_win makeKeyAndOrderFront: self];
153 - (IBAction)buttonAction:(id)sender
155 if( sender == o_sprefs_cancel_btn )
156 [o_sprefs_win orderOut: sender];
157 else if( sender == o_sprefs_save_btn )
159 msg_Warn( p_intf, "sprefs saving not implemented, your changes have no effect!" );
160 [o_sprefs_win orderOut: sender];
162 else if( sender == o_sprefs_reset_btn )
163 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
164 _NS("Continue"), nil, o_sprefs_win, self,
165 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
166 _NS("Beware this will reset the VLC media player preferences.\n"
167 "Are you sure you want to continue?") );
168 else if( sender == o_sprefs_basicFull_matrix )
170 [o_sprefs_win orderOut: self];
171 [[[VLCMain sharedInstance] getPreferences] showPrefs];
172 /* TODO: reset our selector controls here */
175 msg_Err( p_intf, "unknown buttonAction sender" );
178 - (void)sheetDidEnd:(NSWindow *)o_sheet
179 returnCode:(int)i_return
180 contextInfo:(void *)o_context
182 if( i_return == NSAlertAlternateReturn )
184 config_ResetAll( p_intf );
185 /* TODO: we need to reset our views here */
189 - (void)showSettingsForCategory: (id)o_new_category_view
191 msg_Dbg( p_intf, "switching to another category" );
192 NSRect o_win_rect, o_view_rect, o_old_view_rect;
193 o_win_rect = [o_sprefs_win frame];
194 o_view_rect = [o_new_category_view frame];
196 if( o_currentlyShownCategoryView != nil )
198 /* restore our window's height, if we've shown another category previously */
199 o_old_view_rect = [o_currentlyShownCategoryView frame];
200 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
202 /* remove our previous category view */
203 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
206 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
208 [o_sprefs_win displayIfNeeded];
209 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
211 [o_new_category_view setFrame: NSMakeRect( 0,
212 [o_sprefs_controls_box frame].size.height,
213 o_view_rect.size.width,
214 o_view_rect.size.height )];
215 [o_new_category_view setNeedsDisplay: YES];
216 [o_new_category_view setAutoresizesSubviews: YES];
217 [[o_sprefs_win contentView] addSubview: o_new_category_view];
219 /* keep our current category for further reference */
220 [o_currentlyShownCategoryView release];
221 o_currentlyShownCategoryView = o_new_category_view;
222 [o_currentlyShownCategoryView retain];
225 - (IBAction)interfaceSettingChanged:(id)sender
229 - (void)showInterfaceSettings
231 msg_Dbg( p_intf, "showing interface settings" );
232 [self showSettingsForCategory: o_intf_view];
235 - (IBAction)audioSettingChanged:(id)sender
239 - (void)showAudioSettings
241 msg_Dbg( p_intf, "showing audio settings" );
242 [self showSettingsForCategory: o_audio_view];