]> git.sesse.net Git - vlc/blob - modules/gui/beos/InterfaceWindow.cpp
ec92a03fe7b725237f4e0e0bb4dfa8e4bb294898
[vlc] / modules / gui / beos / InterfaceWindow.cpp
1 /*****************************************************************************
2  * InterfaceWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
5  * $Id$
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 <superstippi@gmx.de>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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
39 /* VLC headers */
40 #ifdef HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43
44 #include <vlc_common.h>
45 #include <vlc_aout.h>
46 #include <vlc_interface.h>
47
48 /* BeOS interface headers */
49 #include "MsgVals.h"
50 #include "MediaControlView.h"
51 #include "PlayListWindow.h"
52 #include "PreferencesWindow.h"
53 #include "MessagesWindow.h"
54 #include "InterfaceWindow.h"
55
56 #define INTERFACE_UPDATE_TIMEOUT  80000 // 2 frames if at 25 fps
57 #define INTERFACE_LOCKING_TIMEOUT 5000
58
59 // make_sure_frame_is_on_screen
60 bool
61 make_sure_frame_is_on_screen( BRect& frame )
62 {
63     BScreen screen( B_MAIN_SCREEN_ID );
64     if (frame.IsValid() && screen.IsValid()) {
65         if (!screen.Frame().Contains(frame)) {
66             // make sure frame fits in the screen
67             if (frame.Width() > screen.Frame().Width())
68                 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
69             if (frame.Height() > screen.Frame().Height())
70                 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
71             // frame is now at the most the size of the screen
72             if (frame.right > screen.Frame().right)
73                 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
74             if (frame.bottom > screen.Frame().bottom)
75                 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
76             if (frame.left < screen.Frame().left)
77                 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
78             if (frame.top < screen.Frame().top)
79                 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
80         }
81         return true;
82     }
83     return false;
84 }
85
86 // make_sure_frame_is_within_limits
87 void
88 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
89                                   float maxWidth, float maxHeight )
90 {
91     if ( frame.Width() < minWidth )
92         frame.right = frame.left + minWidth;
93     if ( frame.Height() < minHeight )
94         frame.bottom = frame.top + minHeight;
95     if ( frame.Width() > maxWidth )
96         frame.right = frame.left + maxWidth;
97     if ( frame.Height() > maxHeight )
98         frame.bottom = frame.top + maxHeight;
99 }
100
101 // get_volume_info
102 bool
103 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
104 {
105     bool success = false;
106     isCDROM = false;
107     deviceName = "";
108     volumeName = "";
109     char name[B_FILE_NAME_LENGTH];
110     if ( volume.GetName( name ) >= B_OK )    // disk is currently mounted
111     {
112         volumeName = name;
113         dev_t dev = volume.Device();
114         fs_info info;
115         if ( fs_stat_dev( dev, &info ) == B_OK )
116         {
117             success = true;
118             deviceName = info.device_name;
119             if ( volume.IsReadOnly() )
120             {
121                 int i_dev = open( info.device_name, O_RDONLY );
122                 if ( i_dev >= 0 )
123                 {
124                     device_geometry g;
125                     if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
126                         isCDROM = ( g.device_type == B_CD );
127                     close( i_dev );
128                 }
129             }
130         }
131      }
132      return success;
133 }
134
135 // collect_folder_contents
136 void
137 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
138 {
139     while ( dir.GetNextEntry( &entry, true ) == B_OK )
140     {
141         if ( !entry.IsDirectory() )
142         {
143             BPath path;
144             // since the directory will give us the entries in reverse order,
145             // we put them each at the same index, effectively reversing the
146             // items while adding them
147             if ( entry.GetPath( &path ) == B_OK )
148             {
149                 BString* string = new BString( path.Path() );
150                 if ( !list.AddItem( string, 0 ) )
151                     delete string;    // at least don't leak
152             }
153         }
154         else
155         {
156             if ( !asked )
157             {
158                 // ask user if we should parse sub-folders as well
159                 BAlert* alert = new BAlert( "sub-folders?",
160                                             _("Open files from all sub-folders as well?"),
161                                             _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,
162                                             B_IDEA_ALERT );
163                 int32 buttonIndex = alert->Go();
164                 deep = buttonIndex == 1;
165                 asked = true;
166                 // never delete BAlerts!!
167             }
168             if ( deep )
169             {
170                 BDirectory subDir( &entry );
171                 if ( subDir.InitCheck() == B_OK )
172                     collect_folder_contents( subDir, list,
173                                              deep, asked, entry );
174             }
175         }
176     }
177 }
178
179 static int PlaylistChanged( vlc_object_t *p_this, const char * psz_variable,
180                             vlc_value_t old_val, vlc_value_t new_val,
181                             void * param )
182 {
183     InterfaceWindow * w = (InterfaceWindow *) param;
184     w->UpdatePlaylist();
185     return VLC_SUCCESS;
186 }
187
188 /*****************************************************************************
189  * InterfaceWindow
190  *****************************************************************************/
191
192 InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
193                                   const char * name )
194     : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
195                B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
196
197       /* Initializations */
198       p_intf( _p_intf ),
199       p_input( NULL ),
200       p_playlist( NULL ),
201
202       fFilePanel( NULL ),
203       fLastUpdateTime( system_time() ),
204       fSettings( new BMessage( 'sett' ) )
205 {
206     p_playlist = pl_Hold( p_intf );
207
208     var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
209     var_AddCallback( p_playlist, "item-change", PlaylistChanged, this );
210     var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, this );
211     var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, this );
212     var_AddCallback( p_playlist, "item-current", PlaylistChanged, this );
213
214     char psz_tmp[1024];
215 #define ADD_ELLIPSIS( a ) \
216     memset( psz_tmp, 0, 1024 ); \
217     snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
218
219     BScreen screen;
220     BRect screen_rect = screen.Frame();
221     BRect window_rect;
222     window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
223                      ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
224                      ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
225                      ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
226     fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
227     window_rect.Set( screen_rect.right - 500,
228                      screen_rect.top + 50,
229                      screen_rect.right - 150,
230                      screen_rect.top + 250 );
231 #if 0
232     fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
233     window_rect.Set( screen_rect.right - 550,
234                      screen_rect.top + 300,
235                      screen_rect.right - 150,
236                      screen_rect.top + 500 );
237 #endif
238     fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
239
240     // the media control view
241     p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
242     p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
243
244     float width, height;
245     p_mediaControl->GetPreferredSize( &width, &height );
246
247     // set up the main menu
248     fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
249                              B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
250
251     // make menu bar resize to correct height
252     float menuWidth, menuHeight;
253     fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
254     fMenuBar->ResizeTo( width, menuHeight );    // don't change! it's a workarround!
255     // take care of proper size for ourself
256     height += fMenuBar->Bounds().Height();
257     ResizeTo( width, height );
258
259     p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
260     AddChild( fMenuBar );
261
262
263     // Add the file Menu
264     BMenu* fileMenu = new BMenu( _("File") );
265     fMenuBar->AddItem( fileMenu );
266     ADD_ELLIPSIS( _("Open File") );
267     fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
268     fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
269     ADD_ELLIPSIS( _("Open Subtitles") );
270     fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );
271
272     fileMenu->AddSeparatorItem();
273     ADD_ELLIPSIS( _("About") );
274     BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
275     item->SetTarget( be_app );
276     fileMenu->AddItem( item );
277     fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
278
279     fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
280     fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );
281
282     /* Add the Audio menu */
283     fAudioMenu = new BMenu( _("Audio") );
284     fMenuBar->AddItem ( fAudioMenu );
285     fAudioMenu->AddItem( fLanguageMenu );
286     fAudioMenu->AddItem( fSubtitlesMenu );
287
288     fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
289     fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
290     fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
291     fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );
292
293     /* Add the Navigation menu */
294     fNavigationMenu = new BMenu( _("Navigation") );
295     fMenuBar->AddItem( fNavigationMenu );
296     fNavigationMenu->AddItem( fPrevTitleMI );
297     fNavigationMenu->AddItem( fNextTitleMI );
298     fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
299     fNavigationMenu->AddSeparatorItem();
300     fNavigationMenu->AddItem( fPrevChapterMI );
301     fNavigationMenu->AddItem( fNextChapterMI );
302     fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
303
304     /* Add the Speed menu */
305     fSpeedMenu = new BMenu( _("Speed") );
306     fSpeedMenu->SetRadioMode( true );
307     fSpeedMenu->AddItem(
308         fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
309     fSpeedMenu->AddItem(
310         fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
311     fSpeedMenu->AddItem(
312         fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
313     fSpeedMenu->AddItem(
314         fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
315     fSpeedMenu->AddItem(
316         fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
317     fSpeedMenu->AddItem(
318         fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
319     fSpeedMenu->AddItem(
320         fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
321     fMenuBar->AddItem( fSpeedMenu );
322
323     /* Add the Show menu */
324     fShowMenu = new BMenu( _("Window") );
325 #if 0
326     ADD_ELLIPSIS( _("Playlist") );
327     fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
328 #endif
329     ADD_ELLIPSIS( _("Messages") );
330     fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
331     ADD_ELLIPSIS( _("Preferences") );
332     fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
333     fMenuBar->AddItem( fShowMenu );
334
335     // add the media control view after the menubar is complete
336     // because it will set the window size limits in AttachedToWindow()
337     // and the menubar needs to report the correct PreferredSize()
338     AddChild( p_mediaControl );
339
340     /* Prepare fow showing */
341     _SetMenusEnabled( false );
342     p_mediaControl->SetEnabled( false );
343
344     _RestoreSettings();
345
346     Show();
347 }
348
349 InterfaceWindow::~InterfaceWindow()
350 {
351     if( p_input )
352     {
353         vlc_object_release( p_input );
354     }
355     if( p_playlist )
356     {
357         vlc_object_release( p_playlist );
358     }
359 #if 0
360     if( fPlaylistWindow )
361     {
362         fPlaylistWindow->ReallyQuit();
363     }
364 #endif
365     if( fMessagesWindow )
366     {
367         fMessagesWindow->ReallyQuit();
368     }
369     if( fPreferencesWindow )
370     {
371         fPreferencesWindow->ReallyQuit();
372     }
373     delete fFilePanel;
374     delete fSettings;
375 }
376
377 /*****************************************************************************
378  * InterfaceWindow::FrameResized
379  *****************************************************************************/
380 void
381 InterfaceWindow::FrameResized(float width, float height)
382 {
383     BRect r(Bounds());
384     fMenuBar->MoveTo(r.LeftTop());
385     fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
386     r.top += fMenuBar->Bounds().Height() + 1.0;
387     p_mediaControl->MoveTo(r.LeftTop());
388     p_mediaControl->ResizeTo(r.Width(), r.Height());
389 }
390
391 /*****************************************************************************
392  * InterfaceWindow::MessageReceived
393  *****************************************************************************/
394 void InterfaceWindow::MessageReceived( BMessage * p_message )
395 {
396     switch( p_message->what )
397     {
398         case B_ABOUT_REQUESTED:
399         {
400             BAlert * alert;
401
402             alert = new BAlert( "VLC media player" VERSION,
403                                 "VLC media player" VERSION " (BeOS interface)\n\n"
404                                 "The VideoLAN team <videolan@videolan.org>\n"
405                                 "http://www.videolan.org/", _("OK") );
406             alert->Go();
407             break;
408         }
409         case TOGGLE_ON_TOP:
410             break;
411
412         case OPEN_FILE:
413             _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
414             break;
415
416         case LOAD_SUBFILE:
417             _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
418             break;
419 #if 0
420         case OPEN_PLAYLIST:
421             if (fPlaylistWindow->Lock())
422             {
423                 if (fPlaylistWindow->IsHidden())
424                     fPlaylistWindow->Show();
425                 else
426                     fPlaylistWindow->Activate();
427                 fPlaylistWindow->Unlock();
428             }
429             break;
430 #endif
431         case OPEN_DVD:
432             {
433                 const char * psz_device;
434                 if( p_playlist &&
435                     p_message->FindString( "device", &psz_device ) == B_OK )
436                 {
437                     char psz_uri[1024];
438                     memset( psz_uri, 0, 1024 );
439                     snprintf( psz_uri, 1024, "dvdnav:%s", psz_device );
440                     playlist_Add( p_playlist, psz_uri, psz_device,
441                         PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
442                 }
443                 UpdatePlaylist();
444             }
445             break;
446
447         case SUBFILE_RECEIVED:
448         {
449             entry_ref ref;
450             if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
451             {
452                 BPath path( &ref );
453                 if ( path.InitCheck() == B_OK )
454                     config_PutPsz( p_intf, "sub-file", path.Path() );
455             }
456             break;
457         }
458
459         case STOP_PLAYBACK:
460             if( p_playlist )
461             {
462                 playlist_Stop( p_playlist );
463             }
464             p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
465             break;
466
467         case START_PLAYBACK:
468         case PAUSE_PLAYBACK:
469         {
470             vlc_value_t val;
471             val.i_int = PLAYING_S;
472             if( p_input )
473             {
474                 var_Get( p_input, "state", &val );
475             }
476             if( p_input && val.i_int != PAUSE_S )
477             {
478                 val.i_int = PAUSE_S;
479                 var_Set( p_input, "state", val );
480             }
481             else
482             {
483                 playlist_Play( p_playlist );
484             }
485             break;
486         }
487         case HEIGHTH_PLAY:
488             if( p_input )
489             {
490                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
491             }
492             break;
493
494         case QUARTER_PLAY:
495             if( p_input )
496             {
497                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
498             }
499             break;
500
501         case HALF_PLAY:
502             if( p_input )
503             {
504                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
505             }
506             break;
507
508         case NORMAL_PLAY:
509             if( p_input )
510             {
511                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
512             }
513             break;
514
515         case TWICE_PLAY:
516             if( p_input )
517             {
518                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
519             }
520             break;
521
522         case FOUR_PLAY:
523             if( p_input )
524             {
525                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
526             }
527             break;
528
529         case HEIGHT_PLAY:
530             if( p_input )
531             {
532                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
533             }
534             break;
535
536         case SEEK_PLAYBACK:
537             /* handled by semaphores */
538             break;
539
540         case VOLUME_CHG:
541             aout_VolumeSet( p_intf, p_mediaControl->GetVolume() );
542             break;
543
544         case VOLUME_MUTE:
545             aout_VolumeMute( p_intf, NULL );
546             break;
547
548         case SELECT_CHANNEL:
549         {
550             int32 channel;
551             if( p_input )
552             {
553                 if( p_message->FindInt32( "audio-es", &channel ) == B_OK )
554                 {
555                     var_SetInteger( p_input, "audio-es", channel );
556                 }
557                 else if( p_message->FindInt32( "spu-es", &channel ) == B_OK )
558                 {
559                     var_SetInteger( p_input, "spu-es", channel );
560                 }
561             }
562             break;
563         }
564
565         case PREV_TITLE:
566             if( p_input )
567             {
568                 var_SetVoid( p_input, "prev-title" );
569             }
570             break;
571
572         case NEXT_TITLE:
573             if( p_input )
574             {
575                 var_SetVoid( p_input, "next-title" );
576             }
577             break;
578
579         case TOGGLE_TITLE:
580         {
581             int32 index;
582             if( p_input &&
583                 p_message->FindInt32( "index", &index ) == B_OK )
584             {
585                 var_SetInteger( p_input, "title", index );
586             }
587             break;
588         }
589
590         case PREV_CHAPTER:
591             if( p_input )
592             {
593                 var_SetVoid( p_input, "prev-chapter" );
594             }
595             break;
596
597         case NEXT_CHAPTER:
598             if( p_input )
599             {
600                 var_SetVoid( p_input, "next-chapter" );
601             }
602             break;
603
604         case TOGGLE_CHAPTER:
605         {
606             int32 index;
607             if( p_input &&
608                 p_message->FindInt32( "index", &index ) == B_OK )
609             {
610                 var_SetInteger( p_input, "chapter", index );
611             }
612             break;
613         }
614
615         case PREV_FILE:
616             if( p_playlist )
617             {
618                 playlist_Prev( p_playlist );
619             }
620             break;
621
622         case NEXT_FILE:
623             if( p_playlist )
624             {
625                 playlist_Next( p_playlist );
626             }
627             break;
628
629         case NAVIGATE_PREV:
630             if( p_input )
631             {
632                 vlc_value_t val;
633
634                 /* First try to go to previous chapter */
635                 if( !var_Get( p_input, "chapter", &val ) )
636                 {
637                     if( val.i_int > 1 )
638                     {
639                         var_SetVoid( p_input, "prev-chapter" );
640                         break;
641                     }
642                 }
643
644                 /* Try to go to previous title */
645                 if( !var_Get( p_input, "title", &val ) )
646                 {
647                     if( val.i_int > 1 )
648                     {
649                         var_SetVoid( p_input, "prev-title" );
650                         break;
651                     }
652                 }
653
654                 /* Try to go to previous file */
655                 if( p_playlist )
656                 {
657                     playlist_Prev( p_playlist );
658                 }
659             }
660             break;
661
662         case NAVIGATE_NEXT:
663             if( p_input )
664             {
665                 vlc_value_t val, val_list;
666
667                 /* First try to go to next chapter */
668                 if( !var_Get( p_input, "chapter", &val ) )
669                 {
670                     var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
671                                 &val_list, NULL );
672                     if( val_list.p_list->i_count > val.i_int )
673                     {
674                         var_FreeList( &val_list, NULL );
675                         var_SetVoid( p_input, "next-chapter" );
676                         break;
677                     }
678                     var_FreeList( &val_list, NULL );
679                 }
680
681                 /* Try to go to next title */
682                 if( !var_Get( p_input, "title", &val ) )
683                 {
684                     var_Change( p_input, "title", VLC_VAR_GETCHOICES,
685                                 &val_list, NULL );
686                     if( val_list.p_list->i_count > val.i_int )
687                     {
688                         var_FreeList( &val_list, NULL );
689                         var_SetVoid( p_input, "next-title" );
690                         break;
691                     }
692                     var_FreeList( &val_list, NULL );
693                 }
694
695                 /* Try to go to next file */
696                 if( p_playlist )
697                 {
698                     playlist_Next( p_playlist );
699                 }
700             }
701             break;
702
703         // drag'n'drop and system messages
704         case MSG_SOUNDPLAY:
705             // convert soundplay drag'n'drop message (containing paths)
706             // to normal message (containing refs)
707             {
708                 const char* path;
709                 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
710                 {
711                     entry_ref ref;
712                     if ( get_ref_for_path( path, &ref ) == B_OK )
713                         p_message->AddRef( "refs", &ref );
714                 }
715             }
716             // fall through
717         case B_REFS_RECEIVED:
718         case B_SIMPLE_DATA:
719         {
720             /* file(s) opened by the File menu -> append to the playlist;
721                file(s) opened by drag & drop -> replace playlist;
722                file(s) opened by 'shift' + drag & drop -> append */
723
724             int32 count;
725             type_code dummy;
726             if( p_message->GetInfo( "refs", &dummy, &count ) != B_OK ||
727                 count < 1 )
728             {
729                 break;
730             }
731
732             bool b_remove = ( p_message->WasDropped() &&
733                                     !( modifiers() & B_SHIFT_KEY ) );
734
735             if( b_remove && p_playlist )
736             {
737                 playlist_Clear( p_playlist, true );
738             }
739
740             entry_ref ref;
741             for( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
742             {
743                 BPath path( &ref );
744
745                 /* TODO: find out if this is a DVD icon */
746
747                 if( p_playlist )
748                 {
749                     playlist_Add( p_playlist, path.Path(), NULL,
750                        PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
751                 }
752             }
753
754             UpdatePlaylist();
755             break;
756         }
757
758         case OPEN_PREFERENCES:
759         {
760             if( fPreferencesWindow->Lock() )
761             {
762                 if (fPreferencesWindow->IsHidden())
763                     fPreferencesWindow->Show();
764                 else
765                     fPreferencesWindow->Activate();
766                 fPreferencesWindow->Unlock();
767             }
768             break;
769         }
770
771         case OPEN_MESSAGES:
772         {
773             if( fMessagesWindow->Lock() )
774             {
775                 if (fMessagesWindow->IsHidden())
776                     fMessagesWindow->Show();
777                 else
778                     fMessagesWindow->Activate();
779                 fMessagesWindow->Unlock();
780             }
781             break;
782         }
783         case MSG_UPDATE:
784             UpdateInterface();
785             break;
786         default:
787             BWindow::MessageReceived( p_message );
788             break;
789     }
790 }
791
792 /*****************************************************************************
793  * InterfaceWindow::QuitRequested
794  *****************************************************************************/
795 bool InterfaceWindow::QuitRequested()
796 {
797     if( p_playlist )
798     {
799         playlist_Stop( p_playlist );
800     }
801     p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
802
803      _StoreSettings();
804
805     vlc_object_kill( p_intf );
806
807     return( true );
808 }
809
810 /*****************************************************************************
811  * InterfaceWindow::UpdateInterface
812  *****************************************************************************/
813 void InterfaceWindow::UpdateInterface()
814 {
815     if( !p_input )
816     {
817         p_input = (input_thread_t *)
818             vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
819     }
820     else if( p_input->b_dead )
821     {
822         vlc_object_release( p_input );
823         p_input = NULL;
824     }
825
826     /* Get ready to update the interface */
827     if( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) != B_OK )
828     {
829         return;
830     }
831
832     if( b_playlist_update )
833     {
834 #if 0
835         if( fPlaylistWindow->Lock() )
836         {
837             fPlaylistWindow->UpdatePlaylist( true );
838             fPlaylistWindow->Unlock();
839             b_playlist_update = false;
840         }
841 #endif
842         p_mediaControl->SetEnabled( !playlist_IsEmpty( p_playlist ) );
843     }
844
845     if( p_input )
846     {
847         vlc_value_t val;
848         p_mediaControl->SetEnabled( true );
849         bool hasTitles   = !var_Get( p_input, "title", &val );
850         bool hasChapters = !var_Get( p_input, "chapter", &val );
851         p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
852                                    var_GetInteger( p_input, "rate" ) );
853         var_Get( p_input, "position", &val );
854         p_mediaControl->SetProgress( val.f_float );
855         _SetMenusEnabled( true, hasChapters, hasTitles );
856         _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
857
858         // enable/disable skip buttons
859 #if 0
860         bool canSkipPrev;
861         bool canSkipNext;
862         p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
863         p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
864 #endif
865
866         audio_volume_t i_volume;
867         aout_VolumeGet( p_intf, &i_volume );
868         p_mediaControl->SetAudioEnabled( true );
869         p_mediaControl->SetMuted( i_volume );
870     }
871     else
872     {
873         p_mediaControl->SetAudioEnabled( false );
874
875         _SetMenusEnabled( false );
876
877         if( !playlist_IsEmpty( p_playlist ) )
878         {
879             p_mediaControl->SetProgress( 0 );
880
881 #if 0
882             // enable/disable skip buttons
883             bool canSkipPrev;
884             bool canSkipNext;
885             p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
886             p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
887 #endif
888         }
889         else
890         {
891             p_mediaControl->SetEnabled( false );
892         }
893     }
894
895     Unlock();
896     fLastUpdateTime = system_time();
897 }
898
899 /*****************************************************************************
900  * InterfaceWindow::UpdatePlaylist
901  *****************************************************************************/
902 void
903 InterfaceWindow::UpdatePlaylist()
904 {
905     b_playlist_update = true;
906 }
907
908 /*****************************************************************************
909  * InterfaceWindow::IsStopped
910  *****************************************************************************/
911 bool
912 InterfaceWindow::IsStopped() const
913 {
914     return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
915 }
916
917 /*****************************************************************************
918  * InterfaceWindow::_SetMenusEnabled
919  *****************************************************************************/
920 void
921 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
922 {
923     if (!hasFile)
924     {
925         hasChapters = false;
926         hasTitles = false;
927     }
928     if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
929     {
930         if ( fNextChapterMI->IsEnabled() != hasChapters )
931              fNextChapterMI->SetEnabled( hasChapters );
932         if ( fPrevChapterMI->IsEnabled() != hasChapters )
933              fPrevChapterMI->SetEnabled( hasChapters );
934         if ( fChapterMenu->IsEnabled() != hasChapters )
935              fChapterMenu->SetEnabled( hasChapters );
936         if ( fNextTitleMI->IsEnabled() != hasTitles )
937              fNextTitleMI->SetEnabled( hasTitles );
938         if ( fPrevTitleMI->IsEnabled() != hasTitles )
939              fPrevTitleMI->SetEnabled( hasTitles );
940         if ( fTitleMenu->IsEnabled() != hasTitles )
941              fTitleMenu->SetEnabled( hasTitles );
942         if ( fAudioMenu->IsEnabled() != hasFile )
943              fAudioMenu->SetEnabled( hasFile );
944         if ( fNavigationMenu->IsEnabled() != hasFile )
945              fNavigationMenu->SetEnabled( hasFile );
946         if ( fLanguageMenu->IsEnabled() != hasFile )
947              fLanguageMenu->SetEnabled( hasFile );
948         if ( fSubtitlesMenu->IsEnabled() != hasFile )
949              fSubtitlesMenu->SetEnabled( hasFile );
950         if ( fSpeedMenu->IsEnabled() != hasFile )
951              fSpeedMenu->SetEnabled( hasFile );
952         Unlock();
953     }
954 }
955
956 /*****************************************************************************
957  * InterfaceWindow::_UpdateSpeedMenu
958  *****************************************************************************/
959 void
960 InterfaceWindow::_UpdateSpeedMenu( int rate )
961 {
962     BMenuItem * toMark = NULL;
963
964     switch( rate )
965     {
966         case ( INPUT_RATE_DEFAULT * 8 ):
967             toMark = fHeighthMI;
968             break;
969
970         case ( INPUT_RATE_DEFAULT * 4 ):
971             toMark = fQuarterMI;
972             break;
973
974         case ( INPUT_RATE_DEFAULT * 2 ):
975             toMark = fHalfMI;
976             break;
977
978         case ( INPUT_RATE_DEFAULT ):
979             toMark = fNormalMI;
980             break;
981
982         case ( INPUT_RATE_DEFAULT / 2 ):
983             toMark = fTwiceMI;
984             break;
985
986         case ( INPUT_RATE_DEFAULT / 4 ):
987             toMark = fFourMI;
988             break;
989
990         case ( INPUT_RATE_DEFAULT / 8 ):
991             toMark = fHeightMI;
992             break;
993     }
994
995     if ( toMark && !toMark->IsMarked() )
996     {
997         toMark->SetMarked( true );
998     }
999 }
1000
1001 /*****************************************************************************
1002  * InterfaceWindow::_ShowFilePanel
1003  *****************************************************************************/
1004 void
1005 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1006 {
1007     if( !fFilePanel )
1008     {
1009         fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1010                                      B_FILE_NODE | B_DIRECTORY_NODE );
1011         fFilePanel->SetTarget( this );
1012     }
1013     fFilePanel->Window()->SetTitle( windowTitle );
1014     BMessage message( command );
1015     fFilePanel->SetMessage( &message );
1016     if ( !fFilePanel->IsShowing() )
1017     {
1018         fFilePanel->Refresh();
1019         fFilePanel->Show();
1020     }
1021 }
1022
1023 // set_window_pos
1024 void
1025 set_window_pos( BWindow* window, BRect frame )
1026 {
1027     // sanity checks: make sure window is not too big/small
1028     // and that it's not off-screen
1029     float minWidth, maxWidth, minHeight, maxHeight;
1030     window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1031
1032     make_sure_frame_is_within_limits( frame,
1033                                       minWidth, minHeight, maxWidth, maxHeight );
1034     if ( make_sure_frame_is_on_screen( frame ) )
1035     {
1036         window->MoveTo( frame.LeftTop() );
1037         window->ResizeTo( frame.Width(), frame.Height() );
1038     }
1039 }
1040
1041 // set_window_pos
1042 void
1043 launch_window( BWindow* window, bool showing )
1044 {
1045     if ( window->Lock() )
1046     {
1047         if ( showing )
1048         {
1049             if ( window->IsHidden() )
1050                 window->Show();
1051         }
1052         else
1053         {
1054             if ( !window->IsHidden() )
1055                 window->Hide();
1056         }
1057         window->Unlock();
1058     }
1059 }
1060
1061 /*****************************************************************************
1062  * InterfaceWindow::_RestoreSettings
1063  *****************************************************************************/
1064 void
1065 InterfaceWindow::_RestoreSettings()
1066 {
1067     if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1068     {
1069         BRect frame;
1070         if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1071             set_window_pos( this, frame );
1072 #if 0
1073         if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1074             set_window_pos( fPlaylistWindow, frame );
1075 #endif
1076         if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1077             set_window_pos( fMessagesWindow, frame );
1078         if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1079         {
1080             /* FIXME: Preferences resizing doesn't work correctly yet */
1081             frame.right = frame.left + fPreferencesWindow->Frame().Width();
1082             frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
1083             set_window_pos( fPreferencesWindow, frame );
1084         }
1085
1086         bool showing;
1087 #if 0
1088         if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1089             launch_window( fPlaylistWindow, showing );
1090 #endif
1091         if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1092             launch_window( fMessagesWindow, showing );
1093         if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1094             launch_window( fPreferencesWindow, showing );
1095 #if 0
1096         uint32 displayMode;
1097         if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1098             fPlaylistWindow->SetDisplayMode( displayMode );
1099 #endif
1100     }
1101 }
1102
1103 /*****************************************************************************
1104  * InterfaceWindow::_StoreSettings
1105  *****************************************************************************/
1106 void
1107 InterfaceWindow::_StoreSettings()
1108 {
1109     /* Save the volume */
1110     config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1111
1112     /* Save the windows positions */
1113     if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1114         fSettings->AddRect( "main frame", Frame() );
1115 #if 0
1116     if ( fPlaylistWindow->Lock() )
1117     {
1118         if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1119             fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1120         if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1121             fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1122         fPlaylistWindow->Unlock();
1123     }
1124 #endif
1125     if ( fMessagesWindow->Lock() )
1126     {
1127         if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1128             fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1129         if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1130             fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1131         fMessagesWindow->Unlock();
1132     }
1133     if ( fPreferencesWindow->Lock() )
1134     {
1135         if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1136             fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1137         if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1138             fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1139         fPreferencesWindow->Unlock();
1140     }
1141 #if 0
1142     uint32 displayMode = fPlaylistWindow->DisplayMode();
1143     if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1144         fSettings->AddInt32( "playlist display mode", displayMode );
1145 #endif
1146     save_settings( fSettings, "interface_settings", "VideoLAN Client" );
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     return 0;
1203 }
1204
1205 /*****************************************************************************
1206  * LanguageMenu::LanguageMenu
1207  *****************************************************************************/
1208 LanguageMenu::LanguageMenu( intf_thread_t * _p_intf, const char * psz_name,
1209                             char * _psz_variable )
1210     : BMenu( psz_name )
1211 {
1212     p_intf       = _p_intf;
1213     psz_variable = strdup( _psz_variable );
1214 }
1215
1216 /*****************************************************************************
1217  * LanguageMenu::~LanguageMenu
1218  *****************************************************************************/
1219 LanguageMenu::~LanguageMenu()
1220 {
1221     free( psz_variable );
1222 }
1223
1224 /*****************************************************************************
1225  * LanguageMenu::AttachedToWindow
1226  *****************************************************************************/
1227 void LanguageMenu::AttachedToWindow()
1228 {
1229     BMenuItem * item;
1230
1231     // remove all items
1232     while( ( item = RemoveItem( 0L ) ) )
1233     {
1234         delete item;
1235     }
1236
1237     SetRadioMode( true );
1238
1239     input_thread_t * p_input = (input_thread_t *)
1240             vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1241     if( !p_input )
1242     {
1243         return;
1244     }
1245
1246     vlc_value_t val_list, text_list;
1247     BMessage * message;
1248     int i_current;
1249
1250     i_current = var_GetInteger( p_input, psz_variable );
1251     var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list );
1252     for( int i = 0; i < val_list.p_list->i_count; i++ )
1253     {
1254         message = new BMessage( SELECT_CHANNEL );
1255         message->AddInt32( psz_variable, val_list.p_list->p_values[i].i_int );
1256         item = new BMenuItem( text_list.p_list->p_values[i].psz_string, message );
1257         if( val_list.p_list->p_values[i].i_int == i_current )
1258         {
1259             item->SetMarked( true );
1260         }
1261         AddItem( item );
1262     }
1263     var_FreeList( &val_list, &text_list );
1264
1265     vlc_object_release( p_input );
1266
1267     BMenu::AttachedToWindow();
1268 }
1269
1270 /*****************************************************************************
1271  * TitleMenu::TitleMenu
1272  *****************************************************************************/
1273 TitleMenu::TitleMenu( const char *name, intf_thread_t  *p_interface )
1274     : BMenu(name),
1275     p_intf( p_interface )
1276 {
1277 }
1278
1279 /*****************************************************************************
1280  * TitleMenu::~TitleMenu
1281  *****************************************************************************/
1282 TitleMenu::~TitleMenu()
1283 {
1284 }
1285
1286 /*****************************************************************************
1287  * TitleMenu::AttachedToWindow
1288  *****************************************************************************/
1289 void TitleMenu::AttachedToWindow()
1290 {
1291     BMenuItem * item;
1292     while( ( item = RemoveItem( 0L ) ) )
1293     {
1294         delete item;
1295     }
1296
1297     input_thread_t * p_input;
1298     p_input = (input_thread_t *)
1299         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1300     if( !p_input )
1301     {
1302         return;
1303     }
1304
1305     vlc_value_t val;
1306     BMessage * message;
1307     if( !var_Get( p_input, "title", &val ) )
1308     {
1309         vlc_value_t val_list, text_list;
1310         var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1311                     &val_list, &text_list );
1312
1313         for( int i = 0; i < val_list.p_list->i_count; i++ )
1314         {
1315             message = new BMessage( TOGGLE_TITLE );
1316             message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1317             item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1318                                   message );
1319             if( val_list.p_list->p_values[i].i_int == val.i_int )
1320             {
1321                 item->SetMarked( true );
1322             }
1323             AddItem( item );
1324         }
1325
1326         var_FreeList( &val_list, &text_list );
1327     }
1328     vlc_object_release( p_input );
1329     BMenu::AttachedToWindow();
1330 }
1331
1332
1333 /*****************************************************************************
1334  * ChapterMenu::ChapterMenu
1335  *****************************************************************************/
1336 ChapterMenu::ChapterMenu( const char *name, intf_thread_t  *p_interface )
1337     : BMenu(name),
1338     p_intf( p_interface )
1339 {
1340 }
1341
1342 /*****************************************************************************
1343  * ChapterMenu::~ChapterMenu
1344  *****************************************************************************/
1345 ChapterMenu::~ChapterMenu()
1346 {
1347 }
1348
1349 /*****************************************************************************
1350  * ChapterMenu::AttachedToWindow
1351  *****************************************************************************/
1352 void ChapterMenu::AttachedToWindow()
1353 {
1354     BMenuItem * item;
1355     while( ( item = RemoveItem( 0L ) ) )
1356     {
1357         delete item;
1358     }
1359
1360     input_thread_t * p_input;
1361     p_input = (input_thread_t *)
1362         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1363     if( !p_input )
1364     {
1365         return;
1366     }
1367
1368     vlc_value_t val;
1369     BMessage * message;
1370     if( !var_Get( p_input, "chapter", &val ) )
1371     {
1372         vlc_value_t val_list, text_list;
1373         var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1374                     &val_list, &text_list );
1375
1376         for( int i = 0; i < val_list.p_list->i_count; i++ )
1377         {
1378             message = new BMessage( TOGGLE_CHAPTER );
1379             message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1380             item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1381                                   message );
1382             if( val_list.p_list->p_values[i].i_int == val.i_int )
1383             {
1384                 item->SetMarked( true );
1385             }
1386             AddItem( item );
1387         }
1388
1389         var_FreeList( &val_list, &text_list );
1390     }
1391     vlc_object_release( p_input );
1392     BMenu::AttachedToWindow();
1393 }
1394
1395
1396 /*****************************************************************************
1397  * load_settings
1398  *****************************************************************************/
1399 status_t
1400 load_settings( BMessage* message, const char* fileName, const char* folder )
1401 {
1402     status_t ret = B_BAD_VALUE;
1403     if ( message )
1404     {
1405         BPath path;
1406         if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1407         {
1408             // passing folder is optional
1409             if ( folder )
1410                 ret = path.Append( folder );
1411             if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1412             {
1413                 BFile file( path.Path(), B_READ_ONLY );
1414                 if ( ( ret = file.InitCheck() ) == B_OK )
1415                 {
1416                     ret = message->Unflatten( &file );
1417                     file.Unset();
1418                 }
1419             }
1420         }
1421     }
1422     return ret;
1423 }
1424
1425 /*****************************************************************************
1426  * save_settings
1427  *****************************************************************************/
1428 status_t
1429 save_settings( BMessage* message, const char* fileName, const char* folder )
1430 {
1431     status_t ret = B_BAD_VALUE;
1432     if ( message )
1433     {
1434         BPath path;
1435         if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1436         {
1437             // passing folder is optional
1438             if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1439                 ret = create_directory( path.Path(), 0777 );
1440             if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1441             {
1442                 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1443                 if ( ( ret = file.InitCheck() ) == B_OK )
1444                 {
1445                     ret = message->Flatten( &file );
1446                     file.Unset();
1447                 }
1448             }
1449         }
1450     }
1451     return ret;
1452 }