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 <vlc/vlc.h>
\r
27 #include <vlc/intf.h>
\r
29 #include "playlist.h"
\r
30 #include "win32_common.h"
\r
32 //---------------------------------------------------------------------------
\r
33 //#pragma package(smart_init)
\r
34 #pragma resource "*.dfm"
\r
36 extern intf_thread_t *p_intfGlobal;
\r
38 //---------------------------------------------------------------------------
\r
39 __fastcall TPlaylistDlg::TPlaylistDlg( TComponent* Owner )
\r
42 Icon = p_intfGlobal->p_sys->p_window->Icon;
\r
44 //---------------------------------------------------------------------------
\r
45 char * __fastcall TPlaylistDlg::rindex( char *s, char c )
\r
49 s = s + strlen( s ) - 2;
\r
50 while( ( s > ref ) && ( *s != c ) )
\r
63 //---------------------------------------------------------------------------
\r
66 /*****************************************************************************
\r
68 ****************************************************************************/
\r
69 void __fastcall TPlaylistDlg::FormShow( TObject *Sender )
\r
71 p_intfGlobal->p_sys->p_window->MenuPlaylist->Checked = true;
\r
72 p_intfGlobal->p_sys->p_window->PopupPlaylist->Checked = true;
\r
73 p_intfGlobal->p_sys->p_window->ToolButtonPlaylist->Down = true;
\r
75 //---------------------------------------------------------------------------
\r
76 void __fastcall TPlaylistDlg::FormHide( TObject *Sender )
\r
78 p_intfGlobal->p_sys->p_window->MenuPlaylist->Checked = false;
\r
79 p_intfGlobal->p_sys->p_window->PopupPlaylist->Checked = false;
\r
80 p_intfGlobal->p_sys->p_window->ToolButtonPlaylist->Down = false;
\r
82 //---------------------------------------------------------------------------
\r
83 void __fastcall TPlaylistDlg::BitBtnOkClick( TObject *Sender )
\r
87 //---------------------------------------------------------------------------
\r
88 void __fastcall TPlaylistDlg::ListViewPlaylistDblClick( TObject *Sender )
\r
91 TListItem *ItemStart;
\r
92 TItemStates Focused;
\r
94 playlist_t * p_playlist = (playlist_t *)
\r
95 vlc_object_find( p_intfGlobal, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
\r
96 if( p_playlist == NULL )
\r
101 /* search the selected item */
\r
102 if( ListViewPlaylist->SelCount > 0 )
\r
104 if( ListViewPlaylist->SelCount == 1 )
\r
106 Item = ListViewPlaylist->Selected;
\r
110 Focused << isFocused;
\r
111 ItemStart = ListViewPlaylist->Items->Item[0];
\r
113 Item = ListViewPlaylist->GetNextItem( ItemStart, sdAll, Focused );
\r
116 playlist_Goto( p_playlist, Item->Index - 1 );
\r
119 vlc_object_release( p_playlist );
\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 #if 0 /* PLAYLIST TARASS */
\r
185 /* user wants to delete a file in the queue */
\r
187 playlist_t *p_playlist = p_intfGlobal->p_vlc->p_playlist;
\r
189 /* lock the struct */
\r
190 vlc_mutex_lock( &p_intfGlobal->change_lock );
\r
192 /* delete the items from the last to the first */
\r
193 for( i_pos = p_playlist->i_size - 1; i_pos >= 0; i_pos-- )
\r
195 if( ListViewPlaylist->Items->Item[i_pos]->Selected )
\r
197 DeleteItem( i_pos );
\r
201 /* Rebuild the ListView */
\r
202 UpdateGrid( p_playlist );
\r
204 vlc_mutex_unlock( &p_intfGlobal->change_lock );
\r
207 //---------------------------------------------------------------------------
\r
208 void __fastcall TPlaylistDlg::MenuDeleteAllClick( TObject *Sender )
\r
210 #if 0 /* PLAYLIST TARASS */
\r
212 playlist_t *p_playlist = p_intfGlobal->p_vlc->p_playlist;
\r
214 /* lock the struct */
\r
215 vlc_mutex_lock( &p_intfGlobal->change_lock );
\r
217 /* delete the items from the last to the first */
\r
218 for( i_pos = p_playlist->i_size - 1; i_pos >= 0; i_pos-- )
\r
220 DeleteItem( i_pos );
\r
223 /* Rebuild the ListView */
\r
224 UpdateGrid( p_playlist );
\r
226 vlc_mutex_unlock( &p_intfGlobal->change_lock );
\r
229 //---------------------------------------------------------------------------
\r
230 void __fastcall TPlaylistDlg::MenuSelectionInvertClick( TObject *Sender )
\r
232 #if 0 /* PLAYLIST TARASS */
\r
233 #define NOT( var ) ( (var) ? false : true )
\r
235 playlist_t *p_playlist = p_intfGlobal->p_vlc->p_playlist;
\r
236 TListItems *Items = ListViewPlaylist->Items;
\r
238 /* delete the items from the last to the first */
\r
239 for( i_pos = p_playlist->i_size - 1; i_pos >= 0; i_pos-- )
\r
241 Items->Item[i_pos]->Selected = NOT( Items->Item[i_pos]->Selected );
\r
246 //---------------------------------------------------------------------------
\r
247 void __fastcall TPlaylistDlg::MenuSelectionCropClick( TObject *Sender )
\r
249 MenuSelectionInvertClick( Sender );
\r
250 MenuDeleteSelectedClick( Sender );
\r
252 //---------------------------------------------------------------------------
\r
255 /*****************************************************************************
\r
257 ****************************************************************************/
\r
258 void __fastcall TPlaylistDlg::PopupPlayClick( TObject *Sender )
\r
260 ListViewPlaylistDblClick( Sender );
\r
262 //---------------------------------------------------------------------------
\r
263 void __fastcall TPlaylistDlg::PopupInvertSelectionClick( TObject *Sender )
\r
265 MenuSelectionInvertClick( Sender );
\r
267 //---------------------------------------------------------------------------
\r
268 void __fastcall TPlaylistDlg::PopupCropSelectionClick( TObject *Sender )
\r
270 MenuSelectionCropClick( Sender );
\r
272 //---------------------------------------------------------------------------
\r
273 void __fastcall TPlaylistDlg::PopupDeleteSelectedClick( TObject *Sender )
\r
275 MenuDeleteSelectedClick( Sender );
\r
277 //---------------------------------------------------------------------------
\r
278 void __fastcall TPlaylistDlg::PopupDeleteAllClick( TObject *Sender )
\r
280 MenuDeleteAllClick( Sender );
\r
282 //---------------------------------------------------------------------------
\r
285 /*****************************************************************************
\r
286 * Useful functions, needed by the event handlers
\r
287 ****************************************************************************/
\r
288 void __fastcall TPlaylistDlg::UpdateGrid( playlist_t * p_playlist )
\r
294 ListViewPlaylist->Items->BeginUpdate();
\r
296 /* Clear the list... */
\r
297 ListViewPlaylist->Items->Clear();
\r
299 /* ...and rebuild it */
\r
300 for( i_dummy = 0; i_dummy < p_playlist->i_size; i_dummy++ )
\r
303 /* Position of the last '\' in the string */
\r
304 FileName = rindex( p_playlist->pp_items[i_dummy]->psz_name, '\\' );
\r
306 /* Position of the last '/' in the string */
\r
307 FileName = rindex( p_playlist->pp_items[i_dummy]->psz_name, '/' );
\r
309 if( ( FileName == NULL ) || ( *(FileName + 1) == '\0' ) )
\r
311 FileName = p_playlist->pp_items[i_dummy]->psz_name;
\r
315 /* Skip leading '\' or '/' */
\r
319 Item = ListViewPlaylist->Items->Add();
\r
320 Item->Caption = FileName;
\r
321 Item->SubItems->Add( "no info" );
\r
323 /* TODO: Set background color ? */
\r
325 ListViewPlaylist->Items->EndUpdate();
\r
327 //---------------------------------------------------------------------------
\r
328 void __fastcall TPlaylistDlg::Manage( intf_thread_t * p_intf )
\r
330 playlist_t * p_playlist = (playlist_t *)
\r
331 vlc_object_find( p_intfGlobal, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
\r
332 if( p_playlist == NULL )
\r
337 vlc_mutex_lock( &p_playlist->object_lock );
\r
339 if( p_intf->p_sys->i_playing != p_playlist->i_index )
\r
341 p_intf->p_sys->i_playing = p_playlist->i_index;
\r
343 /* update the background color */
\r
344 UpdateGrid( p_playlist );
\r
347 vlc_mutex_unlock( &p_playlist->object_lock );
\r
348 vlc_object_release( p_playlist );
\r
350 //---------------------------------------------------------------------------
\r
351 void __fastcall TPlaylistDlg::DeleteItem( int i_pos )
\r
353 playlist_t * p_playlist = (playlist_t *)
\r
354 vlc_object_find( p_intfGlobal, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
\r
355 if( p_playlist == NULL )
\r
360 playlist_Delete( p_playlist, i_pos );
\r
362 //---------------------------------------------------------------------------
\r
363 void __fastcall TPlaylistDlg::Previous()
\r
365 playlist_t * p_playlist = (playlist_t *)
\r
366 vlc_object_find( p_intfGlobal, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
\r
367 if( p_playlist == NULL )
\r
372 playlist_Prev( p_playlist );
\r
374 //---------------------------------------------------------------------------
\r
375 void __fastcall TPlaylistDlg::Next()
\r
377 playlist_t * p_playlist = (playlist_t *)
\r
378 vlc_object_find( p_intfGlobal, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
\r
379 if( p_playlist == NULL )
\r
384 playlist_Next( p_playlist );
\r
386 //---------------------------------------------------------------------------
\r