1 /*****************************************************************************
2 * convert.cpp : Convertion dialogs
3 ****************************************************************************
4 * Copyright (C) 2009 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include "dialogs/sout.hpp"
29 #include "dialogs/convert.hpp"
30 #include "components/sout/sout_widgets.hpp"
32 #include "util/qt_dirs.hpp"
36 #include <QDialogButtonBox>
37 #include <QFileDialog>
40 ConvertDialog::ConvertDialog( QWidget *parent, intf_thread_t *_p_intf,
41 const QString& inputMRL )
42 : QVLCDialog( parent, _p_intf )
44 setWindowTitle( qtr( "Convert" ) );
45 setWindowRole( "vlc-convert" );
47 QGridLayout *mainLayout = new QGridLayout( this );
48 SoutInputBox *inputBox = new SoutInputBox( this );
49 inputBox->setMRL( inputMRL );
50 mainLayout->addWidget( inputBox, 0, 0, 1, -1 );
55 QGroupBox *destBox = new QGroupBox( qtr( "Destination" ) );
56 QGridLayout *destLayout = new QGridLayout( destBox );
58 QLabel *destLabel = new QLabel( qtr( "Destination file:" ) );
59 destLayout->addWidget( destLabel, 0, 0);
61 fileLine = new QLineEdit;
62 fileLine->setMinimumWidth( 300 );
63 fileLine->setFocus( Qt::ActiveWindowFocusReason );
64 destLabel->setBuddy( fileLine );
66 QPushButton *fileSelectButton = new QPushButton( qtr( "Browse" ) );
67 destLayout->addWidget( fileLine, 0, 1 );
68 destLayout->addWidget( fileSelectButton, 0, 2);
69 BUTTONACT( fileSelectButton, fileBrowse() );
71 mainLayout->addWidget( destBox, 3, 0, 1, -1 );
75 QGroupBox *settingBox = new QGroupBox( qtr( "Settings" ) );
76 QGridLayout *settingLayout = new QGridLayout( settingBox );
78 QRadioButton *convertRadio = new QRadioButton( qtr( "Convert" ) );
79 dumpRadio = new QRadioButton( qtr( "Dump raw input" ) );
80 QButtonGroup *buttonGroup = new QButtonGroup(this);
81 buttonGroup->addButton( convertRadio );
82 buttonGroup->addButton( dumpRadio );
83 convertRadio->setChecked( true );
85 settingLayout->addWidget( convertRadio, 1, 0 );
87 QWidget *convertPanel = new QWidget( this );
88 QVBoxLayout *convertLayout = new QVBoxLayout( convertPanel );
90 displayBox = new QCheckBox( qtr( "Display the output" ) );
91 displayBox->setToolTip( qtr( "This display the resulting media, but can "
92 "slow things down." ) );
93 convertLayout->addWidget( displayBox );
95 deinterBox = new QCheckBox( qtr( "Deinterlace" ) );
96 convertLayout->addWidget( deinterBox );
98 profile = new VLCProfileSelector( this );
99 convertLayout->addWidget( profile );
101 settingLayout->addWidget( convertPanel, 2, 0 );
103 settingLayout->addWidget( dumpRadio, 5, 0 );
105 mainLayout->addWidget( settingBox, 1, 0, 1, -1 );
108 okButton = new QPushButton( qtr( "&Start" ) );
109 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
110 QDialogButtonBox *buttonBox = new QDialogButtonBox;
112 okButton->setDefault( true );
113 buttonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
114 buttonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
116 mainLayout->addWidget( buttonBox, 5, 3 );
118 BUTTONACT(okButton,close());
119 BUTTONACT(cancelButton,cancel());
121 CONNECT( convertRadio, toggled(bool), convertPanel, setEnabled(bool) );
122 CONNECT(profile, optionsChanged(), this, setDestinationFileExtension());
123 CONNECT(fileLine, editingFinished(), this, setDestinationFileExtension());
124 CONNECT(fileLine, textChanged(const QString&), this, validate());
129 void ConvertDialog::fileBrowse()
131 QString fileExtension = ( ! profile->isEnabled() ) ? ".*" : "." + profile->getMux();
133 QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
134 p_intf->p_sys->filepath,
135 QString( "%1 (*%2);;%3 (*.*)" ).arg( qtr( "Containers" ) )
136 .arg( fileExtension ).arg( qtr("All") ) );
137 fileLine->setText( toNativeSeparators( fileName ) );
138 setDestinationFileExtension();
141 void ConvertDialog::cancel()
146 void ConvertDialog::close()
150 if( dumpRadio->isChecked() )
152 mrl = "demux=dump :demuxdump-file=" + fileLine->text();
156 mrl = "sout=#" + profile->getTranscode();
157 if( deinterBox->isChecked() )
160 mrl += ",deinterlace}";
163 if( displayBox->isChecked() )
164 mrl += "duplicate{dst=display,dst=";
165 mrl += "std{access=file{no-overwrite},mux=" + profile->getMux()
166 + ",dst='" + fileLine->text().replace( QChar('\''), "\\\'" )
168 if( displayBox->isChecked() )
172 msg_Dbg( p_intf, "Transcode MRL: %s", qtu( mrl ) );
176 void ConvertDialog::setDestinationFileExtension()
178 if( !fileLine->text().isEmpty() && profile->isEnabled() )
180 QString newFileExtension = "." + profile->getMux();
181 if( fileLine->text().lastIndexOf( "." ) == -1 )
183 QString newFileName = fileLine->text().append( newFileExtension );
184 fileLine->setText( toNativeSeparators( newFileName ) );
189 void ConvertDialog::validate()
191 okButton->setEnabled( !fileLine->text().isEmpty() );