summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-09-23 21:55:47 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-09-23 21:55:47 (GMT)
commitcedf32e806f1cd48afc27be36bd754c27db832d7 (patch)
tree433fab55b24427f0976c3ee2f675c04cfe95b11e
parent518d3d901352f8000846ac262870a8c3097ac27a (diff)
downloadlibkolab-cedf32e806f1cd48afc27be36bd754c27db832d7.tar.gz
email types.
-rw-r--r--conversion/kabcconversion.cpp30
-rw-r--r--tests/kcalconversiontest.cpp34
2 files changed, 57 insertions, 7 deletions
diff --git a/conversion/kabcconversion.cpp b/conversion/kabcconversion.cpp
index 112633f..566652f 100644
--- a/conversion/kabcconversion.cpp
+++ b/conversion/kabcconversion.cpp
@@ -398,6 +398,28 @@ std::string getCustom(const std::string &id, T &object)
return std::string();
}
+static QString emailTypesToStringList(int emailTypes) {
+ QStringList types;
+ if (emailTypes & Kolab::Email::Home) {
+ types << "home";
+ }
+ if (emailTypes & Kolab::Email::Work) {
+ types << "work";
+ }
+ return types.join(",");
+}
+
+static int emailTypesFromStringlist(const QString &types) {
+ int emailTypes = Kolab::Email::NoType;
+ if (types.contains("home")) {
+ emailTypes |= Kolab::Email::Home;
+ }
+ if (types.contains("work")) {
+ emailTypes |= Kolab::Email::Work;
+ }
+ return emailTypes;
+}
+
KABC::Addressee toKABC(const Kolab::Contact &contact)
{
KABC::Addressee addressee;
@@ -434,7 +456,10 @@ KABC::Addressee toKABC(const Kolab::Contact &contact)
QStringList emails;
foreach( const Kolab::Email &email, contact.emailAddresses()) {
emails << fromStdString(email.address());
- //FIXME preserve type
+ const QString types = emailTypesToStringList(email.types());
+ if (!types.isEmpty()) {
+ addressee.insertCustom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(fromStdString(email.address())), types);
+ }
}
addressee.setEmails(emails);
if ((contact.emailAddressPreferredIndex() >= 0) && (contact.emailAddressPreferredIndex() < static_cast<int>(contact.emailAddresses().size()))) {
@@ -716,8 +741,7 @@ Kolab::Contact fromKABC(const KABC::Addressee &addressee)
prefEmail = count;
}
count++;
- //FIXME preserve types
- emails.push_back(Kolab::Email(toStdString(e)));
+ emails.push_back(Kolab::Email(toStdString(e), emailTypesFromStringlist(addressee.custom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(e)))));
}
c.setEmailAddresses(emails, prefEmail);
if (addressee.geo().isValid()) {
diff --git a/tests/kcalconversiontest.cpp b/tests/kcalconversiontest.cpp
index 635b8ae..6f7e84d 100644
--- a/tests/kcalconversiontest.cpp
+++ b/tests/kcalconversiontest.cpp
@@ -506,17 +506,36 @@ void KCalConversionTest::testContactConversion_data()
Kolab::cDateTime date(2011,2,2,12,11,10,true);
Kolab::cDateTime date2(2011,2,2,12,12,10,true);
-
{
KABC::Addressee kcal;
kcal.setUid("uid");
kcal.setFormattedName("name");
-
+
Kolab::Contact kolab;
kolab.setUid("uid");
kolab.setName("name");
-
- QTest::newRow( "contact" ) << kcal << kolab;
+
+ QTest::newRow("basic") << kcal << kolab;
+ }
+ {
+ KABC::Addressee kcal;
+ kcal.setUid("uid");
+ //The first address is always the preferred
+ kcal.setEmails(QStringList() << "email1@example.org" << "email2@example.org");
+ kcal.insertCustom("KOLAB", "EmailTypesemail1@example.org", "home,work");
+
+ Kolab::Contact kolab;
+ kolab.setUid("uid");
+
+ Kolab::Email email1("email1@example.org", Kolab::Email::Work|Kolab::Email::Home);
+ Kolab::Email email2("email2@example.org");
+
+ std::vector<Kolab::Email> emails;
+ emails.push_back(email1);
+ emails.push_back(email2);
+ kolab.setEmailAddresses(emails, 0);
+
+ QTest::newRow("emailTypesAndPreference") << kcal << kolab;
}
}
@@ -530,10 +549,17 @@ void KCalConversionTest::testContactConversion()
QCOMPARE(e.uid(), kcal.uid());
QCOMPARE(e.formattedName(), kcal.formattedName());
+ QCOMPARE(e.emails(), kcal.emails());
+ QCOMPARE(e.preferredEmail(), kcal.preferredEmail());
+ foreach (const QString &mail, e.emails()) {
+ QCOMPARE(e.custom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(mail)), kcal.custom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(mail)));
+ }
const Kolab::Contact &b = fromKABC(kcal);
QCOMPARE(b.uid(), kolab.uid());
QCOMPARE(b.name(), kolab.name());
+ QCOMPARE(b.emailAddresses(), kolab.emailAddresses());
+ QCOMPARE(b.emailAddressPreferredIndex(), kolab.emailAddressPreferredIndex());
}