InterfaceWindow.cpp 45 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * InterfaceWindow.cpp: beos interface
 *****************************************************************************
 * Copyright (C) 1999, 2000, 2001 VideoLAN
5
 * $Id: InterfaceWindow.cpp,v 1.33 2003/04/18 16:10:28 titer Exp $
6
7
8
9
10
 *
 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
 *          Samuel Hocevar <sam@zoy.org>
 *          Tony Castley <tony@castley.net>
 *          Richard Shepherd <richard@rshepherd.demon.co.uk>
11
 *          Stephan Aßmus <stippi@yellowbites.com>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/* System headers */
#include <kernel/OS.h>
#include <InterfaceKit.h>
#include <AppKit.h>
#include <StorageKit.h>
#include <SupportKit.h>
#include <malloc.h>
#include <scsi.h>
#include <scsiprobe_driver.h>
#include <fs_info.h>
#include <string.h>

/* VLC headers */
#include <vlc/vlc.h>
#include <vlc/aout.h>
#include <vlc/intf.h>

/* BeOS interface headers */
46
#include "VlcWrapper.h"
47
48
49
#include "MsgVals.h"
#include "MediaControlView.h"
#include "PlayListWindow.h"
50
#include "PreferencesWindow.h"
51
#include "MessagesWindow.h"
52
53
#include "InterfaceWindow.h"

54
#define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
55
#define INTERFACE_LOCKING_TIMEOUT 5000
Stephan Assmus's avatar
   
Stephan Assmus committed
56
#define USE_VLC_CONFIG_FILE 0
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

// make_sure_frame_is_on_screen
bool
make_sure_frame_is_on_screen( BRect& frame )
{
	BScreen screen( B_MAIN_SCREEN_ID );
	if (frame.IsValid() && screen.IsValid()) {
		if (!screen.Frame().Contains(frame)) {
			// make sure frame fits in the screen
			if (frame.Width() > screen.Frame().Width())
				frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
			if (frame.Height() > screen.Frame().Height())
				frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
			// frame is now at the most the size of the screen
			if (frame.right > screen.Frame().right)
				frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
			if (frame.bottom > screen.Frame().bottom)
				frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
			if (frame.left < screen.Frame().left)
				frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
			if (frame.top < screen.Frame().top)
				frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
		}
		return true;
	}
	return false;
}

// make_sure_frame_is_within_limits
void
make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
                                  float maxWidth, float maxHeight )
{
    if ( frame.Width() < minWidth )
        frame.right = frame.left + minWidth;
    if ( frame.Height() < minHeight )
        frame.bottom = frame.top + minHeight;
    if ( frame.Width() > maxWidth )
        frame.right = frame.left + maxWidth;
    if ( frame.Height() > maxHeight )
        frame.bottom = frame.top + maxHeight;
}

// get_volume_info
bool
get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
{
	bool success = false;
	isCDROM = false;
	deviceName = "";
	volumeName = "";
	char name[B_FILE_NAME_LENGTH];
	if ( volume.GetName( name ) >= B_OK )	// disk is currently mounted
	{
		volumeName = name;
		dev_t dev = volume.Device();
		fs_info info;
		if ( fs_stat_dev( dev, &info ) == B_OK )
		{
			success = true;
			deviceName = info.device_name;
			if ( volume.IsReadOnly() )
			{
				int i_dev = open( info.device_name, O_RDONLY );
				if ( i_dev >= 0 )
				{
					device_geometry g;
					if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
						isCDROM = ( g.device_type == B_CD );
					close( i_dev );
				}
			}
		}
 	}
 	return success;
}
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// collect_folder_contents
void
collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
{
	while ( dir.GetNextEntry( &entry, true ) == B_OK )
	{
		if ( !entry.IsDirectory() )
		{
			BPath path;
			// since the directory will give us the entries in reverse order,
			// we put them each at the same index, effectively reversing the
			// items while adding them
			if ( entry.GetPath( &path ) == B_OK )
			{
				BString* string = new BString( path.Path() );
				if ( !list.AddItem( string, 0 ) )
					delete string;	// at least don't leak
			}
		}
		else
		{
			if ( !asked )
			{
				// ask user if we should parse sub-folders as well
				BAlert* alert = new BAlert( "sub-folders?",
											"Open files from all sub-folders as well?",
											"No", "Yes", NULL, B_WIDTH_AS_USUAL,
											B_IDEA_ALERT );
				int32 buttonIndex = alert->Go();
				deep = buttonIndex == 1;
				asked = true;
				// never delete BAlerts!!
			}
			if ( deep )
			{
				BDirectory subDir( &entry );
				if ( subDir.InitCheck() == B_OK )
					collect_folder_contents( subDir, list,
											 deep, asked, entry );
			}
		}
	}
}

178
179
180
181
182

/*****************************************************************************
 * InterfaceWindow
 *****************************************************************************/

183
184
InterfaceWindow::InterfaceWindow( BRect frame, const char* name,
                                  intf_thread_t* p_interface )
185
186
187
188
    : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
               B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
      p_intf( p_interface ),
      fFilePanel( NULL ),
189
190
191
      fLastUpdateTime( system_time() ),
	  fSettings( new BMessage( 'sett' ) ),
	  p_wrapper( p_intf->p_sys->p_wrapper )
192
{
193
	// TODO: ?!? what about user settings?
194
    p_intf->p_sys->b_dvdmenus = false;
195
    
196
    fPlaylistIsEmpty = !( p_wrapper->PlaylistSize() > 0 );
197
    
198
199
    BScreen screen;
    BRect screen_rect = screen.Frame();
200
201
202
203
204
    BRect window_rect;
    window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
                     ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
                     ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
                     ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
Stephan Assmus's avatar
   
Stephan Assmus committed
205
    fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, "Settings" );
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
    window_rect.Set( screen_rect.right - 500,
                     screen_rect.top + 50,
                     screen_rect.right - 150,
                     screen_rect.top + 250 );
    fPlaylistWindow = new PlayListWindow( window_rect, "Playlist", this, p_intf );
    window_rect.Set( screen_rect.right - 500,
                     screen_rect.top + 300,
                     screen_rect.right - 150,
                     screen_rect.top + 600 );
    fMessagesWindow = new MessagesWindow( p_intf, window_rect, "Messages" );

    // the media control view
    p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
                                           p_intf );
    p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );

    float width, height;
    p_mediaControl->GetPreferredSize( &width, &height );

    // set up the main menu
    fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
                             B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );

    // make menu bar resize to correct height
    float menuWidth, menuHeight;
    fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
    fMenuBar->ResizeTo( width, menuHeight );    // don't change! it's a workarround!
    // take care of proper size for ourself
    height += fMenuBar->Bounds().Height();
    ResizeTo( width, height );

    p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
    AddChild( fMenuBar );
    AddChild( p_mediaControl );

    // Add the file Menu
Eric Petit's avatar
Eric Petit committed
242
    BMenu* fileMenu = new BMenu( _("File") );
243
244
245
246
247
248
    fMenuBar->AddItem( fileMenu );
    fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
                                      new BMessage( OPEN_FILE ), 'O') );
    
    fileMenu->AddItem( new CDMenu( "Open Disc" ) );

249
    fileMenu->AddItem( new BMenuItem( "Open Subtitles" B_UTF8_ELLIPSIS,
250
251
252
253
254
255
256
257
258
259
260
261
262
                                      new BMessage( LOAD_SUBFILE ) ) );
    
    fileMenu->AddSeparatorItem();
    BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
                                     new BMessage( B_ABOUT_REQUESTED ), 'A');
    item->SetTarget( be_app );
    fileMenu->AddItem( item );
    fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );

    fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
    fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);

    /* Add the Audio menu */
Eric Petit's avatar
Eric Petit committed
263
    fAudioMenu = new BMenu( _("Audio") );
264
265
266
267
268
269
270
271
    fMenuBar->AddItem ( fAudioMenu );
    fAudioMenu->AddItem( fLanguageMenu );
    fAudioMenu->AddItem( fSubtitlesMenu );

    fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
    fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
    fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
    fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
Stephan Assmus's avatar
   
Stephan Assmus committed
272
    fGotoMenuMI = new BMenuItem( "Goto Menu", new BMessage( NAVIGATE_MENU ) );
273
274

    /* Add the Navigation menu */
Eric Petit's avatar
Eric Petit committed
275
    fNavigationMenu = new BMenu( _("Navigation") );
276
    fMenuBar->AddItem( fNavigationMenu );
Stephan Assmus's avatar
   
Stephan Assmus committed
277
278
    fNavigationMenu->AddItem( fGotoMenuMI );
    fNavigationMenu->AddSeparatorItem();
279
280
281
282
283
284
285
286
287
    fNavigationMenu->AddItem( fPrevTitleMI );
    fNavigationMenu->AddItem( fNextTitleMI );
    fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
    fNavigationMenu->AddSeparatorItem();
    fNavigationMenu->AddItem( fPrevChapterMI );
    fNavigationMenu->AddItem( fNextChapterMI );
    fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );

    /* Add the Speed menu */
Eric Petit's avatar
Eric Petit committed
288
    fSpeedMenu = new BMenu( _("Speed") );
289
290
291
292
293
294
295
296
297
298
    fSpeedMenu->SetRadioMode( true );
    fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
    fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
    fNormalMI->SetMarked(true); // default to normal speed
    fSpeedMenu->AddItem( fNormalMI );
    fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
    fSpeedMenu->SetTargetForItems( this );
    fMenuBar->AddItem( fSpeedMenu );

    /* Add the Show menu */
Eric Petit's avatar
Eric Petit committed
299
    fShowMenu = new BMenu( _("Window") );
300
301
302
303
304
305
306
307
308
309
310
    fShowMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
                                       new BMessage( OPEN_PLAYLIST ), 'P') );
    fShowMenu->AddItem( new BMenuItem( "Messages" B_UTF8_ELLIPSIS,
                                       new BMessage( OPEN_MESSAGES ), 'M' ) );
    fShowMenu->AddItem( new BMenuItem( "Settings" B_UTF8_ELLIPSIS,
                                       new BMessage( OPEN_PREFERENCES ), 'S' ) );
    fMenuBar->AddItem( fShowMenu );                            

    /* Prepare fow showing */
    _SetMenusEnabled( false );
    p_mediaControl->SetEnabled( false );
311

Stephan Assmus's avatar
   
Stephan Assmus committed
312
	_RestoreSettings();    
313

314
    Show();
315
316
317
318
}

InterfaceWindow::~InterfaceWindow()
{
319
    if( fPlaylistWindow )
320
        fPlaylistWindow->ReallyQuit();
321
    fPlaylistWindow = NULL;
322
323
    if( fMessagesWindow )
        fMessagesWindow->ReallyQuit();
324
    fMessagesWindow = NULL;
Stephan Assmus's avatar
   
Stephan Assmus committed
325
326
327
    if( fPreferencesWindow )
        fPreferencesWindow->ReallyQuit();
    fPreferencesWindow = NULL;
328
329
	delete fFilePanel;
	delete fSettings;
330
331
332
333
334
335
336
337
}

/*****************************************************************************
 * InterfaceWindow::FrameResized
 *****************************************************************************/
void
InterfaceWindow::FrameResized(float width, float height)
{
338
339
340
341
342
343
    BRect r(Bounds());
    fMenuBar->MoveTo(r.LeftTop());
    fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
    r.top += fMenuBar->Bounds().Height() + 1.0;
    p_mediaControl->MoveTo(r.LeftTop());
    p_mediaControl->ResizeTo(r.Width(), r.Height());
344
345
346
347
348
349
350
}

/*****************************************************************************
 * InterfaceWindow::MessageReceived
 *****************************************************************************/
