| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# 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
    00060     changes = NONE;
    00061
    00062     window = 0;
    00063
    00064     lstFilters.setAutoDelete( true );
    00065     oldFilters.setAutoDelete( true );
    00066   }
    00067
    00072   KURL::List lstDirs;
    00073
    00074   // toplevel URL
    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   // file item for the root itself (".")
    00096   KFileItem *rootFileItem;
    00097
    00098   KFileItemList *lstNewItems, *lstRefreshItems, *lstMimeFilteredItems;
    00099
    00100   int changes;
    00101
    00102   QWidget *window; // Main window ths lister is associated with
    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   // stop all running jobs for lister
    00133   void stop( KDirLister *lister );
    00134   // stop just the job listing url for lister
    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   // if lister is set, it is checked that the url is held by the lister
    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   // 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

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:21 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001