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
50 [o_specificTime_mi setTitle: _NS("Jump To Time")];
51 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
52 [o_specificTime_ok_btn setTitle: _NS("OK")];
53 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
54 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
59 [[NSNotificationCenter defaultCenter] removeObserver: self];
64 - (IBAction)play:(id)sender
66 [[VLCCoreInteraction sharedInstance] playOrPause];
69 - (IBAction)stop:(id)sender
71 [[VLCCoreInteraction sharedInstance] stop];
74 - (IBAction)prev:(id)sender
76 [[VLCCoreInteraction sharedInstance] previous];
79 - (IBAction)next:(id)sender
81 [[VLCCoreInteraction sharedInstance] next];
84 - (IBAction)random:(id)sender
86 [[VLCCoreInteraction sharedInstance] shuffle];
89 - (IBAction)repeat:(id)sender
92 intf_thread_t * p_intf = VLCIntf;
93 playlist_t * p_playlist = pl_Get(p_intf);
95 var_Get(p_playlist, "repeat", &val);
97 [[VLCCoreInteraction sharedInstance] repeatOne];
99 [[VLCCoreInteraction sharedInstance] repeatOff];
102 - (IBAction)loop:(id)sender
105 intf_thread_t * p_intf = VLCIntf;
106 playlist_t * p_playlist = pl_Get(p_intf);
108 var_Get(p_playlist, "loop", &val);
110 [[VLCCoreInteraction sharedInstance] repeatAll];
112 [[VLCCoreInteraction sharedInstance] repeatOff];
115 - (IBAction)quitAfterPlayback:(id)sender
118 playlist_t * p_playlist = pl_Get(VLCIntf);
119 var_ToggleBool(p_playlist, "play-and-exit");
122 - (IBAction)forward:(id)sender
124 [[VLCCoreInteraction sharedInstance] forward];
127 - (IBAction)backward:(id)sender
129 [[VLCCoreInteraction sharedInstance] backward];
132 - (IBAction)volumeUp:(id)sender
134 [[VLCCoreInteraction sharedInstance] volumeUp];
137 - (IBAction)volumeDown:(id)sender
139 [[VLCCoreInteraction sharedInstance] volumeDown];
142 - (IBAction)mute:(id)sender
144 [[VLCCoreInteraction sharedInstance] setMute: YES];
147 - (IBAction)volumeSliderUpdated:(id)sender
149 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
152 - (IBAction)showPosition: (id)sender
154 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
155 if (p_input != NULL) {
156 vout_thread_t *p_vout = input_GetVout(p_input);
157 if (p_vout != NULL) {
158 var_SetInteger(VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION);
159 vlc_object_release(p_vout);
161 vlc_object_release(p_input);
165 - (IBAction)lockVideosAspectRatio:(id)sender
167 [[VLCCoreInteraction sharedInstance] setAspectRatioIsLocked: ![sender state]];
168 [sender setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
171 - (BOOL)keyEvent:(NSEvent *)o_event
173 BOOL eventHandled = NO;
174 NSString * characters = [o_event charactersIgnoringModifiers];
175 if ([characters length] > 0) {
176 unichar key = [characters characterAtIndex: 0];
179 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
180 if (p_input != NULL) {
181 vout_thread_t *p_vout = input_GetVout(p_input);
183 if (p_vout != NULL) {
185 if (key == (unichar) 0x1b) {
186 if (var_GetBool(p_vout, "fullscreen")) {
187 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
191 else if (key == ' ') {
195 vlc_object_release(p_vout);
197 vlc_object_release(p_input);
204 - (IBAction)goToSpecificTime:(id)sender
206 if (sender == o_specificTime_cancel_btn)
208 [NSApp endSheet: o_specificTime_win];
209 [o_specificTime_win close];
210 } else if (sender == o_specificTime_ok_btn) {
211 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
213 int64_t timeInSec = 0;
214 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
215 if ([[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
216 [[fieldContent componentsSeparatedByString: @":"] count] <= 3) {
217 NSArray * ourTempArray = \
218 [fieldContent componentsSeparatedByString: @":"];
220 if ([[fieldContent componentsSeparatedByString: @":"] count] == 3) {
221 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
222 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
223 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
225 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
226 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
230 timeInSec = [fieldContent intValue];
232 input_Control(p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
233 vlc_object_release(p_input);
236 [NSApp endSheet: o_specificTime_win];
237 [o_specificTime_win close];
239 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
241 /* we can obviously only do that if an input is available */
242 vlc_value_t pos, length;
243 var_Get(p_input, "time", &pos);
244 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
245 var_Get(p_input, "length", &length);
246 [o_specificTime_stepper setMaxValue: (length.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];