]>
cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/spaceinfoobserver.cpp
0fb018727c5e7ea68d583c4f633621c886ab3b26
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"
26 SpaceInfoObserver::SpaceInfoObserver(const QUrl
& url
, QObject
* parent
) :
28 m_mountPointObserver(0),
32 m_mountPointObserver
= MountPointObserver::observerForUrl(url
);
33 m_mountPointObserver
->ref();
34 connect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
35 m_mountPointObserver
->update();
38 SpaceInfoObserver::~SpaceInfoObserver()
40 if (m_mountPointObserver
) {
41 m_mountPointObserver
->deref();
42 m_mountPointObserver
= 0;
46 quint64
SpaceInfoObserver::size() const
51 quint64
SpaceInfoObserver::available() const
53 return m_dataAvailable
;
56 void SpaceInfoObserver::setUrl(const QUrl
& url
)
58 MountPointObserver
* newObserver
= MountPointObserver::observerForUrl(url
);
59 if (newObserver
!= m_mountPointObserver
) {
60 if (m_mountPointObserver
) {
61 disconnect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
62 m_mountPointObserver
->deref();
63 m_mountPointObserver
= 0;
66 m_mountPointObserver
= newObserver
;
67 m_mountPointObserver
->ref();
68 connect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
70 // If newObserver is cached it won't call update until the next timer update,
71 // so update the observer now.
72 m_mountPointObserver
->update();
76 void SpaceInfoObserver::spaceInfoChanged(quint64 size
, quint64 available
)
78 // Make sure that the size has actually changed
79 if (m_dataSize
!= size
|| m_dataAvailable
!= available
) {
81 m_dataAvailable
= available
;