void InterfaceWindow::MessageReceived( BMessage * p_message )
{
351
352
353
354
355
356
357
    int playback_status;      // remember playback state
    playback_status = p_wrapper->InputStatus();

    switch( p_message->what )
    {
        case B_ABOUT_REQUESTED:
        {
358
359
360
            BAlert* alert = new BAlert( "VLC " PACKAGE_VERSION,
                                        "VLC " PACKAGE_VERSION " for BeOS\n\n"
                                        "<www.videolan.org>", "OK");
361
362
363
364
365
366
367
            alert->Go();
            break;
        }
        case TOGGLE_ON_TOP:
            break;
            
        case OPEN_FILE:
368
        	_ShowFilePanel( B_REFS_RECEIVED, "VideoLAN Client: Open Media Files" );
369
            break;
370
371
372
373
374

        case LOAD_SUBFILE:
        	_ShowFilePanel( SUBFILE_RECEIVED, "VideoLAN Client: Open Subtitle File" );
            break;

375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
        case OPEN_PLAYLIST:
            if (fPlaylistWindow->Lock())
            {
                if (fPlaylistWindow->IsHidden())
                    fPlaylistWindow->Show();
                else
                    fPlaylistWindow->Activate();
                fPlaylistWindow->Unlock();
            }
            break;
        case OPEN_DVD:
            {
                const char *psz_device;
                BString type( "dvd" );
                if( p_message->FindString( "device", &psz_device ) == B_OK )
                {
                    BString device( psz_device );
                    p_wrapper->OpenDisc( type, device, 0, 0 );
                }
                _UpdatePlaylist();
            }
            break;
        
        case SUBFILE_RECEIVED:
        {
            entry_ref ref;
            if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
            {
                BPath path( &ref );
                if ( path.InitCheck() == B_OK )
405
                    p_wrapper->LoadSubFile( path.Path() );
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
            }
            break;
        }
    
        case STOP_PLAYBACK:
            // this currently stops playback not nicely
            if (playback_status > UNDEF_S)
            {
                p_wrapper->PlaylistStop();
                p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
            }
            break;
    
        case START_PLAYBACK:
            /*  starts playing in normal mode */
    
        case PAUSE_PLAYBACK:
            /* toggle between pause and play */
            if (playback_status > UNDEF_S)
            {
                /* pause if currently playing */
                if ( playback_status == PLAYING_S )
                {
                    p_wrapper->PlaylistPause();
                }
                else
                {
                    p_wrapper->PlaylistPlay();
                }
            }
            else
            {
                /* Play a new file */
                p_wrapper->PlaylistPlay();
            }    
            break;
    
        case FASTER_PLAY:
            /* cycle the fast playback modes */
            if (playback_status > UNDEF_S)
            {
                p_wrapper->InputFaster();
            }
            break;
    
        case SLOWER_PLAY:
            /*  cycle the slow playback modes */
            if (playback_status > UNDEF_S)
            {
                p_wrapper->InputSlower();
            }
            break;
    
        case NORMAL_PLAY:
            /*  restore speed to normal if already playing */
            if (playback_status > UNDEF_S)
            {
                p_wrapper->PlaylistPlay();
            }
            break;
    
        case SEEK_PLAYBACK:
            /* handled by semaphores */
            break;
        // volume related messages
        case VOLUME_CHG:
            /* adjust the volume */
            if (playback_status > UNDEF_S)
            {
                p_wrapper->SetVolume( p_mediaControl->GetVolume() );
                p_mediaControl->SetMuted( p_wrapper->IsMuted() );
            }
            break;
    
        case VOLUME_MUTE:
            // toggle muting
            if( p_wrapper->IsMuted() )
                p_wrapper->VolumeRestore();
            else
                p_wrapper->VolumeMute();
            p_mediaControl->SetMuted( p_wrapper->IsMuted() );
            break;
    
        case SELECT_CHANNEL:
            if ( playback_status > UNDEF_S )
            {
                int32 channel;
                if ( p_message->FindInt32( "channel", &channel ) == B_OK )
                {
                    p_wrapper->ToggleLanguage( channel );
                }
            }
            break;
    
        case SELECT_SUBTITLE:
            if ( playback_status > UNDEF_S )
            {
                int32 subtitle;
                if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
                     p_wrapper->ToggleSubtitle( subtitle );
            }
            break;
    
        // specific navigation messages
        case PREV_TITLE:
        {
            p_wrapper->PrevTitle();
            break;
        }
        case NEXT_TITLE:
        {
517
            p_wrapper->NextTitle();
518
519
            break;
        }
Stephan Assmus's avatar
   
Stephan Assmus committed
520
521
522
        case NAVIGATE_MENU:
        	p_wrapper->ToggleTitle( 0 );
        	break;
523
524
525
526
527
528
529
530
531
532
        case TOGGLE_TITLE:
            if ( playback_status > UNDEF_S )
            {
                int32 index;
                if( p_message->FindInt32( "index", &index ) == B_OK )
                    p_wrapper->ToggleTitle( index );
            }
            break;
        case PREV_CHAPTER:
        {
533
            p_wrapper->PrevChapter();
534
535
536
537
            break;
        }
        case NEXT_CHAPTER:
        {
538
            p_wrapper->NextChapter();
539
540
541
542
543
544
545
            break;
        }
        case TOGGLE_CHAPTER:
            if ( playback_status > UNDEF_S )
            {
                int32 index;
                if( p_message->FindInt32( "index", &index ) == B_OK )
Eric Petit's avatar
Eric Petit committed
546
                    p_wrapper->ToggleChapter( index );
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
            }
            break;
        case PREV_FILE:
            p_wrapper->PlaylistPrev();
            break;
        case NEXT_FILE:
            p_wrapper->PlaylistNext();
            break;
        // general next/prev functionality (skips to whatever makes most sense)
        case NAVIGATE_PREV:
            p_wrapper->NavigatePrev();
            break;
        case NAVIGATE_NEXT:
            p_wrapper->NavigateNext();
            break;
        // drag'n'drop and system messages
563
564
565
566
567
568
569
570
571
572
573
574
575
        case MSG_SOUNDPLAY:
        	// convert soundplay drag'n'drop message (containing paths)
        	// to normal message (containing refs)
        	{
	        	const char* path;
	        	for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
	        	{
	        		entry_ref ref;
	        		if ( get_ref_for_path( path, &ref ) == B_OK )
		        		p_message->AddRef( "refs", &ref );
	        	}
        	}
        	// fall through
576
577
578
579
580
581
582
        case B_REFS_RECEIVED:
        case B_SIMPLE_DATA:
            {
                /* file(s) opened by the File menu -> append to the playlist;
                 * file(s) opened by drag & drop -> replace playlist;
                 * file(s) opened by 'shift' + drag & drop -> append */
                bool replace = false;
583
                bool reverse = false;
584
                if ( p_message->WasDropped() )
585
                {
586
                    replace = !( modifiers() & B_SHIFT_KEY );
587
588
                    reverse = true;
                }
589
590
591
592
                    
                // build list of files to be played from message contents
                entry_ref ref;
                BList files;
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
                
                // if we should parse sub-folders as well
           		bool askedAlready = false;
           		bool parseSubFolders = askedAlready;
           		// traverse refs in reverse order
           		int32 count;
           		type_code dummy;
           		if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
           		{
           			int32 i = reverse ? count - 1 : 0;
           			int32 increment = reverse ? -1 : 1;
	                for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
	                {
	                    BPath path( &ref );
	                    if ( path.InitCheck() == B_OK )
	                    {
	                        bool add = true;
	                        // has the user dropped a folder?
	                        BDirectory dir( &ref );
	                        if ( dir.InitCheck() == B_OK)
	                        {
		                        // has the user dropped a dvd disk icon?
								if ( dir.IsRootDirectory() )
616
								{
617
618
619
620
621
									BVolumeRoster volRoster;
									BVolume vol;
									BDirectory volumeRoot;
									status_t status = volRoster.GetNextVolume( &vol );
									while ( status == B_NO_ERROR )
622
									{
623
624
										if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
											 && dir == volumeRoot )
625
										{
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
											BString volumeName;
											BString deviceName;
											bool isCDROM;
											if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
												 && isCDROM )
											{
												BMessage msg( OPEN_DVD );
												msg.AddString( "device", deviceName.String() );
												PostMessage( &msg );
												add = false;
											}
									 		break;
										}
										else
										{
									 		vol.Unset();
											status = volRoster.GetNextVolume( &vol );
643
644
645
										}
									}
								}
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
	                        	if ( add )
	                        	{
	                        		add = false;
	                        		dir.Rewind();	// defensive programming
	                        		BEntry entry;
									collect_folder_contents( dir, files,
															 parseSubFolders,
															 askedAlready,
															 entry );
	                        	}
	                        }
	                        if ( add )
	                        {
	                        	BString* string = new BString( path.Path() );
	                        	if ( !files.AddItem( string, 0 ) )
	                        		delete string;	// at least don't leak
	                        }
	                    }
	                }
	                // give the list to VLC
	                // BString objects allocated here will be deleted there
	                int32 index;
	                if ( p_message->FindInt32("drop index", &index) != B_OK )
	                	index = -1;
	                p_wrapper->OpenFiles( &files, replace, index );
	                _UpdatePlaylist();
           		}
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
            }
            break;

        case OPEN_PREFERENCES:
        {
            if( fPreferencesWindow->Lock() )
            {
                if (fPreferencesWindow->IsHidden())
                    fPreferencesWindow->Show();
                else
                    fPreferencesWindow->Activate();
                fPreferencesWindow->Unlock();
            }
            break;
        }

        case OPEN_MESSAGES:
        {
            if( fMessagesWindow->Lock() )
            {
                if (fMessagesWindow->IsHidden())
                    fMessagesWindow->Show();
                else
                    fMessagesWindow->Activate();
                fMessagesWindow->Unlock();
            }
            break;
        }
