QIODevice::OpenMode QIODeviceProto::openMode() const
{
  QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject());
  if (item)
    return item->openMode();
  return QIODevice::OpenMode();
}
Exemplo n.º 2
0
//----------------------------------------------------------------------------------
void tst_QIODevice::constructing_QFile()
{
    QFile file;
    QIODevice *device = &file;

    QVERIFY(!device->isOpen());

    file.setFileName(SRCDIR "tst_qiodevice.cpp");
    QVERIFY(file.open(QFile::ReadOnly));
    QVERIFY(device->isOpen());
    QCOMPARE((int) device->openMode(), (int) QFile::ReadOnly);

    char buf[1024];
    memset(buf, 0, sizeof(buf));
    qlonglong lineLength = device->readLine(buf, sizeof(buf));
    QVERIFY(lineLength > 0);
    QCOMPARE(file.pos(), lineLength);

    file.seek(0);
    char buf2[1024];
    memset(buf2, 0, sizeof(buf2));
    QCOMPARE(file.readLine(buf2, sizeof(buf2)), lineLength);

    char *c1 = buf;
    char *c2 = buf2;
    while (*c1 && *c2) {
        QCOMPARE(*c1, *c2);
        ++c1;
        ++c2;
    }
    QCOMPARE(*c1, *c2);
}
Exemplo n.º 3
0
ColorScheme* KDE3ColorSchemeReader::read()
{
    Q_ASSERT(_device->openMode() == QIODevice::ReadOnly ||
             _device->openMode() == QIODevice::ReadWrite);

    ColorScheme* scheme = new ColorScheme();

    QRegExp comment("#.*$");
    while (!_device->atEnd()) {
        QString line(_device->readLine());
        line.remove(comment);
        line = line.simplified();

        if (line.isEmpty())
            continue;

        if (line.startsWith(QLatin1String("color"))) {
            if (!readColorLine(line, scheme))
                kWarning() << "Failed to read KDE 3 color scheme line" << line;
        } else if (line.startsWith(QLatin1String("title"))) {
            if (!readTitleLine(line, scheme))
                kWarning() << "Failed to read KDE 3 color scheme title line" << line;
        } else {
            kWarning() << "KDE 3 color scheme contains an unsupported feature, '" <<
                       line << "'";
        }
    }

    return scheme;
}
Exemplo n.º 4
0
void CompiledMaterial::save(QIODevice &dev) {
	const uint NodeData = NmtReader::Reserved + 1;

	QByteArray sh = getShader().toLatin1();
	if(!(dev.openMode() & QIODevice::WriteOnly || dev.openMode() & QIODevice::Append)) {
		dev.open(QIODevice::WriteOnly);
	}

	NmtReader::Version2Header header;
	header.version = 2;
	header.numData = 2 + samplers.size();

	dev.write((const char *)&header, sizeof(header));

	NmtReader::DataHeader h;
	h.id = NmtReader::FragShader;
	h.offset = sizeof(header) + header.numData * sizeof(h);
	dev.write((const char *)&h, sizeof(h));

	h.id = NodeData;
	h.offset += sh.size() + sizeof(uint);
	dev.write((const char *)&h, sizeof(h));

	h.offset += data.size() + sizeof(uint);
	for(int i = 0; i != samplers.size(); i++) {
		h.id = NmtReader::TextureName;
		h.offset += sizeof(uint) + samplers[i].file.toLatin1().size();
		dev.write((const char *)&h, sizeof(h));
	}

	uint len = sh.size();
	dev.write((const char *)&len, sizeof(uint));
	dev.write(sh);

	len = data.size();
	dev.write((const char *)&len, sizeof(uint));
	dev.write(data);


	for(int i = 0; i != samplers.size(); i++) {
		QByteArray name = samplers[i].file.toLatin1();
		uint len = name.size();
		dev.write((const char *)&len, sizeof(uint));
		dev.write(name);
	}
}
Exemplo n.º 5
0
voidpf ZCALLBACK qiodevice_open_file_func (
   voidpf opaque,
   voidpf file,
   int mode)
{
    QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
    QIODevice *iodevice = reinterpret_cast<QIODevice*>(file);
    QIODevice::OpenMode desiredMode;
    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
        desiredMode = QIODevice::ReadOnly;
    else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
        desiredMode = QIODevice::ReadWrite;
    else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
        desiredMode = QIODevice::WriteOnly;
    if (iodevice->isOpen()) {
        if ((iodevice->openMode() & desiredMode) == desiredMode) {
            if (desiredMode != QIODevice::WriteOnly
                    && iodevice->isSequential()) {
                // We can use sequential devices only for writing.
                delete d;
                return NULL;
            } else {
                if ((desiredMode & QIODevice::WriteOnly) != 0) {
                    // open for writing, need to seek existing device
                    if (!iodevice->isSequential()) {
                        iodevice->seek(0);
                    } else {
                        d->pos = iodevice->pos();
                    }
                }
            }
            return iodevice;
        } else {
            delete d;
            return NULL;
        }
    }
    iodevice->open(desiredMode);
    if (iodevice->isOpen()) {
        if (desiredMode != QIODevice::WriteOnly && iodevice->isSequential()) {
            // We can use sequential devices only for writing.
            iodevice->close();
            delete d;
            return NULL;
        } else {
            return iodevice;
        }
    } else {
        delete d;
        return NULL;
    }
}
Exemplo n.º 6
0
bool copyData(QIODevice& src, QIODevice& dest)
{
	bool success = false;
	if ((src.openMode() & QIODevice::ReadOnly) == 0)
		return false;
	if ((dest.openMode() & QIODevice::WriteOnly) == 0)
		return false;
	QByteArray bb( 65536, ' ' );
	if (bb.size() > 0) // Check for memory allocation failure
	{
		qint64 byteswritten;
		qint64 bytesread = src.read( bb.data(), bb.size() );
		success = (bytesread > 0);
		while (bytesread > 0)
		{
			byteswritten = dest.write( bb.data(), bytesread );
			success  &= (bytesread == byteswritten);
			bytesread = src.read( bb.data(), bb.size() );
		}
	}
	return success;
}
Exemplo n.º 7
0
voidpf ZCALLBACK qiodevice_open_file_func (
   voidpf /*opaque UNUSED*/,
   voidpf file,
   int mode)
{
    QIODevice *iodevice = reinterpret_cast<QIODevice*>(file);
    QIODevice::OpenMode desiredMode;
    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
        desiredMode = QIODevice::ReadOnly;
    else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
        desiredMode = QIODevice::ReadWrite;
    else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
        desiredMode = QIODevice::WriteOnly;
    if (iodevice->isOpen()) {
        if ((iodevice->openMode() & desiredMode) == desiredMode) {
            if (iodevice->isSequential()) {
                return NULL;
            } else {
                if ((desiredMode & QIODevice::WriteOnly) != 0) {
                    // open for writing, need to seek existing device
                    iodevice->seek(0);
                }
            }
            return iodevice;
        } else {
            return NULL;
        }
    }
    iodevice->open(desiredMode);
    if (iodevice->isOpen()) {
        if (iodevice->isSequential()) {
            iodevice->close();
            return NULL;
        } else {
            return iodevice;
        }
    } else
        return NULL;
}