diff options
author | Sandro Knauß <sknauss@kde.org> | 2017-01-26 00:05:11 +0100 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2017-01-30 10:59:30 +0100 |
commit | e61b0ab5a8eb3b5014892b9fd5ad26ebe57bccf5 (patch) | |
tree | 7c929889d1988c7cad6701e3b47dc375ae668234 /common/contactpreprocessor.cpp | |
parent | d03c67ede657851735945c52895da411458cb7c4 (diff) | |
download | sink-e61b0ab5a8eb3b5014892b9fd5ad26ebe57bccf5.tar.gz sink-e61b0ab5a8eb3b5014892b9fd5ad26ebe57bccf5.zip |
extract datas from VCard
Diffstat (limited to 'common/contactpreprocessor.cpp')
-rw-r--r-- | common/contactpreprocessor.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/common/contactpreprocessor.cpp b/common/contactpreprocessor.cpp new file mode 100644 index 0000000..fbf5e2c --- /dev/null +++ b/common/contactpreprocessor.cpp | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 Sandro Knauß <knauss@kolabsys.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include "contactpreprocessor.h" | ||
21 | |||
22 | #include <KContacts/VCardConverter> | ||
23 | #include <KContacts/Addressee> | ||
24 | |||
25 | using namespace Sink; | ||
26 | |||
27 | SINK_DEBUG_AREA("contactpreprocessor") | ||
28 | |||
29 | void updatedProperties(Sink::ApplicationDomain::Contact &contact, const KContacts::Addressee &addressee) | ||
30 | { | ||
31 | contact.setUid(addressee.uid()); | ||
32 | contact.setFn(addressee.formattedName()); | ||
33 | QByteArrayList emails; | ||
34 | for (const auto email : addressee.emails()) { | ||
35 | emails << email.toUtf8(); | ||
36 | } | ||
37 | contact.setEmails(emails); | ||
38 | } | ||
39 | |||
40 | ContactPropertyExtractor::~ContactPropertyExtractor() | ||
41 | { | ||
42 | } | ||
43 | |||
44 | void ContactPropertyExtractor::newEntity(Sink::ApplicationDomain::Contact &contact) | ||
45 | { | ||
46 | KContacts::VCardConverter converter; | ||
47 | const auto addressee = converter.parseVCard(contact.getVcard()); | ||
48 | if (!addressee.isEmpty()) { | ||
49 | updatedProperties(contact, addressee); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | void ContactPropertyExtractor::modifiedEntity(const Sink::ApplicationDomain::Contact &oldContact, Sink::ApplicationDomain::Contact &newContact) | ||
54 | { | ||
55 | KContacts::VCardConverter converter; | ||
56 | const auto addressee = converter.parseVCard(newContact.getVcard()); | ||
57 | if (!addressee.isEmpty()) { | ||
58 | updatedProperties(newContact, addressee); | ||
59 | } | ||
60 | } | ||