From e52a02bb77c5292a016d2c14e0730d44d25d4000 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 10 Mar 2017 21:50:08 +0100 Subject: Simple peoplemodel for addressbook Currently just queries for a flat list of contacts. Read-only. --- framework/domain/contactcontroller.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'framework/domain/contactcontroller.cpp') diff --git a/framework/domain/contactcontroller.cpp b/framework/domain/contactcontroller.cpp index 0be90e77..a1a805c9 100644 --- a/framework/domain/contactcontroller.cpp +++ b/framework/domain/contactcontroller.cpp @@ -18,16 +18,17 @@ #include "contactcontroller.h" +#include + ContactController::ContactController() : Kube::Controller(), action_save{new Kube::ControllerAction{this, &ContactController::save}} { - loadContact("test"); updateSaveAction(); } void ContactController::save() { - //TODO + qWarning() << "Saving is not implemented"; } void ContactController::updateSaveAction() @@ -37,23 +38,31 @@ void ContactController::updateSaveAction() void ContactController::loadContact(const QVariant &contact) { - setName("Anita Rosenzweig"); - m_emails << "rosenzweig@kolabnow.com" << "wolfi@kolabnow.com"; + if (auto c = contact.value()) { + setName(c->getFn()); + QStringList emails; + for (const auto &e : c->getEmails()) { + emails << e; + } + setEmails(emails); + } } -void ContactController::removeEmail(const QString &email) +QVariant ContactController::contact() const { - m_emails.removeOne(email); - emit emailsChanged(); + return QVariant{}; } -void ContactController::addEmail(const QString &email) +void ContactController::removeEmail(const QString &email) { - m_emails << email; - emit emailsChanged(); + auto emails = getEmails(); + emails.removeAll(email); + setEmails(emails); } -QStringList ContactController::emails() const +void ContactController::addEmail(const QString &email) { - return m_emails; + auto emails = getEmails(); + emails.append(email); + setEmails(emails); } -- cgit v1.2.3