|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qvcard30writer_p.h" |
|
43 #include "versitutils_p.h" |
|
44 #include "qversitdefs.h" |
|
45 #include "qmobilityglobal.h" |
|
46 |
|
47 QTM_BEGIN_NAMESPACE |
|
48 |
|
49 /*! Constructs a writer. */ |
|
50 QVCard30Writer::QVCard30Writer() |
|
51 : QVersitWriterPrivate(QByteArray("VCARD"),QByteArray("3.0")) |
|
52 { |
|
53 mPropertyNameMappings.insert( |
|
54 QString::fromAscii("X-NICKNAME"),QString::fromAscii("NICKNAME")); |
|
55 mPropertyNameMappings.insert( |
|
56 QString::fromAscii("X-IMPP"),QString::fromAscii("IMPP")); |
|
57 } |
|
58 |
|
59 /*! Destroys a writer. */ |
|
60 QVCard30Writer::~QVCard30Writer() |
|
61 { |
|
62 } |
|
63 |
|
64 /*! |
|
65 * Encodes the \a property to text. |
|
66 */ |
|
67 QByteArray QVCard30Writer::encodeVersitProperty(const QVersitProperty& property) |
|
68 { |
|
69 QVersitProperty modifiedProperty(property); |
|
70 QString name = mPropertyNameMappings.value(property.name(),property.name()); |
|
71 modifiedProperty.setName(name); |
|
72 QByteArray encodedProperty(encodeGroupsAndName(modifiedProperty)); |
|
73 encodedProperty.append(encodeParameters(modifiedProperty.parameters())); |
|
74 encodedProperty.append(":"); |
|
75 QByteArray value(modifiedProperty.value()); |
|
76 if (modifiedProperty.name() == QString::fromAscii("AGENT")) { |
|
77 QVersitDocument embeddedDocument = modifiedProperty.embeddedDocument(); |
|
78 value = encodeVersitDocument(embeddedDocument); |
|
79 VersitUtils::backSlashEscape(value); |
|
80 } |
|
81 encodedProperty.append(value); |
|
82 encodedProperty.append("\r\n"); |
|
83 |
|
84 return encodedProperty; |
|
85 } |
|
86 |
|
87 /*! |
|
88 * Encodes the \a parameters to text. |
|
89 */ |
|
90 QByteArray QVCard30Writer::encodeParameters( |
|
91 const QMultiHash<QString,QString>& parameters) const |
|
92 { |
|
93 QByteArray encodedParameters; |
|
94 QList<QString> names = parameters.uniqueKeys(); |
|
95 foreach (QString nameString, names) { |
|
96 encodedParameters.append(";"); |
|
97 QByteArray name = nameString.toAscii(); |
|
98 VersitUtils::backSlashEscape(name); |
|
99 encodedParameters.append(name); |
|
100 encodedParameters.append("="); |
|
101 QStringList values = parameters.values(nameString); |
|
102 for (int i=0; i<values.size(); i++) { |
|
103 if (i > 0) |
|
104 encodedParameters.append(","); |
|
105 QByteArray value = values.at(i).toAscii(); |
|
106 // QVersitContactExporterPrivate implementation may have added |
|
107 // base64 encoding parameter according to vCard 2.1. |
|
108 // Convert it to vCard 3.0 compatible. |
|
109 if (name == "ENCODING" && value == "BASE64") |
|
110 value = "B"; |
|
111 VersitUtils::backSlashEscape(value); |
|
112 encodedParameters.append(value); |
|
113 } |
|
114 } |
|
115 |
|
116 return encodedParameters; |
|
117 } |
|
118 |
|
119 QTM_END_NAMESPACE |