KFileItem Class
Header: | #include <KFileItem> |
CMake: | find_package(KF6 REQUIRED COMPONENTS KIO) target_link_libraries(mytarget PRIVATE KF6::KIOCore) |
Public Types
enum | FileTimes { ModificationTime, AccessTime, CreationTime } |
Public Functions
KFileItem() | |
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 &) | |
KFileItem(KFileItem &&) | |
~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 |
bool | exists() const |
QString | getStatusBarInfo() const |
QString | group() const |
int | groupId() const |
bool | hasExtendedACL() const |
QString | iconName() const |
bool | isDesktopFile() const |
bool | isDir() const |
bool | isExecutable() const |
bool | isFile() const |
bool | isFinalIconKnown() const |
bool | isHidden() const |
bool | isLink() const |
bool | isLocalFile() const |
bool | isMimeTypeKnown() const |
KFileItem::MostLocalUrlResult | isMostLocalUrl() const |
bool | isNull() const |
bool | isReadable() const |
bool | isRegularFile() const |
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 |
KIO::filesize_t | recursiveSize() const |
void | refresh() |
void | refreshMimeType() |
void | setDelayedMimeTypes(bool b) |
void | setLocalPath(const QString &path) |
void | setName(const QString &name) |
void | setUrl(const QUrl &url) |
KIO::filesize_t | size() const |
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 |
int | userId() const |
QVariant | operator QVariant() const |
bool | operator!=(const KFileItem &other) const |
bool | operator<(const KFileItem &other) const |
bool | operator<(const QUrl &other) const |
KFileItem & | operator=(KFileItem &&) |
KFileItem & | operator=(const KFileItem &) |
bool | operator==(const KFileItem &other) const |
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 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. - 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
Member Function Documentation
KFileItem::KFileItem()
Null KFileItem. Doesn't represent any file, only exists for convenience.
KFileItem::KFileItem(const QUrl &url, KFileItem::MimeTypeDetermination mimeTypeDetermination)
Creates an item representing a file, with the option of skipping MIME type determination. @param url the file url @param 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. @since 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. @param url the file url @param mimeType the name of the file's MIME type @param 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().
@param entry the KIO entry used to get the file, contains info about it @param itemOrDirUrl the URL of the item or of the directory containing this item (see urlIsDirectory). @param 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. @param 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
KFileItem::KFileItem(KFileItem &&)
Move constructor @since 5.43
[noexcept]
KFileItem::~KFileItem()
Destructor
KACL KFileItem::ACL() const
Returns the access control list for the file. @return the access control list as a KACL
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. @param item the item to compare @return true if all values are equal
QString 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. @return the known MIME type
Note: Getter function for property currentMimeType.
KACL KFileItem::defaultACL() const
Returns the default access control list for the directory. @return the default access control list as a KACL
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. @return the MIME type
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. @return the UDS entry
bool KFileItem::exists() const
returns whether the KFileItem exists on-disk Call only after initialization (i.e `KIO::stat` or `refresh()` for local files) @since 6.0
QString KFileItem::getStatusBarInfo() const
Returns the string to be displayed in the statusbar, e.g. when the mouse is over this item. @return the status bar information
Note: Getter function for property getStatusBarInfo.
QString KFileItem::group() const
Returns the group of the file. @return the file's group
Note: Getter function for property group.
int KFileItem::groupId() const
Returns the file's owner's group id. Available only on supported protocols. @since 6.0
bool KFileItem::hasExtendedACL() const
Tells if the file has extended access level information ( Posix ACL ) @return true if the file has extend ACL information or false if it hasn't
QString KFileItem::iconName() const
Returns the full path name to the icon that represents this MIME type. @return iconName the name of the file's icon
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 @return 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. @return true if the item is a directory
Note: Getter function for property isDir.
bool KFileItem::isExecutable() const
Return true if the file has executable permission @since 6.0
bool KFileItem::isFile() const
Returns true if this item represents a file (and not a directory) @return true if the item is a file
Note: Getter function for property isFile.
bool KFileItem::isFinalIconKnown() const
@return true if we have determined the final icon of this file already. @since 4.10.2
Note: Getter function for property isFinalIconKnown.
bool KFileItem::isHidden() const
Checks whether the file is hidden. @return 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. @return true if the file is a link
Note: Getter function for property isLink.
bool KFileItem::isLocalFile() const
Returns true if the file is a local file. @return true if the file is local, false otherwise
Note: Getter function for property isLocalFile.
bool KFileItem::isMimeTypeKnown() const
@return 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.
KFileItem::MostLocalUrlResult KFileItem::isMostLocalUrl() const
Returns a MostLocalUrlResult, with the local Url for this item if possible (otherwise an empty Url), and a bool that is set to @c true if this Url does represent a local file otherwise @c false.
Basically this is an alternative to mostLocalUrl(bool*), that does not use an output parameter.
Example: @code KFileItem item; const MostLocalUrlResult result = item.isMostLocalUrl(); if (result.local) { // A local file // Use result.url } @endcode @since 5.84
bool KFileItem::isNull() const
Return true if default-constructed
bool 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. @return true if the file can be read - more precisely, false if we know for sure it can't
Note: 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.
bool KFileItem::isSlow() const
@return true if the file is a remote URL, or a local file on a network mount. It will return false only for really-local file systems. @since 4.7.4
Note: Getter function for property isSlow.
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. @return true if the file or directory can be written to - more precisely, false if we know for sure it can't
Note: Getter function for property isWritable.
QString KFileItem::linkDest() const
Returns the link destination if isLink() == true. @return the link destination. 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.
@return 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". @return the type of this KFileItem
Note: Getter function for property mimeComment.
QString KFileItem::mimetype() const
Returns the MIME type of the file item. If @p delayedMimeTypes was used in the constructor, this will determine the MIME type first. Equivalent to determineMimeType()->name() @return the MIME type of the file
Note: Getter function for property mimetype.
mode_t KFileItem::mode() const
Returns the file type (stat.st_mode containing only S_IFDIR, S_IFLNK, ...). @return the file type
QUrl KFileItem::mostLocalUrl(bool *local = nullptr) const
Tries to return a local URL for this file item if possible. If @p local is not null, it will be set to @c true if the returned url is local, @c false otherwise.
Example: @code bool isLocal = false; KFileItem item; const QUrl url = item.mostLocalUrl(&isLocal); if (isLocal) { // Use url } @endcode
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. @param lowerCase if true, the name will be returned in lower case, which is useful to speed up sorting by name, case insensitively. @return 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. @return the overlays of the pixmap
Note: Getter function for property overlays.
mode_t KFileItem::permissions() const
Returns the permissions of the file (stat.st_mode containing only permissions). @return the permissions of the file
QString KFileItem::permissionsString() const
Returns the access permissions for the file as a string. @return the access permission as string
KIO::filesize_t KFileItem::recursiveSize() const
@brief For folders, its recursive size: the size of its files plus the recursiveSize of its folder
Initially only implemented for trash:/
@since 5.70 @return The recursive size
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. @since 5.0
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). @param path the item's local path @since 5.20
Note: Setter function for property localPath.
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) @param 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). @param 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. @return the file size, or 0 if not known
QString KFileItem::suffix() const
Returns the file extension Similar to QFileInfo::suffix except it takes into account UDS_DISPLAY_NAME and saves a stat call @since 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 @return the 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'->'/'). @return the text of the file item
Note: Getter function for property text.
[invokable]
QDateTime KFileItem::time(KFileItem::FileTimes which) const
Requests the modification, access or creation time, depending on @p which. @param which the timestamp @return the time asked for, QDateTime() if not available @see 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) const
Requests the modification, access or creation time as a string, depending on @p which. @param which the timestamp @returns a formatted string of the requested time. @see 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. @return the url of the file
Note: Getter function for property url.
See also setUrl().
QString KFileItem::user() const
Returns the owner of the file. @return the file's owner
Note: Getter function for property user.
int KFileItem::userId() const
Returns the file's owner's user id. Available only on supported protocols. @since 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.
bool KFileItem::operator<(const KFileItem &other) const
Returns true if this item's URL is lexically less than other's URL; otherwise returns false @since 5.48
bool KFileItem::operator<(const QUrl &other) const
Returns true if this item's URL is lexically less than url other; otherwise returns false @since 5.48
KFileItem &KFileItem::operator=(KFileItem &&)
Move assignment @since 5.43
KFileItem &KFileItem::operator=(const KFileItem &)
Copy assignment
bool KFileItem::operator==(const KFileItem &other) const
Returns true if both items share the same URL.