[vlc-devel] [PATCH 2/4] qt: keep files with local file representation and store them as URL in open dialog

Pierre Lamot pierre at videolabs.io
Fri Jan 19 18:10:22 CET 2018


  - fields are now, read only and can be only edited throught the add/browse
    buttons
---
 modules/gui/qt/components/open_panels.cpp | 40 +++++++++++++++++--------------
 modules/gui/qt/components/open_panels.hpp |  2 ++
 modules/gui/qt/ui/open_file.ui            |  8 +++++--
 3 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/modules/gui/qt/components/open_panels.cpp b/modules/gui/qt/components/open_panels.cpp
index 8da218b321..77d87c5460 100644
--- a/modules/gui/qt/components/open_panels.cpp
+++ b/modules/gui/qt/components/open_panels.cpp
@@ -153,6 +153,7 @@ void FileOpenPanel::dropEvent( QDropEvent *event )
                                          ui.fileListWidg );
             item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
             ui.fileListWidg->addItem( item );
+            urlList << url;
         }
     }
     updateMRL();
@@ -165,9 +166,14 @@ void FileOpenPanel::browseFile()
     QStringList files = THEDP->showSimpleOpen( qtr( "Select one or multiple files" ) );
     foreach( const QString &file, files )
     {
-        QListWidgetItem *item =
-            new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
-        item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
+        QUrl url(file);
+        urlList << url;
+        QListWidgetItem *item = nullptr;
+        item = new QListWidgetItem(
+            toNativeSeparators( url.toDisplayString(QUrl::RemovePassword | QUrl::PreferLocalFile | QUrl::NormalizePathSegments) ),
+            ui.fileListWidg
+            );
+        item->setFlags( Qt::ItemIsEnabled );
         ui.fileListWidg->addItem( item );
         savedirpathFromFile( file );
     }
@@ -182,6 +188,7 @@ void FileOpenPanel::removeFile()
     {
         QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
         delete temp;
+        urlList.removeAt( i );
     }
 
     updateMRL();
@@ -194,15 +201,12 @@ void FileOpenPanel::browseFileSub()
     QStringList urls = THEDP->showSimpleOpen( qtr("Open subtitle file"),
                            EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
 
-    if( urls.isEmpty() ) return;
-
-    // TODO Handle selection of more than one subtitles file
-    char *path = vlc_uri2path( qtu(urls[0]) );
-    if( path == NULL )
+    if( urls.isEmpty() ) {
         return;
+    }
 
-    ui.subInput->setText( qfu(path) );
-    free( path );
+    subUrl = QUrl(urls[0]);
+    ui.subInput->setText( subUrl.toDisplayString(QUrl::RemovePassword | QUrl::PreferLocalFile | QUrl::NormalizePathSegments) );
     updateMRL();
 }
 
@@ -213,15 +217,12 @@ void FileOpenPanel::updateMRL()
     QString mrl;
 
     /* File Listing */
-    for( int i = 0; i < ui.fileListWidg->count(); i++ )
-    {
-        if( !ui.fileListWidg->item( i )->text().isEmpty() )
-            fileList << toURI(ui.fileListWidg->item( i )->text());
-    }
+    foreach( const QUrl& url, urlList )
+        fileList << url.toEncoded();
 
     /* Options */
-    if( ui.subGroupBox->isChecked() &&  !ui.subInput->text().isEmpty() ) {
-        mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
+    if( ui.subGroupBox->isChecked() &&  !subUrl.isEmpty() ) {
+        mrl.append( " :sub-file=" + colon_escape( subUrl.toEncoded() ) );
     }
 
     emit methodChanged( "file-caching" );
@@ -232,6 +233,7 @@ void FileOpenPanel::updateMRL()
 void FileOpenPanel::accept()
 {
     ui.fileListWidg->clear();
+    urlList.clear();
 }
 
 /* Function called by Open Dialog when clicked on cancel */
@@ -239,12 +241,14 @@ void FileOpenPanel::clear()
 {
     ui.fileListWidg->clear();
     ui.subInput->clear();
+    urlList.clear();
+    subUrl = QUrl();
 }
 
 /* Update buttons depending on current selection */
 void FileOpenPanel::updateButtons()
 {
-    bool b_has_files = ( ui.fileListWidg->count() > 0 );
+    bool b_has_files = !urlList.empty();
     ui.removeFileButton->setEnabled( b_has_files );
     ui.subGroupBox->setEnabled( b_has_files );
 }
diff --git a/modules/gui/qt/components/open_panels.hpp b/modules/gui/qt/components/open_panels.hpp
index b753087cf7..81396bbb09 100644
--- a/modules/gui/qt/components/open_panels.hpp
+++ b/modules/gui/qt/components/open_panels.hpp
@@ -116,6 +116,8 @@ protected:
     void dragLeaveEvent( QDragLeaveEvent * ) Q_DECL_OVERRIDE;
 private:
     Ui::OpenFile ui;
+    QList<QUrl> urlList;
+    QUrl subUrl; //url for subtitle
     void BuildOldPanel();
 public slots:
     void updateMRL() Q_DECL_OVERRIDE;
diff --git a/modules/gui/qt/ui/open_file.ui b/modules/gui/qt/ui/open_file.ui
index 8da3e20ec1..233b61cd47 100644
--- a/modules/gui/qt/ui/open_file.ui
+++ b/modules/gui/qt/ui/open_file.ui
@@ -40,7 +40,11 @@
      </property>
      <layout class="QHBoxLayout" name="horizontalLayout_2">
       <item>
-       <widget class="QLineEdit" name="subInput"/>
+       <widget class="QLineEdit" name="subInput">
+        <property name="readOnly">
+         <bool>true</bool>
+        </property>
+       </widget>
       </item>
       <item>
        <widget class="QPushButton" name="subBrowseButton">
@@ -95,7 +99,7 @@
          <enum>Qt::ScrollBarAlwaysOff</enum>
         </property>
         <property name="editTriggers">
-         <set>QAbstractItemView::AllEditTriggers</set>
+         <set>QAbstractItemView::NoEditTriggers</set>
         </property>
         <property name="alternatingRowColors">
          <bool>true</bool>
-- 
2.14.1



More information about the vlc-devel mailing list