701
702
703
        case MSG_UPDATE:
        	UpdateInterface();
        	break;
704
705
706
707
        default:
            BWindow::MessageReceived( p_message );
            break;
    }
708

709
710
711
712
713
714
715
}

/*****************************************************************************
 * InterfaceWindow::QuitRequested
 *****************************************************************************/
bool InterfaceWindow::QuitRequested()
{
716
717
    p_wrapper->PlaylistStop();
    p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
718

719
720
 	_StoreSettings();
   
721
    p_intf->b_die = 1;
722

723
    return( true );
724
725
726
}

/*****************************************************************************
727
 * InterfaceWindow::UpdateInterface
728
 *****************************************************************************/
729
void InterfaceWindow::UpdateInterface()
730
{
731
    if( p_wrapper->HasInput() )
732
    {
733
734
        if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
        {
735
            p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
736
        }
737
        else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
        {
            p_mediaControl->SetEnabled( true );
            bool hasTitles = p_wrapper->HasTitles();
            bool hasChapters = p_wrapper->HasChapters();
            p_mediaControl->SetStatus( p_wrapper->InputStatus(), 
                                       p_wrapper->InputRate() );
            p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
            _SetMenusEnabled( true, hasChapters, hasTitles );

            _UpdateSpeedMenu( p_wrapper->InputRate() );

            // enable/disable skip buttons
            bool canSkipPrev;
            bool canSkipNext;
            p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
            p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );

Eric Petit's avatar
Eric Petit committed
755
            if ( p_wrapper->HasInput() )
756
757
758
759
760
761
762
763
764
            {
                p_mediaControl->SetAudioEnabled( true );
                p_mediaControl->SetMuted( p_wrapper->IsMuted() );
            } else
                p_mediaControl->SetAudioEnabled( false );

            Unlock();
        }
        // update playlist as well
765
        if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
766
767
768
769
770
        {
            fPlaylistWindow->UpdatePlaylist();
            fPlaylistWindow->Unlock();
        }
    }
771
    else
772
    {
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
		if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
		{
	        _SetMenusEnabled( false );
	        if( !( p_wrapper->PlaylistSize() > 0 ) )
	            p_mediaControl->SetEnabled( false );
	        else
	        {
	            p_mediaControl->SetProgress( 0 );
	            // enable/disable skip buttons
	            bool canSkipPrev;
	            bool canSkipNext;
	            p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
	            p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
			}
            Unlock();
        }
789
    }
790

791
    fLastUpdateTime = system_time();
792
793
794
795
796
797
798
799
}

/*****************************************************************************
 * InterfaceWindow::IsStopped
 *****************************************************************************/
bool
InterfaceWindow::IsStopped() const
{
800
    return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
801
802
803
804
805
806
807
808
}

/*****************************************************************************
 * InterfaceWindow::_UpdatePlaylist
 *****************************************************************************/
void
InterfaceWindow::_UpdatePlaylist()
{
809
810
811
812
813
814
    if ( fPlaylistWindow->Lock() )
    {
        fPlaylistWindow->UpdatePlaylist( true );
        fPlaylistWindow->Unlock();
        p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
    }
815
}
816

817
818
819
820
821
822
/*****************************************************************************
 * InterfaceWindow::_SetMenusEnabled
 *****************************************************************************/
void
InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
{
823
824
825
826
827
    if (!hasFile)
    {
        hasChapters = false;
        hasTitles = false;
    }
828
    if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
829
    {
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
        if ( fNextChapterMI->IsEnabled() != hasChapters )
             fNextChapterMI->SetEnabled( hasChapters );
        if ( fPrevChapterMI->IsEnabled() != hasChapters )
             fPrevChapterMI->SetEnabled( hasChapters );
        if ( fChapterMenu->IsEnabled() != hasChapters )
             fChapterMenu->SetEnabled( hasChapters );
        if ( fNextTitleMI->IsEnabled() != hasTitles )
             fNextTitleMI->SetEnabled( hasTitles );
        if ( fPrevTitleMI->IsEnabled() != hasTitles )
             fPrevTitleMI->SetEnabled( hasTitles );
        if ( fTitleMenu->IsEnabled() != hasTitles )
             fTitleMenu->SetEnabled( hasTitles );
        if ( fAudioMenu->IsEnabled() != hasFile )
             fAudioMenu->SetEnabled( hasFile );
        if ( fNavigationMenu->IsEnabled() != hasFile )
             fNavigationMenu->SetEnabled( hasFile );
        if ( fLanguageMenu->IsEnabled() != hasFile )
             fLanguageMenu->SetEnabled( hasFile );
        if ( fSubtitlesMenu->IsEnabled() != hasFile )
             fSubtitlesMenu->SetEnabled( hasFile );
        if ( fSpeedMenu->IsEnabled() != hasFile )
             fSpeedMenu->SetEnabled( hasFile );
Stephan Assmus's avatar
   
Stephan Assmus committed
852
853
854
855
        // "goto menu" menu item
        bool hasMenu = p_intf->p_sys->b_dvdmenus ? hasTitles : false;
        if ( fGotoMenuMI->IsEnabled() != hasMenu )
             fGotoMenuMI->SetEnabled( hasMenu );
856
857
        Unlock();
    }
858
859
860
}

