class KFileItem

# class KFileItem | A KFileItem is a generic class to handle a file, local or remote. More...
Definition | `#include <kfileitem.h>`
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Types

- enum { Unknown = (mode_t) - 1 }

#### Public Methods

- KFileItem ( const KIO::UDSEntry& _entry, const KURL& _url, bool _determineMimeTypeOnDemand = false, bool _urlIsDirectory = false )
- KFileItem ( mode_t _mode, mode_t _permissions, const KURL& _url, bool _determineMimeTypeOnDemand = false )
- KFileItem ( const KURL &url, const QString &mimeType, mode_t mode )
- KFileItem ( const KFileItem &item )
- virtual ~KFileItem ()
- void refresh ()
- void refreshMimeType ()
- const KURL & url () const
- void setURL ( const KURL &url )
- mode_t permissions () const
- QString permissionsString () const
- mode_t mode () const
- QString user () const
- QString group () const
- bool isLink () const
- bool isDir () const
- bool isFile () const
- bool isReadable () const
- QString linkDest () const
- KIO::filesize_t size () const
- time_t time ( unsigned int which ) const
- QString timeString ( unsigned int which = KIO::UDS_MODIFICATION_TIME ) const
- bool isLocalFile () const
- const QString& text () const
- const QString& name ( bool lowerCase = false ) const
- QString mimetype () const
- KMimeType::Ptr determineMimeType ()
- KMimeType::Ptr mimeTypePtr () const
- bool isMimeTypeKnown () const
- QString mimeComment ()
- QString iconName ()
- QPixmap pixmap ( int _size, int _state=0 ) const
- int overlays () const
- QString getStatusBarInfo ()
- QString getToolTipText (int maxcount = 6)
- bool acceptsDrops ( )
- void run ()
- const KIO::UDSEntry & entry () const
- bool isMarked () const
- void mark ()
- void unmark ()
- bool cmp ( const KFileItem & item )
- virtual void setExtraData ( const void *key, void *value )
- virtual const void * extraData ( const void *key ) const
- virtual void * extraData ( const void *key )
- virtual void removeExtraData ( const void *key )
- void setMetaInfo ( const KFileMetaInfo & info )
- const KFileMetaInfo & metaInfo (bool autoget = true, int what = KFileMetaInfo::Fastest) const
- void assign ( const KFileItem & item )

#### Protected Methods

- void init ( bool _determineMimeTypeOnDemand )
- QString parsePermissions ( mode_t perm ) const
- virtual void virtual_hook ( int id, void* data )

## Detailed Description

