]> git.sesse.net Git - vlc/blob - modules/gui/beos/InterfaceWindow.cpp
* store windows sizes in the vlc configuration file
[vlc] / modules / gui / beos / InterfaceWindow.cpp
1 /*****************************************************************************
2  * InterfaceWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: InterfaceWindow.cpp,v 1.21 2003/01/25 01:03:44 titer Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Tony Castley <tony@castley.net>
10  *          Richard Shepherd <richard@rshepherd.demon.co.uk>
11  *          Stephan Aßmus <stippi@yellowbites.com>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
26  *****************************************************************************/
27
28 /* System headers */
29 #include <kernel/OS.h>
30 #include <InterfaceKit.h>
31 #include <AppKit.h>
32 #include <StorageKit.h>
33 #include <SupportKit.h>
34 #include <malloc.h>
35 #include <scsi.h>
36 #include <scsiprobe_driver.h>
37 #include <fs_info.h>
38 #include <string.h>
39
40 /* VLC headers */
41 #include <vlc/vlc.h>
42 #include <vlc/aout.h>
43 #include <vlc/intf.h>
44
45 /* BeOS interface headers */
46 #include "VlcWrapper.h"
47 #include "MsgVals.h"
48 #include "MediaControlView.h"
49 #include "PlayListWindow.h"
50 #include "PreferencesWindow.h"
51 #include "InterfaceWindow.h"
52
53 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
54
55
56 /*****************************************************************************
57  * InterfaceWindow
58  *****************************************************************************/
59
60 InterfaceWindow::InterfaceWindow( BRect frame, const char *name,
61                                                                   intf_thread_t  *p_interface )
62         : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
63                            B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
64           p_intf( p_interface ),
65           fFilePanel( NULL ),
66           fSubtitlesPanel( NULL ),
67           fLastUpdateTime( system_time() )
68 {
69     p_intf = p_interface;
70     p_wrapper = p_intf->p_sys->p_wrapper;
71     p_intf->p_sys->b_dvdold = false;
72     
73     fPlaylistIsEmpty = !( p_wrapper->PlaylistSize() > 0 );
74     
75     fPlaylistWindow = new PlayListWindow( BRect( 100.0, 100.0, 400.0, 350.0 ),
76                                                                                   "Playlist",
77                                                                                   this,
78                                                                                   p_intf );
79     BScreen *p_screen = new BScreen();
80     BRect screen_rect = p_screen->Frame();
81     delete p_screen;
82     BRect window_rect;
83     window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
84                      ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
85                      ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
86                      ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
87         fPreferencesWindow = new PreferencesWindow( window_rect,
88                                                     "Preferences",
89                                                     p_intf );
90     
91         // set the title bar
92         SetName( "interface" );
93         SetTitle( VOUT_TITLE );
94
95         // the media control view
96         p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
97                                                p_intf );
98         p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
99
100         float width, height;
101         p_mediaControl->GetPreferredSize( &width, &height );
102
103         // set up the main menu
104         fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
105                                                          B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
106
107         // make menu bar resize to correct height
108         float menuWidth, menuHeight;
109         fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
110         fMenuBar->ResizeTo( width, menuHeight );        // don't change! it's a workarround!
111         // take care of proper size for ourself
112         height += fMenuBar->Bounds().Height();
113         ResizeTo( width, height );
114
115         p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
116         AddChild( fMenuBar );
117         AddChild( p_mediaControl );
118
119         // Add the file Menu
120         BMenu* fileMenu = new BMenu( "File" );
121         fMenuBar->AddItem( fileMenu );
122         fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
123                                                                           new BMessage( OPEN_FILE ), 'O') );
124         
125         fileMenu->AddItem( new CDMenu( "Open Disc" ) );
126
127         fileMenu->AddItem( new BMenuItem( "Load a subtitle file" B_UTF8_ELLIPSIS,
128                                                                           new BMessage( LOAD_SUBFILE ) ) );
129         
130         fileMenu->AddSeparatorItem();
131         fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
132                                                                           new BMessage( OPEN_PLAYLIST ), 'P') );
133         
134         fileMenu->AddSeparatorItem();
135         BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
136                                                                          new BMessage( B_ABOUT_REQUESTED ), 'A');
137         item->SetTarget( be_app );
138         fileMenu->AddItem( item );
139         fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
140
141         fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
142         fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);
143
144         /* Add the Audio menu */
145         fAudioMenu = new BMenu( "Audio" );
146         fMenuBar->AddItem ( fAudioMenu );
147         fAudioMenu->AddItem( fLanguageMenu );
148         fAudioMenu->AddItem( fSubtitlesMenu );
149
150         fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
151         fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
152         fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
153         fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
154
155         /* Add the Navigation menu */
156         fNavigationMenu = new BMenu( "Navigation" );
157         fMenuBar->AddItem( fNavigationMenu );
158         fNavigationMenu->AddItem( fPrevTitleMI );
159         fNavigationMenu->AddItem( fNextTitleMI );
160         fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
161         fNavigationMenu->AddSeparatorItem();
162         fNavigationMenu->AddItem( fPrevChapterMI );
163         fNavigationMenu->AddItem( fNextChapterMI );
164         fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
165
166         /* Add the Speed menu */
167         fSpeedMenu = new BMenu( "Speed" );
168         fSpeedMenu->SetRadioMode( true );
169         fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
170         fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
171         fNormalMI->SetMarked(true); // default to normal speed
172         fSpeedMenu->AddItem( fNormalMI );
173         fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
174         fSpeedMenu->SetTargetForItems( this );
175         fMenuBar->AddItem( fSpeedMenu );
176
177     /* Add the Settings menu */
178     fSettingsMenu = new BMenu( "Settings" );
179     fSettingsMenu->AddItem( fPreferencesMI =
180         new BMenuItem( "Preferences", new BMessage( OPEN_PREFERENCES ) ) );
181         fMenuBar->AddItem( fSettingsMenu );                                                     
182
183         /* Prepare fow showing */
184         _SetMenusEnabled( false );
185         p_mediaControl->SetEnabled( false );
186         
187     /* Restore interface settings */
188     int i_width = config_GetInt( p_intf, "beos-intf-width" ),
189         i_height = config_GetInt( p_intf, "beos-intf-height" ),
190         i_xpos = config_GetInt( p_intf, "beos-intf-xpos" ),
191         i_ypos = config_GetInt( p_intf, "beos-intf-ypos" );
192     if( i_width && i_height && i_xpos && i_ypos )
193     {
194         /* main window size and position */
195         ResizeTo( i_width, i_height );
196         MoveTo( i_xpos, i_ypos );
197     }
198     i_width = config_GetInt( p_intf, "beos-playlist-width" ),
199     i_height = config_GetInt( p_intf, "beos-playlist-height" ),
200     i_xpos = config_GetInt( p_intf, "beos-playlist-xpos" ),
201     i_ypos = config_GetInt( p_intf, "beos-playlist-ypos" );
202     if( i_width && i_height && i_xpos && i_ypos )
203     {
204         /* playlist window size and position */
205         fPlaylistWindow->ResizeTo( i_width, i_height );
206         fPlaylistWindow->MoveTo( i_xpos, i_ypos );
207     }
208     if( config_GetInt( p_intf, "beos-playlist-show" ) )
209     {
210         /* playlist showing */
211         if( fPlaylistWindow->Lock() )
212         {
213             fPlaylistWindow->Show();
214             fPlaylistWindow->Unlock();
215         }
216     }
217         
218         Show();
219 }
220
221 InterfaceWindow::~InterfaceWindow()
222 {
223         if (fPlaylistWindow)
224                 fPlaylistWindow->ReallyQuit();
225 }
226
227 /*****************************************************************************
228  * InterfaceWindow::FrameResized
229  *****************************************************************************/
230 void
231 InterfaceWindow::FrameResized(float width, float height)
232 {
233         BRect r(Bounds());
234         fMenuBar->MoveTo(r.LeftTop());
235         fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
236         r.top += fMenuBar->Bounds().Height() + 1.0;
237         p_mediaControl->MoveTo(r.LeftTop());
238         p_mediaControl->ResizeTo(r.Width(), r.Height());
239 }
240
241 /*****************************************************************************
242  * InterfaceWindow::MessageReceived
243  *****************************************************************************/
244 void InterfaceWindow::MessageReceived( BMessage * p_message )
245 {
246         int playback_status;      // remember playback state
247         playback_status = p_wrapper->InputStatus();
248
249         switch( p_message->what )
250         {
251                 case B_ABOUT_REQUESTED:
252                 {
253                         BAlert* alert = new BAlert( VOUT_TITLE,
254                                                                                 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
255                         alert->Go();
256                         break;
257                 }
258                 case TOGGLE_ON_TOP:
259                         break;
260                         
261                 case OPEN_FILE:
262                         if( fFilePanel )
263                         {
264                                 fFilePanel->Show();
265                                 break;
266                         }
267                         fFilePanel = new BFilePanel();
268                         fFilePanel->SetTarget( this );
269                         fFilePanel->Show();
270                         break;
271         
272                 case OPEN_PLAYLIST:
273                         if (fPlaylistWindow->Lock())
274                         {
275                                 if (fPlaylistWindow->IsHidden())
276                                         fPlaylistWindow->Show();
277                                 else
278                                         fPlaylistWindow->Activate();
279                                 fPlaylistWindow->Unlock();
280                         }
281                         break;
282                 case OPEN_DVD:
283                         {
284                                 const char *psz_device;
285                                 BString type( "dvd" );
286                                 if( p_message->FindString( "device", &psz_device ) == B_OK )
287                                 {
288                                         BString device( psz_device );
289                                         p_wrapper->OpenDisc( type, device, 0, 0 );
290                                 }
291                                 _UpdatePlaylist();
292                         }
293                         break;
294                 
295                 case LOAD_SUBFILE:
296                         if( fSubtitlesPanel )
297                         {
298                                 fSubtitlesPanel->Show();
299                                 break;
300                         }
301                         fSubtitlesPanel = new BFilePanel();
302                         fSubtitlesPanel->SetTarget( this );
303                         fSubtitlesPanel->SetMessage( new BMessage( SUBFILE_RECEIVED ) );
304                         fSubtitlesPanel->Show();
305                         break;
306
307                 case SUBFILE_RECEIVED:
308                 {
309                         entry_ref ref;
310                         if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
311                         {
312                                 BPath path( &ref );
313                                 if ( path.InitCheck() == B_OK )
314                                         p_wrapper->LoadSubFile( (char*)path.Path() );
315                         }
316                         break;
317                 }
318         
319                 case STOP_PLAYBACK:
320                         // this currently stops playback not nicely
321                         if (playback_status > UNDEF_S)
322                         {
323                                 snooze( 400000 );
324                                 p_wrapper->PlaylistStop();
325                                 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
326                         }
327                         break;
328         
329                 case START_PLAYBACK:
330                         /*  starts playing in normal mode */
331         
332                 case PAUSE_PLAYBACK:
333                         /* toggle between pause and play */
334                         if (playback_status > UNDEF_S)
335                         {
336                                 /* pause if currently playing */
337                                 if ( playback_status == PLAYING_S )
338                                 {
339                                         p_wrapper->PlaylistPause();
340                                 }
341                                 else
342                                 {
343                                         p_wrapper->PlaylistPlay();
344                                 }
345                         }
346                         else
347                         {
348                                 /* Play a new file */
349                                 p_wrapper->PlaylistPlay();
350                         }       
351                         break;
352         
353                 case FASTER_PLAY:
354                         /* cycle the fast playback modes */
355                         if (playback_status > UNDEF_S)
356                         {
357                                 p_wrapper->InputFaster();
358                         }
359                         break;
360         
361                 case SLOWER_PLAY:
362                         /*  cycle the slow playback modes */
363                         if (playback_status > UNDEF_S)
364                         {
365                                 p_wrapper->InputSlower();
366                         }
367                         break;
368         
369                 case NORMAL_PLAY:
370                         /*  restore speed to normal if already playing */
371                         if (playback_status > UNDEF_S)
372                         {
373                                 p_wrapper->PlaylistPlay();
374                         }
375                         break;
376         
377                 case SEEK_PLAYBACK:
378                         /* handled by semaphores */
379                         break;
380                 // volume related messages
381                 case VOLUME_CHG:
382                         /* adjust the volume */
383                         if (playback_status > UNDEF_S)
384                         {
385                                 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
386                                 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
387                         }
388                         break;
389         
390                 case VOLUME_MUTE:
391                         // toggle muting
392                         if( p_wrapper->IsMuted() )
393                             p_wrapper->VolumeRestore();
394                         else
395                             p_wrapper->VolumeMute();
396                         p_mediaControl->SetMuted( p_wrapper->IsMuted() );
397                         break;
398         
399                 case SELECT_CHANNEL:
400                         if ( playback_status > UNDEF_S )
401                         {
402                                 int32 channel;
403                                 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
404                                 {
405                                         p_wrapper->ToggleLanguage( channel );
406                                 }
407                         }
408                         break;
409         
410                 case SELECT_SUBTITLE:
411                         if ( playback_status > UNDEF_S )
412                         {
413                                 int32 subtitle;
414                                 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
415                                          p_wrapper->ToggleSubtitle( subtitle );
416                         }
417                         break;
418         
419                 // specific navigation messages
420                 case PREV_TITLE:
421                 {
422                         p_wrapper->PrevTitle();
423                         break;
424                 }
425                 case NEXT_TITLE:
426                 {
427             p_wrapper->NextTitle();
428                         break;
429                 }
430                 case TOGGLE_TITLE:
431                         if ( playback_status > UNDEF_S )
432                         {
433                                 int32 index;
434                                 if( p_message->FindInt32( "index", &index ) == B_OK )
435                                         p_wrapper->ToggleTitle( index );
436                         }
437                         break;
438                 case PREV_CHAPTER:
439                 {
440             p_wrapper->PrevChapter();
441                         break;
442                 }
443                 case NEXT_CHAPTER:
444                 {
445             p_wrapper->NextChapter();
446                         break;
447                 }
448                 case TOGGLE_CHAPTER:
449                         if ( playback_status > UNDEF_S )
450                         {
451                                 int32 index;
452                                 if( p_message->FindInt32( "index", &index ) == B_OK )
453                     p_wrapper->ToggleChapter( index );
454                         }
455                         break;
456                 case PREV_FILE:
457                         p_wrapper->PlaylistPrev();
458                         break;
459                 case NEXT_FILE:
460                         p_wrapper->PlaylistNext();
461                         break;
462                 // general next/prev functionality (skips to whatever makes most sense)
463                 case NAVIGATE_PREV:
464                         p_wrapper->NavigatePrev();
465                         break;
466                 case NAVIGATE_NEXT:
467                         p_wrapper->NavigateNext();
468                         break;
469                 // drag'n'drop and system messages
470                 case B_REFS_RECEIVED:
471                 case B_SIMPLE_DATA:
472                         {
473                                 /* file(s) opened by the File menu -> append to the playlist;
474                                  * file(s) opened by drag & drop -> replace playlist;
475                                  * file(s) opened by 'shift' + drag & drop -> append */
476                                 bool replace = false;
477                                 if ( p_message->WasDropped() )
478                                         replace = !( modifiers() & B_SHIFT_KEY );
479                                         
480                                 // build list of files to be played from message contents
481                                 entry_ref ref;
482                                 BList files;
483                                 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
484                                 {
485                                         BPath path( &ref );
486                                         if ( path.InitCheck() == B_OK )
487                                         {
488                                                 bool add = true;
489                                                 // has the user dropped a dvd disk icon?
490                                                 BDirectory dir( &ref );
491                                                 if ( dir.InitCheck() == B_OK && dir.IsRootDirectory() )
492                                                 {
493                                                         BVolumeRoster volRoster;
494                                                         BVolume vol;
495                                                         BDirectory volumeRoot;
496                                                         status_t status = volRoster.GetNextVolume( &vol );
497                                                         while( status == B_NO_ERROR )
498                                                         {
499                                                                 if( vol.GetRootDirectory( &volumeRoot ) == B_OK
500                                                                         && dir == volumeRoot )
501                                                                 {
502                                                                         BString volumeName;
503                                                                         BString deviceName;
504                                                                         bool isCDROM = false;
505                                                                         bool success = false;
506                                                                         deviceName = "";
507                                                                         volumeName = "";
508                                                                         char name[B_FILE_NAME_LENGTH];
509                                                                         if ( vol.GetName( name ) >= B_OK )      // disk is currently mounted
510                                                                         {
511                                                                                 volumeName = name;
512                                                                                 dev_t dev = vol.Device();
513                                                                                 fs_info info;
514                                                                                 if ( fs_stat_dev( dev, &info ) == B_OK )
515                                                                                 {
516                                                                                         success = true;
517                                                                                         deviceName = info.device_name;
518                                                                                         if ( vol.IsReadOnly() )
519                                                                                         {
520                                                                                                 int i_dev = open( info.device_name, O_RDONLY );
521                                                                                                 if ( i_dev >= 0 )
522                                                                                                 {
523                                                                                                         device_geometry g;
524                                                                                                         if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
525                                                                                                         isCDROM = ( g.device_type == B_CD );
526                                                                                                         close( i_dev );
527                                                                                                 }
528                                                                                         }
529                                                                                 }
530                                                                         }
531                                                                         
532                                                                         if( success && isCDROM )
533                                                                         {
534                                                                                 BMessage msg( OPEN_DVD );
535                                                                                 msg.AddString( "device", deviceName.String() );
536                                                                                 PostMessage( &msg );
537                                                                                 add = false;
538                                                                         }
539                                                                         break;
540                                                                 }
541                                                                 else
542                                                                 {
543                                                                         vol.Unset();
544                                                                         status = volRoster.GetNextVolume( &vol );
545                                                                 }
546                                                         }
547                                                 }
548                                                 if( add )
549                                                 {
550                                                         files.AddItem( new BString( (char*)path.Path() ) );
551                                                 }
552                                         }
553                                 }
554                                 // give the list to VLC
555                                 p_wrapper->OpenFiles(&files, replace);
556                                 _UpdatePlaylist();
557                         }
558                         break;
559
560                 case OPEN_PREFERENCES:
561                     if( fPreferencesWindow->Lock() )
562                     {
563                             if (fPreferencesWindow->IsHidden())
564                                     fPreferencesWindow->Show();
565                             else
566                                     fPreferencesWindow->Activate();
567                                 fPreferencesWindow->Unlock();
568                         }
569                         break;
570                                 
571                 default:
572                         BWindow::MessageReceived( p_message );
573                         break;
574         }
575
576 }
577
578 /*****************************************************************************
579  * InterfaceWindow::QuitRequested
580  *****************************************************************************/
581 bool InterfaceWindow::QuitRequested()
582 {
583         p_wrapper->PlaylistStop();
584         p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
585
586     /* Save interface settings */
587     BRect frame = Frame();
588     config_PutInt( p_intf, "beos-intf-width", (int)frame.Width() );
589     config_PutInt( p_intf, "beos-intf-height", (int)frame.Height() );
590     config_PutInt( p_intf, "beos-intf-xpos", (int)frame.left );
591     config_PutInt( p_intf, "beos-intf-ypos", (int)frame.top );
592     if( fPlaylistWindow->Lock() )
593     {
594         frame = fPlaylistWindow->Frame();
595         config_PutInt( p_intf, "beos-playlist-width", (int)frame.Width() );
596         config_PutInt( p_intf, "beos-playlist-height", (int)frame.Height() );
597         config_PutInt( p_intf, "beos-playlist-xpos", (int)frame.left );
598         config_PutInt( p_intf, "beos-playlist-ypos", (int)frame.top );
599         config_PutInt( p_intf, "beos-playlist-show", !fPlaylistWindow->IsHidden() );
600         fPlaylistWindow->Unlock();
601     }
602     config_SaveConfigFile( p_intf, "beos" );
603     
604         p_intf->b_die = 1;
605
606         return( true );
607 }
608
609 /*****************************************************************************
610  * InterfaceWindow::updateInterface
611  *****************************************************************************/
612 void InterfaceWindow::updateInterface()
613 {
614     if( p_wrapper->HasInput() )
615     {
616                 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
617                 {
618                     p_wrapper->SetTimeAsFloat(p_mediaControl->GetSeekTo());
619                 }
620                 else if ( Lock() )
621                 {
622                         p_mediaControl->SetEnabled( true );
623                         bool hasTitles = p_wrapper->HasTitles();
624                         bool hasChapters = p_wrapper->HasChapters();
625                         p_mediaControl->SetStatus( p_wrapper->InputStatus(), 
626                                                                            p_wrapper->InputRate() );
627                         p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
628                         _SetMenusEnabled( true, hasChapters, hasTitles );
629
630                         _UpdateSpeedMenu( p_wrapper->InputRate() );
631
632                         // enable/disable skip buttons
633                         bool canSkipPrev;
634                         bool canSkipNext;
635                         p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
636                         p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
637
638                         if ( p_wrapper->HasAudio() )
639                         {
640                                 p_mediaControl->SetAudioEnabled( true );
641                                 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
642                         } else
643                                 p_mediaControl->SetAudioEnabled( false );
644
645                         Unlock();
646                 }
647                 // update playlist as well
648                 if ( fPlaylistWindow->Lock() )
649                 {
650                         fPlaylistWindow->UpdatePlaylist();
651                         fPlaylistWindow->Unlock();
652                 }
653         }
654     else
655     {
656         _SetMenusEnabled( false );
657         if( !( p_wrapper->PlaylistSize() > 0 ) )
658                    p_mediaControl->SetEnabled( false );
659                 else
660                     p_mediaControl->SetProgress( 0 );
661     }
662
663     /* always force the user-specified volume */
664     /* FIXME : I'm quite sure there is a cleaner way to do this */
665     int i_volume = p_mediaControl->GetVolume();
666     if( p_wrapper->GetVolume() != i_volume )
667     {
668         p_wrapper->SetVolume( i_volume );
669     }
670
671         fLastUpdateTime = system_time();
672 }
673
674 /*****************************************************************************
675  * InterfaceWindow::IsStopped
676  *****************************************************************************/
677 bool
678 InterfaceWindow::IsStopped() const
679 {
680         return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
681 }
682
683 /*****************************************************************************
684  * InterfaceWindow::_UpdatePlaylist
685  *****************************************************************************/
686 void
687 InterfaceWindow::_UpdatePlaylist()
688 {
689         if ( fPlaylistWindow->Lock() )
690         {
691                 fPlaylistWindow->UpdatePlaylist( true );
692                 fPlaylistWindow->Unlock();
693                 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
694         }
695 }
696
697 /*****************************************************************************
698  * InterfaceWindow::_SetMenusEnabled
699  *****************************************************************************/
700 void
701 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
702 {
703         if (!hasFile)
704         {
705                 hasChapters = false;
706                 hasTitles = false;
707         }
708         if (Lock())
709         {
710                 if (fNextChapterMI->IsEnabled() != hasChapters)
711                         fNextChapterMI->SetEnabled(hasChapters);
712                 if (fPrevChapterMI->IsEnabled() != hasChapters)
713                         fPrevChapterMI->SetEnabled(hasChapters);
714                 if (fChapterMenu->IsEnabled() != hasChapters)
715                         fChapterMenu->SetEnabled(hasChapters);
716                 if (fNextTitleMI->IsEnabled() != hasTitles)
717                         fNextTitleMI->SetEnabled(hasTitles);
718                 if (fPrevTitleMI->IsEnabled() != hasTitles)
719                         fPrevTitleMI->SetEnabled(hasTitles);
720                 if (fTitleMenu->IsEnabled() != hasTitles)
721                         fTitleMenu->SetEnabled(hasTitles);
722                 if (fAudioMenu->IsEnabled() != hasFile)
723                         fAudioMenu->SetEnabled(hasFile);
724                 if (fNavigationMenu->IsEnabled() != hasFile)
725                         fNavigationMenu->SetEnabled(hasFile);
726                 if (fLanguageMenu->IsEnabled() != hasFile)
727                         fLanguageMenu->SetEnabled(hasFile);
728                 if (fSubtitlesMenu->IsEnabled() != hasFile)
729                         fSubtitlesMenu->SetEnabled(hasFile);
730                 if (fSpeedMenu->IsEnabled() != hasFile)
731                         fSpeedMenu->SetEnabled(hasFile);
732                 Unlock();
733         }
734 }
735
736 /*****************************************************************************
737  * InterfaceWindow::_UpdateSpeedMenu
738  *****************************************************************************/
739 void
740 InterfaceWindow::_UpdateSpeedMenu( int rate )
741 {
742         if ( rate == DEFAULT_RATE )
743         {
744                 if ( !fNormalMI->IsMarked() )
745                         fNormalMI->SetMarked( true );
746         }
747         else if ( rate < DEFAULT_RATE )
748         {
749                 if ( !fFasterMI->IsMarked() )
750                         fFasterMI->SetMarked( true );
751         }
752         else
753         {
754                 if ( !fSlowerMI->IsMarked() )
755                         fSlowerMI->SetMarked( true );
756         }
757 }
758
759 /*****************************************************************************
760  * InterfaceWindow::_InputStreamChanged
761  *****************************************************************************/
762 void
763 InterfaceWindow::_InputStreamChanged()
764 {
765         // TODO: move more stuff from updateInterface() here!
766         snooze( 400000 );
767         p_wrapper->SetVolume( p_mediaControl->GetVolume() );
768 }
769
770 void
771 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
772                                                                   float maxWidth, float maxHeight )
773 {
774         if ( frame.Width() < minWidth )
775                 frame.right = frame.left + minWidth;
776         if ( frame.Height() < minHeight )
777                 frame.bottom = frame.top + minHeight;
778         if ( frame.Width() > maxWidth )
779                 frame.right = frame.left + maxWidth;
780         if ( frame.Height() > maxHeight )
781                 frame.bottom = frame.top + maxHeight;
782 }
783
784 /*****************************************************************************
785  * CDMenu::CDMenu
786  *****************************************************************************/
787 CDMenu::CDMenu(const char *name)
788           : BMenu(name)
789 {
790 }
791
792 /*****************************************************************************
793  * CDMenu::~CDMenu
794  *****************************************************************************/
795 CDMenu::~CDMenu()
796 {
797 }
798
799 /*****************************************************************************
800  * CDMenu::AttachedToWindow
801  *****************************************************************************/
802 void CDMenu::AttachedToWindow(void)
803 {
804         // remove all items
805         while (BMenuItem* item = RemoveItem(0L))
806                 delete item;
807         GetCD("/dev/disk");
808         BMenu::AttachedToWindow();
809 }
810
811 /*****************************************************************************
812  * CDMenu::GetCD
813  *****************************************************************************/
814 int CDMenu::GetCD( const char *directory )
815 {
816         BVolumeRoster *volRoster;
817         BVolume    *vol;
818         BDirectory      *dir;
819         int                status;
820         int                mounted;   
821         char              name[B_FILE_NAME_LENGTH]; 
822         fs_info    info;
823         dev_t            dev;
824         
825         volRoster = new BVolumeRoster();
826         vol = new BVolume();
827         dir = new BDirectory();
828         status = volRoster->GetNextVolume(vol);
829         status = vol->GetRootDirectory(dir);
830         while (status ==  B_NO_ERROR)
831         {
832                 mounted = vol->GetName(name);   
833                 if ((mounted == B_OK) && /* Disk is currently Mounted */
834                         (vol->IsReadOnly()) ) /* Disk is read-only */
835                 {
836                         dev = vol->Device();
837                         fs_stat_dev(dev, &info);
838                         
839                         device_geometry g;
840                         int i_dev;
841                         i_dev = open( info.device_name, O_RDONLY );
842                    
843                         if( i_dev >= 0 )
844                         {
845                                 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
846                                 {
847                                         if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
848                                         {
849                                                 BMessage *msg;
850                                                 msg = new BMessage( OPEN_DVD );
851                                                 msg->AddString( "device", info.device_name );
852                                                 BMenuItem *menu_item;
853                                                 menu_item = new BMenuItem( name, msg );
854                                                 AddItem( menu_item );
855                                         }
856                                         close(i_dev);
857                                 }
858                         }
859                 }
860                 vol->Unset();
861                 status = volRoster->GetNextVolume(vol);
862         }
863         return 0;
864 }
865
866 /*****************************************************************************
867  * LanguageMenu::LanguageMenu
868  *****************************************************************************/
869 LanguageMenu::LanguageMenu( const char *name, int menu_kind, 
870                                                         VlcWrapper *p_wrapper )
871         :BMenu(name)
872 {
873         kind = menu_kind;
874         this->p_wrapper = p_wrapper;
875 }
876
877 /*****************************************************************************
878  * LanguageMenu::~LanguageMenu
879  *****************************************************************************/
880 LanguageMenu::~LanguageMenu()
881 {
882 }
883
884 /*****************************************************************************
885  * LanguageMenu::AttachedToWindow
886  *****************************************************************************/
887 void LanguageMenu::AttachedToWindow()
888 {
889         // remove all items
890         while ( BMenuItem* item = RemoveItem( 0L ) )
891                 delete item;
892
893         SetRadioMode( true );
894         _GetChannels();
895         BMenu::AttachedToWindow();
896 }
897
898 /*****************************************************************************
899  * LanguageMenu::_GetChannels
900  *****************************************************************************/
901 void LanguageMenu::_GetChannels()
902 {
903     BMenuItem *item;
904     BList *list;
905     
906     if( ( list = p_wrapper->GetChannels( kind ) ) == NULL )
907         return;
908     
909     for( int i = 0; i < list->CountItems(); i++ )
910     {
911         item = (BMenuItem*)list->ItemAt( i );
912         AddItem( item );
913     }
914     
915     if( list->CountItems() > 1 )
916         AddItem( new BSeparatorItem(), 1 );
917 }
918
919
920 /*****************************************************************************
921  * TitleMenu::TitleMenu
922  *****************************************************************************/
923 TitleMenu::TitleMenu( const char *name, intf_thread_t  *p_interface )
924         : BMenu(name),
925         p_intf( p_interface )
926 {
927 }
928
929 /*****************************************************************************
930  * TitleMenu::~TitleMenu
931  *****************************************************************************/
932 TitleMenu::~TitleMenu()
933 {
934 }
935
936 /*****************************************************************************
937  * TitleMenu::AttachedToWindow
938  *****************************************************************************/
939 void TitleMenu::AttachedToWindow()
940 {
941     BMenuItem *item;
942     BList *list;
943
944         while( ( item = RemoveItem( 0L ) ) )
945                 delete item;
946     
947     if( ( list = p_intf->p_sys->p_wrapper->GetTitles() ) == NULL )
948         return;
949     
950     for( int i = 0; i < list->CountItems(); i++ )
951     {
952         item = (BMenuItem*)list->ItemAt( i );
953         AddItem( item );
954     }
955     
956         BMenu::AttachedToWindow();
957 }
958
959
960 /*****************************************************************************
961  * ChapterMenu::ChapterMenu
962  *****************************************************************************/
963 ChapterMenu::ChapterMenu( const char *name, intf_thread_t  *p_interface )
964         : BMenu(name),
965         p_intf( p_interface )
966 {
967 }
968
969 /*****************************************************************************
970  * ChapterMenu::~ChapterMenu
971  *****************************************************************************/
972 ChapterMenu::~ChapterMenu()
973 {
974 }
975
976 /*****************************************************************************
977  * ChapterMenu::AttachedToWindow
978  *****************************************************************************/
979 void ChapterMenu::AttachedToWindow()
980 {
981     BMenuItem *item;
982     BList *list;
983
984         while( ( item = RemoveItem( 0L ) ) )
985                 delete item;
986     
987     if( ( list = p_intf->p_sys->p_wrapper->GetChapters() ) == NULL )
988         return;
989     
990     for( int i = 0; i < list->CountItems(); i++ )
991     {
992         item = (BMenuItem*)list->ItemAt( i );
993         AddItem( item );
994     }
995     
996         BMenu::AttachedToWindow();
997 }
998