dolphin/src/statusbar/spaceinfoobserver.h
Frank Reininghaus 4fe788f115 Keep the "free space" information updated in all visible views
The old code would watch the free space on a mount point, i.e.,
determine the free space again, in 10-second intervals, only until the
view became invisible once (even if it was invisible only for a very
short moment, i.e., while splitting the view).

This commit ensures that the mount point is watched again as soon as
the corresponding view becomes visible again.

Moreover, the object that watches the free space for a mount point is
shared among all views that show URLs that belong to this mount point.
To achieve this, there is a central cache which can be used to obtain
an existing MountPointObserver for a certain path. If necessary, a new
MountPointObserver is created and added to the cache.

The MountPointObserver is removed from the cache and destroyed only if
no views use it any more, and no new users appear until the next update
(which happens every 10 seconds). This prevents that the free space is
measured repeatedly when changing the current directory on the same
mount point.

Many thanks to Emmanuel Pescosta for the initial ideas to factor out
the "free space" code and to establish a central storage for the
"observer" objects, and for providing many good suggestions how to
improve the code!

BUG: 327708
REVIEW: 118208
FIXED-IN: 4.14.0
2014-05-22 18:42:17 +02:00

52 lines
1.9 KiB
C++

/***************************************************************************
* Copyright (C) 2014 by Frank Reininghaus <frank78ac@googlemail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef SPACEINFOOBSERVER_H
#define SPACEINFOOBSERVER_H
#include <QObject>
class KUrl;
class MountPointObserver;
class SpaceInfoObserver : public QObject
{
Q_OBJECT
public:
explicit SpaceInfoObserver(const KUrl& url, QObject* parent = 0);
virtual ~SpaceInfoObserver();
quint64 size() const;
quint64 available() const;
void setUrl(const KUrl& url);
signals:
/**
* This signal is emitted if the information that size() and/or available() will return has changed.
*/
void valuesChanged();
private:
MountPointObserver* m_mountPointObserver;
};
#endif