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();
}
bool QIODeviceProto::isWritable() const
{
  QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject());
  if (item)
    return item->isWritable();
  return false;
}
Ejemplo n.º 3
0
void FeatureExporter::exportItem(QIODevice &device, const DataProxy::FeatureList &featureList) const
{
    // early out
    if (!device.isWritable()) {
        return;
    }

    QTextStream otxt(&device);

    // prepend header
    if (m_detailLevel.testFlag(FeatureExporter::Extended)) {
        // identifying comment
        if (m_detailLevel.testFlag(FeatureExporter::Comments)) {
            otxt << QString("# %1").arg("ST Viewer export: feature list") << endl;
        }

        // prepend data with application version
        const QString version = QCoreApplication::applicationVersion();
        if (m_detailLevel.testFlag(FeatureExporter::Comments)) {
            otxt << QString("# %1").arg("version") << endl;
        }

        otxt << (version.isEmpty() ? QString("0.0.0") : version) << endl;

        // prepend ISO 8601 compliant timestamp
        if (m_detailLevel.testFlag(FeatureExporter::Comments)) {
            otxt << QString("# %1 (UTC)").arg("date") << endl;
        }

        otxt << QDateTime::currentDateTimeUtc().toString(Qt::ISODate) << endl;
    }

    exportItem(otxt, featureList);
}
Ejemplo n.º 4
0
bool QUnZip::getCurrentFile(QIODevice &d) {
    if (!isOpen()) {
        qWarning("QUnZip::locateFile File not open.");
        return false;
    }
    if (!d.isWritable()) {
        qWarning("QUnZip::getCurrentFile File not open for writing.");
        return false;
    }
    if (unzOpenCurrentFile(_d->_unzFile) != UNZ_OK) {
        qWarning("QUnZip::getCurrentFile unzOpenCurrentFile failed.");
        return false;
    }
    char * buf = new char[1024];
    Q_CHECK_PTR(buf);
    int len;
    while ((len = ::unzReadCurrentFile(_d->_unzFile,
                buf, 1024)) > 0) {
        d.writeBlock(buf, len);
    }
    delete []buf;
    ::unzCloseCurrentFile(_d->_unzFile);
    if (d.isBuffered())
        d.flush();
    if (len == 0) {
        return true;
    }
    qWarning("QUnZip::getCurrentFile unzReadCurrentFile failed.");
    return false;
}
Ejemplo n.º 5
0
bool PDFOptionsIO::writeTo(QIODevice& outDevice, bool includePasswords)
{
	m_includePasswords = includePasswords;
	if (!outDevice.isWritable())
	{
		m_error = QObject::tr("Output stream not writeable");
		return false;
	}
	QString xml = buildXMLString();
	if (xml.isNull())
		return false;
	QTextStream ts(&outDevice);
	ts.setCodec("UTF-8");
	ts << xml;
	m_includePasswords = false; // just to be paranoid
	m_error = QString::null;
	return true;
}
Ejemplo n.º 6
0
bool QImageWriterPrivate::canWriteHelper()
{
    if (!device) {
        imageWriterError = QImageWriter::DeviceError;
        errorString = QImageWriter::tr("Device is not set");
        return false;
    }
    if (!device->isOpen())
        device->open(QIODevice::WriteOnly);
    if (!device->isWritable()) {
        imageWriterError = QImageWriter::DeviceError;
        errorString = QImageWriter::tr("Device not writable");
        return false;
    }
    if (!handler && (handler = createWriteHandlerHelper(device, format)) == 0) {
        imageWriterError = QImageWriter::UnsupportedFormatError;
        errorString = QImageWriter::tr("Unsupported image format");
        return false;
    }
    return true;
}
Ejemplo n.º 7
0
bool QUnZip::getCurrentFileRaw(QIODevice &d, int &method,
        unsigned long &crc, unsigned long &uncompressed_size) {
    if (!isOpen()) {
        qWarning("QUnZip::getCurrentFileRaw File not open.");
        return false;
    }
    if (!d.isWritable()) {
        qWarning("QUnZip::getCurrentFileRaw File not open for writing.");
        return false;
    }
    if (unzOpenCurrentFile2(_d->_unzFile, &method, NULL, 1) != UNZ_OK) {
        qWarning("QUnZip::getCurrentFileRaw unzOpenCurrentFile2 failed.");
        return false;
    }
    unz_file_info fi;
    if (::unzGetCurrentFileInfo(_d->_unzFile, &fi,
                NULL, 0 , NULL, 0, NULL, 0) != UNZ_OK) {
        qWarning("QUnZip::getCurrentFileRaw unzGetCurrentFileInfo failed.");
        return false;
    }
    crc = fi.crc;
    uncompressed_size = fi.uncompressed_size;

    char * buf = new char[1024];
    Q_CHECK_PTR(buf);
    int len;
    while ((len = ::unzReadCurrentFile(_d->_unzFile,
                buf, 1024)) > 0) {
        d.writeBlock(buf, len);
    }
    delete[] buf;
    ::unzCloseCurrentFile(_d->_unzFile);
    if (d.isBuffered())
        d.flush();
    if (len == 0) {
        return true;
    }
    qWarning("QUnZip::getCurrentFileRaw unzReadCurrentFile failed.");
    return false;
}
bool QBuildingCardPropertiesWidget::write( QIODevice & device )
{
    assert( device.isOpen() && device.isWritable() );
    return true;
}