diff options
author | Emanoil Kotsev <deloptes@gmail.com> | 2016-10-12 15:20:02 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2016-10-12 15:20:02 +0900 |
commit | ee3091bc41f5cae8be2ba5f8335e0b866edb4711 (patch) | |
tree | 8ffc7ba391bb968e9de33674fa6caf5e9166e5eb /tdeioslave/trash/discspaceutil.cpp | |
parent | 443c910570647f415838e65a1b8add30b00b7dbb (diff) | |
download | tdebase-ee3091bc41f5cae8be2ba5f8335e0b866edb4711.tar.gz tdebase-ee3091bc41f5cae8be2ba5f8335e0b866edb4711.zip |
Added trash limit configuration option
This work is based on original patch created by Tobias Koenig <tokoe@kde.org> for KDE 3.5.9 and later added to KDE 4.2, and available under GPL version 2 License, or any later version.
See also http://tokoe-kde.blogspot.com/2008/08/size-limits-for-trash.html
This relates to bug 1923.
Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdeioslave/trash/discspaceutil.cpp')
-rw-r--r-- | tdeioslave/trash/discspaceutil.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tdeioslave/trash/discspaceutil.cpp b/tdeioslave/trash/discspaceutil.cpp new file mode 100644 index 000000000..a771638fc --- /dev/null +++ b/tdeioslave/trash/discspaceutil.cpp @@ -0,0 +1,112 @@ +/* + This file is part of the KDE project + + Copyright (C) 2008 Tobias Koenig <tokoe@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <tqapplication.h> +#include <tqdir.h> +#include <tqeventloop.h> +#include <tqfileinfo.h> + +#include <kdiskfreesp.h> +#include <kdebug.h> + +#include "discspaceutil.h" + +DiscSpaceUtil::DiscSpaceUtil( const TQString &directory, TQObject *parent ) + : TQObject( parent ), + mDirectory( directory ), + mFullSize( 0 ) +{ + calculateFullSize(); +} + +unsigned long DiscSpaceUtil::sizeOfPath( const TQString &path ) +{ + TQFileInfo info( path ); + if ( !info.exists() ) { + return 0; + } + + if ( info.isFile() ) { + return info.size(); + } else if ( info.isDir() ) { + TQDir dir( path ); + const TQFileInfoList *infos = dir.entryInfoList( TQDir::Files | TQDir::Dirs | TQDir::NoSymLinks ); + TQFileInfoListIterator it( *infos ); + + unsigned long sum = 0; + TQFileInfo *info = 0; + while ( (info = it.current()) != 0 ) { + if ( info->fileName() != "." && info->fileName() != ".." ) + sum += sizeOfPath( info->absFilePath() ); + ++it; + } + + return sum; + } else { + return 0; + } +} + +double DiscSpaceUtil::usage( unsigned long additional ) const +{ + if ( mFullSize == 0 ) + return 0; + + unsigned long sum = sizeOfPath( mDirectory ); + sum += additional; + + sum = sum/1024; // convert to kB + + return (((double)sum*100)/(double)mFullSize); +} + +unsigned long DiscSpaceUtil::size() const +{ + return mFullSize; +} + +TQString DiscSpaceUtil::mountPoint() const +{ + return mMountPoint; +} + +void DiscSpaceUtil::foundMountPoint( const TQString &mountPoint, unsigned long kbSize, unsigned long, unsigned long ) +{ + mFullSize = kbSize; + mMountPoint = mountPoint; +} + +void DiscSpaceUtil::done() +{ + tqApp->eventLoop()->exitLoop(); +} + +void DiscSpaceUtil::calculateFullSize() +{ + KDiskFreeSp *sp = KDiskFreeSp::findUsageInfo( mDirectory ); + connect( sp, SIGNAL( foundMountPoint( const TQString&, unsigned long, unsigned long, unsigned long ) ), + this, SLOT( foundMountPoint( const TQString&, unsigned long, unsigned long, unsigned long ) ) ); + connect( sp, SIGNAL( done() ), this, SLOT( done() ) ); + + tqApp->eventLoop()->enterLoop(); +} + +#include "discspaceutil.moc" |