22 #include <tdeglobal.h>
23 #include <tqapplication.h>
25 #include <config-tdefile.h>
27 using namespace TDEIO;
29 KDirSize::KDirSize(
const KURL & directory )
30 : TDEIO::Job(false ), m_bAsync(true), m_totalSize(0L), m_totalFiles(0L), m_totalSubdirs(0L)
32 startNextJob( directory );
35 KDirSize::KDirSize(
const KFileItemList & lstItems )
36 : TDEIO::Job(false ), m_bAsync(true), m_totalSize(0L), m_totalFiles(0L), m_totalSubdirs(0L), m_lstItems(lstItems)
38 TQTimer::singleShot( 0,
this, TQ_SLOT(processList()) );
41 void KDirSize::processList()
43 while (!m_lstItems.isEmpty())
45 KFileItem * item = m_lstItems.first();
46 m_lstItems.removeFirst();
47 if ( !item->isLink() )
51 kdDebug(tdefile_area) <<
"KDirSize::processList dir -> listing" << endl;
52 KURL url = item->url();
58 m_totalSize += item->size();
64 kdDebug(tdefile_area) <<
"KDirSize::processList finished" << endl;
70 void KDirSize::startNextJob(
const KURL & url )
72 TDEIO::ListJob * listJob = TDEIO::listRecursive( url,
false );
73 connect( listJob, TQ_SIGNAL(entries( TDEIO::Job *,
74 const TDEIO::UDSEntryList& )),
75 TQ_SLOT( slotEntries( TDEIO::Job*,
76 const TDEIO::UDSEntryList& )));
80 void KDirSize::slotEntries( TDEIO::Job*,
const TDEIO::UDSEntryList & list )
82 static const TQString& dot = TDEGlobal::staticQString(
"." );
83 static const TQString& dotdot = TDEGlobal::staticQString(
".." );
84 TDEIO::UDSEntryListConstIterator it = list.begin();
85 TDEIO::UDSEntryListConstIterator end = list.end();
86 for (; it != end; ++it) {
87 TDEIO::UDSEntry::ConstIterator it2 = (*it).begin();
88 TDEIO::filesize_t size = 0;
92 for( ; it2 != (*it).end(); it2++ ) {
93 switch( (*it2).m_uds ) {
97 case TDEIO::UDS_LINK_DEST:
98 isLink = !(*it2).m_str.isEmpty();
100 case TDEIO::UDS_SIZE:
101 size = ((*it2).m_long);
103 case TDEIO::UDS_FILE_TYPE:
104 isDir = S_ISDIR((*it2).m_long);
112 else if ( name != dotdot )
147 void KDirSize::slotResult( TDEIO::Job * job )
149 kdDebug(tdefile_area) <<
" KDirSize::slotResult( TDEIO::Job * job ) m_lstItems:" << m_lstItems.count() << endl;
150 if ( !m_lstItems.isEmpty() )
159 TDEIO::Job::slotResult( job );
163 void KDirSize::virtual_hook(
int id,
void* data )
164 { TDEIO::Job::virtual_hook(
id, data ); }
166 #include "kdirsize.moc"
Computes a directory size (similar to "du", but doesn't give the same results since we simply sum up ...
static KDirSize * dirSizeJob(const KURL &directory)
Asynchronous method.
static TDEIO::filesize_t dirSize(const KURL &directory)
Synchronous method - you get the result as soon as the call returns.