diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2025-08-28 22:44:34 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2025-08-31 23:30:34 +0900 |
commit | f9abd9d505434c9244c03eac708e29a0ca042f6b (patch) | |
tree | 30a197ab4c413849188bc131ff859212e636c821 /src/app/DiskUsage/filelightParts/fileTree.cpp | |
parent | 14d42d284de233f9937becf3fc9ee0dabede3b21 (diff) | |
download | krusader-r14.1.x.tar.gz krusader-r14.1.x.zip |
Restructure source foldersr14.1.x
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 086012dcad8a976a0dabbb7cbc20c9cb612cdfa9)
Diffstat (limited to 'src/app/DiskUsage/filelightParts/fileTree.cpp')
-rw-r--r-- | src/app/DiskUsage/filelightParts/fileTree.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/app/DiskUsage/filelightParts/fileTree.cpp b/src/app/DiskUsage/filelightParts/fileTree.cpp new file mode 100644 index 0000000..0afd4d4 --- /dev/null +++ b/src/app/DiskUsage/filelightParts/fileTree.cpp @@ -0,0 +1,78 @@ +//Author: Max Howell <max.howell@methylblue.com>, (C) 2004 +//Copyright: See COPYING file that comes with this distribution + +#include "fileTree.h" +#include <tdeglobal.h> +#include <tdelocale.h> +#include <tqstring.h> + +//static definitions +const FileSize File::DENOMINATOR[4] = { 1ull, 1ull<<10, 1ull<<20, 1ull<<30 }; +const char File::PREFIX[5][2] = { "", "K", "M", "G", "T" }; + +TQString +File::fullPath( const Directory *root /*= 0*/ ) const +{ + TQString path; + + if( root == this ) root = 0; //prevent returning empty string when there is something we could return + + const File *d; + + for( d = this; d != root && d && d->parent() != 0; d = d->parent() ) + { + if( !path.isEmpty() ) + path = "/" + path; + + path = d->name() + path; + } + + if( d ) + { + while( d->parent() ) + d = d->parent(); + + if( d->directory().endsWith( "/" ) ) + return d->directory() + path; + else + return d->directory() + "/" + path; + } + else + return path; +} + +TQString +File::humanReadableSize( UnitPrefix key /*= mega*/ ) const //FIXME inline +{ + return humanReadableSize( m_size, key ); +} + +TQString +File::humanReadableSize( FileSize size, UnitPrefix key /*= mega*/ ) //static +{ + TQString s; + double prettySize = (double)size / (double)DENOMINATOR[key]; + const TDELocale &locale = *TDEGlobal::locale(); + + if( prettySize >= 0.01 ) + { + if( prettySize < 1 ) s = locale.formatNumber( prettySize, 2 ); + else if( prettySize < 100 ) s = locale.formatNumber( prettySize, 1 ); + else s = locale.formatNumber( prettySize, 0 ); + + s += ' '; + s += PREFIX[key]; + s += 'B'; + } + + if( prettySize < 0.1 ) + { + s += " ("; + s += locale.formatNumber( size / DENOMINATOR[ key ? key - 1 : 0 ], 0 ); + s += ' '; + s += PREFIX[key]; + s += "B)"; + } + + return s; +} |