on 5b03213 help sign in
unity8/plugins/Unity/Indicators/qml/MenuItemFactory.qml
248 lines 8.4 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
26Item {
27 id: menuFactory
29 property var model: null
31 property var _map: {
32 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
33 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
35 "com.canonical.indicator.button" : buttonMenu,
36 "com.canonical.indicator.div" : divMenu,
37 "com.canonical.indicator.section" : sectionMenu,
38 "com.canonical.indicator.progress" : progressMenu,
39 "com.canonical.indicator.slider" : sliderMenu,
40 "com.canonical.indicator.switch" : switchMenu,
42 "com.canonical.indicator.messages.messageitem" : messageItem,
43 "com.canonical.indicator.messages.sourceitem" : groupedMessage,
45 "com.canonical.unity.slider" : sliderMenu,
46 "com.canonical.unity.switch" : switchMenu,
48 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
49 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
50 }
52 Component { id: divMenu; Indicators.DivMenuItem {} }
54 Component {
55 id: sliderMenu;
56 Indicators.SliderMenuItem {
57 property QtObject menu: null
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 : ""
64 minimumValue: menu.ext.minValue ? menu.ext.minValue : 0.0
65 maximumValue: {
66 var maximum = menu.ext.maxValue ? menu.ext.maxValue : 1.0
67 if (maximum <= minimumValue) {
68 return minimumValue + 1;
69 }
70 return maximum;
71 }
72 value: menu ? menu.actionState : 0.0
73 enabled: menu ? menu.sensitive : false
75 Component.onCompleted: {
76 model.loadExtendedAttributes(modelIndex, {'min-value': 'double',
77 'max-value': 'double',
78 'min-icon': 'icon',
79 'max-icon': 'icon'});
80 }
82 onChangeState: {
83 model.changeState(modelIndex, value);
84 }
85 }
86 }
88 Component {
89 id: buttonMenu;
90 Indicators.ButtonMenuItem {
91 property QtObject menu: null
93 text: menu && menu.label ? menu.label : ""
94 enabled: menu ? menu.sensitive : false
96 onActivate: {
97 model.activate(modelIndex);
98 }
99 }
100 }
101 Component {
102 id: sectionMenu;
103 Indicators.SectionMenuItem {
104 property QtObject menu: null
106 text: menu && menu.label ? menu.label : ""
107 }
108 }
110 Component {
111 id: progressMenu;
112 Indicators.ProgressMenuItem {
113 property QtObject menu: null
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
119 }
120 }
122 Component {
123 id: standardMenu;
124 Indicators.StandardMenuItem {
125 property QtObject menu: null
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
133 onActivate: {
134 model.activate(modelIndex);
135 }
136 }
137 }
139 Component {
140 id: switchMenu;
141 Indicators.SwitchMenuItem {
142 property QtObject menu: null
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
149 onActivate: {
150 model.activate(modelIndex);
151 }
152 }
153 }
155 Component {
156 id: wifiSection;
157 Indicators.SectionMenuItem {
158 property QtObject menu: null
160 text: menu && menu.label ? menu.label : ""
161 busy: menu ? menu.ext.xCanonicalBusyAction : false
163 Component.onCompleted: {
164 model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
165 }
166 }
167 }
169 Component {
170 id: accessPoint;
171 ICNetwork.AccessPoint {
172 property QtObject menu: null
173 property var strengthAction: QMenuModel.UnityMenuAction {
174 model: menuFactory.model ? menuFactory.model : null
175 index: modelIndex
176 name: menu ? menu.ext.xCanonicalWifiApStrengthAction : ""
177 }
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
183 signalStrength: strengthAction.valid ? strengthAction.state : 0
184 enabled: menu ? menu.sensitive : false
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'});
190 }
191 onActivate: {
192 model.activate(modelIndex);
193 }
194 }
195 }
197 Component {
198 id: messageItem
199 ICMessaging.MessageMenuItemFactory {
201 property QtObject menu: null
202 model: menuFactory.model ? menuFactory.model : null
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 }
211 }
212 }
214 Component {
215 id: groupedMessage
216 ICMessaging.GroupedMessage {
217 property QtObject menu: null
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"
223 Component.onCompleted: {
224 model.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
225 }
226 onActivateApp: {
227 model.activate(modelIndex, true);
228 }
229 onDismiss: {
230 model.activate(modelIndex, false);
231 }
232 }
233 }
235 function load(modelData) {
236 if (modelData.type !== undefined) {
237 var component = _map[modelData.type];
238 if (component !== undefined) {
239 return component;
240 }
241 } else {
242 if (modelData.isSeparator) {
243 return divMenu;
244 }
245 }
246 return standardMenu;
247 }