File indexing completed on 2024-05-12 04:51:05
0001 /* 0002 SPDX-FileCopyrightText: 2011 Michal Malek <michalm@jabster.pl> 0003 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 0008 #ifndef K3BDIRITEM_H 0009 #define K3BDIRITEM_H 0010 0011 #include "k3bdataitem.h" 0012 #include "k3b_export.h" 0013 0014 #include <KIO/Global> 0015 0016 #include <QList> 0017 #include <QString> 0018 0019 namespace K3b { 0020 class DataDoc; 0021 0022 class LIBK3B_EXPORT DirItem : public DataItem 0023 { 0024 public: 0025 typedef QList<DataItem*> Children; 0026 0027 public: 0028 explicit DirItem( const QString& name, const ItemFlags& flags = ItemFlags() ); 0029 0030 /** 0031 * Default copy constructor. Copies the dir including all children. However, none of the 0032 * children will have set a doc and the copy dir will not have set a parent dir. 0033 */ 0034 DirItem( const DirItem& ); 0035 0036 ~DirItem() override; 0037 0038 DataItem* copy() const override; 0039 0040 DirItem* getDirItem() const override; 0041 0042 Children const& children() const { return m_children; } 0043 DirItem* addDataItem( DataItem* item ); 0044 void addDataItems( Children const& items ); 0045 void removeDataItems( int start, int count ); 0046 DataItem* takeDataItem( DataItem* item ); 0047 Children takeDataItems( int start, int count ); 0048 0049 DataItem* nextSibling() const override; 0050 DataItem* nextChild( DataItem* ) const; 0051 0052 bool alreadyInDirectory( const QString& fileName ) const; 0053 DataItem* find( const QString& filename ) const; 0054 DataItem* findByPath( const QString& ); 0055 0056 long numFiles() const; 0057 long numDirs() const; 0058 0059 bool isEmpty() const { return ( numDirs() + numFiles() == 0 ); } 0060 0061 /** 0062 * returns true if item is a subItem of 0063 * this dir item 0064 * (returns also true if item == this 0065 */ 0066 bool isSubItem( const DataItem* item ) const; 0067 0068 bool isRemoveable() const override; 0069 0070 /** 0071 * Recursively creates a directory. 0072 */ 0073 bool mkdir( const QString& dir ); 0074 0075 void setLocalPath( const QString& p ) { m_localPath = p; } 0076 QString localPath() const override { return m_localPath; } 0077 0078 QMimeType mimeType() const override; 0079 0080 /** 0081 * \reimplemented 0082 */ 0083 bool writeToCd() const override; 0084 0085 protected: 0086 /** 0087 * Normally one does not use this method but DataItem::size() 0088 * 0089 * This method does not take into account the possibility to share the data 0090 * between files with the same inode in an iso9660 filesystem. 0091 * For that one has to use FileCompilationSizeHandler. 0092 */ 0093 KIO::filesize_t itemSize( bool followSymlinks ) const override; 0094 0095 /* 0096 * Normally one does not use this method but DataItem::blocks() 0097 */ 0098 Msf itemBlocks( bool followSymlinks ) const override; 0099 0100 private: 0101 /** 0102 * this recursively updates the size of the directories. 0103 * The size of this dir and the parent dir is updated. 0104 * These values are just used for user information. 0105 */ 0106 void updateSize( DataItem*, bool removed = false ); 0107 /** 0108 * Updates the number of files and directories. These values are 0109 * just used for user information. 0110 */ 0111 void updateFiles( long files, long dirs ); 0112 /** 0113 * Unsets OLD_SESSION flag when directory no longer has 0114 * children from previous sessions 0115 */ 0116 void updateOldSessionFlag(); 0117 0118 bool canAddDataItem( DataItem* item ) const; 0119 void addDataItemImpl( DataItem* item ); 0120 0121 mutable Children m_children; 0122 0123 // size of the items simply added 0124 KIO::filesize_t m_size; 0125 KIO::filesize_t m_followSymlinksSize; 0126 0127 // number of blocks (2048 bytes) used by all the items 0128 long m_blocks; 0129 long m_followSymlinksBlocks; 0130 0131 long m_files; 0132 long m_dirs; 0133 0134 // HACK: store the original path to be able to use it's permissions 0135 // remove this once we have a backup project 0136 QString m_localPath; 0137 }; 0138 0139 0140 class RootItem : public DirItem 0141 { 0142 public: 0143 explicit RootItem( DataDoc& doc ); 0144 ~RootItem() override; 0145 0146 DataDoc* getDoc() const override; 0147 QString k3bName() const override; 0148 void setK3bName( const QString& ) override; 0149 0150 bool isMoveable() const override { return false; } 0151 bool isRemoveable() const override { return false; } 0152 0153 private: 0154 DataDoc& m_doc; 0155 }; 0156 } 0157 #endif