1 /*
2     SPDX-FileCopyrightText: 1998-2010 Sebastian Trueg <trueg@k3b.org>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "k3bisooptions.h"
7 #include "k3bcore.h"
8 #include "k3bversion.h"
9 #include "k3bglobals.h"
10 #include "k3b_i18n.h"
11 
12 #include <KConfig>
13 #include <KConfigGroup>
14 #include <QString>
15 
16 
IsoOptions()17 K3b::IsoOptions::IsoOptions()
18     : m_defaultVolumeIDSet(false),
19       m_volumeIDSet(false),
20       m_applicationID( QString("K3B THE CD KREATOR (C) 1998-2018 SEBASTIAN TRUEG, MICHAL MALEK AND LESLIE ZHAI") ),
21       m_systemId( K3b::systemName().toUpper() ),
22       m_whiteSpaceTreatmentReplaceString( "_" )
23 {
24     m_createRockRidge = true;
25     m_createJoliet = true;
26     m_createUdf = false;
27     m_ISOallowLowercase = false;
28     m_ISOallowPeriodAtBegin = false;
29     m_ISOallow31charFilenames = true;
30     m_ISOomitVersionNumbers = false;
31     m_ISOomitTrailingPeriod = false;
32     m_ISOmaxFilenameLength = false;
33     m_ISOrelaxedFilenames = false;
34     m_ISOnoIsoTranslate = false;
35     m_ISOallowMultiDot = false;
36     m_ISOuntranslatedFilenames = false;
37     m_followSymbolicLinks = false;
38     m_createTRANS_TBL = false;
39     m_hideTRANS_TBL = false;
40     m_jolietLong = true;
41 
42     m_doNotCacheInodes = true;
43     m_doNotImportSession = false;
44 
45     m_isoLevel = 3;
46 
47     m_discardSymlinks = false;
48     m_discardBrokenSymlinks = false;
49 
50     m_preserveFilePermissions = false;
51 
52     m_whiteSpaceTreatment = noChange;
53 
54     m_volumeSetSize = 1;
55     m_volumeSetNumber = 1;
56 }
57 
58 
volumeID() const59 const QString& K3b::IsoOptions::volumeID() const {
60     if (m_volumeIDSet)
61         return m_volumeID;
62     else {
63         if (!m_defaultVolumeIDSet) {
64             m_defaultVolumeIDSet = true;
65             m_defaultVolumeID = i18nc( "This is the default volume identifier of a data project created by K3b. "
66                  "The string should not be longer than 16 characters to avoid warnings regarding "
67                  "Joiliet extensions which induce this restriction.",
68                  "K3b data project" );
69         }
70         return m_defaultVolumeID;
71     }
72 }
73 
74 
save(KConfigGroup c,bool saveVolumeDesc)75 void K3b::IsoOptions::save( KConfigGroup c, bool saveVolumeDesc )
76 {
77     if( saveVolumeDesc ) {
78         c.writeEntry( "volume id", volumeID() );
79         c.writeEntry( "application id", m_applicationID );
80         c.writeEntry( "preparer", m_preparer );
81         c.writeEntry( "publisher", m_publisher );
82         c.writeEntry( "system id", m_systemId );
83         c.writeEntry( "volume set id", m_volumeSetId );
84         c.writeEntry( "volume set size", m_volumeSetSize );
85         c.writeEntry( "volume set number", m_volumeSetNumber );
86         c.writeEntry( "abstract file", m_abstractFile );
87         c.writeEntry( "copyright file", m_copyrightFile );
88         c.writeEntry( "bibliograph file", m_bibliographFile );
89     }
90 
91     c.writeEntry( "rock_ridge", m_createRockRidge );
92     c.writeEntry( "joliet", m_createJoliet );
93     c.writeEntry( "udf", m_createUdf );
94 
95     // save iso-level
96     c.writeEntry( "iso_level", m_isoLevel );
97 
98     c.writeEntry( "create TRANS_TBL", m_createTRANS_TBL );
99     c.writeEntry( "hide TRANS_TBL", m_hideTRANS_TBL );
100     c.writeEntry( "untranslated filenames", m_ISOuntranslatedFilenames );
101     c.writeEntry( "allow 31 character filenames", m_ISOallow31charFilenames );
102     c.writeEntry( "max ISO filenames", m_ISOmaxFilenameLength );
103     c.writeEntry( "allow beginning period", m_ISOallowPeriodAtBegin );
104     c.writeEntry( "relaxed filenames", m_ISOrelaxedFilenames );
105     c.writeEntry( "omit version numbers", m_ISOomitVersionNumbers );
106     c.writeEntry( "omit trailing period", m_ISOomitTrailingPeriod );
107     c.writeEntry( "no iSO translation", m_ISOnoIsoTranslate );
108     c.writeEntry( "allow multiple dots", m_ISOallowMultiDot );
109     c.writeEntry( "allow lowercase filenames", m_ISOallowLowercase );
110     c.writeEntry( "follow symbolic links", m_followSymbolicLinks );
111 
112     c.writeEntry( "joliet long", m_jolietLong );
113 
114     c.writeEntry( "do not cache inodes", m_doNotCacheInodes );
115     c.writeEntry( "do not import last session", m_doNotImportSession );
116 
117     // save whitespace-treatment
118     switch( m_whiteSpaceTreatment ) {
119     case strip:
120         c.writeEntry( "white_space_treatment", "strip" );
121         break;
122     case extended:
123         c.writeEntry( "white_space_treatment", "extended" );
124         break;
125     case replace:
126         c.writeEntry( "white_space_treatment", "replace" );
127         break;
128     default:
129         c.writeEntry( "white_space_treatment", "noChange" );
130     }
131 
132     c.writeEntry( "whitespace replace string", m_whiteSpaceTreatmentReplaceString );
133 
134     c.writeEntry( "discard symlinks", discardSymlinks() );
135     c.writeEntry( "discard broken symlinks", discardBrokenSymlinks() );
136 
137     c.writeEntry( "preserve file permissions", m_preserveFilePermissions );
138 }
139 
140 
load(const KConfigGroup & c,bool loadVolumeDesc)141 K3b::IsoOptions K3b::IsoOptions::load( const KConfigGroup& c, bool loadVolumeDesc )
142 {
143     K3b::IsoOptions options;
144 
145     if( loadVolumeDesc ) {
146         options.setVolumeID( c.readEntry( "volume id", options.volumeID() ) );
147         options.setApplicationID( c.readEntry( "application id", options.applicationID() ) );
148         options.setPreparer( c.readEntry( "preparer", options.preparer() ) );
149         options.setPublisher( c.readEntry( "publisher", options.publisher() ) );
150         options.setSystemId( c.readEntry( "system id", options.systemId() ) );
151         options.setVolumeSetId( c.readEntry( "volume set id", options.volumeSetId() ) );
152         options.setVolumeSetSize( c.readEntry( "volume set size", options.volumeSetSize() ) );
153         options.setVolumeSetNumber( c.readEntry( "volume set number", options.volumeSetNumber() ) );
154         options.setAbstractFile( c.readEntry( "abstract file", options.abstractFile() ) );
155         options.setCoprightFile( c.readEntry( "copyright file", options.copyrightFile() ) );
156         options.setBibliographFile( c.readEntry( "bibliograph file", options.bibliographFile() ) );
157     }
158 
159     options.setCreateRockRidge( c.readEntry( "rock_ridge", options.createRockRidge() ) );
160     options.setCreateJoliet( c.readEntry( "joliet", options.createJoliet() ) );
161     options.setCreateUdf( c.readEntry( "udf", options.createUdf() ) );
162 
163     options.setISOLevel( c.readEntry( "iso_level", options.ISOLevel() ) );
164 
165     options.setCreateTRANS_TBL( c.readEntry( "create TRANS_TBL", options.createTRANS_TBL() ) );
166     options.setHideTRANS_TBL( c.readEntry( "hide TRANS_TBL", options.hideTRANS_TBL() ) );
167 
168     //
169     // We need to use the member variables here instead of the access methods
170     // which do not return the actual value of the member variables but the value
171     // representing the use in mkisofs (i.e. ISOomitVersionNumbers is also enabled
172     // if ISOmaxFilenameLength is enabled.
173     //
174     options.setISOuntranslatedFilenames( c.readEntry( "untranslated filenames", options.m_ISOuntranslatedFilenames ) );
175     options.setISOallow31charFilenames( c.readEntry( "allow 31 character filenames", options.m_ISOallow31charFilenames ) );
176     options.setISOmaxFilenameLength( c.readEntry( "max ISO filenames", options.m_ISOmaxFilenameLength ) );
177     options.setISOallowPeriodAtBegin( c.readEntry( "allow beginning period", options.m_ISOallowPeriodAtBegin ) );
178     options.setISOrelaxedFilenames( c.readEntry( "relaxed filenames", options.m_ISOrelaxedFilenames ) );
179     options.setISOomitVersionNumbers( c.readEntry( "omit version numbers", options.m_ISOomitVersionNumbers ) );
180     options.setISOnoIsoTranslate( c.readEntry( "no iSO translation", options.m_ISOnoIsoTranslate ) );
181     options.setISOallowMultiDot( c.readEntry( "allow multiple dots", options.m_ISOallowMultiDot ) );
182     options.setISOallowLowercase( c.readEntry( "allow lowercase filenames", options.m_ISOallowLowercase ) );
183     options.setISOomitTrailingPeriod( c.readEntry( "omit trailing period", options.m_ISOomitTrailingPeriod ) );
184 
185     options.setFollowSymbolicLinks( c.readEntry( "follow symbolic links", options.m_followSymbolicLinks ) );
186 
187     options.setJolietLong( c.readEntry( "joliet long", options.jolietLong() ) );
188 
189     options.setDoNotCacheInodes( c.readEntry( "do not cache inodes", options.doNotCacheInodes() ) );
190     options.setDoNotImportSession( c.readEntry( "no not import last session", options.doNotImportSession() ) );
191 
192     QString w = c.readEntry( "white_space_treatment", "noChange" );
193     if( w == "replace" )
194         options.setWhiteSpaceTreatment( replace );
195     else if( w == "strip" )
196         options.setWhiteSpaceTreatment( strip );
197     else if( w == "extended" )
198         options.setWhiteSpaceTreatment( extended );
199     else
200         options.setWhiteSpaceTreatment( noChange );
201 
202     options.setWhiteSpaceTreatmentReplaceString( c.readEntry( "whitespace replace string", options.whiteSpaceTreatmentReplaceString() ) );
203 
204     options.setDiscardSymlinks( c.readEntry("discard symlinks", options.discardSymlinks() ) );
205     options.setDiscardBrokenSymlinks( c.readEntry("discard broken symlinks", options.discardBrokenSymlinks() ) );
206 
207     options.setPreserveFilePermissions( c.readEntry( "preserve file permissions", options.preserveFilePermissions() ) );
208 
209     return options;
210 }
211 
212 
defaults()213 K3b::IsoOptions K3b::IsoOptions::defaults()
214 {
215     // let the constructor create defaults
216     return K3b::IsoOptions();
217 }
218