KPeople

defaultcontactmonitor.cpp
1 /*
2  Abstract class to load a monitor changes for a single contact
3  SPDX-FileCopyrightText: 2013 David Edmundson <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7 
8 #include "defaultcontactmonitor_p.h"
9 
10 DefaultContactMonitor::DefaultContactMonitor(const QString &contactUri, const AllContactsMonitorPtr &allContactsWatcher)
11  : ContactMonitor(contactUri)
12  , m_allContactsMonitor(allContactsWatcher)
13 {
14  connect(allContactsWatcher.data(), &AllContactsMonitor::contactAdded, this, &DefaultContactMonitor::onContactAdded);
15  connect(allContactsWatcher.data(), &AllContactsMonitor::contactRemoved, this, &DefaultContactMonitor::onContactRemoved);
16  connect(allContactsWatcher.data(), &AllContactsMonitor::contactChanged, this, &DefaultContactMonitor::onContactChanged);
17 
18  const QMap<QString, AbstractContact::Ptr> &contacts = m_allContactsMonitor->contacts();
19  QMap<QString, AbstractContact::Ptr>::const_iterator it = contacts.constFind(contactUri);
20  if (it != contacts.constEnd()) {
21  setContact(it.value());
22  }
23 }
24 
25 void DefaultContactMonitor::onContactAdded(const QString &id, const AbstractContact::Ptr &contact)
26 {
27  if (id == contactUri()) {
28  setContact(contact);
29  }
30 }
31 
32 void DefaultContactMonitor::onContactChanged(const QString &id, const AbstractContact::Ptr &contact)
33 {
34  if (id == contactUri()) {
35  setContact(contact);
36  }
37 }
38 
39 void DefaultContactMonitor::onContactRemoved(const QString &id)
40 {
41  if (id == contactUri()) {
42  setContact(AbstractContact::Ptr());
43  }
44 }
void contactChanged(const QString &contactUri, const KPeople::AbstractContact::Ptr &contact)
DataSources should emit this whenever a known contact changes.
QString contactUri() const
The ID of the contact being loaded.
T * data() const const
void contactRemoved(const QString &contactUri)
DataSources should emit this whenever a contact is removed and they are no longer able to supply up-t...
AbstractContact::Ptr contact() const
The currently loaded information on this contact.
void contactAdded(const QString &contactUri, const KPeople::AbstractContact::Ptr &contact)
DataSources should emit this whenever a contact is added.
void setContact(const AbstractContact::Ptr &contact)
Sets or updates the contact and emits contactChanged Subclasses should call this when data is loaded ...
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jan 27 2022 22:42:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.