File: diskusage.h

package info (click to toggle)
krusader 2%3A2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,448 kB
  • sloc: cpp: 56,112; ansic: 1,187; xml: 811; sh: 23; makefile: 3
file content (200 lines) | stat: -rw-r--r-- 4,169 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
    SPDX-FileCopyrightText: 2004 Csaba Karai <krusader@users.sourceforge.net>
    SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef DISKUSAGE_H
#define DISKUSAGE_H

// QtCore
#include <QEvent>
#include <QHash>
#include <QStack>
#include <QTimer>
#include <QUrl>
// QtGui
#include <QKeyEvent>
#include <QPixmap>
#include <QResizeEvent>
// QtWidgets
#include <QDialog>
#include <QLabel>
#include <QScrollArea>
#include <QStackedWidget>

#include <KSqueezedTextLabel>

#include "filelightParts/fileTree.h"

#define VIEW_LINES 0
#define VIEW_DETAILED 1
#define VIEW_FILELIGHT 2
#define VIEW_LOADER 3

typedef QHash<QString, void *> Properties;

class DUListView;
class DULines;
class DUFilelight;
class QMenu;
class LoaderWidget;
class FileItem;
class FileSystem;

class DiskUsage : public QStackedWidget
{
    Q_OBJECT

public:
    explicit DiskUsage(QString confGroup, QWidget *parent = nullptr);
    ~DiskUsage();

    void load(const QUrl &dirName);
    void close();
    void stopLoad();
    bool isLoading()
    {
        return loading;
    }

    void setView(int view);
    int getActiveView()
    {
        return activeView;
    }

    Directory *getDirectory(QString path);
    File *getFile(const QString &path);

    QString getConfigGroup()
    {
        return configGroup;
    }

    void *getProperty(File *, const QString &);
    void addProperty(File *, const QString &, void *);
    void removeProperty(File *, const QString &);

    int exclude(File *file, bool calcPercents = true, int depth = 0);
    void includeAll();

    int del(File *file, bool calcPercents = true, int depth = 0);

    QString getToolTip(File *);

    void rightClickMenu(const QPoint &, File *, QMenu * = nullptr, const QString & = QString());

    void changeDirectory(Directory *dir);

    Directory *getCurrentDir();
    File *getCurrentFile();

    QPixmap getIcon(const QString &mime);

    QUrl getBaseURL()
    {
        return baseURL;
    }

public slots:
    void dirUp();
    void clear();

signals:
    void enteringDirectory(Directory *);
    void clearing();
    void changed(File *);
    void changeFinished();
    void deleted(File *);
    void deleteFinished();
    void status(QString);
    void viewChanged(int);
    void loadFinished(bool);
    void newSearch();

protected slots:
    void slotLoadDirectory();

protected:
    QHash<QString, Directory *> contentMap;
    QHash<File *, Properties *> propertyMap;

    Directory *currentDirectory;
    KIO::filesize_t currentSize;

    virtual void keyPressEvent(QKeyEvent *) override;
    virtual bool event(QEvent *) override;

    int calculateSizes(Directory *dir = nullptr, bool emitSig = false, int depth = 0);
    int calculatePercents(bool emitSig = false, Directory *dir = nullptr, int depth = 0);
    int include(Directory *dir, int depth = 0);
    void createStatus();
    void executeAction(int, File * = nullptr);

    QUrl baseURL; //< the base URL of loading

    DUListView *listView;
    DULines *lineView;
    DUFilelight *filelightView;
    LoaderWidget *loaderView;

    Directory *root;

    int activeView;

    QString configGroup;

    bool first;
    bool loading;
    bool abortLoading;
    bool clearAfterAbort;
    bool deleting;

    QStack<QString> directoryStack;
    QStack<Directory *> parentStack;

    FileSystem *searchFileSystem;
    FileItem *currentFileItem;
    QList<FileItem *> fileItems;
    Directory *currentParent;
    QString dirToCheck;

    int fileNum;
    int dirNum;
    int viewBeforeLoad;

    QTimer loadingTimer;
};

class LoaderWidget : public QScrollArea
{
    Q_OBJECT

public:
    explicit LoaderWidget(QWidget *parent = nullptr);

    void init();
    void setCurrentURL(const QUrl &url);
    void setValues(int fileNum, int dirNum, KIO::filesize_t total);
    bool wasCancelled()
    {
        return cancelled;
    }

public slots:
    void slotCancelled();

protected:
    QLabel *totalSize;
    QLabel *files;
    QLabel *directories;

    KSqueezedTextLabel *searchedDirectory;
    QWidget *widget;

    bool cancelled;
};

#endif /* __DISK_USAGE_GUI_H__ */