From 246138505cedc96dbcc2a1c6067befa1b4410b6a Mon Sep 17 00:00:00 2001
From: Sergey Chupligin <neochapay@gmail.com>
Date: Wed, 4 Mar 2020 11:48:42 +0300
Subject: [PATCH] [packaging] Drop old api

---
 rpm/qtcontacts-sqlite-qt5.spec | 20 ++-----------
 src/engine/contactid.cpp       | 51 ----------------------------------
 src/engine/contactid_p.h       | 14 ----------
 src/engine/contactreader.cpp   | 14 ----------
 src/engine/contactsengine.cpp  | 13 ---------
 src/engine/contactsengine.h    |  6 +---
 src/engine/contactsplugin.cpp  | 13 ---------
 src/engine/contactwriter.cpp   | 18 +-----------
 8 files changed, 4 insertions(+), 145 deletions(-)

diff --git a/rpm/qtcontacts-sqlite-qt5.spec b/rpm/qtcontacts-sqlite-qt5.spec
index 8bbb896..18949ed 100644
--- a/rpm/qtcontacts-sqlite-qt5.spec
+++ b/rpm/qtcontacts-sqlite-qt5.spec
@@ -1,5 +1,3 @@
-%define qtpim_verion %(rpm -q --qf "%{VERS""ION}\n" qt5-qtpim-contacts | tr --delete .  | cut -f1 -d"+" | cut -c1-3)
-
 Name: qtcontacts-sqlite-qt5
 Version: 0.2.36
 Release: 0
@@ -11,7 +9,7 @@ Source0: %{name}-%{version}.tar.gz
 BuildRequires: pkgconfig(Qt5Core)
 BuildRequires: pkgconfig(Qt5Sql)
 BuildRequires: pkgconfig(Qt5DBus)
-BuildRequires: pkgconfig(Qt5Contacts)
+BuildRequires: qt5-qtpim-contacts-devel >= 5.9.0
 BuildRequires: pkgconfig(mlite5)
 Requires: qt5-plugin-sqldriver-sqlite
 
