1 /*****************************************************************************
2 * PlayListWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: PlayListWindow.cpp,v 1.2 2002/09/30 18:30:27 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 : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
63 B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
64 fPlaylist( playlist ),
65 fMainWindow( mainWindow )
67 SetName( "playlist" );
69 // set up the main menu bar
70 fMenuBar = new BMenuBar( BRect(0.0, 0.0, frame.Width(), 15.0), "main menu",
71 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
76 BMenu *fileMenu = new BMenu( "File" );
77 fMenuBar->AddItem( fileMenu );
78 BMenuItem* item = new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
79 new BMessage( OPEN_FILE ), 'O' );
80 item->SetTarget( fMainWindow );
81 fileMenu->AddItem( item );
83 CDMenu* cd_menu = new CDMenu( "Open Disc" );
84 fileMenu->AddItem( cd_menu );
86 fileMenu->AddSeparatorItem();
87 item = new BMenuItem( "Close",
88 new BMessage( B_QUIT_REQUESTED ), 'W' );
89 fileMenu->AddItem( item );
92 BMenu *editMenu = new BMenu( "Edit" );
93 fMenuBar->AddItem( editMenu );
94 item = new BMenuItem( "Select All",
95 new BMessage( MSG_SELECT_ALL ), 'A' );
96 editMenu->AddItem( item );
97 item = new BMenuItem( "Select None",
98 new BMessage( MSG_SELECT_NONE ), 'A', B_SHIFT_KEY );
99 editMenu->AddItem( item );
101 editMenu->AddSeparatorItem();
102 item = new BMenuItem( "Sort by Name",
103 new BMessage( MSG_SORT_NAME ), 'N' );
104 editMenu->AddItem( item );
105 item = new BMenuItem( "Sort by Path",
106 new BMessage( MSG_SORT_PATH ), 'P' );
107 editMenu->AddItem( item );
108 item = new BMenuItem( "Randomize",
109 new BMessage( MSG_RANDOMIZE ), 'R' );
110 editMenu->AddItem( item );
111 editMenu->AddSeparatorItem();
112 item = new BMenuItem( "Remove",
113 new BMessage( MSG_REMOVE ) );
114 editMenu->AddItem( item );
115 item = new BMenuItem( "Remove All",
116 new BMessage( MSG_REMOVE_ALL ) );
117 editMenu->AddItem( item );
119 editMenu->SetEnabled( false );
121 // make menu bar resize to correct height
122 float menuWidth, menuHeight;
123 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
124 // don't change next line! it's a workarround!
125 fMenuBar->ResizeTo( frame.Width(), menuHeight );
128 frame.top += fMenuBar->Bounds().IntegerHeight() + 1;
129 frame.right -= B_V_SCROLL_BAR_WIDTH;
131 fListView = new PlaylistView( frame, fMainWindow );
132 fBackgroundView = new BScrollView( "playlist scrollview",
133 fListView, B_FOLLOW_ALL_SIDES,
137 AddChild( fBackgroundView );
141 FrameResized( Bounds().Width(), Bounds().Height() );
142 SetSizeLimits( menuWidth * 2.0, menuWidth * 6.0,
143 menuHeight * 5.0, menuHeight * 25.0 );
145 UpdatePlaylist( true );
146 // start window thread in hidden state
151 /*****************************************************************************
152 * PlayListWindow::~PlayListWindow
153 *****************************************************************************/
154 PlayListWindow::~PlayListWindow()
158 /*****************************************************************************
159 * PlayListWindow::QuitRequested
160 *****************************************************************************/
162 PlayListWindow::QuitRequested()
168 /*****************************************************************************
169 * PlayListWindow::MessageReceived
170 *****************************************************************************/
172 PlayListWindow::MessageReceived( BMessage * p_message )
174 switch ( p_message->what )
177 case B_REFS_RECEIVED:
179 // forward to interface window
180 fMainWindow->PostMessage( p_message );
184 case MSG_SELECT_NONE:
197 BWindow::MessageReceived( p_message );
202 /*****************************************************************************
203 * PlayListWindow::FrameResized
204 *****************************************************************************/
206 PlayListWindow::FrameResized(float width, float height)
209 fMenuBar->MoveTo(r.LeftTop());
210 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
211 r.top += fMenuBar->Bounds().Height() + 1.0;
212 fBackgroundView->MoveTo(r.LeftTop());
213 // the "+ 1.0" is to make the scrollbar
214 // be partly covered by the window border
215 fBackgroundView->ResizeTo(r.Width() + 1.0, r.Height() + 1.0);
218 /*****************************************************************************
219 * PlayListWindow::ReallyQuit
220 *****************************************************************************/
222 PlayListWindow::ReallyQuit()
229 /*****************************************************************************
230 * PlayListWindow::UpdatePlaylist
231 *****************************************************************************/
233 PlayListWindow::UpdatePlaylist( bool rebuild )
238 int32 count = fListView->CountItems();
239 while ( BListItem* item = fListView->RemoveItem( --count ) )
242 // rebuild listview from VLC's playlist
243 for ( int i = 0; i < fPlaylist->i_size; i++ )
244 fListView->AddItem( new PlaylistItem( fPlaylist->p_item[i].psz_name ) );
246 fListView->SetCurrent( fPlaylist->i_index );
247 fListView->SetPlaying( Intf_VLCWrapper::is_playing() ); */