Commit e5940f08 authored by David Fuhrmann's avatar David Fuhrmann

macosx: manage main window with an NSWindowController, simplify VLCMain

The window controller ensures that all top-level objects of the
mainwindow xib are properly released.

This removes the last occurence of VLCMain in xib files, thus
awakeFromNib will not be called for this object anymore. The code
has been moved to initThis removes the last occurence of VLCMain in xib files, thus
awakeFromNib will not be called for this object anymore. The code
has been moved to init.
parent ffe31745
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8152.3" systemVersion="14F6a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14F25a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment version="1070" identifier="macosx"/>
<development version="5100" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8152.3"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="VLCMain">
<customObject id="-2" userLabel="File's Owner" customClass="NSWindowController">
<connections>
<outlet property="o_mainwindow" destination="21" id="5603"/>
<outlet property="window" destination="21" id="W4k-Fn-FoX"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="VLC media player" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="21" userLabel="Main Window" customClass="VLCMainWindow">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" topStrut="YES"/>
......@@ -38,7 +38,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<outlineView focusRingType="none" appearanceType="vibrantLight" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="sourceList" columnReordering="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" rowHeight="20" indentationPerLevel="14" autoresizesOutlineColumn="YES" outlineTableColumn="4717" id="4714" customClass="PXSourceList">
<rect key="frame" x="0.0" y="0.0" width="199" height="272"/>
<rect key="frame" x="0.0" y="0.0" width="199" height="20"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<size key="intercellSpacing" width="3" height="0.0"/>
<color key="backgroundColor" name="_sourceListBackgroundColor" catalog="System" colorSpace="catalog"/>
......@@ -62,11 +62,11 @@
</subviews>
<nil key="backgroundColor"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" appearanceType="vibrantLight" verticalHuggingPriority="750" horizontal="YES" id="4715">
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="4715">
<rect key="frame" x="-100" y="-100" width="212" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" appearanceType="vibrantLight" verticalHuggingPriority="750" horizontal="NO" id="4716">
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="4716">
<rect key="frame" x="198" y="17" width="15" height="539"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
......@@ -85,7 +85,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<outlineView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="reverseSequential" alternatingRowBackgroundColors="YES" autosaveColumns="NO" rowHeight="15" headerView="4373" indentationPerLevel="16" autoresizesOutlineColumn="YES" outlineTableColumn="4380" id="4376" customClass="VLCPlaylistView">
<rect key="frame" x="0.0" y="0.0" width="401" height="236"/>
<rect key="frame" x="0.0" y="0.0" width="21" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
......@@ -727,7 +727,7 @@ Gw
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="5322" id="5320">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="5321">
<items>
<menuItem title="Item 1" state="on" id="5322"/>
......
......@@ -156,7 +156,7 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
self = [super init];
if(self) {
o_main = o_mainObj;
var_AddCallback(pl_Get(VLCIntf), "input-current", InputThreadChanged, (__bridge void *)self);
var_AddCallback(pl_Get([o_mainObj intf]), "input-current", InputThreadChanged, (__bridge void *)self);
informInputChangedQueue = dispatch_queue_create("org.videolan.vlc.inputChangedQueue", DISPATCH_QUEUE_SERIAL);
......
......@@ -71,19 +71,18 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
@class VLCConvertAndSave;
@interface VLCMain : NSObject <NSWindowDelegate, NSApplicationDelegate>
{
IBOutlet VLCMainWindow *o_mainwindow; /* VLCMainWindow */
}
@property (readonly) VLCVoutWindowController* voutController;
@property (readonly) BOOL nativeFullscreenMode;
@property (nonatomic, readwrite) BOOL playlistUpdatedSelectorInQueue;
+ (VLCMain *)createInstanceWithIntf:(intf_thread_t *)intf;
+ (VLCMain *)sharedInstance;
+ (void)killInstance;
- (id)initWithIntf:(intf_thread_t *)intf;
- (intf_thread_t *)intf;
- (void)setIntf:(intf_thread_t *)p_mainintf;
- (VLCMainMenu *)mainMenu;
- (VLCMainWindow *)mainWindow;
......
......@@ -40,6 +40,8 @@
#include <vlc_keys.h>
#include <vlc_dialog.h>
#include <vlc_url.h>
#include <vlc_variables.h>
#include <unistd.h> /* execl() */
#import "CompatibilityFixes.h"
......@@ -82,10 +84,9 @@ int OpenIntf (vlc_object_t *p_this)
msg_Dbg(p_intf, "Starting macosx interface");
[VLCApplication sharedApplication];
[[VLCMain sharedInstance] setIntf: p_intf];
[VLCMain createInstanceWithIntf: p_intf];
[NSBundle loadNibNamed:@"MainMenu" owner:[[VLCMain sharedInstance] mainMenu]];
[NSBundle loadNibNamed:@"MainWindow" owner:[VLCMain sharedInstance]];
[[[VLCMain sharedInstance] mainWindow] makeKeyAndOrderFront:nil];
return VLC_SUCCESS;
......@@ -141,11 +142,12 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
BOOL launched;
int items_at_launch;
BOOL nib_main_loaded; /* main nibfile */
BOOL nib_about_loaded; /* about nibfile */
BOOL nib_coredialogs_loaded; /* CoreDialogs nibfile */
BOOL b_active_videoplayback;
NSWindowController *_mainWindowController;
VLCMainMenu *_mainmenu;
VLCPrefs *_prefs;
VLCSimplePrefs *_sprefs;
......@@ -178,11 +180,16 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
static VLCMain *sharedInstance = nil;
+ (VLCMain *)sharedInstance
{
return sharedInstance;
}
+ (VLCMain *)createInstanceWithIntf:(intf_thread_t *)intf;
{
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [VLCMain new];
sharedInstance = [[VLCMain alloc] initWithIntf:intf];
});
return sharedInstance;
......@@ -193,38 +200,57 @@ static VLCMain *sharedInstance = nil;
sharedInstance = nil;
}
- (id)init
- (id)initWithIntf:(intf_thread_t *)intf;
{
self = [super init];
if (self) {
p_intf = NULL;
p_intf = intf;
[VLCApplication sharedApplication].delegate = self;
_mainmenu = [[VLCMainMenu alloc] init];
_voutController = [[VLCVoutWindowController alloc] init];
_playlist = [[VLCPlaylist alloc] init];
_mainWindowController = [[NSWindowController alloc] initWithWindowNibName:@"MainWindow"];
var_Create(p_intf, "intf-change", VLC_VAR_BOOL);
_input_manager = [[VLCInputManager alloc] initWithMain:self];
var_AddCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, (__bridge void *)self);
var_AddCallback(p_intf->p_libvlc, "intf-show", ShowController, (__bridge void *)self);
playlist_t *p_playlist = pl_Get(p_intf);
if ([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen)
var_SetBool(p_playlist, "fullscreen", YES);
_nativeFullscreenMode = var_InheritBool(p_intf, "macosx-nativefullscreenmode");
if (var_InheritInteger(p_intf, "macosx-icon-change")) {
/* After day 354 of the year, the usual VLC cone is replaced by another cone
* wearing a Father Xmas hat.
* Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
*/
NSCalendar *gregorian =
[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
if (dayOfYear >= 354)
[[VLCApplication sharedApplication] setApplicationIconImage: [NSImage imageNamed:@"vlc-xmas"]];
}
/* announce our launch to a potential eyetv plugin */
[[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
object: @"VLCEyeTVSupport"
userInfo: NULL
deliverImmediately: YES];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"LiveUpdateTheMessagesPanel"];
[defaults registerDefaults:appDefaults];
_mainmenu = [[VLCMainMenu alloc] init];
_voutController = [[VLCVoutWindowController alloc] init];
_playlist = [[VLCPlaylist alloc] init];
}
return self;
}
- (void)setIntf: (intf_thread_t *)p_mainintf
{
p_intf = p_mainintf;
}
- (intf_thread_t *)intf
{
return p_intf;
......@@ -244,46 +270,6 @@ static VLCMain *sharedInstance = nil;
#endif
}
- (void)awakeFromNib
{
if (!p_intf) return;
var_Create(p_intf, "intf-change", VLC_VAR_BOOL);
/* Check if we already did this once */
if (nib_main_loaded)
return;
// TODO: take care of VLCIntf initialization order
_input_manager = [[VLCInputManager alloc] initWithMain:self];
var_AddCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, (__bridge void *)self);
var_AddCallback(p_intf->p_libvlc, "intf-show", ShowController, (__bridge void *)self);
playlist_t *p_playlist = pl_Get(p_intf);
if ([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen)
var_SetBool(p_playlist, "fullscreen", YES);
/* load our Shared Dialogs nib */
[NSBundle loadNibNamed:@"SharedDialogs" owner: NSApp];
_nativeFullscreenMode = var_InheritBool(p_intf, "macosx-nativefullscreenmode");
if (config_GetInt(VLCIntf, "macosx-icon-change")) {
/* After day 354 of the year, the usual VLC cone is replaced by another cone
* wearing a Father Xmas hat.
* Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
*/
NSCalendar *gregorian =
[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
if (dayOfYear >= 354)
[[VLCApplication sharedApplication] setApplicationIconImage: [NSImage imageNamed:@"vlc-xmas"]];
}
nib_main_loaded = TRUE;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
launched = YES;
......@@ -311,9 +297,9 @@ static VLCMain *sharedInstance = nil;
name:NSWorkspaceWillSleepNotification object:nil];
/* update the main window */
[o_mainwindow updateWindow];
[o_mainwindow updateTimeSlider];
[o_mainwindow updateVolumeSlider];
[[self mainWindow] updateWindow];
[[self mainWindow] updateTimeSlider];
[[self mainWindow] updateVolumeSlider];
/* Hack: Playlist is started before the interface.
* Thus, call additional updaters as we might miss these events if posted before
......@@ -379,8 +365,6 @@ static VLCMain *sharedInstance = nil;
/* write cached user defaults to disk */
[[NSUserDefaults standardUserDefaults] synchronize];
o_mainwindow = NULL;
}
#pragma mark -
......@@ -485,7 +469,7 @@ static VLCMain *sharedInstance = nil;
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
{
if (!hasVisibleWindows)
[o_mainwindow makeKeyAndOrderFront:self];
[[self mainWindow] makeKeyAndOrderFront:self];
return YES;
}
......@@ -494,7 +478,7 @@ static VLCMain *sharedInstance = nil;
{
// defer selector here (possibly another time) to ensure that keyWindow is set properly
// (needed for NSApplicationDidBecomeActiveNotification)
[o_mainwindow performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
[[self mainWindow] performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
}
- (void)setActiveVideoPlayback:(BOOL)b_value
......@@ -502,8 +486,8 @@ static VLCMain *sharedInstance = nil;
assert([NSThread isMainThread]);
b_active_videoplayback = b_value;
if (o_mainwindow) {
[o_mainwindow setVideoplayEnabled];
if ([self mainWindow]) {
[[self mainWindow] setVideoplayEnabled];
}
// update sleep blockers
......@@ -520,7 +504,7 @@ static VLCMain *sharedInstance = nil;
- (VLCMainWindow *)mainWindow
{
return o_mainwindow;
return (VLCMainWindow *)[_mainWindowController window];
}
- (VLCInputManager *)inputManager
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment