[vlc-devel] [PATCH 3/3] libvlc/Qt: Add variable "playlist-file" to have the file name of the playlist

Mario Speiß 1034-135 at online.de
Wed Jun 13 22:29:48 CEST 2012


If a file is added to VLC, the filename will be stored in this variable. This
cam be used in the playlist export dialog again.
The variable is updated if VLC adds a file to the playlist if it is empty.
However, this might better be done from modules/playlist instead of
src/playlist/item.c, but I do not know where...

Regards,
Mario
---
 modules/gui/qt4/dialogs_provider.cpp |   39 +++++++++++++++++++++++++++++++++-
 src/libvlc.c                         |    1 +
 src/playlist/item.c                  |   11 +++++++++
 3 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index f34cb03..86cf077 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -581,19 +581,49 @@ void DialogsProvider::saveAPlaylist()
     QStringList filters;
     QString ext = getSettings()->value( "last-playlist-ext" ).toString();
 
+    /* Get the filename of the current playlist if it has a name already */
+    bool plfile_match = false;
+    char* plfile = var_GetString( THEPL, "playlist-file" );
+    if( plfile )
+    {
+        char* plpath = make_path( plfile );
+        free( plfile );
+        plfile = plpath;
+    }
+    QString dlgFile = p_intf->p_sys->filepath;
+    if( plfile && *plfile )
+    {
+        dlgFile = QString( plfile );
+        if( dlgFile.lastIndexOf( '.' ) > 0 )
+            ext = dlgFile.mid( dlgFile.lastIndexOf( '.' ) + 1 ).toLower();
+    }
+    free( plfile );
+
     for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++ )
     {
         QString tmp = qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + types[i].filter_patterns + ")";
         if( ext == qfu( types[i].filter_patterns ) )
+        {
             filters.insert( 0, tmp );
+            plfile_match = true;              /* extensions match! */
+        }
         else
             filters.append( tmp );
     }
 
+    /* If the playlist-file variable contains a supported playlist extension then suggest it */
     QString selected;
+    if( plfile_match )
+        selected = ext;                       /* extension matched! */
+    else
+    {
+        dlgFile = p_intf->p_sys->filepath;    /* extension did not match, use filepath as suggestion only (old behavior) */
+        ext = getSettings()->value( "last-playlist-ext" ).toString();
+    }
+
     QString file = QFileDialog::getSaveFileName( NULL,
                                   qtr( "Save playlist as..." ),
-                                  p_intf->p_sys->filepath, filters.join( ";;" ),
+                                  dlgFile, filters.join( ";;" ),
                                   &selected );
     if( file.isEmpty() )
         return;
@@ -604,6 +634,13 @@ void DialogsProvider::saveAPlaylist()
             playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
                              THEPL->p_playing, types[i].module );
             getSettings()->setValue( "last-playlist-ext", types[i].filter_patterns );
+            /* Update the playlist-file variable */
+            plfile = make_URI( qtu( toNativeSeparators( file ) ), "file" );
+            if( plfile )
+            {
+                var_SetString( THEPL, "playlist-file", plfile );
+                free( plfile );
+            }
             break;
         }
 }
diff --git a/src/libvlc.c b/src/libvlc.c
index 49220ab..de4e1d0 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -508,6 +508,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         module_EndBank (true);
         return VLC_EGENERIC;
     }
+    var_Create( p_playlist, "playlist-file", VLC_VAR_STRING );
 
     /* System specific configuration */
     system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
diff --git a/src/playlist/item.c b/src/playlist/item.c
index 2b99dce..1809c80 100644
--- a/src/playlist/item.c
+++ b/src/playlist/item.c
@@ -452,6 +452,17 @@ int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
 {
     playlist_item_t *p_item;
     if( p_playlist->b_die ) return VLC_EGENERIC;
+
+    /* initialize the playlist-file variable, if input is added to the playlist
+       and the playlist is still empty */
+    if( b_playlist )
+    {
+        if( p_playlist->p_playing->i_children == 0 )
+            var_SetString(p_playlist,"playlist-file",p_input->psz_uri);
+        else
+            var_SetString(p_playlist,"playlist-file","");
+    }
+
     if( !pl_priv(p_playlist)->b_doing_ml )
         PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
                                              p_input->psz_uri );
-- 
1.7.5.4




More information about the vlc-devel mailing list