qtmobility/src/versit/qversitwriter.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 8 71781823f776
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    44 #include "versitutils_p.h"
    44 #include "versitutils_p.h"
    45 #include "qmobilityglobal.h"
    45 #include "qmobilityglobal.h"
    46 
    46 
    47 #include <QStringList>
    47 #include <QStringList>
    48 #include <QTextCodec>
    48 #include <QTextCodec>
       
    49 #include <QBuffer>
    49 
    50 
    50 QTM_USE_NAMESPACE
    51 QTM_USE_NAMESPACE
    51 
    52 
    52 /*!
    53 /*!
    53   \class QVersitWriter
    54   \class QVersitWriter
   105  */
   106  */
   106 
   107 
   107 /*! Constructs a new writer. */
   108 /*! Constructs a new writer. */
   108 QVersitWriter::QVersitWriter() : d(new QVersitWriterPrivate)
   109 QVersitWriter::QVersitWriter() : d(new QVersitWriterPrivate)
   109 {
   110 {
   110     connect(d, SIGNAL(stateChanged(QVersitWriter::State)),
   111     d->init(this);
   111             this, SIGNAL(stateChanged(QVersitWriter::State)), Qt::DirectConnection);
   112 }
       
   113 
       
   114 /*! Constructs a new writer that writes to \a outputDevice. */
       
   115 QVersitWriter::QVersitWriter(QIODevice *outputDevice) : d(new QVersitWriterPrivate)
       
   116 {
       
   117     d->init(this);
       
   118     d->mIoDevice = outputDevice;
       
   119 }
       
   120 
       
   121 /*! Constructs a new writer that appends to \a outputBytes. */
       
   122 QVersitWriter::QVersitWriter(QByteArray *outputBytes) : d(new QVersitWriterPrivate)
       
   123 {
       
   124     d->init(this);
       
   125     d->mOutputBytes.reset(new QBuffer);
       
   126     d->mOutputBytes->setBuffer(outputBytes);
       
   127     d->mOutputBytes->open(QIODevice::WriteOnly);
       
   128     d->mIoDevice = d->mOutputBytes.data();
   112 }
   129 }
   113 
   130 
   114 /*!
   131 /*!
   115  * Frees the memory used by the writer.
   132  * Frees the memory used by the writer.
   116  * Waits until a pending asynchronous writing has been completed.
   133  * Waits until a pending asynchronous writing has been completed.
   125  * Sets the device used for writing to \a device.
   142  * Sets the device used for writing to \a device.
   126  * Does not take ownership of the device.
   143  * Does not take ownership of the device.
   127  */
   144  */
   128 void QVersitWriter::setDevice(QIODevice* device)
   145 void QVersitWriter::setDevice(QIODevice* device)
   129 {
   146 {
       
   147     d->mOutputBytes.reset(0);
   130     d->mIoDevice = device;
   148     d->mIoDevice = device;
   131 }
   149 }
   132 
   150 
   133 /*!
   151 /*!
   134  * Returns the device used for writing.
   152  * Returns the device used for writing, or 0 if no device has been set.
   135  */
   153  */
   136 QIODevice* QVersitWriter::device() const
   154 QIODevice* QVersitWriter::device() const
   137 {
   155 {
   138     return d->mIoDevice;
   156     if (d->mOutputBytes.isNull())
       
   157         return d->mIoDevice;
       
   158     else
       
   159         return 0;
   139 }
   160 }
   140 
   161 
   141 /*!
   162 /*!
   142  * Sets the default codec for the writer to use for writing the entire output.
   163  * Sets the default codec for the writer to use for writing the entire output.
   143  *
   164  *
   153  * Returns the document's codec.
   174  * Returns the document's codec.
   154  */
   175  */
   155 QTextCodec* QVersitWriter::defaultCodec() const
   176 QTextCodec* QVersitWriter::defaultCodec() const
   156 {
   177 {
   157     return d->mDefaultCodec;
   178     return d->mDefaultCodec;
       
   179 }
       
   180 
       
   181 /*!
       
   182  * Returns the state of the writer.
       
   183  */
       
   184 QVersitWriter::State QVersitWriter::state() const
       
   185 {
       
   186     return d->state();
       
   187 }
       
   188 
       
   189 /*!
       
   190  * Returns the error encountered by the last operation.
       
   191  */
       
   192 QVersitWriter::Error QVersitWriter::error() const
       
   193 {
       
   194     return d->error();
   158 }
   195 }
   159 
   196 
   160 /*!
   197 /*!
   161  * Starts writing \a input to device() asynchronously.
   198  * Starts writing \a input to device() asynchronously.
   162  * Returns false if the output device has not been set or opened or
   199  * Returns false if the output device has not been set or opened or
   205     } else {
   242     } else {
   206         return false;
   243         return false;
   207     }
   244     }
   208 }
   245 }
   209 
   246 
   210 /*!
       
   211  * Returns the state of the writer.
       
   212  */
       
   213 QVersitWriter::State QVersitWriter::state() const
       
   214 {
       
   215     return d->state();
       
   216 }
       
   217 
       
   218 /*!
       
   219  * Returns the error encountered by the last operation.
       
   220  */
       
   221 QVersitWriter::Error QVersitWriter::error() const
       
   222 {
       
   223     return d->error();
       
   224 }
       
   225 
       
   226 #include "moc_qversitwriter.cpp"
   247 #include "moc_qversitwriter.cpp"