KFilePlacesModel Class
Header: | #include <KFilePlacesModel> |
CMake: | find_package(KF6 REQUIRED COMPONENTS KIO) target_link_libraries(mytarget PRIVATE KF6::KIOFileWidgets) |
Inherits: | QAbstractItemModel |
Note: All functions in this class are reentrant.
Public Types
enum | AdditionalRoles { UrlRole, HiddenRole, SetupNeededRole, FixedDeviceRole, CapacityBarRecommendedRole, …, DeviceAccessibilityRole } |
enum | DeviceAccessibility { SetupNeeded, SetupInProgress, Accessible, TeardownInProgress } |
(since 5.42) enum | GroupType { PlacesType, RemoteType, RecentlySavedType, SearchForType, DevicesType, …, TagsType } |
Properties
- supportedSchemes : QStringList
Public Functions
KFilePlacesModel(QObject *parent = nullptr) | |
void | addPlace(const QString &text, const QUrl &url, const QString &iconName = QString(), const QString &appName = QString()) |
void | addPlace(const QString &text, const QUrl &url, const QString &iconName, const QString &appName, const QModelIndex &after) |
KBookmark | bookmarkForIndex(const QModelIndex &index) const |
(since 5.63) KBookmark | bookmarkForUrl(const QUrl &searchUrl) const |
QModelIndex | closestItem(const QUrl &url) const |
(since 5.99) KFilePlacesModel::DeviceAccessibility | deviceAccessibility(const QModelIndex &index) const |
Solid::Device | deviceForIndex(const QModelIndex &index) const |
void | editPlace(const QModelIndex &index, const QString &text, const QUrl &url, const QString &iconName = QString(), const QString &appName = QString()) |
QAction * | ejectActionForIndex(const QModelIndex &index) const |
(since 5.42) QModelIndexList | groupIndexes(const KFilePlacesModel::GroupType type) const |
(since 5.42) KFilePlacesModel::GroupType | groupType(const QModelIndex &index) const |
int | hiddenCount() const |
QIcon | icon(const QModelIndex &index) const |
bool | isDevice(const QModelIndex &index) const |
(since 5.94) bool | isEjectAllowed(const QModelIndex &index) const |
(since 5.42) bool | isGroupHidden(const KFilePlacesModel::GroupType type) const |
(since 5.42) bool | isGroupHidden(const QModelIndex &index) const |
bool | isHidden(const QModelIndex &index) const |
(since 5.91) bool | isTeardownAllowed(const QModelIndex &index) const |
(since 5.95) bool | isTeardownOverlayRecommended(const QModelIndex &index) const |
(since 5.41) bool | movePlace(int itemRow, int row) |
QAction * | partitionActionForIndex(const QModelIndex &index) const |
(since 5.41) void | refresh() const |
void | removePlace(const QModelIndex &index) const |
void | requestEject(const QModelIndex &index) |
void | requestSetup(const QModelIndex &index) |
void | requestTeardown(const QModelIndex &index) |
(since 5.42) void | setGroupHidden(const KFilePlacesModel::GroupType type, bool hidden) |
void | setPlaceHidden(const QModelIndex &index, bool hidden) |
(since 5.43) void | setSupportedSchemes(const QStringList &schemes) |
bool | setupNeeded(const QModelIndex &index) const |
(since 5.43) QStringList | supportedSchemes() const |
QAction * | teardownActionForIndex(const QModelIndex &index) const |
QString | text(const QModelIndex &index) const |
QUrl | url(const QModelIndex &index) const |
Signals
void | errorMessage(const QString &message) |
(since 5.42) void | groupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden) |
(since 5.71) void | reloaded() |
void | setupDone(const QModelIndex &index, bool success) |
(since 5.94) void | supportedSchemesChanged() |
(since 5.100) void | teardownDone(const QModelIndex &index, Solid::ErrorType error, const QVariant &errorData) |
Static Public Members
(since 5.41) QUrl | convertedUrl(const QUrl &url) |
Detailed Description
This class is a list view model. Each entry represents a "place" where user can access files. Only relevant when used with QListView or QTableView.
Member Type Documentation
enum KFilePlacesModel::AdditionalRoles
Constant | Value | Description |
---|---|---|
KFilePlacesModel::UrlRole | 0x069CD12B | roleName is "url". See url() |
KFilePlacesModel::HiddenRole | 0x0741CAAC | roleName is "isHidden". See isHidden() |
KFilePlacesModel::SetupNeededRole | 0x059A935D | roleName is "isSetupNeeded". See setupNeeded() |
KFilePlacesModel::FixedDeviceRole | 0x332896C1 | Whether the place is a fixed device (neither hotpluggable nor removable). roleName is "isFixedDevice". |
KFilePlacesModel::CapacityBarRecommendedRole | 0x1548C5C4 | Whether the place should have its free space displayed in a capacity bar. roleName is "isCapacityBarRecommended". |
KFilePlacesModel::GroupRole (since Qt 5.40) | 0x0a5b64ee | The name of the group, for example "Remote" or "Devices". roleName is "group". |
KFilePlacesModel::IconNameRole (since Qt 5.41) | 0x00a45c00 | roleName is "iconName". See icon(). |
KFilePlacesModel::GroupHiddenRole (since Qt 5.42) | 0x21a4b936 | roleName is "isGroupHidden". |
KFilePlacesModel::TeardownAllowedRole (since Qt 5.91) | 0x02533364 | roleName is "isTeardownAllowed". |
KFilePlacesModel::EjectAllowedRole (since Qt 5.94) | 0x0A16AC5B | roleName is "isEjectAllowed". |
KFilePlacesModel::TeardownOverlayRecommendedRole (since Qt 5.95) | 0x032EDCCE | roleName is "isTeardownOverlayRecommended". |
KFilePlacesModel::DeviceAccessibilityRole (since Qt 5.99) | 0x023FFD93 | roleName is "deviceAccessibility". |
enum KFilePlacesModel::DeviceAccessibility
Constant | Value |
---|---|
KFilePlacesModel::SetupNeeded | 0 |
KFilePlacesModel::SetupInProgress | 1 |
KFilePlacesModel::Accessible | 2 |
KFilePlacesModel::TeardownInProgress | 3 |
[since 5.42]
enum KFilePlacesModel::GroupType
Describes the available group types used in this model.
Constant | Value | Description |
---|---|---|
KFilePlacesModel::PlacesType | 0 | "Places" section |
KFilePlacesModel::RemoteType | 1 | "Remote" section |
KFilePlacesModel::RecentlySavedType | 2 | "Recent" section |
KFilePlacesModel::SearchForType | 3 | "Search for" section |
KFilePlacesModel::DevicesType | 4 | "Devices" section |
KFilePlacesModel::RemovableDevicesType | 5 | "Removable Devices" section |
KFilePlacesModel::UnknownType | 6 | Unknown GroupType |
KFilePlacesModel::TagsType (since Qt 5.54) | 7 | "Tags" section |
This enum was introduced in 5.42.
Property Documentation
supportedSchemes : QStringList
Access functions:
QStringList | supportedSchemes() const |
void | setSupportedSchemes(const QStringList &schemes) |
Notifier signal:
void | supportedSchemesChanged() |
Member Function Documentation
[explicit]
KFilePlacesModel::KFilePlacesModel(QObject *parent = nullptr)
[invokable]
void KFilePlacesModel::addPlace(const QString &text, const QUrl &url, const QString &iconName = QString(), const QString &appName = QString())
Adds a new place to the model.
text The user-visible text for the place
url The URL of the place. It will be stored in its QUrl::FullyEncoded string format.
iconName The icon of the place
appName If set as the value of QCoreApplication::applicationName(), will make the place visible only in this application.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable]
void KFilePlacesModel::addPlace(const QString &text, const QUrl &url, const QString &iconName, const QString &appName, const QModelIndex &after)
Adds a new place to the model. text The user-visible text for the place
url The URL of the place. It will be stored in its QUrl::FullyEncoded string format.
iconName The icon of the place
appName If set as the value of QCoreApplication::applicationName(), will make the place visible only in this application.
after The index after which the new place will be added.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
KBookmark KFilePlacesModel::bookmarkForIndex(const QModelIndex &index) const
Returns The KBookmark instance of the place at index index. If the index is not valid, a default KBookmark instance is returned.
[since 5.63]
KBookmark KFilePlacesModel::bookmarkForUrl(const QUrl &searchUrl) const
Returns The KBookmark instance of the place with url searchUrl. If the bookmark corresponding to searchUrl is not found, a default KBookmark instance is returned.
This function was introduced in 5.63.
QModelIndex KFilePlacesModel::closestItem(const QUrl &url) const
Returns the closest item for the URL url. The closest item is defined as item which is equal to the URL or at least is a parent URL. If there are more than one possible parent URL candidates, the item which covers the bigger range of the URL is returned.
Example: the url is '/home/peter/Documents/Music'. Available items are: - /home/peter - /home/peter/Documents
The returned item will the one for '/home/peter/Documents'.
[static, since 5.41]
QUrl KFilePlacesModel::convertedUrl(const QUrl &url)
Converts the URL, which contains "virtual" URLs for system-items like "timeline:/lastmonth" into a Query-URL "timeline:/2017-10" that will be handled by the corresponding KIO worker. Virtual URLs for bookmarks are used to be independent from internal format changes.
an url
Returns the converted URL, which can be handled by a KIO worker
This function was introduced in 5.41.
[invokable, since 5.99]
KFilePlacesModel::DeviceAccessibility KFilePlacesModel::deviceAccessibility(const QModelIndex &index) const
Returns Whether this device is currently accessible or being (un)mounted.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.99.
Solid::Device KFilePlacesModel::deviceForIndex(const QModelIndex &index) const
Returns The solid device of the place at index index, if it is a device. Otherwise a default Solid::Device() instance is returned.
See also isDevice().
[invokable]
void KFilePlacesModel::editPlace(const QModelIndex &index, const QString &text, const QUrl &url, const QString &iconName = QString(), const QString &appName = QString())
Edits the place with index index.
text The new user-visible text for the place
url The new URL of the place
iconName The new icon of the place
appName The new application-local filter for the place (
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also addPlace() and ).
[invokable]
QAction *KFilePlacesModel::ejectActionForIndex(const QModelIndex &index) const
Returns A QAction with a proper translated label that can be used to trigger the requestEject() method for the place at index index.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also requestEject().
[signal]
void KFilePlacesModel::errorMessage(const QString &message)
message An error message explaining what went wrong.
[signal, since 5.42]
void KFilePlacesModel::groupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden)
Emitted whenever the visibility of the group group changes.
hidden The new visibility of the group.
This function was introduced in 5.42.
See also setGroupHidden().
[invokable, since 5.42]
QModelIndexList KFilePlacesModel::groupIndexes(const KFilePlacesModel::GroupType type) const
Returns The list of model indexes that have @ type as their group type.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.42.
See also groupType().
[invokable, since 5.42]
KFilePlacesModel::GroupType KFilePlacesModel::groupType(const QModelIndex &index) const
Returns The group type of the place at index index.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.42.
[invokable]
int KFilePlacesModel::hiddenCount() const
Returns the number of hidden places in the model.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also isHidden().
[invokable]
QIcon KFilePlacesModel::icon(const QModelIndex &index) const
Returns The icon of the place at index index.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable]
bool KFilePlacesModel::isDevice(const QModelIndex &index) const
Returns Whether the place at index index is a device handled by Solid.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also deviceForIndex().
[invokable, since 5.94]
bool KFilePlacesModel::isEjectAllowed(const QModelIndex &index) const
Returns Whether the place is a device that can be ejected, e.g. it is a CD, DVD, etc.
It does not indicate whether the eject can succeed.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.94.
[invokable, since 5.42]
bool KFilePlacesModel::isGroupHidden(const KFilePlacesModel::GroupType type) const
Returns Whether the group type type is hidden.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.42.
[invokable, since 5.42]
bool KFilePlacesModel::isGroupHidden(const QModelIndex &index) const
Returns Whether the group of the place at index index is hidden.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.42.
[invokable]
bool KFilePlacesModel::isHidden(const QModelIndex &index) const
Returns Whether the place at index index is hidden or is inside an hidden group.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable, since 5.91]
bool KFilePlacesModel::isTeardownAllowed(const QModelIndex &index) const
Returns Whether the place is a device that can be unmounted, e.g. it is mounted but does not point at system Root or the user's Home directory.
It does not indicate whether the teardown can succeed.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.91.
[invokable, since 5.95]
bool KFilePlacesModel::isTeardownOverlayRecommended(const QModelIndex &index) const
Returns Whether showing an inline teardown button is recommended, e.g. when it is a removable drive.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.95.
[invokable, since 5.41]
bool KFilePlacesModel::movePlace(int itemRow, int row)
Move place at itemRow to a position before row
Returns whether the place has been moved.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.41.
[invokable]
QAction *KFilePlacesModel::partitionActionForIndex(const QModelIndex &index) const
Returns A QAction with a proper translated label that can be used to open a partitioning menu for the device. nullptr if not a device.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable, since 5.41]
void KFilePlacesModel::refresh() const
Reload bookmark information
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.41.
[signal, since 5.71]
void KFilePlacesModel::reloaded()
Called once the model has been reloaded
This function was introduced in 5.71.
[invokable]
void KFilePlacesModel::removePlace(const QModelIndex &index) const
Deletes the place with index index from the model.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable]
void KFilePlacesModel::requestEject(const QModelIndex &index)
Ejects the place at index index by triggering the eject functionality of its Solid device.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also deviceForIndex().
[invokable]
void KFilePlacesModel::requestSetup(const QModelIndex &index)
Mounts the place at index index by triggering the setup functionality of its Solid device.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also deviceForIndex().
[invokable]
void KFilePlacesModel::requestTeardown(const QModelIndex &index)
Unmounts the place at index index by triggering the teardown functionality of its Solid device.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also deviceForIndex().
[invokable, since 5.42]
void KFilePlacesModel::setGroupHidden(const KFilePlacesModel::GroupType type, bool hidden)
Changes the visibility of the group with type type.
hidden Whether the group should be hidden or visible.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.42.
See also isGroupHidden().
[invokable]
void KFilePlacesModel::setPlaceHidden(const QModelIndex &index, bool hidden)
Changes the visibility of the place with index index, but only if the place is not inside an hidden group.
hidden Whether the place should be hidden or visible.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also isGroupHidden().
[since 5.43]
void KFilePlacesModel::setSupportedSchemes(const QStringList &schemes)
Set the URL schemes that the file widget should allow navigating to.
If the returned list is empty, all schemes are supported. Examples for schemes are "file" or "ftp".
Note: Setter function for property supportedSchemes.
This function was introduced in 5.43.
See also supportedSchemes() and QFileDialog::setSupportedSchemes.
[signal]
void KFilePlacesModel::setupDone(const QModelIndex &index, bool success)
Emitted after the Solid setup ends.
success Whether the Solid setup has been successful.
See also requestSetup().
[invokable]
bool KFilePlacesModel::setupNeeded(const QModelIndex &index) const
Returns Whether the place at index index needs to be mounted before it can be used.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[since 5.43]
QStringList KFilePlacesModel::supportedSchemes() const
Returns the URL schemes that the file widget should allow navigating to.
If the returned list is empty, all schemes are supported.
Note: Getter function for property supportedSchemes.
This function was introduced in 5.43.
See also setSupportedSchemes() and QFileDialog::supportedSchemes.
[signal, since 5.94]
void KFilePlacesModel::supportedSchemesChanged()
Emitted whenever the list of supported schemes has been changed
Note: Notifier signal for property supportedSchemes.
This function was introduced in 5.94.
[invokable]
QAction *KFilePlacesModel::teardownActionForIndex(const QModelIndex &index) const
Returns A QAction with a proper translated label that can be used to trigger the requestTeardown() method for the place at index index.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also requestTeardown().
[signal, since 5.100]
void KFilePlacesModel::teardownDone(const QModelIndex &index, Solid::ErrorType error, const QVariant &errorData)
Emitted after the teardown of a device ends.
Note: In case of an error, the errorMessage signal will also be emitted with a message describing the error.
error Type of error that occurred, if any.
errorData More information about the error, if any.
This function was introduced in 5.100.
[invokable]
QString KFilePlacesModel::text(const QModelIndex &index) const
Returns The user-visible text of the place at index index.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable]
QUrl KFilePlacesModel::url(const QModelIndex &index) const
Returns The URL of the place at index index.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.