]> git.sesse.net Git - vlc/commitdiff
Qt: use the native dialog for Save Playlist
authorJean-Baptiste Kempf <jb@videolan.org>
Sun, 21 Jun 2009 16:02:42 +0000 (18:02 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Sun, 21 Jun 2009 16:02:42 +0000 (18:02 +0200)
This is better for translations, and look'n feel.
This defaults the name to .xspf, if not a valid extension is provided.

modules/gui/qt4/dialogs_provider.cpp

index 2f27d3c2336cf1d4e34e9131a74f39d1191920b1..9db54c872158916227fdcca1073f69e3c2273960 100644 (file)
@@ -515,58 +515,37 @@ void DialogsProvider::openAPlaylist()
 
 void DialogsProvider::saveAPlaylist()
 {
-    QFileDialog *qfd = new QFileDialog( NULL,
-                                   qtr( "Save playlist as..." ),
-                                   p_intf->p_sys->filepath,
-                                   qtr( "XSPF playlist (*.xspf);; " ) +
-                                   qtr( "M3U playlist (*.m3u);; " ) +
-                                   qtr( "HTML playlist (*.html)" ) );
-    qfd->setFileMode( QFileDialog::AnyFile );
-    qfd->setAcceptMode( QFileDialog::AcceptSave );
-    qfd->setConfirmOverwrite( true );
-
-    if( qfd->exec() == QDialog::Accepted )
+    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)" ) );
+
+    if( !file.isEmpty() )
     {
-        if( qfd->selectedFiles().count() > 0 )
+        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
         {
-            static const char psz_xspf[] = "export-xspf",
-                              psz_m3u[] = "export-m3u",
-                              psz_html[] = "export-html";
-            const char *psz_module;
-
-            QString file = qfd->selectedFiles().first();
-            QString filter = qfd->selectedFilter();
-
-            if( file.contains( ".xsp" ) || filter.contains( "XSPF" ) )
-            {
-                psz_module = psz_xspf;
-                if( !file.contains( ".xsp" ) )
-                    file.append( ".xspf" );
-            }
-            else if( file.contains( ".m3u" )  || filter.contains( "M3U" ) )
-            {
-                psz_module = psz_m3u;
-                if( !file.contains( ".m3u" ) )
-                    file.append( ".m3u" );
-            }
-            else if( file.contains(".html" ) || filter.contains( "HTML" ) )
-            {
-                psz_module = psz_html;
-                if( !file.contains( "html" ) )
-                    file.append( ".html" );
-            }
-            else
-            {
-                msg_Err( p_intf, "Impossible to recognise the file type" );
-                delete qfd;
-                return;
-            }
-
-            playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
-                        THEPL->p_local_category, psz_module);
+            msg_Warn( p_intf, "Impossible to recognise the file type. "
+                    "Defaulting to XSPF" );
+            psz_module = psz_xspf;
+            file.append( ".xpsf" );
         }
+
+        playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
+                THEPL->p_local_category, psz_module);
     }
-    delete qfd;
 }
 
 /****************************************************************************