]> git.sesse.net Git - vlc/blobdiff - modules/gui/beos/InterfaceWindow.cpp
playlist: Make sure we don't pl_Release(p_playlist).
[vlc] / modules / gui / beos / InterfaceWindow.cpp
index 9e4da2678a2f2a89399bc5cae491eef72a628594..03b304651f32d60cbdb157e14c227b0f50114885 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * InterfaceWindow.cpp: beos interface
  *****************************************************************************
- * Copyright (C) 1999, 2000, 2001 VideoLAN
+ * Copyright (C) 1999, 2000, 2001 the VideoLAN team
  * $Id$
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
@@ -22,7 +22,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /* System headers */
 #include <scsi.h>
 #include <scsiprobe_driver.h>
 #include <fs_info.h>
-#include <string.h>
 
 /* VLC headers */
-#include <vlc/vlc.h>
-#include <vlc/aout.h>
-#include <vlc/intf.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_aout.h>
+#include <vlc_interface.h>
 
 /* BeOS interface headers */
 #include "MsgVals.h"
@@ -174,6 +176,14 @@ collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked,
     }
 }
 
+static int PlaylistChanged( vlc_object_t *p_this, const char * psz_variable,
+                            vlc_value_t old_val, vlc_value_t new_val,
+                            void * param )
+{
+    InterfaceWindow * w = (InterfaceWindow *) param;
+    w->UpdatePlaylist();
+    return VLC_SUCCESS;
+}
 
 /*****************************************************************************
  * InterfaceWindow
@@ -183,16 +193,24 @@ InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
                                   const char * name )
     : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
                B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
-      
+
       /* Initializations */
       p_intf( _p_intf ),
       p_input( NULL ),
       p_playlist( NULL ),
-      
+
       fFilePanel( NULL ),
       fLastUpdateTime( system_time() ),
       fSettings( new BMessage( 'sett' ) )
 {
+    p_playlist = pl_Yield( p_intf );
+
+    var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
+    var_AddCallback( p_playlist, "item-change", PlaylistChanged, this );
+    var_AddCallback( p_playlist, "item-append", PlaylistChanged, this );
+    var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, this );
+    var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, this );
+
     char psz_tmp[1024];
 #define ADD_ELLIPSIS( a ) \
     memset( psz_tmp, 0, 1024 ); \
@@ -210,11 +228,13 @@ InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
                      screen_rect.top + 50,
                      screen_rect.right - 150,
                      screen_rect.top + 250 );
+#if 0
     fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
     window_rect.Set( screen_rect.right - 550,
                      screen_rect.top + 300,
                      screen_rect.right - 150,
                      screen_rect.top + 500 );
+#endif
     fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
 
     // the media control view
@@ -269,13 +289,10 @@ InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
     fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
     fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
     fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );
-    fGotoMenuMI = new BMenuItem( _("Goto Menu"), new BMessage( NAVIGATE_MENU ) );
 
     /* Add the Navigation menu */
     fNavigationMenu = new BMenu( _("Navigation") );
     fMenuBar->AddItem( fNavigationMenu );
-    fNavigationMenu->AddItem( fGotoMenuMI );
-    fNavigationMenu->AddSeparatorItem();
     fNavigationMenu->AddItem( fPrevTitleMI );
     fNavigationMenu->AddItem( fNextTitleMI );
     fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
@@ -305,8 +322,10 @@ InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
 
     /* Add the Show menu */
     fShowMenu = new BMenu( _("Window") );
+#if 0
     ADD_ELLIPSIS( _("Playlist") );
     fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
+#endif
     ADD_ELLIPSIS( _("Messages") );
     fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
     ADD_ELLIPSIS( _("Preferences") );
@@ -337,10 +356,12 @@ InterfaceWindow::~InterfaceWindow()
     {
         vlc_object_release( p_playlist );
     }
+#if 0
     if( fPlaylistWindow )
     {
         fPlaylistWindow->ReallyQuit();
     }
