KDE 4.5 PyKDE API Reference

- KDE's Python API

# KFileItem Class Reference

`from PyKDE4.kio import *`

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

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

## Enumerations
<anonymous> | { Unknown }
FileTimes | { ModificationTime, AccessTime, CreationTime }
## Methods
| __init__ (self)
| __init__ (self, KIO.UDSEntry entry, KUrl itemOrDirUrl, bool delayedMimeTypes=0, bool urlIsDirectory=0)
| __init__ (self, long mode, long permissions, KUrl url, bool delayedMimeTypes=0)
| __init__ (self, KUrl url, QString mimeType, long mode)
| __init__ (self, KFileItem other)
KACL | ACL (self)
bool | acceptsDrops (self)
| assign (self, KFileItem item)
bool | cmp (self, KFileItem item)
KACL | defaultACL (self)
KSharedPtr | determineMimeType (self)
KIO.UDSEntry | entry (self)
QString | getStatusBarInfo (self)
QString | getToolTipText (self, int maxcount=6)
QString | group (self)
bool | hasExtendedACL (self)
QString | iconName (self)
bool | isDesktopFile (self)
bool | isDir (self)
bool | isFile (self)
bool | isHidden (self)
bool | isLink (self)
bool | isLocalFile (self)
bool | isMarked (self)
bool | isMimeTypeKnown (self)
bool | isNull (self)
bool | isReadable (self)
bool | isRegularFile (self)
bool | isWritable (self)
QString | linkDest (self)
QString | localPath (self)
| mark (self)
KFileMetaInfo | metaInfo (self, bool autoget=1, int what=KFileMetaInfo.Fastest)
QString | mimeComment (self)
KSharedPtr | mimeTypePtr (self)
QString | mimetype (self)
long | mode (self)
KUrl, bool local | mostLocalUrl (self)
QString | name (self, bool lowerCase=0)
KUrl | nepomukUri (self)
bool | operator != (self, KFileItem other)
bool | operator == (self, KFileItem other)
QStringList | overlays (self)
long | permissions (self)
QString | permissionsString (self)
QPixmap | pixmap (self, int _size, int _state=0)
| refresh (self)
| refreshMimeType (self)
| run (self, QWidget parentWidget=0)
| setMetaInfo (self, KFileMetaInfo info)
| setName (self, QString name)
| setUDSEntry (self, KIO.UDSEntry entry, KUrl url, bool delayedMimeTypes=0, bool urlIsDirectory=0)
| setUrl (self, KUrl url)
long | size (self)
KUrl | targetUrl (self)
QString | text (self)
KDateTime | time (self, KFileItem.FileTimes which)
long | time (self, long which)
QString | timeString (self, KFileItem.FileTimes which=KFileItem.ModificationTime)
QString | timeString (self, long which)
| unmark (self)
KUrl | url (self)
QString | user (self)

## Method Documentation

__init__ | ( |  | self ) |

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()'

__init__ | ( | self, |
|  | KIO.UDSEntry | entry,
|  | KUrl | itemOrDirUrl,
|  | bool | delayedMimeTypes=0,
|  | bool | urlIsDirectory=0
| ) |  |  |

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
  | itemOrDirUrl | the URL of the item or of the directory containing this item (see urlIsDirectory).
  | 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.

When creating KFileItems out of the UDSEntry emitted by a KIO list job, use KFileItem(entry, listjob->url(), delayedMimeTypes, true);

__init__ | ( | self, |
|  | long | mode,
|  | long | permissions,
|  | KUrl | url,
|  | bool | delayedMimeTypes=0
| ) |  |  |

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
  | delayedMimeTypes | specify if the mimetype of the given URL should be determined immediately or on demand

__init__ | ( | self, |
|  | KUrl | url,
|  | QString | mimeType,
|  | long | mode
| ) |  |  |

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

__init__ | ( | self, |
|  | KFileItem | other
| ) |  |  |

Copy constructor

KACL ACL | ( |  | self ) |

Returns the access control list for the file.

Returns:
  the access control list as a KACL

bool acceptsDrops | ( |  | self ) |

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 | ( | self, |
|  | KFileItem | item
| ) |  |  |

Deprecated:
  simply use '='

bool cmp | ( | self, |
|  | KFileItem | item
| ) |  |  |

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.

Parameters:

  | item | the item to compare

Returns:
  true if all values are equal

KACL defaultACL | ( |  | self ) |

Returns the default access control list for the directory.

Returns:
  the default access control list as a KACL

KSharedPtr determineMimeType | ( |  | self ) |

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

Returns:
  the mime type

KIO.UDSEntry entry | ( |  | self ) |

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

Returns:
  the UDS entry

QString getStatusBarInfo | ( |  | self ) |

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

Returns:
  the status bar information

