KFileItem Class
A KFileItem is a generic class to handle a file, local or remote. More...
Header: | #include <KFileItem> |
CMake: | find_package(KF6 REQUIRED COMPONENTS KIO) target_link_libraries(mytarget PRIVATE KF6::KIOCore) |
Public Types
enum | FileTimes { ModificationTime, AccessTime, CreationTime } |
enum | MimeTypeDetermination { NormalMimeTypeDetermination, SkipMimeTypeFromContent } |
Properties
|
|
Public Functions
KFileItem() | |
(since 5.57) | KFileItem(const QUrl &url, KFileItem::MimeTypeDetermination mimeTypeDetermination) |
KFileItem(const QUrl &url, const QString &mimeType = QString(), mode_t mode = KFileItem::Unknown) | |
KFileItem(const KIO::UDSEntry &entry, const QUrl &itemOrDirUrl, bool delayedMimeTypes = false, bool urlIsDirectory = false) | |
KFileItem(const KFileItem &) | |
KACL | ACL() const |
bool | cmp(const KFileItem &item) const |
QString | comment() const |
QMimeType | currentMimeType() const |
KACL | defaultACL() const |
QMimeType | determineMimeType() const |
KIO::UDSEntry | entry() const |
(since 6.0) bool | exists() const |
QString | getStatusBarInfo() const |
QString | group() const |
(since 6.0) int | groupId() const |
bool | hasExtendedACL() const |
QString | iconName() const |
bool | isDesktopFile() const |
bool | isDir() const |
(since 6.0) bool | isExecutable() const |
bool | isFile() const |
(since 4.10.2) bool | isFinalIconKnown() const |
bool | isHidden() const |
bool | isLink() const |
bool | isLocalFile() const |
bool | isMimeTypeKnown() const |
(since 5.84) KFileItem::MostLocalUrlResult | isMostLocalUrl() const |
bool | isNull() const |
bool | isReadable() const |
bool | isRegularFile() const |
(since 4.7.4) bool | isSlow() const |
bool | isWritable() const |
QString | linkDest() const |
QString | localPath() const |
QString | mimeComment() const |
QString | mimetype() const |
mode_t | mode() const |
QUrl | mostLocalUrl(bool *local = nullptr) const |
QString | name(bool lowerCase = false) const |
QStringList | overlays() const |
mode_t | permissions() const |
QString | permissionsString() const |
(since 5.70) KIO::filesize_t | recursiveSize() const |
void | refresh() |
void | refreshMimeType() |
void | setDelayedMimeTypes(bool b) |
(since 5.20) void | setLocalPath(const QString &path) |
void | setName(const QString &name) |
void | setUrl(const QUrl &url) |
KIO::filesize_t | size() const |
(since 6.0) QString | suffix() const |
QUrl | targetUrl() const |
QString | text() const |
QDateTime | time(KFileItem::FileTimes which) const |
QString | timeString(KFileItem::FileTimes which = ModificationTime) const |
QUrl | url() const |
QString | user() const |
(since 6.0) int | userId() const |
QVariant | operator QVariant() const |
bool | operator!=(const KFileItem &other) const |
(since 5.48) bool | operator<(const KFileItem &other) const |
(since 5.48) bool | operator<(const QUrl &other) const |
bool | operator==(const KFileItem &other) const |
Detailed Description
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 MIME type, icon, text, mode, link...
KFileItem is implicitly shared, i.e. it can be used as a value and copied around at almost no cost.
Member Type Documentation
enum KFileItem::FileTimes
The timestamps associated with a file.
Constant | Value | Description |
---|---|---|
KFileItem::ModificationTime | 0 | The time the file's contents were last modified |
KFileItem::AccessTime | 1 | The time the file was last accessed (last read or written to) |
KFileItem::CreationTime | 2 | The time the file was created |
enum KFileItem::MimeTypeDetermination
Constant | Value |
---|---|
KFileItem::NormalMimeTypeDetermination | 0 |
KFileItem::SkipMimeTypeFromContent | 1 |
Property Documentation
[read-only]
comment : const QString
Access functions:
QString | comment() const |
[read-only]
currentMimeType : const QMimeType
Access functions:
QMimeType | currentMimeType() const |
[read-only]
determineMimeType : const QMimeType
Access functions:
QMimeType | determineMimeType() const |
[read-only]
getStatusBarInfo : const QString
Access functions:
QString | getStatusBarInfo() const |
[read-only]
group : const QString
Access functions:
QString | group() const |
[read-only]
iconName : const QString
Access functions:
QString | iconName() const |
[read-only]
isDesktopFile : const bool
Access functions:
bool | isDesktopFile() const |
[read-only]
isDir : const bool
Access functions:
bool | isDir() const |
[read-only]
isFile : const bool
Access functions:
bool | isFile() const |
[read-only]
isFinalIconKnown : const bool
Access functions:
bool | isFinalIconKnown() const |
[read-only]
isHidden : const bool
Access functions:
bool | isHidden() const |
[read-only]
isLink : const bool
Access functions:
bool | isLink() const |
[read-only]
isLocalFile : const bool
Access functions:
bool | isLocalFile() const |
[read-only]
isMimeTypeKnown : const bool
Access functions:
bool | isMimeTypeKnown() const |
[read-only]
isReadable : const bool
Access functions:
bool | isReadable() const |
[read-only]
isRegularFile : const bool
Access functions:
bool | isRegularFile() const |
[read-only]
isSlow : const bool
Access functions:
bool | isSlow() const |
[read-only]
isWritable : const bool
Access functions:
bool | isWritable() const |
[read-only]
linkDest : const QString
Access functions:
QString | linkDest() const |
localPath : QString
Access functions:
QString | localPath() const |
void | setLocalPath(const QString &path) |
[read-only]
mimeComment : const QString
Access functions:
QString | mimeComment() const |
[read-only]
mimetype : const QString
Access functions:
QString | mimetype() const |
name : QString
Access functions:
[read-only]
overlays : const QStringList
Access functions:
QStringList | overlays() const |
[read-only]
targetUrl : const QUrl
Access functions:
QUrl | targetUrl() const |
[read-only]
text : const QString
Access functions:
QString | text() const |
url : QUrl
Access functions:
[read-only]
user : const QString
Access functions:
QString | user() const |
Member Function Documentation
KFileItem::KFileItem()
Null KFileItem. Doesn't represent any file, only exists for convenience.
[since 5.57]
KFileItem::KFileItem(const QUrl &url, KFileItem::MimeTypeDetermination mimeTypeDetermination)
Creates an item representing a file, with the option of skipping MIME type determination.
url the file url
mimeTypeDetermination the mode of determining the MIME type:
- NormalMimeTypeDetermination: By content if local file, i.e. access the file, open and read part of it; by QMimeDatabase::MatchMode::MatchExtension if not local.
- SkipMimeTypeFromContent: Always by QMimeDatabase::MatchMode::MatchExtension, i.e. won't access the file by stat() or opening it; only suitable for files, directories won't be recognized.
This function was introduced in 5.57.
[explicit]
KFileItem::KFileItem(const QUrl &url, const QString &mimeType = QString(), mode_t mode = KFileItem::Unknown)Creates an item representing a file, for which the MIME type is already known.
url the file url
mimeType the name of the file's MIME type
mode the mode (S_IFDIR...)
KFileItem::KFileItem(const KIO::UDSEntry &entry, const QUrl &itemOrDirUrl, bool delayedMimeTypes = false, bool urlIsDirectory = false)
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
itemOrDirUrl the URL of the item or of the directory containing this item (see urlIsDirectory).
delayedMimeTypes specifies if the MIME type 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);
KFileItem::KFileItem(const KFileItem &)
Copy constructor
KACL KFileItem::ACL() const
Returns the access control list for the file.
bool KFileItem::cmp(const KFileItem &item) const
Somewhat like a comparison operator, but more explicit, and it can detect that two fileitems differ if any property of the file item has changed (file size, modification date, etc.). Two items are equal if all properties are equal. In contrast, operator== only compares URLs.
item the item to compare
Returns
true
if all values are equalQString KFileItem::comment() const
A comment which can contain anything - even rich text. It will simply be displayed to the user as is.
Note: Getter function for property comment.
QMimeType KFileItem::currentMimeType() const
Returns the currently known MIME type of the file item. This will not try to determine the MIME type if unknown.
Note: Getter function for property currentMimeType.
KACL KFileItem::defaultACL() const
Returns the default access control list for the directory.
QMimeType KFileItem::determineMimeType() const
Returns the MIME type of the file item.
If delayedMimeTypes was used in the constructor, this will determine the MIME type first.
Note: Getter function for property determineMimeType.
KIO::UDSEntry KFileItem::entry() const
Returns the UDS entry. Used by the tree view to access all details by position.
[since 6.0]
bool KFileItem::exists() constReturns whether the KFileItem exists on-disk
Call only after initialization (i.e `KIO::stat` or `refresh()` for local files)
This function was introduced in 6.0.
QString KFileItem::getStatusBarInfo() const
Returns the string to be displayed in the statusbar, e.g. when the mouse is over this item.
Note: Getter function for property getStatusBarInfo.
QString KFileItem::group() const
Returns the group of the file.
Note: Getter function for property group.
[since 6.0]
int KFileItem::groupId() constReturns the file's owner's group id. Available only on supported protocols.
This function was introduced in 6.0.
bool KFileItem::hasExtendedACL() const
Tells if the file has extended access level information ( Posix ACL )
QString KFileItem::iconName() const
Returns the full path name to the icon that represents this MIME type.
Note: Getter function for property iconName.
bool KFileItem::isDesktopFile() const
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.Note: Getter function for property isDesktopFile.
bool KFileItem::isDir() const
Returns
true
if this item represents a directory.Note: Getter function for property isDir.
[since 6.0]
bool KFileItem::isExecutable() constReturns
true
if the file has executable permissionThis function was introduced in 6.0.
bool KFileItem::isFile() const
Returns
true
if this item represents a file (and not a directory)Note: Getter function for property isFile.
[since 4.10.2]
bool KFileItem::isFinalIconKnown() constReturns
true
if we have determined the final icon of this file already.Note: Getter function for property isFinalIconKnown.
This function was introduced in 4.10.2.
bool KFileItem::isHidden() const
Checks whether the file is hidden.
Returns
true
if the file is hidden.Note: Getter function for property isHidden.
bool KFileItem::isLink() const
Returns
true
if this item represents a link in the UNIX sense of a link.Note: Getter function for property isLink.
bool KFileItem::isLocalFile() const
Returns
true
if the file is a local file.Note: Getter function for property isLocalFile.
bool KFileItem::isMimeTypeKnown() const
Returns
true
if we have determined the MIME type of this file already, i.e. if determineMimeType() will be fast. Otherwise it will have to find what the MIME type is, which is a possibly slow operation; usually this is delayed until necessary.Note: Getter function for property isMimeTypeKnown.
[since 5.84]
KFileItem::MostLocalUrlResult KFileItem::isMostLocalUrl() constReturns a MostLocalUrlResult, with the local Url for this item if possible (otherwise an empty Url), and a bool that is set to
true
if this Url does represent a local file otherwisefalse
.Basically this is an alternative to mostLocalUrl(bool*), that does not use an output parameter.
Example:
KFileItem item; const MostLocalUrlResult result = item.isMostLocalUrl(); if (result.local) { // A local file // Use result.url }
This function was introduced in 5.84.
bool KFileItem::isNull() const
Returns
true
if default-constructedbool KFileItem::isReadable() const
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'tNote: Getter function for property isReadable.
bool KFileItem::isRegularFile() const
Return
true
if this item is a regular file,false
otherwise (directory, link, character/block device, fifo, socket)Note: Getter function for property isRegularFile.
[since 4.7.4]
bool KFileItem::isSlow() constReturns
true
if the file is a remote URL, or a local file on a network mount. It will returnfalse
only for really-local file systems.Note: Getter function for property isSlow.
This function was introduced in 4.7.4.
bool KFileItem::isWritable() const
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'tNote: Getter function for property isWritable.
QString KFileItem::linkDest() const
Returns the link destination if isLink() == true, or QString() if the item is not a link
Note: Getter function for property linkDest.
QString KFileItem::localPath() const
Returns the local path if isLocalFile() == true or the KIO item has a UDS_LOCAL_PATH atom.
Treat it as a readonly path to open/list contents, use original url to move/delete files.
Returns the item local path, or QString() if not known
Note: Getter function for property localPath.
See also setLocalPath().
QString KFileItem::mimeComment() const
Returns the user-readable string representing the type of this file, like "OpenDocument Text File".
Note: Getter function for property mimeComment.
QString KFileItem::mimetype() const
Returns the MIME type of the file item.
If delayedMimeTypes was used in the constructor, this will determine the MIME type first. Equivalent to determineMimeType()->name()
Note: Getter function for property mimetype.
mode_t KFileItem::mode() const
Returns the file type (stat.st_mode containing only S_IFDIR, S_IFLNK, ...).
QUrl KFileItem::mostLocalUrl(bool *local = nullptr) const
Tries to return a local URL for this file item if possible.
If local is not null, it will be set to
true
if the returned url is local,false
otherwise.Example:
bool isLocal = false; KFileItem item; const QUrl url = item.mostLocalUrl(&isLocal); if (isLocal) { // Use url }
QString KFileItem::name(bool lowerCase = false) const
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
Note: Getter function for property name.
See also setName().
QStringList KFileItem::overlays() const
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.
Note: Getter function for property overlays.
mode_t KFileItem::permissions() const
Returns the permissions of the file (stat.st_mode containing only permissions).
QString KFileItem::permissionsString() const
Returns the access permissions for the file as a string.
[since 5.70]
KIO::filesize_t KFileItem::recursiveSize() constFor folders, returns its recursive size: the size of its files plus the recursiveSize of its folder
Initially only implemented for trash:/
This function was introduced in 5.70.
void KFileItem::refresh()
Throw away and re-read (for local files) all information about the file. This is called when the _file_ changes.
void KFileItem::refreshMimeType()
Re-reads MIME type information. This is called when the MIME type database changes.
void KFileItem::setDelayedMimeTypes(bool b)
Sets MIME type determination to be immediate or on demand. Call this after the constructor, and before using any MIME-type-related method. 5.0
[since 5.20]
void KFileItem::setLocalPath(const QString &path)Sets the item's local path (UDS_LOCAL_PATH). Do not call unless you know what you are doing! This won't change the item's name or URL. (used for example when an item got renamed).
path the item's local path
Note: Setter function for property localPath.
This function was introduced in 5.20.
See also localPath().
void KFileItem::setName(const 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)
name the item's name
Note: Setter function for property name.
See also name().
void KFileItem::setUrl(const QUrl &url)
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
Note: Setter function for property url.
See also url().
KIO::filesize_t KFileItem::size() const
Returns the size of the file, if known.
Returns 0 otherwise.
[since 6.0]
QString KFileItem::suffix() constReturns the file extension
Similar to QFileInfo::suffix except it takes into account UDS_DISPLAY_NAME and saves a stat call
This function was introduced in 6.0.
QUrl KFileItem::targetUrl() const
Returns the target url of the file, which is the same as url() in cases where the worker doesn't specify UDS_TARGET_URL
Note: Getter function for property targetUrl.
QString KFileItem::text() const
Returns the text of the file item.
It's not exactly the filename since some decoding happens ('%2F'->'/').
Note: Getter function for property text.
[invokable]
QDateTime KFileItem::time(KFileItem::FileTimes which) constRequests the modification, access or creation time, depending on which.
which the timestamp
Returns the time asked for, QDateTime() if not available timeString()
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable]
QString KFileItem::timeString(KFileItem::FileTimes which = ModificationTime) constRequests the modification, access or creation time as a string, depending on which.
which the timestamp
Returns a formatted string of the requested time. time
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
QUrl KFileItem::url() const
Returns the url of the file.
Note: Getter function for property url.
See also setUrl().
QString KFileItem::user() const
Returns the owner of the file.
Note: Getter function for property user.
[since 6.0]
int KFileItem::userId() constReturns the file's owner's user id. Available only on supported protocols.
This function was introduced in 6.0.
QVariant KFileItem::operator QVariant() const
Converts this KFileItem to a QVariant, this allows to use KFileItem in QVariant() constructor
bool KFileItem::operator!=(const KFileItem &other) const
Returns
true
if both items do not share the same URL.[since 5.48]
bool KFileItem::operator<(const KFileItem &other) constReturns
true
if this item's URL is lexically less than other's URL; otherwise returnsfalse
This function was introduced in 5.48.
[since 5.48]
bool KFileItem::operator<(const QUrl &other) constReturns
true
if this item's URL is lexically less than url other; otherwise returnsfalse
This function was introduced in 5.48.
bool KFileItem::operator==(const KFileItem &other) const
Returns
true
if both items share the same URL.