]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/MainWindow.m
macosx/CAS: simplify stream-out summary to something useful
[vlc] / modules / gui / macosx / MainWindow.m
index cdb2056c27243b2e5a68a691e1a974a9773f9c43..3550610a5a9e878733d409309b180b7f99ebb827 100644 (file)
 #import "SideBarItem.h"
 #import <math.h>
 #import <vlc_playlist.h>
-#import <vlc_aout_intf.h>
 #import <vlc_url.h>
 #import <vlc_strings.h>
 #import <vlc_services_discovery.h>
-#import <vlc_aout_intf.h>
 
 #import "ControlsBar.h"
 #import "VideoView.h"
 #import "VLCVoutWindowController.h"
 
 
-@interface VLCMainWindow ()
+@interface VLCMainWindow (Internal)
 - (void)resizePlaylistAfterCollapse;
 - (void)makeSplitViewVisible;
 - (void)makeSplitViewHidden;
-
+- (void)showPodcastControls;
+- (void)hidePodcastControls;
 @end
 
 
@@ -59,6 +58,7 @@
 
 @synthesize fullscreen=b_fullscreen;
 @synthesize nativeFullscreenMode=b_nativeFullscreenMode;
+@synthesize nonembedded=b_nonembedded;
 @synthesize fsPanel=o_fspanel;
 
 static VLCMainWindow *_o_sharedInstance = nil;
@@ -158,7 +158,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
 #endif
     t_hide_mouse_timer = nil;
     [self useOptimizedDrawing: YES];
-    
+
     [[o_search_fld cell] setPlaceholderString: _NS("Search")];
     [[o_search_fld cell] accessibilitySetOverrideValue:_NS("Enter a term to search the playlist. Results will be selected in the table.") forAttribute:NSAccessibilityDescriptionAttribute];
 
@@ -199,7 +199,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
     b_dropzone_active = YES;
     [o_dropzone_view setFrame: [o_playlist_table frame]];
     [o_left_split_view setFrame: [o_sidebar_view frame]];
-    
+
     if (b_nativeFullscreenMode) {
         [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
     } else {
@@ -360,7 +360,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
         o_color_backdrop = [[VLCColorView alloc] initWithFrame: [o_split_view frame]];
         [[self contentView] addSubview: o_color_backdrop positioned: NSWindowBelow relativeTo: o_split_view];
         [o_color_backdrop setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
-        
+
     } else {
         [o_video_view setFrame: [o_split_view frame]];
         [o_playlist_table setBorderType: NSNoBorder];
@@ -370,8 +370,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillClose:) name: NSWindowWillCloseNotification object: nil];
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillMiniaturize:) name: NSWindowWillMiniaturizeNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainSplitViewWillResizeSubviews:) name:NSSplitViewWillResizeSubviewsNotification object:o_split_view];
 
-    [o_split_view setAutosaveName:@"10thanniversary-splitview"];
     if (b_splitviewShouldBeHidden) {
         [self hideSplitView];
         i_lastSplitViewHeight = 300;
@@ -384,9 +384,20 @@ static VLCMainWindow *_o_sharedInstance = nil;
         nativeVideoSize = screenSize;
         [self resizeWindow];
     }
+
+    /* update fs button to reflect state for next startup */
+    if (var_InheritBool(pl_Get(VLCIntf), "fullscreen"))
+        [o_controls_bar setFullscreenState:YES];
+
+    /* restore split view */
+    i_lastLeftSplitViewWidth = 200;
+    /* trick NSSplitView implementation, which pretends to know better than us */
+    if (!config_GetInt(VLCIntf, "macosx-show-sidebar"))
+        [self performSelector:@selector(toggleLeftSubSplitView) withObject:nil afterDelay:0.05];
 }
 
 #pragma mark -
+#pragma mark appearance management
 
 - (VLCMainWindowControlsBar *)controlsBar;
 {
@@ -493,9 +504,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
         } else {
             [o_split_view setHidden: NO];
             [o_playlist_table setHidden: NO];
-            [o_video_view setHidden: !b_activeVideo];
-            if (b_activeVideo && [[o_video_view subviews] count] > 0)
-                [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
+            [o_video_view setHidden: YES];
         }
     }
 }
