Marble

FileStorageWatcher.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
4//
5
6#ifndef MARBLE_FILESTORAGEWATCHER_H
7#define MARBLE_FILESTORAGEWATCHER_H
8
9#include <QDateTime>
10#include <QMultiMap>
11#include <QMutex>
12#include <QThread>
13
14namespace Marble
15{
16
17// Worker object that lives inside the new Thread
18class FileStorageWatcherThread : public QObject
19{
21
22public:
23 explicit FileStorageWatcherThread(const QString &dataDirectory, QObject *parent = nullptr);
24
25 ~FileStorageWatcherThread() override;
26
27 quint64 cacheLimit();
28
30 /**
31 * Is emitted when a variable has changed.
32 */
33 void variableChanged();
34
35public Q_SLOTS:
36 /**
37 * Sets the limit of the cache in @p bytes.
38 */
39 void setCacheLimit(quint64 bytes);
40
41 /**
42 * Add @p bytes to the current cache size.
43 * So FileStorageWatcher is aware of the current cache size.
44 */
45 void addToCurrentSize(qint64 bytes);
46
47 /**
48 * Setting current cache size to 0.
49 */
50 void resetCurrentSize();
51
52 /**
53 * Stop doing things that take a long time to quit.
54 */
55 void prepareQuit();
56
57 /**
58 * Getting the current size of the data stored on the disc
59 */
60 void getCurrentCacheSize();
61
62private Q_SLOTS:
63 /**
64 * Ensures that the cache doesn't exceed limits.
65 */
66 void ensureCacheSize();
67
68private:
69 Q_DISABLE_COPY(FileStorageWatcherThread)
70
71 /**
72 * Returns true if it is necessary to delete files.
73 */
74 bool keepDeleting() const;
75
76 QString m_dataDirectory;
78 quint64 m_cacheLimit;
79 quint64 m_cacheSoftLimit;
80 quint64 m_currentCacheSize;
81 int m_filesDeleted;
82 bool m_deleting;
83 QMutex m_limitMutex;
84 bool m_willQuit;
85};
86
87// Lives inside main thread
88class FileStorageWatcher : public QThread
89{
91
92public:
93 /**
94 * Creates a new FileStorageWatcher, which is a thread watching the
95 * space Marble takes on the hard drive and deletes files if necessary.
96 *
97 * @param dataDirectory The directory where the data is stored
98 * @param parent The parent of the object.
99 */
100 explicit FileStorageWatcher(const QString &dataDirectory = QString(), QObject *parent = nullptr);
101
102 ~FileStorageWatcher() override;
103
104 /**
105 * Returns the limit of the cache in bytes.
106 */
107 quint64 cacheLimit();
108
109public Q_SLOTS:
110 /**
111 * Sets the limit of the cache in @p bytes.
112 */
113 void setCacheLimit(quint64 bytes);
114
115 /**
116 * Add @p bytes to the current cache size.
117 * So FileStorageWatcher is aware of the current cache size.
118 */
119 void addToCurrentSize(qint64 bytes);
120
121 /**
122 * Setting current cache size to 0.
123 */
124 void resetCurrentSize();
125
127 void sizeChanged(qint64 bytes);
128 void cleared();
129
130protected:
131 /**
132 * The function being called at starting Thread.
133 * The thread is started by QThread::start().
134 */
135 void run() override;
136
137private:
138 Q_DISABLE_COPY(FileStorageWatcher)
139
140 QString m_dataDirectory;
141 FileStorageWatcherThread *m_thread;
142 QMutex *m_limitMutex;
143 quint64 m_limit;
144 bool m_started;
145 bool m_quitting;
146};
147
148}
149
150#endif
Binds a QML item to a specific geodetic location in screen coordinates.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.