/*****************************************************************************
861
 * InterfaceWindow::_UpdateSpeedMenu
862
 *****************************************************************************/
863
864
void
InterfaceWindow::_UpdateSpeedMenu( int rate )
865
{
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
    if ( rate == DEFAULT_RATE )
    {
        if ( !fNormalMI->IsMarked() )
            fNormalMI->SetMarked( true );
    }
    else if ( rate < DEFAULT_RATE )
    {
        if ( !fFasterMI->IsMarked() )
            fFasterMI->SetMarked( true );
    }
    else
    {
        if ( !fSlowerMI->IsMarked() )
            fSlowerMI->SetMarked( true );
    }
881
}
882

883
884
885
886
887
888
/*****************************************************************************
 * InterfaceWindow::_InputStreamChanged
 *****************************************************************************/
void
InterfaceWindow::_InputStreamChanged()
{
889
890
891
    // TODO: move more stuff from updateInterface() here!
    snooze( 400000 );
    p_wrapper->SetVolume( p_mediaControl->GetVolume() );
892
893
}

894
895
896
/*****************************************************************************
 * InterfaceWindow::_ShowFilePanel
 *****************************************************************************/
897
void
898
InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
899
{
900
901
	if( !fFilePanel )
	{
902
903
		fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
									 B_FILE_NODE | B_DIRECTORY_NODE );
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
		fFilePanel->SetTarget( this );
	}
	fFilePanel->Window()->SetTitle( windowTitle );
	BMessage message( command );
	fFilePanel->SetMessage( &message );
	if ( !fFilePanel->IsShowing() )
	{
		fFilePanel->Refresh();
		fFilePanel->Show();
	}
}

// set_window_pos
void
set_window_pos( BWindow* window, BRect frame )
{
	// sanity checks: make sure window is not too big/small
	// and that it's not off-screen
	float minWidth, maxWidth, minHeight, maxHeight;
	window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );

	make_sure_frame_is_within_limits( frame,
									  minWidth, minHeight, maxWidth, maxHeight );
	if ( make_sure_frame_is_on_screen( frame ) )
	{
		window->MoveTo( frame.LeftTop() );
		window->ResizeTo( frame.Width(), frame.Height() );
	}
}

// set_window_pos
void
launch_window( BWindow* window, bool showing )
{
	if ( window->Lock() )
	{
		if ( showing )
		{
			if ( window->IsHidden() )
				window->Show();
		}
		else
		{
			if ( !window->IsHidden() )
				window->Hide();
		}
		window->Unlock();
	}
}

/*****************************************************************************
 * InterfaceWindow::_RestoreSettings
 *****************************************************************************/
void
InterfaceWindow::_RestoreSettings()
{
Stephan Assmus's avatar
   
Stephan Assmus committed
960
	if ( USE_VLC_CONFIG_FILE )
961
	{
Stephan Assmus's avatar
   
Stephan Assmus committed
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
		// main window size and position
	    int i_width = config_GetInt( p_intf, "beos-intf-width" ),
	        i_height = config_GetInt( p_intf, "beos-intf-height" ),
	        i_xpos = config_GetInt( p_intf, "beos-intf-xpos" ),
	        i_ypos = config_GetInt( p_intf, "beos-intf-ypos" );
	    if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
	    {
	    	BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
	    	set_window_pos( this, r );
	    }
		// playlist window size and position
	    i_width = config_GetInt( p_intf, "beos-playlist-width" ),
	    i_height = config_GetInt( p_intf, "beos-playlist-height" ),
	    i_xpos = config_GetInt( p_intf, "beos-playlist-xpos" ),
	    i_ypos = config_GetInt( p_intf, "beos-playlist-ypos" );
	    if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
	    {
	    	BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
	    	set_window_pos( fPlaylistWindow, r );
	    }
	    // playlist showing
	    launch_window( fPlaylistWindow, config_GetInt( p_intf, "beos-playlist-show" ) );
	    // messages window size and position
	    i_width = config_GetInt( p_intf, "beos-messages-width" ),
	    i_height = config_GetInt( p_intf, "beos-messages-height" ),
	    i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
	    i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
	    if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
	    {
	    	BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
	    	set_window_pos( fMessagesWindow, r );
	    }
	    // messages showing
	    launch_window( fMessagesWindow, config_GetInt( p_intf, "beos-messages-show" ) );

		// messages window size and position
	    i_width = config_GetInt( p_intf, "beos-settings-width" ),
	    i_height = config_GetInt( p_intf, "beos-settings-height" ),
	    i_xpos = config_GetInt( p_intf, "beos-settings-xpos" ),
	    i_ypos = config_GetInt( p_intf, "beos-settings-ypos" );
	    if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
	    {
	    	BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
	    	set_window_pos( fPreferencesWindow, r );
	    }
	    // settings showing
	    launch_window( fPreferencesWindow, config_GetInt( p_intf, "beos-settings-show" ) );
	}
	else
	{
		if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
		{
			BRect frame;
			if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
				set_window_pos( this, frame );
			if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
				set_window_pos( fPlaylistWindow, frame );
			if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
				set_window_pos( fMessagesWindow, frame );
			if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
				set_window_pos( fPreferencesWindow, frame );
			
			bool showing;
			if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
				launch_window( fPlaylistWindow, showing );
			if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
				launch_window( fMessagesWindow, showing );
			if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
				launch_window( fPreferencesWindow, showing );
	
			uint32 displayMode;
			if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
				fPlaylistWindow->SetDisplayMode( displayMode );
		}
1036
	}
1037
1038
}

