summaryrefslogtreecommitdiffstats
path: root/src/contacts/doc/src/contactsactions.qdoc
blob: 0ba8b560fb9526b364f706f7b55a3bec4624f6a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt PIM Module.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!

\page contactsactions.html

\title Qt Contacts Action API

\tableofcontents

The Qt Contacts API supports the concept of a generic action which may be invoked
upon an \l{QContactActionTarget}{action target} (e.g., a contact) or list thereof.
The API allows clients to invoke an action upon a target (for example, to send an email
to a contact) in a cross-platform manner, and allows third-party developers to provide
platform-specific action plugins which may be used by clients.

\section1 Invoking Actions upon Targets

The client interface to actions consists of three classes: QContactAction, QContactActionTarget
and QContactActionDescriptor.  A \l{QContactActionDescriptor}{descriptor} uniquely identifies
a particular implementation of an \l{QContactAction}{action}, and allows the client to query
meta-data about the action.  An \l{QContactActionTarget}{action target} consists of either a
contact, a detail of a contact, or a list of details of a contact.

The available actions may be queried by calling \l QContactAction::availableActions().  This
function returns the list of names of actions which are provided by the given service name,
or by any service if the parameter is omitted.

There may be multiple implementations of any given action identified by a particular action
name, since multiple third-party action providers could provide (for example) a "call" action,
using various proprietary protocols and techologies.  Once the client knows which action they
wish to perform on a contact, they can retrieve the list of action descriptors for that action
by calling \l QContactAction::actionDescriptors() which takes the action name as a parameter.

Note that there are several predefined action names including QContactAction::ActionCall,
QContactAction::ActionEmail, QContactAction::ActionSms etc, however there is no guarantee
that all of these actions are implemented on any given platform.

Finally, once the client has selected a particular implementation of the action, by inspecting
the action descriptor (from which they can retrieve meta-data and check that it supports the
contact that they wish to perform the action on), the client may request a pointer to the
action implementation by calling \l QContactAction::action() and passing the action descriptor
as a parameter.  Note that the client takes ownership of the returned QContactAction
pointer and must delete it to avoid leaking memory.  The caller is able to delete the action
at any time, however doing so prior to when the action transitions to a finished state may
have an undefined outcome depending on the implementation of the action.

\section1 Implementing Actions

If you are a third-party developer who wants to provide an action for other clients to use,
you must do four things:
\list
\li Implement a QServicePluginInterface-derived class
\li Implement a QContactActionFactory-derived class
\li Implement (one or more) QContactAction-derived classes
\li Write an XML file which describes your service plugin
\endlist

For more information on the QServicePluginInterface and the format of the service description
XML, see the \l{Qt Service Framework}{Qt Service Framework} documentation.
An example action plugin is provided later in this document.

\note While the plugins are loaded by the Qt Service Framework,
clients of the Qt Contacts Action API are entirely shielded from this implementation detail.

The QContactActionDescriptor class is actually a client-facing interface to an action factory,
which allows the factory to provide meta-data and other implementation-specific information
to clients on demand.

\section2 Other Considerations

We recommend that action implementors provide values for the default meta-data keys (including
icons and labels) documented in QContactActionDescriptor, to allow client applications to
provide meaningful user interface elements to represent the action.

We recommend that action implementors read the documentation of the
\l{Qt Service Framework}{Qt Service Framework} carefully, to better understand
how their implementation plugin may be updated with patch releases or major releases,
and how these considerations affect the implementation of the plugin.

\section2 Example Implementation

The following snippet provides an example of an action plugin.  As previously described, the action
plugin consists of a QServicePluginInterface, a QContactActionFactory, and one or more QContactAction
derived classes.  The QServicePluginInterface-derived class merely instantiates the
QContactActionFactory-derived class on request for the Qt Service Framework.  The
QContactActionFactory-derived class then instantiates the actions when required.

\snippet multiaction/multiaction_p.h Example Contact Action Plugin Declaration

The implementation of these classes might be something like the following (example only):

\snippet multiaction/multiaction.cpp Example Contact Action Plugin Implementation

Once implemented, the plugin must be described by an XML file and installed in
an appropriate location. For more information, see the Qt Service Framework
documentation.

\code
<?xml version="1.0" encoding="utf-8" ?>
<service>
    <name>tst_qcontactactions:multiaction</name>
    <filepath>plugins/contacts/libcontacts_multiaction</filepath>
    <description>This service provides two test QContactAction implementations for testing purposes.  It is also an example of a single plugin providing multiple actions whose descriptors are identical except for their meta data.</description>
    <interface>
        <name>org.qt-project.Qt.SampleContactsActionPlugin</name>
        <version>1.1</version>
        <capabilities></capabilities>
        <customproperty key="ActionName">call</customproperty>
        <description>This plugin can instantiate two different QContactAction instances; one which provides the "call" action via the "sip" provider, the other which provides the "call" action via the "example proprietary protocol" provider.</description>
    </interface>
</service>
\endcode

\section2 Deploying Services

Depending on the platform, the service which provides the action must be
deployed in a certain way.

*/