From: Eugene Kurzberg Date: Fri, 15 Jul 2016 07:34:46 +0000 (+0300) Subject: TizenRefApp-6681 Implement Group field in the Contact Details X-Git-Tag: submit/tizen/20160826.132643~1^2~65 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffd7148e0f2a6adae0ead4f861667649d16a08bd;p=profile%2Fmobile%2Fapps%2Fnative%2Fphone-contacts.git TizenRefApp-6681 Implement Group field in the Contact Details Change-Id: I1c76d62053a91654ba5d71055d102d395d09d331 Signed-off-by: Eugene Kurzberg --- diff --git a/lib-contacts/inc/Contacts/Details/GroupsFieldItem.h b/lib-contacts/inc/Contacts/Details/GroupsFieldItem.h new file mode 100644 index 0000000..bc095ed --- /dev/null +++ b/lib-contacts/inc/Contacts/Details/GroupsFieldItem.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef CONTACTS_DETAILS_GROUPS_FIELD_ITEM_H +#define CONTACTS_DETAILS_GROUPS_FIELD_ITEM_H + +#include "Contacts/Details/FieldItem.h" +#include + +namespace Contacts +{ + namespace Details + { + /** + * @brief Genlist item representing Groups field. + */ + class GroupsFieldItem : public FieldItem + { + public: + using FieldItem::FieldItem; + + protected: + /** + * @see GenlistItem::getText() + */ + virtual char *getText(Evas_Object *parent, const char *part) override; + + private: + std::string formatGroups() const; + }; + } +} + +#endif /* CONTACTS_DETAILS_GROUPS_FIELD_ITEM_H */ diff --git a/lib-contacts/inc/Contacts/Model/ContactFieldContainer.h b/lib-contacts/inc/Contacts/Model/ContactFieldContainer.h index bb42a37..f75d5f7 100644 --- a/lib-contacts/inc/Contacts/Model/ContactFieldContainer.h +++ b/lib-contacts/inc/Contacts/Model/ContactFieldContainer.h @@ -80,7 +80,7 @@ namespace Contacts protected: ContactField &addField(contacts_record_h record, const ContactFieldMetadata &metadata); - void removeField(ContactField &field); + ContactFieldPtr removeField(ContactField &field); private: friend ContactField; diff --git a/lib-contacts/src/Contacts/Details/DetailsView.cpp b/lib-contacts/src/Contacts/Details/DetailsView.cpp index 5adfcf1..56d7fcf 100644 --- a/lib-contacts/src/Contacts/Details/DetailsView.cpp +++ b/lib-contacts/src/Contacts/Details/DetailsView.cpp @@ -17,6 +17,7 @@ #include "Contacts/Details/DetailsView.h" #include "Contacts/Details/BasicInfoItem.h" +#include "Contacts/Details/GroupsFieldItem.h" #include "Contacts/Details/MultilineFieldItem.h" #include "Contacts/Details/RingtoneFieldItem.h" #include "Contacts/Details/TypedActionFieldItem.h" @@ -63,7 +64,7 @@ namespace /* [FieldNickname] = */ true, /* [FieldRelationship] = */ true, /* [FieldRingtone] = */ true, - /* [FieldGroups] = */ false + /* [FieldGroups] = */ true }; } @@ -194,6 +195,8 @@ FieldItem *DetailsView::createFieldItem(ContactObject &field) item = new FieldItem(field); } else if (fieldId == FieldRingtone) { item = new RingtoneFieldItem(field); + } else if (fieldId == FieldGroups) { + item = new GroupsFieldItem(field); } else if (field.getInterfaces() & InterfaceTypedObject) { item = new TypedFieldItem(field); } else { diff --git a/lib-contacts/src/Contacts/Details/GroupsFieldItem.cpp b/lib-contacts/src/Contacts/Details/GroupsFieldItem.cpp new file mode 100644 index 0000000..a0cdf63 --- /dev/null +++ b/lib-contacts/src/Contacts/Details/GroupsFieldItem.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "Contacts/Details/GroupsFieldItem.h" +#include "Contacts/Model/ContactArray.h" +#include "Contacts/Model/ContactObject.h" +#include "Common/Database/RecordUtils.h" + +#include + +using namespace Common::Database; +using namespace Contacts::Details; +using namespace Contacts::Model; + +char *GroupsFieldItem::getText(Evas_Object *parent, const char *part) +{ + if (strcmp(part, "elm.text") == 0) { + std::string groups = formatGroups(); + return strdup(!groups.empty() ? groups.c_str() : _("IDS_PB_BODY_NOT_ASSIGNED")); + } + + return FieldItem::getText(parent, part); +} + +std::string GroupsFieldItem::formatGroups() const +{ + std::string groups; + for (auto &&field : *getObject().getField(0)) { + const char *name = getRecordStr(field.getRecord(), _contacts_group_relation.name); + if (!groups.empty()) { + groups.append(", "); + } + groups.append(name); + } + + return groups; +} diff --git a/lib-contacts/src/Contacts/Model/ContactArray.cpp b/lib-contacts/src/Contacts/Model/ContactArray.cpp index 88fed54..3b42980 100644 --- a/lib-contacts/src/Contacts/Model/ContactArray.cpp +++ b/lib-contacts/src/Contacts/Model/ContactArray.cpp @@ -95,8 +95,8 @@ void ContactArray::onUpdate(contacts_record_h record) } while (fieldIt != end()) { - fieldIt->update(nullptr); - ContactFieldContainer::removeField(*fieldIt); + auto field = ContactFieldContainer::removeField(*fieldIt); + field->update(nullptr); } while (recordIt != recordEnd) { diff --git a/lib-contacts/src/Contacts/Model/ContactField.cpp b/lib-contacts/src/Contacts/Model/ContactField.cpp index a381fec..57915f4 100644 --- a/lib-contacts/src/Contacts/Model/ContactField.cpp +++ b/lib-contacts/src/Contacts/Model/ContactField.cpp @@ -126,6 +126,9 @@ void ContactField::onUpdated(ContactField &field, contacts_changed_e change) } if (m_Parent) { + if (&field != this) { + change = CONTACTS_CHANGE_UPDATED; + } m_Parent->onChildUpdated(*this, change); } } diff --git a/lib-contacts/src/Contacts/Model/ContactFieldContainer.cpp b/lib-contacts/src/Contacts/Model/ContactFieldContainer.cpp index d5703d8..a5aa2e4 100644 --- a/lib-contacts/src/Contacts/Model/ContactFieldContainer.cpp +++ b/lib-contacts/src/Contacts/Model/ContactFieldContainer.cpp @@ -81,17 +81,24 @@ ContactField &ContactFieldContainer::addField(contacts_record_h record, return *m_Fields.back(); } -void ContactFieldContainer::removeField(ContactField &field) +ContactFieldPtr ContactFieldContainer::removeField(ContactField &field) { - auto comp = [&field](ContactFieldPtr &ptr) { - return ptr.get() == &field; - }; - if (field.isFilled()) { onChildFilled(field, false); } - m_Fields.erase(std::remove_if(m_Fields.begin(), m_Fields.end(), comp), m_Fields.end()); + auto it = std::find_if(m_Fields.begin(), m_Fields.end(), + [&field](ContactFieldPtr &fieldPtr) { + return fieldPtr.get() == &field; + }); + + if (it != m_Fields.end()) { + auto fieldPtr = std::move(*it); + m_Fields.erase(it); + return fieldPtr; + } + + return nullptr; } void ContactFieldContainer::onChildUpdated(ContactField &field, contacts_changed_e change)