File indexing completed on 2024-04-21 04:57:57
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 TreeMap classes. 0009 */ 0010 0011 #ifndef FSVIEW_H 0012 #define FSVIEW_H 0013 0014 #include <QMap> 0015 #include <QFileInfo> 0016 #include <QString> 0017 0018 #include <kconfiggroup.h> 0019 0020 #include "treemap.h" 0021 #include "inode.h" 0022 #include "scan.h" 0023 0024 class QMenu; 0025 class KConfig; 0026 0027 /* Cached Metric info config */ 0028 class MetricEntry 0029 { 0030 public: 0031 MetricEntry() 0032 { 0033 size = 0.0; 0034 fileCount = 0; 0035 dirCount = 0; 0036 } 0037 MetricEntry(double s, unsigned int f, unsigned int d) 0038 { 0039 size = s; 0040 fileCount = f; 0041 dirCount = d; 0042 } 0043 0044 double size; 0045 unsigned int fileCount, dirCount; 0046 }; 0047 0048 /** 0049 * The root object for the treemap. 0050 * 0051 * Does context menu handling and 0052 * asynchronous file size update 0053 */ 0054 class FSView : public TreeMapWidget, public ScanListener 0055 { 0056 Q_OBJECT 0057 0058 public: 0059 enum ColorMode { None = 0, Depth, Name, Owner, Group, Mime }; 0060 0061 explicit FSView(Inode *, QWidget *parent = nullptr); 0062 ~FSView() override; 0063 0064 KConfig *config() 0065 { 0066 return _config; 0067 } 0068 0069 void setPath(const QString &); 0070 QString path() 0071 { 0072 return _path; 0073 } 0074 int pathDepth() 0075 { 0076 return _pathDepth; 0077 } 0078 0079 void setColorMode(FSView::ColorMode cm); 0080 FSView::ColorMode colorMode() const 0081 { 0082 return _colorMode; 0083 } 0084 // returns true if string was recognized 0085 bool setColorMode(const QString &); 0086 QString colorModeString() const; 0087 0088 void requestUpdate(Inode *); 0089 0090 /* Implementation of listener interface of ScanManager. 0091 * Used to calculate progress info */ 0092 void scanFinished(ScanDir *) override; 0093 0094 void stop(); 0095 0096 static bool getDirMetric(const QString &, double &, unsigned int &, unsigned int &); 0097 static void setDirMetric(const QString &, double, unsigned int, unsigned int); 0098 void saveMetric(KConfigGroup *); 0099 void saveFSOptions(); 0100 0101 // for color mode 0102 void addColorItems(QMenu *, int); 0103 0104 QList<QUrl> selectedUrls(); 0105 0106 public slots: 0107 void selected(TreeMapItem *); 0108 void contextMenu(TreeMapItem *, const QPoint &); 0109 void quit(); 0110 void doUpdate(); 0111 void doRedraw(); 0112 void colorActivated(QAction *); 0113 0114 signals: 0115 void started(); 0116 void progress(int percent, int dirs, const QString &lastDir); 0117 void completed(int dirs); 0118 0119 protected: 0120 void keyPressEvent(QKeyEvent *) override; 0121 0122 private: 0123 KConfig *_config; 0124 ScanManager _sm; 0125 0126 // when a contextMenu is shown, we don't allow async. refreshing 0127 bool _allowRefresh; 0128 // a cache for directory sizes with long lasting updates 0129 static QMap<QString, MetricEntry> _dirMetric; 0130 0131 // current root path 0132 int _pathDepth; 0133 QString _path; 0134 0135 // for progress info 0136 int _progressPhase; 0137 int _chunkData1, _chunkData2, _chunkData3; 0138 int _chunkSize1, _chunkSize2, _chunkSize3; 0139 int _progress, _progressSize, _dirsFinished; 0140 ScanDir *_lastDir; 0141 0142 ColorMode _colorMode; 0143 int _colorID; 0144 }; 0145 0146 #endif // FSVIEW_H 0147