on xenial help sign in
Fixed up connections for changes to model data. Fixes: https://bugs.launchpad.net/bugs/1253810.

Approved by PS Jenkins bot, Michał Sawicz.

commit22a15ee884ca167ce796bf95a99d8372ee598fa9 authorNick Dedekind <nicholas.dedekind@gmail.com> dateThu 12 Dec 2013, 18:05 (13 years ago) parenta0dd24c98e447c
3 files changed+217−136
plugins/Unity/Indicators/Messaging/qml/MessageMenuItemFactory.qml+79−47 plugins/Unity/Indicators/qml/IndicatorPage.qml+6−4 plugins/Unity/Indicators/qml/MenuItemFactory.qml+132−85
plugins/Unity/Indicators/Messaging/qml/MessageMenuItemFactory.qml+79−47
@@ -24,12 +24,39 @@ import Unity.Indicators 0.1 as Indicators
2424import QMenuModel 0.1 as QMenuModel
2525
2626Indicators.BaseMenuItem {
27− id: menuItem
28− property var actionsDescription: menu ? menu.ext.xCanonicalMessageActions : undefined
27+ id: messageFactoryItem
28+ property var menuModel: null
29+ property QtObject menuData: null
30+ property int menuIndex: -1
2931
30− implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
32+ property var extendedData: menuData && menuData.ext || undefined
33+ property var actionsDescription: getExtendedProperty(extendedData, "xCanonicalMessageActions", undefined)
34+
35+ onMenuModelChanged: {
36+ loadAttributes();
37+ }
38+ onMenuIndexChanged: {
39+ loadAttributes();
40+ }
3141
32− property var model: null
42+ function loadAttributes() {
43+ if (!menuModel || menuIndex == undefined) return;
44+
45+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
46+ 'x-canonical-text': 'string',
47+ 'x-canonical-message-actions': 'variant',
48+ 'icon': 'icon',
49+ 'x-canonical-app-icon': 'icon'});
50+ }
51+
52+ function getExtendedProperty(object, propertyName, defaultValue) {
53+ if (object && object.hasOwnProperty(propertyName)) {
54+ return object[propertyName];
55+ }
56+ return defaultValue;
57+ }
58+
59+ implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
3360
3461 Loader {
3562 id: contents
@@ -41,96 +68,101 @@ Indicators.BaseMenuItem {
4168 id: simpleTextMessage
4269 SimpleTextMessage {
4370 // text
44− title: menu && menu.label ? menu.label : ""
45− time: menu ? menu.ext.xCanonicalTime : 0
46− message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
71+ title: menuData && menuData.label || ""
72+ time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
73+ message: getExtendedProperty(extendedData, "xCanonicalText", "")
4774 // icons
48− avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
49− appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
75+ avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
76+ appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
5077
5178 onActivateApp: {
52− menuItem.model.activate(modelIndex, true);
79+ menuModel.activate(menuIndex, true);
5380 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
5481 }
5582 onDismiss: {
56− menuItem.model.activate(modelIndex, false);
83+ menuModel.activate(menuIndex, false);
5784 }
5885
59− menuSelected: menuItem.menuSelected
60− onSelectMenu: menuItem.selectMenu()
61− onDeselectMenu: menuItem.deselectMenu()
86+ menuSelected: messageFactoryItem.menuSelected
87+ onSelectMenu: messageFactoryItem.selectMenu()
88+ onDeselectMenu: messageFactoryItem.deselectMenu()
6289 }
6390 }
6491 Component {
6592 id: textMessage
6693 TextMessage {
94+ property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
95+
6796 property var replyAction: QMenuModel.UnityMenuAction {
68− model: menuItem.model
69− index: modelIndex
70− name: menu && actionsDescription[0].name ? actionsDescription[0].name : ""
97+ model: menuModel
98+ index: menuIndex
99+ name: getExtendedProperty(replyActionDescription, "name", "")
71100 }
72101
73102 // text
74− title: menu && menu.label ? menu.label : ""
75− time: menu ? menu.ext.xCanonicalTime : 0
76− message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
77− replyButtonText: actionsDescription && actionsDescription[0].label ? actionsDescription[0].label : "Send"
103+ title: menuData && menuData.label || ""
104+ time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
105+ message: getExtendedProperty(extendedData, "xCanonicalText", "")
106+ replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
78107 // icons
79− avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
80− appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
108+ avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
109+ appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
81110 // actions
82111 replyEnabled: replyAction.valid && replyAction.enabled
83112
84113 onActivateApp: {
85− menuItem.model.activate(modelIndex, true);
114+ menuModel.activate(menuIndex, true);
86115 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
87116 }
88117 onDismiss: {
89− menuItem.model.activate(modelIndex, false);
118+ menuModel.activate(menuIndex, false);
90119 }
91120 onReply: {
92121 replyAction.activate(value);
93122 }
94123
95− menuSelected: menuItem.menuSelected
96− onSelectMenu: menuItem.selectMenu()
97− onDeselectMenu: menuItem.deselectMenu()
124+ menuSelected: messageFactoryItem.menuSelected
125+ onSelectMenu: messageFactoryItem.selectMenu()
126+ onDeselectMenu: messageFactoryItem.deselectMenu()
98127 }
99128 }
100129 Component {
101130 id: snapDecision
102131 SnapDecision {
132+ property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
133+ property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
134+
103135 property var activateAction: QMenuModel.UnityMenuAction {
104− model: menuItem.model
105− index: modelIndex
106− name: menu && actionsDescription[0].name ? actionsDescription[0].name : ""
136+ model: menuModel
137+ index: menuIndex
138+ name: getExtendedProperty(activateActionDescription, "name", "")
107139 }
108140 property var replyAction: QMenuModel.UnityMenuAction {
109− model: menuItem.model
110− index: modelIndex
111− name: menu && actionsDescription[1].name ? actionsDescription[1].name : ""
141+ model: menuModel
142+ index: menuIndex
143+ name: getExtendedProperty(replyActionDescription, "name", "")
112144 }
113145
114146 // text
115− title: menu && menu.label ? menu.label : ""
116− time: menu ? menu.ext.xCanonicalTime : ""
117− message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
118− actionButtonText: actionsDescription && actionsDescription[0].label ? actionsDescription[0].label : "Call back"
119− replyButtonText: actionsDescription && actionsDescription[1].label ? actionsDescription[1].label : "Send"
120− replyMessages: actionsDescription && actionsDescription[1]["parameter-hint"] ? actionsDescription[1]["parameter-hint"] : ""
147+ title: menuData && menuData.label || ""
148+ time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
149+ message: getExtendedProperty(extendedData, "xCanonicalText", "")
150+ actionButtonText: getExtendedProperty(activateActionDescription, "label", "Call back")
151+ replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
152+ replyMessages: getExtendedProperty(replyActionDescription, "parameter-hint", "")
121153 // icons
122− avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
123− appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
154+ avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
155+ appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
124156 // actions
125157 activateEnabled: activateAction.valid && activateAction.enabled
126158 replyEnabled: replyAction.valid && replyAction.enabled
127159
128160 onActivateApp: {
129− menuItem.model.activate(modelIndex, true);
161+ menuModel.activate(menuIndex, true);
130162 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
131163 }
132164 onDismiss: {
133− menuItem.model.activate(modelIndex, false);
165+ menuModel.activate(menuIndex, false);
134166 }
135167 onActivate: {
136168 activateAction.activate();
@@ -139,9 +171,9 @@ Indicators.BaseMenuItem {
139171 replyAction.activate(value);
140172 }
141173
142− menuSelected: menuItem.menuSelected
143− onSelectMenu: menuItem.selectMenu()
144− onDeselectMenu: menuItem.deselectMenu()
174+ menuSelected: messageFactoryItem.menuSelected
175+ onSelectMenu: messageFactoryItem.selectMenu()
176+ onDeselectMenu: messageFactoryItem.deselectMenu()
145177 }
146178 }
147179 }
plugins/Unity/Indicators/qml/IndicatorPage.qml+6−4
@@ -144,9 +144,11 @@ IndicatorBase {
144144 item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
145145 item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
146146 }
147−
148− if (item.hasOwnProperty("menu")) {
149− item.menu = Qt.binding(function() { return model; });
147+ if (item.hasOwnProperty("menuData")) {
148+ item.menuData = Qt.binding(function() { return model; });
149+ }
150+ if (item.hasOwnProperty("menuIndex")) {
151+ item.menuIndex = Qt.binding(function() { return modelIndex; });
150152 }
151153 }
152154
@@ -172,7 +174,7 @@ IndicatorBase {
172174
173175 MenuItemFactory {
174176 id: factory
175− model: mainMenu.model
177+ menuModel: mainMenu.model ? mainMenu.model : null
176178 }
177179
178180 Components.Label {
plugins/Unity/Indicators/qml/MenuItemFactory.qml+132−85
@@ -27,7 +27,7 @@ import Ubuntu.Components 0.1
2727Item {
2828 id: menuFactory
2929
30− property var model: null
30+ property var menuModel: null
3131
3232 property var _map: {
3333 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
@@ -50,38 +50,55 @@ Item {
5050 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
5151 }
5252
53+ function getExtendedProperty(object, propertyName, defaultValue) {
54+ if (object && object.hasOwnProperty(propertyName)) {
55+ return object[propertyName];
56+ }
57+ return defaultValue;
58+ }
59+
5360 Component { id: divMenu; Indicators.DivMenuItem {} }
5461
5562 Component {
5663 id: sliderMenu;
5764 Indicators.SliderMenuItem {
58− property QtObject menu: null
65+ property QtObject menuData: null
66+ property var menuModel: menuFactory.menuModel
67+ property int menuIndex: -1
68+ property var extendedData: menuData && menuData.ext || undefined
5969
60− text: menu && menu.label ? menu.label : ""
61− icon: menu && menu.icon ? menu.icon : ""
62− minIcon: menu && menu.ext.minIcon ? menu.ext.minIcon : ""
63− maxIcon: menu && menu.ext.maxIcon ? menu.ext.maxIcon : ""
70+ text: menuData && menuData.label || ""
71+ iconSource: menuData && menuData.icon || ""
72+ minIcon: getExtendedProperty(extendedData, "minIcon", "")
73+ maxIcon: getExtendedProperty(extendedData, "maxIcon", "")
6474
65− minimumValue: menu.ext.minValue ? menu.ext.minValue : 0.0
75+ minimumValue: getExtendedProperty(extendedData, "minValue", 0.0)
6676 maximumValue: {
67− var maximum = menu.ext.maxValue ? menu.ext.maxValue : 1.0
77+ var maximum = getExtendedProperty(extendedData, "maxValue", 1.0);
6878 if (maximum <= minimumValue) {
6979 return minimumValue + 1;
7080 }
7181 return maximum;
7282 }
73− value: menu ? menu.actionState : 0.0
74− enabled: menu ? menu.sensitive : false
83+ value: menuData && menuData.actionState || 0.0
84+ enabled: menuData && menuData.sensitive || false
7585
76− Component.onCompleted: {
77− model.loadExtendedAttributes(modelIndex, {'min-value': 'double',
78− 'max-value': 'double',
79− 'min-icon': 'icon',
80− 'max-icon': 'icon'});
86+ onMenuModelChanged: {
87+ loadAttributes();
88+ }
89+ onMenuIndexChanged: {
90+ loadAttributes();
8191 }
82−
8392 onChangeState: {
84− model.changeState(modelIndex, value);
93+ menuModel.changeState(menuIndex, value);
94+ }
95+
96+ function loadAttributes() {
97+ if (!menuModel || menuIndex == undefined) return;
98+ menuModel.loadExtendedAttributes(menuIndex, {'min-value': 'double',
99+ 'max-value': 'double',
100+ 'min-icon': 'icon',
101+ 'max-icon': 'icon'});
85102 }
86103 }
87104 }
@@ -89,13 +106,15 @@ Item {
89106 Component {
90107 id: buttonMenu;
91108 Indicators.ButtonMenuItem {
92− property QtObject menu: null
109+ property QtObject menuData: null
110+ property var menuModel: menuFactory.menuModel
111+ property int menuIndex: -1
93112
94− text: menu && menu.label ? menu.label : ""
95− enabled: menu ? menu.sensitive : false
113+ text: menuData && menuData.label || ""
114+ enabled: menuData && menuData.sensitive || false
96115
97116 onActivate: {
98− model.activate(modelIndex);
117+ menuModel.activate(menuIndex);
99118 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
100119 }
101120 }
@@ -103,37 +122,40 @@ Item {
103122 Component {
104123 id: sectionMenu;
105124 Indicators.SectionMenuItem {
106− property QtObject menu: null
125+ property QtObject menuData: null
126+ property var menuIndex: undefined
107127
108− text: menu && menu.label ? menu.label : ""
128+ text: menuData && menuData.label || ""
109129 }
110130 }
111131
112132 Component {
113133 id: progressMenu;
114134 Indicators.ProgressMenuItem {
115− property QtObject menu: null
135+ property QtObject menuData: null
136+ property int menuIndex: -1
116137
117− text: menu && menu.label ? menu.label : ""
118− icon: menu ? menu.icon : ""
119− value : menu ? menu.actionState : 0.0
120− enabled: menu ? menu.sensitive : false
138+ text: menuData && menuData.label || ""
139+ iconSource: menuData && menuData.icon || ""
140+ value : menuData && menuData.actionState || 0.0
141+ enabled: menuData && menuData.sensitive || false
121142 }
122143 }
123144
124145 Component {
125146 id: standardMenu;
126147 Indicators.StandardMenuItem {
127− property QtObject menu: null
148+ property QtObject menuData: null
149+ property int menuIndex: -1
128150
129− text: menu && menu.label ? menu.label : ""
130− icon: menu && menu.icon ? menu.icon : ""
131− checkable: menu ? (menu.isCheck || menu.isRadio) : false
132− checked: checkable ? menu.isToggled : false
133− enabled: menu ? menu.sensitive : false
151+ text: menuData && menuData.label || ""
152+ iconSource: menuData && menuData.icon || ""
153+ enabled: menuData && menuData.sensitive || false
154+ checkable: menuData ? (menuData.isCheck || menuData.isRadio) : false
155+ checked: checkable ? menuData.isToggled : false
134156
135157 onActivate: {
136− model.activate(modelIndex);
158+ menuModel.activate(menuIndex);
137159 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
138160 }
139161 }
@@ -142,15 +164,16 @@ Item {
142164 Component {
143165 id: switchMenu;
144166 Indicators.SwitchMenuItem {
145− property QtObject menu: null
167+ property QtObject menuData: null
168+ property int menuIndex: -1
146169
147− text: menu && menu.label ? menu.label : ""
148− icon: menu && menu.icon ? menu.icon : ""
149− checked: menu ? menu.isToggled : false
150− enabled: menu ? menu.sensitive : false
170+ text: menuData && menuData.label || ""
171+ iconSource: menuData && menuData.icon || ""
172+ enabled: menuData && menuData.sensitive || false
173+ checked: menuData ? menuData.isToggled : false
151174
152175 onActivate: {
153− model.activate(modelIndex);
176+ menuModel.activate(menuIndex);
154177 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
155178 }
156179 }
@@ -159,13 +182,24 @@ Item {
159182 Component {
160183 id: wifiSection;
161184 Indicators.SectionMenuItem {
162− property QtObject menu: null
185+ property QtObject menuData: null
186+ property var menuModel: menuFactory.menuModel
187+ property int menuIndex: -1
188+ property var extendedData: menuData && menuData.ext || undefined
189+
190+ text: menuData && menuData.label || ""
191+ busy: getExtendedProperty(extendedData, "xCanonicalBusyAction", false)
163192
164− text: menu && menu.label ? menu.label : ""
165− busy: menu ? menu.ext.xCanonicalBusyAction : false
193+ onMenuModelChanged: {
194+ loadAttributes();
195+ }
196+ onMenuIndexChanged: {
197+ loadAttributes();
198+ }
166199
167− Component.onCompleted: {
168− model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
200+ function loadAttributes() {
201+ if (!menuModel || menuIndex == undefined) return;
202+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-busy-action': 'bool'})
169203 }
170204 }
171205 }
@@ -173,67 +207,81 @@ Item {
173207 Component {
174208 id: accessPoint;
175209 ICNetwork.AccessPoint {
176− property QtObject menu: null
210+ property QtObject menuData: null
211+ property var menuModel: menuFactory.menuModel
212+ property int menuIndex: -1
213+ property var extendedData: menuData && menuData.ext || undefined
214+
177215 property var strengthAction: QMenuModel.UnityMenuAction {
178− model: menuFactory.model ? menuFactory.model : null
179− index: modelIndex
180− name: menu ? menu.ext.xCanonicalWifiApStrengthAction : ""
216+ model: menuModel
217+ index: menuIndex
218+ name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
181219 }
182220
183− text: menu && menu.label ? menu.label : ""
184− secure: menu ? menu.ext.xCanonicalWifiApIsSecure : false
185− adHoc: menu ? menu.ext.xCanonicalWifiApIsAdhoc : false
186− checked: menu ? menu.isToggled : false
221+ text: menuData && menuData.label || ""
222+ enabled: menuData && menuData.sensitive || false
223+ secure: getExtendedProperty(extendedData, "xCanonicalWifiApIsSecure", false)
224+ adHoc: getExtendedProperty(extendedData, "xCanonicalWifiApIsAdhoc", false)
225+ checked: menuData ? menuData.isToggled : false
187226 signalStrength: strengthAction.valid ? strengthAction.state : 0
188− enabled: menu ? menu.sensitive : false
189227
190− Component.onCompleted: {
191− model.loadExtendedAttributes(modelIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
192− 'x-canonical-wifi-ap-is-secure': 'bool',
193− 'x-canonical-wifi-ap-strength-action': 'string'});
228+ onMenuModelChanged: {
229+ loadAttributes();
230+ }
231+ onMenuIndexChanged: {
232+ loadAttributes();
194233 }
195234 onActivate: {
196− model.activate(modelIndex);
235+ menuModel.activate(menuIndex);
197236 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
198237 }
238+
239+ function loadAttributes() {
240+ if (!menuModel || menuIndex == undefined) return;
241+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
242+ 'x-canonical-wifi-ap-is-secure': 'bool',
243+ 'x-canonical-wifi-ap-strength-action': 'string'});
244+ }
199245 }
200246 }
201247
202248 Component {
203249 id: messageItem
204250 ICMessaging.MessageMenuItemFactory {
205−
206− property QtObject menu: null
207− model: menuFactory.model ? menuFactory.model : null
208−
209− Component.onCompleted: {
210− model.loadExtendedAttributes(modelIndex, {'x-canonical-time': 'int64',
211− 'x-canonical-text': 'string',
212− 'x-canonical-message-actions': 'variant',
213− 'icon': 'icon',
214− 'x-canonical-app-icon': 'icon'});
215− }
251+ menuModel: menuFactory.menuModel
216252 }
217253 }
218254
219255 Component {
220256 id: groupedMessage
221257 ICMessaging.GroupedMessage {
222− property QtObject menu: null
223−
224− title: menu && menu.label ? menu.label : ""
225− count: menu && menu.actionState[0] ? menu.actionState[0] : "0"
226− appIcon: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_app.svg"
227−
228− Component.onCompleted: {
229− model.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
258+ property QtObject menuData: null
259+ property var menuModel: menuFactory.menuModel
260+ property int menuIndex: -1
261+ property var extendedData: menuData && menuData.ext || undefined
262+
263+ title: menuData && menuData.label || ""
264+ appIcon: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_app.svg")
265+ count: menuData && menuData.actionState.length > 0 ? menuData.actionState[0] : "0"
266+ enabled: menuData && menuData.sensitive || false
267+
268+ onMenuModelChanged: {
269+ loadAttributes();
270+ }
271+ onMenuIndexChanged: {
272+ loadAttributes();
230273 }
231274 onActivateApp: {
232− model.activate(modelIndex, true);
275+ menuModel.activate(menuIndex, true);
233276 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
234277 }
235278 onDismiss: {
236− model.activate(modelIndex, false);
279+ menuModel.activate(menuIndex, false);
280+ }
281+
282+ function loadAttributes() {
283+ if (!menuModel || menuIndex == undefined) return;
284+ menuModel.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
237285 }
238286 }
239287 }
@@ -244,10 +292,9 @@ Item {
244292 if (component !== undefined) {
245293 return component;
246294 }
247− } else {
248− if (modelData.isSeparator) {
249− return divMenu;
250− }
295+ }
296+ if (modelData.isSeparator) {
297+ return divMenu;
251298 }
252299 return standardMenu;
253300 }