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, TQ_SIGNAL( dirty(
const KURL& ) ),
67 this, TQ_SLOT( slotFileDirty(
const KURL& ) ) );
68 connect( kdirwatch, TQ_SIGNAL( created(
const TQString& ) ),
69 this, TQ_SLOT( slotFileCreated(
const TQString& ) ) );
70 connect( kdirwatch, TQ_SIGNAL( deleted(
const TQString& ) ),
71 this, TQ_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 )
97 TQString urlStr = _url.url();
98 TQString urlReferenceStr = _url.internalReferenceURL();
107 kdDebug(7004) << k_funcinfo << lister <<
" url=" << _url
108 <<
" keep=" << _keep <<
" reload=" << _reload << endl;
116 forgetDirs( lister );
118 lister->d->rootFileItem = 0;
120 else if ( lister->d->lstDirs.find( _url ) != lister->d->lstDirs.end() )
123 stop( lister, _url );
126 forgetDirs( lister, _url,
true );
128 if ( lister->d->url == _url )
129 lister->d->rootFileItem = 0;
132 lister->d->lstDirs.append( _url );
134 if ( lister->d->url.isEmpty() || !_keep )
135 lister->d->url = _url;
137 DirItem *itemU = itemsInUse[urlStr +
":" + urlReferenceStr];
140 if ( !urlsCurrentlyListed[urlStr +
":" + urlReferenceStr] )
147 kdDebug(7004) <<
"listDir: Entry already in use: " << _url << endl;
149 bool oldState = lister->d->complete;
150 lister->d->complete =
false;
154 if ( !lister->d->rootFileItem && lister->d->url == _url ) {
155 lister->d->rootFileItem = itemU->rootItem;
158 lister->addNewItems( *(itemU->lstItems) );
162 assert( urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr] );
163 urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr]->append( lister );
165 lister->d->complete = oldState;
167 lister->emitCompleted( _url );
168 if ( lister->d->complete ) {
172 if ( _reload || !itemU->complete ) {
173 updateDirectory( _url );
176 else if ( !_reload && (itemC = itemsCached.take( urlStr )) )
178 kdDebug(7004) <<
"listDir: Entry in cache: " << _url << endl;
180 itemC->decAutoUpdate();
181 itemsInUse.insert( urlStr +
":" + urlReferenceStr, itemC );
184 bool oldState = lister->d->complete;
185 lister->d->complete =
false;
189 if ( !lister->d->rootFileItem && lister->d->url == _url ) {
190 lister->d->rootFileItem = itemC->rootItem;
193 lister->addNewItems( *(itemC->lstItems) );
196 Q_ASSERT( !urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr] );
197 TQPtrList<KDirLister> *list =
new TQPtrList<KDirLister>;
198 list->append( lister );
199 urlsCurrentlyHeld.insert( urlStr +
":" + urlReferenceStr, list );
201 lister->d->complete = oldState;
203 lister->emitCompleted( _url );
204 if ( lister->d->complete ) {
208 if ( !itemC->complete ) {
209 updateDirectory( _url );
214 kdDebug(7004) <<
"listDir: Entry not in cache or reloaded: " << _url << endl;
216 TQPtrList<KDirLister> *list =
new TQPtrList<KDirLister>;
217 list->append( lister );
218 urlsCurrentlyListed.insert( urlStr +
":" + urlReferenceStr, list );
220 itemsCached.remove( urlStr );
221 itemU =
new DirItem( _url );
222 itemsInUse.insert( urlStr +
":" + urlReferenceStr, itemU );
232 if ( lister->d->url == _url ) {
233 lister->d->rootFileItem = 0;
237 jobs.insert( job, TQValueList<TDEIO::UDSEntry>() );
239 lister->jobStarted( job );
240 lister->connectJob( job );
242 if ( lister->d->window ) {
246 connect( job, TQ_SIGNAL( entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & ) ),
247 this, TQ_SLOT( slotEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & ) ) );
248 connect( job, TQ_SIGNAL( result(
TDEIO::Job * ) ),
249 this, TQ_SLOT( slotResult(
TDEIO::Job * ) ) );
250 connect( job, TQ_SIGNAL( redirection(
TDEIO::Job *,
const KURL & ) ),
251 this, TQ_SLOT( slotRedirection(
TDEIO::Job *,
const KURL & ) ) );
260 kdDebug(7004) <<
"listDir: Entry currently being listed: " << _url << endl;
264 urlsCurrentlyListed[urlStr +
":" + urlReferenceStr]->append( lister );
266 TDEIO::ListJob *job = jobForUrl( urlStr +
":" + urlReferenceStr );
269 lister->jobStarted( job );
270 lister->connectJob( job );
274 if ( !lister->d->rootFileItem && lister->d->url == _url ) {
275 lister->d->rootFileItem = itemU->rootItem;
278 lister->addNewItems( *(itemU->lstItems) );
283 if ( lister->d->autoUpdate ) {
284 itemU->incAutoUpdate();
290 bool KDirListerCache::validURL(
const KDirLister *lister,
const KURL& url )
const
292 if ( !url.isValid() )
294 if ( lister->d->autoErrorHandling )
296 TQString tmp = i18n(
"Malformed URL\n%1").arg( url.prettyURL() );
297 KMessageBox::error( lister->d->errorParent, tmp );
304 if ( lister->d->autoErrorHandling )
307 TQString tmp = i18n(
"Malformed URL\n%1").arg( url.prettyURL() );
308 KMessageBox::error( lister->d->errorParent, tmp );
316 void KDirListerCache::stop(
KDirLister *lister )
321 kdDebug(7004) << k_funcinfo <<
"lister: " << lister << endl;
322 bool stopped =
false;
324 TQDictIterator< TQPtrList<KDirLister> > it( urlsCurrentlyListed );
325 TQPtrList<KDirLister> *listers;
327 while ( (listers = it.current()) )
329 curIndex = listers->findRef( lister );
333 TQString url = it.currentKey();
334 KDirLister* curLister = listers->at( curIndex );
337 bool ret = listers->removeRef( lister );
342 lister->jobDone( job );
346 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[url];
349 holders =
new TQPtrList<KDirLister>;
350 urlsCurrentlyHeld.insert( url, holders );
353 holders->append( lister );
355 emit lister->
canceled( curLister->d->url );
359 if ( listers->isEmpty() )
366 urlsCurrentlyListed.remove( url );
378 lister->d->complete =
true;
385 void KDirListerCache::stop(
KDirLister *lister,
const KURL& _u )
387 TQString urlStr( _u.url(-1) );
388 TQString urlReferenceStr = _u.internalReferenceURL();
392 kdDebug(7004) << k_funcinfo << lister <<
" url=" << _url << endl;
394 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr +
":" + urlReferenceStr];
395 if ( !listers || !listers->removeRef( lister ) )
399 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr];
402 holders =
new TQPtrList<KDirLister>;
403 urlsCurrentlyHeld.insert( urlStr +
":" + urlReferenceStr, holders );
406 holders->append( lister );
409 TDEIO::ListJob *job = jobForUrl( urlStr +
":" + urlReferenceStr );
411 lister->jobDone( job );
416 if ( listers->isEmpty() )
422 urlsCurrentlyListed.remove( urlStr +
":" + urlReferenceStr );
425 if ( lister->numJobs() == 0 )
427 lister->d->complete =
true;
434 void KDirListerCache::setAutoUpdate(
KDirLister *lister,
bool enable )
438 for ( KURL::List::Iterator it = lister->d->lstDirs.begin();
439 it != lister->d->lstDirs.end(); ++it )
442 itemsInUse[(*it).url() +
":" + (*it).internalReferenceURL()]->incAutoUpdate();
445 itemsInUse[(*it).url() +
":" + (*it).internalReferenceURL()]->decAutoUpdate();
450 void KDirListerCache::forgetDirs(
KDirLister *lister )
452 kdDebug(7004) << k_funcinfo << lister << endl;
454 emit lister->
clear();
457 KURL::List lstDirsCopy = lister->d->lstDirs;
458 for ( KURL::List::Iterator it = lstDirsCopy.begin();
459 it != lstDirsCopy.end(); ++it )
461 forgetDirs( lister, *it,
false );
465 void KDirListerCache::forgetDirs(
KDirLister *lister,
const KURL& _url,
bool notify )
467 kdDebug(7004) << k_funcinfo << lister <<
" _url: " << _url << endl;
470 url.adjustPath( -1 );
471 TQString urlStr = url.url();
472 TQString urlReferenceStr = url.internalReferenceURL();
473 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr];
477 holders->removeRef( lister );
484 lister->d->lstDirs.remove( lister->d->lstDirs.find( url ) );
486 DirItem *item = itemsInUse[urlStr +
":" + urlReferenceStr];
488 if ( holders && holders->isEmpty() )
490 urlsCurrentlyHeld.remove( urlStr +
":" + urlReferenceStr );
491 if ( !urlsCurrentlyListed[urlStr +
":" + urlReferenceStr] )
494 itemsInUse.remove( urlStr +
":" + urlReferenceStr );
497 TDEIO::ListJob *job = jobForUrl( urlStr +
":" + urlReferenceStr );
500 lister->jobDone( job );
502 kdDebug(7004) << k_funcinfo <<
"Killing update job for " << urlStr << endl;
505 if ( lister->numJobs() == 0 )
507 lister->d->complete =
true;
513 emit lister->
clear( url );
515 if ( item && item->complete )
517 kdDebug(7004) << k_funcinfo << lister <<
" item moved into cache: " << url << endl;
518 itemsCached.insert( urlStr, item );
523 const bool isLocal = item->
url.isLocalFile();
525 bool containsManuallyMounted =
false;
526 if ( !isManuallyMounted && item->lstItems && isLocal )
532 KFileItemListIterator kit( *item->lstItems );
533 for ( ; kit.current() && !containsManuallyMounted; ++kit )
535 containsManuallyMounted =
true;
538 if ( isManuallyMounted || containsManuallyMounted )
540 kdDebug(7004) <<
"Not adding a watch on " << item->url <<
" because it " <<
541 ( isManuallyMounted ?
"is manually mounted" :
"contains a manually mounted subdir" ) << endl;
542 item->complete =
false;
545 item->incAutoUpdate();
555 if ( item && lister->d->autoUpdate )
556 item->decAutoUpdate();
559 void KDirListerCache::updateDirectory(
const KURL& _dir )
561 kdDebug(7004) << k_funcinfo << _dir << endl;
563 TQString urlStr = _dir.url(-1);
564 TQString urlReferenceStr = _dir.internalReferenceURL();
565 if ( !checkUpdate( _dir, -1 ) ) {
575 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr +
":" + urlReferenceStr];
576 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr +
":" + urlReferenceStr];
580 TQWidget *window = 0;
581 TDEIO::ListJob *job = jobForUrl( urlStr +
":" + urlReferenceStr );
590 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
596 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() ) {
601 kdDebug(7004) << k_funcinfo <<
"Killed = " << killed << endl;
606 Q_ASSERT( !listers || (listers && killed) );
609 jobs.insert( job, TQValueList<TDEIO::UDSEntry>() );
611 connect( job, TQ_SIGNAL(entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )),
612 this, TQ_SLOT(slotUpdateEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )) );
613 connect( job, TQ_SIGNAL(result(
TDEIO::Job * )),
614 this, TQ_SLOT(slotUpdateResult(
TDEIO::Job * )) );
616 kdDebug(7004) << k_funcinfo <<
"update started in " << _dir << endl;
619 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
620 kdl->jobStarted( job );
629 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
631 kdl->jobStarted( job );
632 if ( first && kdl->d->window )
637 emit kdl->started( _dir );
644 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() ) {
645 kdl->jobStarted( job );
651 bool KDirListerCache::checkUpdate(
const KURL& _dir,
int truncationMode )
653 if ( !itemsInUse[_dir.url(truncationMode) +
":" + _dir.internalReferenceURL()] )
655 DirItem *item = itemsCached[_dir.url(truncationMode)];
656 if ( item && item->complete )
658 item->complete =
false;
659 item->decAutoUpdate();
672 KFileItemList *KDirListerCache::itemsForDir(
const KURL &_dir )
const
674 TQString urlStr = _dir.url(-1);
675 TQString urlReferenceStr = _dir.internalReferenceURL();
676 DirItem *item = itemsInUse[ urlStr +
":" + urlReferenceStr ];
678 item = itemsCached[ urlStr ];
680 return item ? item->lstItems : 0;
683 KFileItem *KDirListerCache::findByName(
const KDirLister *lister,
const TQString& _name )
const
687 for ( KURL::List::Iterator it = lister->d->lstDirs.begin();
688 it != lister->d->lstDirs.end(); ++it )
690 KFileItemListIterator kit( *itemsInUse[(*it).url() +
":" + (*it).internalReferenceURL()]->lstItems );
691 for ( ; kit.current(); ++kit )
692 if ( (*kit)->name() == _name )
704 KURL parentDir( _url );
705 parentDir.setPath( parentDir.directory() );
708 if ( lister && !lister->d->lstDirs.contains( parentDir ) )
711 KFileItemList *itemList = itemsForDir( parentDir );
714 KFileItemListIterator kit( *itemList );
715 for ( ; kit.current(); ++kit )
716 if ( (*kit)->url() == _url )
722 void KDirListerCache::FilesAdded(
const KURL &dir )
724 kdDebug(7004) << k_funcinfo << dir << endl;
725 updateDirectory( dir );
728 void KDirListerCache::FilesRemoved(
const KURL::List &fileList )
730 kdDebug(7004) << k_funcinfo << endl;
731 KURL::List::ConstIterator it = fileList.begin();
732 for ( ; it != fileList.end() ; ++it )
736 KURL parentDir( *it );
737 parentDir.setPath( parentDir.directory() );
738 KFileItemList *lstItems = itemsForDir( parentDir );
742 for ( ; fit; fit = lstItems->next() )
743 if ( fit->
url() == *it ) {
754 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDir.url() +
":" + parentDir.internalReferenceURL()];
756 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
757 kdl->emitDeleteItem( fileitem );
763 if ( !fileitem || fileitem->
isDir() )
775 void KDirListerCache::FilesChanged(
const KURL::List &fileList )
777 KURL::List dirsToUpdate;
778 kdDebug(7004) << k_funcinfo <<
"only half implemented" << endl;
779 KURL::List::ConstIterator it = fileList.begin();
780 for ( ; it != fileList.end() ; ++it )
782 if ( ( *it ).isLocalFile() )
784 kdDebug(7004) <<
"KDirListerCache::FilesChanged " << *it << endl;
785 KFileItem *fileitem = findByURL( 0, *it );
789 aboutToRefreshItem( fileitem );
791 emitRefreshItem( fileitem );
794 kdDebug(7004) <<
"item not found" << endl;
800 dir.setPath( dir.directory(
true ) );
801 if ( dirsToUpdate.find( dir ) == dirsToUpdate.end() ) {
802 dirsToUpdate.prepend( dir );
807 KURL::List::ConstIterator itdir = dirsToUpdate.begin();
808 for ( ; itdir != dirsToUpdate.end() ; ++itdir ) {
809 updateDirectory( *itdir );
815 void KDirListerCache::FileRenamed(
const KURL &src,
const KURL &dst )
817 kdDebug(7004) << k_funcinfo << src.prettyURL() <<
" -> " << dst.prettyURL() << endl;
824 renameDir( src, dst );
828 oldurl.adjustPath( -1 );
829 KFileItem *fileitem = findByURL( 0, oldurl );
836 aboutToRefreshItem( fileitem );
839 emitRefreshItem( fileitem );
847 void KDirListerCache::aboutToRefreshItem(
KFileItem *fileitem )
850 KURL parentDir( fileitem->
url() );
851 parentDir.setPath( parentDir.directory() );
852 TQString parentDirURL = parentDir.url();
853 TQString parentDirReferenceURL = parentDir.internalReferenceURL();
854 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDirURL +
":" + parentDirReferenceURL];
856 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
857 kdl->aboutToRefreshItem( fileitem );
860 listers = urlsCurrentlyListed[parentDirURL +
":" + parentDirReferenceURL];
862 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
863 kdl->aboutToRefreshItem( fileitem );
866 void KDirListerCache::emitRefreshItem(
KFileItem *fileitem )
869 KURL parentDir( fileitem->
url() );
870 parentDir.setPath( parentDir.directory() );
871 TQString parentDirURL = parentDir.url();
872 TQString parentDirReferenceURL = parentDir.internalReferenceURL();
873 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDirURL +
":" + parentDirReferenceURL];
875 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
877 kdl->addRefreshItem( fileitem );
882 listers = urlsCurrentlyListed[parentDirURL +
":" + parentDirReferenceURL];
884 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
886 kdl->addRefreshItem( fileitem );
891 KDirListerCache* KDirListerCache::self()
894 s_pSelf = sd_KDirListerCache.setObject( s_pSelf,
new KDirListerCache );
899 bool KDirListerCache::exists()
908 void KDirListerCache::slotFileDirty(
const KURL& _url )
910 kdDebug(7004) << k_funcinfo << _url << endl;
912 if ( !pendingUpdates[_url.path()] )
915 dir.setPath( _url.path() );
916 dir.setInternalReferenceURL(_url.internalReferenceURL());
917 if ( checkUpdate( dir, -1 ) ) {
918 updateDirectory( _url );
922 dir.setPath( dir.directory() );
923 dir.setInternalReferenceURL(_url.internalReferenceURL());
924 if ( checkUpdate( dir ) )
927 TQTimer *timer =
new TQTimer(
this, _url.path().utf8() );
928 connect( timer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(slotFileDirtyDelayed()) );
929 pendingUpdates.insert( _url.path(), timer );
930 timer->start( 500,
true );
936 void KDirListerCache::slotFileDirtyDelayed()
938 TQString file = TQString::fromUtf8( sender()->name() );
940 kdDebug(7004) << k_funcinfo << file << endl;
944 pendingUpdates.remove( file );
952 aboutToRefreshItem( item );
954 emitRefreshItem( item );
958 void KDirListerCache::slotFileCreated(
const TQString& _file )
960 kdDebug(7004) << k_funcinfo << _file << endl;
964 u.setPath( u.directory() );
968 void KDirListerCache::slotFileDeleted(
const TQString& _file )
970 kdDebug(7004) << k_funcinfo << _file << endl;
976 void KDirListerCache::slotEntries(
TDEIO::Job *job,
const TDEIO::UDSEntryList &entries )
980 TQString urlStr = url.url();
981 TQString urlReferenceStr = url.internalReferenceURL();
983 kdDebug(7004) << k_funcinfo <<
"new entries for " << url << endl;
985 DirItem *dir = itemsInUse[urlStr +
":" + urlReferenceStr];
988 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr +
":" + urlReferenceStr];
990 Q_ASSERT( !listers->isEmpty() );
993 bool delayedMimeTypes =
true;
994 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
995 delayedMimeTypes = delayedMimeTypes && kdl->d->delayedMimeTypes;
999 static const TQString& dot = TDEGlobal::staticQString(
".");
1000 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
1002 TDEIO::UDSEntryListConstIterator it = entries.begin();
1003 TDEIO::UDSEntryListConstIterator end = entries.end();
1005 for ( ; it != end; ++it )
1010 TDEIO::UDSEntry::ConstIterator entit = (*it).begin();
1011 for( ; entit != (*it).end(); ++entit ) {
1013 name = (*entit).m_str;
1018 Q_ASSERT( !name.isEmpty() );
1019 if ( name.isEmpty() ) {
1025 Q_ASSERT( !dir->rootItem );
1026 dir->rootItem =
new KFileItem( *it, url, delayedMimeTypes,
true );
1028 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1029 if ( !kdl->d->rootFileItem && kdl->d->url == url ) {
1030 kdl->d->rootFileItem = dir->rootItem;
1034 else if ( name != dotdot )
1040 dir->lstItems->append( item );
1042 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1043 kdl->addNewItem( item );
1048 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1053 void KDirListerCache::slotResult(
TDEIO::Job *j )
1059 KURL jobUrl = joburl( job );
1060 jobUrl.adjustPath(-1);
1061 TQString jobUrlStr = jobUrl.url();
1062 TQString jobReferenceUrlStr = jobUrl.internalReferenceURL();
1064 kdDebug(7004) << k_funcinfo <<
"finished listing " << jobUrl << endl;
1069 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( jobUrlStr +
":" + jobReferenceUrlStr );
1070 Q_ASSERT( listers );
1075 Q_ASSERT( !urlsCurrentlyHeld[jobUrlStr +
":" + jobReferenceUrlStr] );
1076 urlsCurrentlyHeld.insert( jobUrlStr +
":" + jobReferenceUrlStr, listers );
1082 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1084 kdl->jobDone( job );
1087 if ( kdl->numJobs() == 0 )
1089 kdl->d->complete =
true;
1096 DirItem *dir = itemsInUse[jobUrlStr +
":" + jobReferenceUrlStr];
1098 dir->complete =
true;
1100 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1102 kdl->jobDone( job );
1103 kdl->emitCompleted( jobUrl );
1104 if ( kdl->numJobs() == 0 )
1106 kdl->d->complete =
true;
1114 processPendingUpdates();
1121 void KDirListerCache::slotRedirection(
TDEIO::Job *j,
const KURL& url )
1126 KURL oldUrl = job->
url();
1130 oldUrl.adjustPath(-1);
1131 newUrl.adjustPath(-1);
1133 if ( oldUrl == newUrl )
1135 kdDebug(7004) << k_funcinfo <<
"New redirection url same as old, giving up." << endl;
1139 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << newUrl.prettyURL() << endl;
1150 DirItem *dir = itemsInUse.take( oldUrl.url() +
":" + oldUrl.internalReferenceURL() );
1153 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( oldUrl.url() +
":" + oldUrl.internalReferenceURL() );
1154 Q_ASSERT( listers );
1155 Q_ASSERT( !listers->isEmpty() );
1157 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1160 if ( kdl->d->url.equals( oldUrl,
true ) )
1162 kdl->d->rootFileItem = 0;
1163 kdl->d->url = newUrl;
1166 *kdl->d->lstDirs.find( oldUrl ) = newUrl;
1168 if ( kdl->d->lstDirs.count() == 1 )
1176 emit kdl->
clear( oldUrl );
1183 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld.take( oldUrl.url() +
":" + oldUrl.internalReferenceURL() );
1186 Q_ASSERT( !holders->isEmpty() );
1188 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1190 kdl->jobStarted( job );
1197 if ( kdl->d->url.equals( oldUrl,
true ) )
1199 kdl->d->rootFileItem = 0;
1200 kdl->d->url = newUrl;
1203 *kdl->d->lstDirs.find( oldUrl ) = newUrl;
1205 if ( kdl->d->lstDirs.count() == 1 )
1213 emit kdl->
clear( oldUrl );
1219 DirItem *newDir = itemsInUse[newUrl.url() +
":" + newUrl.internalReferenceURL()];
1222 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" already in use" << endl;
1229 TDEIO::ListJob *oldJob = jobForUrl( newUrl.url() +
":" + newUrl.internalReferenceURL(), job );
1233 TQPtrList<KDirLister> *curListers = urlsCurrentlyListed[newUrl.url() +
":" + newUrl.internalReferenceURL()];
1236 kdDebug(7004) <<
"slotRedirection: and it is currently listed" << endl;
1240 for (
KDirLister *kdl = curListers->first(); kdl; kdl = curListers->next() )
1242 kdl->jobDone( oldJob );
1244 kdl->jobStarted( job );
1245 kdl->connectJob( job );
1249 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1250 curListers->append( kdl );
1253 urlsCurrentlyListed.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), listers );
1260 TQPtrList<KDirLister> *curHolders = urlsCurrentlyHeld[newUrl.url() +
":" + newUrl.internalReferenceURL()];
1263 kdDebug(7004) <<
"slotRedirection: and it is currently held." << endl;
1265 for (
KDirLister *kdl = curHolders->first(); kdl; kdl = curHolders->next() )
1267 kdl->jobStarted( job );
1273 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1274 curHolders->append( kdl );
1277 urlsCurrentlyHeld.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), holders );
1282 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1284 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1285 kdl->d->rootFileItem = newDir->rootItem;
1287 kdl->addNewItems( *(newDir->lstItems) );
1293 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1295 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1296 kdl->d->rootFileItem = newDir->rootItem;
1298 kdl->addNewItems( *(newDir->lstItems) );
1303 else if ( (newDir = itemsCached.take( newUrl.url() )) )
1305 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" is unused, but already in the cache." << endl;
1308 itemsInUse.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), newDir );
1309 urlsCurrentlyListed.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), listers );
1311 urlsCurrentlyHeld.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), holders );
1314 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1316 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1317 kdl->d->rootFileItem = newDir->rootItem;
1319 kdl->addNewItems( *(newDir->lstItems) );
1325 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1327 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1328 kdl->d->rootFileItem = newDir->rootItem;
1330 kdl->addNewItems( *(newDir->lstItems) );
1337 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" has not been listed yet." << endl;
1339 delete dir->rootItem;
1341 dir->lstItems->clear();
1342 dir->redirect( newUrl );
1343 itemsInUse.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), dir );
1344 urlsCurrentlyListed.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), listers );
1347 urlsCurrentlyHeld.insert( newUrl.url() +
":" + newUrl.internalReferenceURL(), holders );
1358 job->disconnect(
this );
1360 connect( job, TQ_SIGNAL(entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )),
1361 this, TQ_SLOT(slotUpdateEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )) );
1362 connect( job, TQ_SIGNAL(result(
TDEIO::Job * )),
1363 this, TQ_SLOT(slotUpdateResult(
TDEIO::Job * )) );
1372 void KDirListerCache::renameDir(
const KURL &oldUrl,
const KURL &newUrl )
1374 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << newUrl.prettyURL() << endl;
1375 TQString oldUrlStr = oldUrl.url(-1);
1376 TQString newUrlStr = newUrl.url(-1);
1383 TQDictIterator<DirItem> itu( itemsInUse );
1385 while ( itu.current() )
1388 DirItem *dir = itu.current();
1389 TQString oldDirURLIndep = itu.currentKey();
1390 oldDirURLIndep.truncate(oldDirURLIndep.length() - (dir->url.internalReferenceURL().length()+strlen(
":")));
1391 KURL oldDirUrl ( oldDirURLIndep );
1394 if ( oldUrl.isParentOf( oldDirUrl ) )
1397 TQString relPath = oldDirUrl.path().mid( oldUrl.path().length() );
1399 KURL newDirUrl( newUrl );
1400 if ( !relPath.isEmpty() ) {
1401 newDirUrl.addPath( relPath );
1406 dir->redirect( newDirUrl );
1407 itemsInUse.remove( itu.currentKey() );
1408 itemsInUse.insert( newDirUrl.url(-1), dir );
1410 if ( dir->lstItems )
1413 KFileItemListIterator kit( *dir->lstItems );
1414 for ( ; kit.current(); ++kit )
1416 KURL oldItemUrl = (*kit)->url();
1417 TQString oldItemUrlStr( oldItemUrl.url(-1) );
1418 KURL newItemUrl( oldItemUrl );
1419 newItemUrl.setPath( newDirUrl.path() );
1420 newItemUrl.addPath( oldItemUrl.fileName() );
1421 kdDebug(7004) <<
"KDirListerCache::renameDir renaming " << oldItemUrlStr <<
" to " << newItemUrl.url() << endl;
1422 (*kit)->setURL( newItemUrl );
1425 emitRedirections( oldDirUrl, newDirUrl );
1433 removeDirFromCache( oldUrl );
1437 void KDirListerCache::emitRedirections(
const KURL &oldUrl,
const KURL &url )
1439 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << url.prettyURL() << endl;
1440 TQString oldUrlStr = oldUrl.url(-1);
1441 TQString urlStr = url.url(-1);
1442 TQString oldReferenceUrlStr = oldUrl.internalReferenceURL();
1443 TQString urlReferenceStr = url.internalReferenceURL();
1445 TDEIO::ListJob *job = jobForUrl( oldUrlStr +
":" + oldReferenceUrlStr );
1450 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( oldUrlStr +
":" + oldReferenceUrlStr );
1454 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1457 kdl->jobDone( job );
1462 urlsCurrentlyListed.insert( urlStr +
":" + urlReferenceStr, listers );
1467 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld.take( oldUrlStr +
":" + oldReferenceUrlStr );
1471 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1472 kdl->jobDone( job );
1474 urlsCurrentlyHeld.insert( urlStr +
":" + urlReferenceStr, holders );
1479 updateDirectory( url );
1482 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1489 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1491 *kdl->d->lstDirs.find( oldUrl ) = url;
1493 if ( kdl->d->lstDirs.count() == 1 )
1501 void KDirListerCache::removeDirFromCache(
const KURL& dir )
1503 kdDebug(7004) <<
"KDirListerCache::removeDirFromCache " << dir.prettyURL() << endl;
1504 TQCacheIterator<DirItem> itc( itemsCached );
1505 while ( itc.current() )
1507 if ( dir.isParentOf( KURL( itc.currentKey() ) ) )
1508 itemsCached.remove( itc.currentKey() );
1514 void KDirListerCache::slotUpdateEntries(
TDEIO::Job* job,
const TDEIO::UDSEntryList& list )
1519 void KDirListerCache::slotUpdateResult(
TDEIO::Job * j )
1524 KURL jobUrl = joburl( job );
1525 jobUrl.adjustPath(-1);
1526 TQString jobUrlStr = jobUrl.url();
1527 TQString jobReferenceUrlStr = jobUrl.internalReferenceURL();
1529 kdDebug(7004) << k_funcinfo <<
"finished update " << jobUrl << endl;
1533 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[jobUrlStr +
":" + jobReferenceUrlStr];
1534 TQPtrList<KDirLister> *tmpLst = urlsCurrentlyListed.take( jobUrlStr +
":" + jobReferenceUrlStr );
1539 for ( kdl = tmpLst->first(); kdl; kdl = tmpLst->next() )
1541 Q_ASSERT( listers->containsRef( kdl ) == 0 );
1542 listers->append( kdl );
1547 urlsCurrentlyHeld.insert( jobUrlStr +
":" + jobReferenceUrlStr, listers );
1552 Q_ASSERT( listers );
1556 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1558 kdl->jobDone( job );
1564 if ( kdl->numJobs() == 0 )
1566 kdl->d->complete =
true;
1575 processPendingUpdates();
1579 DirItem *dir = itemsInUse[jobUrlStr +
":" + jobReferenceUrlStr];
1580 dir->complete =
true;
1584 bool delayedMimeTypes =
true;
1585 for ( kdl = listers->first(); kdl; kdl = listers->next() ) {
1586 delayedMimeTypes = delayedMimeTypes && kdl->d->delayedMimeTypes;
1590 TQDict<KFileItem> fileItems( 9973 );
1592 KFileItemListIterator kit ( *(dir->lstItems) );
1595 for ( ; kit.current(); ++kit )
1598 if (!((*kit)->listerURL().isEmpty())) {
1599 fileItems.insert( (*kit)->listerURL().url(), *kit );
1602 fileItems.insert( (*kit)->url().url(), *kit );
1606 static const TQString& dot = TDEGlobal::staticQString(
".");
1607 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
1611 TQValueList<TDEIO::UDSEntry> buf = jobs[job];
1612 TQValueListIterator<TDEIO::UDSEntry> it = buf.begin();
1613 for ( ; it != buf.end(); ++it )
1617 item =
new KFileItem( *it, jobUrl, delayedMimeTypes,
true );
1620 item->
setUDSEntry( *it, jobUrl, delayedMimeTypes,
true );
1624 TQString name = item->
name();
1625 Q_ASSERT( !name.isEmpty() );
1629 if ( name.isEmpty() || name == dotdot ) {
1637 if ( !dir->rootItem )
1639 dir->rootItem = item;
1642 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1643 if ( !kdl->d->rootFileItem && kdl->d->url == jobUrl ) {
1644 kdl->d->rootFileItem = dir->rootItem;
1653 if ( (tmp = fileItems[item->
url().url()]) )
1658 if ( !tmp->cmp( *item ) )
1660 for ( kdl = listers->first(); kdl; kdl = listers->next() ) {
1661 kdl->aboutToRefreshItem( tmp );
1665 tmp->assign( *item );
1667 for ( kdl = listers->first(); kdl; kdl = listers->next() ) {
1668 kdl->addRefreshItem( tmp );
1677 dir->lstItems->append( item );
1679 for ( kdl = listers->first(); kdl; kdl = listers->next() ) {
1680 kdl->addNewItem( item );
1694 deleteUnmarkedItems( listers, dir->lstItems );
1696 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1700 kdl->jobDone( job );
1702 kdl->emitCompleted( jobUrl );
1703 if ( kdl->numJobs() == 0 )
1705 kdl->d->complete =
true;
1712 processPendingUpdates();
1720 TQMap< TDEIO::ListJob *, TQValueList<TDEIO::UDSEntry> >::Iterator it = jobs.begin();
1721 while ( it != jobs.end() )
1724 KURL itjoburl = joburl( job );
1725 if ( ((itjoburl.url(-1) +
":" + itjoburl.internalReferenceURL()) == url) && (job != not_job) ) {
1746 job->disconnect(
this );
1750 void KDirListerCache::deleteUnmarkedItems( TQPtrList<KDirLister> *listers, KFileItemList *lstItems )
1755 while ( (item = lstItems->current()) )
1759 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
1760 kdl->emitDeleteItem( item );
1763 if ( item->
isDir() ) {
1764 deleteDir( item->
url() );
1775 void KDirListerCache::deleteDir(
const KURL& dirUrl )
1782 TQDictIterator<DirItem> itu( itemsInUse );
1783 while ( itu.current() )
1785 TQString deletedUrlIndep = itu.currentKey();
1786 deletedUrlIndep.truncate(deletedUrlIndep.length() - ((*itu)->url.internalReferenceURL().length()+strlen(
":")));
1787 KURL deletedUrl( deletedUrlIndep );
1788 if ( dirUrl.isParentOf( deletedUrl ) )
1792 TQPtrList<KDirLister> *kdls = urlsCurrentlyListed[deletedUrl.url() +
":" + deletedUrl.internalReferenceURL()];
1796 kdls =
new TQPtrList<KDirLister>( *kdls );
1797 for (
KDirLister *kdl = kdls->first(); kdl; kdl = kdls->next() )
1798 stop( kdl, deletedUrl );
1806 kdls = urlsCurrentlyHeld[deletedUrl.url() +
":" + deletedUrl.internalReferenceURL()];
1810 kdls =
new TQPtrList<KDirLister>( *kdls );
1812 for (
KDirLister *kdl = kdls->first(); kdl; kdl = kdls->next() )
1815 if ( kdl->d->url == deletedUrl )
1818 if ( kdl->d->rootFileItem )
1819 emit kdl->
deleteItem( kdl->d->rootFileItem );
1821 kdl->d->rootFileItem = 0;
1825 bool treeview = kdl->d->lstDirs.count() > 1;
1829 forgetDirs( kdl, deletedUrl, treeview );
1839 DirItem *dir = itemsInUse.take( deletedUrl.url() +
":" + deletedUrl.internalReferenceURL() );
1849 removeDirFromCache( dirUrl );
1852 void KDirListerCache::processPendingUpdates()
1858 void KDirListerCache::printDebug()
1860 kdDebug(7004) <<
"Items in use: " << endl;
1861 TQDictIterator<DirItem> itu( itemsInUse );
1862 for ( ; itu.current() ; ++itu ) {
1863 kdDebug(7004) <<
" " << itu.currentKey() <<
" URL: " << itu.current()->url
1864 <<
" rootItem: " << ( itu.current()->rootItem ? itu.current()->rootItem->url() : KURL() )
1865 <<
" autoUpdates refcount: " << itu.current()->autoUpdates
1866 <<
" complete: " << itu.current()->complete
1867 << ( itu.current()->lstItems ? TQString(
" with %1 items.").arg(itu.current()->lstItems->count()) : TQString(
" lstItems=NULL") ) << endl;
1870 kdDebug(7004) <<
"urlsCurrentlyHeld: " << endl;
1871 TQDictIterator< TQPtrList<KDirLister> > it( urlsCurrentlyHeld );
1872 for ( ; it.current() ; ++it )
1875 for ( TQPtrListIterator<KDirLister> listit( *it.current() ); listit.current(); ++listit )
1876 list +=
" 0x" + TQString::number( (
long)listit.current(), 16 );
1877 kdDebug(7004) <<
" " << it.currentKey() <<
" " << it.current()->count() <<
" listers: " << list << endl;
1880 kdDebug(7004) <<
"urlsCurrentlyListed: " << endl;
1881 TQDictIterator< TQPtrList<KDirLister> > it2( urlsCurrentlyListed );
1882 for ( ; it2.current() ; ++it2 )
1885 for ( TQPtrListIterator<KDirLister> listit( *it2.current() ); listit.current(); ++listit )
1886 list +=
" 0x" + TQString::number( (
long)listit.current(), 16 );
1887 kdDebug(7004) <<
" " << it2.currentKey() <<
" " << it2.current()->count() <<
" listers: " << list << endl;
1890 TQMap< TDEIO::ListJob *, TQValueList<TDEIO::UDSEntry> >::Iterator jit = jobs.begin();
1891 kdDebug(7004) <<
"Jobs: " << endl;
1892 for ( ; jit != jobs.end() ; ++jit )
1893 kdDebug(7004) <<
" " << jit.key() <<
" listing " << joburl( jit.key() ).prettyURL() <<
": " << (*jit).count() <<
" entries." << endl;
1895 kdDebug(7004) <<
"Items in cache: " << endl;
1896 TQCacheIterator<DirItem> itc( itemsCached );
1897 for ( ; itc.current() ; ++itc )
1898 kdDebug(7004) <<
" " << itc.currentKey() <<
" rootItem: "
1899 << ( itc.current()->rootItem ? itc.current()->rootItem->url().prettyURL() : TQString(
"NULL") )
1900 << ( itc.current()->lstItems ? TQString(
" with %1 items.").arg(itc.current()->lstItems->count()) : TQString(
" lstItems=NULL") ) << endl;
1909 kdDebug(7003) <<
"+KDirLister" << endl;
1911 d =
new KDirListerPrivate;
1914 d->delayedMimeTypes = _delayedMimeTypes;
1925 kdDebug(7003) <<
"-KDirLister" << endl;
1927 if ( KDirListerCache::exists() )
1931 s_pCache->forgetDirs(
this );
1939 kdDebug(7003) << k_funcinfo << _url.prettyURL()
1940 <<
" keep=" << _keep <<
" reload=" << _reload << endl;
1943 if ( d->changes != NONE && _keep ) {
1955 if (!_url.isLocalFile()) {
1958 d->openURLContext[localURLJob] = KDirListerPrivate::OpenURLContext{_url, _keep, _reload};
1961 connect(localURLJob, TQ_SIGNAL(destroyed()),
this, TQ_SLOT(slotLocalURLKIODestroyed()));
1962 d->complete =
false;
1967 return s_pCache->listDir(
this, _url, _keep, _reload );
1970 void KDirLister::slotOpenURLGotLocalURL(
TDEIO::LocalURLJob *job,
const KURL& url,
bool isLocal) {
1971 auto jobIt = d->openURLContext.find(job);
1973 Q_ASSERT( jobIt != d->openURLContext.end() );
1975 auto ctx = jobIt.data();
1976 KURL realURL = ctx.url;
1979 realURL.setInternalReferenceURL(ctx.url.url());
1980 d->m_referenceURLMap[ctx.url.url()] =
url.path();
1982 d->openURLContext.remove(jobIt);
1983 d->complete = d->jobData.isEmpty() && d->openURLContext.isEmpty();
1984 s_pCache->listDir(
this, realURL, ctx.keep, ctx.reload );
1987 void KDirLister::slotLocalURLKIODestroyed() {
1989 auto jobIt = d->openURLContext.find(terminatedJob);
1991 if (jobIt != d->openURLContext.end()) {
1992 auto ctx = jobIt.data();
1993 d->openURLContext.remove(jobIt);
1994 d->complete = d->jobData.isEmpty() && d->openURLContext.isEmpty();
1995 s_pCache->listDir(
this, ctx.url, ctx.keep, ctx.reload );
2001 kdDebug(7003) << k_funcinfo << endl;
2002 s_pCache->stop(
this );
2003 for(
auto it = d->openURLContext.begin(); it != d->openURLContext.end(); ++it ) {
2004 it.key()->disconnect(
this );
2007 d->openURLContext.clear();
2008 d->m_referenceURLMap.clear();
2013 kdDebug(7003) << k_funcinfo << _url.prettyURL() << endl;
2014 s_pCache->stop(
this, _url );
2015 TQPtrList<TDEIO::Job> toRemove;
2016 for(
auto it = d->openURLContext.begin(); it != d->openURLContext.end(); ++it ) {
2017 if( it.data().url ==_url ) {
2018 it.key()->disconnect(
this );
2020 toRemove.append(it.key());
2023 for(
const auto &job: toRemove) {
2024 d->openURLContext.remove(job);
2026 d->m_referenceURLMap.remove(_url.url());
2031 return d->autoUpdate;
2036 if ( d->autoUpdate == _enable )
2039 d->autoUpdate = _enable;
2040 s_pCache->setAutoUpdate(
this, _enable );
2045 return d->isShowingDotFiles;
2050 if ( d->isShowingDotFiles == _showDotFiles )
2053 d->isShowingDotFiles = _showDotFiles;
2054 d->changes ^= DOT_FILES;
2059 return d->dirOnlyMode;
2064 if ( d->dirOnlyMode == _dirsOnly )
2067 d->dirOnlyMode = _dirsOnly;
2068 d->changes ^= DIR_ONLY_MODE;
2073 return d->autoErrorHandling;
2078 d->autoErrorHandling = enable;
2079 d->errorParent = parent;
2094 if ( d->changes == NONE )
2097 static const TQString& dot = TDEGlobal::staticQString(
".");
2098 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
2100 for ( KURL::List::Iterator it = d->lstDirs.begin();
2101 it != d->lstDirs.end(); ++it )
2103 KFileItemListIterator kit( *s_pCache->itemsForDir( *it ) );
2104 for ( ; kit.current(); ++kit )
2106 if ( (*kit)->text() == dot || (*kit)->text() == dotdot )
2109 bool oldMime =
true, newMime =
true;
2111 if ( d->changes & MIME_FILTER )
2113 oldMime =
doMimeFilter( (*kit)->mimetype(), d->oldMimeFilter )
2114 && doMimeExcludeFilter( (*kit)->mimetype(), d->oldMimeExcludeFilter );
2115 newMime =
doMimeFilter( (*kit)->mimetype(), d->mimeFilter )
2116 && doMimeExcludeFilter( (*kit)->mimetype(), d->mimeExcludeFilter );
2118 if ( oldMime && !newMime )
2125 if ( d->changes & DIR_ONLY_MODE )
2128 if ( d->dirOnlyMode )
2130 if ( !(*kit)->isDir() )
2133 else if ( !(*kit)->isDir() ) {
2140 if ( (*kit)->isHidden() )
2142 if ( d->changes & DOT_FILES )
2145 if ( d->isShowingDotFiles ) {
2155 else if ( d->changes & NAME_FILTER )
2157 bool oldName = (*kit)->isDir() ||
2158 d->oldFilters.isEmpty() ||
2161 bool newName = (*kit)->isDir() ||
2162 d->lstFilters.isEmpty() ||
2165 if ( oldName && !newName )
2170 else if ( !oldName && newName ) {
2175 if ( (d->changes & MIME_FILTER) && !oldMime && newMime ) {
2188 s_pCache->updateDirectory( _u );
2198 return d->rootFileItem;
2203 return s_pCache->findByURL(
this, _url );
2208 return s_pCache->findByName(
this, _name );
2211 #ifndef KDE_NO_COMPAT
2212 KFileItem *KDirLister::find(
const KURL& _url )
const
2223 if ( !(d->changes & NAME_FILTER) )
2225 d->oldFilters = d->lstFilters;
2226 d->lstFilters.setAutoDelete(
false );
2229 d->lstFilters.clear();
2230 d->lstFilters.setAutoDelete(
true );
2235 TQStringList list = TQStringList::split(
' ',
nameFilter );
2236 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
2237 d->lstFilters.append(
new TQRegExp(*it,
false,
true ) );
2239 d->changes |= NAME_FILTER;
2244 return d->nameFilter;
2249 if ( !(d->changes & MIME_FILTER) )
2250 d->oldMimeFilter = d->mimeFilter;
2252 if ( mimeFilter.find(
"all/allfiles") != mimeFilter.end() ||
2253 mimeFilter.find(
"all/all") != mimeFilter.end() )
2254 d->mimeFilter.clear();
2256 d->mimeFilter = mimeFilter;
2258 d->changes |= MIME_FILTER;
2263 if ( !(d->changes & MIME_FILTER) )
2264 d->oldMimeExcludeFilter = d->mimeExcludeFilter;
2266 d->mimeExcludeFilter = mimeExcludeFilter;
2267 d->changes |= MIME_FILTER;
2273 if ( !(d->changes & MIME_FILTER) )
2275 d->oldMimeFilter = d->mimeFilter;
2276 d->oldMimeExcludeFilter = d->mimeExcludeFilter;
2278 d->mimeFilter.clear();
2279 d->mimeExcludeFilter.clear();
2280 d->changes |= MIME_FILTER;
2285 return d->mimeFilter;
2295 return doMimeFilter( mime, d->mimeFilter ) && doMimeExcludeFilter(mime,d->mimeExcludeFilter);
2303 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
2305 if ( item->
text() == dotdot )
2308 if ( !d->isShowingDotFiles && item->
isHidden() )
2311 if ( item->
isDir() || d->lstFilters.isEmpty() )
2321 if ( d->mimeFilter.isEmpty() && d->mimeExcludeFilter.isEmpty() )
2328 for ( TQPtrListIterator<TQRegExp> it( filters ); it.current(); ++it )
2329 if ( it.current()->exactMatch( name ) )
2337 if ( filters.isEmpty() )
2342 TQStringList::ConstIterator it = filters.begin();
2343 for ( ; it != filters.end(); ++it )
2344 if ( mimeptr->is(*it) )
2352 bool KDirLister::doMimeExcludeFilter(
const TQString& mime,
const TQStringList& filters )
const
2354 if ( filters.isEmpty() )
2357 TQStringList::ConstIterator it = filters.begin();
2358 for ( ; it != filters.end(); ++it )
2359 if ( (*it) == mime )
2368 return s_pCache->validURL(
this, _url );
2373 if ( d->autoErrorHandling ) {
2381 void KDirLister::addNewItem(
const KFileItem *item )
2383 TQString refURL = item->
url().internalReferenceURL();
2384 if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) &&
2385 item->
url().path().startsWith(d->m_referenceURLMap[refURL]))
2389 if (!refURL.endsWith(
"/"))
2393 KURL newItemURL(refURL);
2394 newItemURL.addPath(item->
url().fileName());
2395 const_cast<KFileItem*
>(item)->setListerURL(newItemURL);
2396 const_cast<KFileItem*
>(item)->setURL(newItemURL);
2405 if ( !d->lstNewItems ) {
2406 d->lstNewItems =
new KFileItemList;
2409 d->lstNewItems->append( item );
2413 if ( !d->lstMimeFilteredItems ) {
2414 d->lstMimeFilteredItems =
new KFileItemList;
2417 d->lstMimeFilteredItems->append( item );
2421 void KDirLister::addNewItems(
const KFileItemList& items )
2426 for ( KFileItemListIterator kit(
items ); kit.current(); ++kit ) {
2431 void KDirLister::aboutToRefreshItem(
const KFileItem *item )
2435 d->refreshItemWasFiltered =
true;
2437 d->refreshItemWasFiltered =
true;
2439 d->refreshItemWasFiltered =
false;
2442 void KDirLister::addRefreshItem(
const KFileItem *item )
2446 TQString refURL = item->
url().internalReferenceURL();
2447 if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) &&
2448 item->
url().path().startsWith(d->m_referenceURLMap[refURL]))
2452 if (!refURL.endsWith(
"/"))
2456 KURL newItemURL(refURL);
2457 newItemURL.addPath(item->
url().fileName());
2458 const_cast<KFileItem*
>(item)->setListerURL(newItemURL);
2459 const_cast<KFileItem*
>(item)->setURL(newItemURL);
2464 if ( d->refreshItemWasFiltered )
2466 if ( !d->lstNewItems ) {
2467 d->lstNewItems =
new KFileItemList;
2470 d->lstNewItems->append( item );
2474 if ( !d->lstRefreshItems ) {
2475 d->lstRefreshItems =
new KFileItemList;
2478 d->lstRefreshItems->append( item );
2481 else if ( !d->refreshItemWasFiltered )
2483 if ( !d->lstRemoveItems ) {
2484 d->lstRemoveItems =
new KFileItemList;
2489 d->lstRemoveItems->append( item );
2493 void KDirLister::emitItems()
2495 KFileItemList *tmpNew = d->lstNewItems;
2498 KFileItemList *tmpMime = d->lstMimeFilteredItems;
2499 d->lstMimeFilteredItems = 0;
2501 KFileItemList *tmpRefresh = d->lstRefreshItems;
2502 d->lstRefreshItems = 0;
2504 KFileItemList *tmpRemove = d->lstRemoveItems;
2505 d->lstRemoveItems = 0;
2512 TQString prevProtocol;
2513 TQString prevPrefix;
2514 KFileItemList emitList;
2515 for ( KFileItemListIterator kit( *tmpNew ); kit.current(); ++kit )
2518 protocol = item->
url().protocol();
2519 prefix = TQStringList::split(
"/", item->
url().path())[0];
2520 if ((protocol != prevProtocol) || (prefix != prevPrefix)) {
2521 if (emitList.count() > 0) {
2526 emitList.append(item);
2527 prevProtocol = protocol;
2528 prevPrefix = prefix;
2531 if (emitList.count() > 0) {
2551 for (
KFileItem *tmp = tmpRemove->first(); tmp; tmp = tmpRemove->next() ) {
2558 void KDirLister::emitDeleteItem(
KFileItem *item )
2572 void KDirLister::slotInfoMessage(
TDEIO::Job *,
const TQString& message )
2577 void KDirLister::slotPercent(
TDEIO::Job *job,
unsigned long pcnt )
2585 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2586 while ( dataIt != d->jobData.end() )
2588 result += (*dataIt).percent * (*dataIt).totalSize;
2589 size += (*dataIt).totalSize;
2605 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2606 while ( dataIt != d->jobData.end() )
2608 result += (*dataIt).totalSize;
2620 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2621 while ( dataIt != d->jobData.end() )
2623 result += (*dataIt).processedSize;
2630 void KDirLister::slotSpeed(
TDEIO::Job *job,
unsigned long spd )
2635 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2636 while ( dataIt != d->jobData.end() )
2638 result += (*dataIt).speed;
2642 emit
speed( result );
2645 uint KDirLister::numJobs()
2647 return d->jobData.count();
2652 d->jobData.remove( job );
2657 KDirListerPrivate::JobData jobData;
2659 jobData.percent = 0;
2660 jobData.processedSize = 0;
2661 jobData.totalSize = 0;
2663 d->jobData.insert( job, jobData );
2664 d->complete =
false;
2670 this, TQ_SLOT(slotInfoMessage(
TDEIO::Job *,
const TQString& )) );
2672 this, TQ_SLOT(slotPercent(
TDEIO::Job *,
unsigned long )) );
2678 this, TQ_SLOT(slotSpeed(
TDEIO::Job *,
unsigned long )) );
2681 void KDirLister::emitCompleted(
const KURL& _url )
2683 TQString refURL = _url.internalReferenceURL();
2684 if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) &&
2685 _url.path().startsWith(d->m_referenceURLMap[refURL]))
2689 if (!refURL.endsWith(
"/"))
2693 KURL newItemURL(refURL);
2694 newItemURL.addPath(_url.fileName());
2720 KFileItemList result;
2721 KFileItemList *allItems = s_pCache->itemsForDir( dir );
2726 if ( which == AllItems ) {
2731 for ( KFileItemListIterator kit( *allItems ); kit.current(); ++kit )
2736 result.append( item );
2746 void KDirLister::virtual_hook(
int,
void * )
2749 #include "kdirlister.moc"
2750 #include "kdirlister_p.moc"
The dir lister deals with the tdeiojob used to list and update a directory and has signals for the us...
bool autoUpdate() const
Checks whether KDirWatch will automatically update directories.
virtual bool openURL(const KURL &_url, bool _keep=false, bool _reload=false)
Run the directory lister on the given url.
void newItems(const KFileItemList &items)
Signal new items.
void speed(int bytes_per_second)
Emitted to display information about the speed of the jobs.
virtual bool doNameFilter(const TQString &name, const TQPtrList< TQRegExp > &filters) const
Called by the public matchesFilter() to do the actual filtering.
virtual bool doMimeFilter(const TQString &mime, const TQStringList &filters) const
Called by the public matchesMimeFilter() to do the actual filtering.
bool autoErrorHandlingEnabled() const
Check whether auto error handling is enabled.
bool matchesFilter(const TQString &name) const
Checks whether name matches a filter in the list of name filters.
bool isFinished() const
Returns true if no io operation is currently in progress.
virtual KFileItem * findByURL(const KURL &_url) const
Find an item by its URL.
const TQStringList & mimeFilters() const
Returns the list of mime based filters, as set via setMimeFilter().
KFileItem * rootItem() const
Returns the file item of the URL.
void setMainWindow(TQWidget *window)
Pass the main window this object is associated with this is used for caching authentication data.
virtual void setMimeFilter(const TQStringList &mimeList)
Set mime-based filter to only list items matching the given mimetypes.
virtual void setNameFilter(const TQString &filter)
Set a name filter to only list items matching this name, e.g.
bool dirOnlyMode() const
Checks whether the KDirLister only lists directories or all files.
virtual KFileItem * findByName(const TQString &name) const
Find an item by its name.
KFileItemList items(WhichItems which=FilteredItems) const
Returns the items listed for the current url().
virtual void clearMimeFilter()
Clears the mime based filter.
void setMimeExcludeFilter(const TQStringList &mimeList)
Filtering should be done with KFileFilter.
virtual void emitChanges()
Actually emit the changes made with setShowingDotFiles, setDirOnlyMode, setNameFilter and setMimeFilt...
void canceled()
Tell the view that the user canceled the listing.
virtual void setDirOnlyMode(bool dirsOnly)
Call this to list only directories.
bool showingDotFiles() const
Checks whether hidden files (files beginning with a dot) will be shown.
void completed()
Tell the view that listing is finished.
void deleteItem(KFileItem *_fileItem)
Signal an item to remove.
virtual bool validURL(const KURL &) const
Checks if an url is malformed or not and displays an error message if it is and autoErrorHandling is ...
KDirLister(bool _delayedMimeTypes=false)
Create a directory lister.
void processedSize(TDEIO::filesize_t size)
Regularly emitted to show the progress of this KDirLister.
void refreshItems(const KFileItemList &items)
Signal an item to refresh (its mimetype/icon/name has changed).
virtual void stop()
Stop listing all directories currently being listed.
virtual ~KDirLister()
Destroy the directory lister.
void clear()
Signal to clear all items.
const TQString & nameFilter() const
Returns the current name filter, as set via setNameFilter()
virtual void handleError(TDEIO::Job *)
Reimplement to customize error handling.
virtual void updateDirectory(const KURL &_dir)
Update the directory dir.
const KURL::List & directories() const
Returns all URLs that are listed by this KDirLister.
const KURL & url() const
Returns the top level URL that is listed by this KDirLister.
void started(const KURL &_url)
Tell the view that we started to list url.
virtual void setShowingDotFiles(bool _showDotFiles)
Changes the "is viewing dot files" setting.
void totalSize(TDEIO::filesize_t size)
Emitted when we know the size of the jobs.
bool matchesMimeFilter(const TQString &mime) const
Checks whether mime matches a filter in the list of mime types.
virtual void setAutoUpdate(bool enable)
Enable/disable automatic directory updating, when a directory changes (using KDirWatch).
void itemsFilteredByMime(const KFileItemList &items)
Send a list of items filtered-out by mime-type.
TQWidget * mainWindow()
Returns the main window associated with this object.
KFileItemList itemsForDir(const KURL &dir, WhichItems which=FilteredItems) const
Returns the items listed for the given dir.
WhichItems
Used by items() and itemsForDir() to specify whether you want all items for a directory or just the f...
void setAutoErrorHandlingEnabled(bool enable, TQWidget *parent)
Enable or disable auto error handling is enabled.
void percent(int percent)
Progress signal showing the overall progress of the KDirLister.
void infoMessage(const TQString &msg)
Emitted to display information about running jobs.
void redirection(const KURL &_url)
Signal a redirection.
static bool exists()
Returns true if there is an instance of KDirWatch.
A KFileItem is a generic class to handle a file, local or remote.
const TQString & text() const
Returns the text of the file item.
bool isMarked() const
Used when updating a directory.
TQString mimetype() const
Returns the mimetype of the file item.
const TQString & name(bool lowerCase=false) const
Return the name of the file item (without a path).
bool isLocalFile() const
Returns true if the file is a local file.
void mark()
Marks the item.
void setURL(const KURL &url)
Sets the item's URL.
void setUDSEntry(const TDEIO::UDSEntry &entry, const KURL &url, bool determineMimeTypeOnDemand=false, bool urlIsDirectory=false)
Reinitialize KFileItem with a new UDSEntry.
const KURL & url() const
Returns the url of the file.
TQString localPath() const
Returns the local path if isLocalFile() == true or the TDEIO item has a UDS_LOCAL_PATH atom.
void refreshMimeType()
Re-reads mimetype information.
bool isDir() const
Returns true if this item represents a directory.
bool isHidden() const
Checks whether the file is hidden.
void refresh()
Throw away and re-read (for local files) all information about the file.
static Ptr mimeType(const TQString &_name)
Retrieve a pointer to the mime type _name or a pointer to the default mime type "application/octet-st...
static bool supportsListing(const KURL &url)
Returns whether the protocol can list files/objects.
The base class for all jobs.
void showErrorDialog(TQWidget *parent=0L)
Display a dialog box to inform the user of the error given by this job.
int error() const
Returns the error code, if there has been an error.
void setWindow(TQWidget *window)
TQWidget * window() const
A ListJob is allows you to get the get the content of a directory.
const KURL & redirectionURL() const
Returns the ListJob's redirection URL.
A TDEIO job that finds a local URL.
const KURL & url() const
Returns the SimpleJob's URL.
virtual void kill(bool quietly=true)
Abort job.
TDEIO_EXPORT LocalURLJob * localURL(const KURL &remoteUrl)
Retrieve local URL if available.
@ UDS_NAME
Filename - as displayed in directory listings etc.
TDEIO_EXPORT bool manually_mounted(const TQString &filename)
Checks if the path belongs to a filesystem that is manually mounted.
TDEIO_EXPORT ListJob * listDir(const KURL &url, bool showProgressInfo=true, bool includeHidden=true)
List the contents of url, which is assumed to be a directory.
TQ_ULLONG filesize_t
64-bit file size