File indexing completed on 2024-05-12 04:51:03

0001 /*
0002     SPDX-FileCopyrightText: 2003-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-FileCopyrightText: 2011 Michal Malek <michalm@jabster.pl>
0004     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 
0010 #ifndef K3BDATADOC_H
0011 #define K3BDATADOC_H
0012 
0013 #include "k3bdoc.h"
0014 
0015 #include "k3b_export.h"
0016 
0017 #include <KIO/Global>
0018 
0019 class QString;
0020 class QDomDocument;
0021 class QDomElement;
0022 
0023 namespace K3b {
0024     class DataItem;
0025     class RootItem;
0026     class DirItem;
0027     class Job;
0028     class BootItem;
0029     class Iso9660Directory;
0030     class IsoOptions;
0031 
0032     namespace Device {
0033         class Device;
0034     }
0035 
0036 
0037     /**
0038      *@author Sebastian Trueg
0039      */
0040     class LIBK3B_EXPORT DataDoc : public Doc
0041     {
0042         Q_OBJECT
0043 
0044     public:
0045         explicit DataDoc( QObject* parent = 0 );
0046         ~DataDoc() override;
0047 
0048         Type type() const override { return DataProject; }
0049         QString typeString() const override { return QString::fromLatin1("data"); }
0050 
0051         QString name() const override;
0052 
0053         /**
0054          * The supported media types based on the project size
0055          * and settings (example: if writing mode == TAO we force
0056          * CD media)
0057          */
0058         Device::MediaTypes supportedMediaTypes() const override;
0059 
0060         enum MultiSessionMode {
0061             /**
0062              * Let the DataJob decide if to close the CD or not.
0063              * The decision is based on the state of the inserted media
0064              * (appendable/closed), the size of the project (will it fill
0065              * up the CD?), and the free space on the inserted media.
0066              */
0067             AUTO,
0068             NONE,
0069             START,
0070             CONTINUE,
0071             FINISH
0072         };
0073 
0074         RootItem* root() const;
0075 
0076         bool newDocument() override;
0077         void clear() override;
0078 
0079         KIO::filesize_t size() const override;
0080 
0081         /**
0082          * This is used for multisession where size() also returns the imported session's size
0083          */
0084         KIO::filesize_t burningSize() const override;
0085         Msf length() const override;
0086         virtual Msf burningLength() const;
0087 
0088         /**
0089          * Simply deletes the item if it is removable (meaning isRemovable() returns true.
0090          * Be aware that you can remove items simply by deleting them even if isRemovable()
0091          * returns false.
0092          */
0093         void removeItem( DataItem* item );
0094         void removeItems( DirItem* parent, int start, int count );
0095 
0096         /**
0097          * Simply calls reparent.
0098          */
0099         void moveItem( DataItem* item, DirItem* newParent );
0100         void moveItems( const QList<DataItem*>& itemList, DirItem* newParent );
0101 
0102         DirItem* addEmptyDir( const QString& name, DirItem* parent );
0103 
0104         QString treatWhitespace( const QString& );
0105 
0106         BurnJob* newBurnJob( JobHandler* hdl, QObject* parent = 0 ) override;
0107 
0108         MultiSessionMode multiSessionMode() const;
0109         void setMultiSessionMode( MultiSessionMode mode );
0110 
0111         int dataMode() const;
0112         void setDataMode( int m );
0113 
0114         void setVerifyData( bool b );
0115         bool verifyData() const;
0116 
0117         static bool nameAlreadyInDir( const QString&, DirItem* );
0118 
0119         /**
0120          * Most of the options that map to the mkisofs parameters are grouped
0121          * together in the IsoOptions class to allow easy saving to and loading
0122          * from a KConfig object.
0123          */
0124         const IsoOptions& isoOptions() const;
0125         void setIsoOptions( const IsoOptions& isoOptions );
0126 
0127         QList<BootItem*> bootImages();
0128         DataItem* bootCataloge();
0129 
0130         DirItem* bootImageDir();
0131 
0132         /**
0133          * Create a boot item and also create a boot catalog file in case none
0134          * exists in the project.
0135          *
0136          * Calling this method has the same effect like creating a new BootItem
0137          * instance manually and then calling createBootCatalogeItem.
0138          *
0139          * \return The new boot item on success or 0 in case a file with the same
0140          *         name already exists.
0141          */
0142         BootItem* createBootItem( const QString& filename, DirItem* bootDir = 0 );
0143 
0144         /**
0145          * Create a new boot catalog item.
0146          * For now this is not called automatically for internal reasons.
0147          *
0148          * Call this if you create boot items manually instead of using createBootItem.
0149          *
0150          * The boot catalog is automatically deleted once the last boot item is removed
0151          * from the doc.
0152          *
0153          * \return The new boot catalog item or the old one if it already exists.
0154          */
0155         DataItem* createBootCatalogeItem( DirItem* bootDir );
0156 
0157         /**
0158          * This will prepare the filenames as written to the image.
0159          * These filenames are saved in DataItem::writtenName
0160          */
0161         void prepareFilenames();
0162 
0163         /**
0164          * Returns true if filenames need to be cut due to the limitations of Joliet.
0165          *
0166          * This is only valid after a call to @p prepareFilenames()
0167          */
0168         bool needToCutFilenames() const;
0169 
0170         QList<DataItem*> needToCutFilenameItems() const;
0171 
0172         /**
0173          * Imports a session into the project. This will create SessionImportItems
0174          * and properly set the imported session size.
0175          * Some settings will be adjusted to the imported session (joliet, rr).
0176          *
0177          * Be aware that this method is blocking.
0178          *
0179          * \return true if the old session was successfully imported, false if no
0180          *         session could be found.
0181          *
0182          * \see clearImportedSession()
0183          */
0184         bool importSession( Device::Device*, int session );
0185 
0186         /**
0187          * The session number that has been imported.
0188          * \return The number of the imported session or 0 if no session information
0189          * was available (last track imported) or -1 if no session was imported.
0190          */
0191         int importedSession() const;
0192 
0193         /**
0194          * Searches for an item by it's local path.
0195          *
0196          * NOT IMPLEMENTED YET!
0197          *
0198          * \return The items that correspond to the specified local path.
0199          */
0200         QList<DataItem*> findItemByLocalPath( const QString& path ) const;
0201 
0202     public Q_SLOTS:
0203         void addUrls( const QList<QUrl>& urls ) override;
0204 
0205         /**
0206          * Add urls synchronously
0207          * This method adds files recursively including symlinks, hidden, and system files.
0208          * If a file already exists the new file's name will be appended a number.
0209          */
0210         virtual void addUrlsToDir( const QList<QUrl>& urls, K3b::DirItem* dir );
0211 
0212         void clearImportedSession();
0213 
0214         /**
0215          * Just a convenience method to prevent using setIsoOptions for this
0216          * often used value.
0217          */
0218         void setVolumeID( const QString& );
0219 
0220     Q_SIGNALS:
0221         void itemsAboutToBeInserted( K3b::DirItem* parent, int start, int end );
0222         void itemsAboutToBeRemoved( K3b::DirItem* parent, int start, int end );
0223         void itemsInserted( K3b::DirItem* parent, int start, int end );
0224         void itemsRemoved( K3b::DirItem* parent, int start, int end );
0225         void volumeIdChanged();
0226         void importedSessionChanged( int importedSession );
0227 
0228     protected:
0229         /** reimplemented from Doc */
0230         bool loadDocumentData( QDomElement* root ) override;
0231         /** reimplemented from Doc */
0232         bool saveDocumentData( QDomElement* ) override;
0233 
0234         void saveDocumentDataOptions( QDomElement& optionsElem );
0235         void saveDocumentDataHeader( QDomElement& headerElem );
0236         bool loadDocumentDataOptions( QDomElement optionsElem );
0237         bool loadDocumentDataHeader( QDomElement optionsElem );
0238 
0239     private:
0240         void prepareFilenamesInDir( DirItem* dir );
0241         void createSessionImportItems( const Iso9660Directory*, DirItem* parent );
0242 
0243         /**
0244          * used by DirItem to inform about removed items.
0245          */
0246         void beginInsertItems( DirItem* parent, int start, int end );
0247         void endInsertItems( DirItem* parent, int start, int end );
0248         void beginRemoveItems( DirItem* parent, int start, int end );
0249         void endRemoveItems( DirItem* parent, int start, int end );
0250 
0251         /**
0252          * load recursively
0253          */
0254         bool loadDataItem( QDomElement& e, DirItem* parent );
0255         /**
0256          * save recursively
0257          */
0258         void saveDataItem( DataItem* item, QDomDocument* doc, QDomElement* parent );
0259 
0260         void informAboutNotFoundFiles();
0261 
0262         class Private;
0263         Private* d;
0264 
0265         friend class MixedDoc;
0266         friend class DirItem;
0267     };
0268 }
0269 
0270 #endif