on bf4d5ed help sign in
unity8/plugins/Unity/Indicators/qml/MenuItemFactory.qml
247 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 }
119 }
121 Component {
122 id: standardMenu;
123 Indicators.StandardMenuItem {
124 property QtObject menu: null
126 text: menu && menu.label ? menu.label : ""
127 icon: menu && menu.icon ? menu.icon : ""
128 checkable: menu ? (menu.isCheck || menu.isRadio) : false
129 checked: checkable ? menu.isToggled : false
130 enabled: menu ? menu.sensitive : false
132 onActivate: {
133 model.activate(modelIndex);
134 }
135 }
136 }
138 Component {
139 id: switchMenu;
140 Indicators.SwitchMenuItem {
141 property QtObject menu: null
143 text: menu && menu.label ? menu.label : ""
144 icon: menu && menu.icon ? menu.icon : ""
145 checked: menu ? menu.isToggled : false
146 enabled: menu ? menu.sensitive : false
148 onActivate: {
149 model.activate(modelIndex);
150 }
151 }
152 }
154 Component {
155 id: wifiSection;
156 Indicators.SectionMenuItem {
157 property QtObject menu: null
159 text: menu && menu.label ? menu.label : ""
160 busy: menu ? menu.ext.xCanonicalBusyAction : false
162 Component.onCompleted: {
163 model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
164 }
165 }
166 }
168 Component {
169 id: accessPoint;
170 ICNetwork.AccessPoint {
171 property QtObject menu: null
172 property var strengthAction: QMenuModel.UnityMenuAction {
173 model: menuFactory.model ? menuFactory.model : null
174 index: modelIndex
175 name: menu ? menu.ext.xCanonicalWifiApStrengthAction : ""
176 }
178 text: menu && menu.label ? menu.label : ""
179 secure: menu ? menu.ext.xCanonicalWifiApIsSecure : false
180 adHoc: menu ? menu.ext.xCanonicalWifiApIsAdhoc : false
181 checked: menu ? menu.isToggled : false
182 signalStrength: strengthAction.valid ? strengthAction.state : 0
183 enabled: menu ? menu.sensitive : false
185 Component.onCompleted: {
186 model.loadExtendedAttributes(modelIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
187 'x-canonical-wifi-ap-is-secure': 'bool',
188 'x-canonical-wifi-ap-strength-action': 'string'});
189 }
190 onActivate: {
191 model.activate(modelIndex);
192 }
193 }
194 }
196 Component {
197 id: messageItem
198 ICMessaging.MessageMenuItemFactory {
200 property QtObject menu: null
201 model: menuFactory.model ? menuFactory.model : null
203 Component.onCompleted: {
204 model.loadExtendedAttributes(modelIndex, {'x-canonical-time': 'int64',
205 'x-canonical-text': 'string',
206 'x-canonical-message-actions': 'variant',
207 'icon': 'icon',
208 'x-canonical-app-icon': 'icon'});
209 }
210 }
211 }
213 Component {
214 id: groupedMessage
215 ICMessaging.GroupedMessage {
216 property QtObject menu: null
218 title: menu && menu.label ? menu.label : ""
219 count: menu && menu.actionState[0] ? menu.actionState[0] : "0"
220 appIcon: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_app.svg"
222 Component.onCompleted: {
223 model.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
224 }
225 onActivateApp: {
226 model.activate(modelIndex, true);
227 }
228 onDismiss: {
229 model.activate(modelIndex, false);
230 }
231 }
232 }
234 function load(modelData) {
235 if (modelData.type !== undefined) {
236 var component = _map[modelData.type];
237 if (component !== undefined) {
238 return component;
239 }
240 } else {
241 if (modelData.isSeparator) {
242 return divMenu;
243 }
244 }
245 return standardMenu;
246 }