+#endif
     if( fMessagesWindow )
     {
         fMessagesWindow->ReallyQuit();
@@ -377,7 +398,7 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
         case B_ABOUT_REQUESTED:
         {
             BAlert * alert;
-            
+
             alert = new BAlert( "VLC media player" VERSION,
                                 "VLC media player" VERSION " (BeOS interface)\n\n"
                                 "The VideoLAN team <videolan@videolan.org>\n"
@@ -395,7 +416,7 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
         case LOAD_SUBFILE:
             _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
             break;
-
+#if 0
         case OPEN_PLAYLIST:
             if (fPlaylistWindow->Lock())
             {
@@ -406,7 +427,7 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                 fPlaylistWindow->Unlock();
             }
             break;
-
+#endif
         case OPEN_DVD:
             {
                 const char * psz_device;
@@ -417,9 +438,9 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                     memset( psz_uri, 0, 1024 );
                     snprintf( psz_uri, 1024, "dvdnav:%s", psz_device );
                     playlist_Add( p_playlist, psz_uri, psz_device,
-                                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
+                        PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
                 }
-                _UpdatePlaylist();
+                UpdatePlaylist();
             }
             break;
 
@@ -442,27 +463,27 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
             }
             p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
             break;
-    
+
         case START_PLAYBACK:
-            /*  starts playing in normal mode */
-    
         case PAUSE_PLAYBACK:
+        {
+            vlc_value_t val;
+            val.i_int = PLAYING_S;
             if( p_input )
             {
-                if( var_GetInteger( p_input, "state" ) == PAUSE_S )
-                {
-                    if( p_playlist )
-                    {
-                        playlist_Play( p_playlist );
-                    }
-                }
-                else
-                {
-                    var_SetInteger( p_input, "state", PAUSE_S );
-                }
+                var_Get( p_input, "state", &val );
+            }
+            if( p_input && val.i_int != PAUSE_S )
+            {
+                val.i_int = PAUSE_S;
+                var_Set( p_input, "state", val );
+            }
+            else
+            {
+                playlist_Play( p_playlist );
             }
             break;
-    
+        }
         case HEIGHTH_PLAY:
             if( p_input )
             {
@@ -519,11 +540,11 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
         case VOLUME_CHG:
             aout_VolumeSet( p_intf, p_mediaControl->GetVolume() );
             break;
-    
+
         case VOLUME_MUTE:
             aout_VolumeMute( p_intf, NULL );
             break;
-    
+
         case SELECT_CHANNEL:
         {
             int32 channel;
@@ -540,7 +561,7 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
             }
             break;
         }
-    
+
         case PREV_TITLE:
             if( p_input )
             {
@@ -555,13 +576,6 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
             }
             break;
 
-        case NAVIGATE_MENU:
-            if( p_input )
-            {
-                var_SetInteger( p_input, "title", 0 );
-            }
-            break;
-
         case TOGGLE_TITLE:
         {
             int32 index;
@@ -718,17 +732,13 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
             {
                 break;
             }
-            
-            vlc_bool_t b_remove = ( p_message->WasDropped() &&
-                                    !( modifiers() & B_SHIFT_KEY ) ); 
+
+            bool b_remove = ( p_message->WasDropped() &&
+                                    !( modifiers() & B_SHIFT_KEY ) );
 
             if( b_remove && p_playlist )
             {
-                /* Empty playlist */
-                while( p_playlist->i_size > 0 )
-                {
-                    playlist_Delete( p_playlist, 0 );
-                }
+                playlist_Clear( p_playlist, true );
             }
 
             entry_ref ref;
@@ -740,12 +750,12 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
 
                 if( p_playlist )
                 {
-                    playlist_Add( p_playlist, path.Path(), path.Path(),
-                                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
+                    playlist_Add( p_playlist, path.Path(), NULL,
+                       PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
                 }
             }
 
-            _UpdatePlaylist();
+            UpdatePlaylist();
             break;
         }
 
@@ -795,8 +805,8 @@ bool InterfaceWindow::QuitRequested()
     p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
 
      _StoreSettings();
-   
-    p_intf->b_die = 1;
+
+    vlc_object_kill( p_intf );
 
     return( true );
 }
@@ -806,12 +816,6 @@ bool InterfaceWindow::QuitRequested()
  *****************************************************************************/
 void InterfaceWindow::UpdateInterface()
 {
-    /* Manage the input part */
-    if( !p_playlist )
-    {
-        p_playlist = (playlist_t *)
-            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    }
     if( !p_input )
     {
         p_input = (input_thread_t *)
@@ -828,14 +832,27 @@ void InterfaceWindow::UpdateInterface()
     {
         return;
     }
-    
+
+    if( b_playlist_update )
+    {
+#if 0
+        if( fPlaylistWindow->Lock() )
+        {
+            fPlaylistWindow->UpdatePlaylist( true );
+            fPlaylistWindow->Unlock();
+            b_playlist_update = false;
+        }
+#endif
+        p_mediaControl->SetEnabled( !playlist_IsEmpty( p_playlist ) );
+    }
+
     if( p_input )
     {
         vlc_value_t val;
         p_mediaControl->SetEnabled( true );
-        bool hasTitles   = var_Get( p_input, "title", &val );
-        bool hasChapters = var_Get( p_input, "chapter", &val );
-        p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ), 
+        bool hasTitles   = !var_Get( p_input, "title", &val );
+        bool hasChapters = !var_Get( p_input, "chapter", &val );
+        p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
                                    var_GetInteger( p_input, "rate" ) );
         var_Get( p_input, "position", &val );
         p_mediaControl->SetProgress( val.f_float );
@@ -851,27 +868,20 @@ void InterfaceWindow::UpdateInterface()
 #endif
 
         audio_volume_t i_volume;
-        aout_VolumeGet( p_input, &i_volume );
+        aout_VolumeGet( p_intf, &i_volume );
         p_mediaControl->SetAudioEnabled( true );
         p_mediaControl->SetMuted( i_volume );
-
-        // update playlist as well
-        if( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
-        {
-            fPlaylistWindow->UpdatePlaylist();
-            fPlaylistWindow->Unlock();
-        }
     }
     else
     {
         p_mediaControl->SetAudioEnabled( false );
 
         _SetMenusEnabled( false );
-        
-        if( !p_playlist || p_playlist->i_size <= 0 )
+
+        if( !playlist_IsEmpty( p_playlist ) )
         {
             p_mediaControl->SetProgress( 0 );
-            
+
 #if 0
             // enable/disable skip buttons
             bool canSkipPrev;
@@ -885,32 +895,27 @@ void InterfaceWindow::UpdateInterface()
             p_mediaControl->SetEnabled( false );
         }
     }
-    
+
     Unlock();
     fLastUpdateTime = system_time();
 }
 
 /*****************************************************************************
- * InterfaceWindow::IsStopped
+ * InterfaceWindow::UpdatePlaylist
  *****************************************************************************/
-bool
-InterfaceWindow::IsStopped() const
+void
+InterfaceWindow::UpdatePlaylist()
 {
-    return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
+    b_playlist_update = true;
 }
 
 /*****************************************************************************
- * InterfaceWindow::_UpdatePlaylist
+ * InterfaceWindow::IsStopped
  *****************************************************************************/
-void
-InterfaceWindow::_UpdatePlaylist()
+bool
+InterfaceWindow::IsStopped() const
 {
-    if( fPlaylistWindow->Lock() )
-    {
-        fPlaylistWindow->UpdatePlaylist( true );
-        fPlaylistWindow->Unlock();
-    }
-    p_mediaControl->SetEnabled( p_playlist->i_size );
+    return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
 }
 
 /*****************************************************************************
@@ -948,7 +953,6 @@ InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles
              fSubtitlesMenu->SetEnabled( hasFile );
         if ( fSpeedMenu->IsEnabled() != hasFile )
              fSpeedMenu->SetEnabled( hasFile );
-        fGotoMenuMI->SetEnabled( true );
         Unlock();
     }
 }
@@ -960,33 +964,33 @@ void
 InterfaceWindow::_UpdateSpeedMenu( int rate )
 {
     BMenuItem * toMark = NULL;
-    
+
     switch( rate )
     {
         case ( INPUT_RATE_DEFAULT * 8 ):
             toMark = fHeighthMI;
             break;
-            
+
         case ( INPUT_RATE_DEFAULT * 4 ):
             toMark = fQuarterMI;
             break;
-            
+
         case ( INPUT_RATE_DEFAULT * 2 ):
             toMark = fHalfMI;
             break;
-            
+
         case ( INPUT_RATE_DEFAULT ):
             toMark = fNormalMI;
             break;
-            
+
         case ( INPUT_RATE_DEFAULT / 2 ):
             toMark = fTwiceMI;
             break;
-            
+
         case ( INPUT_RATE_DEFAULT / 4 ):
             toMark = fFourMI;
             break;
-            
+
         case ( INPUT_RATE_DEFAULT / 8 ):
             toMark = fHeightMI;
             break;
@@ -1069,8 +1073,10 @@ InterfaceWindow::_RestoreSettings()
         BRect frame;
         if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
             set_window_pos( this, frame );
+#if 0
         if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
             set_window_pos( fPlaylistWindow, frame );
+#endif
         if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
             set_window_pos( fMessagesWindow, frame );
         if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
@@ -1080,18 +1086,21 @@ InterfaceWindow::_RestoreSettings()
             frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
             set_window_pos( fPreferencesWindow, frame );
         }
-        
+
         bool showing;
+#if 0
         if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
             launch_window( fPlaylistWindow, showing );
+#endif
         if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
             launch_window( fMessagesWindow, showing );
         if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
             launch_window( fPreferencesWindow, showing );
-
+#if 0
         uint32 displayMode;
         if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
             fPlaylistWindow->SetDisplayMode( displayMode );
+#endif
     }
 }
 
@@ -1108,6 +1117,7 @@ InterfaceWindow::_StoreSettings()
     /* Save the windows positions */
     if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
         fSettings->AddRect( "main frame", Frame() );
+#if 0
     if ( fPlaylistWindow->Lock() )
     {
         if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
@@ -1116,6 +1126,7 @@ InterfaceWindow::_StoreSettings()
             fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
         fPlaylistWindow->Unlock();
     }
+#endif
     if ( fMessagesWindow->Lock() )
     {
         if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
@@ -1132,10 +1143,11 @@ InterfaceWindow::_StoreSettings()
             fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
         fPreferencesWindow->Unlock();
     }
+#if 0
     uint32 displayMode = fPlaylistWindow->DisplayMode();
     if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
         fSettings->AddInt32( "playlist display mode", displayMode );
-
+#endif
     save_settings( fSettings, "interface_settings", "VideoLAN Client" );
 }
 
@@ -1235,11 +1247,11 @@ void LanguageMenu::AttachedToWindow()
     {
         return;
     }
-    
+
     vlc_value_t val_list, text_list;
     BMessage * message;
     int i_current;
-    
+
     i_current = var_GetInteger( p_input, psz_variable );
     var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list );
     for( int i = 0; i < val_list.p_list->i_count; i++ )
