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

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 
0008 #ifndef K3BDATAITEM_H
0009 #define K3BDATAITEM_H
0010 
0011 #include "k3bmsf.h"
0012 #include "k3b_export.h"
0013 
0014 #include <KIO/Global>
0015 
0016 #include <QMimeType>
0017 #include <QString>
0018 
0019 namespace K3b {
0020     class DirItem;
0021     class DataDoc;
0022 
0023     /**
0024      *@author Sebastian Trueg
0025      */
0026     class LIBK3B_EXPORT DataItem
0027     {
0028     public:
0029         enum ItemFlag {
0030             DIR = 0x1,
0031             FILE = 0x2,
0032             SPECIALFILE = 0x4,
0033             SYMLINK = 0x8,
0034             OLD_SESSION = 0x10,
0035             BOOT_IMAGE = 0x20
0036         };
0037         Q_DECLARE_FLAGS( ItemFlags, ItemFlag )
0038         
0039     public:
0040         explicit DataItem( const ItemFlags& flags = ItemFlags() );
0041 
0042         /**
0043          * Default copy constructor.
0044          *
0045          * The result is an exact copy except that no parent dir it set and, thus, also no doc.
0046          */
0047         DataItem( const DataItem& );
0048 
0049         virtual ~DataItem();
0050 
0051         /**
0052          * Return an exact copy of this data item.
0053          *
0054          * The result is an exact copy except that no parent dir it set and, thus, also no doc.
0055          *
0056          * Implementations should use the default constructor.
0057          */
0058         virtual DataItem* copy() const = 0;
0059 
0060         DirItem* parent() const { return m_parentDir; }
0061 
0062         /**
0063          * Remove this item from it's parent and return a pointer to it.
0064          */
0065         DataItem* take();
0066 
0067         virtual DataDoc* getDoc() const;
0068         virtual QString k3bName() const;
0069         virtual void setK3bName( const QString& );
0070 
0071         /**
0072          * returns the path as defined by the k3b-hierarchy, NOT starting with a slash
0073          * (since this is used for graft-points!)
0074          * directories have a trailing "/"
0075          */
0076         virtual QString k3bPath() const;
0077 
0078         /**
0079          * Returns the name of the item as used on the CD or DVD image.
0080          *
0081          * This is only valid after a call to @p DataDoc::prepareFilenames()
0082          */
0083         QString writtenName() const { return m_writtenName; }
0084 
0085         /**
0086          * \return the pure name used in the Iso9660 tree.
0087          *
0088          * This is only valid after a call to @p DataDoc::prepareFilenames()
0089          */
0090         QString iso9660Name() const { return m_rawIsoName; }
0091 
0092         /**
0093          * Returns the path of the item as written to the CD or DVD image.
0094          *
0095          * This is suited to be used for mkisofs graftpoints.
0096          *
0097          * This is only valid after a call to @p DataDoc::prepareFilenames()
0098          */
0099         virtual QString writtenPath() const;
0100 
0101         virtual QString iso9660Path() const;
0102 
0103         /**
0104          * Used to set the written name by @p DataDoc::prepareFilenames()
0105          */
0106         void setWrittenName( const QString& s ) { m_writtenName = s; }
0107 
0108         /**
0109          * Used to set the pure Iso9660 name by @p DataDoc::prepareFilenames()
0110          */
0111         void setIso9660Name( const QString& s ) { m_rawIsoName = s; }
0112 
0113         virtual DataItem* nextSibling() const;
0114 
0115         /** returns the path to the file on the local filesystem */
0116         virtual QString localPath() const { return QString(); }
0117 
0118         /**
0119          * The size of the item
0120          */
0121         KIO::filesize_t size() const;
0122 
0123         /**
0124          * \return The number of blocks (2048 bytes) occupied by this item.
0125          *         This value equals to ceil(size()/2048)
0126          */
0127         Msf blocks() const;
0128 
0129         /**
0130          * \return the dir of the item (or the item itself if it is a dir)
0131          */
0132         virtual DirItem* getDirItem() const { return parent(); }
0133 
0134         virtual void reparent( DirItem* );
0135 
0136         const ItemFlags& flags() const;
0137         bool isDir() const;
0138         bool isFile() const;
0139         bool isSpecialFile() const;
0140         bool isSymLink() const;
0141         bool isFromOldSession() const;
0142         bool isBootItem() const;
0143 
0144         bool hideOnRockRidge() const;
0145         bool hideOnJoliet() const;
0146 
0147         virtual void setHideOnRockRidge( bool b );
0148         virtual void setHideOnJoliet( bool b );
0149 
0150         virtual long sortWeight() const { return m_sortWeight; }
0151         virtual void setSortWeight( long w ) { m_sortWeight = w; }
0152 
0153         virtual int depth() const;
0154 
0155         virtual bool isValid() const { return true; }
0156 
0157         // these are all needed for special fileitems like
0158         // imported sessions or the movix filesystem
0159         virtual bool isRemoveable() const { return m_bRemoveable; }
0160         virtual bool isMoveable() const { return m_bMovable; }
0161         virtual bool isRenameable() const { return m_bRenameable; }
0162         virtual bool isHideable() const { return m_bHideable; }
0163         virtual bool writeToCd() const { return m_bWriteToCd; }
0164         virtual QString extraInfo() const { return m_extraInfo; }
0165 
0166         /**
0167          * Default implementation returns the default mimetype.
0168          */
0169         virtual QMimeType mimeType() const;
0170 
0171         void setRenameable( bool b ) { m_bRenameable = b; }
0172         void setMoveable( bool b ) { m_bMovable = b; }
0173         void setRemoveable( bool b ) { m_bRemoveable = b; }
0174         void setHideable( bool b ) { m_bHideable = b; }
0175         void setWriteToCd( bool b ) { m_bWriteToCd = b; }
0176         void setExtraInfo( const QString& i ) { m_extraInfo = i; }
0177 
0178     protected:
0179         virtual KIO::filesize_t itemSize( bool followSymlinks ) const = 0;
0180 
0181         /**
0182          * \param followSymlinks If true symlinks will be followed and their
0183          *                       size equals the size of the file they are
0184          *                       pointing to.
0185          *
0186          * \return The number of blocks (2048 bytes) occupied by this item.
0187          */
0188         virtual Msf itemBlocks( bool followSymlinks ) const;
0189 
0190         QString m_k3bName;
0191 
0192         void setFlags( const ItemFlags& flags );
0193         void setParentDir( DirItem* parentDir ) { m_parentDir = parentDir; }
0194 
0195     private:
0196         class Private;
0197         Private* d;
0198 
0199         QString m_writtenName;
0200         QString m_rawIsoName;
0201         QString m_extraInfo;
0202 
0203         DirItem* m_parentDir;
0204         long m_sortWeight;
0205 
0206         bool m_bHideOnRockRidge;
0207         bool m_bHideOnJoliet;
0208         bool m_bRemoveable;
0209         bool m_bRenameable;
0210         bool m_bMovable;
0211         bool m_bHideable;
0212         bool m_bWriteToCd;
0213         
0214         friend class DirItem;
0215     };
0216 }
0217 
0218 #endif