File indexing completed on 2024-05-05 04:51:39
0001 /* 0002 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "k3baudioburndialog.h" 0007 #include "k3baudioview.h" 0008 #include "k3baudiotrack.h" 0009 #include "k3baudiocdtracksource.h" 0010 #include "k3bcore.h" 0011 #include "k3baudiodoc.h" 0012 #include "k3bdevice.h" 0013 #include "k3bwriterselectionwidget.h" 0014 #include "k3btempdirselectionwidget.h" 0015 #include "k3baudiocdtextwidget.h" 0016 #include "k3bglobals.h" 0017 #include "k3bstdguiitems.h" 0018 #include "k3bwritingmodewidget.h" 0019 #include "k3bexternalbinmanager.h" 0020 0021 #include <KLocalizedString> 0022 #include <KConfig> 0023 #include <KMessageBox> 0024 0025 #include <QPoint> 0026 #include <QStringList> 0027 #include <QVariant> 0028 #include <QShowEvent> 0029 #include <QCheckBox> 0030 #include <QComboBox> 0031 #include <QGridLayout> 0032 #include <QGroupBox> 0033 #include <QHBoxLayout> 0034 #include <QLabel> 0035 #include <QLayout> 0036 #include <QLineEdit> 0037 #include <QPushButton> 0038 #include <QSpinBox> 0039 #include <QTabWidget> 0040 #include <QToolButton> 0041 #include <QToolTip> 0042 0043 0044 K3b::AudioBurnDialog::AudioBurnDialog(K3b::AudioDoc* _doc, QWidget *parent ) 0045 : K3b::ProjectBurnDialog( _doc, parent ), 0046 m_doc(_doc) 0047 { 0048 prepareGui(); 0049 0050 setTitle( i18n("Audio Project"), 0051 i18np("1 track (%2 minutes)", "%1 tracks (%2 minutes)", 0052 m_doc->numOfTracks(),m_doc->length().toString()) ); 0053 0054 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); 0055 m_optionGroupLayout->addItem( spacer ); 0056 0057 // create cd-text page 0058 m_cdtextWidget = new K3b::AudioCdTextWidget( this ); 0059 addPage( m_cdtextWidget, i18n("CD-Text") ); 0060 0061 // create advanced tab 0062 // ---------------------------------------------------------- 0063 QWidget* advancedTab = new QWidget( this ); 0064 QGridLayout* advancedTabGrid = new QGridLayout( advancedTab ); 0065 0066 QGroupBox* advancedSettingsGroup = new QGroupBox( i18n("Settings"), advancedTab ); 0067 m_checkNormalize = K3b::StdGuiItems::normalizeCheckBox( advancedSettingsGroup ); 0068 QVBoxLayout* advancedSettingsGroupLayout = new QVBoxLayout( advancedSettingsGroup ); 0069 advancedSettingsGroupLayout->addWidget( m_checkNormalize ); 0070 0071 QGroupBox* advancedGimmickGroup = new QGroupBox( i18n("Gimmicks"), advancedTab ); 0072 m_checkHideFirstTrack = new QCheckBox( i18n( "Hide first track" ), advancedGimmickGroup ); 0073 QVBoxLayout* advancedGimmickGroupLayout = new QVBoxLayout( advancedGimmickGroup ); 0074 advancedGimmickGroupLayout->addWidget( m_checkHideFirstTrack ); 0075 0076 m_audioRippingGroup = new QGroupBox( i18n("Audio Ripping"), advancedTab ); 0077 m_comboParanoiaMode = K3b::StdGuiItems::paranoiaModeComboBox( m_audioRippingGroup ); 0078 QHBoxLayout* paranoiaModeLayout = new QHBoxLayout; 0079 paranoiaModeLayout->addWidget( new QLabel( i18n("Paranoia mode:"), m_audioRippingGroup ), 1 ); 0080 paranoiaModeLayout->addWidget( m_comboParanoiaMode ); 0081 m_spinAudioRippingReadRetries = new QSpinBox( m_audioRippingGroup ); 0082 m_spinAudioRippingReadRetries->setRange( 1, 128 ); 0083 m_checkAudioRippingIgnoreReadErrors = new QCheckBox( i18n("Ignore read errors"), m_audioRippingGroup ); 0084 QHBoxLayout* readRetriesLayout = new QHBoxLayout; 0085 readRetriesLayout->addWidget( new QLabel( i18n("Read retries:" ), m_audioRippingGroup ), 1 ); 0086 readRetriesLayout->addWidget( m_spinAudioRippingReadRetries ); 0087 QVBoxLayout* audioRippingGroupLayout = new QVBoxLayout( m_audioRippingGroup ); 0088 audioRippingGroupLayout->addLayout( paranoiaModeLayout ); 0089 audioRippingGroupLayout->addLayout( readRetriesLayout ); 0090 audioRippingGroupLayout->addWidget( m_checkAudioRippingIgnoreReadErrors ); 0091 0092 advancedTabGrid->addWidget( advancedSettingsGroup, 0, 0 ); 0093 advancedTabGrid->addWidget( advancedGimmickGroup, 1, 0 ); 0094 advancedTabGrid->addWidget( m_audioRippingGroup, 2, 0 ); 0095 advancedTabGrid->setRowStretch( 3, 1 ); 0096 0097 addPage( advancedTab, i18n("Advanced") ); 0098 0099 connect( m_checkNormalize, SIGNAL(toggled(bool)), this, SLOT(slotNormalizeToggled(bool)) ); 0100 connect( m_checkCacheImage, SIGNAL(toggled(bool)), this, SLOT(slotCacheImageToggled(bool)) ); 0101 0102 // ToolTips 0103 // ------------------------------------------------------------------------- 0104 m_checkHideFirstTrack->setToolTip( i18n("Hide the first track in the first pregap") ); 0105 0106 // What's This info 0107 // ------------------------------------------------------------------------- 0108 m_checkHideFirstTrack->setWhatsThis( 0109 i18n("<p>If this option is checked K3b will <em>hide</em> the first track." 0110 "<p>The audio CD standard uses pregaps before every track on the CD. " 0111 "By default these last for 2 seconds and are silent. In DAO mode it " 0112 "is possible to have longer pregaps that contain some audio. In this case " 0113 "the first pregap will contain the complete first track." 0114 "<p>You will need to seek back from the beginning of the CD to listen to " 0115 "the first track. Try it, it is quite amusing." 0116 "<p><b>This feature is only available in DAO mode when writing with cdrdao.") ); 0117 0118 // TODO: AudioDoc doesn't have IsoOptions, so it could NOT create iso image like DataDoc. 0119 m_tabWidget->setTabText(1, i18n("Rip Audio")); 0120 m_checkCacheImage->setText(i18n("Rip Audio")); 0121 m_checkOnlyCreateImage->setText(i18n("Only Rip Audio")); 0122 m_imageTipText = i18n("Use the 'Rip Audio' tab to optionally adjust the path of the audio."); 0123 m_tempDirSelectionWidget->setImageFileLabel(i18n("Wri&te Rip Audio files to:")); 0124 } 0125 0126 K3b::AudioBurnDialog::~AudioBurnDialog(){ 0127 } 0128 0129 0130 void K3b::AudioBurnDialog::slotStartClicked() 0131 { 0132 K3b::ProjectBurnDialog::slotStartClicked(); 0133 } 0134 0135 0136 void K3b::AudioBurnDialog::saveSettingsToProject() 0137 { 0138 K3b::ProjectBurnDialog::saveSettingsToProject(); 0139 0140 m_doc->setTempDir( m_tempDirSelectionWidget->tempPath() ); 0141 m_doc->setHideFirstTrack( m_checkHideFirstTrack->isChecked() ); 0142 m_doc->setNormalize( m_checkNormalize->isChecked() ); 0143 0144 // -- save Cd-Text ------------------------------------------------ 0145 m_cdtextWidget->save( m_doc ); 0146 0147 // audio ripping 0148 m_doc->setAudioRippingParanoiaMode( m_comboParanoiaMode->currentText().toInt() ); 0149 m_doc->setAudioRippingRetries( m_spinAudioRippingReadRetries->value() ); 0150 m_doc->setAudioRippingIgnoreReadErrors( m_checkAudioRippingIgnoreReadErrors->isChecked() ); 0151 0152 doc()->setTempDir( m_tempDirSelectionWidget->tempPath() ); 0153 } 0154 0155 0156 void K3b::AudioBurnDialog::readSettingsFromProject() 0157 { 0158 K3b::ProjectBurnDialog::readSettingsFromProject(); 0159 0160 m_checkHideFirstTrack->setChecked( m_doc->hideFirstTrack() ); 0161 m_checkNormalize->setChecked( m_doc->normalize() ); 0162 0163 // read CD-Text ------------------------------------------------------------ 0164 m_cdtextWidget->load( m_doc ); 0165 0166 // audio ripping 0167 m_comboParanoiaMode->setCurrentIndex( m_doc->audioRippingParanoiaMode() ); 0168 m_checkAudioRippingIgnoreReadErrors->setChecked( m_doc->audioRippingIgnoreReadErrors() ); 0169 m_spinAudioRippingReadRetries->setValue( m_doc->audioRippingRetries() ); 0170 0171 if( !doc()->tempDir().isEmpty() ) 0172 m_tempDirSelectionWidget->setTempPath( doc()->tempDir() ); 0173 0174 toggleAll(); 0175 } 0176 0177 0178 void K3b::AudioBurnDialog::loadSettings( const KConfigGroup& c ) 0179 { 0180 K3b::ProjectBurnDialog::loadSettings( c ); 0181 0182 m_cdtextWidget->setChecked( c.readEntry( "cd_text", true ) ); 0183 m_checkHideFirstTrack->setChecked( c.readEntry( "hide_first_track", false ) ); 0184 m_checkNormalize->setChecked( c.readEntry( "normalize", false ) ); 0185 0186 m_comboParanoiaMode->setCurrentIndex( c.readEntry( "paranoia mode", 0 ) ); 0187 m_checkAudioRippingIgnoreReadErrors->setChecked( c.readEntry( "ignore read errors", true ) ); 0188 m_spinAudioRippingReadRetries->setValue( c.readEntry( "read retries", 5 ) ); 0189 0190 toggleAll(); 0191 } 0192 0193 0194 void K3b::AudioBurnDialog::saveSettings( KConfigGroup c ) 0195 { 0196 K3b::ProjectBurnDialog::saveSettings( c ); 0197 0198 c.writeEntry( "cd_text", m_cdtextWidget->isChecked() ); 0199 c.writeEntry( "hide_first_track", m_checkHideFirstTrack->isChecked() ); 0200 c.writeEntry( "normalize", m_checkNormalize->isChecked() ); 0201 0202 c.writeEntry( "paranoia mode", m_comboParanoiaMode->currentText() ); 0203 c.writeEntry( "ignore read errors", m_checkAudioRippingIgnoreReadErrors->isChecked() ); 0204 c.writeEntry( "read retries", m_spinAudioRippingReadRetries->value() ); 0205 } 0206 0207 void K3b::AudioBurnDialog::toggleAll() 0208 { 0209 K3b::ProjectBurnDialog::toggleAll(); 0210 0211 bool cdrecordOnTheFly = false; 0212 bool cdrecordCdText = false; 0213 const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord"); 0214 if ( cdrecordBin ) { 0215 cdrecordOnTheFly = cdrecordBin->hasFeature( "audio-stdin" ); 0216 cdrecordCdText = cdrecordBin->hasFeature( "cdtext" ); 0217 } 0218 0219 // cdrdao always knows onthefly and cdtext 0220 bool onTheFly = true; 0221 bool cdText = true; 0222 if( m_writingModeWidget->writingMode() == K3b::WritingModeTao || 0223 m_writingModeWidget->writingMode() == K3b::WritingModeRaw || 0224 m_writerSelectionWidget->writingApp() == K3b::WritingAppCdrecord ) { 0225 onTheFly = cdrecordOnTheFly; 0226 cdText = cdrecordCdText; 0227 m_checkHideFirstTrack->setChecked(false); 0228 m_checkHideFirstTrack->setEnabled(false); 0229 } 0230 else { 0231 m_checkHideFirstTrack->setEnabled( !m_checkOnlyCreateImage->isChecked() ); 0232 m_cdtextWidget->setEnabled( !m_checkOnlyCreateImage->isChecked() ); 0233 } 0234 0235 m_checkCacheImage->setEnabled( !m_checkOnlyCreateImage->isChecked() && 0236 onTheFly ); 0237 if( !onTheFly ) 0238 m_checkCacheImage->setChecked( true ); 0239 m_cdtextWidget->setEnabled( !m_checkOnlyCreateImage->isChecked() && 0240 cdText && 0241 m_writingModeWidget->writingMode() != K3b::WritingModeTao ); 0242 if( !cdText || m_writingModeWidget->writingMode() == K3b::WritingModeTao ) 0243 m_cdtextWidget->setChecked(false); 0244 } 0245 0246 0247 void K3b::AudioBurnDialog::showEvent( QShowEvent* e ) 0248 { 0249 // we only show the audio ripping options when there are audio cd track sources 0250 bool showRipOptions = false; 0251 if( m_doc->firstTrack() ) { 0252 K3b::AudioTrack* track = m_doc->firstTrack(); 0253 K3b::AudioDataSource* source = track->firstSource(); 0254 0255 while( source ) { 0256 0257 if( dynamic_cast<K3b::AudioCdTrackSource*>(source) ) { 0258 showRipOptions = true; 0259 break; 0260 } 0261 0262 // next source 0263 source = source->next(); 0264 if( !source ) { 0265 track = track->next(); 0266 if( track ) 0267 source = track->firstSource(); 0268 } 0269 } 0270 } 0271 0272 m_audioRippingGroup->setVisible( showRipOptions ); 0273 0274 K3b::ProjectBurnDialog::showEvent(e); 0275 } 0276 0277 0278 void K3b::AudioBurnDialog::slotNormalizeToggled( bool on ) 0279 { 0280 if( on ) { 0281 // we are not able to normalize in on-the-fly mode 0282 if( !k3bcore->externalBinManager()->foundBin( "normalize" ) ) { 0283 KMessageBox::error( this, i18n("<p><b>External program <em>normalize</em> is not installed.</b>" 0284 "<p>K3b uses <em>normalize</em> (http://normalize.nongnu.org/) " 0285 "to normalize audio tracks. In order to " 0286 "use this functionality, please install it first.") ); 0287 m_checkNormalize->setChecked( false ); 0288 } 0289 else if( !m_checkCacheImage->isChecked() && !m_checkOnlyCreateImage->isChecked() ) { 0290 if( KMessageBox::warningTwoActions( this, i18n("<p>K3b is not able to normalize audio tracks when burning on-the-fly. " 0291 "The external program used for this task only supports normalizing a set " 0292 "of audio files."), 0293 QString(), 0294 KGuiItem( i18n("Disable normalization") ), 0295 KGuiItem( i18n("Disable on-the-fly burning") ), 0296 "audioProjectNormalizeOrOnTheFly" ) == KMessageBox::PrimaryAction ) 0297 m_checkNormalize->setChecked( false ); 0298 else 0299 m_checkCacheImage->setChecked( true ); 0300 } 0301 } 0302 } 0303 0304 0305 void K3b::AudioBurnDialog::slotCacheImageToggled( bool on ) 0306 { 0307 if( !on ) { 0308 if( m_checkNormalize->isChecked() ) { 0309 if( KMessageBox::warningTwoActions( this, i18n("<p>K3b is not able to normalize audio tracks when burning on-the-fly. " 0310 "The external program used for this task only supports normalizing a set " 0311 "of audio files."), 0312 QString(), 0313 KGuiItem( i18n("Disable normalization") ), 0314 KGuiItem( i18n("Disable on-the-fly burning") ), 0315 "audioProjectNormalizeOrOnTheFly" ) == KMessageBox::PrimaryAction ) 0316 m_checkNormalize->setChecked( false ); 0317 else 0318 m_checkCacheImage->setChecked( true ); 0319 } 0320 } 0321 } 0322 0323 #include "moc_k3baudioburndialog.cpp"