58 * \a documentType is the type of Versit document, as printed on the BEGIN line of output |
58 * \a documentType is the type of Versit document, as printed on the BEGIN line of output |
59 * eg. "VCARD" |
59 * eg. "VCARD" |
60 * \a version is the version of the Versit format, as printed on the VERSION line of output. |
60 * \a version is the version of the Versit format, as printed on the VERSION line of output. |
61 * eg. "2.1" |
61 * eg. "2.1" |
62 */ |
62 */ |
63 QVersitDocumentWriter::QVersitDocumentWriter( |
63 QVersitDocumentWriter::QVersitDocumentWriter() |
64 const QByteArray& documentType, |
64 : mDevice(0), |
65 const QByteArray& version) |
|
66 : mDocumentType(documentType), |
|
67 mVersion(version), |
|
68 mCodec(0), |
65 mCodec(0), |
69 mEncoder(0), |
66 mEncoder(0), |
70 mUtf8Encoder(QTextCodec::codecForName("UTF-8")->makeEncoder()), |
67 mUtf8Encoder(QTextCodec::codecForName("UTF-8")->makeEncoder()), |
71 mSuccessful(true), |
68 mSuccessful(true), |
72 mCurrentLineLength(0) |
69 mCurrentLineLength(0) |
104 { |
101 { |
105 mDevice = device; |
102 mDevice = device; |
106 } |
103 } |
107 |
104 |
108 /*! |
105 /*! |
109 * Encodes the \a document and writes it to the device |
106 * Encodes the \a document and writes it to the device. A "VERSION:" line is added iff \a |
110 */ |
107 * encodeVersion is true. |
111 void QVersitDocumentWriter::encodeVersitDocument(const QVersitDocument& document) |
108 */ |
|
109 void QVersitDocumentWriter::encodeVersitDocument(const QVersitDocument& document, bool encodeVersion) |
112 { |
110 { |
113 mSuccessful = true; |
111 mSuccessful = true; |
114 QList<QVersitProperty> properties = document.properties(); |
|
115 |
112 |
116 writeString(QLatin1String("BEGIN:" + mDocumentType)); |
113 writeString(QLatin1String("BEGIN:") + document.componentType()); |
117 writeCrlf(); |
114 writeCrlf(); |
118 writeString(QLatin1String("VERSION:" + mVersion)); |
115 if (encodeVersion) { |
119 writeCrlf(); |
116 switch (document.type()) { |
120 foreach (const QVersitProperty& property, properties) { |
117 case QVersitDocument::VCard21Type: |
|
118 writeString(QLatin1String("VERSION:2.1")); |
|
119 writeCrlf(); |
|
120 break; |
|
121 case QVersitDocument::VCard30Type: |
|
122 writeString(QLatin1String("VERSION:3.0")); |
|
123 writeCrlf(); |
|
124 break; |
|
125 case QVersitDocument::VCard40Type: |
|
126 writeString(QLatin1String("VERSION:4.0")); |
|
127 writeCrlf(); |
|
128 break; |
|
129 case QVersitDocument::ICalendar20Type: |
|
130 writeString(QLatin1String("VERSION:2.0")); |
|
131 writeCrlf(); |
|
132 break; |
|
133 default: |
|
134 ; // don't print version |
|
135 } |
|
136 } |
|
137 |
|
138 foreach (const QVersitProperty& property, document.properties()) { |
121 encodeVersitProperty(property); |
139 encodeVersitProperty(property); |
122 } |
140 } |
123 writeString(QLatin1String("END:" + mDocumentType)); |
141 |
|
142 foreach (const QVersitDocument& document, document.subDocuments()) { |
|
143 encodeVersitDocument(document, false); |
|
144 } |
|
145 |
|
146 writeString(QLatin1String("END:") + document.componentType()); |
124 writeCrlf(); |
147 writeCrlf(); |
125 } |
148 } |
126 |
149 |
127 /*! |
150 /*! |
128 * Encodes the groups and name in the \a property and writes it to the device |
151 * Encodes the groups and name in the \a property and writes it to the device |