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"
43 /*****************************************************************************
44 * VLCControls implementation
45 *****************************************************************************/
46 @implementation VLCControls
48 @synthesize jumpTimeValue;
52 [o_specificTime_mi setTitle: _NS("Jump To Time")];
53 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
54 [o_specificTime_ok_btn setTitle: _NS("OK")];
55 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
56 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
61 [[NSNotificationCenter defaultCenter] removeObserver: self];
66 - (IBAction)play:(id)sender
68 [[VLCCoreInteraction sharedInstance] playOrPause];
71 - (IBAction)stop:(id)sender
73 [[VLCCoreInteraction sharedInstance] stop];
76 - (IBAction)prev:(id)sender
78 [[VLCCoreInteraction sharedInstance] previous];
81 - (IBAction)next:(id)sender
83 [[VLCCoreInteraction sharedInstance] next];
86 - (IBAction)random:(id)sender
88 [[VLCCoreInteraction sharedInstance] shuffle];
91 - (IBAction)repeat:(id)sender
94 intf_thread_t * p_intf = VLCIntf;
95 playlist_t * p_playlist = pl_Get(p_intf);
97 var_Get(p_playlist, "repeat", &val);
99 [[VLCCoreInteraction sharedInstance] repeatOne];
101 [[VLCCoreInteraction sharedInstance] repeatOff];
104 - (IBAction)loop:(id)sender
107 intf_thread_t * p_intf = VLCIntf;
108 playlist_t * p_playlist = pl_Get(p_intf);
110 var_Get(p_playlist, "loop", &val);
112 [[VLCCoreInteraction sharedInstance] repeatAll];
114 [[VLCCoreInteraction sharedInstance] repeatOff];
117 - (IBAction)quitAfterPlayback:(id)sender
120 playlist_t * p_playlist = pl_Get(VLCIntf);
121 var_ToggleBool(p_playlist, "play-and-exit");
124 - (IBAction)forward:(id)sender
126 [[VLCCoreInteraction sharedInstance] forward];
129 - (IBAction)backward:(id)sender
131 [[VLCCoreInteraction sharedInstance] backward];
134 - (IBAction)volumeUp:(id)sender
136 [[VLCCoreInteraction sharedInstance] volumeUp];
139 - (IBAction)volumeDown:(id)sender
141 [[VLCCoreInteraction sharedInstance] volumeDown];
144 - (IBAction)mute:(id)sender
146 [[VLCCoreInteraction sharedInstance] setMute: YES];
149 - (IBAction)volumeSliderUpdated:(id)sender
151 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
154 - (IBAction)showPosition: (id)sender
156 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
157 if (p_input != NULL) {
158 vout_thread_t *p_vout = input_GetVout(p_input);
159 if (p_vout != NULL) {
160 var_SetInteger(VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION);
161 vlc_object_release(p_vout);
163 vlc_object_release(p_input);
167 - (IBAction)lockVideosAspectRatio:(id)sender
169 [[VLCCoreInteraction sharedInstance] setAspectRatioIsLocked: ![sender state]];
170 [sender setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
173 - (BOOL)keyEvent:(NSEvent *)o_event
175 BOOL eventHandled = NO;
176 NSString * characters = [o_event charactersIgnoringModifiers];
177 if ([characters length] > 0) {
178 unichar key = [characters characterAtIndex: 0];
181 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
182 if (p_input != NULL) {
183 vout_thread_t *p_vout = input_GetVout(p_input);
185 if (p_vout != NULL) {
187 if (key == (unichar) 0x1b) {
188 if (var_GetBool(p_vout, "fullscreen")) {
189 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
193 else if (key == ' ') {
197 vlc_object_release(p_vout);
199 vlc_object_release(p_input);
206 - (IBAction)goToSpecificTime:(id)sender
208 if (sender == o_specificTime_cancel_btn)
210 [NSApp endSheet: o_specificTime_win];
211 [o_specificTime_win close];
212 } else if (sender == o_specificTime_ok_btn) {
213 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
215 int64_t timeInSec = 0;
216 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
217 if ([[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
218 [[fieldContent componentsSeparatedByString: @":"] count] <= 3) {
219 NSArray * ourTempArray = \
220 [fieldContent componentsSeparatedByString: @":"];
222 if ([[fieldContent componentsSeparatedByString: @":"] count] == 3) {
223 timeInSec += ([ourTempArray[0] intValue] * 3600); //h
224 timeInSec += ([ourTempArray[1] intValue] * 60); //m
225 timeInSec += [ourTempArray[2] intValue]; //s
227 timeInSec += ([ourTempArray[0] intValue] * 60); //m
228 timeInSec += [ourTempArray[1] intValue]; //s
232 timeInSec = [fieldContent intValue];
234 input_Control(p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
235 vlc_object_release(p_input);
238 [NSApp endSheet: o_specificTime_win];
239 [o_specificTime_win close];
241 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
243 /* we can obviously only do that if an input is available */
244 vlc_value_t pos, length;
245 var_Get(p_input, "length", &length);
246 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
247 var_Get(p_input, "time", &pos);
248 [self setJumpTimeValue: (pos.i_time / 1000000)];
249 [NSApp beginSheet: o_specificTime_win modalForWindow: \
250 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
252 [o_specificTime_win makeKeyWindow];
253 vlc_object_release(p_input);
260 @implementation VLCControls (NSMenuValidation)
262 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
264 return [[VLCMainMenu sharedInstance] validateMenuItem:o_mi];