File indexing completed on 2024-05-05 04:51:43

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "k3bdataimagesettingswidget.h"
0008 #include "k3bdataadvancedimagesettingsdialog.h"
0009 #include "k3bdatavolumedescdialog.h"
0010 #include "k3bisooptions.h"
0011 
0012 #include <KLazyLocalizedString>
0013 #include <KMessageBox>
0014 
0015 #include <QDebug>
0016 #include <QCheckBox>
0017 #include <QComboBox>
0018 #include <QLayout>
0019 #include <QLineEdit>
0020 #include <QPushButton>
0021 #include <QRadioButton>
0022 
0023 // indices for the filesystems combobox
0024 static const int FS_LINUX_ONLY = 0;
0025 static const int FS_LINUX_AND_WIN = 1;
0026 static const int FS_UDF = 2;
0027 static const int FS_DOS_COMP = 3;
0028 static const int FS_CUSTOM = 4;
0029 static const int FS_MAX = 5;
0030 
0031 static const KLocalizedString s_fsPresetNames[] = {
0032     kli18n("Linux/Unix only"),
0033     kli18n("Linux/Unix + Windows"),
0034     kli18n("Very large files (UDF)"),
0035     kli18n("DOS Compatibility"),
0036     kli18n("Custom")
0037 };
0038 
0039 static bool s_fsPresetsInitialized = false;
0040 static K3b::IsoOptions s_fsPresets[FS_CUSTOM];
0041 
0042 // indices for the whitespace treatment combobox
0043 static const int WS_NO_CHANGE = 0;
0044 static const int WS_STRIP = 1;
0045 static const int WS_EXTENDED_STRIP = 2;
0046 static const int WS_REPLACE = 3;
0047 
0048 // indices for the symlink handling combobox
0049 static const int SYM_NO_CHANGE = 0;
0050 static const int SYM_DISCARD_BROKEN = 1;
0051 static const int SYM_DISCARD_ALL = 2;
0052 static const int SYM_FOLLOW = 3;
0053 
0054 
0055 //
0056 // returns true if the part of the options that is presented in the advanced custom
0057 // settings dialog is equal. used to determine if some preset is used.
0058 //
0059 static bool compareAdvancedOptions( const K3b::IsoOptions& o1, const K3b::IsoOptions& o2 )
0060 {
0061     return ( o1.createRockRidge() == o2.createRockRidge() &&
0062              o1.createJoliet() == o2.createJoliet() &&
0063              o1.createUdf() == o2.createUdf() &&
0064              o1.ISOallowLowercase() == o2.ISOallowLowercase() &&
0065              o1.ISOallowPeriodAtBegin() == o2.ISOallowPeriodAtBegin() &&
0066              o1.ISOallow31charFilenames() == o2.ISOallow31charFilenames() &&
0067              o1.ISOomitVersionNumbers() == o2.ISOomitVersionNumbers() &&
0068              o1.ISOomitTrailingPeriod() == o2.ISOomitTrailingPeriod() &&
0069              o1.ISOmaxFilenameLength() == o2.ISOmaxFilenameLength() &&
0070              o1.ISOrelaxedFilenames() == o2.ISOrelaxedFilenames() &&
0071              o1.ISOnoIsoTranslate() == o2.ISOnoIsoTranslate() &&
0072              o1.ISOallowMultiDot() == o2.ISOallowMultiDot() &&
0073              o1.ISOuntranslatedFilenames() == o2.ISOuntranslatedFilenames() &&
0074              o1.createTRANS_TBL() == o2.createTRANS_TBL() &&
0075              o1.hideTRANS_TBL() == o2.hideTRANS_TBL() &&
0076              o1.jolietLong() == o2.jolietLong() &&
0077              o1.ISOLevel() == o2.ISOLevel() &&
0078              o1.preserveFilePermissions() == o2.preserveFilePermissions() &&
0079              o1.doNotCacheInodes() == o2.doNotCacheInodes() );
0080 }
0081 
0082 
0083 static void initializePresets()
0084 {
0085     QString vid = i18nc( "This is the default volume identifier of a data project created by K3b. "
0086                          "The string should not be longer than 16 characters to avoid warnings regarding "
0087                          "Joiliet extensions which induce this restriction.",
0088                          "K3b data project" );
0089 
0090     for ( int i = 0; i < FS_CUSTOM; ++i ) {
0091         s_fsPresets[i].setVolumeID( vid );
0092     }
0093 
0094     // Linux-only
0095     s_fsPresets[FS_LINUX_ONLY].setCreateJoliet( false );
0096     s_fsPresets[FS_LINUX_ONLY].setISOallow31charFilenames( true );
0097 
0098     // Linux + Windows
0099     s_fsPresets[FS_LINUX_AND_WIN].setCreateJoliet( true );
0100     s_fsPresets[FS_LINUX_AND_WIN].setJolietLong( true );
0101     s_fsPresets[FS_LINUX_AND_WIN].setISOallow31charFilenames( true );
0102 
0103     // UDF
0104     s_fsPresets[FS_UDF].setCreateJoliet( false );
0105     s_fsPresets[FS_UDF].setCreateUdf( true );
0106     s_fsPresets[FS_UDF].setISOallow31charFilenames( true );
0107 
0108     // DOS comp
0109     s_fsPresets[FS_DOS_COMP].setCreateJoliet( false );
0110     s_fsPresets[FS_DOS_COMP].setCreateRockRidge( false );
0111     s_fsPresets[FS_DOS_COMP].setISOallow31charFilenames( false );
0112     s_fsPresets[FS_DOS_COMP].setISOLevel( 1 );
0113 
0114     s_fsPresetsInitialized = true;
0115 }
0116 
0117 
0118 
0119 K3b::DataImageSettingsWidget::DataImageSettingsWidget( QWidget* parent )
0120     : QWidget( parent ),
0121       m_fileSystemOptionsShown(true)
0122 {
0123     setupUi( this );
0124 
0125     m_customFsDlg = new DataAdvancedImageSettingsDialog( this );
0126     m_volDescDlg = new DataVolumeDescDialog( this );
0127 
0128     connect( m_buttonCustomFilesystems, SIGNAL(clicked()),
0129              this, SLOT(slotCustomFilesystems()) );
0130     connect( m_buttonMoreVolDescFields, SIGNAL(clicked()),
0131              this, SLOT(slotMoreVolDescFields()) );
0132     connect( m_comboSpaceHandling, SIGNAL(activated(int)),
0133              this, SLOT(slotSpaceHandlingChanged(int)) );
0134 
0135     for( int i = 0; i < FS_MAX; ++i )
0136         m_comboFilesystems->addItem( s_fsPresetNames[i].toString() );
0137 
0138     if( !s_fsPresetsInitialized )
0139         initializePresets();
0140 
0141     m_comboFilesystems->setWhatsThis(
0142         i18n("<p><b>File System Presets</b>"
0143              "<p>K3b provides the following file system Presets which allow for a quick selection "
0144              "of the most frequently used settings.")
0145         + "<p><b>" + s_fsPresetNames[0].toString() + "</b><br>"
0146         + i18n("The file system is optimized for usage on Linux/Unix systems. This mainly means that "
0147                "it uses the Rock Ridge extensions to provide long filenames, symbolic links, and POSIX "
0148                "compatible file permissions.")
0149         + "<p><b>" + s_fsPresetNames[1].toString() + "</b><br>"
0150         + i18n("In addition to the settings for Linux/Unix the file system contains a Joliet tree which "
0151                "allows for long file names on Windows which does not support the Rock Ridge extensions. "
0152                "Be aware that the file name length is restricted to 103 characters.")
0153         + "<p><b>" + s_fsPresetNames[2].toString() + "</b><br>"
0154         + i18n("The file system has additional UDF entries attached to it. This raises the maximal file "
0155                "size to 4 GB. Be aware that the UDF support in K3b is limited.")
0156         + "<p><b>" + s_fsPresetNames[3].toString() + "</b><br>"
0157         + i18n("The file system is optimized for compatibility with old systems. That means file names "
0158                "are restricted to 8.3 characters and no symbolic links or file permissions are supported.") );
0159 }
0160 
0161 
0162 K3b::DataImageSettingsWidget::~DataImageSettingsWidget()
0163 {
0164 }
0165 
0166 
0167 void K3b::DataImageSettingsWidget::showFileSystemOptions( bool b )
0168 {
0169     m_groupFileSystem->setVisible(b);
0170     m_groupSymlinks->setVisible(b);
0171     m_groupWhitespace->setVisible(b);
0172 
0173     m_fileSystemOptionsShown = b;
0174 }
0175 
0176 
0177 void K3b::DataImageSettingsWidget::slotSpaceHandlingChanged( int i )
0178 {
0179     m_editReplace->setEnabled( i == WS_REPLACE );
0180 }
0181 
0182 
0183 void K3b::DataImageSettingsWidget::slotCustomFilesystems()
0184 {
0185     // load settings in custom window
0186     if( m_comboFilesystems->currentIndex() != FS_CUSTOM ) {
0187         m_customFsDlg->load( s_fsPresets[m_comboFilesystems->currentIndex()] );
0188     }
0189 
0190     // store the current settings in case the user cancels the changes
0191     K3b::IsoOptions o;
0192     m_customFsDlg->save( o );
0193 
0194     if( m_customFsDlg->exec() == QDialog::Accepted ) {
0195         slotFilesystemsChanged();
0196     }
0197     else {
0198         // reload the old settings discarding any changes
0199         m_customFsDlg->load( o );
0200     }
0201 }
0202 
0203 
0204 void K3b::DataImageSettingsWidget::slotFilesystemsChanged()
0205 {
0206     if( !m_fileSystemOptionsShown )
0207         return;
0208 
0209     // new custom entry
0210     QStringList s;
0211     if( m_customFsDlg->m_checkRockRidge->isChecked() )
0212         s += i18n("Rock Ridge");
0213     if( m_customFsDlg->m_checkJoliet->isChecked() )
0214         s += i18n("Joliet");
0215     if( m_customFsDlg->m_checkUdf->isChecked() )
0216         s += i18n("UDF");
0217     if( s.isEmpty() )
0218         m_comboFilesystems->setItemText( FS_CUSTOM,i18n("Custom (ISO 9660 only)") );
0219     else
0220         m_comboFilesystems->setItemText( FS_CUSTOM,i18n("Custom (%1)", s.join(", ") ) );
0221 
0222     // see if any of the presets is loaded
0223     m_comboFilesystems->setCurrentIndex( FS_CUSTOM );
0224     K3b::IsoOptions o;
0225     m_customFsDlg->save( o );
0226     for( int i = 0; i < FS_CUSTOM; ++i ) {
0227         if( compareAdvancedOptions( o, s_fsPresets[i] ) ) {
0228             qDebug() << i18n("(K3b::DataImageSettingsWidget) found preset settings: ") << s_fsPresetNames[i].toString();
0229             m_comboFilesystems->setCurrentIndex( i );
0230             break;
0231         }
0232     }
0233 
0234     if( m_comboFilesystems->currentIndex() == FS_CUSTOM ) {
0235         if( !m_customFsDlg->m_checkRockRidge->isChecked() ) {
0236             KMessageBox::information( this,
0237                                       i18n("<p>Be aware that it is not recommended to disable the Rock Ridge "
0238                                            "Extensions. There is no disadvantage in enabling Rock Ridge (except "
0239                                            "for a very small space overhead) but a lot of advantages."
0240                                            "<p>Without Rock Ridge Extensions symbolic links are not supported "
0241                                            "and will always be followed as if the \"Follow Symbolic Links\" option "
0242                                            "was enabled."),
0243                                       i18n("Rock Ridge Extensions Disabled"),
0244                                       "warning_about_rock_ridge" );
0245         }
0246 
0247         if( !m_customFsDlg->m_checkJoliet->isChecked() )
0248             KMessageBox::information( this,
0249                                       i18n("<p>Be aware that without the Joliet extensions Windows "
0250                                            "systems will not be able to display long filenames. You "
0251                                            "will only see the ISO 9660 filenames."
0252                                            "<p>If you do not intend to use the CD/DVD on a Windows "
0253                                            "system it is safe to disable Joliet."),
0254                                       i18n("Joliet Extensions Disabled"),
0255                                       "warning_about_joliet" );
0256     }
0257 }
0258 
0259 
0260 void K3b::DataImageSettingsWidget::slotMoreVolDescFields()
0261 {
0262     // update dlg to current state
0263     m_volDescDlg->m_editVolumeName->setText( m_editVolumeName->text() );
0264 
0265     // remember old settings
0266     K3b::IsoOptions o;
0267     m_volDescDlg->save( o );
0268 
0269     m_volDescDlg->m_editVolumeName->setFocus( Qt::PopupFocusReason );
0270 
0271     // exec dlg
0272     if( m_volDescDlg->exec() == QDialog::Accepted ) {
0273         // accept new entries
0274         m_volDescDlg->save( o );
0275         m_editVolumeName->setText( o.volumeID() );
0276     }
0277     else {
0278         // restore old settings
0279         m_volDescDlg->load( o );
0280     }
0281 }
0282 
0283 
0284 void K3b::DataImageSettingsWidget::load( const K3b::IsoOptions& o )
0285 {
0286     m_customFsDlg->load( o );
0287     m_volDescDlg->load( o );
0288 
0289     slotFilesystemsChanged();
0290 
0291     if( o.discardBrokenSymlinks() )
0292         m_comboSymlinkHandling->setCurrentIndex( SYM_DISCARD_BROKEN );
0293     else if( o.discardSymlinks() )
0294         m_comboSymlinkHandling->setCurrentIndex( SYM_DISCARD_ALL );
0295     else if( o.followSymbolicLinks() )
0296         m_comboSymlinkHandling->setCurrentIndex( SYM_FOLLOW );
0297     else
0298         m_comboSymlinkHandling->setCurrentIndex( SYM_NO_CHANGE );
0299 
0300     switch( o.whiteSpaceTreatment() ) {
0301     case K3b::IsoOptions::strip:
0302         m_comboSpaceHandling->setCurrentIndex( WS_STRIP );
0303         break;
0304     case K3b::IsoOptions::extended:
0305         m_comboSpaceHandling->setCurrentIndex( WS_EXTENDED_STRIP );
0306         break;
0307     case K3b::IsoOptions::replace:
0308         m_comboSpaceHandling->setCurrentIndex( WS_REPLACE );
0309         break;
0310     default:
0311         m_comboSpaceHandling->setCurrentIndex( WS_NO_CHANGE );
0312     }
0313     slotSpaceHandlingChanged( m_comboSpaceHandling->currentIndex() );
0314 
0315     m_editReplace->setText( o.whiteSpaceTreatmentReplaceString() );
0316 
0317     m_editVolumeName->setText( o.volumeID() );
0318 }
0319 
0320 
0321 void K3b::DataImageSettingsWidget::save( K3b::IsoOptions& o )
0322 {
0323     if( m_comboFilesystems->currentIndex() != FS_CUSTOM )
0324         m_customFsDlg->load( s_fsPresets[m_comboFilesystems->currentIndex()] );
0325     m_customFsDlg->save( o );
0326 
0327     m_volDescDlg->save( o );
0328 
0329     o.setDiscardSymlinks( m_comboSymlinkHandling->currentIndex() == SYM_DISCARD_ALL );
0330     o.setDiscardBrokenSymlinks( m_comboSymlinkHandling->currentIndex() == SYM_DISCARD_BROKEN );
0331     o.setFollowSymbolicLinks( m_comboSymlinkHandling->currentIndex() == SYM_FOLLOW );
0332 
0333     switch( m_comboSpaceHandling->currentIndex() ) {
0334     case WS_STRIP:
0335         o.setWhiteSpaceTreatment( K3b::IsoOptions::strip );
0336         break;
0337     case WS_EXTENDED_STRIP:
0338         o.setWhiteSpaceTreatment( K3b::IsoOptions::extended );
0339         break;
0340     case WS_REPLACE:
0341         o.setWhiteSpaceTreatment( K3b::IsoOptions::replace );
0342         break;
0343     default:
0344         o.setWhiteSpaceTreatment( K3b::IsoOptions::noChange );
0345     }
0346     o.setWhiteSpaceTreatmentReplaceString( m_editReplace->text() );
0347 
0348     o.setVolumeID( m_editVolumeName->text() );
0349 }
0350 
0351 #include "moc_k3bdataimagesettingswidget.cpp"