~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to src/versit/qversitwriter_p.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
**
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.
15
15
**
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.
35
35
**
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.
41
 
**
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()
90
84
{
91
85
    bool canceled = false;
 
86
 
 
87
    // Try to get the type from the parameter to startWriting...
 
88
    QVersitDocument::VersitType type = documentType();
 
89
 
92
90
    foreach (const QVersitDocument& document, mInput) {
93
91
        if (isCanceling()) {
94
92
            canceled = true;
95
93
            break;
96
94
        }
97
 
        QScopedPointer<QVersitDocumentWriter> writer(writerForType(document.type()));
 
95
 
 
96
        QScopedPointer<QVersitDocumentWriter> writer(
 
97
                writerForType( // ... get type from the document if not specified in startWriting
 
98
                    type == QVersitDocument::InvalidType ? document.type() : type,
 
99
                    document));
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");
102
104
            else
103
105
                codec = QTextCodec::codecForName("UTF-8");
104
106
        }
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);
110
111
            break;
111
112
        }
154
155
 * Returns a QVersitDocumentWriter that can encode a QVersitDocument of type \a type.
155
156
 * The caller is responsible for deleting the object.
156
157
 */
157
 
QVersitDocumentWriter* QVersitWriterPrivate::writerForType(QVersitDocument::VersitType type)
 
158
QVersitDocumentWriter* QVersitWriterPrivate::writerForType(QVersitDocument::VersitType type, const QVersitDocument& document)
158
159
{
159
160
    switch (type) {
 
161
        case QVersitDocument::InvalidType:
 
162
        {
 
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);
 
175
            } else {
 
176
                return new QVCard30Writer(QVersitDocument::VCard30Type);
 
177
            }
 
178
        }
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);
164
183
        default:
165
 
            return new QVCard30Writer;
 
184
            return new QVCard30Writer(type);
166
185
    }
167
186
}
168
187
 
172
191
    mIsCanceling = canceling;
173
192
}
174
193
 
175
 
bool QVersitWriterPrivate::isCanceling()
 
194
bool QVersitWriterPrivate::isCanceling() const
176
195
{
177
196
    QMutexLocker locker(&mMutex);
178
197
    return mIsCanceling;
179
198
}
180
199
 
 
200
void QVersitWriterPrivate::setDocumentType(QVersitDocument::VersitType type)
 
201
{
 
202
    QMutexLocker locker(&mMutex);
 
203
    mType = type;
 
204
}
 
205
 
 
206
QVersitDocument::VersitType QVersitWriterPrivate::documentType() const
 
207
{
 
208
    QMutexLocker locker(&mMutex);
 
209
    return mType;
 
210
}
 
211
 
181
212
#include "moc_qversitwriter_p.cpp"