1039
1040
1041
1042
1043
1044
/*****************************************************************************
 * InterfaceWindow::_StoreSettings
 *****************************************************************************/
void
InterfaceWindow::_StoreSettings()
{
Stephan Assmus's avatar
   
Stephan Assmus committed
1045
	if ( USE_VLC_CONFIG_FILE )
1046
	{
Stephan Assmus's avatar
   
Stephan Assmus committed
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
	    // save interface settings in vlc config file
	    BRect frame = Frame();
	    config_PutInt( p_intf, "beos-intf-width", (int)frame.Width() );
	    config_PutInt( p_intf, "beos-intf-height", (int)frame.Height() );
	    config_PutInt( p_intf, "beos-intf-xpos", (int)frame.left );
	    config_PutInt( p_intf, "beos-intf-ypos", (int)frame.top );
	    if( fPlaylistWindow->Lock() )
	    {
	        frame = fPlaylistWindow->Frame();
	        config_PutInt( p_intf, "beos-playlist-width", (int)frame.Width() );
	        config_PutInt( p_intf, "beos-playlist-height", (int)frame.Height() );
	        config_PutInt( p_intf, "beos-playlist-xpos", (int)frame.left );
	        config_PutInt( p_intf, "beos-playlist-ypos", (int)frame.top );
	        config_PutInt( p_intf, "beos-playlist-show", !fPlaylistWindow->IsHidden() );
	        fPlaylistWindow->Unlock();
	    }
	    if( fMessagesWindow->Lock() )
	    {
	        frame = fMessagesWindow->Frame();
	        config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
	        config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
	        config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
	        config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
	        config_PutInt( p_intf, "beos-messages-show", !fMessagesWindow->IsHidden() );
	        fMessagesWindow->Unlock();
	    }
	    if( fPreferencesWindow->Lock() )
	    {
	        frame = fPreferencesWindow->Frame();
	        config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
	        config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
	        config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
	        config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
	        config_PutInt( p_intf, "beos-messages-show", !fPreferencesWindow->IsHidden() );
	        fPreferencesWindow->Unlock();
	    }
1083
	}
Stephan Assmus's avatar
   
Stephan Assmus committed
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
    else
    {
		if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
			fSettings->AddRect( "main frame", Frame() );
		if ( fPlaylistWindow->Lock() )
		{
			if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
				fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
			if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
				fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
			fPlaylistWindow->Unlock();
		}
		if ( fMessagesWindow->Lock() )
		{
			if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
				fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
			if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
				fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
			fMessagesWindow->Unlock();
		}
		if ( fPreferencesWindow->Lock() )
		{
			if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
				fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
			if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
				fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
			fPreferencesWindow->Unlock();
		}
		uint32 displayMode = fPlaylistWindow->DisplayMode();
		if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
			fSettings->AddInt32( "playlist display mode", displayMode );
	
		save_settings( fSettings, "interface_settings", "VideoLAN Client" );
    }
1118

Stephan Assmus's avatar
   
Stephan Assmus committed
1119
1120
1121
1122
1123
	// save VLC internal settings
	config_SaveConfigFile( p_intf, "beos" );
	config_SaveConfigFile( p_intf, "main" );
	config_SaveConfigFile( p_intf, "adjust" );
	config_SaveConfigFile( p_intf, "ffmpeg" );
1124
1125
1126
1127
1128
1129
1130
}






1131
1132
1133
1134
/*****************************************************************************
 * CDMenu::CDMenu
 *****************************************************************************/
CDMenu::CDMenu(const char *name)
1135
      : BMenu(name)
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
{
}

/*****************************************************************************
 * CDMenu::~CDMenu
 *****************************************************************************/
CDMenu::~CDMenu()
{
}

/*****************************************************************************
 * CDMenu::AttachedToWindow
 *****************************************************************************/
