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
1=== modified file 'src/imports/Ubuntu/AddressBook/ContactEditor/ContactDetailSyncTargetEditor.qml'
2--- src/imports/Ubuntu/AddressBook/ContactEditor/ContactDetailSyncTargetEditor.qml 2015-10-26 13:18:11 +0000
3+++ src/imports/Ubuntu/AddressBook/ContactEditor/ContactDetailSyncTargetEditor.qml 2015-11-04 15:41:52 +0000
4@@ -27,6 +27,9 @@
5 id: root
6
7 property alias active: sourceModel.autoUpdate
8+ property bool isNewContact: contact && contact.contactId === "qtcontacts:::"
9+ property real myHeight: sources.currentlyExpanded ? sources.containerHeight + units.gu(6) + label.height : sources.itemHeight + units.gu(6) + label.height
10+
11 signal changed()
12
13 function save() {
14@@ -49,9 +52,9 @@
15 if (sources.model.count <= 0)
16 return -1
17
18- var selectedContact = sources.model.get(sources.selectedIndex).contact
19- if (selectedContact) {
20- return selectedContact.guid.guid
21+ var selectedSourceId = sources.model.get(sources.selectedIndex).sourceId
22+ if (selectedSourceId) {
23+ return selectedSourceId
24 } else {
25 return -1
26 }
27@@ -69,23 +72,6 @@
28 return true
29 }
30
31- function targetIsReadOnly(target) {
32- if (!target)
33- return true
34-
35- var details = target.details(ContactDetail.ExtendedDetail)
36- for(var d in details) {
37- if ((details[d].name === "READ-ONLY") && (details[d].data === true)) {
38- return true
39- }
40- }
41-
42- return false
43- }
44-
45- property bool isNewContact: contact && contact.contactId === "qtcontacts:::"
46- property real myHeight: sources.currentlyExpanded ? sources.containerHeight + units.gu(6) + label.height : sources.itemHeight + units.gu(6) + label.height
47-
48 detail: root.contact ? contact.detail(ContactDetail.SyncTarget) : null
49 implicitHeight: root.isNewContact && sources.model && (sources.model.count > 1) ? myHeight : 0
50
51@@ -111,6 +97,27 @@
52 ListModel {
53 id: writableSources
54
55+ function getSourceMetaData(contact) {
56+ var metaData = {'read-only' : false,
57+ 'account-provider': '',
58+ 'account-id': 0,
59+ 'is-primary': false}
60+
61+ var details = contact.details(ContactDetail.ExtendedDetail)
62+ for(var d in details) {
63+ if (details[d].name === "READ-ONLY") {
64+ metaData['read-only'] = details[d].data
65+ } else if (details[d].name === "PROVIDER") {
66+ metaData['account-provider'] = details[d].data
67+ } else if (details[d].name === "APPLICATION-ID") {
68+ metaData['account-id'] = details[d].data
69+ } else if (details[d].name === "IS-PRIMARY") {
70+ metaData['is-primary'] = details[d].data
71+ }
72+ }
73+ return metaData
74+ }
75+
76 function reload() {
77 clear()
78
79@@ -120,11 +127,47 @@
80 return
81 }
82
83+ var data = []
84 for(var i in contacts) {
85- if (!targetIsReadOnly(contacts[i])) {
86- append({'contact': contacts[i]})
87- }
88- }
89+ var sourceMetaData = getSourceMetaData(contacts[i])
90+ if (!sourceMetaData['readOnly']) {
91+ data.push({'sourceId': contacts[i].guid.guid,
92+ 'sourceName': contacts[i].displayLabel.label,
93+ 'accountId': sourceMetaData['account-id'],
94+ 'accountProvider': sourceMetaData['account-provider'],
95+ 'readOnly': sourceMetaData['read-only'],
96+ 'isPrimary': sourceMetaData['is-primary']
97+ })
98+ }
99+ }
100+
101+ data.sort(function(a, b) {
102+ var valA = a.accountId
103+ var valB = b.accountId
104+ if (a.accountId == b.accountId) {
105+ valA = a.sourceName
106+ valB = b.sourceName
107+ }
108+
109+ if (valA == valB) {
110+ return 0
111+ } else if (valA < valB) {
112+ return -1
113+ } else {
114+ return 1
115+ }
116+ })
117+
118+ var primaryIndex = 0
119+ for (var i in data) {
120+ if (data[i].isPrimary) {
121+ primaryIndex = i
122+ }
123+ append(data[i])
124+ }
125+
126+ // select primary account
127+ sources.selectedIndex = primaryIndex
128 }
129 }
130
131@@ -164,27 +207,17 @@
132
133 delegate: OptionSelectorDelegate {
134 text: {
135- if ((contact.guid.guid != "system-address-book") &&
136+ if ((sourceId != "system-address-book") &&
137 (iconSource == "image://theme/address-book-app-symbolic")) {
138- return i18n.dtr("address-book-app", "Personal - %1").arg(contact.displayLabel.label)
139+ return i18n.dtr("address-book-app", "Personal - %1").arg(sourceName)
140 } else {
141- return contact.displayLabel.label
142+ return sourceName
143 }
144 }
145 constrainImage: true
146- iconSource: {
147- var details = contact.details(ContactDetail.ExtendedDetail)
148- for(var i in details) {
149- if (details[i].name === "PROVIDER") {
150- if (details[i].data === "") {
151- return "image://theme/address-book-app-symbolic"
152- } else {
153- return "image://theme/online-accounts-%1".arg(details[i].data)
154- }
155- }
156- }
157- return "image://theme/address-book-app-symbolic"
158- }
159+ iconSource: accountProvider == "" ?
160+ "image://theme/address-book-app-symbolic" :
161+ "image://theme/online-accounts-%1".arg(accountProvider)
162 height: units.gu(4)
163 }
164

Subscribers

People subscribed via source and target branches