9
9
** $QT_BEGIN_LICENSE:LGPL$
10
10
** Commercial Usage
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Solutions Commercial License Agreement provided
13
** with the Software or, alternatively, in accordance with the terms
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Commercial License Agreement provided with
13
** the Software or, alternatively, in accordance with the terms
14
14
** contained in a written agreement between you and Nokia.
16
16
** GNU Lesser General Public License Usage
33
33
** ensure the GNU General Public License version 3.0 requirements will be
34
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** Please note Third Party Software included with Qt Solutions may impose
37
** additional restrictions and it is the user's responsibility to ensure
38
** that they have met the licensing requirements of the GPL, LGPL, or Qt
39
** Solutions Commercial license and the relevant license of the Third
40
** Party Software they are using.
42
36
** If you are unsure which license is appropriate for your use, please
43
37
** contact the sales department at qt-sales@nokia.com.
44
38
** $QT_END_LICENSE$
89
83
void QVersitWriterPrivate::write()
91
85
bool canceled = false;
87
// Try to get the type from the parameter to startWriting...
88
QVersitDocument::VersitType type = documentType();
92
90
foreach (const QVersitDocument& document, mInput) {
93
91
if (isCanceling()) {
97
QScopedPointer<QVersitDocumentWriter> writer(writerForType(document.type()));
96
QScopedPointer<QVersitDocumentWriter> writer(
97
writerForType( // ... get type from the document if not specified in startWriting
98
type == QVersitDocument::InvalidType ? document.type() : type,
98
100
QTextCodec* codec = mDefaultCodec;
99
101
if (codec == NULL) {
100
if (document.type() == QVersitDocument::VCard21Type)
102
if (type == QVersitDocument::VCard21Type)
101
103
codec = QTextCodec::codecForName("ISO-8859-1");
103
105
codec = QTextCodec::codecForName("UTF-8");
105
107
writer->setCodec(codec);
106
108
writer->setDevice(mIoDevice);
107
writer->encodeVersitDocument(document);
108
if (!writer->mSuccessful) {
109
if (!writer->encodeVersitDocument(document)) {
109
110
setError(QVersitWriter::IOError);
154
155
* Returns a QVersitDocumentWriter that can encode a QVersitDocument of type \a type.
155
156
* The caller is responsible for deleting the object.
157
QVersitDocumentWriter* QVersitWriterPrivate::writerForType(QVersitDocument::VersitType type)
158
QVersitDocumentWriter* QVersitWriterPrivate::writerForType(QVersitDocument::VersitType type, const QVersitDocument& document)
161
case QVersitDocument::InvalidType:
163
// Neither startWriting or the document provided the type.
164
// Need to infer the type from the document's componentType
165
QString componentType(document.componentType());
166
if (componentType == QLatin1String("VCARD")) {
167
return new QVCard30Writer(QVersitDocument::VCard30Type);
168
} else if (componentType == QLatin1String("VCALENDAR")
169
|| componentType == QLatin1String("VEVENT")
170
|| componentType == QLatin1String("VTODO")
171
|| componentType == QLatin1String("VJOURNAL")
172
|| componentType == QLatin1String("VTIMEZONE")
173
|| componentType == QLatin1String("VALARM")) {
174
return new QVCard30Writer(QVersitDocument::ICalendar20Type);
176
return new QVCard30Writer(QVersitDocument::VCard30Type);
160
179
case QVersitDocument::VCard21Type:
161
return new QVCard21Writer;
180
return new QVCard21Writer(type);
162
181
case QVersitDocument::VCard30Type:
163
return new QVCard30Writer;
182
return new QVCard30Writer(type);
165
return new QVCard30Writer;
184
return new QVCard30Writer(type);
172
191
mIsCanceling = canceling;
175
bool QVersitWriterPrivate::isCanceling()
194
bool QVersitWriterPrivate::isCanceling() const
177
196
QMutexLocker locker(&mMutex);
178
197
return mIsCanceling;
200
void QVersitWriterPrivate::setDocumentType(QVersitDocument::VersitType type)
202
QMutexLocker locker(&mMutex);
206
QVersitDocument::VersitType QVersitWriterPrivate::documentType() const
208
QMutexLocker locker(&mMutex);
181
212
#include "moc_qversitwriter_p.cpp"