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     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   // toplevel URL
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   // file item for the root itself (".")
00099   KFileItem *rootFileItem;
00100 
00101   KFileItemList *lstNewItems, *lstRefreshItems, *lstMimeFilteredItems;
00102 
00103   int changes;
00104  
00105   QWidget *window; // Main window ths lister is associated with
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   // stop all running jobs for lister
00136   void stop( KDirLister *lister );
00137   // stop just the job listing url for lister
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   // if lister is set, it is checked that the url is held by the lister
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   // check if _url is held by some lister and return true,
00198   // otherwise schedule a delayed update and return false
00199   bool checkUpdate( const QString& _url );
00200   // when there were items deleted from the filesystem all the listers holding
00201   // the parent directory need to be notified, the unmarked items have to be deleted
00202   // and removed from the cache including all the childs.
00203   void deleteUnmarkedItems( QPtrList<KDirLister> *, KFileItemList * );
00204   void processPendingUpdates();
00205   // common for slotRedirection and FileRenamed
00206   void renameDir( const KURL &oldUrl, const KURL &url );
00207   // common for deleteUnmarkedItems and FilesRemoved
00208   void deleteDir( const KURL& dirUrl );
00209   // remove directory from cache (itemsCached), including all child dirs
00210   void removeDirFromCache( const KURL& dir );
00211   // helper for renameDir
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     // number of KDirListers using autoUpdate for this dir
00255     short autoUpdates;
00256 
00257     // this directory is up-to-date
00258     bool complete;
00259 
00260     // the complete url of this directory
00261     KURL url;
00262 
00263     // KFileItem representing the root of this directory.
00264     // Remember that this is optional. FTP sites don't return '.' in
00265     // the list, so they give no root item
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   // an item is a complete directory
00274   QDict<DirItem> itemsInUse;
00275   QCache<DirItem> itemsCached;
00276 
00277   // A lister can be EITHER in urlsCurrentlyListed OR urlsCurrentlyHeld but NOT
00278   // in both at the same time.
00279   //     On the other hand there can be some listers in urlsCurrentlyHeld
00280   // and some in urlsCurrentlyListed for the same url!
00281   // Or differently said, there can be an entry for url in urlsCurrentlyListed
00282   // and urlsCurrentlyHeld. This happens if more listers are requesting url at
00283   // the same time and one lister was stopped during the listing of files.
00284 
00285   // saves all urls that are currently being listed and maps them
00286   // to their KDirListers
00287   QDict< QPtrList<KDirLister> > urlsCurrentlyListed;
00288 
00289   // saves all KDirListers that are just holding url
00290   QDict< QPtrList<KDirLister> > urlsCurrentlyHeld;
00291 
00292   // running timers for the delayed update
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
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:28 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001