3 commits - c++/CMakeLists.txt c++/lib c++/tests schemas/xCard.xsd
Christian Mollekopf
mollekopf at kolabsys.com
Fri Mar 16 19:21:13 CET 2012
c++/CMakeLists.txt | 2
c++/lib/kolabcontact.h | 50 +++++++++---
c++/lib/xcardconversions.h | 72 +++++++++++++++---
c++/tests/bindingstest.cpp | 12 ++-
c++/tests/serializers.h | 25 ++++++
schemas/xCard.xsd | 176 ++++++++++++++++++++++-----------------------
6 files changed, 221 insertions(+), 116 deletions(-)
New commits:
commit 6ed9a90747bba67d140bd59c6559a80fb7a442f9
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Mar 16 19:20:39 2012 +0100
Fix indent.
diff --git a/schemas/xCard.xsd b/schemas/xCard.xsd
index 88f16c4..e456aff 100644
--- a/schemas/xCard.xsd
+++ b/schemas/xCard.xsd
@@ -36,89 +36,89 @@
<xs:complexType name="BaseParameterType" abstract="true"/>
<xs:element name="baseParameter" type="xcard:BaseParameterType"/>
<xs:complexType name="ArrayOfParameters">
- <xs:sequence>
- <xs:element ref="xcard:baseParameter" minOccurs="0" maxOccurs="unbounded"/>
- </xs:sequence>
+ <xs:sequence>
+ <xs:element ref="xcard:baseParameter" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
</xs:complexType>
<xs:complexType name="TextParameterType" mixed="false">
- <xs:complexContent>
- <xs:extension base="xcard:BaseParameterType">
- <xs:sequence>
- <xs:element ref="xcard:text"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
+ <xs:complexContent>
+ <xs:extension base="xcard:BaseParameterType">
+ <xs:sequence>
+ <xs:element ref="xcard:text"/>
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
</xs:complexType>
<xs:complexType name="UriParameterType" mixed="false">
- <xs:complexContent>
- <xs:extension base="xcard:BaseParameterType">
- <xs:sequence>
- <xs:element ref="xcard:uri"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
+ <xs:complexContent>
+ <xs:extension base="xcard:BaseParameterType">
+ <xs:sequence>
+ <xs:element ref="xcard:uri"/>
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
</xs:complexType>
<!-- We mix types from different properties here for simplicity -->
- <xs:simpleType name="TypeValueType">
- <xs:restriction base="xs:token">
- <!--Address-->
- <xs:enumeration value="work"/>
- <xs:enumeration value="home"/>
- <!--Telephone-->
- <xs:enumeration value="text"/>
- <xs:enumeration value="voice"/>
- <xs:enumeration value="fax"/>
- <xs:enumeration value="cell"/>
- <xs:enumeration value="video"/>
- <xs:enumeration value="pager"/>
- <xs:enumeration value="textphone"/>
- <xs:enumeration value="x-car"/>
- <!-- Related -->
- <xs:enumeration value="spouse"/>
- <xs:enumeration value="child"/>
- </xs:restriction>
- </xs:simpleType>
-
- <xs:complexType name="typeParamType" mixed="false">
- <xs:complexContent>
- <xs:extension base="xcard:BaseParameterType">
- <xs:sequence>
- <xs:element name="text" type="xcard:TypeValueType" minOccurs="1" maxOccurs="unbounded" />
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
-
- <xs:complexType name="labelParamType" mixed="false">
- <xs:complexContent>
- <xs:extension base="xcard:TextParameterType"/>
- </xs:complexContent>
- </xs:complexType>
-
- <xs:complexType name="prefParamType" mixed="false">
- <xs:complexContent>
- <xs:extension base="xcard:BaseParameterType">
- <xs:sequence>
- <xs:element name="integer" type="xs:string" fixed="1" />
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
-
- <xs:complexType name="xuidParamType" mixed="false">
- <xs:complexContent>
- <xs:extension base="xcard:UriParameterType"/>
- </xs:complexContent>
- </xs:complexType>
+ <xs:simpleType name="TypeValueType">
+ <xs:restriction base="xs:token">
+ <!--Address-->
+ <xs:enumeration value="work"/>
+ <xs:enumeration value="home"/>
+ <!--Telephone-->
+ <xs:enumeration value="text"/>
+ <xs:enumeration value="voice"/>
+ <xs:enumeration value="fax"/>
+ <xs:enumeration value="cell"/>
+ <xs:enumeration value="video"/>
+ <xs:enumeration value="pager"/>
+ <xs:enumeration value="textphone"/>
+ <xs:enumeration value="x-car"/>
+ <!-- Related -->
+ <xs:enumeration value="spouse"/>
+ <xs:enumeration value="child"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:complexType name="typeParamType" mixed="false">
+ <xs:complexContent>
+ <xs:extension base="xcard:BaseParameterType">
+ <xs:sequence>
+ <xs:element name="text" type="xcard:TypeValueType" minOccurs="1" maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="labelParamType" mixed="false">
+ <xs:complexContent>
+ <xs:extension base="xcard:TextParameterType"/>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="prefParamType" mixed="false">
+ <xs:complexContent>
+ <xs:extension base="xcard:BaseParameterType">
+ <xs:sequence>
+ <xs:element name="integer" type="xs:string" fixed="1" />
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="xuidParamType" mixed="false">
+ <xs:complexContent>
+ <xs:extension base="xcard:UriParameterType"/>
+ </xs:complexContent>
+ </xs:complexType>
- <!-- WARNING: don't forget to add those, otherwise the serialization code will not be built and you're up for a long debugging session -->
- <xs:element name="type" type="xcard:typeParamType" substitutionGroup="xcard:baseParameter"/>
- <xs:element name="label" type="xcard:labelParamType" substitutionGroup="xcard:baseParameter"/>
- <xs:element name="pref" type="xcard:prefParamType" substitutionGroup="xcard:baseParameter"/>
- <xs:element name="x-uid" type="xcard:xuidParamType" substitutionGroup="xcard:baseParameter"/>
+ <!-- WARNING: don't forget to add those, otherwise the serialization code will not be built and you're up for a long debugging session -->
+ <xs:element name="type" type="xcard:typeParamType" substitutionGroup="xcard:baseParameter"/>
+ <xs:element name="label" type="xcard:labelParamType" substitutionGroup="xcard:baseParameter"/>
+ <xs:element name="pref" type="xcard:prefParamType" substitutionGroup="xcard:baseParameter"/>
+ <xs:element name="x-uid" type="xcard:xuidParamType" substitutionGroup="xcard:baseParameter"/>
<!-- Properties -->
<xs:complexType name="BasePropertyType" abstract="true" >
@@ -256,11 +256,11 @@
<xs:complexContent mixed="false">
<xs:extension base="xcard:BasePropertyType">
<xs:sequence>
- <xs:element name="surname" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
- <xs:element name="given" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
- <xs:element name="additional" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
- <xs:element name="prefix" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
- <xs:element name="suffix" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="surname" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="given" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="additional" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="prefix" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="suffix" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
@@ -348,15 +348,15 @@
</xs:complexType>
<xs:simpleType name="SexType">
- <xs:restriction base="xs:token">
- <xs:enumeration value=""/>
- <xs:enumeration value="M"/>
- <xs:enumeration value="F"/>
- </xs:restriction>
+ <xs:restriction base="xs:token">
+ <xs:enumeration value=""/>
+ <xs:enumeration value="M"/>
+ <xs:enumeration value="F"/>
+ </xs:restriction>
</xs:simpleType>
<xs:complexType name="genderPropType">
- <xs:sequence>
+ <xs:sequence>
<xs:element name="sex" type="xcard:SexType" />
</xs:sequence>
</xs:complexType>
@@ -395,13 +395,6 @@
</xs:complexContent>
</xs:complexType>
- <xs:complexType name="cryptoPropType">
- <xs:complexContent mixed="false">
- <xs:extension base="xcard:TextPropertyType"/>
-<!-- TODO -->
- </xs:complexContent>
- </xs:complexType>
-
<xs:complexType name="memberPropType">
<xs:complexContent mixed="false">
<xs:extension base="xcard:UriPropertyType"/>
commit 6a4cbdf839d3cc9fcd9a641575d5c58c5ba5221c
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Mar 16 19:16:51 2012 +0100
Recompile schemas when any schema changed.
diff --git a/c++/CMakeLists.txt b/c++/CMakeLists.txt
index bf3e267..2e70a9b 100644
--- a/c++/CMakeLists.txt
+++ b/c++/CMakeLists.txt
@@ -105,7 +105,7 @@ add_custom_command(OUTPUT kolabformat-xcal-schema.cxx
COMMAND ${CMAKE_BUILD_DIR}/xsdbin --verbose --array-name iCalendar_schema --output-dir ${CMAKE_BUILD_DIR} ${SCHEMA_DIR}/ical/kolabformat-xcal.xsd ${SCHEMA_DIR}/ical/iCalendar-params.xsd ${SCHEMA_DIR}/ical/iCalendar-props.xsd ${SCHEMA_DIR}/ical/iCalendar-valtypes.xsd ${SCHEMA_DIR}/xCard.xsd ${SCHEMA_DIR}/kolabformat-xcard.xsd ${SCHEMA_DIR}/kolabformat.xsd
COMMENT "Compiling Kolab XSD schema"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
- DEPENDS ${XCAL_SCHEMAS} xsdbin
+ DEPENDS ${SCHEMAS} xsdbin
VERBATIM
)
set( SCHEMA_SOURCEFILES ${SCHEMA_SOURCEFILES} ${CMAKE_BUILD_DIR}/kolabformat-xcal-schema.cxx)
commit cf5f2a528328e9f087718864fe7bc67c25741885
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Mar 16 19:16:36 2012 +0100
Implemented Relateds.
diff --git a/c++/lib/kolabcontact.h b/c++/lib/kolabcontact.h
index 2402995..2b2b63f 100644
--- a/c++/lib/kolabcontact.h
+++ b/c++/lib/kolabcontact.h
@@ -138,20 +138,42 @@ private:
};
struct Related {
-// void setUri(const std::string &);
-// std::string uri() const;
-// void setText(const std::string &);
-// std::string text() const;
-// enum Type {
-// Child,
-// Spouse
-// };
-// void setType(Type t) { type = t; };
-// Type type() const { return type; };
-// private:
-// std::string uri;
-// std::string text;
-// Type type;
+
+ enum DescriptionType {
+ Invalid,
+ Text,
+ Urn
+ };
+ Related(): mType(Invalid), mRelationType(NoRelation) {};
+ Related(DescriptionType t, const std::string &textOrUri)
+ : mType(t), mRelationType(NoRelation)
+ {
+ if (t == Text) {
+ mText = textOrUri;
+ } else {
+ mUri = textOrUri;
+ }
+ };
+ bool operator==(const Related &other) const { return mType == other.mType &&
+ mUri == other.mUri &&
+ mText == other.mText &&
+ mRelationType == other.mRelationType;
+ };
+ DescriptionType type() const { return mType; };
+ std::string uri() const { return mUri; };
+ std::string text() const { return mText; };
+ enum RelationType {
+ NoRelation = 0,
+ Child = 0x01,
+ Spouse = 0x02
+ };
+ void setRelationTypes(int t) { mRelationType = t; };
+ int relationTypes() const { return mRelationType; };
+private:
+ DescriptionType mType;
+ std::string mUri;
+ std::string mText;
+ int mRelationType;
};
struct Telephone {
diff --git a/c++/lib/xcardconversions.h b/c++/lib/xcardconversions.h
index c2ea691..1f9d094 100644
--- a/c++/lib/xcardconversions.h
+++ b/c++/lib/xcardconversions.h
@@ -377,10 +377,35 @@ void writeCard<Kolab::Contact>(vcard_4_0::vcard &vcard, const Kolab::Contact &co
if (!contact.relateds().empty()) {
vcard::related_sequence seq;
-// BOOST_FOREACH(const std::string &s, contact.urls()) {
-// urls.push_back(vcard::url_type(s));
-// }
- //TODO
+ BOOST_FOREACH(const Kolab::Related &r, contact.relateds()) {
+ vcard_4_0::vcard::related_type related;
+ if (!r.uri().empty()) {
+ related.uri(r.uri());
+ } else {
+ related.text(r.text());
+ }
+ if (r.relationTypes() != Kolab::Related::NoRelation) {
+
+ vcard::adr_type::parameters_type::baseParameter_sequence base;
+ vcard::adr_type::parameters_type b;
+
+ vcard_4_0::typeParamType::text_sequence seq;
+ if (r.relationTypes() & Kolab::Related::Child) {
+ seq.push_back(TypeValueType::child);
+ }
+ if (r.relationTypes() & Kolab::Related::Spouse) {
+ seq.push_back(TypeValueType::spouse);
+ }
+ if (!seq.empty()) {
+ vcard_4_0::typeParamType type;
+ type.text(seq);
+ b.baseParameter().push_back(type);
+ }
+
+ related.parameters(b);
+ }
+ seq.push_back(related);
+ }
vcard.related(seq);
}
@@ -683,12 +708,39 @@ boost::shared_ptr<Kolab::Contact> readCard <Kolab::Contact> (const vcard_4_0::Vc
contact->setNickNames(toTextList<TextListPropertyType::text_type>((*vcard.nickname()).text()));
}
if (!vcard.related().empty()) {
-// std::vector<Related> list;
-// BOOST_FOREACH(const vcard::lang_type l, vcard.lang()) {
-// list.push_back(l.language_tag());
-// }
-// contact->setRelateds();
- //TODO
+ std::vector<Related> list;
+ BOOST_FOREACH(const vcard_4_0::vcard::related_type &r, vcard.related()) {
+ Kolab::Related::DescriptionType type;
+ std::string textOrUri;
+ if (r.uri()) {
+ type = Kolab::Related::Urn;
+ textOrUri = *r.uri();
+ } else if (r.text()) {
+ type = Kolab::Related::Text;
+ textOrUri = *r.text();
+ } else {
+ ERROR("no text and no uri");
+ }
+ Kolab::Related related(type, textOrUri);
+ if (r.parameters()) {
+ BOOST_FOREACH(const vcard_4_0::ArrayOfParameters::baseParameter_type ¶m, (*r.parameters()).baseParameter()) {
+ if (const vcard_4_0::typeParamType *rel = dynamic_cast<const vcard_4_0::typeParamType*> (¶m)) {
+ int types = 0;
+ BOOST_FOREACH(const std::string &s, rel->text()) {
+ if (s == TypeValueType(TypeValueType::child)) {
+ types |= Kolab::Related::Child;
+ }
+ if (s == TypeValueType(TypeValueType::spouse)) {
+ types |= Kolab::Related::Spouse;
+ }
+ }
+ related.setRelationTypes(types);
+ }
+ }
+ }
+ list.push_back(related);
+ }
+ contact->setRelateds(list);
}
if (vcard.bday()) {
contact->setBDay(toDateTime(*vcard.bday()));
diff --git a/c++/tests/bindingstest.cpp b/c++/tests/bindingstest.cpp
index 66d5f28..5aece5c 100644
--- a/c++/tests/bindingstest.cpp
+++ b/c++/tests/bindingstest.cpp
@@ -350,6 +350,16 @@ void BindingsTest::contactCompletness()
c.setFreeBusyUrl("freebusy");
c.setUrls(stringlist);
c.setNickNames(stringlist);
+
+ std::vector <Kolab::Related> relateds;
+ Kolab::Related r1(Kolab::Related::Text, "text");
+ r1.setRelationTypes(Kolab::Related::Child);
+ relateds.push_back(r1);
+ Kolab::Related r2(Kolab::Related::Urn, "urn");
+ r2.setRelationTypes(Kolab::Related::Child|Kolab::Related::Spouse);
+ relateds.push_back(r2);
+ c.setRelateds(relateds);
+
c.setBDay(Kolab::cDateTime(2001,12,10,12,12,12,false));
c.setAnniversary(Kolab::cDateTime(2001,3,2,1,1,1,false));
c.setPhoto("photo", "mimetype");
@@ -431,7 +441,7 @@ void BindingsTest::contactCompletness()
QCOMPARE(e.addresses(), c.addresses());
QCOMPARE(e.addressPreferredIndex(), c.addressPreferredIndex());
QCOMPARE(e.nickNames(), c.nickNames());
-// QCOMPARE(e.relateds(), c.relateds());
+ QCOMPARE(e.relateds(), c.relateds());
QCOMPARE(e.bDay(), c.bDay());
QCOMPARE(e.anniversary(), c.anniversary());
QCOMPARE(e.photo(), c.photo());
diff --git a/c++/tests/serializers.h b/c++/tests/serializers.h
index 7d4cb70..a669347 100644
--- a/c++/tests/serializers.h
+++ b/c++/tests/serializers.h
@@ -176,7 +176,7 @@ namespace QTest {
return qstrdup(ba.data());
}
- template<>
+ template<>
char *toString(const std::vector<Kolab::Affiliation> &v)
{
QByteArray ba = "vector<Kolab::Affiliation>(";
@@ -186,6 +186,29 @@ namespace QTest {
ba += ")";
return qstrdup(ba.data());
}
+
+ template<>
+ char *toString(const Kolab::Related &a)
+ {
+ QByteArray ba = "Kolab::Related(";
+ ba += QString::fromStdString(a.text()).toAscii()+ "\n " +
+ QString::fromStdString(a.uri()).toAscii()+"\n " +
+ QByteArray::number(a.relationTypes()) + "\n " +
+ QByteArray::number(a.type()) + "\n ";
+ ba += ")";
+ return qstrdup(ba.data());
+ }
+
+ template<>
+ char *toString(const std::vector<Kolab::Related> &v)
+ {
+ QByteArray ba = "vector<Kolab::Related>(";
+ for (int i = 0; i < v.size(); i++) {
+ ba += QByteArray(toString(v.at(i)))+ "\n";
+ }
+ ba += ")";
+ return qstrdup(ba.data());
+ }
}
diff --git a/schemas/xCard.xsd b/schemas/xCard.xsd
index beb7970..88f16c4 100644
--- a/schemas/xCard.xsd
+++ b/schemas/xCard.xsd
@@ -61,11 +61,13 @@
</xs:complexContent>
</xs:complexType>
-
+<!-- We mix types from different properties here for simplicity -->
<xs:simpleType name="TypeValueType">
<xs:restriction base="xs:token">
+ <!--Address-->
<xs:enumeration value="work"/>
<xs:enumeration value="home"/>
+ <!--Telephone-->
<xs:enumeration value="text"/>
<xs:enumeration value="voice"/>
<xs:enumeration value="fax"/>
@@ -74,6 +76,9 @@
<xs:enumeration value="pager"/>
<xs:enumeration value="textphone"/>
<xs:enumeration value="x-car"/>
+ <!-- Related -->
+ <xs:enumeration value="spouse"/>
+ <xs:enumeration value="child"/>
</xs:restriction>
</xs:simpleType>
More information about the commits
mailing list