Пример #1
0
void ErrorFactory::serialize(Payload* obj, QXmlStreamWriter* writer)
{
	Error *error = se_cast<Error*>(obj);
	if(error->type() == Error::UndefinedType || error->condition() == Error::Undefined)
		return;
	writer->writeStartElement(QLatin1String("error"));
	writer->writeAttribute(QLatin1String("type"),enumToStr(error->type(),error_types));
	writer->writeEmptyElement(enumToStr(error->condition(),error_conditions));
	writer->writeDefaultNamespace(NS_ERROR);
	writer->writeEndElement();
}
Пример #2
0
void PrivacyQueryFactory::serialize(Payload *extension, QXmlStreamWriter *writer)
{
	PrivacyQuery *query = se_cast<PrivacyQuery*>(extension);
	Q_ASSERT(query);
	writer->writeStartElement(QLatin1String("query"));
	writer->writeDefaultNamespace(NS_PRIVACY);
	if (!query->activeList.isNull()) {
		writer->writeEmptyElement(QLatin1String("active"));
		if (!query->activeList.isEmpty())
			writer->writeAttribute(QLatin1String("name"), query->activeList);
	}
	if (!query->defaultList.isNull()) {
		writer->writeEmptyElement(QLatin1String("default"));
		if (!query->defaultList.isEmpty())
			writer->writeAttribute(QLatin1String("name"), query->defaultList);
	}
	for (int i = 0; i < query->lists.size(); i++) {
		const PrivacyQuery::List &list = query->lists.at(i);
		writer->writeStartElement(QLatin1String("list"));
		writer->writeAttribute(QLatin1String("name"), list.name);
		for (int j = 0; j < list.items.size(); j++) {
			const PrivacyItem &item = list.items.at(j);
			QString value;
			switch (item.type()) {
			case PrivacyItem::ByJID:
				value = item.jid().full();
				break;
			case PrivacyItem::ByGroup:
				value = item.group();
				break;
			case PrivacyItem::BySubscription:
				value = enumToStr(item.subscription(), subscription_types);
				break;
			default:
				break;
			}
			writer->writeStartElement(QLatin1String("item"));
			if (item.type() != PrivacyItem::All) {
				writer->writeAttribute(QLatin1String("type"), enumToStr(item.type(), privacy_types));
				writer->writeAttribute(QLatin1String("value"), value);
			}
			writer->writeAttribute(QLatin1String("action"), enumToStr(item.action(), privacy_actions));
			writer->writeAttribute(QLatin1String("order"), QString::number(item.order()));
			int types = item.stanzaTypes();
			for (int k = 0; k < 4; k++) {
				if (types & (1 << k))
					writer->writeEmptyElement(QLatin1String(privacy_stanzas[k]));
			}
			writer->writeEndElement();
		}
		writer->writeEndElement();
	}
	writer->writeEndElement();
}
Пример #3
0
void BookmarkFactory::serialize(Payload *extension, QXmlStreamWriter *writer)
{
	Bookmark *bookmark = se_cast<Bookmark*>(extension);
	writer->writeStartElement(QLatin1String("storage"));
	writer->writeDefaultNamespace(NS_BOOKMARKS);
	foreach (const Bookmark::Conference &conf, bookmark->conferences()) {
		writer->writeStartElement(QLatin1String("conference"));
		writeAttribute(writer,QLatin1String("jid"), conf.jid().full());
		writeAttribute(writer,QLatin1String("name"), conf.name());
		writeAttribute(writer,QLatin1String("autojoin"), enumToStr(conf.autojoin(), autojoin_types));
		writeTextElement(writer,QLatin1String("nick"), conf.nick());
		writeTextElement(writer,QLatin1String("password"), conf.password());
		writer->writeEndElement();
	}
	writer->writeEndElement();
}
Пример #4
0
void MessageFactory::serialize(Stanza *stanza, QXmlStreamWriter *writer)
{
	if (!StanzaPrivate::get(*stanza)->tokens.isEmpty()) {
		StanzaFactory::serialize(stanza, writer);
		return;
	}
	Message *message = static_cast<Message*>(stanza);
	if (message->subtype() == Message::Invalid)
		return;

	QLatin1String subtype = enumToStr(message->subtype(),message_types);

	writer->writeStartElement(QLatin1String("message"));
	writeAttributes(stanza, writer);
	if (subtype != QLatin1String(""))
		writer->writeAttribute(QLatin1String("type"), subtype);
	writeLangMap(QLatin1String("subject"),message->subject(),writer);
	writeLangMap(QLatin1String("body"),message->body(),writer);
	if(!message->thread().isEmpty())
		writer->writeTextElement(QLatin1String("thread"),message->thread());
	writePayloads(stanza, writer);
	writer->writeEndElement();
}
Пример #5
0
void toBytes(Str& topic,Bytes& message) {
	Str& str = (Str&) message;
	enumToStr(str, gpioModeEnum, sizeof(gpioModeEnum) / sizeof(EnumEntry),
			_gpio.getMode());
}