]> 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 586024b7ec36708c9988d2f6c0c51a5d204d745e..03b304651f32d60cbdb157e14c227b0f50114885 100644 (file)
@@ -1,14 +1,14 @@
 /*****************************************************************************
  * InterfaceWindow.cpp: beos interface
  *****************************************************************************
- * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: InterfaceWindow.cpp,v 1.7 2002/10/30 06:12:27 titer Exp $
+ * Copyright (C) 1999, 2000, 2001 the VideoLAN team
+ * $Id$
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
  *          Tony Castley <tony@castley.net>
  *          Richard Shepherd <richard@rshepherd.demon.co.uk>
- *          Stephan Aßmus <stippi@yellowbites.com>
+ *          Stephan Aßmus <superstippi@gmx.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -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>
+#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"
 #include "MediaControlView.h"
 #include "PlayListWindow.h"
 #include "PreferencesWindow.h"
-#include "VlcWrapper.h"
+#include "MessagesWindow.h"
 #include "InterfaceWindow.h"
 
-#define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
+#define INTERFACE_UPDATE_TIMEOUT  80000 // 2 frames if at 25 fps
+#define INTERFACE_LOCKING_TIMEOUT 5000
+
+// make_sure_frame_is_on_screen
+bool
+make_sure_frame_is_on_screen( BRect& frame )
+{
+    BScreen screen( B_MAIN_SCREEN_ID );
+    if (frame.IsValid() && screen.IsValid()) {
+        if (!screen.Frame().Contains(frame)) {
+            // make sure frame fits in the screen
+            if (frame.Width() > screen.Frame().Width())
+                frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
+            if (frame.Height() > screen.Frame().Height())
+                frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
+            // frame is now at the most the size of the screen
+            if (frame.right > screen.Frame().right)
+                frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
+            if (frame.bottom > screen.Frame().bottom)
+                frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
+            if (frame.left < screen.Frame().left)
+                frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
+            if (frame.top < screen.Frame().top)
+                frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
+        }
+        return true;
+    }
+    return false;
+}
+
+// make_sure_frame_is_within_limits
+void
+make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
+                                  float maxWidth, float maxHeight )
+{
+    if ( frame.Width() < minWidth )
+        frame.right = frame.left + minWidth;
+    if ( frame.Height() < minHeight )
+        frame.bottom = frame.top + minHeight;
+    if ( frame.Width() > maxWidth )
+        frame.right = frame.left + maxWidth;
+    if ( frame.Height() > maxHeight )
+        frame.bottom = frame.top + maxHeight;
+}
 
+// get_volume_info
+bool
+get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
+{
+    bool success = false;
+    isCDROM = false;
+    deviceName = "";
+    volumeName = "";
+    char name[B_FILE_NAME_LENGTH];
+    if ( volume.GetName( name ) >= B_OK )    // disk is currently mounted
+    {
+        volumeName = name;
+        dev_t dev = volume.Device();
+        fs_info info;
+        if ( fs_stat_dev( dev, &info ) == B_OK )
+        {
+            success = true;
+            deviceName = info.device_name;
+            if ( volume.IsReadOnly() )
+            {
+                int i_dev = open( info.device_name, O_RDONLY );
+                if ( i_dev >= 0 )
+                {
+                    device_geometry g;
+                    if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
+                        isCDROM = ( g.device_type == B_CD );
+                    close( i_dev );
+                }
+            }
+        }
+     }
+     return success;
+}
+
+// collect_folder_contents
+void
+collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
+{
+    while ( dir.GetNextEntry( &entry, true ) == B_OK )
+    {
+        if ( !entry.IsDirectory() )
+        {
+            BPath path;
+            // since the directory will give us the entries in reverse order,
+            // we put them each at the same index, effectively reversing the
+            // items while adding them
+            if ( entry.GetPath( &path ) == B_OK )
+            {
+                BString* string = new BString( path.Path() );
+                if ( !list.AddItem( string, 0 ) )
+                    delete string;    // at least don't leak
+            }
+        }
+        else
+        {
+            if ( !asked )
+            {
+                // ask user if we should parse sub-folders as well
+                BAlert* alert = new BAlert( "sub-folders?",
+                                            _("Open files from all sub-folders as well?"),
+                                            _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,
+                                            B_IDEA_ALERT );
+                int32 buttonIndex = alert->Go();
+                deep = buttonIndex == 1;
+                asked = true;
+                // never delete BAlerts!!
+            }
+            if ( deep )
+            {
+                BDirectory subDir( &entry );
+                if ( subDir.InitCheck() == B_OK )
+                    collect_folder_contents( subDir, list,
+                                             deep, asked, entry );
+            }
+        }
+    }
+}
+
+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
  *****************************************************************************/
 
