]> git.sesse.net Git - vlc/commitdiff
Adds batch convert support to the VLC GUI.
authorLochlin Duperron <lochlinduperron@gmail.com>
Tue, 11 Nov 2014 07:46:26 +0000 (07:46 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 28 Nov 2014 11:27:11 +0000 (12:27 +0100)
This commit modifies the convert wizard to accept multiple files from the file dialog box

The GUI should operate the same when a single file is selected (providing
an option of where and what to name the file), but when multiple files are
selected the files are placed into the same folder with the same name and a
new extention (there is an option to append -converted if you are converting
to the same extention).
There are some tooltips to explain this operation.

Most of the changes are pretty straight-forward, converting QStrings to
QStringLists and passing the full list of MRLs around. The playlist already
supports the batch processing in a pretty straightforward way, so there's no
issues there.

StandardPanel.cpp was modified to create a temp QStringList for passing to the
streamingDialog, as it now takes the full list of input files rather than just
one

Convert.cpp/hpp modified to take the QStringList and to behave (semi)-intelligently when reciving multiple files,
Open.cpp modified to pass the MRLs rather than MRL[0]
and the Dialogs_provider.cpp/hpp to pass the MRLs along, pretty much.

It also clears the playlist when recieving a list and starts the playlist from the beginning when it's added all the files to be converted.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/gui/qt4/components/playlist/standardpanel.cpp
modules/gui/qt4/dialogs/convert.cpp
modules/gui/qt4/dialogs/convert.hpp
modules/gui/qt4/dialogs/open.cpp
modules/gui/qt4/dialogs_provider.cpp
modules/gui/qt4/dialogs_provider.hpp

index 38de867c24be39a570cb11b3ec39030a6c16ec2c..eb99f1bef3e210bf7d8b46de7014478132afc623 100644 (file)
@@ -319,14 +319,22 @@ void StandardPLPanel::popupAction( QAction *action )
         /* locally handled only */
         temp = model->getURI( index );
         if ( ! temp.isEmpty() )
-            THEDP->streamingDialog( NULL, temp, false );
+        {
+            QStringList tempList;
+            tempList.append(temp);
+            THEDP->streamingDialog( NULL, tempList, false );
+        }
         break;
 
     case VLCModelSubInterface::ACTION_SAVE:
         /* locally handled only */
         temp = model->getURI( index );
         if ( ! temp.isEmpty() )
-            THEDP->streamingDialog( NULL, temp );
+        {
+            QStringList tempList;
+            tempList.append(temp);
+            THEDP->streamingDialog( NULL, tempList );
+        }
         break;
 
     case VLCModelSubInterface::ACTION_CREATENODE:
index 267492844dc88bb6d478e545388f8a16d8e60a2e..5a7bceea962540fc367bdca333114568b6190199 100644 (file)
@@ -38,7 +38,7 @@
 #include <QCheckBox>
 
 ConvertDialog::ConvertDialog( QWidget *parent, intf_thread_t *_p_intf,
-                              const QString& inputMRL )
+                              const QStringList& inputMRLs )
               : QVLCDialog( parent, _p_intf )
 {
     setWindowTitle( qtr( "Convert" ) );
@@ -46,7 +46,18 @@ ConvertDialog::ConvertDialog( QWidget *parent, intf_thread_t *_p_intf,
 
     QGridLayout *mainLayout = new QGridLayout( this );
     SoutInputBox *inputBox = new SoutInputBox( this );
-    inputBox->setMRL( inputMRL );
+    incomingMRLs = &inputMRLs;
+
+    singleFileSelected = (inputMRLs.length() == 1);
+
+    if(singleFileSelected)
+    {
+        inputBox->setMRL( inputMRLs[0] );
+    }
+    else
+    {
+        inputBox->setMRL("Multiple files selected.");
+    }
     mainLayout->addWidget( inputBox, 0, 0, 1, -1  );
 
     /**
@@ -62,12 +73,26 @@ ConvertDialog::ConvertDialog( QWidget *parent, intf_thread_t *_p_intf,
     fileLine->setMinimumWidth( 300 );
     fileLine->setFocus( Qt::ActiveWindowFocusReason );
     destLabel->setBuddy( fileLine );
+    // You can set a specific name for only one file.
+    if(singleFileSelected)
+    {
+        QPushButton *fileSelectButton = new QPushButton( qtr( "Browse" ) );
+        destLayout->addWidget( fileSelectButton, 0, 2);
+        BUTTONACT( fileSelectButton, fileBrowse() );
+    }
 
-    QPushButton *fileSelectButton = new QPushButton( qtr( "Browse" ) );
-    destLayout->addWidget( fileLine, 0, 1 );
-    destLayout->addWidget( fileSelectButton, 0, 2);
-    BUTTONACT( fileSelectButton, fileBrowse() );
+    // but multiple files follow a naming convention
+    else
+    {
+        fileLine->setText("Multiple Files Selected.");
+        fileLine->setReadOnly(true);
+        fileLine->setToolTip("Files will be placed in the same directory "
+                "with the same name.");
 
+        appendBox = new QCheckBox( qtr( "Append '-converted' to filename" ) );
+        destLayout->addWidget( appendBox, 1, 0 );
+    }
+    destLayout->addWidget( fileLine, 0, 1 );
     mainLayout->addWidget( destBox, 3, 0, 1, -1  );
 
 
@@ -147,29 +172,74 @@ void ConvertDialog::close()
 {
     hide();
 
-    if( dumpRadio->isChecked() )
-    {
-        mrl = "demux=dump :demuxdump-file=" + fileLine->text();
-    }
-    else
+    for(int i = 0; i < incomingMRLs->length(); i++)
     {
-        mrl = "sout=#" + profile->getTranscode();
-        if( deinterBox->isChecked() )
+        QString mrl;
+
+        if( dumpRadio->isChecked() )
         {
-            mrl.remove( '}' );
-            mrl += ",deinterlace}";
+            mrl = "demux=dump :demuxdump-file=" + fileLine->text();
         }
-        mrl += ":";
-        if( displayBox->isChecked() )
-            mrl += "duplicate{dst=display,dst=";
-        mrl += "std{access=file{no-overwrite},mux=" + profile->getMux()
-             + ",dst='" + fileLine->text().replace( QChar('\''), "\\\'" )
-             + "'}";
-        if( displayBox->isChecked() )
-            mrl += "}";
+        else
+        {
+            mrl = "sout=#" + profile->getTranscode();
+            if( deinterBox->isChecked() )
+            {
+                mrl.remove( '}' );
+                mrl += ",deinterlace}";
+            }
+            mrl += ":";
+            if( displayBox->isChecked() )
+            {
+                mrl += "duplicate{dst=display,dst=";
+            }
+
+            QString newFileName;
+
+            // Only one file, use the destination provided
+            if(singleFileSelected)
+            {
+                newFileName = fileLine->text();
+            }
+
+            // Multiple, use the convention.
+            else
+            {
+                QString fileExtension = ( ! profile->isEnabled() ) ? ".*" : "." + profile->getMux();
+
+                newFileName = incomingMRLs->at(i);
+
+                // Remove the file:// from the front of our MRL
+                newFileName = newFileName.remove(0,7);
+
+                // Remote the existing extention (if any)
+                int extentionPos = newFileName.lastIndexOf('.');
+                if(extentionPos >= 0)
+                {
+                    newFileName = newFileName.remove(extentionPos, newFileName.length() - extentionPos);
+                }
+
+                // If we have multiple files (i.e. we have an appenBox) and it's checked
+                if(!singleFileSelected && appendBox->isChecked())
+                {
+                    newFileName = newFileName.append("-converted");
+                }
+
+                // Stick our new extention on
+                newFileName = newFileName.append(fileExtension);
+            }
+
+            newFileName.replace( QChar('\''), "\\\'" );
+
+            mrl += "std{access=file{no-overwrite},mux=" + profile->getMux()
+                 + ",dst='" + newFileName
+                 + "'}";
+            if( displayBox->isChecked() )
+                mrl += "}";
+        }
+        msg_Dbg( p_intf, "Transcode MRL: %s", qtu( mrl ) );
+        mrls.append(mrl);
     }
-
-    msg_Dbg( p_intf, "Transcode MRL: %s", qtu( mrl ) );
     accept();
 }
 
index 9a9727e69e9d9cb3c1fd6cdaf2f5f7a717ccaa9c..8b69c0b0bda691db978a0af99d61a1663ce20d67 100644 (file)
@@ -36,19 +36,23 @@ class ConvertDialog : public QVLCDialog
 {
     Q_OBJECT
 public:
-    ConvertDialog( QWidget *, intf_thread_t *, const QString& );
+    ConvertDialog( QWidget *, intf_thread_t *, const QStringList& );
     virtual ~ConvertDialog(){}
 
-    QString getMrl() {return mrl;}
+    QStringList getMrls() {return mrls;}
 
 private:
     QLineEdit *fileLine;
 
-    QCheckBox *displayBox, *deinterBox;
+    QCheckBox *displayBox, *deinterBox, *appendBox;
     QRadioButton *dumpRadio;
     QPushButton *okButton;
     VLCProfileSelector *profile;
-    QString mrl;
+
+    const QStringList *incomingMRLs;
+    bool singleFileSelected;
+    QStringList mrls;
+
 private slots:
     void close() Q_DECL_OVERRIDE;
     void cancel() Q_DECL_OVERRIDE;
index 56ea9801ff012e03932555b732de83929f171ae8..90c7949a9378a5265e3509f4bfc106ab43a95f07 100644 (file)
@@ -392,13 +392,24 @@ void OpenDialog::transcode()
 
 void OpenDialog::stream( bool b_transcode_only )
 {
-    QString soutMRL = getMRL( false );
-    if( soutMRL.isEmpty() ) return;
+//    QString soutMRL = getMRL( false );
+//    if( soutMRL.isEmpty() ) return;
+
+    QStringList soutMRLS = getMRLs(false);
+    if(soutMRLS.empty())
+    {
+        return;
+    }
+
     toggleVisible();
 
     /* Dbg and send :D */
-    msg_Dbg( p_intf, "MRL passed to the Sout: %s", qtu( soutMRL ) );
-    THEDP->streamingDialog( this, soutMRL, b_transcode_only,
+    msg_Dbg( p_intf, "MRL(s) passed to the Sout: %i", soutMRLS.length() );
+    for(int i = 0; i < soutMRLS.length(); i++)
+    {
+        msg_Dbg( p_intf, "MRL(s) passed to the Sout: %s", qtu( soutMRLS[i] ) );
+    }
+    THEDP->streamingDialog( this, soutMRLS, b_transcode_only,
                             getOptions().split( " :" ) );
 }
 
index 7c3cf165c958182a302536924c458fd7081c1ffb..025d31db30ffc0073a5a8f2a83fd3ff1c9a95ce3 100644 (file)
@@ -689,20 +689,22 @@ void DialogsProvider::saveRecentsToPlaylist()
  ****************************************************************************/
 
 void DialogsProvider::streamingDialog( QWidget *parent,
-                                       const QString& mrl,
+                                       const QStringList& mrls,
                                        bool b_transcode_only,
                                        QStringList options )
 {
-    QString soutoption;
+    QStringList outputMRLs;
 
     /* Stream */
+    // Does streaming multiple files make sense?  I suppose so, just stream one
+    // after the other, but not at the moment.
     if( !b_transcode_only )
     {
-        SoutDialog *s = new SoutDialog( parent, p_intf, mrl );
+        SoutDialog *s = new SoutDialog( parent, p_intf, mrls[0] );
         s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
         if( s->exec() == QDialog::Accepted )
         {
-            soutoption = s->getMrl();
+            outputMRLs.append(s->getMrl());
             delete s;
         }
         else
@@ -711,11 +713,15 @@ void DialogsProvider::streamingDialog( QWidget *parent,
         }
     } else {
     /* Convert */
-        ConvertDialog *s = new ConvertDialog( parent, p_intf, mrl );
+        ConvertDialog *s = new ConvertDialog( parent, p_intf, mrls );
         s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
         if( s->exec() == QDialog::Accepted )
         {
-            soutoption = s->getMrl();
+            /* Clear the playlist.  This is because we're going to be populating
+               it */
+            playlist_Clear( THEPL, pl_Unlocked );
+
+            outputMRLs = s->getMrls();
             delete s;
         }
         else
@@ -724,12 +730,30 @@ void DialogsProvider::streamingDialog( QWidget *parent,
         }
     }
 
-    /* Get SoutMRL */
-    if( !soutoption.isEmpty() )
+    /* Get SoutMRL(s) */
+    if( !outputMRLs.isEmpty() )
     {
-        options += soutoption.split( " :");
+        /* For all of our MRLs */
+        for(int i = 0; i < outputMRLs.length(); i++)
+        {
+
+            /* Duplicate the options list.  This is because we need to have a
+             copy for every file we add to the playlist.*/
+            QStringList optionsCopy;
+            for(int j = 0; j < options.length(); j++)
+            {
+                optionsCopy.append(options[j]);
+            }
+
+            optionsCopy+= outputMRLs[i].split( " :");
+            QString title = "Converting " + mrls[i];
+
+            /* Add each file to convert to our playlist, making sure to not attempt to start playing it.*/
+            Open::openMRLwithOptions( p_intf, mrls[i], &optionsCopy, false, true, _(title.toStdString().c_str()) );
+        }
 
-        Open::openMRLwithOptions( p_intf, mrl, &options, true, true, _("Streaming") );
+        /* Start the playlist from the beginning */
+        playlist_Control(THEPL,PLAYLIST_PLAY,pl_Unlocked);
     }
 }
 
index 4327fcda77e104d2a42132be1061b14756d177cc..3b577d0075826c2d9081265abf5fb81ac567617b 100644 (file)
@@ -160,7 +160,7 @@ public slots:
     void PLOpenDir();
     void PLAppendDir();
 
-    void streamingDialog( QWidget *parent, const QString& mrl, bool b_stream = true,
+    void streamingDialog( QWidget *parent, const QStringList& mrls, bool b_stream = true,
                           QStringList options = QStringList("") );
     void openAndStreamingDialogs();
     void openAndTranscodingDialogs();