• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

Public Types | Public Member Functions | Friends

KFileItem Class Reference

A KFileItem is a generic class to handle a file, local or remote. More...

#include <kfileitem.h>

List of all members.

Public Types

enum  { Unknown = static_cast<mode_t>(-1) }
enum  FileTimes { ModificationTime = 0, AccessTime = 1, CreationTime = 2 }

Public Member Functions

 KFileItem ()
 KFileItem (const KIO::UDSEntry &entry, const KUrl &itemOrDirUrl, bool delayedMimeTypes=false, bool urlIsDirectory=false)
 KFileItem (const KUrl &url, const QString &mimeType, mode_t mode)
 KFileItem (const KFileItem &other)
 KFileItem (mode_t mode, mode_t permissions, const KUrl &url, bool delayedMimeTypes=false)
 ~KFileItem ()
bool acceptsDrops () const
KACL ACL () const
void assign (const KFileItem &item)
bool cmp (const KFileItem &item) const
QString comment () const
KACL defaultACL () const
KMimeType::Ptr determineMimeType () const
KIO::UDSEntry entry () const
const void * extraData (const void *key) const
QString getStatusBarInfo () const
QString getToolTipText (int maxcount=6) const
QString group () const
bool hasExtendedACL () const
QString iconName () const
bool isDesktopFile () const
bool isDir () const
bool isFile () const
bool isHidden () const
bool isLink () const
bool isLocalFile () const
bool isMarked () const
bool isMimeTypeKnown () const
bool isNull () const
bool isReadable () const
bool isRegularFile () const
bool isWritable () const
QString linkDest () const
QString localPath () const
void mark ()
KFileMetaInfo metaInfo (bool autoget=true, int what=KFileMetaInfo::ContentInfo|KFileMetaInfo::TechnicalInfo) const
QString mimeComment () const
QString mimetype () const
KMimeType::Ptr mimeTypePtr () const
mode_t mode () const
KUrl mostLocalUrl () const
KUrl mostLocalUrl (bool &local) const
QString name (bool lowerCase=false) const
KUrl nepomukUri () const
 operator QVariant () const
bool operator!= (const KFileItem &other) const
KFileItem & operator= (const KFileItem &other)
bool operator== (const KFileItem &other) const
QStringList overlays () const
mode_t permissions () const
QString permissionsString () const
QPixmap pixmap (int _size, int _state=0) const
void refresh ()
void refreshMimeType ()
void removeExtraData (const void *key)
void run (QWidget *parentWidget=0) const
void setExtraData (const void *key, void *value)
void setMetaInfo (const KFileMetaInfo &info) const
void setName (const QString &name)
void setUDSEntry (const KIO::UDSEntry &entry, const KUrl &url, bool delayedMimeTypes=false, bool urlIsDirectory=false)
void setUrl (const KUrl &url)
KIO::filesize_t size () const
KUrl targetUrl () const
QString text () const
KDateTime time (FileTimes which) const
time_t time (unsigned int which) const
QString timeString (FileTimes which=ModificationTime) const
QString timeString (unsigned int which) const
void unmark ()
KUrl url () const
QString user () const

Friends

QDataStream & operator<< (QDataStream &s, const KFileItem &a)
QDataStream & operator>> (QDataStream &s, KFileItem &a)

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.

Definition at line 45 of file kfileitem.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
Unknown 

Definition at line 48 of file kfileitem.h.

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
Enumerator:
ModificationTime 
AccessTime 
CreationTime 

Definition at line 56 of file kfileitem.h.


Constructor & Destructor Documentation

KFileItem::KFileItem ( )

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

Definition at line 468 of file kfileitem.cpp.

