1 /*****************************************************************************
2 * controls.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2013 VLC authors and VideoLAN
7 * Authors: Derk-Jan Hartman <hartman at videolan dot org>
8 * Benjamin Pracht <bigben at videolan doit org>
9 * Felix Paul Kühne <fkuehne at videolan dot org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <stdlib.h> /* malloc(), free() */
30 #include <sys/param.h> /* for MAXPATHLEN */
39 #import "CoreInteraction.h"
44 /*****************************************************************************
45 * VLCControls implementation
46 *****************************************************************************/
47 @implementation VLCControls
49 @synthesize jumpTimeValue;
53 [o_specificTime_mi setTitle: _NS("Jump to Time")];
54 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
55 [o_specificTime_ok_btn setTitle: _NS("OK")];
56 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
57 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to Time")];
59 [o_specificTime_enter_fld setFormatter:[[[PositionFormatter alloc] init] autorelease]];
64 [[NSNotificationCenter defaultCenter] removeObserver: self];
69 - (IBAction)play:(id)sender
71 [[VLCCoreInteraction sharedInstance] playOrPause];
74 - (IBAction)stop:(id)sender
76 [[VLCCoreInteraction sharedInstance] stop];
79 - (IBAction)prev:(id)sender
81 [[VLCCoreInteraction sharedInstance] previous];
84 - (IBAction)next:(id)sender
86 [[VLCCoreInteraction sharedInstance] next];
89 - (IBAction)random:(id)sender
91 [[VLCCoreInteraction sharedInstance] shuffle];
94 - (IBAction)repeat:(id)sender
97 intf_thread_t * p_intf = VLCIntf;
98 playlist_t * p_playlist = pl_Get(p_intf);
100 var_Get(p_playlist, "repeat", &val);
102 [[VLCCoreInteraction sharedInstance] repeatOne];
104 [[VLCCoreInteraction sharedInstance] repeatOff];
107 - (IBAction)loop:(id)sender
110 intf_thread_t * p_intf = VLCIntf;
111 playlist_t * p_playlist = pl_Get(p_intf);
113 var_Get(p_playlist, "loop", &val);
115 [[VLCCoreInteraction sharedInstance] repeatAll];
117 [[VLCCoreInteraction sharedInstance] repeatOff];
120 - (IBAction)forward:(id)sender
122 [[VLCCoreInteraction sharedInstance] forward];
125 - (IBAction)backward:(id)sender
127 [[VLCCoreInteraction sharedInstance] backward];
130 - (IBAction)volumeUp:(id)sender
132 [[VLCCoreInteraction sharedInstance] volumeUp];
135 - (IBAction)volumeDown:(id)sender
137 [[VLCCoreInteraction sharedInstance] volumeDown];
140 - (IBAction)mute:(id)sender
142 [[VLCCoreInteraction sharedInstance] toggleMute];
145 - (IBAction)volumeSliderUpdated:(id)sender
147 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
150 - (IBAction)showPosition: (id)sender
152 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
153 if (p_input != NULL) {
154 vout_thread_t *p_vout = input_GetVout(p_input);
155 if (p_vout != NULL) {
156 var_SetInteger(VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION);
157 vlc_object_release(p_vout);
159 vlc_object_release(p_input);
163 - (IBAction)lockVideosAspectRatio:(id)sender
165 [[VLCCoreInteraction sharedInstance] setAspectRatioIsLocked: ![sender state]];
166 [sender setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
169 - (BOOL)keyEvent:(NSEvent *)o_event
171 BOOL eventHandled = NO;
172 NSString * characters = [o_event charactersIgnoringModifiers];
173 if ([characters length] > 0) {
174 unichar key = [characters characterAtIndex: 0];
177 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
178 if (p_input != NULL) {
179 vout_thread_t *p_vout = input_GetVout(p_input);
181 if (p_vout != NULL) {
183 if (key == (unichar) 0x1b) {
184 if (var_GetBool(p_vout, "fullscreen")) {
185 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
189 vlc_object_release(p_vout);
191 vlc_object_release(p_input);
198 - (IBAction)goToSpecificTime:(id)sender
200 if (sender == o_specificTime_cancel_btn)
202 [NSApp endSheet: o_specificTime_win];
203 [o_specificTime_win close];
204 } else if (sender == o_specificTime_ok_btn) {
205 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
207 int64_t timeInSec = 0;
208 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
209 if ([[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
210 [[fieldContent componentsSeparatedByString: @":"] count] <= 3) {
211 NSArray * ourTempArray = \
212 [fieldContent componentsSeparatedByString: @":"];
214 if ([[fieldContent componentsSeparatedByString: @":"] count] == 3) {
215 timeInSec += ([[ourTempArray objectAtIndex:0] intValue] * 3600); //h
216 timeInSec += ([[ourTempArray objectAtIndex:1] intValue] * 60); //m
217 timeInSec += [[ourTempArray objectAtIndex:2] intValue]; //s
219 timeInSec += ([[ourTempArray objectAtIndex:0] intValue] * 60); //m
220 timeInSec += [[ourTempArray objectAtIndex:1] intValue]; //s
224 timeInSec = [fieldContent intValue];
226 input_Control(p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
227 vlc_object_release(p_input);
230 [NSApp endSheet: o_specificTime_win];
231 [o_specificTime_win close];
233 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
235 /* we can obviously only do that if an input is available */
236 vlc_value_t pos, length;
237 var_Get(p_input, "length", &length);
238 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
239 var_Get(p_input, "time", &pos);
240 [self setJumpTimeValue: (pos.i_time / 1000000)];
241 [NSApp beginSheet: o_specificTime_win modalForWindow: \
242 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
244 [o_specificTime_win makeKeyWindow];
245 vlc_object_release(p_input);
252 @implementation VLCControls (NSMenuValidation)
254 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
256 return [[VLCMainMenu sharedInstance] validateMenuItem:o_mi];