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 )
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, TQT_SIGNAL( entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & ) ),
247 this, TQT_SLOT( slotEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & ) ) );
248 connect( job, TQT_SIGNAL( result(
TDEIO::Job * ) ),
249 this, TQT_SLOT( slotResult(
TDEIO::Job * ) ) );
250 connect( job, TQT_SIGNAL( redirection(
TDEIO::Job *,
const KURL & ) ),
251 this, TQT_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, TQT_SIGNAL(entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )),
612 this, TQT_SLOT(slotUpdateEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )) );
613 connect( job, TQT_SIGNAL(result(
TDEIO::Job * )),
614 this, TQT_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, TQT_SIGNAL(timeout()),
this, TQT_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 )
978 KURL url = joburl( static_cast<TDEIO::ListJob *>(job) );
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, TQT_SIGNAL(entries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )),
1361 this, TQT_SLOT(slotUpdateEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList & )) );
1362 connect( job, TQT_SIGNAL(result(
TDEIO::Job * )),
1363 this, TQT_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;
1916 setAutoUpdate(
true );
1917 setDirOnlyMode(
false );
1918 setShowingDotFiles(
false );
1920 setAutoErrorHandlingEnabled(
true, 0 );
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 ) {
1950 if (!_url.isLocalFile()) {
1953 d->openURL_url[localURLJob] = _url;
1954 d->openURL_keep[localURLJob] = _keep;
1955 d->openURL_reload[localURLJob] = _reload;
1957 connect(localURLJob, TQT_SIGNAL(destroyed()),
this, TQT_SLOT(slotLocalURLKIODestroyed()));
1962 return s_pCache->listDir(
this, _url, _keep, _reload );
1966 void KDirLister::slotOpenURLGotLocalURL(
TDEIO::LocalURLJob *job,
const KURL& url,
bool isLocal) {
1967 KURL realURL = d->openURL_url[job];
1970 realURL.setInternalReferenceURL(d->openURL_url[job].url());
1971 d->m_referenceURLMap[d->openURL_url[job].url()] = url.path();
1973 s_pCache->listDir(
this, realURL, d->openURL_keep[job], d->openURL_reload[job] );
1974 d->openURL_url.remove(job);
1975 d->openURL_keep.remove(job);
1976 d->openURL_reload.remove(job);
1979 void KDirLister::slotLocalURLKIODestroyed() {
1982 if (d->openURL_url.contains(terminatedJob)) {
1983 s_pCache->listDir(
this, d->openURL_url[terminatedJob], d->openURL_keep[terminatedJob], d->openURL_reload[terminatedJob] );
1984 d->openURL_url.remove(terminatedJob);
1985 d->openURL_keep.remove(terminatedJob);
1986 d->openURL_reload.remove(terminatedJob);
1992 kdDebug(7003) << k_funcinfo << endl;
1993 s_pCache->stop(
this );
1994 d->m_referenceURLMap.clear();
1999 kdDebug(7003) << k_funcinfo << _url.prettyURL() << endl;
2000 s_pCache->stop(
this, _url );
2001 d->m_referenceURLMap.remove(_url.url());
2006 return d->autoUpdate;
2011 if ( d->autoUpdate == _enable )
2014 d->autoUpdate = _enable;
2015 s_pCache->setAutoUpdate(
this, _enable );
2020 return d->isShowingDotFiles;
2025 if ( d->isShowingDotFiles == _showDotFiles )
2028 d->isShowingDotFiles = _showDotFiles;
2029 d->changes ^= DOT_FILES;
2034 return d->dirOnlyMode;
2039 if ( d->dirOnlyMode == _dirsOnly )
2042 d->dirOnlyMode = _dirsOnly;
2043 d->changes ^= DIR_ONLY_MODE;
2048 return d->autoErrorHandling;
2053 d->autoErrorHandling = enable;
2054 d->errorParent = parent;
2069 if ( d->changes == NONE )
2072 static const TQString& dot = TDEGlobal::staticQString(
".");
2073 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
2075 for ( KURL::List::Iterator it = d->lstDirs.begin();
2076 it != d->lstDirs.end(); ++it )
2078 KFileItemListIterator kit( *s_pCache->itemsForDir( *it ) );
2079 for ( ; kit.current(); ++kit )
2081 if ( (*kit)->text() == dot || (*kit)->text() == dotdot )
2084 bool oldMime =
true, newMime =
true;
2086 if ( d->changes & MIME_FILTER )
2088 oldMime = doMimeFilter( (*kit)->mimetype(), d->oldMimeFilter )
2089 && doMimeExcludeFilter( (*kit)->mimetype(), d->oldMimeExcludeFilter );
2090 newMime = doMimeFilter( (*kit)->mimetype(), d->mimeFilter )
2091 && doMimeExcludeFilter( (*kit)->mimetype(), d->mimeExcludeFilter );
2093 if ( oldMime && !newMime )
2095 emit deleteItem( *kit );
2100 if ( d->changes & DIR_ONLY_MODE )
2103 if ( d->dirOnlyMode )
2105 if ( !(*kit)->isDir() )
2106 emit deleteItem( *kit );
2108 else if ( !(*kit)->isDir() ) {
2115 if ( (*kit)->isHidden() )
2117 if ( d->changes & DOT_FILES )
2120 if ( d->isShowingDotFiles ) {
2124 emit deleteItem( *kit );
2130 else if ( d->changes & NAME_FILTER )
2132 bool oldName = (*kit)->isDir() ||
2133 d->oldFilters.isEmpty() ||
2134 doNameFilter( (*kit)->text(), d->oldFilters );
2136 bool newName = (*kit)->isDir() ||
2137 d->lstFilters.isEmpty() ||
2138 doNameFilter( (*kit)->text(), d->lstFilters );
2140 if ( oldName && !newName )
2142 emit deleteItem( *kit );
2145 else if ( !oldName && newName ) {
2150 if ( (d->changes & MIME_FILTER) && !oldMime && newMime ) {
2163 s_pCache->updateDirectory( _u );
2173 return d->rootFileItem;
2178 return s_pCache->findByURL(
this, _url );
2183 return s_pCache->findByName(
this, _name );
2186 #ifndef KDE_NO_COMPAT 2187 KFileItem *KDirLister::find(
const KURL& _url )
const 2189 return findByURL( _url );
2198 if ( !(d->changes & NAME_FILTER) )
2200 d->oldFilters = d->lstFilters;
2201 d->lstFilters.setAutoDelete(
false );
2204 d->lstFilters.clear();
2205 d->lstFilters.setAutoDelete(
true );
2207 d->nameFilter = nameFilter;
2210 TQStringList list = TQStringList::split(
' ', nameFilter );
2211 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
2212 d->lstFilters.append(
new TQRegExp(*it,
false,
true ) );
2214 d->changes |= NAME_FILTER;
2219 return d->nameFilter;
2224 if ( !(d->changes & MIME_FILTER) )
2225 d->oldMimeFilter = d->mimeFilter;
2227 if ( mimeFilter.find(
"all/allfiles") != mimeFilter.end() ||
2228 mimeFilter.find(
"all/all") != mimeFilter.end() )
2229 d->mimeFilter.clear();
2231 d->mimeFilter = mimeFilter;
2233 d->changes |= MIME_FILTER;
2238 if ( !(d->changes & MIME_FILTER) )
2239 d->oldMimeExcludeFilter = d->mimeExcludeFilter;
2241 d->mimeExcludeFilter = mimeExcludeFilter;
2242 d->changes |= MIME_FILTER;
2248 if ( !(d->changes & MIME_FILTER) )
2250 d->oldMimeFilter = d->mimeFilter;
2251 d->oldMimeExcludeFilter = d->mimeExcludeFilter;
2253 d->mimeFilter.clear();
2254 d->mimeExcludeFilter.clear();
2255 d->changes |= MIME_FILTER;
2260 return d->mimeFilter;
2265 return doNameFilter( name, d->lstFilters );
2270 return doMimeFilter( mime, d->mimeFilter ) && doMimeExcludeFilter(mime,d->mimeExcludeFilter);
2278 static const TQString& dotdot = TDEGlobal::staticQString(
"..");
2280 if ( item->
text() == dotdot )
2283 if ( !d->isShowingDotFiles && item->
isHidden() )
2286 if ( item->
isDir() || d->lstFilters.isEmpty() )
2289 return matchesFilter( item->
text() );
2296 if ( d->mimeFilter.isEmpty() && d->mimeExcludeFilter.isEmpty() )
2298 return matchesMimeFilter( item->
mimetype() );
2303 for ( TQPtrListIterator<TQRegExp> it( filters ); it.current(); ++it )
2304 if ( it.current()->exactMatch( name ) )
2312 if ( filters.isEmpty() )
2317 TQStringList::ConstIterator it = filters.begin();
2318 for ( ; it != filters.end(); ++it )
2319 if ( mimeptr->is(*it) )
2327 bool KDirLister::doMimeExcludeFilter(
const TQString& mime,
const TQStringList& filters )
const 2329 if ( filters.isEmpty() )
2332 TQStringList::ConstIterator it = filters.begin();
2333 for ( ; it != filters.end(); ++it )
2334 if ( (*it) == mime )
2343 return s_pCache->validURL(
this, _url );
2348 if ( d->autoErrorHandling ) {
2356 void KDirLister::addNewItem(
const KFileItem *item )
2358 TQString refURL = item->
url().internalReferenceURL();
2359 if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) &&
2360 item->
url().path().startsWith(d->m_referenceURLMap[refURL]))
2364 if (!refURL.endsWith(
"/"))
2368 KURL newItemURL(refURL);
2369 newItemURL.addPath(item->
url().fileName());
2370 const_cast<KFileItem*
>(item)->setListerURL(newItemURL);
2371 const_cast<KFileItem*
>(item)->setURL(newItemURL);
2374 if ( ( d->dirOnlyMode && !item->
isDir() ) || !matchesFilter( item ) ) {
2378 if ( matchesMimeFilter( item ) )
2380 if ( !d->lstNewItems ) {
2381 d->lstNewItems =
new KFileItemList;
2384 d->lstNewItems->append( item );
2388 if ( !d->lstMimeFilteredItems ) {
2389 d->lstMimeFilteredItems =
new KFileItemList;
2392 d->lstMimeFilteredItems->append( item );
2396 void KDirLister::addNewItems(
const KFileItemList& items )
2401 for ( KFileItemListIterator kit( items ); kit.current(); ++kit ) {
2406 void KDirLister::aboutToRefreshItem(
const KFileItem *item )
2409 if ( ( d->dirOnlyMode && !item->
isDir() ) || !matchesFilter( item ) )
2410 d->refreshItemWasFiltered =
true;
2411 else if ( !matchesMimeFilter( item ) )
2412 d->refreshItemWasFiltered =
true;
2414 d->refreshItemWasFiltered =
false;
2417 void KDirLister::addRefreshItem(
const KFileItem *item )
2419 bool isExcluded = (d->dirOnlyMode && !item->
isDir()) || !matchesFilter( item );
2421 TQString refURL = item->
url().internalReferenceURL();
2422 if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) &&
2423 item->
url().path().startsWith(d->m_referenceURLMap[refURL]))
2427 if (!refURL.endsWith(
"/"))
2431 KURL newItemURL(refURL);
2432 newItemURL.addPath(item->
url().fileName());
2433 const_cast<KFileItem*
>(item)->setListerURL(newItemURL);
2434 const_cast<KFileItem*
>(item)->setURL(newItemURL);
2437 if ( !isExcluded && matchesMimeFilter( item ) )
2439 if ( d->refreshItemWasFiltered )
2441 if ( !d->lstNewItems ) {
2442 d->lstNewItems =
new KFileItemList;
2445 d->lstNewItems->append( item );
2449 if ( !d->lstRefreshItems ) {
2450 d->lstRefreshItems =
new KFileItemList;
2453 d->lstRefreshItems->append( item );
2456 else if ( !d->refreshItemWasFiltered )
2458 if ( !d->lstRemoveItems ) {
2459 d->lstRemoveItems =
new KFileItemList;
2464 d->lstRemoveItems->append( item );
2468 void KDirLister::emitItems()
2470 KFileItemList *tmpNew = d->lstNewItems;
2473 KFileItemList *tmpMime = d->lstMimeFilteredItems;
2474 d->lstMimeFilteredItems = 0;
2476 KFileItemList *tmpRefresh = d->lstRefreshItems;
2477 d->lstRefreshItems = 0;
2479 KFileItemList *tmpRemove = d->lstRemoveItems;
2480 d->lstRemoveItems = 0;
2487 TQString prevProtocol;
2488 TQString prevPrefix;
2489 KFileItemList emitList;
2490 for ( KFileItemListIterator kit( *tmpNew ); kit.current(); ++kit )
2493 protocol = item->
url().protocol();
2494 prefix = TQStringList::split(
"/", item->
url().path())[0];
2495 if ((protocol != prevProtocol) || (prefix != prevPrefix)) {
2496 if (emitList.count() > 0) {
2497 emit newItems( emitList );
2501 emitList.append(item);
2502 prevProtocol = protocol;
2503 prevPrefix = prefix;
2506 if (emitList.count() > 0) {
2507 emit newItems( emitList );
2514 emit itemsFilteredByMime( *tmpMime );
2520 emit refreshItems( *tmpRefresh );
2526 for (
KFileItem *tmp = tmpRemove->first(); tmp; tmp = tmpRemove->next() ) {
2527 emit deleteItem( tmp );
2533 void KDirLister::emitDeleteItem(
KFileItem *item )
2535 if ( ( d->dirOnlyMode && !item->
isDir() ) || !matchesFilter( item ) ) {
2539 if ( matchesMimeFilter( item ) ) {
2540 emit deleteItem( item );
2547 void KDirLister::slotInfoMessage(
TDEIO::Job *,
const TQString& message )
2549 emit infoMessage( message );
2552 void KDirLister::slotPercent(
TDEIO::Job *job,
unsigned long pcnt )
2560 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2561 while ( dataIt != d->jobData.end() )
2563 result += (*dataIt).percent * (*dataIt).totalSize;
2564 size += (*dataIt).totalSize;
2572 emit percent( result );
2580 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2581 while ( dataIt != d->jobData.end() )
2583 result += (*dataIt).totalSize;
2587 emit totalSize( result );
2592 d->jobData[
static_cast<TDEIO::ListJob *
>(job)].processedSize = size;
2595 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2596 while ( dataIt != d->jobData.end() )
2598 result += (*dataIt).processedSize;
2602 emit processedSize( result );
2605 void KDirLister::slotSpeed(
TDEIO::Job *job,
unsigned long spd )
2610 TQMap< TDEIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2611 while ( dataIt != d->jobData.end() )
2613 result += (*dataIt).speed;
2617 emit speed( result );
2620 uint KDirLister::numJobs()
2622 return d->jobData.count();
2627 d->jobData.remove( job );
2632 KDirListerPrivate::JobData jobData;
2634 jobData.percent = 0;
2635 jobData.processedSize = 0;
2636 jobData.totalSize = 0;
2638 d->jobData.insert( job, jobData );
2639 d->complete =
false;
2644 connect( job, TQT_SIGNAL(infoMessage(
TDEIO::Job *,
const TQString& )),
2645 this, TQT_SLOT(slotInfoMessage(
TDEIO::Job *,
const TQString& )) );
2646 connect( job, TQT_SIGNAL(percent(
TDEIO::Job *,
unsigned long )),
2647 this, TQT_SLOT(slotPercent(
TDEIO::Job *,
unsigned long )) );
2652 connect( job, TQT_SIGNAL(speed(
TDEIO::Job *,
unsigned long )),
2653 this, TQT_SLOT(slotSpeed(
TDEIO::Job *,
unsigned long )) );
2656 void KDirLister::emitCompleted(
const KURL& _url )
2658 TQString refURL = _url.internalReferenceURL();
2659 if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) &&
2660 _url.path().startsWith(d->m_referenceURLMap[refURL]))
2664 if (!refURL.endsWith(
"/"))
2668 KURL newItemURL(refURL);
2669 newItemURL.addPath(_url.fileName());
2670 emit completed(newItemURL);
2674 emit completed(_url);
2690 return itemsForDir( url(), which );
2695 KFileItemList result;
2696 KFileItemList *allItems = s_pCache->itemsForDir( dir );
2701 if ( which == AllItems ) {
2706 for ( KFileItemListIterator kit( *allItems ); kit.current(); ++kit )
2709 bool isExcluded = (d->dirOnlyMode && !item->
isDir()) || !matchesFilter( item );
2710 if ( !isExcluded && matchesMimeFilter( item ) ) {
2711 result.append( item );
2721 void KDirLister::virtual_hook(
int,
void * )
2724 #include "kdirlister.moc" 2725 #include "kdirlister_p.moc" bool matchesFilter(const TQString &name) const
Checks whether name matches a filter in the list of name filters.
virtual ~KDirLister()
Destroy the directory lister.
void setMimeExcludeFilter(const TQStringList &mimeList)
Filtering should be done with KFileFilter.
virtual void setShowingDotFiles(bool _showDotFiles)
Changes the "is viewing dot files" setting.
const KURL & url() const
Returns the url of the file.
bool isDir() const
Returns true if this item represents a directory.
TQWidget * mainWindow()
Returns the main window associated with this object.
virtual void setAutoUpdate(bool enable)
Enable/disable automatic directory updating, when a directory changes (using KDirWatch).
TQ_ULLONG filesize_t
64-bit file size
const TQString & nameFilter() const
Returns the current name filter, as set via setNameFilter()
void refresh()
Throw away and re-read (for local files) all information about the file.
const KURL & url() const
Returns the SimpleJob's URL.
KFileItem * rootItem() const
Returns the file item of the URL.
virtual void clearMimeFilter()
Clears the mime based filter.
const TQString & name(bool lowerCase=false) const
Return the name of the file item (without a path).
virtual bool doNameFilter(const TQString &name, const TQPtrList< TQRegExp > &filters) const
Called by the public matchesFilter() to do the actual filtering.
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...
bool dirOnlyMode() const
Checks whether the KDirLister only lists directories or all files.
KFileItemList itemsForDir(const KURL &dir, WhichItems which=FilteredItems) const
Returns the items listed for the given dir.
void mark()
Marks the item.
The base class for all jobs.
const TQStringList & mimeFilters() const
Returns the list of mime based filters, as set via setMimeFilter().
bool isLocalFile() const
Returns true if the file is a local file.
bool autoErrorHandlingEnabled() const
Check whether auto error handling is enabled.
virtual void stop()
Stop listing all directories currently being listed.
void deleteItem(KFileItem *_fileItem)
Signal an item to remove.
void setWindow(TQWidget *window)
Associate this job with a window given by window.
virtual void kill(bool quietly=true)
Abort job.
virtual KFileItem * findByName(const TQString &name) const
Find an item by its name.
virtual void setDirOnlyMode(bool dirsOnly)
Call this to list only directories.
void setURL(const KURL &url)
Sets the item's URL.
virtual void handleError(TDEIO::Job *)
Reimplement to customize error handling.
KFileItemList items(WhichItems which=FilteredItems) const
Returns the items listed for the current url().
const KURL::List & directories() const
Returns all URLs that are listed by this KDirLister.
TQWidget * window() const
Returns the window this job is associated with.
TDEIO_EXPORT LocalURLJob * localURL(const KURL &remoteUrl)
Retrieve local URL if available.
virtual void updateDirectory(const KURL &_dir)
Update the directory _dir.
int error() const
Returns the error code, if there has been an error.
TQString mimetype() const
Returns the mimetype of the file item.
bool matchesMimeFilter(const TQString &mime) const
Checks whether mime matches a filter in the list of mime types.
virtual void setMimeFilter(const TQStringList &mimeList)
Set mime-based filter to only list items matching the given mimetypes.
static bool supportsListing(const KURL &url)
Returns whether the protocol can list files/objects.
TQString localPath() const
Returns the local path if isLocalFile() == true or the TDEIO item has a UDS_LOCAL_PATH atom...
bool isFinished() const
Returns true if no io operation is currently in progress.
void canceled()
Tell the view that the user canceled the listing.
void completed()
Tell the view that listing is finished.
A TDEIO job that finds a local URL.
void started(const KURL &_url)
Tell the view that we started to list _url.
const KURL & url() const
Returns the top level URL that is listed by this KDirLister.
void refreshMimeType()
Re-reads mimetype information.
virtual KFileItem * findByURL(const KURL &_url) const
Find an item by its URL.
bool showingDotFiles() const
Checks whether hidden files (files beginning with a dot) will be shown.
void showErrorDialog(TQWidget *parent=0L)
Display a dialog box to inform the user of the error given by this job.
void clear()
Signal to clear all items.
KDirLister(bool _delayedMimeTypes=false)
Create a directory lister.
WhichItems
Used by items() and itemsForDir() to specify whether you want all items for a directory or just the f...
void redirection(const KURL &_url)
Signal a redirection.
A ListJob is allows you to get the get the content of a directory.
void setUDSEntry(const TDEIO::UDSEntry &entry, const KURL &url, bool determineMimeTypeOnDemand=false, bool urlIsDirectory=false)
Reinitialize KFileItem with a new UDSEntry.
bool autoUpdate() const
Checks whether KDirWatch will automatically update directories.
void setAutoErrorHandlingEnabled(bool enable, TQWidget *parent)
Enable or disable auto error handling is enabled.
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.
bool isMarked() const
Used when updating a directory.
void setMainWindow(TQWidget *window)
Pass the main window this object is associated with this is used for caching authentication data...
bool isHidden() const
Checks whether the file is hidden.
virtual void setNameFilter(const TQString &filter)
Set a name filter to only list items matching this name, e.g.
static bool exists()
Returns true if there is an instance of KDirWatch.
The dir lister deals with the tdeiojob used to list and update a directory and has signals for the us...
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.
const TQString & text() const
Returns the text of the file item.
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 ...
const KURL & redirectionURL() const
Returns the ListJob's redirection URL.
virtual void emitChanges()
Actually emit the changes made with setShowingDotFiles, setDirOnlyMode, setNameFilter and setMimeFilt...
virtual bool doMimeFilter(const TQString &mime, const TQStringList &filters) const
Called by the public matchesMimeFilter() to do the actual filtering.
A KFileItem is a generic class to handle a file, local or remote.
virtual bool openURL(const KURL &_url, bool _keep=false, bool _reload=false)
Run the directory lister on the given url.