Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KFileItem (./kdelibs/kio/kfileitem.h:38)
class KFileItem
{
public:
/**
* Create an item representing a file, from an UDSEntry (see kio/global.h)
* This is the preferred constructor when using KIO::listDir().
*
* @param _entry the KIO entry used to get the file, contains info about it
* @param _url the file url
* @param _determineMimeTypeOnDemand specify if the mimetype of the given URL
* should be determined immediately or on demand
*/
KFileItem( const KIO::UDSEntry& _entry, KURL& _url, bool _determineMimeTypeOnDemand = false );
/**
* Create an item representing a file, from all the necessary info for it
* @param _mode the file mode (according to stat())
* Set to -1 if unknown. For local files, KFileItem will use stat().
* @param _mode the mode (S_IFDIR...)
* @param _permissions the access permissions
* If you set both the mode and the permissions, you save a ::stat() for
* local files
* Set to -1 if you don't know the mode or the permission.
* @param _url the file url
*
* @param _determineMimeTypeOnDemand specify if the mimetype of the given URL
* should be determined immediately or on demand
*/
KFileItem( mode_t _mode, mode_t _permissions, const KURL& _url, bool _determineMimeTypeOnDemand = false );
/**
* Create an item representing a file, for which the mimetype is already known
* @param url the file url
* @param mimeType the name of the file's mimetype
* @param mode the mode (S_IFDIR...)
*/
KFileItem( const KURL &url, const QString &mimeType, mode_t mode );
/**
* Destructor
*/
~KFileItem() { }
/**
* Re-read information (currently only permissions and mimetype)
* This is called when the _file_ changes
*/
void refresh();
/**
* Re-read mimetype information
* This is called when the mimetype database changes
*/
void refreshMimeType();
/**
* @return the url of the file
*/
const KURL & url() const { return m_url; }
/**
* @return the permissions of the file (stat.st_mode containing only permissions)
*/
mode_t permissions() const { return m_permissions; }
/**
* @return the file type (stat.st_mode containing only S_IFDIR, S_IFLNK, ...)
*/
mode_t mode() const { return m_fileMode; }
/**
* @return the owner of the file.
*/
QString user() const { return m_user; }
/**
* @return the group of the file.
*/
QString group() const { return m_group; }
/**
* @return true if this icons represents a link in the UNIX sense of
* a link. If yes, then we have to draw the label with an italic font.
*/
bool isLink() const { return m_bLink; }
/**
* @return the link destination if isLink() == true
*/
QString linkDest() const;
/**
* @return the size of the file, if known
*/
long size() const;
/**
* @param which UDS_MODIFICATION_TIME, UDS_ACCESS_TIME or even UDS_CREATION_TIME
* @return the time asked for
*/
time_t time( unsigned int which ) const;
/**
* @return true if the file is a local file
*/
bool isLocalFile() const { return m_bIsLocalURL; }
/**
* @return the text of the file item
* It's not exactly the filename since some decoding happens ('%2F'->'/')
*/
QString text() const { return m_strText; }
/**
* @return the mimetype of the file item
*/
QString mimetype() const;
/**
* @return the mimetype of the file item
* If determineMimeTypeOnDemand was used, this will determine the mimetype first.
*/
KMimeType::Ptr determineMimeType();
/**
* @return the currently-known mmietype of the file item
* This will not try to determine the mimetype if unknown.
*/
KMimeType::Ptr mimeTypePtr();
/**
* @return the descriptive comment for this mime type, or
* the mime type itself if none is present.
*/
QString mimeComment();
/**
* @return the full path name to the icon that represents
* this mime type.
*/
QString iconName();
/**
* @return the UDS entry. Used by the tree view to access all details
* by position.
*/
const KIO::UDSEntry & entry() const { return m_entry; }
// Used when updating a directory - marked == seen when refreshing
bool isMarked() const { return m_bMarked; }
void mark() { m_bMarked = true; }
void unmark() { m_bMarked = false; }
/////////////
protected:
/**
* Computes the text, mode, and mimetype from the UDSEntry
* Called by constructor, but can be called again later
*/
void init( bool _determineMimeTypeOnDemand );
/**
* We keep a copy of the UDSEntry since we need it for @ref #getStatusBarInfo
*/
KIO::UDSEntry m_entry;
/**
* The url of the file
*/
KURL m_url;
/**
* True if local file
*/
bool m_bIsLocalURL;
/**
* The text for this item, i.e. the file name without path
*/
QString m_strText;
/**
* The file mode
*/
mode_t m_fileMode;
/**
* The permissions
*/
mode_t m_permissions;
/**
* the user and group assigned to the file.
*/
QString m_user, m_group;
/**
* Whether the file is a link
*/
bool m_bLink;
/**
* The mimetype of the file
*/
KMimeType::Ptr m_pMimeType;
private:
/**
* Marked : see @ref #mark()
*/
bool m_bMarked;
};
/**
* List of KFileItems
*/
kdelibs'KFileItem::KFileItem() (./kdelibs/kio/kfileitem.cpp:37)
KFileItem::KFileItem( const KIO::UDSEntry& _entry, KURL& _url, bool _determineMimeTypeOnDemand ) :
m_entry( _entry ),
m_url( _url ),
m_bIsLocalURL( _url.isLocalFile() ),
m_fileMode( (mode_t)-1 ),
m_permissions( (mode_t)-1 ),
m_bLink( false ),
m_pMimeType( 0 ),
m_bMarked( false )
{
// extract the mode and the filename from the KIO::UDS Entry
KIO::UDSEntry::ConstIterator it = m_entry.begin();
for( ; it != m_entry.end(); it++ ) {
switch ((*it).m_uds) {
case KIO::UDS_FILE_TYPE:
m_fileMode = (mode_t)((*it).m_long);
break;
case KIO::UDS_ACCESS:
m_permissions = (mode_t)((*it).m_long);
break;
case KIO::UDS_USER:
m_user = ((*it).m_str);
break;
case KIO::UDS_GROUP:
m_group = ((*it).m_str);
break;
case KIO::UDS_NAME:
m_strText = KIO::decodeFileName( (*it).m_str );
break;
case KIO::UDS_URL:
m_url = KURL((*it).m_str);
break;
case KIO::UDS_MIME_TYPE:
m_pMimeType = KMimeType::mimeType((*it).m_str);
break;
case KIO::UDS_LINK_DEST:
m_bLink = !(*it).m_str.isEmpty(); // we don't store the link dest
break;
}
}
init( _determineMimeTypeOnDemand );
}
kdelibs'KFileItem::KFileItem() (./kdelibs/kio/kfileitem.cpp:88)
KFileItem::KFileItem( mode_t _mode, mode_t _permissions, const KURL& _url, bool _determineMimeTypeOnDemand ) :
m_entry(), // warning !
m_url( _url ),
m_bIsLocalURL( _url.isLocalFile() ),
m_strText( KIO::decodeFileName( _url.filename() ) ),
m_fileMode ( _mode ),
m_permissions( _permissions ),
m_bLink( false ),
m_bMarked( false )
{
init( _determineMimeTypeOnDemand );
}
kdelibs'KFileItem::KFileItem() (./kdelibs/kio/kfileitem.cpp:101)
KFileItem::KFileItem( const KURL &url, const QString &mimeType, mode_t mode )
: m_url( url ),
m_bIsLocalURL( url.isLocalFile() ),
m_strText( KIO::decodeFileName( url.filename() ) ),
m_fileMode( mode ),
m_permissions( 0 ),
m_bLink( false ),
m_bMarked( false )
{
m_pMimeType = KMimeType::mimeType( mimeType );
init( false );
}
kdelibs'KFileItem::init() (./kdelibs/kio/kfileitem.cpp:114)
void KFileItem::init( bool _determineMimeTypeOnDemand )
{
// determine mode and/or permissions if unknown
if ( m_fileMode == (mode_t) -1 || m_permissions == (mode_t) -1 )
{
mode_t mode = 0;
if ( m_url.isLocalFile() )
{
/* directories may not have a slash at the end if
* we want to stat() them; it requires that we
* change into it .. which may not be allowed
* stat("/is/unaccessible") -> rwx------
* stat("/is/unaccessible/") -> EPERM H.Z.
* This is the reason for the -1
*/
struct stat buf;
lstat( m_url.path( -1 ), &buf );
mode = buf.st_mode;
if ( S_ISLNK( mode ) )
{
m_bLink = true;
stat( m_url.path( -1 ), &buf );
mode = buf.st_mode;
}
}
if ( m_fileMode == (mode_t) -1 )
m_fileMode = mode & S_IFMT; // extract file type
if ( m_permissions == (mode_t) -1 )
m_permissions = mode & 07777; // extract permissions
}
// determine the mimetype
if (!m_pMimeType && !_determineMimeTypeOnDemand )
m_pMimeType = KMimeType::findByURL( m_url, m_fileMode, m_bIsLocalURL );
// assert (m_pMimeType);
}
kdelibs'KFileItem::refresh() (./kdelibs/kio/kfileitem.cpp:153)
void KFileItem::refresh()
{
m_fileMode = (mode_t)-1;
m_permissions = (mode_t)-1;
init( false );
}
kdelibs'KFileItem::refreshMimeType() (./kdelibs/kio/kfileitem.cpp:160)
void KFileItem::refreshMimeType()
{
m_pMimeType = 0L;
init( false ); // Will determine the mimetype
}
kdelibs'KFileItem::linkDest() (./kdelibs/kio/kfileitem.cpp:166)
QString KFileItem::linkDest() const
{
// Extract it from the KIO::UDSEntry
KIO::UDSEntry::ConstIterator it = m_entry.begin();
for( ; it != m_entry.end(); it++ )
if ( (*it).m_uds == KIO::UDS_LINK_DEST )
return (*it).m_str;
// If not in the KIO::UDSEntry, or if UDSEntry empty, use readlink() [if local URL]
if ( m_bIsLocalURL )
{
char buf[1000];
int n = readlink( m_url.path( -1 ), buf, 1000 );
if ( n != -1 )
{
buf[ n ] = 0;
return QString( buf );
}
}
return QString::null;
}
kdelibs'KFileItem::size() (./kdelibs/kio/kfileitem.cpp:187)
long KFileItem::size() const
{
// Extract it from the KIO::UDSEntry
KIO::UDSEntry::ConstIterator it = m_entry.begin();
for( ; it != m_entry.end(); it++ )
if ( (*it).m_uds == KIO::UDS_SIZE )
return (*it).m_long;
// If not in the KIO::UDSEntry, or if UDSEntry empty, use stat() [if local URL]
if ( m_bIsLocalURL )
{
struct stat buf;
stat( m_url.path( -1 ), &buf );
return buf.st_size;
}
return 0L;
}
kdelibs'KFileItem::time() (./kdelibs/kio/kfileitem.cpp:204)
time_t KFileItem::time( unsigned int which ) const
{
// Extract it from the KIO::UDSEntry
KIO::UDSEntry::ConstIterator it = m_entry.begin();
for( ; it != m_entry.end(); it++ )
if ( (*it).m_uds == which )
return static_cast<time_t>((*it).m_long);
// If not in the KIO::UDSEntry, or if UDSEntry empty, use stat() [if local URL]
if ( m_bIsLocalURL )
{
struct stat buf;
stat( m_url.path( -1 ), &buf );
return (which == KIO::UDS_MODIFICATION_TIME) ? buf.st_mtime :
(which == KIO::UDS_ACCESS_TIME) ? buf.st_atime :
(which == KIO::UDS_CREATION_TIME) ? buf.st_ctime :
static_cast<time_t>(0);
}
return static_cast<time_t>(0);
}
kdelibs'KFileItem::mimetype() (./kdelibs/kio/kfileitem.cpp:225)
QString KFileItem::mimetype() const
{
KFileItem * that = const_cast<KFileItem *>(this);
return that->determineMimeType()->name();
}
KMimeType::Ptr KFileItem::determineMimeType()
{
if ( !m_pMimeType )
{
//kdDebug(1203) << "finding mimetype for " << m_url.url() << endl;
m_pMimeType = KMimeType::findByURL( m_url, m_fileMode, m_bIsLocalURL );
}
return m_pMimeType;
}
kdelibs'KFileItem::mimeComment() (./kdelibs/kio/kfileitem.cpp:242)
QString KFileItem::mimeComment()
{
KMimeType::Ptr mType = determineMimeType();
QString comment = mType->comment( m_url, false );
if (!comment.isEmpty())
return comment;
else
return mType->name();
}
kdelibs'KFileItem::iconName() (./kdelibs/kio/kfileitem.cpp:252)
QString KFileItem::iconName()
{
return determineMimeType()->icon(m_url, false);
}