コード例 #1
0
KJS::Value TextStreamImp::call( KJS::ExecState *exec, KJS::Object &/*self*/, const KJS::List &args )
{
    QString not_readable = i18n( "Attempt to read from a write-only text stream." );
    QString not_writable = i18n( "Attempt to write to a read-only text stream." );

		QString arg0 = extractQString(exec, args, 0);

    QIODevice *dev = ts->device();
    KJS::Object err;

    switch ( id ) {
	case MethodIsReadable:
	    return KJS::Boolean( dev->isReadable() );
	    break;
	case MethodIsWritable:
	    return KJS::Boolean( dev->isWritable() );
	    break;
	case MethodPrint:
	    if ( !dev->isWritable() ) {
          return throwError(exec, not_writable.utf8());
	    }
	    (*ts) << arg0; 
	    break;
	case MethodPrintLn:
	    if ( !dev->isWritable() ) {
          return throwError(exec, not_writable.utf8());
	    }
	    (*ts) << arg0 << endl;
	    break;
	case MethodReadLine:
	    if ( dev->isReadable() ) {
		QString line = ts->readLine();
		if ( line.isNull() )
		    return KJS::Null();
		else
		    return KJS::String( line );
	    }
	    else {
          return throwError(exec, not_readable.utf8());
	    }
	    break;
	case MethodFlush:
	    if ( !dev->isWritable() ) {
          return throwError(exec, not_writable.utf8());
	    }
	    (*ts) << flush; 
	    break;
	default:
	    kdWarning() << "TextStreamImp has no method " << id << endl;
	    break;
    }

    return KJS::Value();
}
コード例 #2
0
bool QIODeviceProto::isReadable() const
{
  QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject());
  if (item)
    return item->isReadable();
  return false;
}
コード例 #3
0
QNetworkRequest QNetworkAccessManagerPrivate::prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart)
{
    // copy the request, we probably need to add some headers
    QNetworkRequest newRequest(request);

    // add Content-Type header if not there already
    if (!request.header(QNetworkRequest::ContentTypeHeader).isValid()) {
        QByteArray contentType;
        contentType.reserve(34 + multiPart->d_func()->boundary.count());
        contentType += "multipart/";
        switch (multiPart->d_func()->contentType) {
        case QHttpMultiPart::RelatedType:
            contentType += "related";
            break;
        case QHttpMultiPart::FormDataType:
            contentType += "form-data";
            break;
        case QHttpMultiPart::AlternativeType:
            contentType += "alternative";
            break;
        default:
            contentType += "mixed";
            break;
        }
        // putting the boundary into quotes, recommended in RFC 2046 section 5.1.1
        contentType += "; boundary=\"" + multiPart->d_func()->boundary + "\"";
        newRequest.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(contentType));
    }

    // add MIME-Version header if not there already (we must include the header
    // if the message conforms to RFC 2045, see section 4 of that RFC)
    QByteArray mimeHeader("MIME-Version");
    if (!request.hasRawHeader(mimeHeader))
        newRequest.setRawHeader(mimeHeader, QByteArray("1.0"));

    QIODevice *device = multiPart->d_func()->device;
    if (!device->isReadable()) {
        if (!device->isOpen()) {
            if (!device->open(QIODevice::ReadOnly))
                qWarning("could not open device for reading");
        } else {
            qWarning("device is not readable");
        }
    }

    return newRequest;
}
コード例 #4
0
QDomDocument KOfficePlugin::getMetaDocument(const QString &path) const
{
    QDomDocument doc;
    KZip m_zip(path);
    QIODevice * io = getData(m_zip, IO_ReadOnly);
    if (!io || !io->isReadable())
	    return doc;
    QString errorMsg;
    int errorLine, errorColumn;
    if ( !doc.setContent( io, &errorMsg, &errorLine, &errorColumn ) ){
      kdDebug(7034) << "Error " << errorMsg.latin1()
		    << "while getting XML content at line "
		    << errorLine << ", column "<< errorColumn << endl;
    	delete io;
	return doc;
    }
    delete io;
    return doc;
}
コード例 #5
0
ファイル: pdfoptionsio.cpp プロジェクト: hasenj/scribus
bool PDFOptionsIO::readFrom(QIODevice& inDevice)
{
	if (!inDevice.isReadable())
		return false;
	QString domError;
	int errorLine, errorColumn;
	if (!m_doc.setContent(&inDevice, &domError, &errorLine, &errorColumn))
	{
		m_error = QObject::tr("Unable to read settings XML:")
			.arg(QObject::tr("%1 (line %2 col %3)", "Load PDF settings")
				.arg(domError).arg(errorLine).arg(errorColumn)
			);
		return false;
	}
	if (!readSettings())
		// m_error should already be set
		return false;
	m_error = QString::null;
	return true;
}
コード例 #6
0
ファイル: BlockHeader.cpp プロジェクト: jpoirier/x-gauges
/*! Read and parse the header block from the given input device stream. 
    The stream must be random access, binary and positioned to 0.

	 \retval true the header was read successfully.
	 \retval false the header failed to read for some reason.
 */
