/*****************************************************************************
* applescript.m: MacOS X AppleScript support
*****************************************************************************
- * Copyright (C) 2002-2012 VLC authors and VideoLAN
+ * Copyright (C) 2002-2013 VLC authors and VideoLAN
* $Id$
*
* Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include "intf.h"
-#include "applescript.h"
-#include "CoreInteraction.h"
-#include "vlc_aout_intf.h"
+#import "intf.h"
+#import "applescript.h"
+#import "CoreInteraction.h"
+#import "playlist.h"
+#import <vlc_url.h>
/*****************************************************************************
* VLGetURLScriptCommand implementation
NSString *o_command = [[self commandDescription] commandName];
NSString *o_urlString = [self directParameter];
- if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] )
- {
- intf_thread_t * p_intf = VLCIntf;
- playlist_t * p_playlist = pl_Get( p_intf );
- if( p_playlist == NULL )
- {
- return nil;
- }
-
- if ( o_urlString )
- {
- NSURL * o_url;
- input_item_t *p_input;
-
- p_input = input_item_New( [o_urlString fileSystemRepresentation],
- [[[NSFileManager defaultManager]
- displayNameAtPath: o_urlString] UTF8String] );
- /* FIXME: playlist_AddInput() can fail */
- playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
- PLAYLIST_END, true, pl_Unlocked );
-
- vlc_gc_decref( p_input );
-
- o_url = [NSURL fileURLWithPath: o_urlString];
- if( o_url != nil )
- {
- [[NSDocumentController sharedDocumentController]
- noteNewRecentDocumentURL: o_url];
+ if ([o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"]) {
+ if (o_urlString) {
+ BOOL b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
+ NSURL * o_url = [NSURL fileURLWithPath: o_urlString];
+ if (o_url != nil)
+ [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_url];
+
+ input_thread_t * p_input = pl_CurrentInput(VLCIntf);
+ BOOL b_returned = NO;
+
+ if (p_input) {
+ b_returned = input_AddSubtitle(p_input, [o_urlString UTF8String], true);
+ vlc_object_release(p_input);
+ if (!b_returned)
+ return nil;
}
+
+ NSDictionary *o_dic;
+ NSArray *o_array;
+ o_dic = [NSDictionary dictionaryWithObject:o_urlString forKey:@"ITEM_URL"];
+ o_array = [NSArray arrayWithObject: o_dic];
+
+ if (b_autoplay)
+ [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue: NO];
+ else
+ [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue: YES];
}
}
return nil;
NSString *o_parameter = [self directParameter];
intf_thread_t * p_intf = VLCIntf;
- playlist_t * p_playlist = pl_Get( p_intf );
- if( p_playlist == NULL )
- {
- return nil;
- }
+ playlist_t * p_playlist = pl_Get(p_intf);
- if ( [o_command isEqualToString:@"play"] )
- {
- [[VLCCoreInteraction sharedInstance] play];
- }
- else if ( [o_command isEqualToString:@"stop"] )
- {
+ if ([o_command isEqualToString:@"play"])
+ [[VLCCoreInteraction sharedInstance] playOrPause];
+ else if ([o_command isEqualToString:@"stop"])
[[VLCCoreInteraction sharedInstance] stop];
- }
- else if ( [o_command isEqualToString:@"previous"] )
- {
+ else if ([o_command isEqualToString:@"previous"])
[[VLCCoreInteraction sharedInstance] previous];
- }
- else if ( [o_command isEqualToString:@"next"] )
- {
+ else if ([o_command isEqualToString:@"next"])
[[VLCCoreInteraction sharedInstance] next];
- }
- else if ( [o_command isEqualToString:@"fullscreen"] )
- {
+ else if ([o_command isEqualToString:@"fullscreen"])
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
- }
- else if ( [o_command isEqualToString:@"mute"] )
- {
- [[VLCCoreInteraction sharedInstance] setMute: YES];
- }
- else if ( [o_command isEqualToString:@"volumeUp"] )
- {
+ else if ([o_command isEqualToString:@"mute"])
+ [[VLCCoreInteraction sharedInstance] toggleMute];
+ else if ([o_command isEqualToString:@"volumeUp"])
[[VLCCoreInteraction sharedInstance] volumeUp];
- }
- else if ( [o_command isEqualToString:@"volumeDown"] )
- {
+ else if ([o_command isEqualToString:@"volumeDown"])
[[VLCCoreInteraction sharedInstance] volumeDown];
- }
- else if ( [o_command isEqualToString:@"stepForward"] )
- {
+ else if ([o_command isEqualToString:@"stepForward"]) {
//default: forwardShort
- if (o_parameter)
- {
+ if (o_parameter) {
int i_parameter = [o_parameter intValue];
- switch (i_parameter)
- {
+ switch (i_parameter) {
case 1:
[[VLCCoreInteraction sharedInstance] forwardExtraShort];
break;
[[VLCCoreInteraction sharedInstance] forwardShort];
break;
}
- }
- else
- {
+ } else
[[VLCCoreInteraction sharedInstance] forwardShort];
- }
- }
- else if ( [o_command isEqualToString:@"stepBackward"] )
- {
+ } else if ([o_command isEqualToString:@"stepBackward"]) {
//default: backwardShort
- if (o_parameter)
- {
+ if (o_parameter) {
int i_parameter = [o_parameter intValue];
- switch (i_parameter)
- {
+ switch (i_parameter) {
case 1:
[[VLCCoreInteraction sharedInstance] backwardExtraShort];
break;
[[VLCCoreInteraction sharedInstance] backwardShort];
break;
}
- }
- else
- {
+ } else
[[VLCCoreInteraction sharedInstance] backwardShort];
- }
}
return nil;
}
*****************************************************************************/
@implementation NSApplication(ScriptSupport)
-- (BOOL) scriptFullscreenMode {
- vout_thread_t * p_vout = getVout();
- if( !p_vout )
+- (BOOL)scriptFullscreenMode {
+ vout_thread_t * p_vout = getVoutForActiveWindow();
+ if (!p_vout)
return NO;
- BOOL b_value = var_GetBool( p_vout, "fullscreen");
- vlc_object_release( p_vout );
+ BOOL b_value = var_GetBool(p_vout, "fullscreen");
+ vlc_object_release(p_vout);
return b_value;
}
-- (void) setScriptFullscreenMode: (BOOL) mode {
- vout_thread_t * p_vout = getVout();
- if( !p_vout )
+
+- (void)setScriptFullscreenMode:(BOOL)mode {
+ vout_thread_t * p_vout = getVoutForActiveWindow();
+ if (!p_vout)
return;
- if (var_GetBool( p_vout, "fullscreen") == mode)
- {
- vlc_object_release( p_vout );
+ if (var_GetBool(p_vout, "fullscreen") == mode) {
+ vlc_object_release(p_vout);
return;
}
- vlc_object_release( p_vout );
+ vlc_object_release(p_vout);
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
}
- (BOOL) playing {
intf_thread_t *p_intf = VLCIntf;
- if( !p_intf )
+ if (!p_intf)
return NO;
- input_thread_t * p_input = pl_CurrentInput( p_intf );
- if( !p_input )
+ input_thread_t * p_input = pl_CurrentInput(p_intf);
+ if (!p_input)
return NO;
input_state_e i_state = ERROR_S;
- input_Control( p_input, INPUT_GET_STATE, &i_state );
- vlc_object_release( p_input );
+ input_Control(p_input, INPUT_GET_STATE, &i_state);
+ vlc_object_release(p_input);
- return ( ( i_state == OPENING_S ) || ( i_state == PLAYING_S ) );
+ return ((i_state == OPENING_S) || (i_state == PLAYING_S));
}
- (int) audioVolume {
- return ( [[VLCCoreInteraction sharedInstance] volume] );
+ return ([[VLCCoreInteraction sharedInstance] volume]);
}
-- (void) setAudioVolume: (int) i_audioVolume {
+- (void) setAudioVolume:(int)i_audioVolume {
[[VLCCoreInteraction sharedInstance] setVolume:(int)i_audioVolume];
}
+- (int) audioDesync {
+ input_thread_t * p_input = pl_CurrentInput(VLCIntf);
+ int i_delay = -1;
+
+ if(!p_input)
+ return i_delay;
+
+ i_delay = var_GetTime(p_input, "audio-delay");
+ vlc_object_release(p_input);
+
+ return (i_delay / 1000);
+}
+
+- (void) setAudioDesync:(int)i_audioDesync {
+ input_thread_t * p_input = pl_CurrentInput(VLCIntf);
+ if(!p_input)
+ return;
+
+ var_SetTime(p_input, "audio-delay", i_audioDesync * 1000);
+ vlc_object_release(p_input);
+}
+
- (int) currentTime {
- input_thread_t * p_input = pl_CurrentInput( VLCIntf );
+ input_thread_t * p_input = pl_CurrentInput(VLCIntf);
int64_t i_currentTime = -1;
- if( !p_input )
+ if (!p_input)
return i_currentTime;
- input_Control( p_input, INPUT_GET_TIME, &i_currentTime );
- vlc_object_release( p_input );
+ input_Control(p_input, INPUT_GET_TIME, &i_currentTime);
+ vlc_object_release(p_input);
- return (int)( i_currentTime / 1000000 );
+ return (int)(i_currentTime / 1000000);
}
-- (void) setCurrentTime: (int) i_currentTime {
+- (void) setCurrentTime:(int)i_currentTime {
if (i_currentTime) {
int64_t i64_value = (int64_t)i_currentTime;
- input_thread_t * p_input = pl_CurrentInput( VLCIntf );
+ input_thread_t * p_input = pl_CurrentInput(VLCIntf);
- if ( !p_input )
+ if (!p_input)
return;
- input_Control( p_input, INPUT_SET_TIME, (int64_t)(i64_value * 1000000) );
- vlc_object_release( p_input );
+ input_Control(p_input, INPUT_SET_TIME, (int64_t)(i64_value * 1000000));
+ vlc_object_release(p_input);
}
}
-#pragma mark -
-//TODO:whenever VLC should implement NSDocument, the methods below should move or be additionaly implemented in the NSDocument category
- (int) durationOfCurrentItem {
return [[VLCCoreInteraction sharedInstance] durationOfCurrentPlaylistItem];
}