Merge lp:~renatofilho/address-book-app/fix-1419854-rtm into lp:address-book-app/rtm-14.09

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Bill Filler
Approved revision: 296
Merged at revision: 296
Proposed branch: lp:~renatofilho/address-book-app/fix-1419854-rtm
Merge into: lp:address-book-app/rtm-14.09
Diff against target: 167 lines (+46/-15)
2 files modified
src/imports/Common/ContactExporter.qml (+43/-12)
src/imports/ContactList/ContactListPage.qml (+3/-3)
To merge this branch: bzr merge lp:~renatofilho/address-book-app/fix-1419854-rtm
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+249737@code.launchpad.net

Commit message

Show a dialog with a spinner while exporting contacts.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/imports/Common/ContactExporter.qml'
--- src/imports/Common/ContactExporter.qml 2014-10-09 18:06:08 +0000
+++ src/imports/Common/ContactExporter.qml 2015-02-13 23:38:59 +0000
@@ -16,17 +16,20 @@
1616
17import QtQuick 2.217import QtQuick 2.2
18import QtContacts 5.018import QtContacts 5.0
19
20import Ubuntu.Components 1.1
19import Ubuntu.Content 1.121import Ubuntu.Content 1.1
22import Ubuntu.Components.Popups 1.0
2023
21Item {24Item {
22 id: root25 id: root
2326
24 property var contactModel27 property var contactModel
25 property var outputFile28 property bool exportToDisk: true
26 property var activeTransfer: null29 property var activeTransfer: null
2730
28 signal contactsFetched(var contacts)31 signal contactsFetched(var contacts)
29 signal done()32 signal done(string outputFile)
3033
31 function start(contacts) {34 function start(contacts) {
32 if (!contactModel) {35 if (!contactModel) {
@@ -36,24 +39,38 @@
3639
37 // skip if a query is running40 // skip if a query is running
38 if (priv.currentQueryId != -1) {41 if (priv.currentQueryId != -1) {
39 completed(0)42 console.error("Export already running")
40 return43 return
41 }44 }
4245
46 if (!priv.busyDialog) {
47 priv.busyDialog = PopupUtils.open(busyDialogComponent, root)
48 }
49
43 var ids = []50 var ids = []
44 for (var i=0; i < contacts.length; i++) {51 for (var i=0; i < contacts.length; i++) {
45 ids.push(contacts[i].contactId)52 ids.push(contacts[i].contactId)
46 }53 }
47 if (ids.length == 0) {54 if (ids.length == 0) {
48 completed(0)55 console.debug("The contact list is empty")
56 done("")
49 } else {57 } else {
50 priv.currentQueryId = contactModel.fetchContacts(ids)58 priv.currentQueryId = contactModel.fetchContacts(ids)
51 }59 }
52 }60 }
5361
62 function dismissBusyDialog()
63 {
64 if (priv.busyDialog) {
65 PopupUtils.close(priv.busyDialog)
66 priv.busyDialog = null
67 }
68 }
69
54 Item {70 Item {
55 id: priv71 id: priv
5672
73 property var busyDialog: null
57 property int currentQueryId: -174 property int currentQueryId: -1
58 readonly property var detailsBlackList: [ ContactDetail.Favorite, ContactDetail.Tag ]75 readonly property var detailsBlackList: [ ContactDetail.Favorite, ContactDetail.Tag ]
5976
@@ -83,8 +100,6 @@
83 target: root.contactModel100 target: root.contactModel
84101
85 onExportCompleted: {102 onExportCompleted: {
86 priv.currentQueryId = -1
87
88 // send contacts back to source app (pick mode)103 // send contacts back to source app (pick mode)
89 if (error === ContactModel.ExportNoError) {104 if (error === ContactModel.ExportNoError) {
90 var obj = Qt.createQmlObject("import Ubuntu.Content 1.1; ContentItem { url: '" + url + "' }", root)105 var obj = Qt.createQmlObject("import Ubuntu.Content 1.1; ContentItem { url: '" + url + "' }", root)
@@ -98,26 +113,27 @@
98 root.activeTransfer = ContentHub.ContentTransfer.Aborted113 root.activeTransfer = ContentHub.ContentTransfer.Aborted
99 console.error("Fail to export contacts:" + error)114 console.error("Fail to export contacts:" + error)
100 }115 }
101 root.done()116 root.dismissBusyDialog()
117 root.done(url)
102 }118 }
103119
104 onContactsFetched: {120 onContactsFetched: {
105 // currentQueryId == -2 is used during a fetch using "memory" manager121 // currentQueryId == -2 is used during a fetch using "memory" manager
106 if ((priv.currentQueryId == -2) || (requestId == priv.currentQueryId)) {122 if ((priv.currentQueryId == -2) || (requestId == priv.currentQueryId)) {
107 if (root.outputFile !== "") {123 if (root.exportToDisk) {
108 var contacts = []124 var contacts = []
109 // remove unnecessary info from contacts125 // remove unnecessary info from contacts
110 for(var i=0; i < fetchedContacts.length; i++) {126 for(var i=0; i < fetchedContacts.length; i++) {
111 contacts.push(priv.filterContactDetails(fetchedContacts[i]))127 contacts.push(priv.filterContactDetails(fetchedContacts[i]))
112 }128 }
113 // update outputFile with a friendly name129 // update outputFile with a friendly name
114 root.outputFile = priv.generateOutputFileName(contacts)130 var outputFile = priv.generateOutputFileName(contacts)
115131 root.contactModel.exportContacts(outputFile,
116 root.contactModel.exportContacts(root.outputFile,
117 [],132 [],
118 contacts)133 contacts)
119 }134 }
120 root.contactsFetched(fetchedContacts)135 root.contactsFetched(fetchedContacts)
136 priv.currentQueryId = -1
121 }137 }
122 }138 }
123 }139 }
@@ -128,9 +144,24 @@
128 onStateChanged: {144 onStateChanged: {
129 if (root.activeTransfer.state === ContentTransfer.Aborted) {145 if (root.activeTransfer.state === ContentTransfer.Aborted) {
130 root.activeTransfer = null146 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}
137168
=== modified file 'src/imports/ContactList/ContactListPage.qml'
--- src/imports/ContactList/ContactListPage.qml 2015-01-21 12:56:18 +0000
+++ src/imports/ContactList/ContactListPage.qml 2015-02-13 23:38:59 +0000
@@ -430,7 +430,6 @@
430 for (var i=0, iMax=items.count; i < iMax; i++) {430 for (var i=0, iMax=items.count; i < iMax; i++) {
431 contacts.push(items.get(i).model.contact)431 contacts.push(items.get(i).model.contact)
432 }432 }
433
434 contactExporter.start(contacts)433 contactExporter.start(contacts)
435 contactList.endSelection()434 contactList.endSelection()
436 }435 }
@@ -569,16 +568,17 @@
569 id: contactExporter568 id: contactExporter
570569
571 contactModel: contactList.listModel570 contactModel: contactList.listModel
572 outputFile: mainPage.pickMode ? "file:///tmp/address_book_app_export.vcf" : ""571 exportToDisk: mainPage.pickMode
573 onDone: {572 onDone: {
574 mainPage.pickMode = false573 mainPage.pickMode = false
575 mainPage.state = "default"574 mainPage.state = "default"
576 application.returnVcard(contactExporter.outputFile)575 application.returnVcard(outputFile)
577 }576 }
578577
579 onContactsFetched: {578 onContactsFetched: {
580 // Share contacts to an application chosen by the user579 // Share contacts to an application chosen by the user
581 if (!mainPage.pickMode) {580 if (!mainPage.pickMode) {
581 contactExporter.dismissBusyDialog()
582 pageStack.push(Qt.resolvedUrl("../ContactShare/ContactSharePage.qml"),582 pageStack.push(Qt.resolvedUrl("../ContactShare/ContactSharePage.qml"),
583 { contactModel: contactExporter.contactModel, contacts: contacts })583 { contactModel: contactExporter.contactModel, contacts: contacts })
584 }584 }

Subscribers

People subscribed via source and target branches