1 /*****************************************************************************
2 * profile_selector.cpp : A small profile selector and editor
3 ****************************************************************************
4 * Copyright (C) 2009 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb@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 *****************************************************************************/
25 #include "components/sout/profile_selector.hpp"
26 #include "components/sout/profiles.hpp"
27 #include "dialogs/sout.hpp"
29 #include <QHBoxLayout>
30 #include <QToolButton>
33 #include <QMessageBox>
35 VLCProfileSelector::VLCProfileSelector( QWidget *_parent ): QWidget( _parent )
37 QHBoxLayout *layout = new QHBoxLayout( this );
39 QLabel *prLabel = new QLabel( qtr( "Profile"), this );
40 layout->addWidget( prLabel );
42 profileBox = new QComboBox( this );
43 layout->addWidget( profileBox );
45 QToolButton *editButton = new QToolButton( this );
46 editButton->setIcon( QIcon( ":/preferences" ) );
47 editButton->setToolTip( qtr( "Edit selected profile" ) );
48 layout->addWidget( editButton );
50 QToolButton *deleteButton = new QToolButton( this );
51 deleteButton->setIcon( QIcon( ":/clear" ) );
52 deleteButton->setToolTip( qtr( "Delete selected profile" ) );
53 layout->addWidget( deleteButton );
55 QToolButton *newButton = new QToolButton( this );
56 newButton->setIcon( QIcon( ":/new" ) );
57 newButton->setToolTip( qtr( "Create a new profile" ) );
58 layout->addWidget(newButton);
60 BUTTONACT( newButton, newProfile() );
61 BUTTONACT( editButton, editProfile() );
62 BUTTONACT( deleteButton, deleteProfile() );
65 CONNECT( profileBox, activated( int ),
66 this, updateOptions( int ) );
71 inline void VLCProfileSelector::fillProfilesCombo()
77 QSettings::NativeFormat,
79 QSettings::UserScope, "vlc", "vlc-qt-interface" );
81 int i_size = settings.beginReadArray( "codecs-profiles" );
83 for( int i = 0; i < i_size; i++ )
85 settings.setArrayIndex( i );
86 if( settings.value( "Profile-Name" ).toString().isEmpty() ) continue;
87 profileBox->addItem( settings.value( "Profile-Name" ).toString(),
88 settings.value( "Profile-Value" ) );
92 for( int i = 0; i < NB_PROFILE; i++ )
94 profileBox->addItem( video_profile_name_list[i],
95 video_profile_value_list[i] );
101 void VLCProfileSelector::newProfile()
103 editProfile( "", "" );
106 void VLCProfileSelector::editProfile()
108 editProfile( profileBox->currentText(),
109 profileBox->itemData( profileBox->currentIndex() ).toString() );
112 void VLCProfileSelector::editProfile( QString qs, QString value )
114 VLCProfileEditor *editor = new VLCProfileEditor( qs, value, this );
116 if( QDialog::Accepted == editor->exec() )
119 profileBox->addItem( editor->name, QVariant( editor->transcodeValue() ) );
122 int i_profile = profileBox->findText( qs );
123 profileBox->setItemText( i_profile, editor->name );
124 profileBox->setItemData( i_profile, QVariant( editor->transcodeValue() ) );
130 emit optionsChanged();
133 void VLCProfileSelector::deleteProfile()
135 profileBox->removeItem( profileBox->currentIndex() );
138 void VLCProfileSelector::saveProfiles()
142 QSettings::IniFormat,
144 QSettings::NativeFormat,
146 QSettings::UserScope, "vlc", "vlc-qt-interface" );
148 settings.beginWriteArray( "codecs-profiles" );
149 for( int i = 0; i < profileBox->count(); i++ )
151 settings.setArrayIndex( i );
152 settings.setValue( "Profile-Name", profileBox->itemText( i ) );
153 settings.setValue( "Profile-Value", profileBox->itemData( i ).toString() );
158 void VLCProfileSelector::updateOptions( int i )
160 QStringList options = profileBox->itemData( i ).toString().split( ";" );
161 if( options.size() < 16 )
167 if( options[1].toInt() || options[2].toInt() )
169 smrl.begin( "transcode" );
171 if( options[1].toInt() )
173 smrl.option( "vcodec", options[4] );
174 smrl.option( "vb", options[5].toInt() );
175 smrl.option( "scale", options[6] );
176 smrl.option( "fps", options[7] );
177 smrl.option( "width", options[8].toInt() );
178 smrl.option( "height", options[9].toInt() );
181 if( options[2].toInt() )
183 smrl.option( "acodec", options[10] );
184 smrl.option( "ab", options[11].toInt() );
185 smrl.option( "channels", options[12].toInt() );
186 smrl.option( "samplerate", options[13].toInt() );
189 if( options[3].toInt() )
191 smrl.option( "scodec", options[14] );
192 if( options[15].toInt() )
193 smrl.option( "soverlay" );
198 transcode = smrl.getMrl();
202 emit optionsChanged();
209 VLCProfileEditor::VLCProfileEditor( QString qs_name, QString value,
211 : QVLCDialog( _parent, NULL )
214 if( !qs_name.isEmpty() )
216 ui.profileLine->setText( qs_name );
217 ui.profileLine->setReadOnly( true );
220 CONNECT( ui.transcodeVideo, toggled( bool ),
221 this, setVTranscodeOptions( bool ) );
222 CONNECT( ui.transcodeAudio, toggled( bool ),
223 this, setATranscodeOptions( bool ) );
224 CONNECT( ui.transcodeSubs, toggled( bool ),
225 this, setSTranscodeOptions( bool ) );
226 setVTranscodeOptions( false );
227 setATranscodeOptions( false );
228 setSTranscodeOptions( false );
230 QPushButton *saveButton = new QPushButton( qtr( "Save" ) );
231 ui.buttonBox->addButton( saveButton, QDialogButtonBox::AcceptRole );
232 BUTTONACT( saveButton, close() );
233 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
234 ui.buttonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
235 BUTTONACT( cancelButton, reject() );
237 fillProfile( value );
240 inline void VLCProfileEditor::registerCodecs()
243 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
244 ADD_VCODEC( "MPEG-1", "mp1v" )
245 ADD_VCODEC( "MPEG-2", "mp2v" )
246 ADD_VCODEC( "MPEG-4", "mp4v" )
247 ADD_VCODEC( "DIVX 1" , "DIV1" )
248 ADD_VCODEC( "DIVX 2" , "DIV2" )
249 ADD_VCODEC( "DIVX 3" , "DIV3" )
250 ADD_VCODEC( "H-263", "H263" )
251 ADD_VCODEC( "H-264", "h264" )
252 ADD_VCODEC( "WMV1", "WMV1" )
253 ADD_VCODEC( "WMV2" , "WMV2" )
254 ADD_VCODEC( "M-JPEG", "MJPG" )
255 ADD_VCODEC( "Theora", "theo" )
256 ADD_VCODEC( "Dirac", "drac" )
258 #define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
259 ADD_ACODEC( "MPEG Audio", "mpga" )
260 ADD_ACODEC( "MP3", "mp3" )
261 ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
262 ADD_ACODEC( "A52/AC-3", "a52" )
263 ADD_ACODEC( "Vorbis", "vorb" )
264 ADD_ACODEC( "Flac", "flac" )
265 ADD_ACODEC( "Speex", "spx" )
266 ADD_ACODEC( "WAV", "s16l" )
267 ADD_ACODEC( "WMA", "wma" )
269 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
271 ADD_SCALING( "0.25" )
273 ADD_SCALING( "0.75" )
274 ADD_SCALING( "1.25" )
276 ADD_SCALING( "1.75" )
279 #define ADD_SAMPLERATE( sample ) ui.aSampleBox->addItem( sample );
280 ADD_SAMPLERATE( "11250" )
281 ADD_SAMPLERATE( "22500" )
282 ADD_SAMPLERATE( "44100" )
283 ADD_SAMPLERATE( "48000" )
285 #define ADD_SCODEC( name, fourcc ) ui.subsCodecBox->addItem( name, QVariant( fourcc ) );
286 ADD_SCODEC( "DVB subtitle", "dvbs" )
287 ADD_SCODEC( "T.140", "t140" )
290 void VLCProfileEditor::fillProfile( QString qs )
292 QStringList options = qs.split( ";" );
293 if( options.size() < 16 )
296 ui.transcodeVideo->setChecked( options[1].toInt() );
297 ui.transcodeAudio->setChecked( options[2].toInt() );
298 ui.transcodeSubs->setChecked( options[3].toInt() );
300 ui.vCodecBox->setCurrentIndex( ui.vCodecBox->findData( options[4] ) );
301 ui.vBitrateSpin->setValue( options[5].toInt() );
302 ui.vScaleBox->setEditText( options[6] );
303 ui.vFrameBox->setValue( options[7].toDouble() );
304 ui.widthBox->setValue( options[8].toInt() );
305 ui.heightBox->setValue( options[9].toInt() );
307 ui.aCodecBox->setCurrentIndex( ui.aCodecBox->findData( options[10] ) );
308 ui.aBitrateSpin->setValue( options[11].toInt() );
309 ui.aChannelsSpin->setValue( options[12].toInt() );
310 ui.aSampleBox->setCurrentIndex( ui.aSampleBox->findText( options[13] ) );
312 ui.subsCodecBox->setCurrentIndex( ui.subsCodecBox->findData( options[14] ) );
313 ui.subsOverlay->setChecked( options[15].toInt() );
316 void VLCProfileEditor::setVTranscodeOptions( bool b_trans )
318 ui.vCodecLabel->setEnabled( b_trans );
319 ui.vCodecBox->setEnabled( b_trans );
320 ui.vBitrateLabel->setEnabled( b_trans );
321 ui.vBitrateSpin->setEnabled( b_trans );
322 ui.vScaleLabel->setEnabled( b_trans );
323 ui.vScaleBox->setEnabled( b_trans );
324 ui.heightBox->setEnabled( b_trans );
325 ui.heightLabel->setEnabled( b_trans );
326 ui.widthBox->setEnabled( b_trans );
327 ui.widthLabel->setEnabled( b_trans );
328 ui.vFrameBox->setEnabled( b_trans );
329 ui.vFrameLabel->setEnabled( b_trans );
332 void VLCProfileEditor::setATranscodeOptions( bool b_trans )
334 ui.aCodecLabel->setEnabled( b_trans );
335 ui.aCodecBox->setEnabled( b_trans );
336 ui.aBitrateLabel->setEnabled( b_trans );
337 ui.aBitrateSpin->setEnabled( b_trans );
338 ui.aChannelsLabel->setEnabled( b_trans );
339 ui.aChannelsSpin->setEnabled( b_trans );
340 ui.aSampleLabel->setEnabled( b_trans );
341 ui.aSampleBox->setEnabled( b_trans );
344 void VLCProfileEditor::setSTranscodeOptions( bool b_trans )
346 ui.subsCodecBox->setEnabled( b_trans );
347 ui.subsOverlay->setEnabled( b_trans );
350 void VLCProfileEditor::close()
352 if( ui.profileLine->text().isEmpty() )
354 QMessageBox::warning( this, qtr(" Profile Name Missing" ),
355 qtr( "You must set a name for the profile." ) );
356 ui.profileLine->setFocus();
359 name = ui.profileLine->text();
364 QString VLCProfileEditor::transcodeValue()
366 #define SMUX( x, txt ) if( ui.x->isChecked() ) muxValue = txt; else
369 SMUX( MPEG1Mux, "mpeg1" )
370 SMUX( OggMux, "ogg" )
371 SMUX( ASFMux, "asf" )
372 SMUX( MOVMux, "mp4" )
373 SMUX( WAVMux, "wav" )
374 SMUX( RAWMux, "raw" )
375 SMUX( FLVMux, "flv" )
376 SMUX( MKVMux, "mkv" )
377 SMUX( AVIMux, "avi" )
378 SMUX( MJPEGMux, "mjpg" );
380 #define currentData( box ) box->itemData( box->currentIndex() )
381 QStringList transcodeMRL;
385 << QString::number( ui.transcodeVideo->isChecked() )
386 << QString::number( ui.transcodeAudio->isChecked() )
387 << QString::number( ui.transcodeSubs->isChecked() )
389 << currentData( ui.vCodecBox ).toString()
390 << QString::number( ui.vBitrateSpin->value() )
391 << ui.vScaleBox->currentText()
392 << QString::number( ui.vFrameBox->value() )
393 << QString::number( ui.widthBox->value() )
394 << QString::number( ui.heightBox->value() )
396 << currentData( ui.aCodecBox ).toString()
397 << QString::number( ui.aBitrateSpin->value() )
398 << QString::number( ui.aChannelsSpin->value() )
399 << ui.aSampleBox->currentText()
401 << currentData( ui.subsCodecBox ).toString()
402 << QString::number( ui.subsOverlay->isChecked() );
404 return transcodeMRL.join( ";" );