Example #1
0
bool Fixture::loadXML(QXmlStreamReader &xmlDoc, Doc *doc,
                      const QLCFixtureDefCache* fixtureDefCache)
{
    QLCFixtureDef* fixtureDef = NULL;
    QLCFixtureMode* fixtureMode = NULL;
    QString manufacturer;
    QString model;
    QString modeName;
    QString name;
    quint32 id = Fixture::invalidId();
    quint32 universe = 0;
    quint32 address = 0;
    quint32 channels = 0;
    quint32 width = 0, height = 0;
    QList<int> excludeList;
    QList<int> forcedHTP;
    QList<int> forcedLTP;
    QList<quint32>modifierIndices;
    QList<ChannelModifier *>modifierPointers;

    if (xmlDoc.name() != KXMLFixture)
    {
        qWarning() << Q_FUNC_INFO << "Fixture node not found";
        return false;
    }

    while (xmlDoc.readNextStartElement())
    {
        if (xmlDoc.name() == KXMLQLCFixtureDefManufacturer)
        {
            manufacturer = xmlDoc.readElementText();
        }
        else if (xmlDoc.name() == KXMLQLCFixtureDefModel)
        {
            model = xmlDoc.readElementText();
        }
        else if (xmlDoc.name() == KXMLQLCFixtureMode)
        {
            modeName = xmlDoc.readElementText();
        }
        else if (xmlDoc.name() == KXMLQLCPhysicalDimensionsWeight)
        {
            width = xmlDoc.readElementText().toUInt();
        }
        else if (xmlDoc.name() == KXMLQLCPhysicalDimensionsHeight)
        {
            height = xmlDoc.readElementText().toUInt();
        }
        else if (xmlDoc.name() == KXMLFixtureID)
        {
            id = xmlDoc.readElementText().toUInt();
        }
        else if (xmlDoc.name() == KXMLFixtureName)
        {
            name = xmlDoc.readElementText();
        }
        else if (xmlDoc.name() == KXMLFixtureUniverse)
        {
            universe = xmlDoc.readElementText().toInt();
        }
        else if (xmlDoc.name() == KXMLFixtureAddress)
        {
            address = xmlDoc.readElementText().toInt();
        }
        else if (xmlDoc.name() == KXMLFixtureChannels)
        {
            channels = xmlDoc.readElementText().toInt();
        }
        else if (xmlDoc.name() == KXMLFixtureExcludeFade)
        {
            QString list = xmlDoc.readElementText();
            QStringList values = list.split(",");

            for (int i = 0; i < values.count(); i++)
                excludeList.append(values.at(i).toInt());
        }
        else if (xmlDoc.name() == KXMLFixtureForcedHTP)
        {
            QString list = xmlDoc.readElementText();
            QStringList values = list.split(",");

            for (int i = 0; i < values.count(); i++)
                forcedHTP.append(values.at(i).toInt());
        }
        else if (xmlDoc.name() == KXMLFixtureForcedLTP)
        {
            QString list = xmlDoc.readElementText();
            QStringList values = list.split(",");

            for (int i = 0; i < values.count(); i++)
                forcedLTP.append(values.at(i).toInt());
        }
        else if (xmlDoc.name() == KXMLFixtureChannelModifier)
        {
            QXmlStreamAttributes attrs = xmlDoc.attributes();
            if (attrs.hasAttribute(KXMLFixtureChannelIndex) &&
                attrs.hasAttribute(KXMLFixtureModifierName))
            {
                quint32 chIdx = attrs.value(KXMLFixtureChannelIndex).toString().toUInt();
                QString modName = attrs.value(KXMLFixtureModifierName).toString();
                ChannelModifier *chMod = doc->modifiersCache()->modifier(modName);
                if (chMod != NULL)
                {
                    modifierIndices.append(chIdx);
                    modifierPointers.append(chMod);
                }
                xmlDoc.skipCurrentElement();
            }
        }
        else
        {
            qWarning() << Q_FUNC_INFO << "Unknown fixture tag:" << xmlDoc.name();
            xmlDoc.skipCurrentElement();
        }
    }

    /* Find the given fixture definition, unless its a generic dimmer */
    if (model != KXMLFixtureGeneric && model != KXMLFixtureRGBPanel)
    {
        fixtureDef = fixtureDefCache->fixtureDef(manufacturer, model);
        if (fixtureDef == NULL)
        {
            doc->appendToErrorLog(QString("No fixture definition found for <b>%1</b> <b>%2</b>")
                                  .arg(manufacturer)
                                  .arg(model));
        }
        else
        {
            /* Find the given fixture mode */
            fixtureMode = fixtureDef->mode(modeName);
            if (fixtureMode == NULL)
            {
                doc->appendToErrorLog(QString("Fixture mode <b>%1</b> not found for <b>%2</b> <b>%3</b>")
                                      .arg(modeName).arg(manufacturer).arg(model));

                /* Set this also NULL so that a generic dimmer will be
                   created instead as a backup. */
                fixtureDef = NULL;
            }
        }
    }

    /* Number of channels */
    if (channels <= 0)
    {
        doc->appendToErrorLog(QString("%1 channels of fixture <b>%2</b> are our of bounds")
                              .arg(QString::number(channels))
                              .arg(name));
        channels = 1;
    }

    /* Make sure that address is something sensible */
    if (address > 511 || address + (channels - 1) > 511)
    {
        doc->appendToErrorLog(QString("Fixture address range %1-%2 is out of DMX bounds")
                              .arg(QString::number(address))
                              .arg(QString::number(address + channels - 1)));
        address = 0;
    }

    /* Check that the invalid ID is not used */
    if (id == Fixture::invalidId())
    {
        qWarning() << Q_FUNC_INFO << "Fixture ID" << id << "is not allowed.";
        return false;
    }

    if (model == KXMLFixtureGeneric)
    {
        fixtureDef = genericDimmerDef(channels);
        fixtureMode = genericDimmerMode(fixtureDef, channels);
    }
    else if (model == KXMLFixtureRGBPanel)
    {
        Components components = RGB;
        int compNum = 3;
        if (modeName == "BGR") components = BGR;
        else if (modeName == "BRG") components = BRG;
        else if (modeName == "GBR") components = GBR;
        else if (modeName == "GRB") components = GRB;
        else if (modeName == "RBG") components = RBG;
        else if (modeName == "RGBW")
        {
            components = RGBW;
            compNum = 4;
        }

        fixtureDef = genericRGBPanelDef(channels / compNum, components);
        fixtureMode = genericRGBPanelMode(fixtureDef, components, width, height);
    }

    if (fixtureDef != NULL && fixtureMode != NULL)
    {
        /* Assign fixtureDef & mode only if BOTH are not NULL */
        setFixtureDefinition(fixtureDef, fixtureMode);
    }
    else
    {
        /* Otherwise set just the channel count */
        setChannels(channels);
    }

    setAddress(address);
    setUniverse(universe);
    setName(name);
    setExcludeFadeChannels(excludeList);
    setForcedHTPChannels(forcedHTP);
    setForcedLTPChannels(forcedLTP);
    for (int i = 0; i < modifierIndices.count(); i++)
        setChannelModifier(modifierIndices.at(i), modifierPointers.at(i));
    setID(id);

    return true;
}
Example #2
0
bool Template::loadTypeSpecificTemplateConfiguration(QXmlStreamReader& xml)
{
	xml.skipCurrentElement();
	return true;
}
Example #3
0
bool Video::loadXML(QXmlStreamReader &root)
{
    if (root.name() != KXMLQLCFunction)
    {
        qWarning() << Q_FUNC_INFO << "Function node not found";
        return false;
    }

    if (root.attributes().value(KXMLQLCFunctionType).toString() != typeToString(Function::Video))
    {
        qWarning() << Q_FUNC_INFO << root.attributes().value(KXMLQLCFunctionType).toString()
                   << "is not Video";
        return false;
    }

    QString fname = name();

    while (root.readNextStartElement())
    {
        if (root.name() == KXMLQLCVideoSource)
        {
            QXmlStreamAttributes attrs = root.attributes();
            if (attrs.hasAttribute(KXMLQLCVideoStartTime))
                setStartTime(attrs.value(KXMLQLCVideoStartTime).toString().toUInt());
            if (attrs.hasAttribute(KXMLQLCVideoColor))
                setColor(QColor(attrs.value(KXMLQLCVideoColor).toString()));
            if (attrs.hasAttribute(KXMLQLCVideoLocked))
                setLocked(true);
            if (attrs.hasAttribute(KXMLQLCVideoScreen))
                setScreen(attrs.value(KXMLQLCVideoScreen).toString().toInt());
            if (attrs.hasAttribute(KXMLQLCVideoFullscreen))
            {
                if (attrs.value(KXMLQLCVideoFullscreen).toString() == "1")
                    setFullscreen(true);
                else
                    setFullscreen(false);
            }
            QString path = root.readElementText();
            if (path.contains("://") == true)
                setSourceUrl(path);
            else
                setSourceUrl(m_doc->denormalizeComponentPath(path));
        }
        else if (root.name() == KXMLQLCFunctionSpeed)
        {
            loadXMLSpeed(root);
        }
        else if (root.name() == KXMLQLCFunctionRunOrder)
        {
            loadXMLRunOrder(root);
        }
        else
        {
            qWarning() << Q_FUNC_INFO << "Unknown Video tag:" << root.name();
            root.skipCurrentElement();
        }
    }

    setName(fname);

    return true;
}
Example #4
0
bool EFX::loadXML(QXmlStreamReader &root)
{
    if (root.name() != KXMLQLCFunction)
    {
        qWarning() << "Function node not found!";
        return false;
    }

    if (root.attributes().value(KXMLQLCFunctionType).toString() != typeToString(Function::EFX))
    {
        qWarning("Function is not an EFX!");
        return false;
    }

    /* Load EFX contents */
    while (root.readNextStartElement())
    {
        if (root.name() == KXMLQLCBus)
        {
            /* Bus */
            QString str = root.attributes().value(KXMLQLCBusRole).toString();
            if (str == KXMLQLCBusFade)
                m_legacyFadeBus = root.readElementText().toUInt();
            else if (str == KXMLQLCBusHold)
                m_legacyHoldBus = root.readElementText().toUInt();
        }
        else if (root.name() == KXMLQLCFunctionSpeed)
        {
            loadXMLSpeed(root);
        }
        else if (root.name() == KXMLQLCEFXFixture)
        {
            EFXFixture* ef = new EFXFixture(this);
            ef->loadXML(root);
            if (ef->head().isValid())
            {
                if (addFixture(ef) == false)
                    delete ef;
            }
        }
        else if (root.name() == KXMLQLCEFXPropagationMode)
        {
            /* Propagation mode */
            setPropagationMode(stringToPropagationMode(root.readElementText()));
        }
        else if (root.name() == KXMLQLCEFXAlgorithm)
        {
            /* Algorithm */
            setAlgorithm(stringToAlgorithm(root.readElementText()));
        }
        else if (root.name() == KXMLQLCFunctionDirection)
        {
            loadXMLDirection(root);
        }
        else if (root.name() == KXMLQLCFunctionRunOrder)
        {
            loadXMLRunOrder(root);
        }
        else if (root.name() == KXMLQLCEFXWidth)
        {
            /* Width */
            setWidth(root.readElementText().toInt());
        }
        else if (root.name() == KXMLQLCEFXHeight)
        {
            /* Height */
            setHeight(root.readElementText().toInt());
        }
        else if (root.name() == KXMLQLCEFXRotation)
        {
            /* Rotation */
            setRotation(root.readElementText().toInt());
        }
        else if (root.name() == KXMLQLCEFXStartOffset)
        {
            /* StartOffset */
            setStartOffset(root.readElementText().toInt());
        }
        else if (root.name() == KXMLQLCEFXIsRelative)
        {
            /* IsRelative */
            setIsRelative(root.readElementText().toInt() != 0);
        }
        else if (root.name() == KXMLQLCEFXAxis)
        {
            /* Axes */
            loadXMLAxis(root);
        }
        else
        {
            qWarning() << "Unknown EFX tag:" << root.name();
            root.skipCurrentElement();
        }
    }

    return true;
}
Example #5
0
void jcz::XmlParser::readPoint(QXmlStreamReader & xml, QList<XMLTile> & tiles)
{
	bool ok1, ok2;
	QString featureName = xml.attributes().value("feature").toString().toLower();
	int cx = xml.attributes().value("cx").toInt(&ok1);
	int cy = xml.attributes().value("cy").toInt(&ok2);
	Location baseLocation = Location::valueOf(xml.attributes().value("baseLocation").toString());

	if (featureName.isEmpty() || !ok1 || !ok2)
	{
		qWarning() << "bad point definition";
		Q_ASSERT(false);
		return;
	}

//	qDebug() << featureName << cx << cy << xml.attributes().value("baseLocation");

	while (xml.readNextStartElement())
	{
		int transform = -1;
		if (xml.name() != "apply")
		{
			if (xml.name() == "g")
			{
				auto const & value = xml.attributes().value("svg:transform");
				if (value == "rotate(90 500 500)") // Well, this is actually hardcoded this way in jcz
					transform = 90;
				else if (value == "rotate(180 500 500)")
					transform = 180;
				else if (value == "rotate(270 500 500)")
					transform = 270;
			}
			if (transform < 0)
			{
				qWarning() << "bad point apply definition 1";
				Q_ASSERT(false);
//				return;
				xml.skipCurrentElement();
				continue;
			}
			else
			{
				xml.readNextStartElement();
				if (xml.name() != "apply")
				{
					qWarning() << "bad point apply definition 2";
					Q_ASSERT(false);
	//				return;
					xml.skipCurrentElement();
					continue;
				}
			}
		}

		bool allRotations = (xml.attributes().value("allRotations") == "1");

		xml.readNext();
//		qDebug() << "apply" << xml.text();

		QStringList const & split = xml.text().toString().split(' ', QString::SkipEmptyParts);
		if (split.length() != 2)
		{
			qWarning() << "bad point apply location definition";
			Q_ASSERT(false);
			return;
		}

		QString const & fullTileName = split.at(0);
		QString const & locationName = split.at(1);

		QList<Location> locations;
		{
			Location location = Location::valueOf(locationName);
			locations.append(location);
			if (allRotations)
				for (uchar i = 1; i < 4; ++i)
					locations.append(location.rotateCCW(i));
		}

		bool allTiles = true;
		QString expansionName;
		QString tileName;
		if (fullTileName != "*")
		{
			allTiles = false;

			if (fullTileName.indexOf('.') != 2)
			{
				qWarning() << "bad point apply location definition";
				Q_ASSERT(false);
				return;
			}
			expansionName = fullTileName.left(2);
			tileName = fullTileName.mid(3);
		}


		QPoint point(cx, cy);
		Q_ASSERT(!point.isNull());
		for (int i = 0; i < locations.length(); ++i)
		{
			Location const & l = locations.at(i);
			QTransform t;
			t.translate(500, 500);
			t.rotate(-i * 90);
			if (transform > 0)
				t.rotate(-transform); // Untested, since it does not apply to the base game.

			signed char r = l.getRotationOf(baseLocation);
			if (r > 0)
				t.rotate(r * 90);

			t.translate(-500, -500);
			QPoint rotatedPoint = t.map(point);

			for (XMLTile & tile : tiles)
			{
				if (!allTiles)
				{
					if (tile.id != tileName)
						continue;
					if (Expansions::getCode(tile.expansion) != expansionName)
						continue;
				}

				if (!tile.locations.contains(l))
					continue;
				XMLFeature & feature = tile.features[tile.locations[l]];
				if (feature.name != featureName)
					continue;

				feature.point = rotatedPoint;
				if (transform > 0)
					qDebug() << tile.id << feature.name << feature.point;
			}
		}

		xml.skipCurrentElement();
		if (transform > 0)
			xml.skipCurrentElement();
	}
//	qDebug();
}
HangingProtocol* HangingProtocolXMLReader::readFile(const QString &path)
{
    QFile file(path);
    HangingProtocol *hangingProtocolLoaded = NULL;

    if (!file.open(QFile::ReadOnly | QFile::Text))
    {
        QMessageBox::warning(0, tr("Hanging Protocol XML File"),
                             tr("Unable to read file %1:\n%2.")
                             .arg(path)
                             .arg(file.errorString()));
        return NULL;
    }

    QXmlStreamReader *reader = new QXmlStreamReader(&file);

    if (reader->readNextStartElement())
    {
        if (reader->name() == "hangingProtocol")
        {
            HangingProtocol *hangingProtocol = new HangingProtocol();
            QStringList protocols;
            QList<HangingProtocolImageSet::Restriction> restrictionList;

            while (reader->readNextStartElement())
            {
                if (reader->name() == "hangingProtocolName")
                {
                    hangingProtocol->setName(reader->readElementText());
                }
                else if (reader->name() == "numberScreens")
                {
                    hangingProtocol->setNumberOfScreens(reader->readElementText().toInt());
                }
                else if (reader->name() == "protocol")
                {
                    protocols << reader->readElementText();
                }
                else if (reader->name() == "institutions")
                {
                    hangingProtocol->setInstitutionsRegularExpression(QRegExp(reader->readElementText(), Qt::CaseInsensitive));
                }
                else if (reader->name() == "restriction")
                {
                    restrictionList << readRestriction(reader);
                }
                else if (reader->name() == "imageSet")
                {
                    HangingProtocolImageSet *imageSet = readImageSet(reader, restrictionList);
                    hangingProtocol->addImageSet(imageSet);
                }
                else if (reader->name() == "displaySet")
                {
                    HangingProtocolDisplaySet *displaySet = readDisplaySet(reader, hangingProtocol);
                    hangingProtocol->addDisplaySet(displaySet);
                }
                else if (reader->name() == "strictness")
                {
                    hangingProtocol->setStrictness(reader->readElementText().contains("yes"));
                }
                else if (reader->name() == "allDifferent")
                {
                    hangingProtocol->setAllDiferent(reader->readElementText().contains("yes"));
                }
                else if (reader->name() == "iconType")
                {
                    hangingProtocol->setIconType(reader->readElementText());
                }
                else if (reader->name() == "hasPrevious")
                {
                    hangingProtocol->setPrevious(reader->readElementText().contains("yes"));
                }
                else if (reader->name() == "priority")
                {
                    hangingProtocol->setPriority(reader->readElementText().toDouble());
                }
                else
                {
                    reader->skipCurrentElement();
                }
            }

            if (!reader->hasError())
            {
                hangingProtocol->setProtocolsList(protocols);
                hangingProtocolLoaded = hangingProtocol;
            }
            else
            {
                delete hangingProtocol;
            }
        }
    }

    if (reader->hasError())
    {
        DEBUG_LOG(QString("[Line: %1, Column:%2] Error in hanging protocol file %3: %4, error: %5").arg(reader->lineNumber()).arg(reader->columnNumber()).arg(
                  path).arg(reader->errorString()).arg(reader->error()));
        ERROR_LOG(QString("[Line: %1, Column:%2] Error in hanging protocol file %3: %4, error: %5").arg(reader->lineNumber()).arg(reader->columnNumber()).arg(
                  path).arg(reader->errorString()).arg(reader->error()));
    }

    delete reader;

    return hangingProtocolLoaded;
}
Example #7
0
void AdvancedSettings::loadSettings()
{
    qDebug() << "Loading advanced settings";
    reset();

    QXmlStreamReader xml;
    QFile file(Settings::applicationDir() + "/advancedsettings.xml");
    if (!file.exists())
        file.setFileName(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/advancedsettings.xml");

    if (!file.exists())
        return;

    if (!file.open(QIODevice::ReadOnly))
        return;
    xml.addData(file.readAll());
    file.close();

    if (!xml.readNextStartElement() || xml.name().toString() != "advancedsettings")
        return;

    while (xml.readNextStartElement()) {
        if (xml.name() == "log")
            loadLog(xml);
        else if (xml.name() == "gui")
            loadGui(xml);
        else if (xml.name() == "sorttokens")
            loadSortTokens(xml);
        else if (xml.name() == "genres")
            loadGenreMappings(xml);
        else if (xml.name() == "fileFilters")
            loadFilters(xml);
        else if (xml.name() == "audioCodecs")
            loadAudioCodecMappings(xml);
        else if (xml.name() == "videoCodecs")
            loadVideoCodecMappings(xml);
        else if (xml.name() == "certifications")
            loadCertificationMappings(xml);
        else if (xml.name() == "studios")
            loadStudioMappings(xml);
        else if (xml.name() == "countries")
            loadCountryMappings(xml);
        else if (xml.name() == "portableMode")
            m_portableMode = (xml.readElementText() == "true");
        else
            xml.skipCurrentElement();
    }

    qDebug() << "Advanced settings";
    qDebug() << "    debugLog              " << m_debugLog;
    qDebug() << "    logFile               " << m_logFile;
    qDebug() << "    forceCache            " << m_forceCache;
    qDebug() << "    sortTokens            " << m_sortTokens;
    qDebug() << "    genreMappings         " << m_genreMappings;
    qDebug() << "    movieFilters          " << m_movieFilters;
    qDebug() << "    concertFilters        " << m_concertFilters;
    qDebug() << "    tvShowFilters         " << m_tvShowFilters;
    qDebug() << "    subtitleFilters       " << m_subtitleFilters;
    qDebug() << "    audioCodecMappings    " << m_audioCodecMappings;
    qDebug() << "    videoCodecMappings    " << m_videoCodecMappings;
    qDebug() << "    certificationMappings " << m_certificationMappings;
    qDebug() << "    studioMappings        " << m_studioMappings;
    qDebug() << "    useFirstStudioOnly    " << m_useFirstStudioOnly;
    qDebug() << "    countryMappings       " << m_countryMappings;
}
Example #8
0
void MapView::load(QXmlStreamReader& xml)
{
	XmlElementReader mapview_element(xml);
	zoom = mapview_element.attribute<double>(literal::zoom);
	if (zoom < 0.001)
		zoom = 1.0;
	rotation = mapview_element.attribute<double>(literal::rotation);
	
	auto center_x = mapview_element.attribute<qint64>(literal::position_x);
	auto center_y = mapview_element.attribute<qint64>(literal::position_y);
	try
	{
		center_pos = MapCoord::fromNative64withOffset(center_x, center_y);
	}
	catch (std::range_error)
	{
		// leave center_pos unchanged
	}
	
	grid_visible = mapview_element.attribute<bool>(literal::grid);
	overprinting_simulation_enabled = mapview_element.attribute<bool>(literal::overprinting_simulation_enabled);
	updateTransform(CenterChange | ZoomChange | RotationChange);
	
	while (xml.readNextStartElement())
	{
		if (xml.name() == literal::map)
		{
			XmlElementReader map_element(xml);
			map_visibility->opacity = map_element.attribute<float>(literal::opacity);
			if (map_element.hasAttribute(literal::visible))
				map_visibility->visible = map_element.attribute<bool>(literal::visible);
			else
				map_visibility->visible = true;
		}
		else if (xml.name() == literal::templates)
		{
			XmlElementReader templates_element(xml);
			int num_template_visibilities = templates_element.attribute<int>(XmlStreamLiteral::count);
			if (num_template_visibilities > 0)
				template_visibilities.reserve(qMin(num_template_visibilities, 20)); // 20 is not a limit
			all_templates_hidden = templates_element.attribute<bool>(literal::hidden);
			
			while (xml.readNextStartElement())
			{
				if (xml.name() == literal::ref)
				{
					XmlElementReader ref_element(xml);
					int pos = ref_element.attribute<int>(literal::template_string);
					if (pos >= 0 && pos < map->getNumTemplates())
					{
						TemplateVisibility* vis = getTemplateVisibility(map->getTemplate(pos));
						vis->visible = ref_element.attribute<bool>(literal::visible);
						vis->opacity = ref_element.attribute<float>(literal::opacity);
					}
				}
				else
					xml.skipCurrentElement();
			}
		}
		else
			xml.skipCurrentElement(); // unsupported
	}
}
bool EwsFindFolderResponse::parseRootFolder(QXmlStreamReader &reader)
{
    if (reader.namespaceUri() != ewsMsgNsUri || reader.name() != QStringLiteral("RootFolder")) {
        return setErrorMsg(QStringLiteral("Failed to read EWS request - expected %1 element (got %2).")
                        .arg(QStringLiteral("RootFolder")).arg(reader.qualifiedName().toString()));
    }

    if (!reader.attributes().hasAttribute(QStringLiteral("TotalItemsInView"))
        || !reader.attributes().hasAttribute(QStringLiteral("TotalItemsInView"))) {
        return setErrorMsg(QStringLiteral("Failed to read EWS request - missing attributes of %1 element.")
                                .arg(QStringLiteral("RootFolder")));
    }
    bool ok;
    unsigned totalItems = reader.attributes().value(QStringLiteral("TotalItemsInView")).toUInt(&ok);
    if (!ok) {
        return setErrorMsg(QStringLiteral("Failed to read EWS request - failed to read %1 attribute.")
                                        .arg(QStringLiteral("TotalItemsInView")));
    }

    if (!reader.readNextStartElement()) {
        return setErrorMsg(QStringLiteral("Failed to read EWS request - expected a child element in %1 element.")
                        .arg(QStringLiteral("RootFolder")));
    }

    if (reader.namespaceUri() != ewsTypeNsUri || reader.name() != QStringLiteral("Folders")) {
        return setErrorMsg(QStringLiteral("Failed to read EWS request - expected %1 element (got %2).")
                        .arg(QStringLiteral("Folders")).arg(reader.qualifiedName().toString()));
    }

    if (!reader.readNextStartElement()) {
        return setErrorMsg(QStringLiteral("Failed to read EWS request - expected a child element in %1 element.")
                        .arg(QStringLiteral("Folders")));
    }

    if (reader.namespaceUri() != ewsTypeNsUri) {
        return setErrorMsg(QStringLiteral("Failed to read EWS request - expected child element from types namespace."));
    }

    unsigned i = 0;
    for (i = 0; i < totalItems; i++) {
        EwsFolder *folder = readFolder(reader);
        reader.readNextStartElement();
        if (folder) {
            bool ok;
            int childCount = (*folder)[EwsFolderFieldChildFolderCount].toUInt(&ok);
            if (childCount > 0) {
                unsigned readCount = readChildFolders(*folder, childCount, reader);
                if (readCount == 0)
                    return false;
                i += readCount;
            }
            mFolders.append(*folder);
        }
    }

    // Finish the Folders element
    reader.skipCurrentElement();

    // Finish the RootFolder element
    reader.skipCurrentElement();

    return true;
}
Example #10
0
bool Chaser::loadXML(QXmlStreamReader &root)
{
    if (root.name() != KXMLQLCFunction)
    {
        qWarning() << Q_FUNC_INFO << "Function node not found";
        return false;
    }

    if (root.attributes().value(KXMLQLCFunctionType).toString() != typeToString(Function::Chaser))
    {
        qWarning() << Q_FUNC_INFO << root.attributes().value(KXMLQLCFunctionType).toString()
                   << "is not a chaser";
        return false;
    }

    /* Load chaser contents */
    while (root.readNextStartElement())
    {
        if (root.name() == KXMLQLCBus)
        {
            m_legacyHoldBus = root.readElementText().toUInt();
        }
        else if (root.name() == KXMLQLCFunctionSpeed)
        {
            loadXMLSpeed(root);
        }
        else if (root.name() == KXMLQLCFunctionDirection)
        {
            loadXMLDirection(root);
        }
        else if (root.name() == KXMLQLCFunctionRunOrder)
        {
            loadXMLRunOrder(root);
        }
        else if (root.name() == KXMLQLCChaserSpeedModes)
        {
            QXmlStreamAttributes attrs = root.attributes();
            QString str;

            str = attrs.value(KXMLQLCFunctionSpeedFadeIn).toString();
            setFadeInMode(stringToSpeedMode(str));

            str = attrs.value(KXMLQLCFunctionSpeedFadeOut).toString();
            setFadeOutMode(stringToSpeedMode(str));

            str = attrs.value(KXMLQLCFunctionSpeedDuration).toString();
            setDurationMode(stringToSpeedMode(str));
            root.skipCurrentElement();
        }
        else if (root.name() == KXMLQLCChaserSequenceTag)
        {
            QXmlStreamAttributes attrs = root.attributes();
            QString str = attrs.value(KXMLQLCChaserSequenceBoundScene).toString();
            enableSequenceMode(str.toUInt());
            if (attrs.hasAttribute(KXMLQLCChaserSequenceStartTime))
                setStartTime(attrs.value(KXMLQLCChaserSequenceStartTime).toString().toUInt());
            if (attrs.hasAttribute(KXMLQLCChaserSequenceColor))
                setColor(QColor(attrs.value(KXMLQLCChaserSequenceColor).toString()));
            if (attrs.hasAttribute(KXMLQLCChaserSequenceLocked))
                setLocked(true);
            root.skipCurrentElement();
        }
        else if (root.name() == KXMLQLCFunctionStep)
        {
            //! @todo stepNumber is useless if the steps are in the wrong order
            ChaserStep step;
            int stepNumber = -1;

            if (step.loadXML(root, stepNumber) == true)
            {
                if (isSequence() == true)
                    step.fid = getBoundSceneID();
                if (stepNumber >= m_steps.size())
                    m_steps.append(step);
                else
                    m_steps.insert(stepNumber, step);
            }
        }
        else
        {
            qWarning() << Q_FUNC_INFO << "Unknown chaser tag:" << root.name();
            root.skipCurrentElement();
        }
    }

    return true;
}
Example #11
0
bool Chaser::loadXML(QXmlStreamReader &root)
{
    if (root.name() != KXMLQLCFunction)
    {
        qWarning() << Q_FUNC_INFO << "Function node not found";
        return false;
    }

    if (root.attributes().value(KXMLQLCFunctionType).toString() != typeToString(Function::ChaserType))
    {
        qWarning() << Q_FUNC_INFO << root.attributes().value(KXMLQLCFunctionType).toString()
                   << "is not a Chaser";
        return false;
    }

    /* Load chaser contents */
    while (root.readNextStartElement())
    {
        if (root.name() == KXMLQLCBus)
        {
            m_legacyHoldBus = root.readElementText().toUInt();
        }
        else if (root.name() == KXMLQLCFunctionSpeed)
        {
            loadXMLSpeed(root);
        }
        else if (root.name() == KXMLQLCFunctionDirection)
        {
            loadXMLDirection(root);
        }
        else if (root.name() == KXMLQLCFunctionRunOrder)
        {
            loadXMLRunOrder(root);
        }
        else if (root.name() == KXMLQLCChaserSpeedModes)
        {
            loadXMLSpeedModes(root);
        }
        else if (root.name() == KXMLQLCFunctionStep)
        {
            //! @todo stepNumber is useless if the steps are in the wrong order
            ChaserStep step;
            int stepNumber = -1;

            if (step.loadXML(root, stepNumber, doc()) == true)
            {
                if (stepNumber >= m_steps.size())
                    m_steps.append(step);
                else
                    m_steps.insert(stepNumber, step);
            }
        }
        else if (root.name() == "Sequence")
        {
            doc()->appendToErrorLog(QString("<b>Unsupported sequences found</b>. Please convert your project "
                                            "at <a href=http://www.qlcplus.org/sequence_migration.php>http://www.qlcplus.org/sequence_migration.php</a>"));
            root.skipCurrentElement();
        }
        else
        {
            qWarning() << Q_FUNC_INFO << "Unknown chaser tag:" << root.name();
            root.skipCurrentElement();
        }
    }

    return true;
}
Example #12
0
//--------------------------------------------------------------------------------------------------
/// Reads all the fields into this PdmObject
/// Assumes xmlStream points to the start element token of the PdmObject for which to read fields.
/// ( and not first token of object content)
/// This makes attribute based field storage possible.
/// Leaves the xmlStream pointing to the EndElement of the PdmObject.
//--------------------------------------------------------------------------------------------------
void PdmObject::readFields (QXmlStreamReader& xmlStream )
{
   bool isObjectFinished = false;
   QXmlStreamReader::TokenType type;
   while(!isObjectFinished)
   {
       type = xmlStream.readNext();

       switch (type)
       {
       case QXmlStreamReader::StartElement:
           {
               QString name = xmlStream.name().toString();
               if (name == QString("SimpleObjPtrField"))
               {
                   int a;
                   a = 2 + 7;
               }
               PdmFieldHandle* currentField = findField(name);
               if (currentField)
               {
                   if (currentField->isIOReadable())
                   {
                       // readFieldData assumes that the xmlStream points to first token of field content.
                       // After reading, the xmlStream is supposed to point to the first token after the field content.
                       // (typically an "endElement")
                       QXmlStreamReader::TokenType tt;
                       tt = xmlStream.readNext();
                       currentField->readFieldData( xmlStream );
                   }
                   else
                   {
                       xmlStream.skipCurrentElement();
                   }
               }
               else
               {
                   std::cout << "Line "<< xmlStream.lineNumber() << ": Warning: Could not find a field with name " << name.toLatin1().data() << " in the current object : " << classKeyword().toLatin1().data() << std::endl;
                   xmlStream.skipCurrentElement();
               }
               break;
           }
           break;
       case QXmlStreamReader::EndElement:
           {
               // End of object.
               QString name = xmlStream.name().toString(); // For debugging
               isObjectFinished = true;
           }
           break;
       case QXmlStreamReader::EndDocument:
           {
               // End of object.
               isObjectFinished = true;
           }
           break;
       default:
           {
               // Just read on
               // Todo: Error handling   
           }
           break;
       }
   }

}
Example #13
0
bool TextSymbol::loadImpl(QXmlStreamReader& xml, const Map& map, SymbolDictionary& symbol_dict)
{
	Q_UNUSED(symbol_dict);
	
	if (xml.name() != "text_symbol")
		return false;
	
	icon_text = xml.attributes().value("icon_text").toString();
	framing = false;
	line_below = false;
	custom_tabs.clear();
	
	while (xml.readNextStartElement())
	{
		QXmlStreamAttributes attributes(xml.attributes());
		if (xml.name() == "font")
		{
			font_family = xml.attributes().value("family").toString();
			font_size = attributes.value("size").toString().toInt();
			bold = (attributes.value("bold") == "true");
			italic = (attributes.value("italic") == "true");
			underline = (attributes.value("underline") == "true");
			xml.skipCurrentElement();
		}
		else if (xml.name() == "text")
		{
			int temp = attributes.value("color").toString().toInt();
			color = map.getColor(temp);
			line_spacing = attributes.value("line_spacing").toString().toFloat();
			paragraph_spacing = attributes.value("paragraph_spacing").toString().toInt();
			character_spacing = attributes.value("character_spacing").toString().toFloat();
			kerning = (attributes.value("kerning") == "true");
			xml.skipCurrentElement();
		}
		else if (xml.name() == "framing")
		{
			framing = true;
			int temp = attributes.value("color").toString().toInt();
			framing_color = map.getColor(temp);
			framing_mode = attributes.value("mode").toString().toInt();
			framing_line_half_width = attributes.value("line_half_width").toString().toInt();
			framing_shadow_x_offset = attributes.value("shadow_x_offset").toString().toInt();
			framing_shadow_y_offset = attributes.value("shadow_y_offset").toString().toInt();
			xml.skipCurrentElement();
		}
		else if (xml.name() == "line_below")
		{
			line_below = true;
			int temp = attributes.value("color").toString().toInt();
			line_below_color = map.getColor(temp);
			line_below_width = attributes.value("width").toString().toInt();
			line_below_distance = attributes.value("distance").toString().toInt();
			xml.skipCurrentElement();
		}
		else if (xml.name() == "tabs")
		{
			int num_custom_tabs = attributes.value("count").toString().toInt();
			custom_tabs.reserve(num_custom_tabs % 20); // 20 is not the limit
			while (xml.readNextStartElement())
			{
				if (xml.name() == "tab")
					custom_tabs.push_back(xml.readElementText().toInt());
				else
					xml.skipCurrentElement();
			}
		}
		else
			xml.skipCurrentElement(); // unknown
	}
	
	updateQFont();
	return true;
}
Example #14
0
void FileReader::parseFile(QString &filename, FileRecord &record)
{
    QFileInfo f(filename);
    QFile file(filename);
    QByteArray data;
    QXmlStreamReader reader;

    if (f.suffix() == "fb2")
    {
        if (!file.open(QFile::ReadOnly | QFile::Text))
        {
            return;
        }

        reader.setDevice(&file);
    }
    else
        if (f.suffix() == "zip")
        {
            int res = unzipFile(filename, data);

            if (0 != res)
            {
                return;
            }

            reader.addData(data);
        }

    reader.readNext();

    if (reader.isStartDocument())
    {
        record.setEncoding(reader.documentEncoding().toString());
    }

    if (reader.readNextStartElement())
    {
        if (reader.name() == "FictionBook")
        {
            if (reader.readNextStartElement())
            {
                if (reader.name() == "description")
                {
                    if (reader.readNextStartElement())
                    {
                        if (reader.name() == "title-info")
                        {
                            while (reader.readNextStartElement())
                            {
                                if (reader.name() == "genre")
                                {
                                    QString genre = reader.readElementText();

                                    if (reader.attributes().hasAttribute("match"))
                                    {
                                        int match = reader.attributes().value("match").toInt();
                                        record.addGenre(genre, match);
                                    }
                                    else
                                        record.addGenre(genre);
                                }
                                else
                                    if (reader.name() == "author")
                                    {
                                        Person *tmpAuthor = new Person();

                                        while (reader.readNextStartElement())
                                        {
                                            if (reader.name() == "first-name")
                                            {
                                                tmpAuthor->setFirstName(reader.readElementText());
                                            }

                                            if (reader.name() == "middle-name")
                                            {
                                                tmpAuthor->setMiddleName(reader.readElementText());
                                            }

                                            if (reader.name() == "last-name")
                                            {
                                                tmpAuthor->setLastName(reader.readElementText());
                                            }

                                            if (reader.name() == "nickname")
                                            {
                                                tmpAuthor->setNickname(reader.readElementText());
                                            }

                                            if (reader.name() == "home-page")
                                            {
                                                tmpAuthor->addHomePage(reader.readElementText());
                                            }

                                            if (reader.name() == "email")
                                            {
                                                tmpAuthor->addEmail(reader.readElementText());
                                            }

                                            if (reader.name() == "id")
                                            {
                                                tmpAuthor->setId(reader.readElementText());
                                            }
                                        }

                                        record.addAuthor(*tmpAuthor);
                                        delete tmpAuthor;
                                    }
                                    else
                                        if (reader.name() == "book-title")
                                        {
                                            record.setBookTitle(reader.readElementText());
                                        }
                                        else
                                            if (reader.name() == "sequence")
                                            {
                                                if (reader.attributes().hasAttribute("name"))
                                                {
                                                    QString sequence = reader.attributes().value("name").toString();

                                                    if (reader.attributes().hasAttribute("number"))
                                                    {
                                                        int number = reader.attributes().value("number").toInt();
                                                        record.addSequence(sequence, number);
                                                    }
                                                    else
                                                        record.addSequence(sequence);
                                                }
                                            }
                                            else reader.skipCurrentElement();
                            }
                        }
                    }
                }
            }
        }
    }

    file.close();
}
Example #15
0
bool RGBMatrix::loadXML(QXmlStreamReader &root)
{
    if (root.name() != KXMLQLCFunction)
    {
        qWarning() << Q_FUNC_INFO << "Function node not found";
        return false;
    }

    if (root.attributes().value(KXMLQLCFunctionType).toString() != typeToString(Function::RGBMatrixType))
    {
        qWarning() << Q_FUNC_INFO << "Function is not an RGB matrix";
        return false;
    }

    /* Load matrix contents */
    while (root.readNextStartElement())
    {
        if (root.name() == KXMLQLCFunctionSpeed)
        {
            loadXMLSpeed(root);
        }
        else if (root.name() == KXMLQLCRGBAlgorithm)
        {
            setAlgorithm(RGBAlgorithm::loader(doc(), root));
        }
        else if (root.name() == KXMLQLCRGBMatrixFixtureGroup)
        {
            setFixtureGroup(root.readElementText().toUInt());
        }
        else if (root.name() == KXMLQLCFunctionDirection)
        {
            loadXMLDirection(root);
        }
        else if (root.name() == KXMLQLCFunctionRunOrder)
        {
            loadXMLRunOrder(root);
        }
        else if (root.name() == KXMLQLCRGBMatrixStartColor)
        {
            setStartColor(QColor::fromRgb(QRgb(root.readElementText().toUInt())));
        }
        else if (root.name() == KXMLQLCRGBMatrixEndColor)
        {
            setEndColor(QColor::fromRgb(QRgb(root.readElementText().toUInt())));
        }
        else if (root.name() == KXMLQLCRGBMatrixProperty)
        {
            QString name = root.attributes().value(KXMLQLCRGBMatrixPropertyName).toString();
            QString value = root.attributes().value(KXMLQLCRGBMatrixPropertyValue).toString();
            setProperty(name, value);
            root.skipCurrentElement();
        }
        else if (root.name() == KXMLQLCRGBMatrixDimmerControl)
        {
            setDimmerControl(root.readElementText().toInt());
        }
        else
        {
            qWarning() << Q_FUNC_INFO << "Unknown RGB matrix tag:" << root.name();
            root.skipCurrentElement();
        }
    }

    return true;
}
Example #16
0
void QgsOSMXmlImport::readWay( QXmlStreamReader& xml )
{
  /*
   <way id="141756602" user="******" uid="527259" visible="true" version="1" changeset="10145142" timestamp="2011-12-18T10:43:14Z">
    <nd ref="318529958"/>
    <nd ref="1551725779"/>
    <nd ref="1551725792"/>
    <nd ref="809695938"/>
    <nd ref="1551725689"/>
    <nd ref="809695935"/>
    <tag k="highway" v="service"/>
    <tag k="oneway" v="yes"/>
   </way>
  */
  QXmlStreamAttributes attrs = xml.attributes();
  QgsOSMId id = attrs.value( "id" ).toString().toLongLong();

  // insert to DB
  sqlite3_bind_int64( mStmtInsertWay, 1, id );

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

  sqlite3_reset( mStmtInsertWay );

  int way_pos = 0;

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

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

    if ( xml.isStartElement() )
    {
      if ( xml.name() == "nd" )
      {
        QgsOSMId node_id = xml.attributes().value( "ref" ).toString().toLongLong();

        sqlite3_bind_int64( mStmtInsertWayNode, 1, id );
        sqlite3_bind_int64( mStmtInsertWayNode, 2, node_id );
        sqlite3_bind_int( mStmtInsertWayNode, 3, way_pos );

        if ( sqlite3_step( mStmtInsertWayNode ) != SQLITE_DONE )
        {
          xml.raiseError( QString( "Storing ways_nodes %1 - %2 failed." ).arg( id ).arg( node_id ) );
        }

        sqlite3_reset( mStmtInsertWayNode );

        way_pos++;

        xml.skipCurrentElement();
      }
      else if ( xml.name() == "tag" )
        readTag( true, id, xml );
      else
        xml.skipCurrentElement();
    }
  }
}
Example #17
0
void FuzzyDetector::LoadFromXml(QString settingsFileName)
{

    QFile data_input(settingsFileName);
    if(! data_input.open(QFile::ReadOnly | QFile::Text))
    {
        qDebug() << "Could not load settings, creating new one!";
        SaveToXml(settingsFileName);
        return;
    }

    QXmlStreamReader xml;
    xml.setDevice(&data_input);

    fp_onAir.clear();
    fp_onGrnd.clear();

    pa_onAir.clear();
    pa_onGrnd.clear();

    ia_onAir.clear();
    ia_onGrnd.clear();

    if(xml.readNextStartElement())
    {
        if(xml.name() != "FuzzyDetectorSettings") {
            qDebug() << "not a fuzzy detector log file";
            return;
        }
    }

    do
    {
        while( xml.readNextStartElement()) {
            if(xml.name() == "FP_OnAir") {
                do {
                while(xml.readNextStartElement()) {
                    if(xml.name() == "relation") {
                        fp_onAir.push_back(Relation(
                                xml.attributes().value("inVal").toString().toDouble(),
                                xml.attributes().value("outVal").toString().toDouble()
                                ));
                    } else {
                        xml.skipCurrentElement();
                    }
                } } while(xml.name() != "FP_OnAir");
            } else if(xml.name() == "FP_OnGrnd") {
                do {
                while(xml.readNextStartElement()) {
                    if(xml.name() == "relation") {
                        fp_onGrnd.push_back(Relation(
                                xml.attributes().value("inVal").toString().toDouble(),
                                xml.attributes().value("outVal").toString().toDouble()
                                ));
                    } else {
                        xml.skipCurrentElement();
                    }
                } } while(xml.name() != "FP_OnGrnd");
            } else if(xml.name() == "PA_OnAir") {
                do {
                while(xml.readNextStartElement()) {
                    if(xml.name() == "relation") {
                        pa_onAir.push_back(Relation(
                                xml.attributes().value("inVal").toString().toDouble(),
                                xml.attributes().value("outVal").toString().toDouble()
                                ));
                    } else {
                        xml.skipCurrentElement();
                    }
                } } while(xml.name() != "PA_OnAir");
            } else if(xml.name() == "PA_OnGrnd") {
                do {
                while(xml.readNextStartElement()) {
                    if(xml.name() == "relation") {
                        pa_onGrnd.push_back(Relation(
                                xml.attributes().value("inVal").toString().toDouble(),
                                xml.attributes().value("outVal").toString().toDouble()
                                ));
                    } else {
                        xml.skipCurrentElement();
                    }
                } } while(xml.name() != "PA_OnGrnd");
            } else if(xml.name() == "IA_OnAir") {
                do {
                while(xml.readNextStartElement()) {
                    if(xml.name() == "relation") {
                        ia_onAir.push_back(Relation(
                                xml.attributes().value("inVal").toString().toDouble(),
                                xml.attributes().value("outVal").toString().toDouble()
                                ));
                    } else {
                        xml.skipCurrentElement();
                    }
                } } while(xml.name() != "IA_OnAir");
            } else if(xml.name() == "IA_OnGrnd") {
                do {
                while(xml.readNextStartElement()) {
                    if(xml.name() == "relation") {
                        ia_onGrnd.push_back(Relation(
                                xml.attributes().value("inVal").toString().toDouble(),
                                xml.attributes().value("outVal").toString().toDouble()
                                ));
                    } else {
                        xml.skipCurrentElement();
                    }
                } } while(xml.name() != "IA_OnGrnd");
            } else {
                xml.skipCurrentElement();
            }
        }
    }while(xml.name() != "FuzzyDetectorSettings");
}
void process(QXmlStreamReader &xml, const QByteArray &headerPath, const QByteArray &prefix)
{
    if (!xml.readNextStartElement())
        return;

    if (xml.name() != "protocol") {
        xml.raiseError(QStringLiteral("The file is not a wayland protocol file."));
        return;
    }

    protocolName = byteArrayValue(xml, "name");

    if (protocolName.isEmpty()) {
        xml.raiseError(QStringLiteral("Missing protocol name."));
        return;
    }

    //We should convert - to _ so that the preprocessor wont generate code which will lead to unexpected behavior
    //However, the wayland-scanner doesn't do so we will do the same for now
    //QByteArray preProcessorProtocolName = QByteArray(protocolName).replace('-', '_').toUpper();
    QByteArray preProcessorProtocolName = QByteArray(protocolName).toUpper();

    QList<WaylandInterface> interfaces;

    while (xml.readNextStartElement()) {
        if (xml.name() == "interface")
            interfaces << readInterface(xml);
        else
            xml.skipCurrentElement();
    }

    if (xml.hasError())
        return;

    if (option == ServerHeader) {
        QByteArray inclusionGuard = QByteArray("QT_WAYLAND_SERVER_") + preProcessorProtocolName.constData();
        printf("#ifndef %s\n", inclusionGuard.constData());
        printf("#define %s\n", inclusionGuard.constData());
        printf("\n");
        printf("#include \"wayland-server.h\"\n");
        if (headerPath.isEmpty())
            printf("#include \"wayland-%s-server-protocol.h\"\n", QByteArray(protocolName).replace('_', '-').constData());
        else
            printf("#include <%s/wayland-%s-server-protocol.h>\n", headerPath.constData(), QByteArray(protocolName).replace('_', '-').constData());
        printf("#include <QByteArray>\n");
        printf("#include <QMultiMap>\n");
        printf("#include <QString>\n");

        printf("\n");
        printf("#ifndef WAYLAND_VERSION_CHECK\n");
        printf("#define WAYLAND_VERSION_CHECK(major, minor, micro) \\\n");
        printf("    ((WAYLAND_VERSION_MAJOR > (major)) || \\\n");
        printf("    (WAYLAND_VERSION_MAJOR == (major) && WAYLAND_VERSION_MINOR > (minor)) || \\\n");
        printf("    (WAYLAND_VERSION_MAJOR == (major) && WAYLAND_VERSION_MINOR == (minor) && WAYLAND_VERSION_MICRO >= (micro)))\n");
        printf("#endif\n");

        printf("\n");
        printf("QT_BEGIN_NAMESPACE\n");

        QByteArray serverExport;
        if (headerPath.size()) {
            serverExport = QByteArray("Q_WAYLAND_SERVER_") + preProcessorProtocolName + "_EXPORT";
            printf("\n");
            printf("#if !defined(%s)\n", serverExport.constData());
            printf("#  if defined(QT_SHARED)\n");
            printf("#    define %s Q_DECL_EXPORT\n", serverExport.constData());
            printf("#  else\n");
            printf("#    define %s\n", serverExport.constData());
            printf("#  endif\n");
            printf("#endif\n");
        }
        printf("\n");
        printf("namespace QtWaylandServer {\n");

        for (int j = 0; j < interfaces.size(); ++j) {
            const WaylandInterface &interface = interfaces.at(j);

            if (ignoreInterface(interface.name))
                continue;

            const char *interfaceName = interface.name.constData();

            QByteArray stripped = stripInterfaceName(interface.name, prefix);
            const char *interfaceNameStripped = stripped.constData();

            printf("    class %s %s\n    {\n", serverExport.constData(), interfaceName);
            printf("    public:\n");
            printf("        %s(struct ::wl_client *client, int id, int version);\n", interfaceName);
            printf("        %s(struct ::wl_display *display, int version);\n", interfaceName);
            printf("        %s();\n", interfaceName);
            printf("\n");
            printf("        virtual ~%s();\n", interfaceName);
            printf("\n");
            printf("        class Resource\n");
            printf("        {\n");
            printf("        public:\n");
            printf("            Resource() : %s_object(0), handle(0) {}\n", interfaceNameStripped);
            printf("            virtual ~Resource() {}\n");
            printf("\n");
            printf("            %s *%s_object;\n", interfaceName, interfaceNameStripped);
            printf("            struct ::wl_resource *handle;\n");
            printf("\n");
            printf("            struct ::wl_client *client() const { return handle->client; }\n");
            printf("            int version() const { return wl_resource_get_version(handle); }\n");
            printf("\n");
            printf("            static Resource *fromResource(struct ::wl_resource *resource) { return static_cast<Resource *>(resource->data); }\n");
            printf("        };\n");
            printf("\n");
            printf("        void init(struct ::wl_client *client, int id, int version);\n");
            printf("        void init(struct ::wl_display *display, int version);\n");
            printf("\n");
            printf("        Resource *add(struct ::wl_client *client, int version);\n");
            printf("        Resource *add(struct ::wl_client *client, int id, int version);\n");
            printf("        Resource *add(struct wl_list *resource_list, struct ::wl_client *client, int id, int version);\n");
            printf("\n");
            printf("        Resource *resource() { return m_resource; }\n");
            printf("        const Resource *resource() const { return m_resource; }\n");
            printf("\n");
            printf("        QMultiMap<struct ::wl_client*, Resource*> resourceMap() { return m_resource_map; }\n");
            printf("        const QMultiMap<struct ::wl_client*, Resource*> resourceMap() const { return m_resource_map; }\n");
            printf("\n");
            printf("        bool isGlobal() const { return m_global != 0; }\n");
            printf("        bool isResource() const { return m_resource != 0; }\n");

            printEnums(interface.enums);

            bool hasEvents = !interface.events.isEmpty();

            if (hasEvents) {
                printf("\n");
                foreach (const WaylandEvent &e, interface.events) {
                    printf("        void send_");
                    printEvent(e);
                    printf(";\n");
                    printf("        void send_");
                    printEvent(e, false, true);
                    printf(";\n");
                }
            }

            printf("\n");
            printf("    protected:\n");
            printf("        virtual Resource *%s_allocate();\n", interfaceNameStripped);
            printf("\n");
            printf("        virtual void %s_bind_resource(Resource *resource);\n", interfaceNameStripped);
            printf("        virtual void %s_destroy_resource(Resource *resource);\n", interfaceNameStripped);

            bool hasRequests = !interface.requests.isEmpty();

            if (hasRequests) {
                printf("\n");
                foreach (const WaylandEvent &e, interface.requests) {
                    printf("        virtual void %s_", interfaceNameStripped);
                    printEvent(e);
                    printf(";\n");
                }
            }

            printf("\n");
            printf("    private:\n");
            printf("        static void bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id);\n");
            printf("        static void destroy_func(struct ::wl_resource *client_resource);\n");
            printf("\n");
            printf("        Resource *bind(struct ::wl_client *client, uint32_t id, int version);\n");

            if (hasRequests) {
                printf("\n");
                printf("        static const struct ::%s_interface m_%s_interface;\n", interfaceName, interfaceName);

                printf("\n");
                for (int i = 0; i < interface.requests.size(); ++i) {
                    const WaylandEvent &e = interface.requests.at(i);
                    printf("        static void ");

                    printEventHandlerSignature(e, interfaceName);
                    printf(";\n");
                }
            }

            printf("\n");
            printf("        QMultiMap<struct ::wl_client*, Resource*> m_resource_map;\n");
            printf("        Resource *m_resource;\n");
            printf("        struct ::wl_global *m_global;\n");
            printf("        uint32_t m_globalVersion;\n");
            printf("    };\n");

            if (j < interfaces.size() - 1)
                printf("\n");
        }

        printf("}\n");
        printf("\n");
        printf("QT_END_NAMESPACE\n");
        printf("\n");
        printf("#endif\n");
    }
Example #19
0
void
CoverFetchArtPayload::prepareDiscogsUrls( QXmlStreamReader &xml )
{
    while( !xml.atEnd() && !xml.hasError() )
    {
        xml.readNext();
        if( !xml.isStartElement() || xml.name() != "release" )
            continue;

        const QString releaseId = xml.attributes().value( "id" ).toString();
        while( !xml.atEnd() && !xml.hasError() )
        {
            xml.readNext();
            const QStringRef &n = xml.name();
            if( xml.isEndElement() && n == "release" )
                break;
            if( !xml.isStartElement() )
                continue;

            CoverFetch::Metadata metadata;
            metadata[ "source" ] = "Discogs";
            if( n == "title" )
                metadata[ "title" ] = xml.readElementText();
            else if( n == "country" )
                metadata[ "country" ] = xml.readElementText();
            else if( n == "released" )
                metadata[ "released" ] = xml.readElementText();
            else if( n == "notes" )
                metadata[ "notes" ] = xml.readElementText();
            else if( n == "images" )
            {
                while( !xml.atEnd() && !xml.hasError() )
                {
                    xml.readNext();
                    if( xml.isEndElement() && xml.name() == "images" )
                        break;
                    if( !xml.isStartElement() )
                        continue;
                    if( xml.name() == "image" )
                    {
                        const QXmlStreamAttributes &attr = xml.attributes();
                        const KUrl thburl( attr.value( "uri150" ).toString() );
                        const KUrl uri( attr.value( "uri" ).toString() );
                        const KUrl url = (m_size == CoverFetch::ThumbSize) ? thburl : uri;
                        if( !url.isValid() )
                            continue;

                        metadata[ "releaseid"    ] = releaseId;
                        metadata[ "releaseurl"   ] = "http://discogs.com/release/" + releaseId;
                        metadata[ "normalarturl" ] = uri.url();
                        metadata[ "thumbarturl"  ] = thburl.url();
                        metadata[ "width"        ] = attr.value( "width"  ).toString();
                        metadata[ "height"       ] = attr.value( "height" ).toString();
                        metadata[ "type"         ] = attr.value( "type"   ).toString();
                        m_urls.insert( url, metadata );
                    }
                    else
                        xml.skipCurrentElement();
                }
            }
            else
                xml.skipCurrentElement();
        }
    }
}
Example #20
0
bool App::loadXML(QXmlStreamReader &doc, bool goToConsole, bool fromMemory)
{
    if (doc.readNextStartElement() == false)
        return false;

    if (doc.name() != KXMLQLCWorkspace)
    {
        qWarning() << Q_FUNC_INFO << "Workspace node not found";
        return false;
    }

    QString contextName = doc.attributes().value(KXMLQLCWorkspaceWindow).toString();

    while (doc.readNextStartElement())
    {
        if (doc.name() == KXMLQLCEngine)
        {
            m_doc->loadXML(doc);
        }
        else if (doc.name() == KXMLQLCVirtualConsole)
        {
            m_virtualConsole->loadXML(doc);
        }
#if 0
        else if (doc.name() == KXMLQLCSimpleDesk)
        {
            SimpleDesk::instance()->loadXML(doc);
        }
#endif
        else if (doc.name() == KXMLQLCCreator)
        {
            /* Ignore creator information */
            doc.skipCurrentElement();
        }
        else
        {
            qWarning() << Q_FUNC_INFO << "Unknown Workspace tag:" << doc.name().toString();
            doc.skipCurrentElement();
        }
    }

    if (goToConsole == true || accessMask() == AC_VCControl)
        // Force the active window to be Virtual Console
        m_contextManager->switchToContext("VirtualConsole");
    else
        // Set the active window to what was saved in the workspace file
        m_contextManager->switchToContext(contextName);

    // Perform post-load operations
    m_virtualConsole->postLoad();

    if (m_doc->errorLog().isEmpty() == false &&
        fromMemory == false)
    {
        // TODO: emit a signal to inform the QML UI to display an error message
        /*
        QMessageBox msg(QMessageBox::Warning, tr("Warning"),
                        tr("Some errors occurred while loading the project:") + "\n\n" + m_doc->errorLog(),
                        QMessageBox::Ok);
        msg.exec();
        */
    }

    return true;
}
Example #21
0
bool QLCFixtureDef::loadXML(QXmlStreamReader& doc)
{
    bool retval = false;

    if (doc.readNextStartElement() == false)
        return false;

    if (doc.name() == KXMLQLCFixtureDef)
    {
        while (doc.readNextStartElement())
        {
            if (doc.name() == KXMLQLCCreator)
            {
                loadCreator(doc);
            }
            else if (doc.name() == KXMLQLCFixtureDefManufacturer)
            {
                setManufacturer(doc.readElementText());
            }
            else if (doc.name() == KXMLQLCFixtureDefModel)
            {
                setModel(doc.readElementText());
            }
            else if (doc.name() == KXMLQLCFixtureDefType)
            {
                setType(doc.readElementText());
            }
            else if (doc.name() == KXMLQLCChannel)
            {
                QLCChannel* ch = new QLCChannel();
                if (ch->loadXML(doc) == true)
                {
                    /* Loading succeeded */
                    if (addChannel(ch) == false)
                    {
                        /* Channel already exists */
                        delete ch;
                    }
                }
                else
                {
                    /* Loading failed */
                    delete ch;
                }
            }
            else if (doc.name() == KXMLQLCFixtureMode)
            {
                QLCFixtureMode* mode = new QLCFixtureMode(this);
                if (mode->loadXML(doc) == true)
                {
                    /* Loading succeeded */
                    if (addMode(mode) == false)
                    {
                        /* Mode already exists */
                        delete mode;
                    }
                }
                else
                {
                    /* Loading failed */
                    delete mode;
                }
            }
            else
            {
                qWarning() << Q_FUNC_INFO << "Unknown Fixture tag: " << doc.name();
                doc.skipCurrentElement();
            }
        }

        retval = true;
    }
    else
    {
        qWarning() << Q_FUNC_INFO << "Fixture node not found";
        retval = false;
    }

    if (retval == true)
        m_isLoaded = true;
    return retval;
}
Example #22
0
std::unique_ptr<Template> Template::loadTemplateConfiguration(QXmlStreamReader& xml, Map& map, bool& open)
{
    Q_ASSERT(xml.name() == QLatin1String("template"));

    QXmlStreamAttributes attributes = xml.attributes();
    if (attributes.hasAttribute(QLatin1String("open")))
        open = (attributes.value(QLatin1String("open")) == QLatin1String("true"));

    QString path = attributes.value(QLatin1String("path")).toString();
    auto temp = templateForFile(path, &map);
    if (!temp)
        temp.reset(new TemplateImage(path, &map)); // fallback

    temp->setTemplateRelativePath(attributes.value(QLatin1String("relpath")).toString());
    if (attributes.hasAttribute(QLatin1String("name")))
        temp->template_file = attributes.value(QLatin1String("name")).toString();
    temp->is_georeferenced = (attributes.value(QLatin1String("georef")) == QLatin1String("true"));
    if (attributes.hasAttribute(QLatin1String("group")))
        temp->template_group = attributes.value(QLatin1String("group")).toInt();

    while (xml.readNextStartElement())
    {
        if (!temp->is_georeferenced && xml.name() == QLatin1String("transformations"))
        {
            temp->adjusted = (xml.attributes().value(QLatin1String("adjusted")) == QLatin1String("true"));
            temp->adjustment_dirty = (xml.attributes().value(QLatin1String("adjustment_dirty")) == QLatin1String("true"));
            int num_passpoints = xml.attributes().value(QLatin1String("passpoints")).toInt();
            Q_ASSERT(temp->passpoints.size() == 0);
            temp->passpoints.reserve(qMin(num_passpoints, 10)); // 10 is not a limit

            while (xml.readNextStartElement())
            {
                QStringRef role = xml.attributes().value(QLatin1String("role"));
                if (xml.name() == QLatin1String("transformation"))
                {
                    if (role == QLatin1String("active"))
                        temp->transform.load(xml);
                    else if (xml.attributes().value(QLatin1String("role")) == QLatin1String("other"))
                        temp->other_transform.load(xml);
                    else
                    {
                        qDebug() << xml.qualifiedName();
                        xml.skipCurrentElement(); // unsupported
                    }
                }
                else if (xml.name() == QLatin1String("passpoint"))
                {
                    temp->passpoints.push_back(PassPoint::load(xml));
                }
                else if (xml.name() == QLatin1String("matrix"))
                {
                    if (role == QLatin1String("map_to_template"))
                        temp->map_to_template.load(xml);
                    else if (role == QLatin1String("template_to_map"))
                        temp->template_to_map.load(xml);
                    else if (role == QLatin1String("template_to_map_other"))
                        temp->template_to_map_other.load(xml);
                    else
                    {
                        qDebug() << xml.qualifiedName();
                        xml.skipCurrentElement(); // unsupported
                    }
                }
                else
                {
                    qDebug() << xml.qualifiedName();
                    xml.skipCurrentElement(); // unsupported
                }
            }
        }
        else if (!temp->loadTypeSpecificTemplateConfiguration(xml))
        {
            temp.reset();
            break;
        }
    }

    if (temp && !temp->is_georeferenced)
    {
        // Fix template adjustment after moving objects during import (cf. #513)
        const auto offset = MapCoord::boundsOffset();
        if (!offset.isZero())
        {
            if (temp->template_to_map.getCols() == 3 && temp->template_to_map.getRows() == 3)
            {
                temp->template_to_map.set(0, 2, temp->template_to_map.get(0, 2) - offset.x / 1000.0);
                temp->template_to_map.set(1, 2, temp->template_to_map.get(1, 2) - offset.y / 1000.0);
                temp->template_to_map.invert(temp->map_to_template);
            }

            if (temp->template_to_map_other.getCols() == 3 && temp->template_to_map_other.getRows() == 3)
            {
                temp->template_to_map_other.set(0, 2, temp->template_to_map_other.get(0, 2) - offset.x / 1000.0);
                temp->template_to_map_other.set(1, 2, temp->template_to_map_other.get(1, 2) - offset.y / 1000.0);
            }
        }

        // Fix template alignment problems caused by grivation rounding since version 0.6
        const double correction = map.getGeoreferencing().getGrivationError();
        if (qAbs(correction) != 0.0
                && (qstrcmp(temp->getTemplateType(), "TemplateTrack") == 0
                    || qstrcmp(temp->getTemplateType(), "OgrTemplate") == 0) )
        {
            temp->setTemplateRotation(temp->getTemplateRotation() + Georeferencing::degToRad(correction));
        }
    }

    return temp;
}
bool QLCFixtureDefCache::loadMap(const QDir &dir)
{
    qDebug() << Q_FUNC_INFO << dir.path();

    if (dir.exists() == false || dir.isReadable() == false)
        return false;

    QString mapPath(dir.absoluteFilePath(FIXTURES_MAP_NAME));

    if (mapPath.isEmpty() == true)
        return false;

    // cache the map path to be used when composing the fixture
    // definition absolute path
    m_mapAbsolutePath = dir.absolutePath();

    QXmlStreamReader *doc = QLCFile::getXMLReader(mapPath);
    if (doc == NULL || doc->device() == NULL || doc->hasError())
    {
        qWarning() << Q_FUNC_INFO << "Unable to read from" << mapPath;
        return false;
    }

    while (!doc->atEnd())
    {
        if (doc->readNext() == QXmlStreamReader::DTD)
            break;
    }

    if (doc->hasError())
    {
        QLCFile::releaseXMLReader(doc);
        return false;
    }

    // make sure the doc type is FixtureMap
    if (doc->dtdName() != KXMLQLCFixtureMap)
    {
        qWarning() << Q_FUNC_INFO << mapPath << "is not a fixture map file";
        QLCFile::releaseXMLReader(doc);
        return false;
    }

    if (doc->readNextStartElement() == false)
    {
        QLCFile::releaseXMLReader(doc);
        return false;
    }

    // make sure the root tag is FixtureMap
    if (doc->name() != KXMLQLCFixtureMap)
    {
        qWarning() << Q_FUNC_INFO << mapPath << "is not a fixture map file";
        QLCFile::releaseXMLReader(doc);
        return false;
    }

    int fxCount = 0;
    QString manufacturer = "";

    while (doc->readNextStartElement())
    {
        if (doc->name() == "M")
        {
            if (doc->attributes().hasAttribute("n"))
            {
                manufacturer = doc->attributes().value("n").toString();
                fxCount += loadMapManufacturer(doc, manufacturer);
            }
        }
        else
        {
            qWarning() << Q_FUNC_INFO << "Unknown Fixture Map tag: " << doc->name();
            doc->skipCurrentElement();
        }
    }
    qDebug() << fxCount << "fixtures found in map";

#if 0
    /* Attempt to read all files not in FixtureMap */
    QStringList definitionPaths;

    // Gather a list of manufacturers
    QListIterator <QLCFixtureDef*> mfit(m_defs);
    while (mfit.hasNext() == true)
        definitionPaths << mfit.next()->definitionSourceFile();

    QStringListIterator it(dir.entryList());
    while (it.hasNext() == true)
    {
        QString path(dir.absoluteFilePath(it.next()));
        if (definitionPaths.contains(path))
            continue;

        qWarning() << path << "not in" << FIXTURES_MAP_NAME;

        if (path.toLower().endsWith(KExtFixture) == true)
            loadQXF(path);
        else if (path.toLower().endsWith(KExtAvolitesFixture) == true)
            loadD4(path);
        else
            qWarning() << Q_FUNC_INFO << "Unrecognized fixture extension:" << path;
    }
#endif
    return true;
}
Example #24
0
bool TagIO::read_xml(
        QIODevice* in,
        const QString& relative_dir,
        QHash< QString, QList<TagItem::Elements> >& elts
    )
{
    if( !in ) {
        return false;
    }

    QDir dir;
    if( !relative_dir.isEmpty() ) {
        dir = QDir( relative_dir ).absolutePath();
    }

    QXmlStreamReader xml;
    xml.setDevice( in );

    if( xml.readNext() == QXmlStreamReader::StartDocument && !xml.isStartDocument() ) {
        return false;
    }

    if( !xml.readNextStartElement() ) {
        return false;
    }

    if( xml.name() != DATASET ) {
        return false;
    }

    // skip info for user
    while( xml.readNextStartElement() && ( xml.name() != IMAGES && xml.name() != TAGS ) ) {
        xml.skipCurrentElement();
    }

    QHash<QString, QColor> tag_color_dict;
    if( xml.name() == TAGS ) {
        while( xml.readNextStartElement() && xml.name() == SINGLE_TAG ) {
            tag_color_dict[ xml.attributes().value( NAME ).toString() ] = QColor( xml.attributes().value( COLOR ).toString() );
            // empty elements are directly followed by endElement
            // so readNext must be called
            xml.readNextStartElement();
        }
    }

    // within the "images" element
    while( !xml.atEnd() ) {
        if( xml.name() == SINGLE_IMAGE ) {
            QString fullpath = xml.attributes().value( PATH ).toString();
            if( fullpath.isEmpty() ) {
                xml.skipCurrentElement();
                continue;
            }

            if( !relative_dir.isEmpty() && dir.exists() ) {
                fullpath = dir.absoluteFilePath( fullpath );
            }

            if( !xml.readNextStartElement() ) {
                xml.skipCurrentElement();
                continue;
            }

            while( xml.name() == BOX ) {
                QXmlStreamAttributes att =  xml.attributes();
                QStringRef top = att.value( TOP );
                QStringRef left = att.value( LEFT );
                QStringRef width = att.value( WIDTH );
                QStringRef height = att.value( HEIGHT );

                bool skip = ( top.isEmpty() || left.isEmpty() || width.isEmpty() || height.isEmpty() );
                xml.readNextStartElement();
                skip = skip || ( xml.name() != LABEL );
                QString label = xml.readElementText();
                skip = skip || ( label.isEmpty() );

                if( skip ) {
                    xml.skipCurrentElement();
                    xml.readNextStartElement();
                    continue;
                }

                TagItem::Elements elt;
                elt._fullpath = fullpath;
                elt._label = label;
                elt._color = tag_color_dict.value( label );
                elt._bbox.append( QRect( left.toInt(), top.toInt(), width.toInt(), height.toInt() ) );
                elts[ fullpath ].append( elt );

                xml.readNextStartElement();
                while( xml.isEndElement() ) {
                    xml.readNextStartElement();
                }
            }
        } else {
            xml.readNextStartElement();
        }
    }

    return true;
}