diff options
| author | Peter Penz <[email protected]> | 2009-08-01 20:01:51 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2009-08-01 20:01:51 +0000 |
| commit | 99eacd9f56acf4ad21994508ee824b1ce1594be1 (patch) | |
| tree | d1cd73d8073c511ec56095cab664e3bf24c2a99a /src/statusbarspaceinfo.cpp | |
| parent | 67de9286a05b14e8d2611a2acb359b39c86eab3c (diff) | |
move statusbar code into the directory "statusbar"
svn path=/trunk/KDE/kdebase/apps/; revision=1005704
Diffstat (limited to 'src/statusbarspaceinfo.cpp')
| -rw-r--r-- | src/statusbarspaceinfo.cpp | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/src/statusbarspaceinfo.cpp b/src/statusbarspaceinfo.cpp deleted file mode 100644 index c9173b8f9..000000000 --- a/src/statusbarspaceinfo.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz ([email protected]) and * - * and Patrice Tremblay * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "statusbarspaceinfo.h" - -#include <KDiskFreeSpaceInfo> -#include <kmountpoint.h> -#include <klocale.h> -#include <kio/job.h> - -#include <QTimer> -#include <QKeyEvent> - -StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget* parent) : - KCapacityBar(KCapacityBar::DrawTextInline, parent), - m_kBSize(0), - m_timer(0) -{ - setMaximumWidth(200); - setMinimumWidth(200); // something to fix on kcapacitybar (ereslibre) - - // Use a timer to update the space information. Polling is useful - // here, as files can be deleted/added outside the scope of Dolphin. - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(refresh())); -} - -StatusBarSpaceInfo::~StatusBarSpaceInfo() -{ -} - -void StatusBarSpaceInfo::setUrl(const KUrl& url) -{ - m_url = url; - refresh(); -} - -void StatusBarSpaceInfo::showEvent(QShowEvent* event) -{ - KCapacityBar::showEvent(event); - if (!event->spontaneous()) { - refresh(); - m_timer->start(10000); - } -} - -void StatusBarSpaceInfo::hideEvent(QHideEvent* event) -{ - m_timer->stop(); - KCapacityBar::hideEvent(event); -} - -void StatusBarSpaceInfo::refresh() -{ - if (!isVisible()) { - return; - } - - // KDiskFreeSpace is for local paths only - if (!m_url.isLocalFile()) { - setText(i18nc("@info:status", "Unknown size")); - setValue(0); - update(); - return; - } - - KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(m_url.toLocalFile()); - if (!mp) { - return; - } - - KDiskFreeSpaceInfo job = KDiskFreeSpaceInfo::freeSpaceInfo(mp->mountPoint()); - if (!job.isValid()) { - setText(i18nc("@info:status", "Unknown size")); - setValue(0); - update(); - return; - } - - KIO::filesize_t kBSize = job.size() / 1024; - KIO::filesize_t kBUsed = job.used() / 1024; - - const bool valuesChanged = (kBUsed != static_cast<quint64>(value())) || (kBSize != m_kBSize); - if (valuesChanged) { - setText(i18nc("@info:status Free disk space", "%1 free", - KIO::convertSize(job.available()))); - - setUpdatesEnabled(false); - m_kBSize = kBSize; - setValue(kBSize > 0 ? (kBUsed * 100) / kBSize : 0); - setUpdatesEnabled(true); - update(); - } -} - -#include "statusbarspaceinfo.moc" |
