⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intf.m

📁 uclinux 下的vlc播放器源代码
💻 M
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * intf.m: MacOS X interface module ***************************************************************************** * Copyright (C) 2002-2006 the VideoLAN team * $Id: intf.m 18971 2007-02-23 17:17:38Z fkuehne $ * * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> *          Christophe Massiot <massiot@via.ecp.fr> *          Derk-Jan Hartman <hartman at videolan.org> *          Felix K焗ne <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>#import "intf.h"#import "fspanel.h"#import "vout.h"#import "prefs.h"#import "playlist.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"/***************************************************************************** * Local prototypes. *****************************************************************************/static void Run ( intf_thread_t *p_intf );/***************************************************************************** * OpenIntf: initialize interface *****************************************************************************/int E_(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];    /* Put Cocoa into multithread mode as soon as possible.     * http://developer.apple.com/techpubs/macosx/Cocoa/     * TasksAndConcepts/ProgrammingTopics/Multithreading/index.html     * This thread does absolutely nothing at all. */    [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil];    p_intf->p_sys->o_sendport = [[NSPort port] retain];    p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );    p_intf->b_play = VLC_TRUE;    p_intf->pf_run = Run;    return( 0 );}/***************************************************************************** * CloseIntf: destroy interface *****************************************************************************/void E_(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_sendport release];    [p_intf->p_sys->o_pool release];    free( p_intf->p_sys );}/***************************************************************************** * Run: main loop *****************************************************************************/static void Run( intf_thread_t *p_intf ){    /* 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 );    [[VLCMain sharedInstance] setIntf: p_intf];    [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];    [NSApp run];    [[VLCMain sharedInstance] terminate];}int ExecuteOnMainThread( id target, SEL sel, void * p_arg ){    int i_ret = 0;    //NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];    if( [target respondsToSelector: @selector(performSelectorOnMainThread:                                             withObject:waitUntilDone:)] )    {        [target performSelectorOnMainThread: sel                withObject: [NSValue valueWithPointer: p_arg]                waitUntilDone: NO];    }    else if( NSApp != nil && [[VLCMain sharedInstance] respondsToSelector: @selector(getIntf)] )    {        NSValue * o_v1;        NSValue * o_v2;        NSArray * o_array;        NSPort * o_recv_port;        NSInvocation * o_inv;        NSPortMessage * o_msg;        intf_thread_t * p_intf;        NSConditionLock * o_lock;        NSMethodSignature * o_sig;        id * val[] = { &o_lock, &o_v2 };        p_intf = (intf_thread_t *)VLCIntf;        o_recv_port = [[NSPort port] retain];        o_v1 = [NSValue valueWithPointer: val];        o_v2 = [NSValue valueWithPointer: p_arg];        o_sig = [target methodSignatureForSelector: sel];        o_inv = [NSInvocation invocationWithMethodSignature: o_sig];        [o_inv setArgument: &o_v1 atIndex: 2];        [o_inv setTarget: target];        [o_inv setSelector: sel];        o_array = [NSArray arrayWithObject:            [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];        o_msg = [[NSPortMessage alloc]            initWithSendPort: p_intf->p_sys->o_sendport            receivePort: o_recv_port components: o_array];        o_lock = [[NSConditionLock alloc] initWithCondition: 0];        [o_msg sendBeforeDate: [NSDate distantPast]];        [o_lock lockWhenCondition: 1];        [o_lock unlock];        [o_lock release];        [o_msg release];        [o_recv_port release];    }    else    {        i_ret = 1;    }    //[o_pool release];    return( i_ret );}/***************************************************************************** * 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_playlist_update = VLC_TRUE;    p_intf->p_sys->b_intf_update = VLC_TRUE;    p_intf->p_sys->b_playmode_update = VLC_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 = VLC_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 = VLC_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;}static struct{    unichar i_nskey;    unsigned int i_vlckey;} nskeys_to_vlckeys[] ={    { NSUpArrowFunctionKey, KEY_UP },    { NSDownArrowFunctionKey, KEY_DOWN },    { NSLeftArrowFunctionKey, KEY_LEFT },    { NSRightArrowFunctionKey, KEY_RIGHT },    { NSF1FunctionKey, KEY_F1 },    { NSF2FunctionKey, KEY_F2 },    { NSF3FunctionKey, KEY_F3 },    { NSF4FunctionKey, KEY_F4 },    { NSF5FunctionKey, KEY_F5 },    { NSF6FunctionKey, KEY_F6 },    { NSF7FunctionKey, KEY_F7 },    { NSF8FunctionKey, KEY_F8 },    { NSF9FunctionKey, KEY_F9 },    { NSF10FunctionKey, KEY_F10 },    { NSF11FunctionKey, KEY_F11 },    { NSF12FunctionKey, KEY_F12 },    { NSHomeFunctionKey, KEY_HOME },    { NSEndFunctionKey, KEY_END },    { NSPageUpFunctionKey, KEY_PAGEUP },    { NSPageDownFunctionKey, KEY_PAGEDOWN },    { NSTabCharacter, KEY_TAB },    { NSCarriageReturnCharacter, KEY_ENTER },    { NSEnterCharacter, KEY_ENTER },    { NSBackspaceCharacter, KEY_BACKSPACE },    { (unichar) ' ', KEY_SPACE },    { (unichar) 0x1b, KEY_ESC },    {0,0}};unichar VLCKeyToCocoa( unsigned int i_key ){    unsigned int i;    for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )    {        if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )        {            return nskeys_to_vlckeys[i].i_nskey;        }    }    return (unichar)(i_key & ~KEY_MODIFIER);}unsigned int CocoaKeyToVLC( unichar i_key ){    unsigned int i;    for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )    {        if( nskeys_to_vlckeys[i].i_nskey == i_key )        {            return nskeys_to_vlckeys[i].i_vlckey;        }    }    return (unsigned int)i_key;}unsigned int VLCModifiersToCocoa( unsigned int i_key ){    unsigned int new = 0;    if( i_key & KEY_MODIFIER_COMMAND )        new |= NSCommandKeyMask;    if( i_key & KEY_MODIFIER_ALT )        new |= NSAlternateKeyMask;    if( i_key & KEY_MODIFIER_SHIFT )        new |= NSShiftKeyMask;    if( i_key & KEY_MODIFIER_CTRL )        new |= NSControlKeyMask;    return new;}/***************************************************************************** * VLCMain implementation *****************************************************************************/@implementation VLCMainstatic VLCMain *_o_sharedMainInstance = nil;+ (VLCMain *)sharedInstance{    return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];}- (id)init{    if( _o_sharedMainInstance) {        [self dealloc];    } 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_update = [[VLCUpdate alloc] init];    i_lastShownVolume = -1;    o_remote = [[AppleRemote alloc] init];    [o_remote setDelegate: _o_sharedMainInstance];        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: TRUE];    [o_msgs_panel setExcludedFromWindowsMenu: TRUE];    [o_msgs_panel setDelegate: self];    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)];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -