kfileitem.h
00001 /* This file is part of the KDE project 00002 Copyright (C) 1999 David Faure <faure@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., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef __kfileitem_h__ 00021 #define __kfileitem_h__ 00022 00023 #include <qstringlist.h> 00024 #include <sys/stat.h> 00025 00026 #include <qptrlist.h> 00027 #include <kio/global.h> 00028 #include <kurl.h> 00029 #include <kacl.h> 00030 #include <kmimetype.h> 00031 #include <kfilemetainfo.h> 00032 00033 #define KFILEITEM_HAS_ISWRITABLE // only used in libkonq/konq_iconviewwidget.cc, will be removed for 3.4 00034 00041 class KIO_EXPORT KFileItem 00042 { 00043 public: 00044 enum { Unknown = (mode_t) - 1 }; 00045 00057 KFileItem( const KIO::UDSEntry& _entry, const KURL& _url, 00058 bool _determineMimeTypeOnDemand = false, 00059 bool _urlIsDirectory = false ); 00060 00074 KFileItem( mode_t _mode, mode_t _permissions, const KURL& _url, 00075 bool _determineMimeTypeOnDemand = false ); 00076 00083 KFileItem( const KURL &url, const QString &mimeType, mode_t mode ); 00084 00089 KFileItem( const KFileItem &item ); 00090 00095 virtual ~KFileItem(); 00096 00101 void refresh(); 00102 00107 void refreshMimeType(); 00108 00113 const KURL & url() const { return m_url; } 00114 00120 void setURL( const KURL &url ); 00121 00128 void setName( const QString &name ); 00129 00134 mode_t permissions() const { return m_permissions; } 00135 00140 QString permissionsString() const; 00141 00147 bool hasExtendedACL() const; 00148 00154 KACL ACL() const; 00155 00161 KACL defaultACL() const; 00162 00167 mode_t mode() const { return m_fileMode; } 00168 00173 QString user() const; 00174 00179 QString group() const; 00180 00186 bool isLink() const { return m_bLink; } 00187 00192 bool isDir() const; 00193 00198 bool isFile() const { return !isDir(); } 00199 00206 bool isReadable() const; 00207 00215 bool isWritable() const; 00216 00221 bool isHidden() const; 00222 00227 QString linkDest() const; 00228 00235 QString localPath() const; 00236 00237 //FIXME KDE4 deprecate this in favor of size(bool &hasSize) 00242 KIO::filesize_t size() const; 00243 00249 KIO::filesize_t size(bool &hasSize) const; 00250 00251 //FIXME KDE4 deprecate this in favor of time(unsigned int which, bool &hasSize) 00258 time_t time( unsigned int which ) const; 00259 00267 time_t time( unsigned int which, bool &hasTime ) const; 00268 00276 QString timeString( unsigned int which = KIO::UDS_MODIFICATION_TIME ) const; 00277 00282 bool isLocalFile() const { return m_bIsLocalURL; } 00283 00289 const QString& text() const { return m_strText; } 00290 00298 const QString& name( bool lowerCase = false ) const { 00299 if ( !lowerCase ) 00300 return m_strName; 00301 else 00302 if ( m_strLowerCaseName.isNull() ) 00303 m_strLowerCaseName = m_strName.lower(); 00304 return m_strLowerCaseName; 00305 } 00306 00313 QString mimetype() const; 00314 00321 KMimeType::Ptr determineMimeType(); 00322 00328 KMimeType::Ptr mimeTypePtr() const { return m_pMimeType; } 00329 00330 bool isMimeTypeKnown() const; 00336 QString mimeComment(); 00337 00343 QString iconName(); 00344 00353 QPixmap pixmap( int _size, int _state=0 ) const; 00354 00361 int overlays() const; 00362 00368 QString getStatusBarInfo(); 00369 00378 QString getToolTipText(int maxcount = 6); 00379 00386 bool acceptsDrops( ); 00387 00392 void run(); 00393 00399 const KIO::UDSEntry & entry() const { return m_entry; } 00400 00405 bool isMarked() const { return m_bMarked; } 00410 void mark() { m_bMarked = true; } 00415 void unmark() { m_bMarked = false; } 00416 00422 bool cmp( const KFileItem & item ); 00423 00457 virtual void setExtraData( const void *key, void *value ); 00458 00466 virtual const void * extraData( const void *key ) const; 00467 00475 virtual void * extraData( const void *key ); 00476 00481 virtual void removeExtraData( const void *key ); 00482 00487 void setMetaInfo( const KFileMetaInfo & info ); 00488 00496 void setFileMode( mode_t m ); 00497 00503 void setMimeType( const QString& mimetype ); 00504 00510 const KFileMetaInfo & metaInfo(bool autoget = true, 00511 int what = KFileMetaInfo::Fastest) const; 00512 00520 void assign( const KFileItem & item ); 00521 00539 void setUDSEntry( const KIO::UDSEntry& entry, const KURL& url, 00540 bool determineMimeTypeOnDemand = false, 00541 bool urlIsDirectory = false ); 00542 00546 KFileItem& operator=( const KFileItem& ); 00547 00552 KURL mostLocalURL(bool &local) const; 00553 00555 00556 protected: 00561 void init( bool _determineMimeTypeOnDemand ); 00562 00568 void readUDSEntry( bool _urlIsDirectory ); 00569 00573 QString parsePermissions( mode_t perm ) const; 00574 00575 private: 00579 KIO::UDSEntry m_entry; 00583 KURL m_url; 00584 00588 QString m_strName; 00589 00594 QString m_strText; 00595 00599 mutable QString m_user, m_group; 00600 00604 mutable QString m_strLowerCaseName; 00605 00609 KMimeType::Ptr m_pMimeType; 00610 00614 mode_t m_fileMode; 00618 mode_t m_permissions; 00619 00623 bool m_bMarked:1; 00627 bool m_bLink:1; 00631 bool m_bIsLocalURL:1; 00632 00633 bool m_bMimeTypeKnown:1; 00634 00635 // Auto: check leading dot. 00636 enum { Auto, Hidden, Shown } m_hidden:3; 00637 00638 // For special case like link to dirs over FTP 00639 QString m_guessedMimeType; 00640 mutable QString m_access; 00641 QMap<const void*, void*> m_extra; 00642 mutable KFileMetaInfo m_metaInfo; 00643 00644 enum { Modification = 0, Access = 1, Creation = 2, NumFlags = 3 }; 00645 mutable time_t m_time[3]; 00646 mutable KIO::filesize_t m_size; 00647 00648 protected: 00649 virtual void virtual_hook( int id, void* data ); 00650 private: 00651 class KFileItemPrivate; 00652 KFileItemPrivate * d; 00653 KIO_EXPORT friend QDataStream & operator<< ( QDataStream & s, const KFileItem & a ); 00654 KIO_EXPORT friend QDataStream & operator>> ( QDataStream & s, KFileItem & a ); 00655 }; 00656 00660 typedef QPtrList<KFileItem> KFileItemList; 00661 00665 typedef QPtrListIterator<KFileItem> KFileItemListIterator; 00666 00667 KIO_EXPORT QDataStream & operator<< ( QDataStream & s, const KFileItem & a ); 00668 KIO_EXPORT QDataStream & operator>> ( QDataStream & s, KFileItem & a ); 00669 00670 00671 #endif