File indexing completed on 2024-05-05 17:32:29

0001 // SPDX-FileCopyrightText: 2020 Jonah BrĂ¼chert <jbb@kaidan.im>
0002 //
0003 // SPDX-License-Identifier: LicenseRef-KDE-Accepted-GPL
0004 
0005 #pragma once
0006 
0007 #include <KPeople/PersonsModel>
0008 #include <QObject>
0009 
0010 #include <unordered_map>
0011 
0012 #include "phonenumber.h"
0013 
0014 class ContactPhoneNumberMapper : public QObject
0015 {
0016     Q_OBJECT
0017 
0018 public:
0019     /**
0020      * @brief Returns the KPeople URI belonging to phone number,
0021      * provided a contact exists containing the phone number.
0022      * If that is not the case, an empty string is returned.
0023      * @param phone number
0024      * @return the uri belonging to the phone number
0025      */
0026     QString uriForNumber(const PhoneNumber &phoneNumber) const;
0027 
0028     static ContactPhoneNumberMapper &instance();
0029 
0030 Q_SIGNALS:
0031     /**
0032      * @brief contactsChanged is emitted whenever the ContactMapper has new data,
0033      * because a contact was added to KPeople
0034      * @param list of affected numbers
0035      */
0036     void contactsChanged(const QVector<PhoneNumber> phoneNumber);
0037 
0038 private Q_SLOTS:
0039     void processRows(const int first, const int last);
0040 
0041 private:
0042     explicit ContactPhoneNumberMapper();
0043     [[nodiscard]] std::string normalizeNumber(const std::string &numberString) const;
0044 
0045     KPeople::PersonsModel *m_model;
0046     QHash<PhoneNumber, QString> m_numberToUri;
0047     std::string m_country;
0048 };