• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
kdirsize.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kdirsize.h"
21 #include <kdebug.h>
22 #include <tdeglobal.h>
23 #include <tqapplication.h>
24 #include <tqtimer.h>
25 #include <config-tdefile.h>
26 
27 using namespace TDEIO;
28 
29 KDirSize::KDirSize( const KURL & directory )
30  : TDEIO::Job(false /*No GUI*/), m_bAsync(true), m_totalSize(0L), m_totalFiles(0L), m_totalSubdirs(0L)
31 {
32  startNextJob( directory );
33 }
34 
35 KDirSize::KDirSize( const KFileItemList & lstItems )
36  : TDEIO::Job(false /*No GUI*/), m_bAsync(true), m_totalSize(0L), m_totalFiles(0L), m_totalSubdirs(0L), m_lstItems(lstItems)
37 {
38  TQTimer::singleShot( 0, this, TQT_SLOT(processList()) );
39 }
40 
41 void KDirSize::processList()
42 {
43  while (!m_lstItems.isEmpty())
44  {
45  KFileItem * item = m_lstItems.first();
46  m_lstItems.removeFirst();
47  if ( !item->isLink() )
48  {
49  if ( item->isDir() )
50  {
51  kdDebug(tdefile_area) << "KDirSize::processList dir -> listing" << endl;
52  KURL url = item->url();
53  startNextJob( url );
54  return; // we'll come back later, when this one's finished
55  }
56  else
57  {
58  m_totalSize += item->size();
59 // no long long with kdDebug()
60 // kdDebug(tdefile_area) << "KDirSize::processList file -> " << m_totalSize << endl;
61  }
62  }
63  }
64  kdDebug(tdefile_area) << "KDirSize::processList finished" << endl;
65  if ( !m_bAsync )
66  tqApp->exit_loop();
67  emitResult();
68 }
69 
70 void KDirSize::startNextJob( const KURL & url )
71 {
72  TDEIO::ListJob * listJob = TDEIO::listRecursive( url, false /* no GUI */ );
73  connect( listJob, TQT_SIGNAL(entries( TDEIO::Job *,
74  const TDEIO::UDSEntryList& )),
75  TQT_SLOT( slotEntries( TDEIO::Job*,
76  const TDEIO::UDSEntryList& )));
77  addSubjob( listJob );
78 }
79 
80 void KDirSize::slotEntries( TDEIO::Job*, const TDEIO::UDSEntryList & list )
81 {
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;
89  bool isLink = false;
90  bool isDir = false;
91  TQString name;
92  for( ; it2 != (*it).end(); it2++ ) {
93  switch( (*it2).m_uds ) {
94  case TDEIO::UDS_NAME:
95  name = (*it2).m_str;
96  break;
97  case TDEIO::UDS_LINK_DEST:
98  isLink = !(*it2).m_str.isEmpty();
99  break;
100  case TDEIO::UDS_SIZE:
101  size = ((*it2).m_long);
102  break;
103  case TDEIO::UDS_FILE_TYPE:
104  isDir = S_ISDIR((*it2).m_long);
105  break;
106  default:
107  break;
108  }
109  }
110  if ( name == dot )
111  m_totalSize += size;
112  else if ( name != dotdot )
113  {
114  if (!isLink)
115  m_totalSize += size;
116  if (!isDir)
117  m_totalFiles++;
118  else
119  m_totalSubdirs++;
120  //kdDebug(tdefile_area) << name << ":" << size << endl;
121  }
122  }
123 }
124 
125 //static
126 KDirSize * KDirSize::dirSizeJob( const KURL & directory )
127 {
128  return new KDirSize( directory ); // useless - but consistent with other jobs
129 }
130 
131 //static
132 KDirSize * KDirSize::dirSizeJob( const KFileItemList & lstItems )
133 {
134  return new KDirSize( lstItems );
135 }
136 
137 //static
138 TDEIO::filesize_t KDirSize::dirSize( const KURL & directory )
139 {
140  KDirSize * dirSize = dirSizeJob( directory );
141  dirSize->setSync();
142  tqApp->enter_loop();
143  return dirSize->totalSize();
144 }
145 
146 
147 void KDirSize::slotResult( TDEIO::Job * job )
148 {
149  kdDebug(tdefile_area) << " KDirSize::slotResult( TDEIO::Job * job ) m_lstItems:" << m_lstItems.count() << endl;
150  if ( !m_lstItems.isEmpty() )
151  {
152  subjobs.remove(job); // Remove job, but don't kill this job.
153  processList();
154  }
155  else
156  {
157  if ( !m_bAsync )
158  tqApp->exit_loop();
159  TDEIO::Job::slotResult( job );
160  }
161 }
162 
163 void KDirSize::virtual_hook( int id, void* data )
164 { TDEIO::Job::virtual_hook( id, data ); }
165 
166 #include "kdirsize.moc"
TDEIO
Definition: kimagefilepreview.h:26
KDirSize::dirSize
static TDEIO::filesize_t dirSize(const KURL &directory)
Synchronous method - you get the result as soon as the call returns.
Definition: kdirsize.cpp:138
KDirSize
Computes a directory size (similar to "du", but doesn't give the same results since we simply sum up ...
Definition: kdirsize.h:30
KDirSize::dirSizeJob
static KDirSize * dirSizeJob(const KURL &directory)
Asynchronous method.
Definition: kdirsize.cpp:126
KDirSize::totalSize
TDEIO::filesize_t totalSize() const
Definition: kdirsize.h:42

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.8.8
This website is maintained by Timothy Pearson.