22 #include "kdirlister.h" 25 #include <tqptrlist.h> 28 #include <kapplication.h> 32 #include <kmessagebox.h> 34 #include <kglobalsettings.h> 35 #include <kstaticdeleter.h> 36 #include <kprotocolinfo.h> 38 #include "kdirlister_p.h" 42 KDirListerCache* KDirListerCache::s_pSelf = 0;
43 static KStaticDeleter<KDirListerCache> sd_KDirListerCache;
53 KDirListerCache::KDirListerCache(
int maxCount )
54 : itemsCached( maxCount )
56 kdDebug(7004) <<
"+KDirListerCache" << endl;
58 itemsInUse.setAutoDelete(
false );
59 itemsCached.setAutoDelete(
true );
60 urlsCurrentlyListed.setAutoDelete(
true );
61 urlsCurrentlyHeld.setAutoDelete(
true );
62 pendingUpdates.setAutoDelete(
true );
64 connect( kdirwatch, TQT_SIGNAL( dirty(
const TQString& ) ),
65 this, TQT_SLOT( slotFileDirty(
const TQString& ) ) );
66 connect( kdirwatch, TQT_SIGNAL( created(
const TQString& ) ),
67 this, TQT_SLOT( slotFileCreated(
const TQString& ) ) );
68 connect( kdirwatch, TQT_SIGNAL( deleted(
const TQString& ) ),
69 this, TQT_SLOT( slotFileDeleted(
const TQString& ) ) );
72 KDirListerCache::~KDirListerCache()
74 kdDebug(7004) <<
"-KDirListerCache" << endl;
76 itemsInUse.setAutoDelete(
true );
79 urlsCurrentlyListed.clear();
80 urlsCurrentlyHeld.clear();
83 kdirwatch->disconnect(
this );
88 bool KDirListerCache::listDir(
KDirLister *lister,
const KURL& _u,
89 bool _keep,
bool _reload )
95 TQString urlStr = _url.url();
103 kdDebug(7004) << k_funcinfo << lister <<
" url=" << _url
104 <<
" keep=" << _keep <<
" reload=" << _reload << endl;
112 forgetDirs( lister );
114 lister->d->rootFileItem = 0;
116 else if ( lister->d->lstDirs.find( _url ) != lister->d->lstDirs.end() )
119 stop( lister, _url );
122 forgetDirs( lister, _url,
true );
124 if ( lister->d->url == _url )
125 lister->d->rootFileItem = 0;
128 lister->d->lstDirs.append( _url );
130 if ( lister->d->url.isEmpty() || !_keep )
131 lister->d->url = _url;
133 DirItem *itemU = itemsInUse[urlStr];
136 if ( !urlsCurrentlyListed[urlStr] )
143 kdDebug(7004) <<
"listDir: Entry already in use: " << _url << endl;
145 bool oldState = lister->d->complete;
146 lister->d->complete =
false;
150 if ( !lister->d->rootFileItem && lister->d->url == _url )
151 lister->d->rootFileItem = itemU->rootItem;
153 lister->addNewItems( *(itemU->lstItems) );
157 assert( urlsCurrentlyHeld[urlStr] );
158 urlsCurrentlyHeld[urlStr]->append( lister );
160 lister->d->complete = oldState;
163 if ( lister->d->complete )
166 if ( _reload || !itemU->complete )
167 updateDirectory( _url );
169 else if ( !_reload && (itemC = itemsCached.take( urlStr )) )
171 kdDebug(7004) <<
"listDir: Entry in cache: " << _url << endl;
173 itemC->decAutoUpdate();
174 itemsInUse.insert( urlStr, itemC );
177 bool oldState = lister->d->complete;
178 lister->d->complete =
false;
182 if ( !lister->d->rootFileItem && lister->d->url == _url )
183 lister->d->rootFileItem = itemC->rootItem;
185 lister->addNewItems( *(itemC->lstItems) );
188 Q_ASSERT( !urlsCurrentlyHeld[urlStr] );
189 TQPtrList<KDirLister> *list =
new TQPtrList<KDirLister>;
190 list->append( lister );
191 urlsCurrentlyHeld.insert( urlStr, list );
193 lister->d->complete = oldState;
196 if ( lister->d->complete )
199 if ( !itemC->complete )
200 updateDirectory( _url );
204 kdDebug(7004) <<
"listDir: Entry not in cache or reloaded: " << _url << endl;
206 TQPtrList<KDirLister> *list =
new TQPtrList<KDirLister>;
207 list->append( lister );
208 urlsCurrentlyListed.insert( urlStr, list );
210 itemsCached.remove( urlStr );
211 itemU =
new DirItem( _url );
212 itemsInUse.insert( urlStr, itemU );
222 if ( lister->d->url == _url )
223 lister->d->rootFileItem = 0;
226 jobs.insert( job, TQValueList<KIO::UDSEntry>() );
228 lister->jobStarted( job );
229 lister->connectJob( job );
231 if ( lister->d->window )
234 connect( job, TQT_SIGNAL( entries(
KIO::Job *,
const KIO::UDSEntryList & ) ),
235 this, TQT_SLOT( slotEntries(
KIO::Job *,
const KIO::UDSEntryList & ) ) );
236 connect( job, TQT_SIGNAL( result(
KIO::Job * ) ),
237 this, TQT_SLOT( slotResult(
KIO::Job * ) ) );
238 connect( job, TQT_SIGNAL( redirection(
KIO::Job *,
const KURL & ) ),
239 this, TQT_SLOT( slotRedirection(
KIO::Job *,
const KURL & ) ) );
248 kdDebug(7004) <<
"listDir: Entry currently being listed: " << _url << endl;
252 urlsCurrentlyListed[urlStr]->append( lister );
257 lister->jobStarted( job );
258 lister->connectJob( job );
262 if ( !lister->d->rootFileItem && lister->d->url == _url )
263 lister->d->rootFileItem = itemU->rootItem;
265 lister->addNewItems( *(itemU->lstItems) );
270 if ( lister->d->autoUpdate )
271 itemU->incAutoUpdate();
276 bool KDirListerCache::validURL(
const KDirLister *lister,
const KURL& url )
const 278 if ( !url.isValid() )
280 if ( lister->d->autoErrorHandling )
282 TQString tmp = i18n(
"Malformed URL\n%1").arg( url.prettyURL() );
283 KMessageBox::error( lister->d->errorParent, tmp );
290 if ( lister->d->autoErrorHandling )
293 TQString tmp = i18n(
"Malformed URL\n%1").arg( url.prettyURL() );
294 KMessageBox::error( lister->d->errorParent, tmp );
302 void KDirListerCache::stop(
KDirLister *lister )
307 kdDebug(7004) << k_funcinfo <<
"lister: " << lister << endl;
308 bool stopped =
false;
310 TQDictIterator< TQPtrList<KDirLister> > it( urlsCurrentlyListed );
311 TQPtrList<KDirLister> *listers;
312 while ( (listers = it.current()) )
314 if ( listers->findRef( lister ) > -1 )
317 TQString url = it.currentKey();
320 bool ret = listers->removeRef( lister );
325 lister->jobDone( job );
328 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[url];
331 holders =
new TQPtrList<KDirLister>;
332 urlsCurrentlyHeld.insert( url, holders );
335 holders->append( lister );
337 emit lister->
canceled( KURL( url ) );
341 if ( listers->isEmpty() )
347 urlsCurrentlyListed.remove( url );
359 lister->d->complete =
true;
366 void KDirListerCache::stop(
KDirLister *lister,
const KURL& _u )
368 TQString urlStr( _u.url(-1) );
372 kdDebug(7004) << k_funcinfo << lister <<
" url=" << _url << endl;
374 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr];
375 if ( !listers || !listers->removeRef( lister ) )
379 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr];
382 holders =
new TQPtrList<KDirLister>;
383 urlsCurrentlyHeld.insert( urlStr, holders );
386 holders->append( lister );
391 lister->jobDone( job );
395 if ( listers->isEmpty() )
401 urlsCurrentlyListed.remove( urlStr );
404 if ( lister->numJobs() == 0 )
406 lister->d->complete =
true;
413 void KDirListerCache::setAutoUpdate(
KDirLister *lister,
bool enable )
417 for ( KURL::List::Iterator it = lister->d->lstDirs.begin();
418 it != lister->d->lstDirs.end(); ++it )
421 itemsInUse[(*it).url()]->incAutoUpdate();
423 itemsInUse[(*it).url()]->decAutoUpdate();
427 void KDirListerCache::forgetDirs(
KDirLister *lister )
429 kdDebug(7004) << k_funcinfo << lister << endl;
431 emit lister->
clear();
434 KURL::List lstDirsCopy = lister->d->lstDirs;
435 for ( KURL::List::Iterator it = lstDirsCopy.begin();
436 it != lstDirsCopy.end(); ++it )
438 forgetDirs( lister, *it,
false );
442 void KDirListerCache::forgetDirs(
KDirLister *lister,
const KURL& _url,
bool notify )
444 kdDebug(7004) << k_funcinfo << lister <<
" _url: " << _url << endl;
447 url.adjustPath( -1 );
448 TQString urlStr = url.url();
449 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr];
453 holders->removeRef( lister );
460 lister->d->lstDirs.remove( lister->d->lstDirs.find( url ) );
462 DirItem *item = itemsInUse[urlStr];
464 if ( holders && holders->isEmpty() )
466 urlsCurrentlyHeld.remove( urlStr );
467 if ( !urlsCurrentlyListed[urlStr] )
470 itemsInUse.remove( urlStr );
476 lister->jobDone( job );
478 kdDebug(7004) << k_funcinfo <<
"Killing update job for " << urlStr << endl;
481 if ( lister->numJobs() == 0 )
483 lister->d->complete =
true;
489 emit lister->
clear( url );
491 if ( item && item->complete )
493 kdDebug(7004) << k_funcinfo << lister <<
" item moved into cache: " << url << endl;
494 itemsCached.insert( urlStr, item );
499 const bool isLocal = item->
url.isLocalFile();
501 bool containsManuallyMounted =
false;
502 if ( !isManuallyMounted && item->lstItems && isLocal )
508 KFileItemListIterator kit( *item->lstItems );
509 for ( ; kit.current() && !containsManuallyMounted; ++kit )
511 containsManuallyMounted =
true;
514 if ( isManuallyMounted || containsManuallyMounted )
516 kdDebug(7004) <<
"Not adding a watch on " << item->url <<
" because it " <<
517 ( isManuallyMounted ?
"is manually mounted" :
"contains a manually mounted subdir" ) << endl;
518 item->complete =
false;
521 item->incAutoUpdate();
531 if ( item && lister->d->autoUpdate )
532 item->decAutoUpdate();
535 void KDirListerCache::updateDirectory(
const KURL& _dir )
537 kdDebug(7004) << k_funcinfo << _dir << endl;
539 TQString urlStr = _dir.url(-1);
540 if ( !checkUpdate( urlStr ) )
549 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr];
550 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld[urlStr];
554 TQWidget *window = 0;
564 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
568 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
571 kdDebug(7004) << k_funcinfo <<
"Killed = " << killed << endl;
576 Q_ASSERT( !listers || (listers && killed) );
579 jobs.insert( job, TQValueList<KIO::UDSEntry>() );
581 connect( job, TQT_SIGNAL(entries(
KIO::Job *,
const KIO::UDSEntryList & )),
582 this, TQT_SLOT(slotUpdateEntries(
KIO::Job *,
const KIO::UDSEntryList & )) );
583 connect( job, TQT_SIGNAL(result(
KIO::Job * )),
584 this, TQT_SLOT(slotUpdateResult(
KIO::Job * )) );
586 kdDebug(7004) << k_funcinfo <<
"update started in " << _dir << endl;
589 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
590 kdl->jobStarted( job );
597 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
599 kdl->jobStarted( job );
600 if ( first && kdl->d->window )
605 emit kdl->started( _dir );
612 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
613 kdl->jobStarted( job );
618 bool KDirListerCache::checkUpdate(
const TQString& _dir )
620 if ( !itemsInUse[_dir] )
622 DirItem *item = itemsCached[_dir];
623 if ( item && item->complete )
625 item->complete =
false;
626 item->decAutoUpdate();
639 KFileItemList *KDirListerCache::itemsForDir(
const KURL &_dir )
const 641 TQString urlStr = _dir.url(-1);
642 DirItem *item = itemsInUse[ urlStr ];
644 item = itemsCached[ urlStr ];
645 return item ? item->lstItems : 0;
648 KFileItem *KDirListerCache::findByName(
const KDirLister *lister,
const TQString& _name )
const 652 for ( KURL::List::Iterator it = lister->d->lstDirs.begin();
653 it != lister->d->lstDirs.end(); ++it )
655 KFileItemListIterator kit( *itemsInUse[(*it).url()]->lstItems );
656 for ( ; kit.current(); ++kit )
657 if ( (*kit)->name() == _name )
669 KURL parentDir( _url );
670 parentDir.setPath( parentDir.directory() );
673 if ( lister && !lister->d->lstDirs.contains( parentDir ) )
676 KFileItemList *itemList = itemsForDir( parentDir );
679 KFileItemListIterator kit( *itemList );
680 for ( ; kit.current(); ++kit )
681 if ( (*kit)->url() == _url )
687 void KDirListerCache::FilesAdded(
const KURL &dir )
689 kdDebug(7004) << k_funcinfo << dir << endl;
690 updateDirectory( dir );
693 void KDirListerCache::FilesRemoved(
const KURL::List &fileList )
695 kdDebug(7004) << k_funcinfo << endl;
696 KURL::List::ConstIterator it = fileList.begin();
697 for ( ; it != fileList.end() ; ++it )
701 KURL parentDir( *it );
702 parentDir.setPath( parentDir.directory() );
703 KFileItemList *lstItems = itemsForDir( parentDir );
707 for ( ; fit; fit = lstItems->next() )
708 if ( fit->
url() == *it ) {
719 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDir.url()];
721 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
722 kdl->emitDeleteItem( fileitem );
726 if ( !fileitem || fileitem->
isDir() )
738 void KDirListerCache::FilesChanged(
const KURL::List &fileList )
740 KURL::List dirsToUpdate;
741 kdDebug(7004) << k_funcinfo <<
"only half implemented" << endl;
742 KURL::List::ConstIterator it = fileList.begin();
743 for ( ; it != fileList.end() ; ++it )
745 if ( ( *it ).isLocalFile() )
747 kdDebug(7004) <<
"KDirListerCache::FilesChanged " << *it << endl;
748 KFileItem *fileitem = findByURL( 0, *it );
752 aboutToRefreshItem( fileitem );
754 emitRefreshItem( fileitem );
757 kdDebug(7004) <<
"item not found" << endl;
762 dir.setPath( dir.directory(
true ) );
763 if ( dirsToUpdate.find( dir ) == dirsToUpdate.end() )
764 dirsToUpdate.prepend( dir );
768 KURL::List::ConstIterator itdir = dirsToUpdate.begin();
769 for ( ; itdir != dirsToUpdate.end() ; ++itdir )
770 updateDirectory( *itdir );
775 void KDirListerCache::FileRenamed(
const KURL &src,
const KURL &dst )
777 kdDebug(7004) << k_funcinfo << src.prettyURL() <<
" -> " << dst.prettyURL() << endl;
784 renameDir( src, dst );
788 oldurl.adjustPath( -1 );
789 KFileItem *fileitem = findByURL( 0, oldurl );
796 aboutToRefreshItem( fileitem );
799 emitRefreshItem( fileitem );
807 void KDirListerCache::aboutToRefreshItem(
KFileItem *fileitem )
810 KURL parentDir( fileitem->
url() );
811 parentDir.setPath( parentDir.directory() );
812 TQString parentDirURL = parentDir.url();
813 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDirURL];
815 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
816 kdl->aboutToRefreshItem( fileitem );
819 listers = urlsCurrentlyListed[parentDirURL];
821 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
822 kdl->aboutToRefreshItem( fileitem );
825 void KDirListerCache::emitRefreshItem(
KFileItem *fileitem )
828 KURL parentDir( fileitem->
url() );
829 parentDir.setPath( parentDir.directory() );
830 TQString parentDirURL = parentDir.url();
831 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDirURL];
833 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
835 kdl->addRefreshItem( fileitem );
840 listers = urlsCurrentlyListed[parentDirURL];
842 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
844 kdl->addRefreshItem( fileitem );
849 KDirListerCache* KDirListerCache::self()
852 s_pSelf = sd_KDirListerCache.setObject( s_pSelf,
new KDirListerCache );
857 bool KDirListerCache::exists()
866 void KDirListerCache::slotFileDirty(
const TQString& _file )
868 kdDebug(7004) << k_funcinfo << _file << endl;
870 if ( !pendingUpdates[_file] )
873 dir.setPath( _file );
874 if ( checkUpdate( dir.url(-1) ) )
875 updateDirectory( dir );
878 dir.setPath( dir.directory() );
879 if ( checkUpdate( dir.url() ) )
882 TQTimer *timer =
new TQTimer(
this, _file.utf8() );
883 connect( timer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(slotFileDirtyDelayed()) );
884 pendingUpdates.insert( _file, timer );
885 timer->start( 500,
true );
891 void KDirListerCache::slotFileDirtyDelayed()
893 TQString file = TQString::fromUtf8( TQT_TQOBJECT_CONST(sender())->name() );
895 kdDebug(7004) << k_funcinfo << file << endl;
899 pendingUpdates.remove( file );
907 aboutToRefreshItem( item );
909 emitRefreshItem( item );
913 void KDirListerCache::slotFileCreated(
const TQString& _file )
915 kdDebug(7004) << k_funcinfo << _file << endl;
919 u.setPath( u.directory() );
923 void KDirListerCache::slotFileDeleted(
const TQString& _file )
925 kdDebug(7004) << k_funcinfo << _file << endl;
931 void KDirListerCache::slotEntries(
KIO::Job *job,
const KIO::UDSEntryList &entries )
933 KURL url = joburl( static_cast<KIO::ListJob *>(job) );
935 TQString urlStr = url.url();
937 kdDebug(7004) << k_funcinfo <<
"new entries for " << url << endl;
939 DirItem *dir = itemsInUse[urlStr];
942 TQPtrList<KDirLister> *listers = urlsCurrentlyListed[urlStr];
944 Q_ASSERT( !listers->isEmpty() );
947 bool delayedMimeTypes =
true;
948 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
949 delayedMimeTypes = delayedMimeTypes && kdl->d->delayedMimeTypes;
952 static const TQString& dot = KGlobal::staticQString(
".");
953 static const TQString& dotdot = KGlobal::staticQString(
"..");
955 KIO::UDSEntryListConstIterator it = entries.begin();
956 KIO::UDSEntryListConstIterator end = entries.end();
958 for ( ; it != end; ++it )
963 KIO::UDSEntry::ConstIterator entit = (*it).begin();
964 for( ; entit != (*it).end(); ++entit )
967 name = (*entit).m_str;
971 Q_ASSERT( !name.isEmpty() );
972 if ( name.isEmpty() )
977 Q_ASSERT( !dir->rootItem );
978 dir->rootItem =
new KFileItem( *it, url, delayedMimeTypes,
true );
980 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
981 if ( !kdl->d->rootFileItem && kdl->d->url == url )
982 kdl->d->rootFileItem = dir->rootItem;
984 else if ( name != dotdot )
990 dir->lstItems->append( item );
992 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
993 kdl->addNewItem( item );
997 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1001 void KDirListerCache::slotResult(
KIO::Job *j )
1007 KURL jobUrl = joburl( job );
1008 jobUrl.adjustPath(-1);
1009 TQString jobUrlStr = jobUrl.url();
1011 kdDebug(7004) << k_funcinfo <<
"finished listing " << jobUrl << endl;
1016 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( jobUrlStr );
1017 Q_ASSERT( listers );
1022 Q_ASSERT( !urlsCurrentlyHeld[jobUrlStr] );
1023 urlsCurrentlyHeld.insert( jobUrlStr, listers );
1029 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1031 kdl->jobDone( job );
1034 if ( kdl->numJobs() == 0 )
1036 kdl->d->complete =
true;
1043 DirItem *dir = itemsInUse[jobUrlStr];
1045 dir->complete =
true;
1047 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1049 kdl->jobDone( job );
1051 if ( kdl->numJobs() == 0 )
1053 kdl->d->complete =
true;
1061 processPendingUpdates();
1068 void KDirListerCache::slotRedirection(
KIO::Job *j,
const KURL& url )
1073 KURL oldUrl = job->
url();
1077 oldUrl.adjustPath(-1);
1078 newUrl.adjustPath(-1);
1080 if ( oldUrl == newUrl )
1082 kdDebug(7004) << k_funcinfo <<
"New redirection url same as old, giving up." << endl;
1086 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << newUrl.prettyURL() << endl;
1097 DirItem *dir = itemsInUse.take( oldUrl.url() );
1100 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( oldUrl.url() );
1101 Q_ASSERT( listers );
1102 Q_ASSERT( !listers->isEmpty() );
1104 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1107 if ( kdl->d->url.equals( oldUrl,
true ) )
1109 kdl->d->rootFileItem = 0;
1110 kdl->d->url = newUrl;
1113 *kdl->d->lstDirs.find( oldUrl ) = newUrl;
1115 if ( kdl->d->lstDirs.count() == 1 )
1123 emit kdl->
clear( oldUrl );
1130 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld.take( oldUrl.url() );
1133 Q_ASSERT( !holders->isEmpty() );
1135 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1137 kdl->jobStarted( job );
1144 if ( kdl->d->url.equals( oldUrl,
true ) )
1146 kdl->d->rootFileItem = 0;
1147 kdl->d->url = newUrl;
1150 *kdl->d->lstDirs.find( oldUrl ) = newUrl;
1152 if ( kdl->d->lstDirs.count() == 1 )
1160 emit kdl->
clear( oldUrl );
1166 DirItem *newDir = itemsInUse[newUrl.url()];
1169 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" already in use" << endl;
1180 TQPtrList<KDirLister> *curListers = urlsCurrentlyListed[newUrl.url()];
1183 kdDebug(7004) <<
"slotRedirection: and it is currently listed" << endl;
1187 for (
KDirLister *kdl = curListers->first(); kdl; kdl = curListers->next() )
1189 kdl->jobDone( oldJob );
1191 kdl->jobStarted( job );
1192 kdl->connectJob( job );
1196 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1197 curListers->append( kdl );
1200 urlsCurrentlyListed.insert( newUrl.url(), listers );
1206 TQPtrList<KDirLister> *curHolders = urlsCurrentlyHeld[newUrl.url()];
1209 kdDebug(7004) <<
"slotRedirection: and it is currently held." << endl;
1211 for (
KDirLister *kdl = curHolders->first(); kdl; kdl = curHolders->next() )
1213 kdl->jobStarted( job );
1219 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1220 curHolders->append( kdl );
1223 urlsCurrentlyHeld.insert( newUrl.url(), holders );
1228 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1230 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1231 kdl->d->rootFileItem = newDir->rootItem;
1233 kdl->addNewItems( *(newDir->lstItems) );
1239 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1241 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1242 kdl->d->rootFileItem = newDir->rootItem;
1244 kdl->addNewItems( *(newDir->lstItems) );
1249 else if ( (newDir = itemsCached.take( newUrl.url() )) )
1251 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" is unused, but already in the cache." << endl;
1254 itemsInUse.insert( newUrl.url(), newDir );
1255 urlsCurrentlyListed.insert( newUrl.url(), listers );
1257 urlsCurrentlyHeld.insert( newUrl.url(), holders );
1260 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1262 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1263 kdl->d->rootFileItem = newDir->rootItem;
1265 kdl->addNewItems( *(newDir->lstItems) );
1271 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1273 if ( !kdl->d->rootFileItem && kdl->d->url == newUrl )
1274 kdl->d->rootFileItem = newDir->rootItem;
1276 kdl->addNewItems( *(newDir->lstItems) );
1283 kdDebug(7004) <<
"slotRedirection: " << newUrl.url() <<
" has not been listed yet." << endl;
1285 delete dir->rootItem;
1287 dir->lstItems->clear();
1288 dir->redirect( newUrl );
1289 itemsInUse.insert( newUrl.url(), dir );
1290 urlsCurrentlyListed.insert( newUrl.url(), listers );
1293 urlsCurrentlyHeld.insert( newUrl.url(), holders );
1304 job->disconnect(
this );
1306 connect( job, TQT_SIGNAL(entries(
KIO::Job *,
const KIO::UDSEntryList & )),
1307 this, TQT_SLOT(slotUpdateEntries(
KIO::Job *,
const KIO::UDSEntryList & )) );
1308 connect( job, TQT_SIGNAL(result(
KIO::Job * )),
1309 this, TQT_SLOT(slotUpdateResult(
KIO::Job * )) );
1318 void KDirListerCache::renameDir(
const KURL &oldUrl,
const KURL &newUrl )
1320 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << newUrl.prettyURL() << endl;
1321 TQString oldUrlStr = oldUrl.url(-1);
1322 TQString newUrlStr = newUrl.url(-1);
1329 TQDictIterator<DirItem> itu( itemsInUse );
1331 while ( itu.current() )
1334 DirItem *dir = itu.current();
1335 KURL oldDirUrl ( itu.currentKey() );
1338 if ( oldUrl.isParentOf( oldDirUrl ) )
1341 TQString relPath = oldDirUrl.path().mid( oldUrl.path().length() );
1343 KURL newDirUrl( newUrl );
1344 if ( !relPath.isEmpty() )
1345 newDirUrl.addPath( relPath );
1349 dir->redirect( newDirUrl );
1350 itemsInUse.remove( itu.currentKey() );
1351 itemsInUse.insert( newDirUrl.url(-1), dir );
1353 if ( dir->lstItems )
1356 KFileItemListIterator kit( *dir->lstItems );
1357 for ( ; kit.current(); ++kit )
1359 KURL oldItemUrl = (*kit)->url();
1360 TQString oldItemUrlStr( oldItemUrl.url(-1) );
1361 KURL newItemUrl( oldItemUrl );
1362 newItemUrl.setPath( newDirUrl.path() );
1363 newItemUrl.addPath( oldItemUrl.fileName() );
1364 kdDebug(7004) <<
"KDirListerCache::renameDir renaming " << oldItemUrlStr <<
" to " << newItemUrl.url() << endl;
1365 (*kit)->setURL( newItemUrl );
1368 emitRedirections( oldDirUrl, newDirUrl );
1376 removeDirFromCache( oldUrl );
1380 void KDirListerCache::emitRedirections(
const KURL &oldUrl,
const KURL &url )
1382 kdDebug(7004) << k_funcinfo << oldUrl.prettyURL() <<
" -> " << url.prettyURL() << endl;
1383 TQString oldUrlStr = oldUrl.url(-1);
1384 TQString urlStr = url.url(-1);
1391 TQPtrList<KDirLister> *listers = urlsCurrentlyListed.take( oldUrlStr );
1395 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1398 kdl->jobDone( job );
1403 urlsCurrentlyListed.insert( urlStr, listers );
1408 TQPtrList<KDirLister> *holders = urlsCurrentlyHeld.take( oldUrlStr );
1412 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1413 kdl->jobDone( job );
1415 urlsCurrentlyHeld.insert( urlStr, holders );
1420 updateDirectory( url );
1423 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1430 for (
KDirLister *kdl = holders->first(); kdl; kdl = holders->next() )
1432 *kdl->d->lstDirs.find( oldUrl ) = url;
1434 if ( kdl->d->lstDirs.count() == 1 )
1442 void KDirListerCache::removeDirFromCache(
const KURL& dir )
1444 kdDebug(7004) <<
"KDirListerCache::removeDirFromCache " << dir.prettyURL() << endl;
1445 TQCacheIterator<DirItem> itc( itemsCached );
1446 while ( itc.current() )
1448 if ( dir.isParentOf( KURL( itc.currentKey() ) ) )
1449 itemsCached.remove( itc.currentKey() );
1455 void KDirListerCache::slotUpdateEntries(
KIO::Job* job,
const KIO::UDSEntryList& list )
1460 void KDirListerCache::slotUpdateResult(
KIO::Job * j )
1465 KURL jobUrl = joburl( job );
1466 jobUrl.adjustPath(-1);
1467 TQString jobUrlStr = jobUrl.url();
1469 kdDebug(7004) << k_funcinfo <<
"finished update " << jobUrl << endl;
1473 TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[jobUrlStr];
1474 TQPtrList<KDirLister> *tmpLst = urlsCurrentlyListed.take( jobUrlStr );
1479 for ( kdl = tmpLst->first(); kdl; kdl = tmpLst->next() )
1481 Q_ASSERT( listers->containsRef( kdl ) == 0 );
1482 listers->append( kdl );
1487 urlsCurrentlyHeld.insert( jobUrlStr, listers );
1492 Q_ASSERT( listers );
1496 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1498 kdl->jobDone( job );
1504 if ( kdl->numJobs() == 0 )
1506 kdl->d->complete =
true;
1515 processPendingUpdates();
1519 DirItem *dir = itemsInUse[jobUrlStr];
1520 dir->complete =
true;
1524 bool delayedMimeTypes =
true;
1525 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1526 delayedMimeTypes = delayedMimeTypes && kdl->d->delayedMimeTypes;
1529 TQDict<KFileItem> fileItems( 9973 );
1531 KFileItemListIterator kit ( *(dir->lstItems) );
1534 for ( ; kit.current(); ++kit )
1537 fileItems.insert( (*kit)->url().url(), *kit );
1540 static const TQString& dot = KGlobal::staticQString(
".");
1541 static const TQString& dotdot = KGlobal::staticQString(
"..");
1545 TQValueList<KIO::UDSEntry> buf = jobs[job];
1546 TQValueListIterator<KIO::UDSEntry> it = buf.begin();
1547 for ( ; it != buf.end(); ++it )
1551 item =
new KFileItem( *it, jobUrl, delayedMimeTypes,
true );
1553 item->
setUDSEntry( *it, jobUrl, delayedMimeTypes,
true );
1556 TQString name = item->
name();
1557 Q_ASSERT( !name.isEmpty() );
1561 if ( name.isEmpty() || name == dotdot )
1568 if ( !dir->rootItem )
1570 dir->rootItem = item;
1573 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1574 if ( !kdl->d->rootFileItem && kdl->d->url == jobUrl )
1575 kdl->d->rootFileItem = dir->rootItem;
1582 if ( (tmp = fileItems[item->
url().url()]) )
1587 if ( !tmp->cmp( *item ) )
1589 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1590 kdl->aboutToRefreshItem( tmp );
1593 tmp->assign( *item );
1595 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1596 kdl->addRefreshItem( tmp );
1604 dir->lstItems->append( item );
1606 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1607 kdl->addNewItem( item );
1619 deleteUnmarkedItems( listers, dir->lstItems );
1621 for ( kdl = listers->first(); kdl; kdl = listers->next() )
1625 kdl->jobDone( job );
1628 if ( kdl->numJobs() == 0 )
1630 kdl->d->complete =
true;
1637 processPendingUpdates();
1645 TQMap< KIO::ListJob *, TQValueList<KIO::UDSEntry> >::Iterator it = jobs.begin();
1646 while ( it != jobs.end() )
1649 if ( joburl( job ).url(-1) == url && job != not_job )
1656 const KURL& KDirListerCache::joburl(
KIO::ListJob *job )
1667 job->disconnect(
this );
1671 void KDirListerCache::deleteUnmarkedItems( TQPtrList<KDirLister> *listers, KFileItemList *lstItems )
1676 while ( (item = lstItems->current()) )
1680 for (
KDirLister *kdl = listers->first(); kdl; kdl = listers->next() )
1681 kdl->emitDeleteItem( item );
1683 if ( item->
isDir() )
1684 deleteDir( item->
url() );
1694 void KDirListerCache::deleteDir(
const KURL& dirUrl )
1701 TQDictIterator<DirItem> itu( itemsInUse );
1702 while ( itu.current() )
1704 KURL deletedUrl( itu.currentKey() );
1705 if ( dirUrl.isParentOf( deletedUrl ) )
1709 TQPtrList<KDirLister> *kdls = urlsCurrentlyListed[deletedUrl.url()];
1713 kdls =
new TQPtrList<KDirLister>( *kdls );
1714 for (
KDirLister *kdl = kdls->first(); kdl; kdl = kdls->next() )
1715 stop( kdl, deletedUrl );
1723 kdls = urlsCurrentlyHeld[deletedUrl.url()];
1727 kdls =
new TQPtrList<KDirLister>( *kdls );
1729 for (
KDirLister *kdl = kdls->first(); kdl; kdl = kdls->next() )
1732 if ( kdl->d->url == deletedUrl )
1735 if ( kdl->d->rootFileItem )
1736 emit kdl->
deleteItem( kdl->d->rootFileItem );
1738 kdl->d->rootFileItem = 0;
1742 bool treeview = kdl->d->lstDirs.count() > 1;
1746 forgetDirs( kdl, deletedUrl, treeview );
1756 DirItem *dir = itemsInUse.take( deletedUrl.url() );
1766 removeDirFromCache( dirUrl );
1769 void KDirListerCache::processPendingUpdates()
1775 void KDirListerCache::printDebug()
1777 kdDebug(7004) <<
"Items in use: " << endl;
1778 TQDictIterator<DirItem> itu( itemsInUse );
1779 for ( ; itu.current() ; ++itu ) {
1780 kdDebug(7004) <<
" " << itu.currentKey() <<
" URL: " << itu.current()->url
1781 <<
" rootItem: " << ( itu.current()->rootItem ? itu.current()->rootItem->url() : KURL() )
1782 <<
" autoUpdates refcount: " << itu.current()->autoUpdates
1783 <<
" complete: " << itu.current()->complete
1784 << ( itu.current()->lstItems ? TQString(
" with %1 items.").arg(itu.current()->lstItems->count()) : TQString(
" lstItems=NULL") ) << endl;
1787 kdDebug(7004) <<
"urlsCurrentlyHeld: " << endl;
1788 TQDictIterator< TQPtrList<KDirLister> > it( urlsCurrentlyHeld );
1789 for ( ; it.current() ; ++it )
1792 for ( TQPtrListIterator<KDirLister> listit( *it.current() ); listit.current(); ++listit )
1793 list +=
" 0x" + TQString::number( (
long)listit.current(), 16 );
1794 kdDebug(7004) <<
" " << it.currentKey() <<
" " << it.current()->count() <<
" listers: " << list << endl;
1797 kdDebug(7004) <<
"urlsCurrentlyListed: " << endl;
1798 TQDictIterator< TQPtrList<KDirLister> > it2( urlsCurrentlyListed );
1799 for ( ; it2.current() ; ++it2 )
1802 for ( TQPtrListIterator<KDirLister> listit( *it2.current() ); listit.current(); ++listit )
1803 list +=
" 0x" + TQString::number( (
long)listit.current(), 16 );
1804 kdDebug(7004) <<
" " << it2.currentKey() <<
" " << it2.current()->count() <<
" listers: " << list << endl;
1807 TQMap< KIO::ListJob *, TQValueList<KIO::UDSEntry> >::Iterator jit = jobs.begin();
1808 kdDebug(7004) <<
"Jobs: " << endl;
1809 for ( ; jit != jobs.end() ; ++jit )
1810 kdDebug(7004) <<
" " << jit.key() <<
" listing " << joburl( jit.key() ).prettyURL() <<
": " << (*jit).count() <<
" entries." << endl;
1812 kdDebug(7004) <<
"Items in cache: " << endl;
1813 TQCacheIterator<DirItem> itc( itemsCached );
1814 for ( ; itc.current() ; ++itc )
1815 kdDebug(7004) <<
" " << itc.currentKey() <<
" rootItem: " 1816 << ( itc.current()->rootItem ? itc.current()->rootItem->url().prettyURL() : TQString(
"NULL") )
1817 << ( itc.current()->lstItems ? TQString(
" with %1 items.").arg(itc.current()->lstItems->count()) : TQString(
" lstItems=NULL") ) << endl;
1826 kdDebug(7003) <<
"+KDirLister" << endl;
1828 d =
new KDirListerPrivate;
1831 d->delayedMimeTypes = _delayedMimeTypes;
1833 setAutoUpdate(
true );
1834 setDirOnlyMode(
false );
1835 setShowingDotFiles(
false );
1837 setAutoErrorHandlingEnabled(
true, 0 );
1842 kdDebug(7003) <<
"-KDirLister" << endl;
1844 if ( KDirListerCache::exists() )
1848 s_pCache->forgetDirs(
this );
1856 kdDebug(7003) << k_funcinfo << _url.prettyURL()
1857 <<
" keep=" << _keep <<
" reload=" << _reload << endl;
1860 if ( d->changes != NONE && _keep )
1865 return s_pCache->listDir(
this, _url, _keep, _reload );
1870 kdDebug(7003) << k_funcinfo << endl;
1871 s_pCache->stop(
this );
1876 kdDebug(7003) << k_funcinfo << _url.prettyURL() << endl;
1877 s_pCache->stop(
this, _url );
1882 return d->autoUpdate;
1887 if ( d->autoUpdate == _enable )
1890 d->autoUpdate = _enable;
1891 s_pCache->setAutoUpdate(
this, _enable );
1896 return d->isShowingDotFiles;
1901 if ( d->isShowingDotFiles == _showDotFiles )
1904 d->isShowingDotFiles = _showDotFiles;
1905 d->changes ^= DOT_FILES;
1910 return d->dirOnlyMode;
1915 if ( d->dirOnlyMode == _dirsOnly )
1918 d->dirOnlyMode = _dirsOnly;
1919 d->changes ^= DIR_ONLY_MODE;
1924 return d->autoErrorHandling;
1929 d->autoErrorHandling = enable;
1930 d->errorParent = parent;
1945 if ( d->changes == NONE )
1948 static const TQString& dot = KGlobal::staticQString(
".");
1949 static const TQString& dotdot = KGlobal::staticQString(
"..");
1951 for ( KURL::List::Iterator it = d->lstDirs.begin();
1952 it != d->lstDirs.end(); ++it )
1954 KFileItemListIterator kit( *s_pCache->itemsForDir( *it ) );
1955 for ( ; kit.current(); ++kit )
1957 if ( (*kit)->text() == dot || (*kit)->text() == dotdot )
1960 bool oldMime =
true, newMime =
true;
1962 if ( d->changes & MIME_FILTER )
1964 oldMime = doMimeFilter( (*kit)->mimetype(), d->oldMimeFilter )
1965 && doMimeExcludeFilter( (*kit)->mimetype(), d->oldMimeExcludeFilter );
1966 newMime = doMimeFilter( (*kit)->mimetype(), d->mimeFilter )
1967 && doMimeExcludeFilter( (*kit)->mimetype(), d->mimeExcludeFilter );
1969 if ( oldMime && !newMime )
1971 emit deleteItem( *kit );
1976 if ( d->changes & DIR_ONLY_MODE )
1979 if ( d->dirOnlyMode )
1981 if ( !(*kit)->isDir() )
1982 emit deleteItem( *kit );
1984 else if ( !(*kit)->isDir() )
1990 if ( (*kit)->isHidden() )
1992 if ( d->changes & DOT_FILES )
1995 if ( d->isShowingDotFiles )
1998 emit deleteItem( *kit );
2003 else if ( d->changes & NAME_FILTER )
2005 bool oldName = (*kit)->isDir() ||
2006 d->oldFilters.isEmpty() ||
2007 doNameFilter( (*kit)->text(), d->oldFilters );
2009 bool newName = (*kit)->isDir() ||
2010 d->lstFilters.isEmpty() ||
2011 doNameFilter( (*kit)->text(), d->lstFilters );
2013 if ( oldName && !newName )
2015 emit deleteItem( *kit );
2018 else if ( !oldName && newName )
2022 if ( (d->changes & MIME_FILTER) && !oldMime && newMime )
2034 s_pCache->updateDirectory( _u );
2044 return d->rootFileItem;
2049 return s_pCache->findByURL(
this, _url );
2054 return s_pCache->findByName(
this, _name );
2057 #ifndef KDE_NO_COMPAT 2058 KFileItem *KDirLister::find(
const KURL& _url )
const 2060 return findByURL( _url );
2069 if ( !(d->changes & NAME_FILTER) )
2071 d->oldFilters = d->lstFilters;
2072 d->lstFilters.setAutoDelete(
false );
2075 d->lstFilters.clear();
2076 d->lstFilters.setAutoDelete(
true );
2078 d->nameFilter = nameFilter;
2081 TQStringList list = TQStringList::split(
' ', nameFilter );
2082 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
2083 d->lstFilters.append(
new TQRegExp(*it,
false,
true ) );
2085 d->changes |= NAME_FILTER;
2090 return d->nameFilter;
2095 if ( !(d->changes & MIME_FILTER) )
2096 d->oldMimeFilter = d->mimeFilter;
2098 if ( mimeFilter.find(
"all/allfiles") != mimeFilter.end() ||
2099 mimeFilter.find(
"all/all") != mimeFilter.end() )
2100 d->mimeFilter.clear();
2102 d->mimeFilter = mimeFilter;
2104 d->changes |= MIME_FILTER;
2109 if ( !(d->changes & MIME_FILTER) )
2110 d->oldMimeExcludeFilter = d->mimeExcludeFilter;
2112 d->mimeExcludeFilter = mimeExcludeFilter;
2113 d->changes |= MIME_FILTER;
2119 if ( !(d->changes & MIME_FILTER) )
2121 d->oldMimeFilter = d->mimeFilter;
2122 d->oldMimeExcludeFilter = d->mimeExcludeFilter;
2124 d->mimeFilter.clear();
2125 d->mimeExcludeFilter.clear();
2126 d->changes |= MIME_FILTER;
2131 return d->mimeFilter;
2136 return doNameFilter( name, d->lstFilters );
2141 return doMimeFilter( mime, d->mimeFilter ) && doMimeExcludeFilter(mime,d->mimeExcludeFilter);
2149 static const TQString& dotdot = KGlobal::staticQString(
"..");
2151 if ( item->
text() == dotdot )
2154 if ( !d->isShowingDotFiles && item->
isHidden() )
2157 if ( item->
isDir() || d->lstFilters.isEmpty() )
2160 return matchesFilter( item->
text() );
2167 if ( d->mimeFilter.isEmpty() && d->mimeExcludeFilter.isEmpty() )
2169 return matchesMimeFilter( item->
mimetype() );
2174 for ( TQPtrListIterator<TQRegExp> it( filters ); it.current(); ++it )
2175 if ( it.current()->exactMatch( name ) )
2183 if ( filters.isEmpty() )
2188 TQStringList::ConstIterator it = filters.begin();
2189 for ( ; it != filters.end(); ++it )
2190 if ( mimeptr->is(*it) )
2198 bool KDirLister::doMimeExcludeFilter(
const TQString& mime,
const TQStringList& filters )
const 2200 if ( filters.isEmpty() )
2203 TQStringList::ConstIterator it = filters.begin();
2204 for ( ; it != filters.end(); ++it )
2205 if ( (*it) == mime )
2214 return s_pCache->validURL(
this, _url );
2219 if ( d->autoErrorHandling )
2226 void KDirLister::addNewItem(
const KFileItem *item )
2228 if ( ( d->dirOnlyMode && !item->
isDir() ) || !matchesFilter( item ) )
2231 if ( matchesMimeFilter( item ) )
2233 if ( !d->lstNewItems )
2234 d->lstNewItems =
new KFileItemList;
2236 d->lstNewItems->append( item );
2240 if ( !d->lstMimeFilteredItems )
2241 d->lstMimeFilteredItems =
new KFileItemList;
2243 d->lstMimeFilteredItems->append( item );
2247 void KDirLister::addNewItems(
const KFileItemList& items )
2253 for ( KFileItemListIterator kit( items ); kit.current(); ++kit )
2257 void KDirLister::aboutToRefreshItem(
const KFileItem *item )
2260 if ( ( d->dirOnlyMode && !item->
isDir() ) || !matchesFilter( item ) )
2261 d->refreshItemWasFiltered =
true;
2262 else if ( !matchesMimeFilter( item ) )
2263 d->refreshItemWasFiltered =
true;
2265 d->refreshItemWasFiltered =
false;
2268 void KDirLister::addRefreshItem(
const KFileItem *item )
2270 bool isExcluded = (d->dirOnlyMode && !item->
isDir()) || !matchesFilter( item );
2272 if ( !isExcluded && matchesMimeFilter( item ) )
2274 if ( d->refreshItemWasFiltered )
2276 if ( !d->lstNewItems )
2277 d->lstNewItems =
new KFileItemList;
2279 d->lstNewItems->append( item );
2283 if ( !d->lstRefreshItems )
2284 d->lstRefreshItems =
new KFileItemList;
2286 d->lstRefreshItems->append( item );
2289 else if ( !d->refreshItemWasFiltered )
2291 if ( !d->lstRemoveItems )
2292 d->lstRemoveItems =
new KFileItemList;
2296 d->lstRemoveItems->append( item );
2300 void KDirLister::emitItems()
2302 KFileItemList *tmpNew = d->lstNewItems;
2305 KFileItemList *tmpMime = d->lstMimeFilteredItems;
2306 d->lstMimeFilteredItems = 0;
2308 KFileItemList *tmpRefresh = d->lstRefreshItems;
2309 d->lstRefreshItems = 0;
2311 KFileItemList *tmpRemove = d->lstRemoveItems;
2312 d->lstRemoveItems = 0;
2316 emit newItems( *tmpNew );
2322 emit itemsFilteredByMime( *tmpMime );
2328 emit refreshItems( *tmpRefresh );
2334 for (
KFileItem *tmp = tmpRemove->first(); tmp; tmp = tmpRemove->next() )
2335 emit deleteItem( tmp );
2340 void KDirLister::emitDeleteItem(
KFileItem *item )
2342 if ( ( d->dirOnlyMode && !item->
isDir() ) || !matchesFilter( item ) )
2344 if ( matchesMimeFilter( item ) )
2345 emit deleteItem( item );
2351 void KDirLister::slotInfoMessage(
KIO::Job *,
const TQString& message )
2353 emit infoMessage( message );
2356 void KDirLister::slotPercent(
KIO::Job *job,
unsigned long pcnt )
2358 d->jobData[
static_cast<KIO::ListJob *
>(job)].percent = pcnt;
2364 TQMap< KIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2365 while ( dataIt != d->jobData.end() )
2367 result += (*dataIt).percent * (*dataIt).totalSize;
2368 size += (*dataIt).totalSize;
2376 emit percent( result );
2381 d->jobData[
static_cast<KIO::ListJob *
>(job)].totalSize = size;
2384 TQMap< KIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2385 while ( dataIt != d->jobData.end() )
2387 result += (*dataIt).totalSize;
2391 emit totalSize( result );
2396 d->jobData[
static_cast<KIO::ListJob *
>(job)].processedSize = size;
2399 TQMap< KIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2400 while ( dataIt != d->jobData.end() )
2402 result += (*dataIt).processedSize;
2406 emit processedSize( result );
2409 void KDirLister::slotSpeed(
KIO::Job *job,
unsigned long spd )
2411 d->jobData[
static_cast<KIO::ListJob *
>(job)].speed = spd;
2414 TQMap< KIO::ListJob *, KDirListerPrivate::JobData >::Iterator dataIt = d->jobData.begin();
2415 while ( dataIt != d->jobData.end() )
2417 result += (*dataIt).speed;
2421 emit speed( result );
2424 uint KDirLister::numJobs()
2426 return d->jobData.count();
2431 d->jobData.remove( job );
2436 KDirListerPrivate::JobData jobData;
2438 jobData.percent = 0;
2439 jobData.processedSize = 0;
2440 jobData.totalSize = 0;
2442 d->jobData.insert( job, jobData );
2443 d->complete =
false;
2448 connect( job, TQT_SIGNAL(infoMessage(
KIO::Job *,
const TQString& )),
2449 this, TQT_SLOT(slotInfoMessage(
KIO::Job *,
const TQString& )) );
2450 connect( job, TQT_SIGNAL(percent(
KIO::Job *,
unsigned long )),
2451 this, TQT_SLOT(slotPercent(
KIO::Job *,
unsigned long )) );
2456 connect( job, TQT_SIGNAL(speed(
KIO::Job *,
unsigned long )),
2457 this, TQT_SLOT(slotSpeed(
KIO::Job *,
unsigned long )) );
2472 return itemsForDir( url(), which );
2477 KFileItemList result;
2478 KFileItemList *allItems = s_pCache->itemsForDir( dir );
2482 if ( which == AllItems )
2486 for ( KFileItemListIterator kit( *allItems ); kit.current(); ++kit )
2489 bool isExcluded = (d->dirOnlyMode && !item->
isDir()) || !matchesFilter( item );
2490 if ( !isExcluded && matchesMimeFilter( item ) )
2491 result.append( item );
2500 void KDirLister::virtual_hook(
int,
void * )
2503 #include "kdirlister.moc" 2504 #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.
TQWidget * window() const
Returns the window this job is associated with.
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.
void showErrorDialog(TQWidget *parent=0L)
Display a dialog box to inform the user of the error given by this job.
virtual void setAutoUpdate(bool enable)
Enable/disable automatic directory updating, when a directory changes (using KDirWatch).
A ListJob is allows you to get the get the content of a directory.
const KURL & url() const
Returns the SimpleJob's URL.
virtual void handleError(KIO::Job *)
Reimplement to customize error handling.
void refresh()
Throw away and re-read (for local files) all information about the file.
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.
void setWindow(TQWidget *window)
Associate this job with a window given by window.
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.
KIO_EXPORT bool manually_mounted(const TQString &filename)
Checks if the path belongs to a filesystem that is manually mounted.
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.
KIO_EXPORT ListJob * listDir(const KURL &url, bool showProgressInfo=true, bool includeHidden=true)
List the contents of url, which is assumed to be a directory.
virtual void stop()
Stop listing all directories currently being listed.
virtual void kill(bool quietly=true)
Abort job.
void deleteItem(KFileItem *_fileItem)
Signal an item to remove.
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.
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.
virtual void updateDirectory(const KURL &_dir)
Update the directory _dir.
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.
Filename - as displayed in directory listings etc.
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.
void setUDSEntry(const KIO::UDSEntry &entry, const KURL &url, bool determineMimeTypeOnDemand=false, bool urlIsDirectory=false)
Reinitialize KFileItem with a new UDSEntry.
TQString localPath() const
Returns the local path if isLocalFile() == true or the KIO 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.
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.
TQ_ULLONG filesize_t
64-bit file size
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.
int error() const
Returns the error code, if there has been an error.
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.
bool autoUpdate() const
Checks whether KDirWatch will automatically update directories.
void setAutoErrorHandlingEnabled(bool enable, TQWidget *parent)
Enable or disable auto error handling is enabled.
bool isMarked() const
Used when updating a directory.
The base class for all jobs.
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 kiojob used to list and update a directory and has signals for the user...
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 TQString & nameFilter() const
Returns the current name filter, as set via setNameFilter()
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.