]>
cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/mountpointobserver.h
2 * SPDX-FileCopyrightText: 2014 Frank Reininghaus <frank78ac@googlemail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef MOUNTPOINTOBSERVER_H
8 #define MOUNTPOINTOBSERVER_H
16 * A MountPointObserver can be used to determine the free space on a mount
17 * point. It will then check the free space periodically, and emit the signal
18 * spaceInfoChanged() if the return value of spaceInfo() has changed.
20 * Since multiple users which watch paths on the same mount point can share
21 * a MountPointObserver, it is not possible to create a MountPointObserver
22 * manually. Instead, the function observerForPath(QString&) should be called,
23 * which returns either an existing or a newly created MountPointObserver for
24 * the mount point where the path is mounted. observerForPath(QString&) looks
25 * for a suitable MountPointObserver in an internal cache and creates new
26 * MountPointObservers and adds them to the cache if necessary.
28 * Reference counting is used to keep track of the number of users, and to
29 * decide when the object can be deleted. A user of this class should call
30 * the method ref() when it starts using it, and deref() when it does not need
31 * the MountPointObserver any more.
33 * The object will not be deleted immediately if the reference count reaches
34 * zero. The object will only be destroyed when the next periodic update of
35 * the free space information happens, and the reference count is still zero.
36 * This approach makes it possible to re-use the object if a new user requests
37 * the free space for the same mount point before the next update.
39 class MountPointObserver
: public QObject
43 explicit MountPointObserver(const QUrl
&url
, QObject
*parent
= nullptr);
44 ~MountPointObserver() override
50 * Call this function to indicate that the caller intends to continue using this object. An
51 * internal reference count is increased then. When the observer is not needed any more,
52 * deref() should be called, which decreases the reference count again.
60 * This function can be used to indicate that the caller does not need this MountPointObserver
61 * any more. Internally, a reference count is decreased. If the reference count is zero while
62 * update() is called, the object deletes itself.
67 Q_ASSERT(m_referenceCount
>= 0);
71 * Returns a MountPointObserver for the given \a url. If the caller intends to continue using
72 * the returned object, it must call its ref() method.
74 static MountPointObserver
*observerForUrl(const QUrl
&url
);
78 * This signal is emitted when the size has been retrieved.
80 void spaceInfoChanged(quint64 size
, quint64 available
);
84 * If this slot is invoked, MountPointObserver starts a new driveSize job
85 * to get the drive's size.
90 void freeSpaceResult(KJob
*job
);
96 friend class MountPointObserverCache
;