~renatofilho/address-book-app/new-designer-contact-list

« back to all changes in this revision

Viewing changes to src/imports/ContactShare/ContactSharePage.qml

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2014-06-17 00:41:33 UTC
  • mfrom: (169.9.9 staging)
  • Revision ID: renato.filho@canonical.com-20140617004133-m4lm6hbiiyd1zx0w
Staging merged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012-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.2
 
18
import QtContacts 5.0
 
19
import Ubuntu.Components 0.1
 
20
import Ubuntu.Content 0.1 as ContentHub
 
21
 
 
22
Page {
 
23
    id: picker
 
24
 
 
25
    property var contactModel
 
26
    property var contact
 
27
    property var curTransfer
 
28
 
 
29
    ContentHub.ContentPeerPicker {
 
30
        visible: true
 
31
        anchors.fill: parent
 
32
        contentType: ContentHub.ContentType.Contacts
 
33
        handler: ContentHub.ContentHandler.Share
 
34
 
 
35
        onPeerSelected: {
 
36
            picker.curTransfer = peer.request();
 
37
            if (picker.curTransfer.state === ContentHub.ContentTransfer.InProgress) {
 
38
                var vCardUrl = "file:///tmp/vcard_" + encodeURIComponent(contact.contactId) + ".vcf"
 
39
                picker.contactModel.exportContacts(vCardUrl, [], [picker.contact])
 
40
            }
 
41
        }
 
42
 
 
43
        onCancelPressed: pageStack.pop()
 
44
    }
 
45
 
 
46
    Connections {
 
47
        target: picker.contactModel
 
48
        onExportCompleted: {
 
49
            if (picker.curTransfer && (picker.curTransfer.state === ContentHub.ContentTransfer.InProgress)) {
 
50
                if (error === ContactModel.ExportNoError) {
 
51
                    var obj = Qt.createQmlObject("import Ubuntu.Content 0.1;  ContentItem { url: '" + url + "' }", picker)
 
52
                    picker.curTransfer.items = [ obj ]
 
53
                    picker.curTransfer.state = ContentHub.ContentTransfer.Charged
 
54
                } else {
 
55
                    picker.curTransfer = ContentHub.ContentTransfer.Aborted
 
56
                    console.error("Fail to export contact:" + error)
 
57
                }
 
58
            }
 
59
            pageStack.pop()
 
60
        }
 
61
    }
 
62
}