KFileItemActions

Search for usage in LXR

#include <KFileItemActions>

Inheritance diagram for KFileItemActions:

Public Types

enum  MenuActionSource { MenuActionSource::Services = 0x1, MenuActionSource::Plugins = 0x2, All = Services | Plugins }
 
typedef QFlags< MenuActionSourceMenuActionSources
 

Signals

void error (const QString &errorMessage)
 
void openWithDialogAboutToBeShown ()
 

Public Slots

void runPreferredApplications (const KFileItemList &fileOpenList)
 
void runPreferredApplications (const KFileItemList &fileOpenList, const QString &traderConstraint)
 

Public Member Functions

 KFileItemActions (QObject *parent=nullptr)
 
 ~KFileItemActions () override
 
void addActionsTo (QMenu *menu, MenuActionSources sources=MenuActionSource::All, const QList< QAction * > &additionalActions={}, const QStringList &excludeList={})
 
void addOpenWithActionsTo (QMenu *menu, const QString &traderConstraint=QString())
 
int addPluginActionsTo (QMenu *menu)
 
int addServiceActionsTo (QMenu *menu)
 
void insertOpenWithActionsTo (QAction *before, QMenu *topMenu, const QString &traderConstraint)
 
void insertOpenWithActionsTo (QAction *before, QMenu *topMenu, const QStringList &excludedDesktopEntryNames)
 
QActionpreferredOpenWithAction (const QString &traderConstraint)
 
void setItemListProperties (const KFileItemListProperties &itemList)
 
void setParentWidget (QWidget *widget)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static KService::List associatedApplications (const QStringList &mimeTypeList)
 
static KService::List associatedApplications (const QStringList &mimeTypeList, const QString &traderConstraint)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

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.
Since
4.3

Definition at line 50 of file kfileitemactions.h.

Member Enumeration Documentation

◆ MenuActionSource

Enumerator
Services 

Add user defined actions and servicemenu actions (this used to include builtin actions, which have been deprecated since 5.82 see class API documentation)

Plugins 

Add actions implemented by plugins. See KAbstractFileItemActionPlugin base class.

Definition at line 258 of file kfileitemactions.h.

Constructor & Destructor Documentation

◆ KFileItemActions()

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.

Definition at line 208 of file kfileitemactions.cpp.

◆ ~KFileItemActions()

KFileItemActions::~KFileItemActions ( )
overridedefault

Destructor.

Member Function Documentation

◆ addActionsTo()

void KFileItemActions::addActionsTo ( QMenu menu,
MenuActionSources  sources = MenuActionSource::All,
const QList< QAction * > &  additionalActions = {},
const QStringList excludeList = {} 
)

This methods adds additional actions to the menu.

Parameters
menuMenu to which the actions/submenus will be added.
sourcessources from which the actions should be fetched. By default all sources are used.
additionalActionsadditional actions that should be added to the "Actions" submenu or top level menu if there are less than three entries in total.
excludeListlist of action names or plugin ids that should be excluded
Since
5.77

Definition at line 243 of file kfileitemactions.cpp.

◆ addOpenWithActionsTo()

void KFileItemActions::addOpenWithActionsTo ( QMenu menu,
const QString traderConstraint = QString() 
)

Generates the "Open With <Application>" actions, and appends them to 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()).

Parameters
menuthe QMenu where the actions will be added
traderConstraintthis constraint allows to exclude the current application from the "open with" list. Example: "DesktopEntryName != 'kfmclient'".
See also
insertOpenWithActionsTo()
Deprecated:
Since 5.82, use insertOpenWithActionsTo(QAction *before, QMenu *topMenu, const QStringList &excludedDesktopEntryNames) instead and pass in a nullptr for the before parameter

Definition at line 297 of file kfileitemactions.cpp.

◆ addPluginActionsTo()

int KFileItemActions::addPluginActionsTo ( QMenu menu)

Add actions implemented by plugins.

These are defined in .desktop files or JSON in plugins using the KFileItemAction/Plugin service type, and the KAbstractFileItemActionPlugin base class.

All actions are created as children of the menu.

Returns
the number of actions added
Since
5.27
Deprecated:
since 5.79, use addActionsTo(QMenu *menu, MenuActionSources, QList<QAction *> &, const QStringList &) instead

Definition at line 237 of file kfileitemactions.cpp.

◆ addServiceActionsTo()

int KFileItemActions::addServiceActionsTo ( QMenu menu)

Generate the user-defined actions and submenus, and adds them to the menu.

User-defined actions include:

  • builtin services like mount/unmount for old-style device desktop files
  • 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

When KFileItemListProperties::supportsWriting() is false, actions that modify the files are not shown. This is controlled by Require=Write in the servicemenu desktop files.

