summaryrefslogtreecommitdiffstats
path: root/src/projects/k3bmixedburndialog.cpp
blob: 7d74a2f1bd511cc3dbfb50fc1366426afc911681 (plain)
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
 *
 * $Id: k3bmixedburndialog.cpp 627521 2007-01-26 22:39:53Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.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.
 * See the file "COPYING" for the exact licensing terms.
 */

#include "k3bmixedburndialog.h"
#include "k3bmixeddoc.h"
#include "k3bmixedview.h"

#include <k3bdataimagesettingswidget.h>
#include <k3bdatadoc.h>
#include <k3baudiodoc.h>
#include <k3bdevice.h>
#include <k3bwriterselectionwidget.h>
#include <k3btempdirselectionwidget.h>
#include <k3bisooptions.h>
#include <k3bglobals.h>
#include <k3baudiocdtextwidget.h>
#include <k3bdatamodewidget.h>
#include <k3bmsf.h>
#include <k3bstdguiitems.h>
#include <k3bwritingmodewidget.h>
#include <k3bexternalbinmanager.h>
#include <k3bversion.h>
#include <k3bcore.h>
#include <k3baudiotrackplayer.h>
#include <k3bintmapcombobox.h>

#include <tqtabwidget.h>
#include <tqcheckbox.h>
#include <tqframe.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqtoolbutton.h>
#include <tqlayout.h>
#include <tqvariant.h>
#include <tqtooltip.h>
#include <tqwhatsthis.h>
#include <tqvbox.h>
#include <tqbuttongroup.h>
#include <tqradiobutton.h>

#include <klocale.h>
#include <kconfig.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kmessagebox.h>


K3bMixedBurnDialog::K3bMixedBurnDialog( K3bMixedDoc* doc, TQWidget *parent, const char *name, bool modal )
  : K3bProjectBurnDialog( doc, parent, name, modal ), m_doc(doc)
{
  prepareGui();

  setTitle( i18n("Mixed Project"), i18n("1 track (%1 minutes)",
					"%n tracks (%1 minutes)",
					m_doc->numOfTracks()).arg(m_doc->length().toString()) );

  m_checkOnlyCreateImage->hide();

  // create cd-text page
  m_cdtextWidget = new K3bAudioCdTextWidget( this );
  addPage( m_cdtextWidget, i18n("CD-Text") );

  // create image settings tab
  m_imageSettingsWidget = new K3bDataImageSettingsWidget( this );
  addPage( m_imageSettingsWidget, i18n("Filesystem") );

  setupSettingsPage();

  TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
  m_optionGroupLayout->addItem( spacer );

  connect( m_checkNormalize, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotNormalizeToggled(bool)) );
  connect( m_checkCacheImage, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotCacheImageToggled(bool)) );
  connect( m_writerSelectionWidget, TQT_SIGNAL(writingAppChanged(int)), this, TQT_SLOT(slotToggleAll()) );
  connect( m_writingModeWidget, TQT_SIGNAL(writingModeChanged(int)), this, TQT_SLOT(slotToggleAll()) );
}


void K3bMixedBurnDialog::setupSettingsPage()
{
  TQWidget* w = new TQWidget( this );

  TQGroupBox* groupDataMode = new TQGroupBox( 1, Qt::Vertical, i18n("Datatrack Mode"), w );
  m_dataModeWidget = new K3bDataModeWidget( groupDataMode );

  TQGroupBox* groupNormalize = new TQGroupBox( 1, Qt::Vertical, i18n("Misc"), w );
  m_checkNormalize = K3bStdGuiItems::normalizeCheckBox( groupNormalize );

  TQGroupBox* groupMixedType = new TQGroupBox( 1, Qt::Vertical, i18n("Mixed Mode Type"), w );
  m_comboMixedModeType = new K3bIntMapComboBox( groupMixedType );

  m_comboMixedModeType->insertItem( K3bMixedDoc::DATA_SECOND_SESSION,
				    i18n("Data in second session (CD-Extra)"),
				    i18n("<em>Blue book CD</em>"
					 "<br>K3b will create a multisession CD with "
					 "2 sessions. The first session will contain all "
					 "audio tracks and the second session will contain "
					 "a mode 2 form 1 data track."
					 "<br>This mode is based on the <em>Blue book</em> "
					 "standard (also known as <em>Extended Audio CD</em>, "
					 "<em>CD-Extra</em>, or <em>CD Plus</em>) "
					 "and has the advantage that a hifi audio "
					 "CD player will only recognize the first session "
					 "and ignore the second session with the data track."
					 "<br>If the CD is intended to be used in a hifi audio CD player "
					 "this is the recommended mode."
					 "<br>Some older CD-ROMs may have problems reading "
					 "a blue book CD since it is a multisession CD.") );
  m_comboMixedModeType->insertItem( K3bMixedDoc::DATA_FIRST_TRACK,
				    i18n("Data in first track"),
				    i18n("K3b will write the data track before all "
					 "audio tracks.") );
  m_comboMixedModeType->insertItem( K3bMixedDoc::DATA_LAST_TRACK,
				    i18n("Data in last track"),
				    i18n("K3b will write the data track after all "
					 "audio tracks.") );
  m_comboMixedModeType->addGlobalWhatsThisText( TQString(),
						i18n("<b>Caution:</b> The last two modes should only be used for CDs that are unlikely to "
						     "be played on a hifi audio CD player."
						     "<br>It could lead to problems with some older "
						     "hifi audio CD players that try to play the data track.") );
				    
  TQGridLayout* grid = new TQGridLayout( w );
  grid->setMargin( marginHint() );
  grid->setSpacing( spacingHint() );
  grid->addWidget( groupMixedType, 0, 0 );
  grid->addWidget( groupDataMode, 1, 0 );
  grid->addWidget( groupNormalize, 2, 0 );
  grid->setRowStretch( 3, 1 );

  addPage( w, i18n("Misc") );
}