-InterfaceWindow::InterfaceWindow( BRect frame, const char *name,
-                                                                 intf_thread_t  *p_interface )
-       : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
-                          B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
-         p_intf( p_interface ),
-         fInputThread( NULL ),
-         fFilePanel( NULL ),
-         fLastUpdateTime( system_time() ),
-         fSettings( new BMessage( 'sett' ) )
+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_intf = p_interface;
-    playlist_t *p_playlist = p_intf->p_sys->p_playlist;
-    
-    fPlaylistIsEmpty = (p_playlist->i_size < 0);
-    
-    fPlaylistWindow = new PlayListWindow( BRect( 100.0, 100.0, 400.0, 350.0 ),
-                                                                                 "Playlist",
-                                                                                 p_playlist,
-                                                                                 this,
-                                                                                 p_intf );
-       fPreferencesWindow = new PreferencesWindow( BRect( 100, 400, 500, 595 ),
-                                                   "Preferences",
-                                                   p_intf );
-    
-       // set the title bar
-       SetName( "interface" );
-       SetTitle( VOUT_TITLE );
-
-       // the media control view
-       p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
-                                              p_intf );
-       p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
-       p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
-
-       float width, height;
-       p_mediaControl->GetPreferredSize( &width, &height );
-
-       // set up the main menu
-       fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
-                                                        B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
-
-       // make menu bar resize to correct height
-       float menuWidth, menuHeight;
-       fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
-       fMenuBar->ResizeTo( width, menuHeight );        // don't change! it's a workarround!
-       // take care of proper size for ourself
-       height += fMenuBar->Bounds().Height();
-       ResizeTo( width, height );
-
-       p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
-       AddChild( fMenuBar );
-       AddChild( p_mediaControl );
-
-       // Add the file Menu
-       BMenu* fileMenu = new BMenu( "File" );
-       fMenuBar->AddItem( fileMenu );
-       fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
-                                                                         new BMessage( OPEN_FILE ), 'O') );
-       
-       fileMenu->AddItem( new CDMenu( "Open Disc" ) );
-       
-       fileMenu->AddSeparatorItem();
-       fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
-                                                                         new BMessage( OPEN_PLAYLIST ), 'P') );
-       
-       fileMenu->AddSeparatorItem();
-       BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
-                                                                        new BMessage( B_ABOUT_REQUESTED ), 'A');
-       item->SetTarget( be_app );
-       fileMenu->AddItem( item );
-       fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
-
-       fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_intf);
-       fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_intf);
-
-       /* Add the Audio menu */
-       fAudioMenu = new BMenu( "Audio" );
-       fMenuBar->AddItem ( fAudioMenu );
-       fAudioMenu->AddItem( fLanguageMenu );
-       fAudioMenu->AddItem( fSubtitlesMenu );
-
-       fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
-       fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
-       fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
-       fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
-
-       /* Add the Navigation menu */
-       fNavigationMenu = new BMenu( "Navigation" );
-       fMenuBar->AddItem( fNavigationMenu );
-       fNavigationMenu->AddItem( fPrevTitleMI );
-       fNavigationMenu->AddItem( fNextTitleMI );
-       fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
-       fNavigationMenu->AddSeparatorItem();
-       fNavigationMenu->AddItem( fPrevChapterMI );
-       fNavigationMenu->AddItem( fNextChapterMI );
-       fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
-
-       /* Add the Speed menu */
-       fSpeedMenu = new BMenu( "Speed" );
-       fSpeedMenu->SetRadioMode( true );
-       fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
-       fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
-       fNormalMI->SetMarked(true); // default to normal speed
-       fSpeedMenu->AddItem( fNormalMI );
-       fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
-       fSpeedMenu->SetTargetForItems( this );
-       fMenuBar->AddItem( fSpeedMenu );
-
-    /* Add the Settings menu */
-    fSettingsMenu = new BMenu( "Settings" );
-    fSettingsMenu->AddItem( fPreferencesMI =
-        new BMenuItem( "Preferences", new BMessage( OPEN_PREFERENCES ) ) );
-       fMenuBar->AddItem( fSettingsMenu );                                                     
-
-       // prepare fow showing
-       _SetMenusEnabled(false);
-
-       _RestoreSettings();
-
-       Show();
+    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 ); \
+    snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
+
+    BScreen screen;
+    BRect screen_rect = screen.Frame();
+    BRect window_rect;
+    window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
+                     ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
+                     ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
+                     ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
+    fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
+    window_rect.Set( screen_rect.right - 500,
+                     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
+    p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
+    p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
+
+    float width, height;
+    p_mediaControl->GetPreferredSize( &width, &height );
+
+    // set up the main menu
+    fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
+                             B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
+
+    // make menu bar resize to correct height
+    float menuWidth, menuHeight;
+    fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
+    fMenuBar->ResizeTo( width, menuHeight );    // don't change! it's a workarround!
+    // take care of proper size for ourself
+    height += fMenuBar->Bounds().Height();
+    ResizeTo( width, height );
+
+    p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
+    AddChild( fMenuBar );
+
+
+    // Add the file Menu
+    BMenu* fileMenu = new BMenu( _("File") );
+    fMenuBar->AddItem( fileMenu );
+    ADD_ELLIPSIS( _("Open File") );
+    fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
+    fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
+    ADD_ELLIPSIS( _("Open Subtitles") );
+    fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );
+
+    fileMenu->AddSeparatorItem();
+    ADD_ELLIPSIS( _("About") );
+    BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
+    item->SetTarget( be_app );
+    fileMenu->AddItem( item );
+    fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
+
+    fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
+    fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );
+
+    /* Add the Audio menu */
+    fAudioMenu = new BMenu( _("Audio") );
+    fMenuBar->AddItem ( fAudioMenu );
+    fAudioMenu->AddItem( fLanguageMenu );
+    fAudioMenu->AddItem( fSubtitlesMenu );
+
+    fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
+    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 ) );
+
+    /* Add the Navigation menu */
+    fNavigationMenu = new BMenu( _("Navigation") );
+    fMenuBar->AddItem( fNavigationMenu );
+    fNavigationMenu->AddItem( fPrevTitleMI );
+    fNavigationMenu->AddItem( fNextTitleMI );
+    fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
+    fNavigationMenu->AddSeparatorItem();
+    fNavigationMenu->AddItem( fPrevChapterMI );
+    fNavigationMenu->AddItem( fNextChapterMI );
+    fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
+
+    /* Add the Speed menu */
+    fSpeedMenu = new BMenu( _("Speed") );
+    fSpeedMenu->SetRadioMode( true );
+    fSpeedMenu->AddItem(
+        fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
+    fSpeedMenu->AddItem(
+        fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
+    fSpeedMenu->AddItem(
+        fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
+    fSpeedMenu->AddItem(
+        fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
+    fSpeedMenu->AddItem(
+        fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
+    fSpeedMenu->AddItem(
+        fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
+    fSpeedMenu->AddItem(
+        fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
+    fMenuBar->AddItem( fSpeedMenu );
+
+    /* 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") );
+    fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
+    fMenuBar->AddItem( fShowMenu );
+
+    // add the media control view after the menubar is complete
+    // because it will set the window size limits in AttachedToWindow()
+    // and the menubar needs to report the correct PreferredSize()
+    AddChild( p_mediaControl );
+
+    /* Prepare fow showing */
+    _SetMenusEnabled( false );
+    p_mediaControl->SetEnabled( false );
+
+    _RestoreSettings();
+
+    Show();
 }
 
 InterfaceWindow::~InterfaceWindow()
 {
-       if (fPlaylistWindow)
-               fPlaylistWindow->ReallyQuit();
-       delete fSettings;
+    if( p_input )
+    {
+        vlc_object_release( p_input );
+    }
+    if( p_playlist )
+    {
+        vlc_object_release( p_playlist );
+    }
+#if 0
+    if( fPlaylistWindow )
+    {
+        fPlaylistWindow->ReallyQuit();
+    }
+#endif
+    if( fMessagesWindow )
+    {
+        fMessagesWindow->ReallyQuit();
+    }
+    if( fPreferencesWindow )
+    {
+        fPreferencesWindow->ReallyQuit();
+    }
+    delete fFilePanel;
+    delete fSettings;
 }
 
 /*****************************************************************************
@@ -192,12 +380,12 @@ InterfaceWindow::~InterfaceWindow()
 void
 InterfaceWindow::FrameResized(float width, float height)
 {
-       BRect r(Bounds());
-       fMenuBar->MoveTo(r.LeftTop());
-       fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
-       r.top += fMenuBar->Bounds().Height() + 1.0;
-       p_mediaControl->MoveTo(r.LeftTop());
-       p_mediaControl->ResizeTo(r.Width(), r.Height());
+    BRect r(Bounds());
+    fMenuBar->MoveTo(r.LeftTop());
+    fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
+    r.top += fMenuBar->Bounds().Height() + 1.0;
+    p_mediaControl->MoveTo(r.LeftTop());
+    p_mediaControl->ResizeTo(r.Width(), r.Height());
 }
 
 /*****************************************************************************
@@ -205,287 +393,404 @@ InterfaceWindow::FrameResized(float width, float height)
  *****************************************************************************/
 void InterfaceWindow::MessageReceived( BMessage * p_message )
 {
-       int playback_status;      // remember playback state
-       playback_status = p_intf->p_sys->p_vlc_wrapper->inputGetStatus();
-
-       switch( p_message->what )
-       {
-               case B_ABOUT_REQUESTED:
-               {
-                       BAlert* alert = new BAlert( VOUT_TITLE,
-                                                                               "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
-                       alert->Go();
-                       break;
-               }
-               case TOGGLE_ON_TOP:
-                       break;
-                       
-               case OPEN_FILE:
-                       if( fFilePanel )
-                       {
-                               fFilePanel->Show();
-                               break;
-                       }
-                       fFilePanel = new BFilePanel();
-                       fFilePanel->SetTarget( this );
-                       fFilePanel->Show();
-                       break;
-       
-               case OPEN_PLAYLIST:
-                       if (fPlaylistWindow->Lock())
-                       {
-                               if (fPlaylistWindow->IsHidden())
-                                       fPlaylistWindow->Show();
-                               else
-                                       fPlaylistWindow->Activate();
-                               fPlaylistWindow->Unlock();
-                       }
-                       break;
-               case OPEN_DVD:
-                       {
-                               const char *psz_device;
-                               BString type( "dvd" );
-                               if( p_message->FindString( "device", &psz_device ) == B_OK )
-                               {
-                                       BString device( psz_device );
-                                       p_intf->p_sys->p_vlc_wrapper->openDisc( type, device, 0, 0 );
-                               }
-                               _UpdatePlaylist();
-                       }
-                       break;
-       
-               case STOP_PLAYBACK:
-                       // this currently stops playback not nicely
-                       if (playback_status > UNDEF_S)
-                       {
-                               p_intf->p_sys->p_vlc_wrapper->volume_mute();
-                               snooze( 400000 );
-                               p_intf->p_sys->p_vlc_wrapper->playlistStop();
-                               p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
-                       }
-                       break;
-       
-               case START_PLAYBACK:
-                       /*  starts playing in normal mode */
-       
-               case PAUSE_PLAYBACK:
-                       /* toggle between pause and play */
-                       if (playback_status > UNDEF_S)
-                       {
-                               /* pause if currently playing */
-                               if ( playback_status == PLAYING_S )
-                               {
-                                       p_intf->p_sys->p_vlc_wrapper->volume_mute();
-                                       snooze( 400000 );
-                                       p_intf->p_sys->p_vlc_wrapper->playlistPause();
-                               }
-                               else
-                               {
-                                       p_intf->p_sys->p_vlc_wrapper->volume_restore();
-                                       p_intf->p_sys->p_vlc_wrapper->playlistPlay();
-                               }
-                       }
-                       else
-                       {
-                               /* Play a new file */
-                               p_intf->p_sys->p_vlc_wrapper->playlistPlay();
-                       }       
-                       break;
-       
-               case FASTER_PLAY:
-                       /* cycle the fast playback modes */
-                       if (playback_status > UNDEF_S)
-                       {
-                               p_intf->p_sys->p_vlc_wrapper->volume_mute();
-                               snooze( 400000 );
-                               p_intf->p_sys->p_vlc_wrapper->playFaster();
-                       }
-                       break;
-       
-               case SLOWER_PLAY:
-                       /*  cycle the slow playback modes */
-                       if (playback_status > UNDEF_S)
-                       {
-                               p_intf->p_sys->p_vlc_wrapper->volume_mute();
-                               snooze( 400000 );
-                               p_intf->p_sys->p_vlc_wrapper->playSlower();
-                       }
-                       break;
-       
-               case NORMAL_PLAY:
-                       /*  restore speed to normal if already playing */
-                       if (playback_status > UNDEF_S)
-                       {
-                               p_intf->p_sys->p_vlc_wrapper->volume_restore();
-                               p_intf->p_sys->p_vlc_wrapper->playlistPlay();
-                       }
-                       break;
-       
-               case SEEK_PLAYBACK:
-                       /* handled by semaphores */
-                       break;
-               // volume related messages
-               case VOLUME_CHG:
-                       /* adjust the volume */
-                       if (playback_status > UNDEF_S)
-                       {
-                               p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
-                               p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
-                       }
-                       break;
-       
-               case VOLUME_MUTE:
-                       // toggle muting
-                       p_intf->p_sys->p_vlc_wrapper->toggle_mute();
-                       p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
-                       break;
-       
-               case SELECT_CHANNEL:
-                       if ( playback_status > UNDEF_S )
-                       {
-                               int32 channel;
-                               if ( p_message->FindInt32( "channel", &channel ) == B_OK )
-                               {
-                                       p_intf->p_sys->p_vlc_wrapper->toggleLanguage( channel );
-                                       // vlc seems to remember the volume for every channel,
-                                       // but I would assume that to be somewhat annoying to the user
-                                       // the next call will also unmute the volume, which is probably
-                                       // desired as well, because if the user selects another language,
-                                       // he probably wants to hear the change as well
-                                       snooze( 400000 );       // we have to wait a bit, or the change will be reverted
-                                       p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
-                               }
-                       }
-                       break;
-       
-               case SELECT_SUBTITLE:
-                       if ( playback_status > UNDEF_S )
-                       {
-                               int32 subtitle;
-                               if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
-                                       p_intf->p_sys->p_vlc_wrapper->toggleSubtitle( subtitle );
-                       }
-                       break;
-       
-               // specific navigation messages
-               case PREV_TITLE:
-               {
-                       int             i_id;
-            i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id - 1;
-
-            /* Disallow area 0 since it is used for video_ts.vob */
-            if( i_id > 0 )
+    switch( p_message->what )
+    {
+        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"
+                                "http://www.videolan.org/", _("OK") );
+            alert->Go();
+            break;
+        }
+        case TOGGLE_ON_TOP:
+            break;
+
+        case OPEN_FILE:
+            _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
+            break;
+
+        case LOAD_SUBFILE:
+            _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
+            break;
+#if 0
+        case OPEN_PLAYLIST:
+            if (fPlaylistWindow->Lock())
+            {
+                if (fPlaylistWindow->IsHidden())
+                    fPlaylistWindow->Show();
+                else
+                    fPlaylistWindow->Activate();
+                fPlaylistWindow->Unlock();
+            }
+            break;
+#endif
+        case OPEN_DVD:
+            {
+                const char * psz_device;
+                if( p_playlist &&
+                    p_message->FindString( "device", &psz_device ) == B_OK )
+                {
+                    char psz_uri[1024];
+                    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, true );
+                }
+                UpdatePlaylist();
+            }
+            break;
+
+        case SUBFILE_RECEIVED:
+        {
+            entry_ref ref;
+            if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
+            {
+                BPath path( &ref );
+                if ( path.InitCheck() == B_OK )
+                    config_PutPsz( p_intf, "sub-file", path.Path() );
+            }
+            break;
+        }
+
+        case STOP_PLAYBACK:
+            if( p_playlist )
+            {
+                playlist_Stop( p_playlist );
+            }
+            p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
+            break;
+
+        case START_PLAYBACK:
+        case PAUSE_PLAYBACK:
+        {
+            vlc_value_t val;
+            val.i_int = PLAYING_S;
+            if( p_input )
+            {
+                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 )
+            {
+                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
+            }
+            break;
+
+        case QUARTER_PLAY:
+            if( p_input )
+            {
+                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
+            }
+            break;
+
+        case HALF_PLAY:
+            if( p_input )
+            {
+                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
+            }
+            break;
+
+        case NORMAL_PLAY:
+            if( p_input )
+            {
+                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
+            }
+            break;
+
+        case TWICE_PLAY:
+            if( p_input )
+            {
+                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
+            }
+            break;
+
+        case FOUR_PLAY:
+            if( p_input )
+            {
+                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
+            }
+            break;
+
+        case HEIGHT_PLAY:
+            if( p_input )
+            {
+                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
+            }
+            break;
+
+        case SEEK_PLAYBACK:
+            /* handled by semaphores */
+            break;
+
+        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;
+            if( p_input )
+            {
+                if( p_message->FindInt32( "audio-es", &channel ) == B_OK )
+                {
+                    var_SetInteger( p_input, "audio-es", channel );
+                }
+                else if( p_message->FindInt32( "spu-es", &channel ) == B_OK )
+                {
+                    var_SetInteger( p_input, "spu-es", channel );
+                }
+            }
+            break;
+        }
+
+        case PREV_TITLE:
+            if( p_input )
+            {
+                var_SetVoid( p_input, "prev-title" );
+            }
+            break;
+
+        case NEXT_TITLE:
+            if( p_input )
+            {
+                var_SetVoid( p_input, "next-title" );
+            }
+            break;
+
+        case TOGGLE_TITLE:
+        {
+            int32 index;
+            if( p_input &&
+                p_message->FindInt32( "index", &index ) == B_OK )
+            {
+                var_SetInteger( p_input, "title", index );
+            }
+            break;
+        }
+
+        case PREV_CHAPTER:
+            if( p_input )
+            {
+                var_SetVoid( p_input, "prev-chapter" );
+            }
+            break;
+
+        case NEXT_CHAPTER:
+            if( p_input )
+            {
+                var_SetVoid( p_input, "next-chapter" );
+            }
+            break;
+
+        case TOGGLE_CHAPTER:
+        {
+            int32 index;
+            if( p_input &&
+                p_message->FindInt32( "index", &index ) == B_OK )
+            {
+                var_SetInteger( p_input, "chapter", index );
+            }
+            break;
+        }
+
+        case PREV_FILE:
+            if( p_playlist )
+            {
+                playlist_Prev( p_playlist );
+            }
+            break;
+
+        case NEXT_FILE:
+            if( p_playlist )
+            {
+                playlist_Next( p_playlist );
+            }
+            break;
+
+        case NAVIGATE_PREV:
+            if( p_input )
             {
-                p_intf->p_sys->p_vlc_wrapper->toggleTitle(i_id);
+                vlc_value_t val;
+
+                /* First try to go to previous chapter */
+                if( !var_Get( p_input, "chapter", &val ) )
+                {
+                    if( val.i_int > 1 )
+                    {
+                        var_SetVoid( p_input, "prev-chapter" );
+                        break;
+                    }
+                }
+
+                /* Try to go to previous title */
+                if( !var_Get( p_input, "title", &val ) )
+                {
+                    if( val.i_int > 1 )
+                    {
+                        var_SetVoid( p_input, "prev-title" );
+                        break;
+                    }
+                }
+
+                /* Try to go to previous file */
+                if( p_playlist )
+                {
+                    playlist_Prev( p_playlist );
+                }
             }
-                       break;
-               }
-               case NEXT_TITLE:
-               {
-                       int             i_id;
+            break;
 
-            i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
+        case NAVIGATE_NEXT:
+            if( p_input )
+            {
+                vlc_value_t val, val_list;
+
+                /* First try to go to next chapter */
+                if( !var_Get( p_input, "chapter", &val ) )
+                {
+                    var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
+                                &val_list, NULL );
+                    if( val_list.p_list->i_count > val.i_int )
+                    {
+                        var_Change( p_input, "chapter", VLC_VAR_FREELIST,
+                                    &val_list, NULL );
+                        var_SetVoid( p_input, "next-chapter" );
+                        break;
+                    }
+                    var_Change( p_input, "chapter", VLC_VAR_FREELIST,
+                                &val_list, NULL );
+                }
+
+                /* Try to go to next title */
+                if( !var_Get( p_input, "title", &val ) )
+                {
+                    var_Change( p_input, "title", VLC_VAR_GETCHOICES,
+                                &val_list, NULL );
+                    if( val_list.p_list->i_count > val.i_int )
+                    {
+                        var_Change( p_input, "title", VLC_VAR_FREELIST,
+                                    &val_list, NULL );
+                        var_SetVoid( p_input, "next-title" );
+                        break;
+                    }
+                    var_Change( p_input, "title", VLC_VAR_FREELIST,
+                                &val_list, NULL );
+                }
+
+                /* Try to go to next file */
+                if( p_playlist )
+                {
+                    playlist_Next( p_playlist );
+                }
+            }
+            break;
 
-            if( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
+        // drag'n'drop and system messages
+        case MSG_SOUNDPLAY:
+            // convert soundplay drag'n'drop message (containing paths)
+            // to normal message (containing refs)
             {
-                p_intf->p_sys->p_vlc_wrapper->toggleTitle(i_id);
+                const char* path;
+                for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
+                {
+                    entry_ref ref;
+                    if ( get_ref_for_path( path, &ref ) == B_OK )
+                        p_message->AddRef( "refs", &ref );
+                }
             }
-                       break;
-               }
-               case TOGGLE_TITLE:
-                       if ( playback_status > UNDEF_S )
-                       {
-                               int32 index;
-                               if ( p_message->FindInt32( "index", &index ) == B_OK )
-                                       p_intf->p_sys->p_vlc_wrapper->toggleTitle( index );
-                       }
-                       break;
-               case PREV_CHAPTER:
-               {
-                       int             i_id;
-
-            i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part - 1;
-
-            if( i_id >= 0 )
+            // fall through
+        case B_REFS_RECEIVED:
+        case B_SIMPLE_DATA:
+        {
+            /* file(s) opened by the File menu -> append to the playlist;
+               file(s) opened by drag & drop -> replace playlist;
+               file(s) opened by 'shift' + drag & drop -> append */
+
+            int32 count;
+            type_code dummy;
+            if( p_message->GetInfo( "refs", &dummy, &count ) != B_OK ||
+                count < 1 )
             {
-                p_intf->p_sys->p_vlc_wrapper->toggleChapter(i_id);
+                break;
             }
-                       break;
-               }
-               case NEXT_CHAPTER:
-               {
-                       int             i_id;
 
-            i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part + 1;
+            bool b_remove = ( p_message->WasDropped() &&
+                                    !( modifiers() & B_SHIFT_KEY ) );
 
-            if( i_id >= 0 )
+            if( b_remove && p_playlist )
             {
-                p_intf->p_sys->p_vlc_wrapper->toggleChapter(i_id);
+                playlist_Clear( p_playlist, true );
             }
-                       break;
-               }
-               case TOGGLE_CHAPTER:
-                       if ( playback_status > UNDEF_S )
-                       {
-                               int32 index;
-                               if ( p_message->FindInt32( "index", &index ) == B_OK )
-                                       p_intf->p_sys->p_vlc_wrapper->toggleChapter( index );
-                       }
-                       break;
-               case PREV_FILE:
-                       p_intf->p_sys->p_vlc_wrapper->playlistPrev();
-                       break;
-               case NEXT_FILE:
-                       p_intf->p_sys->p_vlc_wrapper->playlistNext();
-                       break;
-               // general next/prev functionality (skips to whatever makes most sense)
-               case NAVIGATE_PREV:
-                       p_intf->p_sys->p_vlc_wrapper->navigatePrev();
-                       break;
-               case NAVIGATE_NEXT:
-                       p_intf->p_sys->p_vlc_wrapper->navigateNext();
-                       break;
-               // drag'n'drop and system messages
-               case B_REFS_RECEIVED:
-               case B_SIMPLE_DATA:
-                       {
-                               // figure out if user wants files replaced or added
-                               bool replace = false;
-                               if ( p_message->WasDropped() )
-                                       replace = !( modifiers() & B_SHIFT_KEY );
-                               // build list of files to be played from message contents
-                               entry_ref ref;
-                               BList files;
-                               for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
-                               {
-                                       BPath path( &ref );
-                                       if ( path.InitCheck() == B_OK )
-                                               // the BString objects will be deleted
-                                               // by the wrapper function further down
-                                               files.AddItem( new BString( (char*)path.Path() ) );
-                               }
-                               // give the list to VLC
-                               p_intf->p_sys->p_vlc_wrapper->openFiles(&files, replace);
-                               _UpdatePlaylist();
-                       }
-                       break;
-
-               case OPEN_PREFERENCES:
-                   if( fPreferencesWindow->Lock() )
-                   {
-                           if (fPreferencesWindow->IsHidden())
-                                   fPreferencesWindow->Show();
-                           else
-                                   fPreferencesWindow->Activate();
-                               fPreferencesWindow->Unlock();
-                       }
-                       break;
-                               
-               default:
-                       BWindow::MessageReceived( p_message );
-                       break;
-       }
 
+            entry_ref ref;
+            for( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
+            {
+                BPath path( &ref );
+
+                /* TODO: find out if this is a DVD icon */
+
+                if( p_playlist )
+                {
+                    playlist_Add( p_playlist, path.Path(), NULL,
+                       PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
+                }
+            }
+
+            UpdatePlaylist();
+            break;
+        }
+
+        case OPEN_PREFERENCES:
+        {
+            if( fPreferencesWindow->Lock() )
+            {
+                if (fPreferencesWindow->IsHidden())
+                    fPreferencesWindow->Show();
+                else
+                    fPreferencesWindow->Activate();
+                fPreferencesWindow->Unlock();
+            }
+            break;
+        }
+
+        case OPEN_MESSAGES:
+        {
+            if( fMessagesWindow->Lock() )
+            {
+                if (fMessagesWindow->IsHidden())
+                    fMessagesWindow->Show();
+                else
+                    fMessagesWindow->Activate();
+                fMessagesWindow->Unlock();
+            }
+            break;
+        }
+        case MSG_UPDATE:
+            UpdateInterface();
+            break;
+        default:
+            BWindow::MessageReceived( p_message );
+            break;
+    }
 }
 
 /*****************************************************************************
@@ -493,116 +798,124 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
  *****************************************************************************/
 bool InterfaceWindow::QuitRequested()
 {
-       if (p_intf->p_sys->p_input)
-       {
-               p_intf->p_sys->p_vlc_wrapper->volume_mute();
-               snooze( 400000 );
-               p_intf->p_sys->p_vlc_wrapper->playlistStop();
-               p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
-       }
-       
-       p_intf->b_die = 1;
-
-       _StoreSettings();
-
-       return( true );
+    if( p_playlist )
+    {
+        playlist_Stop( p_playlist );
+    }
+    p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
+
+     _StoreSettings();
+
+    vlc_object_kill( p_intf );
+
+    return( true );
 }
 
 /*****************************************************************************
- * InterfaceWindow::updateInterface
+ * InterfaceWindow::UpdateInterface
  *****************************************************************************/
-void InterfaceWindow::updateInterface()
+void InterfaceWindow::UpdateInterface()
 {
-       input_thread_t* input = p_intf->p_sys->p_input;
-       if ( input )
-       {
-               if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
-               {
-                   p_intf->p_sys->p_vlc_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
-               }
-               else if ( Lock() )
-               {
-                       bool hasTitles = input->stream.i_area_nb > 1;
-                       bool hasChapters = input->stream.p_selected_area->i_part_nb > 1;
-                       p_mediaControl->SetStatus( input->stream.control.i_status, 
-                                                                          input->stream.control.i_rate );
-                       p_mediaControl->SetProgress( input->stream.p_selected_area->i_tell,
-                                                                                input->stream.p_selected_area->i_size );
-                       _SetMenusEnabled( true, hasChapters, hasTitles );
-
-                       _UpdateSpeedMenu( input->stream.control.i_rate );
-
-                       // enable/disable skip buttons
-                       bool canSkipPrev;
-                       bool canSkipNext;
-                       p_intf->p_sys->p_vlc_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
-                       p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
-
-                       if ( p_intf->p_sys->p_vlc_wrapper->has_audio() )
-                       {
-                               p_mediaControl->SetAudioEnabled( true );
-                               p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
-                       } else
-                               p_mediaControl->SetAudioEnabled( false );
-
-                       if ( input != fInputThread )
-                       {
-                               fInputThread = input;
-                               _InputStreamChanged();
-                       }
-
-                       Unlock();
-               }
-               // update playlist as well
-               if ( fPlaylistWindow->Lock() )
-               {
-                       fPlaylistWindow->UpdatePlaylist();
-                       fPlaylistWindow->Unlock();
-               }
-       }
-       else
-               _SetMenusEnabled(false);
-
-       playlist_t *p_playlist = p_intf->p_sys->p_playlist;
-       
-       if ( fPlaylistIsEmpty != ( p_playlist->i_size < 0) )
-       {
-               if ( Lock() )
-               {
-                       fPlaylistIsEmpty = !fPlaylistIsEmpty;
-                       p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
-                       Unlock();
-               }
-       }
-       if ( input != fInputThread )
-               fInputThread = input;
-
-       fLastUpdateTime = system_time();
+    if( !p_input )
+    {
+        p_input = (input_thread_t *)
+            vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    }
+    else if( p_input->b_dead )
+    {
+        vlc_object_release( p_input );
+        p_input = NULL;
+    }
+
+    /* Get ready to update the interface */
+    if( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) != B_OK )
+    {
+        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" ),
+                                   var_GetInteger( p_input, "rate" ) );
+        var_Get( p_input, "position", &val );
+        p_mediaControl->SetProgress( val.f_float );
+        _SetMenusEnabled( true, hasChapters, hasTitles );
+        _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
+
+        // enable/disable skip buttons
+#if 0
+        bool canSkipPrev;
+        bool canSkipNext;
+        p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
+        p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
+#endif
+
+        audio_volume_t i_volume;
+        aout_VolumeGet( p_intf, &i_volume );
+        p_mediaControl->SetAudioEnabled( true );
+        p_mediaControl->SetMuted( i_volume );
+    }
+    else
+    {
+        p_mediaControl->SetAudioEnabled( false );
+
+        _SetMenusEnabled( false );
+
+        if( !playlist_IsEmpty( p_playlist ) )
+        {
+            p_mediaControl->SetProgress( 0 );
+
+#if 0
+            // enable/disable skip buttons
+            bool canSkipPrev;
+            bool canSkipNext;
+            p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
+            p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
+#endif
+        }
+        else
+        {
+            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();
-               playlist_t *p_playlist = p_intf->p_sys->p_playlist;
-               fPlaylistIsEmpty = p_playlist->i_size < 1;
-               p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
-       }
+    return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
 }
 
 /*****************************************************************************
@@ -611,37 +924,37 @@ InterfaceWindow::_UpdatePlaylist()
 void
 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
 {
-       if (!hasFile)
-       {
-               hasChapters = false;
-               hasTitles = false;
-       }
-       if (Lock())
-       {
-               if (fNextChapterMI->IsEnabled() != hasChapters)
-                       fNextChapterMI->SetEnabled(hasChapters);
-               if (fPrevChapterMI->IsEnabled() != hasChapters)
-                       fPrevChapterMI->SetEnabled(hasChapters);
-               if (fChapterMenu->IsEnabled() != hasChapters)
-                       fChapterMenu->SetEnabled(hasChapters);
-               if (fNextTitleMI->IsEnabled() != hasTitles)
-                       fNextTitleMI->SetEnabled(hasTitles);
-               if (fPrevTitleMI->IsEnabled() != hasTitles)
-                       fPrevTitleMI->SetEnabled(hasTitles);
-               if (fTitleMenu->IsEnabled() != hasTitles)
-                       fTitleMenu->SetEnabled(hasTitles);
-               if (fAudioMenu->IsEnabled() != hasFile)
-                       fAudioMenu->SetEnabled(hasFile);
-               if (fNavigationMenu->IsEnabled() != hasFile)
-                       fNavigationMenu->SetEnabled(hasFile);
-               if (fLanguageMenu->IsEnabled() != hasFile)
-                       fLanguageMenu->SetEnabled(hasFile);
-               if (fSubtitlesMenu->IsEnabled() != hasFile)
-                       fSubtitlesMenu->SetEnabled(hasFile);
-               if (fSpeedMenu->IsEnabled() != hasFile)
-                       fSpeedMenu->SetEnabled(hasFile);
-               Unlock();
-       }
+    if (!hasFile)
+    {
+        hasChapters = false;
+        hasTitles = false;
+    }
+    if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
+    {
+        if ( fNextChapterMI->IsEnabled() != hasChapters )
+             fNextChapterMI->SetEnabled( hasChapters );
+        if ( fPrevChapterMI->IsEnabled() != hasChapters )
+             fPrevChapterMI->SetEnabled( hasChapters );
+        if ( fChapterMenu->IsEnabled() != hasChapters )
+             fChapterMenu->SetEnabled( hasChapters );
+        if ( fNextTitleMI->IsEnabled() != hasTitles )
+             fNextTitleMI->SetEnabled( hasTitles );
+        if ( fPrevTitleMI->IsEnabled() != hasTitles )
+             fPrevTitleMI->SetEnabled( hasTitles );
+        if ( fTitleMenu->IsEnabled() != hasTitles )
+             fTitleMenu->SetEnabled( hasTitles );
+        if ( fAudioMenu->IsEnabled() != hasFile )
+             fAudioMenu->SetEnabled( hasFile );
+        if ( fNavigationMenu->IsEnabled() != hasFile )
+             fNavigationMenu->SetEnabled( hasFile );
+        if ( fLanguageMenu->IsEnabled() != hasFile )
+             fLanguageMenu->SetEnabled( hasFile );
+        if ( fSubtitlesMenu->IsEnabled() != hasFile )
+             fSubtitlesMenu->SetEnabled( hasFile );
+        if ( fSpeedMenu->IsEnabled() != hasFile )
+             fSpeedMenu->SetEnabled( hasFile );
+        Unlock();
+    }
 }
 
 /*****************************************************************************
@@ -650,134 +963,103 @@ InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles
 void
 InterfaceWindow::_UpdateSpeedMenu( int rate )
 {
-       if ( rate == DEFAULT_RATE )
-       {
-               if ( !fNormalMI->IsMarked() )
-                       fNormalMI->SetMarked( true );
-       }
-       else if ( rate < DEFAULT_RATE )
-       {
-               if ( !fFasterMI->IsMarked() )
-                       fFasterMI->SetMarked( true );
-       }
-       else
-       {
-               if ( !fSlowerMI->IsMarked() )
-                       fSlowerMI->SetMarked( true );
-       }
+    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;
+    }
+
+    if ( toMark && !toMark->IsMarked() )
+    {
+        toMark->SetMarked( true );
+    }
 }
 
 /*****************************************************************************
- * InterfaceWindow::_InputStreamChanged
+ * InterfaceWindow::_ShowFilePanel
  *****************************************************************************/
 void
-InterfaceWindow::_InputStreamChanged()
-{
-//printf("InterfaceWindow::_InputStreamChanged()\n");
-       // TODO: move more stuff from updateInterface() here!
-       snooze( 400000 );
-       p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
-}
-
-/*****************************************************************************
- * InterfaceWindow::_LoadSettings
- *****************************************************************************/
-status_t
-InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
+InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
 {
-       status_t ret = B_BAD_VALUE;
-       if ( message )
-       {
-               BPath path;
-               if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
-               {
-                       // passing folder is optional
-                       if ( folder )
-                               ret = path.Append( folder );
-                       if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
-                       {
-                               BFile file( path.Path(), B_READ_ONLY );
-                               if ( ( ret = file.InitCheck() ) == B_OK )
-                               {
-                                       ret = message->Unflatten( &file );
-                                       file.Unset();
-                               }
-                       }
-               }
-       }
-       return ret;
+    if( !fFilePanel )
+    {
+        fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
+                                     B_FILE_NODE | B_DIRECTORY_NODE );
+        fFilePanel->SetTarget( this );
+    }
+    fFilePanel->Window()->SetTitle( windowTitle );
+    BMessage message( command );
+    fFilePanel->SetMessage( &message );
+    if ( !fFilePanel->IsShowing() )
+    {
+        fFilePanel->Refresh();
+        fFilePanel->Show();
+    }
 }
 
-/*****************************************************************************
- * InterfaceWindow::_SaveSettings
- *****************************************************************************/
-status_t
-InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
-{
-       status_t ret = B_BAD_VALUE;
-       if ( message )
-       {
-               BPath path;
-               if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
-               {
-                       // passing folder is optional
-                       if ( folder && ( ret = path.Append( folder ) ) == B_OK )
-                               ret = create_directory( path.Path(), 0777 );
-                       if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
-                       {
-                               BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
-                               if ( ( ret = file.InitCheck() ) == B_OK )
-                               {
-                                       ret = message->Flatten( &file );
-                                       file.Unset();
-                               }
-                       }
-               }
-       }
-       return ret;
-}
-
-/*****************************************************************************
- * InterfaceWindow::_RestoreSettings
- *****************************************************************************/
-bool
-make_sure_frame_is_on_screen( BRect& frame )
+// set_window_pos
+void
+set_window_pos( BWindow* window, BRect frame )
 {
-       BScreen screen( B_MAIN_SCREEN_ID );
-       if (frame.IsValid() && screen.IsValid()) {
-               if (!screen.Frame().Contains(frame)) {
-                       // make sure frame fits in the screen
-                       if (frame.Width() > screen.Frame().Width())
-                               frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
-                       if (frame.Height() > screen.Frame().Height())
-                               frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
-                       // frame is now at the most the size of the screen
-                       if (frame.right > screen.Frame().right)
-                               frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
-                       if (frame.bottom > screen.Frame().bottom)
-                               frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
-                       if (frame.left < screen.Frame().left)
-                               frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
-                       if (frame.top < screen.Frame().top)
-                               frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
-               }
-               return true;
-       }
-       return false;
+    // sanity checks: make sure window is not too big/small
+    // and that it's not off-screen
+    float minWidth, maxWidth, minHeight, maxHeight;
+    window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
+
+    make_sure_frame_is_within_limits( frame,
+                                      minWidth, minHeight, maxWidth, maxHeight );
+    if ( make_sure_frame_is_on_screen( frame ) )
+    {
+        window->MoveTo( frame.LeftTop() );
+        window->ResizeTo( frame.Width(), frame.Height() );
+    }
 }
 
+// set_window_pos
 void
-make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
-                                                                 float maxWidth, float maxHeight )
+launch_window( BWindow* window, bool showing )
 {
-       if ( frame.Width() < minWidth )
-               frame.right = frame.left + minWidth;
-       if ( frame.Height() < minHeight )
-               frame.bottom = frame.top + minHeight;
-       if ( frame.Width() > maxWidth )
-               frame.right = frame.left + maxWidth;
-       if ( frame.Height() > maxHeight )
-               frame.bottom = frame.top + maxHeight;
+    if ( window->Lock() )
+    {
+        if ( showing )
+        {
+            if ( window->IsHidden() )
+                window->Show();
+        }
+        else
+        {
+            if ( !window->IsHidden() )
+                window->Hide();
+        }
+        window->Unlock();
+    }
 }
 
 /*****************************************************************************
@@ -786,60 +1068,40 @@ make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
 void
 InterfaceWindow::_RestoreSettings()
 {
-       if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
-       {
-               BRect mainFrame;
-               if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
-               {
-                       // sanity checks: make sure window is not too big/small
-                       // and that it's not off-screen
-                       float minWidth, maxWidth, minHeight, maxHeight;
-                       GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
-
-                       make_sure_frame_is_within_limits( mainFrame,
-                                                                                         minWidth, minHeight, maxWidth, maxHeight );
-                       make_sure_frame_is_on_screen( mainFrame );
-
-
-                       MoveTo( mainFrame.LeftTop() );
-                       ResizeTo( mainFrame.Width(), mainFrame.Height() );
-               }
-               if ( fPlaylistWindow->Lock() )
-               {
-                       BRect playlistFrame;
-                       if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
-                       {
-                               // sanity checks: make sure window is not too big/small
-                               // and that it's not off-screen
-                               float minWidth, maxWidth, minHeight, maxHeight;
-                               fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
-
-                               make_sure_frame_is_within_limits( playlistFrame,
-                                                                                                 minWidth, minHeight, maxWidth, maxHeight );
-                               make_sure_frame_is_on_screen( playlistFrame );
-
-                               fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
-                               fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
-                       }
-                       
-                       bool showing;
-                       if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
-                       {
-                               if ( showing )
-                               {
-                                       if ( fPlaylistWindow->IsHidden() )
-                                               fPlaylistWindow->Show();
-                               }
-                               else
-                               {
-                                       if ( !fPlaylistWindow->IsHidden() )
-                                               fPlaylistWindow->Hide();
-                               }
-                       }
-
-                       fPlaylistWindow->Unlock();
-               }
-       }
+    if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
+    {
+        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 )
+        {
+            /* FIXME: Preferences resizing doesn't work correctly yet */
+            frame.right = frame.left + fPreferencesWindow->Frame().Width();
+            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
+    }
 }
 
 /*****************************************************************************
@@ -848,24 +1110,53 @@ InterfaceWindow::_RestoreSettings()
 void
 InterfaceWindow::_StoreSettings()
 {
-       if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
-               fSettings->AddRect( "main frame", Frame() );
-       if ( fPlaylistWindow->Lock() )
-       {
-               if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
-                       fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
-               if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
-                       fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
-               fPlaylistWindow->Unlock();
-       }
-       _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
+    /* Save the volume */
+    config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
+    config_SaveConfigFile( p_intf, "main" );
+
+    /* 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)
+            fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
+        if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
+            fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
+        fPlaylistWindow->Unlock();
+    }
+#endif
+    if ( fMessagesWindow->Lock() )
+    {
+        if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
+            fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
+        if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
+            fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
+        fMessagesWindow->Unlock();
+    }
+    if ( fPreferencesWindow->Lock() )
+    {
+        if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
+            fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
+        if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
+            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" );
 }
 
+
 /*****************************************************************************
  * CDMenu::CDMenu
  *****************************************************************************/
 CDMenu::CDMenu(const char *name)
-         : BMenu(name)
+      : BMenu(name)
 {
 }
 
@@ -881,11 +1172,11 @@ CDMenu::~CDMenu()
  *****************************************************************************/
 void CDMenu::AttachedToWindow(void)
 {
-       // remove all items
-       while (BMenuItem* item = RemoveItem(0L))
-               delete item;
-       GetCD("/dev/disk");
-       BMenu::AttachedToWindow();
+    // remove all items
+    while ( BMenuItem* item = RemoveItem( 0L ) )
+        delete item;
+    GetCD( "/dev/disk" );
+    BMenu::AttachedToWindow();
 }
 
 /*****************************************************************************
@@ -893,65 +1184,38 @@ void CDMenu::AttachedToWindow(void)
  *****************************************************************************/
 int CDMenu::GetCD( const char *directory )
 {
-       BVolumeRoster *volRoster;
-       BVolume    *vol;
-       BDirectory      *dir;
-       int                status;
-       int                mounted;   
-       char              name[B_FILE_NAME_LENGTH]; 
-       fs_info    info;
-       dev_t            dev;
-       
-       volRoster = new BVolumeRoster();
-       vol = new BVolume();
-       dir = new BDirectory();
-       status = volRoster->GetNextVolume(vol);
-       status = vol->GetRootDirectory(dir);
-       while (status ==  B_NO_ERROR)
-       {
-               mounted = vol->GetName(name);   
-               if ((mounted == B_OK) && /* Disk is currently Mounted */
-                       (vol->IsReadOnly()) ) /* Disk is read-only */
-               {
-                       dev = vol->Device();
-                       fs_stat_dev(dev, &info);
-                       
-                       device_geometry g;
-                       int i_dev;
-                       i_dev = open( info.device_name, O_RDONLY );
-                  
-                       if( i_dev >= 0 )
-                       {
-                               if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
-                               {
-                                       if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
-                                       {
-                                               BMessage *msg;
-                                               msg = new BMessage( OPEN_DVD );
-                                               msg->AddString( "device", info.device_name );
-                                               BMenuItem *menu_item;
-                                               menu_item = new BMenuItem( name, msg );
-                                               AddItem( menu_item );
-                                       }
-                                       close(i_dev);
-                               }
-                       }
-               }
-               vol->Unset();
-               status = volRoster->GetNextVolume(vol);
-       }
-       return 0;
+    BVolumeRoster volRoster;
+    BVolume vol;
+    BDirectory dir;
+    status_t status = volRoster.GetNextVolume( &vol );
+    while ( status ==  B_NO_ERROR )
+    {
+        BString deviceName;
+        BString volumeName;
+        bool isCDROM;
+        if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
+             && isCDROM )
+        {
+            BMessage* msg = new BMessage( OPEN_DVD );
+            msg->AddString( "device", deviceName.String() );
+            BMenuItem* item = new BMenuItem( volumeName.String(), msg );
+            AddItem( item );
+        }
+         vol.Unset();
+        status = volRoster.GetNextVolume( &vol );
+    }
+    return 0;
 }
 
 /*****************************************************************************
  * LanguageMenu::LanguageMenu
  *****************************************************************************/
