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)quitAfterPlayback:(id)sender
123 playlist_t * p_playlist = pl_Get(VLCIntf);
124 var_ToggleBool(p_playlist, "play-and-exit");
127 - (IBAction)forward:(id)sender
129 [[VLCCoreInteraction sharedInstance] forward];
132 - (IBAction)backward:(id)sender
134 [[VLCCoreInteraction sharedInstance] backward];
137 - (IBAction)volumeUp:(id)sender
139 [[VLCCoreInteraction sharedInstance] volumeUp];
142 - (IBAction)volumeDown:(id)sender
144 [[VLCCoreInteraction sharedInstance] volumeDown];
147 - (IBAction)mute:(id)sender
149 [[VLCCoreInteraction sharedInstance] setMute: YES];
152 - (IBAction)volumeSliderUpdated:(id)sender
154 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
157 - (IBAction)showPosition: (id)sender
159 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
160 if (p_input != NULL) {
161 vout_thread_t *p_vout = input_GetVout(p_input);
162 if (p_vout != NULL) {
163 var_SetInteger(VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION);
164 vlc_object_release(p_vout);
166 vlc_object_release(p_input);
170 - (IBAction)lockVideosAspectRatio:(id)sender
172 [[VLCCoreInteraction sharedInstance] setAspectRatioIsLocked: ![sender state]];
173 [sender setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
176 - (BOOL)keyEvent:(NSEvent *)o_event
178 BOOL eventHandled = NO;
179 NSString * characters = [o_event charactersIgnoringModifiers];
180 if ([characters length] > 0) {
181 unichar key = [characters characterAtIndex: 0];
184 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
185 if (p_input != NULL) {
186 vout_thread_t *p_vout = input_GetVout(p_input);
188 if (p_vout != NULL) {
190 if (key == (unichar) 0x1b) {
191 if (var_GetBool(p_vout, "fullscreen")) {
192 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
196 vlc_object_release(p_vout);
198 vlc_object_release(p_input);
205 - (IBAction)goToSpecificTime:(id)sender
207 if (sender == o_specificTime_cancel_btn)
209 [NSApp endSheet: o_specificTime_win];
210 [o_specificTime_win close];
211 } else if (sender == o_specificTime_ok_btn) {
212 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
214 int64_t timeInSec = 0;
215 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
216 if ([[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
217 [[fieldContent componentsSeparatedByString: @":"] count] <= 3) {
218 NSArray * ourTempArray = \
219 [fieldContent componentsSeparatedByString: @":"];
221 if ([[fieldContent componentsSeparatedByString: @":"] count] == 3) {
222 timeInSec += ([[ourTempArray objectAtIndex:0] intValue] * 3600); //h
223 timeInSec += ([[ourTempArray objectAtIndex:1] intValue] * 60); //m
224 timeInSec += [[ourTempArray objectAtIndex:2] intValue]; //s
226 timeInSec += ([[ourTempArray objectAtIndex:0] intValue] * 60); //m
227 timeInSec += [[ourTempArray objectAtIndex:1] intValue]; //s
231 timeInSec = [fieldContent intValue];
233 input_Control(p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
234 vlc_object_release(p_input);
237 [NSApp endSheet: o_specificTime_win];
238 [o_specificTime_win close];
240 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
242 /* we can obviously only do that if an input is available */
243 vlc_value_t pos, length;
244 var_Get(p_input, "length", &length);
245 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
246 var_Get(p_input, "time", &pos);
247 [self setJumpTimeValue: (pos.i_time / 1000000)];
248 [NSApp beginSheet: o_specificTime_win modalForWindow: \
249 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
251 [o_specificTime_win makeKeyWindow];
252 vlc_object_release(p_input);
259 @implementation VLCControls (NSMenuValidation)
261 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
263 return [[VLCMainMenu sharedInstance] validateMenuItem:o_mi];