81e52c43968428f4a6b950f4802c787042bcb3a3
[vlc.git] / 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.28 2003/02/09 11:51:36 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 "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->HasInput() )
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         // strangly, someone is calling this function even after the object has been destructed!
910         // even more strangly, this workarround seems to work
911         if (fMessagesWindow)
912             fMessagesWindow->UpdateMessages();
913
914     fLastUpdateTime = system_time();
915 }
916
917 /*****************************************************************************
918  * InterfaceWindow::IsStopped
919  *****************************************************************************/
920 bool
921 InterfaceWindow::IsStopped() const
922 {
923     return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
924 }
925
926 /*****************************************************************************
927  * InterfaceWindow::_UpdatePlaylist
928  *****************************************************************************/
929 void
930 InterfaceWindow::_UpdatePlaylist()
931 {
932     if ( fPlaylistWindow->Lock() )
933     {
934         fPlaylistWindow->UpdatePlaylist( true );
935         fPlaylistWindow->Unlock();
936         p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
937     }
938 }
939
940 /*****************************************************************************
941  * InterfaceWindow::_SetMenusEnabled
942  *****************************************************************************/
943 void
944 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
945 {
946     if (!hasFile)
947     {
948         hasChapters = false;
949         hasTitles = false;
950     }
951     if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
952     {
953         if ( fNextChapterMI->IsEnabled() != hasChapters )
954              fNextChapterMI->SetEnabled( hasChapters );
955         if ( fPrevChapterMI->IsEnabled() != hasChapters )
956              fPrevChapterMI->SetEnabled( hasChapters );
957         if ( fChapterMenu->IsEnabled() != hasChapters )
958              fChapterMenu->SetEnabled( hasChapters );
959         if ( fNextTitleMI->IsEnabled() != hasTitles )
960              fNextTitleMI->SetEnabled( hasTitles );
961         if ( fPrevTitleMI->IsEnabled() != hasTitles )
962              fPrevTitleMI->SetEnabled( hasTitles );
963         if ( fTitleMenu->IsEnabled() != hasTitles )
964              fTitleMenu->SetEnabled( hasTitles );
965         if ( fAudioMenu->IsEnabled() != hasFile )
966              fAudioMenu->SetEnabled( hasFile );
967         if ( fNavigationMenu->IsEnabled() != hasFile )
968              fNavigationMenu->SetEnabled( hasFile );
969         if ( fLanguageMenu->IsEnabled() != hasFile )
970              fLanguageMenu->SetEnabled( hasFile );
971         if ( fSubtitlesMenu->IsEnabled() != hasFile )
972              fSubtitlesMenu->SetEnabled( hasFile );
973         if ( fSpeedMenu->IsEnabled() != hasFile )
974              fSpeedMenu->SetEnabled( hasFile );
975         Unlock();
976     }
977 }
978
979 /*****************************************************************************
980  * InterfaceWindow::_UpdateSpeedMenu
981  *****************************************************************************/
982 void
983 InterfaceWindow::_UpdateSpeedMenu( int rate )
984 {
985     if ( rate == DEFAULT_RATE )
986     {
987         if ( !fNormalMI->IsMarked() )
988             fNormalMI->SetMarked( true );
989     }
990     else if ( rate < DEFAULT_RATE )
991     {
992         if ( !fFasterMI->IsMarked() )
993             fFasterMI->SetMarked( true );
994     }
995     else
996     {
997         if ( !fSlowerMI->IsMarked() )
998             fSlowerMI->SetMarked( true );
999     }
1000 }
1001
1002 /*****************************************************************************
1003  * InterfaceWindow::_InputStreamChanged
1004  *****************************************************************************/
1005 void
1006 InterfaceWindow::_InputStreamChanged()
1007 {
1008     // TODO: move more stuff from updateInterface() here!
1009     snooze( 400000 );
1010     p_wrapper->SetVolume( p_mediaControl->GetVolume() );
1011 }
1012
1013 /*****************************************************************************
1014  * InterfaceWindow::_ShowFilePanel
1015  *****************************************************************************/
1016 void
1017 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1018 {
1019         if( !fFilePanel )
1020         {
1021                 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1022                                                                          B_FILE_NODE | B_DIRECTORY_NODE );
1023                 fFilePanel->SetTarget( this );
1024         }
1025         fFilePanel->Window()->SetTitle( windowTitle );
1026         BMessage message( command );
1027         fFilePanel->SetMessage( &message );
1028         if ( !fFilePanel->IsShowing() )
1029         {
1030                 fFilePanel->Refresh();
1031                 fFilePanel->Show();
1032         }
1033 }
1034
1035 // set_window_pos
1036 void
1037 set_window_pos( BWindow* window, BRect frame )
1038 {
1039         // sanity checks: make sure window is not too big/small
1040         // and that it's not off-screen
1041         float minWidth, maxWidth, minHeight, maxHeight;
1042         window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1043
1044         make_sure_frame_is_within_limits( frame,
1045                                                                           minWidth, minHeight, maxWidth, maxHeight );
1046         if ( make_sure_frame_is_on_screen( frame ) )
1047         {
1048                 window->MoveTo( frame.LeftTop() );
1049                 window->ResizeTo( frame.Width(), frame.Height() );
1050         }
1051 }
1052
1053 // set_window_pos
1054 void
1055 launch_window( BWindow* window, bool showing )
1056 {
1057         if ( window->Lock() )
1058         {
1059                 if ( showing )
1060                 {
1061                         if ( window->IsHidden() )
1062                                 window->Show();
1063                 }
1064                 else
1065                 {
1066                         if ( !window->IsHidden() )
1067                                 window->Hide();
1068                 }
1069                 window->Unlock();
1070         }
1071 }
1072
1073 /*****************************************************************************
1074  * InterfaceWindow::_RestoreSettings
1075  *****************************************************************************/
1076 void
1077 InterfaceWindow::_RestoreSettings()
1078 {
1079         if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1080         {
1081                 BRect frame;
1082                 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1083                         set_window_pos( this, frame );
1084                 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1085                         set_window_pos( fPlaylistWindow, frame );
1086                 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1087                         set_window_pos( fMessagesWindow, frame );
1088                 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1089                         set_window_pos( fPreferencesWindow, frame );
1090                 
1091                 bool showing;
1092                 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1093                         launch_window( fPlaylistWindow, showing );
1094                 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1095                         launch_window( fMessagesWindow, showing );
1096                 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1097                         launch_window( fPreferencesWindow, showing );
1098
1099                 uint32 displayMode;
1100                 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1101                         fPlaylistWindow->SetDisplayMode( displayMode );
1102         }
1103 }
1104
1105 /*****************************************************************************
1106  * InterfaceWindow::_StoreSettings
1107  *****************************************************************************/
1108 void
1109 InterfaceWindow::_StoreSettings()
1110 {
1111         if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1112                 fSettings->AddRect( "main frame", Frame() );
1113         if ( fPlaylistWindow->Lock() )
1114         {
1115                 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1116                         fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1117                 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1118                         fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1119                 fPlaylistWindow->Unlock();
1120         }
1121         if ( fMessagesWindow->Lock() )
1122         {
1123                 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1124                         fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1125                 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1126                         fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1127                 fMessagesWindow->Unlock();
1128         }
1129         if ( fPreferencesWindow->Lock() )
1130         {
1131                 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1132                         fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1133                 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1134                         fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1135                 fPreferencesWindow->Unlock();
1136         }
1137
1138         uint32 displayMode = fPlaylistWindow->DisplayMode();
1139         if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1140                 fSettings->AddInt32( "playlist display mode", displayMode );
1141
1142         save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1143 }
1144
1145
1146
1147
1148
1149
1150 /*****************************************************************************
1151  * CDMenu::CDMenu
1152  *****************************************************************************/
1153 CDMenu::CDMenu(const char *name)
1154       : BMenu(name)
1155 {
1156 }
1157
1158 /*****************************************************************************
1159  * CDMenu::~CDMenu
1160  *****************************************************************************/
1161 CDMenu::~CDMenu()
1162 {
1163 }
1164
1165 /*****************************************************************************
1166  * CDMenu::AttachedToWindow
1167  *****************************************************************************/
1168 void CDMenu::AttachedToWindow(void)
1169 {
1170     // remove all items
1171     while ( BMenuItem* item = RemoveItem( 0L ) )
1172         delete item;
1173     GetCD( "/dev/disk" );
1174     BMenu::AttachedToWindow();
1175 }
1176
1177 /*****************************************************************************
1178  * CDMenu::GetCD
1179  *****************************************************************************/
1180 int CDMenu::GetCD( const char *directory )
1181 {
1182         BVolumeRoster volRoster;
1183         BVolume vol;
1184         BDirectory dir;
1185         status_t status = volRoster.GetNextVolume( &vol );
1186         while ( status ==  B_NO_ERROR )
1187         {
1188                 BString deviceName;
1189                 BString volumeName;
1190                 bool isCDROM;
1191                 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1192                          && isCDROM )
1193                 {
1194                         BMessage* msg = new BMessage( OPEN_DVD );
1195                         msg->AddString( "device", deviceName.String() );
1196                         BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1197                         AddItem( item );
1198                 }
1199                 vol.Unset();
1200                 status = volRoster.GetNextVolume( &vol );
1201         }
1202 }
1203
1204 /*****************************************************************************
1205  * LanguageMenu::LanguageMenu
1206  *****************************************************************************/
1207 LanguageMenu::LanguageMenu( const char *name, int menu_kind, 
1208                             VlcWrapper *p_wrapper )
1209     :BMenu(name)
1210 {
1211     kind = menu_kind;
1212     this->p_wrapper = p_wrapper;
1213 }
1214
1215 /*****************************************************************************
1216  * LanguageMenu::~LanguageMenu
1217  *****************************************************************************/
1218 LanguageMenu::~LanguageMenu()
1219 {
1220 }
1221
1222 /*****************************************************************************
1223  * LanguageMenu::AttachedToWindow
1224  *****************************************************************************/
1225 void LanguageMenu::AttachedToWindow()
1226 {
1227     // remove all items
1228     while ( BMenuItem* item = RemoveItem( 0L ) )
1229         delete item;
1230
1231     SetRadioMode( true );
1232         if ( BList *list = p_wrapper->GetChannels( kind ) )
1233         {
1234             for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1235                 AddItem( item );
1236             
1237             if ( list->CountItems() > 1 )
1238                 AddItem( new BSeparatorItem(), 1 );
1239         }
1240     BMenu::AttachedToWindow();
1241 }
1242
1243 /*****************************************************************************
1244  * TitleMenu::TitleMenu
1245  *****************************************************************************/
1246 TitleMenu::TitleMenu( const char *name, intf_thread_t  *p_interface )
1247     : BMenu(name),
1248     p_intf( p_interface )
1249 {
1250 }
1251
1252 /*****************************************************************************
1253  * TitleMenu::~TitleMenu
1254  *****************************************************************************/
1255 TitleMenu::~TitleMenu()
1256 {
1257 }
1258
1259 /*****************************************************************************
1260  * TitleMenu::AttachedToWindow
1261  *****************************************************************************/
1262 void TitleMenu::AttachedToWindow()
1263 {
1264     while( BMenuItem* item = RemoveItem( 0L ) )
1265         delete item;
1266
1267     if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1268         {    
1269                 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1270                 AddItem( item );
1271         }
1272     BMenu::AttachedToWindow();
1273 }
1274
1275
1276 /*****************************************************************************
1277  * ChapterMenu::ChapterMenu
1278  *****************************************************************************/
1279 ChapterMenu::ChapterMenu( const char *name, intf_thread_t  *p_interface )
1280     : BMenu(name),
1281     p_intf( p_interface )
1282 {
1283 }
1284
1285 /*****************************************************************************
1286  * ChapterMenu::~ChapterMenu
1287  *****************************************************************************/
1288 ChapterMenu::~ChapterMenu()
1289 {
1290 }
1291
1292 /*****************************************************************************
1293  * ChapterMenu::AttachedToWindow
1294  *****************************************************************************/
1295 void ChapterMenu::AttachedToWindow()
1296 {
1297     while( BMenuItem* item = RemoveItem( 0L ) )
1298         delete item;
1299
1300     if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1301         {    
1302             for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1303                 AddItem( item );
1304         }
1305     
1306     BMenu::AttachedToWindow();
1307 }
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317 /*****************************************************************************
1318  * load_settings
1319  *****************************************************************************/
1320 status_t
1321 load_settings( BMessage* message, const char* fileName, const char* folder )
1322 {
1323         status_t ret = B_BAD_VALUE;
1324         if ( message )
1325         {
1326                 BPath path;
1327                 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1328                 {
1329                         // passing folder is optional
1330                         if ( folder )
1331                                 ret = path.Append( folder );
1332                         if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1333                         {
1334                                 BFile file( path.Path(), B_READ_ONLY );
1335                                 if ( ( ret = file.InitCheck() ) == B_OK )
1336                                 {
1337                                         ret = message->Unflatten( &file );
1338                                         file.Unset();
1339                                 }
1340                         }
1341                 }
1342         }
1343         return ret;
1344 }
1345
1346 /*****************************************************************************
1347  * save_settings
1348  *****************************************************************************/
1349 status_t
1350 save_settings( BMessage* message, const char* fileName, const char* folder )
1351 {
1352         status_t ret = B_BAD_VALUE;
1353         if ( message )
1354         {
1355                 BPath path;
1356                 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1357                 {
1358                         // passing folder is optional
1359                         if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1360                                 ret = create_directory( path.Path(), 0777 );
1361                         if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1362                         {
1363                                 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1364                                 if ( ( ret = file.InitCheck() ) == B_OK )
1365                                 {
1366                                         ret = message->Flatten( &file );
1367                                         file.Unset();
1368                                 }
1369                         }
1370                 }
1371         }
1372         return ret;
1373 }