File indexing completed on 2024-04-28 04:50:05
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "k3bmediaformattingdialog.h" 0009 0010 #include "k3bapplication.h" 0011 #include "k3bmediacache.h" 0012 #include "k3bmedium.h" 0013 0014 #include "k3bdvdformattingjob.h" 0015 #include "k3bblankingjob.h" 0016 0017 #include "k3bdevice.h" 0018 #include "k3bdevicemanager.h" 0019 #include "k3bglobals.h" 0020 #include "k3bcore.h" 0021 #include "k3bwriterselectionwidget.h" 0022 #include "k3bwritingmodewidget.h" 0023 #include "k3bjobprogressdialog.h" 0024 0025 #include <KConfig> 0026 #include <KSharedConfig> 0027 #include <KLocalizedString> 0028 #include <KMessageBox> 0029 0030 #include <QGroupBox> 0031 #include <QLayout> 0032 #include <QCheckBox> 0033 #include <QPushButton> 0034 #include <QToolTip> 0035 0036 0037 0038 K3b::MediaFormattingDialog::MediaFormattingDialog( QWidget* parent ) 0039 : K3b::InteractionDialog( parent, 0040 i18n("Format and Erase"), 0041 i18n( "CD-RW" ) + '/' + i18n( "DVD±RW" ) + '/' + i18n( "BD-RE" ), 0042 START_BUTTON|CANCEL_BUTTON, 0043 START_BUTTON, 0044 "Formatting and Erasing" ) // config group 0045 { 0046 QWidget* frame = mainWidget(); 0047 0048 m_writerSelectionWidget = new K3b::WriterSelectionWidget( frame ); 0049 m_writerSelectionWidget->setWantedMediumType( K3b::Device::MEDIA_REWRITABLE ); 0050 // we need state empty here for preformatting DVD+RW. 0051 m_writerSelectionWidget->setWantedMediumState( K3b::Device::STATE_COMPLETE| 0052 K3b::Device::STATE_INCOMPLETE| 0053 K3b::Device::STATE_EMPTY ); 0054 m_writerSelectionWidget->setSupportedWritingApps( K3b::WritingAppDvdRwFormat ); 0055 m_writerSelectionWidget->setForceAutoSpeed(true); 0056 0057 QGroupBox* groupWritingMode = new QGroupBox( i18n("Writing Mode"), frame ); 0058 m_writingModeWidget = new K3b::WritingModeWidget( K3b::WritingModeIncrementalSequential|K3b::WritingModeRestrictedOverwrite, 0059 groupWritingMode ); 0060 QVBoxLayout* groupWritingModeLayout = new QVBoxLayout( groupWritingMode ); 0061 groupWritingModeLayout->addWidget( m_writingModeWidget ); 0062 groupWritingModeLayout->addStretch( 1 ); 0063 0064 QGroupBox* groupOptions = new QGroupBox( i18n("Settings"), frame ); 0065 m_checkForce = new QCheckBox( i18n("Force"), groupOptions ); 0066 m_checkQuickFormat = new QCheckBox( i18n("Quick format"), groupOptions ); 0067 QVBoxLayout* groupOptionsLayout = new QVBoxLayout( groupOptions ); 0068 groupOptionsLayout->addWidget( m_checkForce ); 0069 groupOptionsLayout->addWidget( m_checkQuickFormat ); 0070 groupOptionsLayout->addStretch( 1 ); 0071 0072 QGridLayout* grid = new QGridLayout( frame ); 0073 grid->setContentsMargins( 0, 0, 0, 0 ); 0074 0075 grid->addWidget( m_writerSelectionWidget, 0, 0, 1, 2 ); 0076 grid->addWidget( groupWritingMode, 1, 0 ); 0077 grid->addWidget( groupOptions, 1, 1 ); 0078 grid->setRowStretch( 1, 1 ); 0079 0080 m_checkForce->setToolTip( i18n("Force formatting of empty DVDs") ); 0081 m_checkForce->setWhatsThis( i18n("<p>If this option is checked K3b will format a " 0082 "DVD-RW even if it is empty. It may also be used to " 0083 "force K3b to format a DVD+RW, BD-RE or a DVD-RW in restricted " 0084 "overwrite mode." 0085 "<p><b>Caution:</b> It is not recommended to format a DVD often " 0086 "as it may become unusable after only 10-20 reformat procedures." 0087 "<p>DVD+RW and BD-RE media only needs to be formatted once. After that it " 0088 "just needs to be overwritten. The same applies to DVD-RW in " 0089 "restricted overwrite mode.") ); 0090 0091 m_checkQuickFormat->setToolTip( i18n("Try to perform quick formatting") ); 0092 m_checkQuickFormat->setWhatsThis( i18n("<p>If this option is checked K3b will tell the writer " 0093 "to perform a quick format." 0094 "<p>Erasing a rewritable medium completely can take a very long " 0095 "time and some writers perform a full format even if " 0096 "quick format is enabled." ) ); 0097 0098 connect( m_writerSelectionWidget, SIGNAL(writerChanged()), this, SLOT(slotToggleAll()) ); 0099 0100 slotToggleAll(); 0101 } 0102 0103 0104 K3b::MediaFormattingDialog::~MediaFormattingDialog() 0105 { 0106 } 0107 0108 0109 void K3b::MediaFormattingDialog::setDevice( K3b::Device::Device* dev ) 0110 { 0111 m_writerSelectionWidget->setWriterDevice( dev ); 0112 } 0113 0114 0115 void K3b::MediaFormattingDialog::slotStartClicked() 0116 { 0117 K3b::Medium medium = k3bappcore->mediaCache()->medium( m_writerSelectionWidget->writerDevice() ); 0118 0119 K3b::JobProgressDialog dlg( parentWidget(), false ); 0120 0121 K3b::Job* theJob = 0; 0122 0123 if( medium.diskInfo().mediaType() & K3b::Device::MEDIA_CD_ALL ) { 0124 K3b::BlankingJob* job = new K3b::BlankingJob( &dlg, this ); 0125 0126 job->setDevice( m_writerSelectionWidget->writerDevice() ); 0127 job->setSpeed( m_writerSelectionWidget->writerSpeed() ); 0128 job->setForce( m_checkForce->isChecked() ); 0129 job->setWritingApp( m_writerSelectionWidget->writingApp() ); 0130 // no support for all the strange erasing modes anymore, they did not work anyway 0131 job->setFormattingMode( m_checkQuickFormat->isChecked() ? FormattingQuick : FormattingComplete ); 0132 0133 theJob = job; 0134 } 0135 else { // DVDFormattingJob handles DVD and BD discs 0136 K3b::DvdFormattingJob* job = new K3b::DvdFormattingJob( &dlg, this ); 0137 0138 job->setDevice( m_writerSelectionWidget->writerDevice() ); 0139 job->setMode( m_writingModeWidget->writingMode() ); 0140 job->setForce( m_checkForce->isChecked() ); 0141 job->setFormattingMode( m_checkQuickFormat->isChecked() ? FormattingQuick : FormattingComplete ); 0142 0143 theJob = job; 0144 } 0145 0146 hide(); 0147 0148 dlg.startJob( theJob ); 0149 0150 delete theJob; 0151 0152 if( KConfigGroup( KSharedConfig::openConfig(), QStringLiteral("General Options") ).readEntry( "keep action dialogs open", false ) ) 0153 show(); 0154 else 0155 close(); 0156 } 0157 0158 0159 void K3b::MediaFormattingDialog::toggleAll() 0160 { 0161 K3b::Medium medium = k3bappcore->mediaCache()->medium( m_writerSelectionWidget->writerDevice() ); 0162 K3b::WritingModes modes = WritingModeAuto; 0163 if ( medium.diskInfo().mediaType() & (K3b::Device::MEDIA_DVD_RW|K3b::Device::MEDIA_DVD_RW_SEQ|K3b::Device::MEDIA_DVD_RW_OVWR) ) { 0164 modes |= K3b::WritingModeIncrementalSequential|K3b::WritingModeRestrictedOverwrite; 0165 } 0166 m_writingModeWidget->setSupportedModes( modes ); 0167 setButtonEnabled( START_BUTTON, m_writerSelectionWidget->writerDevice() != 0 ); 0168 } 0169 0170 0171 void K3b::MediaFormattingDialog::loadSettings( const KConfigGroup& c ) 0172 { 0173 m_checkForce->setChecked( c.readEntry( "force", false ) ); 0174 m_checkQuickFormat->setChecked( c.readEntry( "quick format", true ) ); 0175 m_writerSelectionWidget->loadConfig( c ); 0176 m_writingModeWidget->loadConfig( c ); 0177 } 0178 0179 0180 void K3b::MediaFormattingDialog::saveSettings( KConfigGroup c ) 0181 { 0182 c.writeEntry( "force", m_checkForce->isChecked() ); 0183 c.writeEntry( "quick format", m_checkQuickFormat->isChecked() ); 0184 m_writerSelectionWidget->saveConfig( c ); 0185 m_writingModeWidget->saveConfig( c ); 0186 } 0187 0188 #include "moc_k3bmediaformattingdialog.cpp"