-LanguageMenu::LanguageMenu(const char *name, int menu_kind, 
-                                                       intf_thread_t  *p_interface)
-       :BMenu(name)
+LanguageMenu::LanguageMenu( intf_thread_t * _p_intf, const char * psz_name,
+                            char * _psz_variable )
+    : BMenu( psz_name )
 {
-       kind = menu_kind;
-       p_intf = p_interface;
+    p_intf       = _p_intf;
+    psz_variable = strdup( _psz_variable );
 }
 
 /*****************************************************************************
@@ -959,6 +1223,7 @@ LanguageMenu::LanguageMenu(const char *name, int menu_kind,
  *****************************************************************************/
 LanguageMenu::~LanguageMenu()
 {
+    free( psz_variable );
 }
 
 /*****************************************************************************
@@ -966,102 +1231,53 @@ LanguageMenu::~LanguageMenu()
  *****************************************************************************/
 void LanguageMenu::AttachedToWindow()
 {
-       // remove all items
-       while ( BMenuItem* item = RemoveItem( 0L ) )
-               delete item;
-
-       SetRadioMode( true );
-       _GetChannels();
-       BMenu::AttachedToWindow();
-}
-
-/*****************************************************************************
- * LanguageMenu::_GetChannels
- *****************************************************************************/
-void LanguageMenu::_GetChannels()
-{
-       char  *psz_name;
-       bool   b_active;
-       BMessage *msg;
-       BMenuItem *menu_item;
-       int     i;
-       es_descriptor_t *p_es  = NULL;
-
-       // Insert the "None" item if in subtitle mode
-       if( kind != AUDIO_ES ) //subtitle
-       {
-               msg = new BMessage( SELECT_SUBTITLE );
-               msg->AddInt32( "subtitle", -1 );
-               menu_item = new BMenuItem( "None", msg );
-               AddItem( menu_item );
-               menu_item->SetMarked( true );
-       }
-
-       input_thread_t* input = p_intf->p_sys->p_input;
-       if ( input )
-       {
-               vlc_mutex_lock( &input->stream.stream_lock );
-               for( i = 0; i < input->stream.i_selected_es_number; i++ )
-               {
-                       if( kind == input->stream.pp_selected_es[i]->i_cat )
-                               p_es = input->stream.pp_selected_es[i];
-               }
-       
-               int32 addedItems = 0;
-               bool emptyItemAdded = false;
-               uint32 what = kind == AUDIO_ES ? SELECT_CHANNEL : SELECT_SUBTITLE;
-               const char* fieldName = kind == AUDIO_ES ? "channel" : "subtitle";
-       
-               for ( i = 0; i < input->stream.i_es_number; i++ )
-               {
-                       if ( kind == input->stream.pp_es[i]->i_cat )
-                       {
-                               bool addItem = true;
-                               psz_name = input->stream.pp_es[i]->psz_desc;
-                               // workarround for irritating empty strings
-                               if ( strcmp(psz_name, "") == 0 )
-                               {
-//                                     if ( kind != AUDIO_ES ) // don't add empty subtitle items, they don't work anyways
-//                                             addItem = false;
-//                                     else
-//                                     {
-                                               if (!emptyItemAdded)
-                                               {
-                                                       psz_name = "<default>";
-                                                       emptyItemAdded = true;
-                                               }
-                                               else
-                                                       psz_name = "<unkown>";
-//                                     }
-                               }
-                               if ( addItem )
-                               {
-                                       addedItems++;
-                                       msg = new BMessage( what );
-                                       msg->AddInt32( fieldName, i );
-                                       menu_item = new BMenuItem( psz_name, msg );
-                                       AddItem( menu_item );
-                                       b_active = ( p_es == input->stream.pp_es[i] );
-                                       menu_item->SetMarked( b_active );
-                               }
-                       }
-               }
-               vlc_mutex_unlock( &input->stream.stream_lock );
-       
-               // enhance readability and separate first item from rest
-               if ( ( emptyItemAdded || kind != AUDIO_ES ) && addedItems > 1 )
-                        AddItem( new BSeparatorItem(), 1 );
-       }
+    BMenuItem * item;
+
+    // remove all items
+    while( ( item = RemoveItem( 0L ) ) )
+    {
+        delete item;
+    }
+
+    SetRadioMode( true );
+
+    input_thread_t * p_input = (input_thread_t *)
+            vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    if( !p_input )
+    {
+        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++ )
+    {
+        message = new BMessage( SELECT_CHANNEL );
+        message->AddInt32( psz_variable, val_list.p_list->p_values[i].i_int );
+        item = new BMenuItem( text_list.p_list->p_values[i].psz_string, message );
+        if( val_list.p_list->p_values[i].i_int == i_current )
+        {
+            item->SetMarked( true );
+        }
+        AddItem( item );
+    }
+    var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
+
+    vlc_object_release( p_input );
+
+    BMenu::AttachedToWindow();
 }
 
