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 
0008 #ifndef K3BSPECIALDATAITEM_H
0009 #define K3BSPECIALDATAITEM_H
0010 
0011 #include "k3bdataitem.h"
0012 #include "k3bdiritem.h"
0013 
0014 #include <KIO/Global>
0015 
0016 namespace K3b {
0017     /**
0018      * This can be used to create fake items like the boot catalog
0019      * It's mainly a DataItem where everything has to be set manually
0020      */
0021     class SpecialDataItem : public DataItem
0022     {
0023     public:
0024         explicit SpecialDataItem( KIO::filesize_t size, const QString& k3bName = QString(), const ItemFlags& flags = ItemFlags() )
0025             : DataItem( flags | SPECIALFILE ),
0026               m_size( size ) {
0027             setK3bName( k3bName );
0028         }
0029 
0030         SpecialDataItem( const SpecialDataItem& item )
0031             : DataItem( item ),
0032               m_specialType( item.m_specialType ),
0033               m_size( item.m_size ) {
0034         }
0035 
0036         ~SpecialDataItem() override {
0037             // remove this from parentdir
0038             if( parent() )
0039                 parent()->takeDataItem( this );
0040         }
0041 
0042         DataItem* copy() const override {
0043             return new SpecialDataItem( *this );
0044         }
0045 
0046         void setSpecialType( const QString& s ) { m_specialType = s; }
0047         QString specialType() const { return m_specialType; }
0048 
0049         bool isSpecialFile() const { return true; }
0050 
0051     protected:
0052         /**
0053          * Normally one does not use this method but DataItem::size()
0054          */
0055         KIO::filesize_t itemSize( bool ) const override { return m_size; }
0056 
0057     private:
0058         QString m_specialType;
0059         KIO::filesize_t m_size;
0060     };
0061 }
0062 
0063 #endif
0064