SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kdat / Util.cpp
blob8e065aadb703ca032bdbccf217b02121c8c8814e
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
4 //
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.
9 //
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>
20 #include <kglobal.h>
21 #include <klocale.h>
23 #include "Util.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();
46 int j;
47 for ( j = 0; j < minLen; j++ ) {
48 i = filesTmp.begin();
49 QString first = *i;
50 for ( ; i != filesTmp.end(); ++i ) {
51 if ( first.left(j) != (*i).left(j) ) {
52 // Prefixes are NOT the same.
53 break;
56 if ( i != filesTmp.end() ) {
57 // The common prefix is 0 to j-1, inclusive.
58 break;
61 i = filesTmp.begin();
62 QString prefix = *i;
63 int idx = prefix.lastIndexOf( '/', j );
64 if ( idx > -1 ) {
65 prefix = prefix.left( prefix.lastIndexOf( '/', j ) );
66 } else {
67 prefix = "";
70 return prefix;