| 1 |
/* |
| 2 |
* Copyright (C) 2012-2015 Canonical, Ltd. |
| 3 |
* |
| 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. |
| 7 |
* |
| 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. |
| 12 |
* |
| 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/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.4 |
| 18 |
import QtContacts 5.0 |
| 19 |
|
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import Lomiri.Components.ListItems 1.3 |
| 22 |
|
| 23 |
import Lomiri.Contacts 0.1 |
| 24 |
import Lomiri.AddressBook.Base 0.1 |
| 25 |
|
| 26 |
ContactDetailBase { |
| 27 |
id: root |
| 28 |
|
| •29 |
property bool isNewContact: contact && contact.contactId.length === 0 |
| 30 |
property real myHeight: label.height + units.gu(6) + addressBooksSelector.childrenRect.height |
| 31 |
|
| 32 |
property var contactModel: null |
| 33 |
property string selectedCollectionId: Contacts.defaultCollectionId |
| 34 |
|
| 35 |
signal changed() |
| 36 |
|
| 37 |
function save() { |
| •38 |
|
| 39 |
// only changes the collection for new contacts |
| 40 |
if (!isNewContact) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| •44 |
root.contact.collectionId = selectedCollectionId |
| 45 |
} |
| 46 |
|
| 47 |
function getSelectedSource() { |
| 48 |
if (sources.model.count <= 0) |
| 49 |
return -1 |
| 50 |
|
| 51 |
var selectedSourceId = sources.model.get(sources.selectedIndex).sourceId |
| 52 |
if (selectedSourceId) { |
| 53 |
return selectedSourceId |
| 54 |
} else { |
| 55 |
return -1 |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
function contactIsReadOnly(contact) { |
| 60 |
var sources = sourceModel.contacts |
| 61 |
var contactSyncTarget = contact.syncTarget.value(SyncTarget.SyncTarget + 1) |
| 62 |
|
| 63 |
for (var i = 0; i < writableSources.count; i++) { |
| 64 |
var source = writableSources.get(i) |
| 65 |
if (source.sourceId === contactSyncTarget) { |
| 66 |
return false |
| 67 |
} |
| 68 |
} |
| 69 |
return true |
| 70 |
} |
| 71 |
|
| 72 |
detail: root.contact ? contact.detail(ContactDetail.SyncTarget) : null |
| •73 |
implicitHeight: isNewContact ? myHeight : 0 |
| 74 |
|
| •75 |
visible: height > 0 |
| 76 |
|
| 77 |
ContactDetailTitle { |
| 78 |
id: label |
| 79 |
title: i18n.dtr("lomiri-addressbook-app", "Addressbook") |
| 80 |
} |
| 81 |
|
| •82 |
AddressBooksSelector { |
| 83 |
id: addressBooksSelector |
| •84 |
currentCollectionId: Contacts.defaultCollectionId |
| 85 |
contactModel: root.contactModel |
| 86 |
anchors { |
| 87 |
left: parent.left |
| 88 |
leftMargin: units.gu(2) |
| 89 |
top: label.bottom |
| 90 |
topMargin: units.gu(2) |
| 91 |
right: parent.right |
| 92 |
rightMargin: units.gu(2) |
| 93 |
bottom: parent.bottom |
| 94 |
bottomMargin: units.gu(2) |
| 95 |
} |
| 96 |
|
| •97 |
onAddressBookChanged: { |
| 98 |
root.selectedCollectionId = collectionId |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
} |
| 104 |
|