]> git.sesse.net Git - vlc/commitdiff
- vlc_playlist.h, playlist.c: added the ability to save a playlist to
authorBoris Dorès <babal@videolan.org>
Fri, 13 Dec 2002 16:26:35 +0000 (16:26 +0000)
committerBoris Dorès <babal@videolan.org>
Fri, 13 Dec 2002 16:26:35 +0000 (16:26 +0000)
  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

include/vlc_playlist.h
modules/gui/win32/mainframe.cpp
modules/gui/win32/mainframe.dfm
modules/gui/win32/playlist.cpp
modules/gui/win32/playlist.dfm
modules/gui/win32/playlist.h
src/playlist/playlist.c

index 8ca7ebb65d1abd45069d8dd1d848e9a74ba344c3..8492740114cabb779655a43b173b8a73c202cbb5 100644 (file)
@@ -2,7 +2,7 @@
  * vlc_playlist.h : Playlist functions
  *****************************************************************************
  * 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>
  *
@@ -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_AddItem, ( playlist_t *, playlist_item_t *, int, 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 * ) );
index 130a7bfc4e7c6c4b5559bc1c92225a616e513da9..add53a7dc23fe16e7c0006beb246e0d5400e89d3 100644 (file)
@@ -147,8 +147,9 @@ void __fastcall TMainFrameDlg::OpenFileActionExecute( TObject *Sender )
     if( OpenDialog1->Execute() )\r
     {\r
         /* add the new file to the interface playlist */\r
-         p_intf->p_sys->p_playwin->Add( OpenDialog1->FileName,\r
-                                        PLAYLIST_APPEND | PLAYLIST_GO,\r
+        for ( int i = 0 ; i < OpenDialog1->Files->Count ; i++ )\r
+            p_intf->p_sys->p_playwin->Add( OpenDialog1->Files->Strings[i],\r
+                                        PLAYLIST_APPEND,\r
                                         PLAYLIST_END );\r
     };\r
 }\r
index 9407a5101513695781bf5e30e8e9f80a314c7641..356353b4bb9a8ef0671742011387d1a633fa26e5 100644 (file)
@@ -1,6 +1,6 @@
 object MainFrameDlg: TMainFrameDlg\r
-  Left = 285\r
-  Top = 170\r
+  Left = 356\r
+  Top = 227\r
   Width = 541\r
   Height = 306\r
   BorderIcons = [biSystemMenu, biMinimize]\r
@@ -256,7 +256,7 @@ object MainFrameDlg: TMainFrameDlg
   end\r
   object StatusBar: TStatusBar\r
     Left = 0\r
-    Top = 241\r
+    Top = 238\r
     Width = 533\r
     Height = 19\r
     Panels = <>\r
@@ -564,6 +564,7 @@ object MainFrameDlg: TMainFrameDlg
   end\r
   object OpenDialog1: TOpenDialog\r
     Filter = 'All Files (*.*)|*.*'\r
+    Options = [ofHideReadOnly, ofAllowMultiSelect, ofEnableSizing]\r
     Left = 8\r
     Top = 208\r
   end\r
index 4508156194bd109469d4bbe993eb6542deb40088..f659f06c0ffe9d2cf5809540b3bac0baedf2808f 100644 (file)
@@ -411,3 +411,29 @@ void __fastcall TPlaylistDlg::Next()
 }\r
 //---------------------------------------------------------------------------\r
 \r
