on xenial help sign in
Refitted DBusActionState to allow activation. Renamed to MenuItemAction & MenuItemActionValue. Now used in buttons as well.
commitd88d5569691bd7f3a32783c449567fe9e5b3464a authorNick Dedekind <nicholas.dedekind@gmail.com> dateFri 28 Jun 2013, 16:24 (13 years ago) parentdb20921
20 files changed+195−77
modules/Unity/Indicators/Messaging/qml/ActionButton.qml+14−4 modules/Unity/Indicators/Messaging/qml/ActionTextField.qml+2 modules/Unity/Indicators/Messaging/qml/GroupedMessage.qml+12−6 modules/Unity/Indicators/Messaging/qml/HeroMessage.qml+9−4 modules/Unity/Indicators/Messaging/qml/QuickReply.qml+2 modules/Unity/Indicators/Messaging/qml/SnapDecision.qml+9−4 modules/Unity/Indicators/Messaging/qml/TextMessage.qml+5−2 modules/Unity/Indicators/Network/qml/AccessPoint.qml+1−1 modules/Unity/Indicators/Network/qml/WifiSection.qml+9−2 modules/Unity/Indicators/qml/ButtonMenuItem.qml+10−5 modules/Unity/Indicators/qml/IndicatorBase.qml−2 modules/Unity/Indicators/qml/IndicatorPage.qml+8−11 modules/Unity/Indicators/qml/IndicatorWidget.qml−3 modules/Unity/Indicators/qml/MenuItemAction.qml+94 modules/Unity/Indicators/qml/DBusActionState.qml → modules/Unity/Indicators/qml/MenuItemActionValue.qml+10−28 modules/Unity/Indicators/qml/ProgressMenuItem.qml+1−1 modules/Unity/Indicators/qml/SliderMenuItem.qml+3−1 modules/Unity/Indicators/qml/SwitchMenuItem.qml+3−1 modules/Unity/Indicators/qml/TextMenuItem.qml+1−1 modules/Unity/Indicators/qml/qmldir+2−1
modules/Unity/Indicators/Messaging/qml/ActionButton.qml+14−4
@@ -20,14 +20,24 @@
2020
2121import QtQuick 2.0
2222import Ubuntu.Components 0.1
23+import Unity.Indicators 0.1 as Indicators
2324
2425Button {
25− property variant action: null
26− property variant actionParameter: null
26+ id: __button
27+ property QtObject actionGroup: null
28+ property string action
29+
30+ property var actionParameter: null
31+
32+ Indicators.MenuItemAction {
33+ id: menuAction
34+ actionGroup: __button.actionGroup
35+ action: __button.action
36+ }
2737
2838 onClicked: {
29− if (action && action.valid) {
30− action.activate(actionParameter);
39+ if (menuAction.valid) {
40+ menuAction.activate(actionParameter);
3141 }
3242 }
3343}
modules/Unity/Indicators/Messaging/qml/ActionTextField.qml+2
@@ -22,7 +22,9 @@ import QtQuick 2.0
2222import Ubuntu.Components 0.1
2323
2424Item {
25+ property alias actionGroup: __sendButton.actionGroup
2526 property alias action: __sendButton.action
27+
2628 property alias text: __replyField.text
2729 property alias buttonText: __sendButton.text
2830
modules/Unity/Indicators/Messaging/qml/GroupedMessage.qml+12−6
@@ -23,12 +23,18 @@ import Ubuntu.Components 0.1
2323import Unity.Indicators 0.1 as Indicators
2424
2525Indicators.BasicMenuItem {
26− property var action: menu && menu.action != "" && actionGroup ? actionGroup.action(menu.action) : null
26+ id: __groupedMessage
2727 property alias count: label.text
2828
2929 color: "#221e1b"
3030 implicitHeight: units.gu(10)
3131
32+ Indicators.MenuItemAction {
33+ id: menuAction
34+ actionGroup: __groupedMessage.actionGroup
35+ action: menu ? menu.action : ""
36+ }
37+
3238 Row {
3339 anchors.fill: parent
3440 anchors.margins: units.gu(2)
@@ -59,7 +65,7 @@ Indicators.BasicMenuItem {
5965 color: "#e8e1d0"
6066 font.weight: Font.DemiBold
6167 fontSize: "medium"
62− text: action && action.valid && action.state ? action.state[0] : "0"
68+ text: menuAction.valid ? menuAction.state[0] : "0"
6369 }
6470 }
6571
@@ -76,15 +82,15 @@ Indicators.BasicMenuItem {
7682 MouseArea {
7783 anchors.fill: parent
7884 onClicked: {
79− if (action && action.valid) {
80− action.activate(true);
85+ if (menuAction.valid) {
86+ menuAction.activate(true);
8187 }
8288 }
8389 }
8490
8591 onItemRemoved: {
86− if (action && action.valid) {
87− action.activate(false);
92+ if (menuAction.valid) {
93+ menuAction.activate(false);
8894 }
8995 }
9096}
modules/Unity/Indicators/Messaging/qml/HeroMessage.qml+9−4
@@ -26,7 +26,6 @@ Indicators.BasicMenuItem {
2626 id: __heroMessage
2727
2828 property variant actionsDescription: null
29− property var action: menu && menu.action != "" && actionGroup ? actionGroup.action(menu.action) : null
3029 property alias heroMessageHeader: __heroMessageHeader
3130 property real collapsedHeight: heroMessageHeader.y + heroMessageHeader.bodyBottom + units.gu(2)
3231 property real expandedHeight: collapsedHeight
@@ -36,6 +35,12 @@ Indicators.BasicMenuItem {
3635 removable: state !== "expanded"
3736 implicitHeight: collapsedHeight
3837
38+ Indicators.MenuItemAction {
39+ id: menuAction
40+ actionGroup: __heroMessage.actionGroup
41+ action: menu ? menu.action : ""
42+ }
43+
3944 HeroMessageHeader {
4045 id: __heroMessageHeader
4146
@@ -50,7 +55,7 @@ Indicators.BasicMenuItem {
5055 state: __heroMessage.state
5156
5257 onAppIconClicked: {
53− if (action && action.valid) {
58+ if (menuAction.valid) {
5459 deactivateMenu();
5560 action.activate(true);
5661 }
@@ -108,8 +113,8 @@ Indicators.BasicMenuItem {
108113 }
109114
110115 onItemRemoved: {
111− if (action && action.valid) {
112− action.activate(false);
116+ if (menuAction.valid) {
117+ menuAction.activate(false);
113118 }
114119 }
115120}
modules/Unity/Indicators/Messaging/qml/QuickReply.qml+2
@@ -23,7 +23,9 @@ import Ubuntu.Components 0.1
2323import Unity.Indicators 0.1 as Indicators
2424
2525Item {
26+ property alias actionGroup: __actionTextField.actionGroup
2627 property alias action: __actionTextField.action
28+
2729 property alias buttonText: __actionTextField.buttonText
2830 property real expandedHeight: childrenRect.height
2931 property alias messages : __messagelistRepeater.model
modules/Unity/Indicators/Messaging/qml/SnapDecision.qml+9−4
@@ -20,10 +20,11 @@
2020
2121import QtQuick 2.0
2222import Ubuntu.Components 0.1
23+import Unity.Indicators 0.1 as Indicators
2324import "utils.js" as Utils
2425
2526HeroMessage {
26− id: __heroMessage
27+ id: __snapDecision
2728
2829 expandedHeight: __buttons.y + __buttons.height + __quickreply.height + units.gu(2)
2930 heroMessageHeader.titleText.text: menu ? menu.label : ""
@@ -62,7 +63,9 @@ HeroMessage {
6263 }
6364
6465 ActionButton {
65− action: menu && actionGroup && actionsDescription ? actionGroup.action(actionsDescription[0].name) : undefined
66+ actionGroup: __snapDecision.actionGroup
67+ action: actionsDescription[0].name
68+
6669 text: actionsDescription ? actionsDescription[0].label : "Call back"
6770 color: "#c94212"
6871 anchors.right: parent.right
@@ -73,7 +76,7 @@ HeroMessage {
7376
7477 states: State {
7578 name: "expanded"
76− when: __heroMessage.state === "expanded"
79+ when: __snapDecision.state === "expanded"
7780
7881 PropertyChanges {
7982 target: __buttons
@@ -92,9 +95,11 @@ HeroMessage {
9295 QuickReply {
9396 id: __quickreply
9497
98+ actionGroup: __snapDecision.actionGroup
99+ action: actionsDescription[1].name
100+
95101 messages: actionsDescription ? actionsDescription[1]["parameter-hint"] : ""
96102 buttonText: actionsDescription ? actionsDescription[1].label : "send"
97− action: menu && actionGroup && actionsDescription ? actionGroup.action(actionsDescription[1].name) : undefined
98103 anchors.top: __buttons.bottom
99104 anchors.topMargin: units.gu(2)
100105 anchors.left: parent.left
modules/Unity/Indicators/Messaging/qml/TextMessage.qml+5−2
@@ -20,13 +20,16 @@
2020
2121import QtQuick 2.0
2222import Ubuntu.Components 0.1
23+import Unity.Indicators 0.1 as Indicators
2324
2425SimpleTextMessage {
25− id: __heroMessage
26+ id: __simpleMessage
2627
2728 footer: ActionTextField {
2829 anchors.fill: parent
29− action: menu && actionGroup && actionsDescription ? actionGroup.action(actionsDescription[0].name) : undefined
30+ actionGroup: __simpleMessage.actionGroup
31+ action: actionsDescription[0].name
32+
3033 buttonText: actionsDescription ? actionsDescription[0].label : "Send"
3134 }
3235}
modules/Unity/Indicators/Network/qml/AccessPoint.qml+1−1
@@ -61,7 +61,7 @@ Indicators.MenuItem {
6161 anchors.centerIn: parent
6262 }
6363
64− Indicators.DBusActionState {
64+ Indicators.MenuItemActionValue {
6565 actionGroup: _accessPoint.actionGroup
6666 action: menu ? menu.action : ""
6767 target: checkBoxActive
modules/Unity/Indicators/Network/qml/WifiSection.qml+9−2
@@ -22,6 +22,13 @@ import Ubuntu.Components 0.1
2222import Unity.Indicators 0.1 as Indicators
2323
2424Indicators.SectionMenuItem {
25− property variant busyAction : actionGroup ? actionGroup.action(menu.extra.canonical_busy_action) : undefined
26− busy: busyAction && busyAction.valid ? busyAction.state : false
25+ id: __wifiSectionMenu
26+
27+ Indicators.MenuItemAction {
28+ id: busyAction
29+ actionGroup: __wifiSectionMenu.actionGroup
30+ action: menu ? menu.extra.canonical_busy_action : ""
31+ }
32+
33+ busy: busyAction.valid ? busyAction.state : false
2734}
modules/Unity/Indicators/qml/ButtonMenuItem.qml+10−5
@@ -21,12 +21,13 @@ import QtQuick 2.0
2121import Ubuntu.Components 0.1
2222
2323BasicMenuItem {
24− property var action: menu && menu.action != "" && actionGroup ? actionGroup.action(menu.action) : null
25−
24+ id: _buttonMenu
2625 color: "#221e1b"
2726 implicitHeight: units.gu(7)
2827
2928 Button {
29+ id: button
30+ enabled: menuAction.valid
3031 text: menu ? menu.label : ""
3132 anchors.centerIn: parent
3233 height: units.gu(4)
@@ -34,9 +35,13 @@ BasicMenuItem {
3435 color: "#1b1817"
3536
3637 onClicked: {
37− if (action && action.valid) {
38− action.activate()
39− }
38+ menuAction.activate()
4039 }
4140 }
41+
42+ MenuItemAction {
43+ id: menuAction
44+ actionGroup: _buttonMenu.actionGroup
45+ action: menu ? menu.action : ""
46+ }
4247}
modules/Unity/Indicators/qml/IndicatorBase.qml−2
@@ -20,8 +20,6 @@
2020
2121import QtQuick 2.0
2222import QMenuModel 0.1
23−import Ubuntu.Components 0.1
24−import Ubuntu.Components.ListItems 0.1 as ListItem
2523import Unity.Indicators 0.1 as Indicators
2624
2725Item {
modules/Unity/Indicators/qml/IndicatorPage.qml+8−11
@@ -19,10 +19,7 @@
1919 */
2020
2121import QtQuick 2.0
22−import QMenuModel 0.1
23−import Ubuntu.Components 0.1
24−import Ubuntu.Components.ListItems 0.1 as ListItem
25−import Unity.Indicators 0.1 as Indicators
22+import Ubuntu.Components 0.1 as Components
2623
2724IndicatorBase {
2825 id: main
@@ -132,7 +129,6 @@ IndicatorBase {
132129 isCurrentItem: item.ListView.isCurrentItem
133130 anchors.left: parent.left
134131 anchors.right: parent.right
135− height: implicitHeight
136132 menu: model
137133
138134 Connections {
@@ -145,14 +141,15 @@ IndicatorBase {
145141 }
146142 }
147143
148− Label {
144+ Components.Label {
149145 id: emptyLabel
150146 visible: (mainMenu.visibleItems === 0)
151− anchors.top: parent.top
152− anchors.left: parent.left
153− anchors.right: parent.right
154− anchors.topMargin: units.gu(2)
155− height: paintedHeight
147+ anchors {
148+ top: parent.top
149+ left: parent.left
150+ right: parent.right
151+ topMargin: units.gu(2)
152+ }
156153 wrapMode: Text.WordWrap
157154 horizontalAlignment: Text.AlignHCenter
158155
modules/Unity/Indicators/qml/IndicatorWidget.qml−3
@@ -18,9 +18,6 @@
1818 */
1919
2020import QtQuick 2.0
21−import QMenuModel 0.1
22−import Ubuntu.Components 0.1
23−import Ubuntu.Components.ListItems 0.1 as ListItem
2421import Unity.Indicators 0.1 as Indicators
2522
2623IndicatorBase {
modules/Unity/Indicators/qml/MenuItemAction.qmlnew file+94
@@ -0,0 +1,94 @@
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+
22+/*!
23+ \qmltype MenuItemActionValue
24+ \inqmlmodule Indicators 0.1
25+ \brief Helper class to connect dbus action state with qml components property
26+
27+ Exampiles:
28+ \qml
29+ Button {
30+ id: slide
31+ onClick: { action.activate() }
32+ }
33+ MenuItemAction {
34+ id: action
35+ actionGroup: menuItem.actionGroup
36+ action: "/ubuntu/sound/auto"
37+ }
38+ \endqml
39+
40+ \b{This component is under heavy development.}
41+*/
42+
43+Item {
44+ id: dbusAction
45+
46+ /*!
47+ \preliminary
48+ The dbus action name
49+ */
50+ property string action: ""
51+
52+ /*!
53+ \preliminary
54+ The dbus action group object
55+ */
56+ property QtObject actionGroup: null
57+
58+ /*!
59+ \preliminary
60+ This is a read-only property with the current validity of the action
61+ */
62+ readonly property bool valid: __actionObject ? __actionObject.valid : false
63+
64+ readonly property var state: __actionObject ? __actionObject.state : undefined
65+
66+ // internal
67+ property QtObject __actionObject: null
68+
69+ function activate(param) {
70+ if (valid) {
71+ __actionObject.activate(param);
72+ console.log("ACTIONED : " + action + "(" + param + ")")
73+ }
74+ }
75+
76+ onActionGroupChanged: updateAction()
77+ onActionChanged: updateAction()
78+
79+ Item {
80+ id: priv
81+ property var actionObject: null
82+
83+ Connections {
84+ target: dbusAction.actionGroup != undefined ? dbusAction.actionGroup : null
85+ onActionAppear: dbusAction.updateAction();
86+ onActionVanish: dbusAction.updateAction();
87+ onStatusChanged: dbusAction.updateAction();
88+ }
89+ }
90+
91+ function updateAction() {
92+ __actionObject = action !== "" && actionGroup ? actionGroup.action(action) : null
93+ }
94+}
modules/Unity/Indicators/qml/DBusActionState.qml → modules/Unity/Indicators/qml/MenuItemActionValue.qmlrenamed+10−28
@@ -20,7 +20,7 @@
2020import QtQuick 2.0
2121
2222/*!
23− \qmltype DBusActionState
23+ \qmltype MenuItemActionValue
2424 \inqmlmodule Indicators 0.1
2525 \brief Helper class to connect dbus action state with qml components property
2626
@@ -29,7 +29,7 @@ import QtQuick 2.0
2929 Slider {
3030 id: slide
3131 }
32− DBusActionState {
32+ MenuItemActionValue {
3333 actionGroup: menuItem.actionGroup
3434 action: "/ubuntu/sound/volume"
3535 target: slider
@@ -40,27 +40,9 @@ import QtQuick 2.0
4040 \b{This component is under heavy development.}
4141*/
4242
43−Item {
43+MenuItemAction {
4444 id: dbusActionState
4545
46− /*!
47− \preliminary
48− The dbus action name
49− */
50− property string action : ""
51−
52− /*!
53− \preliminary
54− The dbus action group object
55− */
56− property QtObject actionGroup : null
57−
58− /*!
59− \preliminary
60− This is a read-only property with the action current value
61− */
62− property var value : undefined
63−
6446 /*!
6547 \preliminary
6648 The component which will have the property changed by action
@@ -85,23 +67,23 @@ Item {
8567
8668 Item {
8769 id: priv
88− property var actionObject: action != "" && dbusActionState.actionGroup ? dbusActionState.actionGroup.action(action) : null
89− property var actionState: actionObject ? actionObject.state : undefined
70+ property alias actionObject : dbusActionState.__actionObject
9071
9172 property var currentTarget: undefined
9273 property string currentSignal
9374
75+
9476 Binding {
9577 id: propertyBinding
96− value: priv.actionState
97− when: (actionGroup && active && priv.actionObject)
78+ value: dbusActionState.state
79+ when: priv.actionObject && dbusActionState.active
9880 property: dbusActionState.property
9981 }
10082 }
10183
10284 function connectViewChanges() {
10385 if (priv.currentTarget != undefined && priv.currentSignal !== "") {
104− if (priv.currentTarget[priv.currentSignal] != undefined) {
86+ if (priv.currentTarget[priv.currentSignal] !== undefined) {
10587 priv.currentTarget[priv.currentSignal].disconnect(onViewValueChanged);
10688 }
10789 }
@@ -110,7 +92,7 @@ Item {
11092 priv.currentSignal = "";
11193 if (target) {
11294 var signal = "on%1Changed".arg(property.charAt(0).toUpperCase() + property.slice(1));
113− if (target[signal] != undefined) {
95+ if (target[signal] !== undefined) {
11496 target[signal].connect(onViewValueChanged);
11597 priv.currentTarget = target;
11698 priv.currentSignal = signal;
@@ -119,7 +101,7 @@ Item {
119101 }
120102
121103 function onViewValueChanged() {
122− if (priv.actionObject.valid) {
104+ if (valid) {
123105 var propertyValue = target[property];
124106 priv.actionObject.updateState(propertyValue);
125107 }
modules/Unity/Indicators/qml/ProgressMenuItem.qml+1−1
@@ -54,7 +54,7 @@ MenuItem {
5454 }
5555 }
5656
57− DBusActionState {
57+ MenuItemActionValue {
5858 actionGroup: _progressMenu.actionGroup
5959 action: menu ? menu.action : ""
6060 target: progressBar
modules/Unity/Indicators/qml/SliderMenuItem.qml+3−1
@@ -29,6 +29,7 @@ MenuItem {
2929
3030 control: Slider {
3131 id: slider
32+ enabled: menuAction.valid
3233 width: _sliderMenu.text ? units.gu(20) : _sliderMenu.width - units.gu(4)
3334 anchors.verticalCenter: parent.verticalCenter
3435 live: false
@@ -58,7 +59,8 @@ MenuItem {
5859 }
5960 }
6061
61− DBusActionState {
62+ MenuItemActionValue {
63+ id: menuAction
6264 actionGroup: _sliderMenu.actionGroup
6365 action: menu ? menu.action : ""
6466 target: slider
modules/Unity/Indicators/qml/SwitchMenuItem.qml+3−1
@@ -27,12 +27,14 @@ MenuItem {
2727
2828 control: Switch {
2929 id: switcher
30+ enabled: menuAction.valid
3031
3132 anchors.verticalCenter: parent.verticalCenter
3233 anchors.right: parent.right
3334 }
3435
35− DBusActionState {
36+ MenuItemActionValue {
37+ id: menuAction
3638 actionGroup: _switchMenu.actionGroup
3739 action: menu ? menu.action : ""
3840 target: switcher
modules/Unity/Indicators/qml/TextMenuItem.qml+1−1
@@ -73,7 +73,7 @@ MenuItem {
7373 }
7474 }
7575
76− DBusActionState {
76+ MenuItemActionValue {
7777 actionGroup: _textMenu.actionGroup
7878 action: menu ? menu.action : ""
7979 target: _textField
modules/Unity/Indicators/qml/qmldir+2−1
@@ -3,13 +3,14 @@ plugin IndicatorsQml
33
44BasicMenuItem 0.1 BasicMenuItem.qml
55ButtonMenuItem 0.1 ButtonMenuItem.qml
6−DBusActionState 0.1 DBusActionState.qml
76DivMenuItem 0.1 DivMenuItem.qml
87HLine 0.1 HLine.qml
98IndicatorBase 0.1 IndicatorBase.qml
109IndicatorPage 0.1 IndicatorPage.qml
1110IndicatorWidget 0.1 IndicatorWidget.qml
1211MenuItem 0.1 MenuItem.qml
12+MenuItemAction 0.1 MenuItemAction.qml
13+MenuItemActionValue 0.1 MenuItemActionValue.qml
1314MenuItemFactory 0.1 MenuItemFactory.qml
1415ProgressMenuItem 0.1 ProgressMenuItem.qml
1516SectionMenuItem 0.1 SectionMenuItem.qml