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 <QThread>
10#include <QMutex>
11#include <QMultiMap>
12#include <QDateTime>
13
14namespace Marble
15{
16
17// Worker object that lives inside the new Thread
18class FileStorageWatcherThread : public QObject
19{
21
22 public:
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
35 public 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
62 private Q_SLOTS:
63 /**
64 * Ensures that the cache doesn't exceed limits.
65 */
66 void ensureCacheSize();
67
68 private:
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
88// Lives inside main thread
89class FileStorageWatcher : public QThread
90{
92
93 public:
94 /**
95 * Creates a new FileStorageWatcher, which is a thread watching the
96 * space Marble takes on the hard drive and deletes files if necessary.
97 *
98 * @param dataDirectory The directory where the data is stored
99 * @param parent The parent of the object.
100 */
101 explicit FileStorageWatcher( const QString &dataDirectory = QString(), QObject * parent = nullptr );
102
103 ~FileStorageWatcher() override;
104
105 /**
106 * Returns the limit of the cache in bytes.
107 */
108 quint64 cacheLimit();
109
110 public Q_SLOTS:
111 /**
112 * Sets the limit of the cache in @p bytes.
113 */
114 void setCacheLimit( quint64 bytes );
115
116 /**
117 * Add @p bytes to the current cache size.
118 * So FileStorageWatcher is aware of the current cache size.
119 */
120 void addToCurrentSize( qint64 bytes );
121
122 /**
123 * Setting current cache size to 0.
124 */
125 void resetCurrentSize();
126
127
128 Q_SIGNALS:
129 void sizeChanged( qint64 bytes );
130 void cleared();
131
132 protected:
133 /**
134 * The function being called at starting Thread.
135 * The thread is started by QThread::start().
136 */
137 void run() override;
138
139 private:
140 Q_DISABLE_COPY( FileStorageWatcher )
141
142 QString m_dataDirectory;
143 FileStorageWatcherThread *m_thread;
144 QMutex *m_limitMutex;
145 quint64 m_limit;
146 bool m_started;
147 bool m_quitting;
148};
149
150}
151
152#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
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.