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     lstRemoveItems = 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   bool complete;
00079 
00080   bool autoUpdate;
00081   bool isShowingDotFiles;
00082   bool dirOnlyMode;
00083 
00084   bool autoErrorHandling;
00085   QWidget *errorParent;
00086 
00087   bool delayedMimeTypes;
00088 
00089   struct JobData {
00090     long unsigned int percent, speed;
00091     KIO::filesize_t processedSize, totalSize;
00092   };
00093 
00094   QMap< KIO::ListJob*, JobData > jobData;
00095 
00096   
00097   KFileItem *rootFileItem;
00098 
00099   KFileItemList *lstNewItems, *lstRefreshItems, *lstMimeFilteredItems,
00100     *lstRemoveItems;
00101 
00102   int changes;
00103  
00104   QWidget *window; 
00105 
00106   QString nameFilter;
00107   QPtrList<QRegExp> lstFilters, oldFilters;
00108   QStringList mimeFilter, oldMimeFilter;
00109   QStringList mimeExcludeFilter, oldMimeExcludeFilter;
00110 };
00111 
00125 class KDirListerCache : public QObject, KDirNotify
00126 {
00127   Q_OBJECT
00128 public:
00129   KDirListerCache( int maxCount = 10 );
00130   ~KDirListerCache();
00131 
00132   void listDir( KDirLister* lister, const KURL &_url, bool _keep, bool _reload );
00133 
00134   
00135   void stop( KDirLister *lister );
00136   
00137   void stop( KDirLister *lister, const KURL &_url );
00138 
00139   void setAutoUpdate( KDirLister *lister, bool enable );
00140 
00141   void forgetDirs( KDirLister *lister );
00142   void forgetDirs( KDirLister *lister, const KURL &_url, bool notify );
00143 
00144   void updateDirectory( const KURL &_dir );
00145 
00146   KFileItemList* itemsForDir( const KURL &_dir ) const;
00147 
00148   KFileItem* findByName( const KDirLister *lister, const QString &_name ) const;
00149   
00150   KFileItem* findByURL( const KDirLister *lister, const KURL &_url ) const;
00151 
00158   virtual void FilesAdded( const KURL &directory );
00159 
00167   virtual void FilesRemoved( const KURL::List &fileList );
00168 
00175   virtual void FilesChanged( const KURL::List &fileList );
00176   virtual void FileRenamed( const KURL &src, const KURL &dst );
00177 
00178   static KDirListerCache* self();
00179 
00180 private slots:
00181   void slotFileDirty( const QString &_file );
00182   void slotFileCreated( const QString &_file );
00183   void slotFileDeleted( const QString &_file );
00184   
00185   void slotFileDirtyDelayed();
00186 
00187   void slotEntries( KIO::Job *job, const KIO::UDSEntryList &entries );
00188   void slotResult( KIO::Job *j );
00189   void slotRedirection( KIO::Job *job, const KURL &url );
00190 
00191   void slotUpdateEntries( KIO::Job *job, const KIO::UDSEntryList &entries );
00192   void slotUpdateResult( KIO::Job *job );
00193 
00194 private:
00195 
00196   KIO::ListJob *jobForUrl(const QString& _url);
00197   void killJob( KIO::ListJob *job );
00198 
00199   
00200   
00201   bool checkUpdate( const QString& _url );
00202   
00203   
00204   
00205   void deleteUnmarkedItems( QPtrList<KDirLister> *, KFileItemList * );
00206   void processPendingUpdates();
00207   
00208   void renameDir( const KURL &oldUrl, const KURL &url );
00209   
00210   void deleteDir( const KURL& dirUrl );
00211   
00212   void removeDirFromCache( const KURL& dir );
00213   
00214   void emitRedirections( const KURL &oldUrl, const KURL &url );
00215   void emitRefreshItem( KFileItem* fileitem );
00216 #ifndef NDEBUG
00217   void printDebug();
00218 #endif
00219 
00220   struct DirItem
00221   {
00222     DirItem( const KURL &dir )
00223       : url(dir), rootItem(0), lstItems(new KFileItemList)
00224     {
00225       autoUpdates = 0;
00226       complete = false;
00227       lstItems->setAutoDelete( true );
00228     }
00229 
00230     ~DirItem()
00231     {
00232       if ( autoUpdates && KDirWatch::exists() )
00233         kdirwatch->removeDir( url.path() );
00234 
00235       delete rootItem;
00236       delete lstItems;
00237     }
00238 
00239     void incAutoUpdate()
00240     {
00241       if ( url.isLocalFile() && autoUpdates++ == 0 )
00242         kdirwatch->addDir( url.path() );
00243     }
00244 
00245     void decAutoUpdate()
00246     {
00247       if ( url.isLocalFile() )
00248       {
00249         if ( --autoUpdates == 0 )
00250           kdirwatch->removeDir( url.path() );
00251         else if ( autoUpdates < 0 )
00252           autoUpdates = 0;
00253       }
00254     }
00255 
00256     
00257     short autoUpdates;
00258 
00259     
00260     bool complete;
00261 
00262     
00263     KURL url;
00264 
00265     
00266     
00267     
00268     KFileItem* rootItem;
00269     KFileItemList* lstItems;
00270   };
00271 
00272   static const unsigned short MAX_JOBS_PER_LISTER;
00273   QMap< KIO::ListJob *, KIO::UDSEntryList > jobs;
00274 
00275   
00276   QDict<DirItem> itemsInUse;
00277   QCache<DirItem> itemsCached;
00278 
00279   
00280   
00281   
00282   
00283   
00284   
00285   
00286 
00287   
00288   
00289   QDict< QPtrList<KDirLister> > urlsCurrentlyListed;
00290 
00291   
00292   QDict< QPtrList<KDirLister> > urlsCurrentlyHeld;
00293 
00294   
00295   QDict<QTimer> pendingUpdates;
00296   
00297   static KDirListerCache* s_pSelf;
00298 };
00299 
00300 const unsigned short KDirListerCache::MAX_JOBS_PER_LISTER = 5;
00301 
00302 #define s_pCache KDirListerCache::self()
00303 
00304 #endif
 
This file is part of the documentation for kio Library Version 3.2.0.