📄 intf.m
字号:
/***************************************************************************** * intf.m: MacOS X interface module ***************************************************************************** * Copyright (C) 2002-2008 the VideoLAN team * $Id: 256f6a23318c4b55f082cdcad2829cb73caa2a61 $ * * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Christophe Massiot <massiot@via.ecp.fr> * Derk-Jan Hartman <hartman at videolan.org> * Felix Paul Kühne <fkuehne 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <sys/param.h> /* for MAXPATHLEN */#include <string.h>#include <vlc_keys.h>#ifdef HAVE_CONFIG_H# include "config.h"#endif#import "intf.h"#import "fspanel.h"#import "vout.h"#import "prefs.h"#import "playlist.h"#import "playlistinfo.h"#import "controls.h"#import "about.h"#import "open.h"#import "wizard.h"#import "extended.h"#import "bookmarks.h"#import "interaction.h"#import "embeddedwindow.h"#import "update.h"#import "AppleRemote.h"#import "eyetv.h"#import "simple_prefs.h"#import <vlc_input.h>#import <vlc_interface.h>#import <AddressBook/AddressBook.h>/***************************************************************************** * Local prototypes. *****************************************************************************/static void Run ( intf_thread_t *p_intf );static void * ManageThread( void *user_data );static unichar VLCKeyToCocoa( unsigned int i_key );static unsigned int VLCModifiersToCocoa( unsigned int i_key );#pragma mark -#pragma mark VLC Interface Object Callbacks/***************************************************************************** * OpenIntf: initialize interface *****************************************************************************/int OpenIntf ( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t*) p_this; p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); if( p_intf->p_sys == NULL ) { return( 1 ); } memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) ); p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init]; p_intf->p_sys->p_sub = msg_Subscribe( p_intf ); p_intf->pf_run = Run; p_intf->b_should_run_on_first_thread = true; return( 0 );}/***************************************************************************** * CloseIntf: destroy interface *****************************************************************************/void CloseIntf ( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t*) p_this; msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); [p_intf->p_sys->o_pool release]; free( p_intf->p_sys );}/***************************************************************************** * Run: main loop *****************************************************************************/jmp_buf jmpbuffer;static void Run( intf_thread_t *p_intf ){ sigset_t set; /* Do it again - for some unknown reason, vlc_thread_create() often * fails to go to real-time priority with the first launched thread * (???) --Meuuh */ vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW ); /* Make sure the "force quit" menu item does quit instantly. * VLC overrides SIGTERM which is sent by the "force quit" * menu item to make sure deamon mode quits gracefully, so * we un-override SIGTERM here. */ sigemptyset( &set ); sigaddset( &set, SIGTERM ); pthread_sigmask( SIG_UNBLOCK, &set, NULL ); NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init]; /* Install a jmpbuffer to where we can go back before the NSApp exit * see applicationWillTerminate: */ [NSApplication sharedApplication]; [[VLCMain sharedInstance] setIntf: p_intf]; [NSBundle loadNibNamed: @"MainMenu" owner: NSApp]; /* Install a jmpbuffer to where we can go back before the NSApp exit * see applicationWillTerminate: */ if(setjmp(jmpbuffer) == 0) [NSApp run]; [o_pool release];}#pragma mark -#pragma mark Variables Callback/***************************************************************************** * playlistChanged: Callback triggered by the intf-change playlist * variable, to let the intf update the playlist. *****************************************************************************/static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable, vlc_value_t old_val, vlc_value_t new_val, void *param ){ intf_thread_t * p_intf = VLCIntf; p_intf->p_sys->b_intf_update = true; p_intf->p_sys->b_playlist_update = true; p_intf->p_sys->b_playmode_update = true; p_intf->p_sys->b_current_title_update = true; return VLC_SUCCESS;}/***************************************************************************** * ShowController: Callback triggered by the show-intf playlist variable * through the ShowIntf-control-intf, to let us show the controller-win; * usually when in fullscreen-mode *****************************************************************************/static int ShowController( vlc_object_t *p_this, const char *psz_variable, vlc_value_t old_val, vlc_value_t new_val, void *param ){ intf_thread_t * p_intf = VLCIntf; p_intf->p_sys->b_intf_show = true; return VLC_SUCCESS;}/***************************************************************************** * FullscreenChanged: Callback triggered by the fullscreen-change playlist * variable, to let the intf update the controller. *****************************************************************************/static int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable, vlc_value_t old_val, vlc_value_t new_val, void *param ){ intf_thread_t * p_intf = VLCIntf; p_intf->p_sys->b_fullscreen_update = true; return VLC_SUCCESS;}/***************************************************************************** * InteractCallback: Callback triggered by the interaction * variable, to let the intf display error and interaction dialogs *****************************************************************************/static int InteractCallback( vlc_object_t *p_this, const char *psz_variable, vlc_value_t old_val, vlc_value_t new_val, void *param ){ NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init]; VLCMain *interface = (VLCMain *)param; interaction_dialog_t *p_dialog = (interaction_dialog_t *)(new_val.p_address); NSValue *o_value = [NSValue valueWithPointer:p_dialog]; [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewInteractionEventNotification" object:[interface getInteractionList] userInfo:[NSDictionary dictionaryWithObject:o_value forKey:@"VLCDialogPointer"]]; [o_pool release]; return VLC_SUCCESS;}#pragma mark -/***************************************************************************** * VLCMain implementation *****************************************************************************/@implementation VLCMain#pragma mark -#pragma mark Initializationstatic VLCMain *_o_sharedMainInstance = nil;+ (VLCMain *)sharedInstance{ return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];}- (id)init{ if( _o_sharedMainInstance) { [self dealloc]; return _o_sharedMainInstance; } else _o_sharedMainInstance = [super init]; o_about = [[VLAboutBox alloc] init]; o_prefs = nil; o_open = [[VLCOpen alloc] init]; o_wizard = [[VLCWizard alloc] init]; o_extended = nil; o_bookmarks = [[VLCBookmarks alloc] init]; o_embedded_list = [[VLCEmbeddedList alloc] init]; o_interaction_list = [[VLCInteractionList alloc] init]; o_info = [[VLCInfo alloc] init];#ifdef UPDATE_CHECK o_update = [[VLCUpdate alloc] init];#endif i_lastShownVolume = -1; o_remote = [[AppleRemote alloc] init]; [o_remote setClickCountEnabledButtons: kRemoteButtonPlay]; [o_remote setDelegate: _o_sharedMainInstance]; o_eyetv = [[VLCEyeTVController alloc] init]; /* announce our launch to a potential eyetv plugin */ [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit" object: @"VLCEyeTVSupport" userInfo: NULL deliverImmediately: YES]; return _o_sharedMainInstance;}- (void)setIntf: (intf_thread_t *)p_mainintf { p_intf = p_mainintf;}- (intf_thread_t *)getIntf { return p_intf;}- (void)awakeFromNib{ unsigned int i_key = 0; playlist_t *p_playlist; vlc_value_t val; /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */ if( nib_main_loaded ) return; [self initStrings]; [o_window setExcludedFromWindowsMenu: YES]; [o_msgs_panel setExcludedFromWindowsMenu: YES]; [o_msgs_panel setDelegate: self]; /* In code and not in Nib for 10.4 compat */ NSToolbar * toolbar = [[[NSToolbar alloc] initWithIdentifier:@"mainControllerToolbar"] autorelease]; [toolbar setDelegate:self]; [toolbar setShowsBaselineSeparator:NO]; [toolbar setAllowsUserCustomization:NO]; [toolbar setDisplayMode:NSToolbarDisplayModeIconOnly]; [toolbar setAutosavesConfiguration:YES]; [o_window setToolbar:toolbar]; i_key = config_GetInt( p_intf, "key-quit" ); [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-play-pause" ); [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-stop" ); [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-faster" ); [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-slower" ); [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-prev" ); [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-next" ); [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-jump+short" ); [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-jump-short" ); [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-jump+medium" ); [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-jump-medium" ); [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-jump+long" ); [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-jump-long" ); [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-vol-up" ); [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-vol-down" ); [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-vol-mute" ); [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-fullscreen" ); [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; i_key = config_GetInt( p_intf, "key-snapshot" ); [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]]; [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)]; var_Create( p_intf, "intf-change", VLC_VAR_BOOL ); [self setSubmenusEnabled: FALSE]; [o_volumeslider setEnabled: YES]; [self manageVolumeSlider]; [o_window setDelegate: self]; b_restore_size = false; // Set that here as IB seems to be buggy [o_window setContentMinSize:NSMakeSize(338., 30.)]; if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. ) { b_small_window = YES; [o_window setFrame: NSMakeRect( [o_window frame].origin.x, [o_window frame].origin.y, [o_window frame].size.width, [o_window minSize].height ) display: YES animate:YES]; [o_playlist_view setAutoresizesSubviews: NO]; } else { b_small_window = NO; NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]]; [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )]; [o_playlist_view setNeedsDisplay:YES]; [o_playlist_view setAutoresizesSubviews: YES]; [[o_window contentView] addSubview: o_playlist_view]; } [self updateTogglePlaylistState];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -