--- /dev/null
+/*
+ * 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 <string>
+
+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 */
protected:
ContactField &addField(contacts_record_h record,
const ContactFieldMetadata &metadata);
- void removeField(ContactField &field);
+ ContactFieldPtr removeField(ContactField &field);
private:
friend ContactField;
#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"
/* [FieldNickname] = */ true,
/* [FieldRelationship] = */ true,
/* [FieldRingtone] = */ true,
- /* [FieldGroups] = */ false
+ /* [FieldGroups] = */ true
};
}
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 {
--- /dev/null
+/*
+ * 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 <app_i18n.h>
+
+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<ContactArray>(0)) {
+ const char *name = getRecordStr(field.getRecord(), _contacts_group_relation.name);
+ if (!groups.empty()) {
+ groups.append(", ");
+ }
+ groups.append(name);
+ }
+
+ return groups;
+}
}
while (fieldIt != end()) {
- fieldIt->update(nullptr);
- ContactFieldContainer::removeField(*fieldIt);
+ auto field = ContactFieldContainer::removeField(*fieldIt);
+ field->update(nullptr);
}
while (recordIt != recordEnd) {
}
if (m_Parent) {
+ if (&field != this) {
+ change = CONTACTS_CHANGE_UPDATED;
+ }
m_Parent->onChildUpdated(*this, change);
}
}
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)