1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
/*****************************************************************************
* convert.cpp : Convertion dialogs
****************************************************************************
* Copyright (C) 2009 the VideoLAN team
* $Id$
*
* Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "dialogs/sout.hpp"
#include "dialogs/convert.hpp"
#include "components/sout/sout_widgets.hpp"
#include "util/qt_dirs.hpp"
#include <QLabel>
#include <QGroupBox>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QCheckBox>
#define urlToDisplayString(filestr) toNativeSeparators(QUrl(filestr).toDisplayString(\
QUrl::RemovePassword | QUrl::PreferLocalFile | QUrl::NormalizePathSegments ))
ConvertDialog::ConvertDialog( QWidget *parent, intf_thread_t *_p_intf,
const QStringList& inputMRLs )
: QVLCDialog( parent, _p_intf ),
singleFileSelected( inputMRLs.length() == 1 )
{
setWindowTitle( qtr( "Convert" ) );
setWindowRole( "vlc-convert" );
QGridLayout *mainLayout = new QGridLayout( this );
SoutInputBox *inputBox = new SoutInputBox( this );
incomingMRLs = &inputMRLs;
if(singleFileSelected)
{
inputBox->setMRL( inputMRLs[0] );
}
else
{
inputBox->setMRL( qtr( "Multiple files selected." ) );
}
mainLayout->addWidget( inputBox, 0, 0, 1, -1 );
/**
* Destination
**/
QGroupBox *destBox = new QGroupBox( qtr( "Destination" ) );
QGridLayout *destLayout = new QGridLayout( destBox );
QLabel *destLabel = new QLabel( qtr( "Destination file:" ) );
destLayout->addWidget( destLabel, 0, 0);
fileLine = new QLineEdit;
fileLine->setMinimumWidth( 300 );
fileLine->setFocus( Qt::ActiveWindowFocusReason );
fileLine->setReadOnly(true);
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() );
}
// but multiple files follow a naming convention
else
{
fileLine->setText( qtr( "Multiple Files Selected." ) );
fileLine->setReadOnly(true);
fileLine->setToolTip( qtr( "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 );
/* Profile Editor */
QGroupBox *settingBox = new QGroupBox( qtr( "Settings" ) );
QGridLayout *settingLayout = new QGridLayout( settingBox );
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" ) );
convertLayout->addWidget( deinterBox );
profile = new VLCProfileSelector( this );
convertLayout->addWidget( profile );
settingLayout->addWidget( convertPanel, 2, 0 );
settingLayout->addWidget( dumpRadio, 5, 0 );
mainLayout->addWidget( settingBox, 1, 0, 1, -1 );
/* Buttons */
okButton = new QPushButton( qtr( "&Start" ) );
QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
QDialogButtonBox *buttonBox = new QDialogButtonBox;
okButton->setDefault( true );
buttonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
buttonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
mainLayout->addWidget( buttonBox, 5, 3 );
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() ) ? QStringLiteral(".*") : QStringLiteral(".") + profile->getMux();
outgoingMRL = QFileDialog::getSaveFileUrl( this, qtr( "Save file..." ),
p_intf->p_sys->filepath,
QString( "%1 (*%2);;%3 (*.*)" ).arg( qtr( "Containers" ) )
.arg( fileExtension ).arg( qtr("All") ), 0, QFileDialog::DontConfirmOverwrite );
fileLine->setText( urlToDisplayString( outgoingMRL ) );
setDestinationFileExtension();
}
void ConvertDialog::cancel()
{
reject();
}
void ConvertDialog::close()
{
hide();
for(int i = 0; i < incomingMRLs->length(); i++)
{
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 = outgoingMRL.toLocalFile();
}
// Multiple, use the convention.
else
{
QString fileExtension = ( ! profile->isEnabled() ) ? QStringLiteral(".*") : QStringLiteral(".") + profile->getMux();
newFileName = incomingMRLs->at(i);
// Remove the file:// from the front of our MRL
newFileName = QUrl(newFileName).toLocalFile();
// 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( 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);
}
accept();
}
void ConvertDialog::setDestinationFileExtension()
{
if( !outgoingMRL.isEmpty() && profile->isEnabled() )
{
QString filepath = outgoingMRL.path(QUrl::FullyEncoded);
if( filepath.lastIndexOf( "." ) == -1 )
{
QString newFileExtension = "." + profile->getMux();
outgoingMRL.setPath(filepath + newFileExtension);
fileLine->setText( urlToDisplayString( outgoingMRL ) );
}
}
}
void ConvertDialog::validate()
{
okButton->setEnabled( !fileLine->text().isEmpty() );
}
|