KFileItemActions Class
Header: | #include <KFileItemActions> |
CMake: | find_package(KF6 REQUIRED COMPONENTS KIO) target_link_libraries(mytarget PRIVATE KF6::KIOWidgets) |
Inherits: | QObject |
Public Types
enum class | MenuActionSource { Services, Plugins, All } |
flags | MenuActionSources |
Public Functions
KFileItemActions(QObject *parent = nullptr) | |
(since 5.77) void | addActionsTo(QMenu *menu, KFileItemActions::MenuActionSources sources = MenuActionSource::All, const QList<QAction *> &additionalActions = {}, const QStringList &excludeList = {}) |
(since 5.82) void | insertOpenWithActionsTo(QAction *before, QMenu *topMenu, const QStringList &excludedDesktopEntryNames) |
void | setItemListProperties(const KFileItemListProperties &itemList) |
void | setParentWidget(QWidget *widget) |
Public Slots
(since 5.83) void | runPreferredApplications(const KFileItemList &fileOpenList) |
Signals
(since 5.82) void | error(const QString &errorMessage) |
(since 4.8.2) void | openWithDialogAboutToBeShown() |
Static Public Members
(since 5.83) KService::List | associatedApplications(const QStringList &mimeTypeList) |
Detailed Description
This class creates and handles the actions for a url (or urls) in a popupmenu.
This includes:
- "open with <application>" actions, but also
- user-defined actions for a .desktop file, defined in the file itself (see the desktop entry standard)
- servicemenus actions, defined in .desktop files and selected based on the MIME type of the url
KFileItemActions respects Kiosk-based restrictions (see the KAuthorized namespace in the KConfig framework). In particular, the "action/openwith" action is checked when determining actions for opening files (see addOpenWithActionsTo()) and service-specific actions are checked before adding service actions to a menu (see addServiceActionsTo()).
For user-defined actions in a .desktop file, the "X-KDE-AuthorizeAction" key can be used to determine which actions are checked before the user-defined action is allowed. The action is ignored if any of the listed actions are not authorized.
Note: The builtin services like mount/unmount for old-style device desktop files (which mainly concerns CDROM and Floppy drives) have been deprecated since 5.82; those menu entries were hidden long before that, since the FSDevice .desktop template file hadn't been installed for quite a while.
Member Type Documentation
enum class KFileItemActions::MenuActionSource
flags KFileItemActions::MenuActionSources
Constant | Value | Description |
---|---|---|
KFileItemActions::MenuActionSource::Services | 0x1 | Add user defined actions and servicemenu actions (this used to include builtin actions, which have been deprecated since 5.82 see class API documentation) |
KFileItemActions::MenuActionSource::Plugins | 0x2 | Add actions implemented by plugins. See KAbstractFileItemActionPlugin base class |
KFileItemActions::MenuActionSource::All | Services | Plugins |
The MenuActionSources type is a typedef for QFlags<MenuActionSource>. It stores an OR combination of MenuActionSource values.
Member Function Documentation
KFileItemActions::KFileItemActions(QObject *parent = nullptr)
Creates a KFileItemActions instance. Note that this instance must stay alive for at least as long as the popupmenu; it has the slots for the actions created by addOpenWithActionsTo/addServiceActionsTo.
[since 5.77]
void KFileItemActions::addActionsTo(QMenu *menu, KFileItemActions::MenuActionSources sources = MenuActionSource::All, const QList<QAction *> &additionalActions = {}, const QStringList &excludeList = {})
This methods adds additional actions to the menu.
menu Menu to which the actions/submenus will be added.
sources sources from which the actions should be fetched. By default all sources are used.
additionalActions additional actions that should be added to the "Actions" submenu or top level menu if there are less than three entries in total.
excludeList list of action names or plugin ids that should be excluded
This function was introduced in 5.77.
[static, since 5.83]
KService::List KFileItemActions::associatedApplications(const QStringList &mimeTypeList)
Returns the applications associated with all the given MIME types.
This is basically a KApplicationTrader::query, but it supports multiple MIME types, and also cleans up "apparent" duplicates, such as different versions of the same application installed in parallel.
The list is sorted according to the user preferences for the given MIME type(s). In case multiple MIME types appear in the URL list, the logic is: applications that on average appear earlier on the associated applications list for the given MIME types also appear earlier on the final applications list.
Note that for a single MIME type there is no need to use this, you should use KApplicationTrader instead, e.g. query() or preferredService().
This will return an empty list if the "openwith" Kiosk action is not authorized (see KAuthorized::authorize()).
mimeTypeList the MIME types
Returns the sorted list of services.
This function was introduced in 5.83.
[signal, since 5.82]
void KFileItemActions::error(const QString &errorMessage)
Forwards the errors from the KAbstractFileItemActionPlugin instances
This function was introduced in 5.82.
[since 5.82]
void KFileItemActions::insertOpenWithActionsTo(QAction *before, QMenu *topMenu, const QStringList &excludedDesktopEntryNames)
Generates the "Open With <Application>" actions, and inserts them in menu, before action before. If before is nullptr or doesn't exist in the menu the actions will be appended to the menu.
All actions are created as children of the menu.
No actions will be added if the "openwith" Kiosk action is not authorized (see KAuthorized::authorize()).
before the "open with" actions will be inserted before this action; if this action is nullptr or isn't available in topMenu, the "open with" actions will be appended
menu the QMenu where the actions will be added
excludedDesktopEntryNames list of desktop entry names that will not be shown
This function was introduced in 5.82.
[signal, since 4.8.2]
void KFileItemActions::openWithDialogAboutToBeShown()
Emitted before the "Open With" dialog is shown This is used e.g in folderview to close the folder peek popups on invoking the "Open With" menu action
This function was introduced in 4.8.2.
[slot, since 5.83]
void KFileItemActions::runPreferredApplications(const KFileItemList &fileOpenList)
Slot used to execute a list of files in their respective preferred application.
fileOpenList the list of KFileItems to open.
This function was introduced in 5.83.
void KFileItemActions::setItemListProperties(const KFileItemListProperties &itemList)
Sets all the data for the next instance of the popupmenu.
See also KFileItemListProperties.
void KFileItemActions::setParentWidget(QWidget *widget)
Set the parent widget for any dialogs being shown.
This should normally be your mainwindow, not a popup menu, so that it still exists even after the popup is closed (e.g. error message from KRun) and so that QAction::setStatusTip can find a statusbar, too.