@@ -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 }