-
-
 /*****************************************************************************
  * TitleMenu::TitleMenu
  *****************************************************************************/
 TitleMenu::TitleMenu( const char *name, intf_thread_t  *p_interface )
-       : BMenu(name),
-       p_intf( p_interface )
+    : BMenu(name),
+    p_intf( p_interface )
 {
 }
 
@@ -1077,35 +1293,46 @@ TitleMenu::~TitleMenu()
  *****************************************************************************/
 void TitleMenu::AttachedToWindow()
 {
-       // make title menu empty
-       while ( BMenuItem* item = RemoveItem( 0L ) )
-               delete item;
-
-       input_thread_t* input = p_intf->p_sys->p_input;
-       if ( input )
-       {
-               // lock stream access
-               vlc_mutex_lock( &input->stream.stream_lock );
-               // populate menu according to current stream
-               int32 numTitles = input->stream.i_area_nb;
-               if ( numTitles > 1 )
-               {
-                       // disallow title 0!
-                       for ( int32 i = 1; i < numTitles; i++ )
-                       {
-                               BMessage* message = new BMessage( TOGGLE_TITLE );
-                               message->AddInt32( "index", i );
-                               BString helper( "" );
-                               helper << i;
-                               BMenuItem* item = new BMenuItem( helper.String(), message );
-                               item->SetMarked( input->stream.p_selected_area->i_id == i );
-                               AddItem( item );
-                       }
-               }
-               // done messing with stream
-               vlc_mutex_unlock( &input->stream.stream_lock );
-       }
-       BMenu::AttachedToWindow();
+    BMenuItem * item;
+    while( ( item = RemoveItem( 0L ) ) )
+    {
+        delete item;
+    }
+
+    input_thread_t * p_input;
+    p_input = (input_thread_t *)
+        vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    if( !p_input )
+    {
+        return;
+    }
+
+    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,
+                                  message );
+            if( val_list.p_list->p_values[i].i_int == val.i_int )
+            {
+                item->SetMarked( true );
+            }
+            AddItem( item );
+        }
+
+        var_Change( p_input, "title", VLC_VAR_FREELIST,
+                    &val_list, &text_list );
+    }
+    vlc_object_release( p_input );
+    BMenu::AttachedToWindow();
 }
 
 
