2
* Copyright (C) 2012-2013 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
import Ubuntu.Components 0.1
19
import QtContacts 5.0 as QtContacts
21
ContactDetailGroupBase {
24
property string defaultIcon : "artwork:/protocol-other.png"
25
property ListModel typeModel
27
function getType(detail) {
29
return typeModel.get(typeModel.getTypeIndex(detail))
35
function updateDetail(detail, index) {
37
return typeModel.updateDetail(detail, index)
42
typeModel: ListModel {
46
function getTypeIndex(detail) {
48
for (var i = 0; i < detail.contexts.length; i++) {
49
context = detail.contexts[i];
53
// not all details have subTypes
54
if (detail.subTypes) {
55
for (var i = 0; i < detail.subTypes.length; i++) {
56
subType = detail.subTypes[i];
60
if (context === QtContacts.ContactDetail.ContextHome) {
62
} else if (context === QtContacts.ContactDetail.ContextWork) {
64
} else if (subType === QtContacts.ContactDetail.ContextOther) {
71
function isNotAModelValue(value) {
72
for(var i=0; i < count; i++) {
73
if (value === get(i).value) {
80
function compareList(listA, listB) {
81
if (!listA && !listB) {
85
if (!listA || !listB) {
89
if (listA.length != listB.length) {
92
for(var i=0; i < listA.length; i++) {
93
if (listA[i] != listB[i]) {
100
function updateDetail(detail, index) {
101
var modelData = get(index)
106
// WORKAROUND: in EDS empty context is equal to QtContacts.ContactDetail.ContextOther
107
// this will avoid call contact update if the context has not changed
108
if ((detail.contexts.length === 0) && (modelData.value === QtContacts.ContactDetail.ContextOther)) {
112
var newContext = detail.contexts.filter(isNotAModelValue)
113
newContext.push(modelData.value)
114
if (!compareList(newContext, detail.contexts)) {
115
detail.contexts = newContext
121
Component.onCompleted: {
122
append({"value": QtContacts.ContactDetail.ContextHome, "label": i18n.tr("Home"), icon: null})
123
append({"value": QtContacts.ContactDetail.ContextWork, "label": i18n.tr("Work"), icon: null})
124
append({"value": QtContacts.ContactDetail.ContextOther, "label": i18n.tr("Other"), icon: null})