1 /*****************************************************************************
2 * PlayListWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: PlayListWindow.cpp,v 1.3 2002/10/10 23:11:52 titer Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tony@castley.net>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
11 * Stephan Aßmus <stippi@yellowbites.com>
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.
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.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
29 #include <InterfaceKit.h>
30 #include <StorageKit.h>
37 /* BeOS interface headers */
38 #include "VlcWrapper.h"
39 #include "InterfaceWindow.h"
40 #include "ListViews.h"
42 #include "PlayListWindow.h"
46 MSG_SELECT_ALL = 'sall',
47 MSG_SELECT_NONE = 'none',
48 MSG_RANDOMIZE = 'rndm',
49 MSG_SORT_NAME = 'srtn',
50 MSG_SORT_PATH = 'srtp',
52 MSG_REMOVE_ALL = 'rmal',
56 /*****************************************************************************
57 * PlayListWindow::PlayListWindow
58 *****************************************************************************/
59 PlayListWindow::PlayListWindow( BRect frame, const char* name,
61 InterfaceWindow* mainWindow,
62 intf_thread_t *p_interface )
63 : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
64 B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
65 fPlaylist( playlist ),
66 fMainWindow( mainWindow )
68 this->p_intf = p_interface;
69 SetName( "playlist" );
71 // set up the main menu bar
72 fMenuBar = new BMenuBar( BRect(0.0, 0.0, frame.Width(), 15.0), "main menu",
73 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
78 BMenu *fileMenu = new BMenu( "File" );
79 fMenuBar->AddItem( fileMenu );
80 BMenuItem* item = new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
81 new BMessage( OPEN_FILE ), 'O' );
82 item->SetTarget( fMainWindow );
83 fileMenu->AddItem( item );
85 CDMenu* cd_menu = new CDMenu( "Open Disc" );
86 fileMenu->AddItem( cd_menu );
88 fileMenu->AddSeparatorItem();
89 item = new BMenuItem( "Close",
90 new BMessage( B_QUIT_REQUESTED ), 'W' );
91 fileMenu->AddItem( item );
94 BMenu *editMenu = new BMenu( "Edit" );
95 fMenuBar->AddItem( editMenu );
96 item = new BMenuItem( "Select All",
97 new BMessage( MSG_SELECT_ALL ), 'A' );
98 editMenu->AddItem( item );
99 item = new BMenuItem( "Select None",
100 new BMessage( MSG_SELECT_NONE ), 'A', B_SHIFT_KEY );
101 editMenu->AddItem( item );
103 editMenu->AddSeparatorItem();
104 item = new BMenuItem( "Sort by Name",
105 new BMessage( MSG_SORT_NAME ), 'N' );
106 editMenu->AddItem( item );
107 item = new BMenuItem( "Sort by Path",
108 new BMessage( MSG_SORT_PATH ), 'P' );
109 editMenu->AddItem( item );
110 item = new BMenuItem( "Randomize",
111 new BMessage( MSG_RANDOMIZE ), 'R' );
112 editMenu->AddItem( item );
113 editMenu->AddSeparatorItem();
114 item = new BMenuItem( "Remove",
115 new BMessage( MSG_REMOVE ) );
116 editMenu->AddItem( item );
117 item = new BMenuItem( "Remove All",
118 new BMessage( MSG_REMOVE_ALL ) );
119 editMenu->AddItem( item );
121 editMenu->SetEnabled( false );
123 // make menu bar resize to correct height
124 float menuWidth, menuHeight;
125 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
126 // don't change next line! it's a workarround!
127 fMenuBar->ResizeTo( frame.Width(), menuHeight );
130 frame.top += fMenuBar->Bounds().IntegerHeight() + 1;
131 frame.right -= B_V_SCROLL_BAR_WIDTH;
133 fListView = new PlaylistView( frame, fMainWindow );
134 fBackgroundView = new BScrollView( "playlist scrollview",
135 fListView, B_FOLLOW_ALL_SIDES,
139 AddChild( fBackgroundView );
143 FrameResized( Bounds().Width(), Bounds().Height() );
144 SetSizeLimits( menuWidth * 2.0, menuWidth * 6.0,
145 menuHeight * 5.0, menuHeight * 25.0 );
147 UpdatePlaylist( true );
148 // start window thread in hidden state
153 /*****************************************************************************
154 * PlayListWindow::~PlayListWindow
155 *****************************************************************************/
156 PlayListWindow::~PlayListWindow()
160 /*****************************************************************************
161 * PlayListWindow::QuitRequested
162 *****************************************************************************/
164 PlayListWindow::QuitRequested()
170 /*****************************************************************************
171 * PlayListWindow::MessageReceived
172 *****************************************************************************/
174 PlayListWindow::MessageReceived( BMessage * p_message )
176 switch ( p_message->what )
179 case B_REFS_RECEIVED:
181 // forward to interface window
182 fMainWindow->PostMessage( p_message );
186 case MSG_SELECT_NONE:
199 BWindow::MessageReceived( p_message );
204 /*****************************************************************************
205 * PlayListWindow::FrameResized
206 *****************************************************************************/
208 PlayListWindow::FrameResized(float width, float height)
211 fMenuBar->MoveTo(r.LeftTop());
212 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
213 r.top += fMenuBar->Bounds().Height() + 1.0;
214 fBackgroundView->MoveTo(r.LeftTop());
215 // the "+ 1.0" is to make the scrollbar
216 // be partly covered by the window border
217 fBackgroundView->ResizeTo(r.Width() + 1.0, r.Height() + 1.0);
220 /*****************************************************************************
221 * PlayListWindow::ReallyQuit
222 *****************************************************************************/
224 PlayListWindow::ReallyQuit()
231 /*****************************************************************************
232 * PlayListWindow::UpdatePlaylist
233 *****************************************************************************/
235 PlayListWindow::UpdatePlaylist( bool rebuild )
240 int32 count = fListView->CountItems();
241 while ( BListItem* item = fListView->RemoveItem( --count ) )
244 // rebuild listview from VLC's playlist
245 for ( int i = 0; i < fPlaylist->i_size; i++ )
246 fListView->AddItem( new PlaylistItem( fPlaylist->pp_items[i]->psz_name ) );
248 fListView->SetCurrent( fPlaylist->i_index );
249 fListView->SetPlaying( p_intf->p_sys->p_vlc_wrapper->is_playing() );