void K3bMixedBurnDialog::slotStartClicked()
{
  // FIXME: this should not be done via the doc. So remove all gui stuff from the doc
  static_cast<K3bMixedView*>(m_doc->view())->player()->stop();
  K3bProjectBurnDialog::slotStartClicked();
}


void K3bMixedBurnDialog::saveSettings()
{
  K3bProjectBurnDialog::saveSettings();

  m_doc->setMixedType( (K3bMixedDoc::MixedType)m_comboMixedModeType->selectedValue() );

  m_cdtextWidget->save( m_doc->audioDoc() );

  m_doc->audioDoc()->setNormalize( m_checkNormalize->isChecked() );

  // save iso image settings
  K3bIsoOptions o = m_doc->dataDoc()->isoOptions();
  m_imageSettingsWidget->save( o );
  m_doc->dataDoc()->setIsoOptions( o );

  m_doc->dataDoc()->setDataMode( m_dataModeWidget->dataMode() );

  // save image file path
  m_doc->setTempDir( m_tempDirSelectionWidget->tempPath() );
}


void K3bMixedBurnDialog::readSettings()
{
  K3bProjectBurnDialog::readSettings();

  m_checkNormalize->setChecked( m_doc->audioDoc()->normalize() );

  if( !m_doc->tempDir().isEmpty() )
    m_tempDirSelectionWidget->setTempPath( m_doc->tempDir() );

  m_comboMixedModeType->setSelectedValue( m_doc->mixedType() );

  m_cdtextWidget->load( m_doc->audioDoc() );

  m_imageSettingsWidget->load( m_doc->dataDoc()->isoOptions() );

  m_dataModeWidget->setDataMode( m_doc->dataDoc()->dataMode() );

  toggleAll();
}


void K3bMixedBurnDialog::loadK3bDefaults()
{
  K3bProjectBurnDialog::loadK3bDefaults();

  m_cdtextWidget->setChecked( false );
  m_checkNormalize->setChecked( false );

  m_comboMixedModeType->setSelectedValue( K3bMixedDoc::DATA_SECOND_SESSION );

  m_dataModeWidget->setDataMode( K3b::DATA_MODE_AUTO );

  m_imageSettingsWidget->load( K3bIsoOptions::defaults() );

  toggleAll();
}


void K3bMixedBurnDialog::loadUserDefaults( TDEConfigBase* c )
{
  K3bProjectBurnDialog::loadUserDefaults( c );

  m_cdtextWidget->setChecked( c->readBoolEntry( "cd_text", false ) );
  m_checkNormalize->setChecked( c->readBoolEntry( "normalize", false ) );

  // load mixed type
  if( c->readEntry( "mixed_type" ) == "last_track" )
    m_comboMixedModeType->setSelectedValue( K3bMixedDoc::DATA_LAST_TRACK );
  else if( c->readEntry( "mixed_type" ) == "first_track" )
    m_comboMixedModeType->setSelectedValue( K3bMixedDoc::DATA_FIRST_TRACK );
  else
    m_comboMixedModeType->setSelectedValue( K3bMixedDoc::DATA_SECOND_SESSION );

  m_dataModeWidget->loadConfig(c);

  K3bIsoOptions o = K3bIsoOptions::load( c );
  m_imageSettingsWidget->load( o );

  toggleAll();
}