A KFileItem is a generic class to handle a file, local or remote. In particular, it makes it easier to handle the result of KIO::listDir. (UDSEntry isn't very friendly to use) It includes many file attributes such as mimetype, icon, text, mode, link...

enum { Unknown = (mode_t) - 1 } | ###

KFileItem ( const KIO::UDSEntry& _entry, const KURL& _url, bool _determineMimeTypeOnDemand = false, bool _urlIsDirectory = false ) | ### KFileItem

Creates an item representing a file, from a UDSEntry. This is the preferred constructor when using KIO::listDir().

Parameters:

_entry | the KIO entry used to get the file, contains info about it
_url | the file url
_determineMimeTypeOnDemand | specifies if the mimetype of the given URL should be determined immediately or on demand
_urlIsDirectory | specifies if the url is just the directory of the fileitem and the filename from the UDSEntry should be used.

KFileItem ( mode_t _mode, mode_t _permissions, const KURL& _url, bool _determineMimeTypeOnDemand = false ) | ### KFileItem

Creates an item representing a file, from all the necessary info for it.

Parameters:

_mode | the file mode (according to stat() (e.g. S_IFDIR...) Set to KFileItem::Unknown if unknown. For local files, KFileItem will use stat().
_permissions | the access permissions If you set both the mode and the permissions, you save a ::stat() for local files. Set to KFileItem::Unknown if you don't know the mode or the permission.
_url | the file url
_determineMimeTypeOnDemand | specify if the mimetype of the given URL should be determined immediately or on demand

KFileItem ( const KURL &url, const QString &mimeType, mode_t mode ) | ### KFileItem

Creates an item representing a file, for which the mimetype is already known.

Parameters:

url | the file url
mimeType | the name of the file's mimetype
mode | the mode (S_IFDIR...)

KFileItem ( const KFileItem &item ) | ### KFileItem

Copy constructor. Note that extra-data set via setExtraData() is not deeply copied -- just the pointers are copied.

~KFileItem () | ### ~KFileItem

[virtual]

Destructs the KFileItem. Extra data set via setExtraData() is not deleted.

void refresh () | ### refresh

Re-reads information (currently only permissions and mimetype). This is called when the _file_ changes.

void refreshMimeType () | ### refreshMimeType

Re-reads mimetype information. This is called when the mimetype database changes.

const KURL & url () | ### url

[const]

Returns the url of the file.

void setURL ( const KURL &url ) | ### setURL

Sets the item's URL. Do not call unless you know what you are doing! (used for example when an item got renamed).

mode_t permissions () | ### permissions

[const]

Returns the permissions of the file (stat.st_mode containing only permissions).

QString permissionsString () | ### permissionsString

[const]

Returns the access permissions for the file as a string.

mode_t mode () | ### mode

[const]

Returns the file type (stat.st_mode containing only S_IFDIR, S_IFLNK, ...).

QString user () | ### user

[const]

Returns the owner of the file.

QString group () | ### group

[const]

Returns the group of the file.

bool isLink () | ### isLink

[const]

Returns true if this item represents a link in the UNIX sense of a link.

bool isDir () | ### isDir

[const]

Returns true if this item represents a directory.

bool isFile () | ### isFile

[const]

Returns true if this item represents a file (and not a a directory)

bool isReadable () | ### isReadable

[const]

Returns: true if the file can be read - more precisely, returns false if we know for sure it can't. In some cases (remote files), we may return true even though it can't be read.

QString linkDest () | ### linkDest

[const]

Returns the link destination if isLink() == true.

KIO::filesize_t size () | ### size

[const]

Returns the size of the file, if known.

time_t time ( unsigned int which ) | ### time

[const]

Parameters:

which | UDS_MODIFICATION_TIME, UDS_ACCESS_TIME or even UDS_CREATION_TIME

Returns: the time asked for, (time_t)0 if not available

See also: timeString

QString timeString ( unsigned int which = KIO::UDS_MODIFICATION_TIME ) | ### timeString

[const]

Parameters:

which | UDS_MODIFICATION_TIME, UDS_ACCESS_TIME or even UDS_CREATION_TIME

Returns: a formatted string of the requested time.

See also: time

bool isLocalFile () | ### isLocalFile

[const]

Returns true if the file is a local file.

const QString& text () | ### text

[const]

Returns the text of the file item. It's not exactly the filename since some decoding happens ('%2F'->'/').

const QString& name ( bool lowerCase = false ) | ### name

[const]

Returns: the name of the file item (without a path) Similar to text(), but unencoded, i.e. the original name If `lowerCase` is true, the name will be returned in lower case, which is useful to speed up sorting by name, case insensitively.

QString mimetype () | ### mimetype

[const]

Returns the mimetype of the file item. If determineMimeTypeOnDemand was used, this will determine the mimetype first. Equivalent to determineMimeType()->name()

KMimeType::Ptr determineMimeType () | ### determineMimeType

Returns the mimetype of the file item. If determineMimeTypeOnDemand was used, this will determine the mimetype first.

KMimeType::Ptr mimeTypePtr () | ### mimeTypePtr

[const]

Returns the currently known mimetype of the file item. This will not try to determine the mimetype if unknown.

bool isMimeTypeKnown () | ### isMimeTypeKnown

[const]

QString mimeComment () | ### mimeComment

Returns the descriptive comment for this mime type, or the mime type itself if none is present.

QString iconName () | ### iconName

Returns the full path name to the icon that represents this mime type.

QPixmap pixmap ( int _size, int _state=0 ) | ### pixmap

[const]

Returns a pixmap representing the file.

Parameters:

_size | Size for the pixmap in pixels. Zero will return the globally configured default size.
_state | The state of the icon: KIcon::DefaultState, KIcon::ActiveState or KIcon::DisabledState.

Returns: the pixmap

int overlays () | ### overlays

[const]

Returns the overlays (bitfield of KIcon::*Overlay flags) that are used for this item's pixmap.

QString getStatusBarInfo () | ### getStatusBarInfo

Returns the string to be displayed in the statusbar, e.g. when the mouse is over this item

QString getToolTipText (int maxcount = 6) | ### getToolTipText

Parameters:

maxcount | the maximum number of entries shown

Returns: the string to be displayed in the tool tip when the mouse is over this item. This may load a plugin to determine additional information specific to the mimetype of the file

bool acceptsDrops ( ) | ### acceptsDrops

Returns true if files can be dropped over this item. Contrary to popular belief, not only dirs will return true :) Executables, .desktop files, will do so as well.

void run () | ### run

Let's "KRun" this file ! (e.g. when file is clicked or double-clicked or return is pressed)

const KIO::UDSEntry & entry () | ### entry

[const]

Returns the UDS entry. Used by the tree view to access all details by position.

bool isMarked () | ### isMarked

[const]

void mark () | ### mark

void unmark () | ### unmark

bool cmp ( const KFileItem & item ) | ### cmp

Somewhat like a comparison operator, but more explicit

void setExtraData ( const void *key, void *value ) | ### setExtraData

[virtual]

This allows to associate some "extra" data to a KFileItem. As one KFileItem can be used by several objects (often views) which all need to add some data, you have to use a key to reference your extra data within the KFileItem.

That way a KFileItem can hold and provide access to all those views separately.

I.e. a KFileIconView that associates a KFileIconViewItem (an item suitable for use with QIconView) does

     kfileItem->setExtraData( this, iconViewItem );

and can later access the iconViewItem by doing

     KFileIconViewItem *iconViewItem = static_cast( kfileItem->extraData( this ));

This is usually more efficient then having every view associate data to items by using a separate QDict or QMap.

Note: you have to remove and destroy the data you associated yourself when you don't need it anymore!

See also: extraData, removeExtraData

const void * extraData ( const void *key ) | ### extraData

[const virtual]

Returns: the extra data associated to an item with `key` via setExtraData. Returns 0L if nothing was associated with `key`.

See also: extraData

void * extraData ( const void *key ) | ### extraData

[virtual]

The non-const version of the previous `extraData`() method.

void removeExtraData ( const void *key ) | ### removeExtraData

[virtual]

Removes the extra data associated with an item via `key`.

void setMetaInfo ( const KFileMetaInfo & info ) | ### setMetaInfo

Sets the metainfo of this item to `info`.

const KFileMetaInfo & metaInfo (bool autoget = true, int what = KFileMetaInfo::Fastest) | ### metaInfo

[const]

Returns the metainfo of this item. If `autoget` is true, it will automatically be created

void assign ( const KFileItem & item ) | ### assign

Somewhat like an assignment operator, but more explicit. Note: extra-data set with setExtraData() is not copied, so be careful what you do!

I.e. KDirLister uses it to update existing items from a fresh item.

void init ( bool _determineMimeTypeOnDemand ) | ### init

[protected]

Computes the text, mode, and mimetype from the UDSEntry Called by constructor, but can be called again later

QString parsePermissions ( mode_t perm ) | ### parsePermissions

[protected const]

Parses the given permission set and provides it for access()

void virtual_hook ( int id, void* data ) | ### virtual_hook

[protected virtual]

Generated by: root on macppc.ports.openbsd.org on Sat Sep 6 10:36:57 2003, using kdoc 2.0a54.