22 #include "kdirlister.h"
25 #include <tqptrlist.h>
27 #include <tqeventloop.h>
29 #include <tdeapplication.h>
31 #include <tdelocale.h>
32 #include <tdeio/job.h>
33 #include <tdemessagebox.h>
34 #include <tdeglobal.h>
35 #include <tdeglobalsettings.h>
36 #include <kstaticdeleter.h>
37 #include <kprotocolinfo.h>
39 #include "kdirlister_p.h"
44 KDirListerCache* KDirListerCache::s_pSelf = 0;
45 static KStaticDeleter<KDirListerCache> sd_KDirListerCache;
55 KDirListerCache::KDirListerCache(
int maxCount )
56 : itemsCached( maxCount )
58 kdDebug(7004) <<
"+KDirListerCache" << endl;
60 itemsInUse.setAutoDelete(
false );
61 itemsCached.setAutoDelete(
true );
62 urlsCurrentlyListed.setAutoDelete(
true );
63 urlsCurrentlyHeld.setAutoDelete(
true );
64 pendingUpdates.setAutoDelete(
true );
66 connect( kdirwatch, TQT_SIGNAL( dirty(
const KURL& ) ),
67 this, TQT_SLOT( slotFileDirty(
const KURL& ) ) );
68 connect( kdirwatch, TQT_SIGNAL( created(
const TQString& ) ),
69 this, TQT_SLOT( slotFileCreated(
const TQString& ) ) );
70 connect( kdirwatch, TQT_SIGNAL( deleted(
const TQString& ) ),
71 this, TQT_SLOT( slotFileDeleted(
const TQString& ) ) );
74 KDirListerCache::~KDirListerCache()
76 kdDebug(7004) <<
"-KDirListerCache" << endl;
78 itemsInUse.setAutoDelete(
true );
81 urlsCurrentlyListed.clear();
82 urlsCurrentlyHeld.clear();
85 kdirwatch->disconnect(
this );
90 bool KDirListerCache::listDir(
KDirLister *lister,
const KURL& _u,
91 bool _keep,
bool _reload )
100 if ((_u.protocol() ==
"media") && (_u.path() ==
"/")) {
108 TQString urlStr = _url.url();
109 TQString urlReferenceStr = _url.internalReferenceURL();
118 kdDebug(7004) << k_funcinfo << lister <<
" url=" << _url
119 <<
" keep=" << _keep <<
" reload=" << _reload << endl;
127 forgetDirs( lister );
129 lister->d->rootFileItem = 0;
131 else if ( lister->d->lstDirs.find( _url ) != lister->d->lstDirs.end() )
134 stop( lister, _url );
137 forgetDirs( lister, _url,
true );
139 if ( lister->d->url == _url )
140 lister->d->rootFileItem = 0;
143 lister->d->lstDirs.append( _url );
145 if ( lister->d->url.isEmpty() || !_keep )
146 lister->d->url = _url;
148 DirItem *itemU = itemsInUse[urlStr +
":" + urlReferenceStr];
151 if ( !urlsCurrentlyListed[urlStr +
":" + urlReferenceStr] )
158 kdDebug(7004) <<
"listDir: Entry already in use: " << _url << endl;
160 bool oldState = lister->d->complete;
161 lister->d->complete =
false;
165 if ( !lister->d->rootFileItem && lister->d->url == _url ) {
166 lister->d->rootFileItem = itemU->rootItem;
169 lister->addNewItems( *(itemU->lstItems) );
173 assert( urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr] );
174 urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr]->append( lister );
176 lister->d->complete = oldState;
178 lister->emitCompleted( _url );
179 if ( lister->d->complete ) {
183 if ( _reload || !itemU->complete ) {
184 updateDirectory( _url );
187 else if ( !_reload && (itemC = itemsCached.take( urlStr )) )
189 kdDebug(7004) <<
"listDir: Entry in cache: " << _url << endl;
191 itemC->decAutoUpdate();
192 itemsInUse.insert( urlStr +
":" + urlReferenceStr, itemC );
195 bool oldState = lister->d->complete;
196 lister->d->complete =
false;
200 if ( !lister->d->rootFileItem && lister->d->url == _url ) {
201 lister->d->rootFileItem = itemC->rootItem;
204 lister->addNewItems( *(itemC->lstItems) );
207 Q_ASSERT( !urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr] );
208 TQPtrList<KDirLister> *list =
new TQPtrList<KDirLister>;
209 list->append( lister );
210 urlsCurrentlyHeld.insert( urlStr +
":" + urlReferenceStr, list );
212 lister->d->complete = oldState;
214 lister->emitCompleted( _url );
215 if ( lister->d->complete ) {
219 if ( !itemC->complete ) {
220 updateDirectory( _url );
225 kdDebug(7004) <<
"listDir: Entry not in cache or reloaded: " << _url << endl;
227 TQPtrList<KDirLister> *list =
new TQPtrList<KDirLister>;
228 list->append( lister );
229 urlsCurrentlyListed.insert( urlStr +
":" + urlReferenceStr, list );
231 itemsCached.remove( urlStr );
232 itemU =
new DirItem( _url );
233 itemsInUse.insert( urlStr +
":" + urlReferenceStr, itemU );
243 if ( lister->d->url == _url ) {
244 lister->d->rootFileItem = 0;
248 jobs.insert( job, TQValueList<TDEIO::UDSEntry>() );
250 lister->jobStarted( job );
251 lister->connectJob( job );
253 if ( lister->d->window ) {
257 connect( job, TQT_SIGNAL( entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & ) ),
258 this, TQT_SLOT( slotEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & ) ) );
259 connect( job, TQT_SIGNAL( result(
TDEIO::Job * ) ),
260 this, TQT_SLOT( slotResult(
TDEIO::Job * ) ) );
261 connect( job, TQT_SIGNAL( redirection(
TDEIO::Job *,
const KURL & ) ),
262 this, TQT_SLOT( slotRedirection(
TDEIO::Job *,
const KURL & ) ) );
271 kdDebug(7004) <<
"listDir: Entry currently being listed: " << _url << endl;
275 urlsCurrentlyListed[urlStr +
":" + urlReferenceStr]->append( lister );
277 TDEIO::ListJob *job = jobForUrl( urlStr +
":" + urlReferenceStr );
280 lister->jobStarted( job );
281 lister->connectJob( job );
285 if ( !lister->d->rootFileItem && lister->d->url == _url ) {
286 lister->d->rootFileItem = itemU->rootItem;
289 lister->addNewItems( *(itemU->lstItems) );
294 if ( lister->d->autoUpdate ) {
295 itemU->incAutoUpdate();
301 bool KDirListerCache::validURL(
const KDirLister *lister,
const KURL& url )
const
303 if ( !url.isValid() )
305 if ( lister->d->autoErrorHandling )
307 TQString tmp = i18n(
"Malformed URL\n%1").arg( url.prettyURL() );
308 KMessageBox::error( lister->d->errorParent, tmp );
315 if ( lister->d->autoErrorHandling )
318 TQString tmp = i18n(
"Malformed URL\n%1").arg( url.prettyURL() );
319 KMessageBox::error( lister->d->errorParent, tmp );
327 void KDirListerCache::stop(
KDirLister *lister )
332 kdDebug(7004) << k_funcinfo <<
"lister: " << lister << endl;
333 bool stopped =
false;
335 TQDictIterator< TQPtrList<KDirLister> > it( urlsCurrentlyListed );
336 TQPtrList<KDirLister> *listers;
338 while ( (listers = it.current()) )
340 curIndex = listers->findRef( lister );
344 TQString url = it.currentKey();
345 KDirLister* curLister = listers->at( curIndex );
348 bool ret = listers->removeRef( lister );
353 lister->jobDone( job );
357 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[url];
360 holders =
new TQPtrList<KDirLister>;
361 urlsCurrentlyHeld.insert( url, holders );
364 holders->append( lister );
366 emit lister->
canceled( curLister->d->url );
370 if ( listers->isEmpty() )
377 urlsCurrentlyListed.remove( url );
389 lister->d->complete =
true;
396 void KDirListerCache::stop(
KDirLister *lister,
const KURL& _u )
398 TQString urlStr( _u.url(-1) );
399 TQString urlReferenceStr = _u.internalReferenceURL();
403 kdDebug(7004) << k_funcinfo << lister <<
" url=" << _url << endl;
405 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr +
":" + urlReferenceStr];
406 if ( !listers || !listers->removeRef( lister ) )
410 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr];
413 holders =
new TQPtrList<KDirLister>;
414 urlsCurrentlyHeld.insert( urlStr +
":" + urlReferenceStr, holders );
417 holders->append( lister );
420 TDEIO::ListJob *job = jobForUrl( urlStr +
":" + urlReferenceStr );
422 lister->jobDone( job );
427 if ( listers->isEmpty() )
433 urlsCurrentlyListed.remove( urlStr +
":" + urlReferenceStr );
436 if ( lister->numJobs() == 0 )
438 lister->d->complete =
true;
445 void KDirListerCache::setAutoUpdate(
KDirLister *lister,
bool enable )
449 for ( KURL::List::Iterator it = lister->d->lstDirs.begin();
450 it != lister->d->lstDirs.end(); ++it )
453 itemsInUse[(*it).url() +
":" + (*it).internalReferenceURL()]->incAutoUpdate();
456 itemsInUse[(*it).url() +
":" + (*it).internalReferenceURL()]->decAutoUpdate();
461 void KDirListerCache::forgetDirs(
KDirLister *lister )
463 kdDebug(7004) << k_funcinfo << lister << endl;
465 emit lister->
clear();
468 KURL::List lstDirsCopy = lister->d->lstDirs;
469 for ( KURL::List::Iterator it = lstDirsCopy.begin();
470 it != lstDirsCopy.end(); ++it )
472 forgetDirs( lister, *it,
false );
476 void KDirListerCache::forgetDirs(
KDirLister *lister,
const KURL& _url,
bool notify )
478 kdDebug(7004) << k_funcinfo << lister <<
" _url: " << _url << endl;
481 url.adjustPath( -1 );
482 TQString urlStr = url.url();
483 TQString urlReferenceStr = url.internalReferenceURL();
484 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr];
488 holders->removeRef( lister );
495 lister->d->lstDirs.remove( lister->d->lstDirs.find( url ) );
497 DirItem *item = itemsInUse[urlStr +
":" + urlReferenceStr];
499 if ( holders && holders->isEmpty() )
501 urlsCurrentlyHeld.remove( urlStr +
":" + urlReferenceStr );
502 if ( !urlsCurrentlyListed[urlStr +
":" + urlReferenceStr] )
505 itemsInUse.remove( urlStr +
":" + urlReferenceStr );
508 TDEIO::ListJob *job = jobForUrl( urlStr +
":" + urlReferenceStr );
511 lister->jobDone( job );
513 kdDebug(7004) << k_funcinfo <<
"Killing update job for " << urlStr << endl;
516 if ( lister->numJobs() == 0 )
518 lister->d->complete =
true;
524 emit lister->
clear( url );
526 if ( item && item->complete )
528 kdDebug(7004) << k_funcinfo << lister <<
" item moved into cache: " << url << endl;
529 itemsCached.insert( urlStr, item );
534 const bool isLocal = item->
url.isLocalFile();
536 bool containsManuallyMounted =
false;
537 if ( !isManuallyMounted && item->lstItems && isLocal )
543 KFileItemListIterator kit( *item->lstItems );
544 for ( ; kit.current() && !containsManuallyMounted; ++kit )
546 containsManuallyMounted =
true;
549 if ( isManuallyMounted || containsManuallyMounted )
551 kdDebug(7004) <<
"Not adding a watch on " << item->url <<
" because it " <<
552 ( isManuallyMounted ?
"is manually mounted" :
"contains a manually mounted subdir" ) << endl;
553 item->complete =
false;
556 item->incAutoUpdate();
566 if ( item && lister->d->autoUpdate )
567 item->decAutoUpdate();
570 void KDirListerCache::updateDirectory(
const KURL& _dir )
572 kdDebug(7004) << k_funcinfo << _dir << endl;
574 TQString urlStr = _dir.url(-1);
575 TQString urlReferenceStr = _dir.internalReferenceURL();
576 if ( !checkUpdate( _dir, -1 ) ) {
586 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr +
":" + urlReferenceStr];
587 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr];
591 TQWidget *window = 0;
592 TDEIO::ListJob *job = jobForUrl( urlStr +
":" + urlReferenceStr );
601 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
607 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() ) {
612 kdDebug(7004) << k_funcinfo <<
"Killed = " << killed << endl;
617 Q_ASSERT( !listers || (listers && killed) );
620 jobs.insert( job, TQValueList<TDEIO::UDSEntry>() );
622 connect( job, TQT_SIGNAL(entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )),
623 this, TQT_SLOT(slotUpdateEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )) );
624 connect( job, TQT_SIGNAL(result(
TDEIO::Job * )),
625 this, TQT_SLOT(slotUpdateResult(
TDEIO::Job * )) );
627 kdDebug(7004) << k_funcinfo <<
"update started in " << _dir << endl;
630 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
631 kdl->jobStarted( job );
640 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
642 kdl->jobStarted( job );
643 if ( first && kdl->d->window )
648 emit kdl->started( _dir );
655 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() ) {
656 kdl->jobStarted( job );
662 bool KDirListerCache::checkUpdate(
const KURL& _dir,
int truncationMode )
664 if ( !itemsInUse[_dir.url(truncationMode) +
":" + _dir.internalReferenceURL()] )
666 DirItem *item = itemsCached[_dir.url(truncationMode)];
667 if ( item && item->complete )
669 item->complete =
false;
670 item->decAutoUpdate();
683 KFileItemList *KDirListerCache::itemsForDir(
const KURL &_dir )
const
685 TQString urlStr = _dir.url(-1);
686 TQString urlReferenceStr = _dir.internalReferenceURL();
687 DirItem *item = itemsInUse[ urlStr +
":" + urlReferenceStr ];
689 item = itemsCached[ urlStr ];
691 return item ? item->lstItems : 0;
694 KFileItem *KDirListerCache::findByName(
const KDirLister *lister,
const TQString& _name )
const
698 for ( KURL::List::Iterator it = lister->d->lstDirs.begin();
699 it != lister->d->lstDirs.end(); ++it )
701 KFileItemListIterator kit( *itemsInUse[(*it).url() +
":" + (*it).internalReferenceURL()]->lstItems );
702 for ( ; kit.current(); ++kit )
703 if ( (*kit)->name() == _name )
715 KURL parentDir( _url );
716 parentDir.setPath( parentDir.directory() );
719 if ( lister && !lister->d->lstDirs.contains( parentDir ) )
722 KFileItemList *itemList = itemsForDir( parentDir );
725 KFileItemListIterator kit( *itemList );
726 for ( ; kit.current(); ++kit )
727 if ( (*kit)->url() == _url )
733 void KDirListerCache::FilesAdded(
const KURL &dir )
735 kdDebug(7004) << k_funcinfo << dir << endl;
736 updateDirectory( dir );
739 void KDirListerCache::FilesRemoved(
const KURL::List &fileList )
741 kdDebug(7004) << k_funcinfo << endl;
742 KURL::List::ConstIterator it = fileList.begin();
743 for ( ; it != fileList.end() ; ++it )
747 KURL parentDir( *it );
748 parentDir.setPath( parentDir.directory() );
749 KFileItemList *lstItems = itemsForDir( parentDir );
753 for ( ; fit; fit = lstItems->next() )
754 if ( fit->
url() == *it ) {
765 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDir.url() +
":" + parentDir.internalReferenceURL()];
767 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
768 kdl->emitDeleteItem( fileitem );
774 if ( !fileitem || fileitem->
isDir() )
786 void KDirListerCache::FilesChanged(
const KURL::List &fileList )
788 KURL::List dirsToUpdate;
789 kdDebug(7004) << k_funcinfo <<
"only half implemented" << endl;
790 KURL::List::ConstIterator it = fileList.begin();
791 for ( ; it != fileList.end() ; ++it )
793 if ( ( *it ).isLocalFile() )
795 kdDebug(7004) <<
"KDirListerCache::FilesChanged " << *it << endl;
796 KFileItem *fileitem = findByURL( 0, *it );
800 aboutToRefreshItem( fileitem );
802 emitRefreshItem( fileitem );
805 kdDebug(7004) <<
"item not found" << endl;
811 dir.setPath( dir.directory(
true ) );
812 if ( dirsToUpdate.find( dir ) == dirsToUpdate.end() ) {
813 dirsToUpdate.prepend( dir );
818 KURL::List::ConstIterator itdir = dirsToUpdate.begin();
819 for ( ; itdir != dirsToUpdate.end() ; ++itdir ) {
820 updateDirectory( *itdir );
826 void KDirListerCache::FileRenamed(
const KURL &src,
const KURL &dst )
828 kdDebug(7004) << k_funcinfo << src.prettyURL() <<
" -> " << dst.prettyURL() << endl;
835 renameDir( src, dst );
839 oldurl.adjustPath( -1 );
840 KFileItem *fileitem = findByURL( 0, oldurl );
847 aboutToRefreshItem( fileitem );
850 emitRefreshItem( fileitem );
858 void KDirListerCache::aboutToRefreshItem(
KFileItem *fileitem )
861 KURL parentDir( fileitem->
url() );
862 parentDir.setPath( parentDir.directory() );
863 TQString parentDirURL = parentDir.url();
864 TQString parentDirReferenceURL = parentDir.internalReferenceURL();
865 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDirURL +
":" + parentDirReferenceURL];
867 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
868 kdl->aboutToRefreshItem( fileitem );
871 listers = urlsCurrentlyListed[parentDirURL +
":" + parentDirReferenceURL];
873 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
874 kdl->aboutToRefreshItem( fileitem );
877 void KDirListerCache::emitRefreshItem(
KFileItem *fileitem )
880 KURL parentDir( fileitem->
url() );
881 parentDir.setPath( parentDir.directory() );
882 TQString parentDirURL = parentDir.url();
883 TQString parentDirReferenceURL = parentDir.internalReferenceURL();
884 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDirURL +
":" + parentDirReferenceURL];
886 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
888 kdl->addRefreshItem( fileitem );
893 listers = urlsCurrentlyListed[parentDirURL +
":" + parentDirReferenceURL];
895 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
897 kdl->addRefreshItem( fileitem );
902 KDirListerCache* KDirListerCache::self()
905 s_pSelf = sd_KDirListerCache.setObject( s_pSelf,
new KDirListerCache );
910 bool KDirListerCache::exists()
919 void KDirListerCache::slotFileDirty(
const KURL& _url )
921 kdDebug(7004) << k_funcinfo << _url << endl;
923 if ( !pendingUpdates[_url.path()] )
926 dir.setPath( _url.path() );
927 dir.setInternalReferenceURL(_url.internalReferenceURL());
928 if ( checkUpdate( dir, -1 ) ) {
929 updateDirectory( _url );
933 dir.setPath( dir.directory() );
934 dir.setInternalReferenceURL(_url.internalReferenceURL());
935 if ( checkUpdate( dir ) )
938 TQTimer *timer =
new TQTimer(
this, _url.path().utf8() );
939 connect( timer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(slotFileDirtyDelayed()) );
940 pendingUpdates.insert( _url.path(), timer );
941 timer->start( 500,
true );
947 void KDirListerCache::slotFileDirtyDelayed()
949 TQString file = TQString::fromUtf8( TQT_TQOBJECT_CONST(sender())->name() );
951 kdDebug(7004) << k_funcinfo << file << endl;
955 pendingUpdates.remove( file );
963 aboutToRefreshItem( item );
965 emitRefreshItem( item );
969 void KDirListerCache::slotFileCreated(
const TQString& _file )
971 kdDebug(7004) << k_funcinfo << _file << endl;
975 u.setPath( u.directory() );
979 void KDirListerCache::slotFileDeleted(
const TQString& _file )
981 kdDebug(7004) << k_funcinfo << _file << endl;
987 void KDirListerCache::slotEntries(
TDEIO::Job *job,
const TDEIO::UDSEntryList &entries )
989 KURL url = joburl( static_cast<TDEIO::ListJob *>(job) );
991 TQString urlStr = url.url();
992 TQString urlReferenceStr = url.internalReferenceURL();
994 kdDebug(7004) << k_funcinfo <<
"new entries for " << url << endl;
996 DirItem *dir = itemsInUse[urlStr +
":" + urlReferenceStr];
999 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr +
":" + urlReferenceStr];
1000 Q_ASSERT( listers );
1001 Q_ASSERT( !listers->isEmpty() );
1004 bool delayedMimeTypes =
true;
1005 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1006 delayedMimeTypes = delayedMimeTypes && kdl->d->delayedMimeTypes;
1010 static const TQString& dot = TDEGlobal::staticQString(
".");
1011 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
1013 TDEIO::UDSEntryListConstIterator it = entries.begin();
1014 TDEIO::UDSEntryListConstIterator end = entries.end();
1016 for ( ; it != end; ++it )
1021 TDEIO::UDSEntry::ConstIterator entit = (*it).begin();
1022 for( ; entit != (*it).end(); ++entit ) {
1024 name = (*entit).m_str;
1029 Q_ASSERT( !name.isEmpty() );
1030 if ( name.isEmpty() ) {
1036 Q_ASSERT( !dir->rootItem );
1037 dir->rootItem =
new KFileItem( *it, url, delayedMimeTypes,
true );
1039 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1040 if ( !kdl->d->rootFileItem && kdl->d->url == url ) {
1041 kdl->d->rootFileItem = dir->rootItem;
1045 else if ( name != dotdot )
1051 dir->lstItems->append( item );
1053 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1054 kdl->addNewItem( item );
1059 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1064 void KDirListerCache::slotResult(
TDEIO::Job *j )
1070 KURL jobUrl = joburl( job );
1071 jobUrl.adjustPath(-1);
1072 TQString jobUrlStr = jobUrl.url();
1073 TQString jobReferenceUrlStr = jobUrl.internalReferenceURL();
1075 kdDebug(7004) << k_funcinfo <<
"finished listing " << jobUrl << endl;
1080 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( jobUrlStr +
":" + jobReferenceUrlStr );
1081 Q_ASSERT( listers );
1086 Q_ASSERT( !urlsCurrentlyHeld[jobUrlStr +
":" + jobReferenceUrlStr] );
1087 urlsCurrentlyHeld.insert( jobUrlStr +
":" + jobReferenceUrlStr, listers );
1093 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1095 kdl->jobDone( job );
1098 if ( kdl->numJobs() == 0 )
1100 kdl->d->complete =
true;
1107 DirItem *dir = itemsInUse[jobUrlStr +
":" + jobReferenceUrlStr];
1109 dir->complete =
true;
1111 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1113 kdl->jobDone( job );
1114 kdl->emitCompleted( jobUrl );
1115 if ( kdl->numJobs() == 0 )
1117 kdl->d->complete =
true;
1125 processPendingUpdates();
1132 void KDirListerCache::slotRedirection(
TDEIO::Job *j,
const KURL& url )
1137 KURL oldUrl = job->
url();
1141 oldUrl.adjustPath(-1);
1142 newUrl.adjustPath(-1);
1144 if ( oldUrl == newUrl )
1146 kdDebug(7004) << k_funcinfo <<
"New redirection url same as old, giving up." << endl;
1150 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << newUrl.prettyURL() << endl;
1161 DirItem *dir = itemsInUse.take( oldUrl.url() +
":" + oldUrl.internalReferenceURL() );
1164 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( oldUrl.url() +
":" + oldUrl.internalReferenceURL() );
1165 Q_ASSERT( listers );
1166 Q_ASSERT( !listers->isEmpty() );
1168 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1171 if ( kdl->d->url.equals( oldUrl,
true ) )
1173 kdl->d->rootFileItem = 0;
1174 kdl->d->url = newUrl;
1177 *kdl->d->lstDirs.find( oldUrl ) = newUrl;
1179 if ( kdl->d->lstDirs.count() == 1 )
1187 emit kdl->
clear( oldUrl );
1194 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld.take( oldUrl.url() +
":" + oldUrl.internalReferenceURL() );
1197 Q_ASSERT( !holders->isEmpty() );
1199 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1201 kdl->jobStarted( job );
1208 if ( kdl->d->url.equals( oldUrl,
true ) )
1210 kdl->d->rootFileItem = 0;
1211 kdl->d->url = newUrl;
1214 *kdl->d->lstDirs.find( oldUrl ) = newUrl;
1216 if ( kdl->d->lstDirs.count() == 1 )
1224 emit kdl->
clear( oldUrl );
1230 DirItem *newDir = itemsInUse[newUrl.url() +
":" + newUrl.internalReferenceURL()];
1233 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" already in use" << endl;
1240 TDEIO::ListJob *oldJob = jobForUrl( newUrl.url() +
":" + newUrl.internalReferenceURL(), job );
1244 TQPtrList<KDirLister> *curListers = urlsCurrentlyListed[newUrl.url() +
":" + newUrl.internalReferenceURL()];
1247 kdDebug(7004) <<
"slotRedirection: and it is currently listed" << endl;
1251 for (
KDirLister *kdl = curListers->first(); kdl; kdl = curListers->next() )
1253 kdl->jobDone( oldJob );
1255 kdl->jobStarted( job );
1256 kdl->connectJob( job );
1260 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1261 curListers->append( kdl );
1264 urlsCurrentlyListed.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), listers );
1271 TQPtrList<KDirLister> *curHolders = urlsCurrentlyHeld[newUrl.url() +
":" + newUrl.internalReferenceURL()];
1274 kdDebug(7004) <<
"slotRedirection: and it is currently held." << endl;
1276 for (
KDirLister *kdl = curHolders->first(); kdl; kdl = curHolders->next() )
1278 kdl->jobStarted( job );
1284 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1285 curHolders->append( kdl );
1288 urlsCurrentlyHeld.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), holders );
1293 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1295 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1296 kdl->d->rootFileItem = newDir->rootItem;
1298 kdl->addNewItems( *(newDir->lstItems) );
1304 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1306 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1307 kdl->d->rootFileItem = newDir->rootItem;
1309 kdl->addNewItems( *(newDir->lstItems) );
1314 else if ( (newDir = itemsCached.take( newUrl.url() )) )
1316 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" is unused, but already in the cache." << endl;
1319 itemsInUse.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), newDir );
1320 urlsCurrentlyListed.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), listers );
1322 urlsCurrentlyHeld.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), holders );
1325 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1327 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1328 kdl->d->rootFileItem = newDir->rootItem;
1330 kdl->addNewItems( *(newDir->lstItems) );
1336 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1338 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1339 kdl->d->rootFileItem = newDir->rootItem;
1341 kdl->addNewItems( *(newDir->lstItems) );
1348 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" has not been listed yet." << endl;
1350 delete dir->rootItem;
1352 dir->lstItems->clear();
1353 dir->redirect( newUrl );
1354 itemsInUse.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), dir );
1355 urlsCurrentlyListed.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), listers );
1358 urlsCurrentlyHeld.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), holders );
1369 job->disconnect(
this );
1371 connect( job, TQT_SIGNAL(entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )),
1372 this, TQT_SLOT(slotUpdateEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )) );
1373 connect( job, TQT_SIGNAL(result(
TDEIO::Job * )),
1374 this, TQT_SLOT(slotUpdateResult(
TDEIO::Job * )) );
1383 void KDirListerCache::renameDir(
const KURL &oldUrl,
const KURL &newUrl )
1385 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << newUrl.prettyURL() << endl;
1386 TQString oldUrlStr = oldUrl.url(-1);
1387 TQString newUrlStr = newUrl.url(-1);
1394 TQDictIterator<DirItem> itu( itemsInUse );
1396 while ( itu.current() )
1399 DirItem *dir = itu.current();
1400 TQString oldDirURLIndep = itu.currentKey();
1401 oldDirURLIndep.truncate(oldDirURLIndep.length() - (dir->url.internalReferenceURL().length()+strlen(
":")));
1402 KURL oldDirUrl ( oldDirURLIndep );
1405 if ( oldUrl.isParentOf( oldDirUrl ) )
1408 TQString relPath = oldDirUrl.path().mid( oldUrl.path().length() );
1410 KURL newDirUrl( newUrl );
1411 if ( !relPath.isEmpty() ) {
1412 newDirUrl.addPath( relPath );
1417 dir->redirect( newDirUrl );
1418 itemsInUse.remove( itu.currentKey() );
1419 itemsInUse.insert( newDirUrl.url(-1), dir );
1421 if ( dir->lstItems )
1424 KFileItemListIterator kit( *dir->lstItems );
1425 for ( ; kit.current(); ++kit )
1427 KURL oldItemUrl = (*kit)->url();
1428 TQString oldItemUrlStr( oldItemUrl.url(-1) );
1429 KURL newItemUrl( oldItemUrl );
1430 newItemUrl.setPath( newDirUrl.path() );
1431 newItemUrl.addPath( oldItemUrl.fileName() );
1432 kdDebug(7004) <<
"KDirListerCache::renameDir renaming " << oldItemUrlStr <<
" to " << newItemUrl.url() << endl;
1433 (*kit)->setURL( newItemUrl );
1436 emitRedirections( oldDirUrl, newDirUrl );
1444 removeDirFromCache( oldUrl );
1448 void KDirListerCache::emitRedirections(
const KURL &oldUrl,
const KURL &url )
1450 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << url.prettyURL() << endl;
1451 TQString oldUrlStr = oldUrl.url(-1);
1452 TQString urlStr = url.url(-1);
1453 TQString oldReferenceUrlStr = oldUrl.internalReferenceURL();
1454 TQString urlReferenceStr = url.internalReferenceURL();
1456 TDEIO::ListJob *job = jobForUrl( oldUrlStr +
":" + oldReferenceUrlStr );
1461 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( oldUrlStr +
":" + oldReferenceUrlStr );
1465 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1468 kdl->jobDone( job );
1473 urlsCurrentlyListed.insert( urlStr +
":" + urlReferenceStr, listers );
1478 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld.take( oldUrlStr +
":" + oldReferenceUrlStr );
1482 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1483 kdl->jobDone( job );
1485 urlsCurrentlyHeld.insert( urlStr +
":" + urlReferenceStr, holders );
1490 updateDirectory( url );
1493 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1500 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1502 *kdl->d->lstDirs.find( oldUrl ) = url;
1504 if ( kdl->d->lstDirs.count() == 1 )
1512 void KDirListerCache::removeDirFromCache(
const KURL& dir )
1514 kdDebug(7004) <<
"KDirListerCache::removeDirFromCache " << dir.prettyURL() << endl;
1515 TQCacheIterator<DirItem> itc( itemsCached );
1516 while ( itc.current() )
1518 if ( dir.isParentOf( KURL( itc.currentKey() ) ) )
1519 itemsCached.remove( itc.currentKey() );
1525 void KDirListerCache::slotUpdateEntries(
TDEIO::Job* job,
const TDEIO::UDSEntryList& list )
1530 void KDirListerCache::slotUpdateResult(
TDEIO::Job * j )
1535 KURL jobUrl = joburl( job );
1536 jobUrl.adjustPath(-1);
1537 TQString jobUrlStr = jobUrl.url();
1538 TQString jobReferenceUrlStr = jobUrl.internalReferenceURL();
1540 kdDebug(7004) << k_funcinfo <<
"finished update " << jobUrl << endl;
1544 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[jobUrlStr +
":" + jobReferenceUrlStr];
1545 TQPtrList<KDirLister> *tmpLst = urlsCurrentlyListed.take( jobUrlStr +
":" + jobReferenceUrlStr );
1550 for ( kdl = tmpLst->first(); kdl; kdl = tmpLst->next() )
1552 Q_ASSERT( listers->containsRef( kdl ) == 0 );
1553 listers->append( kdl );
1558 urlsCurrentlyHeld.insert( jobUrlStr +
":" + jobReferenceUrlStr, listers );
1563 Q_ASSERT( listers );
1567 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1569 kdl->jobDone( job );
1575 if ( kdl->numJobs() == 0 )
1577 kdl->d->complete =
true;
1586 processPendingUpdates();
1590 DirItem *dir = itemsInUse[jobUrlStr +
":" + jobReferenceUrlStr];
1591 dir->complete =
true;
1595 bool delayedMimeTypes =
true;
1596 for ( kdl = listers->first(); kdl; kdl = listers->next() ) {
1597 delayedMimeTypes = delayedMimeTypes && kdl->d->delayedMimeTypes;
1601 TQDict<KFileItem> fileItems( 9973 );
1603 KFileItemListIterator kit ( *(dir->lstItems) );
1606 for ( ; kit.current(); ++kit )
1609 if (!((*kit)->listerURL().isEmpty())) {
1610 fileItems.insert( (*kit)->listerURL().url(), *kit );
1613 fileItems.insert( (*kit)->url().url(), *kit );
1617 static const TQString& dot = TDEGlobal::staticQString(
".");
1618 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
1622 TQValueList<TDEIO::UDSEntry> buf = jobs[job];
1623 TQValueListIterator<TDEIO::UDSEntry> it = buf.begin();
1624 for ( ; it != buf.end(); ++it )
1628 item =
new KFileItem( *it, jobUrl, delayedMimeTypes,
true );
1631 item->
setUDSEntry( *it, jobUrl, delayedMimeTypes,
true );
1635 TQString name = item->
name();
1636 Q_ASSERT( !name.isEmpty() );
1640 if ( name.isEmpty() || name == dotdot ) {
1648 if ( !dir->rootItem )
1650 dir->rootItem = item;
1653 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1654 if ( !kdl->d->rootFileItem && kdl->d->url == jobUrl ) {
1655 kdl->d->rootFileItem = dir->rootItem;
1664 if ( (tmp = fileItems[item->
url().url()]) )
1669 if ( !tmp->cmp( *item ) )
1671 for ( kdl = listers->first(); kdl; kdl = listers->next() ) {
1672 kdl->aboutToRefreshItem( tmp );
1676 tmp->assign( *item );
1678 for ( kdl = listers->first(); kdl; kdl = listers->next() ) {
1679 kdl->addRefreshItem( tmp );
1688 dir->lstItems->append( item );
1690 for ( kdl = listers->first(); kdl; kdl = listers->next() ) {
1691 kdl->addNewItem( item );
1705 deleteUnmarkedItems( listers, dir->lstItems );
1707 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1711 kdl->jobDone( job );
1713 kdl->emitCompleted( jobUrl );
1714 if ( kdl->numJobs() == 0 )
1716 kdl->d->complete =
true;
1723 processPendingUpdates();
1731 TQMap< TDEIO::ListJob *, TQValueList<TDEIO::UDSEntry> >::Iterator it = jobs.begin();
1732 while ( it != jobs.end() )
1735 KURL itjoburl = joburl( job );
1736 if ( ((itjoburl.url(-1) +
":" + itjoburl.internalReferenceURL()) == url) && (job != not_job) ) {
1757 job->disconnect(
this );
1761 void KDirListerCache::deleteUnmarkedItems( TQPtrList<KDirLister> *listers, KFileItemList *lstItems )
1766 while ( (item = lstItems->current()) )
1770 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1771 kdl->emitDeleteItem( item );
1774 if ( item->
isDir() ) {
1775 deleteDir( item->
url() );
1786 void KDirListerCache::deleteDir(
const KURL& dirUrl )
1793 TQDictIterator<DirItem> itu( itemsInUse );
1794 while ( itu.current() )
1796 TQString deletedUrlIndep = itu.currentKey();
1797 deletedUrlIndep.truncate(deletedUrlIndep.length() - ((*itu)->url.internalReferenceURL().length()+strlen(
":")));
1798 KURL deletedUrl( deletedUrlIndep );
1799 if ( dirUrl.isParentOf( deletedUrl ) )
1803 TQPtrList<KDirLister> *kdls = urlsCurrentlyListed[deletedUrl.url() +
":" + deletedUrl.internalReferenceURL()];
1807 kdls =
new TQPtrList<KDirLister>( *kdls );
1808 for (
KDirLister *kdl = kdls->first(); kdl; kdl = kdls->next() )
1809 stop( kdl, deletedUrl );
1817 kdls = urlsCurrentlyHeld[deletedUrl.url() +
":" + deletedUrl.internalReferenceURL()];
1821 kdls =
new TQPtrList<KDirLister>( *kdls );
1823 for (
KDirLister *kdl = kdls->first(); kdl; kdl = kdls->next() )
1826 if ( kdl->d->url == deletedUrl )
1829 if ( kdl->d->rootFileItem )
1830 emit kdl->
deleteItem( kdl->d->rootFileItem );
1832 kdl->d->rootFileItem = 0;
1836 bool treeview = kdl->d->lstDirs.count() > 1;
1840 forgetDirs( kdl, deletedUrl, treeview );
1850 DirItem *dir = itemsInUse.take( deletedUrl.url() +
":" + deletedUrl.internalReferenceURL() );
1860 removeDirFromCache( dirUrl );
1863 void KDirListerCache::processPendingUpdates()
1869 void KDirListerCache::printDebug()
1871 kdDebug(7004) <<
"Items in use: " << endl;
1872 TQDictIterator<DirItem> itu( itemsInUse );
1873 for ( ; itu.current() ; ++itu ) {
1874 kdDebug(7004) <<
" " << itu.currentKey() <<
" URL: " << itu.current()->url
1875 <<
" rootItem: " << ( itu.current()->rootItem ? itu.current()->rootItem->url() : KURL() )
1876 <<
" autoUpdates refcount: " << itu.current()->autoUpdates
1877 <<
" complete: " << itu.current()->complete
1878 << ( itu.current()->lstItems ? TQString(
" with %1 items.").arg(itu.current()->lstItems->count()) : TQString(
" lstItems=NULL") ) << endl;
1881 kdDebug(7004) <<
"urlsCurrentlyHeld: " << endl;
1882 TQDictIterator< TQPtrList<KDirLister> > it( urlsCurrentlyHeld );
1883 for ( ; it.current() ; ++it )
1886 for ( TQPtrListIterator<KDirLister> listit( *it.current() ); listit.current(); ++listit )
1887 list +=
" 0x" + TQString::number( (
long)listit.current(), 16 );
1888 kdDebug(7004) <<
" " << it.currentKey() <<
" " << it.current()->count() <<
" listers: " << list << endl;
1891 kdDebug(7004) <<
"urlsCurrentlyListed: " << endl;
1892 TQDictIterator< TQPtrList<KDirLister> > it2( urlsCurrentlyListed );
1893 for ( ; it2.current() ; ++it2 )
1896 for ( TQPtrListIterator<KDirLister> listit( *it2.current() ); listit.current(); ++listit )
1897 list +=
" 0x" + TQString::number( (
long)listit.current(), 16 );
1898 kdDebug(7004) <<
" " << it2.currentKey() <<
" " << it2.current()->count() <<
" listers: " << list << endl;
1901 TQMap< TDEIO::ListJob *, TQValueList<TDEIO::UDSEntry> >::Iterator jit = jobs.begin();
1902 kdDebug(7004) <<
"Jobs: " << endl;
1903 for ( ; jit != jobs.end() ; ++jit )
1904 kdDebug(7004) <<
" " << jit.key() <<
" listing " << joburl( jit.key() ).prettyURL() <<
": " << (*jit).count() <<
" entries." << endl;
1906 kdDebug(7004) <<
"Items in cache: " << endl;
1907 TQCacheIterator<DirItem> itc( itemsCached );
1908 for ( ; itc.current() ; ++itc )
1909 kdDebug(7004) <<
" " << itc.currentKey() <<
" rootItem: "
1910 << ( itc.current()->rootItem ? itc.current()->rootItem->url().prettyURL() : TQString(
"NULL") )
1911 << ( itc.current()->lstItems ? TQString(
" with %1 items.").arg(itc.current()->lstItems->count()) : TQString(
" lstItems=NULL") ) << endl;
1920 kdDebug(7003) <<
"+KDirLister" << endl;
1922 d =
new KDirListerPrivate;
1925 d->delayedMimeTypes = _delayedMimeTypes;
1936 kdDebug(7003) <<
"-KDirLister" << endl;
1938 if ( KDirListerCache::exists() )
1942 s_pCache->forgetDirs(
this );
1950 kdDebug(7003) << k_funcinfo << _url.prettyURL()
1951 <<
" keep=" << _keep <<
" reload=" << _reload << endl;
1954 if ( d->changes != NONE && _keep ) {
1961 if (!_url.isLocalFile()) {
1964 d->openURL_url[localURLJob] = _url;
1965 d->openURL_keep[localURLJob] = _keep;
1966 d->openURL_reload[localURLJob] = _reload;
1967 connect(localURLJob, TQT_SIGNAL(localURL(
TDEIO::Job*,
const KURL&,
bool)),
this, TQT_SLOT(slotOpenURLGotLocalURL(
TDEIO::Job*,
const KURL&,
bool)));
1968 connect(localURLJob, TQT_SIGNAL(destroyed()),
this, TQT_SLOT(slotLocalURLKIODestroyed()));
1973 return s_pCache->listDir(
this, _url, _keep, _reload );
1977 void KDirLister::slotOpenURLGotLocalURL(
TDEIO::Job *job,
const KURL& url,
bool isLocal) {
1978 KURL realURL = d->openURL_url[job];
1981 realURL.setInternalReferenceURL(d->openURL_url[job].url());
1982 d->m_referenceURLMap[d->openURL_url[job].url()] = url.path();
1984 s_pCache->listDir(
this, realURL, d->openURL_keep[job], d->openURL_reload[job] );
1985 d->openURL_url.remove(job);
1986 d->openURL_keep.remove(job);
1987 d->openURL_reload.remove(job);
1990 void KDirLister::slotLocalURLKIODestroyed() {
1993 if (d->openURL_url.contains(terminatedJob)) {
1994 s_pCache->listDir(
this, d->openURL_url[terminatedJob], d->openURL_keep[terminatedJob], d->openURL_reload[terminatedJob] );
1995 d->openURL_url.remove(terminatedJob);
1996 d->openURL_keep.remove(terminatedJob);
1997 d->openURL_reload.remove(terminatedJob);
2003 kdDebug(7003) << k_funcinfo << endl;
2004 s_pCache->stop(
this );
2005 d->m_referenceURLMap.clear();
2010 kdDebug(7003) << k_funcinfo << _url.prettyURL() << endl;
2011 s_pCache->stop(
this, _url );
2012 d->m_referenceURLMap.remove(_url.url());
2017 return d->autoUpdate;
2022 if ( d->autoUpdate == _enable )
2025 d->autoUpdate = _enable;
2026 s_pCache->setAutoUpdate(
this, _enable );
2031 return d->isShowingDotFiles;
2036 if ( d->isShowingDotFiles == _showDotFiles )
2039 d->isShowingDotFiles = _showDotFiles;
2040 d->changes ^= DOT_FILES;
2045 return d->dirOnlyMode;
2050 if ( d->dirOnlyMode == _dirsOnly )
2053 d->dirOnlyMode = _dirsOnly;
2054 d->changes ^= DIR_ONLY_MODE;
2059 return d->autoErrorHandling;
2064 d->autoErrorHandling = enable;
2065 d->errorParent = parent;
2080 if ( d->changes == NONE )
2083 static const TQString& dot = TDEGlobal::staticQString(
".");
2084 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
2086 for ( KURL::List::Iterator it = d->lstDirs.begin();
2087 it != d->lstDirs.end(); ++it )
2089 KFileItemListIterator kit( *s_pCache->itemsForDir( *it ) );
2090 for ( ; kit.current(); ++kit )
2092 if ( (*kit)->text() == dot || (*kit)->text() == dotdot )
2095 bool oldMime =
true, newMime =
true;
2097 if ( d->changes & MIME_FILTER )
2099 oldMime =
doMimeFilter( (*kit)->mimetype(), d->oldMimeFilter )
2100 && doMimeExcludeFilter( (*kit)->mimetype(), d->oldMimeExcludeFilter );
2101 newMime =
doMimeFilter( (*kit)->mimetype(), d->mimeFilter )
2102 && doMimeExcludeFilter( (*kit)->mimetype(), d->mimeExcludeFilter );
2104 if ( oldMime && !newMime )
2111 if ( d->changes & DIR_ONLY_MODE )
2114 if ( d->dirOnlyMode )
2116 if ( !(*kit)->isDir() )
2119 else if ( !(*kit)->isDir() ) {
2126 if ( (*kit)->isHidden() )
2128 if ( d->changes & DOT_FILES )
2131 if ( d->isShowingDotFiles ) {
2141 else if ( d->changes & NAME_FILTER )
2143 bool oldName = (*kit)->isDir() ||
2144 d->oldFilters.isEmpty() ||
2147 bool newName = (*kit)->isDir() ||
2148 d->lstFilters.isEmpty() ||
2151 if ( oldName && !newName )
2156 else if ( !oldName && newName ) {
2161 if ( (d->changes & MIME_FILTER) && !oldMime && newMime ) {
2174 s_pCache->updateDirectory( _u );
2184 return d->rootFileItem;
2189 return s_pCache->findByURL(
this, _url );
2194 return s_pCache->findByName(
this, _name );
2197 #ifndef KDE_NO_COMPAT
2198 KFileItem *KDirLister::find(
const KURL& _url )
const
2209 if ( !(d->changes & NAME_FILTER) )
2211 d->oldFilters = d->lstFilters;
2212 d->lstFilters.setAutoDelete(
false );
2215 d->lstFilters.clear();
2216 d->lstFilters.setAutoDelete(
true );
2221 TQStringList list = TQStringList::split(
' ', nameFilter );
2222 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
2223 d->lstFilters.append(
new TQRegExp(*it,
false,
true ) );
2225 d->changes |= NAME_FILTER;
2230 return d->nameFilter;
2235 if ( !(d->changes & MIME_FILTER) )
2236 d->oldMimeFilter = d->mimeFilter;
2238 if ( mimeFilter.find(
"all/allfiles") != mimeFilter.end() ||
2239 mimeFilter.find(
"all/all") != mimeFilter.end() )
2240 d->mimeFilter.clear();
2242 d->mimeFilter = mimeFilter;
2244 d->changes |= MIME_FILTER;
2249 if ( !(d->changes & MIME_FILTER) )
2250 d->oldMimeExcludeFilter = d->mimeExcludeFilter;
2252 d->mimeExcludeFilter = mimeExcludeFilter;
2253 d->changes |= MIME_FILTER;
2259 if ( !(d->changes & MIME_FILTER) )
2261 d->oldMimeFilter = d->mimeFilter;
2262 d->oldMimeExcludeFilter = d->mimeExcludeFilter;
2264 d->mimeFilter.clear();
2265 d->mimeExcludeFilter.clear();
2266 d->changes |= MIME_FILTER;
2271 return d->mimeFilter;
2281 return doMimeFilter( mime, d->mimeFilter ) && doMimeExcludeFilter(mime,d->mimeExcludeFilter);
2289 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
2291 if ( item->
text() == dotdot )
2294 if ( !d->isShowingDotFiles && item->
isHidden() )
2297 if ( item->
isDir() || d->lstFilters.isEmpty() )
2307 if ( d->mimeFilter.isEmpty() && d->mimeExcludeFilter.isEmpty() )
2314 for ( TQPtrListIterator<TQRegExp> it( filters ); it.current(); ++it )
2315 if ( it.current()->exactMatch( name ) )
2323 if ( filters.isEmpty() )
2328 TQStringList::ConstIterator it = filters.begin();
2329 for ( ; it != filters.end(); ++it )
2330 if ( mimeptr->is(*it) )
2338 bool KDirLister::doMimeExcludeFilter(
const TQString& mime,
const TQStringList& filters )
const
2340 if ( filters.isEmpty() )
2343 TQStringList::ConstIterator it = filters.begin();
2344 for ( ; it != filters.end(); ++it )
2345 if ( (*it) == mime )
2354 return s_pCache->validURL(
this, _url );
2359 if ( d->autoErrorHandling ) {
2367 void KDirLister::addNewItem(
const KFileItem *item )
2373 if ((item->
url().internalReferenceURL() !=
"")
2374 && (d->m_referenceURLMap.contains(item->
url().internalReferenceURL()))) {
2377 TQString itemPath = item->
url().path();
2378 if (itemPath.startsWith(d->m_referenceURLMap[item->
url().internalReferenceURL()])) {
2379 itemPath = itemPath.remove(0, d->m_referenceURLMap[item->
url().internalReferenceURL()].length());
2380 TQString newPath = item->
url().internalReferenceURL();
2381 if (!newPath.endsWith(
"/")) newPath = newPath +
"/";
2382 while (itemPath.startsWith(
"/")) itemPath = itemPath.remove(0,1);
2383 while (itemPath.endsWith(
"/")) itemPath.truncate(itemPath.length()-1);
2384 newPath = newPath + itemPath;
2385 const_cast<KFileItem*
>(item)->setListerURL(item->
url());
2386 const_cast<KFileItem*
>(item)->setURL(newPath);
2392 if ( !d->lstNewItems ) {
2393 d->lstNewItems =
new KFileItemList;
2396 d->lstNewItems->append( item );
2400 if ( !d->lstMimeFilteredItems ) {
2401 d->lstMimeFilteredItems =
new KFileItemList;
2404 d->lstMimeFilteredItems->append( item );
2408 void KDirLister::addNewItems(
const KFileItemList& items )
2414 for ( KFileItemListIterator kit( items ); kit.current(); ++kit ) {
2419 void KDirLister::aboutToRefreshItem(
const KFileItem *item )
2423 d->refreshItemWasFiltered =
true;
2425 d->refreshItemWasFiltered =
true;
2427 d->refreshItemWasFiltered =
false;
2430 void KDirLister::addRefreshItem(
const KFileItem *item )
2434 if ((item->
url().internalReferenceURL() !=
"")
2435 && (d->m_referenceURLMap.contains(item->
url().internalReferenceURL()))) {
2438 TQString itemPath = item->
url().path();
2439 if (itemPath.startsWith(d->m_referenceURLMap[item->
url().internalReferenceURL()])) {
2440 itemPath = itemPath.remove(0, d->m_referenceURLMap[item->
url().internalReferenceURL()].length());
2441 TQString newPath = item->
url().internalReferenceURL();
2442 if (!newPath.endsWith(
"/")) newPath = newPath +
"/";
2443 while (itemPath.startsWith(
"/")) itemPath = itemPath.remove(0,1);
2444 while (itemPath.endsWith(
"/")) itemPath.truncate(itemPath.length()-1);
2445 newPath = newPath + itemPath;
2446 const_cast<KFileItem*
>(item)->setListerURL(item->
url());
2447 const_cast<KFileItem*
>(item)->setURL(newPath);
2453 if ( d->refreshItemWasFiltered )
2455 if ( !d->lstNewItems ) {
2456 d->lstNewItems =
new KFileItemList;
2459 d->lstNewItems->append( item );
2463 if ( !d->lstRefreshItems ) {
2464 d->lstRefreshItems =
new KFileItemList;
2467 d->lstRefreshItems->append( item );
2470 else if ( !d->refreshItemWasFiltered )
2472 if ( !d->lstRemoveItems ) {
2473 d->lstRemoveItems =
new KFileItemList;
2478 d->lstRemoveItems->append( item );
2482 void KDirLister::emitItems()
2484 KFileItemList *tmpNew = d->lstNewItems;
2487 KFileItemList *tmpMime = d->lstMimeFilteredItems;
2488 d->lstMimeFilteredItems = 0;
2490 KFileItemList *tmpRefresh = d->lstRefreshItems;
2491 d->lstRefreshItems = 0;
2493 KFileItemList *tmpRemove = d->lstRemoveItems;
2494 d->lstRemoveItems = 0;
2501 TQString prevProtocol;
2502 TQString prevPrefix;
2503 KFileItemList emitList;
2504 for ( KFileItemListIterator kit( *tmpNew ); kit.current(); ++kit )
2507 protocol = item->
url().protocol();
2508 prefix = TQStringList::split(
"/", item->
url().path())[0];
2509 if ((protocol != prevProtocol) || (prefix != prevPrefix)) {
2510 if (emitList.count() > 0) {
2515 emitList.append(item);
2516 prevProtocol = protocol;
2517 prevPrefix = prefix;
2520 if (emitList.count() > 0) {
2540 for (
KFileItem *tmp = tmpRemove->first(); tmp; tmp = tmpRemove->next() ) {
2547 void KDirLister::emitDeleteItem(
KFileItem *item )
2561 void KDirLister::slotInfoMessage(
TDEIO::Job *,
const TQString& message )
2566 void KDirLister::slotPercent(
TDEIO::Job *job,
unsigned long pcnt )
2574 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2575 while ( dataIt != d->jobData.end() )
2577 result += (*dataIt).percent * (*dataIt).totalSize;
2578 size += (*dataIt).totalSize;
2594 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2595 while ( dataIt != d->jobData.end() )
2597 result += (*dataIt).totalSize;
2609 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2610 while ( dataIt != d->jobData.end() )
2612 result += (*dataIt).processedSize;
2619 void KDirLister::slotSpeed(
TDEIO::Job *job,
unsigned long spd )
2624 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2625 while ( dataIt != d->jobData.end() )
2627 result += (*dataIt).speed;
2631 emit
speed( result );
2634 uint KDirLister::numJobs()
2636 return d->jobData.count();
2641 d->jobData.remove( job );
2646 KDirListerPrivate::JobData jobData;
2648 jobData.percent = 0;
2649 jobData.processedSize = 0;
2650 jobData.totalSize = 0;
2652 d->jobData.insert( job, jobData );
2653 d->complete =
false;
2659 this, TQT_SLOT(slotInfoMessage(
TDEIO::Job *,
const TQString& )) );
2661 this, TQT_SLOT(slotPercent(
TDEIO::Job *,
unsigned long )) );
2667 this, TQT_SLOT(slotSpeed(
TDEIO::Job *,
unsigned long )) );
2670 void KDirLister::emitCompleted(
const KURL& _url )
2672 KURL emitURL = _url;
2674 if ((_url.internalReferenceURL() !=
"")
2675 && (d->m_referenceURLMap.contains(_url.internalReferenceURL()))) {
2678 TQString itemPath = _url.path();
2679 if (itemPath.startsWith(d->m_referenceURLMap[_url.internalReferenceURL()])) {
2680 itemPath = itemPath.remove(0, d->m_referenceURLMap[_url.internalReferenceURL()].length());
2681 TQString newPath = _url.internalReferenceURL();
2682 if (!newPath.endsWith(
"/")) newPath = newPath +
"/";
2683 while (itemPath.startsWith(
"/")) itemPath = itemPath.remove(0,1);
2684 while (itemPath.endsWith(
"/")) itemPath.truncate(itemPath.length()-1);
2685 newPath = newPath + itemPath;
2710 KFileItemList result;
2711 KFileItemList *allItems = s_pCache->itemsForDir( dir );
2716 if ( which == AllItems ) {
2721 for ( KFileItemListIterator kit( *allItems ); kit.current(); ++kit )
2726 result.append( item );
2736 void KDirLister::virtual_hook(
int,
void * )
2739 #include "kdirlister.moc"
2740 #include "kdirlister_p.moc"