File indexing completed on 2024-04-21 04:50:17

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3bwriterselectionwidget.h"
0007 #include "k3bapplication.h"
0008 #include "k3bmediacache.h"
0009 
0010 #include "k3bmediaselectioncombobox.h"
0011 #include "k3bdevice.h"
0012 #include "k3bdevicemanager.h"
0013 #include "k3bglobals.h"
0014 #include "k3bcore.h"
0015 #include "k3bintmapcombobox.h"
0016 
0017 #include <KConfig>
0018 #include <KConfigGroup>
0019 #include <KSharedConfig>
0020 #include <KLocalizedString>
0021 #include <KMessageBox>
0022 
0023 #include <QCursor>
0024 #include <QApplication>
0025 #include <QGridLayout>
0026 #include <QGroupBox>
0027 #include <QInputDialog>
0028 #include <QLabel>
0029 #include <QLayout>
0030 #include <QToolButton>
0031 #include <QToolTip>
0032 
0033 #include <cstdlib>
0034 
0035 
0036 namespace {
0037     int s_autoSpeedValue = 0;
0038     int s_ignoreSpeedValue = -1;
0039     int s_moreSpeedValue = -2;
0040 }
0041 
0042 
0043 class K3b::WriterSelectionWidget::MediaSelectionComboBox : public K3b::MediaSelectionComboBox
0044 {
0045 public:
0046     MediaSelectionComboBox( QWidget* parent )
0047         : K3b::MediaSelectionComboBox( parent ),
0048           m_overrideDevice( 0 ) {
0049     }
0050 
0051     void setOverrideDevice( K3b::Device::Device* dev, const QString& s, const QString& t ) {
0052         m_overrideDevice = dev;
0053         m_overrideString = s;
0054         m_overrideToolTip = t;
0055         updateMedia();
0056     }
0057 
0058     K3b::Device::Device* overrideDevice() const {
0059         return m_overrideDevice;
0060     }
0061 
0062 protected:
0063     bool showMedium( const K3b::Medium& m ) const override {
0064         return ( m.device() == m_overrideDevice ||
0065                  K3b::MediaSelectionComboBox::showMedium( m ) );
0066     }
0067 
0068     QString mediumString( const K3b::Medium& m ) const override {
0069         if( m.device() == m_overrideDevice )
0070             return m_overrideString;
0071         else
0072             return K3b::MediaSelectionComboBox::mediumString( m );
0073     }
0074 
0075     QString mediumToolTip( const K3b::Medium& m ) const override {
0076         if( m.device() == m_overrideDevice )
0077             return m_overrideToolTip;
0078         else {
0079             QString s = K3b::MediaSelectionComboBox::mediumToolTip( m );
0080             if( !m.diskInfo().empty() && !(wantedMediumState() & m.diskInfo().diskState()) )
0081                 s.append( "<p><i>" + i18n("Medium will be overwritten.") + "</i>" );
0082             return s;
0083         }
0084     }
0085 
0086 private:
0087     K3b::Device::Device* m_overrideDevice;
0088     QString m_overrideString;
0089     QString m_overrideToolTip;
0090 };
0091 
0092 
0093 class K3b::WriterSelectionWidget::Private
0094 {
0095 public:
0096     bool forceAutoSpeed;
0097     bool haveIgnoreSpeed;
0098     bool haveManualSpeed;
0099 
0100     K3b::WritingApps supportedWritingApps;
0101 
0102     int lastSetSpeed;
0103 };
0104 
0105 
0106 K3b::WriterSelectionWidget::WriterSelectionWidget( QWidget *parent )
0107     : QWidget( parent )
0108 {
0109     d = new Private;
0110     d->forceAutoSpeed = false;
0111     d->supportedWritingApps = K3b::WritingAppCdrecord|K3b::WritingAppCdrdao|K3b::WritingAppGrowisofs;
0112     d->lastSetSpeed = -1;
0113 
0114     QGroupBox* groupWriter = new QGroupBox( this );
0115     groupWriter->setTitle( i18n( "Burn Medium" ) );
0116 
0117     QGridLayout* groupWriterLayout = new QGridLayout( groupWriter );
0118     groupWriterLayout->setAlignment( Qt::AlignTop );
0119 
0120     QLabel* labelSpeed = new QLabel( groupWriter );
0121     labelSpeed->setText( i18n( "Speed:" ) );
0122 
0123     m_comboSpeed = new K3b::IntMapComboBox( groupWriter );
0124 
0125     m_comboMedium = new MediaSelectionComboBox( groupWriter );
0126 
0127     m_writingAppLabel = new QLabel( i18n("Writing app:"), groupWriter );
0128     m_comboWritingApp = new K3b::IntMapComboBox( groupWriter );
0129 
0130     groupWriterLayout->addWidget( m_comboMedium, 0, 0 );
0131     groupWriterLayout->addWidget( labelSpeed, 0, 1 );
0132     groupWriterLayout->addWidget( m_comboSpeed, 0, 2 );
0133     groupWriterLayout->addWidget( m_writingAppLabel, 0, 3 );
0134     groupWriterLayout->addWidget( m_comboWritingApp, 0, 4 );
0135     groupWriterLayout->setColumnStretch( 0, 1 );
0136 
0137 
0138     QGridLayout* mainLayout = new QGridLayout( this );
0139     mainLayout->setAlignment( Qt::AlignTop );
0140     mainLayout->setContentsMargins( 0, 0, 0, 0 );
0141 
0142     mainLayout->addWidget( groupWriter, 0, 0 );
0143 
0144     // tab order
0145     setTabOrder( m_comboMedium, m_comboSpeed );
0146     setTabOrder( m_comboSpeed, m_comboWritingApp );
0147 
0148     connect( m_comboMedium, SIGNAL(selectionChanged(K3b::Device::Device*)), this, SIGNAL(writerChanged()) );
0149     connect( m_comboMedium, SIGNAL(selectionChanged(K3b::Device::Device*)),
0150              this, SIGNAL(writerChanged(K3b::Device::Device*)) );
0151     connect( m_comboMedium, SIGNAL(newMedia()), this, SIGNAL(newMedia()) );
0152     connect( m_comboMedium, SIGNAL(newMedium(K3b::Device::Device*)), this, SIGNAL(newMedium(K3b::Device::Device*)) );
0153     connect( m_comboMedium, SIGNAL(newMedium(K3b::Device::Device*)), this, SLOT(slotNewBurnMedium(K3b::Device::Device*)) );
0154     connect( m_comboWritingApp, SIGNAL(valueChanged(int)), this, SLOT(slotWritingAppSelected(int)) );
0155     connect( this, SIGNAL(writerChanged()), SLOT(slotWriterChanged()) );
0156     connect( m_comboSpeed, SIGNAL(valueChanged(int)), this, SLOT(slotSpeedChanged(int)) );
0157 
0158 
0159     m_comboMedium->setToolTip( i18n("The medium that will be used for burning") );
0160     m_comboSpeed->setToolTip( i18n("The speed at which to burn the medium") );
0161     m_comboWritingApp->setToolTip( i18n("The external application to actually burn the medium") );
0162 
0163     m_comboMedium->setWhatsThis( i18n("<p>Select the medium that you want to use for burning."
0164                                       "<p>In most cases there will only be one medium available which "
0165                                       "does not leave much choice.") );
0166     m_comboSpeed->setWhatsThis( i18n("<p>Select the speed with which you want to burn."
0167                                      "<p><b>Auto</b><br>"
0168                                      "This will choose the maximum writing speed possible with the used "
0169                                      "medium. "
0170                                      "This is the recommended selection for most media.</p>"
0171                                      "<p><b>Ignore</b> (DVD only)<br>"
0172                                      "This will leave the speed selection to the writer device. "
0173                                      "Use this if K3b is unable to set the writing speed."
0174                                      "<p>1x refers to 175 KB/s for CD, 1385 KB/s for DVD, and 4496 KB/s for Blu-ray.</p>"
0175                                      "<p><b>Caution:</b> Make sure your system is able to send the data "
0176                                      "fast enough to prevent buffer underruns.") );
0177     m_comboWritingApp->setWhatsThis( i18n("<p>K3b uses the command line tools cdrecord, growisofs, and cdrdao "
0178                                           "to actually write a CD or DVD."
0179                                           "<p>Normally K3b chooses the best "
0180                                           "suited application for every task automatically but in some cases it "
0181                                           "may be possible that one of the applications does not work as intended "
0182                                           "with a certain writer. In this case one may select the "
0183                                           "application manually.") );
0184 
0185     clearSpeedCombo();
0186 
0187     slotConfigChanged( KSharedConfig::openConfig() );
0188     slotWriterChanged();
0189 }
0190 
0191 
0192 K3b::WriterSelectionWidget::~WriterSelectionWidget()
0193 {
0194     delete d;
0195 }
0196 
0197 
0198 void K3b::WriterSelectionWidget::setWantedMediumType( Device::MediaTypes type )
0199 {
0200     m_comboMedium->setWantedMediumType( type );
0201 }
0202 
0203 
0204 void K3b::WriterSelectionWidget::setWantedMediumState( Device::MediaStates state )
0205 {
0206     m_comboMedium->setWantedMediumState( state );
0207 }
0208 
0209 
0210 void K3b::WriterSelectionWidget::setWantedMediumSize( const K3b::Msf& minSize )
0211 {
0212 #ifdef __GNUC__
0213 #warning The wanted medium size may not be enough if we need to handle multisession!
0214 #endif
0215     m_comboMedium->setWantedMediumSize( minSize );
0216 }
0217 
0218 
0219 K3b::Device::MediaTypes K3b::WriterSelectionWidget::wantedMediumType() const
0220 {
0221     return m_comboMedium->wantedMediumType();
0222 }
0223 
0224 
0225 K3b::Device::MediaStates K3b::WriterSelectionWidget::wantedMediumState() const
0226 {
0227     return m_comboMedium->wantedMediumState();
0228 }
0229 
0230 
0231 K3b::Msf K3b::WriterSelectionWidget::wantedMediumSize() const
0232 {
0233     return m_comboMedium->wantedMediumSize();
0234 }
0235 
0236 
0237 void K3b::WriterSelectionWidget::slotConfigChanged( KSharedConfig::Ptr c )
0238 {
0239     KConfigGroup g( c, QStringLiteral("General Options") );
0240     if( g.readEntry( "Show advanced GUI", false ) ) {
0241         m_comboWritingApp->show();
0242         m_writingAppLabel->show();
0243     }
0244     else {
0245         m_comboWritingApp->hide();
0246         m_writingAppLabel->hide();
0247     }
0248 }
0249 
0250 
0251 void K3b::WriterSelectionWidget::slotRefreshWriterSpeeds()
0252 {
0253     if( writerDevice() ) {
0254         QList<int> speeds = k3bappcore->mediaCache()->writingSpeeds( writerDevice() );
0255 
0256         int lastSpeed = writerSpeed();
0257 
0258         clearSpeedCombo();
0259 
0260         m_comboSpeed->insertItem( s_autoSpeedValue, i18n("Auto") );
0261         if( Device::isDvdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
0262             m_comboSpeed->insertItem( s_ignoreSpeedValue, i18n("Ignore") );
0263             d->haveIgnoreSpeed = true;
0264         }
0265         else
0266             d->haveIgnoreSpeed = false;
0267 
0268         if( !d->forceAutoSpeed ) {
0269             if( speeds.isEmpty() || writerDevice() == m_comboMedium->overrideDevice() ) {
0270                 //
0271                 // In case of the override device we do not know which medium will actually be used
0272                 // So this is the only case in which we need to use the device's max writing speed
0273                 //
0274                 // But we need to know if it will be a CD or DVD medium. Since the override device
0275                 // is only used for CD/DVD copy anyway we simply reply on the inserted medium's type.
0276                 //
0277                 int x1Speed = K3b::Device::SPEED_FACTOR_CD;
0278                 if( Device::isDvdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
0279                     x1Speed = K3b::Device::SPEED_FACTOR_DVD;
0280                 }
0281                 else if( Device::isBdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
0282                     x1Speed = K3b::Device::SPEED_FACTOR_BD;
0283                 }
0284 
0285                 const int max = writerDevice()->maxWriteSpeed();
0286                 for( int i = 1; i*x1Speed <= max; i = ( i == 1 ? 2 : i+2 ) ) {
0287                     insertSpeedItem( i*x1Speed );
0288                     // a little hack to handle the stupid 2.4x DVD speed
0289                     if( i == 2 && x1Speed == K3b::Device::SPEED_FACTOR_DVD )
0290                         insertSpeedItem( (int)(2.4*( double )K3b::Device::SPEED_FACTOR_DVD) );
0291                 }
0292             }
0293             else {
0294                 for( QList<int>::iterator it = speeds.begin(); it != speeds.end(); ++it )
0295                     insertSpeedItem( *it );
0296             }
0297         }
0298 
0299 
0300         //
0301         // Although most devices return all speeds properly there are still some dumb ones around
0302         // that don't. Users of those will need the possibility to set the speed manually even if
0303         // a medium is inserted.
0304         //
0305         if ( !d->forceAutoSpeed ) {
0306             m_comboSpeed->insertItem( s_moreSpeedValue, i18n("More...") );
0307             d->haveManualSpeed = true;
0308         }
0309         else {
0310             d->haveManualSpeed = false;
0311         }
0312 
0313 
0314         // try to reload last set speed
0315         if( d->lastSetSpeed == -1 )
0316             setSpeed( lastSpeed );
0317         else
0318             setSpeed( d->lastSetSpeed );
0319     }
0320 
0321     m_comboSpeed->setEnabled( writerDevice() != 0 );
0322 }
0323 
0324 
0325 void K3b::WriterSelectionWidget::clearSpeedCombo()
0326 {
0327     m_comboSpeed->clear();
0328     d->haveManualSpeed = false;
0329     d->haveIgnoreSpeed = false;
0330 }
0331 
0332 
0333 void K3b::WriterSelectionWidget::insertSpeedItem( int speed )
0334 {
0335     Device::MediaType mediaType = k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType();
0336 
0337     int insertIndex = -1;
0338     if ( m_comboSpeed->hasValue( s_moreSpeedValue ) ) {
0339         insertIndex = m_comboSpeed->count()-1;
0340     }
0341 
0342     //
0343     // polish the speed
0344     //
0345     if( K3b::Device::isDvdMedia( mediaType ) ) {
0346         //
0347         // AFAIK there is only one strange DVD burning speed like 2.4
0348         //
0349         int xs = int( double( Device::SPEED_FACTOR_DVD ) * 2.4 );
0350         if ( abs( speed - xs ) < Device::SPEED_FACTOR_DVD/2 )
0351             speed = xs;
0352         else
0353             speed = ( ( speed+692 )/Device::SPEED_FACTOR_DVD )*Device::SPEED_FACTOR_DVD;
0354     }
0355     else if ( K3b::Device::isBdMedia( mediaType ) ) {
0356         speed = ( ( speed+2250 )/Device::SPEED_FACTOR_BD )*Device::SPEED_FACTOR_BD;
0357     }
0358     else {
0359         speed = ( ( speed + ( K3b::Device::SPEED_FACTOR_CD/2 ) )/K3b::Device::SPEED_FACTOR_CD )*K3b::Device::SPEED_FACTOR_CD;
0360     }
0361 
0362     if( !m_comboSpeed->hasValue( speed ) ) {
0363         if( K3b::Device::isDvdMedia( mediaType ) ) {
0364             m_comboSpeed->insertItem( speed,
0365                                       ( speed%Device::SPEED_FACTOR_DVD > 0
0366                                         ? QString::number( float(speed)/float(Device::SPEED_FACTOR_DVD), 'f', 1 )  // example: DVD+R(W): 2.4x
0367                                         : QString::number( speed/K3b::Device::SPEED_FACTOR_DVD ) )
0368                                       + 'x',
0369                                       QString(),
0370                                       insertIndex );
0371         }
0372         else if ( K3b::Device::isBdMedia( mediaType ) ) {
0373             m_comboSpeed->insertItem( speed, QString("%1x").arg(speed/K3b::Device::SPEED_FACTOR_BD), QString(), insertIndex );
0374         }
0375         else {
0376             m_comboSpeed->insertItem( speed, QString("%1x").arg(speed/K3b::Device::SPEED_FACTOR_CD), QString(), insertIndex );
0377         }
0378     }
0379 }
0380 
0381 
0382 void K3b::WriterSelectionWidget::slotWritingAppSelected( int app )
0383 {
0384     emit writingAppChanged( K3b::WritingApp( app ) );
0385 }
0386 
0387 
0388 K3b::Device::Device* K3b::WriterSelectionWidget::writerDevice() const
0389 {
0390     return m_comboMedium->selectedDevice();
0391 }
0392 
0393 
0394 QList<K3b::Device::Device*> K3b::WriterSelectionWidget::allDevices() const
0395 {
0396     return m_comboMedium->allDevices();
0397 }
0398 
0399 
0400 void K3b::WriterSelectionWidget::setWriterDevice( K3b::Device::Device* dev )
0401 {
0402     m_comboMedium->setSelectedDevice( dev );
0403 }
0404 
0405 
0406 void K3b::WriterSelectionWidget::setSpeed( int s )
0407 {
0408     d->lastSetSpeed = -1;
0409 
0410     if( d->haveIgnoreSpeed && s < 0 )
0411         m_comboSpeed->setSelectedValue( s_ignoreSpeedValue ); // Ignore
0412     else if( m_comboSpeed->hasValue( s ) )
0413         m_comboSpeed->setSelectedValue( s );
0414     else {
0415         m_comboSpeed->setSelectedValue( s_autoSpeedValue ); // Auto
0416         d->lastSetSpeed = s; // remember last set speed
0417     }
0418 }
0419 
0420 
0421 void K3b::WriterSelectionWidget::setWritingApp( K3b::WritingApp app )
0422 {
0423     m_comboWritingApp->setSelectedValue( ( int )app );
0424 }
0425 
0426 
0427 int K3b::WriterSelectionWidget::writerSpeed() const
0428 {
0429     if( m_comboSpeed->selectedValue() == s_autoSpeedValue )
0430         return 0; // Auto
0431     else if( d->haveIgnoreSpeed && m_comboSpeed->selectedValue() == s_ignoreSpeedValue )
0432         return -1; // Ignore
0433     else
0434         return m_comboSpeed->selectedValue();
0435 }
0436 
0437 
0438 K3b::WritingApp K3b::WriterSelectionWidget::writingApp() const
0439 {
0440     KConfigGroup g( KSharedConfig::openConfig(), QStringLiteral("General Options") );
0441     if( g.readEntry( "Show advanced GUI", false ) ) {
0442         return selectedWritingApp();
0443     }
0444     else
0445         return K3b::WritingAppAuto;
0446 }
0447 
0448 
0449 K3b::WritingApp K3b::WriterSelectionWidget::selectedWritingApp() const
0450 {
0451     return K3b::WritingApp( m_comboWritingApp->selectedValue() );
0452 }
0453 
0454 
0455 void K3b::WriterSelectionWidget::slotSpeedChanged( int s )
0456 {
0457     // the last item is the manual speed selection item
0458     if( d->haveManualSpeed && s == s_moreSpeedValue ) {
0459         slotManualSpeed();
0460     }
0461     else {
0462         d->lastSetSpeed = s;
0463 
0464         if( K3b::Device::Device* dev = writerDevice() )
0465             dev->setCurrentWriteSpeed( writerSpeed() );
0466     }
0467 }
0468 
0469 
0470 void K3b::WriterSelectionWidget::slotWriterChanged()
0471 {
0472     slotRefreshWriterSpeeds();
0473     slotRefreshWritingApps();
0474 
0475     // save last selected writer
0476     if( K3b::Device::Device* dev = writerDevice() ) {
0477         KConfigGroup g( KSharedConfig::openConfig(), QStringLiteral("General Options") );
0478         g.writeEntry( "current_writer", dev->blockDeviceName() );
0479     }
0480 }
0481 
0482 
0483 void K3b::WriterSelectionWidget::setSupportedWritingApps( K3b::WritingApps i )
0484 {
0485     K3b::WritingApp oldApp = writingApp();
0486 
0487     d->supportedWritingApps = i;
0488 
0489     slotRefreshWritingApps();
0490 
0491     setWritingApp( oldApp );
0492 }
0493 
0494 
0495 void K3b::WriterSelectionWidget::slotRefreshWritingApps()
0496 {
0497     K3b::WritingApps i = K3b::WritingApps();
0498 
0499     int lastSelected = m_comboWritingApp->selectedValue();
0500 
0501     // select the ones that make sense
0502     if( Device::isDvdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) )
0503         i = K3b::WritingAppGrowisofs|K3b::WritingAppDvdRwFormat|K3b::WritingAppCdrecord;
0504     else if ( K3b::Device::isBdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) )
0505         i = K3b::WritingAppGrowisofs|K3b::WritingAppCdrecord;
0506     else
0507         i = K3b::WritingAppCdrdao|K3b::WritingAppCdrecord;
0508 
0509     // now strip it down to the ones we support
0510     i &= d->supportedWritingApps;
0511 
0512     m_comboWritingApp->clear();
0513     m_comboWritingApp->insertItem( K3b::WritingAppAuto, i18n("Auto") );
0514 
0515     if( i & K3b::WritingAppCdrdao )
0516         m_comboWritingApp->insertItem( K3b::WritingAppCdrdao, "cdrdao" );
0517     if( i & K3b::WritingAppCdrecord )
0518         m_comboWritingApp->insertItem( K3b::WritingAppCdrecord, "cdrecord" );
0519     if( i & K3b::WritingAppGrowisofs )
0520         m_comboWritingApp->insertItem( K3b::WritingAppGrowisofs, "growisofs" );
0521     if( i & K3b::WritingAppDvdRwFormat )
0522         m_comboWritingApp->insertItem( K3b::WritingAppDvdRwFormat, "dvd+rw-format" );
0523     if (i & K3b::WritingAppCdrskin)
0524         m_comboWritingApp->insertItem(K3b::WritingAppCdrskin, "cdrskin");
0525 
0526     m_comboWritingApp->setSelectedValue( lastSelected );
0527 
0528     m_comboWritingApp->setEnabled( writerDevice() != 0 );
0529 }
0530 
0531 
0532 void K3b::WriterSelectionWidget::loadConfig( const KConfigGroup& c )
0533 {
0534     setWriterDevice( k3bcore->deviceManager()->findDevice( c.readEntry( "writer_device" ) ) );
0535     setSpeed( c.readEntry( "writing_speed",  s_autoSpeedValue ) );
0536     setWritingApp( K3b::writingAppFromString( c.readEntry( "writing_app" ) ) );
0537 }
0538 
0539 
0540 void K3b::WriterSelectionWidget::saveConfig( KConfigGroup c )
0541 {
0542     c.writeEntry( "writing_speed", writerSpeed() );
0543     c.writeEntry( "writer_device", writerDevice() ? writerDevice()->blockDeviceName() : QString() );
0544     c.writeEntry( "writing_app", m_comboWritingApp->currentText() );
0545 }
0546 
0547 void K3b::WriterSelectionWidget::setForceAutoSpeed( bool b )
0548 {
0549     d->forceAutoSpeed = b;
0550     slotRefreshWriterSpeeds();
0551 }
0552 
0553 
0554 void K3b::WriterSelectionWidget::setOverrideDevice( K3b::Device::Device* dev, const QString& overrideString, const QString& tooltip )
0555 {
0556     m_comboMedium->setOverrideDevice( dev, overrideString, tooltip );
0557 }
0558 
0559 
0560 void K3b::WriterSelectionWidget::slotNewBurnMedium( K3b::Device::Device* dev )
0561 {
0562     //
0563     // Try to select a medium that is better suited than the current one
0564     //
0565     if( dev && dev != writerDevice() ) {
0566         K3b::Medium medium = k3bappcore->mediaCache()->medium( dev );
0567 
0568         //
0569         // Always prefer newly inserted media over the override device
0570         //
0571         if( writerDevice() == m_comboMedium->overrideDevice() ) {
0572             setWriterDevice( dev );
0573         }
0574 
0575         //
0576         // Prefer an empty medium over one that has to be erased
0577         //
0578         else if( wantedMediumState() & K3b::Device::STATE_EMPTY &&
0579                  !k3bappcore->mediaCache()->diskInfo( writerDevice() ).empty() &&
0580                  medium.diskInfo().empty() ) {
0581             setWriterDevice( dev );
0582         }
0583     }
0584 }
0585 
0586 
0587 void K3b::WriterSelectionWidget::slotManualSpeed()
0588 {
0589     //
0590     // In case we think we have all the available speeds (i.e. if the device reported a non-empty list)
0591     // we just treat it as a manual selection. Otherwise we admit that we cannot do better
0592     //
0593     bool haveSpeeds = ( writerDevice() && !k3bappcore->mediaCache()->writingSpeeds( writerDevice() ).isEmpty() );
0594     QString s;
0595     if ( haveSpeeds ) {
0596         s = i18n( "Please enter the speed that K3b should use for burning (Example: 16x)." );
0597     }
0598     else {
0599         s = i18n("<p>K3b is not able to perfectly determine the maximum "
0600                  "writing speed of an optical writer. Writing speed is always "
0601                  "reported subject to the inserted medium."
0602                  "<p>Please enter the writing speed here and K3b will remember it "
0603                  "for future sessions (Example: 16x).");
0604     }
0605 
0606     //
0607     // We need to know the type of medium. Since the override device
0608     // is only used for copy anyway we simply reply on the inserted medium's type.
0609     //
0610     int speedFactor = K3b::Device::SPEED_FACTOR_CD;
0611     if( Device::isDvdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
0612         speedFactor = K3b::Device::SPEED_FACTOR_DVD;
0613     }
0614     else if( Device::isBdMedia( k3bappcore->mediaCache()->diskInfo( writerDevice() ).mediaType() ) ) {
0615         speedFactor = K3b::Device::SPEED_FACTOR_BD;
0616     }
0617 
0618     bool ok = true;
0619     int newSpeed = QInputDialog::getInt( this,
0620                                          i18n("Set writing speed manually"),
0621                                          s,
0622                                          writerDevice()->maxWriteSpeed()/speedFactor,
0623                                          1,
0624                                          10000,
0625                                          1,
0626                                          &ok ) * speedFactor;
0627     if( ok ) {
0628         writerDevice()->setMaxWriteSpeed( qMax( newSpeed, writerDevice()->maxWriteSpeed() ) );
0629         if ( haveSpeeds ) {
0630             insertSpeedItem( newSpeed );
0631         }
0632         else {
0633             slotRefreshWriterSpeeds();
0634         }
0635         setSpeed( newSpeed );
0636     }
0637     else {
0638         if( d->lastSetSpeed == -1 )
0639             m_comboSpeed->setSelectedValue( s_autoSpeedValue ); // Auto
0640         else
0641             setSpeed( d->lastSetSpeed );
0642     }
0643 }
0644 
0645 
0646 void K3b::WriterSelectionWidget::setIgnoreDevice( K3b::Device::Device* dev )
0647 {
0648     m_comboMedium->setIgnoreDevice( dev );
0649 }
0650 
0651 #include "moc_k3bwriterselectionwidget.cpp"