]> git.sesse.net Git - vlc/blob - modules/gui/beos/InterfaceWindow.cpp
modules/gui/beos/InterfaceWindow.h/.cpp
[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.27 2003/02/03 17:18:48 stippi 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 "MessagesWindow.h"
52 #include "InterfaceWindow.h"
53
54 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
55 #define INTERFACE_LOCKING_TIMEOUT 5000
56
57 // make_sure_frame_is_on_screen
58 bool
59 make_sure_frame_is_on_screen( BRect& frame )
60 {
61         BScreen screen( B_MAIN_SCREEN_ID );
62         if (frame.IsValid() && screen.IsValid()) {
63                 if (!screen.Frame().Contains(frame)) {
64                         // make sure frame fits in the screen
65                         if (frame.Width() > screen.Frame().Width())
66                                 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
67                         if (frame.Height() > screen.Frame().Height())
68                                 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
69                         // frame is now at the most the size of the screen
70                         if (frame.right > screen.Frame().right)
71                                 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
72                         if (frame.bottom > screen.Frame().bottom)
73                                 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
74                         if (frame.left < screen.Frame().left)
75                                 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
76                         if (frame.top < screen.Frame().top)
77                                 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
78                 }
79                 return true;
80         }
81         return false;
82 }
83
84 // make_sure_frame_is_within_limits
85 void
86 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
87                                   float maxWidth, float maxHeight )
88 {
89     if ( frame.Width() < minWidth )
90         frame.right = frame.left + minWidth;
91     if ( frame.Height() < minHeight )
92         frame.bottom = frame.top + minHeight;
93     if ( frame.Width() > maxWidth )
94         frame.right = frame.left + maxWidth;
95     if ( frame.Height() > maxHeight )
96         frame.bottom = frame.top + maxHeight;
97 }
98
99 // get_volume_info
100 bool
101 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
102 {
103         bool success = false;
104         isCDROM = false;
105         deviceName = "";
106         volumeName = "";
107         char name[B_FILE_NAME_LENGTH];
108         if ( volume.GetName( name ) >= B_OK )   // disk is currently mounted
109         {
110                 volumeName = name;
111                 dev_t dev = volume.Device();
112                 fs_info info;
113                 if ( fs_stat_dev( dev, &info ) == B_OK )
114                 {
115                         success = true;
116                         deviceName = info.device_name;
117                         if ( volume.IsReadOnly() )
118                         {
119                                 int i_dev = open( info.device_name, O_RDONLY );
120                                 if ( i_dev >= 0 )
121                                 {
122                                         device_geometry g;
123                                         if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
124                                                 isCDROM = ( g.device_type == B_CD );
125                                         close( i_dev );
126                                 }
127                         }
128                 }
129         }
130         return success;
131 }
132
133 // collect_folder_contents
134 void
135 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
136 {
137         while ( dir.GetNextEntry( &entry, true ) == B_OK )
138         {
139                 if ( !entry.IsDirectory() )
140                 {
141                         BPath path;
142                         // since the directory will give us the entries in reverse order,
143                         // we put them each at the same index, effectively reversing the
144                         // items while adding them
145                         if ( entry.GetPath( &path ) == B_OK )
146                         {
147                                 BString* string = new BString( path.Path() );
148                                 if ( !list.AddItem( string, 0 ) )
149                                         delete string;  // at least don't leak
150                         }
151                 }
152                 else
153                 {
154                         if ( !asked )
155                         {
156                                 // ask user if we should parse sub-folders as well
157                                 BAlert* alert = new BAlert( "sub-folders?",
158                                                                                         "Open files from all sub-folders as well?",
159                                                                                         "No", "Yes", NULL, B_WIDTH_AS_USUAL,
160                                                                                         B_IDEA_ALERT );
161                                 int32 buttonIndex = alert->Go();
162                                 deep = buttonIndex == 1;
163                                 asked = true;
164                                 // never delete BAlerts!!
165                         }
166                         if ( deep )
167                         {
168                                 BDirectory subDir( &entry );
169                                 if ( subDir.InitCheck() == B_OK )
170                                         collect_folder_contents( subDir, list,
171                                                                                          deep, asked, entry );
172                         }
173                 }
174         }
175 }
176
177
178 /*****************************************************************************
179  * InterfaceWindow
180  *****************************************************************************/
181
182 InterfaceWindow::InterfaceWindow( BRect frame, const char* name,
183                                   intf_thread_t* p_interface )
184     : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
185                B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
186       p_intf( p_interface ),
187       fFilePanel( NULL ),
188       fLastUpdateTime( system_time() ),
189           fSettings( new BMessage( 'sett' ) ),
190           p_wrapper( p_intf->p_sys->p_wrapper )
191 {
192         // TODO: ?!? what about user settings?
193     p_intf->p_sys->b_dvdmenus = false;
194     
195     fPlaylistIsEmpty = !( p_wrapper->PlaylistSize() > 0 );
196     
197     BScreen screen;
198     BRect screen_rect = screen.Frame();
199     BRect window_rect;
200     window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
201                      ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
202                      ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
203                      ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
204     fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, "Preferences" );
205     window_rect.Set( screen_rect.right - 500,
206                      screen_rect.top + 50,
207                      screen_rect.right - 150,
208                      screen_rect.top + 250 );
209     fPlaylistWindow = new PlayListWindow( window_rect, "Playlist", this, p_intf );
210     window_rect.Set( screen_rect.right - 500,
211                      screen_rect.top + 300,
212                      screen_rect.right - 150,
213                      screen_rect.top + 600 );
214     fMessagesWindow = new MessagesWindow( p_intf, window_rect, "Messages" );
215
216     // set the title bar
217     SetName( "interface" );
218     SetTitle( VOUT_TITLE );
219
220     // the media control view
221     p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
222                                            p_intf );
223     p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
224
225     float width, height;
226     p_mediaControl->GetPreferredSize( &width, &height );
227
228     // set up the main menu
229     fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
230                              B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
231
232     // make menu bar resize to correct height
233     float menuWidth, menuHeight;
234     fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
235     fMenuBar->ResizeTo( width, menuHeight );    // don't change! it's a workarround!
236     // take care of proper size for ourself
237     height += fMenuBar->Bounds().Height();
238     ResizeTo( width, height );
239
240     p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
241     AddChild( fMenuBar );
242     AddChild( p_mediaControl );
243
244     // Add the file Menu
245     BMenu* fileMenu = new BMenu( "File" );
246     fMenuBar->AddItem( fileMenu );
247     fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
248                                       new BMessage( OPEN_FILE ), 'O') );
249     
250     fileMenu->AddItem( new CDMenu( "Open Disc" ) );
251
252     fileMenu->AddItem( new BMenuItem( "Open Subtitles" B_UTF8_ELLIPSIS,
253                                       new BMessage( LOAD_SUBFILE ) ) );
254     
255     fileMenu->AddSeparatorItem();
256     BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
257                                      new BMessage( B_ABOUT_REQUESTED ), 'A');
258     item->SetTarget( be_app );
259     fileMenu->AddItem( item );
260     fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
261
262     fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
263     fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);
264
265     /* Add the Audio menu */
266     fAudioMenu = new BMenu( "Audio" );
267     fMenuBar->AddItem ( fAudioMenu );
268     fAudioMenu->AddItem( fLanguageMenu );
269     fAudioMenu->AddItem( fSubtitlesMenu );
270
271     fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
272     fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
273     fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
274     fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
275
276     /* Add the Navigation menu */
277     fNavigationMenu = new BMenu( "Navigation" );
278     fMenuBar->AddItem( fNavigationMenu );
279     fNavigationMenu->AddItem( fPrevTitleMI );
280     fNavigationMenu->AddItem( fNextTitleMI );
281     fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
282     fNavigationMenu->AddSeparatorItem();
283     fNavigationMenu->AddItem( fPrevChapterMI );
284     fNavigationMenu->AddItem( fNextChapterMI );
285     fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
286
287     /* Add the Speed menu */
288     fSpeedMenu = new BMenu( "Speed" );
289     fSpeedMenu->SetRadioMode( true );
290     fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
291     fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
292     fNormalMI->SetMarked(true); // default to normal speed
293     fSpeedMenu->AddItem( fNormalMI );
294     fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
295     fSpeedMenu->SetTargetForItems( this );
296     fMenuBar->AddItem( fSpeedMenu );
297
298     /* Add the Show menu */
299     fShowMenu = new BMenu( "Window" );
300     fShowMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
301                                        new BMessage( OPEN_PLAYLIST ), 'P') );
302     fShowMenu->AddItem( new BMenuItem( "Messages" B_UTF8_ELLIPSIS,
303                                        new BMessage( OPEN_MESSAGES ), 'M' ) );
304     fShowMenu->AddItem( new BMenuItem( "Settings" B_UTF8_ELLIPSIS,
305                                        new BMessage( OPEN_PREFERENCES ), 'S' ) );
306     fMenuBar->AddItem( fShowMenu );                            
307
308     /* Prepare fow showing */
309     _SetMenusEnabled( false );
310     p_mediaControl->SetEnabled( false );
311
312         _RestoreSettings();
313     
314 /*    // Restore interface settings
315         // main window size and position
316     int i_width = config_GetInt( p_intf, "beos-intf-width" ),
317         i_height = config_GetInt( p_intf, "beos-intf-height" ),
318         i_xpos = config_GetInt( p_intf, "beos-intf-xpos" ),
319         i_ypos = config_GetInt( p_intf, "beos-intf-ypos" );
320     if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
321     {
322         BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
323
324                 float minWidth, maxWidth, minHeight, maxHeight;
325                 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
326
327                 make_sure_frame_is_within_limits( r, minWidth, minHeight, maxWidth, maxHeight );
328                 if ( make_sure_frame_is_on_screen( r ) )
329                 {
330                 ResizeTo( r.Width(), r.Height() );
331                 MoveTo( r.LeftTop() );
332                 }
333     }
334         // playlist window size and position
335     i_width = config_GetInt( p_intf, "beos-playlist-width" ),
336     i_height = config_GetInt( p_intf, "beos-playlist-height" ),
337     i_xpos = config_GetInt( p_intf, "beos-playlist-xpos" ),
338     i_ypos = config_GetInt( p_intf, "beos-playlist-ypos" );
339     if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
340     {
341         BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
342
343                 float minWidth, maxWidth, minHeight, maxHeight;
344                 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
345
346                 make_sure_frame_is_within_limits( r, minWidth, minHeight, maxWidth, maxHeight );
347                 if ( make_sure_frame_is_on_screen( r ) )
348                 {
349                 fPlaylistWindow->ResizeTo( r.Width(), r.Height() );
350                 fPlaylistWindow->MoveTo( r.LeftTop() );
351                 }
352     }
353     // child windows are not running yet, that's why we aint locking them
354     // playlist showing
355     // messages window size and position
356     i_width = config_GetInt( p_intf, "beos-messages-width" ),
357     i_height = config_GetInt( p_intf, "beos-messages-height" ),
358     i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
359     i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
360     if( i_width && i_height && i_xpos && i_ypos )
361     {
362         BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
363
364                 float minWidth, maxWidth, minHeight, maxHeight;
365                 fMessagesWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
366
367                 make_sure_frame_is_within_limits( r, minWidth, minHeight, maxWidth, maxHeight );
368                 if ( make_sure_frame_is_on_screen( r ) )
369                 {
370                 fMessagesWindow->ResizeTo( r.Width(), r.Height() );
371                 fMessagesWindow->MoveTo( r.LeftTop() );
372                 }
373     }
374     if( config_GetInt( p_intf, "beos-playlist-show" ) )
375     {
376                 fPlaylistWindow->Show();
377     }
378     else
379     {
380                 fPlaylistWindow->Hide();
381                 fPlaylistWindow->Show();
382     }
383         // messages window size and position
384     i_width = config_GetInt( p_intf, "beos-messages-width" ),
385     i_height = config_GetInt( p_intf, "beos-messages-height" ),
386     i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
387     i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
388     if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
389     {
390         BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
391                 float minWidth, maxWidth, minHeight, maxHeight;
392                 fMessagesWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
393
394                 make_sure_frame_is_within_limits( r, minWidth, minHeight, maxWidth, maxHeight );
395                 if ( make_sure_frame_is_on_screen( r ) )
396                 {
397                 fMessagesWindow->ResizeTo( r.Width(), r.Height() );
398                 fMessagesWindow->MoveTo( r.LeftTop() );
399                 }
400     }
401     // messages showing
402     if( config_GetInt( p_intf, "beos-messages-show" ) )
403     {
404                 fMessagesWindow->Show();
405     }
406     else
407     {
408                 fMessagesWindow->Hide();
409                 fMessagesWindow->Show();
410     }*/
411     
412     Show();
413 }
414
415 InterfaceWindow::~InterfaceWindow()
416 {
417     if( fPlaylistWindow )
418         fPlaylistWindow->ReallyQuit();
419     fPlaylistWindow = NULL;
420     if( fMessagesWindow )
421         fMessagesWindow->ReallyQuit();
422     fMessagesWindow = NULL;
423         delete fFilePanel;
424         delete fSettings;
425 }
426
427 /*****************************************************************************
428  * InterfaceWindow::FrameResized
429  *****************************************************************************/
430 void
431 InterfaceWindow::FrameResized(float width, float height)
432 {
433     BRect r(Bounds());
434     fMenuBar->MoveTo(r.LeftTop());
435     fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
436     r.top += fMenuBar->Bounds().Height() + 1.0;
437     p_mediaControl->MoveTo(r.LeftTop());
438     p_mediaControl->ResizeTo(r.Width(), r.Height());
439 }
440
441 /*****************************************************************************
442  * InterfaceWindow::MessageReceived
443  *****************************************************************************/
444 void InterfaceWindow::MessageReceived( BMessage * p_message )
445 {
446     int playback_status;      // remember playback state
447     playback_status = p_wrapper->InputStatus();
448
449     switch( p_message->what )
450     {
451         case B_ABOUT_REQUESTED:
452         {
453             BAlert* alert = new BAlert( VOUT_TITLE,
454                                         "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
455             alert->Go();
456             break;
457         }
458         case TOGGLE_ON_TOP:
459             break;
460             
461         case OPEN_FILE:
462                 _ShowFilePanel( B_REFS_RECEIVED, "VideoLAN Client: Open Media Files" );
463             break;
464
465         case LOAD_SUBFILE:
466                 _ShowFilePanel( SUBFILE_RECEIVED, "VideoLAN Client: Open Subtitle File" );
467             break;
468
469         case OPEN_PLAYLIST:
470             if (fPlaylistWindow->Lock())
471             {
472                 if (fPlaylistWindow->IsHidden())
473                     fPlaylistWindow->Show();
474                 else
475                     fPlaylistWindow->Activate();
476                 fPlaylistWindow->Unlock();
477             }
478             break;
479         case OPEN_DVD:
480             {
481                 const char *psz_device;
482                 BString type( "dvd" );
483                 if( p_message->FindString( "device", &psz_device ) == B_OK )
484                 {
485                     BString device( psz_device );
486                     p_wrapper->OpenDisc( type, device, 0, 0 );
487                 }
488                 _UpdatePlaylist();
489             }
490             break;
491         
492         case SUBFILE_RECEIVED:
493         {
494             entry_ref ref;
495             if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
496             {
497                 BPath path( &ref );
498                 if ( path.InitCheck() == B_OK )
499                     p_wrapper->LoadSubFile( path.Path() );
500             }
501             break;
502         }
503     
504         case STOP_PLAYBACK:
505             // this currently stops playback not nicely
506             if (playback_status > UNDEF_S)
507             {
508                 p_wrapper->PlaylistStop();
509                 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
510             }
511             break;
512     
513         case START_PLAYBACK:
514             /*  starts playing in normal mode */
515     
516         case PAUSE_PLAYBACK:
517             /* toggle between pause and play */
518             if (playback_status > UNDEF_S)
519             {
520                 /* pause if currently playing */
521                 if ( playback_status == PLAYING_S )
522                 {
523                     p_wrapper->PlaylistPause();
524                 }
525                 else
526                 {
527                     p_wrapper->PlaylistPlay();
528                 }
529             }
530             else
531             {
532                 /* Play a new file */
533                 p_wrapper->PlaylistPlay();
534             }    
535             break;
536     
537         case FASTER_PLAY:
538             /* cycle the fast playback modes */
539             if (playback_status > UNDEF_S)
540             {
541                 p_wrapper->InputFaster();
542             }
543             break;
544     
545         case SLOWER_PLAY:
546             /*  cycle the slow playback modes */
547             if (playback_status > UNDEF_S)
548             {
549                 p_wrapper->InputSlower();
550             }
551             break;
552     
553         case NORMAL_PLAY:
554             /*  restore speed to normal if already playing */
555             if (playback_status > UNDEF_S)
556             {
557                 p_wrapper->PlaylistPlay();
558             }
559             break;
560     
561         case SEEK_PLAYBACK:
562             /* handled by semaphores */
563             break;
564         // volume related messages
565         case VOLUME_CHG:
566             /* adjust the volume */
567             if (playback_status > UNDEF_S)
568             {
569                 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
570                 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
571             }
572             break;
573     
574         case VOLUME_MUTE:
575             // toggle muting
576             if( p_wrapper->IsMuted() )
577                 p_wrapper->VolumeRestore();
578             else
579                 p_wrapper->VolumeMute();
580             p_mediaControl->SetMuted( p_wrapper->IsMuted() );
581             break;
582     
583         case SELECT_CHANNEL:
584             if ( playback_status > UNDEF_S )
585             {
586                 int32 channel;
587                 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
588                 {
589                     p_wrapper->ToggleLanguage( channel );
590                 }
591             }
592             break;
593     
594         case SELECT_SUBTITLE:
595             if ( playback_status > UNDEF_S )
596             {
597                 int32 subtitle;
598                 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
599                      p_wrapper->ToggleSubtitle( subtitle );
600             }
601             break;
602     
603         // specific navigation messages
604         case PREV_TITLE:
605         {
606             p_wrapper->PrevTitle();
607             break;
608         }
609         case NEXT_TITLE:
610         {
611             p_wrapper->NextTitle();
612             break;
613         }
614         case TOGGLE_TITLE:
615             if ( playback_status > UNDEF_S )
616             {
617                 int32 index;
618                 if( p_message->FindInt32( "index", &index ) == B_OK )
619                     p_wrapper->ToggleTitle( index );
620             }
621             break;
622         case PREV_CHAPTER:
623         {
624             p_wrapper->PrevChapter();
625             break;
626         }
627         case NEXT_CHAPTER:
628         {
629             p_wrapper->NextChapter();
630             break;
631         }
632         case TOGGLE_CHAPTER:
633             if ( playback_status > UNDEF_S )
634             {
635                 int32 index;
636                 if( p_message->FindInt32( "index", &index ) == B_OK )
637                     p_wrapper->ToggleChapter( index );
638             }
639             break;
640         case PREV_FILE:
641             p_wrapper->PlaylistPrev();
642             break;
643         case NEXT_FILE:
644             p_wrapper->PlaylistNext();
645             break;
646         // general next/prev functionality (skips to whatever makes most sense)
647         case NAVIGATE_PREV:
648             p_wrapper->NavigatePrev();
649             break;
650         case NAVIGATE_NEXT:
651             p_wrapper->NavigateNext();
652             break;
653         // drag'n'drop and system messages
654         case MSG_SOUNDPLAY:
655                 // convert soundplay drag'n'drop message (containing paths)
656                 // to normal message (containing refs)
657                 {
658                         const char* path;
659                         for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
660                         {
661                                 entry_ref ref;
662                                 if ( get_ref_for_path( path, &ref ) == B_OK )
663                                         p_message->AddRef( "refs", &ref );
664                         }
665                 }
666                 // fall through
667         case B_REFS_RECEIVED:
668         case B_SIMPLE_DATA:
669             {
670                 /* file(s) opened by the File menu -> append to the playlist;
671                  * file(s) opened by drag & drop -> replace playlist;
672                  * file(s) opened by 'shift' + drag & drop -> append */
673                 bool replace = false;
674                 bool reverse = false;
675                 if ( p_message->WasDropped() )
676                 {
677                     replace = !( modifiers() & B_SHIFT_KEY );
678                     reverse = true;
679                 }
680                     
681                 // build list of files to be played from message contents
682                 entry_ref ref;
683                 BList files;
684                 
685                 // if we should parse sub-folders as well
686                         bool askedAlready = false;
687                         bool parseSubFolders = askedAlready;
688                         // traverse refs in reverse order
689                         int32 count;
690                         type_code dummy;
691                         if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
692                         {
693                                 int32 i = reverse ? count - 1 : 0;
694                                 int32 increment = reverse ? -1 : 1;
695                         for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
696                         {
697                             BPath path( &ref );
698                             if ( path.InitCheck() == B_OK )
699                             {
700                                 bool add = true;
701                                 // has the user dropped a folder?
702                                 BDirectory dir( &ref );
703                                 if ( dir.InitCheck() == B_OK)
704                                 {
705                                         // has the user dropped a dvd disk icon?
706                                                                 if ( dir.IsRootDirectory() )
707                                                                 {
708                                                                         BVolumeRoster volRoster;
709                                                                         BVolume vol;
710                                                                         BDirectory volumeRoot;
711                                                                         status_t status = volRoster.GetNextVolume( &vol );
712                                                                         while ( status == B_NO_ERROR )
713                                                                         {
714                                                                                 if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
715                                                                                          && dir == volumeRoot )
716                                                                                 {
717                                                                                         BString volumeName;
718                                                                                         BString deviceName;
719                                                                                         bool isCDROM;
720                                                                                         if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
721                                                                                                  && isCDROM )
722                                                                                         {
723                                                                                                 BMessage msg( OPEN_DVD );
724                                                                                                 msg.AddString( "device", deviceName.String() );
725                                                                                                 PostMessage( &msg );
726                                                                                                 add = false;
727                                                                                         }
728                                                                                         break;
729                                                                                 }
730                                                                                 else
731                                                                                 {
732                                                                                         vol.Unset();
733                                                                                         status = volRoster.GetNextVolume( &vol );
734                                                                                 }
735                                                                         }
736                                                                 }
737                                         if ( add )
738                                         {
739                                                 add = false;
740                                                 dir.Rewind();   // defensive programming
741                                                 BEntry entry;
742                                                                         collect_folder_contents( dir, files,
743                                                                                                                          parseSubFolders,
744                                                                                                                          askedAlready,
745                                                                                                                          entry );
746                                         }
747                                 }
748                                 if ( add )
749                                 {
750                                         BString* string = new BString( path.Path() );
751                                         if ( !files.AddItem( string, 0 ) )
752                                                 delete string;  // at least don't leak
753                                 }
754                             }
755                         }
756                         // give the list to VLC
757                         // BString objects allocated here will be deleted there
758                         int32 index;
759                         if ( p_message->FindInt32("drop index", &index) != B_OK )
760                                 index = -1;
761                         p_wrapper->OpenFiles( &files, replace, index );
762                         _UpdatePlaylist();
763                         }
764             }
765             break;
766
767         case OPEN_PREFERENCES:
768         {
769             if( fPreferencesWindow->Lock() )
770             {
771                 if (fPreferencesWindow->IsHidden())
772                     fPreferencesWindow->Show();
773                 else
774                     fPreferencesWindow->Activate();
775                 fPreferencesWindow->Unlock();
776             }
777             break;
778         }
779
780         case OPEN_MESSAGES:
781         {
782             if( fMessagesWindow->Lock() )
783             {
784                 if (fMessagesWindow->IsHidden())
785                     fMessagesWindow->Show();
786                 else
787                     fMessagesWindow->Activate();
788                 fMessagesWindow->Unlock();
789             }
790             break;
791         }
792         case MSG_UPDATE:
793                 UpdateInterface();
794                 break;
795         default:
796             BWindow::MessageReceived( p_message );
797             break;
798     }
799
800 }
801
802 /*****************************************************************************
803  * InterfaceWindow::QuitRequested
804  *****************************************************************************/
805 bool InterfaceWindow::QuitRequested()
806 {
807     p_wrapper->PlaylistStop();
808     p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
809
810     /* Save interface settings */
811 /*    BRect frame = Frame();
812     config_PutInt( p_intf, "beos-intf-width", (int)frame.Width() );
813     config_PutInt( p_intf, "beos-intf-height", (int)frame.Height() );
814     config_PutInt( p_intf, "beos-intf-xpos", (int)frame.left );
815     config_PutInt( p_intf, "beos-intf-ypos", (int)frame.top );
816     if( fPlaylistWindow->Lock() )
817     {
818         frame = fPlaylistWindow->Frame();
819         config_PutInt( p_intf, "beos-playlist-width", (int)frame.Width() );
820         config_PutInt( p_intf, "beos-playlist-height", (int)frame.Height() );
821         config_PutInt( p_intf, "beos-playlist-xpos", (int)frame.left );
822         config_PutInt( p_intf, "beos-playlist-ypos", (int)frame.top );
823         config_PutInt( p_intf, "beos-playlist-show", !fPlaylistWindow->IsHidden() );
824         fPlaylistWindow->Unlock();
825     }
826     if( fMessagesWindow->Lock() )
827     {
828         frame = fMessagesWindow->Frame();
829         config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
830         config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
831         config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
832         config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
833         config_PutInt( p_intf, "beos-messages-show", !fMessagesWindow->IsHidden() );
834         fMessagesWindow->Unlock();
835     }*/
836     config_SaveConfigFile( p_intf, "beos" );
837         _StoreSettings();
838    
839     p_intf->b_die = 1;
840
841     return( true );
842 }
843
844 /*****************************************************************************
845  * InterfaceWindow::UpdateInterface
846  *****************************************************************************/
847 void InterfaceWindow::UpdateInterface()
848 {
849     if( p_wrapper->HasInput() )
850     {
851         if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
852         {
853             p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
854         }
855         else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
856         {
857             p_mediaControl->SetEnabled( true );
858             bool hasTitles = p_wrapper->HasTitles();
859             bool hasChapters = p_wrapper->HasChapters();
860             p_mediaControl->SetStatus( p_wrapper->InputStatus(), 
861                                        p_wrapper->InputRate() );
862             p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
863             _SetMenusEnabled( true, hasChapters, hasTitles );
864
865             _UpdateSpeedMenu( p_wrapper->InputRate() );
866
867             // enable/disable skip buttons
868             bool canSkipPrev;
869             bool canSkipNext;
870             p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
871             p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
872
873             if ( p_wrapper->HasAudio() )
874             {
875                 p_mediaControl->SetAudioEnabled( true );
876                 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
877             } else
878                 p_mediaControl->SetAudioEnabled( false );
879
880             Unlock();
881         }
882         // update playlist as well
883         if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
884         {
885             fPlaylistWindow->UpdatePlaylist();
886             fPlaylistWindow->Unlock();
887         }
888     }
889     else
890     {
891                 if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
892                 {
893                 _SetMenusEnabled( false );
894                 if( !( p_wrapper->PlaylistSize() > 0 ) )
895                     p_mediaControl->SetEnabled( false );
896                 else
897                 {
898                     p_mediaControl->SetProgress( 0 );
899                     // enable/disable skip buttons
900                     bool canSkipPrev;
901                     bool canSkipNext;
902                     p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
903                     p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
904                         }
905             Unlock();
906         }
907     }
908
909     /* always force the user-specified volume */
910     /* FIXME : I'm quite sure there is a cleaner way to do this */
911     int i_volume = p_mediaControl->GetVolume();
912     if( p_wrapper->GetVolume() != i_volume )
913     {
914         p_wrapper->SetVolume( i_volume );
915     }
916
917         // strangly, someone is calling this function even after the object has been destructed!
918         // even more strangly, this workarround seems to work
919         if (fMessagesWindow)
920             fMessagesWindow->UpdateMessages();
921
922     fLastUpdateTime = system_time();
923 }
924
925 /*****************************************************************************
926  * InterfaceWindow::IsStopped
927  *****************************************************************************/
928 bool
929 InterfaceWindow::IsStopped() const
930 {
931     return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
932 }
933
934 /*****************************************************************************
935  * InterfaceWindow::_UpdatePlaylist
936  *****************************************************************************/
937 void
938 InterfaceWindow::_UpdatePlaylist()
939 {
940     if ( fPlaylistWindow->Lock() )
941     {
942         fPlaylistWindow->UpdatePlaylist( true );
943         fPlaylistWindow->Unlock();
944         p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
945     }
946 }
947
948 /*****************************************************************************
949  * InterfaceWindow::_SetMenusEnabled
950  *****************************************************************************/
951 void
952 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
953 {
954     if (!hasFile)
955     {
956         hasChapters = false;
957         hasTitles = false;
958     }
959     if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
960     {
961         if ( fNextChapterMI->IsEnabled() != hasChapters )
962              fNextChapterMI->SetEnabled( hasChapters );
963         if ( fPrevChapterMI->IsEnabled() != hasChapters )
964              fPrevChapterMI->SetEnabled( hasChapters );
965         if ( fChapterMenu->IsEnabled() != hasChapters )
966              fChapterMenu->SetEnabled( hasChapters );
967         if ( fNextTitleMI->IsEnabled() != hasTitles )
968              fNextTitleMI->SetEnabled( hasTitles );
969         if ( fPrevTitleMI->IsEnabled() != hasTitles )
970              fPrevTitleMI->SetEnabled( hasTitles );
971         if ( fTitleMenu->IsEnabled() != hasTitles )
972              fTitleMenu->SetEnabled( hasTitles );
973         if ( fAudioMenu->IsEnabled() != hasFile )
974              fAudioMenu->SetEnabled( hasFile );
975         if ( fNavigationMenu->IsEnabled() != hasFile )
976              fNavigationMenu->SetEnabled( hasFile );
977         if ( fLanguageMenu->IsEnabled() != hasFile )
978              fLanguageMenu->SetEnabled( hasFile );
979         if ( fSubtitlesMenu->IsEnabled() != hasFile )
980              fSubtitlesMenu->SetEnabled( hasFile );
981         if ( fSpeedMenu->IsEnabled() != hasFile )
982              fSpeedMenu->SetEnabled( hasFile );
983         Unlock();
984     }
985 }
986
987 /*****************************************************************************
988  * InterfaceWindow::_UpdateSpeedMenu
989  *****************************************************************************/
990 void
991 InterfaceWindow::_UpdateSpeedMenu( int rate )
992 {
993     if ( rate == DEFAULT_RATE )
994     {
995         if ( !fNormalMI->IsMarked() )
996             fNormalMI->SetMarked( true );
997     }
998     else if ( rate < DEFAULT_RATE )
999     {
1000         if ( !fFasterMI->IsMarked() )
1001             fFasterMI->SetMarked( true );
1002     }
1003     else
1004     {
1005         if ( !fSlowerMI->IsMarked() )
1006             fSlowerMI->SetMarked( true );
1007     }
1008 }
1009
1010 /*****************************************************************************
1011  * InterfaceWindow::_InputStreamChanged
1012  *****************************************************************************/
1013 void
1014 InterfaceWindow::_InputStreamChanged()
1015 {
1016     // TODO: move more stuff from updateInterface() here!
1017     snooze( 400000 );
1018     p_wrapper->SetVolume( p_mediaControl->GetVolume() );
1019 }
1020
1021 /*****************************************************************************
1022  * InterfaceWindow::_ShowFilePanel
1023  *****************************************************************************/
1024 void
1025 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1026 {
1027         if( !fFilePanel )
1028         {
1029                 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1030                                                                          B_FILE_NODE | B_DIRECTORY_NODE );
1031                 fFilePanel->SetTarget( this );
1032         }
1033         fFilePanel->Window()->SetTitle( windowTitle );
1034         BMessage message( command );
1035         fFilePanel->SetMessage( &message );
1036         if ( !fFilePanel->IsShowing() )
1037         {
1038                 fFilePanel->Refresh();
1039                 fFilePanel->Show();
1040         }
1041 }
1042
1043 // set_window_pos
1044 void
1045 set_window_pos( BWindow* window, BRect frame )
1046 {
1047         // sanity checks: make sure window is not too big/small
1048         // and that it's not off-screen
1049         float minWidth, maxWidth, minHeight, maxHeight;
1050         window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1051
1052         make_sure_frame_is_within_limits( frame,
1053                                                                           minWidth, minHeight, maxWidth, maxHeight );
1054         if ( make_sure_frame_is_on_screen( frame ) )
1055         {
1056                 window->MoveTo( frame.LeftTop() );
1057                 window->ResizeTo( frame.Width(), frame.Height() );
1058         }
1059 }
1060
1061 // set_window_pos
1062 void
1063 launch_window( BWindow* window, bool showing )
1064 {
1065         if ( window->Lock() )
1066         {
1067                 if ( showing )
1068                 {
1069                         if ( window->IsHidden() )
1070                                 window->Show();
1071                 }
1072                 else
1073                 {
1074                         if ( !window->IsHidden() )
1075                                 window->Hide();
1076                 }
1077                 window->Unlock();
1078         }
1079 }
1080
1081 /*****************************************************************************
1082  * InterfaceWindow::_RestoreSettings
1083  *****************************************************************************/
1084 void
1085 InterfaceWindow::_RestoreSettings()
1086 {
1087         if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1088         {
1089                 BRect frame;
1090                 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1091                         set_window_pos( this, frame );
1092                 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1093                         set_window_pos( fPlaylistWindow, frame );
1094                 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1095                         set_window_pos( fMessagesWindow, frame );
1096                 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1097                         set_window_pos( fPreferencesWindow, frame );
1098                 
1099                 bool showing;
1100                 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1101                         launch_window( fPlaylistWindow, showing );
1102                 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1103                         launch_window( fMessagesWindow, showing );
1104                 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1105                         launch_window( fPreferencesWindow, showing );
1106
1107                 uint32 displayMode;
1108                 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1109                         fPlaylistWindow->SetDisplayMode( displayMode );
1110         }
1111 }
1112
1113 /*****************************************************************************
1114  * InterfaceWindow::_StoreSettings
1115  *****************************************************************************/
1116 void
1117 InterfaceWindow::_StoreSettings()
1118 {
1119         if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1120                 fSettings->AddRect( "main frame", Frame() );
1121         if ( fPlaylistWindow->Lock() )
1122         {
1123                 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1124                         fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1125                 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1126                         fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1127                 fPlaylistWindow->Unlock();
1128         }
1129         if ( fMessagesWindow->Lock() )
1130         {
1131                 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1132                         fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1133                 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1134                         fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1135                 fMessagesWindow->Unlock();
1136         }
1137         if ( fPreferencesWindow->Lock() )
1138         {
1139                 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1140                         fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1141                 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1142                         fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1143                 fPreferencesWindow->Unlock();
1144         }
1145
1146         uint32 displayMode = fPlaylistWindow->DisplayMode();
1147         if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1148                 fSettings->AddInt32( "playlist display mode", displayMode );
1149
1150         save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1151 }
1152
1153
1154
1155
1156
1157
1158 /*****************************************************************************
1159  * CDMenu::CDMenu
1160  *****************************************************************************/
1161 CDMenu::CDMenu(const char *name)
1162       : BMenu(name)
1163 {
1164 }
1165
1166 /*****************************************************************************
1167  * CDMenu::~CDMenu
1168  *****************************************************************************/
1169 CDMenu::~CDMenu()
1170 {
1171 }
1172
1173 /*****************************************************************************
1174  * CDMenu::AttachedToWindow
1175  *****************************************************************************/
1176 void CDMenu::AttachedToWindow(void)
1177 {
1178     // remove all items
1179     while ( BMenuItem* item = RemoveItem( 0L ) )
1180         delete item;
1181     GetCD( "/dev/disk" );
1182     BMenu::AttachedToWindow();
1183 }
1184
1185 /*****************************************************************************
1186  * CDMenu::GetCD
1187  *****************************************************************************/
1188 int CDMenu::GetCD( const char *directory )
1189 {
1190         BVolumeRoster volRoster;
1191         BVolume vol;
1192         BDirectory dir;
1193         status_t status = volRoster.GetNextVolume( &vol );
1194         while ( status ==  B_NO_ERROR )
1195         {
1196                 BString deviceName;
1197                 BString volumeName;
1198                 bool isCDROM;
1199                 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1200                          && isCDROM )
1201                 {
1202                         BMessage* msg = new BMessage( OPEN_DVD );
1203                         msg->AddString( "device", deviceName.String() );
1204                         BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1205                         AddItem( item );
1206                 }
1207                 vol.Unset();
1208                 status = volRoster.GetNextVolume( &vol );
1209         }
1210 }
1211
1212 /*****************************************************************************
1213  * LanguageMenu::LanguageMenu
1214  *****************************************************************************/
1215 LanguageMenu::LanguageMenu( const char *name, int menu_kind, 
1216                             VlcWrapper *p_wrapper )
1217     :BMenu(name)
1218 {
1219     kind = menu_kind;
1220     this->p_wrapper = p_wrapper;
1221 }
1222
1223 /*****************************************************************************
1224  * LanguageMenu::~LanguageMenu
1225  *****************************************************************************/
1226 LanguageMenu::~LanguageMenu()
1227 {
1228 }
1229
1230 /*****************************************************************************
1231  * LanguageMenu::AttachedToWindow
1232  *****************************************************************************/
1233 void LanguageMenu::AttachedToWindow()
1234 {
1235     // remove all items
1236     while ( BMenuItem* item = RemoveItem( 0L ) )
1237         delete item;
1238
1239     SetRadioMode( true );
1240         if ( BList *list = p_wrapper->GetChannels( kind ) )
1241         {
1242             for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1243                 AddItem( item );
1244             
1245             if ( list->CountItems() > 1 )
1246                 AddItem( new BSeparatorItem(), 1 );
1247         }
1248     BMenu::AttachedToWindow();
1249 }
1250
1251 /*****************************************************************************
1252  * TitleMenu::TitleMenu
1253  *****************************************************************************/
1254 TitleMenu::TitleMenu( const char *name, intf_thread_t  *p_interface )
1255     : BMenu(name),
1256     p_intf( p_interface )
1257 {
1258 }
1259
1260 /*****************************************************************************
1261  * TitleMenu::~TitleMenu
1262  *****************************************************************************/
1263 TitleMenu::~TitleMenu()
1264 {
1265 }
1266
1267 /*****************************************************************************
1268  * TitleMenu::AttachedToWindow
1269  *****************************************************************************/
1270 void TitleMenu::AttachedToWindow()
1271 {
1272     while( BMenuItem* item = RemoveItem( 0L ) )
1273         delete item;
1274
1275     if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1276         {    
1277                 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1278                 AddItem( item );
1279         }
1280     BMenu::AttachedToWindow();
1281 }
1282
1283
1284 /*****************************************************************************
1285  * ChapterMenu::ChapterMenu
1286  *****************************************************************************/
1287 ChapterMenu::ChapterMenu( const char *name, intf_thread_t  *p_interface )
1288     : BMenu(name),
1289     p_intf( p_interface )
1290 {
1291 }
1292
1293 /*****************************************************************************
1294  * ChapterMenu::~ChapterMenu
1295  *****************************************************************************/
1296 ChapterMenu::~ChapterMenu()
1297 {
1298 }
1299
1300 /*****************************************************************************
1301  * ChapterMenu::AttachedToWindow
1302  *****************************************************************************/
1303 void ChapterMenu::AttachedToWindow()
1304 {
1305     while( BMenuItem* item = RemoveItem( 0L ) )
1306         delete item;
1307
1308     if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1309         {    
1310             for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1311                 AddItem( item );
1312         }
1313     
1314     BMenu::AttachedToWindow();
1315 }
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325 /*****************************************************************************
1326  * load_settings
1327  *****************************************************************************/
1328 status_t
1329 load_settings( BMessage* message, const char* fileName, const char* folder )
1330 {
1331         status_t ret = B_BAD_VALUE;
1332         if ( message )
1333         {
1334                 BPath path;
1335                 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1336                 {
1337                         // passing folder is optional
1338                         if ( folder )
1339                                 ret = path.Append( folder );
1340                         if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1341                         {
1342                                 BFile file( path.Path(), B_READ_ONLY );
1343                                 if ( ( ret = file.InitCheck() ) == B_OK )
1344                                 {
1345                                         ret = message->Unflatten( &file );
1346                                         file.Unset();
1347                                 }
1348                         }
1349                 }
1350         }
1351         return ret;
1352 }
1353
1354 /*****************************************************************************
1355  * save_settings
1356  *****************************************************************************/
1357 status_t
1358 save_settings( BMessage* message, const char* fileName, const char* folder )
1359 {
1360         status_t ret = B_BAD_VALUE;
1361         if ( message )
1362         {
1363                 BPath path;
1364                 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1365                 {
1366                         // passing folder is optional
1367                         if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1368                                 ret = create_directory( path.Path(), 0777 );
1369                         if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1370                         {
1371                                 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1372                                 if ( ( ret = file.InitCheck() ) == B_OK )
1373                                 {
1374                                         ret = message->Flatten( &file );
1375                                         file.Unset();
1376                                 }
1377                         }
1378                 }
1379         }
1380         return ret;
1381 }