on e04653c help sign in
86 lines 2.3 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 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 */
20import QtQuick 2.0
22/*!
23 \qmltype MenuAction
24 \inqmlmodule Indicators 0.1
25 \brief Helper class to connect to a qmenumodel action
27 Example:
28 \qml
29 Button {
30 id: slide
31 onClick: { action.activate() }
32 }
33 MenuAction {
34 id: action
35 actionGroup: menuItem.actionGroup
36 action: "/ubuntu/sound/enabled"
37 }
38 \endqml
39*/
41Item {
42 id: menuAction
44 /*!
45 \preliminary
46 The dbus action name
47 */
48 property string action: ""
50 /*!
51 \preliminary
52 The dbus action group object
53 */
54 property QtObject actionGroup: null
56 /*!
57 \preliminary
58 This is a read-only property with the current validity of the action
59 */
60 readonly property bool valid: actionObject ? actionObject.valid : false
62 readonly property var state: actionObject ? actionObject.state : undefined
64 // internal
65 property QtObject actionObject: null
67 function activate(param) {
68 if (valid) {
69 actionObject.activate(param);
70 }
71 }
73 onActionGroupChanged: updateAction()
74 onActionChanged: updateAction()
76 Connections {
77 target: menuAction.actionGroup != undefined ? menuAction.actionGroup : null
78 onActionAppear: menuAction.updateAction();
79 onActionVanish: menuAction.updateAction();
80 onStatusChanged: menuAction.updateAction();
81 }
83 function updateAction() {
84 actionObject = action !== "" && actionGroup ? actionGroup.action(action) : null
85 }