Service actions that are not authorized (see KAuthorized::authorize()) are not added. For user-defined actions in a .desktop file, the "X-KDE-AuthorizeAction" key determines the Kiosk actions that are checked.

All actions are created as children of the menu.

Returns
the number of actions added
Deprecated:
since 5.79, use addActionsTo(QMenu *menu, MenuActionSources, QList<QAction *> &, const QStringList &) instead

Definition at line 230 of file kfileitemactions.cpp.

◆ associatedApplications() [1/2]

KService::List KFileItemActions::associatedApplications ( const QStringList mimeTypeList)
static

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

Parameters
mimeTypeListthe MIME types
Returns
the sorted list of services.
Since
5.83

Definition at line 260 of file kfileitemactions.cpp.

◆ associatedApplications() [2/2]

KService::List KFileItemActions::associatedApplications ( const QStringList mimeTypeList,
const QString traderConstraint 
)
static

Returns the applications associated with all the given MIME types.

Helper method used internally, can also be used for similar GUIs that show the list of associated applications. Used in KParts::BrowserOpenOrSaveQuestion for example.

This is basically a KMimeTypeTrader::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 KMimeTypeTrader instead, e.g. query() or preferredService().

This will return an empty list if the "openwith" Kiosk action is not authorized (see KAuthorized::authorize()).

Parameters
mimeTypeListthe MIME types
traderConstraintthis optional constraint allows to exclude the current application from the "open with" list. Example: "DesktopEntryName != 'kfmclient'".
Returns
the sorted list of services.
Since
4.4
Deprecated:
Since 5.83, use associatedApplications(const QStringList &) instead

Definition at line 267 of file kfileitemactions.cpp.

◆ error

void KFileItemActions::error ( const QString errorMessage)
signal

Forwards the errors from the KAbstractFileItemActionPlugin instances.

Since
5.82

◆ insertOpenWithActionsTo() [1/2]

void KFileItemActions::insertOpenWithActionsTo ( QAction before,
QMenu topMenu,
const QString traderConstraint 
)

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

Parameters
beforethe "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
menuthe QMenu where the actions will be added
traderConstraintthis constraint allows to exclude the current application from the "open with" list. Example: "DesktopEntryName != 'kfmclient'".
Since
5.78
Deprecated:
Since 5.82, use insertOpenWithActionsTo(QAction *before, QMenu *topMenu, const QStringList &excludedDesktopEntryNames) instead

Definition at line 304 of file kfileitemactions.cpp.

◆ insertOpenWithActionsTo() [2/2]

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

Parameters
beforethe "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
menuthe QMenu where the actions will be added
excludedDesktopEntryNameslist of desktop entry names that will not be shown
Since
5.82

Definition at line 310 of file kfileitemactions.cpp.

◆ openWithDialogAboutToBeShown

void KFileItemActions::openWithDialogAboutToBeShown ( )
signal

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.

Since
4.8.2

◆ preferredOpenWithAction()

QAction * KFileItemActions::preferredOpenWithAction ( const QString traderConstraint)

Returns an action for the preferred application only.

Parameters
traderConstraintthis constraint allows to exclude the current application from the "open with" list. Example: "DesktopEntryName != 'kfmclient'".
Returns
the action - or nullptr if no application was found.
Deprecated:
Since 5.82, use the first use first entry of associatedApplications() to create the action instead

Definition at line 974 of file kfileitemactions.cpp.

◆ runPreferredApplications [1/2]

void KFileItemActions::runPreferredApplications ( const KFileItemList fileOpenList)
slot

Slot used to execute a list of files in their respective preferred application.

Parameters
fileOpenListthe list of KFileItems to open.
Since
5.83

Definition at line 353 of file kfileitemactions.cpp.

◆ runPreferredApplications [2/2]

void KFileItemActions::runPreferredApplications ( const KFileItemList fileOpenList,
const QString traderConstraint 
)
slot

Slot used to execute a list of files in their respective preferred application.

Parameters
fileOpenListthe list of KFileItems to open.
traderConstraintthis optional constraint allows to exclude the current application
Since
4.5
Deprecated:
Since 5.83, use use runPreferredApplications(const KFileItemList &) instead

Definition at line 345 of file kfileitemactions.cpp.

◆ setItemListProperties()

void KFileItemActions::setItemListProperties ( const KFileItemListProperties itemList)

Sets all the data for the next instance of the popupmenu.

See also
KFileItemListProperties

Definition at line 216 of file kfileitemactions.cpp.

◆ setParentWidget()

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.

Definition at line 984 of file kfileitemactions.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Dec 6 2022 03:56:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.