1 /*****************************************************************************
\r
2 * playlist.cpp: Interface for the playlist dialog
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2002 VideoLAN
\r
6 * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program; if not, write to the Free Software
\r
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
\r
21 *****************************************************************************/
\r
26 #include <videolan/vlc.h>
\r
28 #include "stream_control.h"
\r
29 #include "input_ext-intf.h"
\r
31 #include "interface.h"
\r
32 #include "intf_playlist.h"
\r
33 #include "win32_common.h"
\r
35 #include "playlist.h"
\r
36 //---------------------------------------------------------------------------
\r
37 //#pragma package(smart_init)
\r
38 #pragma resource "*.dfm"
\r
40 extern struct intf_thread_s *p_intfGlobal;
\r
42 //---------------------------------------------------------------------------
\r
43 __fastcall TPlaylistDlg::TPlaylistDlg( TComponent* Owner )
\r
46 Icon = p_intfGlobal->p_sys->p_window->Icon;
\r
48 //---------------------------------------------------------------------------
\r
49 char * __fastcall TPlaylistDlg::rindex( char *s, char c )
\r
53 s = s + strlen( s ) - 2;
\r
54 while( ( s > ref ) && ( *s != c ) )
\r
67 //---------------------------------------------------------------------------
\r
70 /*****************************************************************************
\r
72 ****************************************************************************/
\r
73 void __fastcall TPlaylistDlg::FormShow( TObject *Sender )
\r
75 p_intfGlobal->p_sys->p_window->MenuPlaylist->Checked = true;
\r
76 p_intfGlobal->p_sys->p_window->PopupPlaylist->Checked = true;
\r
78 //---------------------------------------------------------------------------
\r
79 void __fastcall TPlaylistDlg::FormHide( TObject *Sender )
\r
81 p_intfGlobal->p_sys->p_window->MenuPlaylist->Checked = false;
\r
82 p_intfGlobal->p_sys->p_window->PopupPlaylist->Checked = false;
\r
84 //---------------------------------------------------------------------------
\r
85 void __fastcall TPlaylistDlg::BitBtnOkClick( TObject *Sender )
\r
89 //---------------------------------------------------------------------------
\r
90 void __fastcall TPlaylistDlg::ListViewPlaylistDblClick( TObject *Sender )
\r
93 TListItem *ItemStart;
\r
94 TItemStates Focused;
\r
96 /* search the selected item */
\r
97 if( ListViewPlaylist->SelCount > 0 )
\r
99 if( ListViewPlaylist->SelCount == 1 )
\r
101 Item = ListViewPlaylist->Selected;
\r
105 Focused << isFocused;
\r
106 ItemStart = ListViewPlaylist->Items->Item[0];
\r
108 Item = ListViewPlaylist->GetNextItem( ItemStart, sdAll, Focused );
\r
111 /* stop current item, select the good one */
\r
112 if( ( p_input_bank->pp_input[0] != NULL ) &&
\r
113 ( Item->Index != p_intfGlobal->p_sys->i_playing ) )
\r
115 /* FIXME: temporary hack */
\r
116 p_input_bank->pp_input[0]->b_eof = 1;
\r
118 intf_PlaylistJumpto( p_main->p_playlist, Item->Index - 1 );
\r
121 //---------------------------------------------------------------------------
\r
122 void __fastcall TPlaylistDlg::ListViewPlaylistKeyDown( TObject *Sender,
\r
123 WORD &Key, TShiftState Shift )
\r
125 /* 'suppr' or 'backspace' */
\r
126 if( ( Key == VK_DELETE ) || ( Key == VK_BACK ) )
\r
128 MenuDeleteSelectedClick( Sender );
\r
132 if( Key == VK_RETURN )
\r
134 PopupPlayClick( Sender );
\r
137 //---------------------------------------------------------------------------
\r
138 void __fastcall TPlaylistDlg::ListViewPlaylistCustomDrawItem(
\r
139 TCustomListView *Sender, TListItem *Item, TCustomDrawState State,
\r
142 TRect Rect = Item->DisplayRect( drBounds );
\r
144 /* set the background color */
\r
145 if( Item->Index == p_intfGlobal->p_sys->i_playing )
\r
147 Sender->Canvas->Brush->Color = clRed;
\r
151 Sender->Canvas->Brush->Color = clWhite;
\r
154 Sender->Canvas->FillRect( Rect );
\r
156 //---------------------------------------------------------------------------
\r
159 /*****************************************************************************
\r
161 ****************************************************************************/
\r
162 void __fastcall TPlaylistDlg::MenuAddFileClick( TObject *Sender )
\r
164 p_intfGlobal->p_sys->p_window->MenuOpenFileClick( Sender );
\r
166 //---------------------------------------------------------------------------
\r
167 void __fastcall TPlaylistDlg::MenuAddDiscClick( TObject *Sender )
\r
169 p_intfGlobal->p_sys->p_window->MenuOpenDiscClick( Sender );
\r
171 //---------------------------------------------------------------------------
\r
172 void __fastcall TPlaylistDlg::MenuAddNetClick( TObject *Sender )
\r
174 p_intfGlobal->p_sys->p_window->MenuNetworkStreamClick( Sender );
\r
176 //---------------------------------------------------------------------------
\r
177 void __fastcall TPlaylistDlg::MenuAddUrlClick( TObject *Sender )
\r
181 //---------------------------------------------------------------------------
\r
182 void __fastcall TPlaylistDlg::MenuDeleteSelectedClick( TObject *Sender )
\r
184 /* user wants to delete a file in the queue */
\r
186 playlist_t *p_playlist = p_main->p_playlist;
\r
188 /* lock the struct */
\r
189 vlc_mutex_lock( &p_intfGlobal->change_lock );
\r
191 /* delete the items from the last to the first */
\r
192 for( i_pos = p_playlist->i_size - 1; i_pos >= 0; i_pos-- )
\r
194 if( ListViewPlaylist->Items->Item[i_pos]->Selected )
\r
196 DeleteItem( i_pos );
\r
200 /* Rebuild the ListView */
\r
201 UpdateGrid( p_playlist );
\r
203 vlc_mutex_unlock( &p_intfGlobal->change_lock );
\r
205 //---------------------------------------------------------------------------
\r
206 void __fastcall TPlaylistDlg::MenuDeleteAllClick( TObject *Sender )
\r
209 playlist_t *p_playlist = p_main->p_playlist;
\r
211 /* lock the struct */
\r
212 vlc_mutex_lock( &p_intfGlobal->change_lock );
\r
214 /* delete the items from the last to the first */
\r
215 for( i_pos = p_playlist->i_size - 1; i_pos >= 0; i_pos-- )
\r
217 DeleteItem( i_pos );
\r
220 /* Rebuild the ListView */
\r
221 UpdateGrid( p_playlist );
\r
223 vlc_mutex_unlock( &p_intfGlobal->change_lock );
\r
225 //---------------------------------------------------------------------------
\r
226 void __fastcall TPlaylistDlg::MenuSelectionInvertClick( TObject *Sender )
\r
228 #define NOT( var ) ( (var) ? false : true )
\r
230 playlist_t *p_playlist = p_main->p_playlist;
\r
231 TListItems *Items = ListViewPlaylist->Items;
\r
233 /* delete the items from the last to the first */
\r
234 for( i_pos = p_playlist->i_size - 1; i_pos >= 0; i_pos-- )
\r
236 Items->Item[i_pos]->Selected = NOT( Items->Item[i_pos]->Selected );
\r
240 //---------------------------------------------------------------------------
\r
241 void __fastcall TPlaylistDlg::MenuSelectionCropClick( TObject *Sender )
\r
243 MenuSelectionInvertClick( Sender );
\r
244 MenuDeleteSelectedClick( Sender );
\r
246 //---------------------------------------------------------------------------
\r
249 /*****************************************************************************
\r
251 ****************************************************************************/
\r
252 void __fastcall TPlaylistDlg::PopupPlayClick( TObject *Sender )
\r
254 ListViewPlaylistDblClick( Sender );
\r
256 //---------------------------------------------------------------------------
\r
257 void __fastcall TPlaylistDlg::PopupInvertSelectionClick( TObject *Sender )
\r
259 MenuSelectionInvertClick( Sender );
\r
261 //---------------------------------------------------------------------------
\r
262 void __fastcall TPlaylistDlg::PopupCropSelectionClick( TObject *Sender )
\r
264 MenuSelectionCropClick( Sender );
\r
266 //---------------------------------------------------------------------------
\r
267 void __fastcall TPlaylistDlg::PopupDeleteSelectedClick( TObject *Sender )
\r
269 MenuDeleteSelectedClick( Sender );
\r
271 //---------------------------------------------------------------------------
\r
272 void __fastcall TPlaylistDlg::PopupDeleteAllClick( TObject *Sender )
\r
274 MenuDeleteAllClick( Sender );
\r
276 //---------------------------------------------------------------------------
\r
279 /*****************************************************************************
\r
280 * Useful functions, needed by the event handlers
\r
281 ****************************************************************************/
\r
282 void __fastcall TPlaylistDlg::UpdateGrid( playlist_t * p_playlist )
\r
288 ListViewPlaylist->Items->BeginUpdate();
\r
290 /* Clear the list... */
\r
291 ListViewPlaylist->Items->Clear();
\r
293 /* ...and rebuild it */
\r
294 for( i_dummy = 0; i_dummy < p_playlist->i_size; i_dummy++ )
\r
297 /* Position of the last '\' in the string */
\r
298 FileName = rindex( p_playlist->p_item[i_dummy].psz_name, '\\' );
\r
300 /* Position of the last '/' in the string */
\r
301 FileName = rindex( p_playlist->p_item[i_dummy].psz_name, '/' );
\r
303 if( ( FileName == NULL ) || ( *(FileName + 1) == '\0' ) )
\r
305 FileName = p_playlist->p_item[i_dummy].psz_name;
\r
309 /* Skip leading '\' or '/' */
\r
313 Item = ListViewPlaylist->Items->Add();
\r
314 Item->Caption = FileName;
\r
315 Item->SubItems->Add( "no info" );
\r
317 /* TODO: Set background color ? */
\r
319 ListViewPlaylist->Items->EndUpdate();
\r
321 //---------------------------------------------------------------------------
\r
322 void __fastcall TPlaylistDlg::Manage( intf_thread_t * p_intf )
\r
324 playlist_t *p_playlist = p_main->p_playlist ;
\r
326 vlc_mutex_lock( &p_playlist->change_lock );
\r
328 if( p_intf->p_sys->i_playing != p_playlist->i_index )
\r
330 p_intf->p_sys->i_playing = p_playlist->i_index;
\r
332 /* update the background color */
\r
333 UpdateGrid( p_playlist );
\r
336 vlc_mutex_unlock( &p_playlist->change_lock );
\r
338 //---------------------------------------------------------------------------
\r
339 void __fastcall TPlaylistDlg::DeleteItem( int i_pos )
\r
341 intf_PlaylistDelete( p_main->p_playlist, i_pos );
\r
343 /* are we deleting the current played stream */
\r
344 if( p_intfGlobal->p_sys->i_playing == i_pos )
\r
347 p_input_bank->pp_input[0]->b_eof = 1;
\r
348 /* this has to set the slider to 0 */
\r
350 /* step minus one */
\r
351 p_intfGlobal->p_sys->i_playing-- ;
\r
353 vlc_mutex_lock( &p_main->p_playlist->change_lock );
\r
354 p_main->p_playlist->i_index-- ;
\r
355 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
\r
358 //---------------------------------------------------------------------------
\r
359 void __fastcall TPlaylistDlg::Previous()
\r
361 if( p_input_bank->pp_input[0] != NULL )
\r
363 /* FIXME: temporary hack */
\r
364 intf_PlaylistPrev( p_main->p_playlist );
\r
365 intf_PlaylistPrev( p_main->p_playlist );
\r
366 p_input_bank->pp_input[0]->b_eof = 1;
\r
369 //---------------------------------------------------------------------------
\r
370 void __fastcall TPlaylistDlg::Next()
\r
372 if( p_input_bank->pp_input[0] != NULL )
\r
374 /* FIXME: temporary hack */
\r
375 p_input_bank->pp_input[0]->b_eof = 1;
\r
378 //---------------------------------------------------------------------------
\r