kdirlister.h
00001 /* This file is part of the KDE project 00002 Copyright (C) 1999 David Faure <faure@kde.org> 00003 2001, 2002, 2004, 2005 Michael Brade <brade@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef kdirlister_h 00022 #define kdirlister_h 00023 00024 #include "tdefileitem.h" 00025 #include "kdirnotify.h" 00026 00027 #include <tqstring.h> 00028 #include <tqstringlist.h> 00029 00030 #include <kurl.h> 00031 00032 namespace TDEIO { class Job; class LocalURLJob; class ListJob; } 00033 00055 class TDEIO_EXPORT KDirLister : public TQObject 00056 { 00057 class KDirListerPrivate; 00058 friend class KDirListerPrivate; 00059 friend class KDirListerCache; 00060 00061 Q_OBJECT 00062 TQ_PROPERTY( bool autoUpdate READ autoUpdate WRITE setAutoUpdate ) 00063 TQ_PROPERTY( bool showingDotFiles READ showingDotFiles WRITE setShowingDotFiles ) 00064 TQ_PROPERTY( bool dirOnlyMode READ dirOnlyMode WRITE setDirOnlyMode ) 00065 TQ_PROPERTY( bool autoErrorHandlingEnabled READ autoErrorHandlingEnabled ) 00066 TQ_PROPERTY( TQString nameFilter READ nameFilter WRITE setNameFilter ) 00067 TQ_PROPERTY( TQStringList mimeFilter READ mimeFilters WRITE setMimeFilter RESET clearMimeFilter ) 00068 00069 public: 00075 KDirLister( bool _delayedMimeTypes = false ); 00076 00080 virtual ~KDirLister(); 00081 00105 virtual bool openURL( const KURL& _url, bool _keep = false, bool _reload = false ); 00106 00114 virtual void stop(); 00115 00125 virtual void stop( const KURL& _url ); 00126 00132 bool autoUpdate() const; 00133 00139 virtual void setAutoUpdate( bool enable ); 00140 00148 bool autoErrorHandlingEnabled() const; 00149 00159 void setAutoErrorHandlingEnabled( bool enable, TQWidget *parent ); 00160 00168 bool showingDotFiles() const; 00169 00178 virtual void setShowingDotFiles( bool _showDotFiles ); 00179 00186 bool dirOnlyMode() const; 00187 00193 virtual void setDirOnlyMode( bool dirsOnly ); 00194 00203 const KURL& url() const; 00204 00214 const KURL::List& directories() const; 00215 00220 virtual void emitChanges(); 00221 00233 virtual void updateDirectory( const KURL& _dir ); 00234 00239 bool isFinished() const; 00240 00245 KFileItem *rootItem() const; 00246 00252 virtual KFileItem *findByURL( const KURL& _url ) const; 00253 #ifndef KDE_NO_COMPAT 00254 KFileItem *find( const KURL& _url ) const; 00255 #endif 00256 00262 virtual KFileItem *findByName( const TQString& name ) const; 00263 00274 virtual void setNameFilter( const TQString &filter ); 00275 00281 const TQString& nameFilter() const; 00282 00294 virtual void setMimeFilter( const TQStringList &mimeList ); 00295 00311 void setMimeExcludeFilter(const TQStringList &mimeList ); 00312 00313 00319 virtual void clearMimeFilter(); 00320 00325 const TQStringList& mimeFilters() const; 00326 00333 bool matchesFilter( const TQString& name ) const; 00334 00342 bool matchesMimeFilter( const TQString& mime ) const; 00343 00350 void setMainWindow( TQWidget *window ); 00351 00357 TQWidget *mainWindow(); 00358 00363 enum WhichItems 00364 { 00365 AllItems = 0, 00366 FilteredItems = 1 00367 }; 00368 00386 KFileItemList items( WhichItems which = FilteredItems ) const; 00387 00408 KFileItemList itemsForDir( const KURL& dir, 00409 WhichItems which = FilteredItems ) const; 00410 00411 signals: 00421 void started( const KURL& _url ); 00422 00426 void completed(); 00427 00433 void completed( const KURL& _url ); 00434 00438 void canceled(); 00439 00445 void canceled( const KURL& _url ); 00446 00453 void redirection( const KURL& _url ); 00454 00460 void redirection( const KURL& oldUrl, const KURL& newUrl ); 00461 00466 void clear(); 00467 00473 void clear( const KURL& _url ); 00474 00479 void newItems( const KFileItemList& items ); 00480 00485 void itemsFilteredByMime( const KFileItemList& items ); 00486 00496 void deleteItem( KFileItem *_fileItem ); 00497 00503 void refreshItems( const KFileItemList& items ); 00504 00510 void infoMessage( const TQString& msg ); 00511 00517 void percent( int percent ); 00518 00523 void totalSize( TDEIO::filesize_t size ); 00524 00529 void processedSize( TDEIO::filesize_t size ); 00530 00535 void speed( int bytes_per_second ); 00536 00537 protected: 00538 enum Changes { 00539 NONE=0, NAME_FILTER=1, MIME_FILTER=2, DOT_FILES=4, DIR_ONLY_MODE=8 00540 }; 00541 00554 virtual bool matchesFilter( const KFileItem * ) const; 00555 00568 virtual bool matchesMimeFilter( const KFileItem * ) const; 00569 00577 virtual bool doNameFilter( const TQString& name, const TQPtrList<TQRegExp>& filters ) const; 00578 00586 virtual bool doMimeFilter( const TQString& mime, const TQStringList& filters ) const; 00587 00591 bool doMimeExcludeFilter( const TQString& mimeExclude, const TQStringList& filters ) const; 00592 00598 virtual bool validURL( const KURL& ) const; 00599 00601 virtual void handleError( TDEIO::Job * ); 00602 00603 protected: 00604 virtual void virtual_hook( int id, void *data ); 00605 00606 private slots: 00607 void slotInfoMessage( TDEIO::Job *, const TQString& ); 00608 void slotPercent( TDEIO::Job *, unsigned long ); 00609 void slotTotalSize( TDEIO::Job *, TDEIO::filesize_t ); 00610 void slotProcessedSize( TDEIO::Job *, TDEIO::filesize_t ); 00611 void slotSpeed( TDEIO::Job *, unsigned long ); 00612 void slotOpenURLGotLocalURL( TDEIO::LocalURLJob*, const KURL&, bool ); 00613 void slotLocalURLKIODestroyed( ); 00614 00615 private: 00616 void jobStarted( TDEIO::ListJob * ); 00617 void connectJob( TDEIO::ListJob * ); 00618 void jobDone( TDEIO::ListJob * ); 00619 00620 uint numJobs(); 00621 00622 public: 00623 void emitCompleted( const KURL& _url ); 00624 00625 private: 00626 virtual void addNewItem( const KFileItem *item ); 00627 virtual void addNewItems( const KFileItemList& items ); 00628 /*virtual*/ void aboutToRefreshItem( const KFileItem *item ); // TODO: KDE 4.0 make virtual 00629 virtual void addRefreshItem( const KFileItem *item ); 00630 virtual void emitItems(); 00631 virtual void emitDeleteItem( KFileItem *item ); 00632 00633 KDirListerPrivate *d; 00634 }; 00635 00636 #endif 00637