summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-04-12 08:17:04 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-04-15 08:43:37 (GMT)
commitbc397320d395054960197b85861636c5b6a7551c (patch)
treeef10d31af0132a5d8076e6d2e3b55fedb8a7144b
parent78f024d71fdd42923417e3dc03d5a35ab1313efa (diff)
downloadlibkolabxml-bc397320d395054960197b85861636c5b6a7551c.tar.gz
Support for types on email addresses.
Patch by Thomas
-rw-r--r--schemas/xCard.xsd2
-rw-r--r--src/containers/kolabcontact.cpp6
-rw-r--r--src/containers/kolabcontact.h23
-rw-r--r--src/kolabformat.i1
-rw-r--r--src/xcardconversions.h45
-rw-r--r--tests/bindingstest.cpp6
6 files changed, 72 insertions, 11 deletions
diff --git a/schemas/xCard.xsd b/schemas/xCard.xsd
index c02ab52..e2d8034 100644
--- a/schemas/xCard.xsd
+++ b/schemas/xCard.xsd
@@ -64,7 +64,7 @@
<!-- We mix types from different properties here for simplicity -->
<xs:simpleType name="TypeValueType">
<xs:restriction base="xs:token">
- <!--Address-->
+ <!--Address/Email-->
<xs:enumeration value="work"/>
<xs:enumeration value="home"/>
<!--Telephone-->
diff --git a/src/containers/kolabcontact.cpp b/src/containers/kolabcontact.cpp
index 528b13d..1c5bb0d 100644
--- a/src/containers/kolabcontact.cpp
+++ b/src/containers/kolabcontact.cpp
@@ -150,7 +150,7 @@ struct Contact::Private
int telephonesPreferredIndex;
std::vector<std::string> imAddresses;
int imAddressPreferredIndex;
- std::vector<std::string> emailAddresses;
+ std::vector<Email> emailAddresses;
int emailAddressPreferredIndex;
std::vector<Geo> gpsPos;
std::vector<Key> keys;
@@ -416,13 +416,13 @@ int Contact::imAddressPreferredIndex() const
return d->imAddressPreferredIndex;
}
-void Contact::setEmailAddresses(const std::vector< std::string >& email, int preferredIndex)
+void Contact::setEmailAddresses(const std::vector< Email >& email, int preferredIndex)
{
d->emailAddresses = email;
d->emailAddressPreferredIndex = preferredIndex;
}
-std::vector< std::string > Contact::emailAddresses() const
+std::vector< Email > Contact::emailAddresses() const
{
return d->emailAddresses;
}
diff --git a/src/containers/kolabcontact.h b/src/containers/kolabcontact.h
index 86306ba..c790b1e 100644
--- a/src/containers/kolabcontact.h
+++ b/src/containers/kolabcontact.h
@@ -196,6 +196,25 @@ private:
int mType;
};
+struct Email {
+ enum Type {
+ None = 0,
+ Work = 0x01,
+ Home = 0x02
+ };
+ Email(): mType(None){};
+ Email(const std::string &a, int t = None): mAddress(a), mType(t) {};
+ bool operator==(const Email &other) const { return mAddress == other.mAddress &&
+ mType == other.mType; };
+ void setTypes(int t) { mType = t; };
+ int types() const { return mType; };
+ void setAddress(const std::string &n) { mAddress = n; };
+ std::string address() const { return mAddress; };
+private:
+ std::string mAddress;
+ int mType;
+};
+
struct Crypto {
enum CryptoTypes {
PGPinline = 0x01,
@@ -386,8 +405,8 @@ public:
std::vector<std::string> imAddresses() const;
int imAddressPreferredIndex() const;
- void setEmailAddresses(const std::vector<std::string> &, int preferredIndex = -1);
- std::vector<std::string> emailAddresses() const;
+ void setEmailAddresses(const std::vector<Email> &, int preferredIndex = -1);
+ std::vector<Email> emailAddresses() const;
int emailAddressPreferredIndex() const;
void setGPSpos(const std::vector<Geo> &);
diff --git a/src/kolabformat.i b/src/kolabformat.i
index 6a51ccf..f2ffd6c 100644
--- a/src/kolabformat.i
+++ b/src/kolabformat.i
@@ -39,6 +39,7 @@ namespace std {
%template(vectorevent) vector<Kolab::Event>;
%template(vectorrelated) vector<Kolab::Related>;
%template(vectortelephone) vector<Kolab::Telephone>;
+ %template(vectoremail) vector<Kolab::Email>;
%template(vectordatetime) vector<Kolab::cDateTime>;
%template(vectorurl) vector<Kolab::Url>;
%template(vectorkey) vector<Kolab::Key>;
diff --git a/src/xcardconversions.h b/src/xcardconversions.h
index 8e913d3..6461556 100644
--- a/src/xcardconversions.h
+++ b/src/xcardconversions.h
@@ -669,7 +669,31 @@ void writeCard<Kolab::Contact>(vcard_4_0::vcard &vcard, const Kolab::Contact &co
}
if (!contact.emailAddresses().empty()) {
- vcard.email(fromList<vcard::email_type>(contact.emailAddresses(), contact.emailAddressPreferredIndex()));
+ vcard::email_sequence seq;
+ int index = 0;
+ const std::vector<Email> &l = contact.emailAddresses();
+ BOOST_FOREACH(const Kolab::Email &e, l) {
+ vcard::email_type email(e.address());
+ vcard_4_0::typeParamType emailTypeParam;
+ if (e.types() & Kolab::Email::Home) {
+ emailTypeParam.text().push_back(TypeValueType::home);
+ }
+ if (e.types() & Kolab::Email::Work) {
+ emailTypeParam.text().push_back(TypeValueType::work);
+ }
+ vcard::tel_type::parameters_type params;
+ if(contact.emailAddressPreferredIndex() == index) {
+ params.baseParameter().push_back(vcard_4_0::prefParamType(vcard_4_0::prefParamType::integer_default_value()));
+ }
+ index++;
+
+ if (!emailTypeParam.text().empty()) {
+ params.baseParameter().push_back(emailTypeParam);
+ email.parameters(params);
+ }
+ seq.push_back(email);
+ }
+ vcard.email(seq);
}
if (!contact.gpsPos().empty()) {
@@ -1005,18 +1029,31 @@ boost::shared_ptr<Kolab::Contact> readCard <Kolab::Contact> (const vcard_4_0::Vc
if (!vcard.email().empty()) {
int preferredIndex = -1;
- std::vector<std::string> list;
+ std::vector<Kolab::Email> list;
int i = 0;
BOOST_FOREACH(const vcard_4_0::TextPropertyType &s, vcard.email()) {
+ Kolab::Email email;
if (s.parameters()) {
BOOST_FOREACH(const vcard_4_0::ArrayOfParameters::baseParameter_type &param, (*s.parameters()).baseParameter()) {
if (dynamic_cast<const vcard_4_0::prefParamType*> (&param)) {
preferredIndex = i;
- }
+ } else if (const vcard_4_0::typeParamType *rel = dynamic_cast<const vcard_4_0::typeParamType*> (&param)) {
+ int types = 0;
+ BOOST_FOREACH(const std::string &s, rel->text()) {
+ if (s == TypeValueType(TypeValueType::work)) {
+ types |= Kolab::Email::Work;
+ }
+ if (s == TypeValueType(TypeValueType::home)) {
+ types |= Kolab::Email::Home;
+ }
+ }
+ email.setTypes(types);
+ }
}
}
i++;
- list.push_back(s.text());
+ email.setAddress(s.text());
+ list.push_back(email);
}
contact->setEmailAddresses(list, preferredIndex);
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index ed012d7..ebee799 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -566,7 +566,11 @@ void BindingsTest::contactCompletness()
c.setGender(Kolab::Contact::Male);
c.setLanguages(stringlist);
c.setIMaddresses(stringlist,1);
- c.setEmailAddresses(stringlist,1);
+ std::vector <Kolab::Email> emails;
+ emails.push_back(Kolab::Email("email1@example.org", Kolab::Email::None));
+ emails.push_back(Kolab::Email("email2@example.org", Kolab::Email::Work));
+ emails.push_back(Kolab::Email("email3@example.org", Kolab::Email::Work|Kolab::Email::Home));
+ c.setEmailAddresses(emails,1);
c.setTitles(stringlist);
std::vector<Kolab::Affiliation> list;