void CDMenu::AttachedToWindow(void)
{
1151
    // remove all items
1152
    while ( BMenuItem* item = RemoveItem( 0L ) )
1153
        delete item;
1154
    GetCD( "/dev/disk" );
1155
    BMenu::AttachedToWindow();
1156
1157
1158
1159
1160
1161
1162
}

/*****************************************************************************
 * CDMenu::GetCD
 *****************************************************************************/
int CDMenu::GetCD( const char *directory )
{
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
	BVolumeRoster volRoster;
	BVolume vol;
	BDirectory dir;
	status_t status = volRoster.GetNextVolume( &vol );
	while ( status ==  B_NO_ERROR )
	{
		BString deviceName;
		BString volumeName;
		bool isCDROM;
		if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
			 && isCDROM )
		{
			BMessage* msg = new BMessage( OPEN_DVD );
			msg->AddString( "device", deviceName.String() );
			BMenuItem* item = new BMenuItem( volumeName.String(), msg );
			AddItem( item );
		}
 		vol.Unset();
		status = volRoster.GetNextVolume( &vol );
	}
1183
1184
1185
1186
1187
}

/*****************************************************************************
 * LanguageMenu::LanguageMenu
 *****************************************************************************/
1188
LanguageMenu::LanguageMenu( const char *name, int menu_kind, 
1189
1190
                            VlcWrapper *p_wrapper )
    :BMenu(name)
1191
{
1192
1193
    kind = menu_kind;
    this->p_wrapper = p_wrapper;
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
}

/*****************************************************************************
 * LanguageMenu::~LanguageMenu
 *****************************************************************************/
LanguageMenu::~LanguageMenu()
{
}

/*****************************************************************************
 * LanguageMenu::AttachedToWindow
 *****************************************************************************/
1206
void LanguageMenu::AttachedToWindow()
1207
{
1208
1209
1210
    // remove all items
    while ( BMenuItem* item = RemoveItem( 0L ) )
        delete item;
1211

1212
    SetRadioMode( true );
1213
1214
1215
1216
1217
1218
1219
1220
	if ( BList *list = p_wrapper->GetChannels( kind ) )
	{
	    for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
	        AddItem( item );
	    
	    if ( list->CountItems() > 1 )
	        AddItem( new BSeparatorItem(), 1 );
	}
1221
    BMenu::AttachedToWindow();
1222
1223
}

1224
1225
1226
1227
/*****************************************************************************
 * TitleMenu::TitleMenu
 *****************************************************************************/
TitleMenu::TitleMenu( const char *name, intf_thread_t  *p_interface )
1228
1229
    : BMenu(name),
    p_intf( p_interface )
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
{
}

/*****************************************************************************
 * TitleMenu::~TitleMenu
 *****************************************************************************/
TitleMenu::~TitleMenu()
{
}

/*****************************************************************************
 * TitleMenu::AttachedToWindow
 *****************************************************************************/
void TitleMenu::AttachedToWindow()
{
1245
    while( BMenuItem* item = RemoveItem( 0L ) )
1246
        delete item;
1247
1248
1249
1250
1251
1252

    if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
	{    
		for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
	        AddItem( item );
	}
1253
    BMenu::AttachedToWindow();
1254
1255
1256
1257
1258
1259
1260
}


/*****************************************************************************
 * ChapterMenu::ChapterMenu
 *****************************************************************************/
ChapterMenu::ChapterMenu( const char *name, intf_thread_t  *p_interface )
1261
1262
    : BMenu(name),
    p_intf( p_interface )
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
{
}

/*****************************************************************************
 * ChapterMenu::~ChapterMenu
 *****************************************************************************/
ChapterMenu::~ChapterMenu()
{
}

/*****************************************************************************
 * ChapterMenu::AttachedToWindow
 *****************************************************************************/
void ChapterMenu::AttachedToWindow()
{
1278
    while( BMenuItem* item = RemoveItem( 0L ) )
1279
        delete item;
1280
1281
1282
1283
1284
1285

    if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
	{    
	    for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
	        AddItem( item );
	}
Eric Petit's avatar
Eric Petit committed
1286
    
1287
    BMenu::AttachedToWindow();
1288
1289
}

1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354








/*****************************************************************************
 * load_settings
 *****************************************************************************/
status_t
load_settings( BMessage* message, const char* fileName, const char* folder )
{
	status_t ret = B_BAD_VALUE;
	if ( message )
	{
		BPath path;
		if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
		{
			// passing folder is optional
			if ( folder )
				ret = path.Append( folder );
			if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
			{
				BFile file( path.Path(), B_READ_ONLY );
				if ( ( ret = file.InitCheck() ) == B_OK )
				{
					ret = message->Unflatten( &file );
					file.Unset();
				}
			}
		}
	}
	return ret;
}

/*****************************************************************************
 * save_settings
 *****************************************************************************/
status_t
save_settings( BMessage* message, const char* fileName, const char* folder )
{
	status_t ret = B_BAD_VALUE;
	if ( message )
	{
		BPath path;
		if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
		{
			// passing folder is optional
			if ( folder && ( ret = path.Append( folder ) ) == B_OK )
				ret = create_directory( path.Path(), 0777 );
			if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
			{
				BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
				if ( ( ret = file.InitCheck() ) == B_OK )
				{
					ret = message->Flatten( &file );
					file.Unset();
				}
			}
		}
	}
	return ret;
}