on e04653c help sign in
unity8/plugins/Unity/Indicators/qml/MenuItemFactory.qml
110 lines 4.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 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
20import QtQuick 2.0
21import Unity.Indicators 0.1 as Indicators
22import Unity.Indicators.Messaging 0.1 as ICMessaging
23import Unity.Indicators.Network 0.1 as ICNetwork
25Item {
26 id: menuFactory
28 property QtObject menu
29 property QtObject listView
30 property QtObject actionGroup
31 property bool isCurrentItem
32 readonly property bool empty: (loader.item !== undefined && loader.status == Loader.Ready) ? loader.item.state === "EMPTY" : true
34 implicitHeight: loader.height
36 signal activated()
37 signal deactivated()
39 property var _map: {
40 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
41 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
43 "com.canonical.indicator.button" : buttonMenu,
44 "com.canonical.indicator.div" : divMenu,
45 "com.canonical.indicator.section" : sectionMenu,
46 "com.canonical.indicator.progress" : progressMenu,
47 "com.canonical.indicator.slider" : sliderMenu,
48 "com.canonical.indicator.switch" : switchMenu,
50 "com.canonical.indicator.messages.messageitem" : messageItem,
51 "com.canonical.indicator.messages.snapdecision" : snapDecision,
52 "com.canonical.indicator.messages.sourceitem" : groupedMessage,
54 "unity.widget.systemsettings.tablet.sectiontitle" : wifiSection,
55 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
56 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
57 }
59 Component { id: sliderMenu; Indicators.SliderMenuItem {} }
60 Component { id: switchMenu; Indicators.SwitchMenuItem {} }
61 Component { id: buttonMenu; Indicators.ButtonMenuItem {} }
62 Component { id: divMenu; Indicators.DivMenuItem {} }
63 Component { id: sectionMenu; Indicators.SectionMenuItem {} }
64 Component { id: progressMenu; Indicators.ProgressMenuItem {} }
65 Component { id: messageItem; ICMessaging.MessageMenuItem {} }
66 Component { id: snapDecision; ICMessaging.SnapDecision {} }
67 Component { id: groupedMessage; ICMessaging.GroupedMessage {} }
68 Component { id: wifiSection; ICNetwork.WifiSection {} }
69 Component { id: accessPoint; ICNetwork.AccessPoint {} }
70 Component { id: indicatorMenu; Indicators.MenuItem {} }
72 Loader {
73 id: loader
74 asynchronous: true
76 anchors {
77 left: parent.left
78 right: parent.right
79 }
81 sourceComponent: {
82 if (!menuFactory.menu || !menuFactory.menu.extra) {
83 return undefined;
84 }
86 var widgetType = menuFactory.menu.extra.canonical_type;
87 if (widgetType) {
88 return _map[widgetType];
89 } else {
90 if (widgetType === "com.canonical.indicator.root") {
91 return undefined;
92 // Try discovery the item based on the basic properties
93 } else if (menu.hasSection) {
94 return sectionMenu;
95 } else {
96 return indicatorMenu;
97 }
98 }
99 }
101 onLoaded: {
102 item.menuActivated = Qt.binding(function() { return isCurrentItem; });
103 item.actionGroup = Qt.binding(function() { return menuFactory.actionGroup; });
104 item.menu = Qt.binding(function() { return menuFactory.menu; });
106 item.activateMenu.connect(function() { menuFactory.activated(); });
107 item.deactivateMenu.connect(function() { menuFactory.deactivated(); });
108 }
109 }