File indexing completed on 2024-05-12 15:44:26

0001 /*
0002     SPDX-FileCopyrightText: 2013 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef ALLCONTACTSMONITOR_H
0008 #define ALLCONTACTSMONITOR_H
0009 
0010 #include <QObject>
0011 #include <QSharedPointer>
0012 
0013 #include <kpeoplebackend/abstractcontact.h>
0014 #include <kpeoplebackend/kpeoplebackend_export.h>
0015 
0016 namespace KPeople
0017 {
0018 class AllContactsMonitorPrivate;
0019 
0020 /**
0021  * This class should be subclassed by each datasource and return a list of
0022  * all contacts that the datasource knows about.
0023  *
0024  * Subclasses are expected to be asynchronous
0025  *
0026  * @since 5.8
0027  */
0028 class KPEOPLEBACKEND_EXPORT AllContactsMonitor : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032     explicit AllContactsMonitor(); // TODO make protected? this isn't useful unless subclassed
0033     ~AllContactsMonitor() override;
0034 
0035     /**
0036      * Returns all currently loaded contacts
0037      */
0038     virtual QMap<QString, AbstractContact::Ptr> contacts();
0039 
0040     // TODO redo as a state enum - InitialLoad, Fail, Loaded
0041     bool isInitialFetchComplete() const;
0042 
0043     bool initialFetchSuccess() const;
0044 
0045 Q_SIGNALS:
0046     /**
0047      * DataSources should emit this whenever a known contact changes
0048      */
0049     void contactChanged(const QString &contactUri, const KPeople::AbstractContact::Ptr &contact);
0050 
0051     /**
0052      * DataSources should emit this whenever a contact is added
0053      */
0054     void contactAdded(const QString &contactUri, const KPeople::AbstractContact::Ptr &contact);
0055 
0056     /**
0057      * DataSources should emit this whenever a contact is removed and they are no longer able to supply up-to-date data on a contact
0058      */
0059     void contactRemoved(const QString &contactUri);
0060 
0061     /**
0062      * Notifies that the DataSource has completed it's initial fetch.
0063      *
0064      * @warning DataSources should use emitInitialFetchComplete() instead of emitting this signal
0065      * directly.
0066      *
0067      * @param success True when the fetch was successful, False when an error occurred.
0068      */
0069     void initialFetchComplete(bool success);
0070 
0071 protected Q_SLOTS:
0072     /**
0073      * DataSources should call this once they have finished initial retrieval of all contacts from their
0074      * storage.
0075      *
0076      * This will emit initialFetchComplete() signal
0077      *
0078      * @p success Whether the fetch was successful.
0079      */
0080     void emitInitialFetchComplete(bool success);
0081 
0082 private:
0083     Q_DISABLE_COPY(AllContactsMonitor)
0084     Q_DECLARE_PRIVATE(AllContactsMonitor)
0085     AllContactsMonitorPrivate *d_ptr;
0086 };
0087 
0088 }
0089 typedef QSharedPointer<KPeople::AllContactsMonitor> AllContactsMonitorPtr;
0090 
0091 #endif // ALLCONTACTSMONITOR_H