# class KFileItem

###

Module | kio
Namespace |
Class | KFileItem
Inherits |

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...

KFileItem is implicitly shared, i.e. it can be used as a value and copied around at almost no cost.

### enums

- FileTimes { ModificationTime, AccessTime, CreationTime }
- anonymous { Unknown }

enum details

### methods

- ACL ( )

  returns KACL

  Returns the access control list for the file. Returns the access control list as a KACL

- KFileItem ( )

  returns ctor

  Null KFileItem. Doesn't represent any file, only exists for convenience.

  NOTE KDE 4.0 when porting from KFileItem* to KFileItem&: '(KFileItem*)a==0' becomes '(KFileItem)a.isNull()'

- KFileItem (entry, directoryUrl, delayedMimeTypes, urlIsDirectory)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  entry | KIO.UDSEntry |
  directoryUrl | KUrl |
  delayedMimeTypes | bool | 0
  urlIsDirectory | bool | 0

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

  entry - the KIO entry used to get the file, contains info about it

  directoryUrl - the URL of the directory containing this item. This is the URL that was passed to the KIO list job which emitted this UDSEntry.

  delayedMimeTypes - specifies if the mimetype of the given URL should be determined immediately or on demand. See the bool delayedMimeTypes in the KDirLister constructor.

  urlIsDirectory - specifies if the url is just the directory of the fileitem and the filename from the UDSEntry should be used.

- KFileItem (mode, permissions, url, delayedMimeTypes)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  mode | mode_t |
  permissions | mode_t |
  url | KUrl |
  delayedMimeTypes | bool | 0

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

  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

  delayedMimeTypes - specify if the mimetype of the given URL should be determined immediately or on demand

- KFileItem (url, mimeType, mode)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  mimeType | QString |
  mode | mode_t |

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

  url - the file url

  mimeType - the name of the file's mimetype

  mode - the mode (S_IFDIR...)

- KFileItem (other)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  other | KFileItem |

  Copy constructor

- acceptsDrops ( )

  returns bool

  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. Returns true if you can drop files over the item

  Deprecated This logic is application-dependent, the behavior described above mostly makes sense for file managers only. KDirModel has setDropsAllowed for similar (but configurable) logic.

- assign (item)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  item | KFileItem |

  Deprecated simply use '='

- cmp (item)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  item | KFileItem |

  Somewhat like a comparison operator, but more explicit, and it can detect that two kfileitems are equal even when they do not share the same internal pointer - e.g. when KDirLister compares fileitems after listing a directory again, to detect changes.

  item - the item to compare Returns true if all values are equal

- defaultACL ( )

  returns KACL

  Returns the default access control list for the directory. Returns the default access control list as a KACL

- determineMimeType ( )

  returns KMimeType.Ptr

  Returns the mimetype of the file item. If delayedMimeTypes was used in the constructor, this will determine the mimetype first. Returns the mime type

- entry ( )

  returns KIO.UDSEntry

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

- extraData (key)

  returns void
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  key | void |

  Retrieves the extra data with the given key.

  key - the key of the extra data Returns the extra data associated to an item with key via setExtraData. 0 if nothing was associated with key.

  See also extraData

  Deprecated use model/view (KDirModel) and you won't need this anymore

- getStatusBarInfo ( )

  returns QString

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

- getToolTipText (maxcount)

  returns QString

  Argument | Type | Default
  --- | --- | ---
  maxcount | int | 6

  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.

  maxcount - the maximum number of entries shown Returns the tool tip string

- group ( )

  returns QString

  Returns the group of the file. Returns the file's group

- hasExtendedACL ( )

  returns bool

  Tells if the file has extended access level information ( Posix ACL ) Returns true if the file has extend ACL information or false if it hasn't

- iconName ( )

  returns QString

  Returns the full path name to the icon that represents this mime type. Returns iconName the name of the file's icon

- isDesktopFile ( )

  returns bool
  KDE 4.1.0 and later only

  Checks whether the file is a readable local .desktop file, i.e. a file whose path can be given to KDesktopFile Returns true if the file is a desktop file. @since 4.1

- isDir ( )

  returns bool

  Returns true if this item represents a directory. Returns true if the item is a directory

- isFile ( )

  returns bool

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

- isHidden ( )

  returns bool

  Checks whether the file is hidden. Returns true if the file is hidden.

- isLink ( )

  returns bool

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

- isLocalFile ( )

  returns bool

  Returns true if the file is a local file. Returns true if the file is local, false otherwise

- isMarked ( )

  returns bool

  Used when updating a directory. marked == seen when refreshing. Returns true if the file item is marked

- isMimeTypeKnown ( )

  returns bool

  Returns true if we have determined the mimetype of this file already, i.e. if determineMimeType() will be fast. Otherwise it will have to find what the mimetype is, which is a possibly slow operation; usually this is delayed until necessary.

- isNull ( )

  returns bool

  Return true if default-constructed

- isReadable ( )

  returns bool

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

- isWritable ( )

  returns bool

  Checks whether the file or directory is writable. In some cases (remote files), we may return true even though it can't be written to. Returns true if the file or directory can be written to - more precisely, false if we know for sure it can't

- linkDest ( )

  returns QString

  Returns the link destination if isLink() == true. Returns the link destination. QString() if the item is not a link

- localPath ( )

  returns QString

  Returns the local path if isLocalFile() == true or the KIO item has a UDS_LOCAL_PATH atom. Returns the item local path, or QString() if not known

- mark ( )

  returns Nothing

  Marks the item.

  See also isMarked()

