Example #1
0
DriDriver::DriDriver(QXmlStreamReader *xml)
{
    QXmlStreamAttributes attributes = xml->attributes();

    applications.clear();

    if (attributes.hasAttribute("driver"))
        driver = attributes.value("driver").toString();
    else
        driver.clear();

    if (attributes.hasAttribute("screen")) {
        bool ok = 0;
        screen = attributes.value("screen").toInt(&ok);
    } else
        screen = -1;

    while (xml->readNextStartElement()) {
        if (xml->name() == "application")
            DriApplication::insertList(&applications, new DriApplication(xml));
        else
            xml->skipCurrentElement();
    }
}
Example #2
0
void QgsOSMXmlImport::readNode( QXmlStreamReader& xml )
{
  // <node id="2197214" lat="50.0682113" lon="14.4348483" user="******" uid="595326" visible="true" version="10" changeset="10714591" timestamp="2012-02-17T19:58:49Z">
  QXmlStreamAttributes attrs = xml.attributes();
  QgsOSMId id = attrs.value( "id" ).toString().toLongLong();
  double lat = attrs.value( "lat" ).toString().toDouble();
  double lon = attrs.value( "lon" ).toString().toDouble();

  // insert to DB
  sqlite3_bind_int64( mStmtInsertNode, 1, id );
  sqlite3_bind_double( mStmtInsertNode, 2, lat );
  sqlite3_bind_double( mStmtInsertNode, 3, lon );

  if ( sqlite3_step( mStmtInsertNode ) != SQLITE_DONE )
  {
    xml.raiseError( QString( "Storing node %1 failed." ).arg( id ) );
  }

  sqlite3_reset( mStmtInsertNode );

  while ( !xml.atEnd() )
  {
    xml.readNext();

    if ( xml.isEndElement() ) // </node>
      break;

    if ( xml.isStartElement() )
    {
      if ( xml.name() == "tag" )
        readTag( false, id, xml );
      else
        xml.raiseError( "Invalid tag in <node>" );
    }
  }
}
void InstanceParser::readItem()
{
    Q_ASSERT(isStartElement()
             && name() == "item");

    QXmlStreamAttributes elementAttributes = attributes();
    if(m_type == InstanceParser::MultipleKnapsack) {
        if(elementAttributes.hasAttribute("height")
                && elementAttributes.hasAttribute("profit"))
        {
            ProfitItem item;
            item.setSize(elementAttributes.value("height").toString().toInt());
            item.setProfit(elementAttributes.value("profit").toString().toInt());

            m_mkpItems.append(item);
        }
    }
    else if(m_type == InstanceParser::BinPacking) {
        if(elementAttributes.hasAttribute("height")) {
            FloatItem item;
            item.setSize(elementAttributes.value("height").toString().toFloat());

            m_binItems.append(item);
        }
    }

    while(!atEnd()) {
        readNext();

        if(isEndElement())
            break;

        if(isStartElement())
            readUnknownElement();
    }
}
void FluidLauncher::parseDemos(QXmlStreamReader& reader)
{
    while (!reader.atEnd()) {
        reader.readNext();
        if (reader.isStartElement() && reader.name() == "example") {
            QXmlStreamAttributes attrs = reader.attributes();
            QStringRef filename = attrs.value("filename");
            if (!filename.isEmpty()) {
                QStringRef name = attrs.value("name");
                QStringRef image = attrs.value("image");
                QStringRef args = attrs.value("args");

                DemoApplication* newDemo = new DemoApplication(
                        filename.toString(),
                        name.isEmpty() ? "Unnamed Demo" : name.toString(),
                        image.toString(),
                        args.toString().split(" "));
                demoList.append(newDemo);
            }
        } else if(reader.isEndElement() && reader.name() == "demos") {
            return;
        }
    }
}
Example #5
0
void LayoutParser::parseKeyboard()
{
    const QXmlStreamAttributes attributes(m_xml.attributes());
    const QString version(attributes.value(QLatin1String("version")).toString());
    const QString actual_version(version.isEmpty() ? "1.0" : version);
    const QString title(attributes.value(QLatin1String("title")).toString());
    const QString language(attributes.value(QLatin1String("language")).toString());
    const QString catalog(attributes.value(QLatin1String("catalog")).toString());
    const bool autocapitalization(boolValue(attributes.value(QLatin1String("autocapitalization")), true));
    m_keyboard = TagKeyboardPtr(new TagKeyboard(actual_version, title, language,
                                                catalog, autocapitalization));

    while (m_xml.readNextStartElement()) {
        const QStringRef name(m_xml.name());

        if (name == QLatin1String("import")) {
            parseImport();
        } else if (name == QLatin1String("layout")) {
            parseLayout();
        } else {
            error(QString::fromLatin1("Expected '<layout>' or '<import>', but got '<%1>'.").arg(name.toString()));
        }
    }
}
Example #6
0
//------------------------------------------------------------------------------
QString getCommentForChapter(const QString f_path, const QString f_book, const QString f_chapter)
{
    // hindi
    QString r_str = "";

    //    myDebug() << isExistBook(f_path, f_book);

    QString t_findBook;
    if (isExistBook(f_path, f_book, &t_findBook));
    {
        if (!t_findBook.isEmpty())
        {
            QString t_path = f_path;
            t_path.replace("module" + GL_FORMAT_MODULE
                           , "text" + GL_FORMAT_TEXT);

            QXmlStreamReader xmlReader;
            xmlReader.addData(getTextFromHtmlFile(t_path));

            bool flag = false;
            while(!xmlReader.atEnd() and !flag)
            {
                if(xmlReader.isStartElement())
                {
                    QStringList sl;
                    sl << xmlReader.name().toString();
                    QXmlStreamAttributes attrs = xmlReader.attributes();
                    if (attrs.value("name").toString() == t_findBook)
                    {
                        while(!xmlReader.atEnd() and !flag)
                        {
                            if (xmlReader.attributes().value("number") == f_chapter)
                            {
                                flag = true;
                                QString str = xmlReader.readElementText();
                                str.remove("    ");
                                r_str = str;
                            }
                            xmlReader.readNext();
                        }
                    }
                }
                xmlReader.readNext();
            }
        }
    }
    return r_str;
}
Example #7
0
// Constructor for parser function
Message::Message(XmlStreamReader& xml)
 :  QObject(),
    m_timeStamp(),
    m_timeStampPresent( false ),
    m_code( 0 ),
    m_codePresent( false ),
    m_version( "1.0.0" ), // initialize fixed value
    m_versionPresent( true ),
    m_changed(true)
{
    QXmlStreamAttributes attr = xml.attributes();
    if ( attr.hasAttribute( "TimeStamp" ) )
    {
        if ( !setTimeStamp( QDateTime::fromString(attr.value( "TimeStamp" ).toString(), Qt::ISODate)) )
            xml.validationError( "error set TimeStamp = " + attr.value( "TimeStamp" ).toString() );
    }
    if ( attr.hasAttribute( "Code" ) )
    {
        if ( !setCode( attr.value( "Code" ).toString().toInt() ) )
            xml.validationError( "error set Code = " + attr.value( "Code" ).toString() );
    }
    if ( attr.hasAttribute( "Version" ) )
    {
        if ( !setVersion( attr.value( "Version" ).toString() ) )
            xml.validationError( "error set Version = " + attr.value( "Version" ).toString() );
    }
    bool stop(false);
    while(!xml.atEnd() && !stop)
    {
        QXmlStreamReader::TokenType token = xml.readNext();
        switch ( token )
        {
        case QXmlStreamReader::EndElement:
            if (  xml.name() == "Message" )
                stop = true;
            break;
        case QXmlStreamReader::StartElement:
            if ( xml.name() == "Argument" )
            {
                QString val = xml.readElementText();
                if ( xml.name() != "Argument" )
                    xml.raiseError( "tag mismatch Argument" );
                else if ( !addArgument( val ) )
                    xml.validationError( "error add Argument"  );
            }
            else
            {
                xml.validationError( "unexpected element " + xml.name().toString() );
            }
            break;
        default:
            break;
        }
    }
}
FileCmdExport::FileCmdExport (QXmlStreamReader &reader) :
  FileCmdAbstract (CMD_DESCRIPTION)
{
  LOG4CPP_INFO_S ((*mainCat)) << "FileCmdExport::FileCmdExport";

  QXmlStreamAttributes attributes = reader.attributes();

  if (!attributes.hasAttribute(FILE_CMD_SERIALIZE_FILENAME)) {
    xmlExitWithError (reader,
                      QString ("%1 %2")
                      .arg (QObject::tr ("Missing attribute"))
                      .arg (FILE_CMD_SERIALIZE_FILENAME));
  }

  m_filename = attributes.value(FILE_CMD_SERIALIZE_FILENAME).toString();
}
Example #9
0
void PodcastParser::ParseOutline(QXmlStreamReader* reader, OpmlContainer* ret) const {
  while (!reader->atEnd()) {
    QXmlStreamReader::TokenType type = reader->readNext();
    switch (type) {
    case QXmlStreamReader::StartElement: {
      const QStringRef name = reader->name();
      if (name != "outline") {
        Utilities::ConsumeCurrentElement(reader);
        continue;
      }

      QXmlStreamAttributes attributes = reader->attributes();

      if (attributes.value("type").toString() == "rss") {
        // Parse the feed and add it to this container
        Podcast podcast;
        podcast.set_description(attributes.value("description").toString());
        podcast.set_title(attributes.value("text").toString());
        podcast.set_image_url_large(QUrl::fromEncoded(attributes.value("imageHref").toString().toAscii()));
        podcast.set_url(QUrl::fromEncoded(attributes.value("xmlUrl").toString().toAscii()));
        ret->feeds.append(podcast);

        // Consume any children and the EndElement.
        Utilities::ConsumeCurrentElement(reader);
      } else {
        // Create a new child container
        OpmlContainer child;

        // Take the name from the fullname attribute first if it exists.
        child.name = attributes.value("fullname").toString();
        if (child.name.isEmpty()) {
          child.name = attributes.value("text").toString();
        }

        // Parse its contents and add it to this container
        ParseOutline(reader, &child);
        ret->containers.append(child);
      }

      break;
    }

    case QXmlStreamReader::EndElement:
      return;

    default:
      break;
    }
  }
}
Example #10
0
void CMakeCbpParser::parseUnitOption()
{
    const QXmlStreamAttributes optionAttributes = attributes();
    m_parsingCmakeUnit = optionAttributes.hasAttribute(QLatin1String("virtualFolder"));
    m_unitTarget = optionAttributes.value(QLatin1String("target")).toString();

    while (!atEnd()) {
        readNext();

        if (isEndElement())
            break;

        if (isStartElement())
            parseUnknownElement();
    }
}
Example #11
0
void
DirectParser::ParseCtl (QXmlStreamReader & xread, 
                            DirectMessage    & msg,
                            qint64           & offset,
                            bool             & complete,
                            bool             & good,
                            QXmlStreamAttributes & atts)
{
  QString subop = atts.value("subop").toString().toLower();
  msg.SetSubop (subop);
  if (subop == "heartbeat") {
    complete = true;
    good = true;
  }
  ReadNext (xread);
}
void GetTrackInfo::get_finished(QNetworkReply *reply)
{
    int elapsed = time.elapsed();
    if ( reply->error() != QNetworkReply::NoError ) {
        emit add_log(LOG_ERROR, tr("API: Failed to download track length: %1")
                     .arg(reply->errorString()));
        emit finished(index, false, 0, elapsed);
        return;
    }

    QString result(reply->readAll());
    reader->addData(result);
    reader->readNext();
    if (reader->atEnd())
    {
        emit add_log(LOG_ERROR, tr("API: Empty XML"));
        emit finished(index, false, 0, elapsed);
        return;
    }
    QString status;
    int length = 0;
    while (!reader->atEnd())
    {
        if (reader->isStartElement())
        {
            if (reader->name() == "lfm")
            {
                QXmlStreamAttributes attributes = reader->attributes();
                status = attributes.value("status").toString();
            }
            if (reader->name() == "duration")
            {
                length = reader->readElementText().toInt()/1000;
            }
        }
        reader->readNext();
    }

    emit add_log(LOG_TRACE, QString("API: %1 is %2, took %3")
                 .arg(index)
                 .arg(length)
                 .arg(elapsed/1000.0));
    if (status.startsWith("ok"))
        emit finished(index, true, length, elapsed);
    else
        emit finished(index, false, 0, elapsed);
}
void ProjectReader::readProject(QIODevice *device, const QString &path) {
    xml.setDevice(device);
    
    QString mapPath = path + "/Maps";
    QString scriptPath = path + "/Scripts";
    
    if (xml.readNextStartElement() && xml.name() == QLatin1String("AuroraProject")) {
        const QXmlStreamAttributes atts = xml.attributes();
        const int mapCount = 
                atts.value(QLatin1String("mapCount")).toString().toInt();
        const int scriptCount = 
                atts.value(QLatin1String("scriptCount")).toString().toInt();
        const int spriteCount = 
                atts.value(QLatin1String("spriteCount")).toString().toInt();
        const int tilesetCount = 
                atts.value(QLatin1String("tilesetCount")).toString().toInt();
        const int objectCount = 
                atts.value(QLatin1String("objectCount")).toString().toInt();
        
        mDocumentManager->setMapCount(mapCount);
        mDocumentManager->setScriptCount(scriptCount);
        mDocumentManager->setSpriteCount(spriteCount);
        mDocumentManager->setTilesetCount(tilesetCount);
        mDocumentManager->setObjectCount(objectCount);
        
        while (xml.readNextStartElement()) {
            const QXmlStreamAttributes att = xml.attributes();
            //qDebug() << "look an element";
            if (xml.name() == QLatin1String("Map")) {
                //qDebug() << "look a map";
                QString name = att.value(QLatin1String("path")).toString();
                readMaps(mapPath, name, true);
            } else if (xml.name() == QLatin1String("Script")) {
                //qDebug() << "look a script";
                QString name = att.value(QLatin1String("path")).toString();
                //qDebug() << "name" << name;
                readScripts(scriptPath, name, true);
            } else if (xml.name() == QLatin1String("Last")) {
                //qDebug() << "look a last";
                readLastOpen();
            } else {
                readUnknownElement();
            }
        }
        
    } else {
        xml.raiseError(tr("Not a project file."));
    }
}
Example #14
0
void EventFactory::handleStartElement(const QStringRef &name, const QStringRef &uri,
									  const QXmlStreamAttributes &attributes)
{
	m_depth++;
	if (m_depth == 1) {
		m_event.reset(new Event);
	} if (m_depth == 2 && name == QLatin1String("items")) {
		m_factory = findFactory(attributes.value(QLatin1String("node")));
		m_state = m_factory ? AtItems : AtNowhere;
	} else if (m_depth == 3 && m_state == AtItems && name == QLatin1String("item")) {
		m_state = AtItem;
	} else if (m_depth == 4 && m_state == AtItem && m_factory->canParse(name, uri, attributes)) {
		m_state = AtEntity;
	}
	if (m_state == AtEntity)
		m_factory->handleStartElement(name, uri, attributes);
}
Example #15
0
void ErrorFactory::handleStartElement(const QStringRef& name, const QStringRef& uri, const QXmlStreamAttributes& attributes)
{
	Q_UNUSED(uri);
	m_depth++;
	if (m_depth == 1) {
		QStringRef subtype = attributes.value(QLatin1String("type"));
		m_type = strToEnum<Error::Type>(subtype,error_types);
		m_text.clear();
	} else if(m_depth == 2) {
		if(name == QLatin1String("text"))
			m_state = AtText;
		else {
			m_condition = strToEnum<Error::Condition>(name,error_conditions);
			m_state = AtCondition;
		}
	}
}
Example #16
0
const MapGrid& MapGrid::load(QXmlStreamReader& xml)
{
	Q_ASSERT(xml.name() == "grid");
	
	QXmlStreamAttributes attributes = xml.attributes();
	color = QColor(attributes.value("color").toString()).rgba();
	display = (MapGrid::DisplayMode) attributes.value("display").toString().toInt();
	alignment = (MapGrid::Alignment) attributes.value("alignment").toString().toInt();
	additional_rotation = attributes.value("additional_rotation").toString().toDouble();
	unit = (MapGrid::Unit) attributes.value("unit").toString().toInt();
	horz_spacing = attributes.value("h_spacing").toString().toDouble();
	vert_spacing = attributes.value("v_spacing").toString().toDouble();
	horz_offset = attributes.value("h_offset").toString().toDouble();
	vert_offset = attributes.value("v_offset").toString().toDouble();
	snapping_enabled = (attributes.value("snapping_enabled") == "true");
	xml.skipCurrentElement();
	
	return *this;
}
Example #17
0
bool ChartPrivate::loadXmlAxis(QXmlStreamReader &reader)
{
    Q_ASSERT(reader.name().endsWith(QLatin1String("Ax")));
    QString name = reader.name().toString();

    XlsxAxis *axis = new XlsxAxis;
    if (name == QLatin1String("valAx"))
        axis->type = XlsxAxis::T_Val;
    else if (name == QLatin1String("catAx"))
        axis->type = XlsxAxis::T_Cat;
    else if (name == QLatin1String("serAx"))
        axis->type = XlsxAxis::T_Ser;
    else
        axis->type = XlsxAxis::T_Date;

    axisList.append(QSharedPointer<XlsxAxis>(axis));

    while (!reader.atEnd()) {
        reader.readNextStartElement();
        if (reader.tokenType() == QXmlStreamReader::StartElement) {
            if (reader.name() == QLatin1String("axPos")) {
                QXmlStreamAttributes attrs = reader.attributes();
                QStringRef pos = attrs.value(QLatin1String("val"));
                if (pos==QLatin1String("l"))
                    axis->axisPos = XlsxAxis::Left;
                else if (pos==QLatin1String("r"))
                    axis->axisPos = XlsxAxis::Right;
                else if (pos==QLatin1String("b"))
                    axis->axisPos = XlsxAxis::Bottom;
                else
                    axis->axisPos = XlsxAxis::Top;
            } else if (reader.name() == QLatin1String("axId")) {
                axis->axisId = reader.attributes().value(QLatin1String("val")).toString().toInt();
            } else if (reader.name() == QLatin1String("crossAx")) {
                axis->crossAx = reader.attributes().value(QLatin1String("val")).toString().toInt();
            }
        } else if (reader.tokenType() == QXmlStreamReader::EndElement
                   && reader.name() == name) {
            break;
        }
    }

    return true;
}
Example #18
0
QString CurveStyle::loadXml(QXmlStreamReader &reader)
{
    LOG4CPP_INFO_S ((*mainCat)) << "CurveStyle::loadXml";

    bool success = true;
    QString curveName;

    QXmlStreamAttributes attributes = reader.attributes();

    if (attributes.hasAttribute(DOCUMENT_SERIALIZE_CURVE_NAME)) {

        curveName = attributes.value (DOCUMENT_SERIALIZE_CURVE_NAME).toString();

        // Read until end of this subtree
        while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
                (reader.name() != DOCUMENT_SERIALIZE_POINT_STYLE)) {
            loadNextFromReader(reader);

            if (reader.atEnd()) {
                success = false;
                break;
            }

            if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
                    (reader.name() == DOCUMENT_SERIALIZE_LINE_STYLE)) {

                m_lineStyle.loadXml (reader);

            } else if ((reader.tokenType() == QXmlStreamReader::StartElement) &
                       (reader.name() == DOCUMENT_SERIALIZE_POINT_STYLE)) {

                m_pointStyle.loadXml (reader);

            }
        }
    }

    if (!success) {
        reader.raiseError ("Cannot read curve style data");
    }

    return curveName;
}
Example #19
0
bool CodeGenerator::uiData(const QString &uiXml, QString *formBaseClass, QString *uiClassName)
{
    // Parse UI xml to determine
    // 1) The ui class name from "<class>Designer::Internal::FormClassWizardPage</class>"
    // 2) the base class from: widget class="QWizardPage"...
    QXmlStreamReader reader(uiXml);
    while (!reader.atEnd()) {
        if (reader.readNext() == QXmlStreamReader::StartElement) {
            if (reader.name() == QLatin1String("class")) {
                *uiClassName = reader.readElementText();
            } else if (reader.name() == QLatin1String("widget")) {
                const QXmlStreamAttributes attrs = reader.attributes();
                *formBaseClass = attrs.value(QLatin1String("class")).toString();
                return !uiClassName->isEmpty() && !formBaseClass->isEmpty();
            }
        }
    }
    return false;
}
Example #20
0
static bool DecodeCamera(QXmlStreamReader& stream, CameraDesc& camera)
{
	assert(stream.name() == "camera");

	QXmlStreamAttributes cameraAttributes = stream.attributes();
	if (	!cameraAttributes.hasAttribute("id")
		||	!cameraAttributes.hasAttribute("sensor_id")
		||	!cameraAttributes.hasAttribute("label"))
	{
		//invalid camera?!
		assert(false);
		return false;
	}
	
	camera.id = cameraAttributes.value("id").toInt();
	camera.sensorId = cameraAttributes.value("sensor_id").toInt();
	camera.imageFilename = cameraAttributes.value("label").toString();

	while (stream.readNextStartElement())
	{
#ifdef _DEBUG
		//DisplayCurrentNodeInfo(stream);
#endif

		if (stream.name() == "transform")
		{
			QString transformationValues = stream.readElementText();
			DecodeTransformation<float>(transformationValues, camera.trans);
		}
		else if (stream.name() == "reference")
		{
			QXmlStreamAttributes attributes = stream.attributes();
			if (attributes.value("enabled").toString() == "true")
			{
				CCVector3d T = {	attributes.value("x").toDouble(),
									attributes.value("y").toDouble(),
									attributes.value("z").toDouble() };
				//What is exactly the "reference" point?!
				//camera.trans.setTranslation(CCVector3::fromArray(T.u));
			}
			stream.skipCurrentElement();
		}
		else //orientation? Not sure what it corresponds to!
		{
			stream.skipCurrentElement();
		}
	}

	return true;
}
void InstanceParser::readBin()
{
    Q_ASSERT(isStartElement()
             && name() == "bin");

    QXmlStreamAttributes elementAttributes = attributes();
    if(elementAttributes.hasAttribute("height")) {
        m_sizes.append(elementAttributes.value("height").toString().toInt());
    }

    while(!atEnd()) {
        readNext();

        if(isEndElement())
            break;

        if(isStartElement())
            readUnknownElement();
    }
}
Example #22
0
void ProjectFile::ReadCheckPaths(QXmlStreamReader &reader)
{
    QXmlStreamReader::TokenType type;
    bool allRead = false;
    do
    {
        type = reader.readNext();
        switch (type)
        {
        case QXmlStreamReader::StartElement:

            // Read dir-elements
            if (reader.name().toString() == PathName)
            {
                QXmlStreamAttributes attribs = reader.attributes();
                QString name = attribs.value("", PathNameAttrib).toString();
                if (!name.isEmpty())
                    mPaths << name;
            }
            break;

        case QXmlStreamReader::EndElement:
            if (reader.name().toString() == PathsElementName)
                allRead = true;
            break;

            // Not handled
        case QXmlStreamReader::NoToken:
        case QXmlStreamReader::Invalid:
        case QXmlStreamReader::StartDocument:
        case QXmlStreamReader::EndDocument:
        case QXmlStreamReader::Characters:
        case QXmlStreamReader::Comment:
        case QXmlStreamReader::DTD:
        case QXmlStreamReader::EntityReference:
        case QXmlStreamReader::ProcessingInstruction:
            break;
        }
    }
    while (!allRead);
}
Example #23
0
bool MimeType::loadMimeTypes(LiteApi::IMimeTypeManager *manager, QIODevice *dev, const QString &/*fileName*/)
{
    QXmlStreamReader reader(dev);
    QXmlStreamAttributes attrs;
    MimeType *mimeType = 0;
    while (!reader.atEnd()) {
        switch (reader.readNext()) {
        case QXmlStreamReader::StartElement:
            attrs = reader.attributes();
            if (reader.name() == "mime-type" && mimeType == 0) {
                mimeType = new MimeType;
                mimeType->setType(attrs.value("type").toString());
                mimeType->setCodec(attrs.value("codec").toString());
                mimeType->setScheme(attrs.value("scheme").toString());
            } else if (reader.name() == "sub-class-of" && mimeType) {
                mimeType->appendSubClassesOf(attrs.value("type").toString());
            } else if (reader.name() == "comment" && mimeType) {
                QString locale = attrs.value("xml:lang").toString();
                const QString comment = QCoreApplication::translate("MimeType", reader.readElementText().toLatin1());
                if (locale.isEmpty()) {
                    mimeType->setComment(comment);
                } else {
                    mimeType->appendLocalComment(locale,comment);
                }
            } else if (reader.name() == "glob" && mimeType) {
                mimeType->appendGlobPatterns(attrs.value("pattern").toString());
            }
            break;
        case QXmlStreamReader::EndElement:
            if (reader.name() == "mime-type") {
                bool b = false;
                if (mimeType && !mimeType->isEmpty()) {
                    if (manager->addMimeType(mimeType)) {
                        b = true;
                    }
                }
                if (!b) {
                    delete mimeType;
                }
                mimeType = 0;
            }
            break;
        default:
            break;
        }
    }
    return true;
}
Example #24
0
void QgsOSMXmlImport::readTag( bool way, QgsOSMId id, QXmlStreamReader& xml )
{
  QXmlStreamAttributes attrs = xml.attributes();
  QByteArray k = attrs.value( "k" ).toString().toUtf8();
  QByteArray v = attrs.value( "v" ).toString().toUtf8();
  xml.skipCurrentElement();

  sqlite3_stmt* stmtInsertTag = way ? mStmtInsertWayTag : mStmtInsertNodeTag;

  sqlite3_bind_int64( stmtInsertTag, 1, id );
  sqlite3_bind_text( stmtInsertTag, 2, k.constData(), -1, SQLITE_STATIC );
  sqlite3_bind_text( stmtInsertTag, 3, v.constData(), -1, SQLITE_STATIC );

  int res = sqlite3_step( stmtInsertTag );
  if ( res != SQLITE_DONE )
  {
    xml.raiseError( QString( "Storing tag failed [%1]" ).arg( res ) );
  }

  sqlite3_reset( stmtInsertTag );
}
Example #25
0
//------------------------------------------------------------------------------
QStringList getListWord(QString filename)
{
    QStringList r_list;
    QXmlStreamReader xmlReader;

    xmlReader.addData(getTextFromHtmlFile(filename));
    while(!xmlReader.atEnd())
    {
        if(xmlReader.isStartElement())
        {
            QStringList sl;
            sl << xmlReader.name().toString();
            QXmlStreamAttributes attrs = xmlReader.attributes();
            //         myDebug() << attrs.value("name").toString();
            r_list.append(attrs.value("name").toString());
        }
        xmlReader.readNext();
    }
    r_list = removeEmptyQStringFromQStringList(&r_list);
    return r_list;
}
void xmlReader::parseBuild(QXmlStreamReader& xml) {
    if(xml.tokenType() != QXmlStreamReader::StartElement && xml.name() == "build") {
        return;
    }
    QXmlStreamAttributes attributes = xml.attributes();
    if(attributes.hasAttribute("buildNumber")) {
        buildNumber.insertMulti("buildNumber",attributes.value("buildNumber").toString());
        qDebug()<<attributes.value("buildNumber").toString();
    }
    if(attributes.hasAttribute("buildName")) {
        buildName.insertMulti("buildName",attributes.value("buildName").toString());
        qDebug()<<attributes.value("buildName").toString();
    }
    if(attributes.hasAttribute("buildDescription")) {
        buildDescription.insertMulti("buildDescription",attributes.value("buildDescription").toString());
        qDebug()<<attributes.value("buildDescription").toString();
    }
    if(attributes.hasAttribute("buildDirectory")) {
        buildDirectory.insertMulti("buildDirectory",attributes.value("buildDirectory").toString());
        qDebug()<<attributes.value("buildDirectory").toString();
    }
    xml.readNext();
}
Example #27
0
void
DirectParser::ParseMessage (QXmlStreamReader & xread, 
                            DirectMessage    & msg,
                            qint64           & offset,
                            bool             & complete,
                            bool             & good)
{
  QXmlStreamReader::TokenType tokt = NoWhite (xread);
  offset = xread.characterOffset ();
  QXmlStreamAttributes atts;
  QString op;
  QString tag;
  switch (tokt) {
  case QXmlStreamReader::StartElement:
    atts = xread.attributes();
    tag = xread.name().toString();
    op = atts.value ("op").toString().toLower();
    msg.SetOp (op);
    if (tag == "cmd") {
      if (op == "xmpp") {
        ParseXmpp (xread, msg, offset, complete, good, atts);
      } else if (op == "ctl") {
        ParseCtl (xread, msg, offset, complete, good, atts);
      } else if (op == "sendfile") {
        ParseSendfile (xread, msg, offset, complete, good, atts);
      }
      offset = xread.characterOffset ();
      if (xread.tokenType() != QXmlStreamReader::EndElement
         || xread.name() != tag) {
        complete = false;
        good = false;
      }
    }
    break;
  default:
    complete = false;
    good = false;
    break;
  }
}
ScreenieScene *XmlScreenieSceneDao::read() const
{
    ScreenieScene *result = 0;
    if (d->device.open(QIODevice::ReadOnly)) {
        d->streamReader = new QXmlStreamReader(&d->device);
        QXmlStreamReader::TokenType tokenType;
        while ((tokenType = d->streamReader->readNext()) != QXmlStreamReader::EndDocument) {
            if (tokenType == QXmlStreamReader::StartElement) {
                if (d->streamReader->name() == "screeniescene") {
                    QXmlStreamAttributes sceneAttributes = d->streamReader->attributes();
                    QString versionString = sceneAttributes.value("version").toString();
                    Version documentVersion(versionString);
                    if (documentVersion < d->version) {
                        /*!\todo Convert file to current version */
#ifdef DEBUG
                        qDebug("XmlScreenieSceneDao::read: CONVERSION NEEDED, document version: %s, app version: %s", qPrintable(documentVersion.toString()), qPrintable(d->version.toString()));
#endif
                    }
                    result = readScreenieScene();
                } else {
                    result = 0;
                }
            }
            if (d->streamReader->error() != QXmlStreamReader::NoError) {
                // Note: we do not deal yet with QXmlStreamReader::PrematureEndOfDocumentError: disk files
                // should always be complete XML
#ifdef DEBUG
                qDebug("XmlScreenieSceneDao::read: error: %d", d->streamReader->error());
#endif
                result = 0;
                break;
            }
        }
        d->device.close();
    } else {
        result = 0;
    }
    cleanUp();
    return result;
}
Example #29
0
void
DirectParser::ParseSendfile (QXmlStreamReader & xread, 
                            DirectMessage    & msg,
                            qint64           & offset,
                            bool             & complete,
                            bool             & good,
                            QXmlStreamAttributes & atts)
{
  QString subop = atts.value("subop").toString().toLower();
  msg.SetSubop (subop);
  bool valid (false);
  if (subop == "chunk-data") {
    ReadNext (xread);
    if (xread.isCharacters ()) {
      msg.SetData (xread.text().toString().toUtf8());
      valid = true;
      ReadNext (xread);
    }
    offset = xread.characterOffset ();
  } else {
    valid= ( subop == "sendreq"
          || subop == "samreq"
          || subop == "goahead"
          || subop == "deny"
          || subop == "chunk-ack"
          || subop == "snd-done"
          || subop == "abort"
           );
    ReadNext (xread);
  }
  if (valid) {
    for (int i=0; i< atts.size(); i++) {
      msg.SetAttribute (atts[i].name().toString().toLower(),
                        atts[i].value().toString());
    }
    good = true;
    complete = true;
    offset = xread.characterOffset ();
  } 
}
Example #30
0
// -----------------------------------------------------
// General
// -----------------------------------------------------
ReQrcHelper::ReQrcHelper( const QString& _qrcFilename )
: m_file( "", 0 )
, m_isValid( false )
{	
	QFile file( _qrcFilename );
	if( file.open( QFile::ReadOnly | QFile::Text ) )
	{
		m_reader.setDevice( &file );
		m_reader.readNext();
		while( !m_reader.atEnd() )
		{
			if( m_reader.isStartElement() )
			{
				//QString name = m_reader.name().toString();
				if( sQResource == m_reader.name().toString() )
				{
					m_resource.Clear();					
					QXmlStreamAttributes attributes = m_reader.attributes();
					if( attributes.hasAttribute( sPrefix ) )
						m_resource.SetPrefix( attributes.value( sPrefix ).toString() );

					ReadResourceElement();

					m_resourceList.push_back( m_resource );
				}
				else
				{
					m_reader.readNext();
				}
			}
			else
			{
				m_reader.readNext();
			}
		}

		m_isValid = !m_reader.hasError();
	}
}