diff -r 76a2435edfd4 -r de1630741fbe qtcontactsmobility/src/versit/qversitwriter.cpp --- a/qtcontactsmobility/src/versit/qversitwriter.cpp Fri Apr 16 14:53:18 2010 +0300 +++ b/qtcontactsmobility/src/versit/qversitwriter.cpp Mon May 03 12:24:20 2010 +0300 @@ -46,15 +46,16 @@ #include #include +#include QTM_USE_NAMESPACE /*! \class QVersitWriter - \preliminary + \preliminary \brief The QVersitWriter class writes Versit documents such as vCards to a device. \ingroup versit - + QVersitWriter converts a QVersitDocument into its textual representation. QVersitWriter supports writing to an abstract I/O device which can be for example a file or a memory buffer. @@ -107,12 +108,28 @@ /*! Constructs a new writer. */ QVersitWriter::QVersitWriter() : d(new QVersitWriterPrivate) { - connect(d, SIGNAL(stateChanged(QVersitWriter::State)), - this, SIGNAL(stateChanged(QVersitWriter::State)), Qt::DirectConnection); + d->init(this); +} + +/*! Constructs a new writer that writes to \a outputDevice. */ +QVersitWriter::QVersitWriter(QIODevice *outputDevice) : d(new QVersitWriterPrivate) +{ + d->init(this); + d->mIoDevice = outputDevice; } -/*! - * Frees the memory used by the writer. +/*! Constructs a new writer that appends to \a outputBytes. */ +QVersitWriter::QVersitWriter(QByteArray *outputBytes) : d(new QVersitWriterPrivate) +{ + d->init(this); + d->mOutputBytes.reset(new QBuffer); + d->mOutputBytes->setBuffer(outputBytes); + d->mOutputBytes->open(QIODevice::WriteOnly); + d->mIoDevice = d->mOutputBytes.data(); +} + +/*! + * Frees the memory used by the writer. * Waits until a pending asynchronous writing has been completed. */ QVersitWriter::~QVersitWriter() @@ -123,18 +140,23 @@ /*! * Sets the device used for writing to \a device. + * Does not take ownership of the device. */ void QVersitWriter::setDevice(QIODevice* device) { + d->mOutputBytes.reset(0); d->mIoDevice = device; } /*! - * Returns the device used for writing. + * Returns the device used for writing, or 0 if no device has been set. */ QIODevice* QVersitWriter::device() const { - return d->mIoDevice; + if (d->mOutputBytes.isNull()) + return d->mIoDevice; + else + return 0; } /*! @@ -157,6 +179,22 @@ } /*! + * Returns the state of the writer. + */ +QVersitWriter::State QVersitWriter::state() const +{ + return d->state(); +} + +/*! + * Returns the error encountered by the last operation. + */ +QVersitWriter::Error QVersitWriter::error() const +{ + return d->error(); +} + +/*! * Starts writing \a input to device() asynchronously. * Returns false if the output device has not been set or opened or * if there is another asynchronous write operation already pending. @@ -206,48 +244,4 @@ } } -/*! - * Returns the state of the writer. - */ -QVersitWriter::State QVersitWriter::state() const -{ - return d->state(); -} - -/*! - * Returns the error encountered by the last operation. - */ -QVersitWriter::Error QVersitWriter::error() const -{ - return d->error(); -} - - -/*! \internal */ -void QVersitWriter::setVersitDocument(const QVersitDocument& versitDocument) -{ - QList documents; - documents.append(versitDocument); - d->mInput = documents; -} - -/*! \internal */ -QVersitDocument QVersitWriter::versitDocument() const -{ - return QVersitDocument(); -} - -/*! \internal */ -bool QVersitWriter::startWriting() -{ - return startWriting(d->mInput); -} - -/*! \internal */ -bool QVersitWriter::writeAll() -{ - startWriting(d->mInput); - return waitForFinished(); -} - #include "moc_qversitwriter.cpp"