]>
cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/spaceinfoobserver.cpp
692eba7e7a781d52aa5e59acf13426c3cb951cf8
1 /***************************************************************************
2 * Copyright (C) 2014 by Frank Reininghaus <frank78ac@googlemail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "spaceinfoobserver.h"
22 #include "mountpointobserver.h"
24 SpaceInfoObserver::SpaceInfoObserver(const QUrl
& url
, QObject
* parent
) :
26 m_mountPointObserver(nullptr),
30 m_mountPointObserver
= MountPointObserver::observerForUrl(url
);
31 m_mountPointObserver
->ref();
32 connect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
33 m_mountPointObserver
->update();
36 SpaceInfoObserver::~SpaceInfoObserver()
38 if (m_mountPointObserver
) {
39 m_mountPointObserver
->deref();
40 m_mountPointObserver
= nullptr;
44 quint64
SpaceInfoObserver::size() const
49 quint64
SpaceInfoObserver::available() const
51 return m_dataAvailable
;
54 void SpaceInfoObserver::setUrl(const QUrl
& url
)
56 MountPointObserver
* newObserver
= MountPointObserver::observerForUrl(url
);
57 if (newObserver
!= m_mountPointObserver
) {
58 if (m_mountPointObserver
) {
59 disconnect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
60 m_mountPointObserver
->deref();
61 m_mountPointObserver
= nullptr;
64 m_mountPointObserver
= newObserver
;
65 m_mountPointObserver
->ref();
66 connect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
68 // If newObserver is cached it won't call update until the next timer update,
69 // so update the observer now.
70 m_mountPointObserver
->update();
74 void SpaceInfoObserver::update()
76 if (m_mountPointObserver
) {
77 m_mountPointObserver
->update();
81 void SpaceInfoObserver::spaceInfoChanged(quint64 size
, quint64 available
)
83 // Make sure that the size has actually changed
84 if (m_dataSize
!= size
|| m_dataAvailable
!= available
) {
86 m_dataAvailable
= available
;