]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/controls.m
Added random, repeat one and repeat all checkboxes to the playlist
[vlc] / modules / gui / macosx / controls.m
index c5ef187e8456861171f73f53d287d3cb72f4ce18..e8f95a02163bb2ccf1ff28a0c1047934d3457966 100644 (file)
@@ -2,7 +2,7 @@
  * controls.m: MacOS X interface plugin
  *****************************************************************************
  * Copyright (C) 2002-2003 VideoLAN
- * $Id: controls.m,v 1.40 2003/06/01 23:48:17 hartman Exp $
+ * $Id: controls.m,v 1.54 2003/11/15 22:42:16 hartman Exp $
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Christophe Massiot <massiot@via.ecp.fr>
@@ -34,6 +34,7 @@
 #include "vout.h"
 #include "open.h"
 #include "controls.h"
+#include <osd.h>
 
 /*****************************************************************************
  * VLCControls implementation 
 
 - (IBAction)play:(id)sender
 {
+    vlc_value_t val;
+    playlist_t * p_playlist;
     intf_thread_t * p_intf = [NSApp getIntf];
-
-    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+    input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                        FIND_ANYWHERE );
-    if( p_playlist == NULL )
+
+    val.i_int = PLAYING_S;
+    if( p_input )
     {
-        return;
+        var_Get( p_input, "state", &val );
     }
-
-    if( playlist_IsPlaying( p_playlist ) )
+    if( p_input && val.i_int != PAUSE_S )
     {
-        playlist_Pause( p_playlist );
-        vlc_object_release( p_playlist );
+        vout_OSDMessage( VLC_OBJECT(p_intf), _( "Pause" ) );
+        val.i_int = PAUSE_S;
+        var_Set( p_input, "state", val );
     }
     else
     {
-        if( !playlist_IsEmpty( p_playlist ) )
+        p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                        FIND_ANYWHERE );
+        if( p_playlist )
         {
-            playlist_Play( p_playlist );
-            vlc_object_release( p_playlist );
-        }
-        else
-        {
-            vlc_object_release( p_playlist );
-            [o_open openFileGeneric: nil];
+            vlc_mutex_lock( &p_playlist->object_lock );
+            if( p_playlist->i_size )
+            {
+                vlc_mutex_unlock( &p_playlist->object_lock );
+                vout_OSDMessage( VLC_OBJECT(p_intf), _( "Play" ) );
+                playlist_Play( p_playlist );
+                vlc_object_release( p_playlist );
+            }
+            else
+            {
+                vlc_mutex_unlock( &p_playlist->object_lock );
+                vlc_object_release( p_playlist );
+                [o_open openFileGeneric: nil];
+            }
         }
     }
+    if( p_input ) vlc_object_release( p_input );
 }
 
 - (IBAction)stop:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
-
     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
-    if( p_playlist == NULL )
+    if( p_playlist != NULL )
     {
-        return;
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Stop" ) );
+        playlist_Stop( p_playlist );
+        vlc_object_release( p_playlist );
     }
-
-    playlist_Stop( p_playlist );
-    vlc_object_release( p_playlist );
 }
 
 - (IBAction)faster:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
-
-    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+    input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                        FIND_ANYWHERE );
-    if( p_playlist == NULL )
+    if( p_input != NULL )
     {
-        return;
+        vlc_value_t val; val.b_bool = VLC_TRUE;
+
+        var_Set( p_input, "rate-faster", val );
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Faster" ) );
+        vlc_object_release( p_input );
     }
+}
 
-    vlc_mutex_lock( &p_playlist->object_lock );
-    if( p_playlist->p_input != NULL )
+- (IBAction)slower:(id)sender
+{
+    intf_thread_t * p_intf = [NSApp getIntf];
+    input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
+                                                       FIND_ANYWHERE );
+    if( p_input != NULL )
     {
-        input_SetStatus( p_playlist->p_input, INPUT_STATUS_FASTER );
-    } 
-    vlc_mutex_unlock( &p_playlist->object_lock );
+        vlc_value_t val; val.b_bool = VLC_TRUE;
 
-    vlc_object_release( p_playlist );
+        var_Set( p_input, "rate-slower", val );
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Slower" ) );
+        vlc_object_release( p_input );
+    }
 }
 
-- (IBAction)slower:(id)sender
+- (IBAction)prev:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
-
     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
-    if( p_playlist == NULL )
+    if( p_playlist )
     {
-        return;
+        playlist_Prev( p_playlist );
+        vlc_object_release( p_playlist );
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Previous" ) );
     }
+}
 
-    vlc_mutex_lock( &p_playlist->object_lock );
-    if( p_playlist->p_input != NULL )
+- (IBAction)next:(id)sender
+{
+    intf_thread_t * p_intf = [NSApp getIntf];
+    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                                       FIND_ANYWHERE );
+    if( p_playlist )
     {
-        input_SetStatus( p_playlist->p_input, INPUT_STATUS_SLOWER );
+        playlist_Next( p_playlist );
+        vlc_object_release( p_playlist );
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Next" ) );
     }
-    vlc_mutex_unlock( &p_playlist->object_lock );
-
-    vlc_object_release( p_playlist );
 }
 
-- (IBAction)prev:(id)sender
+- (IBAction)random:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
-
+    vlc_value_t val;
     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
     if( p_playlist == NULL )
         return;
     }
 
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    if( p_playlist->p_input == NULL )
+    var_Get( p_playlist, "random", &val );
+    val.b_bool = !val.b_bool;
+    var_Set( p_playlist, "random", val );
+    if( val.b_bool )
     {
-        vlc_mutex_unlock( &p_playlist->object_lock );
-        vlc_object_release( p_playlist );  
-        return;
-    }
-
-    vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
-
-#define p_area p_playlist->p_input->stream.p_selected_area
-
-    if( p_area->i_part_nb > 1 && p_area->i_part > 1 )
-    {
-        p_area->i_part--;
-
-        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
-        input_ChangeArea( p_playlist->p_input, p_area );
-        vlc_mutex_unlock( &p_playlist->object_lock );
-
-        p_intf->p_sys->b_input_update = VLC_TRUE;
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Shuffle On" ) );
     }
     else
     {
-        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
-        vlc_mutex_unlock( &p_playlist->object_lock );
-        playlist_Prev( p_playlist );
-    }
-
-#undef p_area
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Shuffle Off" ) );
+    }    
 
     vlc_object_release( p_playlist );
 }
 
-- (IBAction)next:(id)sender
+- (IBAction)repeat:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
-
+    vlc_value_t val;
     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
     if( p_playlist == NULL )
         return;
     }
 
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    if( p_playlist->p_input == NULL )
-    {
-        vlc_mutex_unlock( &p_playlist->object_lock );
-        vlc_object_release( p_playlist );  
-        return;
-    }
-
-    vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
-
-#define p_area p_playlist->p_input->stream.p_selected_area
-
-    if( p_area->i_part_nb > 1 && p_area->i_part + 1 < p_area->i_part_nb )
+    var_Get( p_playlist, "repeat", &val );
+    val.b_bool = !val.b_bool;
+    var_Set( p_playlist, "repeat", val );
+    if( val.b_bool )
     {
-        p_area->i_part++;
-
-        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
-        input_ChangeArea( p_playlist->p_input, p_area );
-        vlc_mutex_unlock( &p_playlist->object_lock );
-
-        p_intf->p_sys->b_input_update = VLC_TRUE;
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Repeat On" ) );
     }
     else
     {
-        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
-        vlc_mutex_unlock( &p_playlist->object_lock );
-        playlist_Next( p_playlist );
-    }
-
-#undef p_area
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Repeat Off" ) );
+    }    
 
     vlc_object_release( p_playlist );
 }
 - (IBAction)loop:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
-
+    vlc_value_t val;
     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
     if( p_playlist == NULL )
         return;
     }
 
-    config_PutInt( p_playlist, "loop",
-                   !config_GetInt( p_playlist, "loop" ) );
+    var_Get( p_playlist, "loop", &val );
+    val.b_bool = !val.b_bool;
+    var_Set( p_playlist, "loop", val );
+    if( val.b_bool )
+    {
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Loop On" ) );
+    }
+    else
+    {
+        vout_OSDMessage( (vlc_object_t *)p_intf, _( "Loop Off" ) );
+    }    
 
     vlc_object_release( p_playlist );
 }
 - (IBAction)forward:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
-    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+    input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                        FIND_ANYWHERE );
-    if( p_playlist == NULL || p_playlist->p_input == NULL )
+    if( p_input != NULL )
     {
-        if ( p_playlist != NULL ) vlc_object_release( p_playlist );
-        return;
+        vlc_value_t time;
+        time.i_time = 10 * 1000000;
+        var_Set( p_input, "time-offset", time );
+        vlc_object_release( p_input );
     }
-
-    input_Seek( p_playlist->p_input, 5, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
-    vlc_object_release( p_playlist );
 }
 
 - (IBAction)backward:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
-    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+    input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                        FIND_ANYWHERE );
-    if( p_playlist == NULL || p_playlist->p_input == NULL )
+    if( p_input != NULL )
     {
-        if ( p_playlist != NULL ) vlc_object_release( p_playlist );
-        return;
+        vlc_value_t time;
+        time.i_time = -10 * 1000000;
+        var_Set( p_input, "time-offset", time );
+        vlc_object_release( p_input );
     }
-
-    input_Seek( p_playlist->p_input, -5, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
-    vlc_object_release( p_playlist );
 }
 
 - (IBAction)volumeUp:(id)sender
 {
     intf_thread_t * p_intf = [NSApp getIntf];
     audio_volume_t i_volume;
+    char string[9];
 
     aout_VolumeGet( p_intf, &i_volume );
 
-    [o_volumeslider setFloatValue: (float)(i_volume / AOUT_VOLUME_STEP)]; 
+    [o_volumeslider setFloatValue: (float)(i_volume / AOUT_VOLUME_STEP)];
+
+    sprintf( string, "Vol %d%%", i_volume*100/AOUT_VOLUME_MAX );
+    vout_OSDMessage( (vlc_object_t *)p_intf, string );
 }
 
 - (IBAction)windowAction:(id)sender
         {
             if( [[o_window className] isEqualToString: @"VLCWindow"] )
             {
-                if( [o_title isEqualToString: _NS("Fullscreen") ] )
-                    [o_window toggleFullscreen];
-                else if( [o_title isEqualToString: _NS("Half Size") ] )
+                if( [o_title isEqualToString: _NS("Half Size") ] )
                     [o_window scaleWindowWithFactor: 0.5];
                 else if( [o_title isEqualToString: _NS("Normal Size") ] )
                     [o_window scaleWindowWithFactor: 1.0];
                     if( ![o_window isZoomed] )
                         [o_window performZoom:self];
                 }
+                else
+                    [o_window toggleFullscreen];
+                break;
             }
         }
         vlc_object_release( (vlc_object_t *)p_vout );
 {
     NSMenuItem *o_mi = (NSMenuItem *)sender;
     VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
+    [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
+        toTarget: self withObject: o_data];
+
+    return;
+}
+
+- (int)toggleVarThread: (id)_o_data
+{
     vlc_object_t *p_object;
+    NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
+    VLCMenuExt *o_data = (VLCMenuExt *)_o_data;
+
+    vlc_thread_set_priority( [NSApp getIntf] , VLC_THREAD_PRIORITY_LOW );
 
     p_object = (vlc_object_t *)vlc_object_get( [NSApp getIntf],
                                     [o_data objectID] );
-    if( p_object == NULL ) return;
 
-    var_Set( p_object, strdup([o_data name]), [o_data value] );
-    vlc_object_release( p_object );
-    
-    return;
+    if( p_object != NULL )
+    {
+        var_Set( p_object, strdup([o_data name]), [o_data value] );
+        vlc_object_release( p_object );
+        [o_pool release];
+        return VLC_TRUE;
+    }
+    [o_pool release];
+    return VLC_EGENERIC;
 }
 
 @end
 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
 {
     BOOL bEnabled = TRUE;
+    vlc_value_t val;
     intf_thread_t * p_intf = [NSApp getIntf];
-
     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
 
             if( p_input != NULL )
             {
                 vlc_mutex_lock( &p_input->stream.stream_lock );
-                bEnabled |= p_input->stream.p_selected_area->i_part_nb > 1;
+                bEnabled |= p_input->stream.i_area_nb > 1;
                 vlc_mutex_unlock( &p_input->stream.stream_lock );
             }
         }
     }
-    else if( [[o_mi title] isEqualToString: _NS("Loop")] )
+    else if( [[o_mi title] isEqualToString: _NS("Shuffle")] )
     {
-        int i_state = config_GetInt( p_playlist, "loop" ) ?
-                      NSOnState : NSOffState;
-
+        int i_state;
+        var_Get( p_playlist, "random", &val );
+        i_state = val.b_bool ? NSOnState : NSOffState;
+        [o_mi setState: i_state];
+    }
+    else if( [[o_mi title] isEqualToString: _NS("Repeat Item")] )
+    {
+        int i_state;
+        var_Get( p_playlist, "repeat", &val );
+        i_state = val.b_bool ? NSOnState : NSOffState;
+        [o_mi setState: i_state];
+    }
+    else if( [[o_mi title] isEqualToString: _NS("Repeat Playlist")] )
+    {
+        int i_state;
+        var_Get( p_playlist, "loop", &val );
+        i_state = val.b_bool ? NSOnState : NSOffState;
         [o_mi setState: i_state];
     }
     else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||