]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/spaceinfoobserver.cpp
9125a9308a51fc8f406f12d931f7380e06e8f5e9
[dolphin.git] / src / statusbar / spaceinfoobserver.cpp
1 /***************************************************************************
2 * Copyright (C) 2014 by Frank Reininghaus <frank78ac@googlemail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "spaceinfoobserver.h"
21
22 #include "mountpointobserver.h"
23
24 #include <KUrl>
25
26 SpaceInfoObserver::SpaceInfoObserver(const KUrl& url, QObject* parent) :
27 QObject(parent),
28 m_mountPointObserver(0)
29 {
30 if (url.isLocalFile()) {
31 m_mountPointObserver = MountPointObserver::observerForPath(url.toLocalFile());
32 m_mountPointObserver->ref();
33 connect(m_mountPointObserver, SIGNAL(spaceInfoChanged()), this, SIGNAL(valuesChanged()));
34 }
35 }
36
37 SpaceInfoObserver::~SpaceInfoObserver()
38 {
39 if (m_mountPointObserver) {
40 m_mountPointObserver->deref();
41 m_mountPointObserver = 0;
42 }
43 }
44
45 quint64 SpaceInfoObserver::size() const
46 {
47 if (m_mountPointObserver && m_mountPointObserver->spaceInfo().isValid()) {
48 return m_mountPointObserver->spaceInfo().size();
49 } else {
50 return 0;
51 }
52 }
53
54 quint64 SpaceInfoObserver::available() const
55 {
56 if (m_mountPointObserver && m_mountPointObserver->spaceInfo().isValid()) {
57 return m_mountPointObserver->spaceInfo().available();
58 } else {
59 return 0;
60 }
61 }
62
63 void SpaceInfoObserver::setUrl(const KUrl& url)
64 {
65 if (url.isLocalFile()) {
66 MountPointObserver* newObserver = MountPointObserver::observerForPath(url.toLocalFile());
67 if (newObserver != m_mountPointObserver) {
68 if (m_mountPointObserver) {
69 disconnect(m_mountPointObserver, SIGNAL(spaceInfoChanged()), this, SIGNAL(valuesChanged()));
70 m_mountPointObserver->deref();
71 m_mountPointObserver = 0;
72 }
73
74 m_mountPointObserver = newObserver;
75 m_mountPointObserver->ref();
76 connect(m_mountPointObserver, SIGNAL(spaceInfoChanged()), this, SIGNAL(valuesChanged()));
77
78 emit valuesChanged();
79 }
80 } else {
81 if (m_mountPointObserver) {
82 disconnect(m_mountPointObserver, SIGNAL(spaceInfoChanged()), this, SIGNAL(valuesChanged()));
83 m_mountPointObserver->deref();
84 m_mountPointObserver = 0;
85
86 emit valuesChanged();
87 }
88 }
89 }