1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the documentation of the Qt PIM Module.
8
** $QT_BEGIN_LICENSE:FDL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Free Documentation License Usage
18
** Alternatively, this file may be used under the terms of the GNU Free
19
** Documentation License version 1.3 as published by the Free Software
20
** Foundation and appearing in the file included in the packaging of
21
** this file. Please review the following information to ensure
22
** the GNU Free Documentation License version 1.3 requirements
23
** will be met: http://www.gnu.org/copyleft/fdl.html.
26
****************************************************************************/
29
\page versitplugins.html
31
\title Qt Versit Plugins
33
While the \l {Qt Versit Overview}{QtVersit API} provides a convenient way to
34
import and export vCards,
35
it is common to encounter domain-specific vCard properties that the Versit
36
importer and exporter classes don't support. While it would be convenient if
37
the base Versit module could support everything, that is not possible because
38
there may be properties with the same name that have different semantics in
41
\section1 Local Extension with Handlers
43
To remedy this, some hooks are provided to allow clients to alter the behaviour
44
of QVersitContactImporter and QVersitContactExporter. The basic mechanisms that
45
allow this are the QVersitContactImporterPropertyHandlerV2 and the
46
QVersitContactExporterDetailHandlerV2 interfaces. A client can supplement the
47
importer and exporter classes by implementing these interfaces and associating
48
them using QVersitContactImporter::setPropertyHandler() and
49
QVersitContactExporter::setDetailHandler().
51
\section1 Global Extension with Plugins
53
While these interfaces allow a single client to supplement the behaviour of
54
import and export, there are many cases where the entire deployment of the
55
Versit library will be operating under a known context. For example, the
56
library might be deployed on a device on a particular network where all of its
57
peers are known to support certain properties. In this situation, it's
58
desirable for all clients of the Versit library on that device to support those
59
properties through the Qt Versit API. It is possible to extend the library
60
globally by installing plugins that provide handlers automatically to all users
61
of the library on the system.
63
Writing a plugin involves these steps:
65
\li Implement a handler class that inherits from QVersitContactHandler.
66
\li Implement a plugin class that inherits from QObject and QVersitContactHandlerFactory
67
and implements the createHandler() function to create the handler class.
68
\li Include the following two lines at the top of the factory declaration:
71
Q_INTERFACES(QtVersit::QVersitContactHandlerFactory)
73
\li Export the plugin using the Q_EXPORT_PLUGIN2 macro.
74
\li Build the plugin using a suitable \tt{.pro} file.
75
\li Deploy the plugin in the \tt{plugins/versit} directory.
78
Please see the relevant documentation in Qt for more details on writing a
81
\section2 Example Plugin: Backup and Restore
83
A plugin is provided with the Qt Versit module that provides backup and restore
84
functionality to the exporter and importer.
86
These can be used by creating the exporter and importer under the "backup"
89
QVersitContactExporter exporter(QVersitContactHandlerFactory::ProfileBackup);
92
QVersitContactImporter importer(QVersitContactHandlerFactory::ProfileBackup);
95
When applied to the exporter, this handler encodes all writable details that the
96
exporter doesn't recognise. The format it uses to encode the detail is as
99
\li All generated properties will have the name X-NOKIA-QCONTACTFIELD
100
\li All generated properties will have a single Versit group, and all properties
101
generated from a single detail will have the same group.
102
\li All generated properties will have at least the parameters DETAIL, which
103
holds the definition name of the QContactDetail from which it was generated, and
104
FIELD, which holds the name of the field within the detail from which it was
106
\li If the field is of type QString or QByteArray, the property's value is set
107
directly to the value of the field. (For a QByteArray value, the QVersitWriter
108
will base-64 encode it.)
109
\li If the field is of type bool, int, uint, QDate, QTime, QDateTime or QUrl a
110
the property's value is set to a string representation of the field. A
111
parameter DATATYPE is added to the property with value BOOL, INT, UINT, DATE,
112
TIME or DATETIME depending on the type.
113
\li If the field is of some other type, the field value is encoded to a
114
QByteArray via QDataStream (and the resulting byte array is base-64 encoded by
115
the QVersitWriter). In this case, the parameter DATATYPE=VARIANT is added to
119
For example, a detail with definition name "Pet" and fields "Name"="Rex" and
120
"Age"=(int)14 will be exported to the vCard properties:
122
G0.X-NOKIA-QCONTACTFIELD;DETAIL=Pet;FIELD=Name:Rex
123
G0.X-NOKIA-QCONTACTFIELD;DETAIL=Pet;FIELD=Age;DATATYPE=INT:14
126
And the next detail (say, "Pet" with a field "Name"="Molly" will generate:
128
G1.X-NOKIA-QCONTACTFIELD;DETAIL=Pet;FIELD=Name:Molly
131
When applied to the importer, this handler decodes the properties that were
132
generated by the exporter under the backup profile.
134
The code for this plugin can be perused in the
135
\tt{plugins/versit/backuphandler} directory.