]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/convert.cpp
Qt: ConvertDialog: Don't enforce extension on raw dump
[vlc] / modules / gui / qt4 / dialogs / convert.cpp
1 /*****************************************************************************
2  * convert.cpp : Convertion dialogs
3  ****************************************************************************
4  * Copyright (C) 2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "dialogs/sout.hpp"
29 #include "dialogs/convert.hpp"
30 #include "components/sout/sout_widgets.hpp"
31
32 #include "util/qt_dirs.hpp"
33
34 #include <QLabel>
35 #include <QGroupBox>
36 #include <QDialogButtonBox>
37 #include <QFileDialog>
38 #include <QCheckBox>
39
40 ConvertDialog::ConvertDialog( QWidget *parent, intf_thread_t *_p_intf,
41                               const QString& inputMRL )
42               : QVLCDialog( parent, _p_intf )
43 {
44     setWindowTitle( qtr( "Convert" ) );
45     setWindowRole( "vlc-convert" );
46
47     QGridLayout *mainLayout = new QGridLayout( this );
48     SoutInputBox *inputBox = new SoutInputBox( this );
49     inputBox->setMRL( inputMRL );
50     mainLayout->addWidget( inputBox, 0, 0, 1, -1  );
51
52     /**
53      * Destination
54      **/
55     QGroupBox *destBox = new QGroupBox( qtr( "Destination" ) );
56     QGridLayout *destLayout = new QGridLayout( destBox );
57
58     QLabel *destLabel = new QLabel( qtr( "Destination file:" ) );
59     destLayout->addWidget( destLabel, 0, 0);
60
61     fileLine = new QLineEdit;
62     fileLine->setMinimumWidth( 300 );
63     fileLine->setFocus( Qt::ActiveWindowFocusReason );
64     destLabel->setBuddy( fileLine );
65
66     QPushButton *fileSelectButton = new QPushButton( qtr( "Browse" ) );
67     destLayout->addWidget( fileLine, 0, 1 );
68     destLayout->addWidget( fileSelectButton, 0, 2);
69     BUTTONACT( fileSelectButton, fileBrowse() );
70
71     displayBox = new QCheckBox( qtr( "Display the output" ) );
72     displayBox->setToolTip( qtr( "This display the resulting media, but can "
73                                "slow things down." ) );
74     destLayout->addWidget( displayBox, 2, 0, 1, -1 );
75
76     mainLayout->addWidget( destBox, 1, 0, 1, -1  );
77
78
79     /* Profile Editor */
80     QGroupBox *settingBox = new QGroupBox( qtr( "Settings" ) );
81     QGridLayout *settingLayout = new QGridLayout( settingBox );
82
83     profile = new VLCProfileSelector( this );
84     settingLayout->addWidget( profile, 0, 0, 1, -1 );
85
86     deinterBox = new QCheckBox( qtr( "Deinterlace" ) );
87     settingLayout->addWidget( deinterBox, 1, 0 );
88
89     dumpBox = new QCheckBox( qtr( "Dump raw input" ) );
90     settingLayout->addWidget( dumpBox, 1, 1 );
91
92     mainLayout->addWidget( settingBox, 3, 0, 1, -1  );
93
94     /* Buttons */
95     QPushButton *okButton = new QPushButton( qtr( "&Start" ) );
96     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
97     QDialogButtonBox *buttonBox = new QDialogButtonBox;
98
99     okButton->setDefault( true );
100     buttonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
101     buttonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
102
103     mainLayout->addWidget( buttonBox, 5, 3 );
104
105     BUTTONACT(okButton,close());
106     BUTTONACT(cancelButton,cancel());
107
108     CONNECT(dumpBox,toggled(bool),this,dumpChecked(bool));
109     CONNECT(profile, optionsChanged(), this, setDestinationFileExtension());
110     CONNECT(fileLine, editingFinished(), this, setDestinationFileExtension());
111 }
112
113 void ConvertDialog::fileBrowse()
114 {
115     QString fileExtension = ( ! profile->isEnabled() ) ? ".*" : "." + profile->getMux();
116
117     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
118         "",
119         QString( qtr( "Containers (*" ) + fileExtension + ")" ) );
120     fileLine->setText( toNativeSeparators( fileName ) );
121     setDestinationFileExtension();
122 }
123
124 void ConvertDialog::cancel()
125 {
126     reject();
127 }
128
129 void ConvertDialog::close()
130 {
131     hide();
132
133     if( dumpBox->isChecked() )
134     {
135         mrl = "demux=dump :demuxdump-file=" + fileLine->text();
136     }
137     else
138     {
139         mrl = "sout=#" + profile->getTranscode();
140         if( deinterBox->isChecked() )
141         {
142             mrl.remove( '}' );
143             mrl += ",deinterlace}";
144         }
145         mrl += ":";
146         if( displayBox->isChecked() )
147             mrl += "duplicate{dst=display,dst=";
148         mrl += "std{access=file{no-overwrite},mux=" + profile->getMux()
149              + ",dst='" + fileLine->text().replace( QChar('\''), "\\\'" )
150              + "'}";
151         if( displayBox->isChecked() )
152             mrl += "}";
153     }
154
155     msg_Dbg( p_intf, "Transcode MRL: %s", qtu( mrl ) );
156     accept();
157 }
158
159 void ConvertDialog::dumpChecked( bool checked )
160 {
161     deinterBox->setEnabled( !checked );
162     displayBox->setEnabled( !checked );
163     profile->setEnabled( !checked );
164 }
165
166 void ConvertDialog::setDestinationFileExtension()
167 {
168     if( !fileLine->text().isEmpty() && profile->isEnabled() )
169     {
170         QString newFileExtension = "." + profile->getMux();
171         QString newFileName;
172         int index = fileLine->text().lastIndexOf( "." );
173         if( index != -1 ) {
174             newFileName = fileLine->text().left( index ).append( newFileExtension );
175         } else {
176             newFileName = fileLine->text().append( newFileExtension );
177         }
178         fileLine->setText( toNativeSeparators( newFileName ) );
179     }
180 }