void K3bMixedBurnDialog::saveUserDefaults( TDEConfigBase* c )
{
  K3bProjectBurnDialog::saveUserDefaults(c);

  c->writeEntry( "cd_text", m_cdtextWidget->isChecked() );
  c->writeEntry( "normalize", m_checkNormalize->isChecked() );

  // save mixed type
  switch( m_comboMixedModeType->selectedValue() ) {
  case K3bMixedDoc::DATA_LAST_TRACK:
   c->writeEntry( "mixed_type", "last_track" );
   break;
  case K3bMixedDoc::DATA_FIRST_TRACK:
    c->writeEntry( "mixed_type", "first_track" );
    break;
  default:
   c->writeEntry( "mixed_type", "second_session" );
  }

  m_dataModeWidget->saveConfig(c);

  K3bIsoOptions o;
  m_imageSettingsWidget->save( o );
  o.save( c );

  if( m_tempDirSelectionWidget->isEnabled() ) {
    m_tempDirSelectionWidget->saveConfig();
  }
}


void K3bMixedBurnDialog::toggleAll()
{
  K3bProjectBurnDialog::toggleAll();

  bool cdrecordOnTheFly = false;
  bool cdrecordCdText = false;
  if ( k3bcore->externalBinManager()->binObject("cdrecord") ) {
    cdrecordOnTheFly = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "audio-stdin" );
    cdrecordCdText = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "cdtext" );
  }

  // cdrdao always knows onthefly and cdtext
  bool onTheFly = true;
  bool cdText = true;
  if( m_writingModeWidget->writingMode() == K3b::TAO ||
      m_writingModeWidget->writingMode() == K3b::RAW ||
      m_writerSelectionWidget->writingApp() == K3b::CDRECORD ) {
    onTheFly = cdrecordOnTheFly;
    cdText = cdrecordCdText;
  }

  m_checkCacheImage->setEnabled( !m_checkOnlyCreateImage->isChecked() && 
				 onTheFly );
  if( !onTheFly )
    m_checkCacheImage->setChecked( true );

  m_cdtextWidget->setEnabled( !m_checkOnlyCreateImage->isChecked() &&
			      cdText && 
			      m_writingModeWidget->writingMode() != K3b::TAO );
  if( !cdText || m_writingModeWidget->writingMode() == K3b::TAO  )
    m_cdtextWidget->setChecked( false );
}


void K3bMixedBurnDialog::slotNormalizeToggled( bool on )
{
  if( on ) {
    // we are not able to normalize in on-the-fly mode
    if( !k3bcore->externalBinManager()->foundBin( "normalize" ) ) {
      KMessageBox::sorry( this, i18n("<p><b>External program <em>normalize-audio</em> is not installed.</b>"
				     "<p>K3b uses <em>normalize-audio</em> (http://www1.cs.columbia.edu/~cvaill/normalize/) "
				     "to normalize audio tracks. In order to "
				     "use this functionality, please install it first (sudo apt-get install normalize-audio.") );
      m_checkNormalize->setChecked( false );
    }
    else if( !m_checkCacheImage->isChecked() && !m_checkOnlyCreateImage->isChecked() ) {
      if( KMessageBox::warningYesNo( this, i18n("<p>K3b is not able to normalize audio tracks when burning on-the-fly. "
						"The external program used for this task only supports normalizing a set "
						"of audio files."),
				     TQString(),
				     i18n("Disable normalization"),
				     i18n("Disable on-the-fly burning"),
				     "audioProjectNormalizeOrOnTheFly" ) == KMessageBox::Yes )
	m_checkNormalize->setChecked( false );
      else
	m_checkCacheImage->setChecked( true );
    }
  }
}


void K3bMixedBurnDialog::slotCacheImageToggled( bool on )
{
  if( on ) {
    if( m_checkNormalize->isChecked() ) {
      if( KMessageBox::warningYesNo( this, i18n("<p>K3b is not able to normalize audio tracks when burning on-the-fly. "
						"The external program used for this task only supports normalizing a set "
						"of audio files."),
				     TQString(),
				     i18n("Disable normalization"),
				     i18n("Disable on-the-fly burning"),
				     "audioProjectNormalizeOrOnTheFly" ) == KMessageBox::Yes )
	m_checkNormalize->setChecked( false );
      else
	m_checkCacheImage->setChecked( true );
    }
  }
}


#include "k3bmixedburndialog.moc"