QString getToolTipText | ( | self, |
|  | int | maxcount=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.

Parameters:

  | maxcount | the maximum number of entries shown

Returns:
  the tool tip string

QString group | ( |  | self ) |

Returns the group of the file.

Returns:
  the file's group

bool hasExtendedACL | ( |  | self ) |

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

QString iconName | ( |  | self ) |

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

Returns:
  iconName the name of the file's icon

bool isDesktopFile | ( |  | self ) |

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

bool isDir | ( |  | self ) |

Returns true if this item represents a directory.

Returns:
  true if the item is a directory

bool isFile | ( |  | self ) |

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

Returns:
  true if the item is a file

bool isHidden | ( |  | self ) |

Checks whether the file is hidden.

Returns:
  true if the file is hidden.

bool isLink | ( |  | self ) |

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

Returns:
  true if the file is a link

bool isLocalFile | ( |  | self ) |

Returns true if the file is a local file.

Returns:
  true if the file is local, false otherwise

bool isMarked | ( |  | self ) |

Used when updating a directory. marked == seen when refreshing.

Returns:
  true if the file item is marked

bool isMimeTypeKnown | ( |  | self ) |

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.

bool isNull | ( |  | self ) |

Return true if default-constructed

bool isReadable | ( |  | self ) |

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

bool isRegularFile | ( |  | self ) |

Return true if this item is a regular file, false otherwise (directory, link, character/block device, fifo, socket)

Since:
  4.3

bool isWritable | ( |  | self ) |

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

QString linkDest | ( |  | self ) |

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

Returns:
  the link destination. QString() if the item is not a link

QString localPath | ( |  | self ) |

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 | ( |  | self ) |

Marks the item.

See also:
  isMarked()

KFileMetaInfo metaInfo | ( | self, |
|  | bool | autoget=1,
|  | int | what=KFileMetaInfo.Fastest
| ) |  |  |

Returns the metainfo of this item.

(since 4.4.3) By default it uses the KFileMetaInfo.ContentInfo | KFileMetaInfo.TechnicalInfo. If you need more information, create your own KFileMetaInfo object and set it using setMetaInfo()

Parameters:

  | autoget | if true, the metainfo will automatically be created
  | what | how much metainfo you need to retrieve from the file (KFileMetaInfo.WhatFlag)

QString mimeComment | ( |  | self ) |

Returns the user-readable string representing the type of this file, like "OpenDocument Text File".

Returns:
  the type of this KFileItem

KSharedPtr mimeTypePtr | ( |  | self ) |

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

Returns:
  the known mime type

QString mimetype | ( |  | self ) |

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

long mode | ( |  | self ) |

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

Returns:
  the file type

KUrl, bool local mostLocalUrl | ( |  | self ) |

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

QString name | ( | self, |
|  | bool | lowerCase=0
| ) |  |  |

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

Parameters:

  | 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

KUrl nepomukUri | ( |  | self ) |

Returns the resource URI to be used for Nepomuk annotations. In case the slave does not specify UDS_NEPOMUK_URI an invalid url is returned. For local files this is the same as url().

Returns:
  The Nepomuk resource URI.

Since:
  4.4

bool operator != | ( | self, |
|  | KFileItem | other
| ) |  |  |

bool operator == | ( | self, |
|  | KFileItem | other
| ) |  |  |

QStringList overlays | ( |  | self ) |

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

long permissions | ( |  | self ) |

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

Returns:
  the permissions of the file

QString permissionsString | ( |  | self ) |

Returns the access permissions for the file as a string.

Returns:
  the access persmission as string

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

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: KIconLoader.DefaultState, KIconLoader.ActiveState or KIconLoader.DisabledState.

Returns:
  the pixmap

refresh | ( |  | self ) |

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

refreshMimeType | ( |  | self ) |

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

run | ( | self, |
|  | QWidget | parentWidget=0
| ) |  |  |

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

setMetaInfo | ( | self, |
|  | KFileMetaInfo | info
| ) |  |  |

Sets the metainfo of this item to info.

Made const to avoid deep copy.

Parameters:

  | info | the new meta info

setName | ( | self, |
|  | QString | name
| ) |  |  |

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)

Parameters:

  | name | the item's name

setUDSEntry | ( | self, |
|  | KIO.UDSEntry | entry,
|  | KUrl | url,
|  | bool | delayedMimeTypes=0,
|  | bool | urlIsDirectory=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.

Parameters:

  | 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 | ( | self, |
|  | KUrl | url
| ) |  |  |

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

Parameters:

  | url | the item's URL

long size | ( |  | self ) |

Returns the size of the file, if known.

Returns:
  the file size, or 0 if not known

KUrl targetUrl | ( |  | self ) |

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

QString text | ( |  | self ) |

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

KDateTime time | ( | self, |
|  | KFileItem.FileTimes | which
| ) |  |  |

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

Parameters:

  | which | the timestamp

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

See also:
  timeString()

long time | ( | self, |
|  | long | which
| ) |  |  |

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

Parameters:

  | which | the timestamp

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

See also:
  timeString()

QString timeString | ( | self, |
|  | KFileItem.FileTimes | which=KFileItem.ModificationTime
| ) |  |  |

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

Parameters:

  | which | the timestamp

Returns:
  a formatted string of the requested time.

See also:
  time

QString timeString | ( | self, |
|  | long | which
| ) |  |  |

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

Parameters:

  | which | the timestamp

Returns:
  a formatted string of the requested time.

See also:
  time

unmark | ( |  | self ) |

Unmarks the item.

See also:
  isMarked()

KUrl url | ( |  | self ) |

Returns the url of the file.

Returns:
  the url of the file

QString user | ( |  | self ) |

Returns the owner of the file.

Returns:
  the file's owner

## Enumeration Documentation

anonymous

Enumerator:

  Unknown |

FileTimes

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

Enumerator:

  ModificationTime = 0 |
  AccessTime = 1 |
  CreationTime = 2 |