File indexing completed on 2024-04-21 04:57:58

0001 /* This file is part of FSView.
0002     SPDX-FileCopyrightText: 2002, 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 /*
0008  * FSView specialization of TreeMapItem class.
0009  */
0010 
0011 #ifndef INODE_H
0012 #define INODE_H
0013 
0014 #include <QMap>
0015 #include <QFileInfo>
0016 #include <QString>
0017 #include <QPixmap>
0018 
0019 #include <QMimeType>
0020 
0021 #include "treemap.h"
0022 #include "scan.h"
0023 
0024 /**
0025  * A specialized version of a TreeMapItem
0026  * for representation of an Directory or File.
0027  *
0028  * These are dynamically created on drawing.
0029  * The real breadth-first scanning of the filesystem
0030  * uses ScanDir:scan.
0031  */
0032 class Inode: public TreeMapItem, public ScanListener
0033 {
0034 public:
0035     Inode();
0036     Inode(ScanDir *, Inode *);
0037     Inode(ScanFile *, Inode *);
0038     ~Inode() override;
0039     void init(const QString &);
0040 
0041     void setPeer(ScanDir *);
0042 
0043     TreeMapItemList *children() override;
0044 
0045     double value() const override;
0046     double size() const;
0047     unsigned int fileCount() const;
0048     unsigned int dirCount() const;
0049     QString path() const;
0050     QString text(int i) const override;
0051     QPixmap pixmap(int i) const override;
0052     QColor backColor() const override;
0053     QMimeType mimeType() const;
0054 
0055     const QFileInfo &fileInfo() const
0056     {
0057         return _info;
0058     }
0059     ScanDir *dirPeer()
0060     {
0061         return _dirPeer;
0062     }
0063     ScanFile *filePeer()
0064     {
0065         return _filePeer;
0066     }
0067     bool isDir()
0068     {
0069         return (_dirPeer != nullptr);
0070     }
0071 
0072     void sizeChanged(ScanDir *) override;
0073     void scanFinished(ScanDir *) override;
0074     void destroyed(ScanDir *) override;
0075     void destroyed(ScanFile *) override;
0076 
0077 private:
0078     void setMetrics(double, unsigned int);
0079 
0080     QFileInfo _info;
0081     ScanDir *_dirPeer;
0082     ScanFile *_filePeer;
0083 
0084     double _sizeEstimation;
0085     unsigned int _fileCountEstimation, _dirCountEstimation;
0086 
0087     bool _resortNeeded;
0088 
0089     // Cached values, calculated lazy.
0090     // This means a change even in const methods, thus has to be "mutable"
0091     mutable bool _mimeSet, _mimePixmapSet;
0092     mutable QMimeType _mimeType;
0093     mutable QPixmap _mimePixmap;
0094 };
0095 
0096 #endif