on xenial help sign in
Abstraction of indicator menu item properties prior to move into common components library.
22ae3c3Nick Dedekind
plugins/Unity/Indicators/Network/qml/AccessPoint.qml+18−8
@@ -25,29 +25,39 @@ import Unity.Indicators 0.1 as Indicators
25Indicators.FramedMenuItem {
25Indicators.FramedMenuItem {
26 id: accessPoint
26 id: accessPoint
27
27
28− readonly property bool checked: menu ? menu.isToggled : false
28+ property bool checked: false
29+ property bool secure: false
30+ property bool adHoc: false
31+ property int signalStrength: 0
32+
33+ signal activate()
29
34
30 onCheckedChanged: {
35 onCheckedChanged: {
31 // Can't rely on binding. Checked is assigned on click.
36 // Can't rely on binding. Checked is assigned on click.
32 checkBoxActive.checked = checked;
37 checkBoxActive.checked = checked;
33 }
38 }
34
39
35− // FIXME - we need to get the strength from menu.ext.xCanonicalWifiApStrengthAction
40+ icon: {
36− // but UnityMenuModel doesnt support fetching actions not attached to menu item.
37− function getNetworkIcon(data) {
38 var imageName = "nm-signal-100"
41 var imageName = "nm-signal-100"
39
42
40− if (data.ext.xCanonicalWifiApIsAdhoc) {
43+ if (adHoc) {
41 imageName = "nm-adhoc";
44 imageName = "nm-adhoc";
45+ } else if (signalStrength == 0) {
46+ imageName = "nm-signal-00";
47+ } else if (signalStrength <= 25) {
48+ imageName = "nm-signal-25";
49+ } else if (signalStrength <= 50) {
50+ imageName = "nm-signal-50";
51+ } else if (signalStrength <= 75) {
52+ imageName = "nm-signal-75";
42 }
53 }
43− if (data.ext.xCanonicalWifiApIsSecure) {
54+
55+ if (secure) {
44 imageName += "-secure";
56 imageName += "-secure";
45 }
57 }
46−
47 return "image://gicon/" + imageName;
58 return "image://gicon/" + imageName;
48 }
59 }
49
60
50− icon: menu ? getNetworkIcon(menu) : "image://gicon/wifi-none"
51 iconFrame: false
61 iconFrame: false
52 control: CheckBox {
62 control: CheckBox {
53 id: checkBoxActive
63 id: checkBoxActive
plugins/Unity/Indicators/Network/qml/PasswordPage.qml+1−1
@@ -38,7 +38,7 @@ Page {
38 }
38 }
39
39
40 Indicators.SectionMenuItem {
40 Indicators.SectionMenuItem {
41− label: "Authentication"
41+ text: "Authentication"
42 }
42 }
43
43
44 Indicators.FramedMenuItem {
44 Indicators.FramedMenuItem {
plugins/Unity/Indicators/Network/qml/WifiSection.qmldeleted−28
@@ -1,28 +0,0 @@
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− * Renato Araujo Oliveira Filho <renato@canonical.com>
18− */
19−
20−import QtQuick 2.0
21−import Ubuntu.Components 0.1
22−import Unity.Indicators 0.1 as Indicators
23−
24−Indicators.SectionMenuItem {
25− id: wifiSectionMenu
26−
27− busy: menu ? menu.ext.xCanonicalBusyAction : false
28−}
plugins/Unity/Indicators/Network/qml/qmldir+1−2
@@ -5,5 +5,4 @@ typeinfo plugin.qmltypes
5NetworkPage 0.1 NetworkPage.qml
5NetworkPage 0.1 NetworkPage.qml
6AccessPoint 0.1 AccessPoint.qml
6AccessPoint 0.1 AccessPoint.qml
7PasswordPage 0.1 PasswordPage.qml
7PasswordPage 0.1 PasswordPage.qml
8−PasswordTextField 0.1 PasswordTextField.qml
8+PasswordTextField 0.1 PasswordTextField.qml
9−WifiSection 0.1 WifiSection.qml
plugins/Unity/Indicators/qml/BaseMenuItem.qml−4
@@ -25,14 +25,10 @@ ListItem.Standard {
25 id: baseMenu
25 id: baseMenu
26
26
27 property bool menuActivated: false
27 property bool menuActivated: false
28− property QtObject menu
29
28
30 signal selectMenu()
29 signal selectMenu()
31 signal deselectMenu()
30 signal deselectMenu()
32
31
33− signal activate()
34− signal changeState(var value)
35−
36 showDivider: false
32 showDivider: false
37 __foregroundColor: "#e8e1d0" // FIXME not in palette yet
33 __foregroundColor: "#e8e1d0" // FIXME not in palette yet
38
34
plugins/Unity/Indicators/qml/ButtonMenuItem.qml+4−9
@@ -24,14 +24,14 @@ import Unity.Indicators 0.1 as Indicators
24
24
25BaseMenuItem {
25BaseMenuItem {
26 id: menuItem
26 id: menuItem
27− objectName: menuAction.name
28 implicitHeight: units.gu(7)
27 implicitHeight: units.gu(7)
29− enabled: menuAction.active
28+
29+ property alias text: button.text
30+
31+ signal activate()
30
32
31 Button {
33 Button {
32 id: button
34 id: button
33− enabled: menuAction.enabled
34− text: menu ? menu.label : ""
35 anchors.centerIn: parent
35 anchors.centerIn: parent
36 height: units.gu(4)
36 height: units.gu(4)
37 width: units.gu(16)
37 width: units.gu(16)
@@ -41,9 +41,4 @@ BaseMenuItem {
41 menuItem.activate();
41 menuItem.activate();
42 }
42 }
43 }
43 }
44−
45− Indicators.MenuAction {
46− id: menuAction
47− menu: menuItem.menu
48− }
49}
44}
plugins/Unity/Indicators/qml/FramedMenuItem.qml−2
@@ -23,10 +23,8 @@ import Ubuntu.Components 0.1
23import Ubuntu.Components.ListItems 0.1 as ListItem
23import Ubuntu.Components.ListItems 0.1 as ListItem
24
24
25BaseMenuItem {
25BaseMenuItem {
26− text: menu && menu.label ? menu.label : ""
27 implicitHeight: units.gu(7)
26 implicitHeight: units.gu(7)
28
27
29− icon: menu ? menu.icon : ""
30 iconFrame: false
28 iconFrame: false
31
29
32 HLine {
30 HLine {
plugins/Unity/Indicators/qml/IndicatorPage.qml+4−9
@@ -96,18 +96,13 @@ IndicatorBase {
96 }
96 }
97 if (item.hasOwnProperty("menu")) {
97 if (item.hasOwnProperty("menu")) {
98 item.menu = Qt.binding(function() { return model; });
98 item.menu = Qt.binding(function() { return model; });
99−
100− item.activate.connect(onActivateMenu);
101− item.changeState.connect(onChangeState);
102 }
99 }
103 }
100 }
104
101
105− function onActivateMenu(value) {
102+ Binding {
106− mainMenu.model.activate(index, value);
103+ target: item ? item : null
107− }
104+ property: "objectName"
108−
105+ value: model.action
109− function onChangeState(value) {
110− mainMenu.model.changeState(index, value);
111 }
106 }
112 }
107 }
113 }
108 }
plugins/Unity/Indicators/qml/MenuAction.qmldeleted−59
@@ -1,59 +0,0 @@
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− * Renato Araujo Oliveira Filho <renato@canonical.com>
18− * Nick Dedekind <nick.dedekind@canonical.com>
19− */
20−
21−import QtQuick 2.0
22−
23−/*!
24− \qmltype MenuAction
25− \inqmlmodule Indicators 0.1
26− \brief Helper class to connect to a qmenumodel action
27−
28− Example:
29− \qml
30− BaseMenuItem {
31− id: menuItem
32−
33− Switch {
34− checked: menuAction.state
35− }
36−
37− Indicators.MenuAction {
38− id: menuAction
39− menu: menuItem.menu
40− }
41− }
42− \endqml
43−*/
44−
45−Item {
46− id: menuAction
47−
48− /*!
49− \preliminary
50− The dbus action group object
51− */
52− readonly property string name: menu ? menu.action : ""
53−
54− property QtObject menu: null
55−
56− readonly property var state: menu ? menu.actionState : undefined
57−
58− readonly property bool active: menu ? menu.sensitive : false
59−}
plugins/Unity/Indicators/qml/MenuItemFactory.qml+124−7
@@ -20,6 +20,7 @@
20import QtQuick 2.0
20import QtQuick 2.0
21import Unity.Indicators 0.1 as Indicators
21import Unity.Indicators 0.1 as Indicators
22import Unity.Indicators.Network 0.1 as ICNetwork
22import Unity.Indicators.Network 0.1 as ICNetwork
23+import QMenuModel 0.1 as QMenuModel
23
24
24Item {
25Item {
25 id: menuFactory
26 id: menuFactory
@@ -47,35 +48,151 @@ Item {
47 Component {
48 Component {
48 id: sliderMenu;
49 id: sliderMenu;
49 Indicators.SliderMenuItem {
50 Indicators.SliderMenuItem {
51+ property QtObject menu: null
52+
53+ text: menu && menu.label ? menu.label : ""
54+ icon: menu ? menu.icon : ""
55+ minIcon: menu.ext.minIcon
56+ maxIcon: menu.ext.maxIcon
57+
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
68+
50 Component.onCompleted: {
69 Component.onCompleted: {
51 model.loadExtendedAttributes(modelIndex, {'min-value': 'double',
70 model.loadExtendedAttributes(modelIndex, {'min-value': 'double',
52 'max-value': 'double',
71 'max-value': 'double',
53 'min-icon': 'icon',
72 'min-icon': 'icon',
54 'max-icon': 'icon'});
73 'max-icon': 'icon'});
55 }
74 }
75+
76+ // FIXME: The interval should be [0.0 - 1.0]. Unfortunately, when
77+ // reaching the boundaries (0.0 or 1.0), the value is converted
78+ // to an integer when automatically wrapped in a variant when
79+ // passed to QStateAction::updateState(…). The server chokes on
80+ // those values, complaining that they’re not of the right type…
81+ onChangeState: {
82+ if (value == Math.round(value)) {
83+ if (value >= maximumValue) {
84+ model.changeState(modelIndex, maximumValue - 0.000001);
85+ } else if (value <= minimumValue) {
86+ model.changeState(modelIndex, minimumValue + 0.000001);
87+ } else {
88+ model.changeState(modelIndex, value * 1.000001);
89+ }
90+ } else {
91+ model.changeState(modelIndex, value);
92+ }
93+ }
56 }
94 }
57 }
95 }
58− Component { id: buttonMenu; Indicators.ButtonMenuItem {} }
96+
59 Component { id: divMenu; Indicators.DivMenuItem {} }
97 Component { id: divMenu; Indicators.DivMenuItem {} }
98+
99+ Component {
100+ id: buttonMenu;
101+ Indicators.ButtonMenuItem {
102+ property QtObject menu: null
103+
104+ text: menu && menu.label ? menu.label : ""
105+ enabled: menu ? menu.sensitive : false
106+
107+ onActivate: model.activate(modelIndex);
108+ }
109+ }
110+ Component {
111+ id: sectionMenu;
60− Component { id: sectionMenu; Indicators.SectionMenuItem {} }
112+ Indicators.SectionMenuItem {
113+ property QtObject menu: null
114+
115+ text: menu && menu.label ? menu.label : ""
116+ }
117+ }
118+
119+ Component {
120+ id: progressMenu;
61− Component { id: progressMenu; Indicators.ProgressMenuItem {} }
121+ Indicators.ProgressMenuItem {
122+ property QtObject menu: null
123+
124+ text: menu && menu.label ? menu.label : ""
125+ icon: menu ? menu.icon : ""
126+ value : menu ? menu.actionState : 0.0
127+ }
128+ }
129+
130+ Component {
131+ id: standardMenu;
62− Component { id: standardMenu; Indicators.StandardMenuItem {} }
132+ Indicators.StandardMenuItem {
133+ property QtObject menu: null
134+
135+ text: menu && menu.label ? menu.label : ""
136+ icon: menu ? menu.icon : ""
137+ checkable: menu ? (menu.isCheck || menu.isRadio) : false
138+ checked: checkable ? menu.isToggled : false
139+ enabled: menu ? menu.sensitive : false
140+
141+ onActivate: model.activate(modelIndex);
142+ }
143+ }
144+
145+ Component {
146+ id: switchMenu;
63− Component { id: switchMenu; Indicators.SwitchMenuItem {} }
147+ Indicators.SwitchMenuItem {
148+ property QtObject menu: null
149+
150+ text: menu && menu.label ? menu.label : ""
151+ icon: menu ? menu.icon : ""
152+ checked: menu ? menu.isToggled : false
153+ enabled: menu ? menu.sensitive : false
154+
155+ onActivate: model.activate(modelIndex);
156+ }
157+ }
158+
64 Component {
159 Component {
65 id: wifiSection;
160 id: wifiSection;
66− ICNetwork.WifiSection {
161+ Indicators.SectionMenuItem {
162+ property QtObject menu: null
163+
164+ text: menu && menu.label ? menu.label : ""
165+ busy: menu ? menu.ext.xCanonicalBusyAction : false
166+
67 Component.onCompleted: {
167 Component.onCompleted: {
68 model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
168 model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
69 }
169 }
70 }
170 }
71 }
171 }
172+
72 Component {
173 Component {
73 id: accessPoint;
174 id: accessPoint;
74 ICNetwork.AccessPoint {
175 ICNetwork.AccessPoint {
176+ property QtObject menu: null
177+// property var strenthAction: QMenuModel.UnityMenuAction {
178+// model: menuFactory.model ? menuFactory.model : null
179+// name: menu ? menu.ext.xCanonicalWifiApStrengthAction : ""
180+// }
181+
182+ text: menu && menu.label ? menu.label : ""
183+ icon: menu ? menu.icon : ""
184+ secure: menu ? menu.ext.xCanonicalWifiApIsSecure : false
185+ adHoc: menu ? menu.ext.xCanonicalWifiApIsAdhoc : false
186+ checked: menu ? menu.isToggled : false
187+// signalStrength: strenthAction.valid ? strenthAction.state : 0
188+ enabled: menu ? menu.sensitive : false
189+
75 Component.onCompleted: {
190 Component.onCompleted: {
76 model.loadExtendedAttributes(modelIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
191 model.loadExtendedAttributes(modelIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
77− 'x-canonical-wifi-ap-is-secure': 'bool'});
192+ 'x-canonical-wifi-ap-is-secure': 'bool',
193+ 'x-canonical-wifi-ap-strength-action': 'string'});
78 }
194 }
195+ onActivate: model.activate(modelIndex);
79 }
196 }
80 }
197 }
81
198
plugins/Unity/Indicators/qml/ProgressMenuItem.qml+1−8
@@ -23,10 +23,8 @@ import Unity.Indicators 0.1 as Indicators
23
23
24FramedMenuItem {
24FramedMenuItem {
25 id: menuItem
25 id: menuItem
26− objectName: menuAction.name
27− enabled: menuAction.active
28
26
29− property int value : menuAction.state
27+ property int value : 0.0
30
28
31 control: Label {
29 control: Label {
32 id: progress
30 id: progress
@@ -37,9 +35,4 @@ FramedMenuItem {
37 fontSize: "medium"
35 fontSize: "medium"
38 color: "#e8e1d0"
36 color: "#e8e1d0"
39 }
37 }
40−
41− Indicators.MenuAction {
42− id: menuAction
43− menu: menuItem.menu
44− }
45}
38}
plugins/Unity/Indicators/qml/SectionMenuItem.qml+3−3
@@ -22,15 +22,15 @@ import Ubuntu.Components 0.1
22import Ubuntu.Components.ListItems 0.1 as ListItem
22import Ubuntu.Components.ListItems 0.1 as ListItem
23
23
24BaseMenuItem {
24BaseMenuItem {
25− property string label: menu && menu.label ? menu.label : ""
25+ id: menuItem
26+ property alias text: header.text
26 property bool busy: false
27 property bool busy: false
27
28
28− implicitHeight: label !== "" ? header.height : 0
29+ implicitHeight: text !== "" ? header.height : 0
29
30
30 ListItem.Header {
31 ListItem.Header {
31 id: header
32 id: header
32
33
33− text: label
34 height: units.gu(4)
34 height: units.gu(4)
35 anchors {
35 anchors {
36 left: parent.left
36 left: parent.left
plugins/Unity/Indicators/qml/SliderMenuItem.qml+8−23
@@ -24,17 +24,20 @@ import Unity.Indicators 0.1 as Indicators
24
24
25FramedMenuItem {
25FramedMenuItem {
26 id: menuItem
26 id: menuItem
27− objectName: menuAction.name
28− enabled: menuAction.active
29
27
30 property alias minimumValue: slider.minimumValue
28 property alias minimumValue: slider.minimumValue
31 property alias maximumValue: slider.maximumValue
29 property alias maximumValue: slider.maximumValue
32− readonly property double value: menu ? menuAction.state : 0.0
30+ property double value: 0.0
31+
32+ property alias minIcon: leftImage.source
33+ property alias maxIcon: rightImage.source
33
34
34 property QtObject d: QtObject {
35 property QtObject d: QtObject {
35 property bool enableValueConnection: true
36 property bool enableValueConnection: true
36 }
37 }
37
38
39+ signal changeState(real value)
40+
38 onValueChanged: {
41 onValueChanged: {
39 // TODO: look into adding a component to manage bi-directional bindings.
42 // TODO: look into adding a component to manage bi-directional bindings.
40 var oldEnable = d.enableValueConnection
43 var oldEnable = d.enableValueConnection
@@ -58,7 +61,6 @@ FramedMenuItem {
58 anchors.verticalCenter: row.verticalCenter
61 anchors.verticalCenter: row.verticalCenter
59 height: units.gu(4)
62 height: units.gu(4)
60 width: height
63 width: height
61− source: menu.ext.minIcon
62 }
64 }
63
65
64 Components.Slider {
66 Components.Slider {
@@ -75,19 +77,8 @@ FramedMenuItem {
75 value = menuItem.value
77 value = menuItem.value
76 }
78 }
77
79
78− // FIXME: The interval should be [0.0 - 1.0]. Unfortunately, when
80+ minimumValue: 0.0
79− // reaching the boundaries (0.0 or 1.0), the value is converted
80− // to an integer when automatically wrapped in a variant when
81− // passed to QStateAction::updateState(…). The server chokes on
82− // those values, complaining that they’re not of the right type…
83− minimumValue: menu.ext.minValue ? menu.ext.minValue * 1.000001 : 0.0000001
84− maximumValue: {
81+ maximumValue: 0.1
85− var maximum = menu.ext.maxValue ? menu.ext.maxValue * 1.000001 : 0.9999999
86− if (maximum <= minimumValue) {
87− return minimumValue + 1;
88− }
89− return maximum;
90− }
91
82
92 // FIXME - to be deprecated in Ubuntu.Components.
83 // FIXME - to be deprecated in Ubuntu.Components.
93 // Use this to disable the label, since there is not way to do it on the component.
84 // Use this to disable the label, since there is not way to do it on the component.
@@ -109,12 +100,6 @@ FramedMenuItem {
109 anchors.verticalCenter: row.verticalCenter
100 anchors.verticalCenter: row.verticalCenter
110 height: units.gu(4)
101 height: units.gu(4)
111 width: height
102 width: height
112− source: menu.ext.maxIcon
113 }
103 }
114 }
104 }
115−
116− Indicators.MenuAction {
117− id: menuAction
118− menu: menuItem.menu
119− }
120}
105}
plugins/Unity/Indicators/qml/StandardMenuItem.qml+5−10
@@ -23,16 +23,16 @@ import Unity.Indicators 0.1 as Indicators
23
23
24FramedMenuItem {
24FramedMenuItem {
25 id: menuItem
25 id: menuItem
26− objectName: menuAction.name
27− enabled: menuAction.active
28
26
29− readonly property bool checkable: menu ? (menu.isCheck || menu.isRadio) : false
27+ property bool checkable: false
30− readonly property bool checked: checkable ? menu.isToggled : false
28+ property bool checked: false
29+
30+ signal activate()
31
31
32 // FIXME : need a radio button from sdk
32 // FIXME : need a radio button from sdk
33 // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1211866
33 // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1211866
34 onCheckableChanged: {
34 onCheckableChanged: {
35− if (menu && checkable) {
35+ if (checkable) {
36 icon = checkComponent.createObject(menuItem);
36 icon = checkComponent.createObject(menuItem);
37 }
37 }
38 }
38 }
@@ -68,9 +68,4 @@ FramedMenuItem {
68 }
68 }
69 }
69 }
70 }
70 }
71−
72− Indicators.MenuAction {
73− id: menuAction
74− menu: menuItem.menu
75− }
76}
71}
plugins/Unity/Indicators/qml/SwitchMenuItem.qml+3−8
@@ -24,10 +24,10 @@ import Unity.Indicators 0.1 as Indicators
24
24
25FramedMenuItem {
25FramedMenuItem {
26 id: menuItem
26 id: menuItem
27− objectName: menuAction.name
28− enabled: menuAction.enabled
29
27
30− readonly property bool checked: menu ? menu.isToggled : false
28+ property bool checked: false
29+
30+ signal activate()
31
31
32 onCheckedChanged: {
32 onCheckedChanged: {
33 // Can't rely on binding. Checked is assigned on click.
33 // Can't rely on binding. Checked is assigned on click.
@@ -50,9 +50,4 @@ FramedMenuItem {
50 menuItem.activate();
50 menuItem.activate();
51 }
51 }
52 }
52 }
53−
54− Indicators.MenuAction {
55− id: menuAction
56− menu: menuItem.menu
57− }
58}
53}
plugins/Unity/Indicators/qml/qmldir−1
@@ -11,7 +11,6 @@ HLine 0.1 HLine.qml
11IndicatorBase 0.1 IndicatorBase.qml
11IndicatorBase 0.1 IndicatorBase.qml
12IndicatorPage 0.1 IndicatorPage.qml
12IndicatorPage 0.1 IndicatorPage.qml
13IndicatorWidget 0.1 IndicatorWidget.qml
13IndicatorWidget 0.1 IndicatorWidget.qml
14−MenuAction 0.1 MenuAction.qml
15MenuActionBinding 0.1 MenuActionBinding.qml
14MenuActionBinding 0.1 MenuActionBinding.qml
16MenuItemFactory 0.1 MenuItemFactory.qml
15MenuItemFactory 0.1 MenuItemFactory.qml
17ProgressMenuItem 0.1 ProgressMenuItem.qml
16ProgressMenuItem 0.1 ProgressMenuItem.qml