File indexing completed on 2024-05-12 04:51:05
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 K3BFILEITEM_H 0009 #define K3BFILEITEM_H 0010 0011 0012 #include "k3bdataitem.h" 0013 #include "k3bglobals.h" 0014 0015 #include <KIO/Global> 0016 #include <QString> 0017 0018 #include "k3b_export.h" 0019 0020 namespace K3b { 0021 class DataDoc; 0022 class DirItem; 0023 0024 class LIBK3B_EXPORT FileItem : public DataItem 0025 { 0026 public: 0027 /** 0028 * Creates a new FileItem 0029 */ 0030 FileItem( const QString& filePath, DataDoc& doc, const QString& k3bName = 0, const ItemFlags& flags = ItemFlags() ); 0031 0032 /** 0033 * Constructor for optimized file item creation which does no additional stat. 0034 * 0035 * Used by K3b to speedup file item creation. 0036 */ 0037 FileItem( const k3b_struct_stat* stat, 0038 const k3b_struct_stat* followedStat, 0039 const QString& filePath, DataDoc& doc, const QString& k3bName = 0, const ItemFlags& flags = ItemFlags() ); 0040 0041 /** 0042 * Default copy constructor 0043 * Creates a copy of the fileitem. The copy, however, is not an exact duplicate of this item. 0044 * The copy does not have a parent dir set and any old session items are set to 0. 0045 */ 0046 FileItem( const FileItem& ); 0047 0048 ~FileItem() override; 0049 0050 DataItem* copy() const override; 0051 0052 bool exists() const; 0053 0054 QString absIsoPath(); 0055 0056 /** reimplemented from DataItem */ 0057 QString localPath() const override; 0058 0059 /** 0060 * Identification of the files on the local device. 0061 */ 0062 struct Id { 0063 dev_t device; 0064 ino_t inode; 0065 }; 0066 0067 /** 0068 * This is not the normal inode number but it also contains 0069 * the device number. 0070 */ 0071 Id localId() const; 0072 0073 /** 0074 * The id of the file the symlink is pointing to 0075 */ 0076 Id localId( bool followSymlinks ) const; 0077 0078 DirItem* getDirItem() const override; 0079 0080 QString linkDest() const; 0081 0082 QMimeType mimeType() const override; 0083 0084 /** returns true if the item is not a link or 0085 * if the link's destination is part of the compilation */ 0086 bool isValid() const override; 0087 0088 DataItem* replaceItemFromOldSession() const { return m_replacedItemFromOldSession; } 0089 void setReplacedItemFromOldSession( DataItem* item ) { m_replacedItemFromOldSession = item; } 0090 0091 /** 0092 * Normally one does not use this method but DataItem::size() 0093 */ 0094 KIO::filesize_t itemSize( bool followSymlinks ) const override; 0095 0096 private: 0097 void init( const QString& filePath, 0098 const QString& k3bName, 0099 DataDoc& doc, 0100 const k3b_struct_stat* stat, 0101 const k3b_struct_stat* followedStat ); 0102 0103 private: 0104 DataItem* m_replacedItemFromOldSession; 0105 0106 KIO::filesize_t m_size; 0107 KIO::filesize_t m_sizeFollowed; 0108 Id m_id; 0109 Id m_idFollowed; 0110 0111 QString m_localPath; 0112 0113 QMimeType m_mimeType; 0114 }; 0115 0116 bool operator==( const FileItem::Id&, const FileItem::Id& ); 0117 bool operator<( const FileItem::Id&, const FileItem::Id& ); 0118 bool operator>( const FileItem::Id&, const FileItem::Id& ); 0119 } 0120 0121 #endif