- metaInfo (autoget, what)

  returns KFileMetaInfo

  Argument | Type | Default
  --- | --- | ---
  autoget | bool | 1
  what | int | KFileMetaInfo.Fastest

  Returns the metainfo of this item.

  autoget - if true, the metainfo will automatically be created

  what - ignored

- mimeComment ( )

  returns QString

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

- mimeTypePtr ( )

  returns KMimeType.Ptr

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

- mimetype ( )

  returns QString

  Returns the mimetype of the file item. If delayedMimeTypes was used in the constructor, this will determine the mimetype first. Equivalent to determineMimeType()->name() Returns the mime type of the file

- mode ( )

  returns mode_t

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

- mostLocalUrl ()

  returns KUrl, bool (local)

  Argument | Type | Default
  --- | --- | ---

  Tries to give a local URL for this file item if possible. The given boolean indicates if the returned url is local or not.

- name (lowerCase)

  returns QString

  Argument | Type | Default
  --- | --- | ---
  lowerCase | bool | 0

  Return the name of the file item (without a path). Similar to text(), but unencoded, i.e. the original name.

  lowerCase - if true, the name will be returned in lower case, which is useful to speed up sorting by name, case insensitively. Returns the file's name

- operator != (other)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  other | KFileItem |

- operator == (other)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  other | KFileItem |

- overlays ( )

  returns QStringList

  Returns the overlays (bitfield of KIconLoader.*Overlay flags) that are used for this item's pixmap. Overlays are used to show for example, whether a file can be modified. Returns the overlays of the pixmap

- permissions ( )

  returns mode_t

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

- permissionsString ( )

  returns QString

  Returns the access permissions for the file as a string. Returns the access persmission as string

- pixmap (_size, _state)

  returns QPixmap

  Argument | Type | Default
  --- | --- | ---
  _size | int |
  _state | int | 0

  Returns a pixmap representing the file.

  _size - Size for the pixmap in pixels. Zero will return the globally configured default size.

  _state - The state of the icon: KIconLoader.DefaultState, KIconLoader.ActiveState or KIconLoader.DisabledState. Returns the pixmap

- refresh ( )

  returns Nothing

  Throw away and re-read (for local files) all information about the file. This is called when the _file_ changes.

- refreshMimeType ( )

  returns Nothing

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

- removeExtraData (key)

  returns Nothing
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  key | void |

  Removes the extra data associated with an item via key.

  key - the key of the extra data to remove

  Deprecated use model/view (KDirModel) and you won't need this anymore

- run (parentWidget)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  parentWidget | QWidget | 0

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

- setExtraData (key, value)

  returns Nothing
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  key | void |
  value | void |

  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<KFileIconViewItem*>( 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!

  key - the key of the extra data

  value - the value of the extra data

  See also extraData

  See also removeExtraData

  Deprecated use model/view (KDirModel) and you won't need this anymore

- setMetaInfo (info)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  info | KFileMetaInfo |

  Sets the metainfo of this item to info.

  Made const to avoid deep copy.

  info - the new meta info

- setName (name)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  name | QString |

  Sets the item's name (i.e. the filename). This is automatically done by setUrl, to set the name from the URL's fileName(). This method is provided for some special cases like relative paths as names (KFindPart)

  name - the item's name

- setUDSEntry (entry, url, delayedMimeTypes, urlIsDirectory)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  entry | KIO.UDSEntry |
  url | KUrl |
  delayedMimeTypes | bool | 0
  urlIsDirectory | bool | 0

  Reinitialize KFileItem with a new UDSEntry.

  Note: extra-data set with setExtraData() is not changed or deleted, so be careful what you do!

  KDirListerCache uses it to save new/delete calls by updating existing items that are otherwise not needed anymore.

  entry - the UDSEntry to assign to this KFileItem

  url - the file url

  delayedMimeTypes - 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.

  Deprecated why not just create another KFileItem and use operator=, now that it's a value class?

- setUrl (url)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |

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

  url - the item's URL

- size ( )

  returns KIO.filesize_t

  Returns the size of the file, if known. Returns the file size, or 0 if not known

- targetUrl ( )

  returns KUrl
  KDE 4.1.0 and later only

  Returns the target url of the file, which is the same as url() in cases where the slave doesn't specify UDS_TARGET_URL Returns the target url. @since 4.1

- text ( )

  returns QString

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

- time (which)

  returns KDateTime

  Argument | Type | Default
  --- | --- | ---
  which | KFileItem.FileTimes |

  Requests the modification, access or creation time, depending on which.

  which - the timestamp Returns the time asked for, 0 if not available

  See also timeString()

- time (which)

  returns time_t

  Argument | Type | Default
  --- | --- | ---
  which | unsigned int |

- timeString (which)

  returns QString

  Argument | Type | Default
  --- | --- | ---
  which | KFileItem.FileTimes | KFileItem.ModificationTime

  Requests the modification, access or creation time as a string, depending on which.

  which - the timestamp Returns a formatted string of the requested time.

  See also time

- timeString (which)

  returns QString

  Argument | Type | Default
  --- | --- | ---
  which | unsigned int |

- unmark ( )

  returns Nothing

  Unmarks the item.

  See also isMarked()

- url ( )

  returns KUrl

  Returns the url of the file. Returns the url of the file

- user ( )

  returns QString

  Returns the owner of the file. Returns the file's owner

### enums - detail

- FileTimes { ModificationTime, AccessTime, CreationTime }

  The timestamps associated with a file. - ModificationTime: the time the file's contents were last modified - AccessTime: the time the file was last accessed (last read or written to) - CreationTime: the time the file was created

  | ModificationTime | - 0 | - |
  | AccessTime | - 1 | - |
  | CreationTime | - 2 | - |

- anonymous { Unknown }

  | Unknown | - (mode_t)-1 | - |