on 09fab63 help sign in
unity8/plugins/Unity/Indicators/qml/MenuItemFactory.qml
197 lines 6.5 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 QMenuModel 0.1 as QMenuModel
25Item {
26 id: menuFactory
28 property var model: null
30 property var _map: {
31 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
32 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
34 "com.canonical.indicator.button" : buttonMenu,
35 "com.canonical.indicator.div" : divMenu,
36 "com.canonical.indicator.section" : sectionMenu,
37 "com.canonical.indicator.progress" : progressMenu,
38 "com.canonical.indicator.slider" : sliderMenu,
39 "com.canonical.indicator.switch" : switchMenu,
41 "com.canonical.unity.slider" : sliderMenu,
42 "com.canonical.unity.switch" : switchMenu,
44 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
45 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
46 }
48 Component {
49 id: sliderMenu;
50 Indicators.SliderMenuItem {
51 property QtObject menu: null
53 text: menu && menu.label ? menu.label : ""
54 icon: menu ? menu.icon : ""
55 minIcon: menu.ext.minIcon
56 maxIcon: menu.ext.maxIcon
58 minimumValue: menu.ext.minValue ? menu.ext.minValue : 0.0
59 maximumValue: {
60 var maximum = menu.ext.maxValue ? menu.ext.maxValue : 1.0
61 if (maximum <= minimumValue) {
62 return minimumValue + 1;
63 }
64 return maximum;
65 }
66 value: menu ? menu.actionState : 0.0
67 enabled: menu ? menu.sensitive : false
69 Component.onCompleted: {
70 model.loadExtendedAttributes(modelIndex, {'min-value': 'double',
71 'max-value': 'double',
72 'min-icon': 'icon',
73 'max-icon': 'icon'});
74 }
76 onChangeState: {
77 model.changeState(modelIndex, value);
78 }
79 }
80 }
82 Component { id: divMenu; Indicators.DivMenuItem {} }
84 Component {
85 id: buttonMenu;
86 Indicators.ButtonMenuItem {
87 property QtObject menu: null
89 text: menu && menu.label ? menu.label : ""
90 enabled: menu ? menu.sensitive : false
92 onActivate: model.activate(modelIndex);
93 }
94 }
95 Component {
96 id: sectionMenu;
97 Indicators.SectionMenuItem {
98 property QtObject menu: null
100 text: menu && menu.label ? menu.label : ""
101 }
102 }
104 Component {
105 id: progressMenu;
106 Indicators.ProgressMenuItem {
107 property QtObject menu: null
109 text: menu && menu.label ? menu.label : ""
110 icon: menu ? menu.icon : ""
111 value : menu ? menu.actionState : 0.0
112 }
113 }
115 Component {
116 id: standardMenu;
117 Indicators.StandardMenuItem {
118 property QtObject menu: null
120 text: menu && menu.label ? menu.label : ""
121 icon: menu ? menu.icon : ""
122 checkable: menu ? (menu.isCheck || menu.isRadio) : false
123 checked: checkable ? menu.isToggled : false
124 enabled: menu ? menu.sensitive : false
126 onActivate: model.activate(modelIndex);
127 }
128 }
130 Component {
131 id: switchMenu;
132 Indicators.SwitchMenuItem {
133 property QtObject menu: null
135 text: menu && menu.label ? menu.label : ""
136 icon: menu ? menu.icon : ""
137 checked: menu ? menu.isToggled : false
138 enabled: menu ? menu.sensitive : false
140 onActivate: model.activate(modelIndex);
141 }
142 }
144 Component {
145 id: wifiSection;
146 Indicators.SectionMenuItem {
147 property QtObject menu: null
149 text: menu && menu.label ? menu.label : ""
150 busy: menu ? menu.ext.xCanonicalBusyAction : false
152 Component.onCompleted: {
153 model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
154 }
155 }
156 }
158 Component {
159 id: accessPoint;
160 ICNetwork.AccessPoint {
161 property QtObject menu: null
162// property var strenthAction: QMenuModel.UnityMenuAction {
163// model: menuFactory.model ? menuFactory.model : null
164// name: menu ? menu.ext.xCanonicalWifiApStrengthAction : ""
165// }
167 text: menu && menu.label ? menu.label : ""
168 icon: menu ? menu.icon : ""
169 secure: menu ? menu.ext.xCanonicalWifiApIsSecure : false
170 adHoc: menu ? menu.ext.xCanonicalWifiApIsAdhoc : false
171 checked: menu ? menu.isToggled : false
172// signalStrength: strenthAction.valid ? strenthAction.state : 0
173 enabled: menu ? menu.sensitive : false
175 Component.onCompleted: {
176 model.loadExtendedAttributes(modelIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
177 'x-canonical-wifi-ap-is-secure': 'bool',
178 'x-canonical-wifi-ap-strength-action': 'string'});
179 }
180 onActivate: model.activate(modelIndex);
181 }
182 }
184 function load(modelData) {
185 if (modelData.type !== undefined) {
186 var component = _map[modelData.type];
187 if (component !== undefined) {
188 return component;
189 }
190 } else {
191 if (modelData.isSeparator) {
192 return divMenu;
193 }
194 }
195 return standardMenu;
196 }