]> git.sesse.net Git - vlc/blob - modules/gui/beos/PlayListWindow.cpp
Attempt to port new BeOS features from the stable branch.
[vlc] / modules / gui / beos / PlayListWindow.cpp
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 $
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 <stippi@yellowbites.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
26  *****************************************************************************/
27
28 /* System headers */
29 #include <InterfaceKit.h>
30 #include <StorageKit.h>
31 #include <string.h>
32
33 /* VLC headers */
34 #include <vlc/vlc.h>
35 #include <vlc/intf.h>
36
37 /* BeOS interface headers */
38 #include "VlcWrapper.h"
39 #include "InterfaceWindow.h"
40 #include "ListViews.h"
41 #include "MsgVals.h"
42 #include "PlayListWindow.h"
43
44 enum
45 {
46         MSG_SELECT_ALL          = 'sall',
47         MSG_SELECT_NONE         = 'none',
48         MSG_RANDOMIZE           = 'rndm',
49         MSG_SORT_NAME           = 'srtn',
50         MSG_SORT_PATH           = 'srtp',
51         MSG_REMOVE                      = 'rmov',
52         MSG_REMOVE_ALL          = 'rmal',
53 };
54
55
56 /*****************************************************************************
57  * PlayListWindow::PlayListWindow
58  *****************************************************************************/
59 PlayListWindow::PlayListWindow( BRect frame, const char* name,
60                                                                 playlist_t *playlist,
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 )
66 {
67     SetName( "playlist" );
68
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 );
72
73     AddChild( fMenuBar );
74
75         // Add the File menu
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 );
82
83         CDMenu* cd_menu = new CDMenu( "Open Disc" );
84         fileMenu->AddItem( cd_menu );
85
86         fileMenu->AddSeparatorItem();
87         item = new BMenuItem( "Close",
88                                                   new BMessage( B_QUIT_REQUESTED ), 'W' );
89         fileMenu->AddItem( item );
90
91         // Add the Edit menu
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 );
100
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 );
118
119 editMenu->SetEnabled( false );
120
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 );
126
127         frame = Bounds();
128         frame.top += fMenuBar->Bounds().IntegerHeight() + 1;
129         frame.right -= B_V_SCROLL_BAR_WIDTH;
130
131         fListView = new PlaylistView( frame, fMainWindow );
132         fBackgroundView = new BScrollView( "playlist scrollview",
133                                                                            fListView, B_FOLLOW_ALL_SIDES,
134                                                                            0, false, true,
135                                                                            B_NO_BORDER );
136
137         AddChild( fBackgroundView );
138
139         // be up to date
140         UpdatePlaylist();
141         FrameResized( Bounds().Width(), Bounds().Height() );
142         SetSizeLimits( menuWidth * 2.0, menuWidth * 6.0,
143                                    menuHeight * 5.0, menuHeight * 25.0 );
144
145         UpdatePlaylist( true );
146         // start window thread in hidden state
147         Hide();
148         Show();
149 }
150
151 /*****************************************************************************
152  * PlayListWindow::~PlayListWindow
153  *****************************************************************************/
154 PlayListWindow::~PlayListWindow()
155 {
156 }
157
158 /*****************************************************************************
159  * PlayListWindow::QuitRequested
160  *****************************************************************************/
161 bool
162 PlayListWindow::QuitRequested()
163 {
164         Hide(); 
165         return false;
166 }
167
168 /*****************************************************************************
169  * PlayListWindow::MessageReceived
170  *****************************************************************************/
171 void
172 PlayListWindow::MessageReceived( BMessage * p_message )
173 {
174         switch ( p_message->what )
175         {
176                 case OPEN_DVD:
177                 case B_REFS_RECEIVED:
178                 case B_SIMPLE_DATA:
179                         // forward to interface window
180                         fMainWindow->PostMessage( p_message );
181                         break;
182                 case MSG_SELECT_ALL:
183                         break;
184                 case MSG_SELECT_NONE:
185                         break;
186                 case MSG_RANDOMIZE:
187                         break;
188                 case MSG_SORT_NAME:
189                         break;
190                 case MSG_SORT_PATH:
191                         break;
192                 case MSG_REMOVE:
193                         break;
194                 case MSG_REMOVE_ALL:
195                         break;
196                 default:
197                         BWindow::MessageReceived( p_message );
198                         break;
199         }
200 }
201
202 /*****************************************************************************
203  * PlayListWindow::FrameResized
204  *****************************************************************************/
205 void
206 PlayListWindow::FrameResized(float width, float height)
207 {
208         BRect r(Bounds());
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);
216 }
217
218 /*****************************************************************************
219  * PlayListWindow::ReallyQuit
220  *****************************************************************************/
221 void
222 PlayListWindow::ReallyQuit()
223 {
224     Lock();
225     Hide(); 
226     Quit();
227 }
228
229 /*****************************************************************************
230  * PlayListWindow::UpdatePlaylist
231  *****************************************************************************/
232 void
233 PlayListWindow::UpdatePlaylist( bool rebuild )
234 {
235         /* if ( rebuild )
236         {
237                 // remove all items
238                 int32 count = fListView->CountItems();
239                 while ( BListItem* item = fListView->RemoveItem( --count ) )
240                         delete item;
241         
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 ) );
245         }
246         fListView->SetCurrent( fPlaylist->i_index );
247         fListView->SetPlaying( Intf_VLCWrapper::is_playing() ); */
248 }