@@ -22,20 +20,6 @@ Requires: qt5-plugin-sqldriver-sqlite
 %defattr(-,root,root,-)
 %{_libdir}/qt5/plugins/contacts/*.so*
 
-#%package tests
-#Summary:    Unit tests for qtcontacts-sqlite-qt5
-#Group:      System/Libraries
-#BuildRequires:  pkgconfig(Qt5Test)
-#Requires:   %{name} = %{version}-%{release}
-
-#%description tests
-#This package contains unit tests for the qtcontacts-sqlite-qt5 library.
-
-#%files tests
-#%defattr(-,root,root,-)
-#/opt/tests/qtcontacts-sqlite-qt5/*
-#%{_libdir}/qtcontacts-sqlite-qt5/libtestdlgg.so
-
 %package extensions
 Summary:    QtContacts extension headers for qtcontacts-sqlite-qt5
 Group:      Development/Libraries
@@ -54,7 +38,7 @@ This package contains extension headers for the qtcontacts-sqlite-qt5 library.
 %setup -q -n %{name}-%{version}
 
 %build
-%qmake5 "VERSION=%{version}" QTPIM_VERSION=%{qtpim_verion}
+%qmake5 "VERSION=%{version}"
 make %{?_smp_mflags}
 
 %install
diff --git a/src/engine/contactid.cpp b/src/engine/contactid.cpp
index 47025e8..8944d2b 100644
--- a/src/engine/contactid.cpp
+++ b/src/engine/contactid.cpp
@@ -72,13 +72,8 @@ QContactId ContactId::apiId(const QContact &contact)
 
 QContactId ContactId::apiId(quint32 dbId)
 {
-#if QTPIM_VERSION < 59
-    ContactId *eid = new ContactId(dbId);
-    return QContactId(eid);
-#else
     return QContactId(QContactManager::buildUri(default_uri, QMap<QString, QString>()),
                           dbIdToLocalId(dbId));
-#endif
 }
 
 
@@ -89,15 +84,7 @@ quint32 ContactId::databaseId(const QContact &contact)
 
 quint32 ContactId::databaseId(const QContactId &apiId)
 {
-#if QTPIM_VERSION < 59
-    if (const QContactEngineId *eid = QContactManagerEngine::engineId(apiId)) {
-        const ContactId *iid = static_cast<const ContactId*>(eid);
-        return iid->m_databaseId;
-    }
-    return 0;
-#else
     return dbIdFromLocalId(apiId.localId());
-#endif
 }
 
 
@@ -108,46 +95,8 @@ const QContactId &ContactId::contactId(const QContactId &apiId)
 
 QContactId ContactId::fromString(const QString &s)
 {
-#if QTPIM_VERSION < 59
-    return apiId(dbIdFromString(s));
-#else
     return apiId(dbIdFromLocalId(s.toUtf8()));
-#endif
-}
-
-#if QTPIM_VERSION < 59
-ContactId::ContactId(quint32 dbId)
-    : QContactEngineId()
-    , m_databaseId(dbId)
-{
-}
-
-ContactId::ContactId(const QString &s)
-    : QContactEngineId()
-    , m_databaseId(dbIdFromString(s))
-{
-}
-
-bool ContactId::isEqualTo(const QContactEngineId *other) const
-{
-    return m_databaseId == static_cast<const ContactId*>(other)->m_databaseId;
-}
-
-bool ContactId::isLessThan(const QContactEngineId *other) const
-{
-    return m_databaseId < static_cast<const ContactId*>(other)->m_databaseId;
-}
-
-QString ContactId::managerUri() const
-{
-    return QContactManager::buildUri(default_uri, QMap<QString, QString>());
-}
-
-QContactEngineId* ContactId::clone() const
-{
-    return new ContactId(m_databaseId);
 }
-#endif
 
 QString ContactId::toString() const
 {
diff --git a/src/engine/contactid_p.h b/src/engine/contactid_p.h
index 3cd708f..7903185 100644
--- a/src/engine/contactid_p.h
+++ b/src/engine/contactid_p.h
@@ -36,19 +36,11 @@
 #include <QContactId>
 #include <QContact>
 
-#if QTPIM_VERSION < 59
-#include <QContactEngineId>
-#else
 #include <QSharedDataPointer>
-#endif
 
 QTCONTACTS_USE_NAMESPACE
 
-#if QTPIM_VERSION < 59
-class ContactId : public QContactEngineId
-#else
 class ContactId : public QSharedData
-#endif
 {
 public:
     static QContactId apiId(const QContact &contact);
@@ -72,12 +64,6 @@ public:
     ContactId(const QString &s);
 
     QString managerUri() const;
-#if QTPIM_VERSION < 59
-    // implementing QContactEngineId:
-    bool isEqualTo(const QContactEngineId *other) const;
-    bool isLessThan(const QContactEngineId *other) const;
-    QContactEngineId* clone() const;
-#endif
     QString toString() const;
 
 #ifndef QT_NO_DEBUG_STREAM
diff --git a/src/engine/contactreader.cpp b/src/engine/contactreader.cpp
index 2f17bda..6d24213 100644
--- a/src/engine/contactreader.cpp
+++ b/src/engine/contactreader.cpp
@@ -658,15 +658,9 @@ static QContactRelationship makeRelationship(const QString &type, quint32 firstI
 {
     QContactRelationship relationship;
     relationship.setRelationshipType(type);
-#if QTPIM_VERSION < 59
-    QContact first, second;
-    first.setId(ContactId::apiId(firstId));
-    second.setId(ContactId::apiId(secondId));
-#else
     QContactId first, second;
     first = QContactId::fromString(QString::number(firstId));
     second = QContactId::fromString(QString::number(secondId));
-#endif
     relationship.setFirst(first);
     relationship.setSecond(second);
 
@@ -1232,11 +1226,7 @@ static QString buildWhere(const QContactIdFilter &filter, ContactsDatabase &db,
 
 static QString buildWhere(const QContactRelationshipFilter &filter, QVariantList *bindings, bool *failed)
 {
-#if QTPIM_VERSION < 59
-    QContactId rci = filter.relatedContact().id();
-#else
     QContactId rci = filter.relatedContactId();
-#endif
 
     QContactRelationship::Role rcr = filter.relatedContactRole();
     QString rt = filter.relationshipType();
@@ -2184,9 +2174,6 @@ QContactManager::Error ContactReader::queryContacts(
         QContactGender gender;
         // Gender is an enum in qtpim
         QString genderText = contactQuery.value(col++).toString();
-#if QTPIM_VERSION < 59
-        gender.setGender(static_cast<QContactGender::GenderField>(genderText.toInt()));
-#else
         if(genderText == "Male") {
             gender.setGender(QContactGender::GenderType::GenderMale);
         } else if (genderText == "Female") {
@@ -2194,7 +2181,6 @@ QContactManager::Error ContactReader::queryContacts(
         } else {
             gender.setGender(QContactGender::GenderType::GenderUnspecified);
         }
-#endif
         contact.saveDetail(&gender);
 
         QContactFavorite favorite;
diff --git a/src/engine/contactsengine.cpp b/src/engine/contactsengine.cpp
index 301ace8..0d1fe4c 100644
--- a/src/engine/contactsengine.cpp
+++ b/src/engine/contactsengine.cpp
@@ -466,13 +466,8 @@ public:
     RelationshipFetchJob(QContactRelationshipFetchRequest *request)
         : TemplateJob(request)
         , m_type(request->relationshipType())
-#if QTPIM_VERSION < 59
-        , m_first(request->first().id())
-        , m_second(request->second().id())
-#else
         , m_first(request->first().managerUri(), request->first().localId())
         , m_second(request->second().managerUri(), request->second().localId())
-#endif
     {
     }
 
@@ -1409,21 +1404,13 @@ void ContactsEngine::_q_contactsAdded(const QVector<quint32> &contactIds)
 
 void ContactsEngine::_q_contactsChanged(const QVector<quint32> &contactIds)
 {
-#if QTPIM_VERSION < 59
-    emit contactsChanged(idList(contactIds));
-#else
     emit contactsChanged(idList(contactIds), detalId());
-#endif
 }
 
 void ContactsEngine::_q_contactsPresenceChanged(const QVector<quint32> &contactIds)
 {
     if (m_mergePresenceChanges) {
-#if QTPIM_VERSION < 59
-        emit contactsChanged(idList(contactIds));
-#else
         emit contactsChanged(idList(contactIds), detalId());
-#endif
     } else {
         emit contactsPresenceChanged(idList(contactIds));
     }
diff --git a/src/engine/contactsengine.h b/src/engine/contactsengine.h
index 781df49..24c2659 100644
--- a/src/engine/contactsengine.h
+++ b/src/engine/contactsengine.h
@@ -118,11 +118,7 @@ public:
             const QString &relationshipType,
             const QContact &participant,
             QContactRelationship::Role role,
-            QContactManager::Error *error) const
-#if QTPIM_VERSION < 59
-    override
-#endif
-    ;
+            QContactManager::Error *error) const;
 
     bool saveRelationships(
             QList<QContactRelationship> *relationships,
diff --git a/src/engine/contactsplugin.cpp b/src/engine/contactsplugin.cpp
index d662211..f0f936a 100644
--- a/src/engine/contactsplugin.cpp
+++ b/src/engine/contactsplugin.cpp
@@ -48,10 +48,6 @@ public:
     QContactManagerEngine *engine(
             const QMap<QString, QString> &parameters, QContactManager::Error* error);
     QString managerName() const;
-#if QTPIM_VERSION < 59
-    QContactEngineId *createContactEngineId(
-            const QMap<QString, QString> &parameters, const QString &engineIdString) const;
-#endif
 };
 
 
@@ -79,13 +75,4 @@ QString ContactsFactory::managerName() const
     return QString::fromLatin1("org.nemomobile.contacts.sqlite");
 }
 
-#if QTPIM_VERSION < 59
-QContactEngineId *ContactsFactory::createContactEngineId(
-        const QMap<QString, QString> &parameters, const QString &engineIdString) const
-{
-    Q_UNUSED(parameters)
-    return new ContactId(engineIdString);
-}
-#endif
-
 #include "contactsplugin.moc"
diff --git a/src/engine/contactwriter.cpp b/src/engine/contactwriter.cpp
index f2aaef9..3e4fd66 100644
--- a/src/engine/contactwriter.cpp
+++ b/src/engine/contactwriter.cpp
@@ -413,13 +413,9 @@ QContactManager::Error ContactWriter::saveRelationships(
     for (int i = 0; i < relationships.size(); ++i) {
         const QContactRelationship &relationship = relationships.at(i);
 
-#if QTPIM_VERSION < 59
-        QContactId first(relationship.first().id());
-        QContactId second(relationship.second().id());
-#else
         QContactId first = relationship.first();
         QContactId second = relationship.second();
-#endif
+
         const quint32 firstId = ContactId::databaseId(first);
         const quint32 secondId = ContactId::databaseId(second);
         const QString &type = relationship.relationshipType();
@@ -2697,11 +2693,7 @@ static void promoteDetailsToLocal(const QList<QContactDetail> addDelta, const QL
                 localContact->saveDetail(&lts);
             } else if (type == detailType<QContactGender>()) {
                 QContactGender lg = localContact->detail<QContactGender>();
-#if QTPIM_VERSION < 59
-                lg.setGender(static_cast<QContactGender::GenderField>(original.value<int>(QContactGender::FieldGender)));
-#else
                 lg.setGender(lg.gender());
-#endif
                 localContact->saveDetail(&lg);
             } else if (type == detailType<QContactFavorite>()) {
                 QContactFavorite lf = localContact->detail<QContactFavorite>();
@@ -2743,16 +2735,8 @@ static QContactRelationship makeRelationship(const QString &type, const QContact
     QContactRelationship relationship;
     relationship.setRelationshipType(type);
 
-#if QTPIM_VERSION < 59
-    QContact first, second;
-    first.setId(firstId);
-    second.setId(secondId);
-    relationship.setFirst(first);
-    relationship.setSecond(second);
-#else
     relationship.setFirst(firstId);
     relationship.setSecond(secondId);
-#endif
 
     return relationship;
 }
-- 
2.23.0

