[vlc-devel] commit: Qt4: determine saved playlist format from selected filter... ( Rémi Denis-Courmont )

git version control git at videolan.org
Tue Aug 4 19:49:28 CEST 2009


vlc | branch: 1.0-bugfix | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug  4 20:25:49 2009 +0300| [a0fdf749ce7b4e22dfb8dee8ffcc95ea8fa16d09] | committer: Rémi Denis-Courmont 

Qt4: determine saved playlist format from selected filter...

...rather than extension (if any). Fixes: #3016.
Also make the code a bit more generic.
(cherry picked from commit 2037bb718619e167f5a53ec1c445dda50c5b7a84)

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

 modules/gui/qt4/dialogs_provider.cpp |   52 +++++++++++++++++-----------------
 1 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index 19f665d..0c4da89 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -527,37 +527,37 @@ void DialogsProvider::openAPlaylist()
 
 void DialogsProvider::saveAPlaylist()
 {
+    static const struct
+    {
+        char filter[24];
+        char module[12];
+    } types[] = {
+        { N_("XSPF playlist (*.xpsf)"), "export-xspf", },
+        { N_("M3U playlist (*.m3u)"), "export-m3u", },
+        { N_("HTML playlist (*.html)"), "export-html", },
+    };
+    QString filters, selected;
+
+    for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++ )
+    {
+        if( !filters.isEmpty() )
+            filters += ";;";
+        filters += qfu( vlc_gettext( types[i].filter ) );
+    }
+
     QString file = QFileDialog::getSaveFileName( NULL,
                                   qtr( "Save playlist as..." ),
-                                  p_intf->p_sys->filepath,
-                                  qtr( "XSPF playlist (*.xspf);; " ) +
-                                  qtr( "M3U playlist (*.m3u);; " ) +
-                                  qtr( "HTML playlist (*.html)" ) );
+                                  p_intf->p_sys->filepath, filters, &selected );
+    if( file.isEmpty() )
+        return;
 
-    if( !file.isEmpty() )
-    {
-        static const char psz_xspf[] = "export-xspf",
-                          psz_m3u[] = "export-m3u",
-                          psz_html[] = "export-html";
-        const char *psz_module;
-
-        if( file.contains( ".xsp" ) )
-            psz_module = psz_xspf;
-        else if( file.contains( ".m3u" ) )
-            psz_module = psz_m3u;
-        else if( file.contains(".html" ) )
-            psz_module = psz_html;
-        else
+    for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
+        if( selected == qfu( vlc_gettext( types[i].filter ) ) )
         {
-            msg_Warn( p_intf, "Impossible to recognise the file type. "
-                    "Defaulting to XSPF" );
-            psz_module = psz_xspf;
-            file.append( ".xspf" );
+            playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
+                             THEPL->p_local_category, types[i].module );
+            break;
         }
-
-        playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
-                THEPL->p_local_category, psz_module);
-    }
 }
 
 /****************************************************************************




More information about the vlc-devel mailing list