on 02b2ade help sign in
unity8/plugins/Unity/Indicators/qml/MenuItemFactory.qml
254 lines 8.8 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
20import QtQuick 2.0
21import Unity.Indicators 0.1 as Indicators
22import Unity.Indicators.Network 0.1 as ICNetwork
23import Unity.Indicators.Messaging 0.1 as ICMessaging
24import QMenuModel 0.1 as QMenuModel
25import Ubuntu.Components 0.1
27Item {
28 id: menuFactory
30 property var model: null
32 property var _map: {
33 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
34 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
36 "com.canonical.indicator.button" : buttonMenu,
37 "com.canonical.indicator.div" : divMenu,
38 "com.canonical.indicator.section" : sectionMenu,
39 "com.canonical.indicator.progress" : progressMenu,
40 "com.canonical.indicator.slider" : sliderMenu,
41 "com.canonical.indicator.switch" : switchMenu,
43 "com.canonical.indicator.messages.messageitem" : messageItem,
44 "com.canonical.indicator.messages.sourceitem" : groupedMessage,
46 "com.canonical.unity.slider" : sliderMenu,
47 "com.canonical.unity.switch" : switchMenu,
49 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
50 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
51 }
53 Component { id: divMenu; Indicators.DivMenuItem {} }
55 Component {
56 id: sliderMenu;
57 Indicators.SliderMenuItem {
58 property QtObject menu: null
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 : ""
65 minimumValue: menu.ext.minValue ? menu.ext.minValue : 0.0
66 maximumValue: {
67 var maximum = menu.ext.maxValue ? menu.ext.maxValue : 1.0
68 if (maximum <= minimumValue) {
69 return minimumValue + 1;
70 }
71 return maximum;
72 }
73 value: menu ? menu.actionState : 0.0
74 enabled: menu ? menu.sensitive : false
76 Component.onCompleted: {
77 model.loadExtendedAttributes(modelIndex, {'min-value': 'double',
78 'max-value': 'double',
79 'min-icon': 'icon',
80 'max-icon': 'icon'});
81 }
83 onChangeState: {
84 model.changeState(modelIndex, value);
85 }
86 }
87 }
89 Component {
90 id: buttonMenu;
91 Indicators.ButtonMenuItem {
92 property QtObject menu: null
94 text: menu && menu.label ? menu.label : ""
95 enabled: menu ? menu.sensitive : false
97 onActivate: {
98 model.activate(modelIndex);
99 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
100 }
101 }
102 }
103 Component {
104 id: sectionMenu;
105 Indicators.SectionMenuItem {
106 property QtObject menu: null
108 text: menu && menu.label ? menu.label : ""
109 }
110 }
112 Component {
113 id: progressMenu;
114 Indicators.ProgressMenuItem {
115 property QtObject menu: null
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
121 }
122 }
124 Component {
125 id: standardMenu;
126 Indicators.StandardMenuItem {
127 property QtObject menu: null
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
135 onActivate: {
136 model.activate(modelIndex);
137 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
138 }
139 }
140 }
142 Component {
143 id: switchMenu;
144 Indicators.SwitchMenuItem {
145 property QtObject menu: null
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
152 onActivate: {
153 model.activate(modelIndex);
154 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
155 }
156 }
157 }
159 Component {
160 id: wifiSection;
161 Indicators.SectionMenuItem {
162 property QtObject menu: null
164 text: menu && menu.label ? menu.label : ""
165 busy: menu ? menu.ext.xCanonicalBusyAction : false
167 Component.onCompleted: {
168 model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
169 }
170 }
171 }
173 Component {
174 id: accessPoint;
175 ICNetwork.AccessPoint {
176 property QtObject menu: null
177 property var strengthAction: QMenuModel.UnityMenuAction {
178 model: menuFactory.model ? menuFactory.model : null
179 index: modelIndex
180 name: menu ? menu.ext.xCanonicalWifiApStrengthAction : ""
181 }
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
187 signalStrength: strengthAction.valid ? strengthAction.state : 0
188 enabled: menu ? menu.sensitive : false
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'});
194 }
195 onActivate: {
196 model.activate(modelIndex);
197 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
198 }
199 }
200 }
202 Component {
203 id: messageItem
204 ICMessaging.MessageMenuItemFactory {
206 property QtObject menu: null
207 model: menuFactory.model ? menuFactory.model : null
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 }
216 }
217 }
219 Component {
220 id: groupedMessage
221 ICMessaging.GroupedMessage {
222 property QtObject menu: null
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"
228 Component.onCompleted: {
229 model.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
230 }
231 onActivateApp: {
232 model.activate(modelIndex, true);
233 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
234 }
235 onDismiss: {
236 model.activate(modelIndex, false);
237 }
238 }
239 }
241 function load(modelData) {
242 if (modelData.type !== undefined) {
243 var component = _map[modelData.type];
244 if (component !== undefined) {
245 return component;
246 }
247 } else {
248 if (modelData.isSeparator) {
249 return divMenu;
250 }
251 }
252 return standardMenu;
253 }