~phablet-team/address-book-app/rtm-14.09

« back to all changes in this revision

Viewing changes to src/imports/Common/ContactExporter.qml

  • Committer: CI Train Bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2015-02-14 00:56:49 UTC
  • mfrom: (295.1.1 fix-1419854-rtm)
  • Revision ID: ci-train-bot@canonical.com-20150214005649-3ozbfx9ipnr1ohxb
Show a dialog with a spinner while exporting contacts. Fixes: #1419854

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import QtQuick 2.2
18
18
import QtContacts 5.0
 
19
 
 
20
import Ubuntu.Components 1.1
19
21
import Ubuntu.Content 1.1
 
22
import Ubuntu.Components.Popups 1.0
20
23
 
21
24
Item {
22
25
    id: root
23
26
 
24
27
    property var contactModel
25
 
    property var outputFile
 
28
    property bool exportToDisk: true
26
29
    property var activeTransfer: null
27
30
 
28
31
    signal contactsFetched(var contacts)
29
 
    signal done()
 
32
    signal done(string outputFile)
30
33
 
31
34
    function start(contacts) {
32
35
        if (!contactModel) {
36
39
 
37
40
        // skip if a query is running
38
41
        if (priv.currentQueryId != -1) {
39
 
            completed(0)
 
42
            console.error("Export already running")
40
43
            return
41
44
        }
42
45
 
 
46
        if (!priv.busyDialog) {
 
47
            priv.busyDialog = PopupUtils.open(busyDialogComponent, root)
 
48
        }
 
49
 
43
50
        var ids = []
44
51
        for (var i=0; i < contacts.length; i++) {
45
52
            ids.push(contacts[i].contactId)
46
53
        }
47
54
        if (ids.length == 0) {
48
 
            completed(0)
 
55
            console.debug("The contact list is empty")
 
56
            done("")
49
57
        } else {
50
58
            priv.currentQueryId = contactModel.fetchContacts(ids)
51
59
        }
52
60
    }
53
61
 
 
62
    function dismissBusyDialog()
 
63
    {
 
64
        if (priv.busyDialog) {
 
65
            PopupUtils.close(priv.busyDialog)
 
66
            priv.busyDialog = null
 
67
        }
 
68
    }
 
69
 
54
70
    Item {
55
71
        id: priv
56
72
 
 
73
        property var busyDialog: null
57
74
        property int currentQueryId: -1
58
75
        readonly property var detailsBlackList: [ ContactDetail.Favorite, ContactDetail.Tag ]
59
76
 
83
100
            target: root.contactModel
84
101
 
85
102
            onExportCompleted: {
86
 
                priv.currentQueryId = -1
87
 
 
88
103
                // send contacts back to source app (pick mode)
89
104
                if (error === ContactModel.ExportNoError) {
90
105
                    var obj = Qt.createQmlObject("import Ubuntu.Content 1.1;  ContentItem { url: '" + url + "' }", root)
98
113
                    root.activeTransfer = ContentHub.ContentTransfer.Aborted
99
114
                    console.error("Fail to export contacts:" + error)
100
115
                }
101
 
                root.done()
 
116
                root.dismissBusyDialog()
 
117
                root.done(url)
102
118
            }
103
119
 
104
120
            onContactsFetched: {
105
121
                // currentQueryId == -2 is used during a fetch using "memory" manager
106
122
                if ((priv.currentQueryId == -2) || (requestId == priv.currentQueryId)) {
107
 
                    if (root.outputFile !== "") {
 
123
                    if (root.exportToDisk) {
108
124
                        var contacts = []
109
125
                        // remove unnecessary info from contacts
110
126
                        for(var i=0; i < fetchedContacts.length; i++) {
111
127
                            contacts.push(priv.filterContactDetails(fetchedContacts[i]))
112
128
                        }
113
129
                        // update outputFile with a friendly name
114
 
                        root.outputFile = priv.generateOutputFileName(contacts)
115
 
 
116
 
                        root.contactModel.exportContacts(root.outputFile,
 
130
                        var outputFile = priv.generateOutputFileName(contacts)
 
131
                        root.contactModel.exportContacts(outputFile,
117
132
                                                         [],
118
133
                                                         contacts)
119
134
                    }
120
135
                    root.contactsFetched(fetchedContacts)
 
136
                    priv.currentQueryId = -1
121
137
                }
122
138
            }
123
139
        }
128
144
            onStateChanged: {
129
145
                if (root.activeTransfer.state === ContentTransfer.Aborted) {
130
146
                    root.activeTransfer = null
131
 
                    root.done()
 
147
                    root.done("")
132
148
                }
133
149
            }
134
150
        }
135
151
    }
 
152
 
 
153
    Component {
 
154
        id: busyDialogComponent
 
155
 
 
156
        Dialog {
 
157
            title: i18n.tr("Exporting contacts...")
 
158
 
 
159
            ActivityIndicator {
 
160
                id: activity
 
161
 
 
162
                anchors.horizontalCenter: parent.horizontalCenter
 
163
                running: true
 
164
            }
 
165
        }
 
166
    }
136
167
}