KFileItem::KFileItem ( const KIO::UDSEntry &  entry,
const KUrl &  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:
entrythe KIO entry used to get the file, contains info about it
itemOrDirUrlthe URL of the item or of the directory containing this item (see urlIsDirectory).
delayedMimeTypesspecifies if the mimetype of the given URL should be determined immediately or on demand. See the bool delayedMimeTypes in the KDirLister constructor.
urlIsDirectoryspecifies 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 473 of file kfileitem.cpp.

KFileItem::KFileItem ( mode_t  mode,
mode_t  permissions,
const KUrl &  url,
bool  delayedMimeTypes = false 
)

Creates an item representing a file, from all the necessary info for it.

Parameters:
modethe file mode (according to stat() (e.g. S_IFDIR...) Set to KFileItem::Unknown if unknown. For local files, KFileItem will use stat().
permissionsthe 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.
urlthe file url
delayedMimeTypesspecify if the mimetype of the given URL should be determined immediately or on demand

Definition at line 480 of file kfileitem.cpp.

KFileItem::KFileItem ( const KUrl &  url,
const QString &  mimeType,
mode_t  mode 
)

Creates an item representing a file, for which the mimetype is already known.

Parameters:
urlthe file url
mimeTypethe name of the file's mimetype
modethe mode (S_IFDIR...)

Definition at line 486 of file kfileitem.cpp.

KFileItem::KFileItem ( const KFileItem &  other)

Copy constructor.

Definition at line 496 of file kfileitem.cpp.

KFileItem::~KFileItem ( )

Destructs the KFileItem.

Extra data set via setExtraData() is not deleted.

Definition at line 501 of file kfileitem.cpp.


Member Function Documentation

bool KFileItem::acceptsDrops ( ) const

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.

Definition at line 1022 of file kfileitem.cpp.

KACL KFileItem::ACL ( ) const

Returns the access control list for the file.

Returns:
the access control list as a KACL

Definition at line 585 of file kfileitem.cpp.

void KFileItem::assign ( const KFileItem &  item)
Deprecated:
simply use '='

Definition at line 1272 of file kfileitem.cpp.

bool KFileItem::cmp ( const KFileItem &  item) const

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:
itemthe item to compare
Returns:
true if all values are equal

Definition at line 1153 of file kfileitem.cpp.

QString KFileItem::comment ( ) const

A comment which can contain anything - even rich text.

It will simply be displayed to the user as is.

Since:
4.6

Definition at line 885 of file kfileitem.cpp.

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 597 of file kfileitem.cpp.

KMimeType::Ptr KFileItem::determineMimeType ( ) const

Returns the mimetype of the file item.

If delayedMimeTypes was used in the constructor, this will determine the mimetype first.

Returns:
the mime type

Definition at line 694 of file kfileitem.cpp.

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 1422 of file kfileitem.cpp.

const void * KFileItem::extraData ( const void *  key) const

Retrieves the extra data with the given key.

Parameters:
keythe key of the extra data
Returns:
the extra data associated to an item with key via setExtraData. 0L if nothing was associated with key.
See also:
extraData
Deprecated:
use model/view (KDirModel) and you won't need this anymore

Definition at line 1213 of file kfileitem.cpp.

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 1044 of file kfileitem.cpp.

QString KFileItem::getToolTipText ( int  maxcount = 6) const

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:
maxcountthe maximum number of entries shown
Returns:
the tool tip string

Definition at line 1072 of file kfileitem.cpp.

QString KFileItem::group ( ) const

Returns the group of the file.

Returns:
the file's group

Definition at line 655 of file kfileitem.cpp.

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 579 of file kfileitem.cpp.

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 771 of file kfileitem.cpp.

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.
Since:
4.1

Definition at line 1506 of file kfileitem.cpp.

bool KFileItem::isDir ( ) const

Returns true if this item represents a directory.

Returns:
true if the item is a directory

Definition at line 1006 of file kfileitem.cpp.

bool KFileItem::isFile ( ) const

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

Returns:
true if the item is a file

Definition at line 1016 of file kfileitem.cpp.

bool KFileItem::isHidden ( ) const

Checks whether the file is hidden.

Returns:
true if the file is hidden.

Definition at line 993 of file kfileitem.cpp.

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 1338 of file kfileitem.cpp.

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 1343 of file kfileitem.cpp.

bool KFileItem::isMarked ( ) const

Used when updating a directory.

marked == seen when refreshing.

Returns:
true if the file item is marked

Definition at line 1427 of file kfileitem.cpp.

bool KFileItem::isMimeTypeKnown ( ) const
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.

Definition at line 710 of file kfileitem.cpp.

bool KFileItem::isNull ( ) const

Return true if default-constructed.

Definition at line 1448 of file kfileitem.cpp.

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 943 of file kfileitem.cpp.

bool KFileItem::isRegularFile ( ) const

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

Since:
4.3

Definition at line 1511 of file kfileitem.cpp.

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 970 of file kfileitem.cpp.

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 543 of file kfileitem.cpp.

QString KFileItem::localPath ( ) const

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

Definition at line 564 of file kfileitem.cpp.

void KFileItem::mark ( )

Marks the item.

See also:
isMarked()

Definition at line 1432 of file kfileitem.cpp.

KFileMetaInfo KFileItem::metaInfo ( bool  autoget = true,
int  what = KFileMetaInfo::ContentInfo | KFileMetaInfo::TechnicalInfo 
) const

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:
autogetif true, the metainfo will automatically be created
whathow much metainfo you need to retrieve from the file (KFileMetaInfo::WhatFlag)

Definition at line 1260 of file kfileitem.cpp.

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 718 of file kfileitem.cpp.

QString KFileItem::mimetype ( ) const

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

Definition at line 688 of file kfileitem.cpp.

KMimeType::Ptr KFileItem::mimeTypePtr ( ) const

Returns the currently known mimetype of the file item.

This will not try to determine the mimetype if unknown.

Returns:
the known mime type

Definition at line 1402 of file kfileitem.cpp.

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 1333 of file kfileitem.cpp.

KUrl KFileItem::mostLocalUrl ( ) const

Tries to give a local URL for this file item if possible.

Since:
4.6

Definition at line 1296 of file kfileitem.cpp.

KUrl KFileItem::mostLocalUrl ( bool &  local) const

Tries to give a local URL for this file item if possible.

The given boolean indicates if the returned url is local or not.

Definition at line 1278 of file kfileitem.cpp.

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:
lowerCaseif 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 1353 of file kfileitem.cpp.

KUrl KFileItem::nepomukUri ( ) const

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

Definition at line 1372 of file kfileitem.cpp.

KFileItem::operator QVariant ( ) const

Converts this KFileItem to a QVariant, this allows to use KFileItem in QVariant() constructor.

Definition at line 1197 of file kfileitem.cpp.

bool KFileItem::operator!= ( const KFileItem &  other) const

Definition at line 1164 of file kfileitem.cpp.

KFileItem & KFileItem::operator= ( const KFileItem &  other)

Assignment operator.

Definition at line 1442 of file kfileitem.cpp.

bool KFileItem::operator== ( const KFileItem &  other) const

Definition at line 1158 of file kfileitem.cpp.

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 829 of file kfileitem.cpp.

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 1328 of file kfileitem.cpp.

QString KFileItem::permissionsString ( ) const

Returns the access permissions for the file as a string.

Returns:
the access persmission as string

Definition at line 1226 of file kfileitem.cpp.

QPixmap KFileItem::pixmap ( int  _size,
int  _state = 0 
) const

Returns a pixmap representing the file.

Parameters:
_sizeSize for the pixmap in pixels. Zero will return the globally configured default size.
_stateThe state of the icon: KIconLoader::DefaultState, KIconLoader::ActiveState or KIconLoader::DisabledState.
Returns:
the pixmap

Definition at line 891 of file kfileitem.cpp.

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 505 of file kfileitem.cpp.

void KFileItem::refreshMimeType ( )

Re-reads mimetype information.

This is called when the mimetype database changes.

Definition at line 521 of file kfileitem.cpp.

void KFileItem::removeExtraData ( const void *  key)

Removes the extra data associated with an item via key.

Parameters:
keythe key of the extra data to remove
Deprecated:
use model/view (KDirModel) and you won't need this anymore

Definition at line 1220 of file kfileitem.cpp.

void KFileItem::run ( QWidget *  parentWidget = 0) const

Let's "KRun" this file ! (e.g.

when file is clicked or double-clicked or return is pressed)

Definition at line 1148 of file kfileitem.cpp.

void KFileItem::setExtraData ( const 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:
keythe key of the extra data
valuethe value of the extra data
See also:
extraData
removeExtraData
Deprecated:
use model/view (KDirModel) and you won't need this anymore

Definition at line 1203 of file kfileitem.cpp.

void KFileItem::setMetaInfo ( const KFileMetaInfo &  info) const

Sets the metainfo of this item to info.

Made const to avoid deep copy.

Parameters:
infothe new meta info

Definition at line 1255 of file kfileitem.cpp.

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:
namethe item's name

Definition at line 534 of file kfileitem.cpp.

void KFileItem::setUDSEntry ( const KIO::UDSEntry &  entry,
const KUrl &  url,
bool  delayedMimeTypes = false,
bool  urlIsDirectory = false 
)

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:
entrythe UDSEntry to assign to this KFileItem
urlthe file url
delayedMimeTypesspecifies if the mimetype of the given URL should be determined immediately or on demand
urlIsDirectoryspecifies 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?

Definition at line 1170 of file kfileitem.cpp.

void KFileItem::setUrl ( const 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:
urlthe item's URL

Definition at line 528 of file kfileitem.cpp.

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 574 of file kfileitem.cpp.

KUrl KFileItem::targetUrl ( ) const

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

Definition at line 1363 of file kfileitem.cpp.

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 1348 of file kfileitem.cpp.

time_t KFileItem::time ( unsigned int  which) const

Definition at line 613 of file kfileitem.cpp.

KDateTime KFileItem::time ( FileTimes  which) const

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

Parameters:
whichthe timestamp
Returns:
the time asked for, (time_t)0 if not available
See also:
timeString()

Definition at line 607 of file kfileitem.cpp.

QString KFileItem::timeString ( FileTimes  which = ModificationTime) const

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

Parameters:
whichthe timestamp
Returns:
a formatted string of the requested time.
See also:
time

Definition at line 1235 of file kfileitem.cpp.

QString KFileItem::timeString ( unsigned int  which) const

Definition at line 1241 of file kfileitem.cpp.

void KFileItem::unmark ( )

Unmarks the item.

See also:
isMarked()

Definition at line 1437 of file kfileitem.cpp.

KUrl KFileItem::url ( ) const

Returns the url of the file.

Returns:
the url of the file

Definition at line 1323 of file kfileitem.cpp.

QString KFileItem::user ( ) const

Returns the owner of the file.

Returns:
the file's owner

Definition at line 627 of file kfileitem.cpp.


Friends And Related Function Documentation

QDataStream& operator<< ( QDataStream &  s,
const KFileItem &  a 
) [friend]

Definition at line 1302 of file kfileitem.cpp.

QDataStream& operator>> ( QDataStream &  s,
KFileItem &  a 
) [friend]

Definition at line 1312 of file kfileitem.cpp.


The documentation for this class was generated from the following files:
  • kfileitem.h
  • kfileitem.cpp

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal