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

📄 intf.m

📁 video linux conference
💻 M
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************** * intf.m: MacOS X interface module ***************************************************************************** * Copyright (C) 2002-2005 VideoLAN * $Id: intf.m 11483 2005-06-20 21:09:46Z fkuehne $ * * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> *          Christophe Massiot <massiot@via.ecp.fr> *          Derk-Jan Hartman <hartman at videolan.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 <vlc_keys.h>#include "intf.h"#include "vout.h"#include "prefs.h"#include "playlist.h"#include "controls.h"#include "about.h"#include "open.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 );    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. *****************************************************************************/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 = TRUE;    p_intf->p_sys->b_intf_update = TRUE;    p_intf->p_sys->b_playmode_update = TRUE;    return VLC_SUCCESS;}/***************************************************************************** * FullscreenChanged: Callback triggered by the fullscreen-change playlist * variable, to let the intf update the controller. *****************************************************************************/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;}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];    i_lastShownVolume = -1;    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;    [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)];    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+10sec" );    [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-10sec" );    [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+1min" );    [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-1min" );    [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+5min" );    [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-5min" );    [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];    [self manageVolumeSlider];    [o_window setDelegate: self];        if( [o_window frame].size.height <= 200 )    {        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;        [o_playlist_view setFrame: NSMakeRect( 10, 10, [o_window frame].size.width - 20, [o_window frame].size.height - 105 )];        [o_playlist_view setNeedsDisplay:YES];        [o_playlist_view setAutoresizesSubviews: YES];        [[o_window contentView] addSubview: o_playlist_view];    }    [self updateTogglePlaylistState];    o_size_with_playlist = [o_window frame].size;    p_playlist = (playlist_t *) vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );    if( p_playlist )    {        /* Check if we need to start playing */        if( p_intf->b_play )        {            playlist_Play( p_playlist );        }        var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);        val.b_bool = VLC_FALSE;        var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);        [o_btn_fullscreen setState: ( var_Get( p_playlist, "fullscreen", &val )>=0 && val.b_bool )];        vlc_object_release( p_playlist );    }}- (void)initStrings{    [o_window setTitle: _NS("VLC - Controller")];    [self setScrollField:_NS("VLC media player") stopAfter:-1];    /* button controls */    [o_btn_prev setToolTip: _NS("Previous")];    [o_btn_rewind setToolTip: _NS("Rewind")];    [o_btn_play setToolTip: _NS("Play")];    [o_btn_stop setToolTip: _NS("Stop")];    [o_btn_ff setToolTip: _NS("Fast Forward")];    [o_btn_next setToolTip: _NS("Next")];

⌨️ 快捷键说明

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