@@ -515,6 +524,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (void)applicationWillTerminate:(NSNotification *)notification
 {
+    config_PutInt(VLCIntf, "macosx-show-sidebar", ![o_split_view isSubviewCollapsed:o_left_split_view]);
+
     [self saveFrameUsingName: [self frameAutosaveName]];
 }
 
@@ -522,7 +533,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
 - (void)someWindowWillClose:(NSNotification *)notification
 {
     id obj = [notification object];
-    
+
     if ([obj class] == [VLCVideoWindowCommon class] || [obj class] == [VLCDetachedVideoWindow class] || ([obj class] == [VLCMainWindow class] && !b_nonembedded)) {
         if ([[VLCMain sharedInstance] activeVideoPlayback])
             [[VLCCoreInteraction sharedInstance] stop];
@@ -640,12 +651,18 @@ static VLCMainWindow *_o_sharedInstance = nil;
                 aString = [o_url absoluteString];
         }
 
-        [self setTitle: aString];
-        [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
-            [o_window setTitle:aString];
-        }];
+        if ([aString length] > 0) {
+            [self setTitle: aString];
+            [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
+                [o_window setTitle:aString];
+            }];
+
+            [o_fspanel setStreamTitle: aString];
+        } else {
+           [self setTitle: _NS("VLC media player")];
+            [self setRepresentedURL: nil];
+        }
 
