From 2fc4f15ee069734df5891ba53c3a1bf922ab2ff9 Mon Sep 17 00:00:00 2001 From: Olivier SOLDANO <olivier.soldano@savoirfairelinux.com> Date: Wed, 2 Aug 2017 11:50:43 -0400 Subject: [PATCH] add utility functions adding and checking contacts add the contact addition wrapping from ConfigurationManager. add hasContact to check if a contact method is part account contacts. Change-Id: I10cd59ebdba74dba5098d794810f29542b70daa4 --- src/account.cpp | 34 +++++++++++++++++++++++++++++++++- src/account.h | 4 ++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/account.cpp b/src/account.cpp index f00c2c01..a9231b39 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -1455,13 +1455,45 @@ bool Account::removeContact(const ContactMethod* c) bool Account::removeContact( Certificate* c ) { if ((!c) || (c->remoteId().isEmpty())) - return false; + return false; ConfigurationManager::instance().removeContact(id(), c->remoteId(), false); + return true; +} + +bool Account::addContact( const URI& uri ) +{ + if (uri.isEmpty()) + return false; + + ConfigurationManager::instance().addContact(id(), uri); + + return true; +} + +bool Account::addContact(const ContactMethod* c) +{ + if (!c) + return false; + + return addContact(c->uri()); +} + +bool Account::addContact( Certificate* c ) +{ + if ((!c) || (c->remoteId().isEmpty())) + return false; + ConfigurationManager::instance().addContact(id(), c->remoteId()); return true; } +bool Account::hasContact(ContactMethod* c ) +{ + auto contacts = getContacts(); + return contacts.indexOf(c) != -1; +} + uint Account::internalId() const { return d_ptr->m_InternalId; diff --git a/src/account.h b/src/account.h index 77ba1821..4f79ad5d 100644 --- a/src/account.h +++ b/src/account.h @@ -485,6 +485,10 @@ class LIB_EXPORT Account : public ItemBase { Q_INVOKABLE bool removeContact(Certificate* c); Q_INVOKABLE bool removeContact(const ContactMethod* c); Q_INVOKABLE bool removeContact(const URI& uri); + Q_INVOKABLE bool addContact(Certificate* c); + Q_INVOKABLE bool addContact(const ContactMethod* c); + Q_INVOKABLE bool addContact(const URI& uri); + Q_INVOKABLE bool hasContact(ContactMethod* c); Q_INVOKABLE QString accountDetail(const QString& param) const; //Setters -- GitLab