/* * Copyright (C) 2015 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import QtQuick 2.4 import QtContacts 5.0 import Lomiri.Components 1.3 import Lomiri.Components.ListItems 1.3 import Lomiri.Contacts 0.1 import Lomiri.AddressBook.Base 0.1 Empty { id: root property var contactModel: null signal changed() function save() { var changed = false var selectedSource = getSelectedSource() if (!selectedSource) { return } var details = selectedSource.details(ContactDetail.ExtendedDetail) for(var d in details) { if (details[d].name === "IS-PRIMARY") { if (!details[d].data) { details[d].data = true changed = true break } } } if (changed) { sourceModel.saveContact(selectedSource) } } function getSelectedSource() { if (sources.model.count <= 0) return -1 return sources.model.get(sources.selectedIndex).source } height: sources.currentlyExpanded ? sources.containerHeight + units.gu(6) + label.height : sources.itemHeight + units.gu(6) + label.height ListModel { id: writableSources function populate() { clear() var collections = contactModel.collections; for(var i = 0 ; i < collections.length ; ++i) { var col = collections[i] const isReadOnly = col.extendedMetaData("ReadOnly") === true const isAggregate = col.collectionId === Contacts.aggregateCollectionId const accountId = col.extendedMetaData("AccountId") console.log(col.name, isReadOnly, isAggregate, accountId) if (!isReadOnly && !isAggregate) { var item = { 'collectionId': col.collectionId, 'name': col.name, 'description': col.description, 'isLocal': col.extendedMetaData("AccountId") === 0 } append(item) } } } } Label { id: label text: i18n.tr("Default address book") anchors { left: parent.left top: parent.top right: parent.right margins: units.gu(2) } height: units.gu(4) } OptionSelector { id: sources property bool _notify: true model: writableSources delegate: OptionSelectorDelegate { text: { if (isLocal) { return i18n.dtr("lomiri-addressbook-app", "Personal - %1").arg(name) } else { return name } } subText: description height: units.gu(4) } containerHeight: sources.model && sources.model.count > 4 ? itemHeight * 4 : sources.model ? itemHeight * sources.model.count : 0 onDelegateClicked: { const ab = model.get(index) console.log('changed default address book to', ab.name) Contacts.defaultCollectionId = ab.collectionId } Component.onCompleted: { writableSources.populate() for( var i = 0; i < writableSources.count; i++ ) { console.log(writableSources.get(i).collectionId, Contacts.defaultCollectionId) if (writableSources.get(i).collectionId === Contacts.defaultCollectionId) { selectedIndex = i break } } } } }