@@ -1113,8 +1340,8 @@ void TitleMenu::AttachedToWindow()
  * ChapterMenu::ChapterMenu
  *****************************************************************************/
 ChapterMenu::ChapterMenu( const char *name, intf_thread_t  *p_interface )
-       : BMenu(name),
-       p_intf( p_interface )
+    : BMenu(name),
+    p_intf( p_interface )
 {
 }
 
@@ -1130,33 +1357,103 @@ ChapterMenu::~ChapterMenu()
  *****************************************************************************/
 void ChapterMenu::AttachedToWindow()
 {
-       // make title menu empty
-       while ( BMenuItem* item = RemoveItem( 0L ) )
-               delete item;
-
-       input_thread_t* input = p_intf->p_sys->p_input;
-       if ( input )
-       {
-               // lock stream access
-               vlc_mutex_lock( &input->stream.stream_lock );
-               // populate menu according to current stream
-               int32 numChapters = input->stream.p_selected_area->i_part_nb;
-               if ( numChapters > 1 )
-               {
-                       for ( int32 i = 0; i < numChapters; i++ )
-                       {
-                               BMessage* message = new BMessage( TOGGLE_CHAPTER );
-                               message->AddInt32( "index", i );
-                               BString helper( "" );
-                               helper << i + 1;
-                               BMenuItem* item = new BMenuItem( helper.String(), message );
-                               item->SetMarked( input->stream.p_selected_area->i_part == i );
-                               AddItem( item );
-                       }
-               }
-               // done messing with stream
-               vlc_mutex_unlock( &input->stream.stream_lock );
-       }
-       BMenu::AttachedToWindow();
+    BMenuItem * item;
+    while( ( item = RemoveItem( 0L ) ) )
+    {
+        delete item;
+    }
+
+    input_thread_t * p_input;
+    p_input = (input_thread_t *)
+        vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    if( !p_input )
+    {
+        return;
+    }
+
+    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,
+                                  message );
+            if( val_list.p_list->p_values[i].i_int == val.i_int )
+            {
+                item->SetMarked( true );
+            }
+            AddItem( item );
+        }
+
+        var_Change( p_input, "chapter", VLC_VAR_FREELIST,
+                    &val_list, &text_list );
+    }
+    vlc_object_release( p_input );
+    BMenu::AttachedToWindow();
 }
 
