[vlc-commits] Qt: saveAPlaylist: fix file extension logic (fix #7578)

Francois Cartegnie git at videolan.org
Sat Dec 22 22:40:40 CET 2012


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Dec 22 22:40:25 2012 +0100| [f9c17d2ce65af4d8c1f569e1ef9c34837b8826b4] | committer: Francois Cartegnie

Qt: saveAPlaylist: fix file extension logic (fix #7578)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f9c17d2ce65af4d8c1f569e1ef9c34837b8826b4
---

 modules/gui/qt4/dialogs_provider.cpp |   51 ++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index 6a8b0dc..8b2e93e 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -595,21 +595,56 @@ void DialogsProvider::saveAPlaylist()
     }
 
     QString selected;
-    QString file = QFileDialog::getSaveFileName( NULL,
-                                  qtr( "Save playlist as..." ),
-                                  p_intf->p_sys->filepath, filters.join( ";;" ),
-                                  &selected );
+
+    QFileDialog *dialog = new QFileDialog( NULL,
+                                           qtr( "Save playlist as..." ),
+                                           QString( p_intf->p_sys->filepath ),
+                                           filters.join( ";;" ) );
+    dialog->setDefaultSuffix( qfu( types[0].filter_patterns ) );
+    dialog->setAcceptMode( QFileDialog::AcceptSave );
+    dialog->exec();
+    QString file = dialog->selectedFiles().first();
+    QString nameFilter = dialog->selectedNameFilter();
+    const char *psz_selected_module = NULL;
+    const char *psz_last_playlist_ext = NULL;
+    delete dialog;
+
     if( file.isEmpty() )
         return;
 
+    /* First test if the file extension is set, and different to selected filter */
     for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
-        if( selected == qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + qfu( types[i].filter_patterns ) + ")" )
+    {
+        if ( file.endsWith( QString( "." ) + qfu( types[i].filter_patterns ) ) )
         {
-            playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
-                             THEPL->p_playing, types[i].module );
-            getSettings()->setValue( "last-playlist-ext", types[i].filter_patterns );
+            psz_selected_module = types[i].module;
+            psz_last_playlist_ext = types[i].filter_patterns;
             break;
         }
+    }
+
+    /* otherwise apply the selected extension */
+    if ( !psz_last_playlist_ext )
+    {
+        for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
+        {
+            if ( nameFilter.startsWith( vlc_gettext( types[i].filter_name ) ) )
+            {
+                psz_selected_module = types[i].module;
+                psz_last_playlist_ext = types[i].filter_patterns;
+                /* Fix file extension */
+                file = file.append( QString( "." ) + qfu( psz_last_playlist_ext ) );
+                break;
+            }
+        }
+    }
+
+    if ( psz_selected_module )
+    {
+        playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
+                         THEPL->p_playing, psz_selected_module );
+        getSettings()->setValue( "last-playlist-ext", psz_last_playlist_ext );
+    }
 }
 
 /****************************************************************************



More information about the vlc-commits mailing list