on xenial help sign in
Moved all of the menumodel specific code from MenuItems to MenuFactory components.
commitdc81012fbfeea3bef42772805ed74612de2253c7 authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 21 Aug 2013, 22:00 (13 years ago) parent9847f82
19 files changed+200−183
plugins/Unity/Indicators/Network/qml/AccessPoint.qml+19−8 plugins/Unity/Indicators/Network/qml/PasswordPage.qml+1−1 plugins/Unity/Indicators/Network/qml/WifiSection.qml−28 plugins/Unity/Indicators/Network/qml/qmldir+1−2 plugins/Unity/Indicators/qml/BaseMenuItem.qml−4 plugins/Unity/Indicators/qml/ButtonMenuItem.qml+4−9 plugins/Unity/Indicators/qml/CachedUnityMenuModel.qml+6 plugins/Unity/Indicators/qml/FramedMenuItem.qml+1−2 plugins/Unity/Indicators/qml/IndicatorPage.qml+4−9 plugins/Unity/Indicators/qml/MenuAction.qml−59 plugins/Unity/Indicators/qml/MenuItemFactory.qml+124−7 plugins/Unity/Indicators/qml/ProgressMenuItem.qml+1−8 plugins/Unity/Indicators/qml/SectionMenuItem.qml+3−3 plugins/Unity/Indicators/qml/SliderMenuItem.qml+8−23 plugins/Unity/Indicators/qml/StandardMenuItem.qml+5−10 plugins/Unity/Indicators/qml/SwitchMenuItem.qml+3−8 plugins/Unity/Indicators/qml/qmldir−1 plugins/Unity/Indicators/unitymenumodelcache.cpp+16−1 plugins/Unity/Indicators/unitymenumodelcache.h+4
plugins/Unity/Indicators/Network/qml/AccessPoint.qml+19−8
@@ -25,29 +25,40 @@ import Unity.Indicators 0.1 as Indicators
2525Indicators.FramedMenuItem {
2626 id: accessPoint
2727
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()
2934
3035 onCheckedChanged: {
3136 // Can't rely on binding. Checked is assigned on click.
3237 checkBoxActive.checked = checked;
3338 }
3439
35− // FIXME - we need to get the strength from menu.ext.xCanonicalWifiApStrengthAction
36− // but UnityMenuModel doesnt support fetching actions not attached to menu item.
37− function getNetworkIcon(data) {
40+ icon: {
3841 var imageName = "nm-signal-100"
3942
40− if (data.ext.xCanonicalWifiApIsAdhoc) {
43+ if (adHoc) {
4144 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";
4253 }
43− if (data.ext.xCanonicalWifiApIsSecure) {
54+
55+ if (secure) {
4456 imageName += "-secure";
4557 }
46−
4758 return "image://gicon/" + imageName;
4859 }
4960
50− icon: menu ? getNetworkIcon(menu) : "image://gicon/wifi-none"
61+
5162 iconFrame: false
5263 control: CheckBox {
5364 id: checkBoxActive
plugins/Unity/Indicators/Network/qml/PasswordPage.qml+1−1
@@ -38,7 +38,7 @@ Page {
3838 }
3939
4040 Indicators.SectionMenuItem {
41− label: "Authentication"
41+ text: "Authentication"
4242 }
4343
4444 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
55NetworkPage 0.1 NetworkPage.qml
66AccessPoint 0.1 AccessPoint.qml
77PasswordPage 0.1 PasswordPage.qml
8−PasswordTextField 0.1 PasswordTextField.qml
9−WifiSection 0.1 WifiSection.qml
8+PasswordTextField 0.1 PasswordTextField.qml
plugins/Unity/Indicators/qml/BaseMenuItem.qml−4
@@ -25,14 +25,10 @@ ListItem.Standard {
2525 id: baseMenu
2626
2727 property bool menuActivated: false
28− property QtObject menu
2928
3029 signal selectMenu()
3130 signal deselectMenu()
3231
33− signal activate()
34− signal changeState(var value)
35−
3632 showDivider: false
3733 __foregroundColor: "#e8e1d0" // FIXME not in palette yet
3834
plugins/Unity/Indicators/qml/ButtonMenuItem.qml+4−9
@@ -24,14 +24,14 @@ import Unity.Indicators 0.1 as Indicators
2424
2525BaseMenuItem {
2626 id: menuItem
27− objectName: menuAction.name
2827 implicitHeight: units.gu(7)
29− enabled: menuAction.active
28+
29+ property alias text: button.text
30+
31+ signal activate()
3032
3133 Button {
3234 id: button
33− enabled: menuAction.enabled
34− text: menu ? menu.label : ""
3535 anchors.centerIn: parent
3636 height: units.gu(4)
3737 width: units.gu(16)
@@ -41,9 +41,4 @@ BaseMenuItem {
4141 menuItem.activate();
4242 }
4343 }
44−
45− Indicators.MenuAction {
46− id: menuAction
47− menu: menuItem.menu
48− }
4944}
plugins/Unity/Indicators/qml/CachedUnityMenuModel.qml+6
@@ -43,6 +43,12 @@ Item {
4343 return component;
4444 }
4545
46+ Component.onCompleted: Indicators.UnityMenuModelCache.ref()
47+ Component.onDestruction: {
48+ model = null;
49+ Indicators.UnityMenuModelCache.deref();
50+ }
51+
4652 Component {
4753 id: modelComponent
4854
plugins/Unity/Indicators/qml/FramedMenuItem.qml+1−2
@@ -23,10 +23,9 @@ import Ubuntu.Components 0.1
2323import Ubuntu.Components.ListItems 0.1 as ListItem
2424
2525BaseMenuItem {
26− text: menu && menu.label ? menu.label : ""
26+ text: ""
2727 implicitHeight: units.gu(7)
2828
29− icon: menu ? menu.icon : ""
3029 iconFrame: false
3130
3231 HLine {
plugins/Unity/Indicators/qml/IndicatorPage.qml+4−9
@@ -96,18 +96,13 @@ IndicatorBase {
9696 }
9797 if (item.hasOwnProperty("menu")) {
9898 item.menu = Qt.binding(function() { return model; });
99−
100− item.activate.connect(onActivateMenu);
101− item.changeState.connect(onChangeState);
10299 }
103100 }
104101
105− function onActivateMenu(value) {
106− mainMenu.model.activate(index, value);
107− }
108−
109− function onChangeState(value) {
110− mainMenu.model.changeState(index, value);
102+ Binding {
103+ target: item ? item : null
104+ property: "objectName"
105+ value: model.action
111106 }
112107 }
113108 }
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 @@
2020import QtQuick 2.0
2121import Unity.Indicators 0.1 as Indicators
2222import Unity.Indicators.Network 0.1 as ICNetwork
23+import QMenuModel 0.1 as QMenuModel
2324
2425Item {
2526 id: menuFactory
@@ -47,35 +48,151 @@ Item {
4748 Component {
4849 id: sliderMenu;
4950 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+
5069 Component.onCompleted: {
5170 model.loadExtendedAttributes(modelIndex, {'min-value': 'double',
5271 'max-value': 'double',
5372 'min-icon': 'icon',
5473 'max-icon': 'icon'});
5574 }
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+ }
5694 }
5795 }
58− Component { id: buttonMenu; Indicators.ButtonMenuItem {} }
96+
5997 Component { id: divMenu; Indicators.DivMenuItem {} }
60− Component { id: sectionMenu; Indicators.SectionMenuItem {} }
61− Component { id: progressMenu; Indicators.ProgressMenuItem {} }
62− Component { id: standardMenu; Indicators.StandardMenuItem {} }
63− Component { id: switchMenu; Indicators.SwitchMenuItem {} }
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;
112+ Indicators.SectionMenuItem {
113+ property QtObject menu: null
114+
115+ text: menu && menu.label ? menu.label : ""
116+ }
117+ }
118+
119+ Component {
120+ id: progressMenu;
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;
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;
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+
64159 Component {
65160 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+
67167 Component.onCompleted: {
68168 model.loadExtendedAttributes(modelIndex, {'x-canonical-busy-action': 'bool'});
69169 }
70170 }
71171 }
172+
72173 Component {
73174 id: accessPoint;
74175 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+
75190 Component.onCompleted: {
76191 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'});
78194 }
195+ onActivate: model.activate(modelIndex);
79196 }
80197 }
81198
plugins/Unity/Indicators/qml/ProgressMenuItem.qml+1−8
@@ -23,10 +23,8 @@ import Unity.Indicators 0.1 as Indicators
2323
2424FramedMenuItem {
2525 id: menuItem
26− objectName: menuAction.name
27− enabled: menuAction.active
2826
29− property int value : menuAction.state
27+ property int value : 0.0
3028
3129 control: Label {
3230 id: progress
@@ -37,9 +35,4 @@ FramedMenuItem {
3735 fontSize: "medium"
3836 color: "#e8e1d0"
3937 }
40−
41− Indicators.MenuAction {
42− id: menuAction
43− menu: menuItem.menu
44− }
4538}
plugins/Unity/Indicators/qml/SectionMenuItem.qml+3−3
@@ -22,15 +22,15 @@ import Ubuntu.Components 0.1
2222import Ubuntu.Components.ListItems 0.1 as ListItem
2323
2424BaseMenuItem {
25− property string label: menu && menu.label ? menu.label : ""
25+ id: menuItem
26+ property alias text: header.text
2627 property bool busy: false
2728
28− implicitHeight: label !== "" ? header.height : 0
29+ implicitHeight: text !== "" ? header.height : 0
2930
3031 ListItem.Header {
3132 id: header
3233
33− text: label
3434 height: units.gu(4)
3535 anchors {
3636 left: parent.left
plugins/Unity/Indicators/qml/SliderMenuItem.qml+8−23
@@ -24,17 +24,20 @@ import Unity.Indicators 0.1 as Indicators
2424
2525FramedMenuItem {
2626 id: menuItem
27− objectName: menuAction.name
28− enabled: menuAction.active
2927
3028 property alias minimumValue: slider.minimumValue
3129 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
3334
3435 property QtObject d: QtObject {
3536 property bool enableValueConnection: true
3637 }
3738
39+ signal changeState(real value)
40+
3841 onValueChanged: {
3942 // TODO: look into adding a component to manage bi-directional bindings.
4043 var oldEnable = d.enableValueConnection
@@ -58,7 +61,6 @@ FramedMenuItem {
5861 anchors.verticalCenter: row.verticalCenter
5962 height: units.gu(4)
6063 width: height
61− source: menu.ext.minIcon
6264 }
6365
6466 Components.Slider {
@@ -75,19 +77,8 @@ FramedMenuItem {
7577 value = menuItem.value
7678 }
7779
78− // FIXME: The interval should be [0.0 - 1.0]. Unfortunately, when
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: {
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− }
80+ minimumValue: 0.0
81+ maximumValue: 0.1
9182
9283 // FIXME - to be deprecated in Ubuntu.Components.
9384 // Use this to disable the label, since there is not way to do it on the component.
@@ -109,12 +100,6 @@ FramedMenuItem {
109100 anchors.verticalCenter: row.verticalCenter
110101 height: units.gu(4)
111102 width: height
112− source: menu.ext.maxIcon
113103 }
114104 }
115−
116− Indicators.MenuAction {
117− id: menuAction
118− menu: menuItem.menu
119− }
120105}
plugins/Unity/Indicators/qml/StandardMenuItem.qml+5−10
@@ -23,16 +23,16 @@ import Unity.Indicators 0.1 as Indicators
2323
2424FramedMenuItem {
2525 id: menuItem
26− objectName: menuAction.name
27− enabled: menuAction.active
2826
29− readonly property bool checkable: menu ? (menu.isCheck || menu.isRadio) : false
30− readonly property bool checked: checkable ? menu.isToggled : false
27+ property bool checkable: false
28+ property bool checked: false
29+
30+ signal activate()
3131
3232 // FIXME : need a radio button from sdk
3333 // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1211866
3434 onCheckableChanged: {
35− if (menu && checkable) {
35+ if (checkable) {
3636 icon = checkComponent.createObject(menuItem);
3737 }
3838 }
@@ -68,9 +68,4 @@ FramedMenuItem {
6868 }
6969 }
7070 }
71−
72− Indicators.MenuAction {
73− id: menuAction
74− menu: menuItem.menu
75− }
7671}
plugins/Unity/Indicators/qml/SwitchMenuItem.qml+3−8
@@ -24,10 +24,10 @@ import Unity.Indicators 0.1 as Indicators
2424
2525FramedMenuItem {
2626 id: menuItem
27− objectName: menuAction.name
28− enabled: menuAction.enabled
2927
30− readonly property bool checked: menu ? menu.isToggled : false
28+ property bool checked: false
29+
30+ signal activate()
3131
3232 onCheckedChanged: {
3333 // Can't rely on binding. Checked is assigned on click.
@@ -50,9 +50,4 @@ FramedMenuItem {
5050 menuItem.activate();
5151 }
5252 }
53−
54− Indicators.MenuAction {
55− id: menuAction
56− menu: menuItem.menu
57− }
5853}
plugins/Unity/Indicators/qml/qmldir−1
@@ -11,7 +11,6 @@ HLine 0.1 HLine.qml
1111IndicatorBase 0.1 IndicatorBase.qml
1212IndicatorPage 0.1 IndicatorPage.qml
1313IndicatorWidget 0.1 IndicatorWidget.qml
14−MenuAction 0.1 MenuAction.qml
1514MenuActionBinding 0.1 MenuActionBinding.qml
1615MenuItemFactory 0.1 MenuItemFactory.qml
1716ProgressMenuItem 0.1 ProgressMenuItem.qml
plugins/Unity/Indicators/unitymenumodelcache.cpp+16−1
@@ -21,14 +21,29 @@
2121#include <unitymenumodel.h>
2222
2323UnityMenuModelCache::UnityMenuModelCache(QObject* parent)
24− : QObject(parent)
24+ : QObject(parent),
25+ m_ref(0)
2526{
2627}
2728
2829UnityMenuModelCache::~UnityMenuModelCache()
2930{
31+ qDeleteAll(m_menuModels);
3032}
3133
34+void UnityMenuModelCache::ref()
35+{
36+ m_ref++;
37+}
38+
39+void UnityMenuModelCache::deref()
40+{
41+ --m_ref;
42+ if (m_ref == 0) {
43+ qDeleteAll(m_menuModels);
44+ m_menuModels.clear();
45+ }
46+}
3247
3348UnityMenuModel* UnityMenuModelCache::model(const QString& path) const
3449{
plugins/Unity/Indicators/unitymenumodelcache.h+4
@@ -34,11 +34,15 @@ public:
3434 UnityMenuModelCache(QObject*parent=NULL);
3535 ~UnityMenuModelCache();
3636
37+ Q_INVOKABLE void ref();
38+ Q_INVOKABLE void deref();
39+
3740 Q_INVOKABLE UnityMenuModel* model(const QString& path) const;
3841 Q_INVOKABLE void registerModel(const QString& path, UnityMenuModel* menuModel);
3942
4043private:
4144 QHash<QString, UnityMenuModel*> m_menuModels;
45+ int m_ref;
4246};
4347
4448#endif // UNITYMENUMODELCACHE_H