]>
cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/statusbarspaceinfo.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "statusbarspaceinfo.h"
23 #include "spaceinfoobserver.h"
30 StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget
* parent
) :
31 KCapacityBar(KCapacityBar::DrawTextInline
, parent
),
36 StatusBarSpaceInfo::~StatusBarSpaceInfo()
40 void StatusBarSpaceInfo::setUrl(const KUrl
& url
)
45 m_observer
->setUrl(url
);
50 KUrl
StatusBarSpaceInfo::url() const
55 void StatusBarSpaceInfo::showEvent(QShowEvent
* event
)
57 KCapacityBar::showEvent(event
);
58 m_observer
.reset(new SpaceInfoObserver(m_url
, this));
60 connect(m_observer
.data(), SIGNAL(valuesChanged()), this, SLOT(slotValuesChanged()));
63 void StatusBarSpaceInfo::hideEvent(QHideEvent
* event
)
66 KCapacityBar::hideEvent(event
);
69 void StatusBarSpaceInfo::slotValuesChanged()
72 const quint64 size
= m_observer
->size();
74 setText(i18nc("@info:status", "Unknown size"));
78 const quint64 available
= m_observer
->available();
79 const quint64 used
= size
- available
;
80 const int percentUsed
= qRound(100.0 * qreal(used
) / qreal(size
));
82 setText(i18nc("@info:status Free disk space", "%1 free", KIO::convertSize(available
)));
83 setUpdatesEnabled(false);
84 setValue(percentUsed
);
85 setUpdatesEnabled(true);
90 #include "statusbarspaceinfo.moc"