Merge lp:~renatofilho/address-book-app/sort-sources into lp:address-book-app

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Merged at revision: 520
Proposed branch: lp:~renatofilho/address-book-app/sort-sources
Merge into: lp:address-book-app
Diff against target: 163 lines (+73/-40)
1 file modified
src/imports/Ubuntu/AddressBook/ContactEditor/ContactDetailSyncTargetEditor.qml (+73/-40)
To merge this branch: bzr merge lp:~renatofilho/address-book-app/sort-sources
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu Phablet Team Pending
Review via email: mp+276667@code.launchpad.net

Commit message

Sort source list for Contact editor page.
Select default source on page creation.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/imports/Ubuntu/AddressBook/ContactEditor/ContactDetailSyncTargetEditor.qml'
--- src/imports/Ubuntu/AddressBook/ContactEditor/ContactDetailSyncTargetEditor.qml 2015-10-26 13:18:11 +0000
+++ src/imports/Ubuntu/AddressBook/ContactEditor/ContactDetailSyncTargetEditor.qml 2015-11-04 15:41:52 +0000
@@ -27,6 +27,9 @@
27 id: root27 id: root
2828
29 property alias active: sourceModel.autoUpdate29 property alias active: sourceModel.autoUpdate
30 property bool isNewContact: contact && contact.contactId === "qtcontacts:::"
31 property real myHeight: sources.currentlyExpanded ? sources.containerHeight + units.gu(6) + label.height : sources.itemHeight + units.gu(6) + label.height
32
30 signal changed()33 signal changed()
3134
32 function save() {35 function save() {
@@ -49,9 +52,9 @@
49 if (sources.model.count <= 0)52 if (sources.model.count <= 0)
50 return -153 return -1
5154
52 var selectedContact = sources.model.get(sources.selectedIndex).contact55 var selectedSourceId = sources.model.get(sources.selectedIndex).sourceId
53 if (selectedContact) {56 if (selectedSourceId) {
54 return selectedContact.guid.guid57 return selectedSourceId
55 } else {58 } else {
56 return -159 return -1
57 }60 }
@@ -69,23 +72,6 @@
69 return true72 return true
70 }73 }
7174
72 function targetIsReadOnly(target) {
73 if (!target)
74 return true
75
76 var details = target.details(ContactDetail.ExtendedDetail)
77 for(var d in details) {
78 if ((details[d].name === "READ-ONLY") && (details[d].data === true)) {
79 return true
80 }
81 }
82
83 return false
84 }
85
86 property bool isNewContact: contact && contact.contactId === "qtcontacts:::"
87 property real myHeight: sources.currentlyExpanded ? sources.containerHeight + units.gu(6) + label.height : sources.itemHeight + units.gu(6) + label.height
88
89 detail: root.contact ? contact.detail(ContactDetail.SyncTarget) : null75 detail: root.contact ? contact.detail(ContactDetail.SyncTarget) : null
90 implicitHeight: root.isNewContact && sources.model && (sources.model.count > 1) ? myHeight : 076 implicitHeight: root.isNewContact && sources.model && (sources.model.count > 1) ? myHeight : 0
9177
@@ -111,6 +97,27 @@
111 ListModel {97 ListModel {
112 id: writableSources98 id: writableSources
11399
100 function getSourceMetaData(contact) {
101 var metaData = {'read-only' : false,
102 'account-provider': '',
103 'account-id': 0,
104 'is-primary': false}
105
106 var details = contact.details(ContactDetail.ExtendedDetail)
107 for(var d in details) {
108 if (details[d].name === "READ-ONLY") {
109 metaData['read-only'] = details[d].data
110 } else if (details[d].name === "PROVIDER") {
111 metaData['account-provider'] = details[d].data
112 } else if (details[d].name === "APPLICATION-ID") {
113 metaData['account-id'] = details[d].data
114 } else if (details[d].name === "IS-PRIMARY") {
115 metaData['is-primary'] = details[d].data
116 }
117 }
118 return metaData
119 }
120
114 function reload() {121 function reload() {
115 clear()122 clear()
116123
@@ -120,11 +127,47 @@
120 return127 return
121 }128 }
122129
130 var data = []
123 for(var i in contacts) {131 for(var i in contacts) {
124 if (!targetIsReadOnly(contacts[i])) {132 var sourceMetaData = getSourceMetaData(contacts[i])
125 append({'contact': contacts[i]})133 if (!sourceMetaData['readOnly']) {
126 }134 data.push({'sourceId': contacts[i].guid.guid,
127 }135 'sourceName': contacts[i].displayLabel.label,
136 'accountId': sourceMetaData['account-id'],
137 'accountProvider': sourceMetaData['account-provider'],
138 'readOnly': sourceMetaData['read-only'],
139 'isPrimary': sourceMetaData['is-primary']
140 })
141 }
142 }
143
144 data.sort(function(a, b) {
145 var valA = a.accountId
146 var valB = b.accountId
147 if (a.accountId == b.accountId) {
148 valA = a.sourceName
149 valB = b.sourceName
150 }
151
152 if (valA == valB) {
153 return 0
154 } else if (valA < valB) {
155 return -1
156 } else {
157 return 1
158 }
159 })
160
161 var primaryIndex = 0
162 for (var i in data) {
163 if (data[i].isPrimary) {
164 primaryIndex = i
165 }
166 append(data[i])
167 }
168
169 // select primary account
170 sources.selectedIndex = primaryIndex
128 }171 }
129 }172 }
130173
@@ -164,27 +207,17 @@
164207
165 delegate: OptionSelectorDelegate {208 delegate: OptionSelectorDelegate {
166 text: {209 text: {
167 if ((contact.guid.guid != "system-address-book") &&210 if ((sourceId != "system-address-book") &&
168 (iconSource == "image://theme/address-book-app-symbolic")) {211 (iconSource == "image://theme/address-book-app-symbolic")) {
169 return i18n.dtr("address-book-app", "Personal - %1").arg(contact.displayLabel.label)212 return i18n.dtr("address-book-app", "Personal - %1").arg(sourceName)
170 } else {213 } else {
171 return contact.displayLabel.label214 return sourceName
172 }215 }
173 }216 }
174 constrainImage: true217 constrainImage: true
175 iconSource: {218 iconSource: accountProvider == "" ?
176 var details = contact.details(ContactDetail.ExtendedDetail)219 "image://theme/address-book-app-symbolic" :
177 for(var i in details) {220 "image://theme/online-accounts-%1".arg(accountProvider)
178 if (details[i].name === "PROVIDER") {
179 if (details[i].data === "") {
180 return "image://theme/address-book-app-symbolic"
181 } else {
182 return "image://theme/online-accounts-%1".arg(details[i].data)
183 }
184 }
185 }
186 return "image://theme/address-book-app-symbolic"
187 }
188 height: units.gu(4)221 height: units.gu(4)
189 }222 }
190223

Subscribers

People subscribed via source and target branches