1 /*****************************************************************************
2 * PlayListWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: PlayListWindow.cpp,v 1.7 2003/02/01 12:01:11 stippi 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',
54 MSG_SELECTION_CHANGED = 'slch',
58 /*****************************************************************************
59 * PlayListWindow::PlayListWindow
60 *****************************************************************************/
61 PlayListWindow::PlayListWindow( BRect frame, const char* name,
62 InterfaceWindow* mainWindow,
63 intf_thread_t *p_interface )
64 : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
65 B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
66 fMainWindow( mainWindow )
69 p_wrapper = p_intf->p_sys->p_wrapper;
71 SetName( "playlist" );
73 // set up the main menu bar
74 fMenuBar = new BMenuBar( BRect(0.0, 0.0, frame.Width(), 15.0), "main menu",
75 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
80 BMenu *fileMenu = new BMenu( "File" );
81 fMenuBar->AddItem( fileMenu );
82 BMenuItem* item = new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
83 new BMessage( OPEN_FILE ), 'O' );
84 item->SetTarget( fMainWindow );
85 fileMenu->AddItem( item );
87 CDMenu* cd_menu = new CDMenu( "Open Disc" );
88 fileMenu->AddItem( cd_menu );
90 fileMenu->AddSeparatorItem();
91 item = new BMenuItem( "Close",
92 new BMessage( B_QUIT_REQUESTED ), 'W' );
93 fileMenu->AddItem( item );
96 BMenu *editMenu = new BMenu( "Edit" );
97 fMenuBar->AddItem( editMenu );
98 fSelectAllMI = new BMenuItem( "Select All",
99 new BMessage( MSG_SELECT_ALL ), 'A' );
100 editMenu->AddItem( fSelectAllMI );
101 fSelectNoneMI = new BMenuItem( "Select None",
102 new BMessage( MSG_SELECT_NONE ), 'A', B_SHIFT_KEY );
103 editMenu->AddItem( fSelectNoneMI );
105 editMenu->AddSeparatorItem();
106 fSortNameMI = new BMenuItem( "Sort by Name",
107 new BMessage( MSG_SORT_NAME ), 'N' );
108 fSortNameMI->SetEnabled( false );
109 editMenu->AddItem( fSortNameMI );
110 fSortPathMI = new BMenuItem( "Sort by Path",
111 new BMessage( MSG_SORT_PATH ), 'P' );
112 fSortPathMI->SetEnabled( false );
113 editMenu->AddItem( fSortPathMI );
114 fRandomizeMI = new BMenuItem( "Randomize",
115 new BMessage( MSG_RANDOMIZE ), 'R' );
116 fRandomizeMI->SetEnabled( false );
117 editMenu->AddItem( fRandomizeMI );
118 editMenu->AddSeparatorItem();
119 fRemoveMI = new BMenuItem( "Remove",
120 new BMessage( MSG_REMOVE ) );
121 editMenu->AddItem( fRemoveMI );
122 fRemoveAllMI = new BMenuItem( "Remove All",
123 new BMessage( MSG_REMOVE_ALL ) );
124 editMenu->AddItem( fRemoveAllMI );
126 // make menu bar resize to correct height
127 float menuWidth, menuHeight;
128 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
129 // don't change next line! it's a workarround!
130 fMenuBar->ResizeTo( frame.Width(), menuHeight );
133 frame.top += fMenuBar->Bounds().IntegerHeight() + 1;
134 frame.right -= B_V_SCROLL_BAR_WIDTH;
136 fListView = new PlaylistView( frame, fMainWindow, p_wrapper,
137 new BMessage( MSG_SELECTION_CHANGED ) );
138 fBackgroundView = new BScrollView( "playlist scrollview",
139 fListView, B_FOLLOW_ALL_SIDES,
143 AddChild( fBackgroundView );
147 FrameResized( Bounds().Width(), Bounds().Height() );
148 SetSizeLimits( menuWidth * 2.0, menuWidth * 6.0,
149 menuHeight * 5.0, menuHeight * 25.0 );
151 UpdatePlaylist( true );
152 // start window thread in hidden state
157 /*****************************************************************************
158 * PlayListWindow::~PlayListWindow
159 *****************************************************************************/
160 PlayListWindow::~PlayListWindow()
164 /*****************************************************************************
165 * PlayListWindow::QuitRequested
166 *****************************************************************************/
168 PlayListWindow::QuitRequested()
174 /*****************************************************************************
175 * PlayListWindow::MessageReceived
176 *****************************************************************************/
178 PlayListWindow::MessageReceived( BMessage * p_message )
180 switch ( p_message->what )
183 case B_REFS_RECEIVED:
185 // forward to interface window
186 fMainWindow->PostMessage( p_message );
189 fListView->Select( 0, fListView->CountItems() - 1 );
191 case MSG_SELECT_NONE:
192 fListView->DeselectAll();
201 fListView->RemoveSelected();
204 fListView->Select( 0, fListView->CountItems() - 1 );
205 fListView->RemoveSelected();
207 case MSG_SELECTION_CHANGED:
208 _CheckItemsEnableState();
210 case B_MODIFIERS_CHANGED:
211 fListView->ModifiersChanged();
214 BWindow::MessageReceived( p_message );
219 /*****************************************************************************
220 * PlayListWindow::FrameResized
221 *****************************************************************************/
223 PlayListWindow::FrameResized(float width, float height)
226 fMenuBar->MoveTo(r.LeftTop());
227 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
228 r.top += fMenuBar->Bounds().Height() + 1.0;
229 fBackgroundView->MoveTo(r.LeftTop());
230 // the "+ 1.0" is to make the scrollbar
231 // be partly covered by the window border
232 fBackgroundView->ResizeTo(r.Width() + 1.0, r.Height() + 1.0);
235 /*****************************************************************************
236 * PlayListWindow::ReallyQuit
237 *****************************************************************************/
239 PlayListWindow::ReallyQuit()
246 /*****************************************************************************
247 * PlayListWindow::UpdatePlaylist
248 *****************************************************************************/
250 PlayListWindow::UpdatePlaylist( bool rebuild )
253 fListView->RebuildList();
254 fListView->SetCurrent( p_wrapper->PlaylistCurrent() );
255 fListView->SetPlaying( p_wrapper->IsPlaying() );
257 _CheckItemsEnableState();
260 /*****************************************************************************
261 * PlayListWindow::_CheckItemsEnableState
262 *****************************************************************************/
264 PlayListWindow::_CheckItemsEnableState() const
266 // check if one item selected
267 int32 test = fListView->CurrentSelection( 0 );
268 bool enable1 = test >= 0;
269 // check if at least two items selected
270 // test = fListView->CurrentSelection( 1 );
271 // bool enable2 = test >= 0;
272 bool notEmpty = fListView->CountItems() > 0;
273 _SetMenuItemEnabled( fSelectAllMI, notEmpty );
274 _SetMenuItemEnabled( fSelectNoneMI, enable1 );
275 // _SetMenuItemEnabled( fSortNameMI, enable2 );
276 // _SetMenuItemEnabled( fSortPathMI, enable2 );
277 // _SetMenuItemEnabled( fRandomizeMI, enable2 );
278 _SetMenuItemEnabled( fRemoveMI, enable1 );
279 _SetMenuItemEnabled( fRemoveAllMI, notEmpty );
282 /*****************************************************************************
283 * PlayListWindow::_SetMenuItemEnabled
284 *****************************************************************************/
286 PlayListWindow::_SetMenuItemEnabled( BMenuItem* item, bool enabled ) const
288 // this check should actally be done in BMenuItem::SetEnabled(), but it is not...
289 if ( item->IsEnabled() != enabled )
290 item->SetEnabled( enabled );