Debian Codegraph @

src/imports/Lomiri/Contacts/VCardParser.qml

raw
1 /*
2 * Copyright (C) 2014 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 QtObject {
21 id: root
22
23 property string vCardUrl
24 property alias contacts: contactsModel.contacts
25 property var _model
26
27 signal vcardParsed(int error)
28
29 function clearModel()
30 {
31 if (contactsModel.contacts.length === 0)
32 return;
33
34 var ids = []
35 for(var i=0, iMax=contactsModel.contacts.length; i < iMax; i++) {
36 ids.push(contactsModel.contacts[i].contactId)
37 }
38 contactsModel.removeContacts(ids)
39 }
40
41
42
43 _model: ContactModel {
44 id: contactsModel
45
46 manager: "memory"
47
48 onImportCompleted: vcardParsed(error)
49 }
50
51 onVCardUrlChanged: {
52 if (vCardUrl.length > 0) {
53 clearModel()
54 contactsModel.importContacts(vCardUrl)
55 }
56 }
57 }