1 /*
2 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
3 SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #include "k3bwriterselectionwidget.h"
7 #include "k3bapplication.h"
8 #include "k3bmediacache.h"
9
10 #include "k3bmediaselectioncombobox.h"
11 #include "k3bdevice.h"
12 #include "k3bdevicemanager.h"
13 #include "k3bglobals.h"
14 #include "k3bcore.h"
15 #include "k3bintmapcombobox.h"
16
17 #include <KConfig>
18 #include <KConfigGroup>
19 #include <KSharedConfig>
20 #include <KLocalizedString>
21 #include <KMessageBox>
22
23 #include <QCursor>
24 #include <QApplication>
25 #include <QGridLayout>
26 #include <QGroupBox>
27 #include <QInputDialog>
28 #include <QLabel>
29 #include <QLayout>
30 #include <QToolButton>
31 #include <QToolTip>
32
33 #include <cstdlib>
34
35
36 namespace {
37 int s_autoSpeedValue = 0;
38 int s_ignoreSpeedValue = -1;
39 int s_moreSpeedValue = -2;
40 }
41
42
43 class K3b::WriterSelectionWidget::MediaSelectionComboBox : public K3b::MediaSelectionComboBox
44 {
45 public:
MediaSelectionComboBox(QWidget * parent)46 MediaSelectionComboBox( QWidget* parent )
47 : K3b::MediaSelectionComboBox( parent ),
48 m_overrideDevice( 0 ) {
49 }
50
setOverrideDevice(K3b::Device::Device * dev,const QString & s,const QString & t)51 void setOverrideDevice( K3b::Device::Device* dev, const QString& s, const QString& t ) {
52 m_overrideDevice = dev;
53 m_overrideString = s;
54 m_overrideToolTip = t;
55 updateMedia();
56 }
57
overrideDevice() const58 K3b::Device::Device* overrideDevice() const {
59 return m_overrideDevice;
60 }
61
62 protected:
showMedium(const K3b::Medium & m) const63 bool showMedium( const K3b::Medium& m ) const override {
64 return ( m.device() == m_overrideDevice ||
65 K3b::MediaSelectionComboBox::showMedium( m ) );
66 }
67
mediumString(const K3b::Medium & m) const68 QString mediumString( const K3b::Medium& m ) const override {
69 if( m.device() == m_overrideDevice )
70 return m_overrideString;
71 else
72 return K3b::MediaSelectionComboBox::mediumString( m );
73 }
74
mediumToolTip(const K3b::Medium & m) const75 QString mediumToolTip( const K3b::Medium& m ) const override {
76 if( m.device() == m_overrideDevice )
77 return m_overrideToolTip;
78 else {
79 QString s = K3b::MediaSelectionComboBox::mediumToolTip( m );
80 if( !m.diskInfo().empty() && !(wantedMediumState() & m.diskInfo().diskState()) )
81 s.append( "<p><i>" + i18n("Medium will be overwritten.") + "</i>" );
82 return s;
83 }
84 }
85
86 private:
87 K3b::Device::Device* m_overrideDevice;
88 QString m_overrideString;
89 QString m_overrideToolTip;
90 };
91
92
93 class K3b::WriterSelectionWidget::Private
94 {
95 public:
96 bool forceAutoSpeed;
97 bool haveIgnoreSpeed;
98 bool haveManualSpeed;
99
100 K3b::WritingApps supportedWritingApps;
101
102 int lastSetSpeed;
103 };
104
105
WriterSelectionWidget(QWidget * parent)106 K3b::WriterSelectionWidget::WriterSelectionWidget( QWidget *parent )
107 : QWidget( parent )
108 {
109 d = new Private;
110 d->forceAutoSpeed = false;
111 d->supportedWritingApps = K3b::WritingAppCdrecord|K3b::WritingAppCdrdao|K3b::WritingAppGrowisofs;
112 d->lastSetSpeed = -1;
113
114 QGroupBox* groupWriter = new QGroupBox( this );
115 groupWriter->setTitle( i18n( "Burn Medium" ) );
116
117 QGridLayout* groupWriterLayout = new QGridLayout( groupWriter );
118 groupWriterLayout->setAlignment( Qt::AlignTop );
119
120 QLabel* labelSpeed = new QLabel( groupWriter );
121 labelSpeed->setText( i18n( "Speed:" ) );
122
123 m_comboSpeed = new K3b::IntMapComboBox( groupWriter );
124
125 m_comboMedium = new MediaSelectionComboBox( groupWriter );
126
127 m_writingAppLabel = new QLabel( i18n("Writing app:"), groupWriter );
128 m_comboWritingApp = new K3b::IntMapComboBox( groupWriter );
129
130 groupWriterLayout->addWidget( m_comboMedium, 0, 0 );
131 groupWriterLayout->addWidget( labelSpeed, 0, 1 );
132 groupWriterLayout->addWidget( m_comboSpeed, 0, 2 );
133 groupWriterLayout->addWidget( m_writingAppLabel, 0, 3 );
134 groupWriterLayout->addWidget( m_comboWritingApp, 0, 4 );
135 groupWriterLayout->setColumnStretch( 0, 1 );
136
137
138 QGridLayout* mainLayout = new QGridLayout( this );
139 mainLayout->setAlignment( Qt::AlignTop );
140 mainLayout->setContentsMargins( 0, 0, 0, 0 );
141
142 mainLayout->addWidget( groupWriter, 0, 0 );
143
144 // tab order
145 setTabOrder( m_comboMedium, m_comboSpeed );
146 setTabOrder( m_comboSpeed, m_comboWritingApp );
147
148 connect( m_comboMedium, SIGNAL(selectionChanged(K3b::Device::Device*)), this, SIGNAL(writerChanged()) );
149 connect( m_comboMedium, SIGNAL(selectionChanged(K3b::Device::Device*)),
150 this, SIGNAL(writerChanged(K3b::Device::Device*)) );
151 connect( m_comboMedium, SIGNAL(newMedia()), this, SIGNAL(newMedia()) );
152 connect( m_comboMedium, SIGNAL(newMedium(K3b::Device::Device*)), this, SIGNAL(newMedium(K3b::Device::Device*)) );
153 connect( m_comboMedium, SIGNAL(newMedium(K3b::Device::Device*)), this, SLOT(slotNewBurnMedium(K3b::Device::Device*)) );
154 connect( m_comboWritingApp, SIGNAL(valueChanged(int)), this, SLOT(slotWritingAppSelected(int)) );
155 connect( this, SIGNAL(writerChanged()), SLOT(slotWriterChanged()) );
156 connect( m_comboSpeed, SIGNAL(valueChanged(int)), this, SLOT(slotSpeedChanged(int)) );
157
158
159 m_comboMedium->setToolTip( i18n("The medium that will be used for burning") );
160 m_comboSpeed->setToolTip( i18n("The speed at which to burn the medium") );
161 m_comboWritingApp->setToolTip( i18n("The external application to actually burn the medium") );
162
163 m_comboMedium->setWhatsThis( i18n("<p>Select the medium that you want to use for burning."
164 "<p>In most cases there will only be one medium available which "
165 "does not leave much choice.") );
166 m_comboSpeed->setWhatsThis( i18n("<p>Select the speed with which you want to burn."
167 "<p><b>Auto</b><br>"
168 "This will choose the maximum writing speed possible with the used "
169 "medium. "
170 "This is the recommended selection for most media.</p>"
171 "<p><b>Ignore</b> (DVD only)<br>"
172 "This will leave the speed selection to the writer device. "
173 "Use this if K3b is unable to set the writing speed."
174 "<p>1x refers to 175 KB/s for CD, 1385 KB/s for DVD, and 4496 KB/s for Blu-ray.</p>"
175 "<p><b>Caution:</b> Make sure your system is able to send the data "
176 "fast enough to prevent buffer underruns.") );
177 m_comboWritingApp->setWhatsThis( i18n("<p>K3b uses the command line tools cdrecord, growisofs, and cdrdao "
178 "to actually write a CD or DVD."
179 "<p>Normally K3b chooses the best "
180 "suited application for every task automatically but in some cases it "
181 "may be possible that one of the applications does not work as intended "
182 "with a certain writer. In this case one may select the "
183 "application manually.") );
184
185 clearSpeedCombo();
186
187 slotConfigChanged( KSharedConfig::openConfig() );
188 slotWriterChanged();
189 }
190
191
~WriterSelectionWidget()192 K3b::WriterSelectionWidget::~WriterSelectionWidget()
193 {
194 delete d;
195 }
196
197
setWantedMediumType(Device::MediaTypes type)198 void K3b::WriterSelectionWidget::setWantedMediumType( Device::MediaTypes type )
199 {
200 m_comboMedium->setWantedMediumType( type );
201 }
202
203
setWantedMediumState(Device::MediaStates state)204 void K3b::WriterSelectionWidget::setWantedMediumState( Device::MediaStates state )
205 {
206 m_comboMedium->setWantedMediumState( state );
207 }
208
209
setWantedMediumSize(const K3b::Msf & minSize)210 void K3b::WriterSelectionWidget::setWantedMediumSize( const K3b::Msf& minSize )
211 {
212 #ifdef __GNUC__
213 #warning The wanted medium size may not be enough if we need to handle multisession!
214 #endif
215 m_comboMedium->setWantedMediumSize( minSize );
216 }
217
218
wantedMediumType() const219 K3b::Device::MediaTypes K3b::WriterSelectionWidget::wantedMediumType() const
220 {
221 return m_comboMedium->wantedMediumType();
222 }
223
224
wantedMediumState() const225 K3b::Device::MediaStates K3b::WriterSelectionWidget::wantedMediumState() const
226 {
227 return m_comboMedium->wantedMediumState();
228 }
229
230
wantedMediumSize() const231 K3b::Msf K3b::WriterSelectionWidget::wantedMediumSize() const
232 {
233 return m_comboMedium->wantedMediumSize();
234 }
235
236
slotConfigChanged(KSharedConfig::Ptr c)237 void K3b::WriterSelectionWidget::slotConfigChanged( KSharedConfig::Ptr c )
238 {
239 KConfigGroup g( c, "General Options" );
240 if( g.readEntry( "Show advanced GUI", false ) ) {
241 m_comboWritingApp->show();
242 m_writingAppLabel->show();
243 }
244 else {
245 m_comboWritingApp->hide();
246 m_writingAppLabel->hide();
247 }
248 }
249
250
slotRefreshWriterSpeeds()251 void K3b::WriterSelectionWidget::slotRefreshWriterSpeeds()
252 {
253 if( writerDevice() ) {
254 QList<int> speeds = k3bappcore->mediaCache()->writingSpeeds( writerDevice() );
255
256 int lastSpeed = writerSpeed();
257
258 clearSpeedCombo();
259
260 m_comboSpeed->insertItem( s_autoSpeedValue, i18n("Auto") );
261 if( Device::isDvdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
262 m_comboSpeed->insertItem( s_ignoreSpeedValue, i18n("Ignore") );
263 d->haveIgnoreSpeed = true;
264 }
265 else
266 d->haveIgnoreSpeed = false;
267
268 if( !d->forceAutoSpeed ) {
269 if( speeds.isEmpty() || writerDevice() == m_comboMedium->overrideDevice() ) {
270 //
271 // In case of the override device we do not know which medium will actually be used
272 // So this is the only case in which we need to use the device's max writing speed
273 //
274 // But we need to know if it will be a CD or DVD medium. Since the override device
275 // is only used for CD/DVD copy anyway we simply reply on the inserted medium's type.
276 //
277 int x1Speed = K3b::Device::SPEED_FACTOR_CD;
278 if( Device::isDvdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
279 x1Speed = K3b::Device::SPEED_FACTOR_DVD;
280 }
281 else if( Device::isBdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
282 x1Speed = K3b::Device::SPEED_FACTOR_BD;
283 }
284
285 const int max = writerDevice()->maxWriteSpeed();
286 for( int i = 1; i*x1Speed <= max; i = ( i == 1 ? 2 : i+2 ) ) {
287 insertSpeedItem( i*x1Speed );
288 // a little hack to handle the stupid 2.4x DVD speed
289 if( i == 2 && x1Speed == K3b::Device::SPEED_FACTOR_DVD )
290 insertSpeedItem( (int)(2.4*( double )K3b::Device::SPEED_FACTOR_DVD) );
291 }
292 }
293 else {
294 for( QList<int>::iterator it = speeds.begin(); it != speeds.end(); ++it )
295 insertSpeedItem( *it );
296 }
297 }
298
299
300 //
301 // Although most devices return all speeds properly there are still some dumb ones around
302 // that don't. Users of those will need the possibility to set the speed manually even if
303 // a medium is inserted.
304 //
305 if ( !d->forceAutoSpeed ) {
306 m_comboSpeed->insertItem( s_moreSpeedValue, i18n("More...") );
307 d->haveManualSpeed = true;
308 }
309 else {
310 d->haveManualSpeed = false;
311 }
312
313
314 // try to reload last set speed
315 if( d->lastSetSpeed == -1 )
316 setSpeed( lastSpeed );
317 else
318 setSpeed( d->lastSetSpeed );
319 }
320
321 m_comboSpeed->setEnabled( writerDevice() != 0 );
322 }
323
324
clearSpeedCombo()325 void K3b::WriterSelectionWidget::clearSpeedCombo()
326 {
327 m_comboSpeed->clear();
328 d->haveManualSpeed = false;
329 d->haveIgnoreSpeed = false;
330 }
331
332
insertSpeedItem(int speed)333 void K3b::WriterSelectionWidget::insertSpeedItem( int speed )
334 {
335 Device::MediaType mediaType = k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType();
336
337 int insertIndex = -1;
338 if ( m_comboSpeed->hasValue( s_moreSpeedValue ) ) {
339 insertIndex = m_comboSpeed->count()-1;
340 }
341
342 //
343 // polish the speed
344 //
345 if( K3b::Device::isDvdMedia( mediaType ) ) {
346 //
347 // AFAIK there is only one strange DVD burning speed like 2.4
348 //
349 int xs = int( double( Device::SPEED_FACTOR_DVD ) * 2.4 );
350 if ( abs( speed - xs ) < Device::SPEED_FACTOR_DVD/2 )
351 speed = xs;
352 else
353 speed = ( ( speed+692 )/Device::SPEED_FACTOR_DVD )*Device::SPEED_FACTOR_DVD;
354 }
355 else if ( K3b::Device::isBdMedia( mediaType ) ) {
356 speed = ( ( speed+2250 )/Device::SPEED_FACTOR_BD )*Device::SPEED_FACTOR_BD;
357 }
358 else {
359 speed = ( ( speed + ( K3b::Device::SPEED_FACTOR_CD/2 ) )/K3b::Device::SPEED_FACTOR_CD )*K3b::Device::SPEED_FACTOR_CD;
360 }
361
362 if( !m_comboSpeed->hasValue( speed ) ) {
363 if( K3b::Device::isDvdMedia( mediaType ) ) {
364 m_comboSpeed->insertItem( speed,
365 ( speed%Device::SPEED_FACTOR_DVD > 0
366 ? QString::number( float(speed)/float(Device::SPEED_FACTOR_DVD), 'f', 1 ) // example: DVD+R(W): 2.4x
367 : QString::number( speed/K3b::Device::SPEED_FACTOR_DVD ) )
368 + 'x',
369 QString(),
370 insertIndex );
371 }
372 else if ( K3b::Device::isBdMedia( mediaType ) ) {
373 m_comboSpeed->insertItem( speed, QString("%1x").arg(speed/K3b::Device::SPEED_FACTOR_BD), QString(), insertIndex );
374 }
375 else {
376 m_comboSpeed->insertItem( speed, QString("%1x").arg(speed/K3b::Device::SPEED_FACTOR_CD), QString(), insertIndex );
377 }
378 }
379 }
380
381
slotWritingAppSelected(int app)382 void K3b::WriterSelectionWidget::slotWritingAppSelected( int app )
383 {
384 emit writingAppChanged( K3b::WritingApp( app ) );
385 }
386
387
writerDevice() const388 K3b::Device::Device* K3b::WriterSelectionWidget::writerDevice() const
389 {
390 return m_comboMedium->selectedDevice();
391 }
392
393
allDevices() const394 QList<K3b::Device::Device*> K3b::WriterSelectionWidget::allDevices() const
395 {
396 return m_comboMedium->allDevices();
397 }
398
399
setWriterDevice(K3b::Device::Device * dev)400 void K3b::WriterSelectionWidget::setWriterDevice( K3b::Device::Device* dev )
401 {
402 m_comboMedium->setSelectedDevice( dev );
403 }
404
405
setSpeed(int s)406 void K3b::WriterSelectionWidget::setSpeed( int s )
407 {
408 d->lastSetSpeed = -1;
409
410 if( d->haveIgnoreSpeed && s < 0 )
411 m_comboSpeed->setSelectedValue( s_ignoreSpeedValue ); // Ignore
412 else if( m_comboSpeed->hasValue( s ) )
413 m_comboSpeed->setSelectedValue( s );
414 else {
415 m_comboSpeed->setSelectedValue( s_autoSpeedValue ); // Auto
416 d->lastSetSpeed = s; // remember last set speed
417 }
418 }
419
420
setWritingApp(K3b::WritingApp app)421 void K3b::WriterSelectionWidget::setWritingApp( K3b::WritingApp app )
422 {
423 m_comboWritingApp->setSelectedValue( ( int )app );
424 }
425
426
writerSpeed() const427 int K3b::WriterSelectionWidget::writerSpeed() const
428 {
429 if( m_comboSpeed->selectedValue() == s_autoSpeedValue )
430 return 0; // Auto
431 else if( d->haveIgnoreSpeed && m_comboSpeed->selectedValue() == s_ignoreSpeedValue )
432 return -1; // Ignore
433 else
434 return m_comboSpeed->selectedValue();
435 }
436
437
writingApp() const438 K3b::WritingApp K3b::WriterSelectionWidget::writingApp() const
439 {
440 KConfigGroup g( KSharedConfig::openConfig(), "General Options" );
441 if( g.readEntry( "Show advanced GUI", false ) ) {
442 return selectedWritingApp();
443 }
444 else
445 return K3b::WritingAppAuto;
446 }
447
448
selectedWritingApp() const449 K3b::WritingApp K3b::WriterSelectionWidget::selectedWritingApp() const
450 {
451 return K3b::WritingApp( m_comboWritingApp->selectedValue() );
452 }
453
454
slotSpeedChanged(int s)455 void K3b::WriterSelectionWidget::slotSpeedChanged( int s )
456 {
457 // the last item is the manual speed selection item
458 if( d->haveManualSpeed && s == s_moreSpeedValue ) {
459 slotManualSpeed();
460 }
461 else {
462 d->lastSetSpeed = s;
463
464 if( K3b::Device::Device* dev = writerDevice() )
465 dev->setCurrentWriteSpeed( writerSpeed() );
466 }
467 }
468
469
slotWriterChanged()470 void K3b::WriterSelectionWidget::slotWriterChanged()
471 {
472 slotRefreshWriterSpeeds();
473 slotRefreshWritingApps();
474
475 // save last selected writer
476 if( K3b::Device::Device* dev = writerDevice() ) {
477 KConfigGroup g( KSharedConfig::openConfig(), "General Options" );
478 g.writeEntry( "current_writer", dev->blockDeviceName() );
479 }
480 }
481
482
setSupportedWritingApps(K3b::WritingApps i)483 void K3b::WriterSelectionWidget::setSupportedWritingApps( K3b::WritingApps i )
484 {
485 K3b::WritingApp oldApp = writingApp();
486
487 d->supportedWritingApps = i;
488
489 slotRefreshWritingApps();
490
491 setWritingApp( oldApp );
492 }
493
494
slotRefreshWritingApps()495 void K3b::WriterSelectionWidget::slotRefreshWritingApps()
496 {
497 K3b::WritingApps i = 0;
498
499 int lastSelected = m_comboWritingApp->selectedValue();
500
501 // select the ones that make sense
502 if( Device::isDvdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) )
503 i = K3b::WritingAppGrowisofs|K3b::WritingAppDvdRwFormat|K3b::WritingAppCdrecord;
504 else if ( K3b::Device::isBdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) )
505 i = K3b::WritingAppGrowisofs|K3b::WritingAppCdrecord;
506 else
507 i = K3b::WritingAppCdrdao|K3b::WritingAppCdrecord;
508
509 // now strip it down to the ones we support
510 i &= d->supportedWritingApps;
511
512 m_comboWritingApp->clear();
513 m_comboWritingApp->insertItem( K3b::WritingAppAuto, i18n("Auto") );
514
515 if( i & K3b::WritingAppCdrdao )
516 m_comboWritingApp->insertItem( K3b::WritingAppCdrdao, "cdrdao" );
517 if( i & K3b::WritingAppCdrecord )
518 m_comboWritingApp->insertItem( K3b::WritingAppCdrecord, "cdrecord" );
519 if( i & K3b::WritingAppGrowisofs )
520 m_comboWritingApp->insertItem( K3b::WritingAppGrowisofs, "growisofs" );
521 if( i & K3b::WritingAppDvdRwFormat )
522 m_comboWritingApp->insertItem( K3b::WritingAppDvdRwFormat, "dvd+rw-format" );
523 if (i & K3b::WritingAppCdrskin)
524 m_comboWritingApp->insertItem(K3b::WritingAppCdrskin, "cdrskin");
525
526 m_comboWritingApp->setSelectedValue( lastSelected );
527
528 m_comboWritingApp->setEnabled( writerDevice() != 0 );
529 }
530
531
loadConfig(const KConfigGroup & c)532 void K3b::WriterSelectionWidget::loadConfig( const KConfigGroup& c )
533 {
534 setWriterDevice( k3bcore->deviceManager()->findDevice( c.readEntry( "writer_device" ) ) );
535 setSpeed( c.readEntry( "writing_speed", s_autoSpeedValue ) );
536 setWritingApp( K3b::writingAppFromString( c.readEntry( "writing_app" ) ) );
537 }
538
539
saveConfig(KConfigGroup c)540 void K3b::WriterSelectionWidget::saveConfig( KConfigGroup c )
541 {
542 c.writeEntry( "writing_speed", writerSpeed() );
543 c.writeEntry( "writer_device", writerDevice() ? writerDevice()->blockDeviceName() : QString() );
544 c.writeEntry( "writing_app", m_comboWritingApp->currentText() );
545 }
546
setForceAutoSpeed(bool b)547 void K3b::WriterSelectionWidget::setForceAutoSpeed( bool b )
548 {
549 d->forceAutoSpeed = b;
550 slotRefreshWriterSpeeds();
551 }
552
553
setOverrideDevice(K3b::Device::Device * dev,const QString & overrideString,const QString & tooltip)554 void K3b::WriterSelectionWidget::setOverrideDevice( K3b::Device::Device* dev, const QString& overrideString, const QString& tooltip )
555 {
556 m_comboMedium->setOverrideDevice( dev, overrideString, tooltip );
557 }
558
559
slotNewBurnMedium(K3b::Device::Device * dev)560 void K3b::WriterSelectionWidget::slotNewBurnMedium( K3b::Device::Device* dev )
561 {
562 //
563 // Try to select a medium that is better suited than the current one
564 //
565 if( dev && dev != writerDevice() ) {
566 K3b::Medium medium = k3bappcore->mediaCache()->medium( dev );
567
568 //
569 // Always prefer newly inserted media over the override device
570 //
571 if( writerDevice() == m_comboMedium->overrideDevice() ) {
572 setWriterDevice( dev );
573 }
574
575 //
576 // Prefer an empty medium over one that has to be erased
577 //
578 else if( wantedMediumState() & K3b::Device::STATE_EMPTY &&
579 !k3bappcore->mediaCache()->diskInfo( writerDevice() ).empty() &&
580 medium.diskInfo().empty() ) {
581 setWriterDevice( dev );
582 }
583 }
584 }
585
586
slotManualSpeed()587 void K3b::WriterSelectionWidget::slotManualSpeed()
588 {
589 //
590 // In case we think we have all the available speeds (i.e. if the device reported a non-empty list)
591 // we just treat it as a manual selection. Otherwise we admit that we cannot do better
592 //
593 bool haveSpeeds = ( writerDevice() && !k3bappcore->mediaCache()->writingSpeeds( writerDevice() ).isEmpty() );
594 QString s;
595 if ( haveSpeeds ) {
596 s = i18n( "Please enter the speed that K3b should use for burning (Example: 16x)." );
597 }
598 else {
599 s = i18n("<p>K3b is not able to perfectly determine the maximum "
600 "writing speed of an optical writer. Writing speed is always "
601 "reported subject to the inserted medium."
602 "<p>Please enter the writing speed here and K3b will remember it "
603 "for future sessions (Example: 16x).");
604 }
605
606 //
607 // We need to know the type of medium. Since the override device
608 // is only used for copy anyway we simply reply on the inserted medium's type.
609 //
610 int speedFactor = K3b::Device::SPEED_FACTOR_CD;
611 if( Device::isDvdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
612 speedFactor = K3b::Device::SPEED_FACTOR_DVD;
613 }
614 else if( Device::isBdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
615 speedFactor = K3b::Device::SPEED_FACTOR_BD;
616 }
617
618 bool ok = true;
619 int newSpeed = QInputDialog::getInt( this,
620 i18n("Set writing speed manually"),
621 s,
622 writerDevice()->maxWriteSpeed()/speedFactor,
623 1,
624 10000,
625 1,
626 &ok ) * speedFactor;
627 if( ok ) {
628 writerDevice()->setMaxWriteSpeed( qMax( newSpeed, writerDevice()->maxWriteSpeed() ) );
629 if ( haveSpeeds ) {
630 insertSpeedItem( newSpeed );
631 }
632 else {
633 slotRefreshWriterSpeeds();
634 }
635 setSpeed( newSpeed );
636 }
637 else {
638 if( d->lastSetSpeed == -1 )
639 m_comboSpeed->setSelectedValue( s_autoSpeedValue ); // Auto
640 else
641 setSpeed( d->lastSetSpeed );
642 }
643 }
644
645
setIgnoreDevice(K3b::Device::Device * dev)646 void K3b::WriterSelectionWidget::setIgnoreDevice( K3b::Device::Device* dev )
647 {
648 m_comboMedium->setIgnoreDevice( dev );
649 }
650
651
652