[vlc-commits] qt: Don't mix up URLs & path

Hugo Beauzée-Luyssen git at videolan.org
Thu Jan 5 11:34:34 CET 2017


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Jan  5 11:09:11 2017 +0100| [d4254763f030986cb3a3d35fc78d1c1e4dbea7c5] | committer: Hugo Beauzée-Luyssen

qt: Don't mix up URLs & path

This attempts to reduce the mixing up of URLs and file path (and the
often associated back and forth conversions) by using URLs as much as
possible
Fix #17841

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

 modules/gui/qt/components/open_panels.cpp |  8 +++---
 modules/gui/qt/dialogs_provider.cpp       | 47 ++++++++++++++++---------------
 modules/gui/qt/dialogs_provider.hpp       |  2 +-
 3 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/modules/gui/qt/components/open_panels.cpp b/modules/gui/qt/components/open_panels.cpp
index 08d4df0..ec86937 100644
--- a/modules/gui/qt/components/open_panels.cpp
+++ b/modules/gui/qt/components/open_panels.cpp
@@ -220,7 +220,7 @@ void FileOpenPanel::dropEvent( QDropEvent *event )
 
 void FileOpenPanel::browseFile()
 {
-    QStringList files = DialogsProvider::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath );
+    QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath );
     foreach( const QString &file, files )
     {
         QListWidgetItem *item =
@@ -250,11 +250,11 @@ void FileOpenPanel::removeFile()
 void FileOpenPanel::browseFileSub()
 {
     // TODO Handle selection of more than one subtitles file
-    QStringList files = THEDP->showSimpleOpen( qtr("Open subtitle file"),
+    QStringList urls = THEDP->showSimpleOpen( qtr("Open subtitle file"),
                            EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
 
-    if( files.isEmpty() ) return;
-    ui.subInput->setText( toNativeSeparators( files.join(" ") ) );
+    if( urls.isEmpty() ) return;
+    ui.subInput->setText( urls.join(" ") );
     updateMRL();
 }
 
diff --git a/modules/gui/qt/dialogs_provider.cpp b/modules/gui/qt/dialogs_provider.cpp
index 91852f2..9407107 100644
--- a/modules/gui/qt/dialogs_provider.cpp
+++ b/modules/gui/qt/dialogs_provider.cpp
@@ -110,24 +110,26 @@ DialogsProvider::~DialogsProvider()
     delete miscPopupMenu;
 }
 
-QStringList DialogsProvider::getOpenFileNames( QWidget *parent,
+QStringList DialogsProvider::getOpenURL( intf_thread_t* p_intf, QWidget *parent,
                                                const QString &caption,
                                                const QString &dir,
                                                const QString &filter,
                                                QString *selectedFilter )
 {
-    QStringList files;
+    QStringList res;
 
 #if HAS_QT52
     QList<QUrl> urls = QFileDialog::getOpenFileUrls( parent, caption, QUrl::fromUserInput( dir ), filter, selectedFilter );
 
-    foreach( const QUrl url, urls )
-        files.append( url.toEncoded() );
+    foreach( const QUrl& url, urls )
+        res.append( url.toEncoded() );
 #else
-    files = QFileDialog::getOpenFileNames( parent, caption, dir, filter, selectedFilter );
+    QStringList files = QFileDialog::getOpenFileNames( parent, caption, dir, filter, selectedFilter );
+    foreach ( const QString& file : files )
+        res.append( toURI( toNativeSeparators( file ) ) );
 #endif
 
-    return files;
+    return res;
 }
 
 QString DialogsProvider::getSaveFileName( QWidget *parent,
@@ -397,14 +399,14 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
     }
     else /* non-save mode */
     {
-        QStringList files = getOpenFileNames( NULL,
+        QStringList urls = getOpenURL( p_intf, NULL,
                 qfu( p_arg->psz_title ), p_intf->p_sys->filepath,
                 extensions );
-        p_arg->i_results = files.count();
+        p_arg->i_results = urls.count();
         p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
         i = 0;
-        foreach( const QString &file, files )
-            p_arg->psz_results[i++] = strdup( qtu( toNativeSepNoSlash( file ) ) );
+        foreach( const QString &uri, urls )
+            p_arg->psz_results[i++] = strdup( qtu( uri ) );
         if(i == 0)
             p_intf->p_sys->filepath = QString::fromLatin1("");
         else
@@ -496,14 +498,14 @@ QStringList DialogsProvider::showSimpleOpen( const QString& help,
     ADD_EXT_FILTER( fileTypes, EXTENSIONS_ALL );
     fileTypes.replace( ";*", " *");
 
-    QStringList files = getOpenFileNames( NULL,
+    QStringList urls = getOpenURL( p_intf, NULL,
         help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
         path.isEmpty() ? p_intf->p_sys->filepath : path,
         fileTypes );
 
-    if( !files.isEmpty() ) savedirpathFromFile( files.last() );
+    if( !urls.isEmpty() ) savedirpathFromFile( urls.last() );
 
-    return files;
+    return urls;
 }
 
 /**
@@ -513,13 +515,12 @@ QStringList DialogsProvider::showSimpleOpen( const QString& help,
  **/
 void DialogsProvider::addFromSimple( bool pl, bool go)
 {
-    QStringList files = DialogsProvider::showSimpleOpen();
+    QStringList urls = DialogsProvider::showSimpleOpen();
 
     bool first = go;
-    files.sort();
-    foreach( const QString &file, files )
+    urls.sort();
+    foreach( const QString &url, urls )
     {
-        QString url = toURI( toNativeSeparators( file ) );
         Open::openMRL( p_intf, url, first, pl);
         first = false;
     }
@@ -615,11 +616,11 @@ void DialogsProvider::PLAppendDir()
  ****************/
 void DialogsProvider::openAPlaylist()
 {
-    QStringList files = showSimpleOpen( qtr( "Open playlist..." ),
+    QStringList urls = showSimpleOpen( qtr( "Open playlist..." ),
                                         EXT_FILTER_PLAYLIST );
-    foreach( const QString &file, files )
+    foreach( const QString &url, urls )
     {
-        playlist_Import( THEPL, qtu( toNativeSeparators( file ) ) );
+        playlist_Import( THEPL, qtu( url ) );
     }
 }
 
@@ -826,12 +827,12 @@ void DialogsProvider::loadSubtitlesFile()
                                       EXT_FILTER_SUBTITLE,
                                       qfu( path2 ) );
     free( path2 );
-    foreach( const QString &qsFile, qsl )
+    foreach( const QString &qsUrl, qsl )
     {
-        if( input_AddSubtitleOSD( p_input, qtu( toNativeSeparators( qsFile ) ),
+        if( input_AddSubtitleOSD( p_input, qtu( toNativeSeparators( QUrl( qsUrl ).toLocalFile() ) ),
                     true, true ) )
             msg_Warn( p_intf, "unable to load subtitles from '%s'",
-                      qtu( qsFile ) );
+                      qtu( qsUrl ) );
     }
 }
 
diff --git a/modules/gui/qt/dialogs_provider.hpp b/modules/gui/qt/dialogs_provider.hpp
index b72f8ec..ccdc176 100644
--- a/modules/gui/qt/dialogs_provider.hpp
+++ b/modules/gui/qt/dialogs_provider.hpp
@@ -91,7 +91,7 @@ public:
                                 const QString& path = QString() );
     bool isDying() { return b_isDying; }
     static QString getDirectoryDialog( intf_thread_t *p_intf);
-    static QStringList getOpenFileNames( QWidget *parent = Q_NULLPTR,
+    static QStringList getOpenURL(intf_thread_t* p_intf, QWidget *parent = Q_NULLPTR,
                                          const QString &caption = QString(),
                                          const QString &dir = QString(),
                                          const QString &filter = QString(),



More information about the vlc-commits mailing list