on 9ff170c help sign in
unity8/plugins/Unity/IndicatorsLegacy/qml/MenuItemFactory.qml
102 lines 3.8 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.IndicatorsLegacy 0.1 as Indicators
22import Unity.IndicatorsLegacy.Network 0.1 as ICNetwork
24Item {
25 id: menuFactory
27 property QtObject menu
28 property QtObject listView
29 property QtObject actionGroup
30 property bool isCurrentItem
31 readonly property bool empty: (loader.item !== undefined && loader.status == Loader.Ready) ? loader.item.state === "EMPTY" : true
33 implicitHeight: loader.height
35 signal activated()
36 signal deactivated()
38 property var _map: {
39 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
40 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
42 "com.canonical.indicator.button" : buttonMenu,
43 "com.canonical.indicator.div" : divMenu,
44 "com.canonical.indicator.section" : sectionMenu,
45 "com.canonical.indicator.progress" : progressMenu,
46 "com.canonical.indicator.slider" : sliderMenu,
47 "com.canonical.indicator.switch" : switchMenu,
49 "unity.widget.systemsettings.tablet.sectiontitle" : wifiSection,
50 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
51 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
52 }
54 Component { id: sliderMenu; Indicators.SliderMenuItem {} }
55 Component { id: switchMenu; Indicators.SwitchMenuItem {} }
56 Component { id: buttonMenu; Indicators.ButtonMenuItem {} }
57 Component { id: divMenu; Indicators.DivMenuItem {} }
58 Component { id: sectionMenu; Indicators.SectionMenuItem {} }
59 Component { id: progressMenu; Indicators.ProgressMenuItem {} }
60 Component { id: wifiSection; ICNetwork.WifiSection {} }
61 Component { id: accessPoint; ICNetwork.AccessPoint {} }
62 Component { id: indicatorMenu; Indicators.MenuItem {} }
64 Loader {
65 id: loader
66 asynchronous: true
68 anchors {
69 left: parent.left
70 right: parent.right
71 }
73 sourceComponent: {
74 if (!menuFactory.menu || !menuFactory.menu.extra) {
75 return undefined;
76 }
78 var widgetType = menuFactory.menu.extra.canonical_type;
79 if (widgetType) {
80 return _map[widgetType];
81 } else {
82 if (widgetType === "com.canonical.indicator.root") {
83 return undefined;
84 // Try discovery the item based on the basic properties
85 } else if (menu.hasSection) {
86 return sectionMenu;
87 } else {
88 return indicatorMenu;
89 }
90 }
91 }
93 onLoaded: {
94 item.menuActivated = Qt.binding(function() { return isCurrentItem; });
95 item.actionGroup = Qt.binding(function() { return menuFactory.actionGroup; });
96 item.menu = Qt.binding(function() { return menuFactory.menu; });
98 item.activateMenu.connect(function() { menuFactory.activated(); });
99 item.deactivateMenu.connect(function() { menuFactory.deactivated(); });
100 }
101 }