1 /* 2 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 8 #ifndef K3BFILEITEM_H 9 #define K3BFILEITEM_H 10 11 12 #include "k3bdataitem.h" 13 #include "k3bglobals.h" 14 15 #include <KIO/Global> 16 #include <QString> 17 18 #include "k3b_export.h" 19 20 namespace K3b { 21 class DataDoc; 22 class DirItem; 23 24 class LIBK3B_EXPORT FileItem : public DataItem 25 { 26 public: 27 /** 28 * Creates a new FileItem 29 */ 30 FileItem( const QString& filePath, DataDoc& doc, const QString& k3bName = 0, const ItemFlags& flags = ItemFlags() ); 31 32 /** 33 * Constructor for optimized file item creation which does no additional stat. 34 * 35 * Used by K3b to speedup file item creation. 36 */ 37 FileItem( const k3b_struct_stat* stat, 38 const k3b_struct_stat* followedStat, 39 const QString& filePath, DataDoc& doc, const QString& k3bName = 0, const ItemFlags& flags = ItemFlags() ); 40 41 /** 42 * Default copy constructor 43 * Creates a copy of the fileitem. The copy, however, is not an exact duplicate of this item. 44 * The copy does not have a parent dir set and any old session items are set to 0. 45 */ 46 FileItem( const FileItem& ); 47 48 ~FileItem() override; 49 50 DataItem* copy() const override; 51 52 bool exists() const; 53 54 QString absIsoPath(); 55 56 /** reimplemented from DataItem */ 57 QString localPath() const override; 58 59 /** 60 * Identification of the files on the local device. 61 */ 62 struct Id { 63 dev_t device; 64 ino_t inode; 65 }; 66 67 /** 68 * This is not the normal inode number but it also contains 69 * the device number. 70 */ 71 Id localId() const; 72 73 /** 74 * The id of the file the symlink is pointing to 75 */ 76 Id localId( bool followSymlinks ) const; 77 78 DirItem* getDirItem() const override; 79 80 QString linkDest() const; 81 82 QMimeType mimeType() const override; 83 84 /** returns true if the item is not a link or 85 * if the link's destination is part of the compilation */ 86 bool isValid() const override; 87 replaceItemFromOldSession()88 DataItem* replaceItemFromOldSession() const { return m_replacedItemFromOldSession; } setReplacedItemFromOldSession(DataItem * item)89 void setReplacedItemFromOldSession( DataItem* item ) { m_replacedItemFromOldSession = item; } 90 91 /** 92 * Normally one does not use this method but DataItem::size() 93 */ 94 KIO::filesize_t itemSize( bool followSymlinks ) const override; 95 96 private: 97 void init( const QString& filePath, 98 const QString& k3bName, 99 DataDoc& doc, 100 const k3b_struct_stat* stat, 101 const k3b_struct_stat* followedStat ); 102 103 private: 104 DataItem* m_replacedItemFromOldSession; 105 106 KIO::filesize_t m_size; 107 KIO::filesize_t m_sizeFollowed; 108 Id m_id; 109 Id m_idFollowed; 110 111 QString m_localPath; 112 113 QMimeType m_mimeType; 114 }; 115 116 bool operator==( const FileItem::Id&, const FileItem::Id& ); 117 bool operator<( const FileItem::Id&, const FileItem::Id& ); 118 bool operator>( const FileItem::Id&, const FileItem::Id& ); 119 } 120 121 #endif 122