Beispiel #1
0
void QuaZIODevice::close()
{
    if ((openMode() & QIODevice::ReadOnly) != 0) {
        if (inflateEnd(&d->zins) != Z_OK) {
            setErrorString(d->zins.msg);
        }
    }
    if ((openMode() & QIODevice::WriteOnly) != 0) {
        flush();
        if (deflateEnd(&d->zouts) != Z_OK) {
            setErrorString(d->zouts.msg);
        }
    }
    QIODevice::close();
}
void CryptFileDevice::close()
{
    if (!isOpen())
        return;

    if ((openMode() & WriteOnly) || (openMode() & Append))
        flush();

    seek(0);
    m_device->close();
    setOpenMode(NotOpen);

    if (m_encrypted)
        m_encrypted = false;
}
Beispiel #3
0
UnzipFile::~UnzipFile()
{
	if (openMode() != NotOpen)
		close();
	
	delete d;
}
Beispiel #4
0
void UnzipFile::close()
{
	if (openMode() == NotOpen)
		return;
	
	unzCloseCurrentFile(d->archive->d->unzip);
}
/*!
     Closes the QtIOCompressor, and also the underlying device if it was opened by QtIOCompressor.
    \sa open()
*/
void QtIOCompressor::close()
{
    Q_D(QtIOCompressor);
    if (isOpen() == false)
        return;

    // Flush and close the zlib stream.
    if (openMode() & ReadOnly) {
        d->state = QtIOCompressorPrivate::NotReadFirstByte;
        inflateEnd(&d->zlibStream);
    } else {
        if (d->state == QtIOCompressorPrivate::BytesWritten) { // Only flush if we have written anything.
            d->state = QtIOCompressorPrivate::NoBytesWritten;
            d->flushZlib(Z_FINISH);
        }
        deflateEnd(&d->zlibStream);
    }

    // Close the underlying device if we are managing it.
    if (d->manageDevice)
        d->device->close();

    d->zlibStream.next_in = 0;
    d->zlibStream.avail_in = 0;
    d->zlibStream.next_out = NULL;
    d->zlibStream.avail_out = 0;
    d->state = QtIOCompressorPrivate::Closed;

    QIODevice::close();
}
/*!
    Returns 1 if there might be data available for reading, or 0 if there is no data available.

    There is unfortunately no way of knowing how much data there is available when dealing with compressed streams.

    Also, since the remaining compressed data might be a part of the meta-data that ends the compressed stream (and
    therefore will yield no uncompressed data), you cannot assume that a read after getting a 1 from this function will return data.
*/
qint64 QtIOCompressor::bytesAvailable() const
{
    Q_D(const QtIOCompressor);
    if ((openMode() & ReadOnly) == false)
        return 0;

    int numBytes = 0;

    switch (d->state) {
        case QtIOCompressorPrivate::NotReadFirstByte:
            numBytes = d->device->bytesAvailable();
        break;
        case QtIOCompressorPrivate::InStream:
            numBytes = 1;
        break;
        case QtIOCompressorPrivate::EndOfStream:
        case QtIOCompressorPrivate::Error:
        default:
            numBytes = 0;
        break;
    };

    numBytes += QIODevice::bytesAvailable();

    if (numBytes > 0)
        return 1;
    else
        return 0;
}
bool QtIOCompressor::seek(qint64 pos)
{
    Q_D(QtIOCompressor);

    if(isWritable())
		return false;

	OpenMode mode = openMode();
	close();
    if(d->device->isOpen()) {
    	if(!d->device->reset())
    		return false;
    }
	if(!open(mode))
		return false;

	char buffer[0x10000];
	while(pos > 0) {
		qint64 s = read(buffer, std::min(pos, (qint64)sizeof(buffer)));
		if(s <= 0)
			return false;
		pos -= s;
	}

	return true;
}
qint64 CryptFileDevice::calculateSizeHelper()
{
    qint64 position = m_device->pos() - kHeaderLength + (pos() % AES_BLOCK_SIZE);
    qint64 deviceSize = m_device->size();

    QByteArray oldBuffer = m_buffer;
    if (openMode() != QIODevice::ReadOnly)
        flush();

    qint64 size = m_device->size() - kHeaderLength;
    if (size < AES_BLOCK_SIZE)
    {
        seek(position);
        return size;
    }

    seek(size - AES_BLOCK_SIZE);
    QByteArray buffer = read(AES_BLOCK_SIZE);
    m_device->resize(deviceSize);
    seek(position);

    if (m_buffer != oldBuffer)
        m_buffer = oldBuffer;

    qint64 result = size + buffer.length() - AES_BLOCK_SIZE;

    return result;
}
Beispiel #9
0
bool File::changeOpenMode(OpenMode mode)
{
	if (openMode() == mode)	return true;

	close();
	return open(mode);
}
Beispiel #10
0
bool File::open(OpenMode mode)
{
	if (isOpen())
		return changeOpenMode(mode | openMode());
	else
		return QFile::open(mode);
}
Beispiel #11
0
/*!
 * \reimp
 */
