]>
cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/spaceinfoobserver.cpp
0d8f5f2fe73f2e41d152891534c4439a8fe7ee1e
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),
31 m_mountPointObserver
= MountPointObserver::observerForUrl(url
);
32 m_mountPointObserver
->ref();
33 connect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
34 m_mountPointObserver
->update();
37 SpaceInfoObserver::~SpaceInfoObserver()
39 if (m_mountPointObserver
) {
40 m_mountPointObserver
->deref();
41 m_mountPointObserver
= nullptr;
45 quint64
SpaceInfoObserver::size() const
50 quint64
SpaceInfoObserver::available() const
52 return m_dataAvailable
;
55 void SpaceInfoObserver::setUrl(const QUrl
& url
)
57 MountPointObserver
* newObserver
= MountPointObserver::observerForUrl(url
);
58 if (newObserver
!= m_mountPointObserver
) {
59 if (m_mountPointObserver
) {
60 disconnect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
61 m_mountPointObserver
->deref();
62 m_mountPointObserver
= nullptr;
65 m_mountPointObserver
= newObserver
;
66 m_mountPointObserver
->ref();
67 connect(m_mountPointObserver
, &MountPointObserver::spaceInfoChanged
, this, &SpaceInfoObserver::spaceInfoChanged
);
69 // If newObserver is cached it won't call update until the next timer update,
70 // so update the observer now.
71 m_mountPointObserver
->update();
75 void SpaceInfoObserver::update()
77 if (m_mountPointObserver
) {
78 m_mountPointObserver
->update();
82 void SpaceInfoObserver::spaceInfoChanged(quint64 size
, quint64 available
)
84 // Make sure that the size has actually changed
85 if (m_dataSize
!= size
|| m_dataAvailable
!= available
|| !m_hasData
) {
88 m_dataAvailable
= available
;