-        [o_fspanel setStreamTitle: aString];
         vlc_object_release(p_input);
     } else {
         [self setTitle: _NS("VLC media player")];
@@ -708,114 +725,22 @@ static VLCMainWindow *_o_sharedInstance = nil;
 #pragma mark -
 #pragma mark Video Output handling
 
-- (VLCVoutView *)setupVout:(vout_window_t *)p_wnd
-{
-    BOOL b_video_deco = var_InheritBool(VLCIntf, "video-deco");
-    BOOL b_video_wallpaper = var_InheritBool(VLCIntf, "video-wallpaper");
-    VLCVoutView *o_vout_view;
-    VLCVideoWindowCommon *o_new_video_window;
-
-    // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
-    if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
-        // b_video_wallpaper is priorized over !b_video_deco
-
-        msg_Dbg(VLCIntf, "Creating background / blank window");
-        NSScreen *screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
-        if (!screen)
-            screen = [self screen];
-
-        NSRect window_rect;
-        if (b_video_wallpaper)
-            window_rect = [screen frame];
-        else
-            window_rect = [self frame];
-
-        NSUInteger mask = NSBorderlessWindowMask;
-        if (!OSX_SNOW_LEOPARD && !b_video_deco)
-            mask |= NSResizableWindowMask;
-
-        BOOL b_no_video_deco_only = !b_video_wallpaper;
-        o_new_video_window = [[VLCVideoWindowCommon alloc] initWithContentRect:window_rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
-        [o_new_video_window setDelegate:o_new_video_window];
-
-        if (b_video_wallpaper)
-            [o_new_video_window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey) + 1];
-
-        [o_new_video_window setBackgroundColor: [NSColor blackColor]];
-        [o_new_video_window setCanBecomeKeyWindow: !b_video_wallpaper];
-        [o_new_video_window setCanBecomeMainWindow: !b_video_wallpaper];
-        [o_new_video_window setAcceptsMouseMovedEvents: !b_video_wallpaper];
-        [o_new_video_window setMovableByWindowBackground: !b_video_wallpaper];
-        [o_new_video_window useOptimizedDrawing: YES];
-
-        o_vout_view = [[VLCVoutView alloc] initWithFrame:[[o_new_video_window contentView] bounds]];
-        [o_vout_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
-        [[o_new_video_window contentView] addSubview:o_vout_view positioned:NSWindowAbove relativeTo:nil];
-        [o_new_video_window setVideoView:o_vout_view];
-
-
-        if (b_video_wallpaper)
-            [o_new_video_window orderBack:nil];
-        else {
-            [o_new_video_window center];
-            [o_new_video_window setFrameAutosaveName:@"extra-videowindow"];
-            [o_new_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
-        }
-
-        b_nonembedded = YES;
-    } else {
-        if (var_InheritBool(VLCIntf, "embedded-video") || b_nativeFullscreenMode) {
-            o_vout_view = [o_video_view retain];
-            o_new_video_window = self;
-            b_nonembedded = NO;
-        } else {
-            NSWindowController *o_controller = [[NSWindowController alloc] initWithWindowNibName:@"DetachedVideoWindow"];
-            [o_controller loadWindow];
-            o_new_video_window = [(VLCDetachedVideoWindow *)[o_controller window] retain];
-            [o_controller release];
-
-            [o_new_video_window setDelegate: o_new_video_window];
-            [o_new_video_window setLevel:NSNormalWindowLevel];
-            [o_new_video_window useOptimizedDrawing: YES];
-            o_vout_view = [[o_new_video_window videoView] retain];
-            b_nonembedded = YES;
-        }
-    }
-
-    if (!b_video_wallpaper) {
-        [o_new_video_window makeKeyAndOrderFront: self];
-
-        vout_thread_t *p_vout = getVout();
-        if (p_vout) {
-            if (var_GetBool(p_vout, "video-on-top"))
-                [o_new_video_window setLevel: NSStatusWindowLevel];
-            else
-                [o_new_video_window setLevel: NSNormalWindowLevel];
-            vlc_object_release(p_vout);
-        }
-    }
-
-    [o_new_video_window setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
-    [[[VLCMain sharedInstance] voutController] addVout:o_new_video_window forDisplay:p_wnd];
-
-    if(b_nonembedded) {
-        // event occurs before window is created, so call again
-        [[VLCMain sharedInstance] playbackStatusUpdated];
-    }
-
-    return [o_vout_view autorelease];
-}
-
 - (void)setVideoplayEnabled
 {
     BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback];
 
     if (b_videoPlayback) {
-        frameBeforePlayback = [self frame];
+        if (!b_fullscreen)
+            frameBeforePlayback = [self frame];
     } else {
-        if (!b_nonembedded && !b_fullscreen)
+        if (!b_nonembedded && !b_fullscreen && frameBeforePlayback.size.width > 0 && frameBeforePlayback.size.height > 0)
             [[self animator] setFrame:frameBeforePlayback display:YES];
 
+        // update fs button to reflect state for next startup
+        if (var_InheritBool(pl_Get(VLCIntf), "fullscreen")) {
+            [o_controls_bar setFullscreenState:YES];
+        }
+
         [self makeFirstResponder: nil];
 
         if ([self level] != NSNormalWindowLevel)
@@ -867,8 +792,10 @@ static VLCMainWindow *_o_sharedInstance = nil;
     [NSCursor setHiddenUntilMouseMoves: YES];
 }
 
+
 #pragma mark -
 #pragma mark Fullscreen support
+
 - (void)showFullscreenController
 {
      if (b_fullscreen && [[VLCMain sharedInstance] activeVideoPlayback])
@@ -957,8 +884,17 @@ static VLCMainWindow *_o_sharedInstance = nil;
     // But this creates some problems when leaving fs over remote intfs, so activate app here.
     [NSApp activateIgnoringOtherApps:YES];
 
-    [o_fspanel setVoutWasUpdated: (int)[[self screen] displayID]];
+    [o_fspanel setVoutWasUpdated: self];
     [o_fspanel setActive: nil];
+
+    NSArray *subviews = [[self videoView] subviews];
+    NSUInteger count = [subviews count];
+
+    for (NSUInteger x = 0; x < count; x++) {
+        if ([[subviews objectAtIndex:x] respondsToSelector:@selector(reshape)])
+            [[subviews objectAtIndex:x] reshape];
+    }
+
 }
 
 - (void)windowWillExitFullScreen:(NSNotification *)notification
@@ -1031,6 +967,22 @@ static VLCMainWindow *_o_sharedInstance = nil;
     return YES;
 }
 
+- (void)mainSplitViewWillResizeSubviews:(id)object
+{
+    i_lastLeftSplitViewWidth = [o_left_split_view frame].size.width;
+    config_PutInt(VLCIntf, "macosx-show-sidebar", ![o_split_view isSubviewCollapsed:o_left_split_view]);
+    [[[VLCMain sharedInstance] mainMenu] updateSidebarMenuItem];
+}
+
+- (void)toggleLeftSubSplitView
+{
+    [o_split_view adjustSubviews];
+    if ([o_split_view isSubviewCollapsed:o_left_split_view])
+        [o_split_view setPosition:i_lastLeftSplitViewWidth ofDividerAtIndex:0];
+    else
+        [o_split_view setPosition:[o_split_view minPossiblePositionOfDividerAtIndex:0] ofDividerAtIndex:0];
+}
+
 #pragma mark -
 #pragma mark Side Bar Data handling
 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */