on xenial help sign in
Fixed up MenuItem names & bindings
commitb6d73b677b8900a7d57af7111ee7c670fa5b9606 authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 11 Dec 2013, 16:08 (13 years ago) parent98a3fda
3 files changed+187−126
plugins/Unity/Indicators/Messaging/qml/MessageMenuItemFactory.qml+63−45 plugins/Unity/Indicators/qml/IndicatorPage.qml+6−3 plugins/Unity/Indicators/qml/MenuItemFactory.qml+118−78
plugins/Unity/Indicators/Messaging/qml/MessageMenuItemFactory.qml+63−45
@@ -24,12 +24,32 @@ 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 menuItem: null
30+ property var menuIndex: undefined
2931
30− implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
32+ property var extAttrib: menuItem && menuItem.ext ? menuItem.ext : undefined
33+ property var actionsDescription: extAttrib && extAttrib.hasOwnProperty("xCanonicalMessageActions") ? extAttrib.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+ implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
3353
3454 Loader {
3555 id: contents
@@ -46,13 +66,6 @@ Indicators.BaseMenuItem {
4666 when: (contents.status == Loader.Ready)
4767 }
4868
49− Binding {
50− target: contents.item
51− property: "menu"
52− value: menu
53− when: (contents.status == Loader.Ready)
54− }
55−
5669 Connections {
5770 target: contents.item ? contents.item : null
5871 onSelectMenu: selectMenu()
@@ -63,46 +76,48 @@ Indicators.BaseMenuItem {
6376 id: simpleTextMessage
6477 SimpleTextMessage {
6578 // text
66− title: menu && menu.label ? menu.label : ""
67− time: menu ? menu.ext.xCanonicalTime : 0
68− message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
79+ title: menuItem && menuItem.label ? menuItem.label : ""
80+ time: extAttrib && extAttrib.hasOwnProperty("xCanonicalTime") ? extAttrib.xCanonicalTime : 0
81+ message: extAttrib && extAttrib.hasOwnProperty("xCanonicalText") ? extAttrib.xCanonicalText : ""
6982 // icons
70− avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
71− appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
83+ avatar: extAttrib && extAttrib.hasOwnProperty("icon") ? extAttrib.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
84+ appIcon: extAttrib && extAttrib.hasOwnProperty("xCanonicalAppIcon") ? extAttrib.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
7285
7386 onActivateApp: {
74− menuItem.model.activate(modelIndex, true);
87+ menuModel.activate(menuIndex, true);
7588 }
7689 onDismiss: {
77− menuItem.model.activate(modelIndex, false);
90+ menuModel.activate(menuIndex, false);
7891 }
7992 }
8093 }
8194 Component {
8295 id: textMessage
8396 TextMessage {
97+ property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
98+
8499 property var replyAction: QMenuModel.UnityMenuAction {
85− model: menuItem.model
86− index: modelIndex
87− name: menu && actionsDescription[0].name ? actionsDescription[0].name : ""
100+ model: menuModel
101+ index: menuIndex
102+ name: replyActionDescription !== undefined ? replyActionDescription.name : ""
88103 }
89104
90105 // text
91− title: menu && menu.label ? menu.label : ""
92− time: menu ? menu.ext.xCanonicalTime : 0
93− message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
94− replyButtonText: actionsDescription && actionsDescription[0].label ? actionsDescription[0].label : "Send"
106+ title: menuItem && menuItem.label ? menuItem.label : ""
107+ time: extAttrib && extAttrib.hasOwnProperty("xCanonicalTime") ? extAttrib.xCanonicalTime : 0
108+ message: extAttrib && extAttrib.hasOwnProperty("xCanonicalText") ? extAttrib.xCanonicalText : ""
109+ replyButtonText: replyActionDescription !== undefined && replyActionDescription.hasOwnProperty("label") ? replyActionDescription.label : "Send"
95110 // icons
96− avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
97− appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
111+ avatar: extAttrib && extAttrib.hasOwnProperty("icon") ? extAttrib.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
112+ appIcon: extAttrib && extAttrib.hasOwnProperty("xCanonicalAppIcon") ? extAttrib.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
98113 // actions
99114 replyEnabled: replyAction.valid && replyAction.enabled
100115
101116 onActivateApp: {
102− menuItem.model.activate(modelIndex, true);
117+ menuModel.activate(menuIndex, true);
103118 }
104119 onDismiss: {
105− menuItem.model.activate(modelIndex, false);
120+ menuModel.activate(menuIndex, false);
106121 }
107122 onReply: {
108123 replyAction.activate(value);
@@ -112,36 +127,39 @@ Indicators.BaseMenuItem {
112127 Component {
113128 id: snapDecision
114129 SnapDecision {
130+ property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
131+ property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
132+
115133 property var activateAction: QMenuModel.UnityMenuAction {
116− model: menuItem.model
117− index: modelIndex
118− name: menu && actionsDescription[0].name ? actionsDescription[0].name : ""
134+ model: menuModel
135+ index: menuIndex
136+ name: activateActionDescription !== undefined ? activateActionDescription.name : ""
119137 }
120138 property var replyAction: QMenuModel.UnityMenuAction {
121− model: menuItem.model
122− index: modelIndex
123− name: menu && actionsDescription[1].name ? actionsDescription[1].name : ""
139+ model: menuModel
140+ index: menuIndex
141+ name: replyActionDescription !== undefined ? replyActionDescription.name : ""
124142 }
125143
126144 // text
127− title: menu && menu.label ? menu.label : ""
128− time: menu ? menu.ext.xCanonicalTime : ""
129− message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
130− actionButtonText: actionsDescription && actionsDescription[0].label ? actionsDescription[0].label : "Call back"
131− replyButtonText: actionsDescription && actionsDescription[1].label ? actionsDescription[1].label : "Send"
132− replyMessages: actionsDescription && actionsDescription[1]["parameter-hint"] ? actionsDescription[1]["parameter-hint"] : ""
145+ title: menuItem && menuItem.label ? menuItem.label : ""
146+ time: extAttrib && extAttrib.hasOwnProperty("xCanonicalTime") ? extAttrib.xCanonicalTime : ""
147+ message: extAttrib && extAttrib.hasOwnProperty("xCanonicalText") ? extAttrib.xCanonicalText : ""
148+ actionButtonText: activateActionDescription !== undefined && activateActionDescription.hasOwnProperty("label") ? activateActionDescription.label : "Call back"
149+ replyButtonText: replyActionDescription !== undefined && replyActionDescription.hasOwnProperty("label") ? replyActionDescription.label : "Send"
150+ replyMessages: replyActionDescription !== undefined && replyActionDescription.hasOwnProperty("parameter-hint") ? replyActionDescription["parameter-hint"] : ""
133151 // icons
134− avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
135− appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
152+ avatar: extAttrib && extAttrib.hasOwnProperty("icon") ? extAttrib.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
153+ appIcon: extAttrib && extAttrib.hasOwnProperty("xCanonicalAppIcon") ? extAttrib.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
136154 // actions
137155 activateEnabled: activateAction.valid && activateAction.enabled
138156 replyEnabled: replyAction.valid && replyAction.enabled
139157
140158 onActivateApp: {
141− menuItem.model.activate(modelIndex, true);
159+ menuModel.activate(menuIndex, true);
142160 }
143161 onDismiss: {
144− menuItem.model.activate(modelIndex, false);
162+ menuModel.activate(menuIndex, false);
145163 }
146164 onActivate: {
147165 activateAction.activate();
plugins/Unity/Indicators/qml/IndicatorPage.qml+6−3
@@ -144,8 +144,11 @@ IndicatorBase {
144144 item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
145145 item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
146146 }
147− if (item.hasOwnProperty("menu")) {
148− item.menu = Qt.binding(function() { return model; });
147+ if (item.hasOwnProperty("menuItem")) {
148+ item.menuItem = Qt.binding(function() { return model; });
149+ }
150+ if (item.hasOwnProperty("menuIndex")) {
151+ item.menuIndex = Qt.binding(function() { return modelIndex; });
149152 }
150153 }
151154
@@ -160,7 +163,7 @@ IndicatorBase {
160163
161164 MenuItemFactory {
162165 id: factory
163− model: mainMenu.model
166+ menuModel: mainMenu.model
164167 }
165168
166169 Components.Label {
plugins/Unity/Indicators/qml/MenuItemFactory.qml+118−78
@@ -26,7 +26,7 @@ import QMenuModel 0.1 as QMenuModel
2626Item {
2727 id: menuFactory
2828
29− property var model: null
29+ property var menuModel: null
3030
3131 property var _map: {
3232 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
@@ -54,84 +54,99 @@ Item {
5454 Component {
5555 id: sliderMenu;
5656 Indicators.SliderMenuItem {
57− property QtObject menu: null
57+ property QtObject menuItem: null
58+ property var menuModel: menuFactory.menuModel
59+ property var menuIndex: undefined
60+ property var extAttrib: menuItem && menuItem.ext ? menuItem.ext : undefined
5861
59− text: menu && menu.label ? menu.label : ""
60− icon: menu && menu.icon ? menu.icon : ""
61− minIcon: menu && menu.ext.minIcon ? menu.ext.minIcon : ""
62− maxIcon: menu && menu.ext.maxIcon ? menu.ext.maxIcon : ""
62+ text: menuItem && menuItem.label ? menuItem.label : ""
63+ icon: menuItem && menuItem.icon ? menuItem.icon : ""
64+ minIcon: extAttrib && extAttrib.hasOwnProperty("minIcon") ? extAttrib.minIcon : ""
65+ maxIcon: extAttrib && extAttrib.hasOwnProperty("maxIcon") ? extAttrib.maxIcon : ""
6366
64− minimumValue: menu.ext.minValue ? menu.ext.minValue : 0.0
67+ minimumValue: extAttrib && extAttrib.hasOwnProperty("minValue") ? extAttrib.minValue : 0.0
6568 maximumValue: {
66− var maximum = menu.ext.maxValue ? menu.ext.maxValue : 1.0
69+ var maximum = extAttrib && extAttrib.hasOwnProperty("maxValue") ? extAttrib.maxValue : 1.0
6770 if (maximum <= minimumValue) {
6871 return minimumValue + 1;
6972 }
7073 return maximum;
7174 }
72− value: menu ? menu.actionState : 0.0
73− enabled: menu ? menu.sensitive : false
75+ value: menuItem ? menuItem.actionState : 0.0
76+ enabled: menuItem ? menuItem.sensitive : false
7477
75− Component.onCompleted: {
76− model.loadExtendedAttributes(modelIndex, {'min-value': 'double',
78+ onMenuModelChanged: {
79+ loadAttributes();
80+ }
81+ onMenuIndexChanged: {
82+ loadAttributes();
83+ }
84+ onChangeState: {
85+ menuModel.changeState(menuIndex, value);
86+ }
87+
88+ function loadAttributes() {
89+ if (!menuModel || menuIndex == undefined) return;
90+ menuModel.loadExtendedAttributes(menuIndex, {'min-value': 'double',
7791 'max-value': 'double',
7892 'min-icon': 'icon',
7993 'max-icon': 'icon'});
8094 }
81−
82− onChangeState: {
83− model.changeState(modelIndex, value);
84− }
8595 }
8696 }
8797
8898 Component {
8999 id: buttonMenu;
90100 Indicators.ButtonMenuItem {
91− property QtObject menu: null
101+ property QtObject menuItem: null
102+ property var menuModel: menuFactory.menuModel
103+ property var menuIndex: undefined
92104
93− text: menu && menu.label ? menu.label : ""
94− enabled: menu ? menu.sensitive : false
105+ text: menuItem && menuItem.label ? menuItem.label : ""
106+ enabled: menuItem ? menuItem.sensitive : false
95107
96108 onActivate: {
97− model.activate(modelIndex);
109+ menuModel.activate(menuIndex);
98110 }
99111 }
100112 }
101113 Component {
102114 id: sectionMenu;
103115 Indicators.SectionMenuItem {
104− property QtObject menu: null
116+ property QtObject menuItem: null
117+ property var menuIndex: undefined
105118
106− text: menu && menu.label ? menu.label : ""
119+ text: menuItem && menuItem.label ? menuItem.label : ""
107120 }
108121 }
109122
110123 Component {
111124 id: progressMenu;
112125 Indicators.ProgressMenuItem {
113− property QtObject menu: null
126+ property QtObject menuItem: null
127+ property var menuIndex: undefined
114128
115− text: menu && menu.label ? menu.label : ""
116− icon: menu ? menu.icon : ""
117− value : menu ? menu.actionState : 0.0
118− enabled: menu ? menu.sensitive : false
129+ text: menuItem && menuItem.label ? menuItem.label : ""
130+ icon: menuItem ? menuItem.icon : ""
131+ value : menuItem ? menuItem.actionState : 0.0
132+ enabled: menuItem ? menuItem.sensitive : false
119133 }
120134 }
121135
122136 Component {
123137 id: standardMenu;
124138 Indicators.StandardMenuItem {
125− property QtObject menu: null
139+ property QtObject menuItem: null
140+ property var menuIndex: undefined
126141
127− text: menu && menu.label ? menu.label : ""
128− icon: menu && menu.icon ? menu.icon : ""
129− checkable: menu ? (menu.isCheck || menu.isRadio) : false
130− checked: checkable ? menu.isToggled : false
131− enabled: menu ? menu.sensitive : false
142+ text: menuItem && menuItem.label ? menuItem.label : ""
143+ icon: menuItem && menuItem.icon ? menuItem.icon : ""
144+ checkable: menuItem ? (menuItem.isCheck || menuItem.isRadio) : false
145+ checked: checkable ? menuItem.isToggled : false
146+ enabled: menuItem ? menuItem.sensitive : false
132147
133148 onActivate: {
134− model.activate(modelIndex);
149+ menuModel.activate(menuIndex);
135150 }
136151 }
137152 }
@@ -139,15 +154,16 @@ Item {
139154 Component {
140155 id: switchMenu;
141156 Indicators.SwitchMenuItem {
142− property QtObject menu: null
157+ property QtObject menuItem: null
158+ property var menuIndex: undefined
143159
144− text: menu && menu.label ? menu.label : ""
145− icon: menu && menu.icon ? menu.icon : ""
146− checked: menu ? menu.isToggled : false
147− enabled: menu ? menu.sensitive : false
160+ text: menuItem && menuItem.label ? menuItem.label : ""
161+ icon: menuItem && menuItem.icon ? menuItem.icon : ""
162+ checked: menuItem ? menuItem.isToggled : false
163+ enabled: menuItem ? menuItem.sensitive : false
148164
149165 onActivate: {
150− model.activate(modelIndex);
166+ menuModel.activate(menuIndex);
151167 }
152168 }
153169 }
@@ -155,13 +171,24 @@ Item {
155171 Component {
156172 id: wifiSection;
157173 Indicators.SectionMenuItem {
158− property QtObject menu: null
174+ property QtObject menuItem: null
175+ property var menuModel: menuFactory.menuModel
176+ property var menuIndex: undefined
177+ property var extAttrib: menuItem && menuItem.ext ? menuItem.ext : undefined
178+
179+ text: menuItem && menuItem.label ? menuItem.label : ""
180+ busy: extAttrib && extAttrib.hasOwnProperty("xCanonicalBusyAction") ? extAttrib.xCanonicalBusyAction : false
159181
160− text: menu && menu.label ? menu.label : ""
161− busy: menu ? menu.ext.xCanonicalBusyAction : false
182+ onMenuModelChanged: {
183+ loadAttributes();
184+ }
185+ onMenuIndexChanged: {
186+ loadAttributes();
187+ }
162188
163− Component.onCompleted: {
164− model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
189+ function loadAttributes() {
190+ if (!menuModel || menuIndex == undefined) return;
191+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-busy-action': 'bool'})
165192 }
166193 }
167194 }
@@ -169,27 +196,39 @@ Item {
169196 Component {
170197 id: accessPoint;
171198 ICNetwork.AccessPoint {
172− property QtObject menu: null
199+ property QtObject menuItem: null
200+ property var menuModel: menuFactory.menuModel
201+ property var menuIndex: undefined
202+ property var extAttrib: menuItem && menuItem.ext ? menuItem.ext : undefined
203+
173204 property var strengthAction: QMenuModel.UnityMenuAction {
174− model: menuFactory.model ? menuFactory.model : null
175− index: modelIndex
176− name: menu ? menu.ext.xCanonicalWifiApStrengthAction : ""
205+ model: menuModel
206+ index: menuIndex
207+ name: extAttrib && extAttrib.hasOwnProperty("xCanonicalWifiApStrengthAction") ? extAttrib.xCanonicalWifiApStrengthAction : ""
177208 }
178209
179− text: menu && menu.label ? menu.label : ""
180− secure: menu ? menu.ext.xCanonicalWifiApIsSecure : false
181− adHoc: menu ? menu.ext.xCanonicalWifiApIsAdhoc : false
182− checked: menu ? menu.isToggled : false
210+ text: menuItem && menuItem.label ? menuItem.label : ""
211+ secure: extAttrib && extAttrib.hasOwnProperty("xCanonicalWifiApIsSecure") ? extAttrib.xCanonicalWifiApIsSecure : false
212+ adHoc: extAttrib && extAttrib.hasOwnProperty("xCanonicalWifiApIsAdhoc") ? extAttrib.xCanonicalWifiApIsAdhoc : false
213+ checked: menuItem ? menuItem.isToggled : false
183214 signalStrength: strengthAction.valid ? strengthAction.state : 0
184− enabled: menu ? menu.sensitive : false
215+ enabled: menuItem ? menuItem.sensitive : false
185216
186− Component.onCompleted: {
187− model.loadExtendedAttributes(modelIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
188− 'x-canonical-wifi-ap-is-secure': 'bool',
189− 'x-canonical-wifi-ap-strength-action': 'string'});
217+ onMenuModelChanged: {
218+ loadAttributes();
219+ }
220+ onMenuIndexChanged: {
221+ loadAttributes();
190222 }
191223 onActivate: {
192− model.activate(modelIndex);
224+ menuModel.activate(menuIndex);
225+ }
226+
227+ function loadAttributes() {
228+ if (!menuModel || menuIndex == undefined) return;
229+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
230+ 'x-canonical-wifi-ap-is-secure': 'bool',
231+ 'x-canonical-wifi-ap-strength-action': 'string'});
193232 }
194233 }
195234 }
@@ -197,37 +236,38 @@ Item {
197236 Component {
198237 id: messageItem
199238 ICMessaging.MessageMenuItemFactory {
200−
201− property QtObject menu: null
202− model: menuFactory.model ? menuFactory.model : null
203−
204− Component.onCompleted: {
205− model.loadExtendedAttributes(modelIndex, {'x-canonical-time': 'int64',
206− 'x-canonical-text': 'string',
207− 'x-canonical-message-actions': 'variant',
208− 'icon': 'icon',
209− 'x-canonical-app-icon': 'icon'});
210− }
239+ menuModel: menuFactory.menuModel
211240 }
212241 }
213242
214243 Component {
215244 id: groupedMessage
216245 ICMessaging.GroupedMessage {
217− property QtObject menu: null
246+ property QtObject menuItem: null
247+ property var menuModel: menuFactory.menuModel
248+ property var menuIndex: undefined
249+ property var extAttrib: menuItem && menuItem.ext ? menuItem.ext : undefined
218250
219− title: menu && menu.label ? menu.label : ""
220− count: menu && menu.actionState[0] ? menu.actionState[0] : "0"
221− appIcon: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_app.svg"
251+ title: menuItem && menuItem.label ? menuItem.label : ""
252+ count: menuItem && menuItem.actionState.length > 0 ? menuItem.actionState[0] : "0"
253+ appIcon: extAttrib && extAttrib.hasOwnProperty("icon") ? extAttrib.icon : "qrc:/indicators/artwork/messaging/default_app.svg"
222254
223− Component.onCompleted: {
224− model.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
255+ onMenuModelChanged: {
256+ loadAttributes();
257+ }
258+ onMenuIndexChanged: {
259+ loadAttributes();
225260 }
226261 onActivateApp: {
227− model.activate(modelIndex, true);
262+ menuModel.activate(menuIndex, true);
228263 }
229264 onDismiss: {
230− model.activate(modelIndex, false);
265+ menuModel.activate(menuIndex, false);
266+ }
267+
268+ function loadAttributes() {
269+ if (!menuModel || menuIndex == undefined) return;
270+ menuModel.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
231271 }
232272 }
233273 }