prefs.m
来自「VLC媒体播放程序」· M 代码 · 共 1,147 行 · 第 1/3 页
M
1,147 行
/***************************************************************************** * prefs.m: MacOS X module for vlc ***************************************************************************** * Copyright (C) 2002-2004 VideoLAN * $Id: prefs.m,v 1.41 2004/02/19 19:38:58 hartman Exp $ * * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Derk-Jan Hartman <hartman at videolan dot org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <sys/param.h> /* for MAXPATHLEN */#include <string.h>#include "intf.h"#include "prefs.h"#include "vlc_keys.h"/***************************************************************************** * VLCPrefs implementation *****************************************************************************/@implementation VLCPrefs- (id)init{ self = [super init]; if( self != nil ) { o_empty_view = [[NSView alloc] init]; o_save_prefs = [[NSMutableDictionary alloc] init]; } return( self );}- (void)dealloc{ [o_empty_view release]; [o_save_prefs release]; [super dealloc];}- (void)awakeFromNib{ p_intf = [NSApp getIntf]; b_advanced = config_GetInt( p_intf, "advanced" ); [self initStrings]; [o_advanced_ckb setState: b_advanced]; [o_prefs_view setBorderType: NSGrooveBorder]; [o_prefs_view setHasVerticalScroller: YES]; [o_prefs_view setDrawsBackground: NO]; [o_prefs_view setRulersVisible: NO]; [o_prefs_view setDocumentView: o_empty_view]; [o_tree selectRow:0 byExtendingSelection:NO];}- (void)initStrings{ [o_prefs_window setTitle: _NS("Preferences")]; [o_save_btn setTitle: _NS("Save")]; [o_cancel_btn setTitle: _NS("Cancel")]; [o_reset_btn setTitle: _NS("Reset All")]; [o_advanced_ckb setTitle: _NS("Advanced")];}- (void)showPrefs{ [o_save_prefs release]; o_save_prefs = [[NSMutableDictionary alloc] init]; [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID] andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]]; [o_prefs_window center]; [o_prefs_window makeKeyAndOrderFront:self];}- (IBAction)savePrefs: (id)sender{ id o_vlc_config; NSEnumerator *o_enum; o_enum = [o_save_prefs objectEnumerator]; while( ( o_vlc_config = [o_enum nextObject] ) ) { int i_type = [o_vlc_config configType]; NSString *o_name = [o_vlc_config configName]; char *psz_name = (char *)[o_name UTF8String]; switch( i_type ) { case CONFIG_ITEM_MODULE: { char *psz_value; module_t *p_a_module; int i_id = [[o_vlc_config selectedItem] tag]; p_a_module = (module_t *)vlc_object_get( p_intf, i_id ); if( p_a_module == NULL || p_a_module->i_object_type != VLC_OBJECT_MODULE ) { i_id = -1; } psz_value = ( i_id == -1 ) ? "" : p_a_module->psz_object_name ; config_PutPsz( p_intf, psz_name, strdup(psz_value) ); } break; case CONFIG_ITEM_STRING: case CONFIG_ITEM_FILE: case CONFIG_ITEM_DIRECTORY: { char *psz_value; NSString *o_value = [o_vlc_config stringValue]; psz_value = (char *)[o_value UTF8String]; config_PutPsz( p_intf, psz_name, psz_value ); } break; case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_BOOL: { int i_value = [o_vlc_config intValue]; config_PutInt( p_intf, psz_name, i_value ); } break; case CONFIG_ITEM_FLOAT: { float f_value = [o_vlc_config floatValue]; config_PutFloat( p_intf, psz_name, f_value ); } break; case CONFIG_ITEM_KEY: { unsigned int i_key = config_GetInt( p_intf, psz_name ); unsigned int i_new_key = 0; if( [o_vlc_config class] == [VLCMatrix class] ) { int i; NSButtonCell *o_current_cell; NSArray *o_cells = [o_vlc_config cells]; i_new_key = (i_key & ~KEY_MODIFIER); for( i = 0; i < [o_cells count]; i++ ) { o_current_cell = [o_cells objectAtIndex:i]; if( [[o_current_cell title] isEqualToString:_NS("Command")] && [o_current_cell state] == NSOnState ) i_new_key |= KEY_MODIFIER_COMMAND; if( [[o_current_cell title] isEqualToString:_NS("Control")] && [o_current_cell state] == NSOnState ) i_new_key |= KEY_MODIFIER_CTRL; if( [[o_current_cell title] isEqualToString:_NS("Option/Alt")] && [o_current_cell state] == NSOnState ) i_new_key |= KEY_MODIFIER_ALT; if( [[o_current_cell title] isEqualToString:_NS("Shift")] && [o_current_cell state] == NSOnState ) i_new_key |= KEY_MODIFIER_SHIFT; } } else { i_new_key = (i_key & KEY_MODIFIER); i_new_key |= StringToKey([[o_vlc_config stringValue] cString]); } config_PutInt( p_intf, psz_name, i_new_key ); } break; } } config_SaveConfigFile( p_intf, NULL ); [o_prefs_window orderOut:self];}- (IBAction)closePrefs: (id)sender{ [o_prefs_window orderOut:self];}- (IBAction)resetAll: (id)sender{ NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"), _NS("Continue"), nil, o_prefs_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, _NS("Beware this will reset your VLC media player preferences.\n" "Are you sure you want to continue?") );}- (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return contextInfo:(void *)o_context{ if( i_return == NSAlertAlternateReturn ) { config_ResetAll( p_intf ); [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID] andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]]; }}- (IBAction)advancedToggle: (id)sender{ b_advanced = !b_advanced; [o_advanced_ckb setState: b_advanced]; [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID] andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];}- (IBAction)openFileDialog: (id)sender{ NSOpenPanel *o_open_panel = [NSOpenPanel openPanel]; [o_open_panel setTitle: _NS("Select file or directory")]; [o_open_panel setPrompt: _NS("Select")]; [o_open_panel setAllowsMultipleSelection: NO]; [o_open_panel setCanChooseFiles: YES]; [o_open_panel setCanChooseDirectories: YES]; [o_open_panel beginSheetForDirectory:nil file:nil types:nil modalForWindow:[sender window] modalDelegate: self didEndSelector: @selector(pathChosenInPanel: withReturn: contextInfo:) contextInfo: sender];}- (void)pathChosenInPanel:(NSOpenPanel *)o_sheet withReturn:(int)i_return_code contextInfo:(void *)o_context_info{ if( i_return_code == NSOKButton ) { NSString *o_path = [[o_sheet filenames] objectAtIndex: 0]; VLCTextField *o_field = (VLCTextField *)[(VLCButton *)o_context_info tag]; /* FIXME */ [o_field setStringValue: o_path]; [self configChanged: o_field]; }}- (void)loadConfigTree{ }- (void)outlineViewSelectionIsChanging:(NSNotification *)o_notification{}- (void)outlineViewSelectionDidChange:(NSNotification *)o_notification{ [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID] andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];}- (void)configChanged:(id)o_unknown{ id o_vlc_config = [o_unknown isKindOfClass: [NSNotification class]] ? [o_unknown object] : o_unknown; NSString *o_name = [o_vlc_config configName]; [o_save_prefs setObject: o_vlc_config forKey: o_name];}- (void)showViewForID: (int)i_id andName: (NSString *)o_item_name{ vlc_list_t *p_list; module_t *p_parser; module_config_t *p_item; int i_pos, i_module_tag, i_index; NSString *o_module_name; NSRect s_rc; /* rect */ NSView *o_view; /* view */ NSRect s_vrc; /* view rect */ VLCTextField *o_text_field; /* input field / label */ p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); /* Get a pointer to the module */ p_parser = (module_t *)vlc_object_get( p_intf, i_id ); if( p_parser->i_object_type != VLC_OBJECT_MODULE ) { /* 0OOoo something went really bad */ return; } /* Enumerate config options and add corresponding config boxes */ o_module_name = [NSString stringWithUTF8String: p_parser->psz_object_name]; p_item = p_parser->p_config; i_pos = 0; o_view = nil; i_module_tag = 3;#define X_ORIGIN 20#define Y_ORIGIN (X_ORIGIN - 10)#define CHECK_VIEW_HEIGHT \ { \ float f_new_pos = s_rc.origin.y + s_rc.size.height + X_ORIGIN; \ if( f_new_pos > s_vrc.size.height ) \ { \ s_vrc.size.height = f_new_pos; \ [o_view setFrame: s_vrc]; \ } \ }#define CONTROL_LABEL( label ) \ { \ s_rc.origin.x += s_rc.size.width + 10; \ s_rc.size.width = s_vrc.size.width - s_rc.origin.x - X_ORIGIN - 20; \ o_text_field = [[NSTextField alloc] initWithFrame: s_rc]; \ [o_text_field setDrawsBackground: NO]; \ [o_text_field setBordered: NO]; \ [o_text_field setEditable: NO]; \ [o_text_field setSelectable: NO]; \ if ( label ) \ { \ [o_text_field setStringValue: \ [NSApp localizedString: label]]; \ } \ [o_text_field sizeToFit]; \ [o_view addSubview: [o_text_field autorelease]]; \ }#define INPUT_FIELD( ctype, cname, label, w, msg, param, tip ) \ { \ char * psz_duptip = NULL; \ if ( p_item->psz_longtext != NULL ) \ psz_duptip = strdup( p_item->psz_longtext ); \ s_rc.size.height = 25; \ s_rc.size.width = w; \ s_rc.origin.y += 10; \ CHECK_VIEW_HEIGHT; \ o_text_field = [[VLCTextField alloc] initWithFrame: s_rc]; \ [o_text_field setAlignment: NSRightTextAlignment]; \ CONTROL_CONFIG( o_text_field, o_module_name, ctype, cname ); \ [o_text_field msg: param]; \ if ( psz_duptip != NULL ) \ { \ [o_text_field setToolTip: [NSApp wrapString: [NSApp localizedString: \ psz_duptip] toWidth: PREFS_WRAP ]]; \ free(psz_duptip);\ } \ [o_view addSubview: [o_text_field autorelease]]; \ [[NSNotificationCenter defaultCenter] addObserver: self \ selector: @selector(configChanged:) \ name: NSControlTextDidChangeNotification \ object: o_text_field]; \ CONTROL_LABEL( label ); \ s_rc.origin.y += s_rc.size.height; \ s_rc.origin.x = X_ORIGIN; \ }#define INPUT_FIELD_INTEGER( name, label, w, param, tip ) \ INPUT_FIELD( CONFIG_ITEM_INTEGER, name, label, w, setIntValue, param, tip )#define INPUT_FIELD_FLOAT( name, label, w, param, tip ) \ INPUT_FIELD( CONFIG_ITEM_FLOAT, name, label, w, setFloatValue, param, tip )#define INPUT_FIELD_STRING( name, label, w, param, tip ) \ INPUT_FIELD( CONFIG_ITEM_STRING, name, label, w, setStringValue, param, tip ) /* Init View */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?