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 | |
FileTimes | { ModificationTime, AccessTime, CreationTime } |
anonymous | { Unknown } |
Methods | |
KACL | ACL (self) |
__init__ (self) | |
__init__ (self, KIO.UDSEntry entry, KUrl directoryUrl, bool delayedMimeTypes=0, bool urlIsDirectory=0) | |
__init__ (self, mode_t mode, mode_t permissions, KUrl url, bool delayedMimeTypes=0) | |
__init__ (self, KUrl url, QString mimeType, mode_t mode) | |
__init__ (self, KFileItem other) | |
bool | acceptsDrops (self) |
assign (self, KFileItem item) | |
bool | cmp (self, KFileItem item) |
KACL | defaultACL (self) |
KMimeType.Ptr | determineMimeType (self) |
KIO.UDSEntry | entry (self) |
void | extraData (self, void key) |
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 | isWritable (self) |
QString | linkDest (self) |
QString | localPath (self) |
mark (self) | |
KFileMetaInfo | metaInfo (self, bool autoget=1, int what=KFileMetaInfo.Fastest) |
QString | mimeComment (self) |
KMimeType.Ptr | mimeTypePtr (self) |
QString | mimetype (self) |
mode_t | mode (self) |
KUrl, bool (local) | mostLocalUrl (self, ) |
QString | name (self, bool lowerCase=0) |
bool | operator != (self, KFileItem other) |
bool | operator == (self, KFileItem other) |
QStringList | overlays (self) |
mode_t | permissions (self) |
QString | permissionsString (self) |
QPixmap | pixmap (self, int _size, int _state=0) |
refresh (self) | |
refreshMimeType (self) | |
removeExtraData (self, void key) | |
run (self, QWidget parentWidget=0) | |
setExtraData (self, void key, void value) | |
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) | |
KIO.filesize_t | size (self) |
KUrl | targetUrl (self) |
QString | text (self) |
KDateTime | time (self, KFileItem.FileTimes which) |
time_t | 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
KACL ACL | ( | self ) |
Returns the access control list for the file.
- Returns:
- the access control list as a KACL
__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 | directoryUrl, | |||
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 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.
__init__ | ( | self, | ||
mode_t | mode, | |||
mode_t | 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
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
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
KMimeType.Ptr 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
void extraData | ( | self, | ||
void | key | |||
) |
Retrieves the extra data with the given key.
- Parameters:
-
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
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 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.
- Parameters:
-
autoget if true, the metainfo will automatically be created what ignored
QString mimeComment | ( | self ) |
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
KMimeType.Ptr 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
mode_t 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
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
mode_t 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.
removeExtraData | ( | self, | ||
void | key | |||
) |
Removes the extra data associated with an item via key.
- Parameters:
-
key the key of the extra data to remove
- Deprecated:
- use model/view (KDirModel) and you won't need this anymore
run | ( | self, | ||
QWidget | parentWidget=0 | |||
) |
Let's "KRun" this file ! (e.g. when file is clicked or double-clicked or return is pressed)
setExtraData | ( | self, | ||
void | key, | |||
void | value | |||
) |
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!
- Parameters:
-
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 | ( | 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
KIO.filesize_t 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, 0 if not available
- See also:
- timeString()
time_t time | ( | self, | ||
long | which | |||
) |
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 | |||
) |
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
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
anonymous |
- Enumerator:
-
Unknown = (mode_t)-1