File indexing completed on 2024-05-12 05:25:58
0001 /* 0002 * Copyright (C) 2017 Sandro Knauß <knauss@kolabsys.com> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0018 */ 0019 0020 #include "contactpreprocessor.h" 0021 0022 #include <KContacts/VCardConverter> 0023 #include <KContacts/Addressee> 0024 0025 using namespace Sink; 0026 0027 void updatedProperties(Sink::ApplicationDomain::Contact &contact, const KContacts::Addressee &addressee) 0028 { 0029 contact.setUid(addressee.uid()); 0030 contact.setFn(addressee.formattedName()); 0031 contact.setFirstname(addressee.givenName()); 0032 contact.setLastname(addressee.familyName()); 0033 QList<Sink::ApplicationDomain::Contact::Email> emails; 0034 for (const auto &email : addressee.emails()) { 0035 emails << Sink::ApplicationDomain::Contact::Email{Sink::ApplicationDomain::Contact::Email::Undefined, email}; 0036 } 0037 contact.setEmails(emails); 0038 0039 contact.setPhoto(addressee.photo().rawData()); 0040 } 0041 0042 ContactPropertyExtractor::~ContactPropertyExtractor() 0043 { 0044 } 0045 0046 void ContactPropertyExtractor::newEntity(Sink::ApplicationDomain::Contact &contact) 0047 { 0048 KContacts::VCardConverter converter; 0049 const auto addressee = converter.parseVCard(contact.getVcard()); 0050 if (!addressee.isEmpty()) { 0051 updatedProperties(contact, addressee); 0052 } 0053 } 0054 0055 void ContactPropertyExtractor::modifiedEntity(const Sink::ApplicationDomain::Contact &oldContact, Sink::ApplicationDomain::Contact &newContact) 0056 { 0057 KContacts::VCardConverter converter; 0058 const auto addressee = converter.parseVCard(newContact.getVcard()); 0059 if (!addressee.isEmpty()) { 0060 updatedProperties(newContact, addressee); 0061 } 0062 }