]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/intf.m
macosx: sync option strings with 1.0-bugfix
[vlc] / modules / gui / macosx / intf.m
index 6e4ad9ce630c2de71903a16f250be423f4941a16..25494bd01dc6de85faceaeecb61a7b35161ba177 100644 (file)
@@ -91,8 +91,6 @@ int OpenIntf ( vlc_object_t *p_this )
 
     memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
 
-    p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
-
     /* subscribe to LibVLCCore's messages */
     p_intf->p_sys->p_sub = msg_Subscribe( p_intf->p_libvlc, MsgCallback, NULL );
     p_intf->pf_run = Run;
@@ -108,8 +106,6 @@ void CloseIntf ( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t*) p_this;
 
-    [p_intf->p_sys->o_pool release];
-
     free( p_intf->p_sys );
 }
 
@@ -315,6 +311,8 @@ static VLCMain *_o_sharedMainInstance = nil;
     else
         _o_sharedMainInstance = [super init];
 
+    p_intf = NULL;
+
     o_msg_lock = [[NSLock alloc] init];
     o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
     /* subscribe to LibVLC's debug messages as early as possible (for us) */
@@ -336,11 +334,9 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     i_lastShownVolume = -1;
 
-#ifndef __x86_64__
     o_remote = [[AppleRemote alloc] init];
     [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
     [o_remote setDelegate: _o_sharedMainInstance];
-#endif
 
     o_eyetv = [[VLCEyeTVController alloc] init];
 
@@ -367,7 +363,10 @@ static VLCMain *_o_sharedMainInstance = nil;
     playlist_t *p_playlist;
     vlc_value_t val;
 
-    /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
+    if( !p_intf ) return;
+
+    /* Check if we already did this once. Opening the other nibs calls it too,
+       because VLCMain is the owner */
     if( nib_main_loaded ) return;
 
     /* check whether the user runs a valid version of OS X */
@@ -463,6 +462,18 @@ static VLCMain *_o_sharedMainInstance = nil;
     i_key = config_GetInt( p_intf, "key-snapshot" );
     [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
     [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
+    i_key = config_GetInt( p_intf, "key-random" );
+    [o_mi_random setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
+    [o_mi_random setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
+    i_key = config_GetInt( p_intf, "key-zoom-half" );
+    [o_mi_half_window setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
+    [o_mi_half_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
+    i_key = config_GetInt( p_intf, "key-zoom-original" );
+    [o_mi_normal_window setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
+    [o_mi_normal_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
+    i_key = config_GetInt( p_intf, "key-zoom-double" );
+    [o_mi_double_window setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
+    [o_mi_double_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
 
     var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
 
@@ -512,8 +523,10 @@ static VLCMain *_o_sharedMainInstance = nil;
     nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
     
     /* subscribe to various interactive dialogues */
-    var_Create( p_intf, "dialog-fatal", VLC_VAR_ADDRESS );
-    var_AddCallback( p_intf, "dialog-fatal", DialogCallback, self );
+    var_Create( p_intf, "dialog-error", VLC_VAR_ADDRESS );
+    var_AddCallback( p_intf, "dialog-error", DialogCallback, self );
+    var_Create( p_intf, "dialog-critical", VLC_VAR_ADDRESS );
+    var_AddCallback( p_intf, "dialog-critical", DialogCallback, self );
     var_Create( p_intf, "dialog-login", VLC_VAR_ADDRESS );
     var_AddCallback( p_intf, "dialog-login", DialogCallback, self );
     var_Create( p_intf, "dialog-question", VLC_VAR_ADDRESS );
@@ -545,6 +558,8 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
 {
+    if( !p_intf ) return;
+
     /* FIXME: don't poll */
     interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
                                      target: self selector: @selector(manageIntf:)
@@ -561,6 +576,8 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
 {
+    if( !p_intf ) return;
+
     [self _removeOldPreferences];
 
 #ifdef UPDATE_CHECK
@@ -581,6 +598,8 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 - (void)initStrings
 {
+    if( !p_intf ) return;
+
     [o_window setTitle: _NS("VLC media player")];
     [self setScrollField:_NS("VLC media player") stopAfter:-1];
 
@@ -752,6 +771,8 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
 {
+    if( !p_intf ) return;
+
     NSArray *menuitems_array = [the_menu itemArray];
     for( int i=0; i<[menuitems_array count]; i++ )
     {
@@ -769,6 +790,8 @@ static VLCMain *_o_sharedMainInstance = nil;
     vout_thread_t * p_vout;
     int returnedValue = 0;
  
+    if( !p_intf ) return;
+
     msg_Dbg( p_intf, "Terminating" );
 
     /* Make sure the manage_thread won't call -terminate: again */
@@ -796,7 +819,8 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     /* unsubscribe from the interactive dialogues */
     dialog_Unregister( p_intf );
-    var_DelCallback( p_intf, "dialog-fatal", DialogCallback, self );
+    var_DelCallback( p_intf, "dialog-error", DialogCallback, self );
+    var_DelCallback( p_intf, "dialog-critical", DialogCallback, self );
     var_DelCallback( p_intf, "dialog-login", DialogCallback, self );
     var_DelCallback( p_intf, "dialog-question", DialogCallback, self );
     var_DelCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
@@ -909,7 +933,6 @@ static NSString * VLCToolbarMediaControl     = @"VLCToolbarMediaControl";
 {
     NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
 
     if( [itemIdentifier isEqual: VLCToolbarMediaControl] )
     {
         [toolbarItem setLabel:@"Media Controls"];
@@ -991,26 +1014,23 @@ static NSString * VLCToolbarMediaControl     = @"VLCToolbarMediaControl";
    application */
 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
 {
-#ifndef __x86_64__
-    [o_remote startListening: self];
-#endif
+    if( !p_intf ) return;
+       if( config_GetInt( p_intf, "macosx-appleremote" ) == YES )
+               [o_remote startListening: self];
 }
 - (void)applicationDidResignActive:(NSNotification *)aNotification
 {
-#ifndef __x86_64__
+    if( !p_intf ) return;
     [o_remote stopListening: self];
-#endif
 }
 
 /* Triggered when the computer goes to sleep */
 - (void)computerWillSleep: (NSNotification *)notification
 {
     /* Pause */
-    if( p_intf->p_sys->i_play_status == PLAYING_S )
+    if( p_intf && p_intf->p_sys->i_play_status == PLAYING_S )
     {
-        vlc_value_t val;
-        val.i_int = config_GetInt( p_intf, "key-play-pause" );
-        var_Set( p_intf->p_libvlc, "key-pressed", val );
+        var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
     }
 }
 
@@ -1478,6 +1498,11 @@ static unsigned int VLCModifiersToCocoa( unsigned int i_key )
     return nil;
 }
 
+- (id)appleRemoteController
+{
+       return o_remote;
+}
+
 #pragma mark -
 #pragma mark Polling
 
@@ -1508,11 +1533,11 @@ static void manage_cleanup( void * args )
     id self = manage_cleanup_stack->self;
     playlist_t * p_playlist = manage_cleanup_stack->p_playlist;
 
-    var_AddCallback( p_playlist, "item-current", PlaylistChanged, self );
-    var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
-    var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
-    var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, self );
-    var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, self );
+    var_DelCallback( p_playlist, "item-current", PlaylistChanged, self );
+    var_DelCallback( p_playlist, "intf-change", PlaylistChanged, self );
+    var_DelCallback( p_playlist, "item-change", PlaylistChanged, self );
+    var_DelCallback( p_playlist, "playlist-item-append", PlaylistChanged, self );
+    var_DelCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, self );
 
     pl_Release( p_intf );
 
@@ -1587,7 +1612,10 @@ static void manage_cleanup( void * args )
 - (void)manageVolumeSlider
 {
     audio_volume_t i_volume;
-    aout_VolumeGet( p_intf, &i_volume );
+    playlist_t * p_playlist = pl_Hold( p_intf );
+
+    aout_VolumeGet( p_playlist, &i_volume );
+    pl_Release( p_intf );
 
     if( i_volume != i_lastShownVolume )
     {
@@ -1895,20 +1923,11 @@ end:
             [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
                 var: "deinterlace" selector: @selector(toggleVar:)];
 
-#if 0
-/* FIXME Post processing. */
-            p_dec_obj = (vlc_object_t *)vlc_object_find(
-                                                 (vlc_object_t *)p_vout,
-                                                 VLC_OBJECT_DECODER,
-                                                 FIND_PARENT );
-            if( p_dec_obj != NULL )
-            {
-               [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
-                    (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
+#if 1
+           [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
+                    (vlc_object_t *)p_vout var:"postprocess" selector:
                     @selector(toggleVar:)];
 
-                vlc_object_release(p_dec_obj);
-            }
 #endif
             vlc_object_release( (vlc_object_t *)p_vout );
         }
@@ -2562,9 +2581,9 @@ end:
 
     if( [o_msg_arr count] + 2 > 600 )
     {
-               [o_msg_arr removeObjectAtIndex: 0];
+        [o_msg_arr removeObjectAtIndex: 0];
         [o_msg_arr removeObjectAtIndex: 1];
-   }
+    }
 
     o_attr = [NSDictionary dictionaryWithObject: o_gray
                                          forKey: NSForegroundColorAttributeName];
@@ -2841,49 +2860,69 @@ end:
 
 @implementation VLCApplication
 
-- (void)sendEvent: (NSEvent*)event
+- (void)awakeFromNib
 {
-    if( [event type] == NSSystemDefined && [event subtype] == 8 )
-       {
-               int keyCode = (([event data1] & 0xFFFF0000) >> 16);
-               int keyFlags = ([event data1] & 0x0000FFFF);
-               int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
-        int keyRepeat = (keyFlags & 0x1);
+       b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
+    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(coreChangedMediaKeySupportSetting:) name: @"VLCMediaKeySupportSettingChanged" object: nil];
+}
 
-        if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
-            var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver: self];
+    [super dealloc];
+}
 
-        if( keyCode == NX_KEYTYPE_FAST && !b_justJumped )
-        {
-            if( keyState == 0 && keyRepeat == 0 )
-            {
-                    var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
-            }
-            else if( keyRepeat == 1 )
-            {
-                var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
-                b_justJumped = YES;
-                [self performSelector:@selector(resetJump)
-                           withObject: NULL
-                           afterDelay:0.25];
-            }
-        }
+- (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
+{
+       b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
+}
 
-        if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
-        {
-            if( keyState == 0 && keyRepeat == 0 )
-            {
-                var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
-            }
-            else if( keyRepeat == 1 )
-            {
-                var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
-                b_justJumped = YES;
-                [self performSelector:@selector(resetJump)
-                           withObject: NULL
-                           afterDelay:0.25];
-            }
-        }
+- (void)sendEvent: (NSEvent*)event
+{
+       if( b_mediaKeySupport )
+       {
+               if( [event type] == NSSystemDefined && [event subtype] == 8 )
+               {
+                       int keyCode = (([event data1] & 0xFFFF0000) >> 16);
+                       int keyFlags = ([event data1] & 0x0000FFFF);
+                       int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
+                       int keyRepeat = (keyFlags & 0x1);
+
+                       if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
+                               var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
+
+                       if( keyCode == NX_KEYTYPE_FAST && !b_justJumped )
+                       {
+                               if( keyState == 0 && keyRepeat == 0 )
+                               {
+                                               var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
+                               }
+                               else if( keyRepeat == 1 )
+                               {
+                                       var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
+                                       b_justJumped = YES;
+                                       [self performSelector:@selector(resetJump)
+                                                          withObject: NULL
+                                                          afterDelay:0.25];
+                               }
+                       }
+
+                       if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
+                       {
+                               if( keyState == 0 && keyRepeat == 0 )
+                               {
+                                       var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
+                               }
+                               else if( keyRepeat == 1 )
+                               {
+                                       var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
+                                       b_justJumped = YES;
+                                       [self performSelector:@selector(resetJump)
+                                                          withObject: NULL
+                                                          afterDelay:0.25];
+                               }
+                       }
+               }
        }
        [super sendEvent: event];
 }