Commit 4552cb1e authored by Boris Dorès's avatar Boris Dorès

- vlc_playlist.h, playlist.c: added the ability to save a playlist to

  and restore it from a file chosen by the user.

- win32/*:

  - implementation of the previous feature in the win32 interface
>   -> what the other interfaces need to do to support it is simply to
>      call the two following functions:
>       int playlist_LoadFile(playlist_t *p_playlist,const char *psz_filename);
>       int playlist_SaveFile(playlist_t *p_playlist,const char *psz_filename);
>      where psz_filename is the name of the destination/source file.

  - ability to open several files at a time
parent 3f7b412c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* vlc_playlist.h : Playlist functions * vlc_playlist.h : Playlist functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001, 2002 VideoLAN * Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
* $Id: vlc_playlist.h,v 1.6 2002/12/03 23:36:41 gitan Exp $ * $Id: vlc_playlist.h,v 1.7 2002/12/13 16:26:34 babal Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -72,4 +72,5 @@ VLC_EXPORT( void, playlist_Command, ( playlist_t *, int, int ) ); ...@@ -72,4 +72,5 @@ VLC_EXPORT( void, playlist_Command, ( playlist_t *, int, int ) );
VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, int, int ) ); VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, int, int ) );
VLC_EXPORT( int, playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) ); VLC_EXPORT( int, playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) );
VLC_EXPORT( int, playlist_Delete, ( playlist_t *, int ) ); VLC_EXPORT( int, playlist_Delete, ( playlist_t *, int ) );
VLC_EXPORT( int, playlist_LoadFile, ( playlist_t *, const char * ) );
VLC_EXPORT( int, playlist_SaveFile, ( playlist_t *, const char * ) );
...@@ -147,8 +147,9 @@ void __fastcall TMainFrameDlg::OpenFileActionExecute( TObject *Sender ) ...@@ -147,8 +147,9 @@ void __fastcall TMainFrameDlg::OpenFileActionExecute( TObject *Sender )
if( OpenDialog1->Execute() ) if( OpenDialog1->Execute() )
{ {
/* add the new file to the interface playlist */ /* add the new file to the interface playlist */
p_intf->p_sys->p_playwin->Add( OpenDialog1->FileName, for ( int i = 0 ; i < OpenDialog1->Files->Count ; i++ )
PLAYLIST_APPEND | PLAYLIST_GO, p_intf->p_sys->p_playwin->Add( OpenDialog1->Files->Strings[i],
PLAYLIST_APPEND,
PLAYLIST_END ); PLAYLIST_END );
}; };
} }
......
object MainFrameDlg: TMainFrameDlg object MainFrameDlg: TMainFrameDlg
Left = 285 Left = 356
Top = 170 Top = 227
Width = 541 Width = 541
Height = 306 Height = 306
BorderIcons = [biSystemMenu, biMinimize] BorderIcons = [biSystemMenu, biMinimize]
...@@ -256,7 +256,7 @@ object MainFrameDlg: TMainFrameDlg ...@@ -256,7 +256,7 @@ object MainFrameDlg: TMainFrameDlg
end end
object StatusBar: TStatusBar object StatusBar: TStatusBar
Left = 0 Left = 0
Top = 241 Top = 238
Width = 533 Width = 533
Height = 19 Height = 19
Panels = <> Panels = <>
...@@ -564,6 +564,7 @@ object MainFrameDlg: TMainFrameDlg ...@@ -564,6 +564,7 @@ object MainFrameDlg: TMainFrameDlg
end end
object OpenDialog1: TOpenDialog object OpenDialog1: TOpenDialog
Filter = 'All Files (*.*)|*.*' Filter = 'All Files (*.*)|*.*'
Options = [ofHideReadOnly, ofAllowMultiSelect, ofEnableSizing]
Left = 8 Left = 8
Top = 208 Top = 208
end end
......
...@@ -411,3 +411,29 @@ void __fastcall TPlaylistDlg::Next() ...@@ -411,3 +411,29 @@ void __fastcall TPlaylistDlg::Next()
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void __fastcall TPlaylistDlg::MenuFileCloseClick(TObject *Sender)
{
Hide();
}
//---------------------------------------------------------------------------
void __fastcall TPlaylistDlg::MenuFileOpenClick(TObject *Sender)
{
if ( PlaylistOpenDlg->Execute() )
{
playlist_LoadFile ( p_playlist , PlaylistOpenDlg->FileName.c_str() );
UpdateGrid();
}
}
//---------------------------------------------------------------------------
void __fastcall TPlaylistDlg::MenuFileSaveClick(TObject *Sender)
{
if ( PlaylistSaveDlg->Execute() )
{
playlist_SaveFile ( p_playlist , PlaylistSaveDlg->FileName.c_str() );
}
}
//---------------------------------------------------------------------------
object PlaylistDlg: TPlaylistDlg object PlaylistDlg: TPlaylistDlg
Left = 346 Left = 433
Top = 231 Top = 308
Width = 335 Width = 335
Height = 436 Height = 436
Caption = 'Playlist' Caption = 'Playlist'
...@@ -58,23 +58,41 @@ object PlaylistDlg: TPlaylistDlg ...@@ -58,23 +58,41 @@ object PlaylistDlg: TPlaylistDlg
end end
object MainMenuPlaylist: TMainMenu object MainMenuPlaylist: TMainMenu
Left = 8 Left = 8
Top = 352 Top = 8
object MenuFile: TMenuItem
Caption = '&File'
object MenuFileOpen: TMenuItem
Caption = '&Open...'
OnClick = MenuFileOpenClick
end
object MenuFileSave: TMenuItem
Caption = '&Save...'
OnClick = MenuFileSaveClick
end
object N3: TMenuItem
Caption = '-'
end
object MenuFileClose: TMenuItem
Caption = '&Close'
OnClick = MenuFileCloseClick
end
end
object MenuAdd: TMenuItem object MenuAdd: TMenuItem
Tag = 3 Tag = 3
Caption = '&Add' Caption = '&Add'
object MenuAddFile: TMenuItem object MenuAddFile: TMenuItem
Tag = 3 Tag = 3
Caption = '&File' Caption = '&File...'
OnClick = MenuAddFileClick OnClick = MenuAddFileClick
end end
object MenuAddDisc: TMenuItem object MenuAddDisc: TMenuItem
Tag = 3 Tag = 3
Caption = '&Disc' Caption = '&Disc...'
OnClick = MenuAddDiscClick OnClick = MenuAddDiscClick
end end
object MenuAddNet: TMenuItem object MenuAddNet: TMenuItem
Tag = 3 Tag = 3
Caption = '&Network' Caption = '&Network...'
OnClick = MenuAddNetClick OnClick = MenuAddNetClick
end end
object MenuAddUrl: TMenuItem object MenuAddUrl: TMenuItem
...@@ -112,7 +130,7 @@ object PlaylistDlg: TPlaylistDlg ...@@ -112,7 +130,7 @@ object PlaylistDlg: TPlaylistDlg
end end
object PopupMenuPlaylist: TPopupMenu object PopupMenuPlaylist: TPopupMenu
Left = 40 Left = 40
Top = 352 Top = 8
object PopupPlay: TMenuItem object PopupPlay: TMenuItem
Tag = 3 Tag = 3
Action = PlayStreamAction Action = PlayStreamAction
...@@ -145,8 +163,8 @@ object PlaylistDlg: TPlaylistDlg ...@@ -145,8 +163,8 @@ object PlaylistDlg: TPlaylistDlg
end end
end end
object ActionList1: TActionList object ActionList1: TActionList
Left = 264 Left = 72
Top = 352 Top = 8
object InvertSelectionAction: TAction object InvertSelectionAction: TAction
Tag = 3 Tag = 3
Caption = 'Invert' Caption = 'Invert'
...@@ -178,4 +196,16 @@ object PlaylistDlg: TPlaylistDlg ...@@ -178,4 +196,16 @@ object PlaylistDlg: TPlaylistDlg
OnExecute = PlayStreamActionExecute OnExecute = PlayStreamActionExecute
end end
end end
object PlaylistOpenDlg: TOpenDialog
Filter = 'All files(*.*)|*.*'
Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]
Left = 136
Top = 8
end
object PlaylistSaveDlg: TSaveDialog
Filter = 'All files(*.*)|*.*'
Options = [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist, ofEnableSizing]
Left = 104
Top = 8
end
end end
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
#include <ComCtrls.hpp> #include <ComCtrls.hpp>
#include <ActnList.hpp> #include <ActnList.hpp>
#include <oleidl.h> /* for drag and drop */ #include <oleidl.h>
#include <Dialogs.hpp> /* for drag and drop */
/***************************************************************************** /*****************************************************************************
* This message is sent to the controls registered as drop targets * This message is sent to the controls registered as drop targets
...@@ -72,6 +73,13 @@ __published: // IDE-managed Components ...@@ -72,6 +73,13 @@ __published: // IDE-managed Components
TAction *DeleteSelectionAction; TAction *DeleteSelectionAction;
TAction *DeleteAllAction; TAction *DeleteAllAction;
TAction *PlayStreamAction; TAction *PlayStreamAction;
TMenuItem *MenuFile;
TMenuItem *MenuFileOpen;
TMenuItem *MenuFileSave;
TMenuItem *N3;
TMenuItem *MenuFileClose;
TOpenDialog *PlaylistOpenDlg;
TSaveDialog *PlaylistSaveDlg;
void __fastcall FormShow( TObject *Sender ); void __fastcall FormShow( TObject *Sender );
void __fastcall FormHide( TObject *Sender ); void __fastcall FormHide( TObject *Sender );
void __fastcall BitBtnOkClick( TObject *Sender ); void __fastcall BitBtnOkClick( TObject *Sender );
...@@ -88,6 +96,9 @@ __published: // IDE-managed Components ...@@ -88,6 +96,9 @@ __published: // IDE-managed Components
void __fastcall DeleteSelectionActionExecute( TObject *Sender ); void __fastcall DeleteSelectionActionExecute( TObject *Sender );
void __fastcall DeleteAllActionExecute( TObject *Sender ); void __fastcall DeleteAllActionExecute( TObject *Sender );
void __fastcall PlayStreamActionExecute( TObject *Sender ); void __fastcall PlayStreamActionExecute( TObject *Sender );
void __fastcall MenuFileCloseClick(TObject *Sender);
void __fastcall MenuFileOpenClick(TObject *Sender);
void __fastcall MenuFileSaveClick(TObject *Sender);
private: // User declarations private: // User declarations
char * __fastcall rindex( char *s, char c ); char * __fastcall rindex( char *s, char c );
intf_thread_t *p_intf; intf_thread_t *p_intf;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* playlist.c : Playlist management functions * playlist.c : Playlist management functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: playlist.c,v 1.29 2002/12/07 22:15:10 gitan Exp $ * $Id: playlist.c,v 1.30 2002/12/13 16:26:35 babal Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -34,6 +34,13 @@ ...@@ -34,6 +34,13 @@
#define PLAYLIST_STOPPED 0 #define PLAYLIST_STOPPED 0
#define PLAYLIST_RUNNING 1 #define PLAYLIST_RUNNING 1
#define PLAYLIST_FILE_HEADER_0_5 "# vlc playlist file version 0.5"
#ifdef WIN32
# define PLAYLIST_FILE_EOL "\r\n"
#else
# define PLAYLIST_FILE_EOL "\n"
#endif
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -103,8 +110,8 @@ void playlist_Destroy( playlist_t * p_playlist ) ...@@ -103,8 +110,8 @@ void playlist_Destroy( playlist_t * p_playlist )
int playlist_Add( playlist_t *p_playlist, const char * psz_target, int playlist_Add( playlist_t *p_playlist, const char * psz_target,
int i_mode, int i_pos ) int i_mode, int i_pos )
{ {
playlist_item_t * p_item; playlist_item_t * p_item;
p_item = malloc( sizeof( playlist_item_t ) ); p_item = malloc( sizeof( playlist_item_t ) );
if( p_item == NULL ) if( p_item == NULL )
{ {
...@@ -128,20 +135,20 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item, ...@@ -128,20 +135,20 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
vlc_mutex_lock( &p_playlist->object_lock ); vlc_mutex_lock( &p_playlist->object_lock );
/* /*
* CHECK_INSERT : checks if the item is already enqued before * CHECK_INSERT : checks if the item is already enqued before
* enqueing it * enqueing it
*/ */
if ( i_mode & PLAYLIST_CHECK_INSERT ) if ( i_mode & PLAYLIST_CHECK_INSERT )
{ {
int j; int j;
if ( p_playlist->pp_items ) if ( p_playlist->pp_items )
{ {
for ( j = 0; j < p_playlist->i_size; j++ ) for ( j = 0; j < p_playlist->i_size; j++ )
{ {
if ( !strcmp( p_playlist->pp_items[j]->psz_uri, p_item->psz_uri ) ) if ( !strcmp( p_playlist->pp_items[j]->psz_uri, p_item->psz_uri ) )
{ {
if( p_item->psz_name ) if( p_item->psz_name )
{ {
free( p_item->psz_name ); free( p_item->psz_name );
} }
...@@ -151,7 +158,7 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item, ...@@ -151,7 +158,7 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
} }
free( p_item ); free( p_item );
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
return 0; return 0;
} }
} }
} }
...@@ -159,9 +166,9 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item, ...@@ -159,9 +166,9 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
i_mode |= PLAYLIST_APPEND; i_mode |= PLAYLIST_APPEND;
} }
msg_Dbg( p_playlist, "adding playlist item %s ", p_item->psz_name ); msg_Dbg( p_playlist, "adding playlist item %s ", p_item->psz_name );
/* Create the new playlist item */ /* Create the new playlist item */
...@@ -299,10 +306,10 @@ void playlist_Command( playlist_t * p_playlist, int i_command, int i_arg ) ...@@ -299,10 +306,10 @@ void playlist_Command( playlist_t * p_playlist, int i_command, int i_arg )
case PLAYLIST_PLAY: case PLAYLIST_PLAY:
p_playlist->i_status = PLAYLIST_RUNNING; p_playlist->i_status = PLAYLIST_RUNNING;
if ( p_playlist->p_input ) if ( p_playlist->p_input )
{ {
input_SetStatus( p_playlist->p_input, INPUT_STATUS_PLAY ); input_SetStatus( p_playlist->p_input, INPUT_STATUS_PLAY );
} }
break; break;
case PLAYLIST_SKIP: case PLAYLIST_SKIP:
...@@ -550,3 +557,122 @@ static void Poubellize ( playlist_t *p_playlist, input_thread_t *p_input ) ...@@ -550,3 +557,122 @@ static void Poubellize ( playlist_t *p_playlist, input_thread_t *p_input )
msg_Dbg( p_playlist, "poubellizing input %i\n", p_input->i_object_id ); msg_Dbg( p_playlist, "poubellizing input %i\n", p_input->i_object_id );
} }
/*****************************************************************************
* playlist_LoadFile: load a playlist file.
****************************************************************************/
int playlist_LoadFile( playlist_t * p_playlist, const char *psz_filename )
{
FILE *file;
char line[1024];
int i_current_status;
int i;
msg_Dbg( p_playlist, "opening playlist file %s", psz_filename );
file = fopen( psz_filename, "rt" );
if( !file )
{
msg_Err( p_playlist, "playlist file %s does not exist", psz_filename );
return -1;
}
fseek( file, 0L, SEEK_SET );
/* check the file is not empty */
if ( ! fgets( line, 1024, file ) )
{
msg_Err( p_playlist, "playlist file %s is empty", psz_filename );
fclose( file );
return -1;
}
/* get rid of line feed */
if( line[strlen(line)-1] == '\n' || line[strlen(line)-1] == '\r' )
{
line[strlen(line)-1] = (char)0;
if( line[strlen(line)-1] == '\r' ) line[strlen(line)-1] = (char)0;
}
/* check the file format is valid */
if ( strcmp ( line , PLAYLIST_FILE_HEADER_0_5 ) )
{
msg_Err( p_playlist, "playlist file %s format is unsupported"
, psz_filename );
fclose( file );
return -1;
}
/* stop playing */
i_current_status = p_playlist->i_status;
if ( p_playlist->i_status != PLAYLIST_STOPPED )
{
playlist_Stop ( p_playlist );
}
/* delete current content of the playlist */
for( i = p_playlist->i_size - 1; i >= 0; i-- )
{
playlist_Delete ( p_playlist , i );
}
/* simply add each line */
while( fgets( line, 1024, file ) )
{
/* ignore comments or empty lines */
if( (line[0] == '#') || (line[0] == '\r') || (line[0] == '\n')
|| (line[0] == (char)0) )
continue;
/* get rid of line feed */
if( line[strlen(line)-1] == '\n' || line[strlen(line)-1] == '\r' )
{
line[strlen(line)-1] = (char)0;
if( line[strlen(line)-1] == '\r' ) line[strlen(line)-1] = (char)0;
}
playlist_Add ( p_playlist , (char*) &line , PLAYLIST_APPEND , PLAYLIST_END );
}
/* start playing */
if ( i_current_status != PLAYLIST_STOPPED )
{
playlist_Play ( p_playlist );
}
fclose( file );
return 0;
}
/*****************************************************************************
* playlist_SaveFile: Save a playlist in a file.
*****************************************************************************/
int playlist_SaveFile( playlist_t * p_playlist, const char * psz_filename )
{
FILE *file;
int i;
vlc_mutex_lock( &p_playlist->object_lock );
msg_Dbg( p_playlist, "saving playlist file %s", psz_filename );
file = fopen( psz_filename, "wt" );
if( !file )
{
msg_Err( p_playlist , "could not create playlist file %s"
, psz_filename );
return -1;
}
fprintf( file , PLAYLIST_FILE_HEADER_0_5 PLAYLIST_FILE_EOL );
for ( i = 0 ; i < p_playlist->i_size ; i++ )
{
fprintf( file , p_playlist->pp_items[i]->psz_uri );
fprintf( file , PLAYLIST_FILE_EOL );
}
fclose( file );
vlc_mutex_unlock( &p_playlist->object_lock );
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment