]> git.sesse.net Git - vlc/commitdiff
Qt4: determine saved playlist format from selected filter...
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 4 Aug 2009 17:25:49 +0000 (20:25 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 4 Aug 2009 17:48:45 +0000 (20:48 +0300)
...rather than extension (if any). Fixes: #3016.
Also make the code a bit more generic.

modules/gui/qt4/dialogs_provider.cpp

index f150b0eceb431c1f1bba302018d3a25c4d984405..ab2fc5315398626bb0d882af590749722d45b75f 100644 (file)
@@ -525,37 +525,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);
-    }
 }
 
 /****************************************************************************