aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <[email protected]>2018-03-07 21:29:47 +0100
committerDaniel Vrátil <[email protected]>2018-03-07 21:53:38 +0100
commitaa0e64103afd12a42be34893878274e967f5bd41 (patch)
tree62fac992052b40fdaf043f93eac0dceef4e44fa9
parent9d15a2e8fcbf00d73db3110b5f0a2955e801c86b (diff)
Import Akonadi Serializer plugins for contacts from kdepim-runtime
See commit cde643e6d840d591b6ae1b7f1a49488c495c4774 in kdepim-runtime for details.
-rw-r--r--CMakeLists.txt1
-rw-r--r--serializers/CMakeLists.txt40
-rw-r--r--serializers/Messages.sh4
-rw-r--r--serializers/akonadi_serializer_addressee.cpp308
-rw-r--r--serializers/akonadi_serializer_addressee.desktop101
-rw-r--r--serializers/akonadi_serializer_addressee.h54
-rw-r--r--serializers/akonadi_serializer_contactgroup.cpp132
-rw-r--r--serializers/akonadi_serializer_contactgroup.desktop99
-rw-r--r--serializers/akonadi_serializer_contactgroup.h53
-rw-r--r--serializers/autotests/CMakeLists.txt6
-rw-r--r--serializers/autotests/addresseeserializertest.cpp48
-rw-r--r--src/CMakeLists.txt1
12 files changed, 847 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e846662..c80722f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,6 +60,7 @@ endif()
add_subdirectory(src)
add_subdirectory(kcm)
+add_subdirectory(serializers)
install( FILES akonadi-contacts.renamecategories akonadi-contacts.categories DESTINATION ${KDE_INSTALL_CONFDIR} )
diff --git a/serializers/CMakeLists.txt b/serializers/CMakeLists.txt
new file mode 100644
index 0000000..a056c2a
--- /dev/null
+++ b/serializers/CMakeLists.txt
@@ -0,0 +1,40 @@
+add_definitions(-DTRANSLATION_DOMAIN=\"akonadicontact5-serializer\")
+
+if (BUILD_TESTING)
+ add_subdirectory(autotests)
+endif()
+
+set(akonadi_serializer_addressee_SRCS
+ akonadi_serializer_addressee.cpp
+)
+add_library(akonadi_serializer_addressee MODULE ${akonadi_serializer_addressee_SRCS})
+target_link_libraries(akonadi_serializer_addressee
+ KF5::Contacts
+ KF5::AkonadiCore
+ KF5::I18n
+)
+install(TARGETS akonadi_serializer_addressee
+ DESTINATION ${KDE_INSTALL_PLUGINDIR}
+)
+install(FILES akonadi_serializer_addressee.desktop
+ DESTINATION ${KDE_INSTALL_DATADIR}/akonadi/plugins/serializer
+)
+
+
+
+set(akonadi_serializer_contactgroup_SRCS
+ akonadi_serializer_contactgroup.cpp
+)
+add_library(akonadi_serializer_contactgroup MODULE ${akonadi_serializer_contactgroup_SRCS})
+target_link_libraries(akonadi_serializer_contactgroup
+ KF5::Contacts
+ KF5::AkonadiCore
+ KF5::I18n
+ KF5::AkonadiContact
+)
+install(TARGETS akonadi_serializer_contactgroup
+ DESTINATION ${KDE_INSTALL_PLUGINDIR}
+)
+install(FILES akonadi_serializer_contactgroup.desktop
+ DESTINATION ${KDE_INSTALL_DATADIR}/akonadi/plugins/serializer
+)
diff --git a/serializers/Messages.sh b/serializers/Messages.sh
new file mode 100644
index 0000000..07f7db6
--- /dev/null
+++ b/serializers/Messages.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+$XGETTEXT `find . -name \*.cpp | grep -v '/autotests/'` -o $podir/akonadicontact5-serializer.pot
+
+
diff --git a/serializers/akonadi_serializer_addressee.cpp b/serializers/akonadi_serializer_addressee.cpp
new file mode 100644
index 0000000..ca2dbb7
--- /dev/null
+++ b/serializers/akonadi_serializer_addressee.cpp
@@ -0,0 +1,308 @@
+/*
+ Copyright (c) 2007 Till Adam <[email protected]>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+ License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#include "akonadi_serializer_addressee.h"
+
+#include <AkonadiCore/AbstractDifferencesReporter>
+#include <AkonadiCore/Item>
+
+#include <KContacts/Addressee>
+#include <KLocalizedString>
+#include <QDebug>
+
+using namespace Akonadi;
+
+//// ItemSerializerPlugin interface
+
+// FIXME: these values map to Akonadi::ContactParts::Standard and
+// Akonadi::ContactParts::Lookup from AkonadiContact library. We don't use those
+// symbols here, because AkonadiContact library links to Qt5WebEngine, which when
+// loaded tries to initialize OpenGL. When this plugin gets loaded by Akonadi
+// from KRunner, it happens in a non-GUI thread, leading to a crash in Qt5WebEngine.
+#define CONTACTPART_STANDARD "CONTACT_STANDARD"
+#define CONTACTPART_LOOKUP "CONTACT_LOOKUP"
+
+bool SerializerPluginAddressee::deserialize(Item &item, const QByteArray &label, QIODevice &data, int version)
+{
+ Q_UNUSED(version);
+
+ KContacts::Addressee addr;
+ if (label == Item::FullPayload) {
+ addr = m_converter.parseVCard(data.readAll());
+ } else if (label == CONTACTPART_STANDARD) {
+ addr = m_converter.parseVCard(data.readAll());
+
+ // remove pictures and sound
+ addr.setPhoto(KContacts::Picture());
+ addr.setLogo(KContacts::Picture());
+ addr.setSound(KContacts::Sound());
+ } else if (label == CONTACTPART_LOOKUP) {
+ const KContacts::Addressee temp = m_converter.parseVCard(data.readAll());
+
+ // copy only uid, name and email addresses
+ addr.setUid(temp.uid());
+ addr.setPrefix(temp.prefix());
+ addr.setGivenName(temp.givenName());
+ addr.setAdditionalName(temp.additionalName());
+ addr.setFamilyName(temp.familyName());
+ addr.setSuffix(temp.suffix());
+ addr.setEmails(temp.emails());
+ } else {
+ return false;
+ }
+
+ if (!addr.isEmpty()) {
+ item.setPayload<KContacts::Addressee>(addr);
+ } else {
+ qWarning() << "Empty addressee object!";
+ }
+
+ return true;
+}
+
+void SerializerPluginAddressee::serialize(const Item &item, const QByteArray &label, QIODevice &data, int &version)
+{
+ Q_UNUSED(version);
+
+ if (label != Item::FullPayload && label != CONTACTPART_STANDARD && label != CONTACTPART_LOOKUP) {
+ return;
+ }
+
+ if (!item.hasPayload<KContacts::Addressee>()) {
+ return;
+ }
+
+ KContacts::Addressee addr, temp;
+
+ temp = item.payload<KContacts::Addressee>();
+
+ if (label == Item::FullPayload) {
+ addr = temp;
+ } else if (label == CONTACTPART_STANDARD) {
+ addr = temp;
+
+ // remove pictures and sound
+ addr.setPhoto(KContacts::Picture());
+ addr.setLogo(KContacts::Picture());
+ addr.setSound(KContacts::Sound());
+ } else if (label == CONTACTPART_LOOKUP) {
+ // copy only uid, name and email addresses
+ addr.setUid(temp.uid());
+ addr.setPrefix(temp.prefix());
+ addr.setGivenName(temp.givenName());
+ addr.setAdditionalName(temp.additionalName());
+ addr.setFamilyName(temp.familyName());
+ addr.setSuffix(temp.suffix());
+ addr.setEmails(temp.emails());
+ }
+
+ data.write(m_converter.createVCard(addr));
+}
+
+//// DifferencesAlgorithmInterface interface
+
+static bool compareString(const QString &left, const QString &right)
+{
+ if (left.isEmpty() && right.isEmpty()) {
+ return true;
+ } else {
+ return left == right;
+ }
+}
+
+static QString toString(const KContacts::PhoneNumber &phoneNumber)
+{
+ return phoneNumber.number();
+}
+
+static QString toString(const KContacts::Address &address)
+{
+ return address.toString();
+}
+
+static QString toString(const QString &value)
+{
+ return value;
+}
+
+template<class T>
+static void compareList(Akonadi::AbstractDifferencesReporter *reporter, const QString &id, const QList<T> &left, const QList<T> &right)
+{
+ for (int i = 0; i < left.count(); ++i) {
+ if (!right.contains(left[ i ])) {
+ reporter->addProperty(AbstractDifferencesReporter::AdditionalLeftMode, id, toString(left[ i ]), QString());
+ }
+ }
+
+ for (int i = 0; i < right.count(); ++i) {
+ if (!left.contains(right[ i ])) {
+ reporter->addProperty(AbstractDifferencesReporter::AdditionalRightMode, id, QString(), toString(right[ i ]));
+ }
+ }
+}
+
+template<class T>
+static void compareVector(Akonadi::AbstractDifferencesReporter *reporter, const QString &id, const QVector<T> &left, const QVector<T> &right)
+{
+ for (int i = 0; i < left.count(); ++i) {
+ if (!right.contains(left[ i ])) {
+ reporter->addProperty(AbstractDifferencesReporter::AdditionalLeftMode, id, toString(left[ i ]), QString());
+ }
+ }
+
+ for (int i = 0; i < right.count(); ++i) {
+ if (!left.contains(right[ i ])) {
+ reporter->addProperty(AbstractDifferencesReporter::AdditionalRightMode, id, QString(), toString(right[ i ]));
+ }
+ }
+}
+
+void SerializerPluginAddressee::compare(Akonadi::AbstractDifferencesReporter *reporter, const Akonadi::Item &leftItem, const Akonadi::Item &rightItem)
+{
+ Q_ASSERT(reporter);
+ Q_ASSERT(leftItem.hasPayload<KContacts::Addressee>());
+ Q_ASSERT(rightItem.hasPayload<KContacts::Addressee>());
+
+ reporter->setLeftPropertyValueTitle(i18n("Changed Contact"));
+ reporter->setRightPropertyValueTitle(i18n("Conflicting Contact"));
+
+ const KContacts::Addressee leftContact = leftItem.payload<KContacts::Addressee>();
+ const KContacts::Addressee rightContact = rightItem.payload<KContacts::Addressee>();
+
+ if (!compareString(leftContact.uid(), rightContact.uid())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::uidLabel(),
+ leftContact.uid(), rightContact.uid());
+ }
+
+ if (!compareString(leftContact.name(), rightContact.name())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::nameLabel(),
+ leftContact.name(), rightContact.name());
+ }
+
+ if (!compareString(leftContact.formattedName(), rightContact.formattedName())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::formattedNameLabel(),
+ leftContact.formattedName(), rightContact.formattedName());
+ }
+
+ if (!compareString(leftContact.familyName(), rightContact.familyName())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::familyNameLabel(),
+ leftContact.familyName(), rightContact.familyName());
+ }
+
+ if (!compareString(leftContact.givenName(), rightContact.givenName())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::givenNameLabel(),
+ leftContact.givenName(), rightContact.givenName());
+ }
+
+ if (!compareString(leftContact.additionalName(), rightContact.additionalName())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::additionalNameLabel(),
+ leftContact.additionalName(), rightContact.additionalName());
+ }
+
+ if (!compareString(leftContact.prefix(), rightContact.prefix())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::prefixLabel(),
+ leftContact.prefix(), rightContact.prefix());
+ }
+
+ if (!compareString(leftContact.suffix(), rightContact.suffix())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::suffixLabel(),
+ leftContact.suffix(), rightContact.suffix());
+ }
+
+ if (!compareString(leftContact.nickName(), rightContact.nickName())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::nickNameLabel(),
+ leftContact.nickName(), rightContact.nickName());
+ }
+
+ if (leftContact.birthday() != rightContact.birthday()) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::birthdayLabel(),
+ leftContact.birthday().toString(), rightContact.birthday().toString());
+ }
+
+ if (!compareString(leftContact.mailer(), rightContact.mailer())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::mailerLabel(),
+ leftContact.mailer(), rightContact.mailer());
+ }
+
+ if (leftContact.timeZone() != rightContact.timeZone()) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::timeZoneLabel(),
+ leftContact.timeZone().toString(), rightContact.timeZone().toString());
+ }
+
+ if (leftContact.geo() != rightContact.geo()) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::geoLabel(),
+ leftContact.geo().toString(), rightContact.geo().toString());
+ }
+
+ if (!compareString(leftContact.title(), rightContact.title())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::titleLabel(),
+ leftContact.title(), rightContact.title());
+ }
+
+ if (!compareString(leftContact.role(), rightContact.role())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::roleLabel(),
+ leftContact.role(), rightContact.role());
+ }
+
+ if (!compareString(leftContact.organization(), rightContact.organization())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::organizationLabel(),
+ leftContact.organization(), rightContact.organization());
+ }
+
+ if (!compareString(leftContact.note(), rightContact.note())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::noteLabel(),
+ leftContact.note(), rightContact.note());
+ }
+
+ if (!compareString(leftContact.productId(), rightContact.productId())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::productIdLabel(),
+ leftContact.productId(), rightContact.productId());
+ }
+
+ if (!compareString(leftContact.sortString(), rightContact.sortString())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::sortStringLabel(),
+ leftContact.sortString(), rightContact.sortString());
+ }
+
+ if (leftContact.secrecy() != rightContact.secrecy()) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::secrecyLabel(),
+ leftContact.secrecy().toString(), rightContact.secrecy().toString());
+ }
+
+ if (leftContact.url() != rightContact.url()) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, KContacts::Addressee::urlLabel(),
+ leftContact.url().url().toDisplayString(), rightContact.url().url().toDisplayString());
+ }
+
+ compareList(reporter, i18n("Emails"), leftContact.emails(), rightContact.emails());
+ compareVector(reporter, i18n("Phone Numbers"), leftContact.phoneNumbers(), rightContact.phoneNumbers());
+ compareVector(reporter, i18n("Addresses"), leftContact.addresses(), rightContact.addresses());
+
+ //TODO: logo/photo/custom entries
+}
+
+//// GidExtractorInterface
+
+QString SerializerPluginAddressee::extractGid(const Item &item) const
+{
+ if (!item.hasPayload<KContacts::Addressee>()) {
+ return QString();
+ }
+ return item.payload<KContacts::Addressee>().uid();
+}
diff --git a/serializers/akonadi_serializer_addressee.desktop b/serializers/akonadi_serializer_addressee.desktop
new file mode 100644
index 0000000..c5cfa14
--- /dev/null
+++ b/serializers/akonadi_serializer_addressee.desktop
@@ -0,0 +1,101 @@
+[Misc]
+Name=Addressee Serializer
+Name[ar]=مُسلسِل المخاطبين
+Name[bs]=Serializator adresiranog
+Name[ca]=Serialitzador de destinataris
+Name[[email protected]]=Serialitzador de destinataris
+Name[da]=Serieordning af adressater
+Name[de]=Empfänger-Serialisierung
+Name[el]=Σειριακοποιητής παραληπτών
+Name[en_GB]=Addressee Serialiser
+Name[es]=Serializador de destinatarios
+Name[et]=Aadresside jadasti
+Name[fi]=Vastaanottajaserialisoija
+Name[fr]=Sérialiseur de destinataires
+Name[ga]=Srathóir Seolaithe
+Name[gl]=Serializador de destinatarios
+Name[hu]=Címzettkezelő
+Name[ia]=Divulgator partial pro adresses
+Name[it]=Serializzatore degli indirizzi
+Name[ja]=受信者用シリアライザ
+Name[kk]=Адрес тізбектеуіші
+Name[km]=ម៉ាស៊ីន​បោះពុម្ព​អ្នក​ទទួល​សំបុត្រ
+Name[ko]=주소록 시리얼라이저
+Name[lt]=Adresatų serializatorius
+Name[lv]=Adrešu serializētājs
+Name[nb]=Adressatserialisator
+Name[nds]=Adressaten-Reegmoduul
+Name[ne]=प्रापक मिलानकर्ता
+Name[nl]=Adressenadministratie
+Name[nn]=Adressatserialisator
+Name[pa]=ਐਡਰੈੱਸ ਸੀਰੀਅਲਾਈਜ਼ਰ
+Name[pl]=Szeregowanie adresatów
+Name[pt]=Serializador de Destinatários
+Name[pt_BR]=Serializador de destinatários
+Name[ro]=Serializator destinatar
+Name[ru]=Сохранение контактов
+Name[sk]=Serializátor adresátov
+Name[sl]=Razvrščevalnik naslovnikov v zaporedje
+Name[sr]=Серијализатор адресаната
+Name[[email protected]]=Серијализатор адресаната
+Name[[email protected]]=Serijalizator adresanata
+Name[[email protected]]=Serijalizator adresanata
+Name[sv]=Adressatserialisering
+Name[tr]=Adres Sıralandırıcı
+Name[uk]=Серіалізатор адрес
+Name[x-test]=xxAddressee Serializerxx
+Name[zh_CN]=收信人序列转换器
+Name[zh_TW]=地址序列器
+Comment=An Akonadi serializer plugin for addressee objects
+Comment[ar]=ملحقة سَلسَلة «أكونادي» لكائنات المخاطبين
+Comment[bs]=Akonadi serializator za adresirane objekte
+Comment[ca]=Un connector de serialització de l'Akonadi pels objectes destinataris
+Comment[[email protected]]=Un connector de serialització de l'Akonadi pels objectes destinataris
+Comment[da]=Et Akonadi-plugin til serieordning af adressatobjekter
+Comment[de]=Akonadi-Modul zur Serialisierung von Adressobjekten
+Comment[el]=Ένα πρόσθετο σειριακοποιητή του Akonadi για αντικείμενα παραληπτών
+Comment[en_GB]=An Akonadi serialiser plugin for addressee objects
+Comment[es]=Un complemento serializador de Akonadi para objetos destinatario
+Comment[et]=Akonadi aadressiobjektide jadastamisplugin
+Comment[fi]=Akonadi-serialisoijaliitännäinen vastaanottajaobjekteille
+Comment[fr]=Un module externe Akonadi pour la sérialisation des destinataires
+Comment[ga]=Breiseán srathóra Akonadi le haghaidh seolaithe
+Comment[gl]=Complemento de serialización do Akonadi para obxectos destinatario
+Comment[hu]=Akonadi-modul a címzettek kezeléséhez
+Comment[ia]=Un plug-in pro divulgator partial de Akonadi pro objectos de adresses
+Comment[it]=Un'estensione di Akonadi per la serializzazione degli indirizzi
+Comment[ja]=受信者オブジェクトのための Akonadi シリアライザプラグイン
+Comment[kk]=Akonadi адресат нысандарының тізбектеуіш плагині
+Comment[km]=កម្មវិធី​ជំនួយ​កម្មវិធី​បោះពុម្ព Akonadi សម្រាប់​វត្ថុ​អ្នក​ទទួល​សំបុត្រ
+Comment[ko]=주소 객체를 위한 시리얼라이저 플러그인
+Comment[lt]=Akonadi adresatų objektų serializatoriaus papildinys
+Comment[lv]=Akonadi adrešu serializēšanas spraudnis
+Comment[nb]=Et Akonadi programtillegg for serialisering av adressat-objekter
+Comment[nds]=Akonadi-Inreegmoduul för Adressaten
+Comment[ne]=प्रापक वस्तुका लागि एउटा एकोनाडी मिलानकर्ता प्लगइन
+Comment[nl]=Een administratieplug-in voor Akonadi voor adressen
+Comment[nn]=Eit Akonadi-serialisatortillegg for adressatobjekt
+Comment[pa]=ਐਡਰੈੱਸ ਆਬਜੈਕਟਾਂ ਲਈ ਅਕੌਂਡੀ ਸੀਰੀਲਾਈਜ਼ਰ ਪਲੱਗਇਨ
+Comment[pl]=Wtyczka Akonadi do szeregowania obiektów adresata
+Comment[pt]=Um 'plugin' de serialização do Akonadi para os objectos endereçados
+Comment[pt_BR]=Um plugin de serialização do Akonadi para os objetos dos destinatários
+Comment[ro]=Modul de serializare Akonadi pentru obiecte „destinatar”
+Comment[ru]=Модуль сохранения контактов для Akonadi
+Comment[sk]=Plugin serializátora Akonadi pre objekty adresátov
+Comment[sl]=Akonadijev vstavek za razvrščanje predmetov naslovnikov v zaporedje
+Comment[sr]=Аконадијев прикључак серијализатора за објекте адресаната
+Comment[[email protected]]=Аконадијев прикључак серијализатора за објекте адресаната
+Comment[[email protected]]=Akonadijev priključak serijalizatora za objekte adresanata
+Comment[[email protected]]=Akonadijev priključak serijalizatora za objekte adresanata
+Comment[sv]=Ett insticksprogram till Akonadi för serialisering av adressatobjekt
+Comment[tr]=Adres nesneleri için bir Akonadi sıralandırıcısı
+Comment[uk]=Додаток серіалізації Akonadi для об'єктів адресатів
+Comment[x-test]=xxAn Akonadi serializer plugin for addressee objectsxx
+Comment[zh_CN]=对收信人对象进行序列转换的 Akonadi 插件
+Comment[zh_TW]=地址物件的 Akonadi 序列器外掛程式
+
+[Plugin]
+Type=text/vcard,text/directory
+X-Akonadi-Class=legacy;default;KContacts::Addressee;
+X-KDE-Library=akonadi_serializer_addressee
+X-KDE-ClassName=Akonadi::SerializerPluginAddressee
diff --git a/serializers/akonadi_serializer_addressee.h b/serializers/akonadi_serializer_addressee.h
new file mode 100644
index 0000000..d2fd233
--- /dev/null
+++ b/serializers/akonadi_serializer_addressee.h
@@ -0,0 +1,54 @@
+/*
+ Copyright (c) 2007 Till Adam <[email protected]>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+ License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#ifndef __AKONADI_SERIALIZER_ADDRESSEE_H__
+#define __AKONADI_SERIALIZER_ADDRESSEE_H__
+
+#include <QObject>
+
+#include <AkonadiCore/differencesalgorithminterface.h>
+#include <AkonadiCore/itemserializerplugin.h>
+#include <AkonadiCore/gidextractorinterface.h>
+#include <kcontacts/vcardconverter.h>
+
+namespace Akonadi {
+class SerializerPluginAddressee : public QObject
+ , public ItemSerializerPlugin
+ , public DifferencesAlgorithmInterface
+ , public GidExtractorInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(Akonadi::ItemSerializerPlugin)
+ Q_INTERFACES(Akonadi::DifferencesAlgorithmInterface)
+ Q_INTERFACES(Akonadi::GidExtractorInterface)
+ Q_PLUGIN_METADATA(IID "org.kde.akonadi.SerializerPluginAddressee")
+public:
+ bool deserialize(Item &item, const QByteArray &label, QIODevice &data, int version) override;
+ void serialize(const Item &item, const QByteArray &label, QIODevice &data, int &version) override;
+
+ void compare(Akonadi::AbstractDifferencesReporter *reporter, const Akonadi::Item &leftItem, const Akonadi::Item &rightItem) override;
+
+ QString extractGid(const Item &item) const override;
+
+private:
+ KContacts::VCardConverter m_converter;
+};
+}
+
+#endif
diff --git a/serializers/akonadi_serializer_contactgroup.cpp b/serializers/akonadi_serializer_contactgroup.cpp
new file mode 100644
index 0000000..cfcf818
--- /dev/null
+++ b/serializers/akonadi_serializer_contactgroup.cpp
@@ -0,0 +1,132 @@
+/*
+ Copyright (c) 2008 Kevin Krammer <[email protected]>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+ License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#include "akonadi_serializer_contactgroup.h"
+
+#include <AkonadiCore/abstractdifferencesreporter.h>
+#include <Akonadi/Contact/ContactGroupExpandJob>
+#include <AkonadiCore/item.h>
+
+#include <kcontacts/contactgroup.h>
+#include <kcontacts/contactgrouptool.h>
+#include <KLocalizedString>
+
+#include <qplugin.h>
+
+using namespace Akonadi;
+
+//// ItemSerializerPlugin interface
+
+bool SerializerPluginContactGroup::deserialize(Item &item, const QByteArray &label, QIODevice &data, int version)
+{
+ Q_UNUSED(label);
+ Q_UNUSED(version);
+
+ KContacts::ContactGroup contactGroup;
+
+ if (!KContacts::ContactGroupTool::convertFromXml(&data, contactGroup)) {
+ // TODO: error reporting
+ return false;
+ }
+
+ item.setPayload<KContacts::ContactGroup>(contactGroup);
+
+ return true;
+}
+
+void SerializerPluginContactGroup::serialize(const Item &item, const QByteArray &label, QIODevice &data, int &version)
+{
+ Q_UNUSED(label);
+ Q_UNUSED(version);
+
+ if (!item.hasPayload<KContacts::ContactGroup>()) {
+ return;
+ }
+
+ KContacts::ContactGroupTool::convertToXml(item.payload<KContacts::ContactGroup>(), &data);
+}
+
+//// DifferencesAlgorithmInterface interface
+
+static bool compareString(const QString &left, const QString &right)
+{
+ if (left.isEmpty() && right.isEmpty()) {
+ return true;
+ } else {
+ return left == right;
+ }
+}
+
+static QString toString(const KContacts::Addressee &contact)
+{
+ return contact.fullEmail();
+}
+
+template<class T>
+static void compareVector(AbstractDifferencesReporter *reporter, const QString &id, const QVector<T> &left, const QVector<T> &right)
+{
+ for (int i = 0; i < left.count(); ++i) {
+ if (!right.contains(left[ i ])) {
+ reporter->addProperty(AbstractDifferencesReporter::AdditionalLeftMode, id, toString(left[ i ]), QString());
+ }
+ }
+
+ for (int i = 0; i < right.count(); ++i) {
+ if (!left.contains(right[ i ])) {
+ reporter->addProperty(AbstractDifferencesReporter::AdditionalRightMode, id, QString(), toString(right[ i ]));
+ }
+ }
+}
+
+void SerializerPluginContactGroup::compare(Akonadi::AbstractDifferencesReporter *reporter, const Akonadi::Item &leftItem, const Akonadi::Item &rightItem)
+{
+ Q_ASSERT(reporter);
+ Q_ASSERT(leftItem.hasPayload<KContacts::ContactGroup>());
+ Q_ASSERT(rightItem.hasPayload<KContacts::ContactGroup>());
+
+ reporter->setLeftPropertyValueTitle(i18n("Changed Contact Group"));
+ reporter->setRightPropertyValueTitle(i18n("Conflicting Contact Group"));
+
+ const KContacts::ContactGroup leftContactGroup = leftItem.payload<KContacts::ContactGroup>();
+ const KContacts::ContactGroup rightContactGroup = rightItem.payload<KContacts::ContactGroup>();
+
+ if (!compareString(leftContactGroup.name(), rightContactGroup.name())) {
+ reporter->addProperty(AbstractDifferencesReporter::ConflictMode, i18n("Name"),
+ leftContactGroup.name(), rightContactGroup.name());
+ }
+
+ // using job->exec() is ok here, not a hot path
+ Akonadi::ContactGroupExpandJob *leftJob = new Akonadi::ContactGroupExpandJob(leftContactGroup);
+ leftJob->exec();
+
+ Akonadi::ContactGroupExpandJob *rightJob = new Akonadi::ContactGroupExpandJob(rightContactGroup);
+ rightJob->exec();
+
+ compareVector(reporter, i18n("Member"), leftJob->contacts(), rightJob->contacts());
+}
+
+//// GidExtractorInterface
+
+QString SerializerPluginContactGroup::extractGid(const Item &item) const
+{
+ if (!item.hasPayload<KContacts::ContactGroup>()) {
+ return QString();
+ }
+ return item.payload<KContacts::ContactGroup>().id();
+}
diff --git a/serializers/akonadi_serializer_contactgroup.desktop b/serializers/akonadi_serializer_contactgroup.desktop
new file mode 100644
index 0000000..e260566
--- /dev/null
+++ b/serializers/akonadi_serializer_contactgroup.desktop
@@ -0,0 +1,99 @@
+[Misc]
+Name=Contact Group Serializer
+Name[ar]=مُسلسِل مجموعات المتراسلين
+Name[bs]=Serializator kontaktne grupe
+Name[ca]=Serialitzador de grup de contactes
+Name[[email protected]]=Serialitzador de grup de contactes
+Name[da]=Serieordning af kontaktgruppe
+Name[de]=Kontaktgruppen-Serialisierung
+Name[el]=Σειριακοποιητής ομάδας επαφών
+Name[en_GB]=Contact Group Serialiser
+Name[es]=Serializador de grupos de contactos
+Name[et]=Kontaktirühma jadasti
+Name[fi]=Yhteystietoryhmäserialisoija
+Name[fr]=Sérialiseur de groupes de contacts
+Name[ga]=Srathóir Grúpa Teagmhálacha
+Name[gl]=Serializador de grupos de contacto
+Name[hu]=Névjegycsoport-kezelő
+Name[ia]=Divulgator partial de gruppo de contactos
+Name[it]=Serializzatore gruppi di contatti
+Name[ja]=連絡先グループ用シリアライザ
+Name[kk]=Контакт тобын тізбектеуіші
+Name[km]=អ្នក​ដាក់​លេខ​សៀរៀល​ក្រុម​ទំនាក់ទំនង
+Name[ko]=연락처 그룹 시리얼라이저
+Name[lt]=Adresatų grupių serializatorius
+Name[lv]=Kontaktu grupu serializētājs
+Name[nb]=Kontaktgruppeserialisator
+Name[nds]=Kontaktkoppel-Reegmoduul
+Name[nl]=Contactgroepadministratie
+Name[nn]=Kontaktgruppeserialisator
+Name[pa]=ਸੰਪਰਕ ਗਰੁੱਪ ਸੀਰੀਅਲਾਈਜ਼ਰ
+Name[pl]=Szeregowanie grup kontaktów
+Name[pt]=Serializador de Grupos de Contactos
+Name[pt_BR]=Serializador de grupos de contatos
+Name[ro]=Serializator grupuri de contacte
+Name[ru]=Сохранение групп контактов
+Name[sk]=Serializátor skupín kontaktov
+Name[sl]=Razvrščevalnik skupin stikov v zaporedje
+Name[sr]=Серијализатор група контаката
+Name[[email protected]]=Серијализатор група контаката
+Name[[email protected]avianlatin]=Serijalizator grupa kontakata
+Name[[email protected]]=Serijalizator grupa kontakata
+Name[sv]=Kontaktgruppserialisering
+Name[tr]=Kişi Grubu Sıralandırıcı
+Name[uk]=Серіалізатор груп контактів
+Name[x-test]=xxContact Group Serializerxx
+Name[zh_CN]=联系人分组序列转换器
+Name[zh_TW]=聯絡人群組序列器
+Comment=An Akonadi serializer plugin for contact group objects
+Comment[ar]=ملحقة سَلسَلة «أكونادي» لكائنات مجموعات المتراسلين
+Comment[bs]=Akonadi dodatak serializatora za objekte kontakt grupe
+Comment[ca]=Un connector de serialització de l'Akonadi pels objectes de grup de contactes
+Comment[[email protected]]=Un connector de serialització de l'Akonadi pels objectes de grup de contactes
+Comment[da]=Et Akonadi-plugin til serieordning af kontaktgruppeobjekter
+Comment[de]=Akonadi-Modul zur Serialisierung von Kontaktgruppen
+Comment[el]=Ένα πρόσθετο σειριακοποιητή Akonadi για αντικείμενα ομάδων επαφών
+Comment[en_GB]=An Akonadi serialiser plugin for contact group objects
+Comment[es]=Un complemento serializador de Akonadi para objetos de grupos de contacto
+Comment[et]=Akonadi kontaktirühma objektide jadastamisplugin
+Comment[fi]=Akonadi-serialisoijaliitännäinen yhteystietoryhmäobjekteille
+Comment[fr]=Un module externe Akonadi pour la sérialisation des groupes de contacts
+Comment[ga]=Breiseán srathóra Akonadi le haghaidh grúpaí teagmhálacha
+Comment[gl]=Complemento de serialización do Akonadi para obxectos de grupo de contacto
+Comment[hu]=Akonadi-modul névjegycsoportok kezeléséhez
+Comment[ia]=Un plug-in pro divulgator partial de Akonadi pro objectos de gruppo de contactos
+Comment[it]=Un'estensione di Akonadi per la serializzazione dei gruppi di contatti
+Comment[ja]=連絡先グループオブジェクトのための Akonadi シリアライザプラグイン
+Comment[kk]=Akonadi контакт тобы нысандарының тізбектеуіш плагині
+Comment[km]=កម្មវិធី​ជំនួយ​អ្នក​ដាក់លេខ​សៀរៀល Akonadi សម្រាប់​វត្ថុ​ក្រុម​ទំនាក់ទំនង
+Comment[ko]=연락처 그룹 객체를 위한 Akonadi 시리얼라이저 플러그인
+Comment[lt]=Akonadi serializatoriaus papildinys adresatų grupių objektams
+Comment[lv]=Akonadi kontaktu grupu serializēšanas spraudnis
+Comment[nb]=Et Akonadi programtillegg for serialisering av kontaktgruppe-objekter
+Comment[nds]=Akonadi-Inreegmoduul för Kontaktkoppeln
+Comment[nl]=Een administratieplug-in voor Akonadi voor contactgroepobjecten
+Comment[nn]=Eit Akonadi-serialisatortillegg for kontaktgruppeobjekt
+Comment[pa]=ਸੰਪਰਕ ਗਰੁੱਪ ਆਬਜੈਕਟਾਂ ਲਈ ਅਕੌਂਡੀ ਸੀਰੀਲਾਈਜ਼ਰ ਪਲੱਗਇਨ
+Comment[pl]=Wtyczka Akonadi do szeregowania obiektów grup kontaktów
+Comment[pt]=Um 'plugin' de serialização do Akonadi para os objectos de grupos de contactos
+Comment[pt_BR]=Um plugin de serialização do Akonadi para os objetos de grupos de contatos
+Comment[ro]=Modul de serializare Akonadi pentru obiecte „grup de contacte”
+Comment[ru]=Модуль сохранения групп контактов для Akonadi
+Comment[sk]=Plugin serializátora Akonadi pre objekty skupín kontaktov
+Comment[sl]=Akonadijev vstavek za razvrščanje predmetov skupin stikov v zaporedje
+Comment[sr]=Аконадијев прикључак серијализатора за објекте група контаката
+Comment[[email protected]]=Аконадијев прикључак серијализатора за објекте група контаката
+Comment[[email protected]]=Akonadijev priključak serijalizatora za objekte grupa kontakata
+Comment[[email protected]]=Akonadijev priključak serijalizatora za objekte grupa kontakata
+Comment[sv]=Ett insticksprogram till Akonadi för serialisering av kontaktgruppobjekt
+Comment[tr]=Kişi grubu nesneleri için bir Akonadi sıralandırıcısı
+Comment[uk]=Додаток серіалізації Akonadi для об'єктів груп контактів
+Comment[x-test]=xxAn Akonadi serializer plugin for contact group objectsxx
+Comment[zh_CN]=对联系人分组对象进行序列转换的 Akonadi 插件
+Comment[zh_TW]=聯絡人群組物件的 Akonadi 序列器外掛程式
+
+[Plugin]
+Type=application/x-vnd.kde.contactgroup
+X-Akonadi-Class=legacy;default;KContacts::ContactGroup;
+X-KDE-Library=akonadi_serializer_contactgroup
+X-KDE-ClassName=Akonadi::SerializerPluginContactGroup
diff --git a/serializers/akonadi_serializer_contactgroup.h b/serializers/akonadi_serializer_contactgroup.h
new file mode 100644
index 0000000..4820a78
--- /dev/null
+++ b/serializers/akonadi_serializer_contactgroup.h
@@ -0,0 +1,53 @@
+/*
+ Copyright (c) 2008 Kevin Krammer <[email protected]>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+ License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#ifndef __AKONADI_SERIALIZER_CONTACTGROUP_H__
+#define __AKONADI_SERIALIZER_CONTACTGROUP_H__
+
+#include <QObject>
+
+#include <AkonadiCore/differencesalgorithminterface.h>
+#include <AkonadiCore/itemserializerplugin.h>
+#include <AkonadiCore/gidextractorinterface.h>
+
+namespace Akonadi {
+/**
+ * @since 4.2
+ */
+class SerializerPluginContactGroup : public QObject
+ , public ItemSerializerPlugin
+ , public DifferencesAlgorithmInterface
+ , public GidExtractorInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(Akonadi::ItemSerializerPlugin)
+ Q_INTERFACES(Akonadi::DifferencesAlgorithmInterface)
+ Q_INTERFACES(Akonadi::GidExtractorInterface)
+ Q_PLUGIN_METADATA(IID "org.kde.akonadi.SerializerPluginContactGroup")
+public:
+ bool deserialize(Item &item, const QByteArray &label, QIODevice &data, int version) override;
+ void serialize(const Item &item, const QByteArray &label, QIODevice &data, int &version) override;
+
+ void compare(Akonadi::AbstractDifferencesReporter *reporter, const Akonadi::Item &leftItem, const Akonadi::Item &rightItem) override;
+
+ QString extractGid(const Item &item) const override;
+};
+}
+
+#endif
diff --git a/serializers/autotests/CMakeLists.txt b/serializers/autotests/CMakeLists.txt
new file mode 100644
index 0000000..c7748bf
--- /dev/null
+++ b/serializers/autotests/CMakeLists.txt
@@ -0,0 +1,6 @@
+include(ECMAddTests)
+
+ecm_add_test(addresseeserializertest.cpp ../akonadi_serializer_addressee.cpp
+ LINK_LIBRARIES KF5::AkonadiCore KF5::AkonadiContact KF5::Contacts KF5::I18n Qt5::Core Qt5::Test
+ TEST_NAME addresseeserializertest
+)
diff --git a/serializers/autotests/addresseeserializertest.cpp b/serializers/autotests/addresseeserializertest.cpp
new file mode 100644
index 0000000..cb2b97a
--- /dev/null
+++ b/serializers/autotests/addresseeserializertest.cpp
@@ -0,0 +1,48 @@
+/*
+ Copyright (c) 2013 Christian Mollekopf <[email protected]>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+ License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#include <AkonadiCore/Item>
+#include <QTest>
+#include <QObject>
+
+#include "../akonadi_serializer_addressee.h"
+
+using namespace Akonadi;
+
+class AddresseeSerializerTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void testGid()
+ {
+ const QString uid(QStringLiteral("uid"));
+ KContacts::Addressee addressee;
+ addressee.setUid(uid);
+ Akonadi::Item item;
+ item.setMimeType(addressee.mimeType());
+ item.setPayload(addressee);
+ SerializerPluginAddressee plugin;
+ const QString gid = plugin.extractGid(item);
+ QCOMPARE(gid, uid);
+ }
+};
+
+QTEST_MAIN(AddresseeSerializerTest)
+
+#include "addresseeserializertest.moc"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d635953..f74ac2f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,3 +1,4 @@
add_definitions(-DTRANSLATION_DOMAIN=\"akonadicontact5\")
add_subdirectory(contact-editor)
add_subdirectory(akonadi-contacts)
+