File indexing completed on 2024-05-12 04:51:06
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef K3B_ISO_IMAGER_H 0008 #define K3B_ISO_IMAGER_H 0009 0010 #include "k3bjob.h" 0011 #include "k3bmkisofshandler.h" 0012 #include "k3bprocess.h" 0013 0014 #include <QStringList> 0015 0016 class QTextStream; 0017 class QTemporaryFile; 0018 0019 namespace K3b { 0020 class DataDoc; 0021 class DirItem; 0022 class FileItem; 0023 0024 class IsoImager : public Job, public MkisofsHandler 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 IsoImager( DataDoc*, JobHandler*, QObject* parent = 0 ); 0030 ~IsoImager() override; 0031 0032 bool active() const override; 0033 0034 int size() const { return m_mkisofsPrintSizeResult; } 0035 0036 bool hasBeenCanceled() const override; 0037 0038 QIODevice* ioDevice() const; 0039 0040 public Q_SLOTS: 0041 /** 0042 * Starts the actual image creation. Always run init() 0043 * before starting the image creation 0044 */ 0045 void start() override; 0046 void cancel() override; 0047 0048 /** 0049 * Initialize the image creator. This calculates the image size and performs 0050 * some checks on the project. 0051 * 0052 * The initialization process also finishes with the finished() signal just 0053 * like a normal job operation. Get the calculated image size via size() 0054 */ 0055 virtual void init(); 0056 0057 /** 0058 * Only calculates the size of the image without the additional checks in 0059 * init() 0060 * 0061 * Use this if you need to recalculate the image size for example if the 0062 * multisession info changed. 0063 */ 0064 virtual void calculateSize(); 0065 0066 /** 0067 * If dev == 0 IsoImager will ignore the data in the previous session. 0068 * This is usable for CD-Extra. 0069 */ 0070 void setMultiSessionInfo( const QString&, Device::Device* dev = 0 ); 0071 0072 QString multiSessionInfo() const; 0073 Device::Device* multiSessionImportDevice() const; 0074 0075 Device::Device* device() const { return m_device; } 0076 DataDoc* doc() const { return m_doc; } 0077 0078 protected: 0079 void handleMkisofsProgress( int ) override; 0080 void handleMkisofsInfoMessage( const QString&, int ) override; 0081 0082 virtual bool addMkisofsParameters( bool printSize = false ); 0083 0084 /** 0085 * calls writePathSpec, writeRRHideFile, and writeJolietHideFile 0086 */ 0087 bool prepareMkisofsFiles(); 0088 0089 /** 0090 * The dummy dir is used to create dirs on the iso-filesystem. 0091 * 0092 * @return an empty dummy dir for use with DirItems. 0093 */ 0094 QString dummyDir( DirItem* ); 0095 0096 void outputData(); 0097 void initVariables(); 0098 virtual void cleanup(); 0099 void clearDummyDirs(); 0100 0101 /** 0102 * @returns The number of entries written or -1 on error 0103 */ 0104 virtual int writePathSpec(); 0105 bool writeRRHideFile(); 0106 bool writeJolietHideFile(); 0107 bool writeSortWeightFile(); 0108 0109 // used by writePathSpec 0110 virtual int writePathSpecForDir( DirItem* dirItem, QTextStream& stream ); 0111 virtual void writePathSpecForFile( FileItem*, QTextStream& stream ); 0112 QString escapeGraftPoint( const QString& str ); 0113 0114 QTemporaryFile* m_pathSpecFile; 0115 QTemporaryFile* m_rrHideFile; 0116 QTemporaryFile* m_jolietHideFile; 0117 QTemporaryFile* m_sortWeightFile; 0118 0119 Process* m_process; 0120 0121 bool m_canceled; 0122 0123 protected Q_SLOTS: 0124 virtual void slotReceivedStderr( const QString& ); 0125 virtual void slotProcessExited( int, QProcess::ExitStatus ); 0126 0127 private Q_SLOTS: 0128 void slotCollectMkisofsPrintSizeStderr( const QString& ); 0129 void slotCollectMkisofsPrintSizeStdout( const QString& ); 0130 void slotMkisofsPrintSizeFinished(); 0131 void slotDataPreparationDone( bool success ); 0132 0133 private: 0134 void startSizeCalculation(); 0135 0136 class Private; 0137 Private* d; 0138 0139 DataDoc* m_doc; 0140 0141 bool m_noDeepDirectoryRelocation; 0142 0143 bool m_importSession; 0144 QString m_multiSessionInfo; 0145 Device::Device* m_device; 0146 0147 // used for mkisofs -print-size parsing 0148 QString m_collectedMkisofsPrintSizeStdout; 0149 QString m_collectedMkisofsPrintSizeStderr; 0150 int m_mkisofsPrintSizeResult; 0151 0152 QStringList m_tempFiles; 0153 0154 bool m_containsFilesWithMultibleBackslashes; 0155 0156 // used to create a unique session id 0157 static int s_imagerSessionCounter; 0158 0159 int m_sessionNumber; 0160 }; 0161 } 0162 0163 #endif