KFileItem
#include <KFileItem>
Public Types | |
enum | { Unknown = static_cast<mode_t>(-1) } |
enum | FileTimes { ModificationTime = 0 , AccessTime = 1 , CreationTime = 2 } |
enum | MimeTypeDetermination { NormalMimeTypeDetermination = 0 , SkipMimeTypeFromContent } |
Properties | |
QString | comment |
QMimeType | currentMimeType |
QMimeType | determineMimeType |
QString | getStatusBarInfo |
QString | group |
QString | iconName |
bool | isDesktopFile |
bool | isDir |
bool | isFile |
bool | isFinalIconKnown |
bool | isHidden |
bool | isLink |
bool | isLocalFile |
bool | isMimeTypeKnown |
bool | isReadable |
bool | isRegularFile |
bool | isSlow |
bool | isWritable |
QString | linkDest |
QString | localPath |
QString | mimeComment |
QString | mimetype |
QString | name |
QStringList | overlays |
QUrl | targetUrl |
QString | text |
QUrl | url |
QString | user |
Public Member Functions | |
KFileItem () | |
KFileItem (const KFileItem &) | |
KFileItem (const KIO::UDSEntry &entry, const QUrl &itemOrDirUrl, bool delayedMimeTypes=false, bool urlIsDirectory=false) | |
KFileItem (const QUrl &url, const QString &mimeType=QString(), mode_t mode=KFileItem::Unknown) | |
KFileItem (const QUrl &url, KFileItem::MimeTypeDetermination mimeTypeDetermination) | |
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 |
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 |
operator QVariant () const | |
bool | operator!= (const KFileItem &other) const |
bool | operator< (const KFileItem &other) const |
bool | operator< (const QUrl &other) const |
KFileItem & | operator= (const KFileItem &) |
KFileItem & | operator= (KFileItem &&) |
bool | operator== (const KFileItem &other) 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 |
Q_INVOKABLE QDateTime | time (KFileItem::FileTimes which) const |
Q_INVOKABLE QString | timeString (KFileItem::FileTimes which=ModificationTime) const |
QUrl | url () const |
QString | user () const |
int | userId () 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.
Definition at line 35 of file kfileitem.h.
Member Enumeration Documentation
◆ anonymous enum
anonymous enum |
Definition at line 69 of file kfileitem.h.
◆ FileTimes
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
Definition at line 79 of file kfileitem.h.
◆ MimeTypeDetermination
enum KFileItem::MimeTypeDetermination |
Definition at line 88 of file kfileitem.h.
Property Documentation
◆ comment
|
read |
Definition at line 64 of file kfileitem.h.
◆ currentMimeType
|
read |
Definition at line 58 of file kfileitem.h.
◆ determineMimeType
|
read |
Definition at line 57 of file kfileitem.h.
◆ getStatusBarInfo
|
read |
Definition at line 65 of file kfileitem.h.
◆ group
|
read |
Definition at line 41 of file kfileitem.h.
◆ iconName
|
read |
Definition at line 62 of file kfileitem.h.
◆ isDesktopFile
|
read |
Definition at line 49 of file kfileitem.h.
◆ isDir
|
read |
Definition at line 43 of file kfileitem.h.
◆ isFile
|
read |
Definition at line 44 of file kfileitem.h.
◆ isFinalIconKnown
|
read |
Definition at line 59 of file kfileitem.h.
◆ isHidden
|
read |
Definition at line 47 of file kfileitem.h.
◆ isLink
|
read |
Definition at line 42 of file kfileitem.h.
◆ isLocalFile
|
read |
Definition at line 53 of file kfileitem.h.
◆ isMimeTypeKnown
|
read |
Definition at line 60 of file kfileitem.h.
◆ isReadable
|
read |
Definition at line 45 of file kfileitem.h.
◆ isRegularFile
|
read |
Definition at line 66 of file kfileitem.h.
◆ isSlow
|
read |
Definition at line 48 of file kfileitem.h.
◆ isWritable
|
read |
Definition at line 46 of file kfileitem.h.
◆ linkDest
|
read |
Definition at line 50 of file kfileitem.h.
◆ localPath
|
readwrite |
Definition at line 52 of file kfileitem.h.
◆ mimeComment
|
read |
Definition at line 61 of file kfileitem.h.
◆ mimetype
|
read |
Definition at line 56 of file kfileitem.h.
◆ name
|
readwrite |
Definition at line 55 of file kfileitem.h.
◆ overlays
|
read |
Definition at line 63 of file kfileitem.h.
◆ targetUrl
|
read |
Definition at line 51 of file kfileitem.h.
◆ text
|
read |
Definition at line 54 of file kfileitem.h.
◆ url
|
readwrite |
Definition at line 39 of file kfileitem.h.
◆ user
|
read |
Definition at line 40 of file kfileitem.h.
Constructor & Destructor Documentation
◆ KFileItem() [1/6]
KFileItem::KFileItem | ( | ) |
Null KFileItem.
Doesn't represent any file, only exists for convenience.
Definition at line 603 of file kfileitem.cpp.
◆ KFileItem() [2/6]
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().
- 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 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);
Definition at line 608 of file kfileitem.cpp.
◆ KFileItem() [3/6]
|
explicit |
Creates an item representing a file, for which the MIME type is already known.
- Parameters
-
url the file url mimeType the name of the file's MIME type mode the mode (S_IFDIR...)
Definition at line 619 of file kfileitem.cpp.
◆ KFileItem() [4/6]
KFileItem::KFileItem | ( | const QUrl & | url, |
KFileItem::MimeTypeDetermination | mimeTypeDetermination ) |
Creates an item representing a file, with the option of skipping MIME type determination.
- Parameters
-
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.
- Since
- 5.57
Definition at line 629 of file kfileitem.cpp.
◆ KFileItem() [5/6]
|
default |
Copy constructor.
◆ ~KFileItem()
|
default |
Destructor.
◆ KFileItem() [6/6]
|
default |
Move constructor.
- Since
- 5.43
Member Function Documentation
◆ ACL()
KACL KFileItem::ACL | ( | ) | const |
Returns the access control list for the file.
- Returns
- the access control list as a KACL
Definition at line 838 of file kfileitem.cpp.
◆ cmp()
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.
- Parameters
-
item the item to compare
- Returns
- true if all values are equal
Definition at line 1507 of file kfileitem.cpp.
◆ comment()
QString KFileItem::comment | ( | ) | const |
A comment which can contain anything - even rich text.
It will simply be displayed to the user as is.
Definition at line 1282 of file kfileitem.cpp.
◆ currentMimeType()
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.
- Returns
- the known MIME type
Definition at line 1761 of file kfileitem.cpp.
◆ defaultACL()
KACL KFileItem::defaultACL | ( | ) | const |
Returns the default access control list for the directory.
- Returns
- the default access control list as a KACL
Definition at line 856 of file kfileitem.cpp.
◆ determineMimeType()
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.
- Returns
- the MIME type
Definition at line 976 of file kfileitem.cpp.
◆ entry()
KIO::UDSEntry KFileItem::entry | ( | ) | const |
Returns the UDS entry.
Used by the tree view to access all details by position.
- Returns
- the UDS entry
Definition at line 1794 of file kfileitem.cpp.
◆ exists()
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
Definition at line 1810 of file kfileitem.cpp.
◆ getStatusBarInfo()
QString KFileItem::getStatusBarInfo | ( | ) | const |
Returns the string to be displayed in the statusbar, e.g. when the mouse is over this item.
- Returns
- the status bar information
Definition at line 1459 of file kfileitem.cpp.
◆ group()
QString KFileItem::group | ( | ) | const |
Returns the group of the file.
- Returns
- the file's group
Definition at line 907 of file kfileitem.cpp.
◆ groupId()
int KFileItem::groupId | ( | ) | const |
Returns the file's owner's group id.
Available only on supported protocols.
- Since
- 6.0
Definition at line 934 of file kfileitem.cpp.
◆ hasExtendedACL()
bool KFileItem::hasExtendedACL | ( | ) | const |
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
Definition at line 828 of file kfileitem.cpp.
◆ iconName()
QString KFileItem::iconName | ( | ) | const |
Returns the full path name to the icon that represents this MIME type.
- Returns
- iconName the name of the file's icon
Definition at line 1147 of file kfileitem.cpp.
◆ isDesktopFile()
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.
Definition at line 1916 of file kfileitem.cpp.
◆ isDir()
bool KFileItem::isDir | ( | ) | const |
Returns true if this item represents a directory.
- Returns
- true if the item is a directory
Definition at line 1419 of file kfileitem.cpp.
◆ isExecutable()
bool KFileItem::isExecutable | ( | ) | const |
Return true if the file has executable permission.
- Since
- 6.0
Definition at line 1822 of file kfileitem.cpp.
◆ isFile()
bool KFileItem::isFile | ( | ) | const |
Returns true if this item represents a file (and not a directory)
- Returns
- true if the item is a file
Definition at line 1450 of file kfileitem.cpp.
◆ isFinalIconKnown()
bool KFileItem::isFinalIconKnown | ( | ) | const |
- Returns
- true if we have determined the final icon of this file already.
- Since
- 4.10.2
Definition at line 1037 of file kfileitem.cpp.
◆ isHidden()
bool KFileItem::isHidden | ( | ) | const |
Checks whether the file is hidden.
- Returns
- true if the file is hidden.
Definition at line 1387 of file kfileitem.cpp.
◆ isLink()
bool KFileItem::isLink | ( | ) | const |
Returns true if this item represents a link in the UNIX sense of a link.
- Returns
- true if the file is a link
Definition at line 1692 of file kfileitem.cpp.
◆ isLocalFile()
bool KFileItem::isLocalFile | ( | ) | const |
Returns true if the file is a local file.
- Returns
- true if the file is local, false otherwise
Definition at line 1703 of file kfileitem.cpp.
◆ isMimeTypeKnown()
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.
Definition at line 1007 of file kfileitem.cpp.
◆ isMostLocalUrl()
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 true
if this Url does represent a local file otherwise false
.
Basically this is an alternative to mostLocalUrl(bool*), that does not use an output parameter.
Example:
- Since
- 5.84
Definition at line 1600 of file kfileitem.cpp.
◆ isNull()
bool KFileItem::isNull | ( | ) | const |
Return true if default-constructed.
Definition at line 1805 of file kfileitem.cpp.
◆ isReadable()
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.
- Returns
- true if the file can be read - more precisely, false if we know for sure it can't
Definition at line 1291 of file kfileitem.cpp.
◆ isRegularFile()
bool KFileItem::isRegularFile | ( | ) | const |
Return true if this item is a regular file, false otherwise (directory, link, character/block device, fifo, socket)
Definition at line 1921 of file kfileitem.cpp.
◆ isSlow()
bool KFileItem::isSlow | ( | ) | const |
- Returns
- 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
Definition at line 957 of file kfileitem.cpp.
◆ isWritable()
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't
Definition at line 1341 of file kfileitem.cpp.
◆ linkDest()
QString KFileItem::linkDest | ( | ) | const |
Returns the link destination if isLink() == true.
- Returns
- the link destination. QString() if the item is not a link
Definition at line 732 of file kfileitem.cpp.
◆ localPath()
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
Definition at line 801 of file kfileitem.cpp.
◆ mimeComment()
QString KFileItem::mimeComment | ( | ) | const |
Returns the user-readable string representing the type of this file, like "OpenDocument Text File".
- Returns
- the type of this KFileItem
Definition at line 1046 of file kfileitem.cpp.
◆ mimetype()
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()
- Returns
- the MIME type of the file
Definition at line 966 of file kfileitem.cpp.
◆ mode()
mode_t KFileItem::mode | ( | ) | const |
Returns the file type (stat.st_mode containing only S_IFDIR, S_IFLNK, ...).
- Returns
- the file type
Definition at line 1681 of file kfileitem.cpp.
◆ mostLocalUrl()
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:
Definition at line 1587 of file kfileitem.cpp.
◆ name()
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.
- 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
Definition at line 1721 of file kfileitem.cpp.
◆ operator QVariant()
KFileItem::operator QVariant | ( | ) | const |
Converts this KFileItem to a QVariant, this allows to use KFileItem in QVariant() constructor.
Definition at line 1557 of file kfileitem.cpp.
◆ operator!=()
bool KFileItem::operator!= | ( | const KFileItem & | other | ) | const |
Returns true if both items do not share the same URL.
Definition at line 1533 of file kfileitem.cpp.
◆ operator<() [1/2]
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
Definition at line 1538 of file kfileitem.cpp.
◆ operator<() [2/2]
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
Definition at line 1549 of file kfileitem.cpp.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ operator==()
bool KFileItem::operator== | ( | const KFileItem & | other | ) | const |
Returns true if both items share the same URL.
Definition at line 1520 of file kfileitem.cpp.
◆ overlays()
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.
- Returns
- the overlays of the pixmap
Definition at line 1235 of file kfileitem.cpp.
◆ permissions()
mode_t KFileItem::permissions | ( | ) | const |
Returns the permissions of the file (stat.st_mode containing only permissions).
- Returns
- the permissions of the file
Definition at line 1670 of file kfileitem.cpp.
◆ permissionsString()
QString KFileItem::permissionsString | ( | ) | const |
Returns the access permissions for the file as a string.
- Returns
- the access permission as string
Definition at line 1562 of file kfileitem.cpp.
◆ recursiveSize()
KIO::filesize_t KFileItem::recursiveSize | ( | ) | const |
For folders, its recursive size: the size of its files plus the recursiveSize of its folder.
Initially only implemented for trash:/
- Since
- 5.70
- Returns
- The recursive size
Definition at line 819 of file kfileitem.cpp.
◆ refresh()
void KFileItem::refresh | ( | ) |
Throw away and re-read (for local files) all information about the file.
This is called when the file changes.
Definition at line 647 of file kfileitem.cpp.
◆ refreshMimeType()
void KFileItem::refreshMimeType | ( | ) |
Re-reads MIME type information.
This is called when the MIME type database changes.
Definition at line 673 of file kfileitem.cpp.
◆ setDelayedMimeTypes()
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
Definition at line 684 of file kfileitem.cpp.
◆ setLocalPath()
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).
- Parameters
-
path the item's local path
- Since
- 5.20
Definition at line 703 of file kfileitem.cpp.
◆ setName()
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)
- Parameters
-
name the item's name
Definition at line 713 of file kfileitem.cpp.
◆ setUrl()
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).
- Parameters
-
url the item's URL
Definition at line 692 of file kfileitem.cpp.
◆ size()
KIO::filesize_t KFileItem::size | ( | ) | const |
Returns the size of the file, if known.
- Returns
- the file size, or 0 if not known
Definition at line 810 of file kfileitem.cpp.
◆ suffix()
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
Definition at line 1932 of file kfileitem.cpp.
◆ targetUrl()
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.
- Returns
- the target url.
Definition at line 1735 of file kfileitem.cpp.
◆ text()
QString KFileItem::text | ( | ) | const |
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
Definition at line 1712 of file kfileitem.cpp.
◆ time()
QDateTime KFileItem::time | ( | KFileItem::FileTimes | which | ) | const |
Requests the modification, access or creation time, depending on which
.
- Parameters
-
which the timestamp
- Returns
- the time asked for, QDateTime() if not available
- See also
- timeString()
Definition at line 871 of file kfileitem.cpp.
◆ timeString()
QString KFileItem::timeString | ( | KFileItem::FileTimes | which = ModificationTime | ) | const |
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
Definition at line 1578 of file kfileitem.cpp.
◆ url()
QUrl KFileItem::url | ( | ) | const |
Returns the url of the file.
- Returns
- the url of the file
Definition at line 1661 of file kfileitem.cpp.
◆ user()
QString KFileItem::user | ( | ) | const |
Returns the owner of the file.
- Returns
- the file's owner
Definition at line 880 of file kfileitem.cpp.
◆ userId()
int KFileItem::userId | ( | ) | const |
Returns the file's owner's user id.
Available only on supported protocols.
- Since
- 6.0
Definition at line 898 of file kfileitem.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.