diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | common/CMakeLists.txt | 5 | ||||
-rw-r--r-- | common/contactpreprocessor.cpp | 60 | ||||
-rw-r--r-- | common/contactpreprocessor.h | 32 | ||||
-rw-r--r-- | examples/davresource/davresource.cpp | 20 |
5 files changed, 99 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 48a06f7..9e2b3bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -21,7 +21,7 @@ include(ECMSetupVersion) | |||
21 | include(KDEInstallDirs) | 21 | include(KDEInstallDirs) |
22 | 22 | ||
23 | find_package(Qt5 COMPONENTS REQUIRED Core Network) | 23 | find_package(Qt5 COMPONENTS REQUIRED Core Network) |
24 | find_package(KF5 COMPONENTS REQUIRED Async Mime) | 24 | find_package(KF5 COMPONENTS REQUIRED Async Mime Contacts) |
25 | find_package(KPimKDAV REQUIRED) | 25 | find_package(KPimKDAV REQUIRED) |
26 | find_package(FlatBuffers REQUIRED) | 26 | find_package(FlatBuffers REQUIRED) |
27 | 27 | ||
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 676342d..5e26cd9 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt | |||
@@ -71,6 +71,7 @@ set(command_SRCS | |||
71 | adaptorfactoryregistry.cpp | 71 | adaptorfactoryregistry.cpp |
72 | synchronizer.cpp | 72 | synchronizer.cpp |
73 | synchronizerstore.cpp | 73 | synchronizerstore.cpp |
74 | contactpreprocessor.cpp | ||
74 | mailpreprocessor.cpp | 75 | mailpreprocessor.cpp |
75 | specialpurposepreprocessor.cpp | 76 | specialpurposepreprocessor.cpp |
76 | datastorequery.cpp | 77 | datastorequery.cpp |
@@ -115,8 +116,8 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} | |||
115 | SOVERSION 0 | 116 | SOVERSION 0 |
116 | EXPORT_NAME ${PROJECT_NAME} | 117 | EXPORT_NAME ${PROJECT_NAME} |
117 | ) | 118 | ) |
118 | qt5_use_modules(${PROJECT_NAME} Network) | 119 | qt5_use_modules(${PROJECT_NAME} Network Gui) |
119 | target_link_libraries(${PROJECT_NAME} ${storage_LIBS} KF5::Async KF5::Mime) | 120 | target_link_libraries(${PROJECT_NAME} ${storage_LIBS} KF5::Async KF5::Mime KF5::Contacts) |
120 | install(TARGETS ${PROJECT_NAME} | 121 | install(TARGETS ${PROJECT_NAME} |
121 | EXPORT SinkTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) | 122 | EXPORT SinkTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) |
122 | 123 | ||
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 | } | ||
diff --git a/common/contactpreprocessor.h b/common/contactpreprocessor.h new file mode 100644 index 0000000..d3aaf39 --- /dev/null +++ b/common/contactpreprocessor.h | |||
@@ -0,0 +1,32 @@ | |||
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 | #pragma once | ||
21 | |||
22 | #include "sink_export.h" | ||
23 | |||
24 | #include "pipeline.h" | ||
25 | |||
26 | class SINK_EXPORT ContactPropertyExtractor : public Sink::EntityPreprocessor<Sink::ApplicationDomain::Contact> | ||
27 | { | ||
28 | public: | ||
29 | virtual ~ContactPropertyExtractor(); | ||
30 | virtual void newEntity(Sink::ApplicationDomain::Contact &mail) Q_DECL_OVERRIDE; | ||
31 | virtual void modifiedEntity(const Sink::ApplicationDomain::Contact &oldContact, Sink::ApplicationDomain::Contact &newContact) Q_DECL_OVERRIDE; | ||
32 | }; | ||
diff --git a/examples/davresource/davresource.cpp b/examples/davresource/davresource.cpp index 81ae675..b0a9ea3 100644 --- a/examples/davresource/davresource.cpp +++ b/examples/davresource/davresource.cpp | |||
@@ -31,6 +31,8 @@ | |||
31 | #include "facadefactory.h" | 31 | #include "facadefactory.h" |
32 | #include "adaptorfactoryregistry.h" | 32 | #include "adaptorfactoryregistry.h" |
33 | 33 | ||
34 | #include "contactpreprocessor.h" | ||
35 | |||
34 | #include <KDAV/DavCollection> | 36 | #include <KDAV/DavCollection> |
35 | #include <KDAV/DavCollectionsFetchJob> | 37 | #include <KDAV/DavCollectionsFetchJob> |
36 | #include <KDAV/DavItemsListJob> | 38 | #include <KDAV/DavItemsListJob> |
@@ -523,23 +525,7 @@ DavResource::DavResource(const Sink::ResourceContext &resourceContext) | |||
523 | setupSynchronizer(synchronizer); | 525 | setupSynchronizer(synchronizer); |
524 | //setupInspector(QSharedPointer<MaildirInspector>::create(resourceContext)); | 526 | //setupInspector(QSharedPointer<MaildirInspector>::create(resourceContext)); |
525 | 527 | ||
526 | /* | 528 | setupPreprocessors(ENTITY_TYPE_CONTACT, QVector<Sink::Preprocessor*>() << new ContactPropertyExtractor); |
527 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor(resourceContext.resourceType, resourceContext.instanceId()) << new MaildirMimeMessageMover(resourceContext.instanceId(), mMaildirPath) << new MaildirMailPropertyExtractor); | ||
528 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath)); | ||
529 | |||
530 | KPIM::Contactdir dir(mMaildirPath, true); | ||
531 | SinkTrace() << "Started maildir resource for maildir: " << mMaildirPath; | ||
532 | { | ||
533 | auto draftsFolder = dir.addSubFolder("Drafts"); | ||
534 | auto remoteId = synchronizer->createFolder(draftsFolder, "folder", QByteArrayList() << "drafts"); | ||
535 | auto draftsFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId); | ||
536 | } | ||
537 | { | ||
538 | auto trashFolder = dir.addSubFolder("Trash"); | ||
539 | auto remoteId = synchronizer->createFolder(trashFolder, "folder", QByteArrayList() << "trash"); | ||
540 | auto trashFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId); | ||
541 | } | ||
542 | synchronizer->commit();*/ | ||
543 | } | 529 | } |
544 | 530 | ||
545 | 531 | ||