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 complete = false;
00045
00046 autoUpdate = false;
00047 isShowingDotFiles = false;
00048 dirOnlyMode = false;
00049
00050 autoErrorHandling = false;
00051 errorParent = 0;
00052
00053 delayedMimeTypes = false;
00054
00055 rootFileItem = 0;
00056 lstNewItems = 0;
00057 lstRefreshItems = 0;
00058 lstMimeFilteredItems = 0;
00059
00060 changes = NONE;
00061
00062 window = 0;
00063
00064 lstFilters.setAutoDelete( true );
00065 oldFilters.setAutoDelete( true );
00066 }
00067
00072 KURL::List lstDirs;
00073
00074
00075 KURL url;
00076
00077 bool complete;
00078
00079 bool autoUpdate;
00080 bool isShowingDotFiles;
00081 bool dirOnlyMode;
00082
00083 bool autoErrorHandling;
00084 QWidget *errorParent;
00085
00086 bool delayedMimeTypes;
00087
00088 struct JobData {
00089 long unsigned int percent, speed;
00090 KIO::filesize_t processedSize, totalSize;
00091 };
00092
00093 QMap< KIO::ListJob*, JobData > jobData;
00094
00095
00096 KFileItem *rootFileItem;
00097
00098 KFileItemList *lstNewItems, *lstRefreshItems, *lstMimeFilteredItems;
00099
00100 int changes;
00101
00102 QWidget *window;
00103
00104 QString nameFilter;
00105 QPtrList<QRegExp> lstFilters, oldFilters;
00106 QStringList mimeFilter, oldMimeFilter;
00107 QStringList mimeExcludeFilter, oldMimeExcludeFilter;
00108 };
00109
00123 class KDirListerCache : public QObject, KDirNotify
00124 {
00125 Q_OBJECT
00126 public:
00127 KDirListerCache( int maxCount = 10 );
00128 ~KDirListerCache();
00129
00130 void listDir( KDirLister* lister, const KURL &_url, bool _keep, bool _reload );
00131
00132
00133 void stop( KDirLister *lister );
00134
00135 void stop( KDirLister *lister, const KURL &_url );
00136
00137 void setAutoUpdate( KDirLister *lister, bool enable );
00138
00139 void forgetDirs( KDirLister *lister );
00140 void forgetDirs( KDirLister *lister, const KURL &_url, bool notify );
00141
00142 void updateDirectory( const KURL &_dir );
00143
00144 KFileItemList* itemsForDir( const KURL &_dir ) const;
00145
00146 KFileItem* findByName( const KDirLister *lister, const QString &_name ) const;
00147
00148 KFileItem* findByURL( const KDirLister *lister, const KURL &_url ) const;
00149
00156 virtual void FilesAdded( const KURL &directory );
00157
00165 virtual void FilesRemoved( const KURL::List &fileList );
00166
00173 virtual void FilesChanged( const KURL::List &fileList );
00174 virtual void FileRenamed( const KURL &src, const KURL &dst );
00175
00176 static KDirListerCache* self();
00177
00178 private slots:
00179 void slotFileDirty( const QString &_file );
00180 void slotFileCreated( const QString &_file );
00181 void slotFileDeleted( const QString &_file );
00182
00183 void slotFileDirtyDelayed();
00184
00185 void slotEntries( KIO::Job *job, const KIO::UDSEntryList &entries );
00186 void slotResult( KIO::Job *j );
00187 void slotRedirection( KIO::Job *job, const KURL &url );
00188
00189 void slotUpdateEntries( KIO::Job *job, const KIO::UDSEntryList &entries );
00190 void slotUpdateResult( KIO::Job *job );
00191
00192 private:
00193
00194 KIO::ListJob *jobForUrl(const QString& _url);
00195 void killJob( KIO::ListJob *job );
00196
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.4.