1 /*****************************************************************************
2 * MainWindow.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2012 VLC authors and VideoLAN
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8 * Jon Lech Johansen <jon-vl@nanocrew.net>
9 * Christophe Massiot <massiot@via.ecp.fr>
10 * Derk-Jan Hartman <hartman at videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #import "CompatibilityFixes.h"
28 #import "MainWindow.h"
30 #import "CoreInteraction.h"
31 #import "AudioEffects.h"
34 #import "controls.h" // TODO: remove me
36 #import "SideBarItem.h"
38 #import <vlc_playlist.h>
39 #import <vlc_aout_intf.h>
41 #import <vlc_strings.h>
42 #import <vlc_services_discovery.h>
43 #import <vlc_aout_intf.h>
45 #import "ControlsBar.h"
47 #import "VLCVoutWindowController.h"
50 @interface VLCMainWindow ()
51 - (void)resizePlaylistAfterCollapse;
52 - (void)makeSplitViewVisible;
53 - (void)makeSplitViewHidden;
58 @implementation VLCMainWindow
60 @synthesize fullscreen=b_fullscreen;
61 @synthesize nativeFullscreenMode=b_nativeFullscreenMode;
62 @synthesize fsPanel=o_fspanel;
64 static VLCMainWindow *_o_sharedInstance = nil;
66 + (VLCMainWindow *)sharedInstance
68 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
72 #pragma mark Initialization
76 if (_o_sharedInstance) {
78 return _o_sharedInstance;
80 _o_sharedInstance = [super init];
82 return _o_sharedInstance;
85 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
86 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
88 self = [super initWithContentRect:contentRect styleMask:styleMask
89 backing:backingType defer:flag];
90 _o_sharedInstance = self;
92 [[VLCMain sharedInstance] updateTogglePlaylistState];
97 - (BOOL)isEvent:(NSEvent *)o_event forKey:(const char *)keyString
102 key = config_GetPsz(VLCIntf, keyString);
103 o_key = [NSString stringWithFormat:@"%s", key];
106 unsigned int i_keyModifiers = [[VLCStringUtility sharedInstance] VLCModifiersToCocoa:o_key];
108 NSString * characters = [o_event charactersIgnoringModifiers];
109 if ([characters length] > 0) {
110 return [[characters lowercaseString] isEqualToString: [[VLCStringUtility sharedInstance] VLCKeyToString: o_key]] &&
111 (i_keyModifiers & NSShiftKeyMask) == ([o_event modifierFlags] & NSShiftKeyMask) &&
112 (i_keyModifiers & NSControlKeyMask) == ([o_event modifierFlags] & NSControlKeyMask) &&
113 (i_keyModifiers & NSAlternateKeyMask) == ([o_event modifierFlags] & NSAlternateKeyMask) &&
114 (i_keyModifiers & NSCommandKeyMask) == ([o_event modifierFlags] & NSCommandKeyMask);
119 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
122 // these are key events which should be handled by vlc core, but are attached to a main menu item
123 if (![self isEvent: o_event forKey: "key-vol-up"] &&
124 ![self isEvent: o_event forKey: "key-vol-down"] &&
125 ![self isEvent: o_event forKey: "key-vol-mute"]) {
126 /* We indeed want to prioritize some Cocoa key equivalent against libvlc,
127 so we perform the menu equivalent now. */
128 if ([[NSApp mainMenu] performKeyEquivalent:o_event])
134 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event force:b_force] ||
135 [(VLCControls *)[[VLCMain sharedInstance] controls] keyEvent:o_event];
140 if (b_dark_interface)
141 [o_color_backdrop release];
143 [[NSNotificationCenter defaultCenter] removeObserver: self];
144 [o_sidebaritems release];
151 BOOL b_splitviewShouldBeHidden = NO;
153 /* setup the styled interface */
154 b_nativeFullscreenMode = NO;
155 #ifdef MAC_OS_X_VERSION_10_7
156 if (!OSX_SNOW_LEOPARD)
157 b_nativeFullscreenMode = var_InheritBool(VLCIntf, "macosx-nativefullscreenmode");
159 t_hide_mouse_timer = nil;
160 [self useOptimizedDrawing: YES];
162 [[o_search_fld cell] setPlaceholderString: _NS("Search")];
163 [[o_search_fld cell] accessibilitySetOverrideValue:_NS("Enter a term to search the playlist. Results will be selected in the table.") forAttribute:NSAccessibilityDescriptionAttribute];
165 [o_dropzone_btn setTitle: _NS("Open media...")];
166 [[o_dropzone_btn cell] accessibilitySetOverrideValue:_NS("Click to open an advanced dialog to select the media to play. You can also drop files here to play.") forAttribute:NSAccessibilityDescriptionAttribute];
167 [o_dropzone_lbl setStringValue: _NS("Drop media here")];
169 [o_podcast_add_btn setTitle: _NS("Subscribe")];
170 [o_podcast_remove_btn setTitle: _NS("Unsubscribe")];
171 [o_podcast_subscribe_title_lbl setStringValue: _NS("Subscribe to a podcast")];
172 [o_podcast_subscribe_subtitle_lbl setStringValue: _NS("Enter URL of the podcast to subscribe to:")];
173 [o_podcast_subscribe_cancel_btn setTitle: _NS("Cancel")];
174 [o_podcast_subscribe_ok_btn setTitle: _NS("Subscribe")];
175 [o_podcast_unsubscribe_title_lbl setStringValue: _NS("Unsubscribe from a podcast")];
176 [o_podcast_unsubscribe_subtitle_lbl setStringValue: _NS("Select the podcast you would like to unsubscribe from:")];
177 [o_podcast_unsubscribe_ok_btn setTitle: _NS("Unsubscribe")];
178 [o_podcast_unsubscribe_cancel_btn setTitle: _NS("Cancel")];
180 /* interface builder action */
181 float f_threshold_height = f_min_video_height + [[o_controls_bar bottomBarView] frame].size.height;
182 if (b_dark_interface)
183 f_threshold_height += [o_titlebar_view frame].size.height;
184 if ([[self contentView] frame].size.height < f_threshold_height)
185 b_splitviewShouldBeHidden = YES;
187 [self setDelegate: self];
188 [self setExcludedFromWindowsMenu: YES];
189 [self setAcceptsMouseMovedEvents: YES];
190 // Set that here as IB seems to be buggy
191 if (b_dark_interface) {
192 [self setContentMinSize:NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
194 [self setContentMinSize:NSMakeSize(604., 288.)];
197 [self setTitle: _NS("VLC media player")];
199 b_dropzone_active = YES;
200 [o_dropzone_view setFrame: [o_playlist_table frame]];
201 [o_left_split_view setFrame: [o_sidebar_view frame]];
203 if (b_nativeFullscreenMode) {
204 [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
206 [o_titlebar_view setFullscreenButtonHidden: YES];
209 if (!OSX_SNOW_LEOPARD) {
210 /* the default small size of the search field is slightly different on Lion, let's work-around that */
212 frame = [o_search_fld frame];
213 frame.origin.y = frame.origin.y + 2.0;
214 frame.size.height = frame.size.height - 1.0;
215 [o_search_fld setFrame: frame];
218 /* create the sidebar */
219 o_sidebaritems = [[NSMutableArray alloc] init];
220 SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"];
221 SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"];
222 [playlistItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
223 SideBarItem *medialibraryItem = [SideBarItem itemWithTitle:_NS("Media Library") identifier:@"medialibrary"];
224 [medialibraryItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
225 SideBarItem *mycompItem = [SideBarItem itemWithTitle:_NS("MY COMPUTER") identifier:@"mycomputer"];
226 SideBarItem *devicesItem = [SideBarItem itemWithTitle:_NS("DEVICES") identifier:@"devices"];
227 SideBarItem *lanItem = [SideBarItem itemWithTitle:_NS("LOCAL NETWORK") identifier:@"localnetwork"];
228 SideBarItem *internetItem = [SideBarItem itemWithTitle:_NS("INTERNET") identifier:@"internet"];
230 /* SD subnodes, inspired by the Qt4 intf */
231 char **ppsz_longnames;
233 char **ppsz_names = vlc_sd_GetNames(pl_Get(VLCIntf), &ppsz_longnames, &p_categories);
235 msg_Err(VLCIntf, "no sd item found"); //TODO
236 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
237 int *p_category = p_categories;
238 NSMutableArray *internetItems = [[NSMutableArray alloc] init];
239 NSMutableArray *devicesItems = [[NSMutableArray alloc] init];
240 NSMutableArray *lanItems = [[NSMutableArray alloc] init];
241 NSMutableArray *mycompItems = [[NSMutableArray alloc] init];
242 NSString *o_identifier;
243 for (; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++) {
244 o_identifier = [NSString stringWithCString: *ppsz_name encoding: NSUTF8StringEncoding];
245 switch (*p_category) {
246 case SD_CAT_INTERNET:
247 [internetItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
248 if (!strncmp(*ppsz_name, "podcast", 7))
249 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-podcast"]];
251 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
252 [[internetItems lastObject] setSdtype: SD_CAT_INTERNET];
253 [[internetItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
256 [devicesItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
257 [[devicesItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
258 [[devicesItems lastObject] setSdtype: SD_CAT_DEVICES];
259 [[devicesItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
262 [lanItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
263 [[lanItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-local"]];
264 [[lanItems lastObject] setSdtype: SD_CAT_LAN];
265 [[lanItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
267 case SD_CAT_MYCOMPUTER:
268 [mycompItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
269 if (!strncmp(*ppsz_name, "video_dir", 9))
270 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-movie"]];
271 else if (!strncmp(*ppsz_name, "audio_dir", 9))
272 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-music"]];
273 else if (!strncmp(*ppsz_name, "picture_dir", 11))
274 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-pictures"]];
276 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
277 [[mycompItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
278 [[mycompItems lastObject] setSdtype: SD_CAT_MYCOMPUTER];
281 msg_Warn(VLCIntf, "unknown SD type found, skipping (%s)", *ppsz_name);
286 free(*ppsz_longname);
288 [mycompItem setChildren: [NSArray arrayWithArray: mycompItems]];
289 [devicesItem setChildren: [NSArray arrayWithArray: devicesItems]];
290 [lanItem setChildren: [NSArray arrayWithArray: lanItems]];
291 [internetItem setChildren: [NSArray arrayWithArray: internetItems]];
292 [mycompItems release];
293 [devicesItems release];
295 [internetItems release];
297 free(ppsz_longnames);
300 [libraryItem setChildren: [NSArray arrayWithObjects: playlistItem, medialibraryItem, nil]];
301 [o_sidebaritems addObject: libraryItem];
302 if ([mycompItem hasChildren])
303 [o_sidebaritems addObject: mycompItem];
304 if ([devicesItem hasChildren])
305 [o_sidebaritems addObject: devicesItem];
306 if ([lanItem hasChildren])
307 [o_sidebaritems addObject: lanItem];
308 if ([internetItem hasChildren])
309 [o_sidebaritems addObject: internetItem];
311 [o_sidebar_view reloadData];
312 [o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
313 [o_sidebar_view setDropItem:playlistItem dropChildIndex:NSOutlineViewDropOnItemIndex];
314 [o_sidebar_view registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
316 [o_sidebar_view setAutosaveName:@"mainwindow-sidebar"];
317 [(PXSourceList *)o_sidebar_view setDataSource:self];
318 [o_sidebar_view setDelegate:self];
319 [o_sidebar_view setAutosaveExpandedItems:YES];
321 [o_sidebar_view expandItem: libraryItem expandChildren: YES];
323 /* make sure we display the desired default appearance when VLC launches for the first time */
324 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
325 if (![defaults objectForKey:@"VLCFirstRun"]) {
326 [defaults setObject:[NSDate date] forKey:@"VLCFirstRun"];
328 NSUInteger i_sidebaritem_count = [o_sidebaritems count];
329 for (NSUInteger x = 0; x < i_sidebaritem_count; x++)
330 [o_sidebar_view expandItem: [o_sidebaritems objectAtIndex: x] expandChildren: YES];
333 if (b_dark_interface) {
334 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidResizeNotification object: nil];
335 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidMoveNotification object: nil];
337 [self setBackgroundColor: [NSColor clearColor]];
338 [self setOpaque: NO];
340 [self setHasShadow:NO];
341 [self setHasShadow:YES];
343 NSRect winrect = [self frame];
344 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
346 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
347 winrect.size.width, f_titleBarHeight)];
348 [[self contentView] addSubview: o_titlebar_view positioned: NSWindowAbove relativeTo: o_split_view];
350 if (winrect.size.height > 100) {
351 [self setFrame: winrect display:YES animate:YES];
352 previousSavedFrame = winrect;
355 winrect = [o_split_view frame];
356 winrect.size.height = winrect.size.height - f_titleBarHeight;
357 [o_split_view setFrame: winrect];
358 [o_video_view setFrame: winrect];
360 o_color_backdrop = [[VLCColorView alloc] initWithFrame: [o_split_view frame]];
361 [[self contentView] addSubview: o_color_backdrop positioned: NSWindowBelow relativeTo: o_split_view];
362 [o_color_backdrop setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
365 [o_video_view setFrame: [o_split_view frame]];
366 [o_playlist_table setBorderType: NSNoBorder];
367 [o_sidebar_scrollview setBorderType: NSNoBorder];
370 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillClose:) name: NSWindowWillCloseNotification object: nil];
371 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillMiniaturize:) name: NSWindowWillMiniaturizeNotification object:nil];
372 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
374 [o_split_view setAutosaveName:@"10thanniversary-splitview"];
375 if (b_splitviewShouldBeHidden) {
376 [self hideSplitView];
377 i_lastSplitViewHeight = 300;
380 /* sanity check for the window size */
381 NSRect frame = [self frame];
382 NSSize screenSize = [[self screen] frame].size;
383 if (screenSize.width <= frame.size.width || screenSize.height <= frame.size.height) {
384 nativeVideoSize = screenSize;
391 - (VLCMainWindowControlsBar *)controlsBar;
393 return (VLCMainWindowControlsBar *)o_controls_bar;
396 - (void)resizePlaylistAfterCollapse
399 plrect = [o_playlist_table frame];
400 plrect.size.height = i_lastSplitViewHeight - 20.0; // actual pl top bar height, which differs from its frame
401 [[o_playlist_table animator] setFrame: plrect];
403 NSRect rightSplitRect;
404 rightSplitRect = [o_right_split_view frame];
405 plrect = [o_dropzone_box frame];
406 plrect.origin.x = (rightSplitRect.size.width - plrect.size.width) / 2;
407 plrect.origin.y = (rightSplitRect.size.height - plrect.size.height) / 2;
408 [[o_dropzone_box animator] setFrame: plrect];
411 - (void)makeSplitViewVisible
413 if (b_dark_interface)
414 [self setContentMinSize: NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
416 [self setContentMinSize: NSMakeSize(604., 288.)];
418 NSRect old_frame = [self frame];
419 float newHeight = [self minSize].height;
420 if (old_frame.size.height < newHeight) {
421 NSRect new_frame = old_frame;
422 new_frame.origin.y = old_frame.origin.y + old_frame.size.height - newHeight;
423 new_frame.size.height = newHeight;
425 [[self animator] setFrame: new_frame display: YES animate: YES];
428 [o_video_view setHidden: YES];
429 [o_split_view setHidden: NO];
430 [self makeFirstResponder: nil];
434 - (void)makeSplitViewHidden
436 if (b_dark_interface)
437 [self setContentMinSize: NSMakeSize(604., f_min_video_height + [o_titlebar_view frame].size.height)];
439 [self setContentMinSize: NSMakeSize(604., f_min_video_height)];
441 [o_split_view setHidden: YES];
442 [o_video_view setHidden: NO];
444 if ([[o_video_view subviews] count] > 0)
445 [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
448 // only exception for an controls bar button action
449 - (IBAction)togglePlaylist:(id)sender
451 if (![self isVisible] && sender != nil) {
452 [self makeKeyAndOrderFront: sender];
456 BOOL b_activeVideo = [[VLCMain sharedInstance] activeVideoPlayback];
457 BOOL b_restored = NO;
459 // TODO: implement toggle playlist in this situation (triggerd via menu item).
460 // but for now we block this case, to avoid displaying only the half
461 if (b_nativeFullscreenMode && b_fullscreen && b_activeVideo && sender != nil)
464 if (b_dropzone_active && ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0) {
469 if (!(b_nativeFullscreenMode && b_fullscreen) && !b_splitview_removed && ((([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0 && b_activeVideo)
470 || (b_nonembedded && sender != nil)
471 || (!b_activeVideo && sender != nil)
472 || b_minimized_view))
473 [self hideSplitView];
475 if (b_splitview_removed) {
476 if (!b_nonembedded || (sender != nil && b_nonembedded))
477 [self showSplitView];
480 b_minimized_view = YES;
482 b_minimized_view = NO;
488 if (!b_nonembedded) {
489 if (([o_video_view isHidden] && b_activeVideo) || b_restored || (b_activeVideo && sender == nil))
490 [self makeSplitViewHidden];
492 [self makeSplitViewVisible];
494 [o_split_view setHidden: NO];
495 [o_playlist_table setHidden: NO];
496 [o_video_view setHidden: !b_activeVideo];
497 if (b_activeVideo && [[o_video_view subviews] count] > 0)
498 [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
503 - (IBAction)dropzoneButtonAction:(id)sender
505 [[[VLCMain sharedInstance] open] openFileGeneric];
509 #pragma mark overwritten default functionality
511 - (void)windowResizedOrMoved:(NSNotification *)notification
513 [self saveFrameUsingName: [self frameAutosaveName]];
516 - (void)applicationWillTerminate:(NSNotification *)notification
518 [self saveFrameUsingName: [self frameAutosaveName]];
522 - (void)someWindowWillClose:(NSNotification *)notification
524 id obj = [notification object];
526 if ([obj class] == [VLCVideoWindowCommon class] || [obj class] == [VLCDetachedVideoWindow class] || ([obj class] == [VLCMainWindow class] && !b_nonembedded)) {
527 if ([[VLCMain sharedInstance] activeVideoPlayback])
528 [[VLCCoreInteraction sharedInstance] stop];
532 - (void)someWindowWillMiniaturize:(NSNotification *)notification
534 if (config_GetInt(VLCIntf, "macosx-pause-minimized")) {
535 id obj = [notification object];
537 if ([obj class] == [VLCVideoWindowCommon class] || [obj class] == [VLCDetachedVideoWindow class] || ([obj class] == [VLCMainWindow class] && !b_nonembedded)) {
538 if ([[VLCMain sharedInstance] activeVideoPlayback])
539 [[VLCCoreInteraction sharedInstance] pause];
545 #pragma mark Update interface and respond to foreign events
548 b_dropzone_active = YES;
549 [o_right_split_view addSubview: o_dropzone_view positioned:NSWindowAbove relativeTo:o_playlist_table];
550 [o_dropzone_view setFrame: [o_playlist_table frame]];
551 [[o_playlist_table animator] setHidden:YES];
556 b_dropzone_active = NO;
557 [o_dropzone_view removeFromSuperview];
558 [[o_playlist_table animator] setHidden: NO];
561 - (void)hideSplitView
563 NSRect winrect = [self frame];
564 i_lastSplitViewHeight = [o_split_view frame].size.height;
565 winrect.size.height = winrect.size.height - i_lastSplitViewHeight;
566 winrect.origin.y = winrect.origin.y + i_lastSplitViewHeight;
567 [self setFrame: winrect display: YES animate: YES];
568 [self performSelector:@selector(hideDropZone) withObject:nil afterDelay:0.1];
569 if (b_dark_interface) {
570 [self setContentMinSize: NSMakeSize(604., [[o_controls_bar bottomBarView] frame].size.height + [o_titlebar_view frame].size.height)];
571 [self setContentMaxSize: NSMakeSize(FLT_MAX, [[o_controls_bar bottomBarView] frame].size.height + [o_titlebar_view frame].size.height)];
573 [self setContentMinSize: NSMakeSize(604., [[o_controls_bar bottomBarView] frame].size.height)];
574 [self setContentMaxSize: NSMakeSize(FLT_MAX, [[o_controls_bar bottomBarView] frame].size.height)];
577 b_splitview_removed = YES;
580 - (void)showSplitView
583 if (b_dark_interface)
584 [self setContentMinSize:NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
586 [self setContentMinSize:NSMakeSize(604., 288.)];
587 [self setContentMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
590 winrect = [self frame];
591 winrect.size.height = winrect.size.height + i_lastSplitViewHeight;
592 winrect.origin.y = winrect.origin.y - i_lastSplitViewHeight;
593 [self setFrame: winrect display: YES animate: YES];
595 [self performSelector:@selector(resizePlaylistAfterCollapse) withObject: nil afterDelay:0.75];
597 b_splitview_removed = NO;
600 - (void)updateTimeSlider
602 [o_controls_bar updateTimeSlider];
603 [[self controlsBar] updatePosAndTimeInFSPanel:o_fspanel];
605 [[[VLCMain sharedInstance] voutController] updateWindowsControlsBarWithSelector:@selector(updateTimeSlider)];
610 input_thread_t * p_input;
611 p_input = pl_CurrentInput(VLCIntf);
614 char *format = var_InheritString(VLCIntf, "input-title-format");
615 char *formated = str_format_meta(pl_Get(VLCIntf), format);
617 aString = [NSString stringWithUTF8String:formated];
620 char *uri = input_item_GetURI(input_GetItem(p_input));
622 NSURL * o_url = [NSURL URLWithString: [NSString stringWithUTF8String: uri]];
623 if ([o_url isFileURL]) {
624 [self setRepresentedURL: o_url];
625 [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
626 [o_window setRepresentedURL:o_url];
629 [self setRepresentedURL: nil];
630 [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
631 [o_window setRepresentedURL:nil];
636 if ([aString isEqualToString:@""]) {
637 if ([o_url isFileURL])
638 aString = [[NSFileManager defaultManager] displayNameAtPath: [o_url path]];
640 aString = [o_url absoluteString];
643 [self setTitle: aString];
644 [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
645 [o_window setTitle:aString];
648 [o_fspanel setStreamTitle: aString];
649 vlc_object_release(p_input);
651 [self setTitle: _NS("VLC media player")];
652 [self setRepresentedURL: nil];
658 [o_controls_bar updateControls];
659 [[[VLCMain sharedInstance] voutController] updateWindowsControlsBarWithSelector:@selector(updateControls)];
661 bool b_seekable = false;
663 playlist_t * p_playlist = pl_Get(VLCIntf);
664 input_thread_t * p_input = playlist_CurrentInput(p_playlist);
666 /* seekable streams */
667 b_seekable = var_GetBool(p_input, "can-seek");
669 vlc_object_release(p_input);
672 [self updateTimeSlider];
673 if ([o_fspanel respondsToSelector:@selector(setSeekable:)])
674 [o_fspanel setSeekable: b_seekable];
677 if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot] != p_playlist->p_local_category || p_playlist->p_local_category->i_children > 0)
682 [o_sidebar_view setNeedsDisplay:YES];
687 [o_controls_bar setPause];
688 [o_fspanel setPause];
690 [[[VLCMain sharedInstance] voutController] updateWindowsControlsBarWithSelector:@selector(setPause)];
695 [o_controls_bar setPlay];
698 [[[VLCMain sharedInstance] voutController] updateWindowsControlsBarWithSelector:@selector(setPlay)];
702 - (void)updateVolumeSlider
704 [[self controlsBar] updateVolumeSlider];
705 [o_fspanel setVolumeLevel: [[VLCCoreInteraction sharedInstance] volume]];
709 #pragma mark Video Output handling
711 - (VLCVoutView *)setupVout:(vout_window_t *)p_wnd
713 BOOL b_video_deco = var_InheritBool(VLCIntf, "video-deco");
714 BOOL b_video_wallpaper = var_InheritBool(VLCIntf, "video-wallpaper");
715 VLCVoutView *o_vout_view;
716 VLCVideoWindowCommon *o_new_video_window;
718 // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
719 if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
720 // b_video_wallpaper is priorized over !b_video_deco
722 msg_Dbg(VLCIntf, "Creating background / blank window");
723 NSScreen *screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
725 screen = [self screen];
728 if (b_video_wallpaper)
729 window_rect = [screen frame];
731 window_rect = [self frame];
733 NSUInteger mask = NSBorderlessWindowMask;
734 if (!OSX_SNOW_LEOPARD && !b_video_deco)
735 mask |= NSResizableWindowMask;
737 BOOL b_no_video_deco_only = !b_video_wallpaper;
738 o_new_video_window = [[VLCVideoWindowCommon alloc] initWithContentRect:window_rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
739 [o_new_video_window setDelegate:o_new_video_window];
741 if (b_video_wallpaper)
742 [o_new_video_window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey) + 1];
744 [o_new_video_window setBackgroundColor: [NSColor blackColor]];
745 [o_new_video_window setCanBecomeKeyWindow: !b_video_wallpaper];
746 [o_new_video_window setCanBecomeMainWindow: !b_video_wallpaper];
747 [o_new_video_window setAcceptsMouseMovedEvents: !b_video_wallpaper];
748 [o_new_video_window setMovableByWindowBackground: !b_video_wallpaper];
749 [o_new_video_window useOptimizedDrawing: YES];
751 o_vout_view = [[VLCVoutView alloc] initWithFrame:[[o_new_video_window contentView] bounds]];
752 [o_vout_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
753 [[o_new_video_window contentView] addSubview:o_vout_view positioned:NSWindowAbove relativeTo:nil];
754 [o_new_video_window setVideoView:o_vout_view];
757 if (b_video_wallpaper)
758 [o_new_video_window orderBack:nil];
760 [o_new_video_window center];
761 [o_new_video_window setFrameAutosaveName:@"extra-videowindow"];
762 [o_new_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
767 if (var_InheritBool(VLCIntf, "embedded-video") || b_nativeFullscreenMode) {
768 o_vout_view = [o_video_view retain];
769 o_new_video_window = self;
772 NSWindowController *o_controller = [[NSWindowController alloc] initWithWindowNibName:@"DetachedVideoWindow"];
773 [o_controller loadWindow];
774 o_new_video_window = [(VLCDetachedVideoWindow *)[o_controller window] retain];
775 [o_controller release];
777 [o_new_video_window setDelegate: o_new_video_window];
778 [o_new_video_window setLevel:NSNormalWindowLevel];
779 [o_new_video_window useOptimizedDrawing: YES];
780 o_vout_view = [[o_new_video_window videoView] retain];
785 if (!b_video_wallpaper) {
786 [o_new_video_window makeKeyAndOrderFront: self];
788 vout_thread_t *p_vout = getVout();
790 if (var_GetBool(p_vout, "video-on-top"))
791 [o_new_video_window setLevel: NSStatusWindowLevel];
793 [o_new_video_window setLevel: NSNormalWindowLevel];
794 vlc_object_release(p_vout);
798 [o_new_video_window setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
799 [[[VLCMain sharedInstance] voutController] addVout:o_new_video_window forDisplay:p_wnd];
802 // event occurs before window is created, so call again
803 [[VLCMain sharedInstance] playbackStatusUpdated];
806 return [o_vout_view autorelease];
809 - (void)setVideoplayEnabled
811 BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback];
813 if (b_videoPlayback) {
814 frameBeforePlayback = [self frame];
816 if (!b_nonembedded && !b_fullscreen)
817 [[self animator] setFrame:frameBeforePlayback display:YES];
819 [self makeFirstResponder: nil];
821 if ([self level] != NSNormalWindowLevel)
822 [self setLevel: NSNormalWindowLevel];
824 // restore alpha value to 1 for the case that macosx-opaqueness is set to < 1
825 [self setAlphaValue:1.0];
828 if (b_nativeFullscreenMode) {
829 if ([NSApp presentationOptions] & NSApplicationPresentationFullScreen)
830 [[o_controls_bar bottomBarView] setHidden: b_videoPlayback];
832 [[o_controls_bar bottomBarView] setHidden: NO];
833 if (b_videoPlayback && b_fullscreen)
834 [o_fspanel setActive: nil];
835 if (!b_videoPlayback)
836 [o_fspanel setNonActive: nil];
840 // Called automatically if window's acceptsMouseMovedEvents property is true
841 - (void)mouseMoved:(NSEvent *)theEvent
844 [self recreateHideMouseTimer];
846 [super mouseMoved: theEvent];
849 - (void)recreateHideMouseTimer
851 if (t_hide_mouse_timer != nil) {
852 [t_hide_mouse_timer invalidate];
853 [t_hide_mouse_timer release];
856 t_hide_mouse_timer = [NSTimer scheduledTimerWithTimeInterval:2
858 selector:@selector(hideMouseCursor:)
861 [t_hide_mouse_timer retain];
864 // NSTimer selectors require this function signature as per Apple's docs
865 - (void)hideMouseCursor:(NSTimer *)timer
867 [NSCursor setHiddenUntilMouseMoves: YES];
871 #pragma mark Fullscreen support
872 - (void)showFullscreenController
874 if (b_fullscreen && [[VLCMain sharedInstance] activeVideoPlayback])
878 - (void)makeKeyAndOrderFront: (id)sender
881 * when we exit fullscreen and fade out, we may endup in
882 * having a window that is faded. We can't have it fade in unless we
885 if (!b_window_is_invisible) {
886 /* Make sure we don't do it too much */
887 [super makeKeyAndOrderFront: sender];
891 [super setAlphaValue:0.0f];
892 [super makeKeyAndOrderFront: sender];
894 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
895 [dict setObject:self forKey:NSViewAnimationTargetKey];
896 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
898 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
901 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
902 [o_makekey_anim setDuration: 0.1];
903 [o_makekey_anim setFrameRate: 30];
904 [o_makekey_anim setDelegate: self];
906 [o_makekey_anim startAnimation];
907 b_window_is_invisible = NO;
909 /* fullscreenAnimation will be unlocked when animation ends */
913 #pragma mark Lion native fullscreen handling
914 - (void)windowWillEnterFullScreen:(NSNotification *)notification
916 // workaround, see #6668
917 [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
919 var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
921 vout_thread_t *p_vout = getVout();
923 var_SetBool(p_vout, "fullscreen", true);
924 vlc_object_release(p_vout);
927 [o_video_view setFrame: [[self contentView] frame]];
930 [self recreateHideMouseTimer];
931 i_originalLevel = [self level];
932 [self setLevel:NSNormalWindowLevel];
934 if (b_dark_interface) {
935 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
938 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
939 winrect = [self frame];
941 winrect.size.height = winrect.size.height - f_titleBarHeight;
942 [self setFrame: winrect display:NO animate:NO];
943 winrect = [o_split_view frame];
944 winrect.size.height = winrect.size.height + f_titleBarHeight;
945 [o_split_view setFrame: winrect];
948 if ([[VLCMain sharedInstance] activeVideoPlayback])
949 [[o_controls_bar bottomBarView] setHidden: YES];
951 [self setMovableByWindowBackground: NO];
954 - (void)windowDidEnterFullScreen:(NSNotification *)notification
956 // Indeed, we somehow can have an "inactive" fullscreen (but a visible window!).
957 // But this creates some problems when leaving fs over remote intfs, so activate app here.
958 [NSApp activateIgnoringOtherApps:YES];
960 [o_fspanel setVoutWasUpdated: (int)[[self screen] displayID]];
961 [o_fspanel setActive: nil];
964 - (void)windowWillExitFullScreen:(NSNotification *)notification
967 var_SetBool(pl_Get(VLCIntf), "fullscreen", false);
969 vout_thread_t *p_vout = getVout();
971 var_SetBool(p_vout, "fullscreen", false);
972 vlc_object_release(p_vout);
975 [o_video_view setFrame: [o_split_view frame]];
976 [NSCursor setHiddenUntilMouseMoves: NO];
977 [o_fspanel setNonActive: nil];
978 [self setLevel:i_originalLevel];
981 if (b_dark_interface) {
983 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
984 winrect = [self frame];
986 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
987 winrect.size.width, f_titleBarHeight)];
988 [[self contentView] addSubview: o_titlebar_view];
990 winrect.size.height = winrect.size.height + f_titleBarHeight;
991 [self setFrame: winrect display:NO animate:NO];
992 winrect = [o_split_view frame];
993 winrect.size.height = winrect.size.height - f_titleBarHeight;
994 [o_split_view setFrame: winrect];
995 [o_video_view setFrame: winrect];
998 if ([[VLCMain sharedInstance] activeVideoPlayback])
999 [[o_controls_bar bottomBarView] setHidden: NO];
1001 [self setMovableByWindowBackground: YES];
1005 #pragma mark split view delegate
1006 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
1008 if (dividerIndex == 0)
1014 - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
1016 if (dividerIndex == 0)
1022 - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview
1024 return ([subview isEqual:o_left_split_view]);
1027 - (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)subview
1029 if ([subview isEqual:o_left_split_view])
1035 #pragma mark Side Bar Data handling
1036 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
1037 - (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item
1039 //Works the same way as the NSOutlineView data source: `nil` means a parent item
1041 return [o_sidebaritems count];
1043 return [[item children] count];
1047 - (id)sourceList:(PXSourceList*)aSourceList child:(NSUInteger)index ofItem:(id)item
1049 //Works the same way as the NSOutlineView data source: `nil` means a parent item
1051 return [o_sidebaritems objectAtIndex:index];
1053 return [[item children] objectAtIndex:index];
1057 - (id)sourceList:(PXSourceList*)aSourceList objectValueForItem:(id)item
1059 return [item title];
1062 - (void)sourceList:(PXSourceList*)aSourceList setObjectValue:(id)object forItem:(id)item
1064 [item setTitle:object];
1067 - (BOOL)sourceList:(PXSourceList*)aSourceList isItemExpandable:(id)item
1069 return [item hasChildren];
1073 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasBadge:(id)item
1075 if ([[item identifier] isEqualToString: @"playlist"] || [[item identifier] isEqualToString: @"medialibrary"])
1078 return [item hasBadge];
1082 - (NSInteger)sourceList:(PXSourceList*)aSourceList badgeValueForItem:(id)item
1084 playlist_t * p_playlist = pl_Get(VLCIntf);
1085 NSInteger i_playlist_size;
1087 if ([[item identifier] isEqualToString: @"playlist"]) {
1089 i_playlist_size = p_playlist->p_local_category->i_children;
1092 return i_playlist_size;
1094 if ([[item identifier] isEqualToString: @"medialibrary"]) {
1096 i_playlist_size = p_playlist->p_ml_category->i_children;
1099 return i_playlist_size;
1102 return [item badgeValue];
1106 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasIcon:(id)item
1108 return [item hasIcon];
1112 - (NSImage*)sourceList:(PXSourceList*)aSourceList iconForItem:(id)item
1117 - (NSMenu*)sourceList:(PXSourceList*)aSourceList menuForEvent:(NSEvent*)theEvent item:(id)item
1119 if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)) {
1122 if ([item sdtype] > 0)
1124 m = [[NSMenu alloc] init];
1125 playlist_t * p_playlist = pl_Get(VLCIntf);
1126 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [[item identifier] UTF8String]);
1128 [m addItemWithTitle:_NS("Enable") action:@selector(sdmenuhandler:) keyEquivalent:@""];
1130 [m addItemWithTitle:_NS("Disable") action:@selector(sdmenuhandler:) keyEquivalent:@""];
1131 [[m itemAtIndex:0] setRepresentedObject: [item identifier]];
1133 return [m autorelease];
1140 - (IBAction)sdmenuhandler:(id)sender
1142 NSString * identifier = [sender representedObject];
1143 if ([identifier length] > 0 && ![identifier isEqualToString:@"lua{sd='freebox',longname='Freebox TV'}"]) {
1144 playlist_t * p_playlist = pl_Get(VLCIntf);
1145 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [identifier UTF8String]);
1148 playlist_ServicesDiscoveryAdd(p_playlist, [identifier UTF8String]);
1150 playlist_ServicesDiscoveryRemove(p_playlist, [identifier UTF8String]);
1155 #pragma mark Side Bar Delegate Methods
1156 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
1157 - (BOOL)sourceList:(PXSourceList*)aSourceList isGroupAlwaysExpanded:(id)group
1159 if ([[group identifier] isEqualToString:@"library"])
1165 - (void)sourceListSelectionDidChange:(NSNotification *)notification
1167 playlist_t * p_playlist = pl_Get(VLCIntf);
1169 NSIndexSet *selectedIndexes = [o_sidebar_view selectedRowIndexes];
1170 id item = [o_sidebar_view itemAtRow:[selectedIndexes firstIndex]];
1173 //Set the label text to represent the new selection
1174 if ([item sdtype] > -1 && [[item identifier] length] > 0) {
1175 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [[item identifier] UTF8String]);
1177 playlist_ServicesDiscoveryAdd(p_playlist, [[item identifier] UTF8String]);
1180 [o_chosen_category_lbl setStringValue:[item title]];
1182 if ([[item identifier] isEqualToString:@"playlist"]) {
1183 [[[VLCMain sharedInstance] playlist] setPlaylistRoot:p_playlist->p_local_category];
1184 } else if ([[item identifier] isEqualToString:@"medialibrary"]) {
1185 [[[VLCMain sharedInstance] playlist] setPlaylistRoot:p_playlist->p_ml_category];
1187 playlist_item_t * pl_item;
1189 pl_item = playlist_ChildSearchName(p_playlist->p_root, [[item untranslatedTitle] UTF8String]);
1191 [[[VLCMain sharedInstance] playlist] setPlaylistRoot: pl_item];
1195 if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot] != p_playlist->p_local_category || p_playlist->p_local_category->i_children > 0)
1196 [self hideDropZone];
1198 [self showDropZone];
1201 if ([[item identifier] isEqualToString:@"podcast{longname=\"Podcasts\"}"])
1202 [self showPodcastControls];
1204 [self hidePodcastControls];
1207 - (NSDragOperation)sourceList:(PXSourceList *)aSourceList validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1209 if ([[item identifier] isEqualToString:@"playlist"] || [[item identifier] isEqualToString:@"medialibrary"]) {
1210 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1211 if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] || [[o_pasteboard types] containsObject: NSFilenamesPboardType])
1212 return NSDragOperationGeneric;
1214 return NSDragOperationNone;
1217 - (BOOL)sourceList:(PXSourceList *)aSourceList acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1219 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1221 playlist_t * p_playlist = pl_Get(VLCIntf);
1222 playlist_item_t *p_node;
1224 if ([[item identifier] isEqualToString:@"playlist"])
1225 p_node = p_playlist->p_local_category;
1227 p_node = p_playlist->p_ml_category;
1229 if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
1230 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1231 NSUInteger count = [o_values count];
1232 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1234 for(NSUInteger i = 0; i < count; i++) {
1235 NSDictionary *o_dic;
1236 char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
1240 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1244 [o_array addObject: o_dic];
1247 [[[VLCMain sharedInstance] playlist] appendNodeArray:o_array inNode: p_node atPos:-1 enqueue:YES];
1250 else if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
1251 NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
1253 NSUInteger count = [array count];
1254 playlist_item_t * p_item = NULL;
1257 for(NSUInteger i = 0; i < count; i++) {
1258 p_item = [[array objectAtIndex:i] pointerValue];
1259 if (!p_item) continue;
1260 playlist_NodeAddCopy(p_playlist, p_item, p_node, PLAYLIST_END);
1269 - (id)sourceList:(PXSourceList *)aSourceList persistentObjectForItem:(id)item
1271 return [item identifier];
1274 - (id)sourceList:(PXSourceList *)aSourceList itemForPersistentObject:(id)object
1276 /* the following code assumes for sakes of simplicity that only the top level
1277 * items are allowed to have children */
1279 NSArray * array = [NSArray arrayWithArray: o_sidebaritems]; // read-only arrays are noticebly faster
1280 NSUInteger count = [array count];
1284 for (NSUInteger x = 0; x < count; x++) {
1285 id item = [array objectAtIndex: x]; // save one objc selector call
1286 if ([[item identifier] isEqualToString:object])
1294 #pragma mark Podcast
1296 - (IBAction)addPodcast:(id)sender
1298 [NSApp beginSheet:o_podcast_subscribe_window modalForWindow:self modalDelegate:self didEndSelector:NULL contextInfo:nil];
1301 - (IBAction)addPodcastWindowAction:(id)sender
1303 [o_podcast_subscribe_window orderOut:sender];
1304 [NSApp endSheet: o_podcast_subscribe_window];
1306 if (sender == o_podcast_subscribe_ok_btn && [[o_podcast_subscribe_url_fld stringValue] length] > 0) {
1307 NSMutableString * podcastConf = [[NSMutableString alloc] init];
1308 if (config_GetPsz(VLCIntf, "podcast-urls") != NULL)
1309 [podcastConf appendFormat:@"%s|", config_GetPsz(VLCIntf, "podcast-urls")];
1311 [podcastConf appendString: [o_podcast_subscribe_url_fld stringValue]];
1312 config_PutPsz(VLCIntf, "podcast-urls", [podcastConf UTF8String]);
1314 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name(VLCIntf->p_libvlc, "podcast");
1316 var_SetString(p_obj, "podcast-urls", [podcastConf UTF8String]);
1317 vlc_object_release(p_obj);
1319 [podcastConf release];
1323 - (IBAction)removePodcast:(id)sender
1325 if (config_GetPsz(VLCIntf, "podcast-urls") != NULL) {
1326 [o_podcast_unsubscribe_pop removeAllItems];
1327 [o_podcast_unsubscribe_pop addItemsWithTitles:[[NSString stringWithUTF8String:config_GetPsz(VLCIntf, "podcast-urls")] componentsSeparatedByString:@"|"]];
1328 [NSApp beginSheet:o_podcast_unsubscribe_window modalForWindow:self modalDelegate:self didEndSelector:NULL contextInfo:nil];
1332 - (IBAction)removePodcastWindowAction:(id)sender
1334 [o_podcast_unsubscribe_window orderOut:sender];
1335 [NSApp endSheet: o_podcast_unsubscribe_window];
1337 if (sender == o_podcast_unsubscribe_ok_btn) {
1338 NSMutableArray * urls = [[NSMutableArray alloc] initWithArray:[[NSString stringWithUTF8String:config_GetPsz(VLCIntf, "podcast-urls")] componentsSeparatedByString:@"|"]];
1339 [urls removeObjectAtIndex: [o_podcast_unsubscribe_pop indexOfSelectedItem]];
1340 config_PutPsz(VLCIntf, "podcast-urls", [[urls componentsJoinedByString:@"|"] UTF8String]);
1343 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name(VLCIntf->p_libvlc, "podcast");
1345 var_SetString(p_obj, "podcast-urls", config_GetPsz(VLCIntf, "podcast-urls"));
1346 vlc_object_release(p_obj);
1349 /* reload the podcast module, since it won't update its list when removing podcasts */
1350 playlist_t * p_playlist = pl_Get(VLCIntf);
1351 if (playlist_IsServicesDiscoveryLoaded(p_playlist, "podcast{longname=\"Podcasts\"}")) {
1352 playlist_ServicesDiscoveryRemove(p_playlist, "podcast{longname=\"Podcasts\"}");
1353 playlist_ServicesDiscoveryAdd(p_playlist, "podcast{longname=\"Podcasts\"}");
1354 [o_playlist_table reloadData];
1360 - (void)showPodcastControls
1362 NSRect podcastViewDimensions = [o_podcast_view frame];
1363 NSRect rightSplitRect = [o_right_split_view frame];
1364 NSRect playlistTableRect = [o_playlist_table frame];
1366 podcastViewDimensions.size.width = rightSplitRect.size.width;
1367 podcastViewDimensions.origin.x = podcastViewDimensions.origin.y = .0;
1368 [o_podcast_view setFrame:podcastViewDimensions];
1370 playlistTableRect.origin.y = playlistTableRect.origin.y + podcastViewDimensions.size.height;
1371 playlistTableRect.size.height = playlistTableRect.size.height - podcastViewDimensions.size.height;
1372 [o_playlist_table setFrame:playlistTableRect];
1373 [o_playlist_table setNeedsDisplay:YES];
1375 [o_right_split_view addSubview: o_podcast_view positioned: NSWindowAbove relativeTo: o_right_split_view];
1376 b_podcastView_displayed = YES;
1379 - (void)hidePodcastControls
1381 if (b_podcastView_displayed) {
1382 NSRect podcastViewDimensions = [o_podcast_view frame];
1383 NSRect playlistTableRect = [o_playlist_table frame];
1385 playlistTableRect.origin.y = playlistTableRect.origin.y - podcastViewDimensions.size.height;
1386 playlistTableRect.size.height = playlistTableRect.size.height + podcastViewDimensions.size.height;
1388 [o_podcast_view removeFromSuperviewWithoutNeedingDisplay];
1389 [o_playlist_table setFrame: playlistTableRect];
1390 b_podcastView_displayed = NO;
1396 @implementation VLCDetachedVideoWindow
1398 - (void)awakeFromNib
1400 [self setAcceptsMouseMovedEvents: YES];
1402 if (b_dark_interface) {
1403 [self setBackgroundColor: [NSColor clearColor]];
1405 [self setOpaque: NO];
1407 [self setHasShadow:NO];
1408 [self setHasShadow:YES];
1410 NSRect winrect = [self frame];
1411 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
1413 [self setTitle: _NS("VLC media player")];
1414 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight, winrect.size.width, f_titleBarHeight)];
1415 [[self contentView] addSubview: o_titlebar_view positioned: NSWindowAbove relativeTo: nil];
1417 // native fs not supported with detached view yet
1418 [o_titlebar_view setFullscreenButtonHidden: YES];
1420 [self setBackgroundColor: [NSColor blackColor]];
1423 NSRect videoViewRect = [[self contentView] bounds];
1424 if (b_dark_interface)
1425 videoViewRect.size.height -= [o_titlebar_view frame].size.height;
1426 CGFloat f_bottomBarHeight = [[[self controlsBar] bottomBarView] frame].size.height;
1427 videoViewRect.size.height -= f_bottomBarHeight;
1428 videoViewRect.origin.y = f_bottomBarHeight;
1429 [o_video_view setFrame: videoViewRect];
1431 if (b_dark_interface) {
1432 o_color_backdrop = [[VLCColorView alloc] initWithFrame: [o_video_view frame]];
1433 [[self contentView] addSubview: o_color_backdrop positioned: NSWindowBelow relativeTo: o_video_view];
1434 [o_color_backdrop setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
1436 [self setContentMinSize: NSMakeSize(363., f_min_video_height + [[[self controlsBar] bottomBarView] frame].size.height + [o_titlebar_view frame].size.height)];
1438 [self setContentMinSize: NSMakeSize(363., f_min_video_height + [[[self controlsBar] bottomBarView] frame].size.height)];
1444 if (b_dark_interface)
1445 [o_color_backdrop release];