bool BlockHeader::Read(
	QIODevice& fIn	//! Input stream (binary, random access).
							 )
{
	ASSERT(fIn.isSequential()==false);
	ASSERT(fIn.isReadable()==true);
	ASSERT(fIn.isTextModeEnabled()==false);
	ASSERT(fIn.pos() == 0);
	ASSERT(sizeof(float) == 4);
	
	QDataStream in(&fIn);
	// Check the magic number
	quint32 uiMagic;
	in >> uiMagic;
	// OK, try to read the rest of the header.
	if(uiMagic == MAGIC_NUMBER) {
		in >> m_uiVersion;
		in >> m_iJulianDay;
		
		in >> m_fOriginLon;
		in >> m_fOriginLat;
		in >> m_fArcLon;
		in >> m_fArcLat;
		
		in >> m_uiRasterPos;
		in >> m_uiVectorPos;
		
		// The next 24 bytes are reserved. 
		// They should be zero, but we do not read them, just skip them.
		// Some additional checks are fast and harmless.
		if(   m_uiVersion >= 1 
		   && m_iJulianDay > 2454110 // 9.Jan.2007
			&& m_fArcLon >= 1.0f
			&& m_fArcLat >= 1.0f
			&& fIn.size() >= MBH_HEADER_SIZE
		  ) {
			fIn.seek(MBH_HEADER_SIZE); // position the file pointer to the 64-th byte.
			return true;
		}
	}
コード例 #7
0
ファイル: memorymap.cpp プロジェクト: wxdublin/insight-vmi
void MemoryMap::diffWith(MemoryMap* other)
{
    _pmemDiff.clear();

    QIODevice* dev = _vmem->physMem();
    QIODevice* otherDev = other->vmem()->physMem();
    if (!otherDev || !dev)
        return;

    assert(dev != otherDev);

    // Open devices for reading, if required
    if (!dev->isReadable()) {
        if (dev->isOpen())
            dev->close();
        assert(dev->open(QIODevice::ReadOnly));
    }
    else
        assert(dev->reset());

    if (!otherDev->isReadable()) {
        if (otherDev->isOpen())
            otherDev->close();
        assert(otherDev->open(QIODevice::ReadOnly));
    }
    else
        assert(otherDev->reset());

    QTime timer;
    timer.start();
    bool wasEqual = true, equal = true;
    quint64 addr = 0, startAddr = 0, length = 0;
    const int bufsize = 1024;
    const int granularity = 16;
    char buf1[bufsize], buf2[bufsize];
    qint64 readSize1, readSize2;
    qint64 done, prevDone = -1;
    qint64 totalSize = qMin(dev->size(), otherDev->size());
    if (totalSize < 0)
        totalSize = qMax(dev->size(), otherDev->size());

    // Compare the complete physical address space
    while (!Console::interrupted() && !dev->atEnd() && !otherDev->atEnd()) {
        readSize1 = dev->read(buf1, bufsize);
        readSize2 = otherDev->read(buf2, bufsize);

        if (readSize1 <= 0 || readSize2 <= 0)
            break;

        qint64 size = qMin(readSize1, readSize2);
        for (int i = 0; i < size; ++i) {
            if (buf1[i] != buf2[i])
                equal = false;
            // We only consider memory chunks of size "granularity"
            if (addr % granularity == granularity - 1) {
                // Memory is equal
                if (equal) {
                    // Add difference to tree
                    if (!wasEqual)
                        _pmemDiff.insert(Difference(startAddr, length));
                }
                // Memory differs
                else {
                    // Start new difference
                    if (wasEqual) {
                        startAddr = addr - (addr % granularity);
                        length = granularity;
                    }
                    // Enlarge difference
                    else
                        length += granularity;
                }
                wasEqual = equal;
            }
            ++addr;
            equal = true;
        }

        done = (int) (addr / (float) totalSize * 100);
        if (prevDone < 0 || (done != prevDone && timer.elapsed() > 500)) {
            Console::out() << "\rComparing memory dumps: " << done << "%" << flush;
            prevDone = done;
            timer.restart();
        }
    }

    // Add last difference, if any
    if (!wasEqual)
        _pmemDiff.insert(Difference(startAddr, length));

    Console::out() << "\rComparing memory dumps finished." << endl;

//    debugmsg("No. of differences: " << _pmemDiff.objectCount());
}
コード例 #8
0
bool QBuildingCardPropertiesWidget::read( QIODevice & device )
{
    assert( device.isOpen() && device.isReadable() );
    return true;
}
コード例 #9
0
ファイル: generator_tiff.cpp プロジェクト: JPriya/Okular
tsize_t okular_tiffReadProc( thandle_t handle, tdata_t buf, tsize_t size )
{
    QIODevice * device = static_cast< QIODevice * >( handle );
    return device->isReadable() ? device->read( static_cast< char * >( buf ), size ) : -1;
}