qint64 QxtWebContent::writeData(const char *data, qint64 maxSize)
{
    if(!(openMode() & WriteOnly)){
	qWarning("QxtWebContent(): size=%lld but read-only", maxSize);
	return -1; // Not accepting writes
    }
    if(maxSize > 0) {
	// This must match the QxtFifo implementation for consistency
        if(maxSize > INT_MAX) maxSize = INT_MAX; // qint64 could easily exceed QAtomicInt, so let's play it safe
	if(qxt_d().bytesNeeded >= 0){
	    if(maxSize > qxt_d().bytesNeeded){
		qWarning("QxtWebContent(): size=%lld needed %lld", maxSize,
			qxt_d().bytesNeeded);
		maxSize = qxt_d().bytesNeeded;
	    }
	    qxt_d().bytesNeeded -= maxSize;
	    Q_ASSERT(qxt_d().bytesNeeded >= 0);
	}
	if(qxt_d().ignoreRemaining)
	    return maxSize;
	return QxtFifo::writeData(data, maxSize);
    }
    // Error
    return -1;
}
/*!
    Flushes the internal buffer.

    Each time you call flush, all data written to the QtIOCompressor is compressed and written to the
    underlying device. Calling this function can reduce the compression ratio. The underlying device
    is not flushed.

    Calling this function when QtIOCompressor is in ReadOnly mode has no effect.
*/
void QtIOCompressor::flush()
{
    Q_D(QtIOCompressor);
    if (isOpen() == false || openMode() & ReadOnly)
        return;

    d->flushZlib(Z_SYNC_FLUSH);
}
Beispiel #13
0
// ----- events ------------------------------------------------------------------------------------
// ----- private slots -----------------------------------------------------------------------------
// ----- private helpers ---------------------------------------------------------------------------
void SimpleCryptDevice::flushEnd()
{
    if(openMode() & WriteOnly)
    {
        quint64 realBytesWritten = writeBlock(m_byteBuffer);
        emit encryptedBytesWritten(realBytesWritten);
    }
}
Beispiel #14
0
void ZipFile::close()
{
	if (openMode() == NotOpen)
		return;
	
	zipCloseFileInZip(d->archive->d->zip);
	d->archive->d->currentZipFile = 0;
	setOpenMode(NotOpen);
}
Beispiel #15
0
qint64 ZipFile::writeData(const char *data, qint64 maxSize)
{
	if (openMode() == NotOpen)
		return 0;
	
	if (zipWriteInFileInZip(d->archive->d->zip, data, maxSize) != ZIP_OK)
		return 0;
	return maxSize;
}
void CryptFileDevice::close()
{
    if (!isOpen())
        return;

    if ((openMode() & WriteOnly) || (openMode() & Append))
        flush();

    seek(0);
    m_device->close();
    setOpenMode(NotOpen);

    if (m_encrypted)
    {
        EVP_CIPHER_CTX_cleanup(&m_encCtx);
        EVP_CIPHER_CTX_cleanup(&m_decCtx);
        m_encrypted = false;
    }
}
Beispiel #17
0
qint64 UnzipFile::readData(char *data, qint64 maxSize)
{
	if (openMode() == NotOpen)
		return 0;
	
	qint64 size = unzReadCurrentFile(d->archive->d->unzip, data, maxSize);
	if (size < 0)
		return 0;
	return size;
}
Beispiel #18
0
static voidpf openFile(voidpf opaque, const void *filename, int mode)
{
	Q_UNUSED(filename);
	
	auto ioDevice = static_cast<QIODevice *>(opaque);
	
	QIODevice::OpenMode flags;
	if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
		flags = QIODevice::ReadOnly;
	else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
		flags = QIODevice::ReadWrite;
	else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
		flags = QIODevice::WriteOnly;
	else
		return nullptr;
	
	PAINTFIELD_DEBUG << ioDevice->openMode() << flags;
	
	if (ioDevice->openMode() == QIODevice::NotOpen)
	{
		if (!ioDevice->open(flags))
		{
			PAINTFIELD_WARNING << "cannot open io device";
			return nullptr;
		}
	}
	else
	{
		if (ioDevice->openMode() != flags)
		{
			PAINTFIELD_WARNING << "wrong open mode";
			return nullptr;
		}
	}
	
	return ioDevice;
}
Beispiel #19
0
bool QLocalSocket::waitForDisconnected(int msecs)
{
    Q_D(QLocalSocket);
    if (state() == UnconnectedState)
        return false;
    if (!openMode().testFlag(QIODevice::ReadOnly)) {
        qWarning("QLocalSocket::waitForDisconnected isn't supported for write only pipes.");
        return false;
    }
    if (d->pipeReader->waitForPipeClosed(msecs)) {
        d->_q_pipeClosed();
        return true;
    }
    return false;
}
Beispiel #20
0
void QLocalSocket::close()
{
    Q_D(QLocalSocket);
    if (openMode() == NotOpen)
        return;

    QIODevice::close();
    d->serverName = QString();
    d->fullServerName = QString();

    if (state() != UnconnectedState) {
        if (bytesToWrite() > 0) {
            disconnectFromServer();
            return;
        }

        d->_q_pipeClosed();
    }
}
Beispiel #21
0
void InBandStream::setStreamState(int AState)
{
	if (streamState() != AState)
	{
		if (AState == IDataStreamSocket::Opened)
		{
			FSeqIn = 0;
			FSeqOut = 0;
			FDataIqRequestId.clear();
			FThreadLock.lockForWrite();
			QIODevice::open(openMode());
			FThreadLock.unlock();
			LOG_STRM_INFO(FStreamJid,QString("In-band stream opened, sid=%1, stanzaType=%2").arg(FStreamId).arg(FStanzaType));
		}
		else if (AState == IDataStreamSocket::Closed)
		{
			removeStanzaHandle(FSHIOpen);
			removeStanzaHandle(FSHIClose);
			removeStanzaHandle(FSHIData);
			emit readChannelFinished();

			FThreadLock.lockForWrite();
			FStreamState = AState;
			QString saveError = QIODevice::errorString();
			QIODevice::close();
			QIODevice::setErrorString(saveError);
			FReadBuffer.clear();
			FWriteBuffer.clear();
			FThreadLock.unlock();

			FReadyReadCondition.wakeAll();
			FBytesWrittenCondition.wakeAll();
			LOG_STRM_INFO(FStreamJid,QString("In-band stream closed, sid=%1").arg(FStreamId));
		}

		FThreadLock.lockForWrite();
		FStreamState = AState;
		FThreadLock.unlock();

		emit stateChanged(AState);
	}
}
Beispiel #22
0
void K3bExporter::exportTracks( const KURL::List &urls, int openmode )
{
    if( urls.empty() )
        return;

    DCOPClient *client = DCOPClient::mainClient();
    QCString appId, appObj;
    QByteArray data;

    if( openmode == -1 )
        //ask to open a data or an audio cd project
        openmode = openMode();

    if( !client->findObject( "k3b-*", "K3bInterface", "", data, appId, appObj) )
        exportViaCmdLine( urls, openmode );
    else {
        DCOPRef ref( appId, appObj );
        exportViaDCOP( urls, ref, openmode );
    }
}
bool QLocalSocket::waitForDisconnected(int msecs)
{
    Q_D(QLocalSocket);
    if (state() == UnconnectedState)
        return false;
    if (!openMode().testFlag(QIODevice::ReadOnly)) {
        qWarning("QLocalSocket::waitForDisconnected isn't supported for write only pipes.");
        return false;
    }
    QIncrementalSleepTimer timer(msecs);
    forever {
        d->bytesAvailable();    // to check if PeekNamedPipe fails
        if (d->pipeClosed)
            close();
        if (state() == UnconnectedState)
            return true;
        Sleep(timer.nextSleepTime());
        if (timer.hasTimedOut())
            break;
    }

    return false;
}
Beispiel #24
0
void HBackground::onPlayMode() {
    s_style=Play;
    openMode();
}
Beispiel #25
0
void HBackground::onSuggMode() {
    s_mode=Suggestions;
    openMode();
}
Beispiel #26
0
void HBackground::onLocalMode() {
    s_mode=Local;
    openMode();
}
Beispiel #27
0
void HBackground::onTopMode() {
    s_mode=Top;
    openMode();
}
Beispiel #28
0
void HBackground::onAlbumMode() {
    s_style=Album;
    openMode();
}
Beispiel #29
0
void HBackground::onListMode() {
    s_style=List;
    openMode();
}
Beispiel #30
0
bool WFile::isOpen() const{
	return openMode()!=QIODevice::NotOpen;
}