File indexing completed on 2024-06-16 07:42:03

0001 /*
0002     SPDX-FileCopyrightText: 1998-2010 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3bblankingjob.h"
0007 #include "k3bcdrecordwriter.h"
0008 #include "k3bcdrdaowriter.h"
0009 
0010 #include "k3bglobals.h"
0011 #include "k3bdevice.h"
0012 #include "k3bdevicehandler.h"
0013 #include "k3bcore.h"
0014 #include "k3bglobalsettings.h"
0015 #include "k3b_i18n.h"
0016 
0017 #include <KConfig>
0018 #include <KIO/Global>
0019 #include <KIO/Job>
0020 
0021 #include <QDebug>
0022 #include <QString>
0023 
0024 
0025 
0026 K3b::BlankingJob::BlankingJob( K3b::JobHandler* hdl, QObject* parent )
0027     : K3b::BurnJob( hdl, parent ),
0028       m_writerJob(0),
0029       m_force(true),
0030       m_device(0),
0031       m_speed(0),
0032       m_mode(FormattingQuick),
0033       m_writingApp(WritingAppAuto),
0034       m_canceled(false),
0035       m_forceNoEject(false)
0036 {
0037 }
0038 
0039 
0040 K3b::BlankingJob::~BlankingJob()
0041 {
0042     delete m_writerJob;
0043 }
0044 
0045 
0046 K3b::Device::Device* K3b::BlankingJob::writer() const
0047 {
0048     return m_device;
0049 }
0050 
0051 
0052 void K3b::BlankingJob::setDevice( K3b::Device::Device* dev )
0053 {
0054     m_device = dev;
0055 }
0056 
0057 
0058 void K3b::BlankingJob::start()
0059 {
0060     if( m_device == 0 )
0061         return;
0062 
0063     jobStarted();
0064 
0065     emit newTask( i18n( "Erasing CD-RW" ) );
0066     emit infoMessage( i18n( "When erasing a CD-RW no progress information is available." ), MessageWarning );
0067 
0068     slotStartErasing();
0069 }
0070 
0071 void K3b::BlankingJob::slotStartErasing()
0072 {
0073     m_canceled = false;
0074 
0075     if( m_writerJob )
0076         delete m_writerJob;
0077 
0078     if( m_writingApp == K3b::WritingAppCdrdao ) {
0079         K3b::CdrdaoWriter* writer = new K3b::CdrdaoWriter( m_device, this );
0080         m_writerJob = writer;
0081 
0082         writer->setCommand( K3b::CdrdaoWriter::BLANK );
0083         writer->setBlankMode( m_mode );
0084         writer->setForce( m_force );
0085         writer->setBurnSpeed( m_speed );
0086     }
0087     else {
0088         K3b::CdrecordWriter* writer = new K3b::CdrecordWriter( m_device, this );
0089         m_writerJob = writer;
0090 
0091         writer->setFormattingMode( m_mode );
0092         writer->setForce( m_force );
0093         writer->setBurnSpeed( m_speed );
0094     }
0095 
0096     connect(m_writerJob, SIGNAL(finished(bool)), this, SLOT(slotFinished(bool)));
0097     connect(m_writerJob, SIGNAL(infoMessage(QString,int)),
0098             this,SIGNAL(infoMessage(QString,int)));
0099     connect( m_writerJob, SIGNAL(debuggingOutput(QString,QString)),
0100              this, SIGNAL(debuggingOutput(QString,QString)) );
0101 
0102     if( waitForMedium( m_device,
0103                        K3b::Device::STATE_COMPLETE|K3b::Device::STATE_INCOMPLETE,
0104                        K3b::Device::MEDIA_CD_RW,
0105                        0,
0106                        i18n("Please insert a rewritable CD medium into drive<p><b>%1 %2 (%3)</b>.",
0107                             m_device->vendor(),
0108                             m_device->description(),
0109                             m_device->blockDeviceName()) ) == Device::MEDIA_UNKNOWN ) {
0110         emit canceled();
0111         jobFinished(false);
0112         return;
0113     }
0114 
0115     m_writerJob->start();
0116 }
0117 
0118 
0119 void K3b::BlankingJob::cancel()
0120 {
0121     m_canceled = true;
0122 
0123     if( m_writerJob )
0124         m_writerJob->cancel();
0125 }
0126 
0127 
0128 void K3b::BlankingJob::slotFinished(bool success)
0129 {
0130     if ( !m_forceNoEject && k3bcore->globalSettings()->ejectMedia() ) {
0131         K3b::Device::eject( m_device );
0132     }
0133 
0134     if( success ) {
0135         emit percent( 100 );
0136         jobFinished( true );
0137     }
0138     else {
0139         if( m_canceled ) {
0140             emit canceled();
0141         }
0142         else {
0143             emit infoMessage( i18n("Blanking error."), K3b::Job::MessageError );
0144             emit infoMessage( i18n("Sorry, no error handling yet."), K3b::Job::MessageError );
0145         }
0146         jobFinished( false );
0147     }
0148 }
0149 
0150 
0151 QString K3b::BlankingJob::jobDescription() const
0152 {
0153     return i18n("Erasing CD-RW");
0154 }
0155 
0156 
0157 QString K3b::BlankingJob::jobDetails() const
0158 {
0159     if( m_mode == FormattingQuick )
0160         return i18n("Quick Format");
0161     else
0162         return QString();
0163 }
0164 
0165 #include "moc_k3bblankingjob.cpp"