]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/convert.cpp
Adds batch convert support to the VLC GUI.
[vlc] / modules / gui / qt4 / dialogs / convert.cpp
index fc371948380738e0d177519dff74b956ffbd17f4..5a7bceea962540fc367bdca333114568b6190199 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Convert.cpp : Convertion dialogs
+ * convert.cpp : Convertion dialogs
  ****************************************************************************
  * Copyright (C) 2009 the VideoLAN team
  * $Id$
@@ -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,37 +73,64 @@ 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() );
-
-    displayBox = new QCheckBox( qtr( "Display the output" ) );
-    displayBox->setToolTip( qtr( "This display the resulting media, but can "
-                               "slow things down." ) );
-    destLayout->addWidget( displayBox, 2, 0, 1, -1 );
+    // 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.");
 
-    mainLayout->addWidget( destBox, 1, 0, 1, -1  );
+        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  );
 
 
     /* Profile Editor */
     QGroupBox *settingBox = new QGroupBox( qtr( "Settings" ) );
     QGridLayout *settingLayout = new QGridLayout( settingBox );
 
-    profile = new VLCProfileSelector( this );
-    settingLayout->addWidget( profile, 0, 0, 1, -1 );
+    QRadioButton *convertRadio = new QRadioButton( qtr( "Convert" ) );
+    dumpRadio = new QRadioButton( qtr( "Dump raw input" ) );
+    QButtonGroup *buttonGroup = new QButtonGroup(this);
+    buttonGroup->addButton( convertRadio );
+    buttonGroup->addButton( dumpRadio );
+    convertRadio->setChecked( true );
+
+    settingLayout->addWidget( convertRadio, 1, 0 );
+
+    QWidget *convertPanel = new QWidget( this );
+    QVBoxLayout *convertLayout = new QVBoxLayout( convertPanel );
+
+    displayBox = new QCheckBox( qtr( "Display the output" ) );
+    displayBox->setToolTip( qtr( "This display the resulting media, but can "
+                               "slow things down." ) );
+    convertLayout->addWidget( displayBox );
 
     deinterBox = new QCheckBox( qtr( "Deinterlace" ) );
-    settingLayout->addWidget( deinterBox, 1, 0 );
+    convertLayout->addWidget( deinterBox );
+
+    profile = new VLCProfileSelector( this );
+    convertLayout->addWidget( profile );
+
+    settingLayout->addWidget( convertPanel, 2, 0 );
 
-    dumpBox = new QCheckBox( qtr( "Dump raw input" ) );
-    settingLayout->addWidget( dumpBox, 1, 1 );
+    settingLayout->addWidget( dumpRadio, 5, 0 );
 
-    mainLayout->addWidget( settingBox, 3, 0, 1, -1  );
+    mainLayout->addWidget( settingBox, 1, 0, 1, -1  );
 
     /* Buttons */
-    QPushButton *okButton = new QPushButton( qtr( "&Start" ) );
+    okButton = new QPushButton( qtr( "&Start" ) );
     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
     QDialogButtonBox *buttonBox = new QDialogButtonBox;
 
@@ -102,16 +140,27 @@ ConvertDialog::ConvertDialog( QWidget *parent, intf_thread_t *_p_intf,
 
     mainLayout->addWidget( buttonBox, 5, 3 );
 
-    BUTTONACT( okButton, close() );
-    BUTTONACT( cancelButton, cancel() );
+    BUTTONACT(okButton,close());
+    BUTTONACT(cancelButton,cancel());
+
+    CONNECT( convertRadio, toggled(bool), convertPanel, setEnabled(bool) );
+    CONNECT(profile, optionsChanged(), this, setDestinationFileExtension());
+    CONNECT(fileLine, editingFinished(), this, setDestinationFileExtension());
+    CONNECT(fileLine, textChanged(const QString&), this, validate());
+
+    validate();
 }
 
 void ConvertDialog::fileBrowse()
 {
+    QString fileExtension = ( ! profile->isEnabled() ) ? ".*" : "." + profile->getMux();
+
     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
-            "",
- qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
+        p_intf->p_sys->filepath,
+        QString( "%1 (*%2);;%3 (*.*)" ).arg( qtr( "Containers" ) )
+            .arg( fileExtension ).arg( qtr("All") ) );
     fileLine->setText( toNativeSeparators( fileName ) );
+    setDestinationFileExtension();
 }
 
 void ConvertDialog::cancel()
@@ -123,27 +172,91 @@ void ConvertDialog::close()
 {
     hide();
 
-    if( dumpBox->isChecked() )
+    for(int i = 0; i < incomingMRLs->length(); i++)
     {
-        mrl = "demux=dump :demuxdump-file=" + fileLine->text();
+        QString mrl;
+
+        if( dumpRadio->isChecked() )
+        {
+            mrl = "demux=dump :demuxdump-file=" + fileLine->text();
+        }
+        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);
     }
-    else
+    accept();
+}
+
+void ConvertDialog::setDestinationFileExtension()
+{
+    if( !fileLine->text().isEmpty() && profile->isEnabled() )
     {
-        mrl = "sout=#" + profile->getTranscode();
-        if( deinterBox->isChecked() )
+        QString newFileExtension = "." + profile->getMux();
+        if( fileLine->text().lastIndexOf( "." ) == -1 )
         {
-            mrl.remove( '}' );
-            mrl += ",deinterlace}";
+            QString newFileName = fileLine->text().append( newFileExtension );
+            fileLine->setText( toNativeSeparators( newFileName ) );
         }
-        mrl += ":";
-        if( displayBox->isChecked() )
-            mrl += "duplicate{dst=display,dst=";
-        mrl += "file{dst='" + fileLine->text() + "'}";
-        if( displayBox->isChecked() )
-            mrl += "}";
     }
-
-    msg_Warn( p_intf, "Transcode MRL: %s", qtu( mrl ) );
-    accept();
 }
 
+void ConvertDialog::validate()
+{
+    okButton->setEnabled( !fileLine->text().isEmpty() );
+}