@@ -1254,9 +1266,9 @@ void LanguageMenu::AttachedToWindow()
         AddItem( item );
     }
     var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
-    
+
     vlc_object_release( p_input );
-    
+
     BMenu::AttachedToWindow();
 }
 
@@ -1296,16 +1308,19 @@ void TitleMenu::AttachedToWindow()
     }
 
     vlc_value_t val;
+    BMessage * message;
     if( !var_Get( p_input, "title", &val ) )
     {
         vlc_value_t val_list, text_list;
         var_Change( p_input, "title", VLC_VAR_GETCHOICES,
                     &val_list, &text_list );
-        
+
         for( int i = 0; i < val_list.p_list->i_count; i++ )
         {
+            message = new BMessage( TOGGLE_TITLE );
+            message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
             item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
-                                  NULL );
+                                  message );
             if( val_list.p_list->p_values[i].i_int == val.i_int )
             {
                 item->SetMarked( true );
@@ -1316,6 +1331,7 @@ void TitleMenu::AttachedToWindow()
         var_Change( p_input, "title", VLC_VAR_FREELIST,
                     &val_list, &text_list );
     }
+    vlc_object_release( p_input );
     BMenu::AttachedToWindow();
 }
 
@@ -1356,16 +1372,19 @@ void ChapterMenu::AttachedToWindow()
     }
 
     vlc_value_t val;
+    BMessage * message;
     if( !var_Get( p_input, "chapter", &val ) )
     {
         vlc_value_t val_list, text_list;
         var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
                     &val_list, &text_list );
-        
+
         for( int i = 0; i < val_list.p_list->i_count; i++ )
         {
+            message = new BMessage( TOGGLE_CHAPTER );
+            message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
             item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
-                                  NULL );
+                                  message );
             if( val_list.p_list->p_values[i].i_int == val.i_int )
             {
                 item->SetMarked( true );
@@ -1376,6 +1395,7 @@ void ChapterMenu::AttachedToWindow()
         var_Change( p_input, "chapter", VLC_VAR_FREELIST,
                     &val_list, &text_list );
     }
+    vlc_object_release( p_input );
     BMenu::AttachedToWindow();
 }