1 // KDat - a tar-based DAT archiver
2 // Copyright (C) 1998-2000 Sean Vyain, svyain@mail.tds.net
3 // Copyright (C) 2001-2002 Lawrence Widman, kdat@cardiothink.com
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 Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <qstringlist.h>
25 QString
Util::bytesToString( uint bytes
)
27 return KGlobal::locale()->formatNumber(bytes
, 0);
30 QString
Util::kbytesToString( uint kbytes
)
32 return KGlobal::locale()->formatNumber(kbytes
, 0) + 'k';
35 QString
Util::longestCommonPath( const QStringList
& files
)
37 QStringList filesTmp
= files
;
38 QStringList::Iterator i
= filesTmp
.begin();
40 int minLen
= (*i
).length();
41 for ( ; i
!= filesTmp
.end(); ++i
) {
42 if ( minLen
> (*i
).length() ) {
43 minLen
= (*i
).length();
47 for ( j
= 0; j
< minLen
; j
++ ) {
50 for ( ; i
!= filesTmp
.end(); ++i
) {
51 if ( first
.left(j
) != (*i
).left(j
) ) {
52 // Prefixes are NOT the same.
56 if ( i
!= filesTmp
.end() ) {
57 // The common prefix is 0 to j-1, inclusive.
63 int idx
= prefix
.lastIndexOf( '/', j
);
65 prefix
= prefix
.left( prefix
.lastIndexOf( '/', j
) );