Development/Tutorials/Solid/Device Actions: Difference between revisions

From KDE TechBase
(Introduction)
 
(→‎Introduction: Anatomy)
Line 1: Line 1:
== Introduction ==
== Introduction ==
The Device Notifier is a plasmoid that is responsible for handling device events.  When new data device is inserted or detected by Solid, it gets added to the Device Notifier menu.  Each device has a set of actions the user can perform on the device, depending on the device type and its contents.  For example, when the media is an audio CD, the Device Notifier offers you to play that CD using Amarok.  The default actions are not a part of Plasma; each one is installed by the application that handles the action, and goes away when the application is removed.


You can add your own actions and modify existing ones using the Device Actions system setting module; however, such changes are limited to the user that requests the change.  If you want to install a custom action along with your application, you have to dig a bit deeper.
The '''Device Notifier''' is a plasmoid that is responsible for handling device events.  When new data device is inserted or detected by '''Solid''', it gets added to the Device Notifier menu.  Each device has a set of ''actions'' the user can perform on the device, depending on the device type and its contents.  For example, when the media is an audio CD, the Device Notifier offers you to play that CD using '''Amarok'''.  The default actions are not a part of '''Plasma'''; rather, each one is installed by the application that handles the action, and goes away when the application is removed.
 
You can add your own actions and modify existing ones using the '''Device Actions''' system setting module; however, such changes are limited to the user that requests the change.  If you want to install a custom action along with your application, you have to dig a bit deeper.
 
== Anatomy of an action ==
 
An Action file is a desktop configuration file similar to the following one:
<code ini>
[Desktop Entry]
X-KDE-Solid-Predicate=OpticalDisc.availableContent & 'Audio'
Type=Service
Actions=Play;
 
[Desktop Action Play]
Name=Play Audio CD with Amarok
Name[fr]=Jouer CD Audio avec Amarok
# names in other languages
Icon=amarok
Exec=amarok --cdplay %f
</code >
 
== Actions and devices ==
 
The '''Device Notifier''' gets the devices and their corresponding actions by interrogating its data engine called '''hotplug'''.  The '''hotplug''' data engine gets the set of devices from '''Solid''' and the set of actions from the subdirectories {{path|./solid/actions}} relative to the application settings path in '''KDE'''.  The set of actions pertaining to each device is then obtained by evaluating the Solid Predicate specified in the action against the physical and logical properties of the device; if the predicate holds, the action is included.

Revision as of 20:58, 15 September 2010

Introduction

The Device Notifier is a plasmoid that is responsible for handling device events. When new data device is inserted or detected by Solid, it gets added to the Device Notifier menu. Each device has a set of actions the user can perform on the device, depending on the device type and its contents. For example, when the media is an audio CD, the Device Notifier offers you to play that CD using Amarok. The default actions are not a part of Plasma; rather, each one is installed by the application that handles the action, and goes away when the application is removed.

You can add your own actions and modify existing ones using the Device Actions system setting module; however, such changes are limited to the user that requests the change. If you want to install a custom action along with your application, you have to dig a bit deeper.

Anatomy of an action

An Action file is a desktop configuration file similar to the following one: [Desktop Entry] X-KDE-Solid-Predicate=OpticalDisc.availableContent & 'Audio' Type=Service Actions=Play;

[Desktop Action Play] Name=Play Audio CD with Amarok Name[fr]=Jouer CD Audio avec Amarok

  1. names in other languages

Icon=amarok Exec=amarok --cdplay %f

Actions and devices

The Device Notifier gets the devices and their corresponding actions by interrogating its data engine called hotplug. The hotplug data engine gets the set of devices from Solid and the set of actions from the subdirectories ./solid/actions relative to the application settings path in KDE. The set of actions pertaining to each device is then obtained by evaluating the Solid Predicate specified in the action against the physical and logical properties of the device; if the predicate holds, the action is included.