delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kioslave / trash / discspaceutil.cpp
blobb61736f10f8c695d9e6f98778b6c43f98bde1619
1 /*
2 This file is part of the KDE project
4 Copyright (C) 2008 Tobias Koenig <tokoe@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include <QtCore/QDirIterator>
23 #include <QtCore/QFileInfo>
25 #include <kdiskfreespaceinfo.h>
26 #include <kdebug.h>
27 #include <kio/netaccess.h>
28 #include <kio/directorysizejob.h>
30 #include "discspaceutil.h"
32 DiscSpaceUtil::DiscSpaceUtil( const QString &directory )
33 : mDirectory( directory ),
34 mFullSize( 0 )
36 calculateFullSize();
39 qulonglong DiscSpaceUtil::sizeOfPath( const QString &path )
41 KIO::DirectorySizeJob* job = KIO::directorySize( KUrl(path) );
42 job->setUiDelegate( 0 );
43 bool ok = KIO::NetAccess::synchronousRun( job, 0 );
44 return ok?job->totalSize():0;
47 double DiscSpaceUtil::usage( qulonglong additional ) const
49 if ( mFullSize == 0 )
50 return 0;
52 qulonglong sum = sizeOfPath( mDirectory );
53 sum += additional;
55 return (((double)sum*100)/(double)mFullSize);
58 qulonglong DiscSpaceUtil::size() const
60 return mFullSize;
63 QString DiscSpaceUtil::mountPoint() const
65 return mMountPoint;
68 void DiscSpaceUtil::calculateFullSize()
70 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( mDirectory );
71 if ( info.isValid() ) {
72 mFullSize = info.size();
73 mMountPoint = info.mountPoint();