applescript.m
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:5k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * applescript.m: MacOS X AppleScript support
  3.  *****************************************************************************
  4.  * Copyright (C) 2002-2009 the VideoLAN team
  5.  * $Id: 4935d3f71db4a4ffce94f076e2b039285fa72b26 $
  6.  *
  7.  * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
  8.  *
  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.
  13.  *
  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.
  18.  *
  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.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble
  25.  *****************************************************************************/
  26. #include "intf.h"
  27. #include "applescript.h"
  28. #include "controls.h"
  29. #include "open.h"
  30. /*****************************************************************************
  31.  * VLGetURLScriptCommand implementation
  32.  *****************************************************************************/
  33. @implementation VLGetURLScriptCommand
  34. - (id)performDefaultImplementation {
  35.     NSString *o_command = [[self commandDescription] commandName];
  36.     NSString *o_urlString = [self directParameter];
  37.     if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] )
  38.     {
  39.         intf_thread_t * p_intf = VLCIntf;
  40.         playlist_t * p_playlist = pl_Hold( p_intf );
  41.         if( p_playlist == NULL )
  42.         {
  43.             return nil;
  44.         }
  45.         if ( o_urlString )
  46.         {
  47.             NSURL * o_url;
  48.             input_item_t *p_input;
  49.             p_input = input_item_New( p_playlist,
  50.                                     [o_urlString fileSystemRepresentation],
  51.                                     [[[NSFileManager defaultManager]
  52.                                     displayNameAtPath: o_urlString] UTF8String] );
  53.             /* FIXME: playlist_AddInput() can fail */
  54.             playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
  55.                                PLAYLIST_END, true, pl_Unlocked );
  56.             vlc_gc_decref( p_input );
  57.             o_url = [NSURL fileURLWithPath: o_urlString];
  58.             if( o_url != nil )
  59.             {
  60.                 [[NSDocumentController sharedDocumentController]
  61.                     noteNewRecentDocumentURL: o_url];
  62.             }
  63.         }
  64.         pl_Release( p_intf );
  65.     }
  66.     return nil;
  67. }
  68. @end
  69. /*****************************************************************************
  70.  * VLControlScriptCommand implementation
  71.  *****************************************************************************/
  72. /*
  73.  * This entire control command needs a better design. more object oriented.
  74.  * Applescript developers would be very welcome (hartman)
  75.  */
  76. @implementation VLControlScriptCommand
  77. - (id)performDefaultImplementation {
  78.     NSString *o_command = [[self commandDescription] commandName];
  79.     intf_thread_t * p_intf = VLCIntf;
  80.     playlist_t * p_playlist = pl_Hold( p_intf );
  81.     if( p_playlist == NULL )
  82.     {
  83.         return nil;
  84.     }
  85.  
  86.     VLCControls * o_controls = (VLCControls *)[[NSApp delegate] controls];
  87.  
  88.     if ( o_controls )
  89.     {
  90.         if ( [o_command isEqualToString:@"play"] )
  91.         {
  92.             [o_controls play:self];
  93.         }
  94.         else if ( [o_command isEqualToString:@"stop"] )
  95.         {
  96.             [o_controls stop:self];
  97.         }
  98.         else if ( [o_command isEqualToString:@"previous"] )
  99.         {
  100.             [o_controls prev:self];
  101.         }
  102.         else if ( [o_command isEqualToString:@"next"] )
  103.         {
  104.             [o_controls next:self];
  105.         }
  106.         else if ( [o_command isEqualToString:@"fullscreen"] )
  107.         {
  108.             [o_controls toogleFullscreen: self];
  109.         }
  110.         else if ( [o_command isEqualToString:@"mute"] )
  111.         {
  112.             [o_controls mute:self];
  113.         }
  114.         else if ( [o_command isEqualToString:@"volumeUp"] )
  115.         {
  116.             [o_controls volumeUp:self];
  117.         }
  118.         else if ( [o_command isEqualToString:@"volumeDown"] )
  119.         {
  120.             [o_controls volumeDown:self];
  121.         }
  122.     }
  123.     pl_Release( p_intf );
  124.     return nil;
  125. }
  126. @end
  127. /*****************************************************************************
  128.  * Category that adds AppleScript support to NSApplication
  129.  *****************************************************************************/
  130. @implementation NSApplication(ScriptSupport)
  131. - (BOOL) scriptFullscreenMode {    
  132.     VLCControls * o_controls = (VLCControls *)[[self delegate] controls];
  133.     return [o_controls isFullscreen];
  134. }
  135. - (void) setScriptFullscreenMode: (BOOL) mode {
  136.     VLCControls * o_controls = (VLCControls *)[[self delegate] controls];
  137.     if (mode == [o_controls isFullscreen]) return;
  138.     [o_controls toogleFullscreen: self];
  139. }
  140. @end