KDE 4.5 PyKDE API Reference

- KDE's Python API

# KFileItemActions Class Reference

`from PyKDE4.kio import *`

Inherits: QObject

## 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
- 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 mimetype of the url

Since:
  4.3

## Methods
| __init__ (self, QObject parent=0)
| addOpenWithActionsTo (self, QMenu menu, QString traderConstraint=QString())
int | addServiceActionsTo (self, QMenu menu)
KAction | preferredOpenWithAction (self, QString traderConstraint)
| runPreferredApplications (self, KFileItemList fileOpenList, QString traderConstraint)
| setItemListProperties (self, KFileItemListProperties itemList)
| setParentWidget (self, QWidget widget)
## Static Methods
[KSharedPtr] | associatedApplications (QStringList mimeTypeList, QString traderConstraint)

## Method Documentation

__init__ | ( | self, |
|  | QObject | parent=0
| ) |  |  |

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.

addOpenWithActionsTo | ( | self, |
|  | QMenu | menu,
|  | QString | traderConstraint=QString()
| ) |  |  |

Generate the "Open With <Application>" actions, and adds them to the menu. All actions are created as children of the menu.

Parameters:

  | menu | the QMenu where to add actions
  | traderConstraint | this constraint allows to exclude the current application from the "open with" list. Example: "DesktopEntryName != 'kfmclient'". (Default value added in kdelibs-4.5, pass QString() explicitely for earlier versions).

int addServiceActionsTo | ( | self, |
|  | 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 mimetype 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.

All actions are created as children of the menu.

Returns:
  the number of actions added

KAction preferredOpenWithAction | ( | self, |
|  | QString | traderConstraint
| ) |  |  |

Returns an action for the preferred application only.

Parameters:

  | traderConstraint | this constraint allows to exclude the current application from the "open with" list. Example: "DesktopEntryName != 'kfmclient'".

Returns:
  the action - or 0 if no application was found.

runPreferredApplications | ( | self, |
|  | KFileItemList | fileOpenList,
|  | QString | traderConstraint
| ) |  |  |

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

Parameters:

  | fileOpenList | the list of KFileItems to open.
  | traderConstraint | this optional constraint allows to exclude the current application

Since:
  4.5

setItemListProperties | ( | self, |
|  | KFileItemListProperties | itemList
| ) |  |  |

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

See also:
  KFileItemListProperties

setParentWidget | ( | self, |
|  | 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.

## Static Method Documentation

[KSharedPtr] associatedApplications | ( | QStringList | mimeTypeList,
|  | QString | traderConstraint
| ) |  |  |

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 mimetypes, and also cleans up "apparent" duplicates, such as the kde3 and kde4 applications with the same name.

The list is sorted according to the user preferences for the given mimetype(s). In case multiple mimetypes appear in the url list, the logic is: applications that on average appear earlier on the associated applications list for the given mimetypes also appear earlier on the final applications list.

Note that for a single mimetype there is no need to use this, you should use KMimeTypeTrader instead, e.g. query() or preferredService().

Returns the applications associated with all the given mimetypes.

Parameters:

  | mimeTypeList | the mimetypes
  | traderConstraint | this 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