+
+/*****************************************************************************
+ * load_settings
+ *****************************************************************************/
+status_t
+load_settings( BMessage* message, const char* fileName, const char* folder )
+{
+    status_t ret = B_BAD_VALUE;
+    if ( message )
+    {
+        BPath path;
+        if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
+        {
+            // passing folder is optional
+            if ( folder )
+                ret = path.Append( folder );
+            if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
+            {
+                BFile file( path.Path(), B_READ_ONLY );
+                if ( ( ret = file.InitCheck() ) == B_OK )
+                {
+                    ret = message->Unflatten( &file );
+                    file.Unset();
+                }
+            }
+        }
+    }
+    return ret;
+}
+
+/*****************************************************************************
+ * save_settings
+ *****************************************************************************/
+status_t
+save_settings( BMessage* message, const char* fileName, const char* folder )
+{
+    status_t ret = B_BAD_VALUE;
+    if ( message )
+    {
+        BPath path;
+        if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
+        {
+            // passing folder is optional
+            if ( folder && ( ret = path.Append( folder ) ) == B_OK )
+                ret = create_directory( path.Path(), 0777 );
+            if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
+            {
+                BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
+                if ( ( ret = file.InitCheck() ) == B_OK )
+                {
+                    ret = message->Flatten( &file );
+                    file.Unset();
+                }
+            }
+        }
+    }
+    return ret;
+}