+\r
+void __fastcall TPlaylistDlg::MenuFileCloseClick(TObject *Sender)\r
+{\r
+    Hide();\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
+void __fastcall TPlaylistDlg::MenuFileOpenClick(TObject *Sender)\r
+{\r
+    if ( PlaylistOpenDlg->Execute() )\r
+    {\r
+        playlist_LoadFile ( p_playlist , PlaylistOpenDlg->FileName.c_str() );\r
+        UpdateGrid();\r
+    }\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
+void __fastcall TPlaylistDlg::MenuFileSaveClick(TObject *Sender)\r
+{\r
+    if ( PlaylistSaveDlg->Execute() )\r
+    {\r
+        playlist_SaveFile ( p_playlist , PlaylistSaveDlg->FileName.c_str() );\r
+    }\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
index c3567550dd05048114c3b93166a4727321d7051c..a9afc6fe8490aa08f68ecd23e038208e59d3f62e 100644 (file)
@@ -1,6 +1,6 @@
 object PlaylistDlg: TPlaylistDlg\r
-  Left = 346\r
-  Top = 231\r
+  Left = 433\r
+  Top = 308\r
   Width = 335\r
   Height = 436\r
   Caption = 'Playlist'\r
@@ -58,23 +58,41 @@ object PlaylistDlg: TPlaylistDlg
   end\r
   object MainMenuPlaylist: TMainMenu\r
     Left = 8\r
-    Top = 352\r
+    Top = 8\r
+    object MenuFile: TMenuItem\r
+      Caption = '&File'\r
+      object MenuFileOpen: TMenuItem\r
+        Caption = '&Open...'\r
+        OnClick = MenuFileOpenClick\r
+      end\r
+      object MenuFileSave: TMenuItem\r
+        Caption = '&Save...'\r
+        OnClick = MenuFileSaveClick\r
+      end\r
+      object N3: TMenuItem\r
+        Caption = '-'\r
+      end\r
+      object MenuFileClose: TMenuItem\r
+        Caption = '&Close'\r
+        OnClick = MenuFileCloseClick\r
+      end\r
+    end\r
     object MenuAdd: TMenuItem\r
       Tag = 3\r
       Caption = '&Add'\r
       object MenuAddFile: TMenuItem\r
         Tag = 3\r
-        Caption = '&File'\r
+        Caption = '&File...'\r
         OnClick = MenuAddFileClick\r
       end\r
       object MenuAddDisc: TMenuItem\r
         Tag = 3\r
-        Caption = '&Disc'\r
+        Caption = '&Disc...'\r
         OnClick = MenuAddDiscClick\r
       end\r
       object MenuAddNet: TMenuItem\r
         Tag = 3\r
-        Caption = '&Network'\r
+        Caption = '&Network...'\r
         OnClick = MenuAddNetClick\r
       end\r
       object MenuAddUrl: TMenuItem\r
@@ -112,7 +130,7 @@ object PlaylistDlg: TPlaylistDlg
   end\r
   object PopupMenuPlaylist: TPopupMenu\r
     Left = 40\r
-    Top = 352\r
+    Top = 8\r
     object PopupPlay: TMenuItem\r
       Tag = 3\r
       Action = PlayStreamAction\r
@@ -145,8 +163,8 @@ object PlaylistDlg: TPlaylistDlg
     end\r
   end\r
   object ActionList1: TActionList\r
-    Left = 264\r
-    Top = 352\r
+    Left = 72\r
+    Top = 8\r
     object InvertSelectionAction: TAction\r
       Tag = 3\r
       Caption = 'Invert'\r
@@ -178,4 +196,16 @@ object PlaylistDlg: TPlaylistDlg
       OnExecute = PlayStreamActionExecute\r
     end\r
   end\r
+  object PlaylistOpenDlg: TOpenDialog\r
+    Filter = 'All files(*.*)|*.*'\r
+    Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]\r
+    Left = 136\r
+    Top = 8\r
+  end\r
+  object PlaylistSaveDlg: TSaveDialog\r
+    Filter = 'All files(*.*)|*.*'\r
+    Options = [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist, ofEnableSizing]\r
+    Left = 104\r
+    Top = 8\r
+  end\r
 end\r
index 4e713a6b407273768caf54400cf2502e06a0f1bd..3a859fc98bd76511ae7fbf41b317327c6d02e3b3 100644 (file)
@@ -33,7 +33,8 @@
 #include <ComCtrls.hpp>\r
 #include <ActnList.hpp>\r
 \r
-#include <oleidl.h>                                   /* for drag and drop */\r
+#include <oleidl.h>\r
+#include <Dialogs.hpp>                                   /* for drag and drop */\r
 \r
 /*****************************************************************************\r
  * This message is sent to the controls registered as drop targets\r
@@ -72,6 +73,13 @@ __published: // IDE-managed Components
     TAction *DeleteSelectionAction;\r
     TAction *DeleteAllAction;\r
     TAction *PlayStreamAction;\r
+    TMenuItem *MenuFile;\r
+    TMenuItem *MenuFileOpen;\r
+    TMenuItem *MenuFileSave;\r
+   TMenuItem *N3;\r
+    TMenuItem *MenuFileClose;\r
+    TOpenDialog *PlaylistOpenDlg;\r
+    TSaveDialog *PlaylistSaveDlg;\r
     void __fastcall FormShow( TObject *Sender );\r
     void __fastcall FormHide( TObject *Sender );\r
     void __fastcall BitBtnOkClick( TObject *Sender );\r
@@ -88,6 +96,9 @@ __published:  // IDE-managed Components
     void __fastcall DeleteSelectionActionExecute( TObject *Sender );\r
     void __fastcall DeleteAllActionExecute( TObject *Sender );\r
     void __fastcall PlayStreamActionExecute( TObject *Sender );\r
+   void __fastcall MenuFileCloseClick(TObject *Sender);\r
+    void __fastcall MenuFileOpenClick(TObject *Sender);\r
+    void __fastcall MenuFileSaveClick(TObject *Sender);\r
 private:       // User declarations\r
     char * __fastcall rindex( char *s, char c );\r
     intf_thread_t *p_intf;\r
index bd4270597306a72de55271e0959bc41f12efdbfc..9a57a6e799c9de0e18b420c5fb99cc6f2153a548 100644 (file)
@@ -2,7 +2,7 @@
  * playlist.c : Playlist management functions
  *****************************************************************************
  * 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>
  *
 #define PLAYLIST_STOPPED 0
 #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
  *****************************************************************************/
@@ -103,8 +110,8 @@ void playlist_Destroy( playlist_t * p_playlist )
 int playlist_Add( playlist_t *p_playlist, const char * psz_target,
                                           int i_mode, int i_pos )
 {
-    playlist_item_t * p_item; 
-    
+    playlist_item_t * p_item;
+
     p_item = malloc( sizeof( playlist_item_t ) );
     if( p_item == NULL )
     {
@@ -128,20 +135,20 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
     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
      */
     if ( i_mode & PLAYLIST_CHECK_INSERT )
     {
          int j;
-       
+
          if ( p_playlist->pp_items )
          {
              for ( j = 0; j < p_playlist->i_size; j++ )
              {
                  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 );
                       }
@@ -151,7 +158,7 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
                       }
                       free( p_item );
                       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,
          i_mode |= PLAYLIST_APPEND;
     }
 
-    
+
     msg_Dbg( p_playlist, "adding playlist item « %s »", p_item->psz_name );
-    
+
     /* Create the new playlist item */
 
 
@@ -299,10 +306,10 @@ void playlist_Command( playlist_t * p_playlist, int i_command, int i_arg )
 
     case PLAYLIST_PLAY:
         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 );
-       }
+        }
         break;
 
     case PLAYLIST_SKIP:
@@ -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 );
 }
 
+/*****************************************************************************
+ * 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;
+}