kdirlister_p.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef kdirlister_p_h
00021 #define kdirlister_p_h
00022
00023 #include "kfileitem.h"
00024
00025 #include <qmap.h>
00026 #include <qdict.h>
00027 #include <qcache.h>
00028 #include <qwidget.h>
00029
00030 #include <kurl.h>
00031 #include <kio/global.h>
00032 #include <kdirwatch.h>
00033
00034 class QTimer;
00035 class KDirLister;
00036 namespace KIO { class Job; class ListJob; }
00037
00038
00039 class KDirLister::KDirListerPrivate
00040 {
00041 public:
00042 KDirListerPrivate()
00043 {
00044 numJobs = 0;
00045 complete = false;
00046
00047 autoUpdate = false;
00048 isShowingDotFiles = false;
00049 dirOnlyMode = false;
00050
00051 autoErrorHandling = false;
00052 errorParent = 0;
00053
00054 delayedMimeTypes = false;
00055
00056 rootFileItem = 0;
00057 lstNewItems = 0;
00058 lstRefreshItems = 0;
00059 lstMimeFilteredItems = 0;
00060
00061 changes = NONE;
00062
00063 window = 0;
00064
00065 lstFilters.setAutoDelete( true );
00066 oldFilters.setAutoDelete( true );
00067 }
00068
00073 KURL::List lstDirs;
00074
00075
00076 KURL url;
00077
00078 unsigned short numJobs;
00079
00080 bool complete;
00081
00082 bool autoUpdate;
00083 bool isShowingDotFiles;
00084 bool dirOnlyMode;
00085
00086 bool autoErrorHandling;
00087 QWidget *errorParent;
00088
00089 bool delayedMimeTypes;
00090
00091 struct JobData {
00092 long unsigned int percent, speed;
00093 KIO::filesize_t processedSize, totalSize;
00094 };
00095
00096 QMap< KIO::ListJob*, JobData > jobData;
00097
00098
00099 KFileItem *rootFileItem;
00100
00101 KFileItemList *lstNewItems, *lstRefreshItems, *lstMimeFilteredItems;
00102
00103 int changes;
00104
00105 QWidget *window;
00106
00107 QString nameFilter;
00108 QPtrList<QRegExp> lstFilters, oldFilters;
00109 QStringList mimeFilter, oldMimeFilter;
00110 QStringList mimeExcludeFilter, oldMimeExcludeFilter;
00111 };
00112
00126 class KDirListerCache : public QObject, KDirNotify
00127 {
00128 Q_OBJECT
00129 public:
00130 KDirListerCache( int maxCount = 10 );
00131 ~KDirListerCache();
00132
00133 void listDir( KDirLister* lister, const KURL &_url, bool _keep, bool _reload );
00134
00135
00136 void stop( KDirLister *lister );
00137
00138 void stop( KDirLister *lister, const KURL &_url );
00139
00140 void setAutoUpdate( KDirLister *lister, bool enable );
00141
00142 void forgetDirs( KDirLister *lister );
00143 void forgetDirs( KDirLister *lister, const KURL &_url, bool notify );
00144
00145 void updateDirectory( const KURL &_dir );
00146
00147 KFileItemList* itemsForDir( const KURL &_dir ) const;
00148
00149 KFileItem* findByName( const KDirLister *lister, const QString &_name ) const;
00150
00151 KFileItem* findByURL( const KDirLister *lister, const KURL &_url ) const;
00152
00159 virtual void FilesAdded( const KURL &directory );
00160
00168 virtual void FilesRemoved( const KURL::List &fileList );
00169
00176 virtual void FilesChanged( const KURL::List &fileList );
00177 virtual void FileRenamed( const KURL &src, const KURL &dst );
00178
00179 static KDirListerCache* self();
00180
00181 private slots:
00182 void slotFileDirty( const QString &_file );
00183 void slotFileCreated( const QString &_file );
00184 void slotFileDeleted( const QString &_file );
00185
00186 void slotFileDirtyDelayed();
00187
00188 void slotEntries( KIO::Job *job, const KIO::UDSEntryList &entries );
00189 void slotResult( KIO::Job *j );
00190 void slotRedirection( KIO::Job *job, const KURL &url );
00191
00192 void slotUpdateEntries( KIO::Job *job, const KIO::UDSEntryList &entries );
00193 void slotUpdateResult( KIO::Job *job );
00194
00195 private:
00196 bool killJob( const QString& _url );
00197
00198
00199 bool checkUpdate( const QString& _url );
00200
00201
00202
00203 void deleteUnmarkedItems( QPtrList<KDirLister> *, KFileItemList * );
00204 void processPendingUpdates();
00205
00206 void renameDir( const KURL &oldUrl, const KURL &url );
00207
00208 void deleteDir( const KURL& dirUrl );
00209
00210 void removeDirFromCache( const KURL& dir );
00211
00212 void emitRedirections( const KURL &oldUrl, const KURL &url );
00213 void emitRefreshItem( KFileItem* fileitem );
00214 #ifndef NDEBUG
00215 void printDebug();
00216 #endif
00217
00218 struct DirItem
00219 {
00220 DirItem( const KURL &dir )
00221 : url(dir), rootItem(0), lstItems(new KFileItemList)
00222 {
00223 autoUpdates = 0;
00224 complete = false;
00225 lstItems->setAutoDelete( true );
00226 }
00227
00228 ~DirItem()
00229 {
00230 if ( autoUpdates && KDirWatch::exists() )
00231 kdirwatch->removeDir( url.path() );
00232
00233 delete rootItem;
00234 delete lstItems;
00235 }
00236
00237 void incAutoUpdate()
00238 {
00239 if ( url.isLocalFile() && autoUpdates++ == 0 )
00240 kdirwatch->addDir( url.path() );
00241 }
00242
00243 void decAutoUpdate()
00244 {
00245 if ( url.isLocalFile() )
00246 {
00247 if ( --autoUpdates == 0 )
00248 kdirwatch->removeDir( url.path() );
00249 else if ( autoUpdates < 0 )
00250 autoUpdates = 0;
00251 }
00252 }
00253
00254
00255 short autoUpdates;
00256
00257
00258 bool complete;
00259
00260
00261 KURL url;
00262
00263
00264
00265
00266 KFileItem* rootItem;
00267 KFileItemList* lstItems;
00268 };
00269
00270 static const unsigned short MAX_JOBS_PER_LISTER;
00271 QMap< KIO::ListJob *, KIO::UDSEntryList > jobs;
00272
00273
00274 QDict<DirItem> itemsInUse;
00275 QCache<DirItem> itemsCached;
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 QDict< QPtrList<KDirLister> > urlsCurrentlyListed;
00288
00289
00290 QDict< QPtrList<KDirLister> > urlsCurrentlyHeld;
00291
00292
00293 QDict<QTimer> pendingUpdates;
00294
00295 static KDirListerCache* s_pSelf;
00296 };
00297
00298 const unsigned short KDirListerCache::MAX_JOBS_PER_LISTER = 5;
00299
00300 #define s_pCache KDirListerCache::self()
00301
00302 #endif
This file is part of the documentation for kdelibs Version 3.1.0.