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 #include "k3bwritingmodewidget.h"
0006 #include "k3bmediacache.h"
0007 #include "k3bapplication.h"
0008 
0009 #include "k3bglobals.h"
0010 
0011 #include <KConfig>
0012 #include <KLocalizedString>
0013 
0014 #include <QToolTip>
0015 
0016 static const KLocalizedString s_autoHelp =
0017     ki18n("Let K3b select the best-suited mode. This is the recommended selection.");
0018 static const KLocalizedString s_daoHelp =
0019     ki18n("<em>Disk At Once</em> or more properly <em>Session At Once</em>. "
0020           "The laser is never turned off while writing the CD or DVD. "
0021           "This is the preferred mode to write audio CDs since it allows "
0022           "pregaps other than 2 seconds. Not all writers support DAO.<br>"
0023           "DVD-R(W)s written in DAO provide the best DVD-Video compatibility.");
0024 static const KLocalizedString s_taoHelp =
0025     ki18n("<em>Track At Once</em> should be supported by every CD writer. "
0026           "The laser will be turned off after every track.<br>"
0027           "Most CD writers need this mode for writing multisession CDs.");
0028 // TODO: add something like: "No CD-TEXT writing in TAO mode."
0029 
0030 static const KLocalizedString s_rawHelp =
0031     ki18n("RAW writing mode. The error correction data is created by the "
0032           "software instead of the writer device.<br>"
0033           "Try this if your CD writer fails to write in DAO and TAO.");
0034 static const KLocalizedString s_seqHelp =
0035     ki18n("Incremental sequential is the default writing mode for DVD-R(W). "
0036           "It allows multisession DVD-R(W)s. It only applies to DVD-R(W).");
0037 static const KLocalizedString s_ovwHelp =
0038     ki18n("Restricted Overwrite allows one to use a DVD-RW just like a DVD-RAM "
0039           "or a DVD+RW. The media may just be overwritten. It is not possible "
0040           "to write multisession DVD-RWs in this mode but K3b uses growisofs "
0041           "to grow an ISO 9660 filesystem within the first session, thus allowing "
0042           "new files to be added to an already burned disk.");
0043 
0044 
0045 class K3b::WritingModeWidget::Private
0046 {
0047 public:
0048     // modes set via setSupportedModes
0049     WritingModes supportedModes;
0050 
0051     // filtered modes
0052     WritingModes selectedModes;
0053 
0054     Device::Device* device;
0055 
0056     void _k_writingModeChanged( int mode ) {
0057         emit q->writingModeChanged( WritingMode( mode ) );
0058     }
0059 
0060     WritingModeWidget* q;
0061 };
0062 
0063 
0064 K3b::WritingModeWidget::WritingModeWidget( WritingModes modes, QWidget* parent )
0065     : IntMapComboBox( parent )
0066 {
0067     init();
0068     setSupportedModes( modes );
0069 }
0070 
0071 
0072 K3b::WritingModeWidget::WritingModeWidget( QWidget* parent )
0073     : IntMapComboBox( parent )
0074 {
0075     init();
0076     setSupportedModes( WritingModeSao | WritingModeTao | WritingModeRaw );   // default: support all CD-R(W) modes
0077 }
0078 
0079 
0080 K3b::WritingModeWidget::~WritingModeWidget()
0081 {
0082     delete d;
0083 }
0084 
0085 
0086 void K3b::WritingModeWidget::init()
0087 {
0088     d = new Private();
0089     d->q = this;
0090     d->device = 0;
0091 
0092     connect( this, SIGNAL(valueChanged(int)), this, SLOT(_k_writingModeChanged(int)) );
0093 
0094     setToolTip( i18n("Select the writing mode to use") );
0095     addGlobalWhatsThisText( "<p><b>" + i18n("Writing mode") + "</b></p>",
0096                             i18n("Be aware that the writing mode is ignored when writing DVD+R(W) and BD-R(E) since "
0097                                  "there is only one way to write them.")
0098                             + "<p><i>"
0099                             + i18n("The selection of writing modes depends on the inserted burning medium.")
0100                             + "</i>" );
0101 }
0102 
0103 
0104 K3b::WritingMode K3b::WritingModeWidget::writingMode() const
0105 {
0106     return WritingMode( selectedValue() );
0107 }
0108 
0109 
0110 K3b::WritingModes K3b::WritingModeWidget::supportedWritingModes() const
0111 {
0112     return d->selectedModes;
0113 }
0114 
0115 
0116 void K3b::WritingModeWidget::setWritingMode( WritingMode m )
0117 {
0118     if( m & d->selectedModes ) {
0119         setSelectedValue( m );
0120     }
0121     else {
0122         setSelectedValue( WritingModeAuto );
0123     }
0124 }
0125 
0126 
0127 void K3b::WritingModeWidget::setSupportedModes( WritingModes m )
0128 {
0129     d->supportedModes = m|WritingModeAuto;  // we always support the Auto mode
0130     updateModes();
0131 }
0132 
0133 
0134 void K3b::WritingModeWidget::setDevice( Device::Device* dev )
0135 {
0136     d->device = dev;
0137     updateModes();
0138 }
0139 
0140 
0141 void K3b::WritingModeWidget::updateModes()
0142 {
0143     // save current mode
0144     int currentMode = writingMode();
0145 
0146     clear();
0147 
0148     if( d->device )
0149         d->selectedModes = d->supportedModes & d->device->writingModes();
0150     else
0151         d->selectedModes = d->supportedModes;
0152 
0153     insertItem( WritingModeAuto, i18n("Auto"), s_autoHelp.toString() );
0154     if( d->selectedModes & WritingModeSao )
0155         insertItem( WritingModeSao, i18n("DAO"), s_daoHelp.toString() );
0156     if( d->selectedModes & WritingModeTao )
0157         insertItem( WritingModeTao, i18n("TAO"), s_taoHelp.toString() );
0158     if( d->selectedModes & WritingModeRaw )
0159         insertItem( WritingModeRaw, i18n("RAW"), s_rawHelp.toString() );
0160     if( d->selectedModes & WritingModeRestrictedOverwrite )
0161         insertItem( WritingModeRestrictedOverwrite, i18n("Restricted Overwrite"), s_ovwHelp.toString() );
0162     if( d->selectedModes & WritingModeIncrementalSequential )
0163         insertItem( WritingModeIncrementalSequential, i18n("Incremental"), s_seqHelp.toString() );
0164 
0165     setWritingMode( currentMode != -1 ? WritingMode( currentMode ) : WritingModeAuto );
0166 }
0167 
0168 
0169 void K3b::WritingModeWidget::saveConfig( KConfigGroup c )
0170 {
0171     switch( writingMode() ) {
0172     case WritingModeSao:
0173         c.writeEntry( "writing_mode", "dao" );
0174         break;
0175     case WritingModeTao:
0176         c.writeEntry( "writing_mode", "tao" );
0177         break;
0178     case WritingModeRaw:
0179         c.writeEntry( "writing_mode", "raw" );
0180         break;
0181     case WritingModeIncrementalSequential:
0182         c.writeEntry( "writing_mode", "incremental" );
0183         break;
0184     case WritingModeRestrictedOverwrite:
0185         c.writeEntry( "writing_mode", "overwrite" );
0186         break;
0187     default:
0188         c.writeEntry( "writing_mode", "auto" );
0189         break;
0190     }
0191 }
0192 
0193 void K3b::WritingModeWidget::loadConfig( const KConfigGroup& c )
0194 {
0195     QString mode = c.readEntry( "writing_mode" );
0196     if ( mode == "dao" )
0197         setWritingMode( WritingModeSao );
0198     else if( mode == "tao" )
0199         setWritingMode( WritingModeTao );
0200     else if( mode == "raw" )
0201         setWritingMode( WritingModeRaw );
0202     else if( mode == "incremental" )
0203         setWritingMode( WritingModeIncrementalSequential );
0204     else if( mode == "overwrite" )
0205         setWritingMode( WritingModeRestrictedOverwrite );
0206     else
0207         setWritingMode( WritingModeAuto );
0208 }
0209 
0210 
0211 void K3b::WritingModeWidget::determineSupportedModesFromMedium( const Medium& m )
0212 {
0213     WritingModes modes = WritingModeAuto;
0214 
0215     if( m.diskInfo().mediaType() & (Device::MEDIA_CD_R|Device::MEDIA_CD_RW) ) {
0216         modes |= WritingModeTao;
0217         if( m.device()->supportsWritingMode( Device::WRITINGMODE_SAO ) )
0218             modes |= WritingModeSao;
0219         if( m.device()->supportsWritingMode( Device::WRITINGMODE_RAW ) )
0220             modes |= WritingModeRaw;
0221     }
0222 
0223     if( m.diskInfo().mediaType() & Device::MEDIA_DVD_MINUS_ALL ) {
0224         modes |= WritingModeSao;
0225         if ( !k3bcore->deviceBlocked( m.device() ) )
0226              if( m.device()->featureCurrent( Device::FEATURE_INCREMENTAL_STREAMING_WRITABLE ) != 0 )
0227                  modes |= WritingModeIncrementalSequential;
0228     }
0229 
0230     if( m.diskInfo().mediaType() & (Device::MEDIA_DVD_RW|
0231                                     Device::MEDIA_DVD_RW_SEQ|
0232                                     Device::MEDIA_DVD_RW_OVWR) ) {
0233         modes |= WritingModeRestrictedOverwrite;
0234     }
0235 
0236     setSupportedModes( modes );
0237     setDevice( m.device() );
0238 }
0239 
0240 
0241 void K3b::WritingModeWidget::determineSupportedModesFromMedium( K3b::Device::Device* dev )
0242 {
0243     if( dev )
0244         determineSupportedModesFromMedium( k3bappcore->mediaCache()->medium( dev ) );
0245     else
0246         determineSupportedModesFromMedium( Medium() ); // no medium
0247 }
0248 
0249 #include "moc_k3bwritingmodewidget.cpp"