kio Library API Documentation

kdirlister_p.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Michael Brade <brade@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
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   // toplevel URL
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   // file item for the root itself (".")
00097   KFileItem *rootFileItem;
00098 
00099   KFileItemList *lstNewItems, *lstRefreshItems, *lstMimeFilteredItems,
00100     *lstRemoveItems;
00101 
00102   int changes;
00103  
00104   QWidget *window; // Main window ths lister is associated with
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   // stop all running jobs for lister
00135   void stop( KDirLister *lister );
00136   // stop just the job listing url for lister
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   // if lister is set, it is checked that the url is held by the lister
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   // check if _url is held by some lister and return true,
00200   // otherwise schedule a delayed update and return false
00201   bool checkUpdate( const QString& _url );
00202   // when there were items deleted from the filesystem all the listers holding
00203   // the parent directory need to be notified, the unmarked items have to be deleted
00204   // and removed from the cache including all the childs.
00205   void deleteUnmarkedItems( QPtrList<KDirLister> *, KFileItemList * );
00206   void processPendingUpdates();
00207   // common for slotRedirection and FileRenamed
00208   void renameDir( const KURL &oldUrl, const KURL &url );
00209   // common for deleteUnmarkedItems and FilesRemoved
00210   void deleteDir( const KURL& dirUrl );
00211   // remove directory from cache (itemsCached), including all child dirs
00212   void removeDirFromCache( const KURL& dir );
00213   // helper for renameDir
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     // number of KDirListers using autoUpdate for this dir
00257     short autoUpdates;
00258 
00259     // this directory is up-to-date
00260     bool complete;
00261 
00262     // the complete url of this directory
00263     KURL url;
00264 
00265     // KFileItem representing the root of this directory.
00266     // Remember that this is optional. FTP sites don't return '.' in
00267     // the list, so they give no root item
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   // an item is a complete directory
00276   QDict<DirItem> itemsInUse;
00277   QCache<DirItem> itemsCached;
00278 
00279   // A lister can be EITHER in urlsCurrentlyListed OR urlsCurrentlyHeld but NOT
00280   // in both at the same time.
00281   //     On the other hand there can be some listers in urlsCurrentlyHeld
00282   // and some in urlsCurrentlyListed for the same url!
00283   // Or differently said, there can be an entry for url in urlsCurrentlyListed
00284   // and urlsCurrentlyHeld. This happens if more listers are requesting url at
00285   // the same time and one lister was stopped during the listing of files.
00286 
00287   // saves all urls that are currently being listed and maps them
00288   // to their KDirListers
00289   QDict< QPtrList<KDirLister> > urlsCurrentlyListed;
00290 
00291   // saves all KDirListers that are just holding url
00292   QDict< QPtrList<KDirLister> > urlsCurrentlyHeld;
00293 
00294   // running timers for the delayed update
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
KDE Logo
This file is part of the documentation for kio Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 14 09:17:08 2006 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003