8#include "kpeople_debug.h"
9#include "metacontact_p.h"
15class MetaContactData :
public QSharedData
19 QStringList contactUris;
20 AbstractContact::List contacts;
21 AbstractContact::Ptr personAddressee;
31 MetaContactProxy(
const AbstractContact::List &contacts)
32 : m_contacts(contacts)
36 QVariant customProperty(
const QString &key)
const override
40 for (
const AbstractContact::Ptr &contact : std::as_const(m_contacts)) {
41 QVariant val = contact->customProperty(key);
50 for (
const AbstractContact::Ptr &contact : std::as_const(m_contacts)) {
51 QVariant val = contact->customProperty(key);
60 const AbstractContact::List m_contacts;
63using namespace KPeople;
65MetaContact::MetaContact()
66 : d(new MetaContactData)
72 : d(new MetaContactData)
74 d->personUri = personUri;
78 insertContactInternal(it.key(), it.value());
84MetaContact::MetaContact(
const QString &contactUri,
const AbstractContact::Ptr &contact)
85 : d(new MetaContactData)
87 d->personUri = contactUri;
88 insertContactInternal(contactUri, contact);
92MetaContact::MetaContact(
const MetaContact &other)
97MetaContact &MetaContact::operator=(
const MetaContact &other)
106MetaContact::~MetaContact()
115bool MetaContact::isValid()
const
122 return d->contactUris;
125AbstractContact::Ptr MetaContact::contact(
const QString &contactUri)
127 int index = d->contactUris.
indexOf(contactUri);
129 return d->contacts[index];
131 return AbstractContact::Ptr();
135AbstractContact::List MetaContact::contacts()
const
140const AbstractContact::Ptr &MetaContact::personAddressee()
const
142 Q_ASSERT(d->personAddressee);
143 return d->personAddressee;
146int MetaContact::insertContact(
const QString &contactUri,
const AbstractContact::Ptr &contact)
148 int index = insertContactInternal(contactUri, contact);
152 qCWarning(KPEOPLE_LOG) <<
"Inserting an already-present contact" << contactUri;
157int MetaContact::insertContactInternal(
const QString &contactUri,
const AbstractContact::Ptr &contact)
159 if (d->contactUris.contains(contactUri)) {
164 int index = d->contacts.size();
165 d->contacts.append(contact);
166 d->contactUris.append(contactUri);
171int MetaContact::updateContact(
const QString &contactUri,
const AbstractContact::Ptr &contact)
173 const int index = d->contactUris.indexOf(contactUri);
174 Q_ASSERT(index < 0 || d->contacts[index] == contact);
176 qCWarning(KPEOPLE_LOG) <<
"contact not part of the metacontact";
181int MetaContact::removeContact(
const QString &contactUri)
183 const int index = d->contactUris.indexOf(contactUri);
185 d->contacts.removeAt(index);
186 d->contactUris.removeAt(index);
192void MetaContact::reload()
197 d->personAddressee = (d->contacts.size() == 1) ? d->contacts.first() : AbstractContact::Ptr(
new MetaContactProxy(d->contacts));
198 Q_ASSERT(d->personAddressee);
const QList< QKeySequence > & reload()
const_iterator constBegin() const const
const_iterator constEnd() const const
bool isEmpty() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
bool canConvert() const const
bool isNull() const const
bool isValid() const const
QList< QVariant > toList() const const